| [ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 <?php 2 /** 3 * Mnemo external API interface. 4 * 5 * $Horde: mnemo/lib/api.php,v 1.52 2004/09/14 04:27:07 chuck Exp $ 6 * 7 * This file defines Mnemo's external API interface. Other 8 * applications can interact with Mnemo through this API. 9 * 10 * @package Mnemo 11 */ 12 13 $_services['list'] = array( 14 'args' => array(), 15 'type' => 'stringArray' 16 ); 17 18 $_services['listBy'] = array( 19 'args' => array('action', 'timestamp'), 20 'type' => 'stringArray' 21 ); 22 23 $_services['import'] = array( 24 'args' => array('content', 'contentType'), 25 'type' => 'integer' 26 ); 27 28 $_services['search'] = array( 29 'args' => array('content', 'contentType'), 30 'type' => 'integer' 31 ); 32 33 $_services['export'] = array( 34 'args' => array('guid', 'contentType'), 35 'type' => 'string' 36 ); 37 38 $_services['delete'] = array( 39 'args' => array('guid'), 40 'type' => 'boolean' 41 ); 42 43 $_services['replace'] = array( 44 'args' => array('guid', 'content', 'contentType'), 45 'type' => 'boolean' 46 ); 47 48 49 /** 50 * Returns an array of GUIDs for all notes that the current user is 51 * authorized to see. 52 * 53 * @return array An array of GUIDs for all notes the user can access. 54 */ 55 function _egwsifcontactssync_list() 56 { 57 $guids = array(); 58 59 #Horde::logMessage("SymcML: egwsifcontactssync list ", __FILE__, __LINE__, PEAR_LOG_DEBUG); 60 61 $allContacts = ExecMethod('addressbook.vcaladdressbook.read_entries',array()); 62 63 #Horde::logMessage("SymcML: egwsifcontactssync list ", __FILE__, __LINE__, PEAR_LOG_DEBUG); 64 65 foreach((array)$allContacts as $contact) 66 { 67 $guids[] = $GLOBALS['phpgw']->common->generate_uid('contacts',$contact['id']); 68 } 69 70 return $guids; 71 } 72 73 /** 74 * Returns an array of GUIDs for notes that have had $action happen 75 * since $timestamp. 76 * 77 * @param string $action The action to check for - add, modify, or delete. 78 * @param integer $timestamp The time to start the search. 79 * 80 * @return array An array of GUIDs matching the action and time criteria. 81 */ 82 function &_egwsifcontactssync_listBy($action, $timestamp) 83 { 84 // todo 85 // check for acl 86 87 #Horde::logMessage("SymcML: egwsifcontactssync listBy action: $action timestamp: $timestamp", __FILE__, __LINE__, PEAR_LOG_DEBUG); 88 89 $allChangedItems = $GLOBALS['phpgw']->contenthistory->getHistory('contacts', $action, $timestamp); 90 91 if($action != 'delete') 92 { 93 $boAddressBook = CreateObject('addressbook.boaddressbook'); 94 $readAbleItems = array(); 95 96 // check if we have access to the changed data 97 // need to get improved in the future 98 foreach($allChangedItems as $guid) 99 { 100 $uid = $GLOBALS['phpgw']->common->get_egwId($guid); 101 if($boAddressBook->check_perms($uid, PHPGW_ACL_READ)) 102 { 103 $readAbleItems[] = $guid; 104 } 105 } 106 107 return $readAbleItems; 108 } 109 110 return $allChangedItems; 111 } 112 113 /** 114 * Import a memo represented in the specified contentType. 115 * 116 * @param string $content The content of the memo. 117 * @param string $contentType What format is the data in? Currently supports: 118 * text/plain 119 * text/x-vnote 120 * @param string $notepad (optional) The notepad to save the memo on. 121 * 122 * @return string The new GUID, or false on failure. 123 */ 124 function _egwsifcontactssync_import($content, $contentType, $notepad = null) 125 { 126 #error_log("SymcML: egwsifcontactssync import content: ".base64_decode($ccontent)." contentType: $contentType"); 127 #Horde::logMessage("SymcML: egwsifcontactssync import content: $content contenttype: $contentType", __FILE__, __LINE__, PEAR_LOG_DEBUG); 128 129 $state = $_SESSION['SyncML.state']; 130 $deviceInfo = $state->getClientDeviceInfo(); 131 132 133 switch ($contentType) { 134 case 'text/x-vcard': 135 $vcaladdressbook =& CreateObject('addressbook.vcaladdressbook',true); 136 $vcaladdressbook->setSupportedFields($deviceInfo['manufacturer'],$deviceInfo['model']); 137 138 $contactId = $vcaladdressbook->addVCard($content,-1); 139 break; 140 141 case 'text/x-s4j-sifc': 142 $sifaddressbook =& CreateObject('addressbook.sifaddressbook'); 143 $contactId = $sifaddressbook->addSIF($content,-1); 144 break; 145 146 default: 147 return PEAR::raiseError(_("Unsupported Content-Type.")); 148 } 149 150 if (is_a($contactId, 'PEAR_Error')) { 151 return $contactId; 152 } 153 154 #Horde::logMessage("SymcML: egwsifcontactssync import imported: ".$GLOBALS['phpgw']->common->generate_uid('contacts',$contactId), __FILE__, __LINE__, PEAR_LOG_DEBUG); 155 return $GLOBALS['phpgw']->common->generate_uid('contacts',$contactId); 156 } 157 158 /** 159 * Import a memo represented in the specified contentType. 160 * 161 * @param string $content The content of the memo. 162 * @param string $contentType What format is the data in? Currently supports: 163 * text/plain 164 * text/x-vnote 165 * @param string $notepad (optional) The notepad to save the memo on. 166 * 167 * @return string The new GUID, or false on failure. 168 */ 169 function _egwsifcontactssync_search($content, $contentType) 170 { 171 #error_log("SymcML: egwsifcontactssync search content contentType: $contentType"); 172 #Horde::logMessage("SymcML: egwsifcontactssync import content: $content contenttype: $contentType", __FILE__, __LINE__, PEAR_LOG_DEBUG); 173 174 $state = $_SESSION['SyncML.state']; 175 $deviceInfo = $state->getClientDeviceInfo(); 176 177 178 switch ($contentType) { 179 case 'text/x-s4j-sifc': 180 $sifaddressbook =& CreateObject('addressbook.sifaddressbook'); 181 $contactId = $sifaddressbook->search($content); 182 break; 183 184 default: 185 return PEAR::raiseError(_("Unsupported Content-Type.")); 186 } 187 188 if (is_a($contactId, 'PEAR_Error')) { 189 return $contactId; 190 } 191 192 #error_log("SymcML: egwsifcontactssync search found: $contactId"); 193 #Horde::logMessage("SymcML: egwsifcontactssync import imported: ".$GLOBALS['phpgw']->common->generate_uid('contacts',$contactId), __FILE__, __LINE__, PEAR_LOG_DEBUG); 194 if(!$contactId) { 195 return false; 196 } else { 197 return $GLOBALS['phpgw']->common->generate_uid('contacts',$contactId); 198 } 199 } 200 201 /** 202 * Export a memo, identified by GUID, in the requested contentType. 203 * 204 * @param string $guid Identify the memo to export. 205 * @param mixed $contentType What format should the data be in? 206 * Either a string with one of: 207 * 'text/plain' 208 * 'text/x-vnote' 209 * or an array with options: 210 * 'ContentType': as above 211 * 'ENCODING': (optional) character encoding 212 * for strings fields 213 * 'CHARSET': (optional) charset. Like UTF-8 214 * 215 * @return string The requested data. 216 */ 217 function _egwsifcontactssync_export($guid, $contentType) 218 { 219 #Horde::logMessage("-- SymcML: egwsifcontactssync export guid: $guid contenttype: $contentType", __FILE__, __LINE__, PEAR_LOG_DEBUG); 220 if (is_array($contentType)) { 221 $options = $contentType; 222 $contentType = $options['ContentType']; 223 unset($options['ContentType']); 224 } else { 225 $options = array(); 226 } 227 228 $state = $_SESSION['SyncML.state']; 229 $deviceInfo = $state->getClientDeviceInfo(); 230 231 $sifaddressbook =& CreateObject('addressbook.sifaddressbook'); 232 $contactID = $GLOBALS['phpgw']->common->get_egwId($guid); 233 234 switch ($contentType) { 235 case 'text/x-s4j-sifc': 236 if($sifcard = $sifaddressbook->getSIF($contactID)) 237 { 238 return $sifcard; 239 } 240 else 241 { 242 return PEAR::raiseError(_("Access Denied")); 243 } 244 245 break; 246 247 default: 248 #Horde::logMessage("SymcML: export unsupported", __FILE__, __LINE__, PEAR_LOG_DEBUG); 249 return PEAR::raiseError(_("Unsupported Content-Type.")); 250 } 251 } 252 253 /** 254 * Delete a memo identified by GUID. 255 * 256 * @param string | array $guid Identify the note to delete, either a 257 * single GUID or an array. 258 * 259 * @return boolean Success or failure. 260 */ 261 function _egwsifcontactssync_delete($guid) 262 { 263 // Handle an arrray of GUIDs for convenience of deleting multiple 264 // contacts at once. 265 if (is_array($guid)) { 266 foreach ($guid as $g) { 267 $result = _egwsifcontactssync_delete($g); 268 if (is_a($result, 'PEAR_Error')) { 269 return $result; 270 } 271 } 272 273 return true; 274 } 275 276 #if (!array_key_exists($memo['memolist_id'], Mnemo::listNotepads(false, PERMS_DELETE))) { 277 # return PEAR::raiseError(_("Permission Denied")); 278 #} 279 280 return ExecMethod('addressbook.boaddressbook.delete_entry',$GLOBALS['egw']->common->get_egwId($guid)); 281 } 282 283 /** 284 * Replace the memo identified by GUID with the content represented in 285 * the specified contentType. 286 * 287 * @param string $guid Idenfity the memo to replace. 288 * @param string $content The content of the memo. 289 * @param string $contentType What format is the data in? Currently supports: 290 * text/plain 291 * text/x-vnote 292 * 293 * @return boolean Success or failure. 294 */ 295 function _egwsifcontactssync_replace($guid, $content, $contentType) 296 { 297 #Horde::logMessage("SymcML: egwsifcontactssync replace guid: $guid content: $content", __FILE__, __LINE__, PEAR_LOG_DEBUG); 298 #error_log("SymcML: egwsifcontactssync replace guid: $guid content: $ccontent contentType: $contentType"); 299 #if (!array_key_exists($memo['memolist_id'], Mnemo::listNotepads(false, PERMS_EDIT))) { 300 # return PEAR::raiseError(_("Permission Denied")); 301 #} 302 303 $state = $_SESSION['SyncML.state']; 304 $deviceInfo = $state->getClientDeviceInfo(); 305 306 $contactID = $GLOBALS['phpgw']->common->get_egwId($guid); 307 308 switch ($contentType) { 309 case 'text/x-vcard': 310 $vcaladdressbook =& CreateObject('addressbook.vcaladdressbook',True); 311 $vcaladdressbook->setSupportedFields($deviceInfo['manufacturer'],$deviceInfo['model']); 312 $result = $vcaladdressbook->addVCard($content,$contactID); 313 314 return $result; 315 316 break; 317 318 case 'text/x-s4j-sifc': 319 #$tmpfname = tempnam('/tmp/sync/contents','sifcontact_'); 320 #$handle = fopen($tmpfname, "w"); 321 #fwrite($handle, base64_decode($content)); 322 #fclose($handle); 323 324 $sifaddressbook =& CreateObject('addressbook.sifaddressbook'); 325 $result = $sifaddressbook->addSIF($content,$contactID); 326 327 #error_log("SymcML: egwsifcontactssync replace result: $result"); 328 329 return $result; 330 331 break; 332 333 default: 334 return PEAR::raiseError(_("Unsupported Content-Type.")); 335 } 336 } 337
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 |