[ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 <?php 2 /**************************************************************************\ 3 * eGroupWare - XMLRPC or SOAP access to the Calendar * 4 * http://www.egroupware.org * 5 * Written and (c) 2005 by Ralf Becker <RalfBecker@outdoor-training.de> * 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, or (at your * 10 * option) any later version. * 11 \**************************************************************************/ 12 13 /* $Id: class.bocalendar.inc.php 20358 2006-03-02 16:44:58Z ralfbecker $ */ 14 15 require_once (EGW_INCLUDE_ROOT.'/calendar/inc/class.bocalupdate.inc.php'); 16 17 /** 18 * Class to access AND manipulate calendar data via XMLRPC or SOAP 19 * 20 * eGW's xmlrpc interface is documented at http://egroupware.org/wiki/xmlrpc 21 * 22 * @package calendar 23 * @author Ralf Becker <RalfBecker-AT-outdoor-training.de> 24 * @copyright (c) 2005 by RalfBecker-At-outdoor-training.de 25 * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License 26 * @link http://egroupware.org/wiki/xmlrpc 27 */ 28 29 class bocalendar 30 { 31 var $xmlrpc_date_format = 'Y-m-d\\TH:i:s'; 32 var $debug = false; // log function call to the apache error_log 33 var $cal; 34 var $public_functions = Array( 35 'read' => True, 36 'delete' => True, 37 'write' => True, 38 'search' => True, 39 'categories'=> True, 40 'list_methods' => True, 41 ); 42 43 function bocalendar() 44 { 45 $this->cal =& new bocalupdate(); 46 47 if (is_object($GLOBALS['server']) && $GLOBALS['server']->simpledate) 48 { 49 $this->xmlrpc_date_format = 'Ymd\\TH:i:s'; 50 } 51 } 52 53 /** 54 * This handles introspection or discovery by the logged in client, 55 * in which case the input might be an array. The server always calls 56 * this function to fill the server dispatch map using a string. 57 * 58 * @param string/array $_type string or array with key 'type' for type of interface: xmlrpc or soap 59 * @return array 60 */ 61 function list_methods($_type='xmlrpc') 62 { 63 switch(is_array($_type) ? ($_type['type'] ? $_type['type'] : $_type[0]) : $_type) 64 { 65 case 'xmlrpc': 66 return array( 67 'list_methods' => array( 68 'function' => 'list_methods', 69 'signature' => array(array(xmlrpcStruct,xmlrpcString)), 70 'docstring' => 'Read this list of methods.' 71 ), 72 'read' => array( 73 'function' => 'read', 74 'signature' => array(array(xmlrpcStruct,xmlrpcInt)), 75 'docstring' => 'Read a single entry by passing the id or uid.' 76 ), 77 'write' => array( 78 'function' => 'write', 79 'signature' => array(array(xmlrpcStruct,xmlrpcStruct)), 80 'docstring' => 'Add or update a single entry by passing the fields.' 81 ), 82 'delete' => array( 83 'function' => 'delete', 84 'signature' => array(array(xmlrpcInt,xmlrpcInt)), 85 'docstring' => 'Delete a single entry by passing the id.' 86 ), 87 'search' => array( 88 'function' => 'search', 89 'signature' => array(array(xmlrpcStruct,xmlrpcStruct)), 90 'docstring' => 'Read a list of entries.' 91 ), 92 'categories' => array( 93 'function' => 'categories', 94 'signature' => array(array(xmlrpcStruct,xmlrpcStruct)), 95 'docstring' => 'List all categories.' 96 ), 97 ); 98 99 case 'soap': 100 return Array( 101 'read' => Array( 102 'in' => Array('int'), 103 'out' => Array('SOAPStruct') 104 ), 105 'delete' => Array( 106 'in' => Array('int'), 107 'out' => Array('int') 108 ), 109 'write' => Array( 110 'in' => Array('array'), 111 'out' => Array('array') 112 ), 113 'search' => Array( 114 'in' => Array('struct'), 115 'out' => Array('SOAPStruct') 116 ), 117 'categories' => array( 118 'in' => array('bool'), 119 'out' => array('array') 120 ), 121 ); 122 } 123 return array(); 124 } 125 126 /** 127 * Read a single entry 128 * 129 * @param int/array $id 130 * @return array with event(s) or XMLRPC error not_existent or no_access 131 */ 132 function read($id) 133 { 134 if ($this->debug) error_log('bocalendar::read('.print_r($id,true).')'); 135 136 $events =& $this->cal->read($id,null,true,$this->xmlrpc_date_format); // true = ignore acl!!! 137 138 if (!$events) // only id not found, as ignore_acl=true 139 { 140 // xmlrpc_error does NOT return 141 $GLOBALS['server']->xmlrpc_error($GLOBALS['xmlrpcerr']['not_existent'],$GLOBALS['xmlrpcstr']['not_existent']); 142 } 143 if (is_array($id) && count($id) > 1) 144 { 145 foreach($events as $key => $event) 146 { 147 if (!$this->cal->check_perms(EGW_ACL_READ,$event,0,$this->xmlrpc_date_format)) 148 { 149 // xmlrpc_error does NOT return 150 $GLOBALS['server']->xmlrpc_error($GLOBALS['xmlrpcerr']['no_access'],$GLOBALS['xmlrpcstr']['no_access']); 151 } 152 $events[$key] = $this->xmlrpc_prepare($event); 153 } 154 } 155 else 156 { 157 // for a single id the event is returned and not an array with the event 158 if (is_array($id)) $events = array_shift($events); 159 160 if (!$this->cal->check_perms(EGW_ACL_READ,$events,0,$this->xmlrpc_date_format)) 161 { 162 // xmlrpc_error does NOT return 163 $GLOBALS['server']->xmlrpc_error($GLOBALS['xmlrpcerr']['no_access'],$GLOBALS['xmlrpcstr']['no_access']); 164 } 165 $events = $this->xmlrpc_prepare($events); 166 } 167 return $events; 168 } 169 170 /** 171 * Delete an event 172 * 173 * @param array $ids event-id(s) 174 * @return boolean true or XMLRPC error not_existent or no_access 175 */ 176 function delete($ids) 177 { 178 if ($this->debug) error_log('bocalendar::delete('.print_r($ids,true).')'); 179 180 foreach((array) $ids as $id) 181 { 182 if (!$event = $this->cal->read($id,null,true)) // id not found, as ignore_acl=true 183 { 184 // xmlrpc_error does NOT return 185 $GLOBALS['server']->xmlrpc_error($GLOBALS['xmlrpcerr']['not_existent'],$GLOBALS['xmlrpcstr']['not_existent']); 186 } 187 if (!$this->cal->check_perms(EGW_ACL_DELETE,$event)) 188 { 189 // xmlrpc_error does NOT return 190 $GLOBALS['server']->xmlrpc_error($GLOBALS['xmlrpcerr']['no_access'],$GLOBALS['xmlrpcstr']['no_access']); 191 } 192 if (!$this->cal->delete($id)) 193 { 194 return false; // other db-problem 195 } 196 } 197 return true; 198 } 199 200 /** 201 * Add/update an event 202 * 203 * @param array $event event-data 204 * @return int cal-id 205 */ 206 function write($event) 207 { 208 if ($this->debug) error_log('bocalendar::write('.print_r($event,true).')'); 209 210 // convert xmlrpc specific values back 211 $event['category'] = $event['category'] ? $GLOBALS['server']->xmlrpc2cats($event['category']) : null; 212 213 // using access={public|private} in all modules via xmlrpc 214 $event['public'] = $event['access'] != 'private'; 215 unset($event['access']); 216 217 if (is_array($event['participants'])) 218 { 219 foreach($event['participants'] as $user => $data) 220 { 221 if (!is_numeric($user)) 222 { 223 unset($event['participants'][$user]); 224 $user = $GLOBALS['egw']->accounts->name2id($data['email'],'account_email'); 225 } 226 if (!$user) continue; 227 228 $event['participants'][$user] = in_array($data['status'],array('U','A','R','T')) ? $data['status'] : 'U'; 229 } 230 } 231 if (!is_array($event['participants']) || !count($event['participants'])) 232 { 233 $event['participants'] = array($GLOBALS['egw_info']['user']['account_id'] => 'A'); 234 } 235 if (!($id = $this->cal->update($event,true))) // true=no conflict check for now 236 { 237 $GLOBALS['server']->xmlrpc_error($GLOBALS['xmlrpcerr']['no_access'],$GLOBALS['xmlrpcstr']['no_access']); 238 } 239 return (int) $id; 240 } 241 242 /** 243 * search calendar for events 244 * 245 * If daywise is not set or false, an XMLRPC array of events is returned, otherwise an 246 * XMLRCP struct with date as string (eg. '20060101') and an array of events is returned. 247 * 248 * @param array $params following keys are allowed: start, end, user (more see bocal::search) 249 * @return array with events 250 */ 251 function search($params) 252 { 253 if ($this->debug) error_log('bocalendar::search('.print_r($params,true).')'); 254 255 // some defaults for xmlrpc 256 if (!isset($params['date_format'])) $params['date_format'] = $this->xmlrpc_date_format; 257 if (!isset($params['enum_recuring'])) $params['enum_recuring'] = false; 258 // security precausion 259 unset($params['ignore_acl']); 260 261 $events =& $this->cal->search($params); 262 263 foreach($events as $key => $event) 264 { 265 $events[$key] = $this->xmlrpc_prepare($event); 266 } 267 return !$params['daywise'] ? array_values($events) : $events; 268 } 269 270 /** 271 * prepare regular event-array (already with iso8601 dates) to be send by xmlrpc 272 * - participants are send as struct/array with keys: name, email, status 273 * - categories are send as array with cat_id - title pairs 274 * - public is transformed to access={public|private} 275 * - new (1.2) values get unset (eg. participant_types) 276 * 277 * @param array &$event 278 * @return array 279 */ 280 function xmlrpc_prepare(&$event) 281 { 282 $event['rights'] = $this->cal->grants[$event['owner']]; 283 284 static $user_cache = array(); 285 286 foreach((array) $event['participants'] as $uid => $status) 287 { 288 if (!is_numeric($uid)) continue; // resources 289 290 if (!isset($user_cache[$uid])) 291 { 292 $user_cache[$uid] = array( 293 'name' => $GLOBALS['egw']->common->grab_owner_name($uid), 294 'email' => $GLOBALS['egw']->accounts->id2name($uid,'account_email') 295 ); 296 } 297 $event['participants'][$uid] = $user_cache[$uid] + array( 298 'status' => $status, 299 ); 300 } 301 if (is_array($event['alarm'])) 302 { 303 foreach($event['alarm'] as $id => $alarm) 304 { 305 if ($alarm['owner'] != $GLOBALS['egw_info']['user']['account_id']) 306 { 307 unset($event['alarm'][$id]); 308 } 309 } 310 } 311 if ($event['category']) 312 { 313 $event['category'] = $GLOBALS['server']->cats2xmlrpc(explode(',',$event['category'])); 314 } 315 else 316 { 317 unset($event['category']); 318 } 319 // using access={public|private} in all modules via xmlrpc 320 $event['access'] = $event['public'] ? 'public' : 'private'; 321 322 // unset everything not known in version 1.0 323 foreach(array('public','participant_types') as $key) 324 { 325 unset($event[$key]); 326 } 327 // unsetting everything which could result in an typeless <value /> 328 foreach($event as $key => $value) 329 { 330 if (is_null($value) || is_array($value) && !$value) 331 { 332 unset($event[$key]); 333 } 334 } 335 return $event; 336 } 337 338 /** 339 * return array with all categories 340 * 341 * @param boolean $complete=false false: return id => title pairs, true array with full data instead of title 342 * @return array 343 */ 344 function categories($complete = False) 345 { 346 return $GLOBALS['server']->categories($complete); 347 } 348 }
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 |