[ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 <?php 2 // This file defines a set of functions and an associative array. 3 // The key of the array corresponds to a header in the source 4 // export file and the value of the array item will be used in 5 // the creation of the output file. 6 // 7 // The array need not be in any order and any fields not defined will 8 // not be transferred. If the val='+', the value will be appended to 9 // the previous field and any text after the '+' will be appended 10 // before the value. For example, the following would add a comma and 11 // a space between LastName and FirstName and store it in FullName: 12 // 13 // array("LastName" => "FullName","FirstName" => "+, "); 14 // 15 // Also start with a '#' symbol and a comma separated list will be 16 // turned into a number of the same entries. 17 18 class export_conv 19 { 20 var $currentrecord = array(); //used for buffering to allow uid lines to go first 21 var $id; 22 //list of all id's 23 var $ids = array(); 24 var $type = 'ldif'; 25 26 var $export = array( 27 'title' => 'title', 28 'n_given' => 'givenname', 29 'n_family' => 'sn', 30 'fn' => 'cn', 31 'org_name' => 'o', 32 'org_unit' => 'ou', 33 'adr_one_street' => 'postaladdress', 34 'address2' => 'mozillaPostalAddress2', 35 'adr_one_locality' => 'l', 36 'adr_one_region' => 'st', 37 'adr_one_postalcode' => 'postalcode', 38 'adr_one_countryname' => 'c', 39 'adr_two_street' => 'homepostaladdress', 40 'adr_two_locality' => 'mozillahomelocalityname', 41 'adr_two_region' => 'mozillahomestate', 42 'adr_two_postalcode' => 'mozillahomepostalcode', 43 'adr_two_countryname' => 'mozillahomecountryname', 44 'tel_work' => 'telephonenumber', 45 'tel_home' => 'homephone', 46 'tel_fax' => 'facsimiletelephonenumber', 47 'ophone' => 'custom1', 48 'tel_cell' => 'mobile', 49 'note' => 'description', 50 'tel_pager' => 'pagerp', 51 'email' => 'mail', 52 'url' => 'workurl' 53 ); 54 55 // This will store the contacts object 56 var $contacts = ''; 57 58 // Read full list of user's contacts only to get id's for each 59 function export_start_file($buffer,$ncat_id='') 60 { 61 $this->id = -1; 62 if($ncat_id) 63 { 64 $filter = 'tid=n,cat_id=' . $ncat_id; 65 } 66 else 67 { 68 $filter = 'tid=n'; 69 } 70 $this->contacts = CreateObject('phpgwapi.contacts'); 71 72 $tmp = $this->contacts->read('','',array('id'=>'id'),'',$filter); 73 for($i=0;$i<count($tmp);$i++) 74 { 75 $this->ids[$i] = $tmp[$i]['id']; 76 } 77 // $ids is now an array of all id's for this user, e.g. $ids[0] = 21, etc... 78 // $buffer is still empty 79 return $buffer; 80 } 81 82 // Read each entry 83 function export_start_record($buffer) 84 { 85 $this->id++; 86 $top = $this->contacts->read_single_entry($this->ids[$this->id],$this->qfields); 87 $this->currentrecord = $top[0]; 88 return $buffer; 89 } 90 91 // Read each attribute, populate buffer 92 // name/value are the fields from the export array above 93 function export_new_attrib($buffer,$name,$value) 94 { 95 if($this->export[$name]) 96 { 97 if(strstr($value,"\n")) 98 { 99 $value = ': '.base64_encode($value); 100 } 101 else 102 { 103 $value = ' '.$value; 104 } 105 $buffer[$this->id][$this->export[$name]] = $value; 106 //echo '<br>'.$this->id.' - '.$this->export[$name].': '.$buffer[$this->id][$this->export[$name]]; 107 } 108 return $buffer; 109 } 110 111 // Tack on some extra values 112 function export_end_record($buffer) 113 { 114 $buffer[$this->id]['dn'] = 'cn='.$buffer[$this->id]['cn'].',mail='.$buffer[$this->id]['mail']; 115 $buffer[$this->id]['xmozillauseconferenceserver'] = '0'; 116 $buffer[$this->id]['xmozillanickname'] = ''; 117 $buffer[$this->id]['xmozillausehtmlmail'] = 'False'; 118 if($buffer[$this->id]['ophone']) 119 { 120 $buffer[$this->id]['xmozillaanyphone'] = $buffer[$this->id]['ophone']; 121 } 122 else 123 { 124 $buffer[$this->id]['xmozillaanyphone'] = $buffer[$this->id]['telephonenumber']; 125 } 126 //echo '<br>'.$this->id.' - '.$buffer[$this->id]['dn']; 127 return $buffer; 128 } 129 130 function export_end_file($buffer) 131 { 132 reset($this->ids); 133 for($i=0;$i<count($this->ids);$i++) 134 { 135 $entries .= 'dn: ' . $buffer[$i]['dn'] . "\n"; 136 reset($this->export); 137 while(list($name,$value)=each($this->export)) 138 { 139 if($value != 'dn') 140 { 141 $entries .= $value . ":" . $buffer[$i][$value] . "\n"; 142 } 143 } 144 $entries .= 'xmozillauseconferenceserver: ' . $buffer[$i]['xmozillauseconferenceserver'] . "\n"; 145 $entries .= 'xmozillanickname: ' . $buffer[$i]['xmozillanickname'] . "\n"; 146 $entries .= 'xmozillausehtmlmail: ' . $buffer[$i]['xmozillausehtmlmail'] . "\n"; 147 $entries .= 'xmozillaanyphone: ' . $buffer[$i]['xmozillaanyphone'] . "\n"; 148 $entries .= 'objectClass: person' . "\n"; 149 $entries .= 'objectClass: account' . "\n"; 150 $entries .= 'objectClass: organizationalPerson' . "\n"; 151 $entries .= 'objectClass: posixAccount' . "\n"; 152 $entries .= 'objectClass: inetOrgPerson' . "\n"; 153 $entries .= 'objectClass: shadowAccount' . "\n"; 154 $entries .= "\n"; 155 } 156 $buffer = $entries; 157 return $buffer; 158 } 159 } 160 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 17:20:01 2007 | par Balluche grâce à PHPXref 0.7 |