[ 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 'id' => 'uidnumber', 28 'lid' => 'uid', 29 'tid' => 'phpgwcontacttypeid', 30 'owner' => 'phpgwcontactowner', 31 'access' => 'phpgwcontactaccess', 32 'fn' => 'cn', // 'prefix given middle family suffix' 33 'n_given' => 'givenname', // firstname 34 'n_family' => 'sn', // lastname 35 'n_middle' => 'phpgwmiddlename', 36 'n_prefix' => 'phpgwprefix', 37 'n_suffix' => 'phpgwsuffix', 38 'sound' => 'phpgwaudio', 39 'bday' => 'phpgwbirthday', 40 'note' => 'description', 41 'tz' => 'phpgwtz', 42 'geo' => 'phpgwgeo', 43 'url' => 'phpgwurl', 44 'pubkey' => 'phpgwpublickey', 45 46 'org_name' => 'o', // company 47 'org_unit' => 'ou', // division 48 'title' => 'title', 49 50 'adr_one_street' => 'streetaddress', 51 'adr_one_locality' => 'localityname', 52 'adr_one_region' => 'st', 53 'adr_one_postalcode' => 'postalcode', 54 'adr_one_countryname' => 'co', 55 'adr_one_type' => 'phpgwadronetype', // address is domestic/intl/postal/parcel/work/home 56 'label' => 'phpgwaddresslabel', // address label 57 58 'adr_two_street' => 'phpgwadrtwostreet', 59 'adr_two_locality' => 'phpgwadrtwolocality', 60 'adr_two_region' => 'phpgwadrtworegion', 61 'adr_two_postalcode' => 'phpgwadrtwopostalcode', 62 'adr_two_countryname' => 'phpgwadrtwocountryname', 63 'adr_two_type' => 'phpgwadrtwotype', // address is domestic/intl/postal/parcel/work/home 64 65 'tel_work' => 'telephonenumber', 66 'tel_home' => 'homephone', 67 'tel_voice' => 'phpgwvoicetelephonenumber', 68 'tel_fax' => 'facsimiletelephonenumber', 69 'tel_msg' => 'phpgwmsgtelephonenumber', 70 'tel_cell' => 'phpgwcelltelephonenumber', 71 'tel_pager' => 'phpgwpagertelephonenumber', 72 'tel_bbs' => 'phpgwbbstelephonenumber', 73 'tel_modem' => 'phpgwmodemtelephonenumber', 74 'tel_car' => 'phpgwmobiletelephonenumber', 75 'tel_isdn' => 'phpgwisdnphonenumber', 76 'tel_video' => 'phpgwvideophonenumber', 77 'tel_prefer' => 'phpgwpreferphone', // home, work, voice, etc 78 'email' => 'mail', 79 'email_type' => 'phpgwmailtype', //'INTERNET','CompuServe',etc... 80 'email_home' => 'phpgwmailhome', 81 'email_home_type' => 'phpgwmailhometype' //'INTERNET','CompuServe',etc... 82 ); 83 84 // This will store the contacts object 85 var $contacts = ''; 86 87 // Read full list of user's contacts only to get id's for each 88 function export_start_file($buffer,$ncat_id='') 89 { 90 $this->id=-1; 91 if ($ncat_id) 92 { 93 $filter = 'tid=n,cat_id='.$ncat_id; 94 } 95 else 96 { 97 $filter = 'tid=n'; 98 } 99 $this->contacts = CreateObject('phpgwapi.contacts'); 100 101 $tmp = $this->contacts->read('','',array('id'=>'id'),'',$filter); 102 for ($i=0;$i<count($tmp);$i++) 103 { 104 $this->ids[$i] = $tmp[$i]['id']; 105 } 106 // $ids is now an array of all id's for this user, e.g. $ids[0] = 21, etc... 107 // $buffer is still empty 108 return $buffer; 109 } 110 111 // Read each entry 112 function export_start_record($buffer) 113 { 114 $this->id++; 115 $top = $this->contacts->read_single_entry($this->ids[$this->id],$this->qfields); 116 $this->currentrecord = $top[0]; 117 return $buffer; 118 } 119 120 // Read each attribute, populate buffer 121 // name/value are the fields from the export array above 122 function export_new_attrib($buffer,$name,$value) 123 { 124 if ($this->export[$name] && ($value != '') ) 125 { 126 $buffer[$this->id][$this->export[$name]] = $value; 127 //echo '<br>'.$this->id.' - '.$this->export[$name].': '.$buffer[$this->id][$this->export[$name]]; 128 } 129 return $buffer; 130 } 131 132 // Tack on some extra values 133 function export_end_record($buffer) 134 { 135 $context = 'ou=contacts,dc=domain,dc=com'; // some default to replace later 136 if ($GLOBALS['egw_info']['server']['ldap_contact_context']) 137 { 138 $context = $GLOBALS['egw_info']['server']['ldap_contact_context']; 139 } 140 $buffer[$this->id]['uid'] = time().':'.$this->id.($buffer[$this->id]['cn'] ? ':'.str_replace(',','',$buffer[$this->id]['cn']) : ''); 141 $buffer[$this->id]['dn'] = 'uid='.$buffer[$this->id]['uid'].','.$context; 142 $buffer[$this->id]['description'] = ereg_replace("\r\n",';',$buffer[$this->id]['description']); 143 //echo '<br>'.$this->id.' - '.$buffer[$this->id]['dn']; 144 return $buffer; 145 } 146 147 function export_end_file($buffer) 148 { 149 reset($this->ids); 150 for ($i=0;$i<count($this->ids);$i++) 151 { 152 $entries .= 'dn: '.$buffer[$i]['dn'] . "\n"; 153 reset($this->export); 154 while (list($name,$value)=each($this->export)) 155 { 156 if (($value != 'dn') && !empty($buffer[$i][$value])) 157 { 158 $tmp = str_replace(',','',$buffer[$i][$value]); 159 $entries .= $value . ': ' . $tmp . "\n"; 160 } 161 } 162 $entries .= 'objectClass: person' . "\n"; 163 $entries .= 'objectClass: organizationalPerson' . "\n"; 164 # not needed for openldap > 2.1 anymore 165 #$entries .= 'objectClass: inetOrgPerson' . "\n"; 166 $entries .= 'objectClass: phpgwContact' . "\n"; 167 $entries .= "\n"; 168 } 169 $buffer = $entries; 170 return $buffer; 171 } 172 } 173 ?>
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 |