[ 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 _egwsifcalendarsync_list() 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 &_egwsifcalendarsync_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 _egwsifcalendarsync_import($content, $contentType, $notepad = null) 140 { 141 #error_log("SymcML: egwsifcalendarsync import content: ".base64_decode($ccontent)." contentType: $contentType"); 142 Horde::logMessage("SymcML: egwsifcalendarsync import content: $content contenttype: $contentType", __FILE__, __LINE__, PEAR_LOG_DEBUG); 143 144 switch ($contentType) { 145 case 'text/x-s4j-sife': 146 $sifcalendar =& CreateObject('calendar.sifcalendar'); 147 $eventId = $sifcalendar->addSIF($content,-1); 148 break; 149 150 default: 151 return PEAR::raiseError(_("Unsupported Content-Type.")); 152 } 153 154 if (is_a($eventId, 'PEAR_Error')) { 155 return $eventId; 156 } 157 158 #Horde::logMessage("SymcML: egwsifcalendarsync import imported: ".$GLOBALS['phpgw']->common->generate_uid('contacts',$contactId), __FILE__, __LINE__, PEAR_LOG_DEBUG); 159 return $GLOBALS['egw']->common->generate_uid('calendar',$eventId); 160 } 161 162 /** 163 * Import a memo represented in the specified contentType. 164 * 165 * @param string $content The content of the memo. 166 * @param string $contentType What format is the data in? Currently supports: 167 * text/plain 168 * text/x-vnote 169 * @param string $notepad (optional) The notepad to save the memo on. 170 * 171 * @return string The new GUID, or false on failure. 172 */ 173 function _egwsifcalendarsync_search($content, $contentType) 174 { 175 #error_log("SymcML: egwsifcalendarsync search content contentType: $contentType"); 176 #Horde::logMessage("SymcML: egwsifcalendarsync import content: $content contenttype: $contentType", __FILE__, __LINE__, PEAR_LOG_DEBUG); 177 Horde::logMessage("SymcML: egwsifcalendarsync import contenttype: $contentType", __FILE__, __LINE__, PEAR_LOG_DEBUG); 178 179 switch ($contentType) { 180 case 'text/x-s4j-sife': 181 $sifcalendar =& CreateObject('calendar.sifcalendar'); 182 $eventId = $sifcalendar->search($content); 183 break; 184 185 default: 186 return PEAR::raiseError(_("Unsupported Content-Type.")); 187 } 188 189 if (is_a($eventId, 'PEAR_Error')) { 190 return $eventId; 191 } 192 193 if(!$eventId) { 194 return false; 195 } else { 196 $eventId = $GLOBALS['egw']->common->generate_uid('calendar', $eventId); 197 198 Horde::logMessage('SymcML: egwsifcalendarsync search found: '. $eventId, __FILE__, __LINE__, PEAR_LOG_DEBUG); 199 200 return $eventId; 201 } 202 } 203 204 /** 205 * Export a memo, identified by GUID, in the requested contentType. 206 * 207 * @param string $guid Identify the memo to export. 208 * @param mixed $contentType What format should the data be in? 209 * Either a string with one of: 210 * 'text/plain' 211 * 'text/x-vnote' 212 * or an array with options: 213 * 'ContentType': as above 214 * 'ENCODING': (optional) character encoding 215 * for strings fields 216 * 'CHARSET': (optional) charset. Like UTF-8 217 * 218 * @return string The requested data. 219 */ 220 function _egwsifcalendarsync_export($guid, $contentType) 221 { 222 #Horde::logMessage("-- SymcML: egwsifcalendarsync export guid: $guid contenttype: $contentType", __FILE__, __LINE__, PEAR_LOG_DEBUG); 223 if (is_array($contentType)) { 224 $options = $contentType; 225 $contentType = $options['ContentType']; 226 unset($options['ContentType']); 227 } else { 228 $options = array(); 229 } 230 231 $eventId = $GLOBALS['egw']->common->get_egwId($guid); 232 233 switch ($contentType) { 234 case 'text/x-s4j-sife': 235 $sifcalendar =& CreateObject('calendar.sifcalendar'); 236 if($sifevent = $sifcalendar->getSIF($eventId)) 237 { 238 return $sifevent; 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 _egwsifcalendarsync_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 = _egwsifcalendarsync_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 $bocalendar =& CreateObject('calendar.bocalupdate'); 281 282 return $bocalendar->delete($GLOBALS['egw']->common->get_egwId($guid)); 283 } 284 285 /** 286 * Replace the memo identified by GUID with the content represented in 287 * the specified contentType. 288 * 289 * @param string $guid Idenfity the memo to replace. 290 * @param string $content The content of the memo. 291 * @param string $contentType What format is the data in? Currently supports: 292 * text/plain 293 * text/x-vnote 294 * 295 * @return boolean Success or failure. 296 */ 297 function _egwsifcalendarsync_replace($guid, $content, $contentType) 298 { 299 #Horde::logMessage("SymcML: egwsifcalendarsync replace guid: $guid content: $content", __FILE__, __LINE__, PEAR_LOG_DEBUG); 300 #error_log("SymcML: egwsifcalendarsync replace guid: $guid content: $ccontent contentType: $contentType"); 301 #if (!array_key_exists($memo['memolist_id'], Mnemo::listNotepads(false, PERMS_EDIT))) { 302 # return PEAR::raiseError(_("Permission Denied")); 303 #} 304 305 $eventId = $GLOBALS['egw']->common->get_egwId($guid); 306 307 switch ($contentType) { 308 case 'text/x-s4j-sife': 309 $sifcalendar =& CreateObject('calendar.sifcalendar'); 310 $eventId = $sifcalendar->addSIF($content,$eventId); 311 312 return $eventId; 313 314 break; 315 316 default: 317 return PEAR::raiseError(_("Unsupported Content-Type.")); 318 } 319 } 320
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 |