[ 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('startDate','endDate'), 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 _egwcalendarsync_list($_startDate='', $_endDate='') 56 { 57 $guids = array(); 58 59 // until it's configurable we do 1 month back and ~2 years in the future 60 $startDate = (!empty($_startDate)?$_startDate:date('Ymd',time()-2678400)); 61 $endDate = (!empty($_endDate)?$_endDate:date('Ymd',time()+65000000)); 62 63 $searchFilter = array 64 ( 65 'start' => $startDate, 66 'end' => $endDate, 67 'filter' => 'all', 68 'daywise' => false, 69 'enum_recuring' => false, 70 ); 71 72 $events =& ExecMethod('calendar.bocal.search',$searchFilter); 73 74 foreach((array)$events as $event) 75 { 76 $guids[] = $GLOBALS['egw']->common->generate_uid('calendar',$event['id']); 77 } 78 return $guids; 79 } 80 81 /** 82 * Returns an array of GUIDs for notes that have had $action happen 83 * since $timestamp. 84 * 85 * @param string $action The action to check for - add, modify, or delete. 86 * @param integer $timestamp The time to start the search. 87 * 88 * @return array An array of GUIDs matching the action and time criteria. 89 */ 90 function &_egwcalendarsync_listBy($action, $timestamp) 91 { 92 Horde::logMessage("SymcML: egwcalendarsync listBy action: $action timestamp: $timestamp", __FILE__, __LINE__, PEAR_LOG_DEBUG); 93 94 $allChangedItems = $GLOBALS['egw']->contenthistory->getHistory('calendar', $action, $timestamp); 95 Horde::logMessage("SymcML: egwcalendarsync getHistory('calendar', $action, $timestamp)=".print_r($allChangedItems,true), __FILE__, __LINE__, PEAR_LOG_DEBUG); 96 97 if($action == 'delete') 98 { 99 return $allChangedItems; // we cant query the calendar for deleted events 100 } 101 // query the calendar, to check if we are a participants in these changed events 102 $boCalendar =& CreateObject('calendar.bocal'); 103 $user = (int) $GLOBALS['egw_info']['user']['account_id']; 104 $show_rejected = $GLOBALS['egw_info']['user']['preferences']['calendar']['show_rejected']; 105 106 // get the calendar id's for all these items 107 $ids = $guids = array(); 108 foreach($allChangedItems as $guid) 109 { 110 $ids[] = $GLOBALS['egw']->common->get_egwId($guid); 111 } 112 // read all events in one go, and check if the user participats 113 if (count($ids) && ($events =& $boCalendar->read($ids))) 114 { 115 foreach((array)$boCalendar->read($ids) as $event) 116 { 117 Horde::logMessage("SymcML: egwcalendarsync check participation for $event[id] / $event[title]", __FILE__, __LINE__, PEAR_LOG_DEBUG); 118 if (isset($event['participants'][$user]) && ($show_rejected || $event['participants'][$user] != 'R')) 119 { 120 $guids[] = $guid = $GLOBALS['egw']->common->generate_uid('calendar',$event['id']); 121 Horde::logMessage("SymcML: egwcalendarsync added id $event[id] ($guid) / $event[title]", __FILE__, __LINE__, PEAR_LOG_DEBUG); 122 } 123 } 124 } 125 return $guids; 126 } 127 128 /** 129 * Import a memo represented in the specified contentType. 130 * 131 * @param string $content The content of the memo. 132 * @param string $contentType What format is the data in? Currently supports: 133 * text/plain 134 * text/x-vnote 135 * @param string $notepad (optional) The notepad to save the memo on. 136 * 137 * @return string The new GUID, or false on failure. 138 */ 139 function _egwcalendarsync_import($content, $contentType, $notepad = null) 140 { 141 Horde::logMessage("SymcML: egwcalendarsync import content: $content contenttype: $contentType", __FILE__, __LINE__, PEAR_LOG_DEBUG); 142 143 $state = $_SESSION['SyncML.state']; 144 $deviceInfo = $state->getClientDeviceInfo(); 145 146 $boical =& CreateObject('calendar.boical'); 147 $boical->setSupportedFields($deviceInfo['manufacturer'],$deviceInfo['model']); 148 149 #$syncProfile = _egwcalendarsync_getSyncProfile(); 150 151 switch ($contentType) { 152 case 'text/x-vcalendar': 153 case 'text/calendar': 154 $calendarId = $boical->importVCal($content); 155 break; 156 157 default: 158 return PEAR::raiseError(_("Unsupported Content-Type.")); 159 } 160 161 if (is_a($calendarId, 'PEAR_Error')) { 162 return $calendarId; 163 } 164 165 $guid = $GLOBALS['egw']->common->generate_uid('calendar',$calendarId); 166 Horde::logMessage("SymcML: egwcalendarsync import imported: ".$guid, __FILE__, __LINE__, PEAR_LOG_DEBUG); 167 return $guid; 168 } 169 170 /** 171 * Import a memo represented in the specified contentType. 172 * 173 * @param string $content The content of the memo. 174 * @param string $contentType What format is the data in? Currently supports: 175 * text/plain 176 * text/x-vnote 177 * @param string $notepad (optional) The notepad to save the memo on. 178 * 179 * @return string The new GUID, or false on failure. 180 */ 181 function _egwcalendarsync_search($content, $contentType) 182 { 183 #error_log("SymcML: egwsifcalendarsync search content contentType: $contentType"); 184 #Horde::logMessage("SymcML: egwsifcalendarsync import content: $content contenttype: $contentType", __FILE__, __LINE__, PEAR_LOG_DEBUG); 185 Horde::logMessage("SymcML: egwcalendarsync search contenttype: $contentType", __FILE__, __LINE__, PEAR_LOG_DEBUG); 186 187 switch ($contentType) { 188 case 'text/x-vcalendar': 189 case 'text/calendar': 190 $boical =& CreateObject('calendar.boical'); 191 $eventId = $boical->search($content); 192 break; 193 194 default: 195 return PEAR::raiseError(_("Unsupported Content-Type.")); 196 } 197 198 if (is_a($eventId, 'PEAR_Error')) { 199 return $eventId; 200 } 201 202 if(!$eventId) { 203 return false; 204 } else { 205 $eventId = $GLOBALS['egw']->common->generate_uid('calendar', $eventId); 206 207 Horde::logMessage('SymcML: egwcalendarsync search found: '. $eventId, __FILE__, __LINE__, PEAR_LOG_DEBUG); 208 209 return $eventId; 210 } 211 } 212 213 /** 214 * Export a memo, identified by GUID, in the requested contentType. 215 * 216 * @param string $guid Identify the memo to export. 217 * @param mixed $contentType What format should the data be in? 218 * Either a string with one of: 219 * 'text/plain' 220 * 'text/x-vnote' 221 * or an array with options: 222 * 'ContentType': as above 223 * 'ENCODING': (optional) character encoding 224 * for strings fields 225 * 'CHARSET': (optional) charset. Like UTF-8 226 * 227 * @return string The requested data. 228 */ 229 function _egwcalendarsync_export($guid, $contentType) 230 { 231 232 # require_once dirname(__FILE__) . '/base.php'; 233 # 234 # $storage = &Mnemo_Driver::singleton(); 235 # $memo = $storage->getByGUID($guid); 236 # if (is_a($memo, 'PEAR_Error')) { 237 # return $memo; 238 # } 239 # 240 # if (!array_key_exists($memo['memolist_id'], Mnemo::listNotepads(false, PERMS_EDIT))) { 241 # return PEAR::raiseError(_("Permission Denied")); 242 # } 243 # 244 245 if (is_array($contentType)) { 246 $options = $contentType; 247 $contentType = $options['ContentType']; 248 unset($options['ContentType']); 249 } else { 250 $options = array(); 251 } 252 253 Horde::logMessage("SymcML: egwcalendarsync export guid: $guid contenttype: ".$contentType, __FILE__, __LINE__, PEAR_LOG_DEBUG); 254 255 $state = $_SESSION['SyncML.state']; 256 $deviceInfo = $state->getClientDeviceInfo(); 257 258 $boical =& CreateObject('calendar.boical'); 259 $boical->setSupportedFields($deviceInfo['manufacturer'],$deviceInfo['model']); 260 261 $eventID = $GLOBALS['egw']->common->get_egwId($guid); 262 263 switch ($contentType) { 264 case 'text/x-vcalendar': 265 return $boical->exportVCal($eventID,'1.0'); 266 267 break; 268 case 'text/calendar': 269 return $boical->exportVCal($eventID,'2.0'); 270 271 break; 272 default: 273 return PEAR::raiseError(_("Unsupported Content-Type.")); 274 } 275 } 276 277 /** 278 * Delete a memo identified by GUID. 279 * 280 * @param string | array $guid Identify the note to delete, either a 281 * single GUID or an array. 282 * 283 * @return boolean Success or failure. 284 */ 285 function _egwcalendarsync_delete($guid) 286 { 287 // Handle an arrray of GUIDs for convenience of deleting multiple 288 // contacts at once. 289 if (is_array($guid)) { 290 foreach ($guid as $g) { 291 $result = _egwcalendarsync_delete($g); 292 if (is_a($result, 'PEAR_Error')) { 293 return $result; 294 } 295 } 296 297 return true; 298 } 299 300 #if (!array_key_exists($memo['memolist_id'], Mnemo::listNotepads(false, PERMS_DELETE))) { 301 # return PEAR::raiseError(_("Permission Denied")); 302 #} 303 Horde::logMessage("SymcML: egwcalendarsync delete id: ".$GLOBALS['egw']->common->get_egwId($guid), __FILE__, __LINE__, PEAR_LOG_DEBUG); 304 305 $bocalendar =& CreateObject('calendar.bocalupdate'); 306 307 return $bocalendar->delete($GLOBALS['egw']->common->get_egwId($guid)); 308 309 #return $bocalendar->expunge(); 310 } 311 312 /** 313 * Replace the memo identified by GUID with the content represented in 314 * the specified contentType. 315 * 316 * @param string $guid Idenfity the memo to replace. 317 * @param string $content The content of the memo. 318 * @param string $contentType What format is the data in? Currently supports: 319 * text/plain 320 * text/x-vnote 321 * 322 * @return boolean Success or failure. 323 */ 324 function _egwcalendarsync_replace($guid, $content, $contentType) 325 { 326 Horde::logMessage("SymcML: egwcalendarsync replace guid: $guid content: $content contenttype: $contentType", __FILE__, __LINE__, PEAR_LOG_DEBUG); 327 $state = $_SESSION['SyncML.state']; 328 $deviceInfo = $state->getClientDeviceInfo(); 329 330 $boical =& CreateObject('calendar.boical'); 331 $boical->setSupportedFields($deviceInfo['manufacturer'],$deviceInfo['model']); 332 333 $eventID = $GLOBALS['egw']->common->get_egwId($guid); 334 335 switch ($contentType) { 336 case 'text/x-vcalendar': 337 case 'text/calendar': 338 return $boical->importVCal($content, $eventID); 339 break; 340 341 default: 342 return PEAR::raiseError(_("Unsupported Content-Type.")); 343 } 344 345 }
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 |