1 | <?php |
---|
2 | /**************************************************************************\ |
---|
3 | * eGroupWare - Calendar * |
---|
4 | * http://www.eGroupWare.org * |
---|
5 | * Maintained and further developed by RalfBecker@outdoor-training.de * |
---|
6 | * Based on Webcalendar by Craig Knudsen <cknudsen@radix.net> * |
---|
7 | * http://www.radix.net/~cknudsen * |
---|
8 | * Originaly modified by Mark Peters <skeeter@phpgroupware.org> * |
---|
9 | * -------------------------------------------- * |
---|
10 | * This program is free software; you can redistribute it and/or modify it * |
---|
11 | * under the terms of the GNU General Public License as published by the * |
---|
12 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
13 | * option) any later version. * |
---|
14 | \**************************************************************************/ |
---|
15 | |
---|
16 | |
---|
17 | class bocalendar |
---|
18 | { |
---|
19 | var $public_functions = Array( |
---|
20 | 'read_entry' => True, |
---|
21 | 'delete_entry' => True, |
---|
22 | 'delete_calendar' => True, |
---|
23 | 'change_owner' => True, |
---|
24 | 'update' => True, |
---|
25 | 'check_set_default_prefs' => True, |
---|
26 | 'store_to_cache' => True, |
---|
27 | 'export_event' => True, |
---|
28 | 'send_alarm' => True, |
---|
29 | 'reinstate' => True |
---|
30 | ); |
---|
31 | |
---|
32 | var $soap_functions = Array( |
---|
33 | 'read_entry' => Array( |
---|
34 | 'in' => Array( |
---|
35 | 'int' |
---|
36 | ), |
---|
37 | 'out' => Array( |
---|
38 | 'SOAPStruct' |
---|
39 | ) |
---|
40 | ), |
---|
41 | 'delete_entry' => Array( |
---|
42 | 'in' => Array( |
---|
43 | 'int' |
---|
44 | ), |
---|
45 | 'out' => Array( |
---|
46 | 'int' |
---|
47 | ) |
---|
48 | ), |
---|
49 | 'delete_calendar' => Array( |
---|
50 | 'in' => Array( |
---|
51 | 'int' |
---|
52 | ), |
---|
53 | 'out' => Array( |
---|
54 | 'int' |
---|
55 | ) |
---|
56 | ), |
---|
57 | 'change_owner' => Array( |
---|
58 | 'in' => Array( |
---|
59 | 'array' |
---|
60 | ), |
---|
61 | 'out' => Array( |
---|
62 | 'int' |
---|
63 | ) |
---|
64 | ), |
---|
65 | 'update' => Array( |
---|
66 | 'in' => Array( |
---|
67 | 'array', |
---|
68 | 'array', |
---|
69 | 'array', |
---|
70 | 'array', |
---|
71 | 'array' |
---|
72 | ), |
---|
73 | 'out' => Array( |
---|
74 | 'array' |
---|
75 | ) |
---|
76 | ), |
---|
77 | 'store_to_cache' => Array( |
---|
78 | 'in' => Array( |
---|
79 | 'struct' |
---|
80 | ), |
---|
81 | 'out' => Array( |
---|
82 | 'SOAPStruct' |
---|
83 | ) |
---|
84 | ), |
---|
85 | 'store_to_cache' => Array( |
---|
86 | 'in' => Array( |
---|
87 | 'array' |
---|
88 | ), |
---|
89 | 'out' => Array( |
---|
90 | 'string' |
---|
91 | ) |
---|
92 | ), |
---|
93 | 'categories' => array( |
---|
94 | 'in' => array('bool'), |
---|
95 | 'out' => array('array') |
---|
96 | ), |
---|
97 | ); |
---|
98 | |
---|
99 | var $wdays; |
---|
100 | |
---|
101 | var $debug = False; |
---|
102 | // var $debug = True; |
---|
103 | |
---|
104 | var $so; |
---|
105 | var $so1; |
---|
106 | var $ex_participants; |
---|
107 | var $cached_events; |
---|
108 | var $repeating_events; |
---|
109 | var $day; |
---|
110 | var $month; |
---|
111 | var $year; |
---|
112 | var $prefs; |
---|
113 | |
---|
114 | var $owner; |
---|
115 | var $holiday_color; |
---|
116 | var $printer_friendly = False; |
---|
117 | |
---|
118 | var $cached_holidays; |
---|
119 | |
---|
120 | var $g_owner = 0; |
---|
121 | |
---|
122 | var $filter; |
---|
123 | var $cat_id; |
---|
124 | var $users_timeformat; |
---|
125 | |
---|
126 | var $modified; |
---|
127 | var $deleted; |
---|
128 | var $added; |
---|
129 | |
---|
130 | var $is_group = False; |
---|
131 | |
---|
132 | var $soap = False; |
---|
133 | |
---|
134 | var $use_session = False; |
---|
135 | |
---|
136 | var $today; |
---|
137 | var $debug_string; |
---|
138 | |
---|
139 | var $sortby; |
---|
140 | var $num_months; |
---|
141 | var $xmlrpc = False; // not called via xmlrpc |
---|
142 | var $async = false; |
---|
143 | |
---|
144 | function bocalendar($session=0) |
---|
145 | { |
---|
146 | |
---|
147 | if(!is_object($GLOBALS['phpgw']->datetime)) |
---|
148 | { |
---|
149 | $GLOBALS['phpgw']->datetime = createobject('phpgwapi.date_time'); |
---|
150 | } |
---|
151 | |
---|
152 | $this->cat = CreateObject('phpgwapi.categories'); |
---|
153 | $this->grants = $GLOBALS['phpgw']->acl->get_grants('calendar'); |
---|
154 | @reset($this->grants); |
---|
155 | if(DEBUG_APP) |
---|
156 | { |
---|
157 | if(floor(phpversion()) >= 4) |
---|
158 | { |
---|
159 | $this->debug_string = ''; |
---|
160 | ob_start(); |
---|
161 | } |
---|
162 | |
---|
163 | foreach($this->grants as $grantor => $rights) |
---|
164 | { |
---|
165 | print_debug('Grantor',$grantor); |
---|
166 | print_debug('Rights',$rights); |
---|
167 | } |
---|
168 | } |
---|
169 | |
---|
170 | print_debug('Read use_session',$session); |
---|
171 | |
---|
172 | if($session) |
---|
173 | { |
---|
174 | $this->read_sessiondata(); |
---|
175 | $this->use_session = True; |
---|
176 | } |
---|
177 | print_debug('BO Filter',$this->filter); |
---|
178 | print_debug('Owner',$this->owner); |
---|
179 | |
---|
180 | if ($GLOBALS['argv']) { |
---|
181 | $this->async = true; |
---|
182 | $this->load_lang(); |
---|
183 | } |
---|
184 | |
---|
185 | $this->prefs['calendar'] = $GLOBALS['phpgw_info']['user']['preferences']['calendar']; |
---|
186 | $this->check_set_default_prefs(); |
---|
187 | |
---|
188 | $owner = get_var('owner',array('GET','POST'),$GLOBALS['owner']); |
---|
189 | |
---|
190 | ereg('menuaction=([a-zA-Z.]+)',$_SERVER['HTTP_REFERER'],$regs); |
---|
191 | $from = $regs[1]; |
---|
192 | if ((substr($_SERVER['PHP_SELF'],-8) == 'home.php' && substr($this->prefs['calendar']['defaultcalendar'],0,7) == 'planner' |
---|
193 | || $_GET['menuaction'] == 'calendar.uicalendar.planner' && |
---|
194 | $from != 'calendar.uicalendar.planner' && !$this->save_owner) |
---|
195 | && (int)$this->prefs['calendar']['planner_start_with_group'] > 0) |
---|
196 | { |
---|
197 | // entering planner for the first time ==> saving owner in save_owner, setting owner to default |
---|
198 | // |
---|
199 | $this->save_owner = $this->owner; |
---|
200 | $owner = 'g_'.$this->prefs['calendar']['planner_start_with_group']; |
---|
201 | } |
---|
202 | elseif ($_GET['menuaction'] != 'calendar.uicalendar.planner' && |
---|
203 | $this->save_owner) |
---|
204 | { |
---|
205 | // leaving planner with an unchanged user/owner ==> setting owner back to save_owner |
---|
206 | // |
---|
207 | $owner = (int)(isset($_GET['owner']) ? $_GET['owner'] : $this->save_owner); |
---|
208 | unset($this->save_owner); |
---|
209 | } |
---|
210 | elseif (!empty($owner) && $owner != $this->owner && $from == 'calendar.uicalendar.planner') |
---|
211 | { |
---|
212 | // user/owner changed within planner ==> forgetting save_owner |
---|
213 | // |
---|
214 | unset($this->save_owner); |
---|
215 | } |
---|
216 | |
---|
217 | if(isset($owner) && $owner!='' && substr($owner,0,2) == 'g_') |
---|
218 | { |
---|
219 | $this->set_owner_to_group(substr($owner,2)); |
---|
220 | } |
---|
221 | elseif(isset($owner) && $owner!='') |
---|
222 | { |
---|
223 | $this->owner = (int)$owner; |
---|
224 | } |
---|
225 | elseif(!@isset($this->owner) || !@$this->owner) |
---|
226 | { |
---|
227 | $this->owner = (int)$GLOBALS['phpgw_info']['user']['account_id']; |
---|
228 | } |
---|
229 | elseif(isset($this->owner) && $GLOBALS['phpgw']->accounts->get_type($this->owner) == 'g') |
---|
230 | { |
---|
231 | $this->set_owner_to_group((int)$this->owner); |
---|
232 | } |
---|
233 | |
---|
234 | $this->prefs['common'] = $GLOBALS['phpgw_info']['user']['preferences']['common']; |
---|
235 | |
---|
236 | if ($this->prefs['common']['timeformat'] == '12') |
---|
237 | { |
---|
238 | $this->users_timeformat = 'h:ia'; |
---|
239 | } |
---|
240 | else |
---|
241 | { |
---|
242 | $this->users_timeformat = 'H:i'; |
---|
243 | } |
---|
244 | $this->holiday_color = (substr($GLOBALS['phpgw_info']['theme']['bg07'],0,1)=='#'?'':'#').$GLOBALS['phpgw_info']['theme']['bg07']; |
---|
245 | |
---|
246 | $friendly = (isset($_GET['friendly'])?$_GET['friendly']:''); |
---|
247 | $friendly = ($friendly=='' && isset($_POST['friendly'])?$_POST['friendly']:$friendly); |
---|
248 | |
---|
249 | $this->printer_friendly = ((int)$friendly == 1?True:False); |
---|
250 | |
---|
251 | if(isset($_POST['filter'])) { $this->filter = $_POST['filter']; } |
---|
252 | if(isset($_POST['sortby'])) { $this->sortby = $_POST['sortby']; } |
---|
253 | if(isset($_POST['cat_id'])) { $this->cat_id = $_POST['cat_id']; } |
---|
254 | |
---|
255 | if(!isset($this->filter)) |
---|
256 | { |
---|
257 | $this->filter = ' '.$this->prefs['calendar']['defaultfilter'].' '; |
---|
258 | } |
---|
259 | |
---|
260 | if(!isset($this->sortby)) |
---|
261 | { |
---|
262 | $this->sortby = $this->prefs['calendar']['defaultcalendar'] == 'planner_user' ? 'user' : 'category'; |
---|
263 | } |
---|
264 | |
---|
265 | if($GLOBALS['phpgw']->accounts->get_type($this->owner)=='g') |
---|
266 | { |
---|
267 | $this->filter = ' all '; |
---|
268 | } |
---|
269 | |
---|
270 | $this->so = CreateObject('calendar.socalendar', |
---|
271 | Array( |
---|
272 | 'owner' => $this->owner, |
---|
273 | 'filter' => $this->filter, |
---|
274 | 'category' => $this->cat_id, |
---|
275 | 'g_owner' => $this->g_owner |
---|
276 | ) |
---|
277 | ); |
---|
278 | $this->rpt_day = array( // need to be after creation of socalendar |
---|
279 | MCAL_M_SUNDAY => 'Sunday', |
---|
280 | MCAL_M_MONDAY => 'Monday', |
---|
281 | MCAL_M_TUESDAY => 'Tuesday', |
---|
282 | MCAL_M_WEDNESDAY => 'Wednesday', |
---|
283 | MCAL_M_THURSDAY => 'Thursday', |
---|
284 | MCAL_M_FRIDAY => 'Friday', |
---|
285 | MCAL_M_SATURDAY => 'Saturday' |
---|
286 | ); |
---|
287 | if($this->bo->prefs['calendar']['weekdaystarts'] != 'Sunday') |
---|
288 | { |
---|
289 | $mcals = array_keys($this->rpt_day); |
---|
290 | $days = array_values($this->rpt_day); |
---|
291 | $this->rpt_day = array(); |
---|
292 | list($n) = $found = array_keys($days,$this->prefs['calendar']['weekdaystarts']); |
---|
293 | for ($i = 0; $i < 7; ++$i,++$n) |
---|
294 | { |
---|
295 | $this->rpt_day[$mcals[$n % 7]] = $days[$n % 7]; |
---|
296 | } |
---|
297 | } |
---|
298 | $this->rpt_type = Array( |
---|
299 | MCAL_RECUR_NONE => 'None', |
---|
300 | MCAL_RECUR_DAILY => 'Daily', |
---|
301 | MCAL_RECUR_WEEKLY => 'Weekly', |
---|
302 | MCAL_RECUR_MONTHLY_WDAY => 'Monthly (by day)', |
---|
303 | MCAL_RECUR_MONTHLY_MDAY => 'Monthly (by date)', |
---|
304 | MCAL_RECUR_YEARLY => 'Yearly' |
---|
305 | ); |
---|
306 | |
---|
307 | $localtime = $GLOBALS['phpgw']->datetime->users_localtime; |
---|
308 | |
---|
309 | $date = (isset($GLOBALS['date'])?$GLOBALS['date']:''); |
---|
310 | $date = (isset($_GET['date'])?$_GET['date']:$date); |
---|
311 | $date = ($date=='' && isset($_POST['date'])?$_POST['date']:$date); |
---|
312 | |
---|
313 | $year = (isset($_GET['year'])?$_GET['year']:''); |
---|
314 | $year = ($year=='' && isset($_POST['year'])?$_POST['year']:$year); |
---|
315 | |
---|
316 | $month = (isset($_GET['month'])?$_GET['month']:''); |
---|
317 | $month = ($month=='' && isset($_POST['month'])?$_POST['month']:$month); |
---|
318 | |
---|
319 | $day = (isset($_GET['day'])?$_GET['day']:''); |
---|
320 | $day = ($day=='' && isset($_POST['day'])?$_POST['day']:''); |
---|
321 | |
---|
322 | $num_months = (isset($_GET['num_months'])?$_GET['num_months']:''); |
---|
323 | $num_months = ($num_months=='' && isset($_POST['num_months'])?$_POST['num_months']:$num_months); |
---|
324 | |
---|
325 | if(isset($date) && $date!='') |
---|
326 | { |
---|
327 | $this->year = (int)(substr($date,0,4)); |
---|
328 | $this->month = (int)(substr($date,4,2)); |
---|
329 | $this->day = (int)(substr($date,6,2)); |
---|
330 | } |
---|
331 | else |
---|
332 | { |
---|
333 | if(isset($year) && $year!='') |
---|
334 | { |
---|
335 | $this->year = $year; |
---|
336 | } |
---|
337 | else |
---|
338 | { |
---|
339 | $this->year = date('Y',$localtime); |
---|
340 | } |
---|
341 | if(isset($month) && $month!='') |
---|
342 | { |
---|
343 | $this->month = $month; |
---|
344 | } |
---|
345 | else |
---|
346 | { |
---|
347 | $this->month = date('m',$localtime); |
---|
348 | } |
---|
349 | if(isset($day) && $day!='') |
---|
350 | { |
---|
351 | $this->day = $day; |
---|
352 | } |
---|
353 | else |
---|
354 | { |
---|
355 | $this->day = date('d',$localtime); |
---|
356 | } |
---|
357 | } |
---|
358 | |
---|
359 | if(isset($num_months) && $num_months!='') |
---|
360 | { |
---|
361 | $this->num_months = $num_months; |
---|
362 | } |
---|
363 | elseif($this->num_months == 0) |
---|
364 | { |
---|
365 | $this->num_months = 1; |
---|
366 | } |
---|
367 | |
---|
368 | $this->today = date('Ymd',$GLOBALS['phpgw']->datetime->users_localtime); |
---|
369 | |
---|
370 | if(DEBUG_APP) |
---|
371 | { |
---|
372 | print_debug('BO Filter','('.$this->filter.')'); |
---|
373 | print_debug('Owner',$this->owner); |
---|
374 | print_debug('Today',$this->today); |
---|
375 | if(floor(phpversion()) >= 4) |
---|
376 | { |
---|
377 | $this->debug_string .= ob_get_contents(); |
---|
378 | ob_end_clean(); |
---|
379 | } |
---|
380 | } |
---|
381 | $this->xmlrpc = is_object($GLOBALS['server']) && $GLOBALS['server']->last_method; |
---|
382 | $this->wdays = Array(MCAL_M_SUNDAY,MCAL_M_MONDAY,MCAL_M_TUESDAY,MCAL_M_WEDNESDAY, |
---|
383 | MCAL_M_THURSDAY,MCAL_M_FRIDAY,MCAL_M_SATURDAY); |
---|
384 | } |
---|
385 | |
---|
386 | function delegar($idDelegador,$idDelegado,$idEvento) { |
---|
387 | |
---|
388 | $this->so->cal->stream->lock(array("phpgw_cal_user")); |
---|
389 | |
---|
390 | if(substr($idDelegado,-1) == 'U') { |
---|
391 | $idDelegado = substr($idDelegado,0,-1); |
---|
392 | } |
---|
393 | |
---|
394 | $sql = "SELECT * FROM phpgw_cal_user where cal_id=$idEvento and cal_login=$idDelegado"; |
---|
395 | |
---|
396 | if($idDelegado != '') |
---|
397 | { |
---|
398 | $this->so->cal->stream->query($sql,__LINE__,__FILE__); |
---|
399 | if($this->so->cal->stream->next_record()) |
---|
400 | { |
---|
401 | throw new Exception("The selected User is already included in this event"); |
---|
402 | }else{ |
---|
403 | $sql = "update phpgw_cal_user set cal_login = $idDelegado,cal_status='U' where cal_id=$idEvento |
---|
404 | and cal_login=$idDelegador"; |
---|
405 | |
---|
406 | $this->so->cal->stream->query($sql,__LINE__,__FILE__,0,-1,true); |
---|
407 | |
---|
408 | $event = $this->so->read_entry($idEvento); |
---|
409 | |
---|
410 | $this->send_update(MSG_ADDED,array($idDelegado => 'U'),$event,$event); |
---|
411 | } |
---|
412 | }else { |
---|
413 | throw new Exception('999'); |
---|
414 | } |
---|
415 | |
---|
416 | $this->so->cal->stream->unlock(); |
---|
417 | } |
---|
418 | |
---|
419 | function load_lang() { |
---|
420 | if(!$_SESSION['phpgw_info']['calendar']['langAlarm']) |
---|
421 | { |
---|
422 | $array_keys = array(); |
---|
423 | $fn = '../../calendar/setup/phpgw_alarm_'.$GLOBALS['phpgw_info']['user']['preferences']['common']['lang'].'.lang'; |
---|
424 | echo $fn; |
---|
425 | if (file_exists($fn)){ |
---|
426 | $fp = fopen($fn,'r'); |
---|
427 | while ($data = fgets($fp,16000)) { |
---|
428 | list($message_id,$app_name,$null,$content) = explode("\t",substr($data,0,-1)); |
---|
429 | $_SESSION['phpgw_info']['calendar']['langAlarm'][$message_id] = $content; |
---|
430 | } |
---|
431 | fclose($fp); |
---|
432 | } |
---|
433 | } |
---|
434 | } |
---|
435 | function list_methods($_type='xmlrpc') |
---|
436 | { |
---|
437 | /* |
---|
438 | This handles introspection or discovery by the logged in client, |
---|
439 | in which case the input might be an array. The server always calls |
---|
440 | this function to fill the server dispatch map using a string. |
---|
441 | */ |
---|
442 | if (is_array($_type)) |
---|
443 | { |
---|
444 | $_type = $_type['type']; |
---|
445 | } |
---|
446 | switch($_type) |
---|
447 | { |
---|
448 | case 'xmlrpc': |
---|
449 | $xml_functions = array( |
---|
450 | 'list_methods' => array( |
---|
451 | 'function' => 'list_methods', |
---|
452 | 'signature' => array(array(xmlrpcStruct,xmlrpcString)), |
---|
453 | 'docstring' => lang('Read this list of methods.') |
---|
454 | ), |
---|
455 | 'read' => array( |
---|
456 | 'function' => 'read_entry', |
---|
457 | 'signature' => array(array(xmlrpcStruct,xmlrpcInt)), |
---|
458 | 'docstring' => lang('Read a single entry by passing the id and fieldlist.') |
---|
459 | ), |
---|
460 | 'read_entry' => array( // deprecated, use read |
---|
461 | 'function' => 'read_entry', |
---|
462 | 'signature' => array(array(xmlrpcStruct,xmlrpcInt)), |
---|
463 | 'docstring' => lang('Read a single entry by passing the id and fieldlist.') |
---|
464 | ), |
---|
465 | 'write' => array( |
---|
466 | 'function' => 'update', |
---|
467 | 'signature' => array(array(xmlrpcStruct,xmlrpcStruct)), |
---|
468 | 'docstring' => lang('Add or update a single entry by passing the fields.') |
---|
469 | ), |
---|
470 | 'add_entry' => array( // deprecated, use write |
---|
471 | 'function' => 'update', |
---|
472 | 'signature' => array(array(xmlrpcStruct,xmlrpcStruct)), |
---|
473 | 'docstring' => lang('Add a single entry by passing the fields.') |
---|
474 | ), |
---|
475 | 'update_entry' => array( // deprecated, use write |
---|
476 | 'function' => 'update', |
---|
477 | 'signature' => array(array(xmlrpcStruct,xmlrpcStruct)), |
---|
478 | 'docstring' => lang('Update a single entry by passing the fields.') |
---|
479 | ), |
---|
480 | 'delete' => array( |
---|
481 | 'function' => 'delete_entry', |
---|
482 | 'signature' => array(array(xmlrpcInt,xmlrpcInt)), |
---|
483 | 'docstring' => lang('Delete a single entry by passing the id.') |
---|
484 | ), |
---|
485 | 'delete_entry' => array( // deprecated, use delete |
---|
486 | 'function' => 'delete_entry', |
---|
487 | 'signature' => array(array(xmlrpcInt,xmlrpcInt)), |
---|
488 | 'docstring' => lang('Delete a single entry by passing the id.') |
---|
489 | ), |
---|
490 | 'delete_calendar' => array( |
---|
491 | 'function' => 'delete_calendar', |
---|
492 | 'signature' => array(array(xmlrpcInt,xmlrpcInt)), |
---|
493 | 'docstring' => lang('Delete an entire users calendar.') |
---|
494 | ), |
---|
495 | 'change_owner' => array( |
---|
496 | 'function' => 'change_owner', |
---|
497 | 'signature' => array(array(xmlrpcInt,xmlrpcStruct)), |
---|
498 | 'docstring' => lang('Change all events for $params[\'old_owner\'] to $params[\'new_owner\'].') |
---|
499 | ), |
---|
500 | 'search' => array( |
---|
501 | 'function' => 'store_to_cache', |
---|
502 | 'signature' => array(array(xmlrpcStruct,xmlrpcStruct)), |
---|
503 | 'docstring' => lang('Read a list of entries.') |
---|
504 | ), |
---|
505 | 'store_to_cache' => array( // deprecated, use search |
---|
506 | 'function' => 'store_to_cache', |
---|
507 | 'signature' => array(array(xmlrpcStruct,xmlrpcStruct)), |
---|
508 | 'docstring' => lang('Read a list of entries.') |
---|
509 | ), |
---|
510 | 'export_event' => array( |
---|
511 | 'function' => 'export_event', |
---|
512 | 'signature' => array(array(xmlrpcString,xmlrpcStruct)), |
---|
513 | 'docstring' => lang('Export a list of entries in iCal format.') |
---|
514 | ), |
---|
515 | 'categories' => array( |
---|
516 | 'function' => 'categories', |
---|
517 | 'signature' => array(array(xmlrpcStruct,xmlrpcStruct)), |
---|
518 | 'docstring' => lang('List all categories.') |
---|
519 | ), |
---|
520 | ); |
---|
521 | return $xml_functions; |
---|
522 | break; |
---|
523 | case 'soap': |
---|
524 | return $this->soap_functions; |
---|
525 | break; |
---|
526 | default: |
---|
527 | return array(); |
---|
528 | break; |
---|
529 | } |
---|
530 | } |
---|
531 | |
---|
532 | function set_owner_to_group($owner) |
---|
533 | { |
---|
534 | print_debug('calendar::bocalendar::set_owner_to_group:owner',$owner); |
---|
535 | $this->owner = (int)$owner; |
---|
536 | $this->is_group = True; |
---|
537 | $this->g_owner = Array(); |
---|
538 | $members = $GLOBALS['phpgw']->accounts->member($owner); |
---|
539 | if (is_array($members)) |
---|
540 | { |
---|
541 | foreach($members as $user) |
---|
542 | { |
---|
543 | // use only members which gave the user a read-grant |
---|
544 | if ($this->check_perms(PHPGW_ACL_READ,0,$user['account_id'])) |
---|
545 | { |
---|
546 | $this->g_owner[] = $user['account_id']; |
---|
547 | } |
---|
548 | } |
---|
549 | } |
---|
550 | //echo "<p>".function_backtrace().": set_owner_to_group($owner) = ".print_r($this->g_owner,True)."</p>\n"; |
---|
551 | } |
---|
552 | |
---|
553 | function member_of_group($owner=0) |
---|
554 | { |
---|
555 | $owner = ($owner==0?$GLOBALS['phpgw_info']['user']['account_id']:$owner); |
---|
556 | $group_owners = $GLOBALS['phpgw']->accounts->membership(); |
---|
557 | while($group_owners && list($index,$group_info) = each($group_owners)) |
---|
558 | { |
---|
559 | if($this->owner == $group_info['account_id']) |
---|
560 | { |
---|
561 | return True; |
---|
562 | } |
---|
563 | } |
---|
564 | return False; |
---|
565 | } |
---|
566 | |
---|
567 | function save_sessiondata($data='') |
---|
568 | { |
---|
569 | if ($this->use_session) |
---|
570 | { |
---|
571 | if (!is_array($data)) |
---|
572 | { |
---|
573 | $data = array( |
---|
574 | 'filter' => $this->filter, |
---|
575 | 'cat_id' => $this->cat_id, |
---|
576 | 'owner' => $this->owner, |
---|
577 | 'save_owner' => $this->save_owner, |
---|
578 | 'year' => $this->year, |
---|
579 | 'month' => $this->month, |
---|
580 | 'day' => $this->day, |
---|
581 | 'date' => $this->date, |
---|
582 | 'sortby' => $this->sortby, |
---|
583 | 'num_months' => $this->num_months, |
---|
584 | 'return_to' => $this->return_to |
---|
585 | ); |
---|
586 | } |
---|
587 | if($this->debug) |
---|
588 | { |
---|
589 | if(floor(phpversion()) >= 4) |
---|
590 | { |
---|
591 | ob_start(); |
---|
592 | } |
---|
593 | echo '<!-- '."\n".'Save:'."\n"._debug_array($data,False)."\n".' -->'."\n"; |
---|
594 | if(floor(phpversion()) >= 4) |
---|
595 | { |
---|
596 | $this->debug_string .= ob_get_contents(); |
---|
597 | ob_end_clean(); |
---|
598 | } |
---|
599 | } |
---|
600 | $GLOBALS['phpgw']->session->appsession('session_data','calendar',$data); |
---|
601 | } |
---|
602 | } |
---|
603 | |
---|
604 | function read_sessiondata() |
---|
605 | { |
---|
606 | $data = $GLOBALS['phpgw']->session->appsession('session_data','calendar'); |
---|
607 | print_debug('Read',_debug_array($data,False)); |
---|
608 | |
---|
609 | $this->filter = $data['filter']; |
---|
610 | $this->cat_id = $data['cat_id']; |
---|
611 | $this->sortby = $data['sortby']; |
---|
612 | $this->owner = (int)$data['owner']; |
---|
613 | $this->save_owner = (int)$data['save_owner']; |
---|
614 | $this->year = (int)$data['year']; |
---|
615 | $this->month = (int)$data['month']; |
---|
616 | $this->day = (int)$data['day']; |
---|
617 | $this->num_months = (int)$data['num_months']; |
---|
618 | $this->return_to = $data['return_to']; |
---|
619 | } |
---|
620 | |
---|
621 | function read_entry($id,$ignore_acl=False) |
---|
622 | { |
---|
623 | if (is_array($id) && count($id) == 1) |
---|
624 | { |
---|
625 | list(,$id) = each($id); |
---|
626 | } |
---|
627 | if($ignore_acl || $this->check_perms(PHPGW_ACL_READ,$id)) |
---|
628 | { |
---|
629 | $event = $this->so->read_entry($id); |
---|
630 | if(!isset($event['participants'][$this->owner]) && $this->user_is_a_member($event,$this->owner)) |
---|
631 | { |
---|
632 | $this->so->add_attribute('participants','U',(int)$this->owner); |
---|
633 | $this->so->add_entry($event); |
---|
634 | $event = $this->get_cached_event(); |
---|
635 | } |
---|
636 | return $this->xmlrpc ? $this->xmlrpc_prepare($event) : $event; |
---|
637 | } |
---|
638 | if ($this->xmlrpc) |
---|
639 | { |
---|
640 | $GLOBALS['server']->xmlrpc_error($GLOBALS['xmlrpcerr']['no_access'],$GLOBALS['xmlrpcstr']['no_access']); |
---|
641 | } |
---|
642 | return False; |
---|
643 | } |
---|
644 | |
---|
645 | function delete_single($param) |
---|
646 | { |
---|
647 | if($this->check_perms(PHPGW_ACL_DELETE,(int)$param['id'])) |
---|
648 | { |
---|
649 | $temp_event = $this->get_cached_event(); |
---|
650 | $event = $this->read_entry((int)$param['id']); |
---|
651 | // if($this->owner == $event['owner']) |
---|
652 | // { |
---|
653 | $exception_time = mktime($event['start']['hour'],$event['start']['min'],0,$param['month'],$param['day'],$param['year']) - $GLOBALS['phpgw']->datetime->tz_offset; |
---|
654 | $event['recur_exception'][] = (int)$exception_time; |
---|
655 | $this->so->cal->event = $event; |
---|
656 | // print_debug('exception time',$event['recur_exception'][count($event['recur_exception']) -1]); |
---|
657 | // print_debug('count event exceptions',count($event['recur_exception'])); |
---|
658 | $this->so->add_entry($event); |
---|
659 | $cd = 16; |
---|
660 | |
---|
661 | $this->so->cal->event = $temp_event; |
---|
662 | unset($temp_event); |
---|
663 | } |
---|
664 | else |
---|
665 | { |
---|
666 | $cd = 60; |
---|
667 | } |
---|
668 | // } |
---|
669 | return $cd; |
---|
670 | } |
---|
671 | |
---|
672 | function delete_entry($id) |
---|
673 | { |
---|
674 | if (is_array($id) && count($id) == 1) |
---|
675 | { |
---|
676 | list(,$id) = each($id); |
---|
677 | } |
---|
678 | if($this->check_perms(PHPGW_ACL_DELETE,$id)) |
---|
679 | { |
---|
680 | $this->so->delete_entry($id); |
---|
681 | |
---|
682 | if ($this->xmlrpc) |
---|
683 | { |
---|
684 | $this->so->expunge($id); |
---|
685 | } |
---|
686 | return $this->xmlrpc ? True : 16; |
---|
687 | } |
---|
688 | if ($this->xmlrpc) |
---|
689 | { |
---|
690 | $GLOBALS['server']->xmlrpc_error($GLOBALS['xmlrpcerr']['no_access'],$GLOBALS['xmlrpcstr']['no_access']); |
---|
691 | } |
---|
692 | return 60; |
---|
693 | } |
---|
694 | |
---|
695 | function reinstate($params='') |
---|
696 | { |
---|
697 | if($this->check_perms(PHPGW_ACL_EDIT,$params['cal_id']) && isset($params['reinstate_index'])) |
---|
698 | { |
---|
699 | $event = $this->so->read_entry($params['cal_id']); |
---|
700 | @reset($params['reinstate_index']); |
---|
701 | print_debug('Count of reinstate_index',count($params['reinstate_index'])); |
---|
702 | if(count($params['reinstate_index']) > 1) |
---|
703 | { |
---|
704 | while(list($key,$value) = each($params['reinstate_index'])) |
---|
705 | { |
---|
706 | print_debug('reinstate_index ['.$key.']',(int)$value); |
---|
707 | print_debug('exception time',$event['recur_exception'][(int)$value]); |
---|
708 | unset($event['recur_exception'][(int)$value]); |
---|
709 | print_debug('count event exceptions',count($event['recur_exception'])); |
---|
710 | } |
---|
711 | } |
---|
712 | else |
---|
713 | { |
---|
714 | print_debug('reinstate_index[0]',(int)$params['reinstate_index'][0]); |
---|
715 | print_debug('exception time',$event['recur_exception'][(int)$params['reinstate_index'][0]]); |
---|
716 | unset($event['recur_exception'][(int)$params['reinstate_index'][0]]); |
---|
717 | print_debug('count event exceptions',count($event['recur_exception'])); |
---|
718 | } |
---|
719 | $this->so->cal->event = $event; |
---|
720 | $this->so->add_entry($event); |
---|
721 | return 42; |
---|
722 | } |
---|
723 | else |
---|
724 | { |
---|
725 | return 43; |
---|
726 | } |
---|
727 | } |
---|
728 | |
---|
729 | function delete_calendar($owner) |
---|
730 | { |
---|
731 | if($GLOBALS['phpgw_info']['user']['apps']['admin']) |
---|
732 | { |
---|
733 | $this->so->delete_calendar($owner); |
---|
734 | } |
---|
735 | } |
---|
736 | |
---|
737 | function change_owner($params='') |
---|
738 | { |
---|
739 | if($GLOBALS['phpgw_info']['server']['calendar_type'] == 'sql') |
---|
740 | { |
---|
741 | if(is_array($params)) |
---|
742 | { |
---|
743 | $this->so->change_owner($params['old_owner'],$params['new_owner']); |
---|
744 | } |
---|
745 | } |
---|
746 | } |
---|
747 | |
---|
748 | function expunge() |
---|
749 | { |
---|
750 | reset($this->so->cal->deleted_events); |
---|
751 | while(list($i,$event_id) = each($this->so->cal->deleted_events)) |
---|
752 | { |
---|
753 | $event = $this->so->read_entry($event_id); |
---|
754 | if(!$this->ex_participants) |
---|
755 | $this->ex_participants = html_entity_decode($event['ex_participants']); |
---|
756 | if($this->check_perms(PHPGW_ACL_DELETE,$event)) |
---|
757 | { |
---|
758 | $this->send_update(MSG_DELETED,$event['participants'],$event); |
---|
759 | } |
---|
760 | else |
---|
761 | { |
---|
762 | unset($this->so->cal->deleted_events[$i]); |
---|
763 | } |
---|
764 | } |
---|
765 | $this->so->expunge(); |
---|
766 | } |
---|
767 | |
---|
768 | function search_keywords($keywords) |
---|
769 | { |
---|
770 | $type = $GLOBALS['phpgw']->accounts->get_type($this->owner); |
---|
771 | |
---|
772 | if($type == 'g') |
---|
773 | { |
---|
774 | $members = $GLOBALS['phpgw']->acl->get_ids_for_location($this->owner, 1, 'phpgw_group'); |
---|
775 | } |
---|
776 | else |
---|
777 | { |
---|
778 | $members = array_keys($this->grants); |
---|
779 | |
---|
780 | if (!in_array($this->owner,$members)) |
---|
781 | { |
---|
782 | $members[] = $this->owner; |
---|
783 | } |
---|
784 | } |
---|
785 | foreach($members as $n => $uid) |
---|
786 | { |
---|
787 | if (!($this->grants[$uid] & PHPGW_ACL_READ)) |
---|
788 | { |
---|
789 | unset($members[$n]); |
---|
790 | } |
---|
791 | } |
---|
792 | return $this->so->list_events_keyword($keywords,$members); |
---|
793 | } |
---|
794 | |
---|
795 | function getNextDow($start){ |
---|
796 | if ($start == 6) |
---|
797 | { |
---|
798 | return 0; |
---|
799 | } |
---|
800 | else |
---|
801 | { |
---|
802 | return $start + 1; |
---|
803 | } |
---|
804 | } |
---|
805 | |
---|
806 | // TODO: Levar em consideração no cálculo das ocorrências o parâmetro |
---|
807 | // $event['recur_interval'] |
---|
808 | function expand_repetition($event){ |
---|
809 | $return = Array(); |
---|
810 | |
---|
811 | $event['recur_enddate']['hour'] = 24; |
---|
812 | $enddate = $this->maketime($event['recur_enddate']); |
---|
813 | |
---|
814 | $owner = $event['owner']; |
---|
815 | $participants = $event['participants']; |
---|
816 | |
---|
817 | // $new_event = Array(); |
---|
818 | // $new_event['owner'] = $owner; |
---|
819 | // $new_event['participants'] = $participants; |
---|
820 | // $new_event['start'] = $event['start']; |
---|
821 | // $new_event['end'] = $event['end']; |
---|
822 | // |
---|
823 | // $return[] = $new_event; |
---|
824 | |
---|
825 | switch($event['recur_type']) { |
---|
826 | case MCAL_RECUR_DAILY: |
---|
827 | // add 1 day = 86400 sec |
---|
828 | $starttime = $this->maketime($event['start']); |
---|
829 | $endtime = $this->maketime($event['end']); |
---|
830 | |
---|
831 | $offset = 86400; |
---|
832 | for (; $starttime <= $enddate; |
---|
833 | $starttime = $starttime+$offset, |
---|
834 | $endtime = $endtime+$offset) |
---|
835 | { |
---|
836 | $new_event = Array(); |
---|
837 | $new_event['owner'] = $owner; |
---|
838 | $new_event['participants'] = $participants; |
---|
839 | $new_event['start'] = $starttime; |
---|
840 | $new_event['end'] = $endtime; |
---|
841 | $return[] = $new_event; |
---|
842 | } |
---|
843 | |
---|
844 | break; |
---|
845 | case MCAL_RECUR_WEEKLY: |
---|
846 | |
---|
847 | $setDow = (int)date('w',$this->maketime($event['start'])); |
---|
848 | $dowOffsets = Array(); |
---|
849 | $firstDow; |
---|
850 | $firstDowOffset = 0; |
---|
851 | |
---|
852 | // Initializing do |
---|
853 | $mask = $this->wdays[$setDow]; |
---|
854 | $firstDayMismatch = False; |
---|
855 | if (((int)$event['recur_data'] & $mask) == 0){ |
---|
856 | $firstDayMismatch = True; |
---|
857 | } |
---|
858 | |
---|
859 | $dow = $setDow; |
---|
860 | |
---|
861 | for ($nextDow = $setDow; array_sum($dowOffsets) < 7;) |
---|
862 | { |
---|
863 | |
---|
864 | $nextDow = $this->getNextDow($nextDow); |
---|
865 | $mask = $this->wdays[$nextDow]; |
---|
866 | |
---|
867 | if (((int)$event['recur_data'] & $mask) != 0) |
---|
868 | { |
---|
869 | if ($firstDayMismatch and $firstDowOffset == 0) |
---|
870 | { |
---|
871 | if ($dow < $nextDow) |
---|
872 | { |
---|
873 | $firstDowOffset = $nextDow - $dow; |
---|
874 | } |
---|
875 | else if ($dow > $nextDow) |
---|
876 | { |
---|
877 | $firstDowOffset = (7 - $dow) + $nextDow; |
---|
878 | } |
---|
879 | } |
---|
880 | else |
---|
881 | { |
---|
882 | if ($dow < $nextDow) |
---|
883 | { |
---|
884 | $dowOffsets[] = $nextDow - $dow; |
---|
885 | } |
---|
886 | else if ($dow > $nextDow) |
---|
887 | { |
---|
888 | $dowOffsets[] = (7 - $dow) + $nextDow; |
---|
889 | } |
---|
890 | else |
---|
891 | { |
---|
892 | $dowOffsets[] = 7; |
---|
893 | } |
---|
894 | |
---|
895 | } |
---|
896 | |
---|
897 | $dow = $nextDow; |
---|
898 | if (!isset($firstDow)) |
---|
899 | { |
---|
900 | $firstDow = $dow; |
---|
901 | } |
---|
902 | |
---|
903 | } |
---|
904 | |
---|
905 | // $nextDow = $this->getNextDow($nextDow); |
---|
906 | // $mask = $this->wdays[$nextDow]; |
---|
907 | |
---|
908 | } |
---|
909 | |
---|
910 | if ($firstDayMismatch) |
---|
911 | { |
---|
912 | if ($dow < $firstDow) |
---|
913 | { |
---|
914 | $dowOffsets[] = $firstDow - $dow; |
---|
915 | } |
---|
916 | else if ($dow > $firstDow) |
---|
917 | { |
---|
918 | $dowOffsets[] = (7 - $dow) + $firstDow; |
---|
919 | } |
---|
920 | } |
---|
921 | |
---|
922 | // Gera os eventos |
---|
923 | $starttime = $this->maketime($event['start']); |
---|
924 | $endtime = $this->maketime($event['end']); |
---|
925 | $offset = 86400; |
---|
926 | |
---|
927 | $new_event = Array(); |
---|
928 | $new_event['owner'] = $owner; |
---|
929 | $new_event['participants'] = $participants; |
---|
930 | $new_event['start'] = $starttime; |
---|
931 | $new_event['end'] = $endtime; |
---|
932 | $return[] = $new_event; |
---|
933 | |
---|
934 | if ($firstDayMismatch && $firstDowOffset != 0) |
---|
935 | { |
---|
936 | $multi = $firstDowOffset; |
---|
937 | |
---|
938 | $new_event = Array(); |
---|
939 | $new_event['owner'] = $owner; |
---|
940 | $new_event['participants'] = $participants; |
---|
941 | $new_event['start'] = $starttime += $offset*$multi; |
---|
942 | $new_event['end'] = $endtime += $offset*$multi; |
---|
943 | $return[] = $new_event; |
---|
944 | } |
---|
945 | |
---|
946 | for ($i = 0, $multi = $dowOffsets[$i], |
---|
947 | $starttime += $offset*$multi, |
---|
948 | $endtime += $offset*$multi; |
---|
949 | $starttime <= $enddate; |
---|
950 | $i++, |
---|
951 | $i = ($i < count($dowOffsets))?$i:0, |
---|
952 | $multi = $dowOffsets[$i], |
---|
953 | $starttime += $offset*$multi, |
---|
954 | $endtime += $offset*$multi) |
---|
955 | { |
---|
956 | //error_log('loop infinito?'); |
---|
957 | $new_event = Array(); |
---|
958 | $new_event['owner'] = $owner; |
---|
959 | $new_event['participants'] = $participants; |
---|
960 | $new_event['start'] = $starttime; // + $offset*$multi; |
---|
961 | $new_event['end'] = $endtime; // + $offset*$multi; |
---|
962 | $return[] = $new_event; |
---|
963 | } |
---|
964 | |
---|
965 | |
---|
966 | break; |
---|
967 | case MCAL_RECUR_MONTHLY_WDAY: |
---|
968 | // Not working!!! |
---|
969 | break; |
---|
970 | case MCAL_RECUR_MONTHLY_MDAY: |
---|
971 | case MCAL_RECUR_YEARLY: |
---|
972 | |
---|
973 | for ($key = ($event['recur_type'] == MCAL_RECUR_YEARLY)?'year':'month', |
---|
974 | $starttime = $event['start'], $endtime = $event['end']; |
---|
975 | $this->maketime($starttime) <= $enddate; |
---|
976 | $starttime['year'] = ($key == 'month' && $starttime['month'] == 12)?$starttime['year']+1:$starttime['year'], |
---|
977 | $endtime['year'] = ($key == 'month' && $endtime['month'] == 12)?$endtime['year']+1:$endtime['year'], |
---|
978 | $starttime[$key] = ($key == 'year')?$starttime[$key]+1:($key == 'month' && $starttime[$key] < 12)?$starttime[$key]+1:1, |
---|
979 | $endtime[$key] = ($key == 'year')?$endtime[$key]+1:($key == 'month' && $endtime[$key] < 12)?$endtime[$key]+1:1) |
---|
980 | { |
---|
981 | $new_event = Array(); |
---|
982 | $new_event['owner'] = $owner; |
---|
983 | $new_event['participants'] = $participants; |
---|
984 | $new_event['start'] = $this->maketime($starttime); |
---|
985 | $new_event['end'] = $this->maketime($endtime); |
---|
986 | $return[] = $new_event; |
---|
987 | } |
---|
988 | |
---|
989 | break; |
---|
990 | // default: |
---|
991 | // return Array(); |
---|
992 | |
---|
993 | } |
---|
994 | |
---|
995 | return $return; |
---|
996 | } |
---|
997 | |
---|
998 | function update($params='') |
---|
999 | { |
---|
1000 | |
---|
1001 | if($params['from_mobile']) { |
---|
1002 | $ui_return = "mobile.ui_mobilecalendar.edit"; |
---|
1003 | $ui_index = "mobile.ui_mobilecalendar.index"; |
---|
1004 | $ui_overlap = "mobile.ui_mobilecalendar.overlap"; |
---|
1005 | } |
---|
1006 | else { |
---|
1007 | $ui_return = "calendar.uicalendar.edit"; |
---|
1008 | $ui_index = "calendar.uicalendar.index"; |
---|
1009 | $ui_overlap = "calendar.uicalendar.overlap"; |
---|
1010 | } |
---|
1011 | |
---|
1012 | if(!is_object($GLOBALS['phpgw']->datetime)) |
---|
1013 | { |
---|
1014 | $GLOBALS['phpgw']->datetime = createobject('phpgwapi.date_time'); |
---|
1015 | } |
---|
1016 | |
---|
1017 | $l_cal = (@isset($params['cal']) && $params['cal']?$params['cal']:$_POST['cal']); |
---|
1018 | |
---|
1019 | $post_max_size = ini_get('post_max_size'); |
---|
1020 | $mul = substr($post_max_size, -1); |
---|
1021 | $mul = ($mul == 'M' ? 1048576 : ($mul == 'K' ? 1024 : ($mul == 'G' ? 1073741824 : 1))); |
---|
1022 | if ($_SERVER['CONTENT_LENGTH'] > $mul*(int)$post_max_size && $post_max_size) |
---|
1023 | $l_cal['attachment'] = 'ERROR'; |
---|
1024 | |
---|
1025 | if(count($_FILES['cal']) > 0){ |
---|
1026 | |
---|
1027 | if($l_cal['attachment'] != '') |
---|
1028 | $attachments = unserialize($l_cal['attachment']); |
---|
1029 | else |
---|
1030 | $attachments = Array(); |
---|
1031 | |
---|
1032 | foreach ($_FILES['cal']['error']['attachment'] as $key => $error) { |
---|
1033 | |
---|
1034 | if ($error == UPLOAD_ERR_OK) { |
---|
1035 | |
---|
1036 | $new_file= $GLOBALS['phpgw_info']['server']['temp_dir'].'/'.$_SESSION[ 'phpgw_session' ][ 'session_id' ].md5($attachment['name'].microtime()); |
---|
1037 | move_uploaded_file($_FILES['cal']['tmp_name']['attachment'][$key], $new_file); |
---|
1038 | $attach = Array('tmp_name' => $new_file, 'name' => $_FILES['cal']['name']['attachment'][$key], 'type' => $_FILES['cal']['type']['attachment'][$key]); |
---|
1039 | |
---|
1040 | $attachments[] = $attach; |
---|
1041 | |
---|
1042 | }elseif($error == UPLOAD_ERR_INI_SIZE){ |
---|
1043 | $attachments = 'ERROR'; |
---|
1044 | break; |
---|
1045 | |
---|
1046 | } |
---|
1047 | } |
---|
1048 | $l_cal['attachment'] = $attachments; |
---|
1049 | |
---|
1050 | } |
---|
1051 | $l_participants = (@$params['participants']?$params['participants']:$_POST['participants']); |
---|
1052 | $this->ex_participants = (@$params['ex_participants']?$params['ex_participants']:$_POST['ex_participants']); |
---|
1053 | $l_categories = (@$params['categories']?$params['categories']:$_POST['categories']); |
---|
1054 | $l_start = (@isset($params['start']) && $params['start']?$params['start']:$_POST['start']); |
---|
1055 | $l_end = (@isset($params['end']) && $params['end']?$params['end']:$_POST['end']); |
---|
1056 | $l_recur_enddate = (@isset($params['recur_enddate']) && $params['recur_enddate']?$params['recur_enddate']:$_POST['recur_enddate']); |
---|
1057 | |
---|
1058 | |
---|
1059 | $send_to_ui = True; |
---|
1060 | //if ((!is_array($l_start) || !is_array($l_end)) && !isset($_GET['readsess'])) // xmlrpc call |
---|
1061 | if ($this->xmlrpc) // xmlrpc call |
---|
1062 | { |
---|
1063 | $send_to_ui = False; |
---|
1064 | |
---|
1065 | $l_cal = $params; // no extra array |
---|
1066 | |
---|
1067 | foreach(array('start','end','recur_enddate') as $name) |
---|
1068 | { |
---|
1069 | $var = 'l_'.$name; |
---|
1070 | $$var = $GLOBALS['server']->iso86012date($params[$name]); |
---|
1071 | unset($l_cal[$name]); |
---|
1072 | } |
---|
1073 | if (!is_array($l_participants) || !count($l_participants)) |
---|
1074 | { |
---|
1075 | $l_participants = array($GLOBALS['phpgw_info']['user']['account_id'].'A'); |
---|
1076 | } |
---|
1077 | else |
---|
1078 | { |
---|
1079 | $l_participants = array(); |
---|
1080 | foreach($params['participants'] as $user => $data) |
---|
1081 | { |
---|
1082 | $l_participants[] = $user.$data['status']; |
---|
1083 | } |
---|
1084 | } |
---|
1085 | unset($l_cal['participants']); |
---|
1086 | |
---|
1087 | if (!is_object($GLOBALS['phpgw']->categories)) |
---|
1088 | { |
---|
1089 | $GLOBALS['phpgw']->categories = CreateObject('phpgwapi.categories'); |
---|
1090 | } |
---|
1091 | $l_categories = $GLOBALS['server']->xmlrpc2cats($params['category']); |
---|
1092 | unset($l_cal['category']); |
---|
1093 | |
---|
1094 | // using access={public|private} in all modules via xmlrpc |
---|
1095 | $l_cal['public'] = $params['access'] != 'private'; |
---|
1096 | unset($l_cal['access']); |
---|
1097 | /* |
---|
1098 | $fp = fopen('/tmp/xmlrpc.log','a+'); |
---|
1099 | ob_start(); |
---|
1100 | echo "\nbocalendar::update("; print_r($params); echo ")\n"; |
---|
1101 | //echo "\nl_start="; print_r($l_start); |
---|
1102 | //echo "\nl_end="; print_r($l_end); |
---|
1103 | fwrite($fp,ob_get_contents()); |
---|
1104 | ob_end_clean(); |
---|
1105 | fclose($fp); |
---|
1106 | */ |
---|
1107 | } |
---|
1108 | print_debug('ID',$l_cal['id']); |
---|
1109 | |
---|
1110 | // don't wrap to the next day for no time |
---|
1111 | if ($l_end['hour'] == 24 && $l_end['min'] == 0) |
---|
1112 | { |
---|
1113 | $l_end['hour'] = 23; |
---|
1114 | $l_end['min'] = 59; |
---|
1115 | } |
---|
1116 | |
---|
1117 | if(isset($_GET['readsess'])) |
---|
1118 | { |
---|
1119 | $event = $this->restore_from_appsession(); |
---|
1120 | $event['title'] = stripslashes($event['title']); |
---|
1121 | $event['description'] = stripslashes($event['description']); |
---|
1122 | $event['ex_participants'] = stripslashes($event['ex_participants']); |
---|
1123 | $datetime_check = $this->validate_update($event); |
---|
1124 | if($datetime_check) |
---|
1125 | { |
---|
1126 | ExecMethod($ui_return, |
---|
1127 | Array( |
---|
1128 | 'cd' => $datetime_check, |
---|
1129 | 'readsess' => 1 |
---|
1130 | ) |
---|
1131 | ); |
---|
1132 | if(!$params['from_mobile']) |
---|
1133 | $GLOBALS['phpgw']->common->phpgw_exit(True); |
---|
1134 | else |
---|
1135 | return; |
---|
1136 | } |
---|
1137 | $overlapping_events = False; |
---|
1138 | } |
---|
1139 | else |
---|
1140 | { |
---|
1141 | if((!$l_cal['id'] && !$this->check_perms(PHPGW_ACL_ADD)) || |
---|
1142 | ($l_cal['id'] && !$this->check_perms(PHPGW_ACL_EDIT,$l_cal['id']))) |
---|
1143 | { |
---|
1144 | if ($this->xmlrpc) |
---|
1145 | { |
---|
1146 | $GLOBALS['server']->xmlrpc_error($GLOBALS['xmlrpcerr']['no_access'],$GLOBALS['xmlrpcstr']['no_access']); |
---|
1147 | } |
---|
1148 | if (!$send_to_ui) |
---|
1149 | { |
---|
1150 | return array(($l_cal['id']?1:2) => 'permission denied'); |
---|
1151 | } |
---|
1152 | ExecMethod($ui_index); |
---|
1153 | if(!$params['from_mobile']) |
---|
1154 | $GLOBALS['phpgw']->common->phpgw_exit(); |
---|
1155 | else |
---|
1156 | return; |
---|
1157 | } |
---|
1158 | |
---|
1159 | print_debug('Prior to fix_update_time()'); |
---|
1160 | $this->fix_update_time($l_start); |
---|
1161 | $this->fix_update_time($l_end); |
---|
1162 | if(!isset($l_cal['ex_participants'])) |
---|
1163 | { |
---|
1164 | $l_cal['ex_participants'] = $this->ex_participants; |
---|
1165 | } |
---|
1166 | |
---|
1167 | if(!isset($l_categories)) |
---|
1168 | { |
---|
1169 | $l_categories = 0; |
---|
1170 | } |
---|
1171 | |
---|
1172 | $is_public = ($l_cal['type'] != 'private' && $l_cal['type'] != 'privateHiddenFields'); |
---|
1173 | $this->so->event_init(); |
---|
1174 | $this->add_attribute('uid',$l_cal['uid']); |
---|
1175 | $this->add_attribute('type',$l_cal['type']); |
---|
1176 | if($l_cal['ex_participants']) { |
---|
1177 | $this->add_attribute('ex_participants',$l_cal['ex_participants']); |
---|
1178 | } |
---|
1179 | if(count($l_categories) >= 2) |
---|
1180 | { |
---|
1181 | $this->so->set_category(implode(',',$l_categories)); |
---|
1182 | } |
---|
1183 | else |
---|
1184 | { |
---|
1185 | $this->so->set_category(strval($l_categories[0])); |
---|
1186 | } |
---|
1187 | $this->so->set_title($l_cal['title']); |
---|
1188 | $this->so->set_description($l_cal['description']); |
---|
1189 | $this->so->set_attachment($l_cal['attachment']); |
---|
1190 | $this->so->set_ex_participants($l_cal['ex_participants']); |
---|
1191 | $this->so->set_start($l_start['year'],$l_start['month'],$l_start['mday'],$l_start['hour'],$l_start['min'],0); |
---|
1192 | $this->so->set_end($l_end['year'],$l_end['month'],$l_end['mday'],$l_end['hour'],$l_end['min'],0); |
---|
1193 | $this->so->set_class($is_public); |
---|
1194 | $this->so->add_attribute('reference',(@isset($l_cal['reference']) && $l_cal['reference']?$l_cal['reference']:0)); |
---|
1195 | $this->so->add_attribute('location',(@isset($l_cal['location']) && $l_cal['location']?$l_cal['location']:'')); |
---|
1196 | $this->so->add_attribute('repeat',(@isset($l_cal['recur_type']) && $l_cal['recur_type']?$l_cal['recur_type']:'')); |
---|
1197 | $this->so->add_attribute('alarmd',(@isset($l_cal['alarmdays'])?$l_cal['alarmdays']:0)); |
---|
1198 | $this->so->add_attribute('alarmh',(@isset($l_cal['alarmhours'])?$l_cal['alarmhours']:0)); |
---|
1199 | $this->so->add_attribute('alarmm',(@isset($l_cal['alarmminutes'])?$l_cal['alarmminutes']:0)); |
---|
1200 | if($l_cal['id']) |
---|
1201 | { |
---|
1202 | $this->so->add_attribute('id',$l_cal['id']); |
---|
1203 | } |
---|
1204 | |
---|
1205 | if($l_cal['rpt_use_end'] != 'y') |
---|
1206 | { |
---|
1207 | $l_recur_enddate['year'] = 0; |
---|
1208 | $l_recur_enddate['month'] = 0; |
---|
1209 | $l_recur_enddate['mday'] = 0; |
---|
1210 | } |
---|
1211 | elseif (isset($l_recur_enddate['str'])) |
---|
1212 | { |
---|
1213 | $l_recur_enddate = $this->jscal->input2date($l_recur_enddate['str'],False,'mday'); |
---|
1214 | } |
---|
1215 | |
---|
1216 | switch((int)$l_cal['recur_type']) |
---|
1217 | { |
---|
1218 | case MCAL_RECUR_NONE: |
---|
1219 | $this->so->set_recur_none(); |
---|
1220 | |
---|
1221 | $repetido = (int)$l_cal['recur_type']; // recebe o tipo de repeticao; |
---|
1222 | $this->so->add_attribute('recur_type',(@isset($repetido) && $repetido?$repetido:0)); |
---|
1223 | $this->so->add_attribute('rpt_end_use',(@isset($l_cal['rpt_use_end']) && $l_cal['rpt_use_end']?$l_cal['rpt_use_end']:'')); |
---|
1224 | |
---|
1225 | break; |
---|
1226 | case MCAL_RECUR_DAILY: |
---|
1227 | $this->so->set_recur_daily((int)$l_recur_enddate['year'],(int)$l_recur_enddate['month'],(int)$l_recur_enddate['mday'],(int)$l_cal['recur_interval']); |
---|
1228 | |
---|
1229 | $repetido = (int)$l_cal['recur_type']; // recebe o tipo de repeticao; |
---|
1230 | $this->so->add_attribute('recur_type',(@isset($repetido) && $repetido?$repetido:0)); |
---|
1231 | |
---|
1232 | $tmp_init = explode("/",$_POST['start']['str']); // recebe a data inicial da repeticao; |
---|
1233 | $init_rept = mktime($_POST['start']['hour'],$_POST['start']['min'],0,intval($tmp_init[1]),$tmp_init[0],$tmp_init[2]); // transforma a data inicial + hora + minuto em UNIX timestamp; |
---|
1234 | |
---|
1235 | if($l_cal['rpt_use_end'] == 'y') // verifica se foi indicada data final da repeticao, se sim: |
---|
1236 | { |
---|
1237 | $this->so->add_attribute('rpt_end_use',(@isset($l_cal['rpt_use_end']) && $l_cal['rpt_use_end']?$l_cal['rpt_use_end']:'')); |
---|
1238 | |
---|
1239 | $tmp_end = explode("/",$_POST['recur_enddate']['str']); // recebe data final da repeticao; |
---|
1240 | $end_rept = mktime($_POST['start']['hour'],$_POST['start']['min'],0,intval($tmp_end[1]),$tmp_end[0],$tmp_end[2]); // transforma a data inicial + hora e minuto de inicio da repeticao em UNIX timestamp; |
---|
1241 | |
---|
1242 | }else { // se nao existe data final da repeticao (agendamento infinito): |
---|
1243 | |
---|
1244 | $end_rept = 0; // variavel recebe zero e nao sera adicionado nenhum alarme para o agendamento; |
---|
1245 | } |
---|
1246 | break; |
---|
1247 | case MCAL_RECUR_WEEKLY: |
---|
1248 | |
---|
1249 | $repetido = (int)$l_cal['recur_type']; // recebe o tipo de repeticao; |
---|
1250 | $this->so->add_attribute('recur_type',(@isset($repetido) && $repetido?$repetido:0)); |
---|
1251 | |
---|
1252 | $tmp_init = explode("/",$_POST['start']['str']); // recebe a data inicial da repeticao; |
---|
1253 | $init_rept = mktime($_POST['start']['hour'],$_POST['start']['min'],0,intval($tmp_init[1]),$tmp_init[0],$tmp_init[2]); // transforma a data inicial + hora + minuto em UNIX timestamp; |
---|
1254 | |
---|
1255 | if($l_cal['rpt_use_end'] == 'y') // verifica se foi indicada data final da repeticao, se sim: |
---|
1256 | { |
---|
1257 | |
---|
1258 | $this->so->add_attribute('rpt_end_use',(@isset($l_cal['rpt_use_end']) && $l_cal['rpt_use_end']?$l_cal['rpt_use_end']:'')); |
---|
1259 | $tmp_end = explode("/",$_POST['recur_enddate']['str']); // recebe data final da repeticao; |
---|
1260 | $end_rept = mktime($_POST['start']['hour'],$_POST['start']['min'],0,intval($tmp_end[1]),$tmp_end[0],$tmp_end[2]); // transforma a data inicial + hora e minuto de inicio da repeticao em UNIX timestamp; |
---|
1261 | |
---|
1262 | }else { // se nao existe data final da repeticao (agendamento infinito): |
---|
1263 | |
---|
1264 | $end_rept = 0; // variavel recebe zero e nao sera adicionado nenhum alarme para o agendamento; |
---|
1265 | } |
---|
1266 | |
---|
1267 | foreach(array('rpt_sun','rpt_mon','rpt_tue','rpt_wed','rpt_thu','rpt_fri','rpt_sat') as $rpt_day) |
---|
1268 | { |
---|
1269 | $l_cal['recur_data'] += (int)$l_cal[$rpt_day]; |
---|
1270 | } |
---|
1271 | if (is_array($l_cal['rpt_day'])) |
---|
1272 | { |
---|
1273 | foreach ($l_cal['rpt_day'] as $mask) |
---|
1274 | { |
---|
1275 | $l_cal['recur_data'] |= (int)$mask; |
---|
1276 | $rpt_wdays = $l_cal['recur_data']; // recebe os dias da semana (somatorio) para repetir o alarme; |
---|
1277 | } |
---|
1278 | } |
---|
1279 | $this->so->add_attribute('rpt_wdays',(@isset($rpt_wdays) && $rpt_wdays?$rpt_wdays:'')); |
---|
1280 | $this->so->set_recur_weekly((int)$l_recur_enddate['year'],(int)$l_recur_enddate['month'],(int)$l_recur_enddate['mday'],(int)$l_cal['recur_interval'],$l_cal['recur_data']); |
---|
1281 | break; |
---|
1282 | case MCAL_RECUR_MONTHLY_MDAY: |
---|
1283 | $this->so->set_recur_monthly_mday((int)$l_recur_enddate['year'],(int)$l_recur_enddate['month'],(int)$l_recur_enddate['mday'],(int)$l_cal['recur_interval']); |
---|
1284 | |
---|
1285 | $repetido = (int)$l_cal['recur_type']; // recebe o tipo de repeticao; |
---|
1286 | $this->so->add_attribute('recur_type',(@isset($repetido) && $repetido?$repetido:0)); |
---|
1287 | |
---|
1288 | $tmp_init = explode("/",$_POST['start']['str']); // recebe a data inicial da repeticao; |
---|
1289 | $init_rept = mktime($_POST['start']['hour'],$_POST['start']['min'],0,intval($tmp_init[1]),$tmp_init[0],$tmp_init[2]); // transforma a data inicial + hora + minuto em UNIX timestamp; |
---|
1290 | |
---|
1291 | if($l_cal['rpt_use_end'] == 'y') // verifica se foi indicada data final da repeticao, se sim: |
---|
1292 | { |
---|
1293 | $this->so->add_attribute('rpt_end_use',(@isset($l_cal['rpt_use_end']) && $l_cal['rpt_use_end']?$l_cal['rpt_use_end']:'')); |
---|
1294 | $tmp_end = explode("/",$_POST['recur_enddate']['str']); // recebe data final da repeticao; |
---|
1295 | $end_rept = mktime($_POST['start']['hour'],$_POST['start']['min'],0,intval($tmp_end[1]),$tmp_end[0],$tmp_end[2]); // transforma a data inicial + hora e minuto de inicio da repeticao em UNIX timestamp; |
---|
1296 | |
---|
1297 | }else { // se nao existe data final da repeticao (agendamento infinito): |
---|
1298 | |
---|
1299 | $end_rept = 0; // variavel recebe zero e nao sera adicionado nenhum alarme para o agendamento; |
---|
1300 | } |
---|
1301 | break; |
---|
1302 | case MCAL_RECUR_MONTHLY_WDAY: |
---|
1303 | $this->so->set_recur_monthly_wday((int)$l_recur_enddate['year'],(int)$l_recur_enddate['month'],(int)$l_recur_enddate['mday'],(int)$l_cal['recur_interval']); |
---|
1304 | break; |
---|
1305 | case MCAL_RECUR_YEARLY: |
---|
1306 | $this->so->set_recur_yearly((int)$l_recur_enddate['year'],(int)$l_recur_enddate['month'],(int)$l_recur_enddate['mday'],(int)$l_cal['recur_interval']); |
---|
1307 | |
---|
1308 | $repetido = (int)$l_cal['recur_type']; // recebe o tipo de repeticao; |
---|
1309 | $this->so->add_attribute('recur_type',(@isset($repetido) && $repetido?$repetido:0)); |
---|
1310 | |
---|
1311 | $tmp_init = explode("/",$_POST['start']['str']); // recebe a data inicial da repeticao; |
---|
1312 | $init_rept = mktime($_POST['start']['hour'],$_POST['start']['min'],0,intval($tmp_init[1]),$tmp_init[0],$tmp_init[2]); // transforma a data inicial + hora + minuto em UNIX timestamp; |
---|
1313 | |
---|
1314 | if($l_cal['rpt_use_end'] == 'y') // verifica se foi indicada data final da repeticao, se sim: |
---|
1315 | { |
---|
1316 | $this->so->add_attribute('rpt_end_use',(@isset($l_cal['rpt_use_end']) && $l_cal['rpt_use_end']?$l_cal['rpt_use_end']:'')); |
---|
1317 | $tmp_end = explode("/",$_POST['recur_enddate']['str']); // recebe data final da repeticao; |
---|
1318 | $end_rept = mktime($_POST['start']['hour'],$_POST['start']['min'],0,intval($tmp_end[1]),$tmp_end[0],$tmp_end[2]); // transforma a data inicial + hora e minuto de inicio da repeticao em UNIX timestamp; |
---|
1319 | |
---|
1320 | }else { // se nao existe data final da repeticao (agendamento infinito): |
---|
1321 | |
---|
1322 | $end_rept = 0; // variavel recebe zero e nao sera adicionado nenhum alarme para o agendamento; |
---|
1323 | } |
---|
1324 | break; |
---|
1325 | } |
---|
1326 | |
---|
1327 | if($l_participants) |
---|
1328 | { |
---|
1329 | $parts = $l_participants; |
---|
1330 | $minparts = min($l_participants); |
---|
1331 | $part = Array(); |
---|
1332 | for($i=0;$i<count($parts);$i++) |
---|
1333 | { |
---|
1334 | if (($accept_type = substr($parts[$i],-1,1)) == '0' || (int)$accept_type > 0) |
---|
1335 | { |
---|
1336 | $accept_type = 'U'; |
---|
1337 | } |
---|
1338 | $acct_type = $GLOBALS['phpgw']->accounts->get_type((int)$parts[$i]); |
---|
1339 | if($acct_type == 'u') |
---|
1340 | { |
---|
1341 | $part[(int)$parts[$i]] = $accept_type; |
---|
1342 | } |
---|
1343 | elseif($acct_type == 'g') |
---|
1344 | { |
---|
1345 | $part[(int)$parts[$i]] = $accept_type; |
---|
1346 | $groups[] = $parts[$i]; |
---|
1347 | /* This pulls ALL users of a group and makes them as participants to the event */ |
---|
1348 | /* I would like to turn this back into a group thing. */ |
---|
1349 | $acct = CreateObject('phpgwapi.accounts',(int)$parts[$i]); |
---|
1350 | $members = $acct->member((int)$parts[$i]); |
---|
1351 | unset($acct); |
---|
1352 | if($members == False) |
---|
1353 | { |
---|
1354 | continue; |
---|
1355 | } |
---|
1356 | while($member = each($members)) |
---|
1357 | { |
---|
1358 | $part[$member[1]['account_id']] = $accept_type; |
---|
1359 | } |
---|
1360 | } |
---|
1361 | } |
---|
1362 | } |
---|
1363 | else |
---|
1364 | { |
---|
1365 | $part = False; |
---|
1366 | } |
---|
1367 | |
---|
1368 | if($part) |
---|
1369 | { |
---|
1370 | @reset($part); |
---|
1371 | while(list($key,$accept_type) = each($part)) |
---|
1372 | { |
---|
1373 | $this->so->add_attribute('participants',$accept_type,(int)$key); |
---|
1374 | } |
---|
1375 | } |
---|
1376 | |
---|
1377 | if($groups) |
---|
1378 | { |
---|
1379 | @reset($groups); |
---|
1380 | $this->so->add_attribute('groups',(int)$group_id); |
---|
1381 | } |
---|
1382 | |
---|
1383 | $event = $this->get_cached_event(); |
---|
1384 | if(!is_int($minparts)) |
---|
1385 | { |
---|
1386 | $minparts = $this->owner; |
---|
1387 | } |
---|
1388 | if(!@isset($event['participants'][$l_cal['owner']])) |
---|
1389 | { |
---|
1390 | $this->so->add_attribute('owner',$minparts); |
---|
1391 | } |
---|
1392 | else |
---|
1393 | { |
---|
1394 | $this->so->add_attribute('owner',$l_cal['owner']); |
---|
1395 | } |
---|
1396 | $this->so->add_attribute('priority',$l_cal['priority']); |
---|
1397 | |
---|
1398 | foreach($l_cal as $name => $value) |
---|
1399 | { |
---|
1400 | if ($name[0] == '#') // Custom field |
---|
1401 | { |
---|
1402 | $this->so->add_attribute($name,stripslashes($value)); |
---|
1403 | } |
---|
1404 | } |
---|
1405 | if (isset($_POST['preserved']) && is_array($preserved = unserialize(stripslashes($_POST['preserved'])))) |
---|
1406 | { |
---|
1407 | foreach($preserved as $name => $value) |
---|
1408 | { |
---|
1409 | switch($name) |
---|
1410 | { |
---|
1411 | case 'owner': |
---|
1412 | $this->so->add_attribute('participants',$value,$l_cal['owner']); |
---|
1413 | break; |
---|
1414 | default: |
---|
1415 | $this->so->add_attribute($name,str_replace(array('&','"','<','>'),array('&','"','<','>'),$value)); |
---|
1416 | } |
---|
1417 | } |
---|
1418 | } |
---|
1419 | $event = $this->get_cached_event(); |
---|
1420 | |
---|
1421 | if ($l_cal['alarmdays'] > 0 || $l_cal['alarmhours'] > 0 || |
---|
1422 | $l_cal['alarmminutes'] > 0) |
---|
1423 | { |
---|
1424 | $offset = ($l_cal['alarmdays'] * 24 * 3600) + |
---|
1425 | ($l_cal['alarmhours'] * 3600) + ($l_cal['alarmminutes'] * 60); |
---|
1426 | |
---|
1427 | $time = $this->maketime($event['start']) - $offset; |
---|
1428 | |
---|
1429 | $event['alarm'][] = Array( |
---|
1430 | 'time' => $time, |
---|
1431 | 'offset' => $offset, |
---|
1432 | 'owner' => $this->owner, |
---|
1433 | 'enabled' => 1, |
---|
1434 | 'repeat' => $repetido, // para repetir alarme; |
---|
1435 | 'init_rept' => $init_rept, // inicio repeticao; |
---|
1436 | 'end_rept' => $end_rept, // fim repeticao; |
---|
1437 | 'rpt_wdays' => $rpt_wdays // dias repeticao da semana; |
---|
1438 | ); |
---|
1439 | } |
---|
1440 | |
---|
1441 | $this->store_to_appsession($event); |
---|
1442 | $datetime_check = $this->validate_update($event); |
---|
1443 | print_debug('bo->validated_update() returnval',$datetime_check); |
---|
1444 | if($datetime_check) |
---|
1445 | { |
---|
1446 | if (!$send_to_ui) |
---|
1447 | { |
---|
1448 | return array($datetime_check => 'invalid input data'); |
---|
1449 | } |
---|
1450 | ExecMethod($ui_return, |
---|
1451 | Array( |
---|
1452 | 'cd' => $datetime_check, |
---|
1453 | 'readsess' => 1 |
---|
1454 | ) |
---|
1455 | ); |
---|
1456 | if(!$params['from_mobile']) |
---|
1457 | $GLOBALS['phpgw']->common->phpgw_exit(True); |
---|
1458 | else |
---|
1459 | return; |
---|
1460 | } |
---|
1461 | |
---|
1462 | if($event['id']) |
---|
1463 | { |
---|
1464 | $event_ids[] = $event['id']; |
---|
1465 | } |
---|
1466 | if($event['reference']) |
---|
1467 | { |
---|
1468 | $event_ids[] = $event['reference']; |
---|
1469 | } |
---|
1470 | |
---|
1471 | if (isset($repetido) and $repetido > 0){ |
---|
1472 | $events = $this->expand_repetition($event); |
---|
1473 | $overlapping_events = False; |
---|
1474 | foreach($events as $evt){ |
---|
1475 | $overlap = $this->overlap( |
---|
1476 | $evt['start'], |
---|
1477 | $evt['end'], |
---|
1478 | $evt['participants'], |
---|
1479 | $evt['owner'], |
---|
1480 | $event_ids); |
---|
1481 | if ($overlap) |
---|
1482 | { |
---|
1483 | if (!$overlapping_events) |
---|
1484 | { |
---|
1485 | $overlapping_events = Array(); |
---|
1486 | } |
---|
1487 | array_push($overlapping_events, $overlap); |
---|
1488 | } |
---|
1489 | } |
---|
1490 | } |
---|
1491 | else { |
---|
1492 | $overlapping_events = $this->overlap( |
---|
1493 | $this->maketime($event['start']), |
---|
1494 | $this->maketime($event['end']), |
---|
1495 | $event['participants'], |
---|
1496 | $event['owner'], |
---|
1497 | $event_ids |
---|
1498 | ); |
---|
1499 | } |
---|
1500 | } |
---|
1501 | if(!$this->ex_participants) |
---|
1502 | $this->ex_participants = $event['ex_participants']; |
---|
1503 | if($overlapping_events) |
---|
1504 | { |
---|
1505 | if($send_to_ui) |
---|
1506 | { |
---|
1507 | $event['ex_participants'] = $this->ex_participants; |
---|
1508 | unset($GLOBALS['phpgw_info']['flags']['noheader']); |
---|
1509 | unset($GLOBALS['phpgw_info']['flags']['nonavbar']); |
---|
1510 | ExecMethod($ui_overlap, |
---|
1511 | Array( |
---|
1512 | 'o_events' => $overlapping_events, |
---|
1513 | 'this_event' => $event |
---|
1514 | ) |
---|
1515 | ); |
---|
1516 | if(!$params['from_mobile']) |
---|
1517 | $GLOBALS['phpgw']->common->phpgw_exit(True); |
---|
1518 | else |
---|
1519 | return; |
---|
1520 | } |
---|
1521 | else |
---|
1522 | { |
---|
1523 | return $overlapping_events; |
---|
1524 | } |
---|
1525 | } |
---|
1526 | else |
---|
1527 | { |
---|
1528 | if(!$event['id']) |
---|
1529 | { |
---|
1530 | $this->so->add_entry($event); |
---|
1531 | $this->send_update(MSG_ADDED,$event['participants'],'',$this->get_cached_event()); |
---|
1532 | print_debug('New Event ID',$event['id']); |
---|
1533 | } |
---|
1534 | else |
---|
1535 | { |
---|
1536 | print_debug('Updating Event ID',$event['id']); |
---|
1537 | $new_event = $event; |
---|
1538 | $old_event = $this->read_entry($event['id']); |
---|
1539 | // if old event has alarm and the start-time changed => update them |
---|
1540 | //echo "<p>checking ".count($old_event['alarm'])." alarms of event #$event[id] start moved from ".print_r($old_event['start'],True)." to ".print_r($event['start'],True)."</p>\n"; |
---|
1541 | if ($old_event['alarm'] && |
---|
1542 | $this->maketime($old_event['start']) != $this->maketime($event['start'])) |
---|
1543 | { |
---|
1544 | $this->so->delete_alarms($old_event['id']); |
---|
1545 | foreach($old_event['alarm'] as $id => $alarm) |
---|
1546 | { |
---|
1547 | $alarm['time'] = $this->maketime($event['start']) - $alarm['offset']; |
---|
1548 | $event['alarm'][] = $alarm; |
---|
1549 | } |
---|
1550 | //echo "updated alarms<pre>".print_r($event['alarm'],True)."</pre>\n"; |
---|
1551 | } |
---|
1552 | $this->so->cal->event = $event; |
---|
1553 | $this->so->add_entry($event); |
---|
1554 | $this->prepare_recipients($new_event,$old_event); |
---|
1555 | } |
---|
1556 | |
---|
1557 | $date = sprintf("%04d%02d%02d",$event['start']['year'],$event['start']['month'],$event['start']['mday']); |
---|
1558 | if($send_to_ui) |
---|
1559 | { |
---|
1560 | $this->read_sessiondata(); |
---|
1561 | if ($this->return_to) |
---|
1562 | { |
---|
1563 | $GLOBALS['phpgw']->redirect_link('/index.php','menuaction='.$this->return_to); |
---|
1564 | $GLOBALS['phpgw']->common->phpgw_exit(); |
---|
1565 | } |
---|
1566 | Execmethod($ui_index); |
---|
1567 | } |
---|
1568 | else |
---|
1569 | { |
---|
1570 | return (int)$event['id']; |
---|
1571 | } |
---|
1572 | } |
---|
1573 | return True; |
---|
1574 | } |
---|
1575 | |
---|
1576 | /* Private functions */ |
---|
1577 | function read_holidays($year=0) |
---|
1578 | { |
---|
1579 | if(!$year) |
---|
1580 | { |
---|
1581 | $year = $this->year; |
---|
1582 | } |
---|
1583 | $holiday = CreateObject('calendar.boholiday'); |
---|
1584 | $holiday->prepare_read_holidays($year,$this->owner); |
---|
1585 | $this->cached_holidays = $holiday->read_holiday(); |
---|
1586 | unset($holiday); |
---|
1587 | } |
---|
1588 | |
---|
1589 | function user_is_a_member($event,$user) |
---|
1590 | { |
---|
1591 | @reset($event['participants']); |
---|
1592 | $uim = False; |
---|
1593 | $security_equals = $GLOBALS['phpgw']->accounts->membership($user); |
---|
1594 | while(!$uim && $event['participants'] && $security_equals && list($participant,$status) = each($event['participants'])) |
---|
1595 | { |
---|
1596 | if($GLOBALS['phpgw']->accounts->get_type($participant) == 'g') |
---|
1597 | { |
---|
1598 | @reset($security_equals); |
---|
1599 | while(list($key,$group_info) = each($security_equals)) |
---|
1600 | { |
---|
1601 | if($group_info['account_id'] == $participant) |
---|
1602 | { |
---|
1603 | return True; |
---|
1604 | $uim = True; |
---|
1605 | } |
---|
1606 | } |
---|
1607 | } |
---|
1608 | } |
---|
1609 | return $uim; |
---|
1610 | } |
---|
1611 | |
---|
1612 | function maketime($time) |
---|
1613 | { |
---|
1614 | return mktime(intval($time['hour']),intval($time['min']),intval($time['sec']),intval($time['month']),intval($time['mday']),intval($time['year'])); |
---|
1615 | } |
---|
1616 | |
---|
1617 | /*! |
---|
1618 | @function time2array |
---|
1619 | @abstract returns a date-array suitable for the start- or endtime of an event from a timestamp |
---|
1620 | @syntax time2array($time,$alarm=0) |
---|
1621 | @param $time the timestamp for the values of the array |
---|
1622 | @param $alarm (optional) alarm field of the array, defaults to 0 |
---|
1623 | @author ralfbecker |
---|
1624 | */ |
---|
1625 | function time2array($time,$alarm = 0) |
---|
1626 | { |
---|
1627 | return array( |
---|
1628 | 'year' => (int)(date('Y',$time)), |
---|
1629 | 'month' => (int)(date('m',$time)), |
---|
1630 | 'mday' => (int)(date('d',$time)), |
---|
1631 | 'hour' => (int)(date('H',$time)), |
---|
1632 | 'min' => (int)(date('i',$time)), |
---|
1633 | 'sec' => (int)(date('s',$time)), |
---|
1634 | 'alarm' => (int)($alarm) |
---|
1635 | ); |
---|
1636 | } |
---|
1637 | |
---|
1638 | /*! |
---|
1639 | @function set_recur_date |
---|
1640 | @abstract set the start- and enddates of a recuring event for a recur-date |
---|
1641 | @syntax set_recur_date(&$event,$date) |
---|
1642 | @param $event the event which fields to set (has to be the original event for start-/end-times) |
---|
1643 | @param $date the recuring date in form 'Ymd', eg. 20030226 |
---|
1644 | @author ralfbecker |
---|
1645 | */ |
---|
1646 | function set_recur_date(&$event,$date) |
---|
1647 | { |
---|
1648 | $org_start = $this->maketime($event['start']); |
---|
1649 | $org_end = $this->maketime($event['end']); |
---|
1650 | $start = mktime($event['start']['hour'],$event['start']['min'],0,substr($date,4,2),substr($date,6,2),substr($date,0,4)); |
---|
1651 | $end = $org_end + $start - $org_start; |
---|
1652 | $event['start'] = $this->time2array($start); |
---|
1653 | $event['end'] = $this->time2array($end); |
---|
1654 | } |
---|
1655 | |
---|
1656 | function fix_update_time(&$time_param) |
---|
1657 | { |
---|
1658 | if (isset($time_param['str'])) |
---|
1659 | { |
---|
1660 | if (!is_object($this->jscal)) |
---|
1661 | { |
---|
1662 | $this->jscal = CreateObject('phpgwapi.jscalendar'); |
---|
1663 | } |
---|
1664 | $time_param += $this->jscal->input2date($time_param['str'],False,'mday'); |
---|
1665 | unset($time_param['str']); |
---|
1666 | } |
---|
1667 | if ($this->prefs['common']['timeformat'] == '12') |
---|
1668 | { |
---|
1669 | if ($time_param['ampm'] == 'pm') |
---|
1670 | { |
---|
1671 | if ($time_param['hour'] <> 12) |
---|
1672 | { |
---|
1673 | $time_param['hour'] += 12; |
---|
1674 | } |
---|
1675 | } |
---|
1676 | elseif ($time_param['ampm'] == 'am') |
---|
1677 | { |
---|
1678 | if ($time_param['hour'] == 12) |
---|
1679 | { |
---|
1680 | $time_param['hour'] -= 12; |
---|
1681 | } |
---|
1682 | } |
---|
1683 | |
---|
1684 | if($time_param['hour'] > 24) |
---|
1685 | { |
---|
1686 | $time_param['hour'] -= 12; |
---|
1687 | } |
---|
1688 | } |
---|
1689 | } |
---|
1690 | |
---|
1691 | function validate_update($event) |
---|
1692 | { |
---|
1693 | $error = 0; |
---|
1694 | // do a little form verifying |
---|
1695 | if (!count($event['participants'])) |
---|
1696 | { |
---|
1697 | $error = 43; |
---|
1698 | } |
---|
1699 | elseif ($event['title'] == '') |
---|
1700 | { |
---|
1701 | $error = 40; |
---|
1702 | } |
---|
1703 | elseif ($event['repeat'] != 0) |
---|
1704 | { |
---|
1705 | if( $event['rpt_end_use'] != 'y') |
---|
1706 | { |
---|
1707 | $error = 46; |
---|
1708 | } |
---|
1709 | //} |
---|
1710 | if ($event['repeat'] == 2) |
---|
1711 | { |
---|
1712 | if($event['rpt_wdays'] == '') { |
---|
1713 | $error = 44; |
---|
1714 | } |
---|
1715 | if( $event['rpt_end_use'] != 'y') |
---|
1716 | { |
---|
1717 | $error = 46; |
---|
1718 | } |
---|
1719 | |
---|
1720 | if ( ( isset($event['alarmd']) && ($event['alarmd'] != 0) ) || ( isset($event['alarmh']) && ($event['alarmh'] != 0) ) || ( isset($event['alarmm']) && ($event['alarmm'] != 0) ) ) |
---|
1721 | { |
---|
1722 | if( isset($event['recur_type']) && ($event['recur_type'] != 0) ) |
---|
1723 | { |
---|
1724 | if( $event['rpt_end_use'] != 'y') |
---|
1725 | { |
---|
1726 | $error = 45; |
---|
1727 | } |
---|
1728 | } |
---|
1729 | } |
---|
1730 | } |
---|
1731 | |
---|
1732 | //} |
---|
1733 | if ( ( isset($event['alarmd']) && ($event['alarmd'] != 0) ) || ( isset($event['alarmh']) && ($event['alarmh'] != 0) ) || ( isset($event['alarmm']) && ($event['alarmm'] != 0) ) ) |
---|
1734 | { |
---|
1735 | if( isset($event['recur_type']) && ($event['recur_type'] != 0) ) |
---|
1736 | { |
---|
1737 | if( $event['rpt_end_use'] != 'y') |
---|
1738 | { |
---|
1739 | $error = 45; |
---|
1740 | } |
---|
1741 | } |
---|
1742 | } |
---|
1743 | } |
---|
1744 | elseif (($GLOBALS['phpgw']->datetime->time_valid($event['start']['hour'],$event['start']['min'],0) == False) || ($GLOBALS['phpgw']->datetime->time_valid($event['end']['hour'],$event['end']['min'],0) == False)) |
---|
1745 | { |
---|
1746 | $error = 41; |
---|
1747 | } |
---|
1748 | elseif (($GLOBALS['phpgw']->datetime->date_valid($event['start']['year'],$event['start']['month'],$event['start']['mday']) == False) || ($GLOBALS['phpgw']->datetime->date_valid($event['end']['year'],$event['end']['month'],$event['end']['mday']) == False) || ($GLOBALS['phpgw']->datetime->date_compare($event['start']['year'],$event['start']['month'],$event['start']['mday'],$event['end']['year'],$event['end']['month'],$event['end']['mday']) == 1)) |
---|
1749 | { |
---|
1750 | $error = 42; |
---|
1751 | } |
---|
1752 | elseif ($GLOBALS['phpgw']->datetime->date_compare($event['start']['year'],$event['start']['month'],$event['start']['mday'],$event['end']['year'],$event['end']['month'],$event['end']['mday']) == 0) |
---|
1753 | { |
---|
1754 | if ($GLOBALS['phpgw']->datetime->time_compare($event['start']['hour'],$event['start']['min'],0,$event['end']['hour'],$event['end']['min'],0) == 1) |
---|
1755 | { |
---|
1756 | $error = 47; |
---|
1757 | } |
---|
1758 | } |
---|
1759 | if($event['attachment'] == 'ERROR') |
---|
1760 | $error = 99; |
---|
1761 | |
---|
1762 | return $error; |
---|
1763 | } |
---|
1764 | |
---|
1765 | /*! |
---|
1766 | @function participants_not_rejected($participants,$event) |
---|
1767 | @abstract checks if any of the $particpants participates in $event and has not rejected it |
---|
1768 | */ |
---|
1769 | function participants_not_rejected($participants,$event) |
---|
1770 | { |
---|
1771 | //echo "participants_not_rejected()<br>participants =<pre>"; print_r($participants); echo "</pre><br>event[participants]=<pre>"; print_r($event['participants']); echo "</pre>\n"; |
---|
1772 | foreach($participants as $uid => $status) |
---|
1773 | { |
---|
1774 | //echo "testing event[participants][uid=$uid] = '".$event['participants'][$uid]."'<br>\n"; |
---|
1775 | if (isset($event['participants'][$uid]) && $event['participants'][$uid] != 'R' && |
---|
1776 | $status != 'R') |
---|
1777 | { |
---|
1778 | return True; // found not rejected participant in event |
---|
1779 | } |
---|
1780 | } |
---|
1781 | return False; |
---|
1782 | } |
---|
1783 | |
---|
1784 | function participants_unanswered($participants,$event) |
---|
1785 | { |
---|
1786 | foreach($participants as $uid => $status) |
---|
1787 | { |
---|
1788 | if (isset($event['participants'][$uid]) && $event['participants'][$uid] == 'U' && $status == 'U') |
---|
1789 | { |
---|
1790 | return False; |
---|
1791 | } |
---|
1792 | } |
---|
1793 | return True; |
---|
1794 | } |
---|
1795 | |
---|
1796 | function overlap($starttime,$endtime,$participants,$owner=0,$id=0,$restore_cache=False) |
---|
1797 | { |
---|
1798 | // $retval = Array(); |
---|
1799 | // $ok = False; |
---|
1800 | |
---|
1801 | /* This needs some attention.. by commenting this chunk of code it will fix bug #444265 */ |
---|
1802 | |
---|
1803 | if($restore_cache) |
---|
1804 | { |
---|
1805 | $temp_cache_events = $this->cached_events; |
---|
1806 | } |
---|
1807 | |
---|
1808 | // $temp_start = (int)$GLOBALS['phpgw']->common->show_date($starttime,'Ymd'); |
---|
1809 | // $temp_start_time = (int)($GLOBALS['phpgw']->common->show_date($starttime,'Hi'); |
---|
1810 | // $temp_end = (int)$GLOBALS['phpgw']->common->show_date($endtime,'Ymd'); |
---|
1811 | // $temp_end_time = (int)$GLOBALS['phpgw']->common->show_date($endtime,'Hi'); |
---|
1812 | $temp_start = (int)(date('Ymd',$starttime)); |
---|
1813 | $temp_start_time = (int)(date('Hi',$starttime)); |
---|
1814 | $temp_end = (int)(date('Ymd',$endtime)); |
---|
1815 | $temp_end_time = (int)(date('Hi',$endtime)); |
---|
1816 | if($this->debug) |
---|
1817 | { |
---|
1818 | echo '<!-- Temp_Start: '.$temp_start.' -->'."\n"; |
---|
1819 | echo '<!-- Temp_End: '.$temp_end.' -->'."\n"; |
---|
1820 | } |
---|
1821 | |
---|
1822 | $users = Array(); |
---|
1823 | if(count($participants)) |
---|
1824 | { |
---|
1825 | while(list($user,$status) = each($participants)) |
---|
1826 | { |
---|
1827 | $users[] = $user; |
---|
1828 | } |
---|
1829 | } |
---|
1830 | else |
---|
1831 | { |
---|
1832 | $users[] = $this->owner; |
---|
1833 | } |
---|
1834 | |
---|
1835 | $possible_conflicts = $this->store_to_cache( |
---|
1836 | Array( |
---|
1837 | 'smonth' => substr(strval($temp_start),4,2), |
---|
1838 | 'sday' => substr(strval($temp_start),6,2), |
---|
1839 | 'syear' => substr(strval($temp_start),0,4), |
---|
1840 | 'emonth' => substr(strval($temp_end),4,2), |
---|
1841 | 'eday' => substr(strval($temp_end),6,2), |
---|
1842 | 'eyear' => substr(strval($temp_end),0,4), |
---|
1843 | 'owner' => $users |
---|
1844 | ) |
---|
1845 | ); |
---|
1846 | |
---|
1847 | if($this->debug) |
---|
1848 | { |
---|
1849 | echo '<!-- Possible Conflicts ('.($temp_start - 1).'): '.count($possible_conflicts[$temp_start - 1]).' -->'."\n"; |
---|
1850 | echo '<!-- Possible Conflicts ('.$temp_start.'): '.count($possible_conflicts[$temp_start]).' '.count($id).' -->'."\n"; |
---|
1851 | } |
---|
1852 | |
---|
1853 | if($possible_conflicts[$temp_start] || $possible_conflicts[$temp_end]) |
---|
1854 | { |
---|
1855 | if($temp_start == $temp_end) |
---|
1856 | { |
---|
1857 | if($this->debug) |
---|
1858 | { |
---|
1859 | echo '<!-- Temp_Start == Temp_End -->'."\n"; |
---|
1860 | } |
---|
1861 | @reset($possible_conflicts[$temp_start]); |
---|
1862 | while(list($key,$event) = each($possible_conflicts[$temp_start])) |
---|
1863 | { |
---|
1864 | $found = False; |
---|
1865 | if($id) |
---|
1866 | { |
---|
1867 | @reset($id); |
---|
1868 | while(list($key,$event_id) = each($id)) |
---|
1869 | { |
---|
1870 | if($this->debug) |
---|
1871 | { |
---|
1872 | echo '<!-- $id['.$key.'] = '.$id[$key].' = '.$event_id.' -->'."\n"; |
---|
1873 | echo '<!-- '.$event['id'].' == '.$event_id.' -->'."\n"; |
---|
1874 | } |
---|
1875 | if($event['id'] == $event_id) |
---|
1876 | { |
---|
1877 | $found = True; |
---|
1878 | } |
---|
1879 | } |
---|
1880 | } |
---|
1881 | if($this->debug) |
---|
1882 | { |
---|
1883 | echo '<!-- Item found: '.$found.' -->'."<br>\n"; |
---|
1884 | } |
---|
1885 | if(!$found) |
---|
1886 | { |
---|
1887 | if($this->debug) |
---|
1888 | { |
---|
1889 | echo '<!-- Checking event id #'.$event['id']; |
---|
1890 | } |
---|
1891 | $temp_event_start = sprintf("%d%02d",$event['start']['hour'],$event['start']['min']); |
---|
1892 | $temp_event_end = sprintf("%d%02d",$event['end']['hour'],$event['end']['min']); |
---|
1893 | // if((($temp_start_time <= $temp_event_start) && ($temp_end_time >= $temp_event_start) && ($temp_end_time <= $temp_event_end)) || |
---|
1894 | if(($temp_start_time <= $temp_event_start && |
---|
1895 | $temp_end_time > $temp_event_start && |
---|
1896 | $temp_end_time <= $temp_event_end || |
---|
1897 | $temp_start_time >= $temp_event_start && |
---|
1898 | $temp_start_time < $temp_event_end && |
---|
1899 | $temp_end_time >= $temp_event_end || |
---|
1900 | $temp_start_time <= $temp_event_start && |
---|
1901 | $temp_end_time >= $temp_event_end || |
---|
1902 | $temp_start_time >= $temp_event_start && |
---|
1903 | $temp_end_time <= $temp_event_end) && |
---|
1904 | $this->participants_not_rejected($participants,$event) && $this->participants_unanswered($participants,$event)) |
---|
1905 | { |
---|
1906 | if($this->debug) |
---|
1907 | { |
---|
1908 | echo ' Conflicts'; |
---|
1909 | } |
---|
1910 | $retval[] = $event['id']; |
---|
1911 | } |
---|
1912 | if($this->debug) |
---|
1913 | { |
---|
1914 | echo ' -->'."\n"; |
---|
1915 | } |
---|
1916 | } |
---|
1917 | } |
---|
1918 | } |
---|
1919 | } |
---|
1920 | else |
---|
1921 | { |
---|
1922 | $retval = False; |
---|
1923 | } |
---|
1924 | |
---|
1925 | if($restore_cache) |
---|
1926 | { |
---|
1927 | $this->cached_events = $temp_cache_events; |
---|
1928 | } |
---|
1929 | |
---|
1930 | return $retval; |
---|
1931 | } |
---|
1932 | |
---|
1933 | /*! |
---|
1934 | @function check_perms( ) |
---|
1935 | @syntax check_perms($needed,$event=0,$other=0) |
---|
1936 | @abstract Checks if the current user has the necessary ACL rights |
---|
1937 | @author ralfbecker |
---|
1938 | @discussion The check is performed on an event or general on the cal of an other user |
---|
1939 | @param $needed necessary ACL right: PHPGW_ACL_{READ|EDIT|DELETE} |
---|
1940 | @param $event event as array or the event-id or 0 for general check |
---|
1941 | @param $other uid to check (if event==0) or 0 to check against $this->owner |
---|
1942 | @note Participating in an event is considered as haveing read-access on that event, \ |
---|
1943 | even if you have no general read-grant from that user. |
---|
1944 | */ |
---|
1945 | function check_perms($needed,$event=0,$other=0) |
---|
1946 | { |
---|
1947 | $event_in = $event; |
---|
1948 | |
---|
1949 | if (is_int($event) && $event == 0) |
---|
1950 | { |
---|
1951 | $owner = $other > 0 ? $other : $this->owner; |
---|
1952 | } |
---|
1953 | else |
---|
1954 | { |
---|
1955 | if (!is_array($event)) |
---|
1956 | { |
---|
1957 | $event = $this->so->read_entry((int) $event); |
---|
1958 | } |
---|
1959 | if (!is_array($event)) |
---|
1960 | { |
---|
1961 | if ($this->xmlrpc) |
---|
1962 | { |
---|
1963 | $GLOBALS['server']->xmlrpc_error($GLOBALS['xmlrpcerr']['not_exist'],$GLOBALS['xmlrpcstr']['not_exist']); |
---|
1964 | } |
---|
1965 | return False; |
---|
1966 | } |
---|
1967 | $owner = $event['owner']; |
---|
1968 | $private = $event['public'] == False || $event['public'] == 0; |
---|
1969 | } |
---|
1970 | $user = $GLOBALS['phpgw_info']['user']['account_id']; |
---|
1971 | $grants = $this->grants[$owner]; |
---|
1972 | |
---|
1973 | if (is_array($event) && $needed == PHPGW_ACL_READ) |
---|
1974 | { |
---|
1975 | // Check if the $user is one of the participants or has a read-grant from one of them |
---|
1976 | // |
---|
1977 | foreach($event['participants'] as $uid => $accept) |
---|
1978 | { |
---|
1979 | if ($this->grants[$uid] & PHPGW_ACL_READ || $uid == $user) |
---|
1980 | { |
---|
1981 | $grants |= PHPGW_ACL_READ; |
---|
1982 | // if the $user is one of the participants read-grant private (restricted) too. |
---|
1983 | if($uid == $user || ($this->grants[$uid] & PHPGW_ACL_PRIVATE)) { |
---|
1984 | $grants |= PHPGW_ACL_PRIVATE; |
---|
1985 | } |
---|
1986 | //break; |
---|
1987 | } |
---|
1988 | } |
---|
1989 | } |
---|
1990 | |
---|
1991 | if ($GLOBALS['phpgw']->accounts->get_type($owner) == 'g' && $needed == PHPGW_ACL_ADD) |
---|
1992 | { |
---|
1993 | $access = False; // a group can't be the owner of an event |
---|
1994 | } |
---|
1995 | else |
---|
1996 | { |
---|
1997 | $access = $user == $owner || $grants & $needed && (!$private || $grants & PHPGW_ACL_PRIVATE); |
---|
1998 | } |
---|
1999 | //echo "<p>".function_backtrace()." check_perms($needed,$event_id,$other) for user $user and needed_acl $needed: event='$event[title]': owner=$owner, private=$private, grants=$grants ==> access=$access</p>\n"; |
---|
2000 | |
---|
2001 | return $access; |
---|
2002 | } |
---|
2003 | |
---|
2004 | |
---|
2005 | function display_status($user_status) |
---|
2006 | { |
---|
2007 | if(@$this->prefs['calendar']['display_status'] && $user_status) |
---|
2008 | { |
---|
2009 | $user_status = substr($this->get_long_status($user_status),0,1); |
---|
2010 | |
---|
2011 | return ' ('.$user_status.')'; |
---|
2012 | } |
---|
2013 | else |
---|
2014 | { |
---|
2015 | return ''; |
---|
2016 | } |
---|
2017 | } |
---|
2018 | |
---|
2019 | function get_long_status($status_short) |
---|
2020 | { |
---|
2021 | switch ($status_short) |
---|
2022 | { |
---|
2023 | case 'A': |
---|
2024 | $status = lang('Accepted'); |
---|
2025 | break; |
---|
2026 | case 'R': |
---|
2027 | $status = lang('Rejected'); |
---|
2028 | break; |
---|
2029 | case 'T': |
---|
2030 | $status = lang('Tentative'); |
---|
2031 | break; |
---|
2032 | case 'U': |
---|
2033 | $status = lang('No Response'); |
---|
2034 | break; |
---|
2035 | } |
---|
2036 | return $status; |
---|
2037 | } |
---|
2038 | |
---|
2039 | function is_private($event,$owner) |
---|
2040 | { |
---|
2041 | if($owner == 0) |
---|
2042 | { |
---|
2043 | $owner = $this->owner; |
---|
2044 | } |
---|
2045 | if ($owner == $GLOBALS['phpgw_info']['user']['account_id'] || ($event['public']==1) || ($this->check_perms(PHPGW_ACL_PRIVATE,$event) && $event['public']==0) || $event['owner'] == $GLOBALS['phpgw_info']['user']['account_id']) |
---|
2046 | { |
---|
2047 | return False; |
---|
2048 | } |
---|
2049 | elseif($event['public'] == 0) |
---|
2050 | { |
---|
2051 | return True; |
---|
2052 | } |
---|
2053 | elseif($event['public'] == 2) |
---|
2054 | { |
---|
2055 | $is_private = True; |
---|
2056 | $groups = $GLOBALS['phpgw']->accounts->membership($owner); |
---|
2057 | while (list($key,$group) = each($groups)) |
---|
2058 | { |
---|
2059 | if (strpos(' '.implode(',',$event['groups']).' ',$group['account_id'])) |
---|
2060 | { |
---|
2061 | return False; |
---|
2062 | } |
---|
2063 | } |
---|
2064 | } |
---|
2065 | else |
---|
2066 | { |
---|
2067 | return False; |
---|
2068 | } |
---|
2069 | |
---|
2070 | return $is_private; |
---|
2071 | } |
---|
2072 | |
---|
2073 | function get_short_field($event,$is_private=True,$field='') |
---|
2074 | { |
---|
2075 | if($is_private) |
---|
2076 | { |
---|
2077 | return lang('private'); |
---|
2078 | } |
---|
2079 | |
---|
2080 | // cut off too long titles |
---|
2081 | elseif(strlen($event[$field]) > 19 && !$this->printer_friendly && $field=="title") |
---|
2082 | // elseif(strlen($event[$field]) > 19 && $this->printer_friendly) |
---|
2083 | { |
---|
2084 | // we dont use currently 160304 |
---|
2085 | // return substr($event[$field], 0 , 19) . ' ...'; |
---|
2086 | return $event[$field]; |
---|
2087 | } |
---|
2088 | else |
---|
2089 | { |
---|
2090 | return $event[$field]; |
---|
2091 | } |
---|
2092 | } |
---|
2093 | |
---|
2094 | function long_date($first,$last=0) |
---|
2095 | { |
---|
2096 | if (!is_array($first)) |
---|
2097 | { |
---|
2098 | $first = $this->time2array($raw = $first); |
---|
2099 | $first['raw'] = $raw; |
---|
2100 | $first['day'] = $first['mday']; |
---|
2101 | } |
---|
2102 | if ($last && !is_array($last)) |
---|
2103 | { |
---|
2104 | $last = $this->time2array($raw = $last); |
---|
2105 | $last['raw'] = $raw; |
---|
2106 | $last['day'] = $last['mday']; |
---|
2107 | } |
---|
2108 | $datefmt = $this->prefs['common']['dateformat']; |
---|
2109 | |
---|
2110 | $month_before_day = strtolower($datefmt[0]) == 'm' || |
---|
2111 | strtolower($datefmt[2]) == 'm' && $datefmt[4] == 'd'; |
---|
2112 | |
---|
2113 | for ($i = 0; $i < 5; $i += 2) |
---|
2114 | { |
---|
2115 | switch($datefmt[$i]) |
---|
2116 | { |
---|
2117 | case 'd': |
---|
2118 | $range .= $first['day'] . ($datefmt[1] == '.' ? '.' : ''); |
---|
2119 | if ($first['month'] != $last['month'] || $first['year'] != $last['year']) |
---|
2120 | { |
---|
2121 | if (!$month_before_day) |
---|
2122 | { |
---|
2123 | $range .= ' '.lang(strftime('%B',$first['raw'])); |
---|
2124 | } |
---|
2125 | if ($first['year'] != $last['year'] && $datefmt[0] != 'Y') |
---|
2126 | { |
---|
2127 | $range .= ($datefmt[0] != 'd' ? ', ' : ' ') . $first['year']; |
---|
2128 | } |
---|
2129 | if (!$last) |
---|
2130 | { |
---|
2131 | return $range; |
---|
2132 | } |
---|
2133 | $range .= ' - '; |
---|
2134 | |
---|
2135 | if ($first['year'] != $last['year'] && $datefmt[0] == 'Y') |
---|
2136 | { |
---|
2137 | $range .= $last['year'] . ', '; |
---|
2138 | } |
---|
2139 | |
---|
2140 | if ($month_before_day) |
---|
2141 | { |
---|
2142 | $range .= lang(strftime('%B',$last['raw'])); |
---|
2143 | } |
---|
2144 | } |
---|
2145 | else |
---|
2146 | { |
---|
2147 | $range .= ' - '; |
---|
2148 | } |
---|
2149 | $range .= ' ' . $last['day'] . ($datefmt[1] == '.' ? '.' : ''); |
---|
2150 | break; |
---|
2151 | case 'm': |
---|
2152 | case 'M': |
---|
2153 | $range .= ' '.lang(strftime('%B',$month_before_day ? $first['raw'] : $last['raw'])) . ' '; |
---|
2154 | break; |
---|
2155 | case 'Y': |
---|
2156 | $range .= ($datefmt[0] == 'm' ? ', ' : ' ') . ($datefmt[0] == 'Y' ? $first['year'].($datefmt[2] == 'd' ? ', ' : ' ') : $last['year'].' '); |
---|
2157 | break; |
---|
2158 | } |
---|
2159 | } |
---|
2160 | return $range; |
---|
2161 | } |
---|
2162 | |
---|
2163 | function get_week_label() |
---|
2164 | { |
---|
2165 | $first = $GLOBALS['phpgw']->datetime->gmtdate($GLOBALS['phpgw']->datetime->get_weekday_start($this->year, $this->month, $this->day)); |
---|
2166 | $last = $GLOBALS['phpgw']->datetime->gmtdate($first['raw'] + 518400); |
---|
2167 | |
---|
2168 | return ($this->long_date($first,$last)); |
---|
2169 | } |
---|
2170 | |
---|
2171 | function normalizeminutes(&$minutes) |
---|
2172 | { |
---|
2173 | $hour = 0; |
---|
2174 | $min = (int)$minutes; |
---|
2175 | if($min >= 60) |
---|
2176 | { |
---|
2177 | $hour += $min / 60; |
---|
2178 | $min %= 60; |
---|
2179 | } |
---|
2180 | settype($minutes,'integer'); |
---|
2181 | $minutes = $min; |
---|
2182 | return $hour; |
---|
2183 | } |
---|
2184 | |
---|
2185 | function splittime($time,$follow_24_rule=True) |
---|
2186 | { |
---|
2187 | $temp = array('hour','minute','second','ampm'); |
---|
2188 | $time = strrev($time); |
---|
2189 | $second = (int)(strrev(substr($time,0,2))); |
---|
2190 | $minute = (int)(strrev(substr($time,2,2))); |
---|
2191 | $hour = (int)(strrev(substr($time,4))); |
---|
2192 | $hour += $this->normalizeminutes($minute); |
---|
2193 | $temp['second'] = $second; |
---|
2194 | $temp['minute'] = $minute; |
---|
2195 | $temp['hour'] = $hour; |
---|
2196 | $temp['ampm'] = ' '; |
---|
2197 | if($follow_24_rule == True) |
---|
2198 | { |
---|
2199 | if ($this->prefs['common']['timeformat'] == '24') |
---|
2200 | { |
---|
2201 | return $temp; |
---|
2202 | } |
---|
2203 | |
---|
2204 | $temp['ampm'] = 'am'; |
---|
2205 | |
---|
2206 | if ((int)$temp['hour'] > 12) |
---|
2207 | { |
---|
2208 | $temp['hour'] = (int)((int)$temp['hour'] - 12); |
---|
2209 | $temp['ampm'] = 'pm'; |
---|
2210 | } |
---|
2211 | elseif ((int)$temp['hour'] == 12) |
---|
2212 | { |
---|
2213 | $temp['ampm'] = 'pm'; |
---|
2214 | } |
---|
2215 | } |
---|
2216 | return $temp; |
---|
2217 | } |
---|
2218 | |
---|
2219 | function get_exception_array($exception_str='') |
---|
2220 | { |
---|
2221 | $exception = Array(); |
---|
2222 | if(strpos(' '.$exception_str,',')) |
---|
2223 | { |
---|
2224 | $exceptions = explode(',',$exception_str); |
---|
2225 | for($exception_count=0;$exception_count<count($exceptions);$exception_count++) |
---|
2226 | { |
---|
2227 | $exception[] = (int)$exceptions[$exception_count]; |
---|
2228 | } |
---|
2229 | } |
---|
2230 | elseif($exception_str != '') |
---|
2231 | { |
---|
2232 | $exception[] = (int)$exception_str; |
---|
2233 | } |
---|
2234 | return $exception; |
---|
2235 | } |
---|
2236 | |
---|
2237 | function build_time_for_display($fixed_time) |
---|
2238 | { |
---|
2239 | $time = $this->splittime($fixed_time); |
---|
2240 | $str = $time['hour'].':'.((int)$time['minute']<=9?'0':'').$time['minute']; |
---|
2241 | |
---|
2242 | if ($this->prefs['common']['timeformat'] == '12') |
---|
2243 | { |
---|
2244 | $str .= ' ' . $time['ampm']; |
---|
2245 | } |
---|
2246 | |
---|
2247 | return $str; |
---|
2248 | } |
---|
2249 | |
---|
2250 | function sort_event($event,$date) |
---|
2251 | { |
---|
2252 | $inserted = False; |
---|
2253 | if(isset($event['recur_exception'])) |
---|
2254 | { |
---|
2255 | $event_time = mktime($event['start']['hour'],$event['start']['min'],0,(int)(substr($date,4,2)),(int)(substr($date,6,2)),(int)(substr($date,0,4))) - $GLOBALS['phpgw']->datetime->tz_offset; |
---|
2256 | while($inserted == False && list($key,$exception_time) = each($event['recur_exception'])) |
---|
2257 | { |
---|
2258 | if($this->debug) |
---|
2259 | { |
---|
2260 | echo '<!-- checking exception datetime '.$exception_time.' to event datetime '.$event_time.' -->'."\n"; |
---|
2261 | } |
---|
2262 | if($exception_time == $event_time) |
---|
2263 | { |
---|
2264 | $inserted = True; |
---|
2265 | } |
---|
2266 | } |
---|
2267 | } |
---|
2268 | if($this->cached_events[$date] && $inserted == False) |
---|
2269 | { |
---|
2270 | |
---|
2271 | if($this->debug) |
---|
2272 | { |
---|
2273 | echo '<!-- Cached Events found for '.$date.' -->'."\n"; |
---|
2274 | } |
---|
2275 | $year = substr($date,0,4); |
---|
2276 | $month = substr($date,4,2); |
---|
2277 | $day = substr($date,6,2); |
---|
2278 | |
---|
2279 | if($this->debug) |
---|
2280 | { |
---|
2281 | echo '<!-- Date : '.$date.' Count : '.count($this->cached_events[$date]).' -->'."\n"; |
---|
2282 | } |
---|
2283 | |
---|
2284 | for($i=0;$i<count($this->cached_events[$date]);$i++) |
---|
2285 | { |
---|
2286 | if($this->cached_events[$date][$i]['id'] == $event['id'] || $this->cached_events[$date][$i]['reference'] == $event['id']) |
---|
2287 | { |
---|
2288 | if($this->debug) |
---|
2289 | { |
---|
2290 | echo '<!-- Item already inserted! -->'."\n"; |
---|
2291 | } |
---|
2292 | $inserted = True; |
---|
2293 | break; |
---|
2294 | } |
---|
2295 | /* This puts all spanning events across multiple days up at the top. */ |
---|
2296 | if($this->cached_events[$date][$i]['recur_type'] == MCAL_RECUR_NONE) |
---|
2297 | { |
---|
2298 | if($this->cached_events[$date][$i]['start']['mday'] != $day && $this->cached_events[$date][$i]['end']['mday'] >= $day) |
---|
2299 | { |
---|
2300 | continue; |
---|
2301 | } |
---|
2302 | } |
---|
2303 | if(date('Hi',mktime($event['start']['hour'],$event['start']['min'],$event['start']['sec'],$month,$day,$year)) < date('Hi',mktime($this->cached_events[$date][$i]['start']['hour'],$this->cached_events[$date][$i]['start']['min'],$this->cached_events[$date][$i]['start']['sec'],$month,$day,$year))) |
---|
2304 | { |
---|
2305 | for($j=count($this->cached_events[$date]);$j>=$i;$j--) |
---|
2306 | { |
---|
2307 | $this->cached_events[$date][$j] = $this->cached_events[$date][$j-1]; |
---|
2308 | } |
---|
2309 | if($this->debug) |
---|
2310 | { |
---|
2311 | echo '<!-- Adding event ID: '.$event['id'].' to cached_events -->'."\n"; |
---|
2312 | } |
---|
2313 | $inserted = True; |
---|
2314 | $this->cached_events[$date][$i] = $event; |
---|
2315 | break; |
---|
2316 | } |
---|
2317 | } |
---|
2318 | } |
---|
2319 | if(!$inserted) |
---|
2320 | { |
---|
2321 | if($this->debug) |
---|
2322 | { |
---|
2323 | echo '<!-- Adding event ID: '.$event['id'].' to cached_events -->'."\n"; |
---|
2324 | } |
---|
2325 | $this->cached_events[$date][] = $event; |
---|
2326 | } |
---|
2327 | } |
---|
2328 | |
---|
2329 | function check_repeating_events($datetime) |
---|
2330 | { |
---|
2331 | @reset($this->repeating_events); |
---|
2332 | $search_date_full = date('Ymd',$datetime); |
---|
2333 | $search_date_year = date('Y',$datetime); |
---|
2334 | $search_date_month = date('m',$datetime); |
---|
2335 | $search_date_day = date('d',$datetime); |
---|
2336 | $search_date_dow = date('w',$datetime); |
---|
2337 | $search_beg_day = mktime(12,0,0,$search_date_month,$search_date_day,$search_date_year); |
---|
2338 | if($this->debug) |
---|
2339 | { |
---|
2340 | echo '<!-- Search Date Full = '.$search_date_full.' -->'."\n"; |
---|
2341 | } |
---|
2342 | $repeated = $this->repeating_events; |
---|
2343 | $r_events = count($repeated); |
---|
2344 | for ($i=0;$i<$r_events;$i++) |
---|
2345 | { |
---|
2346 | $rep_events = $this->repeating_events[$i]; |
---|
2347 | $id = $rep_events['id']; |
---|
2348 | $event_beg_day = mktime(0,0,0,$rep_events['start']['month'],$rep_events['start']['mday'],$rep_events['start']['year']); |
---|
2349 | if($rep_events['recur_enddate']['month'] != 0 && $rep_events['recur_enddate']['mday'] != 0 && $rep_events['recur_enddate']['year'] != 0) |
---|
2350 | { |
---|
2351 | $event_recur_time = $this->maketime($rep_events['recur_enddate']); |
---|
2352 | } |
---|
2353 | else |
---|
2354 | { |
---|
2355 | $event_recur_time = mktime(0,0,0,1,1,2030); |
---|
2356 | } |
---|
2357 | $end_recur_date = date('Ymd',$event_recur_time); |
---|
2358 | $full_event_date = date('Ymd',$event_beg_day); |
---|
2359 | |
---|
2360 | if($this->debug) |
---|
2361 | { |
---|
2362 | echo '<!-- check_repeating_events - Processing ID - '.$id.' -->'."\n"; |
---|
2363 | echo '<!-- check_repeating_events - Recurring End Date - '.$end_recur_date.' -->'."\n"; |
---|
2364 | } |
---|
2365 | |
---|
2366 | // only repeat after the beginning, and if there is an rpt_end before the end date |
---|
2367 | if (($search_date_full > $end_recur_date) || ($search_date_full < $full_event_date)) |
---|
2368 | { |
---|
2369 | continue; |
---|
2370 | } |
---|
2371 | |
---|
2372 | if ($search_date_full == $full_event_date) |
---|
2373 | { |
---|
2374 | $this->sort_event($rep_events,$search_date_full); |
---|
2375 | continue; |
---|
2376 | } |
---|
2377 | else |
---|
2378 | { |
---|
2379 | $freq = $rep_events['recur_interval']; |
---|
2380 | $freq = $freq ? $freq : 1; |
---|
2381 | $type = $rep_events['recur_type']; |
---|
2382 | switch($type) |
---|
2383 | { |
---|
2384 | case MCAL_RECUR_DAILY: |
---|
2385 | if($this->debug) |
---|
2386 | { |
---|
2387 | echo '<!-- check_repeating_events - MCAL_RECUR_DAILY - '.$id.' -->'."\n"; |
---|
2388 | } |
---|
2389 | |
---|
2390 | if ($freq == 1 && $rep_events['recur_enddate']['month'] != 0 && $rep_events['recur_enddate']['mday'] != 0 && $rep_events['recur_enddate']['year'] != 0 && $search_date_full <= $end_recur_date) |
---|
2391 | { |
---|
2392 | $this->sort_event($rep_events,$search_date_full); |
---|
2393 | } |
---|
2394 | elseif (floor(($search_beg_day - $event_beg_day)/86400) % ($freq ? $freq : 1)) |
---|
2395 | { |
---|
2396 | continue; |
---|
2397 | } |
---|
2398 | else |
---|
2399 | { |
---|
2400 | $this->sort_event($rep_events,$search_date_full); |
---|
2401 | } |
---|
2402 | break; |
---|
2403 | case MCAL_RECUR_WEEKLY: |
---|
2404 | if (floor(($search_beg_day - $event_beg_day)/604800) % ($freq ? $freq : 1)) |
---|
2405 | { |
---|
2406 | continue; |
---|
2407 | } |
---|
2408 | $check = 0; |
---|
2409 | switch($search_date_dow) |
---|
2410 | { |
---|
2411 | case 0: |
---|
2412 | $check = MCAL_M_SUNDAY; |
---|
2413 | break; |
---|
2414 | case 1: |
---|
2415 | $check = MCAL_M_MONDAY; |
---|
2416 | break; |
---|
2417 | case 2: |
---|
2418 | $check = MCAL_M_TUESDAY; |
---|
2419 | break; |
---|
2420 | case 3: |
---|
2421 | $check = MCAL_M_WEDNESDAY; |
---|
2422 | break; |
---|
2423 | case 4: |
---|
2424 | $check = MCAL_M_THURSDAY; |
---|
2425 | break; |
---|
2426 | case 5: |
---|
2427 | $check = MCAL_M_FRIDAY; |
---|
2428 | break; |
---|
2429 | case 6: |
---|
2430 | $check = MCAL_M_SATURDAY; |
---|
2431 | break; |
---|
2432 | } |
---|
2433 | if ($rep_events['recur_data'] & $check) |
---|
2434 | { |
---|
2435 | $this->sort_event($rep_events,$search_date_full); |
---|
2436 | } |
---|
2437 | break; |
---|
2438 | case MCAL_RECUR_MONTHLY_WDAY: |
---|
2439 | if ((($search_date_year - $rep_events['start']['year']) * 12 + $search_date_month - $rep_events['start']['month']) % $freq) |
---|
2440 | { |
---|
2441 | continue; |
---|
2442 | } |
---|
2443 | |
---|
2444 | if (($GLOBALS['phpgw']->datetime->day_of_week($rep_events['start']['year'],$rep_events['start']['month'],$rep_events['start']['mday']) == $GLOBALS['phpgw']->datetime->day_of_week($search_date_year,$search_date_month,$search_date_day)) && |
---|
2445 | (ceil($rep_events['start']['mday']/7) == ceil($search_date_day/7))) |
---|
2446 | { |
---|
2447 | $this->sort_event($rep_events,$search_date_full); |
---|
2448 | } |
---|
2449 | break; |
---|
2450 | case MCAL_RECUR_MONTHLY_MDAY: |
---|
2451 | if ((($search_date_year - $rep_events['start']['year']) * 12 + $search_date_month - $rep_events['start']['month']) % ($freq ? $freq : 1)) |
---|
2452 | { |
---|
2453 | continue; |
---|
2454 | } |
---|
2455 | if ($search_date_day == $rep_events['start']['mday']) |
---|
2456 | { |
---|
2457 | $this->sort_event($rep_events,$search_date_full); |
---|
2458 | } |
---|
2459 | break; |
---|
2460 | case MCAL_RECUR_YEARLY: |
---|
2461 | if (($search_date_year - $rep_events['start']['year']) % ($freq ? $freq : 1)) |
---|
2462 | { |
---|
2463 | continue; |
---|
2464 | } |
---|
2465 | if (date('dm',$datetime) == date('dm',$event_beg_day)) |
---|
2466 | { |
---|
2467 | $this->sort_event($rep_events,$search_date_full); |
---|
2468 | } |
---|
2469 | break; |
---|
2470 | } |
---|
2471 | } |
---|
2472 | } // end for loop |
---|
2473 | } // end function |
---|
2474 | |
---|
2475 | function store_to_cache($params) |
---|
2476 | { |
---|
2477 | if(!is_array($params)) |
---|
2478 | { |
---|
2479 | return False; |
---|
2480 | } |
---|
2481 | if (isset($params['start']) && ($datearr = $GLOBALS['server']->iso86012date($params['start']))) |
---|
2482 | { |
---|
2483 | $syear = $datearr['year']; |
---|
2484 | $smonth = $datearr['month']; |
---|
2485 | $sday = $datearr['mday']; |
---|
2486 | $this->xmlrpc = True; |
---|
2487 | } |
---|
2488 | else |
---|
2489 | { |
---|
2490 | $syear = $params['syear']; |
---|
2491 | $smonth = $params['smonth']; |
---|
2492 | $sday = $params['sday']; |
---|
2493 | } |
---|
2494 | if (isset($params['end']) && ($datearr = $GLOBALS['server']->iso86012date($params['end']))) |
---|
2495 | { |
---|
2496 | $eyear = $datearr['year']; |
---|
2497 | $emonth = $datearr['month']; |
---|
2498 | $eday = $datearr['mday']; |
---|
2499 | $this->xmlrpc = True; |
---|
2500 | } |
---|
2501 | else |
---|
2502 | { |
---|
2503 | $eyear = (isset($params['eyear'])?$params['eyear']:0); |
---|
2504 | $emonth = (isset($params['emonth'])?$params['emonth']:0); |
---|
2505 | $eday = (isset($params['eday'])?$params['eday']:0); |
---|
2506 | } |
---|
2507 | if (!isset($params['owner']) && @$this->xmlrpc) |
---|
2508 | { |
---|
2509 | $owner_id = $GLOBALS['phpgw_info']['user']['user_id']; |
---|
2510 | } |
---|
2511 | else |
---|
2512 | { |
---|
2513 | $owner_id = (isset($params['owner'])?$params['owner']:0); |
---|
2514 | if($owner_id==0 && $this->is_group) |
---|
2515 | { |
---|
2516 | unset($owner_id); |
---|
2517 | $owner_id = $this->g_owner; |
---|
2518 | if($this->debug) |
---|
2519 | { |
---|
2520 | echo '<!-- owner_id in ('.implode(',',$owner_id).') -->'."\n"; |
---|
2521 | } |
---|
2522 | } |
---|
2523 | } |
---|
2524 | if(!$eyear && !$emonth && !$eday) |
---|
2525 | { |
---|
2526 | $edate = mktime(23,59,59,$smonth + 1,$sday + 1,$syear); |
---|
2527 | $eyear = date('Y',$edate); |
---|
2528 | $emonth = date('m',$edate); |
---|
2529 | $eday = date('d',$edate); |
---|
2530 | } |
---|
2531 | else |
---|
2532 | { |
---|
2533 | if(!$eyear) |
---|
2534 | { |
---|
2535 | $eyear = $syear; |
---|
2536 | } |
---|
2537 | //Tratamento do valor final (mes) da pesquisa de eventos feita em $this->so->list_events. |
---|
2538 | //Se $emonth nao tem valor, recebe o valor de $smonth (que recebe $params['smonth']) e soma 1. |
---|
2539 | //O valor $params['emonth'] indica o mes final para a pesquisa de eventos, e passou a ser |
---|
2540 | //informado na a impressao de eventos mensais. Mudancas feitas em class.uicalendar.inc.php, |
---|
2541 | //function display_month_print(); |
---|
2542 | if(!$emonth) |
---|
2543 | { |
---|
2544 | $emonth = $smonth + 1; |
---|
2545 | if($emonth > 12) |
---|
2546 | { |
---|
2547 | $emonth = 1; |
---|
2548 | $eyear++; |
---|
2549 | } |
---|
2550 | } |
---|
2551 | if(!$eday) |
---|
2552 | { |
---|
2553 | $eday = $sday + 1; |
---|
2554 | } |
---|
2555 | $edate = mktime(23,59,59,$emonth,$eday,$eyear); |
---|
2556 | } |
---|
2557 | //echo "<p>bocalendar::store_to_cache(".print_r($params,True).") syear=$syear, smonth=$smonth, sday=$sday, eyear=$eyear, emonth=$emonth, eday=$eday, xmlrpc='$param[xmlrpc]'</p>\n"; |
---|
2558 | if($this->debug) |
---|
2559 | { |
---|
2560 | echo '<!-- Start Date : '.sprintf("%04d%02d%02d",$syear,$smonth,$sday).' -->'."\n"; |
---|
2561 | echo '<!-- End Date : '.sprintf("%04d%02d%02d",$eyear,$emonth,$eday).' -->'."\n"; |
---|
2562 | } |
---|
2563 | //A variavel $month_print recebe o parametro 'saux' com o mes de inicio da pesquisa de eventos por |
---|
2564 | //$this->so->list_events. O valor do mes final da pesquisa e tratado no codigo acima; |
---|
2565 | //$month_ini = $params['saux']; |
---|
2566 | |
---|
2567 | if($owner_id) |
---|
2568 | { |
---|
2569 | $cached_event_ids = $this->so->list_events($syear,$smonth,$sday,$eyear,$emonth,$eday,$owner_id); |
---|
2570 | $cached_event_ids_repeating = $this->so->list_repeated_events($syear,$smonth,$sday,$eyear,$emonth,$eday,$owner_id); |
---|
2571 | } |
---|
2572 | else |
---|
2573 | { |
---|
2574 | $cached_event_ids = $this->so->list_events($syear,$smonth,$sday,$eyear,$emonth,$eday); |
---|
2575 | $cached_event_ids_repeating = $this->so->list_repeated_events($syear,$smonth,$sday,$eyear,$emonth,$eday); |
---|
2576 | } |
---|
2577 | |
---|
2578 | $c_cached_ids = count($cached_event_ids); |
---|
2579 | $c_cached_ids_repeating = count($cached_event_ids_repeating); |
---|
2580 | |
---|
2581 | if($this->debug) |
---|
2582 | { |
---|
2583 | echo '<!-- events cached : '.$c_cached_ids.' : for : '.sprintf("%04d%02d%02d",$syear,$smonth,$sday).' -->'."\n"; |
---|
2584 | echo '<!-- repeating events cached : '.$c_cached_ids_repeating.' : for : '.sprintf("%04d%02d%02d",$syear,$smonth,$sday).' -->'."\n"; |
---|
2585 | } |
---|
2586 | |
---|
2587 | $this->cached_events = Array(); |
---|
2588 | |
---|
2589 | if($c_cached_ids == 0 && $c_cached_ids_repeating == 0) |
---|
2590 | { |
---|
2591 | return; |
---|
2592 | } |
---|
2593 | |
---|
2594 | $cache_start = (int)(sprintf("%04d%02d%02d",$syear,$smonth,$sday)); |
---|
2595 | $cached_event=$this->get_cached_event(); |
---|
2596 | if($c_cached_ids) |
---|
2597 | { |
---|
2598 | for($i=0;$i<$c_cached_ids;$i++) |
---|
2599 | { |
---|
2600 | $event = $this->so->read_entry($cached_event_ids[$i]); |
---|
2601 | if ($event['recur_type']) |
---|
2602 | { |
---|
2603 | continue; // fetch recuring events only in 2. loop |
---|
2604 | } |
---|
2605 | $startdate = (int)(date('Ymd',$this->maketime($event['start']))); |
---|
2606 | $enddate = (int)(date('Ymd',$this->maketime($event['end']))); |
---|
2607 | $this->cached_events[$startdate][] = $event; |
---|
2608 | if($startdate != $enddate) |
---|
2609 | { |
---|
2610 | $start['year'] = (int)(substr($startdate,0,4)); |
---|
2611 | $start['month'] = (int)(substr($startdate,4,2)); |
---|
2612 | $start['mday'] = (int)(substr($startdate,6,2)); |
---|
2613 | for($j=$startdate,$k=0;$j<=$enddate;$k++,$j=(int)(date('Ymd',mktime(0,0,0,$start['month'],$start['mday'] + $k,$start['year'])))) |
---|
2614 | { |
---|
2615 | $c_evt_day = count($this->cached_events[$j]) - 1; |
---|
2616 | if($c_evt_day < 0) |
---|
2617 | { |
---|
2618 | $c_evt_day = 0; |
---|
2619 | } |
---|
2620 | if($this->debug) |
---|
2621 | { |
---|
2622 | echo '<!-- Date: '.$j.' Count : '.$c_evt_day.' -->'."\n"; |
---|
2623 | } |
---|
2624 | if($this->cached_events[$j][$c_evt_day]['id'] != $event['id']) |
---|
2625 | { |
---|
2626 | if($this->debug) |
---|
2627 | { |
---|
2628 | echo '<!-- Adding Event for Date: '.$j.' -->'."\n"; |
---|
2629 | } |
---|
2630 | $this->cached_events[$j][] = $event; |
---|
2631 | } |
---|
2632 | if ($j >= $cache_start && (@$params['no_doubles'] || @$this->xmlrpc)) |
---|
2633 | { |
---|
2634 | break; // add event only once on it's startdate |
---|
2635 | } |
---|
2636 | } |
---|
2637 | } |
---|
2638 | } |
---|
2639 | } |
---|
2640 | |
---|
2641 | $this->repeating_events = Array(); |
---|
2642 | if($c_cached_ids_repeating) |
---|
2643 | { |
---|
2644 | for($i=0;$i<$c_cached_ids_repeating;$i++) |
---|
2645 | { |
---|
2646 | $this->repeating_events[$i] = $this->so->read_entry($cached_event_ids_repeating[$i]); |
---|
2647 | if($this->debug) |
---|
2648 | { |
---|
2649 | echo '<!-- Cached Events ID: '.$cached_event_ids_repeating[$i].' ('.sprintf("%04d%02d%02d",$this->repeating_events[$i]['start']['year'],$this->repeating_events[$i]['start']['month'],$this->repeating_events[$i]['start']['mday']).') -->'."\n"; |
---|
2650 | } |
---|
2651 | } |
---|
2652 | for($date=mktime(0,0,0,$smonth,$sday,$syear);$date<=$edate;$date += 86400) |
---|
2653 | { |
---|
2654 | if($this->debug) |
---|
2655 | { |
---|
2656 | $search_date = date('Ymd',$date); |
---|
2657 | echo '<!-- Calling check_repeating_events('.$search_date.') -->'."\n"; |
---|
2658 | } |
---|
2659 | $this->check_repeating_events($date); |
---|
2660 | if($this->debug) |
---|
2661 | { |
---|
2662 | echo '<!-- Total events found matching '.$search_date.' = '.count($this->cached_events[$search_date]).' -->'."\n"; |
---|
2663 | for($i=0;$i<count($this->cached_events[$search_date]);$i++) |
---|
2664 | { |
---|
2665 | echo '<!-- Date: '.$search_date.' ['.$i.'] = '.$this->cached_events[$search_date][$i]['id'].' -->'."\n"; |
---|
2666 | } |
---|
2667 | } |
---|
2668 | } |
---|
2669 | } |
---|
2670 | $retval = Array(); |
---|
2671 | for($j=date('Ymd',mktime(0,0,0,$smonth,$sday,$syear)),$k=0;$j<=date('Ymd',mktime(0,0,0,$emonth,$eday,$eyear));$k++,$j=date('Ymd',mktime(0,0,0,$smonth,$sday + $k,$syear))) |
---|
2672 | { |
---|
2673 | if(is_array($this->cached_events[$j])) |
---|
2674 | { |
---|
2675 | if ($this->xmlrpc) |
---|
2676 | { |
---|
2677 | foreach($this->cached_events[$j] as $event) |
---|
2678 | { |
---|
2679 | $retval[] = $this->xmlrpc_prepare($event); |
---|
2680 | } |
---|
2681 | } |
---|
2682 | else |
---|
2683 | { |
---|
2684 | $retval[$j] = $this->cached_events[$j]; |
---|
2685 | } |
---|
2686 | } |
---|
2687 | } |
---|
2688 | //echo "store_to_cache(".print_r($params,True).")=<pre>".print_r($retval,True)."</pre>\n"; |
---|
2689 | $this->so->cal->event = $cached_event; |
---|
2690 | return $retval; |
---|
2691 | } |
---|
2692 | |
---|
2693 | function xmlrpc_prepare(&$event) |
---|
2694 | { |
---|
2695 | $event['rights'] = $this->grants[$event['owner']]; |
---|
2696 | |
---|
2697 | foreach(array('start','end','modtime','recur_enddate') as $name) |
---|
2698 | { |
---|
2699 | if (isset($event[$name])) |
---|
2700 | { |
---|
2701 | $event[$name] = $GLOBALS['server']->date2iso8601($event[$name]); |
---|
2702 | } |
---|
2703 | } |
---|
2704 | if (is_array($event['recur_exception'])) |
---|
2705 | { |
---|
2706 | foreach($event['recur_exception'] as $key => $timestamp) |
---|
2707 | { |
---|
2708 | $event['recur_exception'][$key] = $GLOBALS['server']->date2iso8601($timestamp); |
---|
2709 | } |
---|
2710 | } |
---|
2711 | static $user_cache = array(); |
---|
2712 | |
---|
2713 | if (!is_object($GLOBALS['phpgw']->perferences)) |
---|
2714 | { |
---|
2715 | $GLOBALS['phpgw']->perferences = CreateObject('phpgwapi.preferences'); |
---|
2716 | } |
---|
2717 | foreach($event['participants'] as $user_id => $status) |
---|
2718 | { |
---|
2719 | if (!isset($user_cache[$user_id])) |
---|
2720 | { |
---|
2721 | $user_cache[$user_id] = array( |
---|
2722 | 'name' => $GLOBALS['phpgw']->common->grab_owner_name($user_id), |
---|
2723 | 'email' => $GLOBALS['phpgw']->perferences->email_address($user_id) |
---|
2724 | ); |
---|
2725 | } |
---|
2726 | $event['participants'][$user_id] = $user_cache[$user_id] + array( |
---|
2727 | 'status' => $status, |
---|
2728 | ); |
---|
2729 | } |
---|
2730 | if (is_array($event['alarm'])) |
---|
2731 | { |
---|
2732 | foreach($event['alarm'] as $id => $alarm) |
---|
2733 | { |
---|
2734 | $event['alarm'][$id]['time'] = $GLOBALS['server']->date2iso8601($alarm['time']); |
---|
2735 | if ($alarm['owner'] != $GLOBALS['phpgw_info']['user']['account_id']) |
---|
2736 | { |
---|
2737 | unset($event['alarm'][$id]); |
---|
2738 | } |
---|
2739 | } |
---|
2740 | } |
---|
2741 | $event['category'] = $GLOBALS['server']->cats2xmlrpc(explode(',',$event['category'])); |
---|
2742 | |
---|
2743 | // using access={public|privat} in all modules via xmlrpc |
---|
2744 | $event['access'] = $event['public'] ? 'public' : 'privat'; |
---|
2745 | unset($event['public']); |
---|
2746 | |
---|
2747 | return $event; |
---|
2748 | } |
---|
2749 | |
---|
2750 | /* Begin Appsession Data */ |
---|
2751 | function store_to_appsession($event) |
---|
2752 | { |
---|
2753 | $GLOBALS['phpgw']->session->appsession('entry','calendar',$event); |
---|
2754 | } |
---|
2755 | |
---|
2756 | function restore_from_appsession() |
---|
2757 | { |
---|
2758 | $this->event_init(); |
---|
2759 | $event = $GLOBALS['phpgw']->session->appsession('entry','calendar'); |
---|
2760 | $this->so->cal->event = $event; |
---|
2761 | return $event; |
---|
2762 | } |
---|
2763 | /* End Appsession Data */ |
---|
2764 | |
---|
2765 | /* Begin of SO functions */ |
---|
2766 | function get_cached_event() |
---|
2767 | { |
---|
2768 | return $this->so->get_cached_event(); |
---|
2769 | } |
---|
2770 | |
---|
2771 | function add_attribute($var,$value,$index='**(**') |
---|
2772 | { |
---|
2773 | $this->so->add_attribute($var,$value,$index); |
---|
2774 | } |
---|
2775 | |
---|
2776 | function event_init() |
---|
2777 | { |
---|
2778 | $this->so->event_init(); |
---|
2779 | } |
---|
2780 | |
---|
2781 | function set_start($year,$month,$day=0,$hour=0,$min=0,$sec=0) |
---|
2782 | { |
---|
2783 | $this->so->set_start($year,$month,$day,$hour,$min,$sec); |
---|
2784 | } |
---|
2785 | |
---|
2786 | function set_end($year,$month,$day=0,$hour=0,$min=0,$sec=0) |
---|
2787 | { |
---|
2788 | $this->so->set_end($year,$month,$day,$hour,$min,$sec); |
---|
2789 | } |
---|
2790 | |
---|
2791 | function set_title($title='') |
---|
2792 | { |
---|
2793 | $this->so->set_title($title); |
---|
2794 | } |
---|
2795 | |
---|
2796 | function set_description($description='') |
---|
2797 | { |
---|
2798 | $this->so->set_description($description); |
---|
2799 | } |
---|
2800 | function set_ex_participants($ex_participants='') |
---|
2801 | { |
---|
2802 | $this->so->set_ex_participants($ex_participants); |
---|
2803 | } |
---|
2804 | |
---|
2805 | function set_class($class) |
---|
2806 | { |
---|
2807 | $this->so->set_class($class); |
---|
2808 | } |
---|
2809 | |
---|
2810 | function set_category($category='') |
---|
2811 | { |
---|
2812 | $this->so->set_category($category); |
---|
2813 | } |
---|
2814 | |
---|
2815 | function set_alarm($alarm) |
---|
2816 | { |
---|
2817 | $this->so->set_alarm($alarm); |
---|
2818 | } |
---|
2819 | |
---|
2820 | function set_recur_none() |
---|
2821 | { |
---|
2822 | $this->so->set_recur_none(); |
---|
2823 | } |
---|
2824 | |
---|
2825 | function set_recur_daily($year,$month,$day,$interval) |
---|
2826 | { |
---|
2827 | $this->so->set_recur_daily($year,$month,$day,$interval); |
---|
2828 | } |
---|
2829 | |
---|
2830 | function set_recur_weekly($year,$month,$day,$interval,$weekdays) |
---|
2831 | { |
---|
2832 | $this->so->set_recur_weekly($year,$month,$day,$interval,$weekdays); |
---|
2833 | } |
---|
2834 | |
---|
2835 | function set_recur_monthly_mday($year,$month,$day,$interval) |
---|
2836 | { |
---|
2837 | $this->so->set_recur_monthly_mday($year,$month,$day,$interval); |
---|
2838 | } |
---|
2839 | |
---|
2840 | function set_recur_monthly_wday($year,$month,$day,$interval) |
---|
2841 | { |
---|
2842 | $this->so->set_recur_monthly_wday($year,$month,$day,$interval); |
---|
2843 | } |
---|
2844 | |
---|
2845 | function set_recur_yearly($year,$month,$day,$interval) |
---|
2846 | { |
---|
2847 | $this->so->set_recur_yearly($year,$month,$day,$interval); |
---|
2848 | } |
---|
2849 | /* End of SO functions */ |
---|
2850 | |
---|
2851 | function prepare_matrix($interval,$increment,$part,$fulldate) |
---|
2852 | { |
---|
2853 | for($h=0;$h<24;$h++) |
---|
2854 | { |
---|
2855 | for($m=0;$m<$interval;$m++) |
---|
2856 | { |
---|
2857 | $index = (($h * 10000) + (($m * $increment) * 100)); |
---|
2858 | $time_slice[$index]['marker'] = ' '; |
---|
2859 | $time_slice[$index]['description'] = ''; |
---|
2860 | } |
---|
2861 | } |
---|
2862 | foreach($this->cached_events[$fulldate] as $event) |
---|
2863 | { |
---|
2864 | if ($event['participants'][$part] == 'R') |
---|
2865 | { |
---|
2866 | continue; // dont show rejected invitations, as they are free time |
---|
2867 | } |
---|
2868 | $eventstart = $GLOBALS['phpgw']->datetime->localdates($this->maketime($event['start']) - $GLOBALS['phpgw']->datetime->tz_offset); |
---|
2869 | $eventend = $GLOBALS['phpgw']->datetime->localdates($this->maketime($event['end']) - $GLOBALS['phpgw']->datetime->tz_offset); |
---|
2870 | $start = ($eventstart['hour'] * 10000) + ($eventstart['minute'] * 100); |
---|
2871 | $starttemp = $this->splittime("$start",False); |
---|
2872 | $subminute = 0; |
---|
2873 | for($m=0;$m<$interval;$m++) |
---|
2874 | { |
---|
2875 | $minutes = $increment * $m; |
---|
2876 | if((int)$starttemp['minute'] > $minutes && (int)$starttemp['minute'] < ($minutes + $increment)) |
---|
2877 | { |
---|
2878 | $subminute = ($starttemp['minute'] - $minutes) * 100; |
---|
2879 | } |
---|
2880 | } |
---|
2881 | $start -= $subminute; |
---|
2882 | $end = ($eventend['hour'] * 10000) + ($eventend['minute'] * 100); |
---|
2883 | $endtemp = $this->splittime("$end",False); |
---|
2884 | $addminute = 0; |
---|
2885 | for($m=0;$m<$interval;$m++) |
---|
2886 | { |
---|
2887 | $minutes = ($increment * $m); |
---|
2888 | if($endtemp['minute'] < ($minutes + $increment) && $endtemp['minute'] > $minutes) |
---|
2889 | { |
---|
2890 | $addminute = ($minutes + $increment - $endtemp['minute']) * 100; |
---|
2891 | } |
---|
2892 | } |
---|
2893 | $end += $addminute; |
---|
2894 | $starttemp = $this->splittime("$start",False); |
---|
2895 | $endtemp = $this->splittime("$end",False); |
---|
2896 | |
---|
2897 | for($h=$starttemp['hour'];$h<=$endtemp['hour'];$h++) |
---|
2898 | { |
---|
2899 | $startminute = 0; |
---|
2900 | $endminute = $interval; |
---|
2901 | $hour = $h * 10000; |
---|
2902 | if($h == (int)$starttemp['hour']) |
---|
2903 | { |
---|
2904 | $startminute = ($starttemp['minute'] / $increment); |
---|
2905 | } |
---|
2906 | if($h == (int)$endtemp['hour']) |
---|
2907 | { |
---|
2908 | $endminute = ($endtemp['minute'] / $increment); |
---|
2909 | } |
---|
2910 | $private = $this->is_private($event,$part); |
---|
2911 | $time_display = $GLOBALS['phpgw']->common->show_date($eventstart['raw'],$this->users_timeformat).'-'.$GLOBALS['phpgw']->common->show_date($eventend['raw'],$this->users_timeformat); |
---|
2912 | $time_description = '('.$time_display.') '.$this->get_short_field($event,$private,'title').$this->display_status($event['participants'][$part]); |
---|
2913 | for($m=$startminute;$m<$endminute;$m++) |
---|
2914 | { |
---|
2915 | $index = ($hour + (($m * $increment) * 100)); |
---|
2916 | $time_slice[$index]['marker'] = '-'; |
---|
2917 | $time_slice[$index]['description'] = $time_description; |
---|
2918 | $time_slice[$index]['id'] = $event['id']; |
---|
2919 | } |
---|
2920 | } |
---|
2921 | } |
---|
2922 | return $time_slice; |
---|
2923 | } |
---|
2924 | |
---|
2925 | /*! |
---|
2926 | @function set_status |
---|
2927 | @abstract set the participant response $status for event $cal_id and notifies the owner of the event |
---|
2928 | */ |
---|
2929 | function set_status($cal_id,$status) |
---|
2930 | { |
---|
2931 | $status2msg = array( |
---|
2932 | REJECTED => MSG_REJECTED, |
---|
2933 | TENTATIVE => MSG_TENTATIVE, |
---|
2934 | ACCEPTED => MSG_ACCEPTED |
---|
2935 | ); |
---|
2936 | if (!isset($status2msg[$status])) |
---|
2937 | { |
---|
2938 | return False; |
---|
2939 | } |
---|
2940 | $event = $this->so->read_entry($cal_id); |
---|
2941 | $account_id = $GLOBALS['phpgw_info']['user']['account_id']; |
---|
2942 | if(($status2msg[$status] == "5" && $event['participants'][$account_id] == "A") || |
---|
2943 | ($status2msg[$status] == "3" && $event['participants'][$account_id] == "R")) { |
---|
2944 | return True; |
---|
2945 | } |
---|
2946 | $this->so->set_status($cal_id,$status); |
---|
2947 | $event = $this->so->read_entry($cal_id); |
---|
2948 | $this->send_update($status2msg[$status],$event['participants'],$event); |
---|
2949 | |
---|
2950 | } |
---|
2951 | |
---|
2952 | /*! |
---|
2953 | @function update_requested |
---|
2954 | @abstract checks if $userid has requested (in $part_prefs) updates for $msg_type |
---|
2955 | @syntax update_requested($userid,$part_prefs,$msg_type,$old_event,$new_event) |
---|
2956 | @param $userid numerical user-id |
---|
2957 | @param $part_prefs preferces of the user $userid |
---|
2958 | @param $msg_type type of the notification: MSG_ADDED, MSG_MODIFIED, MSG_ACCEPTED, ... |
---|
2959 | @param $old_event Event before the change |
---|
2960 | @param $new_event Event after the change |
---|
2961 | @returns 0 = no update requested, > 0 update requested |
---|
2962 | */ |
---|
2963 | function update_requested($userid,$part_prefs,$msg_type,$old_event,$new_event) |
---|
2964 | { |
---|
2965 | if ($msg_type == MSG_ALARM) |
---|
2966 | { |
---|
2967 | return True; // always True for now |
---|
2968 | } |
---|
2969 | $want_update = 0; |
---|
2970 | |
---|
2971 | // the following switch fall-through all cases, as each included the following too |
---|
2972 | // |
---|
2973 | $msg_is_response = $msg_type == MSG_REJECTED || $msg_type == MSG_ACCEPTED || $msg_type == MSG_TENTATIVE; |
---|
2974 | |
---|
2975 | switch($ru = $part_prefs['calendar']['receive_updates']) |
---|
2976 | { |
---|
2977 | case 'responses': |
---|
2978 | if ($msg_is_response) |
---|
2979 | { |
---|
2980 | ++$want_update; |
---|
2981 | } |
---|
2982 | case 'modifications': |
---|
2983 | if ($msg_type == MSG_MODIFIED) |
---|
2984 | { |
---|
2985 | ++$want_update; |
---|
2986 | } |
---|
2987 | case 'time_change_4h': |
---|
2988 | case 'time_change': |
---|
2989 | $diff = max(abs($this->maketime($old_event['start'])-$this->maketime($new_event['start'])), |
---|
2990 | abs($this->maketime($old_event['end'])-$this->maketime($new_event['end']))); |
---|
2991 | $check = $ru == 'time_change_4h' ? 4 * 60 * 60 - 1 : 0; |
---|
2992 | if ($msg_type == MSG_MODIFIED && $diff > $check) |
---|
2993 | { |
---|
2994 | ++$want_update; |
---|
2995 | } |
---|
2996 | case 'add_cancel': |
---|
2997 | if ($old_event['owner'] == $userid && $msg_is_response || |
---|
2998 | $msg_type == MSG_DELETED || $msg_type == MSG_ADDED) |
---|
2999 | { |
---|
3000 | ++$want_update; |
---|
3001 | } |
---|
3002 | break; |
---|
3003 | case 'no': |
---|
3004 | break; |
---|
3005 | } |
---|
3006 | //echo "<p>bocalendar::update_requested(user=$userid,pref=".$part_prefs['calendar']['receive_updates'] .",msg_type=$msg_type,".($old_event?$old_event['title']:'False').",".($old_event?$old_event['title']:'False').") = $want_update</p>\n"; |
---|
3007 | return $want_update > 0; |
---|
3008 | } |
---|
3009 | |
---|
3010 | function create_vcard($event_arrays) |
---|
3011 | { |
---|
3012 | if(!is_array($event_arrays)) |
---|
3013 | return null; |
---|
3014 | |
---|
3015 | $tmpattach="BEGIN:VCALENDAR\n" |
---|
3016 | ."PRODID:-//Expresso Livre//Calendar//EN\n" |
---|
3017 | ."VERSION:1.0\n"; |
---|
3018 | foreach ($event_arrays as $event) |
---|
3019 | { |
---|
3020 | // It translates int to string |
---|
3021 | if (!is_object($event) && !is_array($event) || !array_key_exists ('end', $event)) |
---|
3022 | $event = $event_arrays; |
---|
3023 | |
---|
3024 | //set to GMT |
---|
3025 | //Aqui estou pegando o horário do evento e setando para GMT de acordo com o fuso horário estabelecido nas configurações do expresso. |
---|
3026 | $start_time = mktime($event['start']['hour'],$event['start']['min'],$event['start']['sec'],$event['start']['month'],$event['start']['mday'],$event['start']['year']) - $GLOBALS['phpgw']->datetime->tz_offset; |
---|
3027 | $end_time = mktime($event['end']['hour'],$event['end']['min'],$event['end']['sec'],$event['end']['month'],$event['end']['mday'],$event['end']['year']) - $GLOBALS['phpgw']->datetime->tz_offset; |
---|
3028 | |
---|
3029 | $start_time = date("Ymd\THis\Z", $start_time); |
---|
3030 | $end_time = date("Ymd\THis\Z", $end_time); |
---|
3031 | |
---|
3032 | // Necessário espaços após quebra-de-linha, na descrição, caso contrário |
---|
3033 | // ocorrerá erro ao importar o agendamento no Outlook (erro lunar). |
---|
3034 | $description = str_replace("\n","\n ", $event['description']); |
---|
3035 | |
---|
3036 | $tmpattach.="BEGIN:VEVENT\r\n" |
---|
3037 | ."DTSTART:".$start_time."\r\n" |
---|
3038 | ."DTEND:".$end_time."\r\n" |
---|
3039 | ."LAST-MODIFIED:".gmdate("Ymd\THis\Z")."\r\n" //Hora no formato UTC |
---|
3040 | ."UID:Expresso-".$event['id'].$event['uid']."\r\n" |
---|
3041 | ."DESCRIPTION:".$description."\r\n" |
---|
3042 | ."SUMMARY:".$event['title']."\r\n" |
---|
3043 | ."LOCATION:".$event['location']."\r\n" |
---|
3044 | ."END:VEVENT\r\n"; |
---|
3045 | } |
---|
3046 | $tmpattach.="END:VCALENDAR\r\n"; |
---|
3047 | return $tmpattach; |
---|
3048 | } |
---|
3049 | |
---|
3050 | /*! |
---|
3051 | @function send_update |
---|
3052 | @abstract sends update-messages to certain participants of an event |
---|
3053 | @syntax send_update($msg_type,$to_notify,$old_event,$new_event=False) |
---|
3054 | @param $msg_type type of the notification: MSG_ADDED, MSG_MODIFIED, MSG_ACCEPTED, ... |
---|
3055 | @param $to_notify array with numerical user-ids as keys (!) (value is not used) |
---|
3056 | @param $old_event Event before the change |
---|
3057 | @param $new_event Event after the change |
---|
3058 | */ |
---|
3059 | function send_update($msg_type,$to_notify,$old_event,$new_event=False,$user=False) |
---|
3060 | { |
---|
3061 | if (!is_array($to_notify)) |
---|
3062 | { |
---|
3063 | $to_notify = array(); |
---|
3064 | } |
---|
3065 | $owner = $old_event ? $old_event['owner'] : $new_event['owner']; |
---|
3066 | if ($owner && !isset($to_notify[$owner]) && $msg_type != MSG_ALARM) |
---|
3067 | { |
---|
3068 | $to_notify[$owner] = 'owner'; // always include the event-owner |
---|
3069 | } |
---|
3070 | $version = $GLOBALS['phpgw_info']['apps']['calendar']['version']; |
---|
3071 | |
---|
3072 | $GLOBALS['phpgw_info']['user']['preferences'] = $GLOBALS['phpgw']->preferences->create_email_preferences(); |
---|
3073 | $sender = $GLOBALS['phpgw_info']['user']['email']; |
---|
3074 | |
---|
3075 | $temp_tz_offset = $this->prefs['common']['tz_offset']; |
---|
3076 | $temp_timeformat = $this->prefs['common']['timeformat']; |
---|
3077 | $temp_dateformat = $this->prefs['common']['dateformat']; |
---|
3078 | |
---|
3079 | $tz_offset = ((60 * 60) * (int)$temp_tz_offset); |
---|
3080 | |
---|
3081 | if($old_event != False) |
---|
3082 | { |
---|
3083 | $t_old_start_time = $this->maketime($old_event['start']); |
---|
3084 | if($t_old_start_time < (time() - 86400)) |
---|
3085 | { |
---|
3086 | return False; |
---|
3087 | } |
---|
3088 | } |
---|
3089 | |
---|
3090 | $temp_user = $GLOBALS['phpgw_info']['user']; |
---|
3091 | |
---|
3092 | if (!$user) |
---|
3093 | { |
---|
3094 | $user = $this->owner; |
---|
3095 | } |
---|
3096 | $GLOBALS['phpgw_info']['user']['preferences'] = $GLOBALS['phpgw']->preferences->create_email_preferences($user); |
---|
3097 | |
---|
3098 | $event = $msg_type == MSG_ADDED || $msg_type == MSG_MODIFIED ? $new_event : $old_event; |
---|
3099 | if($old_event != False) |
---|
3100 | { |
---|
3101 | $old_starttime = $t_old_start_time - $GLOBALS['phpgw']->datetime->tz_offset; |
---|
3102 | } |
---|
3103 | $starttime = $this->maketime($event['start']) - $GLOBALS['phpgw']->datetime->tz_offset; |
---|
3104 | $endtime = $this->maketime($event['end']) - $GLOBALS['phpgw']->datetime->tz_offset; |
---|
3105 | |
---|
3106 | switch($msg_type) |
---|
3107 | { |
---|
3108 | case MSG_DELETED: |
---|
3109 | $action = lang('Canceled'); |
---|
3110 | $msg = 'Canceled'; |
---|
3111 | $msgtype = '"calendar";'; |
---|
3112 | $method = 'cancel'; |
---|
3113 | $typesend = 1; |
---|
3114 | break; |
---|
3115 | case MSG_MODIFIED: |
---|
3116 | $action = lang('Modified'); |
---|
3117 | $msg = 'Modified'; |
---|
3118 | $msgtype = '"calendar"; Version="'.$version.'"; Id="'.$new_event['id'].'"'; |
---|
3119 | $method = 'request'; |
---|
3120 | $typesend = 2; |
---|
3121 | break; |
---|
3122 | case MSG_ADDED: |
---|
3123 | $action = lang('Added'); |
---|
3124 | $msg = 'Added'; |
---|
3125 | $msgtype = '"calendar"; Version="'.$version.'"; Id="'.$new_event['id'].'"'; |
---|
3126 | $method = 'request'; |
---|
3127 | $typesend = 3; |
---|
3128 | break; |
---|
3129 | case MSG_REJECTED: |
---|
3130 | $action = lang('Rejected'); |
---|
3131 | $msg = 'Response'; |
---|
3132 | $msgtype = '"calendar";'; |
---|
3133 | $method = 'reply'; |
---|
3134 | $typesend = 4; |
---|
3135 | break; |
---|
3136 | case MSG_TENTATIVE: |
---|
3137 | $action = lang('Tentative'); |
---|
3138 | $msg = 'Response'; |
---|
3139 | $msgtype = '"calendar";'; |
---|
3140 | $method = 'reply'; |
---|
3141 | $typesend = 5; |
---|
3142 | break; |
---|
3143 | case MSG_ACCEPTED: |
---|
3144 | $action = lang('Accepted'); |
---|
3145 | $msg = 'Response'; |
---|
3146 | $msgtype = '"calendar";'; |
---|
3147 | $method = 'reply'; |
---|
3148 | $typesend = 6; |
---|
3149 | break; |
---|
3150 | case MSG_ALARM: |
---|
3151 | $action = lang('Alarm'); |
---|
3152 | $msg = 'Alarm'; |
---|
3153 | $msgtype = '"calendar";'; |
---|
3154 | $method = 'publish'; // duno if thats right |
---|
3155 | $typesend = 7; |
---|
3156 | break; |
---|
3157 | default: |
---|
3158 | $method = 'publish'; |
---|
3159 | $typesend = 8; |
---|
3160 | } |
---|
3161 | $notify_msg = $this->prefs['calendar']['notify'.$msg]; |
---|
3162 | if (empty($notify_msg)) |
---|
3163 | { |
---|
3164 | $notify_msg = $this->prefs['calendar']['notifyAdded']; // use a default |
---|
3165 | } |
---|
3166 | $details = array( // event-details for the notify-msg |
---|
3167 | 'id' => $msg_type == MSG_ADDED ? $new_event['id'] : $old_event['id'], |
---|
3168 | 'action' => $action, |
---|
3169 | ); |
---|
3170 | $event_arr = $this->event2array($event); |
---|
3171 | foreach($event_arr as $key => $val) |
---|
3172 | { |
---|
3173 | $details[$key] = $val['data']; |
---|
3174 | } |
---|
3175 | |
---|
3176 | $details['participants'] = implode("\n",$details['participants']); |
---|
3177 | |
---|
3178 | $details['link'] = $GLOBALS['phpgw_info']['server']['webserver_url'].'/index.php?menuaction=calendar.uicalendar.view&cal_id='.$event['id']; |
---|
3179 | // if url is only a path, try guessing the rest ;-) |
---|
3180 | if ($GLOBALS['phpgw_info']['server']['webserver_url'][0] == '/') |
---|
3181 | { |
---|
3182 | $details['link'] = ($GLOBALS['phpgw_info']['server']['enforce_ssl'] ? 'https://' : 'http://'). |
---|
3183 | ($GLOBALS['phpgw_info']['server']['hostname'] ? $GLOBALS['phpgw_info']['server']['hostname'] : 'localhost'). |
---|
3184 | $details['link']; |
---|
3185 | } |
---|
3186 | |
---|
3187 | //Seta o email usando phpmailer |
---|
3188 | define('PHPGW_INCLUDE_ROOT','../'); |
---|
3189 | define('PHPGW_API_INC','../phpgwapi/inc'); |
---|
3190 | include_once(PHPGW_API_INC.'/class.phpmailer.inc.php'); |
---|
3191 | $mail = new PHPMailer(); |
---|
3192 | $mail->IsSMTP(); |
---|
3193 | $boemailadmin = CreateObject('emailadmin.bo'); |
---|
3194 | $emailadmin_profile = $boemailadmin->getProfileList(); |
---|
3195 | $emailadmin = $boemailadmin->getProfile($emailadmin_profile[0]['profileID']); |
---|
3196 | |
---|
3197 | $mail->Host = $emailadmin['smtpServer']; |
---|
3198 | $mail->Port = $emailadmin['smtpPort']; |
---|
3199 | $mail->From = $GLOBALS['phpgw']->preferences->values['email']; |
---|
3200 | $mail->FromName = $GLOBALS['phpgw_info']['user']['fullname']; |
---|
3201 | $mail->IsHTML(true); |
---|
3202 | |
---|
3203 | // Aqui e enviado o email |
---|
3204 | foreach($to_notify as $userid => $statusid) |
---|
3205 | { |
---|
3206 | $mail->ClearAttachments(); |
---|
3207 | |
---|
3208 | $userid = (int)$userid; |
---|
3209 | |
---|
3210 | if ($statusid == 'R' || $GLOBALS['phpgw']->accounts->get_type($userid) == 'g') |
---|
3211 | { |
---|
3212 | continue; // dont notify rejected participants |
---|
3213 | } |
---|
3214 | if($userid != $GLOBALS['phpgw_info']['user']['account_id'] || $msg_type == MSG_ALARM) |
---|
3215 | { |
---|
3216 | print_debug('Msg Type',$msg_type); |
---|
3217 | print_debug('UserID',$userid); |
---|
3218 | |
---|
3219 | $preferences = CreateObject('phpgwapi.preferences',$userid); |
---|
3220 | $part_prefs = $preferences->read_repository(); |
---|
3221 | |
---|
3222 | if (!$this->update_requested($userid,$part_prefs,$msg_type,$old_event,$new_event)) |
---|
3223 | { |
---|
3224 | continue; |
---|
3225 | } |
---|
3226 | $GLOBALS['phpgw']->accounts->get_account_name($userid,$lid,$details['to-firstname'],$details['to-lastname']); |
---|
3227 | $details['to-fullname'] = $GLOBALS['phpgw']->common->display_fullname('',$details['to-firstname'],$details['to-lastname']); |
---|
3228 | |
---|
3229 | $to = $preferences->email_address($userid); |
---|
3230 | |
---|
3231 | if (empty($to) || $to[0] == '@' || $to[0] == '$') // we have no valid email-address |
---|
3232 | { |
---|
3233 | //echo "<p>bocalendar::send_update: Empty email adress for user '".$details['to-fullname']."' ==> ignored !!!</p>\n"; |
---|
3234 | continue; |
---|
3235 | } |
---|
3236 | print_debug('Email being sent to',$to); |
---|
3237 | |
---|
3238 | $GLOBALS['phpgw_info']['user']['preferences']['common']['tz_offset'] = $part_prefs['common']['tz_offset']; |
---|
3239 | $GLOBALS['phpgw_info']['user']['preferences']['common']['timeformat'] = $part_prefs['common']['timeformat']; |
---|
3240 | $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'] = $part_prefs['common']['dateformat']; |
---|
3241 | |
---|
3242 | $GLOBALS['phpgw']->datetime->tz_offset = ((60 * 60) * (int)$GLOBALS['phpgw_info']['user']['preferences']['common']['tz_offset']); |
---|
3243 | |
---|
3244 | if($old_starttime) |
---|
3245 | { |
---|
3246 | $details['olddate'] = $GLOBALS['phpgw']->common->show_date($old_starttime); |
---|
3247 | } |
---|
3248 | $details['startdate'] = $GLOBALS['phpgw']->common->show_date($starttime); |
---|
3249 | $details['enddate'] = $GLOBALS['phpgw']->common->show_date($endtime); |
---|
3250 | |
---|
3251 | |
---|
3252 | list($subject,$body1) = split("\n",$GLOBALS['phpgw']->preferences->parse_notify($notify_msg,$details),2); |
---|
3253 | |
---|
3254 | switch($part_prefs['calendar']['update_format']) |
---|
3255 | { |
---|
3256 | case 'extended': |
---|
3257 | //$body .= "\n\n".lang('Event Details follow').":\n"; |
---|
3258 | $body = ''; |
---|
3259 | $body .= "<br>".lang('Event Details follow')." :: "; |
---|
3260 | foreach($event_arr as $key => $val) |
---|
3261 | { |
---|
3262 | // titulo |
---|
3263 | if($key =='title') |
---|
3264 | { |
---|
3265 | $var1 = $val['field']; |
---|
3266 | $vardata1 = $details[$key]; |
---|
3267 | } |
---|
3268 | //descricao |
---|
3269 | if($key =='description') |
---|
3270 | { |
---|
3271 | $var2 = $val['field']; |
---|
3272 | $vardata2 = $details[$key]; |
---|
3273 | } |
---|
3274 | //dt inicio |
---|
3275 | if($key =='startdate') |
---|
3276 | { |
---|
3277 | switch(trim($part_prefs['common']['dateformat'])) |
---|
3278 | { |
---|
3279 | |
---|
3280 | case ($part_prefs['common']['dateformat'] === "m/d/Y" || $part_prefs['common']['dateformat'] === "m-d-Y" || $part_prefs['common']['dateformat'] === "m.d.Y"): |
---|
3281 | $var3 = $val['field']; |
---|
3282 | $vardata3 = $details[$key]; |
---|
3283 | $newmounth3 = substr($vardata3,0,2); |
---|
3284 | $newday3 = substr($vardata3,3,2); |
---|
3285 | $newyear3 = substr($vardata3,6,4); |
---|
3286 | $newall3 =$newyear3.$newmounth3.$newday3; |
---|
3287 | break; |
---|
3288 | |
---|
3289 | case ($part_prefs['common']['dateformat'] === "Y/d/m" || $part_prefs['common']['dateformat'] === "Y-d-m" || $part_prefs['common']['dateformat'] === "Y.d.m"): |
---|
3290 | |
---|
3291 | $var3 = $val['field']; |
---|
3292 | $vardata3 = $details[$key]; |
---|
3293 | $newyear3 = substr($vardata3,0,4); |
---|
3294 | $newday3 = substr($vardata3,5,2); |
---|
3295 | $newmounth3 = substr($vardata3,8,2); |
---|
3296 | $newall3 =$newyear3.$newmounth3.$newday3; |
---|
3297 | break; |
---|
3298 | |
---|
3299 | case ($part_prefs['common']['dateformat'] === "Y/m/d" || $part_prefs['common']['dateformat'] === "Y-m-d" || $part_prefs['common']['dateformat'] === "Y.m.d"): |
---|
3300 | |
---|
3301 | $var3 = $val['field']; |
---|
3302 | $vardata3 = $details[$key]; |
---|
3303 | $newyear3 = substr($vardata3,0,4); |
---|
3304 | $newmounth3 = substr($vardata3,5,2); |
---|
3305 | $newday3 = substr($vardata3,8,2); |
---|
3306 | $newall3 =$newyear3.$newmounth3.$newday3; |
---|
3307 | break; |
---|
3308 | |
---|
3309 | case ($part_prefs['common']['dateformat'] === "d/m/Y" || $part_prefs['common']['dateformat'] === "d-m-Y" || $part_prefs['common']['dateformat'] === "d.m.Y" || $part_prefs['common']['dateformat'] === "d-M-Y"): |
---|
3310 | |
---|
3311 | $var3 = $val['field']; |
---|
3312 | $vardata3 = $details[$key]; |
---|
3313 | $newday3 = substr($vardata3,0,2); |
---|
3314 | $newmounth3 = substr($vardata3,3,2); |
---|
3315 | $newyear3 = substr($vardata3,6,4); |
---|
3316 | $newall3 =$newyear3.$newmounth3.$newday3; |
---|
3317 | break; |
---|
3318 | |
---|
3319 | } |
---|
3320 | |
---|
3321 | } |
---|
3322 | //dt final |
---|
3323 | if($key =='enddate') |
---|
3324 | { |
---|
3325 | $var4 = $val['field']; |
---|
3326 | $vardata4 = $details[$key]; |
---|
3327 | } |
---|
3328 | //localizacao |
---|
3329 | if($key =='location') |
---|
3330 | { |
---|
3331 | $var8 = $val['field']; |
---|
3332 | $vardata8 = $details[$key]; |
---|
3333 | } |
---|
3334 | //participantes |
---|
3335 | if($key =='participants') |
---|
3336 | { |
---|
3337 | $var5 = $val['field']; |
---|
3338 | foreach($val['data'] as $NewKey => $NewVal) |
---|
3339 | { |
---|
3340 | //Research inside of ldap ( Pesquisa dentro do ldap ) |
---|
3341 | $newvalue = $this->so->search_uidNumber($to); |
---|
3342 | foreach($newvalue as $tmp) |
---|
3343 | { |
---|
3344 | $tmpmail = $tmp['mail'][0]; |
---|
3345 | $tmpuid = $tmp['uidnumber'][0]; |
---|
3346 | if( trim($tmpmail) == trim($to) & trim($tmpuid) == trim($NewKey)) |
---|
3347 | { |
---|
3348 | if( ( $typesend == 3 ) || ( $typesend == 2 ) ) |
---|
3349 | { |
---|
3350 | $question = ""; |
---|
3351 | |
---|
3352 | if( $typesend == 2 ) |
---|
3353 | $question = lang("Do you wish to change your participation in this event?"); |
---|
3354 | |
---|
3355 | $lang1 = lang("To See Commitment"); |
---|
3356 | $varbuttom = "<form action=".$GLOBALS['phpgw_info']['server']['webserver_url']."/index.php?menuaction=calendar.uicalendar.view&cal_id=$event[id]&date=$newall3' method='POST'> |
---|
3357 | <input type='submit' value='$lang1'> |
---|
3358 | </form>"; |
---|
3359 | $lang2 = lang("To accept"); |
---|
3360 | $varbuttom1 ="<input type='submit' value='$lang2' onClick='javascript:window.open(\"".$GLOBALS['phpgw_info']['server']['webserver_url']."/index.php?menuaction=calendar.uicalendar.set_action&cal_id=$event[id]&action=3&response=1&user_id=$userid\",\"frontpage\",\"height=200,width=450,statusbar=no,toolbar=no,scrollbars=no,menubar=no,left=300,top=200\")'>"; |
---|
3361 | |
---|
3362 | $lang3 = lang("To reject"); |
---|
3363 | $varbuttom2 ="<input type='submit' value='$lang3' onClick='javascript:window.open(\"".$GLOBALS['phpgw_info']['server']['webserver_url']."/index.php?menuaction=calendar.uicalendar.set_action&cal_id=$event[id]&action=0&response=0\",\"frontpage\",\"height=100,width=400,statusbar=no,toolbar=no,scrollbars=no,menubar=no,left=300,top=200\")'>"; |
---|
3364 | |
---|
3365 | $lang4 = lang("Alarm"); |
---|
3366 | $varbuttom3 = "<form action=".$GLOBALS['phpgw_info']['server']['webserver_url']."/index.php?menuaction=calendar.uialarm.manager method='POST'> |
---|
3367 | <input type='submit' value='$lang4'> |
---|
3368 | <input type='hidden' name='cal_id' value=$event[id]> |
---|
3369 | </form>"; |
---|
3370 | |
---|
3371 | $lang5 = lang("Delegate"); |
---|
3372 | $varbuttom4 = "<form action='".$GLOBALS['phpgw_info']['server']['webserver_url']."/index.php?menuaction=calendar.uicalendar.screen_delegate_event&id_event=$event[id]&date=$newall3&delegator=$tmpuid' method='POST'> |
---|
3373 | <input type='submit' value='$lang5'> |
---|
3374 | </form>"; |
---|
3375 | |
---|
3376 | $lang6 = lang("Tentative"); |
---|
3377 | $varbuttom5 ="<input type='submit' value='$lang6' onClick='javascript:window.open(\"".$GLOBALS['phpgw_info']['server']['webserver_url']."/index.php?menuaction=calendar.uicalendar.set_action&cal_id=$event[id]&action=2&response=1&user_id=$userid\",\"frontpage\",\"height=200,width=450,statusbar=no,toolbar=no,scrollbars=no,menubar=no,left=300,top=200\")'>"; |
---|
3378 | } |
---|
3379 | else |
---|
3380 | { |
---|
3381 | $varbuttom = ""; |
---|
3382 | $varbuttom1 = ""; |
---|
3383 | $varbuttom2 = ""; |
---|
3384 | $varbuttom3 = ""; |
---|
3385 | $varbuttom4 = ""; |
---|
3386 | $varbuttom5 = ""; |
---|
3387 | } |
---|
3388 | } |
---|
3389 | // It only mounts variavel with the name of the participants of the list ( Monta a variavel somente com o nome dos participantes da lista) |
---|
3390 | if($typesend == 3) |
---|
3391 | { |
---|
3392 | list($tmpvardata5,$tmp2vardata5) = explode("(",$NewVal); |
---|
3393 | $vardata5 = $tmpvardata5."<br>"; |
---|
3394 | } |
---|
3395 | else |
---|
3396 | { |
---|
3397 | $vardata5 = $NewVal."<br>"; |
---|
3398 | } |
---|
3399 | |
---|
3400 | } |
---|
3401 | $vardata6 .= $vardata5; |
---|
3402 | unset($vardata5); |
---|
3403 | } |
---|
3404 | } |
---|
3405 | } |
---|
3406 | //To mount the message as text/html (Para montar a mensagem como text/html - /phpgwapi/inc/class.send.inc.php ) |
---|
3407 | $content_type = "text/html"; |
---|
3408 | //It mounts the body of the message (Monta o corpo da mensagem) |
---|
3409 | |
---|
3410 | // A constante PHPGW_APP_TPL nao existe para envio de alarmes (cront, asyncservice). |
---|
3411 | define ("PHPGW_APP_TPL",PHPGW_API_INC . "/../../calendar/templates/".$GLOBALS['phpgw_info']['user']['preferences']['common']['template_set'].""); |
---|
3412 | |
---|
3413 | $body = CreateObject('phpgwapi.Template',PHPGW_APP_TPL); |
---|
3414 | $body->set_file(Array('calendar' => 'body_email.tpl')); |
---|
3415 | $body->set_block('calendar','list'); |
---|
3416 | $var = Array( |
---|
3417 | 'script' => $script, |
---|
3418 | 'subject' => $body1, |
---|
3419 | 'var1' => $var1, |
---|
3420 | 'vardata1' => $vardata1, |
---|
3421 | 'var2' => $var2, |
---|
3422 | 'vardata2' => $vardata2, |
---|
3423 | 'var3' => $var3, |
---|
3424 | 'vardata3' => $vardata3, |
---|
3425 | 'var4' => $var4, |
---|
3426 | 'vardata4' => $vardata4, |
---|
3427 | 'var5' => $var5, |
---|
3428 | 'vardata6' => $vardata6, |
---|
3429 | 'var8' => $var8, |
---|
3430 | 'vardata8' => $vardata8, |
---|
3431 | 'question' => $question, |
---|
3432 | 'varbuttom' => $varbuttom, |
---|
3433 | 'varbuttom1' => $varbuttom1, |
---|
3434 | 'varbuttom2' => $varbuttom2, |
---|
3435 | 'varbuttom3' => $varbuttom3, |
---|
3436 | 'varbuttom4' => $varbuttom4, |
---|
3437 | 'varbuttom5' => $varbuttom5 |
---|
3438 | ); |
---|
3439 | $body->set_var($var); |
---|
3440 | $tmpbody = $body->fp('out','list'); |
---|
3441 | |
---|
3442 | break; |
---|
3443 | |
---|
3444 | case 'ical': |
---|
3445 | $content_type = "calendar; method=$method; name=calendar.ics"; |
---|
3446 | /* if ($body != '') |
---|
3447 | { |
---|
3448 | $boundary = '----Message-Boundary'; |
---|
3449 | $body .= "\n\n\n$boundary\nContent-type: text/$content_type\n". |
---|
3450 | "Content-Disposition: inline\nContent-transfer-encoding: 7BIT\n\n"; |
---|
3451 | $content_type = ''; |
---|
3452 | } |
---|
3453 | */ |
---|
3454 | $body = ExecMethod('calendar.boicalendar.export',array( |
---|
3455 | 'l_event_id' => $event['id'], |
---|
3456 | 'method' => $method, |
---|
3457 | 'chunk_split' => False |
---|
3458 | )); |
---|
3459 | break; |
---|
3460 | } |
---|
3461 | $mail->AddAddress($to); |
---|
3462 | $mail->Body = $tmpbody; |
---|
3463 | $mail->From = $sender; |
---|
3464 | $mail->FromName = $GLOBALS['phpgw_info']['user']['fullname']; |
---|
3465 | $mail->Sender = $mail->From; |
---|
3466 | $mail->SenderName = $mail->FromName; |
---|
3467 | $mail->Subject = $subject; |
---|
3468 | unset($vardata5); |
---|
3469 | unset($vardata6); |
---|
3470 | } |
---|
3471 | } |
---|
3472 | |
---|
3473 | //Inicializa variᅵvel de retorno. |
---|
3474 | $returncode=true; |
---|
3475 | if(count($mail->to)) { |
---|
3476 | |
---|
3477 | if(isset($new_event['attachment'])){ |
---|
3478 | foreach($new_event['attachment'] as $attach){ |
---|
3479 | $mail->AddAttachment($attach['tmp_name'], $attach['name'], "base64", $attach['type']); |
---|
3480 | } |
---|
3481 | } |
---|
3482 | // Envia aviso a todos os participantes. |
---|
3483 | if(!$mail->Send()) { |
---|
3484 | $returncode = false; |
---|
3485 | $errorInfo['participants'] = $mail->ErrorInfo; |
---|
3486 | } |
---|
3487 | else |
---|
3488 | $returncode = true; |
---|
3489 | } |
---|
3490 | |
---|
3491 | if(count($to_notify) && $this->ex_participants){ |
---|
3492 | $mail->ClearAllRecipients(); |
---|
3493 | $var = explode(",",trim($this->ex_participants)); |
---|
3494 | $to = array(); |
---|
3495 | if(!$subject) { |
---|
3496 | $details['startdate'] = $GLOBALS['phpgw']->common->show_date($starttime); |
---|
3497 | $details['enddate'] = $GLOBALS['phpgw']->common->show_date($endtime); |
---|
3498 | list($subject,$body1) = split("\n",$GLOBALS['phpgw']->preferences->parse_notify($notify_msg,$details),2); |
---|
3499 | } |
---|
3500 | |
---|
3501 | foreach($var as $index => $ex_participant){ |
---|
3502 | $ex_participant = trim($ex_participant); |
---|
3503 | $ex_participant = preg_replace('#"(.*)" <(.*)\@(.*)\.(.*)>#','\\2@\\3.\\4',$ex_participant); |
---|
3504 | if($ex_participant) |
---|
3505 | $to[] = $ex_participant; |
---|
3506 | } |
---|
3507 | |
---|
3508 | foreach($to as $i => $to_array) |
---|
3509 | $mail->AddAddress($to_array); |
---|
3510 | |
---|
3511 | $_body = explode("<hr size='1' width='100%'>",$tmpbody); |
---|
3512 | $tmpbody = $_body[0] ? $_body[0] : $subject ; |
---|
3513 | $tmpbody.= "<br><b>".lang("external participants").":: </b> ".htmlentities($this->ex_participants); |
---|
3514 | $tmpbody.= "<br>".lang("Summary").": ".$this->so->cal->event[title]."<br>"; |
---|
3515 | $tmpbody.= "<br>".lang("Start time").": ".$GLOBALS['phpgw']->common->show_date($starttime)."<br>".lang("End date").": ".$GLOBALS['phpgw']->common->show_date($endtime)."<br>"; |
---|
3516 | $tmpbody.= "<br><br><hr size='1' width='100%'><font color='red'>" |
---|
3517 | .lang("This message was sent by server. You must send a message to sender to confirm this event")."<br>" |
---|
3518 | .lang("This is an external event. Even if it added to your expresso its can be changed any time at all")."</font><br>"; |
---|
3519 | |
---|
3520 | if ($GLOBALS['bocalendar']->so->cal->event[start][month] > 10) |
---|
3521 | $event_month=$GLOBALS['bocalendar']->so->cal->event[start][month]; |
---|
3522 | else |
---|
3523 | $event_month="0".$GLOBALS['bocalendar']->so->cal->event[start][month]; |
---|
3524 | //attach extern vcalendar/icalendar (ics) |
---|
3525 | // define('context','$GLOBALS.bocalendar.so.cal.event'); |
---|
3526 | $tmpattach = $this->create_vcard($GLOBALS['bocalendar']->so->cal->event); |
---|
3527 | if($tmpattach){ |
---|
3528 | $tmpbody .="<a href='../index.php?menuaction=calendar.uicalendar.add&date=" |
---|
3529 | .$GLOBALS['bocalendar']->so->cal->event[start][year] |
---|
3530 | .$event_month |
---|
3531 | .$GLOBALS['bocalendar']->so->cal->event[start][mday] |
---|
3532 | ."&hour=".$GLOBALS['bocalendar']->so->cal->event[start][hour] |
---|
3533 | ."&minute=".$GLOBALS['bocalendar']->so->cal->event[start][min] |
---|
3534 | ."&title=".$GLOBALS['bocalendar']->so->cal->event['title'] |
---|
3535 | ."&description=".$GLOBALS['bocalendar']->so->cal->event['description'] |
---|
3536 | ."&location=".$GLOBALS['bocalendar']->so->cal->event['location']."'>" |
---|
3537 | ."<h2>".lang("Add to my expresso")."</h2>"; |
---|
3538 | $tempdir = $GLOBALS['phpgw_info']['server']['temp_dir'] . SEP; |
---|
3539 | srand((double)microtime()*1000000); |
---|
3540 | $random_number = rand(100000000,999999999); |
---|
3541 | $newfilename = md5(time() . getenv("REMOTE_ADDR") . $random_number ); |
---|
3542 | $filename = $tempdir . $newfilename; |
---|
3543 | $attach_fd = fopen($filename,"w+"); |
---|
3544 | fwrite($attach_fd,$tmpattach); |
---|
3545 | $mail->AddAttachment($filename, "extern.ics", "base64", "text/plain"); // "application/octet-stream" |
---|
3546 | fclose($attach_fd); |
---|
3547 | } |
---|
3548 | |
---|
3549 | if(isset($new_event['attachment'])){ |
---|
3550 | foreach($new_event['attachment'] as $attach){ |
---|
3551 | $mail->AddAttachment($attach['tmp_name'], $attach['name'], "base64", $attach['type']); |
---|
3552 | } |
---|
3553 | } |
---|
3554 | |
---|
3555 | $mail->From = $sender; |
---|
3556 | $mail->FromName = $GLOBALS['phpgw_info']['user']['fullname']; |
---|
3557 | $mail->Sender = $mail->From; |
---|
3558 | $mail->SenderName = $mail->FromName; |
---|
3559 | $mail->Subject = lang("External event from Expresso"); |
---|
3560 | $mail->Body = $tmpbody; |
---|
3561 | |
---|
3562 | if(!$mail->Send()) |
---|
3563 | { |
---|
3564 | $returncode=false; |
---|
3565 | $errorInfo['ex_participants'] = $mail->ErrorInfo; |
---|
3566 | } |
---|
3567 | else |
---|
3568 | { |
---|
3569 | $returncode=true; |
---|
3570 | } |
---|
3571 | } |
---|
3572 | |
---|
3573 | |
---|
3574 | if((is_int($this->user) && $this->user != $temp_user['account_id']) || |
---|
3575 | (is_string($this->user) && $this->user != $temp_user['account_lid'])) |
---|
3576 | { |
---|
3577 | $GLOBALS['phpgw_info']['user'] = $temp_user; |
---|
3578 | } |
---|
3579 | |
---|
3580 | $GLOBALS['phpgw_info']['user']['preferences']['common']['tz_offset'] = $temp_tz_offset; |
---|
3581 | $GLBOALS['phpgw']->datetime->tz_offset = ((60 * 60) * $temp_tz_offset); |
---|
3582 | $GLOBALS['phpgw_info']['user']['preferences']['common']['timeformat'] = $temp_timeformat; |
---|
3583 | $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'] = $temp_dateformat; |
---|
3584 | |
---|
3585 | // Notifica por email o criador do compromisso, com as possᅵveis falhas. |
---|
3586 | if($errorInfo) { |
---|
3587 | $tmpbody = "<font color='red'>".lang("The following commitment had problems for DELIVERING the NOTIFICATION messages.").".</font><br>"; |
---|
3588 | $tmpbody.= "<br>".lang("Summary").": ".$this->so->cal->event[title]."<br>"; |
---|
3589 | $tmpbody.= "<br>".lang("Start time").": ".$GLOBALS['phpgw']->common->show_date($starttime)."<br>".lang("End date").": ".$GLOBALS['phpgw']->common->show_date($endtime)."<br>"; |
---|
3590 | $tmpbody.= "<br><u>".lang("Failed to delivery")."</u><br>"; |
---|
3591 | $failed = false; |
---|
3592 | if(strstr($errorInfo['participants'],"recipients_failed")){ |
---|
3593 | $failed = explode("recipients_failed",$errorInfo['participants']); |
---|
3594 | $tmpbody.= lang("to").": ".$failed[1]; |
---|
3595 | } |
---|
3596 | if(strstr($errorInfo['ex_participants'],"recipients_failed")){ |
---|
3597 | $failed = explode("recipients_failed",$errorInfo['ex_participants']); |
---|
3598 | $tmpbody.= lang("to").": ".$failed[1]; |
---|
3599 | } |
---|
3600 | if(!$failed) { |
---|
3601 | $tmpbody.= lang("Description").":<br>"; |
---|
3602 | $tmpbody.= $errorInfo['participants']; |
---|
3603 | $tmpbody.= "<br>".$errorInfo['ex_participants']; |
---|
3604 | } |
---|
3605 | $tmpbody.= "<br>".lang("Subject").": ".$subject; |
---|
3606 | // Reinicializa o objeto, devido ao erro anterior na entrega. |
---|
3607 | |
---|
3608 | $mail = new PHPMailer(); |
---|
3609 | $mail->IsSMTP(); |
---|
3610 | $mail->Host = $emailadmin['smtpServer']; |
---|
3611 | $mail->Port = $emailadmin['smtpPort']; |
---|
3612 | $mail->From = $sender; |
---|
3613 | $mail->FromName = $GLOBALS['phpgw_info']['user']['fullname']; |
---|
3614 | $mail->Sender = $mail->From; |
---|
3615 | $mail->SenderName = $mail->FromName; |
---|
3616 | $mail->IsHTML(True); |
---|
3617 | $mail->Subject = lang("calendar event")." - ".lang("email notification"); |
---|
3618 | $mail->Body = $tmpbody; |
---|
3619 | $mail->AddAddress($sender); |
---|
3620 | if(!$mail->Send()) |
---|
3621 | $returncode = false; |
---|
3622 | else |
---|
3623 | $returncode = true; |
---|
3624 | } |
---|
3625 | return $returncode; |
---|
3626 | } |
---|
3627 | |
---|
3628 | function send_alarm($alarm) |
---|
3629 | { |
---|
3630 | //echo "<p>bocalendar::send_alarm("; print_r($alarm); echo ")</p>\n"; |
---|
3631 | |
---|
3632 | $GLOBALS['phpgw_info']['user']['account_id'] = $this->owner = $alarm['owner']; |
---|
3633 | |
---|
3634 | if (!$alarm['enabled'] || !$alarm['owner'] || !$alarm['cal_id'] || !($event = $this->so->read_entry($alarm['cal_id']))) |
---|
3635 | { |
---|
3636 | return False; // event not found |
---|
3637 | } |
---|
3638 | if ($alarm['all']) |
---|
3639 | { |
---|
3640 | $to_notify = $event['participants']; |
---|
3641 | } |
---|
3642 | elseif ($this->check_perms(PHPGW_ACL_READ,$event)) // checks agains $this->owner set to $alarm[owner] |
---|
3643 | { |
---|
3644 | $to_notify[$alarm['owner']] = 'A'; |
---|
3645 | } |
---|
3646 | else |
---|
3647 | { |
---|
3648 | return False; // no rights |
---|
3649 | } |
---|
3650 | return $this->send_update(MSG_ALARM,$to_notify,$event,False,$alarm['owner']); |
---|
3651 | } |
---|
3652 | |
---|
3653 | function get_alarms($event_id) |
---|
3654 | { |
---|
3655 | return $this->so->get_alarm($event_id); |
---|
3656 | } |
---|
3657 | |
---|
3658 | function alarm_today($event,$today,$starttime) |
---|
3659 | { |
---|
3660 | $found = False; |
---|
3661 | @reset($event['alarm']); |
---|
3662 | $starttime_hi = $GLOBALS['phpgw']->common->show_date($starttime,'Hi'); |
---|
3663 | $t_appt['month'] =$GLOBALS['phpgw']->common->show_date($today,'m'); |
---|
3664 | $t_appt['mday'] = $GLOBALS['phpgw']->common->show_date($today,'d'); |
---|
3665 | $t_appt['year'] = $GLOBALS['phpgw']->common->show_date($today,'Y'); |
---|
3666 | $t_appt['hour'] = $GLOBALS['phpgw']->common->show_date($starttime,'H'); |
---|
3667 | $t_appt['min'] = $GLOBALS['phpgw']->common->show_date($starttime,'i'); |
---|
3668 | $t_appt['sec'] = 0; |
---|
3669 | $t_time = $this->maketime($t_appt) - $GLOBALS['phpgw']->datetime->tz_offset; |
---|
3670 | $y_time = $t_time - 86400; |
---|
3671 | $tt_time = $t_time + 86399; |
---|
3672 | print_debug('T_TIME',$t_time.' : '.$GLOBALS['phpgw']->common->show_date($t_time)); |
---|
3673 | print_debug('Y_TIME',$y_time.' : '.$GLOBALS['phpgw']->common->show_date($y_time)); |
---|
3674 | print_debug('TT_TIME',$tt_time.' : '.$GLOBALS['phpgw']->common->show_date($tt_time)); |
---|
3675 | while(list($key,$alarm) = each($event['alarm'])) |
---|
3676 | { |
---|
3677 | if($alarm['enabled']) |
---|
3678 | { |
---|
3679 | print_debug('TIME',$alarm['time'].' : '.$GLOBALS['phpgw']->common->show_date($alarm['time']).' ('.$event['id'].')'); |
---|
3680 | if($event['recur_type'] != MCAL_RECUR_NONE) /* Recurring Event */ |
---|
3681 | { |
---|
3682 | print_debug('Recurring Event'); |
---|
3683 | if($alarm['time'] > $y_time && $GLOBALS['phpgw']->common->show_date($alarm['time'],'Hi') < $starttime_hi && $alarm['time'] < $t_time) |
---|
3684 | { |
---|
3685 | $found = True; |
---|
3686 | } |
---|
3687 | } |
---|
3688 | elseif($alarm['time'] > $y_time && $alarm['time'] < $t_time) |
---|
3689 | { |
---|
3690 | $found = True; |
---|
3691 | } |
---|
3692 | } |
---|
3693 | } |
---|
3694 | print_debug('Found',$found); |
---|
3695 | return $found; |
---|
3696 | } |
---|
3697 | |
---|
3698 | function prepare_recipients(&$new_event,$old_event) |
---|
3699 | { |
---|
3700 | |
---|
3701 | // Find modified and deleted users..... |
---|
3702 | while(list($old_userid,$old_status) = each($old_event['participants'])) |
---|
3703 | { |
---|
3704 | if(isset($new_event['participants'][$old_userid])) |
---|
3705 | { |
---|
3706 | print_debug('Modifying event for user',$old_userid); |
---|
3707 | $this->modified[(int)$old_userid] = $new_status; |
---|
3708 | } |
---|
3709 | else |
---|
3710 | { |
---|
3711 | print_debug('Deleting user from the event',$old_userid); |
---|
3712 | $this->deleted[(int)$old_userid] = $old_status; |
---|
3713 | } |
---|
3714 | } |
---|
3715 | // Find new users..... |
---|
3716 | while(list($new_userid,$new_status) = each($new_event['participants'])) |
---|
3717 | { |
---|
3718 | if(!isset($old_event['participants'][$new_userid])) |
---|
3719 | { |
---|
3720 | print_debug('Adding event for user',$new_userid); |
---|
3721 | $this->added[$new_userid] = 'U'; |
---|
3722 | $new_event['participants'][$new_userid] = 'U'; |
---|
3723 | } |
---|
3724 | } |
---|
3725 | |
---|
3726 | if(count($this->added) > 0 || count($this->modified) > 0 || count($this->deleted) > 0) |
---|
3727 | { |
---|
3728 | if(count($this->added) > 0) |
---|
3729 | { |
---|
3730 | $this->ex_participants = ''; |
---|
3731 | $this->send_update(MSG_ADDED,$this->added,'',$new_event); |
---|
3732 | } |
---|
3733 | if(count($this->modified) > 0) |
---|
3734 | { |
---|
3735 | $this->send_update(MSG_MODIFIED,$this->modified,$old_event,$new_event); |
---|
3736 | } |
---|
3737 | if(count($this->deleted) > 0) |
---|
3738 | { |
---|
3739 | $this->ex_participants = ''; |
---|
3740 | $this->send_update(MSG_DELETED,$this->deleted,$old_event); |
---|
3741 | } |
---|
3742 | } |
---|
3743 | } |
---|
3744 | |
---|
3745 | function remove_doubles_in_cache($firstday,$lastday) |
---|
3746 | { |
---|
3747 | $already_moved = Array(); |
---|
3748 | for($v=$firstday;$v<=$lastday;$v++) |
---|
3749 | { |
---|
3750 | if (!$this->cached_events[$v]) |
---|
3751 | { |
---|
3752 | continue; |
---|
3753 | } |
---|
3754 | $cached = $this->cached_events[$v]; |
---|
3755 | $this->cached_events[$v] = array(); |
---|
3756 | while (list($g,$event) = each($cached)) |
---|
3757 | { |
---|
3758 | $end = date('Ymd',$this->maketime($event['end'])); |
---|
3759 | print_debug('EVENT',_debug_array($event,False)); |
---|
3760 | print_debug('start',$start); |
---|
3761 | print_debug('v',$v); |
---|
3762 | |
---|
3763 | if (!isset($already_moved[$event['id']]) || $event['recur_type'] && $v > $end) |
---|
3764 | { |
---|
3765 | $this->cached_events[$v][] = $event; |
---|
3766 | $already_moved[$event['id']] = 1; |
---|
3767 | print_debug('Event moved'); |
---|
3768 | } |
---|
3769 | } |
---|
3770 | } |
---|
3771 | } |
---|
3772 | |
---|
3773 | function get_dirty_entries($lastmod=-1) |
---|
3774 | { |
---|
3775 | $events = false; |
---|
3776 | $event_ids = $this->so->cal->list_dirty_events($lastmod); |
---|
3777 | if(is_array($event_ids)) |
---|
3778 | { |
---|
3779 | foreach($event_ids as $key => $id) |
---|
3780 | { |
---|
3781 | $events[$id] = $this->so->cal->fetch_event($id); |
---|
3782 | } |
---|
3783 | } |
---|
3784 | unset($event_ids); |
---|
3785 | |
---|
3786 | $rep_event_ids = $this->so->cal->list_dirty_events($lastmod,$true); |
---|
3787 | if(is_array($rep_event_ids)) |
---|
3788 | { |
---|
3789 | foreach($rep_event_ids as $key => $id) |
---|
3790 | { |
---|
3791 | $events[$id] = $this->so->cal->fetch_event($id); |
---|
3792 | } |
---|
3793 | } |
---|
3794 | unset($rep_event_ids); |
---|
3795 | |
---|
3796 | return $events; |
---|
3797 | } |
---|
3798 | |
---|
3799 | function _debug_array($data) |
---|
3800 | { |
---|
3801 | echo '<br>UI:'; |
---|
3802 | _debug_array($data); |
---|
3803 | } |
---|
3804 | |
---|
3805 | /*! |
---|
3806 | @function rejected_no_show |
---|
3807 | @abstract checks if event is rejected from user and he's not the owner and dont want rejected |
---|
3808 | @param $event to check |
---|
3809 | @returns True if event should not be shown |
---|
3810 | */ |
---|
3811 | function rejected_no_show($event) |
---|
3812 | { |
---|
3813 | $ret = !$this->prefs['calendar']['show_rejected'] && |
---|
3814 | $event['owner'] != $this->owner && |
---|
3815 | $event['participants'][$this->owner] == 'R'; |
---|
3816 | //echo "<p>rejected_no_show($event[title])='$ret': user=$this->owner, event-owner=$event[owner], status='".$event['participants'][$this->owner]."', show_rejected='".$this->prefs['calendar']['show_rejected']."'</p>\n"; |
---|
3817 | return $ret; |
---|
3818 | } |
---|
3819 | |
---|
3820 | /* This is called only by list_cals(). It was moved here to remove fatal error in php5 beta4 */ |
---|
3821 | function list_cals_add($id,&$users,&$groups) |
---|
3822 | { |
---|
3823 | $name = $GLOBALS['phpgw']->common->grab_owner_name($id); |
---|
3824 | if (($type = $GLOBALS['phpgw']->accounts->get_type($id)) == 'g') |
---|
3825 | { |
---|
3826 | $arr = &$groups; |
---|
3827 | } |
---|
3828 | else |
---|
3829 | { |
---|
3830 | $arr = &$users; |
---|
3831 | } |
---|
3832 | $arr[$name] = Array( |
---|
3833 | 'grantor' => $id, |
---|
3834 | 'value' => ($type == 'g' ? 'g_' : '') . $id, |
---|
3835 | 'name' => $name |
---|
3836 | ); |
---|
3837 | } |
---|
3838 | |
---|
3839 | /*! |
---|
3840 | @function list_cals |
---|
3841 | @abstract generate list of user- / group-calendars for the selectbox in the header |
---|
3842 | @returns alphabeticaly sorted array with groups first and then users |
---|
3843 | */ |
---|
3844 | function list_cals() |
---|
3845 | { |
---|
3846 | $users = $groups = array(); |
---|
3847 | foreach($this->grants as $id => $rights) |
---|
3848 | { |
---|
3849 | $this->list_cals_add($id,$users,$groups); |
---|
3850 | } |
---|
3851 | |
---|
3852 | //by JakJr, melhora de performance na abertura da agenda |
---|
3853 | /*if ($memberships = $GLOBALS['phpgw']->accounts->membership($GLOBALS['phpgw_info']['user']['account_id'])) |
---|
3854 | { |
---|
3855 | foreach($memberships as $group_info) |
---|
3856 | { |
---|
3857 | $this->list_cals_add($group_info['account_id'],$users,$groups); |
---|
3858 | |
---|
3859 | if ($account_perms = $GLOBALS['phpgw']->acl->get_ids_for_location($group_info['account_id'],PHPGW_ACL_READ,'calendar')) |
---|
3860 | { |
---|
3861 | foreach($account_perms as $id) |
---|
3862 | { |
---|
3863 | $this->list_cals_add($id,$users,$groups); |
---|
3864 | } |
---|
3865 | } |
---|
3866 | } |
---|
3867 | }*/ |
---|
3868 | uksort($users,'strnatcasecmp'); |
---|
3869 | uksort($groups,'strnatcasecmp'); |
---|
3870 | |
---|
3871 | return $users + $groups; // users first and then groups, both alphabeticaly |
---|
3872 | } |
---|
3873 | |
---|
3874 | function translate($key,$vars=false, $not_found='*' ) |
---|
3875 | { |
---|
3876 | if ($this->async) |
---|
3877 | return $GLOBALS['phpgw']->translation->translate_async($key, $vars); |
---|
3878 | return lang($key, $vars); |
---|
3879 | } |
---|
3880 | |
---|
3881 | /*! |
---|
3882 | @function event2array |
---|
3883 | @abstract create array with name, translated name and readable content of each attributes of an event |
---|
3884 | @syntax event2array($event,$sep='<br>') |
---|
3885 | @param $event event to use |
---|
3886 | @returns array of attributes with fieldname as key and array with the 'field'=translated name \ |
---|
3887 | 'data' = readable content (for participants this is an array !) |
---|
3888 | */ |
---|
3889 | function event2array($event) |
---|
3890 | { |
---|
3891 | |
---|
3892 | |
---|
3893 | $var['title'] = Array( |
---|
3894 | 'field' => $this->translate('Title'), |
---|
3895 | 'data' => $event['title'] |
---|
3896 | ); |
---|
3897 | |
---|
3898 | // Some browser add a \n when its entered in the database. Not a big deal |
---|
3899 | // this will be printed even though its not needed. |
---|
3900 | $var['description'] = Array( |
---|
3901 | 'field' => $this->translate('Description'), |
---|
3902 | 'data' => $event['description'] |
---|
3903 | ); |
---|
3904 | |
---|
3905 | $var['ex_participants'] = Array( |
---|
3906 | 'field' => $this->translate('External Participants'), |
---|
3907 | 'data' => $event['ex_participants'] |
---|
3908 | ); |
---|
3909 | |
---|
3910 | $cats = Array(); |
---|
3911 | $this->cat->categories($this->bo->owner,'calendar'); |
---|
3912 | if(strpos($event['category'],',')) |
---|
3913 | { |
---|
3914 | $cats = explode(',',$event['category']); |
---|
3915 | } |
---|
3916 | else |
---|
3917 | { |
---|
3918 | $cats[] = $event['category']; |
---|
3919 | } |
---|
3920 | foreach($cats as $cat_id) |
---|
3921 | { |
---|
3922 | list($cat) = $this->cat->return_single($cat_id); |
---|
3923 | $cat_string[] = $cat['name']; |
---|
3924 | } |
---|
3925 | $var['category'] = Array( |
---|
3926 | 'field' => $this->translate('Category'), |
---|
3927 | 'data' => implode(', ',$cat_string) |
---|
3928 | ); |
---|
3929 | |
---|
3930 | $var['location'] = Array( |
---|
3931 | 'field' => $this->translate('Location'), |
---|
3932 | 'data' => $event['location'] |
---|
3933 | ); |
---|
3934 | |
---|
3935 | $var['startdate'] = Array( |
---|
3936 | 'field' => $this->translate('Start Date/Time'), |
---|
3937 | 'data' => $GLOBALS['phpgw']->common->show_date($this->maketime($event['start']) - $GLOBALS['phpgw']->datetime->tz_offset), |
---|
3938 | ); |
---|
3939 | |
---|
3940 | $var['enddate'] = Array( |
---|
3941 | 'field' => $this->translate('End Date/Time'), |
---|
3942 | 'data' => $GLOBALS['phpgw']->common->show_date($this->maketime($event['end']) - $GLOBALS['phpgw']->datetime->tz_offset) |
---|
3943 | ); |
---|
3944 | |
---|
3945 | $pri = Array( |
---|
3946 | 1 => lang('Low'), |
---|
3947 | 2 => lang('Normal'), |
---|
3948 | 3 => lang('High') |
---|
3949 | ); |
---|
3950 | $var['priority'] = Array( |
---|
3951 | 'field' => lang('Priority'), |
---|
3952 | 'data' => $pri[$event['priority']] |
---|
3953 | ); |
---|
3954 | |
---|
3955 | $var['owner'] = Array( |
---|
3956 | 'field' => lang('Created By'), |
---|
3957 | 'data' => $GLOBALS['phpgw']->common->grab_owner_name($event['owner']) |
---|
3958 | ); |
---|
3959 | |
---|
3960 | $var['updated'] = Array( |
---|
3961 | 'field' => lang('Updated'), |
---|
3962 | 'data' => $GLOBALS['phpgw']->common->show_date($this->maketime($event['modtime']) - $GLOBALS['phpgw']->datetime->tz_offset) |
---|
3963 | ); |
---|
3964 | |
---|
3965 | $var['attachment'] = Array( |
---|
3966 | 'field' => $this->translate('Attachment'), |
---|
3967 | 'data' => $event['attachment'] |
---|
3968 | ); |
---|
3969 | |
---|
3970 | $var['alter_by'] = Array( |
---|
3971 | 'field' => $this->translate('Alter by'), |
---|
3972 | 'data' => $event['alter_by'] |
---|
3973 | ); |
---|
3974 | |
---|
3975 | $var['access'] = Array( |
---|
3976 | 'field' => lang('Access'), |
---|
3977 | 'data' => $event['public'] ? lang('Public') : lang('Private') |
---|
3978 | ); |
---|
3979 | |
---|
3980 | if(@isset($event['groups'][0])) |
---|
3981 | { |
---|
3982 | $cal_grps = ''; |
---|
3983 | for($i=0;$i<count($event['groups']);$i++) |
---|
3984 | { |
---|
3985 | if($GLOBALS['phpgw']->accounts->exists($event['groups'][$i])) |
---|
3986 | { |
---|
3987 | $cal_grps .= ($i>0?'<br>':'').$GLOBALS['phpgw']->accounts->id2name($event['groups'][$i]); |
---|
3988 | } |
---|
3989 | } |
---|
3990 | |
---|
3991 | $var['groups'] = Array( |
---|
3992 | 'field' => lang('Groups'), |
---|
3993 | 'data' => $cal_grps |
---|
3994 | ); |
---|
3995 | } |
---|
3996 | |
---|
3997 | $participants = array(); |
---|
3998 | foreach($event['participants'] as $user => $short_status) |
---|
3999 | { |
---|
4000 | if($GLOBALS['phpgw']->accounts->exists($user)) |
---|
4001 | { |
---|
4002 | $participants[$user] = $GLOBALS['phpgw']->common->grab_owner_name($user).' ('.$this->get_long_status($short_status).')'; |
---|
4003 | } |
---|
4004 | } |
---|
4005 | $var['participants'] = Array( |
---|
4006 | 'field' => $this->translate('Participants'), |
---|
4007 | 'data' => $participants |
---|
4008 | ); |
---|
4009 | |
---|
4010 | // Repeated Events |
---|
4011 | if($event['recur_type'] != MCAL_RECUR_NONE) |
---|
4012 | { |
---|
4013 | $str = lang($this->rpt_type[$event['recur_type']]); |
---|
4014 | |
---|
4015 | $str_extra = array(); |
---|
4016 | if ($event['recur_enddate']['mday'] != 0 && $event['recur_enddate']['month'] != 0 && $event['recur_enddate']['year'] != 0) |
---|
4017 | { |
---|
4018 | $recur_end = $this->maketime($event['recur_enddate']); |
---|
4019 | if($recur_end != 0) |
---|
4020 | { |
---|
4021 | $recur_end -= $GLOBALS['phpgw']->datetime->tz_offset; |
---|
4022 | $str_extra[] = lang('ends').': '.lang($GLOBALS['phpgw']->common->show_date($recur_end,'l')).', '.$this->long_date($recur_end).' '; |
---|
4023 | } |
---|
4024 | } |
---|
4025 | // only weekly uses the recur-data (days) !!! |
---|
4026 | if($event['recur_type'] == MCAL_RECUR_WEEKLY) |
---|
4027 | { |
---|
4028 | $repeat_days = array(); |
---|
4029 | foreach ($this->rpt_day as $mcal_mask => $dayname) |
---|
4030 | { |
---|
4031 | if ($event['recur_data'] & $mcal_mask) |
---|
4032 | { |
---|
4033 | $repeat_days[] = lang($dayname); |
---|
4034 | } |
---|
4035 | } |
---|
4036 | if(count($repeat_days)) |
---|
4037 | { |
---|
4038 | $str_extra[] = lang('days repeated').': '.implode(', ',$repeat_days); |
---|
4039 | } |
---|
4040 | } |
---|
4041 | if($event['recur_interval'] != 0) |
---|
4042 | { |
---|
4043 | $str_extra[] = lang('Interval').': '.$event['recur_interval']; |
---|
4044 | } |
---|
4045 | |
---|
4046 | if(count($str_extra)) |
---|
4047 | { |
---|
4048 | $str .= ' ('.implode(', ',$str_extra).')'; |
---|
4049 | } |
---|
4050 | |
---|
4051 | $var['recure_type'] = Array( |
---|
4052 | 'field' => lang('Repetition'), |
---|
4053 | 'data' => $str, |
---|
4054 | ); |
---|
4055 | } |
---|
4056 | |
---|
4057 | if (!isset($this->fields)) |
---|
4058 | { |
---|
4059 | $this->custom_fields = CreateObject('calendar.bocustom_fields'); |
---|
4060 | $this->fields = &$this->custom_fields->fields; |
---|
4061 | $this->stock_fields = &$this->custom_fields->stock_fields; |
---|
4062 | } |
---|
4063 | foreach($this->fields as $field => $data) |
---|
4064 | { |
---|
4065 | if (!$data['disabled']) |
---|
4066 | { |
---|
4067 | if (isset($var[$field])) |
---|
4068 | { |
---|
4069 | $sorted[$field] = $var[$field]; |
---|
4070 | } |
---|
4071 | elseif (!isset($this->stock_fields[$field]) && strlen($event[$field])) // Custom field |
---|
4072 | { |
---|
4073 | $lang = lang($name = substr($field,1)); |
---|
4074 | $sorted[$field] = array( |
---|
4075 | 'field' => $lang == $name.'*' ? $name : $lang, |
---|
4076 | 'data' => $event[$field] |
---|
4077 | ); |
---|
4078 | } |
---|
4079 | } |
---|
4080 | unset($var[$field]); |
---|
4081 | } |
---|
4082 | foreach($var as $name => $v) |
---|
4083 | { |
---|
4084 | $sorted[$name] = $v; |
---|
4085 | |
---|
4086 | } |
---|
4087 | return $sorted; |
---|
4088 | } |
---|
4089 | |
---|
4090 | /*! |
---|
4091 | @function check_set_default_prefs |
---|
4092 | @abstract sets the default prefs, if they are not already set (on a per pref. basis) |
---|
4093 | @note It sets a flag in the app-session-data to be called only once per session |
---|
4094 | */ |
---|
4095 | function check_set_default_prefs() |
---|
4096 | { |
---|
4097 | if (($set = $GLOBALS['phpgw']->session->appsession('default_prefs_set','calendar'))) |
---|
4098 | { |
---|
4099 | return; |
---|
4100 | } |
---|
4101 | $GLOBALS['phpgw']->session->appsession('default_prefs_set','calendar','set'); |
---|
4102 | |
---|
4103 | $default_prefs = $GLOBALS['phpgw']->preferences->default['calendar']; |
---|
4104 | |
---|
4105 | $subject = $this->translate('Calendar Event') . ' - $$action$$: $$startdate$$ $$title$$'."\n"; |
---|
4106 | $defaults = array( |
---|
4107 | 'defaultcalendar' => 'week', |
---|
4108 | 'mainscreen_showevents' => '0', |
---|
4109 | 'summary' => 'no', |
---|
4110 | 'receive_updates' => 'no', |
---|
4111 | 'update_format' => 'extended', // leave it to extended for now, as iCal kills the message-body |
---|
4112 | 'notifyAdded' => $subject . $this->translate ('You have a meeting scheduled for %1',array('$$startdate$$')), |
---|
4113 | 'notifyCanceled' => $subject . $this->translate ('Your meeting scheduled for %1 has been canceled',array('$$startdate$$')), |
---|
4114 | 'notifyModified' => $subject . $this->translate ('Your meeting that had been scheduled for %1 has been rescheduled to %2',array('$$olddate$$','$$startdate$$')), |
---|
4115 | 'notifyResponse' => $subject . $this->translate ('On %1 %2 %3 your meeting request for %4', array('$$date$$','$$fullname$$','$$action$$','$$startdate$$')), |
---|
4116 | 'notifyAlarm' => $this->translate('Alarm for %1 at %2 in %3',array('$$title$$','$$startdate$$','$$location$$')) . "\n" . $this->translate('Here is your requested alarm.'), |
---|
4117 | 'show_rejected' => '0', |
---|
4118 | 'hide_event_conflict' => '0', |
---|
4119 | 'display_status' => '1', |
---|
4120 | 'weekdaystarts' => 'Monday', |
---|
4121 | 'workdaystarts' => '9', |
---|
4122 | 'workdayends' => '17', |
---|
4123 | 'interval' => '30', |
---|
4124 | 'defaultlength' => '60', |
---|
4125 | 'planner_start_with_group' => $GLOBALS['phpgw']->accounts->name2id('Default'), |
---|
4126 | 'planner_intervals_per_day'=> '4', |
---|
4127 | 'defaultfilter' => 'all', |
---|
4128 | 'default_private' => '0', |
---|
4129 | 'display_minicals'=> '1', |
---|
4130 | 'print_black_white'=>'0' |
---|
4131 | ); |
---|
4132 | foreach($defaults as $var => $default) |
---|
4133 | { |
---|
4134 | if (!isset($default_prefs[$var]) || $default_prefs[$var] == '') |
---|
4135 | { |
---|
4136 | $GLOBALS['phpgw']->preferences->add('calendar',$var,$default,'default'); |
---|
4137 | $need_save = True; |
---|
4138 | } |
---|
4139 | } |
---|
4140 | if ($need_save) |
---|
4141 | { |
---|
4142 | $prefs = $GLOBALS['phpgw']->preferences->save_repository(False,'default'); |
---|
4143 | $this->prefs['calendar'] = $prefs['calendar']; |
---|
4144 | } |
---|
4145 | if ($this->prefs['calendar']['send_updates'] && !isset($this->prefs['calendar']['receive_updates'])) |
---|
4146 | { |
---|
4147 | $this->prefs['calendar']['receive_updates'] = $this->prefs['calendar']['send_updates']; |
---|
4148 | $GLOBALS['phpgw']->preferences->add('calendar','receive_updates',$this->prefs['calendar']['send_updates']); |
---|
4149 | $GLOBALS['phpgw']->preferences->delete('calendar','send_updates'); |
---|
4150 | $prefs = $GLOBALS['phpgw']->preferences->save_repository(); |
---|
4151 | } |
---|
4152 | } |
---|
4153 | |
---|
4154 | // return array with all infolog categories (for xmlrpc) |
---|
4155 | function categories($complete = False) |
---|
4156 | { |
---|
4157 | return $GLOBALS['server']->categories($complete); |
---|
4158 | } |
---|
4159 | } |
---|
4160 | ?> |
---|