[ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 <?php 2 /**************************************************************************\ 3 * eGroupWare - iCalendar Parser * 4 * http://www.egroupware.org * 5 * Written by Lars Kneschke <lkneschke@egroupware.org> * 6 * -------------------------------------------- * 7 * This program is free software; you can redistribute it and/or modify it * 8 * under the terms of the GNU General Public License as published by the * 9 * Free Software Foundation; either version 2 of the License. * 10 \**************************************************************************/ 11 12 /* $Id: class.sifaddressbook.inc.php 21678 2006-06-01 13:23:47Z lkneschke $ */ 13 14 require_once EGW_SERVER_ROOT.'/addressbook/inc/class.boaddressbook.inc.php'; 15 #require_once EGW_SERVER_ROOT.'/phpgwapi/inc/horde/Horde/iCalendar.php'; 16 17 class sifaddressbook extends boaddressbook 18 { 19 var $sifMapping = array( 20 'Anniversary' => '', 21 'AssistantName' => '', 22 'AssistantTelephoneNumber' => '', 23 'BillingInformation' => '', 24 'Birthday' => 'bday', 25 'Body' => 'note', 26 'Business2TelephoneNumber' => '', 27 'BusinessAddressCity' => 'adr_one_locality', 28 'BusinessAddressCountry' => 'adr_one_countryname', 29 'BusinessAddressPostalCode' => 'adr_one_postalcode', 30 'BusinessAddressPostOfficeBox' => '', 31 'BusinessAddressState' => 'adr_one_region', 32 'BusinessAddressStreet' => 'adr_one_street', 33 'BusinessFaxNumber' => 'tel_fax', 34 'BusinessTelephoneNumber' => 'tel_work', 35 'CallbackTelephoneNumber' => '', 36 'CarTelephoneNumber' => '', 37 'Categories' => 'cat_id', 38 'Children' => '', 39 'Companies' => '', 40 'CompanyMainTelephoneNumber' => '', 41 'CompanyName' => 'org_name', 42 'ComputerNetworkName' => '', 43 'Department' => 'org_unit', 44 'Email1Address' => 'email', 45 'Email1AddressType' => '', 46 'Email2Address' => 'email_home', 47 'Email2AddressType' => '', 48 'Email3Address' => '', 49 'Email3AddressType' => '', 50 'FileAs' => 'fn', 51 'FirstName' => 'n_given', 52 'Hobby' => '', 53 'Home2TelephoneNumber' => '', 54 'HomeAddressCity' => 'adr_two_locality', 55 'HomeAddressCountry' => 'adr_two_countryname', 56 'HomeAddressPostalCode' => 'adr_two_postalcode', 57 'HomeAddressPostOfficeBox' => '', 58 'HomeAddressState' => 'adr_two_region', 59 'HomeAddressStreet' => 'adr_two_street', 60 'HomeFaxNumber' => '', 61 'HomeTelephoneNumber' => 'tel_home', 62 'Importance' => '', 63 'Initials' => '', 64 'JobTitle' => 'title', 65 'Language' => '', 66 'LastName' => 'n_family', 67 'ManagerName' => '', 68 'MiddleName' => 'n_middle', 69 'Mileage' => '', 70 'MobileTelephoneNumber' => 'tel_cell', 71 'NickName' => '', 72 'OfficeLocation' => '', 73 'OrganizationalIDNumber' => '', 74 'OtherAddressCity' => '', 75 'OtherAddressCountry' => '', 76 'OtherAddressPostalCode' => '', 77 'OtherAddressPostOfficeBox' => '', 78 'OtherAddressState' => '', 79 'OtherAddressStreet' => '', 80 'OtherFaxNumber' => '', 81 'OtherTelephoneNumber' => '', 82 'PagerNumber' => 'tel_pager', 83 'PrimaryTelephoneNumber' => '', 84 'Profession' => '', 85 'RadioTelephoneNumber' => '', 86 'Sensitivity' => 'access', 87 'Spouse' => '', 88 'Subject' => '', 89 'Suffix' => 'n_suffix', 90 'TelexNumber' => '', 91 'Title' => 'n_prefix', 92 'WebPage' => 'url', 93 'YomiCompanyName' => '', 94 'YomiFirstName' => '', 95 'YomiLastName' => '', 96 'HomeWebPage' => '', 97 'Folder' => '', 98 ); 99 100 function startElement($_parser, $_tag, $_attributes) { 101 } 102 103 function endElement($_parser, $_tag) { 104 if(!empty($this->sifMapping[$_tag])) { 105 $this->contact[$this->sifMapping[$_tag]] = $this->sifData; 106 } 107 unset($this->sifData); 108 } 109 110 function characterData($_parser, $_data) { 111 $this->sifData .= $_data; 112 } 113 114 function siftoegw($_sifdata) { 115 $sysCharSet = $GLOBALS['egw']->translation->charset(); 116 $sifData = base64_decode($_sifdata); 117 118 #$tmpfname = tempnam('/tmp/sync/contents','sifc_'); 119 120 #$handle = fopen($tmpfname, "w"); 121 #fwrite($handle, $sifdata); 122 #fclose($handle); 123 124 $this->xml_parser = xml_parser_create('UTF-8'); 125 xml_set_object($this->xml_parser, $this); 126 xml_parser_set_option($this->xml_parser, XML_OPTION_CASE_FOLDING, false); 127 xml_set_element_handler($this->xml_parser, "startElement", "endElement"); 128 xml_set_character_data_handler($this->xml_parser, "characterData"); 129 $this->strXmlData = xml_parse($this->xml_parser, $sifData); 130 if(!$this->strXmlData) { 131 error_log(sprintf("XML error: %s at line %d", 132 xml_error_string(xml_get_error_code($this->xml_parser)), 133 xml_get_current_line_number($this->xml_parser))); 134 return false; 135 } 136 137 foreach($this->contact as $key => $value) { 138 $value = $GLOBALS['egw']->translation->convert($value, 'utf-8', $sysCharSet); 139 switch($key) { 140 case 'access': 141 $finalContact[$key] = ((int)$value > 0) ? 'private' : 'public'; 142 break; 143 144 case 'cat_id': 145 if(!empty($value)) { 146 $isAdmin = $GLOBALS['egw']->acl->check('run',1,'admin'); 147 $egwCategories =& CreateObject('phpgwapi.categories',$GLOBALS['egw_info']['user']['account_id'],'addressbook'); 148 $categories = explode('; ',$value); 149 $cat_id = ''; 150 foreach($categories as $categorieName) { 151 $categorieName = trim($categorieName); 152 if(!($cat_id = $egwCategories->name2id($categorieName)) && $isAdmin) { 153 $cat_id = $egwCategories->add(array('name' => $categorieName, 'descr' => $categorieName)); 154 } 155 if($cat_id) { 156 if(!empty($finalContact[$key])) $finalContact[$key] .= ','; 157 $finalContact[$key] .= $cat_id; 158 } 159 } 160 } 161 break; 162 163 case 'bday': 164 if(!empty($value)) { 165 $bdayParts = explode('-',$value); 166 $finalContact[$key] = $bdayParts[1]. '/' .$bdayParts[2]. '/' .$bdayParts[0]; 167 } 168 break; 169 170 default: 171 $finalContact[$key] = $value; 172 break; 173 } 174 } 175 176 $middleName = ($finalContact['n_middle']) ? ' '.trim($finalContact['n_middle']) : ''; 177 $finalContact['fn'] = trim($finalContact['n_given']. $middleName .' '. $finalContact['n_family']); 178 179 180 return $finalContact; 181 } 182 183 function search($_sifdata) { 184 if(!$contact = $this->siftoegw($_sifdata)) { 185 return false; 186 } 187 unset($contact['note']); 188 189 if($foundContacts = $this->read_entries(array('query' => $contact))) { 190 #error_log(print_r($foundContacts,true)); 191 return $foundContacts[0][id]; 192 } 193 194 return false; 195 } 196 197 /** 198 * @return int contact id 199 * @param string $_vcard the vcard 200 * @param int $_abID the internal addressbook id 201 * @desc import a vard into addressbook 202 */ 203 function addSIF($_sifdata, $_abID) 204 { 205 #error_log('ABID: '.$_abID); 206 #error_log(base64_decode($_sifdata)); 207 208 if(!$contact = $this->siftoegw($_sifdata)) { 209 return false; 210 } 211 212 if($_abID > 0) 213 { 214 // update entry 215 $contact['ab_id'] = $_abID; 216 return $this->update_entry($contact); 217 } 218 else 219 { 220 // add entry 221 return $this->add_entry($contact); 222 } 223 } 224 225 /** 226 * return a vcard 227 * 228 * @param int $_id the id of the contact 229 * @param int $_vcardProfile profile id for mapping from vcard values to egw addressbook 230 * @return string containing the vcard 231 */ 232 function getSIF($_id) 233 { 234 $fields = array_unique(array_values($this->sifMapping)); 235 sort($fields); 236 237 if($this->check_perms($_id,EGW_ACL_READ)) 238 { 239 $sifContact = '<contact>'; 240 //$data = array('id' => $_id, 'fields' => $fields); 241 $entry = $this->so->read_entry($_id,$fields); 242 $entry = $this->strip_html($entry); 243 if($this->xmlrpc) 244 { 245 $entry = $this->data2xmlrpc($entry); 246 } 247 #error_log(print_r($entry,true)); 248 $sysCharSet = $GLOBALS['egw']->translation->charset(); 249 250 foreach($this->sifMapping as $sifField => $egwField) 251 { 252 if(empty($egwField)) continue; 253 254 #error_log("$sifField => $egwField"); 255 #error_log('VALUE1: '.$entry[0][$egwField]); 256 $value = $GLOBALS['egw']->translation->convert($entry[0][$egwField], $sysCharSet, 'utf-8'); 257 #error_log('VALUE2: '.$value); 258 259 switch($sifField) 260 { 261 // TODO handle multiple categories 262 case 'Categories': 263 if(!empty($value)) { 264 $egwCategories =& CreateObject('phpgwapi.categories',$GLOBALS['egw_info']['user']['account_id'],'addressbook'); 265 $categories = explode(',',$value); 266 $value = ''; 267 foreach($categories as $cat_id) { 268 if($catData = $egwCategories->return_single($cat_id)) { 269 if(!empty($value)) $value .= '; '; 270 $value .= $catData[0]['name']; 271 } 272 } 273 } 274 $sifContact .= "<$sifField>$value</$sifField>"; 275 break; 276 277 case 'Sensitivity': 278 $value = ($value == 'private' ? '2' : '0'); 279 $sifContact .= "<$sifField>$value</$sifField>"; 280 break; 281 282 case 'Birthday': 283 if(!empty($value)) { 284 $dateParts = explode('/',$value); 285 $value = sprintf('%04-d%02-d%02',$dateParts[2],$dateParts[0],$dateParts[1]); 286 } 287 $sifContact .= "<$sifField>$value</$sifField>"; 288 break; 289 290 case 'Folder': 291 # skip currently. This is the folder where Outlook stores the contact. 292 #$sifContact .= "<$sifField>/</$sifField>"; 293 break; 294 295 default: 296 $sifContact .= "<$sifField>$value</$sifField>"; 297 break; 298 } 299 } 300 $sifContact .= "</contact>"; 301 302 return base64_encode($sifContact); 303 } 304 305 if($this->xmlrpc) 306 { 307 $GLOBALS['server']->xmlrpc_error($GLOBALS['xmlrpcerr']['no_access'],$GLOBALS['xmlrpcstr']['no_access']); 308 } 309 return False; 310 } 311 312 }
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 |