@@ -19,40 +19,40 @@ discard block |
||
19 | 19 | /** |
20 | 20 | * some necessary defines used by the calendar |
21 | 21 | */ |
22 | -if(!extension_loaded('mcal')) |
|
22 | +if (!extension_loaded('mcal')) |
|
23 | 23 | { |
24 | - define('MCAL_RECUR_NONE',0); |
|
25 | - define('MCAL_RECUR_DAILY',1); |
|
26 | - define('MCAL_RECUR_WEEKLY',2); |
|
27 | - define('MCAL_RECUR_MONTHLY_MDAY',3); |
|
28 | - define('MCAL_RECUR_MONTHLY_WDAY',4); |
|
29 | - define('MCAL_RECUR_YEARLY',5); |
|
30 | - define('MCAL_RECUR_SECONDLY',6); |
|
31 | - define('MCAL_RECUR_MINUTELY',7); |
|
32 | - define('MCAL_RECUR_HOURLY',8); |
|
33 | - |
|
34 | - define('MCAL_M_SUNDAY',1); |
|
35 | - define('MCAL_M_MONDAY',2); |
|
36 | - define('MCAL_M_TUESDAY',4); |
|
37 | - define('MCAL_M_WEDNESDAY',8); |
|
38 | - define('MCAL_M_THURSDAY',16); |
|
39 | - define('MCAL_M_FRIDAY',32); |
|
40 | - define('MCAL_M_SATURDAY',64); |
|
41 | - |
|
42 | - define('MCAL_M_WEEKDAYS',62); |
|
43 | - define('MCAL_M_WEEKEND',65); |
|
44 | - define('MCAL_M_ALLDAYS',127); |
|
24 | + define('MCAL_RECUR_NONE', 0); |
|
25 | + define('MCAL_RECUR_DAILY', 1); |
|
26 | + define('MCAL_RECUR_WEEKLY', 2); |
|
27 | + define('MCAL_RECUR_MONTHLY_MDAY', 3); |
|
28 | + define('MCAL_RECUR_MONTHLY_WDAY', 4); |
|
29 | + define('MCAL_RECUR_YEARLY', 5); |
|
30 | + define('MCAL_RECUR_SECONDLY', 6); |
|
31 | + define('MCAL_RECUR_MINUTELY', 7); |
|
32 | + define('MCAL_RECUR_HOURLY', 8); |
|
33 | + |
|
34 | + define('MCAL_M_SUNDAY', 1); |
|
35 | + define('MCAL_M_MONDAY', 2); |
|
36 | + define('MCAL_M_TUESDAY', 4); |
|
37 | + define('MCAL_M_WEDNESDAY', 8); |
|
38 | + define('MCAL_M_THURSDAY', 16); |
|
39 | + define('MCAL_M_FRIDAY', 32); |
|
40 | + define('MCAL_M_SATURDAY', 64); |
|
41 | + |
|
42 | + define('MCAL_M_WEEKDAYS', 62); |
|
43 | + define('MCAL_M_WEEKEND', 65); |
|
44 | + define('MCAL_M_ALLDAYS', 127); |
|
45 | 45 | } |
46 | 46 | |
47 | -define('REJECTED',0); |
|
48 | -define('NO_RESPONSE',1); |
|
49 | -define('TENTATIVE',2); |
|
50 | -define('ACCEPTED',3); |
|
51 | -define('DELEGATED',4); |
|
47 | +define('REJECTED', 0); |
|
48 | +define('NO_RESPONSE', 1); |
|
49 | +define('TENTATIVE', 2); |
|
50 | +define('ACCEPTED', 3); |
|
51 | +define('DELEGATED', 4); |
|
52 | 52 | |
53 | -define('HOUR_s',60*60); |
|
54 | -define('DAY_s',24*HOUR_s); |
|
55 | -define('WEEK_s',7*DAY_s); |
|
53 | +define('HOUR_s', 60 * 60); |
|
54 | +define('DAY_s', 24 * HOUR_s); |
|
55 | +define('WEEK_s', 7 * DAY_s); |
|
56 | 56 | |
57 | 57 | /** |
58 | 58 | * Class to store all calendar data (storage object) |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | * name of the main calendar table and prefix for all other calendar tables |
101 | 101 | */ |
102 | 102 | var $cal_table = 'egw_cal'; |
103 | - var $extra_table,$repeats_table,$user_table,$dates_table,$all_tables; |
|
103 | + var $extra_table, $repeats_table, $user_table, $dates_table, $all_tables; |
|
104 | 104 | |
105 | 105 | /** |
106 | 106 | * reference to global db-object |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | $this->db = $GLOBALS['egw']->db; |
142 | 142 | |
143 | 143 | $this->all_tables = array($this->cal_table); |
144 | - foreach(array('extra','repeats','user','dates') as $name) |
|
144 | + foreach (array('extra', 'repeats', 'user', 'dates') as $name) |
|
145 | 145 | { |
146 | 146 | $vname = $name.'_table'; |
147 | 147 | $this->all_tables[] = $this->$vname = $this->cal_table.'_'.$name; |
@@ -157,11 +157,11 @@ discard block |
||
157 | 157 | * @param boolean $deleted =false |
158 | 158 | * @return string |
159 | 159 | */ |
160 | - protected function cal_range_view($start, $end, array $_where=null, $deleted=false) |
|
160 | + protected function cal_range_view($start, $end, array $_where = null, $deleted = false) |
|
161 | 161 | { |
162 | 162 | if ($GLOBALS['egw_info']['server']['no_timerange_views'] || !$start) // using view without start-date is slower! |
163 | 163 | { |
164 | - return $this->cal_table; // no need / use for a view |
|
164 | + return $this->cal_table; // no need / use for a view |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | $where = array(); |
@@ -187,11 +187,11 @@ discard block |
||
187 | 187 | * @param boolean $deleted =false |
188 | 188 | * @return string |
189 | 189 | */ |
190 | - protected function dates_range_view($start, $end, array $_where=null, $deleted=false) |
|
190 | + protected function dates_range_view($start, $end, array $_where = null, $deleted = false) |
|
191 | 191 | { |
192 | 192 | if ($GLOBALS['egw_info']['server']['no_timerange_views'] || !$start || !$end) // using view without start- AND end-date is slower! |
193 | 193 | { |
194 | - return $this->dates_table; // no need / use for a view |
|
194 | + return $this->dates_table; // no need / use for a view |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | $where = array(); |
@@ -236,14 +236,14 @@ discard block |
||
236 | 236 | * @param int $remove_rejected_by_user =null add join to remove entry, if given user has rejected it |
237 | 237 | * @return array of events |
238 | 238 | */ |
239 | - function &events($start,$end,$users,$cat_id=0,$filter='all',$offset=False,$num_rows=0,array $params=array(),$remove_rejected_by_user=null) |
|
239 | + function &events($start, $end, $users, $cat_id = 0, $filter = 'all', $offset = False, $num_rows = 0, array $params = array(), $remove_rejected_by_user = null) |
|
240 | 240 | { |
241 | - error_log(__METHOD__.'('.($start ? date('Y-m-d H:i',$start) : '').','.($end ? date('Y-m-d H:i',$end) : '').','.array2string($users).','.array2string($cat_id).",'$filter',".array2string($offset).",$num_rows,".array2string($params).') '.function_backtrace()); |
|
241 | + error_log(__METHOD__.'('.($start ? date('Y-m-d H:i', $start) : '').','.($end ? date('Y-m-d H:i', $end) : '').','.array2string($users).','.array2string($cat_id).",'$filter',".array2string($offset).",$num_rows,".array2string($params).') '.function_backtrace()); |
|
242 | 242 | $start_time = microtime(true); |
243 | 243 | // not everything is supported by now |
244 | 244 | if (!$start || !$end || is_string($params['query']) || |
245 | 245 | //in_array($filter,array('owner','deleted')) || |
246 | - $params['enum_recuring']===false) |
|
246 | + $params['enum_recuring'] === false) |
|
247 | 247 | { |
248 | 248 | throw new Api\Exception\AssertionFailed("Unsupported value for parameters!"); |
249 | 249 | } |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | { |
271 | 271 | // fix $users to also prefix system users and groups (with 'u') |
272 | 272 | if (!is_array($users)) $users = $users ? (array)$users : array(); |
273 | - foreach($users as &$uid) |
|
273 | + foreach ($users as &$uid) |
|
274 | 274 | { |
275 | 275 | $user_type = $user_id = null; |
276 | 276 | self::split_user($uid, $user_type, $user_id, true); |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | |
292 | 292 | if ($params['order']) // only order if requested |
293 | 293 | { |
294 | - if (!preg_match('/^[a-z_ ,c]+$/i',$params['order'])) $params['order'] = 'cal_start'; // gard against SQL injection |
|
294 | + if (!preg_match('/^[a-z_ ,c]+$/i', $params['order'])) $params['order'] = 'cal_start'; // gard against SQL injection |
|
295 | 295 | $sql .= "\nORDER BY ".$params['order']; |
296 | 296 | } |
297 | 297 | |
@@ -300,8 +300,8 @@ discard block |
||
300 | 300 | $offset = 0; |
301 | 301 | $num_rows = -1; |
302 | 302 | } |
303 | - $events =& $this->get_events($this->db->query($sql, __LINE__, __FILE__, $offset, $num_rows)); |
|
304 | - error_log(__METHOD__."(...) $sql --> ".number_format(microtime(true)-$start_time, 3)); |
|
303 | + $events = & $this->get_events($this->db->query($sql, __LINE__, __FILE__, $offset, $num_rows)); |
|
304 | + error_log(__METHOD__."(...) $sql --> ".number_format(microtime(true) - $start_time, 3)); |
|
305 | 305 | return $events; |
306 | 306 | } |
307 | 307 | |
@@ -315,12 +315,12 @@ discard block |
||
315 | 315 | * @param boolean $read_recurrence =false true: read the exception, not the series master (only for recur_date && $ids='<uid>'!) |
316 | 316 | * @return array|boolean array with cal_id => event array pairs or false if entry not found |
317 | 317 | */ |
318 | - function read($ids, $recur_date=0, $read_recurrence=false) |
|
318 | + function read($ids, $recur_date = 0, $read_recurrence = false) |
|
319 | 319 | { |
320 | 320 | //error_log(__METHOD__.'('.array2string($ids).",$recur_date) ".function_backtrace()); |
321 | 321 | $cols = self::get_columns('calendar', $this->cal_table); |
322 | 322 | $cols[0] = $this->db->to_varchar($this->cal_table.'.cal_id'); |
323 | - $cols = "$this->repeats_table.recur_type,$this->repeats_table.recur_interval,$this->repeats_table.recur_data,".implode(',',$cols); |
|
323 | + $cols = "$this->repeats_table.recur_type,$this->repeats_table.recur_interval,$this->repeats_table.recur_data,".implode(',', $cols); |
|
324 | 324 | $join = "LEFT JOIN $this->repeats_table ON $this->cal_table.cal_id=$this->repeats_table.cal_id"; |
325 | 325 | |
326 | 326 | $where = array(); |
@@ -337,23 +337,23 @@ discard block |
||
337 | 337 | $where['cal_reference'] = 0; |
338 | 338 | } |
339 | 339 | } |
340 | - elseif(is_array($ids) && isset($ids[count($ids)-1]) || is_scalar($ids)) // one or more cal_id's |
|
340 | + elseif (is_array($ids) && isset($ids[count($ids) - 1]) || is_scalar($ids)) // one or more cal_id's |
|
341 | 341 | { |
342 | 342 | $where['cal_id'] = $ids; |
343 | 343 | } |
344 | 344 | else // array with column => value pairs |
345 | 345 | { |
346 | 346 | $where = $ids; |
347 | - unset($ids); // otherwise users get not read! |
|
347 | + unset($ids); // otherwise users get not read! |
|
348 | 348 | } |
349 | 349 | if (isset($where['cal_id'])) // prevent non-unique column-name cal_id |
350 | 350 | { |
351 | - $where[] = $this->db->expression($this->cal_table, $this->cal_table.'.',array( |
|
351 | + $where[] = $this->db->expression($this->cal_table, $this->cal_table.'.', array( |
|
352 | 352 | 'cal_id' => $where['cal_id'], |
353 | 353 | )); |
354 | 354 | unset($where['cal_id']); |
355 | 355 | } |
356 | - if ((int) $recur_date && !$read_recurrence) |
|
356 | + if ((int)$recur_date && !$read_recurrence) |
|
357 | 357 | { |
358 | 358 | $where[] = 'cal_start >= '.(int)$recur_date; |
359 | 359 | $group_by = 'GROUP BY '.$cols; |
@@ -366,7 +366,7 @@ discard block |
||
366 | 366 | } |
367 | 367 | $cols .= ',range_end-1 AS recur_enddate'; |
368 | 368 | |
369 | - $events =& $this->get_events($this->db->select($this->cal_table, $cols, $where, __LINE__, __FILE__, false, $group_by, 'calendar', 0, $join), $recur_date); |
|
369 | + $events = & $this->get_events($this->db->select($this->cal_table, $cols, $where, __LINE__, __FILE__, false, $group_by, 'calendar', 0, $join), $recur_date); |
|
370 | 370 | |
371 | 371 | // if we wanted to read the real recurrence, but we have eg. only a virtual one, we need to try again without $read_recurrence |
372 | 372 | if ((!$events || ($e = current($events)) && $e['deleted']) && $recur_date && $read_recurrence) |
@@ -384,7 +384,7 @@ discard block |
||
384 | 384 | * @param int $recur_date =0 |
385 | 385 | * @return array |
386 | 386 | */ |
387 | - protected function &get_events($rs, $recur_date=0) |
|
387 | + protected function &get_events($rs, $recur_date = 0) |
|
388 | 388 | { |
389 | 389 | if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'])) |
390 | 390 | { |
@@ -396,7 +396,7 @@ discard block |
||
396 | 396 | } |
397 | 397 | |
398 | 398 | $events = array(); |
399 | - foreach($rs as $row) |
|
399 | + foreach ($rs as $row) |
|
400 | 400 | { |
401 | 401 | if (!$row['recur_type']) |
402 | 402 | { |
@@ -404,7 +404,7 @@ discard block |
||
404 | 404 | unset($row['recur_enddate']); |
405 | 405 | } |
406 | 406 | $row['recur_exception'] = $row['alarm'] = array(); |
407 | - $events[$row['cal_id']] = Api\Db::strip_array_keys($row,'cal_'); |
|
407 | + $events[$row['cal_id']] = Api\Db::strip_array_keys($row, 'cal_'); |
|
408 | 408 | } |
409 | 409 | if (!$events) return $events; |
410 | 410 | |
@@ -416,26 +416,26 @@ discard block |
||
416 | 416 | if (!isset($event['uid']) || strlen($event['uid']) < $minimum_uid_length) |
417 | 417 | { |
418 | 418 | // event (without uid), not strong enough uid => create new uid |
419 | - $event['uid'] = Api\CalDAV::generate_uid('calendar',$event['id']); |
|
419 | + $event['uid'] = Api\CalDAV::generate_uid('calendar', $event['id']); |
|
420 | 420 | $this->db->update($this->cal_table, array('cal_uid' => $event['uid']), |
421 | - array('cal_id' => $event['id']),__LINE__,__FILE__,'calendar'); |
|
421 | + array('cal_id' => $event['id']), __LINE__, __FILE__, 'calendar'); |
|
422 | 422 | } |
423 | 423 | if (!(int)$recur_date && $event['recur_type'] != MCAL_RECUR_NONE) |
424 | 424 | { |
425 | - foreach($this->db->select($this->dates_table, 'cal_id,cal_start', array( |
|
425 | + foreach ($this->db->select($this->dates_table, 'cal_id,cal_start', array( |
|
426 | 426 | 'cal_id' => $ids, |
427 | 427 | 'recur_exception' => true, |
428 | 428 | ), __LINE__, __FILE__, false, 'ORDER BY cal_id,cal_start', 'calendar') as $row) |
429 | 429 | { |
430 | 430 | $events[$row['cal_id']]['recur_exception'][] = $row['cal_start']; |
431 | 431 | } |
432 | - break; // as above select read all exceptions (and I dont think too short uid problem still exists) |
|
432 | + break; // as above select read all exceptions (and I dont think too short uid problem still exists) |
|
433 | 433 | } |
434 | 434 | // make sure we fetch only real exceptions (deleted occurrences of a series should not show up) |
435 | - if (($recur_date && $event['recur_type'] != MCAL_RECUR_NONE)) |
|
435 | + if (($recur_date && $event['recur_type'] != MCAL_RECUR_NONE)) |
|
436 | 436 | { |
437 | 437 | //_debug_array(__METHOD__.__LINE__.' recur_date:'.$recur_date.' check cal_start:'.$event['start']); |
438 | - foreach($this->db->select($this->dates_table, 'cal_id,cal_start', array( |
|
438 | + foreach ($this->db->select($this->dates_table, 'cal_id,cal_start', array( |
|
439 | 439 | 'cal_id' => $event['id'], |
440 | 440 | 'cal_start' => $event['start'], |
441 | 441 | 'recur_exception' => true, |
@@ -451,7 +451,7 @@ discard block |
||
451 | 451 | 'cal_deleted' => NULL |
452 | 452 | ), __LINE__, __FILE__, false, '', 'calendar')->fetchColumn()) |
453 | 453 | { |
454 | - $e = $this->read($event['id'],$event['start']+1); |
|
454 | + $e = $this->read($event['id'], $event['start'] + 1); |
|
455 | 455 | $event = $e[$event['id']]; |
456 | 456 | break; |
457 | 457 | } |
@@ -473,21 +473,21 @@ discard block |
||
473 | 473 | if ($recur_date) |
474 | 474 | { |
475 | 475 | // also remember recur_date, maybe we need it later, duno now |
476 | - $recur_date = array(0,$events[$ids]['recur_date'] = $events[$ids]['start']); |
|
476 | + $recur_date = array(0, $events[$ids]['recur_date'] = $events[$ids]['start']); |
|
477 | 477 | } |
478 | 478 | } |
479 | 479 | |
480 | 480 | // participants, if a recur_date give, we read that recurance, plus the one users from the default entry with recur_date=0 |
481 | 481 | // sorting by cal_recur_date ASC makes sure recurence status always overwrites series status |
482 | - foreach($this->db->select($this->user_table,'*',array( |
|
482 | + foreach ($this->db->select($this->user_table, '*', array( |
|
483 | 483 | 'cal_id' => $ids, |
484 | 484 | 'cal_recur_date' => $recur_date, |
485 | 485 | "cal_status NOT IN ('X','E')", |
486 | - ),__LINE__,__FILE__,false,'ORDER BY cal_user_type DESC,cal_recur_date ASC,'.self::STATUS_SORT,'calendar') as $row) // DESC puts users before resources and contacts |
|
486 | + ), __LINE__, __FILE__, false, 'ORDER BY cal_user_type DESC,cal_recur_date ASC,'.self::STATUS_SORT, 'calendar') as $row) // DESC puts users before resources and contacts |
|
487 | 487 | { |
488 | 488 | // combine all participant data in uid and status values |
489 | 489 | $uid = self::combine_user($row['cal_user_type'], $row['cal_user_id'], $row['cal_user_attendee']); |
490 | - $status = self::combine_status($row['cal_status'],$row['cal_quantity'],$row['cal_role']); |
|
490 | + $status = self::combine_status($row['cal_status'], $row['cal_quantity'], $row['cal_role']); |
|
491 | 491 | |
492 | 492 | $events[$row['cal_id']]['participants'][$uid] = $status; |
493 | 493 | $events[$row['cal_id']]['participant_types'][$row['cal_user_type']][is_numeric($uid) ? $uid : substr($uid, 1)] = $status; |
@@ -496,7 +496,7 @@ discard block |
||
496 | 496 | } |
497 | 497 | |
498 | 498 | // custom fields |
499 | - foreach($this->db->select($this->extra_table,'*',array('cal_id'=>$ids),__LINE__,__FILE__,false,'','calendar') as $row) |
|
499 | + foreach ($this->db->select($this->extra_table, '*', array('cal_id'=>$ids), __LINE__, __FILE__, false, '', 'calendar') as $row) |
|
500 | 500 | { |
501 | 501 | $events[$row['cal_id']]['#'.$row['cal_extra_name']] = $row['cal_extra_value']; |
502 | 502 | } |
@@ -504,7 +504,7 @@ discard block |
||
504 | 504 | // alarms |
505 | 505 | if (is_array($ids)) |
506 | 506 | { |
507 | - foreach($this->read_alarms((array)$ids) as $cal_id => $alarms) |
|
507 | + foreach ($this->read_alarms((array)$ids) as $cal_id => $alarms) |
|
508 | 508 | { |
509 | 509 | $events[$cal_id]['alarm'] = $alarms; |
510 | 510 | } |
@@ -533,11 +533,11 @@ discard block |
||
533 | 533 | * @param boolean $master_only =false only check recurance master (egw_cal_user.recur_date=0) |
534 | 534 | * @return int maximum modification timestamp |
535 | 535 | */ |
536 | - function get_ctag($users, $owner_too=false,$master_only=false) |
|
536 | + function get_ctag($users, $owner_too = false, $master_only = false) |
|
537 | 537 | { |
538 | - static $ctags = array(); // some per-request caching |
|
538 | + static $ctags = array(); // some per-request caching |
|
539 | 539 | static $last_request = null; |
540 | - if (!isset($last_request) || time()-$last_request > self::MAX_CTAG_CACHE_TIME) |
|
540 | + if (!isset($last_request) || time() - $last_request > self::MAX_CTAG_CACHE_TIME) |
|
541 | 541 | { |
542 | 542 | $ctags = array(); |
543 | 543 | $last_request = time(); |
@@ -546,13 +546,13 @@ discard block |
||
546 | 546 | if (isset($ctags[$signature])) return $ctags[$signature]; |
547 | 547 | |
548 | 548 | $types = array(); |
549 | - foreach((array)$users as $uid) |
|
549 | + foreach ((array)$users as $uid) |
|
550 | 550 | { |
551 | 551 | $type = $id = null; |
552 | 552 | self::split_user($uid, $type, $id, true); |
553 | 553 | $types[$type][] = $id; |
554 | 554 | } |
555 | - foreach($types as $type => $ids) |
|
555 | + foreach ($types as $type => $ids) |
|
556 | 556 | { |
557 | 557 | $where = array( |
558 | 558 | 'cal_user_type' => $type, |
@@ -574,17 +574,17 @@ discard block |
||
574 | 574 | if ($owner_too) |
575 | 575 | { |
576 | 576 | // owner can only by users, no groups or resources |
577 | - foreach($users as $key => $user) |
|
577 | + foreach ($users as $key => $user) |
|
578 | 578 | { |
579 | 579 | if (!($user > 0)) unset($users[$key]); |
580 | 580 | } |
581 | 581 | $where = $this->db->expression($this->user_table, '(', $where, ' OR '). |
582 | 582 | $this->db->expression($this->cal_table, array( |
583 | 583 | 'cal_owner' => $users, |
584 | - ),')'); |
|
584 | + ), ')'); |
|
585 | 585 | } |
586 | - return $ctags[$signature] = $this->db->select($this->user_table,'MAX(cal_modified)', |
|
587 | - $where,__LINE__,__FILE__,false,'','calendar',0,'JOIN egw_cal ON egw_cal.cal_id=egw_cal_user.cal_id')->fetchColumn(); |
|
586 | + return $ctags[$signature] = $this->db->select($this->user_table, 'MAX(cal_modified)', |
|
587 | + $where, __LINE__, __FILE__, false, '', 'calendar', 0, 'JOIN egw_cal ON egw_cal.cal_id=egw_cal_user.cal_id')->fetchColumn(); |
|
588 | 588 | } |
589 | 589 | |
590 | 590 | /** |
@@ -596,7 +596,7 @@ discard block |
||
596 | 596 | * @param string|array $cols ='cal_id,cal_reference,cal_etag,cal_modified,cal_user_modified' cols to query |
597 | 597 | * @return Iterator as Api\Db::select |
598 | 598 | */ |
599 | - function get_cal_data(array $query, $cols='cal_id,cal_reference,cal_etag,cal_modified,cal_user_modified') |
|
599 | + function get_cal_data(array $query, $cols = 'cal_id,cal_reference,cal_etag,cal_modified,cal_user_modified') |
|
600 | 600 | { |
601 | 601 | if (!is_array($cols)) $cols = explode(',', $cols); |
602 | 602 | |
@@ -624,14 +624,14 @@ discard block |
||
624 | 624 | $cats = $GLOBALS['egw']->categories->return_all_children($cat_id); |
625 | 625 | array_walk($cats, function(&$val, $key) |
626 | 626 | { |
627 | - unset($key); // not used, but required by function signature |
|
628 | - $val = (int) $val; |
|
627 | + unset($key); // not used, but required by function signature |
|
628 | + $val = (int)$val; |
|
629 | 629 | }); |
630 | - if (is_array($cat_id) && count($cat_id)==1) $cat_id = $cat_id[0]; |
|
631 | - $sql = '(cal_category'.(count($cats) > 1 ? " IN ('".implode("','",$cats)."')" : '='.$this->db->quote((int)$cat_id)); |
|
632 | - foreach($cats as $cat) |
|
630 | + if (is_array($cat_id) && count($cat_id) == 1) $cat_id = $cat_id[0]; |
|
631 | + $sql = '(cal_category'.(count($cats) > 1 ? " IN ('".implode("','", $cats)."')" : '='.$this->db->quote((int)$cat_id)); |
|
632 | + foreach ($cats as $cat) |
|
633 | 633 | { |
634 | - $sql .= ' OR '.$this->db->concat("','",'cal_category',"','").' LIKE '.$this->db->quote('%,'.$cat.',%'); |
|
634 | + $sql .= ' OR '.$this->db->concat("','", 'cal_category', "','").' LIKE '.$this->db->quote('%,'.$cat.',%'); |
|
635 | 635 | } |
636 | 636 | $sql .= ') '; |
637 | 637 | } |
@@ -646,13 +646,13 @@ discard block |
||
646 | 646 | * @param array $where =array() array to add filters too |
647 | 647 | * @return array |
648 | 648 | */ |
649 | - protected function status_filter($filter, $enum_recuring=true, array $where=array()) |
|
649 | + protected function status_filter($filter, $enum_recuring = true, array $where = array()) |
|
650 | 650 | { |
651 | - if($filter != 'deleted' && $filter != 'everything') |
|
651 | + if ($filter != 'deleted' && $filter != 'everything') |
|
652 | 652 | { |
653 | 653 | $where[] = 'cal_deleted IS NULL'; |
654 | 654 | } |
655 | - switch($filter) |
|
655 | + switch ($filter) |
|
656 | 656 | { |
657 | 657 | case 'everything': // no filter at all |
658 | 658 | break; |
@@ -726,7 +726,7 @@ discard block |
||
726 | 726 | * @param int $remove_rejected_by_user =null add join to remove entry, if given user has rejected it |
727 | 727 | * @return Iterator|array of events |
728 | 728 | */ |
729 | - function &search($start,$end,$users,$cat_id=0,$filter='all',$offset=False,$num_rows=0,array $params=array(),$remove_rejected_by_user=null) |
|
729 | + function &search($start, $end, $users, $cat_id = 0, $filter = 'all', $offset = False, $num_rows = 0, array $params = array(), $remove_rejected_by_user = null) |
|
730 | 730 | { |
731 | 731 | //error_log(__METHOD__.'('.($start ? date('Y-m-d H:i',$start) : '').','.($end ? date('Y-m-d H:i',$end) : '').','.array2string($users).','.array2string($cat_id).",'$filter',".array2string($offset).",$num_rows,".array2string($params).') '.function_backtrace()); |
732 | 732 | |
@@ -749,7 +749,7 @@ discard block |
||
749 | 749 | { |
750 | 750 | $all_cols = self::get_columns('calendar', $this->cal_table); |
751 | 751 | $all_cols[0] = $this->db->to_varchar($this->cal_table.'.cal_id'); |
752 | - $cols = "$this->repeats_table.recur_type,$this->repeats_table.recur_interval,$this->repeats_table.recur_data,range_end - 1 AS recur_enddate,".implode(',',$all_cols).",cal_start,cal_end,$this->user_table.cal_recur_date"; |
|
752 | + $cols = "$this->repeats_table.recur_type,$this->repeats_table.recur_interval,$this->repeats_table.recur_data,range_end - 1 AS recur_enddate,".implode(',', $all_cols).",cal_start,cal_end,$this->user_table.cal_recur_date"; |
|
753 | 753 | } |
754 | 754 | $where = array(); |
755 | 755 | $join = ''; |
@@ -759,7 +759,7 @@ discard block |
||
759 | 759 | } |
760 | 760 | elseif ($params['query']) |
761 | 761 | { |
762 | - $columns = array('cal_title','cal_description','cal_location'); |
|
762 | + $columns = array('cal_title', 'cal_description', 'cal_location'); |
|
763 | 763 | |
764 | 764 | $wildcard = '%'; $op = null; |
765 | 765 | $so_sql = new Api\Storage('calendar', $this->cal_table, $this->extra_table, '', 'cal_extra_name', 'cal_extra_value', 'cal_id', $this->db); |
@@ -769,9 +769,9 @@ discard block |
||
769 | 769 | if (!isset($params['private_grants'])) |
770 | 770 | { |
771 | 771 | $params['private_grants'] = $GLOBALS['egw']->acl->get_ids_for_location($GLOBALS['egw_info']['user']['account_id'], Acl::PRIVAT, 'calendar'); |
772 | - $params['private_grants'][] = $GLOBALS['egw_info']['user']['account_id']; // db query does NOT return current user |
|
772 | + $params['private_grants'][] = $GLOBALS['egw_info']['user']['account_id']; // db query does NOT return current user |
|
773 | 773 | } |
774 | - $private_filter = '(cal_public=1 OR cal_public=0 AND '.$this->db->expression($this->cal_table, array('cal_owner' => $params['private_grants'])) . ')'; |
|
774 | + $private_filter = '(cal_public=1 OR cal_public=0 AND '.$this->db->expression($this->cal_table, array('cal_owner' => $params['private_grants'])).')'; |
|
775 | 775 | $where[] = $private_filter; |
776 | 776 | } |
777 | 777 | if (!empty($params['sql_filter'])) |
@@ -780,7 +780,7 @@ discard block |
||
780 | 780 | { |
781 | 781 | $where[] = $params['sql_filter']; |
782 | 782 | } |
783 | - elseif(is_array($params['sql_filter'])) |
|
783 | + elseif (is_array($params['sql_filter'])) |
|
784 | 784 | { |
785 | 785 | $where = array_merge($where, $params['sql_filter']); |
786 | 786 | } |
@@ -789,11 +789,11 @@ discard block |
||
789 | 789 | if ($users) |
790 | 790 | { |
791 | 791 | $users_by_type = array(); |
792 | - foreach((array)$users as $user) |
|
792 | + foreach ((array)$users as $user) |
|
793 | 793 | { |
794 | 794 | if (is_numeric($user)) |
795 | 795 | { |
796 | - $users_by_type['u'][] = (int) $user; |
|
796 | + $users_by_type['u'][] = (int)$user; |
|
797 | 797 | } |
798 | 798 | else |
799 | 799 | { |
@@ -804,45 +804,45 @@ discard block |
||
804 | 804 | } |
805 | 805 | $to_or = $user_or = array(); |
806 | 806 | $owner_or = null; |
807 | - $table_def = $this->db->get_table_definitions('calendar',$this->user_table); |
|
808 | - foreach($users_by_type as $type => $ids) |
|
807 | + $table_def = $this->db->get_table_definitions('calendar', $this->user_table); |
|
808 | + foreach ($users_by_type as $type => $ids) |
|
809 | 809 | { |
810 | 810 | // when we are able to use Union Querys, we do not OR our query, we save the needed parts for later construction of the union |
811 | 811 | if ($useUnionQuery) |
812 | 812 | { |
813 | - $user_or[] = $this->db->expression($table_def,$this->user_table.'.',array( |
|
813 | + $user_or[] = $this->db->expression($table_def, $this->user_table.'.', array( |
|
814 | 814 | 'cal_user_type' => $type, |
815 | - ),' AND '.$this->user_table.'.',array( |
|
815 | + ), ' AND '.$this->user_table.'.', array( |
|
816 | 816 | 'cal_user_id' => $ids, |
817 | 817 | )); |
818 | 818 | if ($type == 'u' && $filter == 'owner') |
819 | 819 | { |
820 | - $cal_table_def = $this->db->get_table_definitions('calendar',$this->cal_table); |
|
820 | + $cal_table_def = $this->db->get_table_definitions('calendar', $this->cal_table); |
|
821 | 821 | // only users can be owners, no need to add groups |
822 | 822 | $user_ids = array(); |
823 | - foreach($ids as $user_id) |
|
823 | + foreach ($ids as $user_id) |
|
824 | 824 | { |
825 | 825 | if ($GLOBALS['egw']->accounts->get_type($user_id) === 'u') $user_ids[] = $user_id; |
826 | 826 | } |
827 | - $owner_or = $this->db->expression($cal_table_def,array('cal_owner' => $user_ids)); |
|
827 | + $owner_or = $this->db->expression($cal_table_def, array('cal_owner' => $user_ids)); |
|
828 | 828 | } |
829 | 829 | } |
830 | 830 | else |
831 | 831 | { |
832 | - $to_or[] = $this->db->expression($table_def,$this->user_table.'.',array( |
|
832 | + $to_or[] = $this->db->expression($table_def, $this->user_table.'.', array( |
|
833 | 833 | 'cal_user_type' => $type, |
834 | - ),' AND '.$this->user_table.'.',array( |
|
834 | + ), ' AND '.$this->user_table.'.', array( |
|
835 | 835 | 'cal_user_id' => $ids, |
836 | 836 | )); |
837 | 837 | if ($type == 'u' && $filter == 'owner') |
838 | 838 | { |
839 | - $cal_table_def = $this->db->get_table_definitions('calendar',$this->cal_table); |
|
840 | - $to_or[] = $this->db->expression($cal_table_def,array('cal_owner' => $ids)); |
|
839 | + $cal_table_def = $this->db->get_table_definitions('calendar', $this->cal_table); |
|
840 | + $to_or[] = $this->db->expression($cal_table_def, array('cal_owner' => $ids)); |
|
841 | 841 | } |
842 | 842 | } |
843 | 843 | } |
844 | 844 | // this is only used, when we cannot use UNIONS |
845 | - if (!$useUnionQuery) $where[] = '('.implode(' OR ',$to_or).')'; |
|
845 | + if (!$useUnionQuery) $where[] = '('.implode(' OR ', $to_or).')'; |
|
846 | 846 | |
847 | 847 | $where = $this->status_filter($filter, $params['enum_recuring'], $where); |
848 | 848 | } |
@@ -861,15 +861,15 @@ discard block |
||
861 | 861 | $where[] = '('.((int)$start).' < range_end OR range_end IS NULL)'; |
862 | 862 | } |
863 | 863 | } |
864 | - if (!preg_match('/^[a-z_ ,c]+$/i',$params['order'])) $params['order'] = 'cal_start'; // gard against SQL injection |
|
864 | + if (!preg_match('/^[a-z_ ,c]+$/i', $params['order'])) $params['order'] = 'cal_start'; // gard against SQL injection |
|
865 | 865 | |
866 | 866 | // if not enum recuring events, we have to use minimum start- AND end-dates, otherwise we get more then one event per cal_id! |
867 | 867 | if (!$params['enum_recuring']) |
868 | 868 | { |
869 | 869 | $where[] = "$this->user_table.cal_recur_date=0"; |
870 | - $cols = str_replace(array('cal_start','cal_end'),array('range_start AS cal_start','(SELECT MIN(cal_end) FROM egw_cal_dates WHERE egw_cal.cal_id=egw_cal_dates.cal_id) AS cal_end'),$cols); |
|
870 | + $cols = str_replace(array('cal_start', 'cal_end'), array('range_start AS cal_start', '(SELECT MIN(cal_end) FROM egw_cal_dates WHERE egw_cal.cal_id=egw_cal_dates.cal_id) AS cal_end'), $cols); |
|
871 | 871 | // in case cal_start is used in a query, eg. calendar_ical::find_event |
872 | - $where = str_replace(array('cal_start','cal_end'), array('range_start','(SELECT MIN(cal_end) FROM egw_cal_dates WHERE egw_cal.cal_id=egw_cal_dates.cal_id)'), $where); |
|
872 | + $where = str_replace(array('cal_start', 'cal_end'), array('range_start', '(SELECT MIN(cal_end) FROM egw_cal_dates WHERE egw_cal.cal_id=egw_cal_dates.cal_id)'), $where); |
|
873 | 873 | $params['order'] = str_replace('cal_start', 'range_start', $params['order']); |
874 | 874 | if ($end) $where[] = (int)$end.' > range_start'; |
875 | 875 | } |
@@ -881,14 +881,13 @@ discard block |
||
881 | 881 | " ON $this->cal_table.cal_id=rejected_by_user.cal_id". |
882 | 882 | " AND rejected_by_user.cal_user_type='u'". |
883 | 883 | " AND rejected_by_user.cal_user_id=".$this->db->quote($remove_rejected_by_user). |
884 | - " AND ".(!$params['enum_recuring'] ? 'rejected_by_user.cal_recur_date=0' : |
|
885 | - '(recur_type IS NULL AND rejected_by_user.cal_recur_date=0 OR cal_start=rejected_by_user.cal_recur_date)'); |
|
884 | + " AND ".(!$params['enum_recuring'] ? 'rejected_by_user.cal_recur_date=0' : '(recur_type IS NULL AND rejected_by_user.cal_recur_date=0 OR cal_start=rejected_by_user.cal_recur_date)'); |
|
886 | 885 | $or_required = array( |
887 | 886 | 'rejected_by_user.cal_status IS NULL', |
888 | 887 | "rejected_by_user.cal_status NOT IN ('R','X')", |
889 | 888 | ); |
890 | 889 | if ($filter == 'owner') $or_required[] = 'cal_owner='.(int)$remove_rejected_by_user; |
891 | - $where[] = '('.implode(' OR ',$or_required).')'; |
|
890 | + $where[] = '('.implode(' OR ', $or_required).')'; |
|
892 | 891 | } |
893 | 892 | // using a time-range and deleted attribute limited view instead of full table |
894 | 893 | $cal_table = $this->cal_range_view($start, $end, null, $filter == 'everything' ? null : $filter != 'deleted'); |
@@ -900,7 +899,7 @@ discard block |
||
900 | 899 | // dates table join only needed to enum recuring events, we use a time-range limited view here too |
901 | 900 | if ($params['enum_recuring']) |
902 | 901 | { |
903 | - $join .= "JOIN ".$this->dates_table. // using dates_table direct seems quicker then an other view |
|
902 | + $join .= "JOIN ".$this->dates_table.// using dates_table direct seems quicker then an other view |
|
904 | 903 | //$this->dates_range_view($start, $end, null, $filter == 'everything' ? null : $filter == 'deleted'). |
905 | 904 | " ON $this->cal_table.cal_id=$this->dates_table.cal_id ".$u_join; |
906 | 905 | } |
@@ -910,12 +909,12 @@ discard block |
||
910 | 909 | } |
911 | 910 | |
912 | 911 | // Check for some special sorting, used by planner views |
913 | - if($params['order'] == 'participants , cal_non_blocking DESC') |
|
912 | + if ($params['order'] == 'participants , cal_non_blocking DESC') |
|
914 | 913 | { |
915 | 914 | $order = ($GLOBALS['egw_info']['user']['preferences']['common']['account_display'] == 'lastname' ? 'n_family' : 'n_fileas'); |
916 | 915 | $cols .= ",egw_addressbook.{$order}"; |
917 | 916 | $join .= "LEFT JOIN egw_addressbook ON ". |
918 | - ($this->db->Type == 'pgsql'? "egw_addressbook.account_id::varchar = ":"egw_addressbook.account_id = "). |
|
917 | + ($this->db->Type == 'pgsql' ? "egw_addressbook.account_id::varchar = " : "egw_addressbook.account_id = "). |
|
919 | 918 | "{$this->user_table}.cal_user_id"; |
920 | 919 | $params['order'] = "$order, cal_non_blocking DESC"; |
921 | 920 | } |
@@ -948,29 +947,29 @@ discard block |
||
948 | 947 | // as replace the OR by construction of a suitable UNION for performance reasons |
949 | 948 | if ($owner_or || $user_or) |
950 | 949 | { |
951 | - foreach($user_or as $user_sql) |
|
950 | + foreach ($user_or as $user_sql) |
|
952 | 951 | { |
953 | 952 | $selects[] = $select; |
954 | - $selects[count($selects)-1]['where'][] = $user_sql; |
|
953 | + $selects[count($selects) - 1]['where'][] = $user_sql; |
|
955 | 954 | if ($params['enum_recuring']) |
956 | 955 | { |
957 | - $selects[count($selects)-1]['where'][] = "recur_type IS NULL AND $this->user_table.cal_recur_date=0"; |
|
956 | + $selects[count($selects) - 1]['where'][] = "recur_type IS NULL AND $this->user_table.cal_recur_date=0"; |
|
958 | 957 | $selects[] = $select; |
959 | - $selects[count($selects)-1]['where'][] = $user_sql; |
|
960 | - $selects[count($selects)-1]['where'][] = "$this->user_table.cal_recur_date=cal_start"; |
|
958 | + $selects[count($selects) - 1]['where'][] = $user_sql; |
|
959 | + $selects[count($selects) - 1]['where'][] = "$this->user_table.cal_recur_date=cal_start"; |
|
961 | 960 | } |
962 | 961 | } |
963 | 962 | // if the query is to be filtered by owner we need to add more selects for the union |
964 | 963 | if ($owner_or) |
965 | 964 | { |
966 | 965 | $selects[] = $select; |
967 | - $selects[count($selects)-1]['where'][] = $owner_or; |
|
966 | + $selects[count($selects) - 1]['where'][] = $owner_or; |
|
968 | 967 | if ($params['enum_recuring']) |
969 | 968 | { |
970 | - $selects[count($selects)-1]['where'][] = "recur_type IS NULL AND $this->user_table.cal_recur_date=0"; |
|
969 | + $selects[count($selects) - 1]['where'][] = "recur_type IS NULL AND $this->user_table.cal_recur_date=0"; |
|
971 | 970 | $selects[] = $select; |
972 | - $selects[count($selects)-1]['where'][] = $owner_or; |
|
973 | - $selects[count($selects)-1]['where'][] = "$this->user_table.cal_recur_date=cal_start"; |
|
971 | + $selects[count($selects) - 1]['where'][] = $owner_or; |
|
972 | + $selects[count($selects) - 1]['where'][] = "$this->user_table.cal_recur_date=cal_start"; |
|
974 | 973 | } |
975 | 974 | } |
976 | 975 | } |
@@ -980,34 +979,34 @@ discard block |
||
980 | 979 | $selects[] = $select; |
981 | 980 | if ($params['enum_recuring']) |
982 | 981 | { |
983 | - $selects[count($selects)-1]['where'][] = "recur_type IS NULL AND $this->user_table.cal_recur_date=0"; |
|
982 | + $selects[count($selects) - 1]['where'][] = "recur_type IS NULL AND $this->user_table.cal_recur_date=0"; |
|
984 | 983 | $selects[] = $select; |
985 | - $selects[count($selects)-1]['where'][] = "$this->user_table.cal_recur_date=cal_start"; |
|
984 | + $selects[count($selects) - 1]['where'][] = "$this->user_table.cal_recur_date=cal_start"; |
|
986 | 985 | } |
987 | 986 | } |
988 | 987 | if (is_numeric($offset) && !$params['no_total']) // get the total too |
989 | 988 | { |
990 | 989 | $save_selects = $selects; |
991 | 990 | // we only select cal_table.cal_id (and not cal_table.*) to be able to use DISTINCT (eg. MsSQL does not allow it for text-columns) |
992 | - foreach(array_keys($selects) as $key) |
|
991 | + foreach (array_keys($selects) as $key) |
|
993 | 992 | { |
994 | 993 | $selects[$key]['cols'] = "$this->repeats_table.recur_type,range_end AS recur_enddate,$this->repeats_table.recur_interval,$this->repeats_table.recur_data,".$this->db->to_varchar($this->cal_table.'.cal_id').",cal_start,cal_end,$this->user_table.cal_recur_date"; |
995 | 994 | if (!$params['enum_recuring']) |
996 | 995 | { |
997 | - $selects[$key]['cols'] = str_replace(array('cal_start','cal_end'), |
|
998 | - array('range_start AS cal_start','range_end AS cal_end'), $selects[$key]['cols']); |
|
996 | + $selects[$key]['cols'] = str_replace(array('cal_start', 'cal_end'), |
|
997 | + array('range_start AS cal_start', 'range_end AS cal_end'), $selects[$key]['cols']); |
|
999 | 998 | } |
1000 | 999 | } |
1001 | - if (!isset($params['cols']) && !$params['no_integration']) self::get_union_selects($selects,$start,$end,$users,$cat_id,$filter,$params['query'],$params['users']); |
|
1000 | + if (!isset($params['cols']) && !$params['no_integration']) self::get_union_selects($selects, $start, $end, $users, $cat_id, $filter, $params['query'], $params['users']); |
|
1002 | 1001 | |
1003 | - $this->total = $this->db->union($selects,__LINE__,__FILE__)->NumRows(); |
|
1002 | + $this->total = $this->db->union($selects, __LINE__, __FILE__)->NumRows(); |
|
1004 | 1003 | |
1005 | 1004 | // restore original cols / selects |
1006 | 1005 | $selects = $save_selects; unset($save_selects); |
1007 | 1006 | } |
1008 | - if (!isset($params['cols']) && !$params['no_integration']) self::get_union_selects($selects,$start,$end,$users,$cat_id,$filter,$params['query'],$params['users']); |
|
1007 | + if (!isset($params['cols']) && !$params['no_integration']) self::get_union_selects($selects, $start, $end, $users, $cat_id, $filter, $params['query'], $params['users']); |
|
1009 | 1008 | |
1010 | - $rs = $this->db->union($selects,__LINE__,__FILE__,$params['order'],$offset,$num_rows); |
|
1009 | + $rs = $this->db->union($selects, __LINE__, __FILE__, $params['order'], $offset, $num_rows); |
|
1011 | 1010 | } |
1012 | 1011 | else // MsSQL oder MySQL 3.23 |
1013 | 1012 | { |
@@ -1030,27 +1029,27 @@ discard block |
||
1030 | 1029 | $selects[0]['cols'] = "$this->cal_table.cal_id,cal_start"; |
1031 | 1030 | if (!isset($params['cols']) && !$params['no_integration'] && $this->db->capabilities['union']) |
1032 | 1031 | { |
1033 | - self::get_union_selects($selects,$start,$end,$users,$cat_id,$filter,$params['query'],$params['users']); |
|
1032 | + self::get_union_selects($selects, $start, $end, $users, $cat_id, $filter, $params['query'], $params['users']); |
|
1034 | 1033 | } |
1035 | 1034 | $this->total = $this->db->union($selects, __LINE__, __FILE__)->NumRows(); |
1036 | 1035 | $selects = $save_selects; |
1037 | 1036 | } |
1038 | 1037 | if (!isset($params['cols']) && !$params['no_integration'] && $this->db->capabilities['union']) |
1039 | 1038 | { |
1040 | - self::get_union_selects($selects,$start,$end,$users,$cat_id,$filter,$params['query'],$params['users']); |
|
1039 | + self::get_union_selects($selects, $start, $end, $users, $cat_id, $filter, $params['query'], $params['users']); |
|
1041 | 1040 | } |
1042 | - $rs = $this->db->union($selects,__LINE__,__FILE__,$params['order'],$offset,$num_rows); |
|
1041 | + $rs = $this->db->union($selects, __LINE__, __FILE__, $params['order'], $offset, $num_rows); |
|
1043 | 1042 | } |
1044 | 1043 | //error_log(__METHOD__."() useUnionQuery=$useUnionQuery --> query took ".(microtime(true)-$starttime).'s '.$rs->sql); |
1045 | 1044 | |
1046 | 1045 | if (isset($params['cols'])) |
1047 | 1046 | { |
1048 | - return $rs; // if colums are specified we return the recordset / iterator |
|
1047 | + return $rs; // if colums are specified we return the recordset / iterator |
|
1049 | 1048 | } |
1050 | 1049 | // Todo: return $this->get_events($rs); |
1051 | 1050 | |
1052 | 1051 | $events = $ids = $recur_dates = $recur_ids = array(); |
1053 | - foreach($rs as $row) |
|
1052 | + foreach ($rs as $row) |
|
1054 | 1053 | { |
1055 | 1054 | $id = $row['cal_id']; |
1056 | 1055 | if (is_numeric($id)) $ids[] = $id; |
@@ -1062,9 +1061,9 @@ discard block |
||
1062 | 1061 | } |
1063 | 1062 | if ($row['participants']) |
1064 | 1063 | { |
1065 | - $row['participants'] = explode(',',$row['participants']); |
|
1064 | + $row['participants'] = explode(',', $row['participants']); |
|
1066 | 1065 | $row['participants'] = array_combine($row['participants'], |
1067 | - array_fill(0,count($row['participants']),'')); |
|
1066 | + array_fill(0, count($row['participants']), '')); |
|
1068 | 1067 | } |
1069 | 1068 | else |
1070 | 1069 | { |
@@ -1073,9 +1072,9 @@ discard block |
||
1073 | 1072 | $row['recur_exception'] = $row['alarm'] = array(); |
1074 | 1073 | |
1075 | 1074 | // compile a list of recurrences per cal_id |
1076 | - if (!in_array($id,(array)$recur_ids[$row['cal_id']])) $recur_ids[$row['cal_id']][] = $id; |
|
1075 | + if (!in_array($id, (array)$recur_ids[$row['cal_id']])) $recur_ids[$row['cal_id']][] = $id; |
|
1077 | 1076 | |
1078 | - $events[$id] = Api\Db::strip_array_keys($row,'cal_'); |
|
1077 | + $events[$id] = Api\Db::strip_array_keys($row, 'cal_'); |
|
1079 | 1078 | } |
1080 | 1079 | //_debug_array($events); |
1081 | 1080 | if (count($ids)) |
@@ -1085,26 +1084,26 @@ discard block |
||
1085 | 1084 | // now ready all users with the given cal_id AND (cal_recur_date=0 or the fitting recur-date) |
1086 | 1085 | // This will always read the first entry of each recuring event too, we eliminate it later |
1087 | 1086 | $recur_dates[] = 0; |
1088 | - $utcal_id_view = " (SELECT * FROM ".$this->user_table." WHERE cal_id IN (".implode(',',$ids).")". |
|
1087 | + $utcal_id_view = " (SELECT * FROM ".$this->user_table." WHERE cal_id IN (".implode(',', $ids).")". |
|
1089 | 1088 | ($filter != 'everything' ? " AND cal_status NOT IN ('X','E')" : '').") utcalid "; |
1090 | 1089 | //$utrecurdate_view = " (select * from ".$this->user_table." where cal_recur_date in (".implode(',',array_unique($recur_dates)).")) utrecurdates "; |
1091 | - foreach($this->db->select($utcal_id_view,'*',array( |
|
1090 | + foreach ($this->db->select($utcal_id_view, '*', array( |
|
1092 | 1091 | //'cal_id' => array_unique($ids), |
1093 | 1092 | 'cal_recur_date' => $recur_dates, |
1094 | - ),__LINE__,__FILE__,false,'ORDER BY cal_id,cal_user_type DESC,'.self::STATUS_SORT,'calendar',-1,$join='', |
|
1095 | - $this->db->get_table_definitions('calendar',$this->user_table)) as $row) // DESC puts users before resources and contacts |
|
1093 | + ), __LINE__, __FILE__, false, 'ORDER BY cal_id,cal_user_type DESC,'.self::STATUS_SORT, 'calendar', -1, $join = '', |
|
1094 | + $this->db->get_table_definitions('calendar', $this->user_table)) as $row) // DESC puts users before resources and contacts |
|
1096 | 1095 | { |
1097 | 1096 | $id = $row['cal_id']; |
1098 | 1097 | if ($row['cal_recur_date']) $id .= '-'.$row['cal_recur_date']; |
1099 | 1098 | |
1100 | 1099 | // combine all participant data in uid and status values |
1101 | 1100 | $uid = self::combine_user($row['cal_user_type'], $row['cal_user_id'], $row['cal_user_attendee']); |
1102 | - $status = self::combine_status($row['cal_status'],$row['cal_quantity'],$row['cal_role']); |
|
1101 | + $status = self::combine_status($row['cal_status'], $row['cal_quantity'], $row['cal_role']); |
|
1103 | 1102 | |
1104 | 1103 | // set accept/reject/tentative of series for all recurrences |
1105 | 1104 | if (!$row['cal_recur_date']) |
1106 | 1105 | { |
1107 | - foreach((array)$recur_ids[$row['cal_id']] as $i) |
|
1106 | + foreach ((array)$recur_ids[$row['cal_id']] as $i) |
|
1108 | 1107 | { |
1109 | 1108 | if (isset($events[$i]) && !isset($events[$i]['participants'][$uid])) |
1110 | 1109 | { |
@@ -1119,16 +1118,16 @@ discard block |
||
1119 | 1118 | // query recurrance exceptions, if needed: enum_recuring && !daywise is used in calendar_groupdav::get_series($uid,...) |
1120 | 1119 | if (!$params['enum_recuring'] || !$params['daywise']) |
1121 | 1120 | { |
1122 | - foreach($this->db->select($this->dates_table, 'cal_id,cal_start', array( |
|
1121 | + foreach ($this->db->select($this->dates_table, 'cal_id,cal_start', array( |
|
1123 | 1122 | 'cal_id' => $ids, |
1124 | 1123 | 'recur_exception' => true, |
1125 | 1124 | ), __LINE__, __FILE__, false, 'ORDER BY cal_id,cal_start', 'calendar') as $row) |
1126 | 1125 | { |
1127 | 1126 | // for enum_recurring events are not indexed by cal_id, but $cal_id.'-'.$cal_start |
1128 | 1127 | // find master, which is first recurrence |
1129 | - if (!isset($events[$id=$row['cal_id']])) |
|
1128 | + if (!isset($events[$id = $row['cal_id']])) |
|
1130 | 1129 | { |
1131 | - foreach($events as $id => $event) |
|
1130 | + foreach ($events as $id => $event) |
|
1132 | 1131 | { |
1133 | 1132 | if ($event['id'] == $row['cal_id']) break; |
1134 | 1133 | } |
@@ -1141,10 +1140,10 @@ discard block |
||
1141 | 1140 | { |
1142 | 1141 | $where = array('cal_id' => $ids); |
1143 | 1142 | if ($params['cfs']) $where['cal_extra_name'] = $params['cfs']; |
1144 | - foreach($this->db->select($this->extra_table,'*',$where, |
|
1145 | - __LINE__,__FILE__,false,'','calendar') as $row) |
|
1143 | + foreach ($this->db->select($this->extra_table, '*', $where, |
|
1144 | + __LINE__, __FILE__, false, '', 'calendar') as $row) |
|
1146 | 1145 | { |
1147 | - foreach((array)$recur_ids[$row['cal_id']] as $id) |
|
1146 | + foreach ((array)$recur_ids[$row['cal_id']] as $id) |
|
1148 | 1147 | { |
1149 | 1148 | if (isset($events[$id])) |
1150 | 1149 | { |
@@ -1154,9 +1153,9 @@ discard block |
||
1154 | 1153 | } |
1155 | 1154 | } |
1156 | 1155 | // alarms |
1157 | - foreach($this->read_alarms($ids) as $cal_id => $alarms) |
|
1156 | + foreach ($this->read_alarms($ids) as $cal_id => $alarms) |
|
1158 | 1157 | { |
1159 | - foreach($alarms as $id => $alarm) |
|
1158 | + foreach ($alarms as $id => $alarm) |
|
1160 | 1159 | { |
1161 | 1160 | $event_start = $alarm['time'] + $alarm['offset']; |
1162 | 1161 | |
@@ -1193,16 +1192,16 @@ discard block |
||
1193 | 1192 | * @param $query |
1194 | 1193 | * @param $users_raw as passed to calendar_bo::search (no members and memberships added) |
1195 | 1194 | */ |
1196 | - private static function get_union_selects(array &$selects,$start,$end,$users,$cat_id,$filter,$query,$users_raw) |
|
1195 | + private static function get_union_selects(array &$selects, $start, $end, $users, $cat_id, $filter, $query, $users_raw) |
|
1197 | 1196 | { |
1198 | - if (in_array(basename($_SERVER['SCRIPT_FILENAME']),array('groupdav.php','rpc.php','xmlrpc.php','/activesync/index.php')) || |
|
1199 | - !in_array($GLOBALS['egw_info']['flags']['currentapp'],array('calendar','home'))) |
|
1197 | + if (in_array(basename($_SERVER['SCRIPT_FILENAME']), array('groupdav.php', 'rpc.php', 'xmlrpc.php', '/activesync/index.php')) || |
|
1198 | + !in_array($GLOBALS['egw_info']['flags']['currentapp'], array('calendar', 'home'))) |
|
1200 | 1199 | { |
1201 | - return; // disable integration for GroupDAV, SyncML, ... |
|
1200 | + return; // disable integration for GroupDAV, SyncML, ... |
|
1202 | 1201 | } |
1203 | 1202 | self::$integration_data = Api\Hooks::process(array( |
1204 | 1203 | 'location' => 'calendar_search_union', |
1205 | - 'cols' => $selects[0]['cols'], // cols to return |
|
1204 | + 'cols' => $selects[0]['cols'], // cols to return |
|
1206 | 1205 | 'start' => $start, |
1207 | 1206 | 'end' => $end, |
1208 | 1207 | 'users' => $users, |
@@ -1211,12 +1210,12 @@ discard block |
||
1211 | 1210 | 'filter'=> $filter, |
1212 | 1211 | 'query' => $query, |
1213 | 1212 | )); |
1214 | - foreach(self::$integration_data as $data) |
|
1213 | + foreach (self::$integration_data as $data) |
|
1215 | 1214 | { |
1216 | 1215 | if (is_array($data['selects'])) |
1217 | 1216 | { |
1218 | 1217 | //echo $app; _debug_array($data); |
1219 | - $selects = array_merge($selects,$data['selects']); |
|
1218 | + $selects = array_merge($selects, $data['selects']); |
|
1220 | 1219 | } |
1221 | 1220 | } |
1222 | 1221 | } |
@@ -1241,35 +1240,35 @@ discard block |
||
1241 | 1240 | * @param string $required_app ='calendar' |
1242 | 1241 | * @return string cols for union query to match ones supplied in $required |
1243 | 1242 | */ |
1244 | - public static function union_cols(array $app_cols,$required,$required_app='calendar') |
|
1243 | + public static function union_cols(array $app_cols, $required, $required_app = 'calendar') |
|
1245 | 1244 | { |
1246 | 1245 | // remove evtl. used DISTINCT, we currently dont need it |
1247 | - if (($distinct = substr($required,0,9) == 'DISTINCT ')) |
|
1246 | + if (($distinct = substr($required, 0, 9) == 'DISTINCT ')) |
|
1248 | 1247 | { |
1249 | - $required = substr($required,9); |
|
1248 | + $required = substr($required, 9); |
|
1250 | 1249 | } |
1251 | 1250 | $return_cols = array(); |
1252 | - foreach(is_array($required) ? $required : explode(',',$required) as $cols) |
|
1251 | + foreach (is_array($required) ? $required : explode(',', $required) as $cols) |
|
1253 | 1252 | { |
1254 | 1253 | $matches = null; |
1255 | - if (substr($cols,-2) == '.*') |
|
1254 | + if (substr($cols, -2) == '.*') |
|
1256 | 1255 | { |
1257 | - $cols = self::get_columns($required_app,substr($cols,0,-2)); |
|
1256 | + $cols = self::get_columns($required_app, substr($cols, 0, -2)); |
|
1258 | 1257 | } |
1259 | 1258 | // remove CAST added for PostgreSQL from eg. "CAST(egw_cal.cal_id AS varchar)" |
1260 | 1259 | elseif (preg_match('/CAST\(([a-z0-9_.]+) AS [a-z0-9_]+\)/i', $cols, $matches)) |
1261 | 1260 | { |
1262 | 1261 | $cols = $matches[1]; |
1263 | 1262 | } |
1264 | - elseif (strpos($cols,' AS ') !== false) |
|
1263 | + elseif (strpos($cols, ' AS ') !== false) |
|
1265 | 1264 | { |
1266 | - list(,$cols) = explode(' AS ',$cols); |
|
1265 | + list(,$cols) = explode(' AS ', $cols); |
|
1267 | 1266 | } |
1268 | - foreach((array)$cols as $col) |
|
1267 | + foreach ((array)$cols as $col) |
|
1269 | 1268 | { |
1270 | - if (substr($col,0,7) == 'egw_cal') // remove table name |
|
1269 | + if (substr($col, 0, 7) == 'egw_cal') // remove table name |
|
1271 | 1270 | { |
1272 | - $col = preg_replace('/^egw_cal[a-z_]*\./','',$col); |
|
1271 | + $col = preg_replace('/^egw_cal[a-z_]*\./', '', $col); |
|
1273 | 1272 | } |
1274 | 1273 | if (isset($app_cols[$col])) |
1275 | 1274 | { |
@@ -1282,7 +1281,7 @@ discard block |
||
1282 | 1281 | } |
1283 | 1282 | } |
1284 | 1283 | //error_log(__METHOD__."(".array2string($app_cols).", ".array2string($required).", '$required_app') returning ".array2string(implode(',',$return_cols))); |
1285 | - return implode(',',$return_cols); |
|
1284 | + return implode(',', $return_cols); |
|
1286 | 1285 | } |
1287 | 1286 | |
1288 | 1287 | /** |
@@ -1292,21 +1291,21 @@ discard block |
||
1292 | 1291 | * @param string $table |
1293 | 1292 | * @return array of column names |
1294 | 1293 | */ |
1295 | - static private function get_columns($app,$table) |
|
1294 | + static private function get_columns($app, $table) |
|
1296 | 1295 | { |
1297 | 1296 | if ($table != 'egw_cal') |
1298 | 1297 | { |
1299 | - $table_def = $GLOBALS['egw']->db->get_table_definitions($app,$table); |
|
1298 | + $table_def = $GLOBALS['egw']->db->get_table_definitions($app, $table); |
|
1300 | 1299 | $cols = array_keys($table_def['fd']); |
1301 | 1300 | } |
1302 | 1301 | else |
1303 | 1302 | { |
1304 | 1303 | // special handling for egw_cal, as old databases have a different column order!!! |
1305 | - $cols =& Api\Cache::getSession(__CLASS__,$table); |
|
1304 | + $cols = & Api\Cache::getSession(__CLASS__, $table); |
|
1306 | 1305 | |
1307 | 1306 | if (is_null($cols)) |
1308 | 1307 | { |
1309 | - $meta = $GLOBALS['egw']->db->metadata($table,true); |
|
1308 | + $meta = $GLOBALS['egw']->db->metadata($table, true); |
|
1310 | 1309 | $cols = array_keys($meta['meta']); |
1311 | 1310 | } |
1312 | 1311 | } |
@@ -1359,12 +1358,12 @@ discard block |
||
1359 | 1358 | * @param int &$etag etag=null etag to check or null, on return new etag |
1360 | 1359 | * @return boolean|int false on error, 0 if etag does not match, cal_id otherwise |
1361 | 1360 | */ |
1362 | - function save(&$event,&$set_recurrences,&$set_recurrences_start=0,$change_since=0,&$etag=null) |
|
1361 | + function save(&$event, &$set_recurrences, &$set_recurrences_start = 0, $change_since = 0, &$etag = null) |
|
1363 | 1362 | { |
1364 | 1363 | if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'])) |
1365 | 1364 | { |
1366 | 1365 | $minimum_uid_length = $GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length']; |
1367 | - if (empty($minimum_uid_length) || $minimum_uid_length<=1) $minimum_uid_length = 8; // we just do not accept no uid, or uid way to short! |
|
1366 | + if (empty($minimum_uid_length) || $minimum_uid_length <= 1) $minimum_uid_length = 8; // we just do not accept no uid, or uid way to short! |
|
1368 | 1367 | } |
1369 | 1368 | else |
1370 | 1369 | { |
@@ -1375,7 +1374,7 @@ discard block |
||
1375 | 1374 | |
1376 | 1375 | //error_log(__METHOD__.'('.array2string($event).",$set_recurrences,$change_since,$etag) ".function_backtrace()); |
1377 | 1376 | |
1378 | - $cal_id = (int) $event['id']; |
|
1377 | + $cal_id = (int)$event['id']; |
|
1379 | 1378 | unset($event['id']); |
1380 | 1379 | $set_recurrences = $set_recurrences || !$cal_id && $event['recur_type'] != MCAL_RECUR_NONE; |
1381 | 1380 | |
@@ -1386,9 +1385,9 @@ discard block |
||
1386 | 1385 | } |
1387 | 1386 | |
1388 | 1387 | // add colum prefix 'cal_' if there's not already a 'recur_' prefix |
1389 | - foreach(array_keys($event) as $col) |
|
1388 | + foreach (array_keys($event) as $col) |
|
1390 | 1389 | { |
1391 | - if ($col[0] != '#' && substr($col,0,6) != 'recur_' && substr($col,0,6) != 'range_' && $col != 'alarm' && $col != 'tz_id' && $col != 'caldav_name') |
|
1390 | + if ($col[0] != '#' && substr($col, 0, 6) != 'recur_' && substr($col, 0, 6) != 'range_' && $col != 'alarm' && $col != 'tz_id' && $col != 'caldav_name') |
|
1392 | 1391 | { |
1393 | 1392 | $event['cal_'.$col] = $event[$col]; |
1394 | 1393 | unset($event[$col]); |
@@ -1398,13 +1397,12 @@ discard block |
||
1398 | 1397 | if (isset($event['cal_start'])) $event['range_start'] = $event['cal_start']; |
1399 | 1398 | if (isset($event['cal_end'])) |
1400 | 1399 | { |
1401 | - $event['range_end'] = $event['recur_type'] == MCAL_RECUR_NONE ? $event['cal_end'] : |
|
1402 | - ($event['recur_enddate'] ? $event['recur_enddate'] : null); |
|
1400 | + $event['range_end'] = $event['recur_type'] == MCAL_RECUR_NONE ? $event['cal_end'] : ($event['recur_enddate'] ? $event['recur_enddate'] : null); |
|
1403 | 1401 | } |
1404 | 1402 | // ensure that we find mathing entries later on |
1405 | 1403 | if (!is_array($event['cal_category'])) |
1406 | 1404 | { |
1407 | - $categories = array_unique(explode(',',$event['cal_category'])); |
|
1405 | + $categories = array_unique(explode(',', $event['cal_category'])); |
|
1408 | 1406 | sort($categories); |
1409 | 1407 | } |
1410 | 1408 | else |
@@ -1413,7 +1411,7 @@ discard block |
||
1413 | 1411 | } |
1414 | 1412 | sort($categories, SORT_NUMERIC); |
1415 | 1413 | |
1416 | - $event['cal_category'] = implode(',',$categories); |
|
1414 | + $event['cal_category'] = implode(',', $categories); |
|
1417 | 1415 | |
1418 | 1416 | // make sure recurring events never reference to an other recurrent event |
1419 | 1417 | if ($event['recur_type'] != MCAL_RECUR_NONE) $event['cal_reference'] = 0; |
@@ -1431,18 +1429,18 @@ discard block |
||
1431 | 1429 | // read only timezone id, to check if it is changed |
1432 | 1430 | if ($event['recur_type'] != MCAL_RECUR_NONE) |
1433 | 1431 | { |
1434 | - $old_tz_id = $this->db->select($this->cal_table,'tz_id',$where,__LINE__,__FILE__,'calendar')->fetchColumn(); |
|
1432 | + $old_tz_id = $this->db->select($this->cal_table, 'tz_id', $where, __LINE__, __FILE__, 'calendar')->fetchColumn(); |
|
1435 | 1433 | } |
1436 | 1434 | if (!is_null($etag)) $where['cal_etag'] = $etag; |
1437 | 1435 | |
1438 | 1436 | unset($event['cal_etag']); |
1439 | - $event[] = 'cal_etag=COALESCE(cal_etag,0)+1'; // always update the etag, even if none given to check |
|
1437 | + $event[] = 'cal_etag=COALESCE(cal_etag,0)+1'; // always update the etag, even if none given to check |
|
1440 | 1438 | |
1441 | - $this->db->update($this->cal_table,$event,$where,__LINE__,__FILE__,'calendar'); |
|
1439 | + $this->db->update($this->cal_table, $event, $where, __LINE__, __FILE__, 'calendar'); |
|
1442 | 1440 | |
1443 | 1441 | if (!is_null($etag) && $this->db->affected_rows() < 1) |
1444 | 1442 | { |
1445 | - return 0; // wrong etag, someone else updated the entry |
|
1443 | + return 0; // wrong etag, someone else updated the entry |
|
1446 | 1444 | } |
1447 | 1445 | if (!is_null($etag)) ++$etag; |
1448 | 1446 | } |
@@ -1451,11 +1449,11 @@ discard block |
||
1451 | 1449 | // new event |
1452 | 1450 | if (!$event['cal_owner']) $event['cal_owner'] = $GLOBALS['egw_info']['user']['account_id']; |
1453 | 1451 | |
1454 | - if (!$event['cal_id'] && !isset($event['cal_uid'])) $event['cal_uid'] = ''; // uid is NOT NULL! |
|
1452 | + if (!$event['cal_id'] && !isset($event['cal_uid'])) $event['cal_uid'] = ''; // uid is NOT NULL! |
|
1455 | 1453 | |
1456 | 1454 | $event['cal_etag'] = $etag = 0; |
1457 | - $this->db->insert($this->cal_table,$event,false,__LINE__,__FILE__,'calendar'); |
|
1458 | - if (!($cal_id = $this->db->get_last_insert_id($this->cal_table,'cal_id'))) |
|
1455 | + $this->db->insert($this->cal_table, $event, false, __LINE__, __FILE__, 'calendar'); |
|
1456 | + if (!($cal_id = $this->db->get_last_insert_id($this->cal_table, 'cal_id'))) |
|
1459 | 1457 | { |
1460 | 1458 | return false; |
1461 | 1459 | } |
@@ -1464,7 +1462,7 @@ discard block |
||
1464 | 1462 | // event without uid or not strong enough uid |
1465 | 1463 | if (!isset($event['cal_uid']) || strlen($event['cal_uid']) < $minimum_uid_length) |
1466 | 1464 | { |
1467 | - $update['cal_uid'] = $event['cal_uid'] = Api\CalDAV::generate_uid('calendar',$cal_id); |
|
1465 | + $update['cal_uid'] = $event['cal_uid'] = Api\CalDAV::generate_uid('calendar', $cal_id); |
|
1468 | 1466 | } |
1469 | 1467 | // set caldav_name, if not given by caller |
1470 | 1468 | if (empty($event['caldav_name']) && version_compare($GLOBALS['egw_info']['apps']['calendar']['version'], '1.9.003', '>=')) |
@@ -1473,37 +1471,37 @@ discard block |
||
1473 | 1471 | } |
1474 | 1472 | if ($update) |
1475 | 1473 | { |
1476 | - $this->db->update($this->cal_table, $update, array('cal_id' => $cal_id),__LINE__,__FILE__,'calendar'); |
|
1474 | + $this->db->update($this->cal_table, $update, array('cal_id' => $cal_id), __LINE__, __FILE__, 'calendar'); |
|
1477 | 1475 | } |
1478 | 1476 | |
1479 | 1477 | if ($event['recur_type'] == MCAL_RECUR_NONE) |
1480 | 1478 | { |
1481 | - $this->db->delete($this->dates_table,array( |
|
1479 | + $this->db->delete($this->dates_table, array( |
|
1482 | 1480 | 'cal_id' => $cal_id), |
1483 | - __LINE__,__FILE__,'calendar'); |
|
1481 | + __LINE__, __FILE__, 'calendar'); |
|
1484 | 1482 | |
1485 | 1483 | // delete all user-records, with recur-date != 0 |
1486 | - $this->db->delete($this->user_table,array( |
|
1484 | + $this->db->delete($this->user_table, array( |
|
1487 | 1485 | 'cal_id' => $cal_id, 'cal_recur_date != 0'), |
1488 | - __LINE__,__FILE__,'calendar'); |
|
1486 | + __LINE__, __FILE__, 'calendar'); |
|
1489 | 1487 | |
1490 | - $this->db->delete($this->repeats_table,array( |
|
1488 | + $this->db->delete($this->repeats_table, array( |
|
1491 | 1489 | 'cal_id' => $cal_id), |
1492 | - __LINE__,__FILE__,'calendar'); |
|
1490 | + __LINE__, __FILE__, 'calendar'); |
|
1493 | 1491 | |
1494 | 1492 | // add exception marker to master, so participants added to exceptions *only* get found |
1495 | 1493 | if ($event['cal_reference']) |
1496 | 1494 | { |
1497 | 1495 | $master_participants = array(); |
1498 | - foreach($this->db->select($this->user_table, 'cal_user_type,cal_user_id,cal_user_attendee', array( |
|
1496 | + foreach ($this->db->select($this->user_table, 'cal_user_type,cal_user_id,cal_user_attendee', array( |
|
1499 | 1497 | 'cal_id' => $event['cal_reference'], |
1500 | 1498 | 'cal_recur_date' => 0, |
1501 | - "cal_status != 'X'", // deleted need to be replaced with exception marker too |
|
1499 | + "cal_status != 'X'", // deleted need to be replaced with exception marker too |
|
1502 | 1500 | ), __LINE__, __FILE__, 'calendar') as $row) |
1503 | 1501 | { |
1504 | 1502 | $master_participants[] = self::combine_user($row['cal_user_type'], $row['cal_user_id'], $row['cal_user_attendee']); |
1505 | 1503 | } |
1506 | - foreach(array_diff(array_keys((array)$event['cal_participants']), $master_participants) as $uid) |
|
1504 | + foreach (array_diff(array_keys((array)$event['cal_participants']), $master_participants) as $uid) |
|
1507 | 1505 | { |
1508 | 1506 | $user_type = $user_id = null; |
1509 | 1507 | self::split_user($uid, $user_type, $user_id, true); |
@@ -1522,10 +1520,10 @@ discard block |
||
1522 | 1520 | else // write information about recuring event, if recur_type is present in the array |
1523 | 1521 | { |
1524 | 1522 | // fetch information about the currently saved (old) event |
1525 | - $old_min = (int) $this->db->select($this->dates_table,'MIN(cal_start)',array('cal_id'=>$cal_id),__LINE__,__FILE__,false,'','calendar')->fetchColumn(); |
|
1526 | - $old_duration = (int) $this->db->select($this->dates_table,'MIN(cal_end)',array('cal_id'=>$cal_id),__LINE__,__FILE__,false,'','calendar')->fetchColumn() - $old_min; |
|
1523 | + $old_min = (int)$this->db->select($this->dates_table, 'MIN(cal_start)', array('cal_id'=>$cal_id), __LINE__, __FILE__, false, '', 'calendar')->fetchColumn(); |
|
1524 | + $old_duration = (int)$this->db->select($this->dates_table, 'MIN(cal_end)', array('cal_id'=>$cal_id), __LINE__, __FILE__, false, '', 'calendar')->fetchColumn() - $old_min; |
|
1527 | 1525 | $old_exceptions = array(); |
1528 | - foreach($this->db->select($this->dates_table, 'cal_start', array( |
|
1526 | + foreach ($this->db->select($this->dates_table, 'cal_start', array( |
|
1529 | 1527 | 'cal_id' => $cal_id, |
1530 | 1528 | 'recur_exception' => true |
1531 | 1529 | ), __LINE__, __FILE__, false, 'ORDER BY cal_start', 'calendar') as $row) |
@@ -1544,8 +1542,8 @@ discard block |
||
1544 | 1542 | 'cal_recur_date' => 0, |
1545 | 1543 | ); |
1546 | 1544 | $old_participants = array(); |
1547 | - foreach ($this->db->select($this->user_table,'cal_user_type,cal_user_id,cal_user_attendee,cal_status,cal_quantity,cal_role', $where, |
|
1548 | - __LINE__,__FILE__,false,'','calendar') as $row) |
|
1545 | + foreach ($this->db->select($this->user_table, 'cal_user_type,cal_user_id,cal_user_attendee,cal_status,cal_quantity,cal_role', $where, |
|
1546 | + __LINE__, __FILE__, false, '', 'calendar') as $row) |
|
1549 | 1547 | { |
1550 | 1548 | $uid = self::combine_user($row['cal_user_type'], $row['cal_user_id'], $row['cal_user_attendee']); |
1551 | 1549 | $status = self::combine_status($row['cal_status'], $row['cal_quantity'], $row['cal_role']); |
@@ -1555,7 +1553,7 @@ discard block |
||
1555 | 1553 | // re-check: did so much recurrence data change that we have to rebuild it from scratch? |
1556 | 1554 | if (!$set_recurrences) |
1557 | 1555 | { |
1558 | - $set_recurrences = (isset($event['cal_start']) && (int)$old_min != (int) $event['cal_start']) || |
|
1556 | + $set_recurrences = (isset($event['cal_start']) && (int)$old_min != (int)$event['cal_start']) || |
|
1559 | 1557 | $event['recur_type'] != $old_repeats['recur_type'] || $event['recur_data'] != $old_repeats['recur_data'] || |
1560 | 1558 | (int)$event['recur_interval'] != (int)$old_repeats['recur_interval'] || $event['tz_id'] != $old_tz_id; |
1561 | 1559 | } |
@@ -1564,22 +1562,22 @@ discard block |
||
1564 | 1562 | { |
1565 | 1563 | // too much recurrence data has changed, we have to do a rebuild from scratch |
1566 | 1564 | // delete all, but the lowest dates record |
1567 | - $this->db->delete($this->dates_table,array( |
|
1565 | + $this->db->delete($this->dates_table, array( |
|
1568 | 1566 | 'cal_id' => $cal_id, |
1569 | 1567 | 'cal_start > '.(int)$old_min, |
1570 | - ),__LINE__,__FILE__,'calendar'); |
|
1568 | + ), __LINE__, __FILE__, 'calendar'); |
|
1571 | 1569 | |
1572 | 1570 | // delete all user-records, with recur-date != 0 |
1573 | - $this->db->delete($this->user_table,array( |
|
1571 | + $this->db->delete($this->user_table, array( |
|
1574 | 1572 | 'cal_id' => $cal_id, |
1575 | 1573 | 'cal_recur_date != 0', |
1576 | - ),__LINE__,__FILE__,'calendar'); |
|
1574 | + ), __LINE__, __FILE__, 'calendar'); |
|
1577 | 1575 | } |
1578 | 1576 | else |
1579 | 1577 | { |
1580 | 1578 | // we adjust some possibly changed recurrences manually |
1581 | 1579 | // deleted exceptions: re-insert recurrences into the user and dates table |
1582 | - if (count($deleted_exceptions = array_diff($old_exceptions,$event['recur_exception']))) |
|
1580 | + if (count($deleted_exceptions = array_diff($old_exceptions, $event['recur_exception']))) |
|
1583 | 1581 | { |
1584 | 1582 | if (isset($event['cal_participants'])) |
1585 | 1583 | { |
@@ -1590,7 +1588,7 @@ discard block |
||
1590 | 1588 | // use old default |
1591 | 1589 | $participants = $old_participants; |
1592 | 1590 | } |
1593 | - foreach($deleted_exceptions as $id => $deleted_exception) |
|
1591 | + foreach ($deleted_exceptions as $id => $deleted_exception) |
|
1594 | 1592 | { |
1595 | 1593 | // rebuild participants for the re-inserted recurrence |
1596 | 1594 | $this->recurrence($cal_id, $deleted_exception, $deleted_exception + $old_duration, $participants); |
@@ -1598,24 +1596,24 @@ discard block |
||
1598 | 1596 | } |
1599 | 1597 | |
1600 | 1598 | // check if recurrence enddate was adjusted |
1601 | - if(isset($event['recur_enddate'])) |
|
1599 | + if (isset($event['recur_enddate'])) |
|
1602 | 1600 | { |
1603 | 1601 | // recurrences need to be truncated |
1604 | - if((int)$event['recur_enddate'] > 0 && |
|
1602 | + if ((int)$event['recur_enddate'] > 0 && |
|
1605 | 1603 | ((int)$old_repeats['recur_enddate'] == 0 || (int)$old_repeats['recur_enddate'] > (int)$event['recur_enddate']) |
1606 | 1604 | ) |
1607 | 1605 | { |
1608 | - $this->db->delete($this->user_table,array('cal_id' => $cal_id,'cal_recur_date >= '.($event['recur_enddate'] + 1*DAY_s)),__LINE__,__FILE__,'calendar'); |
|
1609 | - $this->db->delete($this->dates_table,array('cal_id' => $cal_id,'cal_start >= '.($event['recur_enddate'] + 1*DAY_s)),__LINE__,__FILE__,'calendar'); |
|
1606 | + $this->db->delete($this->user_table, array('cal_id' => $cal_id, 'cal_recur_date >= '.($event['recur_enddate'] + 1 * DAY_s)), __LINE__, __FILE__, 'calendar'); |
|
1607 | + $this->db->delete($this->dates_table, array('cal_id' => $cal_id, 'cal_start >= '.($event['recur_enddate'] + 1 * DAY_s)), __LINE__, __FILE__, 'calendar'); |
|
1610 | 1608 | } |
1611 | 1609 | |
1612 | 1610 | // recurrences need to be expanded |
1613 | - if(((int)$event['recur_enddate'] == 0 && (int)$old_repeats['recur_enddate'] > 0) |
|
1611 | + if (((int)$event['recur_enddate'] == 0 && (int)$old_repeats['recur_enddate'] > 0) |
|
1614 | 1612 | || ((int)$event['recur_enddate'] > 0 && (int)$old_repeats['recur_enddate'] > 0 && (int)$old_repeats['recur_enddate'] < (int)$event['recur_enddate']) |
1615 | 1613 | ) |
1616 | 1614 | { |
1617 | 1615 | $set_recurrences = true; |
1618 | - $set_recurrences_start = ($old_repeats['recur_enddate'] + 1*DAY_s); |
|
1616 | + $set_recurrences_start = ($old_repeats['recur_enddate'] + 1 * DAY_s); |
|
1619 | 1617 | } |
1620 | 1618 | //error_log(__METHOD__."() event[recur_enddate]=$event[recur_enddate], old_repeats[recur_enddate]=$old_repeats[recur_enddate] --> set_recurrences=".array2string($set_recurrences).", set_recurrences_start=$set_recurrences_start"); |
1621 | 1619 | } |
@@ -1624,9 +1622,9 @@ discard block |
||
1624 | 1622 | if (count($event['recur_exception'])) |
1625 | 1623 | { |
1626 | 1624 | // added and existing exceptions: delete the execeptions from the user table, it could be the first time |
1627 | - $this->db->delete($this->user_table,array('cal_id' => $cal_id,'cal_recur_date' => $event['recur_exception']),__LINE__,__FILE__,'calendar'); |
|
1625 | + $this->db->delete($this->user_table, array('cal_id' => $cal_id, 'cal_recur_date' => $event['recur_exception']), __LINE__, __FILE__, 'calendar'); |
|
1628 | 1626 | // update recur_exception flag based on current exceptions |
1629 | - $this->db->update($this->dates_table, 'recur_exception='.$this->db->expression($this->dates_table,array( |
|
1627 | + $this->db->update($this->dates_table, 'recur_exception='.$this->db->expression($this->dates_table, array( |
|
1630 | 1628 | 'cal_start' => $event['recur_exception'], |
1631 | 1629 | )), array( |
1632 | 1630 | 'cal_id' => $cal_id, |
@@ -1635,27 +1633,27 @@ discard block |
||
1635 | 1633 | } |
1636 | 1634 | |
1637 | 1635 | // write the repeats table |
1638 | - unset($event[0]); // unset the 'etag=etag+1', as it's not in the repeats table |
|
1639 | - $this->db->insert($this->repeats_table,$event,array('cal_id' => $cal_id),__LINE__,__FILE__,'calendar'); |
|
1636 | + unset($event[0]); // unset the 'etag=etag+1', as it's not in the repeats table |
|
1637 | + $this->db->insert($this->repeats_table, $event, array('cal_id' => $cal_id), __LINE__, __FILE__, 'calendar'); |
|
1640 | 1638 | } |
1641 | 1639 | // update start- and endtime if present in the event-array, evtl. we need to move all recurrences |
1642 | 1640 | if (isset($event['cal_start']) && isset($event['cal_end'])) |
1643 | 1641 | { |
1644 | - $this->move($cal_id,$event['cal_start'],$event['cal_end'],!$cal_id ? false : $change_since, $old_min, $old_min + $old_duration); |
|
1642 | + $this->move($cal_id, $event['cal_start'], $event['cal_end'], !$cal_id ? false : $change_since, $old_min, $old_min + $old_duration); |
|
1645 | 1643 | } |
1646 | 1644 | // update participants if present in the event-array |
1647 | 1645 | if (isset($event['cal_participants'])) |
1648 | 1646 | { |
1649 | - $this->participants($cal_id,$event['cal_participants'],!$cal_id ? false : $change_since); |
|
1647 | + $this->participants($cal_id, $event['cal_participants'], !$cal_id ? false : $change_since); |
|
1650 | 1648 | } |
1651 | 1649 | // Custom fields |
1652 | 1650 | Api\Storage\Customfields::handle_files('calendar', $cal_id, $event); |
1653 | 1651 | |
1654 | - foreach($event as $name => $value) |
|
1652 | + foreach ($event as $name => $value) |
|
1655 | 1653 | { |
1656 | 1654 | if ($name[0] == '#') |
1657 | 1655 | { |
1658 | - if (is_array($value) && array_key_exists('id',$value)) |
|
1656 | + if (is_array($value) && array_key_exists('id', $value)) |
|
1659 | 1657 | { |
1660 | 1658 | //error_log(__METHOD__.__LINE__."$name => ".array2string($value).function_backtrace()); |
1661 | 1659 | $value = $value['id']; |
@@ -1663,19 +1661,19 @@ discard block |
||
1663 | 1661 | } |
1664 | 1662 | if ($value) |
1665 | 1663 | { |
1666 | - $this->db->insert($this->extra_table,array( |
|
1667 | - 'cal_extra_value' => is_array($value) ? implode(',',$value) : $value, |
|
1668 | - ),array( |
|
1664 | + $this->db->insert($this->extra_table, array( |
|
1665 | + 'cal_extra_value' => is_array($value) ? implode(',', $value) : $value, |
|
1666 | + ), array( |
|
1669 | 1667 | 'cal_id' => $cal_id, |
1670 | - 'cal_extra_name' => substr($name,1), |
|
1671 | - ),__LINE__,__FILE__,'calendar'); |
|
1668 | + 'cal_extra_name' => substr($name, 1), |
|
1669 | + ), __LINE__, __FILE__, 'calendar'); |
|
1672 | 1670 | } |
1673 | 1671 | else |
1674 | 1672 | { |
1675 | - $this->db->delete($this->extra_table,array( |
|
1673 | + $this->db->delete($this->extra_table, array( |
|
1676 | 1674 | 'cal_id' => $cal_id, |
1677 | - 'cal_extra_name' => substr($name,1), |
|
1678 | - ),__LINE__,__FILE__,'calendar'); |
|
1675 | + 'cal_extra_name' => substr($name, 1), |
|
1676 | + ), __LINE__, __FILE__, 'calendar'); |
|
1679 | 1677 | } |
1680 | 1678 | } |
1681 | 1679 | } |
@@ -1686,9 +1684,9 @@ discard block |
||
1686 | 1684 | { |
1687 | 1685 | if ($alarm['id'] && strpos($alarm['id'], 'cal:'.$cal_id.':') !== 0) |
1688 | 1686 | { |
1689 | - unset($alarm['id']); // unset the temporary id to add the alarm |
|
1687 | + unset($alarm['id']); // unset the temporary id to add the alarm |
|
1690 | 1688 | } |
1691 | - if(!isset($alarm['offset'])) |
|
1689 | + if (!isset($alarm['offset'])) |
|
1692 | 1690 | { |
1693 | 1691 | $alarm['offset'] = $event['cal_start'] - $alarm['time']; |
1694 | 1692 | } |
@@ -1699,14 +1697,14 @@ discard block |
||
1699 | 1697 | |
1700 | 1698 | if ($alarm['time'] < time() && !self::shift_alarm($event, $alarm)) |
1701 | 1699 | { |
1702 | - continue; // pgoerzen: don't add alarm in the past |
|
1700 | + continue; // pgoerzen: don't add alarm in the past |
|
1703 | 1701 | } |
1704 | - $this->save_alarm($cal_id, $alarm, false); // false: not update modified, we do it anyway |
|
1702 | + $this->save_alarm($cal_id, $alarm, false); // false: not update modified, we do it anyway |
|
1705 | 1703 | } |
1706 | 1704 | } |
1707 | 1705 | if (is_null($etag)) |
1708 | 1706 | { |
1709 | - $etag = $this->db->select($this->cal_table,'cal_etag',array('cal_id' => $cal_id),__LINE__,__FILE__,false,'','calendar')->fetchColumn(); |
|
1707 | + $etag = $this->db->select($this->cal_table, 'cal_etag', array('cal_id' => $cal_id), __LINE__, __FILE__, false, '', 'calendar')->fetchColumn(); |
|
1710 | 1708 | } |
1711 | 1709 | |
1712 | 1710 | // if event is an exception: update modified of master, to force etag, ctag and sync-token change |
@@ -1726,7 +1724,7 @@ discard block |
||
1726 | 1724 | * are dealing with, default is now. |
1727 | 1725 | * @return boolean true if alarm could be shifted, false if not |
1728 | 1726 | */ |
1729 | - public static function shift_alarm(array $_event, array &$alarm, $timestamp=null) |
|
1727 | + public static function shift_alarm(array $_event, array &$alarm, $timestamp = null) |
|
1730 | 1728 | { |
1731 | 1729 | if ($_event['recur_type'] == MCAL_RECUR_NONE) |
1732 | 1730 | { |
@@ -1737,7 +1735,7 @@ discard block |
||
1737 | 1735 | $rrule = calendar_rrule::event2rrule($event, false); |
1738 | 1736 | foreach ($rrule as $time) |
1739 | 1737 | { |
1740 | - if ($start < ($ts = Api\DateTime::to($time,'server'))) |
|
1738 | + if ($start < ($ts = Api\DateTime::to($time, 'server'))) |
|
1741 | 1739 | { |
1742 | 1740 | $alarm['time'] = $ts - $alarm['offset']; |
1743 | 1741 | return true; |
@@ -1758,34 +1756,34 @@ discard block |
||
1758 | 1756 | * @todo Recalculate recurrences, if timezone changes |
1759 | 1757 | * @return int|boolean number of moved recurrences or false on error |
1760 | 1758 | */ |
1761 | - function move($cal_id,$start,$end,$change_since=0,$old_start=0,$old_end=0) |
|
1759 | + function move($cal_id, $start, $end, $change_since = 0, $old_start = 0, $old_end = 0) |
|
1762 | 1760 | { |
1763 | 1761 | //echo "<p>socal::move($cal_id,$start,$end,$change_since,$old_start,$old_end)</p>\n"; |
1764 | 1762 | |
1765 | - if (!(int) $cal_id) return false; |
|
1763 | + if (!(int)$cal_id) return false; |
|
1766 | 1764 | |
1767 | 1765 | if (!$old_start) |
1768 | 1766 | { |
1769 | - if ($change_since !== false) $row = $this->db->select($this->dates_table,'MIN(cal_start) AS cal_start,MIN(cal_end) AS cal_end', |
|
1770 | - array('cal_id'=>$cal_id),__LINE__,__FILE__,false,'','calendar')->fetch(); |
|
1767 | + if ($change_since !== false) $row = $this->db->select($this->dates_table, 'MIN(cal_start) AS cal_start,MIN(cal_end) AS cal_end', |
|
1768 | + array('cal_id'=>$cal_id), __LINE__, __FILE__, false, '', 'calendar')->fetch(); |
|
1771 | 1769 | // if no recurrence found, create one with the new dates |
1772 | 1770 | if ($change_since === false || !$row || !$row['cal_start'] || !$row['cal_end']) |
1773 | 1771 | { |
1774 | - $this->db->insert($this->dates_table,array( |
|
1772 | + $this->db->insert($this->dates_table, array( |
|
1775 | 1773 | 'cal_id' => $cal_id, |
1776 | 1774 | 'cal_start' => $start, |
1777 | 1775 | 'cal_end' => $end, |
1778 | - ),false,__LINE__,__FILE__,'calendar'); |
|
1776 | + ), false, __LINE__, __FILE__, 'calendar'); |
|
1779 | 1777 | |
1780 | 1778 | return 1; |
1781 | 1779 | } |
1782 | - $move_start = (int) ($start-$row['cal_start']); |
|
1783 | - $move_end = (int) ($end-$row['cal_end']); |
|
1780 | + $move_start = (int)($start - $row['cal_start']); |
|
1781 | + $move_end = (int)($end - $row['cal_end']); |
|
1784 | 1782 | } |
1785 | 1783 | else |
1786 | 1784 | { |
1787 | - $move_start = (int) ($start-$old_start); |
|
1788 | - $move_end = (int) ($end-$old_end); |
|
1785 | + $move_start = (int)($start - $old_start); |
|
1786 | + $move_end = (int)($end - $old_end); |
|
1789 | 1787 | } |
1790 | 1788 | $where = 'cal_id='.(int)$cal_id; |
1791 | 1789 | |
@@ -1793,13 +1791,13 @@ discard block |
||
1793 | 1791 | { |
1794 | 1792 | // move the recur-date of the participants |
1795 | 1793 | $this->db->query("UPDATE $this->user_table SET cal_recur_date=cal_recur_date+$move_start WHERE $where AND cal_recur_date ". |
1796 | - ((int)$change_since ? '>= '.(int)$change_since : '!= 0'),__LINE__,__FILE__); |
|
1794 | + ((int)$change_since ? '>= '.(int)$change_since : '!= 0'), __LINE__, __FILE__); |
|
1797 | 1795 | } |
1798 | 1796 | if ($move_start || $move_end) |
1799 | 1797 | { |
1800 | 1798 | // move the event and it's recurrences |
1801 | 1799 | $this->db->query("UPDATE $this->dates_table SET cal_start=cal_start+$move_start,cal_end=cal_end+$move_end WHERE $where". |
1802 | - ((int) $change_since ? ' AND cal_start >= '.(int) $change_since : ''),__LINE__,__FILE__); |
|
1800 | + ((int)$change_since ? ' AND cal_start >= '.(int)$change_since : ''), __LINE__, __FILE__); |
|
1803 | 1801 | } |
1804 | 1802 | return $this->db->affected_rows(); |
1805 | 1803 | } |
@@ -1818,8 +1816,7 @@ discard block |
||
1818 | 1816 | } |
1819 | 1817 | if (is_array($attendee)) |
1820 | 1818 | { |
1821 | - $email = !empty($attendee['email']) ? $user_attendee['email'] : |
|
1822 | - (strtolower(substr($attendee['url'], 0, 7)) == 'mailto:' ? substr($user_attendee['url'], 7) : $attendee['url']); |
|
1819 | + $email = !empty($attendee['email']) ? $user_attendee['email'] : (strtolower(substr($attendee['url'], 0, 7)) == 'mailto:' ? substr($user_attendee['url'], 7) : $attendee['url']); |
|
1823 | 1820 | $attendee = !empty($attendee['cn']) ? $attendee['cn'].' <'.$email.'>' : $email; |
1824 | 1821 | } |
1825 | 1822 | return $attendee; |
@@ -1832,11 +1829,11 @@ discard block |
||
1832 | 1829 | * @param string|array $attendee attendee information: email, json or array with attr cn and url |
1833 | 1830 | * @return string|int combined id |
1834 | 1831 | */ |
1835 | - static function combine_user($user_type, $user_id, $attendee=null) |
|
1832 | + static function combine_user($user_type, $user_id, $attendee = null) |
|
1836 | 1833 | { |
1837 | 1834 | if (!$user_type || $user_type == 'u') |
1838 | 1835 | { |
1839 | - return (int) $user_id; |
|
1836 | + return (int)$user_id; |
|
1840 | 1837 | } |
1841 | 1838 | if ($user_type == 'e' && $attendee) |
1842 | 1839 | { |
@@ -1856,12 +1853,12 @@ discard block |
||
1856 | 1853 | * @param string|int &$user_id id |
1857 | 1854 | * @param boolean $md5_email =false md5 hash user_id for email / user_type=="e" |
1858 | 1855 | */ |
1859 | - static function split_user($uid, &$user_type, &$user_id, $md5_email=false) |
|
1856 | + static function split_user($uid, &$user_type, &$user_id, $md5_email = false) |
|
1860 | 1857 | { |
1861 | 1858 | if (is_numeric($uid)) |
1862 | 1859 | { |
1863 | 1860 | $user_type = 'u'; |
1864 | - $user_id = (int) $uid; |
|
1861 | + $user_id = (int)$uid; |
|
1865 | 1862 | } |
1866 | 1863 | // create md5 hash from lowercased and trimed raw email ("[email protected]", not "Ralf Becker <[email protected]>") |
1867 | 1864 | elseif ($md5_email && $uid[0] == 'e') |
@@ -1875,7 +1872,7 @@ discard block |
||
1875 | 1872 | else |
1876 | 1873 | { |
1877 | 1874 | $user_type = $uid[0]; |
1878 | - $user_id = substr($uid,1); |
|
1875 | + $user_id = substr($uid, 1); |
|
1879 | 1876 | } |
1880 | 1877 | } |
1881 | 1878 | |
@@ -1887,7 +1884,7 @@ discard block |
||
1887 | 1884 | * @param string $role ='REQ-PARTICIPANT' |
1888 | 1885 | * @return string |
1889 | 1886 | */ |
1890 | - static function combine_status($status,$quantity=1,$role='REQ-PARTICIPANT') |
|
1887 | + static function combine_status($status, $quantity = 1, $role = 'REQ-PARTICIPANT') |
|
1891 | 1888 | { |
1892 | 1889 | if ((int)$quantity > 1) $status .= (int)$quantity; |
1893 | 1890 | if ($role != 'REQ-PARTICIPANT') $status .= $role; |
@@ -1903,13 +1900,13 @@ discard block |
||
1903 | 1900 | * @param string &$role=null only O: role |
1904 | 1901 | * @return string status U, T, A or R, same as $status parameter on return |
1905 | 1902 | */ |
1906 | - static function split_status(&$status,&$quantity=null,&$role=null) |
|
1903 | + static function split_status(&$status, &$quantity = null, &$role = null) |
|
1907 | 1904 | { |
1908 | 1905 | $quantity = 1; |
1909 | 1906 | $role = 'REQ-PARTICIPANT'; |
1910 | 1907 | //error_log(__METHOD__.__LINE__.array2string($status)); |
1911 | 1908 | $matches = null; |
1912 | - if (is_string($status) && strlen($status) > 1 && preg_match('/^.([0-9]*)(.*)$/',$status,$matches)) |
|
1909 | + if (is_string($status) && strlen($status) > 1 && preg_match('/^.([0-9]*)(.*)$/', $status, $matches)) |
|
1913 | 1910 | { |
1914 | 1911 | if ((int)$matches[1] > 0) $quantity = (int)$matches[1]; |
1915 | 1912 | if ($matches[2]) $role = $matches[2]; |
@@ -1936,14 +1933,14 @@ discard block |
||
1936 | 1933 | * true = only add participants if needed, no participant will be deleted (participants to check/add required in $participants) |
1937 | 1934 | * @return int|boolean number of updated recurrences or false on error |
1938 | 1935 | */ |
1939 | - function participants($cal_id,$participants,$change_since=0,$add_only=false) |
|
1936 | + function participants($cal_id, $participants, $change_since = 0, $add_only = false) |
|
1940 | 1937 | { |
1941 | 1938 | //error_log(__METHOD__."($cal_id,".array2string($participants).",$change_since,$add_only"); |
1942 | 1939 | |
1943 | 1940 | $recurrences = array(); |
1944 | 1941 | |
1945 | 1942 | // remove group-invitations, they are NOT stored in the db |
1946 | - foreach($participants as $uid => $status) |
|
1943 | + foreach ($participants as $uid => $status) |
|
1947 | 1944 | { |
1948 | 1945 | if ($status[0] == 'G') |
1949 | 1946 | { |
@@ -1952,7 +1949,7 @@ discard block |
||
1952 | 1949 | } |
1953 | 1950 | $where = array('cal_id' => $cal_id); |
1954 | 1951 | |
1955 | - if ((int) $change_since) |
|
1952 | + if ((int)$change_since) |
|
1956 | 1953 | { |
1957 | 1954 | $where[] = '(cal_recur_date=0 OR cal_recur_date >= '.(int)$change_since.')'; |
1958 | 1955 | } |
@@ -1960,31 +1957,31 @@ discard block |
||
1960 | 1957 | if ($change_since !== false) |
1961 | 1958 | { |
1962 | 1959 | // find all existing recurrences |
1963 | - foreach($this->db->select($this->user_table,'DISTINCT cal_recur_date',$where,__LINE__,__FILE__,false,'','calendar') as $row) |
|
1960 | + foreach ($this->db->select($this->user_table, 'DISTINCT cal_recur_date', $where, __LINE__, __FILE__, false, '', 'calendar') as $row) |
|
1964 | 1961 | { |
1965 | 1962 | $recurrences[] = $row['cal_recur_date']; |
1966 | 1963 | } |
1967 | 1964 | |
1968 | 1965 | // update existing entries |
1969 | - $existing_entries = $this->db->select($this->user_table,'*',$where,__LINE__,__FILE__,false,'ORDER BY cal_recur_date DESC','calendar'); |
|
1966 | + $existing_entries = $this->db->select($this->user_table, '*', $where, __LINE__, __FILE__, false, 'ORDER BY cal_recur_date DESC', 'calendar'); |
|
1970 | 1967 | |
1971 | 1968 | // create a full list of participants which already exist in the db |
1972 | 1969 | // with status, quantity and role of the earliest recurence |
1973 | 1970 | $old_participants = array(); |
1974 | - foreach($existing_entries as $row) |
|
1971 | + foreach ($existing_entries as $row) |
|
1975 | 1972 | { |
1976 | 1973 | $uid = self::combine_user($row['cal_user_type'], $row['cal_user_id'], $row['cal_user_attendee']); |
1977 | 1974 | if ($row['cal_recur_date'] || !isset($old_participants[$uid])) |
1978 | 1975 | { |
1979 | - $old_participants[$uid] = self::combine_status($row['cal_status'],$row['cal_quantity'],$row['cal_role']); |
|
1976 | + $old_participants[$uid] = self::combine_status($row['cal_status'], $row['cal_quantity'], $row['cal_role']); |
|
1980 | 1977 | } |
1981 | 1978 | } |
1982 | 1979 | |
1983 | 1980 | // tag participants which should be deleted |
1984 | - if($add_only === false) |
|
1981 | + if ($add_only === false) |
|
1985 | 1982 | { |
1986 | 1983 | $deleted = array(); |
1987 | - foreach($existing_entries as $row) |
|
1984 | + foreach ($existing_entries as $row) |
|
1988 | 1985 | { |
1989 | 1986 | $uid = self::combine_user($row['cal_user_type'], $row['cal_user_id'], $row['cal_user_attendee']); |
1990 | 1987 | // delete not longer set participants |
@@ -1997,7 +1994,7 @@ discard block |
||
1997 | 1994 | |
1998 | 1995 | // only keep added OR status (incl. quantity!) changed participants for further steps |
1999 | 1996 | // we do not touch unchanged (!) existing ones |
2000 | - foreach($participants as $uid => $status) |
|
1997 | + foreach ($participants as $uid => $status) |
|
2001 | 1998 | { |
2002 | 1999 | if ($old_participants[$uid] === $status) |
2003 | 2000 | { |
@@ -2009,46 +2006,46 @@ discard block |
||
2009 | 2006 | if ($add_only === false && count($deleted)) |
2010 | 2007 | { |
2011 | 2008 | $to_or = array(); |
2012 | - $table_def = $this->db->get_table_definitions('calendar',$this->user_table); |
|
2013 | - foreach($deleted as $type => $ids) |
|
2009 | + $table_def = $this->db->get_table_definitions('calendar', $this->user_table); |
|
2010 | + foreach ($deleted as $type => $ids) |
|
2014 | 2011 | { |
2015 | - $to_or[] = $this->db->expression($table_def,array( |
|
2012 | + $to_or[] = $this->db->expression($table_def, array( |
|
2016 | 2013 | 'cal_user_type' => $type, |
2017 | 2014 | 'cal_user_id' => $ids, |
2018 | 2015 | )); |
2019 | 2016 | } |
2020 | - $where[] = '('.implode(' OR ',$to_or).')'; |
|
2021 | - $where[] = "cal_status!='E'"; // do NOT delete exception marker |
|
2022 | - $this->db->update($this->user_table,array('cal_status'=>'X'),$where,__LINE__,__FILE__,'calendar'); |
|
2017 | + $where[] = '('.implode(' OR ', $to_or).')'; |
|
2018 | + $where[] = "cal_status!='E'"; // do NOT delete exception marker |
|
2019 | + $this->db->update($this->user_table, array('cal_status'=>'X'), $where, __LINE__, __FILE__, 'calendar'); |
|
2023 | 2020 | } |
2024 | 2021 | } |
2025 | 2022 | |
2026 | 2023 | if (count($participants)) // participants which need to be added |
2027 | 2024 | { |
2028 | - if (!count($recurrences)) $recurrences[] = 0; // insert the default recurrence |
|
2025 | + if (!count($recurrences)) $recurrences[] = 0; // insert the default recurrence |
|
2029 | 2026 | |
2030 | 2027 | $delete_deleted = array(); |
2031 | 2028 | |
2032 | 2029 | // update participants |
2033 | - foreach($participants as $uid => $status) |
|
2030 | + foreach ($participants as $uid => $status) |
|
2034 | 2031 | { |
2035 | 2032 | $type = $id = $quantity = $role = null; |
2036 | 2033 | self::split_user($uid, $type, $id, true); |
2037 | - self::split_status($status,$quantity,$role); |
|
2034 | + self::split_status($status, $quantity, $role); |
|
2038 | 2035 | $set = array( |
2039 | 2036 | 'cal_status' => $status, |
2040 | 2037 | 'cal_quantity' => $quantity, |
2041 | 2038 | 'cal_role' => $role, |
2042 | 2039 | 'cal_user_attendee' => $type == 'e' ? substr($uid, 1) : null, |
2043 | 2040 | ); |
2044 | - foreach($recurrences as $recur_date) |
|
2041 | + foreach ($recurrences as $recur_date) |
|
2045 | 2042 | { |
2046 | - $this->db->insert($this->user_table,$set,array( |
|
2043 | + $this->db->insert($this->user_table, $set, array( |
|
2047 | 2044 | 'cal_id' => $cal_id, |
2048 | 2045 | 'cal_recur_date' => $recur_date, |
2049 | 2046 | 'cal_user_type' => $type, |
2050 | 2047 | 'cal_user_id' => $id, |
2051 | - ),__LINE__,__FILE__,'calendar'); |
|
2048 | + ), __LINE__, __FILE__, 'calendar'); |
|
2052 | 2049 | } |
2053 | 2050 | // for new or changed group-invitations, remove previously deleted members, so they show up again |
2054 | 2051 | if ($uid < 0) |
@@ -2058,13 +2055,13 @@ discard block |
||
2058 | 2055 | } |
2059 | 2056 | if ($delete_deleted) |
2060 | 2057 | { |
2061 | - $this->db->delete($this->user_table, $where=array( |
|
2058 | + $this->db->delete($this->user_table, $where = array( |
|
2062 | 2059 | 'cal_id' => $cal_id, |
2063 | 2060 | 'cal_recur_date' => $recurrences, |
2064 | 2061 | 'cal_user_type' => 'u', |
2065 | 2062 | 'cal_user_id' => array_unique($delete_deleted), |
2066 | 2063 | 'cal_status' => 'X', |
2067 | - ),__LINE__,__FILE__,'calendar'); |
|
2064 | + ), __LINE__, __FILE__, 'calendar'); |
|
2068 | 2065 | //error_log(__METHOD__."($cal_id, ".array2string($participants).", since=$change_since, add_only=$add_only) db->delete('$this->user_table', ".array2string($where).") affected ".$this->db->affected_rows().' rows'); |
2069 | 2066 | } |
2070 | 2067 | } |
@@ -2083,7 +2080,7 @@ discard block |
||
2083 | 2080 | * @param string $attendee =null extra attendee information to set for all types (incl. accounts!) |
2084 | 2081 | * @return int number of changed recurrences |
2085 | 2082 | */ |
2086 | - function set_status($cal_id,$user_type,$user_id,$status,$recur_date=0,$role=null,$attendee=null) |
|
2083 | + function set_status($cal_id, $user_type, $user_id, $status, $recur_date = 0, $role = null, $attendee = null) |
|
2087 | 2084 | { |
2088 | 2085 | static $status_code_short = array( |
2089 | 2086 | REJECTED => 'R', |
@@ -2108,7 +2105,7 @@ discard block |
||
2108 | 2105 | 'cal_user_type' => $user_type, |
2109 | 2106 | 'cal_user_id' => $user_id_md5, |
2110 | 2107 | ); |
2111 | - if ((int) $recur_date) |
|
2108 | + if ((int)$recur_date) |
|
2112 | 2109 | { |
2113 | 2110 | $where['cal_recur_date'] = $recur_date; |
2114 | 2111 | } |
@@ -2119,7 +2116,7 @@ discard block |
||
2119 | 2116 | |
2120 | 2117 | if ($status == 'G') // remove group invitations, as we dont store them in the db |
2121 | 2118 | { |
2122 | - $this->db->delete($this->user_table,$where,__LINE__,__FILE__,'calendar'); |
|
2119 | + $this->db->delete($this->user_table, $where, __LINE__, __FILE__, 'calendar'); |
|
2123 | 2120 | $ret = $this->db->affected_rows(); |
2124 | 2121 | } |
2125 | 2122 | else |
@@ -2127,7 +2124,7 @@ discard block |
||
2127 | 2124 | $set = array('cal_status' => $status); |
2128 | 2125 | if ($user_type == 'e' || $attendee) $set['cal_user_attendee'] = $attendee ? $attendee : $user_id; |
2129 | 2126 | if (!is_null($role) && $role != 'REQ-PARTICIPANT') $set['cal_role'] = $role; |
2130 | - $this->db->insert($this->user_table,$set,$where,__LINE__,__FILE__,'calendar'); |
|
2127 | + $this->db->insert($this->user_table, $set, $where, __LINE__, __FILE__, 'calendar'); |
|
2131 | 2128 | // for new or changed group-invitations, remove previously deleted members, so they show up again |
2132 | 2129 | if (($ret = $this->db->affected_rows()) && $user_type == 'u' && $user_id < 0) |
2133 | 2130 | { |
@@ -2140,7 +2137,7 @@ discard block |
||
2140 | 2137 | // update modified and modifier in main table |
2141 | 2138 | if ($ret) |
2142 | 2139 | { |
2143 | - $this->updateModified($cal_id, true); // true = update series master too |
|
2140 | + $this->updateModified($cal_id, true); // true = update series master too |
|
2144 | 2141 | } |
2145 | 2142 | //error_log(__METHOD__."($cal_id,$user_type,$user_id,$status,$recur_date) = $ret"); |
2146 | 2143 | return $ret; |
@@ -2155,7 +2152,7 @@ discard block |
||
2155 | 2152 | * @param array $participants uid => status pairs |
2156 | 2153 | * @param boolean $exception =null true or false to set recure_exception flag, null leave it unchanged (new are by default no exception) |
2157 | 2154 | */ |
2158 | - function recurrence($cal_id,$start,$end,$participants,$exception=null) |
|
2155 | + function recurrence($cal_id, $start, $end, $participants, $exception = null) |
|
2159 | 2156 | { |
2160 | 2157 | //error_log(__METHOD__."($cal_id, $start, $end, ".array2string($participants).", ".array2string($exception)); |
2161 | 2158 | $update = array('cal_end' => $end); |
@@ -2164,7 +2161,7 @@ discard block |
||
2164 | 2161 | $this->db->insert($this->dates_table, $update, array( |
2165 | 2162 | 'cal_id' => $cal_id, |
2166 | 2163 | 'cal_start' => $start, |
2167 | - ),__LINE__,__FILE__,'calendar'); |
|
2164 | + ), __LINE__, __FILE__, 'calendar'); |
|
2168 | 2165 | |
2169 | 2166 | if (!is_array($participants)) |
2170 | 2167 | { |
@@ -2172,26 +2169,26 @@ discard block |
||
2172 | 2169 | } |
2173 | 2170 | if ($exception !== true) |
2174 | 2171 | { |
2175 | - foreach($participants as $uid => $status) |
|
2172 | + foreach ($participants as $uid => $status) |
|
2176 | 2173 | { |
2177 | - if ($status == 'G') continue; // dont save group-invitations |
|
2174 | + if ($status == 'G') continue; // dont save group-invitations |
|
2178 | 2175 | |
2179 | 2176 | $type = ''; |
2180 | 2177 | $id = null; |
2181 | 2178 | self::split_user($uid, $type, $id, true); |
2182 | 2179 | $quantity = $role = null; |
2183 | - self::split_status($status,$quantity,$role); |
|
2184 | - $this->db->insert($this->user_table,array( |
|
2180 | + self::split_status($status, $quantity, $role); |
|
2181 | + $this->db->insert($this->user_table, array( |
|
2185 | 2182 | 'cal_status' => $status, |
2186 | 2183 | 'cal_quantity' => $quantity, |
2187 | 2184 | 'cal_role' => $role, |
2188 | 2185 | 'cal_user_attendee' => $type == 'e' ? substr($uid, 1) : null, |
2189 | - ),array( |
|
2186 | + ), array( |
|
2190 | 2187 | 'cal_id' => $cal_id, |
2191 | 2188 | 'cal_recur_date' => $start, |
2192 | 2189 | 'cal_user_type' => $type, |
2193 | 2190 | 'cal_user_id' => $id, |
2194 | - ),__LINE__,__FILE__,'calendar'); |
|
2191 | + ), __LINE__, __FILE__, 'calendar'); |
|
2195 | 2192 | } |
2196 | 2193 | } |
2197 | 2194 | } |
@@ -2205,7 +2202,7 @@ discard block |
||
2205 | 2202 | function unfinished_recuring($time) |
2206 | 2203 | { |
2207 | 2204 | $ids = array(); |
2208 | - foreach($rs=$this->db->select($this->repeats_table, "$this->repeats_table.cal_id,MAX(cal_start) AS cal_start", |
|
2205 | + foreach ($rs = $this->db->select($this->repeats_table, "$this->repeats_table.cal_id,MAX(cal_start) AS cal_start", |
|
2209 | 2206 | '(range_end IS NULL OR range_end > '.(int)$time.')', |
2210 | 2207 | __LINE__, __FILE__, false, "GROUP BY $this->repeats_table.cal_id,range_end", 'calendar', 0, |
2211 | 2208 | " JOIN $this->cal_table ON $this->repeats_table.cal_id=$this->cal_table.cal_id". |
@@ -2231,9 +2228,9 @@ discard block |
||
2231 | 2228 | // update timestamp of series master, updates own timestamp too, which does not hurt ;-) |
2232 | 2229 | $this->updateModified($cal_id, true); |
2233 | 2230 | |
2234 | - foreach($this->all_tables as $table) |
|
2231 | + foreach ($this->all_tables as $table) |
|
2235 | 2232 | { |
2236 | - $this->db->delete($table,array('cal_id'=>$cal_id),__LINE__,__FILE__,'calendar'); |
|
2233 | + $this->db->delete($table, array('cal_id'=>$cal_id), __LINE__, __FILE__, 'calendar'); |
|
2237 | 2234 | } |
2238 | 2235 | } |
2239 | 2236 | |
@@ -2249,10 +2246,10 @@ discard block |
||
2249 | 2246 | function purge($date) |
2250 | 2247 | { |
2251 | 2248 | // with new range_end we simple delete all with range_end < $date (range_end NULL is never returned) |
2252 | - foreach($this->db->select($this->cal_table, 'cal_id', 'range_end < '.(int)$date, __LINE__, __FILE__, false, '', 'calendar') as $row) |
|
2249 | + foreach ($this->db->select($this->cal_table, 'cal_id', 'range_end < '.(int)$date, __LINE__, __FILE__, false, '', 'calendar') as $row) |
|
2253 | 2250 | { |
2254 | 2251 | //echo __METHOD__." About to delete".$row['cal_id']."\r\n"; |
2255 | - foreach($this->all_tables as $table) |
|
2252 | + foreach ($this->all_tables as $table) |
|
2256 | 2253 | { |
2257 | 2254 | $this->db->delete($table, array('cal_id'=>$row['cal_id']), __LINE__, __FILE__, 'calendar'); |
2258 | 2255 | } |
@@ -2277,23 +2274,23 @@ discard block |
||
2277 | 2274 | * @param boolean $update_cache =null true: re-read given $cal_id, false: delete given $cal_id |
2278 | 2275 | * @return array of (cal_id => array of) alarms with alarm-id as key |
2279 | 2276 | */ |
2280 | - function read_alarms($cal_id, $update_cache=null) |
|
2277 | + function read_alarms($cal_id, $update_cache = null) |
|
2281 | 2278 | { |
2282 | 2279 | if (!isset(self::$alarm_cache) && is_array($cal_id)) |
2283 | 2280 | { |
2284 | 2281 | self::$alarm_cache = array(); |
2285 | 2282 | if (($jobs = $this->async->read('cal:%'))) |
2286 | 2283 | { |
2287 | - foreach($jobs as $id => $job) |
|
2284 | + foreach ($jobs as $id => $job) |
|
2288 | 2285 | { |
2289 | - $alarm = $job['data']; // text, enabled |
|
2286 | + $alarm = $job['data']; // text, enabled |
|
2290 | 2287 | $alarm['id'] = $id; |
2291 | 2288 | $alarm['time'] = $job['next']; |
2292 | 2289 | |
2293 | 2290 | self::$alarm_cache[$alarm['cal_id']][$id] = $alarm; |
2294 | 2291 | } |
2295 | 2292 | } |
2296 | - unset($update_cache); // just done |
|
2293 | + unset($update_cache); // just done |
|
2297 | 2294 | } |
2298 | 2295 | $alarms = array(); |
2299 | 2296 | |
@@ -2301,13 +2298,13 @@ discard block |
||
2301 | 2298 | { |
2302 | 2299 | if (isset($update_cache)) |
2303 | 2300 | { |
2304 | - foreach((array)$cal_id as $id) |
|
2301 | + foreach ((array)$cal_id as $id) |
|
2305 | 2302 | { |
2306 | 2303 | if ($update_cache === false) |
2307 | 2304 | { |
2308 | 2305 | unset(self::$alarm_cache[$cal_id]); |
2309 | 2306 | } |
2310 | - elseif($update_cache === true) |
|
2307 | + elseif ($update_cache === true) |
|
2311 | 2308 | { |
2312 | 2309 | self::$alarm_cache[$cal_id] = $this->read_alarms_nocache($cal_id); |
2313 | 2310 | } |
@@ -2319,7 +2316,7 @@ discard block |
||
2319 | 2316 | } |
2320 | 2317 | else |
2321 | 2318 | { |
2322 | - foreach($cal_id as $id) |
|
2319 | + foreach ($cal_id as $id) |
|
2323 | 2320 | { |
2324 | 2321 | $alarms[$id] = (array)self::$alarm_cache[$id]; |
2325 | 2322 | } |
@@ -2334,9 +2331,9 @@ discard block |
||
2334 | 2331 | { |
2335 | 2332 | if (($jobs = $this->async->read('cal:'.(int)$cal_id.':%'))) |
2336 | 2333 | { |
2337 | - foreach($jobs as $id => $job) |
|
2334 | + foreach ($jobs as $id => $job) |
|
2338 | 2335 | { |
2339 | - $alarm = $job['data']; // text, enabled |
|
2336 | + $alarm = $job['data']; // text, enabled |
|
2340 | 2337 | $alarm['id'] = $id; |
2341 | 2338 | $alarm['time'] = $job['next']; |
2342 | 2339 | |
@@ -2359,8 +2356,8 @@ discard block |
||
2359 | 2356 | { |
2360 | 2357 | return False; |
2361 | 2358 | } |
2362 | - list($alarm_id,$job) = each($jobs); |
|
2363 | - $alarm = $job['data']; // text, enabled |
|
2359 | + list($alarm_id, $job) = each($jobs); |
|
2360 | + $alarm = $job['data']; // text, enabled |
|
2364 | 2361 | $alarm['id'] = $alarm_id; |
2365 | 2362 | $alarm['time'] = $job['next']; |
2366 | 2363 | |
@@ -2376,12 +2373,12 @@ discard block |
||
2376 | 2373 | * @param boolean $update_modified =true call update modified, default true |
2377 | 2374 | * @return string id of the alarm |
2378 | 2375 | */ |
2379 | - function save_alarm($cal_id, $alarm, $update_modified=true) |
|
2376 | + function save_alarm($cal_id, $alarm, $update_modified = true) |
|
2380 | 2377 | { |
2381 | 2378 | //error_log(__METHOD__."($cal_id, ".array2string($alarm).', '.array2string($update_modified).') '.function_backtrace()); |
2382 | 2379 | if (!($id = $alarm['id'])) |
2383 | 2380 | { |
2384 | - $alarms = $this->read_alarms($cal_id); // find a free alarm# |
|
2381 | + $alarms = $this->read_alarms($cal_id); // find a free alarm# |
|
2385 | 2382 | $n = count($alarms); |
2386 | 2383 | do |
2387 | 2384 | { |
@@ -2394,13 +2391,13 @@ discard block |
||
2394 | 2391 | { |
2395 | 2392 | $this->async->cancel_timer($id); |
2396 | 2393 | } |
2397 | - $alarm['cal_id'] = $cal_id; // we need the back-reference |
|
2394 | + $alarm['cal_id'] = $cal_id; // we need the back-reference |
|
2398 | 2395 | // do not deleted async-job, as we need it for alarm snozzing |
2399 | 2396 | $alarm['keep'] = self::ALARM_KEEP_TIME; |
2400 | 2397 | // past alarms need NOT to be triggered, but kept around for a while to allow alarm snozzing |
2401 | 2398 | if ($alarm['time'] < time()) |
2402 | 2399 | { |
2403 | - $alarm['time'] = $alarm['keep_time'] = time()+self::ALARM_KEEP_TIME; |
|
2400 | + $alarm['time'] = $alarm['keep_time'] = time() + self::ALARM_KEEP_TIME; |
|
2404 | 2401 | } |
2405 | 2402 | // add an alarm uid, if none is given |
2406 | 2403 | if (empty($alarm['uid']) && class_exists('Horde_Support_Uuid')) $alarm['uid'] = (string)new Horde_Support_Uuid; |
@@ -2433,7 +2430,7 @@ discard block |
||
2433 | 2430 | //error_log(__METHOD__."($cal_id) ".function_backtrace()); |
2434 | 2431 | if (($alarms = $this->read_alarms($cal_id))) |
2435 | 2432 | { |
2436 | - foreach(array_keys($alarms) as $id) |
|
2433 | + foreach (array_keys($alarms) as $id) |
|
2437 | 2434 | { |
2438 | 2435 | $this->async->cancel_timer($id); |
2439 | 2436 | } |
@@ -2453,7 +2450,7 @@ discard block |
||
2453 | 2450 | { |
2454 | 2451 | //error_log(__METHOD__."('$id') ".function_backtrace()); |
2455 | 2452 | // update the modification information of the related event |
2456 | - list(,$cal_id) = explode(':',$id); |
|
2453 | + list(,$cal_id) = explode(':', $id); |
|
2457 | 2454 | if ($cal_id) |
2458 | 2455 | { |
2459 | 2456 | $this->updateModified($cal_id, true); |
@@ -2472,7 +2469,7 @@ discard block |
||
2472 | 2469 | * @param array|int $old_user integer old user or array with keys 'account_id' and 'new_owner' as the deleteaccount hook uses it |
2473 | 2470 | * @param int $new_user =null |
2474 | 2471 | */ |
2475 | - function deleteaccount($old_user, $new_user=null) |
|
2472 | + function deleteaccount($old_user, $new_user = null) |
|
2476 | 2473 | { |
2477 | 2474 | if (is_array($old_user)) |
2478 | 2475 | { |
@@ -2483,52 +2480,52 @@ discard block |
||
2483 | 2480 | { |
2484 | 2481 | $user_type = ''; |
2485 | 2482 | $user_id = null; |
2486 | - self::split_user($old_user,$user_type,$user_id); |
|
2483 | + self::split_user($old_user, $user_type, $user_id); |
|
2487 | 2484 | |
2488 | 2485 | if ($user_type == 'u') // only accounts can be owners of events |
2489 | 2486 | { |
2490 | - foreach($this->db->select($this->cal_table,'cal_id',array('cal_owner' => $old_user),__LINE__,__FILE__,false,'','calendar') as $row) |
|
2487 | + foreach ($this->db->select($this->cal_table, 'cal_id', array('cal_owner' => $old_user), __LINE__, __FILE__, false, '', 'calendar') as $row) |
|
2491 | 2488 | { |
2492 | 2489 | $this->delete($row['cal_id']); |
2493 | 2490 | } |
2494 | 2491 | } |
2495 | - $this->db->delete($this->user_table,array( |
|
2492 | + $this->db->delete($this->user_table, array( |
|
2496 | 2493 | 'cal_user_type' => $user_type, |
2497 | 2494 | 'cal_user_id' => $user_id, |
2498 | - ),__LINE__,__FILE__,'calendar'); |
|
2495 | + ), __LINE__, __FILE__, 'calendar'); |
|
2499 | 2496 | |
2500 | 2497 | // delete calendar entries without participants (can happen if the deleted user is the only participants, but not the owner) |
2501 | - foreach($this->db->select($this->cal_table,"DISTINCT $this->cal_table.cal_id",'cal_user_id IS NULL',__LINE__,__FILE__, |
|
2502 | - False,'','calendar',0,"LEFT JOIN $this->user_table ON $this->cal_table.cal_id=$this->user_table.cal_id") as $row) |
|
2498 | + foreach ($this->db->select($this->cal_table, "DISTINCT $this->cal_table.cal_id", 'cal_user_id IS NULL', __LINE__, __FILE__, |
|
2499 | + False, '', 'calendar', 0, "LEFT JOIN $this->user_table ON $this->cal_table.cal_id=$this->user_table.cal_id") as $row) |
|
2503 | 2500 | { |
2504 | 2501 | $this->delete($row['cal_id']); |
2505 | 2502 | } |
2506 | 2503 | } |
2507 | 2504 | else |
2508 | 2505 | { |
2509 | - $this->db->update($this->cal_table,array('cal_owner' => $new_user),array('cal_owner' => $old_user),__LINE__,__FILE__,'calendar'); |
|
2506 | + $this->db->update($this->cal_table, array('cal_owner' => $new_user), array('cal_owner' => $old_user), __LINE__, __FILE__, 'calendar'); |
|
2510 | 2507 | // delete participation of old user, if new user is already a participant |
2511 | 2508 | $ids = array(); |
2512 | - foreach($this->db->select($this->user_table,'cal_id',array( // MySQL does NOT allow to run this as delete! |
|
2509 | + foreach ($this->db->select($this->user_table, 'cal_id', array( // MySQL does NOT allow to run this as delete! |
|
2513 | 2510 | 'cal_user_type' => 'u', |
2514 | 2511 | 'cal_user_id' => $old_user, |
2515 | 2512 | "cal_id IN (SELECT cal_id FROM $this->user_table other WHERE other.cal_id=cal_id AND other.cal_user_id=".$this->db->quote($new_user)." AND cal_user_type='u')", |
2516 | - ),__LINE__,__FILE__,false,'','calendar') as $row) |
|
2513 | + ), __LINE__, __FILE__, false, '', 'calendar') as $row) |
|
2517 | 2514 | { |
2518 | 2515 | $ids[] = $row['cal_id']; |
2519 | 2516 | } |
2520 | - if ($ids) $this->db->delete($this->user_table,array( |
|
2517 | + if ($ids) $this->db->delete($this->user_table, array( |
|
2521 | 2518 | 'cal_user_type' => 'u', |
2522 | 2519 | 'cal_user_id' => $old_user, |
2523 | 2520 | 'cal_id' => $ids, |
2524 | - ),__LINE__,__FILE__,'calendar'); |
|
2521 | + ), __LINE__, __FILE__, 'calendar'); |
|
2525 | 2522 | // now change participant in the rest to contain new user instead of old user |
2526 | - $this->db->update($this->user_table,array( |
|
2523 | + $this->db->update($this->user_table, array( |
|
2527 | 2524 | 'cal_user_id' => $new_user, |
2528 | - ),array( |
|
2525 | + ), array( |
|
2529 | 2526 | 'cal_user_type' => 'u', |
2530 | 2527 | 'cal_user_id' => $old_user, |
2531 | - ),__LINE__,__FILE__,'calendar'); |
|
2528 | + ), __LINE__, __FILE__, 'calendar'); |
|
2532 | 2529 | } |
2533 | 2530 | } |
2534 | 2531 | |
@@ -2542,18 +2539,18 @@ discard block |
||
2542 | 2539 | * |
2543 | 2540 | * @return array recur_date => status pairs (index 0 => main status) |
2544 | 2541 | */ |
2545 | - function get_recurrences($cal_id, $uid=null, $start=0, $end=0) |
|
2542 | + function get_recurrences($cal_id, $uid = null, $start = 0, $end = 0) |
|
2546 | 2543 | { |
2547 | 2544 | $participant_status = array(); |
2548 | 2545 | $where = array('cal_id' => $cal_id); |
2549 | - if ($start != 0 && $end == 0) $where[] = '(cal_recur_date = 0 OR cal_recur_date >= ' . (int)$start . ')'; |
|
2550 | - if ($start == 0 && $end != 0) $where[] = '(cal_recur_date = 0 OR cal_recur_date <= ' . (int)$end . ')'; |
|
2546 | + if ($start != 0 && $end == 0) $where[] = '(cal_recur_date = 0 OR cal_recur_date >= '.(int)$start.')'; |
|
2547 | + if ($start == 0 && $end != 0) $where[] = '(cal_recur_date = 0 OR cal_recur_date <= '.(int)$end.')'; |
|
2551 | 2548 | if ($start != 0 && $end != 0) |
2552 | 2549 | { |
2553 | - $where[] = '(cal_recur_date = 0 OR (cal_recur_date >= ' . (int)$start . |
|
2554 | - ' AND cal_recur_date <= ' . (int)$end . '))'; |
|
2550 | + $where[] = '(cal_recur_date = 0 OR (cal_recur_date >= '.(int)$start. |
|
2551 | + ' AND cal_recur_date <= '.(int)$end.'))'; |
|
2555 | 2552 | } |
2556 | - foreach($this->db->select($this->user_table,'DISTINCT cal_recur_date',$where,__LINE__,__FILE__,false,'','calendar') as $row) |
|
2553 | + foreach ($this->db->select($this->user_table, 'DISTINCT cal_recur_date', $where, __LINE__, __FILE__, false, '', 'calendar') as $row) |
|
2557 | 2554 | { |
2558 | 2555 | // inititalize the array |
2559 | 2556 | $participant_status[$row['cal_recur_date']] = null; |
@@ -2567,17 +2564,17 @@ discard block |
||
2567 | 2564 | 'cal_user_type' => $user_type ? $user_type : 'u', |
2568 | 2565 | 'cal_user_id' => $user_id, |
2569 | 2566 | ); |
2570 | - if ($start != 0 && $end == 0) $where2[] = '(cal_recur_date = 0 OR cal_recur_date >= ' . (int)$start . ')'; |
|
2571 | - if ($start == 0 && $end != 0) $where2[] = '(cal_recur_date = 0 OR cal_recur_date <= ' . (int)$end . ')'; |
|
2567 | + if ($start != 0 && $end == 0) $where2[] = '(cal_recur_date = 0 OR cal_recur_date >= '.(int)$start.')'; |
|
2568 | + if ($start == 0 && $end != 0) $where2[] = '(cal_recur_date = 0 OR cal_recur_date <= '.(int)$end.')'; |
|
2572 | 2569 | if ($start != 0 && $end != 0) |
2573 | 2570 | { |
2574 | - $where2[] = '(cal_recur_date = 0 OR (cal_recur_date >= ' . (int)$start . |
|
2575 | - ' AND cal_recur_date <= ' . (int)$end . '))'; |
|
2571 | + $where2[] = '(cal_recur_date = 0 OR (cal_recur_date >= '.(int)$start. |
|
2572 | + ' AND cal_recur_date <= '.(int)$end.'))'; |
|
2576 | 2573 | } |
2577 | - foreach ($this->db->select($this->user_table,'cal_recur_date,cal_status,cal_quantity,cal_role',$where2, |
|
2578 | - __LINE__,__FILE__,false,'','calendar') as $row) |
|
2574 | + foreach ($this->db->select($this->user_table, 'cal_recur_date,cal_status,cal_quantity,cal_role', $where2, |
|
2575 | + __LINE__, __FILE__, false, '', 'calendar') as $row) |
|
2579 | 2576 | { |
2580 | - $status = self::combine_status($row['cal_status'],$row['cal_quantity'],$row['cal_role']); |
|
2577 | + $status = self::combine_status($row['cal_status'], $row['cal_quantity'], $row['cal_role']); |
|
2581 | 2578 | $participant_status[$row['cal_recur_date']] = $status; |
2582 | 2579 | } |
2583 | 2580 | return $participant_status; |
@@ -2626,8 +2623,8 @@ discard block |
||
2626 | 2623 | 'cal_uid' => $uid, |
2627 | 2624 | ); |
2628 | 2625 | $related = array(); |
2629 | - foreach ($this->db->select($this->cal_table,'cal_id,cal_reference',$where, |
|
2630 | - __LINE__,__FILE__,false,'','calendar') as $row) |
|
2626 | + foreach ($this->db->select($this->cal_table, 'cal_id,cal_reference', $where, |
|
2627 | + __LINE__, __FILE__, false, '', 'calendar') as $row) |
|
2631 | 2628 | { |
2632 | 2629 | if ($row['cal_reference'] != 0) |
2633 | 2630 | { |
@@ -2656,10 +2653,10 @@ discard block |
||
2656 | 2653 | * |
2657 | 2654 | * @return array Array of exception days (false for non-recurring events). |
2658 | 2655 | */ |
2659 | - function get_recurrence_exceptions($event, $tz_id=null, $start=0, $end=0, $filter='all') |
|
2656 | + function get_recurrence_exceptions($event, $tz_id = null, $start = 0, $end = 0, $filter = 'all') |
|
2660 | 2657 | { |
2661 | 2658 | if (!is_array($event)) return false; |
2662 | - $cal_id = (int) $event['id']; |
|
2659 | + $cal_id = (int)$event['id']; |
|
2663 | 2660 | //error_log(__FILE__.'['.__LINE__.'] '.__METHOD__. |
2664 | 2661 | // "($cal_id, $tz_id, $filter): " . $event['tzid']); |
2665 | 2662 | if (!$cal_id || $event['recur_type'] == MCAL_RECUR_NONE) return false; |
@@ -2683,27 +2680,27 @@ discard block |
||
2683 | 2680 | while ($egw_rrule->valid()) |
2684 | 2681 | { |
2685 | 2682 | while ($egw_rrule->exceptions && |
2686 | - in_array($egw_rrule->current->format('Ymd'),$egw_rrule->exceptions)) |
|
2683 | + in_array($egw_rrule->current->format('Ymd'), $egw_rrule->exceptions)) |
|
2687 | 2684 | { |
2688 | - if (in_array($filter, array('map','tz_map','rrule','tz_rrule'))) |
|
2685 | + if (in_array($filter, array('map', 'tz_map', 'rrule', 'tz_rrule'))) |
|
2689 | 2686 | { |
2690 | 2687 | // real exception |
2691 | - $locts = (int)Api\DateTime::to($egw_rrule->current(),'server'); |
|
2688 | + $locts = (int)Api\DateTime::to($egw_rrule->current(), 'server'); |
|
2692 | 2689 | if ($expand_all) |
2693 | 2690 | { |
2694 | - $remts = (int)Api\DateTime::to($remote_rrule->current(),'server'); |
|
2691 | + $remts = (int)Api\DateTime::to($remote_rrule->current(), 'server'); |
|
2695 | 2692 | if ($remote) |
2696 | 2693 | { |
2697 | - $days[$locts]= $remts; |
|
2694 | + $days[$locts] = $remts; |
|
2698 | 2695 | } |
2699 | 2696 | else |
2700 | 2697 | { |
2701 | - $days[$remts]= $locts; |
|
2698 | + $days[$remts] = $locts; |
|
2702 | 2699 | } |
2703 | 2700 | } |
2704 | 2701 | else |
2705 | 2702 | { |
2706 | - $days[$locts]= $locts; |
|
2703 | + $days[$locts] = $locts; |
|
2707 | 2704 | } |
2708 | 2705 | } |
2709 | 2706 | if ($expand_all) |
@@ -2714,14 +2711,14 @@ discard block |
||
2714 | 2711 | if (!$egw_rrule->valid()) return $days; |
2715 | 2712 | } |
2716 | 2713 | $day = $egw_rrule->current(); |
2717 | - $locts = (int)Api\DateTime::to($day,'server'); |
|
2714 | + $locts = (int)Api\DateTime::to($day, 'server'); |
|
2718 | 2715 | $tz_exception = ($filter == 'tz_rrule'); |
2719 | 2716 | //error_log(__FILE__.'['.__LINE__.'] '.__METHOD__. |
2720 | 2717 | // '()[EVENT Server]: ' . $day->format('Ymd\THis') . " ($locts)"); |
2721 | 2718 | if ($expand_all) |
2722 | 2719 | { |
2723 | 2720 | $remote_day = $remote_rrule->current(); |
2724 | - $remts = (int)Api\DateTime::to($remote_day,'server'); |
|
2721 | + $remts = (int)Api\DateTime::to($remote_day, 'server'); |
|
2725 | 2722 | // error_log(__FILE__.'['.__LINE__.'] '.__METHOD__. |
2726 | 2723 | // '()[EVENT Device]: ' . $remote_day->format('Ymd\THis') . " ($remts)"); |
2727 | 2724 | } |
@@ -2740,11 +2737,11 @@ discard block |
||
2740 | 2737 | // '() tz exception: ' . $day->format('Ymd\THis')); |
2741 | 2738 | if ($remote) |
2742 | 2739 | { |
2743 | - $days[$locts]= $remts; |
|
2740 | + $days[$locts] = $remts; |
|
2744 | 2741 | } |
2745 | 2742 | else |
2746 | 2743 | { |
2747 | - $days[$remts]= $locts; |
|
2744 | + $days[$remts] = $locts; |
|
2748 | 2745 | } |
2749 | 2746 | } |
2750 | 2747 | } |
@@ -2766,18 +2763,18 @@ discard block |
||
2766 | 2763 | { |
2767 | 2764 | if ($remote) |
2768 | 2765 | { |
2769 | - $days[$locts]= $remts; |
|
2766 | + $days[$locts] = $remts; |
|
2770 | 2767 | } |
2771 | 2768 | else |
2772 | 2769 | { |
2773 | - $days[$remts]= $locts; |
|
2770 | + $days[$remts] = $locts; |
|
2774 | 2771 | } |
2775 | 2772 | } |
2776 | 2773 | } |
2777 | 2774 | } |
2778 | 2775 | elseif ($filter != 'map') |
2779 | 2776 | { |
2780 | - $days[$locts]= $locts; |
|
2777 | + $days[$locts] = $locts; |
|
2781 | 2778 | } |
2782 | 2779 | } |
2783 | 2780 | elseif (($filter == 'map' || filter == 'tz_map') && |
@@ -2787,11 +2784,11 @@ discard block |
||
2787 | 2784 | if ($expand_all) |
2788 | 2785 | { |
2789 | 2786 | |
2790 | - $days[$remts]= $locts; |
|
2787 | + $days[$remts] = $locts; |
|
2791 | 2788 | } |
2792 | 2789 | else |
2793 | 2790 | { |
2794 | - $days[$locts]= $locts; |
|
2791 | + $days[$locts] = $locts; |
|
2795 | 2792 | } |
2796 | 2793 | } |
2797 | 2794 | } |
@@ -2815,9 +2812,9 @@ discard block |
||
2815 | 2812 | */ |
2816 | 2813 | function status_pseudo_exception($cal_id, $recur_date, $filter) |
2817 | 2814 | { |
2818 | - static $recurrence_zero=null; |
|
2819 | - static $cached_id=null; |
|
2820 | - static $user=null; |
|
2815 | + static $recurrence_zero = null; |
|
2816 | + static $cached_id = null; |
|
2817 | + static $user = null; |
|
2821 | 2818 | |
2822 | 2819 | if (!isset($cached_id) || $cached_id != $cal_id) |
2823 | 2820 | { |
@@ -2828,8 +2825,8 @@ discard block |
||
2828 | 2825 | 'cal_id' => $cal_id, |
2829 | 2826 | 'cal_recur_date' => 0, |
2830 | 2827 | ); |
2831 | - foreach ($this->db->select($this->user_table,'cal_user_type,cal_user_id,cal_user_attendee,cal_status',$where, |
|
2832 | - __LINE__,__FILE__,false,'','calendar') as $row) |
|
2828 | + foreach ($this->db->select($this->user_table, 'cal_user_type,cal_user_id,cal_user_attendee,cal_status', $where, |
|
2829 | + __LINE__, __FILE__, false, '', 'calendar') as $row) |
|
2833 | 2830 | { |
2834 | 2831 | switch ($row['cal_user_type']) |
2835 | 2832 | { |
@@ -2852,8 +2849,8 @@ discard block |
||
2852 | 2849 | 'cal_id' => $cal_id, |
2853 | 2850 | 'cal_recur_date' => $recur_date, |
2854 | 2851 | ); |
2855 | - foreach ($this->db->select($this->user_table,'cal_user_type,cal_user_id,cal_user_attendee,cal_status',$where, |
|
2856 | - __LINE__,__FILE__,false,'','calendar') as $row) |
|
2852 | + foreach ($this->db->select($this->user_table, 'cal_user_type,cal_user_id,cal_user_attendee,cal_status', $where, |
|
2853 | + __LINE__, __FILE__, false, '', 'calendar') as $row) |
|
2857 | 2854 | { |
2858 | 2855 | switch ($row['cal_user_type']) |
2859 | 2856 | { |
@@ -2878,42 +2875,42 @@ discard block |
||
2878 | 2875 | if ($status != 'U') |
2879 | 2876 | { |
2880 | 2877 | unset($participants[$uid]); |
2881 | - continue 2; // +1 for switch |
|
2878 | + continue 2; // +1 for switch |
|
2882 | 2879 | } |
2883 | 2880 | break; |
2884 | 2881 | case 'accepted': |
2885 | 2882 | if ($status != 'A') |
2886 | 2883 | { |
2887 | 2884 | unset($participants[$uid]); |
2888 | - continue 2; // +1 for switch |
|
2885 | + continue 2; // +1 for switch |
|
2889 | 2886 | } |
2890 | 2887 | break; |
2891 | 2888 | case 'tentative': |
2892 | 2889 | if ($status != 'T') |
2893 | 2890 | { |
2894 | 2891 | unset($participants[$uid]); |
2895 | - continue 2; // +1 for switch |
|
2892 | + continue 2; // +1 for switch |
|
2896 | 2893 | } |
2897 | 2894 | break; |
2898 | 2895 | case 'rejected': |
2899 | 2896 | if ($status != 'R') |
2900 | 2897 | { |
2901 | 2898 | unset($participants[$uid]); |
2902 | - continue 2; // +1 for switch |
|
2899 | + continue 2; // +1 for switch |
|
2903 | 2900 | } |
2904 | 2901 | break; |
2905 | 2902 | case 'delegated': |
2906 | 2903 | if ($status != 'D') |
2907 | 2904 | { |
2908 | 2905 | unset($participants[$uid]); |
2909 | - continue 2; // +1 for switch |
|
2906 | + continue 2; // +1 for switch |
|
2910 | 2907 | } |
2911 | 2908 | break; |
2912 | 2909 | case 'default': |
2913 | 2910 | if ($status == 'R') |
2914 | 2911 | { |
2915 | 2912 | unset($participants[$uid]); |
2916 | - continue 2; // +1 for switch |
|
2913 | + continue 2; // +1 for switch |
|
2917 | 2914 | } |
2918 | 2915 | break; |
2919 | 2916 | default: |
@@ -2950,14 +2947,14 @@ discard block |
||
2950 | 2947 | } |
2951 | 2948 | $timezone = self::$tz_cache[$event['tzid']]; |
2952 | 2949 | } |
2953 | - $start_time = new Api\DateTime($event['start'],Api\DateTime::$server_timezone); |
|
2950 | + $start_time = new Api\DateTime($event['start'], Api\DateTime::$server_timezone); |
|
2954 | 2951 | $start_time->setTimezone($timezone); |
2955 | - $end_time = new Api\DateTime($event['end'],Api\DateTime::$server_timezone); |
|
2952 | + $end_time = new Api\DateTime($event['end'], Api\DateTime::$server_timezone); |
|
2956 | 2953 | $end_time->setTimezone($timezone); |
2957 | 2954 | //error_log(__FILE__.'['.__LINE__.'] '.__METHOD__. |
2958 | 2955 | // '(): ' . $start . '-' . $end); |
2959 | - $start = Api\DateTime::to($start_time,'array'); |
|
2960 | - $end = Api\DateTime::to($end_time,'array'); |
|
2956 | + $start = Api\DateTime::to($start_time, 'array'); |
|
2957 | + $end = Api\DateTime::to($end_time, 'array'); |
|
2961 | 2958 | |
2962 | 2959 | |
2963 | 2960 | return !$start['hour'] && !$start['minute'] && $end['hour'] == 23 && $end['minute'] == 59; |
@@ -2971,7 +2968,7 @@ discard block |
||
2971 | 2968 | * |
2972 | 2969 | * @return DateTime |
2973 | 2970 | */ |
2974 | - function &startOfDay(Api\DateTime $time, $tz_id=null) |
|
2971 | + function &startOfDay(Api\DateTime $time, $tz_id = null) |
|
2975 | 2972 | { |
2976 | 2973 | if (empty($tz_id)) |
2977 | 2974 | { |
@@ -2996,14 +2993,14 @@ discard block |
||
2996 | 2993 | * @param int $time =null new timestamp, default current (server-)time |
2997 | 2994 | * @param int $modifier =null uid of the modifier, default current user |
2998 | 2995 | */ |
2999 | - function updateModified($id, $update_master=false, $time=null, $modifier=null) |
|
2996 | + function updateModified($id, $update_master = false, $time = null, $modifier = null) |
|
3000 | 2997 | { |
3001 | 2998 | if (is_null($time) || !$time) $time = time(); |
3002 | 2999 | if (is_null($modifier)) $modifier = $GLOBALS['egw_info']['user']['account_id']; |
3003 | 3000 | |
3004 | 3001 | $this->db->update($this->cal_table, |
3005 | 3002 | array('cal_modified' => $time, 'cal_modifier' => $modifier), |
3006 | - array('cal_id' => $id), __LINE__,__FILE__, 'calendar'); |
|
3003 | + array('cal_id' => $id), __LINE__, __FILE__, 'calendar'); |
|
3007 | 3004 | |
3008 | 3005 | // if event is an exception: update modified of master, to force etag, ctag and sync-token change |
3009 | 3006 | if ($update_master) |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | * @param array $grants =array() |
77 | 77 | * @return soinfolog |
78 | 78 | */ |
79 | - function __construct( $grants=array() ) |
|
79 | + function __construct($grants = array()) |
|
80 | 80 | { |
81 | 81 | $this->db = clone($GLOBALS['egw']->db); |
82 | 82 | $this->db->set_app('infolog'); |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | * @param int $user =null user to check for, default $this->user |
94 | 94 | * @return boolean |
95 | 95 | */ |
96 | - function is_responsible($info,$user=null) |
|
96 | + function is_responsible($info, $user = null) |
|
97 | 97 | { |
98 | 98 | if (!$user) $user = $this->user; |
99 | 99 | |
@@ -111,13 +111,13 @@ discard block |
||
111 | 111 | { |
112 | 112 | |
113 | 113 | static $um_cache = array(); |
114 | - $user_and_memberships =& $um_cache[$user]; |
|
114 | + $user_and_memberships = & $um_cache[$user]; |
|
115 | 115 | if (!isset($user_and_memberships)) |
116 | 116 | { |
117 | - $user_and_memberships = $GLOBALS['egw']->accounts->memberships($user,true); |
|
117 | + $user_and_memberships = $GLOBALS['egw']->accounts->memberships($user, true); |
|
118 | 118 | $user_and_memberships[] = $user; |
119 | 119 | } |
120 | - return $info['info_responsible'] && array_intersect((array)$info['info_responsible'],$user_and_memberships); |
|
120 | + return $info['info_responsible'] && array_intersect((array)$info['info_responsible'], $user_and_memberships); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | * @param int $user =null user to check, default (null) $this->user |
131 | 131 | * @return boolean True if access is granted else False |
132 | 132 | */ |
133 | - function check_access( $info,$required_rights,$implicit_edit=false,array $grants=null,$user=null ) |
|
133 | + function check_access($info, $required_rights, $implicit_edit = false, array $grants = null, $user = null) |
|
134 | 134 | { |
135 | 135 | if (is_null($grants)) $grants = $this->grants; |
136 | 136 | if (!$user) $user = $this->user; |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | { |
143 | 143 | |
144 | 144 | } |
145 | - elseif ((int) $info != $this->data['info_id']) // already loaded? |
|
145 | + elseif ((int)$info != $this->data['info_id']) // already loaded? |
|
146 | 146 | { |
147 | 147 | // dont change our own internal data, |
148 | 148 | $backup_data = $this->data; |
@@ -158,12 +158,12 @@ discard block |
||
158 | 158 | return False; |
159 | 159 | } |
160 | 160 | $owner = $info['info_owner']; |
161 | - $access_ok = $owner == $user || // user has all rights |
|
161 | + $access_ok = $owner == $user || // user has all rights |
|
162 | 162 | // ACL only on public entrys || $owner granted _PRIVATE |
163 | - (!!($grants[$owner] & $required_rights) || |
|
164 | - $this->is_responsible($info,$user) && // implicite rights for responsible user(s) and his memberships |
|
163 | + (!!($grants[$owner]&$required_rights) || |
|
164 | + $this->is_responsible($info, $user) && // implicite rights for responsible user(s) and his memberships |
|
165 | 165 | ($required_rights == Acl::READ || $required_rights == Acl::ADD || $implicit_edit && $required_rights == Acl::EDIT)) && |
166 | - ($info['info_access'] == 'public' || !!($this->grants[$user] & Acl::PRIVAT)); |
|
166 | + ($info['info_access'] == 'public' || !!($this->grants[$user]&Acl::PRIVAT)); |
|
167 | 167 | |
168 | 168 | // error_log(__METHOD__."($info[info_id],$required_rights,$implicit_edit,".array2string($grants).",$user) returning ".array2string($access_ok)); |
169 | 169 | return $access_ok; |
@@ -176,16 +176,15 @@ discard block |
||
176 | 176 | * @param boolean $deleted_too =false true: also use deleted entries |
177 | 177 | * @return string |
178 | 178 | */ |
179 | - function responsible_filter($users, $deleted_too=false) |
|
179 | + function responsible_filter($users, $deleted_too = false) |
|
180 | 180 | { |
181 | 181 | if (!$users) return '0'; |
182 | 182 | |
183 | 183 | $responsible = array(); |
184 | - foreach((array)$users as $user) |
|
184 | + foreach ((array)$users as $user) |
|
185 | 185 | { |
186 | - $responsible = array_merge($responsible,(array) |
|
187 | - ($user > 0 ? $GLOBALS['egw']->accounts->memberships($user,true) : |
|
188 | - $GLOBALS['egw']->accounts->members($user,true))); |
|
186 | + $responsible = array_merge($responsible, (array) |
|
187 | + ($user > 0 ? $GLOBALS['egw']->accounts->memberships($user, true) : $GLOBALS['egw']->accounts->members($user, true))); |
|
189 | 188 | $responsible[] = $user; |
190 | 189 | } |
191 | 190 | if (is_array($users)) |
@@ -214,18 +213,18 @@ discard block |
||
214 | 213 | function aclFilter($_filter = False) |
215 | 214 | { |
216 | 215 | $vars = null; |
217 | - preg_match('/(my|responsible|delegated|own|privat|private|all|user)([0-9,-]*)(\+deleted)?/',$_filter,$vars); |
|
216 | + preg_match('/(my|responsible|delegated|own|privat|private|all|user)([0-9,-]*)(\+deleted)?/', $_filter, $vars); |
|
218 | 217 | $filter = $vars[1]; |
219 | 218 | $f_user = $vars[2]; |
220 | 219 | $deleted_too = !empty($vars[3]); |
221 | 220 | |
222 | 221 | if (isset($this->acl_filter[$filter.$f_user])) |
223 | 222 | { |
224 | - return $this->acl_filter[$filter.$f_user]; // used cached filter if found |
|
223 | + return $this->acl_filter[$filter.$f_user]; // used cached filter if found |
|
225 | 224 | } |
226 | - if ($f_user && strpos($f_user,',') !== false) |
|
225 | + if ($f_user && strpos($f_user, ',') !== false) |
|
227 | 226 | { |
228 | - $f_user = explode(',',$f_user); |
|
227 | + $f_user = explode(',', $f_user); |
|
229 | 228 | } |
230 | 229 | |
231 | 230 | $filtermethod = " (info_owner=$this->user"; // user has all rights |
@@ -242,24 +241,24 @@ discard block |
||
242 | 241 | { |
243 | 242 | if (is_array($this->grants)) |
244 | 243 | { |
245 | - foreach($this->grants as $user => $grant) |
|
244 | + foreach ($this->grants as $user => $grant) |
|
246 | 245 | { |
247 | 246 | // echo "<p>grants: user=$user, grant=$grant</p>"; |
248 | - if ($grant & (EGW_ACL_READ|EGW_ACL_EDIT)) |
|
247 | + if ($grant&(EGW_ACL_READ|EGW_ACL_EDIT)) |
|
249 | 248 | { |
250 | 249 | $public_user_list[] = $user; |
251 | 250 | } |
252 | - if ($grant & Acl::PRIVAT) |
|
251 | + if ($grant&Acl::PRIVAT) |
|
253 | 252 | { |
254 | 253 | $private_user_list[] = $user; |
255 | 254 | } |
256 | 255 | } |
257 | 256 | if (count($private_user_list)) |
258 | 257 | { |
259 | - $has_private_access = $this->db->expression($this->info_table,array('info_owner' => $private_user_list)); |
|
258 | + $has_private_access = $this->db->expression($this->info_table, array('info_owner' => $private_user_list)); |
|
260 | 259 | } |
261 | 260 | } |
262 | - $public_access = $this->db->expression($this->info_table,array('info_owner' => $public_user_list)); |
|
261 | + $public_access = $this->db->expression($this->info_table, array('info_owner' => $public_user_list)); |
|
263 | 262 | // implicit read-rights for responsible user |
264 | 263 | $filtermethod .= " OR (".$this->responsible_filter($this->user, $deleted_too).')'; |
265 | 264 | |
@@ -267,9 +266,9 @@ discard block |
||
267 | 266 | if ($filter == 'private' || $filter == 'privat' || $filter == 'own') |
268 | 267 | { |
269 | 268 | $filtermethod .= " OR (".$this->responsible_filter($this->user, $deleted_too). |
270 | - ($filter == 'own' && count($public_user_list) ? // offer's should show up in own, eg. startpage, but need read-access |
|
269 | + ($filter == 'own' && count($public_user_list) ? // offer's should show up in own, eg. startpage, but need read-access |
|
271 | 270 | " OR info_status = 'offer' AND $public_access" : '').")". |
272 | - " AND (info_access='public'".($has_private_access?" OR $has_private_access":'').')'; |
|
271 | + " AND (info_access='public'".($has_private_access ? " OR $has_private_access" : '').')'; |
|
273 | 272 | } |
274 | 273 | elseif ($filter != 'my' && $filter != 'responsible') // none --> all entrys user has rights to see |
275 | 274 | { |
@@ -286,13 +285,13 @@ discard block |
||
286 | 285 | |
287 | 286 | if ($filter == 'user' && $f_user) |
288 | 287 | { |
289 | - $filtermethod .= $this->db->expression($this->info_table,' AND (',array( |
|
288 | + $filtermethod .= $this->db->expression($this->info_table, ' AND (', array( |
|
290 | 289 | 'info_owner' => $f_user, |
291 | - )," AND $this->users_table.account_id IS NULL OR ",$this->responsible_filter($f_user, $deleted_too),')'); |
|
290 | + ), " AND $this->users_table.account_id IS NULL OR ", $this->responsible_filter($f_user, $deleted_too), ')'); |
|
292 | 291 | } |
293 | 292 | } |
294 | 293 | //echo "<p>aclFilter(filter='$_filter',user='$f_user') = '$filtermethod', privat_user_list=".print_r($privat_user_list,True).", public_user_list=".print_r($public_user_list,True)."</p>\n"; |
295 | - return $this->acl_filter[$filter.$f_user] = $filtermethod; // cache the filter |
|
294 | + return $this->acl_filter[$filter.$f_user] = $filtermethod; // cache the filter |
|
296 | 295 | } |
297 | 296 | |
298 | 297 | /** |
@@ -302,18 +301,18 @@ discard block |
||
302 | 301 | * @param boolean $prefix_and =true if true prefix the fileter with ' AND ' |
303 | 302 | * @return string the necesary sql |
304 | 303 | */ |
305 | - function statusFilter($_filter = '',$prefix_and=true) |
|
304 | + function statusFilter($_filter = '', $prefix_and = true) |
|
306 | 305 | { |
307 | 306 | $vars = null; |
308 | - preg_match('/(done|open|offer|deleted|\+deleted)/',$_filter,$vars); |
|
307 | + preg_match('/(done|open|offer|deleted|\+deleted)/', $_filter, $vars); |
|
309 | 308 | $filter = $vars[1]; |
310 | 309 | |
311 | 310 | switch ($filter) |
312 | 311 | { |
313 | 312 | case 'done': $filter = "info_status IN ('done','billed','cancelled')"; break; |
314 | 313 | case 'open': $filter = "NOT (info_status IN ('done','billed','cancelled','deleted','template','nonactive','archive'))"; break; |
315 | - case 'offer': $filter = "info_status = 'offer'"; break; |
|
316 | - case 'deleted': $filter = "info_status = 'deleted'"; break; |
|
314 | + case 'offer': $filter = "info_status = 'offer'"; break; |
|
315 | + case 'deleted': $filter = "info_status = 'deleted'"; break; |
|
317 | 316 | case '+deleted':$filter = "NOT (info_status IN ('template','nonactive','archive'))"; break; |
318 | 317 | default: $filter = "NOT (info_status IN ('deleted','template','nonactive','archive'))"; break; |
319 | 318 | } |
@@ -334,18 +333,18 @@ discard block |
||
334 | 333 | function dateFilter($_filter = '') |
335 | 334 | { |
336 | 335 | $vars = null; |
337 | - preg_match('/(open-upcoming|upcoming|today|overdue|date|enddate)([-\\/.0-9]*)/',$_filter,$vars); |
|
336 | + preg_match('/(open-upcoming|upcoming|today|overdue|date|enddate)([-\\/.0-9]*)/', $_filter, $vars); |
|
338 | 337 | $filter = $vars[1]; |
339 | 338 | |
340 | - if (isset($vars[2]) && !empty($vars[2]) && ($date = preg_split('/[-\\/.]/',$vars[2]))) |
|
339 | + if (isset($vars[2]) && !empty($vars[2]) && ($date = preg_split('/[-\\/.]/', $vars[2]))) |
|
341 | 340 | { |
342 | - $today = mktime(-$this->tz_offset,0,0,intval($date[1]),intval($date[2]),intval($date[0])); |
|
343 | - $tomorrow = mktime(-$this->tz_offset,0,0,intval($date[1]),intval($date[2])+1,intval($date[0])); |
|
341 | + $today = mktime(-$this->tz_offset, 0, 0, intval($date[1]), intval($date[2]), intval($date[0])); |
|
342 | + $tomorrow = mktime(-$this->tz_offset, 0, 0, intval($date[1]), intval($date[2]) + 1, intval($date[0])); |
|
344 | 343 | } |
345 | 344 | else |
346 | 345 | { |
347 | - $now = getdate(time()-60*60*$this->tz_offset); |
|
348 | - $tomorrow = mktime(-$this->tz_offset,0,0,$now['mon'],$now['mday']+1,$now['year']); |
|
346 | + $now = getdate(time() - 60 * 60 * $this->tz_offset); |
|
347 | + $tomorrow = mktime(-$this->tz_offset, 0, 0, $now['mon'], $now['mday'] + 1, $now['year']); |
|
349 | 348 | } |
350 | 349 | switch ($filter) |
351 | 350 | { |
@@ -432,12 +431,12 @@ discard block |
||
432 | 431 | $this->data['info_uid'] = Api\CalDAV::generate_uid('infolog', $this->data['info_id']); |
433 | 432 | $this->db->update($this->info_table, |
434 | 433 | array('info_uid' => $this->data['info_uid']), |
435 | - array('info_id' => $this->data['info_id']), __LINE__,__FILE__); |
|
434 | + array('info_id' => $this->data['info_id']), __LINE__, __FILE__); |
|
436 | 435 | } |
437 | 436 | if (!is_array($this->data['info_responsible'])) |
438 | 437 | { |
439 | - $this->data['info_responsible'] = $this->data['info_responsible'] ? explode(',',$this->data['info_responsible']) : array(); |
|
440 | - foreach($this->data['info_responsible'] as $k => $v) |
|
438 | + $this->data['info_responsible'] = $this->data['info_responsible'] ? explode(',', $this->data['info_responsible']) : array(); |
|
439 | + foreach ($this->data['info_responsible'] as $k => $v) |
|
441 | 440 | { |
442 | 441 | if (!is_numeric($v)) unset($this->data['info_responsible'][$k]); |
443 | 442 | } |
@@ -445,7 +444,7 @@ discard block |
||
445 | 444 | } |
446 | 445 | // Cast back to integer |
447 | 446 | $this->data['info_id_parent'] = (int)$this->data['info_id_parent']; |
448 | - foreach($this->db->select($this->extra_table,'info_extra_name,info_extra_value',array('info_id'=>$this->data['info_id']),__LINE__,__FILE__) as $row) |
|
447 | + foreach ($this->db->select($this->extra_table, 'info_extra_name,info_extra_value', array('info_id'=>$this->data['info_id']), __LINE__, __FILE__) as $row) |
|
449 | 448 | { |
450 | 449 | $this->data['#'.$row['info_extra_name']] = $row['info_extra_value']; |
451 | 450 | } |
@@ -460,17 +459,17 @@ discard block |
||
460 | 459 | * @param boolean $delete_children delete the children, if not set there parent-id to $new_parent |
461 | 460 | * @param int $new_parent new parent-id to set for subs |
462 | 461 | */ |
463 | - function delete($info_id,$delete_children=True,$new_parent=0) // did _not_ ensure ACL |
|
462 | + function delete($info_id, $delete_children = True, $new_parent = 0) // did _not_ ensure ACL |
|
464 | 463 | { |
465 | 464 | //echo "<p>soinfolog::delete($info_id,'$delete_children',$new_parent)</p>\n"; |
466 | - if ((int) $info_id <= 0) |
|
465 | + if ((int)$info_id <= 0) |
|
467 | 466 | { |
468 | 467 | return; |
469 | 468 | } |
470 | - $this->db->delete($this->info_table,array('info_id'=>$info_id),__LINE__,__FILE__); |
|
471 | - $this->db->delete($this->extra_table,array('info_id'=>$info_id),__LINE__,__FILE__); |
|
472 | - $this->db->delete($this->users_table,array('info_id'=>$info_id),__LINE__,__FILE__); |
|
473 | - Link::unlink(0,'infolog',$info_id); |
|
469 | + $this->db->delete($this->info_table, array('info_id'=>$info_id), __LINE__, __FILE__); |
|
470 | + $this->db->delete($this->extra_table, array('info_id'=>$info_id), __LINE__, __FILE__); |
|
471 | + $this->db->delete($this->users_table, array('info_id'=>$info_id), __LINE__, __FILE__); |
|
472 | + Link::unlink(0, 'infolog', $info_id); |
|
474 | 473 | |
475 | 474 | if ($this->data['info_id'] == $info_id) |
476 | 475 | { |
@@ -479,17 +478,17 @@ discard block |
||
479 | 478 | // delete children, if they are owned by the user |
480 | 479 | if ($delete_children) |
481 | 480 | { |
482 | - $db2 = clone($this->db); // we need an extra result-set |
|
483 | - foreach($db2->select($this->info_table,'info_id',array( |
|
481 | + $db2 = clone($this->db); // we need an extra result-set |
|
482 | + foreach ($db2->select($this->info_table, 'info_id', array( |
|
484 | 483 | 'info_id_parent' => $info_id, |
485 | 484 | 'info_owner' => $this->user, |
486 | - ),__LINE__,__FILE__) as $row) |
|
485 | + ), __LINE__, __FILE__) as $row) |
|
487 | 486 | { |
488 | 487 | $this->delete($row['info_id'], $delete_children); |
489 | 488 | } |
490 | 489 | } |
491 | 490 | // set parent_id to $new_parent or 0 for all not deleted children |
492 | - $this->db->update($this->info_table,array('info_id_parent'=>$new_parent),array('info_id_parent'=>$info_id),__LINE__,__FILE__); |
|
491 | + $this->db->update($this->info_table, array('info_id_parent'=>$new_parent), array('info_id_parent'=>$info_id), __LINE__, __FILE__); |
|
493 | 492 | } |
494 | 493 | |
495 | 494 | /** |
@@ -501,9 +500,9 @@ discard block |
||
501 | 500 | function get_children($info_id) |
502 | 501 | { |
503 | 502 | $children = array(); |
504 | - foreach($this->db->select($this->info_table, 'info_id,info_owner', array( |
|
503 | + foreach ($this->db->select($this->info_table, 'info_id,info_owner', array( |
|
505 | 504 | 'info_id_parent' => $info_id, |
506 | - ),__LINE__,__FILE__) as $row) |
|
505 | + ), __LINE__, __FILE__) as $row) |
|
507 | 506 | { |
508 | 507 | $children[$row['info_id']] = $row['info_owner']; |
509 | 508 | } |
@@ -520,16 +519,16 @@ discard block |
||
520 | 519 | */ |
521 | 520 | function change_delete_owner(array $args) // new_owner=0 means delete |
522 | 521 | { |
523 | - if (!(int) $args['new_owner']) |
|
522 | + if (!(int)$args['new_owner']) |
|
524 | 523 | { |
525 | - foreach($this->db->select($this->info_table,'info_id',array('info_owner'=>$args['account_id']),__LINE__,__FILE__,false,'','infolog') as $row) |
|
524 | + foreach ($this->db->select($this->info_table, 'info_id', array('info_owner'=>$args['account_id']), __LINE__, __FILE__, false, '', 'infolog') as $row) |
|
526 | 525 | { |
527 | - $this->delete($row['info_id'],False); |
|
526 | + $this->delete($row['info_id'], False); |
|
528 | 527 | } |
529 | 528 | } |
530 | 529 | else |
531 | 530 | { |
532 | - $this->db->update($this->info_table,array('info_owner'=>$args['new_owner']),array('info_owner'=>$args['account_id']),__LINE__,__FILE__,'infolog'); |
|
531 | + $this->db->update($this->info_table, array('info_owner'=>$args['new_owner']), array('info_owner'=>$args['account_id']), __LINE__, __FILE__, 'infolog'); |
|
533 | 532 | } |
534 | 533 | |
535 | 534 | if ($args['new_owner']) |
@@ -555,7 +554,7 @@ discard block |
||
555 | 554 | * @param boolean $force_insert =false force using insert, even if an id is given eg. for import |
556 | 555 | * @return int|boolean info_id, false on error or 0 if the entry has been updated in the meantime |
557 | 556 | */ |
558 | - function write($values, $check_modified=0, $purge_cfs=null, $force_insert=false) // did _not_ ensure ACL |
|
557 | + function write($values, $check_modified = 0, $purge_cfs = null, $force_insert = false) // did _not_ ensure ACL |
|
559 | 558 | { |
560 | 559 | if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'])) |
561 | 560 | { |
@@ -567,15 +566,15 @@ discard block |
||
567 | 566 | } |
568 | 567 | |
569 | 568 | //echo "soinfolog::write(,$check_modified) values="; _debug_array($values); |
570 | - $info_id = (int) $values['info_id']; |
|
569 | + $info_id = (int)$values['info_id']; |
|
571 | 570 | |
572 | - $table_def = $this->db->get_table_definitions('infolog',$this->info_table); |
|
571 | + $table_def = $this->db->get_table_definitions('infolog', $this->info_table); |
|
573 | 572 | $to_write = array(); |
574 | - foreach($values as $key => $val) |
|
573 | + foreach ($values as $key => $val) |
|
575 | 574 | { |
576 | 575 | if (($key != 'info_id' || $force_insert && $info_id > 0) && isset($table_def['fd'][$key])) |
577 | 576 | { |
578 | - $to_write[$key] = $this->data[$key] = $val; // update internal data |
|
577 | + $to_write[$key] = $this->data[$key] = $val; // update internal data |
|
579 | 578 | } |
580 | 579 | } |
581 | 580 | // writing no price as SQL NULL (required by postgres) |
@@ -585,23 +584,23 @@ discard block |
||
585 | 584 | { |
586 | 585 | $where = array('info_id' => $info_id); |
587 | 586 | if ($check_modified) $where['info_datemodified'] = $check_modified; |
588 | - if (!$this->db->update($this->info_table,$to_write,$where,__LINE__,__FILE__)) |
|
587 | + if (!$this->db->update($this->info_table, $to_write, $where, __LINE__, __FILE__)) |
|
589 | 588 | { |
590 | 589 | //error_log("### soinfolog::write(".print_r($to_write,true).") where=".print_r($where,true)." returning false"); |
591 | - return false; // Error |
|
590 | + return false; // Error |
|
592 | 591 | } |
593 | 592 | if ($check_modified && $this->db->affected_rows() < 1) |
594 | 593 | { |
595 | 594 | //error_log("### soinfolog::write(".print_r($to_write,true).") where=".print_r($where,true)." returning 0 (nothing updated, eg. condition not met)"); |
596 | - return 0; // someone else updated the modtime or deleted the entry |
|
595 | + return 0; // someone else updated the modtime or deleted the entry |
|
597 | 596 | } |
598 | 597 | } |
599 | 598 | else |
600 | 599 | { |
601 | - if (!isset($to_write['info_id_parent'])) $to_write['info_id_parent'] = 0; // must not be null |
|
600 | + if (!isset($to_write['info_id_parent'])) $to_write['info_id_parent'] = 0; // must not be null |
|
602 | 601 | |
603 | - $this->db->insert($this->info_table,$to_write,false,__LINE__,__FILE__); |
|
604 | - $info_id = $this->data['info_id'] = $this->db->get_last_insert_id($this->info_table,'info_id'); |
|
602 | + $this->db->insert($this->info_table, $to_write, false, __LINE__, __FILE__); |
|
603 | + $info_id = $this->data['info_id'] = $this->db->get_last_insert_id($this->info_table, 'info_id'); |
|
605 | 604 | } |
606 | 605 | |
607 | 606 | $update = array(); |
@@ -617,8 +616,8 @@ discard block |
||
617 | 616 | } |
618 | 617 | if ($update) |
619 | 618 | { |
620 | - $this->db->update($this->info_table,$update, |
|
621 | - array('info_id' => $info_id), __LINE__,__FILE__); |
|
619 | + $this->db->update($this->info_table, $update, |
|
620 | + array('info_id' => $info_id), __LINE__, __FILE__); |
|
622 | 621 | } |
623 | 622 | |
624 | 623 | //echo "<p>soinfolog.write values= "; _debug_array($values); |
@@ -628,42 +627,42 @@ discard block |
||
628 | 627 | { |
629 | 628 | $where = array('info_id' => $info_id); |
630 | 629 | if ($purge_cfs == 'ical') $where[] = "info_extra_name LIKE '#%'"; |
631 | - $this->db->delete($this->extra_table,$where,__LINE__,__FILE__); |
|
630 | + $this->db->delete($this->extra_table, $where, __LINE__, __FILE__); |
|
632 | 631 | } |
633 | 632 | $to_delete = array(); |
634 | 633 | |
635 | 634 | // Deal with files in new entries |
636 | - Api\Storage\Customfields::handle_files('infolog',$info_id,$values); |
|
635 | + Api\Storage\Customfields::handle_files('infolog', $info_id, $values); |
|
637 | 636 | |
638 | - foreach($values as $key => $val) |
|
637 | + foreach ($values as $key => $val) |
|
639 | 638 | { |
640 | 639 | if ($key[0] != '#') |
641 | 640 | { |
642 | - continue; // no customfield |
|
641 | + continue; // no customfield |
|
643 | 642 | } |
644 | - $this->data[$key] = $val; // update internal data |
|
643 | + $this->data[$key] = $val; // update internal data |
|
645 | 644 | |
646 | 645 | if ($val) |
647 | 646 | { |
648 | - $this->db->insert($this->extra_table,array( |
|
647 | + $this->db->insert($this->extra_table, array( |
|
649 | 648 | // store multivalued CalDAV properties as serialized array, everything else get comma-separated |
650 | - 'info_extra_value' => is_array($val) ? ($key[1] == '#' ? serialize($val) : implode(',',$val)) : $val, |
|
651 | - ),array( |
|
649 | + 'info_extra_value' => is_array($val) ? ($key[1] == '#' ? serialize($val) : implode(',', $val)) : $val, |
|
650 | + ), array( |
|
652 | 651 | 'info_id' => $info_id, |
653 | - 'info_extra_name' => substr($key,1), |
|
654 | - ),__LINE__,__FILE__); |
|
652 | + 'info_extra_name' => substr($key, 1), |
|
653 | + ), __LINE__, __FILE__); |
|
655 | 654 | } |
656 | 655 | else |
657 | 656 | { |
658 | - $to_delete[] = substr($key,1); |
|
657 | + $to_delete[] = substr($key, 1); |
|
659 | 658 | } |
660 | 659 | } |
661 | 660 | if ($to_delete && !$purge_cfs) |
662 | 661 | { |
663 | - $this->db->delete($this->extra_table,array( |
|
662 | + $this->db->delete($this->extra_table, array( |
|
664 | 663 | 'info_id' => $info_id, |
665 | 664 | 'info_extra_name' => $to_delete, |
666 | - ),__LINE__,__FILE__); |
|
665 | + ), __LINE__, __FILE__); |
|
667 | 666 | } |
668 | 667 | // echo "<p>soinfolog.write this->data= "; _debug_array($this->data); |
669 | 668 | //error_log("### soinfolog::write(".print_r($to_write,true).") where=".print_r($where,true)." returning id=".$this->data['info_id']); |
@@ -671,10 +670,9 @@ discard block |
||
671 | 670 | // update attendees/delegates |
672 | 671 | if (array_key_exists('info_responsible', $values) || array_key_exists('info_cc', $values)) |
673 | 672 | { |
674 | - $users = empty($values['info_responsible']) ? array() : |
|
675 | - array_combine($values['info_responsible'], array_fill(0, count($values['info_responsible']), null)); |
|
673 | + $users = empty($values['info_responsible']) ? array() : array_combine($values['info_responsible'], array_fill(0, count($values['info_responsible']), null)); |
|
676 | 674 | |
677 | - foreach(!empty($values['info_cc']) ? explode(',', $values['info_cc']) : array() as $email) |
|
675 | + foreach (!empty($values['info_cc']) ? explode(',', $values['info_cc']) : array() as $email) |
|
678 | 676 | { |
679 | 677 | $email = trim($email); |
680 | 678 | $matches = null; |
@@ -696,22 +694,21 @@ discard block |
||
696 | 694 | ), array( |
697 | 695 | 'info_id' => $this->data['info_id'], |
698 | 696 | 'info_res_deleted IS NULL', |
699 | - )+(!$values['info_responsible'] ? array() : |
|
700 | - array(1=>'account_id NOT IN ('.implode(',', array_map(array($this->db, 'quote'), array_keys($users))).')')), |
|
697 | + ) + (!$values['info_responsible'] ? array() : array(1=>'account_id NOT IN ('.implode(',', array_map(array($this->db, 'quote'), array_keys($users))).')')), |
|
701 | 698 | __LINE__, __FILE__, 'infolog'); |
702 | 699 | |
703 | 700 | // add newly added attendees |
704 | 701 | if ($users) |
705 | 702 | { |
706 | 703 | $old_users = array(); |
707 | - foreach($this->db->select($this->users_table,'account_id,info_res_attendee',array( |
|
704 | + foreach ($this->db->select($this->users_table, 'account_id,info_res_attendee', array( |
|
708 | 705 | 'info_id' => $this->data['info_id'], |
709 | 706 | 'info_res_deleted IS NULL', |
710 | 707 | ), __LINE__, __FILE__, false, '', 'infolog') as $row) |
711 | 708 | { |
712 | 709 | $old_users[] = $row['account_id']; |
713 | 710 | } |
714 | - foreach(array_diff(array_keys($users), $old_users) as $account_id) |
|
711 | + foreach (array_diff(array_keys($users), $old_users) as $account_id) |
|
715 | 712 | { |
716 | 713 | $this->db->insert($this->users_table, array( |
717 | 714 | 'info_res_modifier' => $this->user, |
@@ -737,18 +734,18 @@ discard block |
||
737 | 734 | * @param int|array $info_id id(s) of log-entry |
738 | 735 | * @return int|array the number of sub-entries or indexed by info_id, if array as param given |
739 | 736 | */ |
740 | - function anzSubs( $info_id ) |
|
737 | + function anzSubs($info_id) |
|
741 | 738 | { |
742 | 739 | if (!is_array($info_id) || !$info_id) |
743 | 740 | { |
744 | 741 | if ((int)$info_id <= 0) return 0; |
745 | 742 | } |
746 | 743 | $counts = array(); |
747 | - foreach($this->db->select($this->info_table,'info_id_parent,COUNT(*) AS info_anz_subs',array( |
|
744 | + foreach ($this->db->select($this->info_table, 'info_id_parent,COUNT(*) AS info_anz_subs', array( |
|
748 | 745 | 'info_id_parent' => $info_id, |
749 | - "info_status != 'deleted'", // dont count deleted subs as subs, as they are not shown by default |
|
750 | - ),__LINE__,__FILE__, |
|
751 | - false,'GROUP BY info_id_parent','infolog') as $row) |
|
746 | + "info_status != 'deleted'", // dont count deleted subs as subs, as they are not shown by default |
|
747 | + ), __LINE__, __FILE__, |
|
748 | + false, 'GROUP BY info_id_parent', 'infolog') as $row) |
|
752 | 749 | { |
753 | 750 | $counts[$row['info_id_parent']] = (int)$row['info_anz_subs']; |
754 | 751 | } |
@@ -775,7 +772,7 @@ discard block |
||
775 | 772 | * @param boolean $no_acl =false true: ignore all acl |
776 | 773 | * @return array|iterator with id's as key of the matching log-entries or recordset/iterator if cols is set |
777 | 774 | */ |
778 | - function search(&$query, $no_acl=false) |
|
775 | + function search(&$query, $no_acl = false) |
|
779 | 776 | { |
780 | 777 | //error_log(__METHOD__.'('.array2string($query).')'); |
781 | 778 | $action2app = array( |
@@ -789,102 +786,102 @@ discard block |
||
789 | 786 | $action = isset($action2app[$query['action']]) ? $action2app[$query['action']] : $query['action']; |
790 | 787 | if ($action) |
791 | 788 | { |
792 | - $links = Link\Storage::get_links($action=='sp'?'infolog':$action, |
|
793 | - is_array($query['action_id']) ? $query['action_id'] : explode(',',$query['action_id']),'infolog','',$query['col_filter']['info_status'] =='deleted'); |
|
789 | + $links = Link\Storage::get_links($action == 'sp' ? 'infolog' : $action, |
|
790 | + is_array($query['action_id']) ? $query['action_id'] : explode(',', $query['action_id']), 'infolog', '', $query['col_filter']['info_status'] == 'deleted'); |
|
794 | 791 | |
795 | 792 | if (count($links)) |
796 | 793 | { |
797 | - $links = call_user_func_array('array_merge',$links); // flatten the array |
|
798 | - $link_extra = ($action == 'sp' ? 'OR' : 'AND')." main.info_id IN (".implode(',',$links).')'; |
|
794 | + $links = call_user_func_array('array_merge', $links); // flatten the array |
|
795 | + $link_extra = ($action == 'sp' ? 'OR' : 'AND')." main.info_id IN (".implode(',', $links).')'; |
|
799 | 796 | } |
800 | 797 | } |
801 | 798 | } |
802 | - $sortbycf=''; |
|
803 | - if (!empty($query['order']) && (preg_match('/^[a-z_0-9, ]+$/i',$query['order']) || stripos($query['order'],'#')!==FALSE ) && |
|
804 | - (empty($query['sort']) || preg_match('/^(DESC|ASC)$/i',$query['sort']))) |
|
799 | + $sortbycf = ''; |
|
800 | + if (!empty($query['order']) && (preg_match('/^[a-z_0-9, ]+$/i', $query['order']) || stripos($query['order'], '#') !== FALSE) && |
|
801 | + (empty($query['sort']) || preg_match('/^(DESC|ASC)$/i', $query['sort']))) |
|
805 | 802 | { |
806 | 803 | $order = array(); |
807 | - foreach(explode(',',$query['order']) as $val) |
|
804 | + foreach (explode(',', $query['order']) as $val) |
|
808 | 805 | { |
809 | 806 | $val = trim($val); |
810 | 807 | if ($val[0] == '#') |
811 | 808 | { |
812 | - $sortbycf = substr($val,1); |
|
809 | + $sortbycf = substr($val, 1); |
|
813 | 810 | $val = "cfsortcrit IS NULL,cfsortcrit"; |
814 | 811 | } |
815 | 812 | else |
816 | 813 | { |
817 | 814 | static $table_def = null; |
818 | - if (is_null($table_def)) $table_def = $this->db->get_table_definitions('infolog',$this->info_table); |
|
819 | - if (substr($val,0,5) != 'info_' && isset($table_def['fd']['info_'.$val])) $val = 'info_'.$val; |
|
815 | + if (is_null($table_def)) $table_def = $this->db->get_table_definitions('infolog', $this->info_table); |
|
816 | + if (substr($val, 0, 5) != 'info_' && isset($table_def['fd']['info_'.$val])) $val = 'info_'.$val; |
|
820 | 817 | if ($val == 'info_des' && $this->db->capabilities['order_on_text'] !== true) |
821 | 818 | { |
822 | 819 | if (!$this->db->capabilities['order_on_text']) continue; |
823 | 820 | |
824 | - $val = sprintf($this->db->capabilities['order_on_text'],$val); |
|
821 | + $val = sprintf($this->db->capabilities['order_on_text'], $val); |
|
825 | 822 | } |
826 | 823 | } |
827 | 824 | $order[] = $val; |
828 | 825 | } |
829 | - $ordermethod = 'ORDER BY ' . implode(',',$order) . ' ' . $query['sort']; |
|
826 | + $ordermethod = 'ORDER BY '.implode(',', $order).' '.$query['sort']; |
|
830 | 827 | } |
831 | 828 | else |
832 | 829 | { |
833 | - $ordermethod = 'ORDER BY info_datemodified DESC'; // newest first |
|
830 | + $ordermethod = 'ORDER BY info_datemodified DESC'; // newest first |
|
834 | 831 | } |
835 | 832 | $filtermethod = $no_acl ? '1=1' : $this->aclFilter($query['filter']); |
836 | 833 | if (!$query['col_filter']['info_status']) $filtermethod .= $this->statusFilter($query['filter']); |
837 | 834 | $filtermethod .= $this->dateFilter($query['filter']); |
838 | - $cfcolfilter=0; |
|
835 | + $cfcolfilter = 0; |
|
839 | 836 | if (is_array($query['col_filter'])) |
840 | 837 | { |
841 | - foreach($query['col_filter'] as $col => $data) |
|
838 | + foreach ($query['col_filter'] as $col => $data) |
|
842 | 839 | { |
843 | 840 | if (is_int($col)) |
844 | 841 | { |
845 | 842 | $filtermethod .= ' AND '.$data; |
846 | 843 | continue; |
847 | 844 | } |
848 | - if ($col[0] != '#' && substr($col,0,5) != 'info_' && isset($table_def['fd']['info_'.$col])) $col = 'info_'.$col; |
|
849 | - if ((string)$data !== '' && preg_match('/^[a-z_0-9]+$/i',$col)) |
|
845 | + if ($col[0] != '#' && substr($col, 0, 5) != 'info_' && isset($table_def['fd']['info_'.$col])) $col = 'info_'.$col; |
|
846 | + if ((string)$data !== '' && preg_match('/^[a-z_0-9]+$/i', $col)) |
|
850 | 847 | { |
851 | 848 | switch ($col) |
852 | 849 | { |
853 | 850 | case 'info_responsible': |
854 | - $data = (int) $data; |
|
855 | - if (!$data) continue 2; // +1 for switch |
|
851 | + $data = (int)$data; |
|
852 | + if (!$data) continue 2; // +1 for switch |
|
856 | 853 | $filtermethod .= ' AND ('.$this->responsible_filter($data)." OR $this->users_table.account_id IS NULL AND ". |
857 | - $this->db->expression($this->info_table,array( |
|
858 | - 'info_owner' => $data > 0 ? $data : $GLOBALS['egw']->accounts->members($data,true) |
|
854 | + $this->db->expression($this->info_table, array( |
|
855 | + 'info_owner' => $data > 0 ? $data : $GLOBALS['egw']->accounts->members($data, true) |
|
859 | 856 | )).')'; |
860 | 857 | break; |
861 | 858 | |
862 | 859 | case 'info_id': // info_id itself is ambigous |
863 | - $filtermethod .= ' AND '.$this->db->expression($this->info_table,'main.',array('info_id' => $data)); |
|
860 | + $filtermethod .= ' AND '.$this->db->expression($this->info_table, 'main.', array('info_id' => $data)); |
|
864 | 861 | break; |
865 | 862 | |
866 | 863 | default: |
867 | - $filtermethod .= ' AND '.$this->db->expression($this->info_table,array($col => $data)); |
|
864 | + $filtermethod .= ' AND '.$this->db->expression($this->info_table, array($col => $data)); |
|
868 | 865 | break; |
869 | 866 | } |
870 | 867 | } |
871 | - if ($col[0] == '#' && $query['custom_fields'] && $data) |
|
868 | + if ($col[0] == '#' && $query['custom_fields'] && $data) |
|
872 | 869 | { |
873 | 870 | $filtermethod .= " AND main.info_id IN (SELECT DISTINCT info_id FROM $this->extra_table WHERE "; |
874 | 871 | $custom_fields = Api\Storage\Customfields::get('infolog'); |
875 | 872 | |
876 | - if($custom_fields[substr($col,1)]['type'] == 'select' && $custom_fields[substr($col,1)]['rows'] > 1) |
|
873 | + if ($custom_fields[substr($col, 1)]['type'] == 'select' && $custom_fields[substr($col, 1)]['rows'] > 1) |
|
877 | 874 | { |
878 | 875 | // Multi-select - any entry with the filter value selected matches |
879 | 876 | $filtermethod .= $this->db->expression($this->extra_table, array( |
880 | - 'info_extra_name' => substr($col,1), |
|
881 | - $this->db->concat("','",'info_extra_value',"','").' '.$this->db->capabilities[Api\Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.$this->db->quote('%,'.$data.',%'), |
|
877 | + 'info_extra_name' => substr($col, 1), |
|
878 | + $this->db->concat("','", 'info_extra_value', "','").' '.$this->db->capabilities[Api\Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.$this->db->quote('%,'.$data.',%'), |
|
882 | 879 | )).')'; |
883 | 880 | } |
884 | 881 | else |
885 | 882 | { |
886 | - $filtermethod .= $this->db->expression($this->extra_table,array( |
|
887 | - 'info_extra_name' => substr($col,1), |
|
883 | + $filtermethod .= $this->db->expression($this->extra_table, array( |
|
884 | + 'info_extra_name' => substr($col, 1), |
|
888 | 885 | 'info_extra_value' => $data, |
889 | 886 | )).')'; |
890 | 887 | } |
@@ -896,15 +893,15 @@ discard block |
||
896 | 893 | |
897 | 894 | if ((int)$query['cat_id']) |
898 | 895 | { |
899 | - $categories = new Api\Categories('','infolog'); |
|
896 | + $categories = new Api\Categories('', 'infolog'); |
|
900 | 897 | $cats = $categories->return_all_children((int)$query['cat_id']); |
901 | - $filtermethod .= ' AND info_cat'.(count($cats)>1? ' IN ('.implode(',',$cats).') ' : '='.(int)$query['cat_id']); |
|
898 | + $filtermethod .= ' AND info_cat'.(count($cats) > 1 ? ' IN ('.implode(',', $cats).') ' : '='.(int)$query['cat_id']); |
|
902 | 899 | } |
903 | 900 | $join = $distinct = ''; |
904 | - if ($query['query']) $query['search'] = $query['query']; // allow both names |
|
901 | + if ($query['query']) $query['search'] = $query['query']; // allow both names |
|
905 | 902 | if ($query['search']) // we search in _from, _subject, _des and _extra_value for $query |
906 | 903 | { |
907 | - $columns = array('info_from','info_location','info_subject'); |
|
904 | + $columns = array('info_from', 'info_location', 'info_subject'); |
|
908 | 905 | // at the moment MaxDB 7.5 cant cast nor search text columns, it's suppost to change in 7.6 |
909 | 906 | if ($this->db->capabilities['like_on_text']) $columns[] = 'info_des'; |
910 | 907 | |
@@ -913,7 +910,7 @@ discard block |
||
913 | 910 | $so_sql->table_name = 'main'; |
914 | 911 | $search = $so_sql->search2criteria($query['search'], $wildcard, $op, null, $columns); |
915 | 912 | $sql_query = 'AND ('.(is_numeric($query['search']) ? 'main.info_id='.(int)$query['search'].' OR ' : ''). |
916 | - implode($op, $search) .')'; |
|
913 | + implode($op, $search).')'; |
|
917 | 914 | } |
918 | 915 | $join .= " LEFT JOIN $this->users_table ON main.info_id=$this->users_table.info_id"; |
919 | 916 | if (strpos($query['filter'], '+deleted') === false) |
@@ -932,7 +929,7 @@ discard block |
||
932 | 929 | { |
933 | 930 | $query['append'] = $group_by; |
934 | 931 | } |
935 | - $pid = 'AND ' . $this->db->expression($this->info_table,array('info_id_parent' => ($action == 'sp' ?$query['action_id'] : 0))); |
|
932 | + $pid = 'AND '.$this->db->expression($this->info_table, array('info_id_parent' => ($action == 'sp' ? $query['action_id'] : 0))); |
|
936 | 933 | |
937 | 934 | if ($GLOBALS['egw_info']['user']['preferences']['infolog']['listNoSubs'] != '1' && $action != 'sp' || |
938 | 935 | (string)$query['col_filter']['info_id_parent'] !== '' || |
@@ -953,14 +950,14 @@ discard block |
||
953 | 950 | } |
954 | 951 | else |
955 | 952 | { |
956 | - $query['total'] = $this->db->query($sql="SELECT $distinct main.info_id ".$sql_query.$group_by,__LINE__,__FILE__)->NumRows(); |
|
953 | + $query['total'] = $this->db->query($sql = "SELECT $distinct main.info_id ".$sql_query.$group_by, __LINE__, __FILE__)->NumRows(); |
|
957 | 954 | } |
958 | 955 | $info_customfield = ''; |
959 | 956 | if ($sortbycf != '') |
960 | 957 | { |
961 | 958 | $sort_col = "(SELECT DISTINCT info_extra_value FROM $this->extra_table sub2 WHERE sub2.info_id=main.info_id AND info_extra_name=".$this->db->quote($sortbycf).")"; |
962 | 959 | if (!isset($custom_fields)) $custom_fields = Api\Storage\Customfields::get('infolog'); |
963 | - switch($custom_fields[$sortbycf]['type']) |
|
960 | + switch ($custom_fields[$sortbycf]['type']) |
|
964 | 961 | { |
965 | 962 | case 'int': |
966 | 963 | $sort_col = $this->db->to_int($sort_col); |
@@ -979,12 +976,12 @@ discard block |
||
979 | 976 | $query['start'] = 0; |
980 | 977 | } |
981 | 978 | $cols = isset($query['cols']) ? $query['cols'] : 'main.*'; |
982 | - if (is_array($cols)) $cols = implode(',',$cols); |
|
979 | + if (is_array($cols)) $cols = implode(',', $cols); |
|
983 | 980 | $cols .= ','.$this->db->group_concat('attendees.account_id').' AS info_responsible'; |
984 | 981 | $cols .= ','.$this->db->group_concat('attendees.info_res_attendee').' AS info_cc'; |
985 | - $rs = $this->db->query($sql='SELECT '.$mysql_calc_rows.' '.$distinct.' '.$cols.' '.$info_customfield.' '.$sql_query. |
|
986 | - $query['append'].$ordermethod,__LINE__,__FILE__, |
|
987 | - (int) $query['start'],isset($query['start']) ? (int) $query['num_rows'] : -1,false,Api\Db::FETCH_ASSOC); |
|
982 | + $rs = $this->db->query($sql = 'SELECT '.$mysql_calc_rows.' '.$distinct.' '.$cols.' '.$info_customfield.' '.$sql_query. |
|
983 | + $query['append'].$ordermethod, __LINE__, __FILE__, |
|
984 | + (int)$query['start'], isset($query['start']) ? (int)$query['num_rows'] : -1, false, Api\Db::FETCH_ASSOC); |
|
988 | 985 | //echo "<p>db::query('$sql',,,".(int)$query['start'].','.(isset($query['start']) ? (int) $query['num_rows'] : -1).")</p>\n"; |
989 | 986 | |
990 | 987 | if ($mysql_calc_rows) |
@@ -999,10 +996,10 @@ discard block |
||
999 | 996 | { |
1000 | 997 | return $rs; |
1001 | 998 | } |
1002 | - foreach($rs as $info) |
|
999 | + foreach ($rs as $info) |
|
1003 | 1000 | { |
1004 | - $info['info_responsible'] = $info['info_responsible'] ? array_unique(explode(',',$info['info_responsible'])) : array(); |
|
1005 | - foreach($info['info_responsible'] as $k => $v) |
|
1001 | + $info['info_responsible'] = $info['info_responsible'] ? array_unique(explode(',', $info['info_responsible'])) : array(); |
|
1002 | + foreach ($info['info_responsible'] as $k => $v) |
|
1006 | 1003 | { |
1007 | 1004 | if (!is_numeric($v)) unset($info['info_responsible'][$k]); |
1008 | 1005 | } |
@@ -1019,19 +1016,19 @@ discard block |
||
1019 | 1016 | } |
1020 | 1017 | // if no specific custom field is selected, show/query all custom fields |
1021 | 1018 | if ($ids && ($query['custom_fields'] || $query['csv_export'] || |
1022 | - $index_load_cfs && $query['col_filter']['info_type'] && in_array($query['col_filter']['info_type'],$index_load_cfs))) |
|
1019 | + $index_load_cfs && $query['col_filter']['info_type'] && in_array($query['col_filter']['info_type'], $index_load_cfs))) |
|
1023 | 1020 | { |
1024 | 1021 | $where = array('info_id' => array_keys($ids)); |
1025 | - if (!($query['csv_export'] || strchr(is_array($query['selectcols']) ? implode(',',$query['selectcols']):$query['selectcols'],'#') === false || |
|
1026 | - $index_load_cfs && $query['col_filter']['info_type'] && in_array($query['col_filter']['info_type'],$index_load_cfs))) |
|
1022 | + if (!($query['csv_export'] || strchr(is_array($query['selectcols']) ? implode(',', $query['selectcols']) : $query['selectcols'], '#') === false || |
|
1023 | + $index_load_cfs && $query['col_filter']['info_type'] && in_array($query['col_filter']['info_type'], $index_load_cfs))) |
|
1027 | 1024 | { |
1028 | 1025 | $where['info_extra_name'] = array(); |
1029 | - foreach(is_array($query['selectcols']) ? $query['selectcols'] : explode(',',$query['selectcols']) as $col) |
|
1026 | + foreach (is_array($query['selectcols']) ? $query['selectcols'] : explode(',', $query['selectcols']) as $col) |
|
1030 | 1027 | { |
1031 | - if ($col[0] == '#') $where['info_extra_name'][] = substr($col,1); |
|
1028 | + if ($col[0] == '#') $where['info_extra_name'][] = substr($col, 1); |
|
1032 | 1029 | } |
1033 | 1030 | } |
1034 | - foreach($this->db->select($this->extra_table,'*',$where,__LINE__,__FILE__) as $row) |
|
1031 | + foreach ($this->db->select($this->extra_table, '*', $where, __LINE__, __FILE__) as $row) |
|
1035 | 1032 | { |
1036 | 1033 | $ids[$row['info_id']]['#'.$row['info_extra_name']] = $row['info_extra_value']; |
1037 | 1034 | } |
@@ -1056,29 +1053,29 @@ discard block |
||
1056 | 1053 | { |
1057 | 1054 | $users = array(); |
1058 | 1055 | |
1059 | - foreach($this->db->select($this->info_table,'DISTINCT info_owner',array( |
|
1060 | - str_replace(' AND ','',$this->statusFilter('open')), |
|
1061 | - '(ABS(info_startdate-'.time().')<'.(4*24*60*60).' OR '. // start_day within 4 days |
|
1062 | - 'ABS(info_enddate-'.time().')<'.(4*24*60*60).')', // end_day within 4 days |
|
1063 | - ),__LINE__,__FILE__) as $row) |
|
1056 | + foreach ($this->db->select($this->info_table, 'DISTINCT info_owner', array( |
|
1057 | + str_replace(' AND ', '', $this->statusFilter('open')), |
|
1058 | + '(ABS(info_startdate-'.time().')<'.(4 * 24 * 60 * 60).' OR '.// start_day within 4 days |
|
1059 | + 'ABS(info_enddate-'.time().')<'.(4 * 24 * 60 * 60).')', // end_day within 4 days |
|
1060 | + ), __LINE__, __FILE__) as $row) |
|
1064 | 1061 | { |
1065 | 1062 | $users[] = $row['info_owner']; |
1066 | 1063 | } |
1067 | - foreach($this->db->select($this->info_table, "DISTINCT $this->users_table.account_id AS account_id", |
|
1068 | - $this->statusFilter('open',false), __LINE__, __FILE__, false, '', 'infolog', 0, |
|
1064 | + foreach ($this->db->select($this->info_table, "DISTINCT $this->users_table.account_id AS account_id", |
|
1065 | + $this->statusFilter('open', false), __LINE__, __FILE__, false, '', 'infolog', 0, |
|
1069 | 1066 | "JOIN $this->users_table ON $this->info_table.info_id=$this->users_table.info_id AND info_res_deleted IS NULL") as $row) |
1070 | 1067 | { |
1071 | 1068 | $responsible = $row['account_id']; |
1072 | 1069 | |
1073 | 1070 | if ($GLOBALS['egw']->accounts->get_type($responsible) == 'g') |
1074 | 1071 | { |
1075 | - $responsible = $GLOBALS['egw']->accounts->members($responsible,true); |
|
1072 | + $responsible = $GLOBALS['egw']->accounts->members($responsible, true); |
|
1076 | 1073 | } |
1077 | 1074 | if ($responsible) |
1078 | 1075 | { |
1079 | - foreach((array)$responsible as $user) |
|
1076 | + foreach ((array)$responsible as $user) |
|
1080 | 1077 | { |
1081 | - if ($user && !in_array($user,$users)) $users[] = $user; |
|
1078 | + if ($user && !in_array($user, $users)) $users[] = $user; |
|
1082 | 1079 | } |
1083 | 1080 | } |
1084 | 1081 | } |
@@ -95,7 +95,10 @@ discard block |
||
95 | 95 | */ |
96 | 96 | function is_responsible($info,$user=null) |
97 | 97 | { |
98 | - if (!$user) $user = $this->user; |
|
98 | + if (!$user) |
|
99 | + { |
|
100 | + $user = $this->user; |
|
101 | + } |
|
99 | 102 | |
100 | 103 | return self::is_responsible_user($info, $user); |
101 | 104 | } |
@@ -132,20 +135,32 @@ discard block |
||
132 | 135 | */ |
133 | 136 | function check_access( $info,$required_rights,$implicit_edit=false,array $grants=null,$user=null ) |
134 | 137 | { |
135 | - if (is_null($grants)) $grants = $this->grants; |
|
136 | - if (!$user) $user = $this->user; |
|
138 | + if (is_null($grants)) |
|
139 | + { |
|
140 | + $grants = $this->grants; |
|
141 | + } |
|
142 | + if (!$user) |
|
143 | + { |
|
144 | + $user = $this->user; |
|
145 | + } |
|
137 | 146 | |
138 | 147 | // if info-array, but no owner given, force reading of info from db |
139 | - if (is_array($info) && !$info['info_owner']) $info = $info['info_id']; |
|
148 | + if (is_array($info) && !$info['info_owner']) |
|
149 | + { |
|
150 | + $info = $info['info_id']; |
|
151 | + } |
|
140 | 152 | |
141 | 153 | if (is_array($info)) |
142 | 154 | { |
143 | 155 | |
144 | 156 | } |
145 | - elseif ((int) $info != $this->data['info_id']) // already loaded? |
|
157 | + elseif ((int) $info != $this->data['info_id']) |
|
158 | + { |
|
159 | + // already loaded? |
|
146 | 160 | { |
147 | 161 | // dont change our own internal data, |
148 | 162 | $backup_data = $this->data; |
163 | + } |
|
149 | 164 | $info = $this->read(array('info_id'=>$info)); |
150 | 165 | $this->data = $backup_data; |
151 | 166 | } |
@@ -178,7 +193,10 @@ discard block |
||
178 | 193 | */ |
179 | 194 | function responsible_filter($users, $deleted_too=false) |
180 | 195 | { |
181 | - if (!$users) return '0'; |
|
196 | + if (!$users) |
|
197 | + { |
|
198 | + return '0'; |
|
199 | + } |
|
182 | 200 | |
183 | 201 | $responsible = array(); |
184 | 202 | foreach((array)$users as $user) |
@@ -271,11 +289,14 @@ discard block |
||
271 | 289 | " OR info_status = 'offer' AND $public_access" : '').")". |
272 | 290 | " AND (info_access='public'".($has_private_access?" OR $has_private_access":'').')'; |
273 | 291 | } |
274 | - elseif ($filter != 'my' && $filter != 'responsible') // none --> all entrys user has rights to see |
|
292 | + elseif ($filter != 'my' && $filter != 'responsible') |
|
293 | + { |
|
294 | + // none --> all entrys user has rights to see |
|
275 | 295 | { |
276 | 296 | if ($has_private_access) |
277 | 297 | { |
278 | 298 | $filtermethod .= " OR $has_private_access"; |
299 | + } |
|
279 | 300 | } |
280 | 301 | if (count($public_user_list)) |
281 | 302 | { |
@@ -439,7 +460,10 @@ discard block |
||
439 | 460 | $this->data['info_responsible'] = $this->data['info_responsible'] ? explode(',',$this->data['info_responsible']) : array(); |
440 | 461 | foreach($this->data['info_responsible'] as $k => $v) |
441 | 462 | { |
442 | - if (!is_numeric($v)) unset($this->data['info_responsible'][$k]); |
|
463 | + if (!is_numeric($v)) |
|
464 | + { |
|
465 | + unset($this->data['info_responsible'][$k]); |
|
466 | + } |
|
443 | 467 | } |
444 | 468 | $this->data['info_responsible'] = array_values($this->data['info_responsible']); |
445 | 469 | } |
@@ -579,12 +603,18 @@ discard block |
||
579 | 603 | } |
580 | 604 | } |
581 | 605 | // writing no price as SQL NULL (required by postgres) |
582 | - if ($to_write['info_price'] === '') $to_write['info_price'] = NULL; |
|
606 | + if ($to_write['info_price'] === '') |
|
607 | + { |
|
608 | + $to_write['info_price'] = NULL; |
|
609 | + } |
|
583 | 610 | |
584 | 611 | if (($this->data['info_id'] = $info_id) && !$force_insert) |
585 | 612 | { |
586 | 613 | $where = array('info_id' => $info_id); |
587 | - if ($check_modified) $where['info_datemodified'] = $check_modified; |
|
614 | + if ($check_modified) |
|
615 | + { |
|
616 | + $where['info_datemodified'] = $check_modified; |
|
617 | + } |
|
588 | 618 | if (!$this->db->update($this->info_table,$to_write,$where,__LINE__,__FILE__)) |
589 | 619 | { |
590 | 620 | //error_log("### soinfolog::write(".print_r($to_write,true).") where=".print_r($where,true)." returning false"); |
@@ -598,7 +628,11 @@ discard block |
||
598 | 628 | } |
599 | 629 | else |
600 | 630 | { |
601 | - if (!isset($to_write['info_id_parent'])) $to_write['info_id_parent'] = 0; // must not be null |
|
631 | + if (!isset($to_write['info_id_parent'])) |
|
632 | + { |
|
633 | + $to_write['info_id_parent'] = 0; |
|
634 | + } |
|
635 | + // must not be null |
|
602 | 636 | |
603 | 637 | $this->db->insert($this->info_table,$to_write,false,__LINE__,__FILE__); |
604 | 638 | $info_id = $this->data['info_id'] = $this->db->get_last_insert_id($this->info_table,'info_id'); |
@@ -627,7 +661,10 @@ discard block |
||
627 | 661 | if ($purge_cfs) |
628 | 662 | { |
629 | 663 | $where = array('info_id' => $info_id); |
630 | - if ($purge_cfs == 'ical') $where[] = "info_extra_name LIKE '#%'"; |
|
664 | + if ($purge_cfs == 'ical') |
|
665 | + { |
|
666 | + $where[] = "info_extra_name LIKE '#%'"; |
|
667 | + } |
|
631 | 668 | $this->db->delete($this->extra_table,$where,__LINE__,__FILE__); |
632 | 669 | } |
633 | 670 | $to_delete = array(); |
@@ -741,7 +778,10 @@ discard block |
||
741 | 778 | { |
742 | 779 | if (!is_array($info_id) || !$info_id) |
743 | 780 | { |
744 | - if ((int)$info_id <= 0) return 0; |
|
781 | + if ((int)$info_id <= 0) |
|
782 | + { |
|
783 | + return 0; |
|
784 | + } |
|
745 | 785 | } |
746 | 786 | $counts = array(); |
747 | 787 | foreach($this->db->select($this->info_table,'info_id_parent,COUNT(*) AS info_anz_subs',array( |
@@ -815,11 +855,20 @@ discard block |
||
815 | 855 | else |
816 | 856 | { |
817 | 857 | static $table_def = null; |
818 | - if (is_null($table_def)) $table_def = $this->db->get_table_definitions('infolog',$this->info_table); |
|
819 | - if (substr($val,0,5) != 'info_' && isset($table_def['fd']['info_'.$val])) $val = 'info_'.$val; |
|
858 | + if (is_null($table_def)) |
|
859 | + { |
|
860 | + $table_def = $this->db->get_table_definitions('infolog',$this->info_table); |
|
861 | + } |
|
862 | + if (substr($val,0,5) != 'info_' && isset($table_def['fd']['info_'.$val])) |
|
863 | + { |
|
864 | + $val = 'info_'.$val; |
|
865 | + } |
|
820 | 866 | if ($val == 'info_des' && $this->db->capabilities['order_on_text'] !== true) |
821 | 867 | { |
822 | - if (!$this->db->capabilities['order_on_text']) continue; |
|
868 | + if (!$this->db->capabilities['order_on_text']) |
|
869 | + { |
|
870 | + continue; |
|
871 | + } |
|
823 | 872 | |
824 | 873 | $val = sprintf($this->db->capabilities['order_on_text'],$val); |
825 | 874 | } |
@@ -833,7 +882,10 @@ discard block |
||
833 | 882 | $ordermethod = 'ORDER BY info_datemodified DESC'; // newest first |
834 | 883 | } |
835 | 884 | $filtermethod = $no_acl ? '1=1' : $this->aclFilter($query['filter']); |
836 | - if (!$query['col_filter']['info_status']) $filtermethod .= $this->statusFilter($query['filter']); |
|
885 | + if (!$query['col_filter']['info_status']) |
|
886 | + { |
|
887 | + $filtermethod .= $this->statusFilter($query['filter']); |
|
888 | + } |
|
837 | 889 | $filtermethod .= $this->dateFilter($query['filter']); |
838 | 890 | $cfcolfilter=0; |
839 | 891 | if (is_array($query['col_filter'])) |
@@ -845,14 +897,21 @@ discard block |
||
845 | 897 | $filtermethod .= ' AND '.$data; |
846 | 898 | continue; |
847 | 899 | } |
848 | - if ($col[0] != '#' && substr($col,0,5) != 'info_' && isset($table_def['fd']['info_'.$col])) $col = 'info_'.$col; |
|
900 | + if ($col[0] != '#' && substr($col,0,5) != 'info_' && isset($table_def['fd']['info_'.$col])) |
|
901 | + { |
|
902 | + $col = 'info_'.$col; |
|
903 | + } |
|
849 | 904 | if ((string)$data !== '' && preg_match('/^[a-z_0-9]+$/i',$col)) |
850 | 905 | { |
851 | 906 | switch ($col) |
852 | 907 | { |
853 | 908 | case 'info_responsible': |
854 | 909 | $data = (int) $data; |
855 | - if (!$data) continue 2; // +1 for switch |
|
910 | + if (!$data) |
|
911 | + { |
|
912 | + continue 2; |
|
913 | + } |
|
914 | + // +1 for switch |
|
856 | 915 | $filtermethod .= ' AND ('.$this->responsible_filter($data)." OR $this->users_table.account_id IS NULL AND ". |
857 | 916 | $this->db->expression($this->info_table,array( |
858 | 917 | 'info_owner' => $data > 0 ? $data : $GLOBALS['egw']->accounts->members($data,true) |
@@ -901,12 +960,22 @@ discard block |
||
901 | 960 | $filtermethod .= ' AND info_cat'.(count($cats)>1? ' IN ('.implode(',',$cats).') ' : '='.(int)$query['cat_id']); |
902 | 961 | } |
903 | 962 | $join = $distinct = ''; |
904 | - if ($query['query']) $query['search'] = $query['query']; // allow both names |
|
905 | - if ($query['search']) // we search in _from, _subject, _des and _extra_value for $query |
|
963 | + if ($query['query']) |
|
964 | + { |
|
965 | + $query['search'] = $query['query']; |
|
966 | + } |
|
967 | + // allow both names |
|
968 | + if ($query['search']) |
|
969 | + { |
|
970 | + // we search in _from, _subject, _des and _extra_value for $query |
|
906 | 971 | { |
907 | 972 | $columns = array('info_from','info_location','info_subject'); |
973 | + } |
|
908 | 974 | // at the moment MaxDB 7.5 cant cast nor search text columns, it's suppost to change in 7.6 |
909 | - if ($this->db->capabilities['like_on_text']) $columns[] = 'info_des'; |
|
975 | + if ($this->db->capabilities['like_on_text']) |
|
976 | + { |
|
977 | + $columns[] = 'info_des'; |
|
978 | + } |
|
910 | 979 | |
911 | 980 | $wildcard = '%'; $op = null; |
912 | 981 | $so_sql = new Api\Storage('infolog', $this->info_table, $this->extra_table, '', 'info_extra_name', 'info_extra_value', 'info_id', $this->db); |
@@ -959,7 +1028,10 @@ discard block |
||
959 | 1028 | if ($sortbycf != '') |
960 | 1029 | { |
961 | 1030 | $sort_col = "(SELECT DISTINCT info_extra_value FROM $this->extra_table sub2 WHERE sub2.info_id=main.info_id AND info_extra_name=".$this->db->quote($sortbycf).")"; |
962 | - if (!isset($custom_fields)) $custom_fields = Api\Storage\Customfields::get('infolog'); |
|
1031 | + if (!isset($custom_fields)) |
|
1032 | + { |
|
1033 | + $custom_fields = Api\Storage\Customfields::get('infolog'); |
|
1034 | + } |
|
963 | 1035 | switch($custom_fields[$sortbycf]['type']) |
964 | 1036 | { |
965 | 1037 | case 'int': |
@@ -979,7 +1051,10 @@ discard block |
||
979 | 1051 | $query['start'] = 0; |
980 | 1052 | } |
981 | 1053 | $cols = isset($query['cols']) ? $query['cols'] : 'main.*'; |
982 | - if (is_array($cols)) $cols = implode(',',$cols); |
|
1054 | + if (is_array($cols)) |
|
1055 | + { |
|
1056 | + $cols = implode(',',$cols); |
|
1057 | + } |
|
983 | 1058 | $cols .= ','.$this->db->group_concat('attendees.account_id').' AS info_responsible'; |
984 | 1059 | $cols .= ','.$this->db->group_concat('attendees.info_res_attendee').' AS info_cc'; |
985 | 1060 | $rs = $this->db->query($sql='SELECT '.$mysql_calc_rows.' '.$distinct.' '.$cols.' '.$info_customfield.' '.$sql_query. |
@@ -1004,7 +1079,10 @@ discard block |
||
1004 | 1079 | $info['info_responsible'] = $info['info_responsible'] ? array_unique(explode(',',$info['info_responsible'])) : array(); |
1005 | 1080 | foreach($info['info_responsible'] as $k => $v) |
1006 | 1081 | { |
1007 | - if (!is_numeric($v)) unset($info['info_responsible'][$k]); |
|
1082 | + if (!is_numeric($v)) |
|
1083 | + { |
|
1084 | + unset($info['info_responsible'][$k]); |
|
1085 | + } |
|
1008 | 1086 | } |
1009 | 1087 | $info['info_responsible'] = array_values($info['info_responsible']); |
1010 | 1088 | |
@@ -1015,7 +1093,10 @@ discard block |
||
1015 | 1093 | { |
1016 | 1094 | $config_data = Api\Config::read('infolog'); |
1017 | 1095 | $index_load_cfs = $config_data['index_load_cfs']; |
1018 | - if (!is_array($index_load_cfs)) $index_load_cfs = explode(',', $index_load_cfs); |
|
1096 | + if (!is_array($index_load_cfs)) |
|
1097 | + { |
|
1098 | + $index_load_cfs = explode(',', $index_load_cfs); |
|
1099 | + } |
|
1019 | 1100 | } |
1020 | 1101 | // if no specific custom field is selected, show/query all custom fields |
1021 | 1102 | if ($ids && ($query['custom_fields'] || $query['csv_export'] || |
@@ -1028,7 +1109,10 @@ discard block |
||
1028 | 1109 | $where['info_extra_name'] = array(); |
1029 | 1110 | foreach(is_array($query['selectcols']) ? $query['selectcols'] : explode(',',$query['selectcols']) as $col) |
1030 | 1111 | { |
1031 | - if ($col[0] == '#') $where['info_extra_name'][] = substr($col,1); |
|
1112 | + if ($col[0] == '#') |
|
1113 | + { |
|
1114 | + $where['info_extra_name'][] = substr($col,1); |
|
1115 | + } |
|
1032 | 1116 | } |
1033 | 1117 | } |
1034 | 1118 | foreach($this->db->select($this->extra_table,'*',$where,__LINE__,__FILE__) as $row) |
@@ -1078,7 +1162,10 @@ discard block |
||
1078 | 1162 | { |
1079 | 1163 | foreach((array)$responsible as $user) |
1080 | 1164 | { |
1081 | - if ($user && !in_array($user,$users)) $users[] = $user; |
|
1165 | + if ($user && !in_array($user,$users)) |
|
1166 | + { |
|
1167 | + $users[] = $user; |
|
1168 | + } |
|
1082 | 1169 | } |
1083 | 1170 | } |
1084 | 1171 | } |
@@ -118,41 +118,41 @@ discard block |
||
118 | 118 | * @param boolean $allow_multiple_values =false should we allow AND store multiple values (1:N relations) |
119 | 119 | * @param string $timestamp_type =null default null=leave them as is, 'ts'|'integer' use integer unix timestamps, 'object' use DateTime objects |
120 | 120 | */ |
121 | - function __construct($app,$table,$extra_table,$column_prefix='', |
|
122 | - $extra_key='_name',$extra_value='_value',$extra_id='_id', |
|
123 | - Db $db=null,$no_clone=true,$allow_multiple_values=false,$timestamp_type=null) |
|
121 | + function __construct($app, $table, $extra_table, $column_prefix = '', |
|
122 | + $extra_key = '_name', $extra_value = '_value', $extra_id = '_id', |
|
123 | + Db $db = null, $no_clone = true, $allow_multiple_values = false, $timestamp_type = null) |
|
124 | 124 | { |
125 | 125 | // calling the Storage\Base constructor |
126 | - parent::__construct($app,$table,$db,$column_prefix,$no_clone,$timestamp_type); |
|
126 | + parent::__construct($app, $table, $db, $column_prefix, $no_clone, $timestamp_type); |
|
127 | 127 | |
128 | 128 | $this->allow_multiple_values = $allow_multiple_values; |
129 | 129 | $this->extra_table = $extra_table; |
130 | - if (!$this->extra_id) $this->extra_id = $this->autoinc_id; // default to auto id of regular table |
|
130 | + if (!$this->extra_id) $this->extra_id = $this->autoinc_id; // default to auto id of regular table |
|
131 | 131 | |
132 | 132 | // if names from columns of extra table are only postfixes (starting with _), prepend column prefix |
133 | - if (!($prefix=$column_prefix)) |
|
133 | + if (!($prefix = $column_prefix)) |
|
134 | 134 | { |
135 | - list($prefix) = explode('_',$this->autoinc_id); |
|
135 | + list($prefix) = explode('_', $this->autoinc_id); |
|
136 | 136 | } |
137 | - elseif(substr($prefix,-1) == '_') |
|
137 | + elseif (substr($prefix, -1) == '_') |
|
138 | 138 | { |
139 | - $prefix = substr($prefix,0,-1); // remove trailing underscore from column prefix parameter |
|
139 | + $prefix = substr($prefix, 0, -1); // remove trailing underscore from column prefix parameter |
|
140 | 140 | } |
141 | - foreach(array( |
|
141 | + foreach (array( |
|
142 | 142 | 'extra_id' => $extra_id, |
143 | 143 | 'extra_key' => $extra_key, |
144 | 144 | 'extra_value' => $extra_value |
145 | 145 | ) as $col => $val) |
146 | 146 | { |
147 | 147 | $this->$col = $col_name = $val; |
148 | - if ($col_name[0] == '_') $this->$col = $prefix . $val; |
|
148 | + if ($col_name[0] == '_') $this->$col = $prefix.$val; |
|
149 | 149 | } |
150 | 150 | // some sanity checks, maybe they should be active only for development |
151 | - if (!($extra_defs = $this->db->get_table_definitions($app,$extra_table))) |
|
151 | + if (!($extra_defs = $this->db->get_table_definitions($app, $extra_table))) |
|
152 | 152 | { |
153 | 153 | throw new Exception\WrongParameter("extra table $extra_table is NOT defined!"); |
154 | 154 | } |
155 | - foreach(array('extra_id','extra_key','extra_value') as $col) |
|
155 | + foreach (array('extra_id', 'extra_key', 'extra_value') as $col) |
|
156 | 156 | { |
157 | 157 | if (!$this->$col || !isset($extra_defs['fd'][$this->$col])) |
158 | 158 | { |
@@ -177,23 +177,23 @@ discard block |
||
177 | 177 | * @param array $field_names =null custom fields to read, default all |
178 | 178 | * @return array id => $this->cf_field(name) => value |
179 | 179 | */ |
180 | - function read_customfields($ids,$field_names=null) |
|
180 | + function read_customfields($ids, $field_names = null) |
|
181 | 181 | { |
182 | 182 | if (is_null($field_names)) $field_names = array_keys($this->customfields); |
183 | 183 | |
184 | - foreach((array)$ids as $key => $id) |
|
184 | + foreach ((array)$ids as $key => $id) |
|
185 | 185 | { |
186 | 186 | if (!(int)$id && is_array($ids)) unset($ids[$key]); |
187 | 187 | } |
188 | - if (!$ids || !$field_names) return array(); // nothing to do |
|
188 | + if (!$ids || !$field_names) return array(); // nothing to do |
|
189 | 189 | |
190 | 190 | $entries = array(); |
191 | - foreach($this->db->select($this->extra_table,'*',array( |
|
191 | + foreach ($this->db->select($this->extra_table, '*', array( |
|
192 | 192 | $this->extra_id => $ids, |
193 | 193 | $this->extra_key => $field_names, |
194 | - ),__LINE__,__FILE__,false,'',$this->app) as $row) |
|
194 | + ), __LINE__, __FILE__, false, '', $this->app) as $row) |
|
195 | 195 | { |
196 | - $entry =& $entries[$row[$this->extra_id]]; |
|
196 | + $entry = & $entries[$row[$this->extra_id]]; |
|
197 | 197 | if (!is_array($entry)) $entry = array(); |
198 | 198 | $field = $this->get_cf_field($row[$this->extra_key]); |
199 | 199 | |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | * @param array $extra_cols =array() extra-data to be saved |
217 | 217 | * @return bool false on success, errornumber on failure |
218 | 218 | */ |
219 | - function save_customfields(&$data, array $extra_cols=array()) |
|
219 | + function save_customfields(&$data, array $extra_cols = array()) |
|
220 | 220 | { |
221 | 221 | $id = isset($data[$this->autoinc_id]) ? $data[$this->autoinc_id] : $data[$this->db_key_cols[$this->autoinc_id]]; |
222 | 222 | |
@@ -233,22 +233,21 @@ discard block |
||
233 | 233 | $is_multiple = $this->is_multiple($name); |
234 | 234 | |
235 | 235 | // we explicitly need to delete fields, if value is empty or field allows multiple values or we have no unique index |
236 | - if(empty($data[$field]) || $is_multiple || !$this->extra_has_unique_index) |
|
236 | + if (empty($data[$field]) || $is_multiple || !$this->extra_has_unique_index) |
|
237 | 237 | { |
238 | - $this->db->delete($this->extra_table,$where,__LINE__,__FILE__,$this->app); |
|
239 | - if (empty($data[$field])) continue; // nothing else to do for empty values |
|
238 | + $this->db->delete($this->extra_table, $where, __LINE__, __FILE__, $this->app); |
|
239 | + if (empty($data[$field])) continue; // nothing else to do for empty values |
|
240 | 240 | } |
241 | - foreach($is_multiple && !is_array($data[$field]) ? explode(',',$data[$field]) : |
|
242 | - // regular custom fields (!$is_multiple) eg. addressbook store multiple values comma-separated |
|
241 | + foreach ($is_multiple && !is_array($data[$field]) ? explode(',', $data[$field]) : // regular custom fields (!$is_multiple) eg. addressbook store multiple values comma-separated |
|
243 | 242 | (array)(!$is_multiple && is_array($data[$field]) ? implode(',', $data[$field]) : $data[$field]) as $value) |
244 | 243 | { |
245 | - if (!$this->db->insert($this->extra_table,array($this->extra_value => $value)+$extra_cols,$where,__LINE__,__FILE__,$this->app)) |
|
244 | + if (!$this->db->insert($this->extra_table, array($this->extra_value => $value) + $extra_cols, $where, __LINE__, __FILE__, $this->app)) |
|
246 | 245 | { |
247 | 246 | return $this->db->Errno; |
248 | 247 | } |
249 | 248 | } |
250 | 249 | } |
251 | - return false; // no error |
|
250 | + return false; // no error |
|
252 | 251 | } |
253 | 252 | |
254 | 253 | /** |
@@ -264,7 +263,7 @@ discard block |
||
264 | 263 | |
265 | 264 | if ($this->customfields) |
266 | 265 | { |
267 | - foreach(array_keys($this->customfields) as $name) |
|
266 | + foreach (array_keys($this->customfields) as $name) |
|
268 | 267 | { |
269 | 268 | if (isset($new[$field = $this->get_cf_field($name)])) |
270 | 269 | { |
@@ -284,16 +283,16 @@ discard block |
||
284 | 283 | * @param string $join sql to do a join, added as is after the table-name, eg. ", table2 WHERE x=y" or |
285 | 284 | * @return array|boolean data if row could be retrived else False |
286 | 285 | */ |
287 | - function read($keys,$extra_cols='',$join='') |
|
286 | + function read($keys, $extra_cols = '', $join = '') |
|
288 | 287 | { |
289 | - if (!parent::read($keys,$extra_cols,$join)) |
|
288 | + if (!parent::read($keys, $extra_cols, $join)) |
|
290 | 289 | { |
291 | 290 | return false; |
292 | 291 | } |
293 | 292 | if (($id = (int)$this->data[$this->db_key_cols[$this->autoinc_id]]) && $this->customfields && |
294 | 293 | ($cfs = $this->read_customfields($id))) |
295 | 294 | { |
296 | - $this->data = array_merge($this->data,$cfs[$id]); |
|
295 | + $this->data = array_merge($this->data, $cfs[$id]); |
|
297 | 296 | } |
298 | 297 | return $this->data; |
299 | 298 | } |
@@ -307,14 +306,14 @@ discard block |
||
307 | 306 | * @param string|array $extra_where =null extra where clause, eg. to check an etag, returns true if no affected rows! |
308 | 307 | * @return int|boolean 0 on success, or errno != 0 on error, or true if $extra_where is given and no rows affected |
309 | 308 | */ |
310 | - function save($keys=null,$extra_where=null) |
|
309 | + function save($keys = null, $extra_where = null) |
|
311 | 310 | { |
312 | 311 | if (is_array($keys) && count($keys) && !isset($keys[0])) // allow to use an etag, eg array('etag=etag+1') |
313 | 312 | { |
314 | 313 | $this->data_merge($keys); |
315 | 314 | $keys = null; |
316 | 315 | } |
317 | - $ret = parent::save($keys,$extra_where); |
|
316 | + $ret = parent::save($keys, $extra_where); |
|
318 | 317 | |
319 | 318 | if ($ret == 0 && $this->customfields) |
320 | 319 | { |
@@ -332,26 +331,26 @@ discard block |
||
332 | 331 | * @param boolean $only_return_ids =false return $ids of delete call to db object, but not run it (can be used by extending classes!) |
333 | 332 | * @return int|array affected rows, should be 1 if ok, 0 if an error or array with id's if $only_return_ids |
334 | 333 | */ |
335 | - function delete($keys=null,$only_return_ids=false) |
|
334 | + function delete($keys = null, $only_return_ids = false) |
|
336 | 335 | { |
337 | 336 | if ($this->customfields || $only_return_ids) |
338 | 337 | { |
339 | - $query = parent::delete($keys,true); |
|
338 | + $query = parent::delete($keys, true); |
|
340 | 339 | // check if query contains more then the id's |
341 | 340 | if (!isset($query[$this->autoinc_id]) || count($query) != 1) |
342 | 341 | { |
343 | - foreach($this->db->select($this->table_name,$this->autoinc_id,$query,__LINE__,__FILE__,false,'',$this->app) as $row) |
|
342 | + foreach ($this->db->select($this->table_name, $this->autoinc_id, $query, __LINE__, __FILE__, false, '', $this->app) as $row) |
|
344 | 343 | { |
345 | 344 | $ids[] = $row[$this->autoinc_id]; |
346 | 345 | } |
347 | - if (!$ids) return 0; // no rows affected |
|
346 | + if (!$ids) return 0; // no rows affected |
|
348 | 347 | } |
349 | 348 | else |
350 | 349 | { |
351 | 350 | $ids = (array)$query[$this->autoinc_id]; |
352 | 351 | } |
353 | 352 | if ($only_return_ids) return $ids; |
354 | - $this->db->delete($this->extra_table,array($this->extra_id => $ids),__LINE__,__FILE__); |
|
353 | + $this->db->delete($this->extra_table, array($this->extra_id => $ids), __LINE__, __FILE__); |
|
355 | 354 | } |
356 | 355 | return parent::delete($keys); |
357 | 356 | } |
@@ -374,32 +373,32 @@ discard block |
||
374 | 373 | * @param string|array $extra_cols =array() |
375 | 374 | * @return int total number of rows |
376 | 375 | */ |
377 | - function get_rows($query,&$rows,&$readonlys,$join='',$need_full_no_count=false,$only_keys=false,$extra_cols=array()) |
|
376 | + function get_rows($query, &$rows, &$readonlys, $join = '', $need_full_no_count = false, $only_keys = false, $extra_cols = array()) |
|
378 | 377 | { |
379 | - parent::get_rows($query,$rows,$readonlys,$join,$need_full_no_count,$only_keys,$extra_cols); |
|
378 | + parent::get_rows($query, $rows, $readonlys, $join, $need_full_no_count, $only_keys, $extra_cols); |
|
380 | 379 | |
381 | - $selectcols = $query['selectcols'] ? explode(',',$query['selectcols']) : array(); |
|
380 | + $selectcols = $query['selectcols'] ? explode(',', $query['selectcols']) : array(); |
|
382 | 381 | |
383 | - if ($rows && $this->customfields && (!$selectcols || in_array('customfields',$selectcols))) |
|
382 | + if ($rows && $this->customfields && (!$selectcols || in_array('customfields', $selectcols))) |
|
384 | 383 | { |
385 | 384 | $id2keys = array(); |
386 | - foreach($rows as $key => $row) |
|
385 | + foreach ($rows as $key => $row) |
|
387 | 386 | { |
388 | 387 | $id2keys[$row[$this->db_key_cols[$this->autoinc_id]]] = $key; |
389 | 388 | } |
390 | 389 | // check if only certain cf's to show |
391 | 390 | if (!in_array('customfields', $selectcols)) |
392 | 391 | { |
393 | - foreach($selectcols as $col) |
|
392 | + foreach ($selectcols as $col) |
|
394 | 393 | { |
395 | 394 | if ($this->is_cf($col)) $fields[] = $this->get_cf_name($col); |
396 | 395 | } |
397 | 396 | } |
398 | - if (($cfs = $this->read_customfields(array_keys($id2keys),$fields))) |
|
397 | + if (($cfs = $this->read_customfields(array_keys($id2keys), $fields))) |
|
399 | 398 | { |
400 | - foreach($cfs as $id => $data) |
|
399 | + foreach ($cfs as $id => $data) |
|
401 | 400 | { |
402 | - $rows[$id2keys[$id]] = array_merge($rows[$id2keys[$id]],$data); |
|
401 | + $rows[$id2keys[$id]] = array_merge($rows[$id2keys[$id]], $data); |
|
403 | 402 | } |
404 | 403 | } |
405 | 404 | } |
@@ -419,7 +418,7 @@ discard block |
||
419 | 418 | * @param array $search_cols =array() List of columns to search. If not provided, all columns in $this->db_cols will be considered |
420 | 419 | * @return array or column => value pairs |
421 | 420 | */ |
422 | - public function search2criteria($_pattern,&$wildcard='',&$op='AND',$extra_col=null, $search_cols = array()) |
|
421 | + public function search2criteria($_pattern, &$wildcard = '', &$op = 'AND', $extra_col = null, $search_cols = array()) |
|
423 | 422 | { |
424 | 423 | $pattern = $wildcard.$_pattern.$wildcard; |
425 | 424 | |
@@ -454,7 +453,7 @@ discard block |
||
454 | 453 | * @param boolean $need_full_no_count =false If true an unlimited query is run to determine the total number of rows, default false |
455 | 454 | * @return array|NULL array of matching rows (the row is an array of the cols) or NULL |
456 | 455 | */ |
457 | - function &search($criteria,$only_keys=True,$order_by='',$extra_cols='',$wildcard='',$empty=False,$op='AND',$start=false,$filter=null,$join='',$need_full_no_count=false) |
|
456 | + function &search($criteria, $only_keys = True, $order_by = '', $extra_cols = '', $wildcard = '', $empty = False, $op = 'AND', $start = false, $filter = null, $join = '', $need_full_no_count = false) |
|
458 | 457 | { |
459 | 458 | //error_log(__METHOD__.'('.array2string(array_combine(array_slice(array('criteria','only_keys','order_by','extra_cols','wildcard','empty','op','start','filter','join','need_full_no_count'), 0, count(func_get_args())), func_get_args())).')'); |
460 | 459 | |
@@ -462,7 +461,7 @@ discard block |
||
462 | 461 | if (!$this->customfields && strpos($order_by, self::CF_PREFIX) === false && |
463 | 462 | (empty($filter) || strpos(implode(',', array_keys($filter)), self::CF_PREFIX) === false)) |
464 | 463 | { |
465 | - return parent::search($criteria,$only_keys,$order_by,$extra_cols,$wildcard,$empty,$op,$start,$filter,$join,$need_full_no_count); |
|
464 | + return parent::search($criteria, $only_keys, $order_by, $extra_cols, $wildcard, $empty, $op, $start, $filter, $join, $need_full_no_count); |
|
466 | 465 | } |
467 | 466 | if ($only_keys === false) |
468 | 467 | { |
@@ -471,7 +470,7 @@ discard block |
||
471 | 470 | $extra_join_added = $join && strpos($join, $this->extra_join) !== false; |
472 | 471 | if ($criteria && is_string($criteria)) |
473 | 472 | { |
474 | - $extra_join_added = true; // we have NOT added the join, as we use a sub-query and therefore not need it |
|
473 | + $extra_join_added = true; // we have NOT added the join, as we use a sub-query and therefore not need it |
|
475 | 474 | |
476 | 475 | $criteria = $this->search2criteria($criteria, $wildcard, $op); |
477 | 476 | } |
@@ -483,10 +482,10 @@ discard block |
||
483 | 482 | // we should check if the CF is (still) available, but that makes the slow search even slower :( |
484 | 483 | if (($negate = $criteria[$this->extra_value][0] === '!')) |
485 | 484 | { |
486 | - $criteria[$this->extra_value] = substr($criteria[$this->extra_value],1); |
|
485 | + $criteria[$this->extra_value] = substr($criteria[$this->extra_value], 1); |
|
487 | 486 | } |
488 | - $criteria[] = $this->extra_table.'.'.$this->extra_value . ' ' .($negate ? 'NOT ' : ''). |
|
489 | - $this->db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE]. ' ' . |
|
487 | + $criteria[] = $this->extra_table.'.'.$this->extra_value.' '.($negate ? 'NOT ' : ''). |
|
488 | + $this->db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '. |
|
490 | 489 | $this->db->quote($wildcard.$criteria[$this->extra_value].$wildcard); |
491 | 490 | unset($criteria[$this->extra_value]); |
492 | 491 | } |
@@ -495,13 +494,13 @@ discard block |
||
495 | 494 | { |
496 | 495 | if ($criteria[$this->autoinc_id]) |
497 | 496 | { |
498 | - $criteria[] = $this->db->expression($this->table_name,$this->table_name.'.', |
|
497 | + $criteria[] = $this->db->expression($this->table_name, $this->table_name.'.', |
|
499 | 498 | array($this->autoinc_id => $criteria[$this->autoinc_id])); |
500 | 499 | } |
501 | 500 | unset($criteria[$this->autoinc_id]); |
502 | 501 | } |
503 | 502 | // replace ambiguous column with (an exact match of) table_name.column |
504 | - foreach($criteria as $name => $val) |
|
503 | + foreach ($criteria as $name => $val) |
|
505 | 504 | { |
506 | 505 | // only add extra_join, if we really need it |
507 | 506 | if (!$extra_join_added && ( |
@@ -513,9 +512,9 @@ discard block |
||
513 | 512 | $extra_join_added = true; |
514 | 513 | } |
515 | 514 | $extra_columns = $this->db->get_table_definitions($this->app, $this->extra_table); |
516 | - if(is_string($name) && $extra_columns['fd'][array_search($name, $this->db_cols)]) |
|
515 | + if (is_string($name) && $extra_columns['fd'][array_search($name, $this->db_cols)]) |
|
517 | 516 | { |
518 | - $criteria[] = $this->db->expression($this->table_name,$this->table_name.'.',array( |
|
517 | + $criteria[] = $this->db->expression($this->table_name, $this->table_name.'.', array( |
|
519 | 518 | array_search($name, $this->db_cols) => $val, |
520 | 519 | )); |
521 | 520 | unset($criteria[$name]); |
@@ -527,12 +526,12 @@ discard block |
||
527 | 526 | $name = substr($name, 1); |
528 | 527 | if (($negate = $criteria[$name][0] === '!')) |
529 | 528 | { |
530 | - $val = substr($val,1); |
|
529 | + $val = substr($val, 1); |
|
531 | 530 | } |
532 | - $cfcriteria[] = '(' . $this->extra_table.'.'.$this->extra_value . ' ' .($negate ? 'NOT ' : ''). |
|
533 | - $this->db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE]. ' ' . |
|
534 | - $this->db->quote($wildcard.$val.$wildcard) . ' AND ' . |
|
535 | - $this->extra_table.'.'.$this->extra_key . ' = ' . $this->db->quote($name) . |
|
531 | + $cfcriteria[] = '('.$this->extra_table.'.'.$this->extra_value.' '.($negate ? 'NOT ' : ''). |
|
532 | + $this->db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '. |
|
533 | + $this->db->quote($wildcard.$val.$wildcard).' AND '. |
|
534 | + $this->extra_table.'.'.$this->extra_key.' = '.$this->db->quote($name). |
|
536 | 535 | ')'; |
537 | 536 | unset($criteria[self::CF_PREFIX.$name]); |
538 | 537 | } |
@@ -544,49 +543,49 @@ discard block |
||
544 | 543 | } |
545 | 544 | } |
546 | 545 | } |
547 | - if ($cfcriteria && $op =='OR') $criteria[] = implode(' OR ',$cfcriteria); |
|
546 | + if ($cfcriteria && $op == 'OR') $criteria[] = implode(' OR ', $cfcriteria); |
|
548 | 547 | } |
549 | - if($only_keys === true) |
|
548 | + if ($only_keys === true) |
|
550 | 549 | { |
551 | 550 | // Expand to keys here, so table_name can be prepended below |
552 | 551 | $only_keys = array_values($this->db_key_cols); |
553 | 552 | } |
554 | 553 | // replace ambiguous column with (an exact match of) table_name.column |
555 | - if(is_array($only_keys)) |
|
554 | + if (is_array($only_keys)) |
|
556 | 555 | { |
557 | - foreach($only_keys as $key => &$col) |
|
556 | + foreach ($only_keys as $key => &$col) |
|
558 | 557 | { |
559 | - if(is_numeric($key) && in_array($col, $this->db_cols, true)) |
|
558 | + if (is_numeric($key) && in_array($col, $this->db_cols, true)) |
|
560 | 559 | { |
561 | - $col = $this->table_name .'.'.array_search($col, $this->db_cols).' AS '.$col; |
|
560 | + $col = $this->table_name.'.'.array_search($col, $this->db_cols).' AS '.$col; |
|
562 | 561 | } |
563 | 562 | } |
564 | 563 | } |
565 | 564 | // check if we order by a custom field --> join cf table for given cf and order by it's value |
566 | - if (strpos($order_by,self::CF_PREFIX) !== false) |
|
565 | + if (strpos($order_by, self::CF_PREFIX) !== false) |
|
567 | 566 | { |
568 | 567 | // if $order_by contains more then order by columns (eg. group by) split it off before |
569 | 568 | if (($pos = stripos($order_by, 'order by')) !== false) |
570 | 569 | { |
571 | - $group_by = substr($order_by, 0, $pos+9); |
|
572 | - $order_by = substr($order_by, $pos+9); |
|
570 | + $group_by = substr($order_by, 0, $pos + 9); |
|
571 | + $order_by = substr($order_by, $pos + 9); |
|
573 | 572 | } |
574 | 573 | // fields to order by, as cutomfields may have names with spaces, we examine each order by criteria |
575 | - $fields2order = explode(',',$order_by); |
|
576 | - foreach($fields2order as $v) |
|
574 | + $fields2order = explode(',', $order_by); |
|
575 | + foreach ($fields2order as $v) |
|
577 | 576 | { |
578 | - if (strpos($v,self::CF_PREFIX) !== false) |
|
577 | + if (strpos($v, self::CF_PREFIX) !== false) |
|
579 | 578 | { |
580 | 579 | // we found a customfield, so we split that part by space char in order to get Sorting Direction and Fieldname |
581 | - $buff = explode(' ',trim($v)); |
|
580 | + $buff = explode(' ', trim($v)); |
|
582 | 581 | $orderDir = array_pop($buff); |
583 | - $key = substr(trim(implode(' ',$buff)), 1); |
|
582 | + $key = substr(trim(implode(' ', $buff)), 1); |
|
584 | 583 | if (!isset($this->customfields[$key])) |
585 | 584 | { |
586 | 585 | $order_by = preg_replace('/'.preg_quote($v, '/').',?/', '', $order_by); |
587 | - continue; // ignore unavaiable CF |
|
586 | + continue; // ignore unavaiable CF |
|
588 | 587 | } |
589 | - switch($this->customfields[$key]['type']) |
|
588 | + switch ($this->customfields[$key]['type']) |
|
590 | 589 | { |
591 | 590 | case 'int': |
592 | 591 | $order_by = str_replace($v, 'extra_order.'.$this->extra_value.' IS NULL,'. |
@@ -624,26 +623,26 @@ discard block |
||
624 | 623 | { |
625 | 624 | $_cfnames = array_keys($this->customfields); |
626 | 625 | $extra_filter = null; |
627 | - foreach($filter as $name => $val) |
|
626 | + foreach ($filter as $name => $val) |
|
628 | 627 | { |
629 | 628 | // replace ambiguous auto-id with (an exact match of) table_name.autoid |
630 | 629 | if (is_string($name) && $name == $this->autoinc_id) |
631 | 630 | { |
632 | 631 | if ((int)$filter[$this->autoinc_id]) |
633 | 632 | { |
634 | - $filter[] = $this->db->expression($this->table_name,$this->table_name.'.',array( |
|
633 | + $filter[] = $this->db->expression($this->table_name, $this->table_name.'.', array( |
|
635 | 634 | $this->autoinc_id => $filter[$this->autoinc_id], |
636 | 635 | )); |
637 | 636 | } |
638 | 637 | unset($filter[$this->autoinc_id]); |
639 | 638 | } |
640 | 639 | // replace ambiguous column with (an exact match of) table_name.column |
641 | - elseif (is_string($name) && $val!=null && in_array($name, $this->db_cols)) |
|
640 | + elseif (is_string($name) && $val != null && in_array($name, $this->db_cols)) |
|
642 | 641 | { |
643 | 642 | $extra_columns = $this->db->get_table_definitions($this->app, $this->extra_table); |
644 | 643 | if ($extra_columns['fd'][array_search($name, $this->db_cols)]) |
645 | 644 | { |
646 | - $filter[] = $this->db->expression($this->table_name,$this->table_name.'.',array( |
|
645 | + $filter[] = $this->db->expression($this->table_name, $this->table_name.'.', array( |
|
647 | 646 | array_search($name, $this->db_cols) => $val, |
648 | 647 | )); |
649 | 648 | unset($filter[$name]); |
@@ -655,59 +654,59 @@ discard block |
||
655 | 654 | if (!isset($this->customfields[$cf_name])) |
656 | 655 | { |
657 | 656 | unset($filter[$name]); |
658 | - continue; // ignore unavailable CF |
|
657 | + continue; // ignore unavailable CF |
|
659 | 658 | } |
660 | 659 | if (!empty($val)) // empty -> dont filter |
661 | 660 | { |
662 | 661 | if ($val[0] === '!') // negative filter |
663 | 662 | { |
664 | - $sql_filter = 'extra_filter.'.$this->extra_value.'!='.$this->db->quote(substr($val,1)); |
|
663 | + $sql_filter = 'extra_filter.'.$this->extra_value.'!='.$this->db->quote(substr($val, 1)); |
|
665 | 664 | } |
666 | 665 | else // using Db::expression to allow to use array() with possible values or NULL |
667 | 666 | { |
668 | - if($this->customfields[$cf_name]['type'] == 'select' && |
|
667 | + if ($this->customfields[$cf_name]['type'] == 'select' && |
|
669 | 668 | $this->customfields[$cf_name]['rows'] > 1) |
670 | 669 | { |
671 | 670 | // Multi-select - any entry with the filter value selected matches |
672 | - $sql_filter = str_replace($this->extra_value,'extra_filter.'. |
|
673 | - $this->extra_value,$this->db->expression($this->extra_table,array( |
|
674 | - $this->db->concat("','",$this->extra_value,"','").' '.$this->db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.$this->db->quote('%,'.$val.',%') |
|
671 | + $sql_filter = str_replace($this->extra_value, 'extra_filter.'. |
|
672 | + $this->extra_value, $this->db->expression($this->extra_table, array( |
|
673 | + $this->db->concat("','", $this->extra_value, "','").' '.$this->db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.$this->db->quote('%,'.$val.',%') |
|
675 | 674 | )) |
676 | 675 | ); |
677 | 676 | } |
678 | 677 | elseif ($this->customfields[$cf_name]['type'] == 'text') |
679 | 678 | { |
680 | - $sql_filter = str_replace($this->extra_value,'extra_filter.'.$this->extra_value, |
|
681 | - $this->db->expression($this->extra_table,array( |
|
679 | + $sql_filter = str_replace($this->extra_value, 'extra_filter.'.$this->extra_value, |
|
680 | + $this->db->expression($this->extra_table, array( |
|
682 | 681 | $this->extra_value.' '.$this->db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.$this->db->quote($wildcard.$val.$wildcard) |
683 | 682 | )) |
684 | 683 | ); |
685 | 684 | } |
686 | 685 | else |
687 | 686 | { |
688 | - $sql_filter = str_replace($this->extra_value,'extra_filter.'. |
|
689 | - $this->extra_value,$this->db->expression($this->extra_table,array($this->extra_value => $val))); |
|
687 | + $sql_filter = str_replace($this->extra_value, 'extra_filter.'. |
|
688 | + $this->extra_value, $this->db->expression($this->extra_table, array($this->extra_value => $val))); |
|
690 | 689 | } |
691 | 690 | } |
692 | 691 | // need to use a LEFT JOIN for negative search or to allow NULL values |
693 | - $need_left_join = $val[0] === '!' || strpos($sql_filter,'IS NULL') !== false ? ' LEFT ' : ''; |
|
694 | - $join .= str_replace('extra_filter','extra_filter'.$extra_filter,$need_left_join.$this->extra_join_filter. |
|
692 | + $need_left_join = $val[0] === '!' || strpos($sql_filter, 'IS NULL') !== false ? ' LEFT ' : ''; |
|
693 | + $join .= str_replace('extra_filter', 'extra_filter'.$extra_filter, $need_left_join.$this->extra_join_filter. |
|
695 | 694 | ' AND extra_filter.'.$this->extra_key.'='.$this->db->quote($cf_name). |
696 | 695 | ' AND '.$sql_filter); |
697 | 696 | ++$extra_filter; |
698 | 697 | } |
699 | 698 | unset($filter[$name]); |
700 | 699 | } |
701 | - elseif(is_int($name) && $this->is_cf($val)) // lettersearch: #cfname LIKE 's%' |
|
700 | + elseif (is_int($name) && $this->is_cf($val)) // lettersearch: #cfname LIKE 's%' |
|
702 | 701 | { |
703 | - $_cf = explode(' ',$val); |
|
704 | - foreach($_cf as $cf_np) |
|
702 | + $_cf = explode(' ', $val); |
|
703 | + foreach ($_cf as $cf_np) |
|
705 | 704 | { |
706 | 705 | // building cf_name by glueing parts together (, in case someone used whitespace in their custom field names) |
707 | - $tcf_name = ($tcf_name?$tcf_name.' ':'').$cf_np; |
|
706 | + $tcf_name = ($tcf_name ? $tcf_name.' ' : '').$cf_np; |
|
708 | 707 | // reacts on the first one found that matches an existing customfield, should be better then the old behavior of |
709 | 708 | // simply splitting by " " and using the first part |
710 | - if ($this->is_cf($tcf_name) && ($cfn = $this->get_cf_name($tcf_name)) && array_search($cfn,(array)$_cfnames,true)!==false ) |
|
709 | + if ($this->is_cf($tcf_name) && ($cfn = $this->get_cf_name($tcf_name)) && array_search($cfn, (array)$_cfnames, true) !== false) |
|
711 | 710 | { |
712 | 711 | $cf = $tcf_name; |
713 | 712 | break; |
@@ -715,10 +714,10 @@ discard block |
||
715 | 714 | } |
716 | 715 | unset($filter[$name]); |
717 | 716 | $cf_name = $this->get_cf_name($cf); |
718 | - if (!isset($this->customfields[$cf_name])) continue; // ignore unavailable CF |
|
719 | - $join .= str_replace('extra_filter','extra_filter'.$extra_filter,$this->extra_join_filter. |
|
717 | + if (!isset($this->customfields[$cf_name])) continue; // ignore unavailable CF |
|
718 | + $join .= str_replace('extra_filter', 'extra_filter'.$extra_filter, $this->extra_join_filter. |
|
720 | 719 | ' AND extra_filter.'.$this->extra_key.'='.$this->db->quote($cf_name). |
721 | - ' AND '.str_replace($cf,'extra_filter.'.$this->extra_value,$val)); |
|
720 | + ' AND '.str_replace($cf, 'extra_filter.'.$this->extra_value, $val)); |
|
722 | 721 | ++$extra_filter; |
723 | 722 | } |
724 | 723 | } |
@@ -729,15 +728,14 @@ discard block |
||
729 | 728 | if (is_array($only_keys)) |
730 | 729 | { |
731 | 730 | $only_keys = array_values($only_keys); |
732 | - $only_keys[0] = 'DISTINCT '.($only_keys[0] != $this->autoinc_id ? $only_keys[0] : |
|
733 | - $this->table_name.'.'.$this->autoinc_id.' AS '.$this->autoinc_id); |
|
731 | + $only_keys[0] = 'DISTINCT '.($only_keys[0] != $this->autoinc_id ? $only_keys[0] : $this->table_name.'.'.$this->autoinc_id.' AS '.$this->autoinc_id); |
|
734 | 732 | } |
735 | 733 | else |
736 | 734 | { |
737 | 735 | $only_keys = 'DISTINCT '.$only_keys; |
738 | 736 | } |
739 | 737 | } |
740 | - return parent::search($criteria,$only_keys,$order_by,$extra_cols,$wildcard,$empty,$op,$start,$filter,$join,$need_full_no_count); |
|
738 | + return parent::search($criteria, $only_keys, $order_by, $extra_cols, $wildcard, $empty, $op, $start, $filter, $join, $need_full_no_count); |
|
741 | 739 | } |
742 | 740 | |
743 | 741 | /** |
@@ -759,7 +757,7 @@ discard block |
||
759 | 757 | */ |
760 | 758 | function get_cf_name($field) |
761 | 759 | { |
762 | - return substr($field,1); |
|
760 | + return substr($field, 1); |
|
763 | 761 | } |
764 | 762 | |
765 | 763 | /** |
@@ -781,7 +779,7 @@ discard block |
||
781 | 779 | */ |
782 | 780 | function is_multiple($name) |
783 | 781 | { |
784 | - return $this->allow_multiple_values && in_array($this->customfields[$name]['type'],array('select','select-account')) && |
|
782 | + return $this->allow_multiple_values && in_array($this->customfields[$name]['type'], array('select', 'select-account')) && |
|
785 | 783 | $this->customfields[$name]['rows'] > 1; |
786 | 784 | } |
787 | 785 | } |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | * |
69 | 69 | * @var string |
70 | 70 | */ |
71 | - var $distributionlist_view ='(SELECT contact_id, egw_addressbook_lists.list_id as list_id, egw_addressbook_lists.list_name as list_name, egw_addressbook_lists.list_owner as list_owner FROM egw_addressbook_lists, egw_addressbook2list where egw_addressbook_lists.list_id=egw_addressbook2list.list_id) d_view '; |
|
71 | + var $distributionlist_view = '(SELECT contact_id, egw_addressbook_lists.list_id as list_id, egw_addressbook_lists.list_name as list_name, egw_addressbook_lists.list_owner as list_owner FROM egw_addressbook_lists, egw_addressbook2list where egw_addressbook_lists.list_id=egw_addressbook2list.list_id) d_view '; |
|
72 | 72 | var $distributionlist_tabledef = array(); |
73 | 73 | /** |
74 | 74 | * @var string |
@@ -122,10 +122,10 @@ discard block |
||
122 | 122 | * In SQL we can search all columns, though a view make on real sense |
123 | 123 | */ |
124 | 124 | var $sql_cols_not_to_search = array( |
125 | - 'jpegphoto','owner','tid','private','cat_id','etag', |
|
126 | - 'modified','modifier','creator','created','tz','account_id', |
|
127 | - 'uid','carddav_name','freebusy_uri','calendar_uri', |
|
128 | - 'geo','pubkey', |
|
125 | + 'jpegphoto', 'owner', 'tid', 'private', 'cat_id', 'etag', |
|
126 | + 'modified', 'modifier', 'creator', 'created', 'tz', 'account_id', |
|
127 | + 'uid', 'carddav_name', 'freebusy_uri', 'calendar_uri', |
|
128 | + 'geo', 'pubkey', |
|
129 | 129 | ); |
130 | 130 | /** |
131 | 131 | * columns to search, if we search for a single pattern |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | const FILES_DIRECTORY = '.files'; |
166 | 166 | const FILES_PHOTO = '.files/photo.jpeg'; |
167 | 167 | const FILES_PGP_PUBKEY = '.files/pgp-pubkey.asc'; |
168 | - const FILES_SMIME_PUBKEY = '.files/smime-pubkey.crt'; |
|
168 | + const FILES_SMIME_PUBKEY = '.files/smime-pubkey.crt'; |
|
169 | 169 | |
170 | 170 | /** |
171 | 171 | * Constant for bit-field "contact_files" storing what files are available |
@@ -238,12 +238,12 @@ discard block |
||
238 | 238 | * @param string $contact_app ='addressbook' used for acl->get_grants() |
239 | 239 | * @param Api\Db $db =null |
240 | 240 | */ |
241 | - function __construct($contact_app='addressbook',Api\Db $db=null) |
|
241 | + function __construct($contact_app = 'addressbook', Api\Db $db = null) |
|
242 | 242 | { |
243 | - $this->db = is_null($db) ? $GLOBALS['egw']->db : $db; |
|
243 | + $this->db = is_null($db) ? $GLOBALS['egw']->db : $db; |
|
244 | 244 | |
245 | 245 | $this->user = $GLOBALS['egw_info']['user']['account_id']; |
246 | - $this->memberships = $GLOBALS['egw']->accounts->memberships($this->user,true); |
|
246 | + $this->memberships = $GLOBALS['egw']->accounts->memberships($this->user, true); |
|
247 | 247 | |
248 | 248 | // account backend used |
249 | 249 | if ($GLOBALS['egw_info']['server']['account_repository']) |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | } |
257 | 257 | $this->customfields = Api\Storage\Customfields::get('addressbook'); |
258 | 258 | // contacts backend (contacts in LDAP require accounts in LDAP!) |
259 | - if($GLOBALS['egw_info']['server']['contact_repository'] == 'ldap' && $this->account_repository == 'ldap') |
|
259 | + if ($GLOBALS['egw_info']['server']['contact_repository'] == 'ldap' && $this->account_repository == 'ldap') |
|
260 | 260 | { |
261 | 261 | $this->contact_repository = 'ldap'; |
262 | 262 | $this->somain = new Ldap(); |
@@ -271,11 +271,11 @@ discard block |
||
271 | 271 | $this->somain = new Sql($db); |
272 | 272 | |
273 | 273 | // remove some columns, absolutly not necessary to search in sql |
274 | - $this->columns_to_search = array_diff(array_values($this->somain->db_cols),$this->sql_cols_not_to_search); |
|
274 | + $this->columns_to_search = array_diff(array_values($this->somain->db_cols), $this->sql_cols_not_to_search); |
|
275 | 275 | } |
276 | 276 | if ($this->user) |
277 | 277 | { |
278 | - $this->grants = $this->get_grants($this->user,$contact_app); |
|
278 | + $this->grants = $this->get_grants($this->user, $contact_app); |
|
279 | 279 | } |
280 | 280 | if ($this->account_repository != 'sql' && $this->contact_repository == 'sql') |
281 | 281 | { |
@@ -292,8 +292,8 @@ discard block |
||
292 | 292 | } |
293 | 293 | if ($this->contact_repository == 'sql' || $this->contact_repository == 'sql-ldap') |
294 | 294 | { |
295 | - $tda2list = $this->db->get_table_definitions('api','egw_addressbook2list'); |
|
296 | - $tdlists = $this->db->get_table_definitions('api','egw_addressbook_lists'); |
|
295 | + $tda2list = $this->db->get_table_definitions('api', 'egw_addressbook2list'); |
|
296 | + $tdlists = $this->db->get_table_definitions('api', 'egw_addressbook_lists'); |
|
297 | 297 | $this->distributionlist_tabledef = array('fd' => array( |
298 | 298 | $this->distri_id => $tda2list['fd'][$this->distri_id], |
299 | 299 | $this->distri_owner => $tdlists['fd'][$this->distri_owner], |
@@ -303,11 +303,11 @@ discard block |
||
303 | 303 | ); |
304 | 304 | } |
305 | 305 | // ToDo: it should be the other way arround, the backend should set the grants it uses |
306 | - $this->somain->grants =& $this->grants; |
|
306 | + $this->somain->grants = & $this->grants; |
|
307 | 307 | |
308 | - if($this->somain instanceof Sql) |
|
308 | + if ($this->somain instanceof Sql) |
|
309 | 309 | { |
310 | - $this->soextra =& $this->somain; |
|
310 | + $this->soextra = & $this->somain; |
|
311 | 311 | } |
312 | 312 | else |
313 | 313 | { |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | |
328 | 328 | // Add in deleted type, if holding deleted contacts |
329 | 329 | $config = Api\Config::read('phpgwapi'); |
330 | - if($config['history']) |
|
330 | + if ($config['history']) |
|
331 | 331 | { |
332 | 332 | $this->content_types[self::DELETED_TYPE] = array( |
333 | 333 | 'name' => lang('Deleted'), |
@@ -346,18 +346,18 @@ discard block |
||
346 | 346 | * @param string $contact_app ='addressbook' |
347 | 347 | * @return array |
348 | 348 | */ |
349 | - function get_grants($user, $contact_app='addressbook', $preferences=null) |
|
349 | + function get_grants($user, $contact_app = 'addressbook', $preferences = null) |
|
350 | 350 | { |
351 | 351 | if (!isset($preferences)) $preferences = $GLOBALS['egw_info']['user']['preferences']; |
352 | 352 | |
353 | 353 | if ($user) |
354 | 354 | { |
355 | 355 | // contacts backend (contacts in LDAP require accounts in LDAP!) |
356 | - if($GLOBALS['egw_info']['server']['contact_repository'] == 'ldap' && $this->account_repository == 'ldap') |
|
356 | + if ($GLOBALS['egw_info']['server']['contact_repository'] == 'ldap' && $this->account_repository == 'ldap') |
|
357 | 357 | { |
358 | 358 | // static grants from ldap: all rights for the own personal addressbook and the group ones of the meberships |
359 | 359 | $grants = array($user => ~0); |
360 | - foreach($GLOBALS['egw']->accounts->memberships($user,true) as $gid) |
|
360 | + foreach ($GLOBALS['egw']->accounts->memberships($user, true) as $gid) |
|
361 | 361 | { |
362 | 362 | $grants[$gid] = ~0; |
363 | 363 | } |
@@ -366,22 +366,22 @@ discard block |
||
366 | 366 | { |
367 | 367 | // group grants are now grants for the group addressbook and NOT grants for all its members, |
368 | 368 | // therefor the param false! |
369 | - $grants = $GLOBALS['egw']->acl->get_grants($contact_app,false,$user); |
|
369 | + $grants = $GLOBALS['egw']->acl->get_grants($contact_app, false, $user); |
|
370 | 370 | } |
371 | 371 | // add grants for accounts: if account_selection not in ('none','groupmembers'): everyone has read access, |
372 | 372 | // if he has not set the hide_accounts preference |
373 | 373 | // ToDo: be more specific for 'groupmembers', they should be able to see the groupmembers |
374 | - if (!in_array($preferences['common']['account_selection'], array('none','groupmembers'))) |
|
374 | + if (!in_array($preferences['common']['account_selection'], array('none', 'groupmembers'))) |
|
375 | 375 | { |
376 | 376 | $grants[0] = Api\Acl::READ; |
377 | 377 | } |
378 | 378 | // add account grants for admins (only for current user!) |
379 | 379 | if ($user == $this->user && $this->is_admin()) // admin rights can be limited by ACL! |
380 | 380 | { |
381 | - $grants[0] = Api\Acl::READ; // admins always have read-access |
|
382 | - if (!$GLOBALS['egw']->acl->check('account_access',16,'admin')) $grants[0] |= Api\Acl::EDIT; |
|
383 | - if (!$GLOBALS['egw']->acl->check('account_access',4,'admin')) $grants[0] |= Api\Acl::ADD; |
|
384 | - if (!$GLOBALS['egw']->acl->check('account_access',32,'admin')) $grants[0] |= Api\Acl::DELETE; |
|
381 | + $grants[0] = Api\Acl::READ; // admins always have read-access |
|
382 | + if (!$GLOBALS['egw']->acl->check('account_access', 16, 'admin')) $grants[0] |= Api\Acl::EDIT; |
|
383 | + if (!$GLOBALS['egw']->acl->check('account_access', 4, 'admin')) $grants[0] |= Api\Acl::ADD; |
|
384 | + if (!$GLOBALS['egw']->acl->check('account_access', 32, 'admin')) $grants[0] |= Api\Acl::DELETE; |
|
385 | 385 | } |
386 | 386 | // allow certain groups to edit contact-data of accounts |
387 | 387 | if (self::allow_account_edit($user)) |
@@ -405,11 +405,11 @@ discard block |
||
405 | 405 | * @param array $contact =null for future use, where admins might not be admins for all accounts |
406 | 406 | * @return boolean |
407 | 407 | */ |
408 | - function is_admin($contact=null) |
|
408 | + function is_admin($contact = null) |
|
409 | 409 | { |
410 | - unset($contact); // not (yet) used |
|
410 | + unset($contact); // not (yet) used |
|
411 | 411 | |
412 | - return isset($GLOBALS['egw_info']['user']['apps']['admin']) && !$GLOBALS['egw']->acl->check('account_access',16,'admin'); |
|
412 | + return isset($GLOBALS['egw_info']['user']['apps']['admin']) && !$GLOBALS['egw']->acl->check('account_access', 16, 'admin'); |
|
413 | 413 | } |
414 | 414 | |
415 | 415 | /** |
@@ -418,7 +418,7 @@ discard block |
||
418 | 418 | * @param int $user =null default $this->user |
419 | 419 | * @return boolean |
420 | 420 | */ |
421 | - function allow_account_edit($user=null) |
|
421 | + function allow_account_edit($user = null) |
|
422 | 422 | { |
423 | 423 | return $GLOBALS['egw_info']['server']['allow_account_edit'] && |
424 | 424 | array_intersect($GLOBALS['egw_info']['server']['allow_account_edit'], |
@@ -432,9 +432,9 @@ discard block |
||
432 | 432 | * @param array $field_names =null custom fields to read, default all |
433 | 433 | * @return array id => name => value |
434 | 434 | */ |
435 | - function read_customfields($ids,$field_names=null) |
|
435 | + function read_customfields($ids, $field_names = null) |
|
436 | 436 | { |
437 | - return $this->soextra->read_customfields($ids,$field_names); |
|
437 | + return $this->soextra->read_customfields($ids, $field_names); |
|
438 | 438 | } |
439 | 439 | |
440 | 440 | /** |
@@ -443,26 +443,26 @@ discard block |
||
443 | 443 | * @param int|array $ids |
444 | 444 | * @return array id => name => value |
445 | 445 | */ |
446 | - function read_distributionlist($ids, $dl_allowed=array()) |
|
446 | + function read_distributionlist($ids, $dl_allowed = array()) |
|
447 | 447 | { |
448 | 448 | if ($this->contact_repository == 'ldap') |
449 | 449 | { |
450 | - return array(); // ldap does not support distributionlists |
|
450 | + return array(); // ldap does not support distributionlists |
|
451 | 451 | } |
452 | - foreach($ids as $key => $id) |
|
452 | + foreach ($ids as $key => $id) |
|
453 | 453 | { |
454 | 454 | if (!is_numeric($id)) unset($ids[$key]); |
455 | 455 | } |
456 | - if (!$ids) return array(); // nothing to do, eg. all these contacts are in ldap |
|
456 | + if (!$ids) return array(); // nothing to do, eg. all these contacts are in ldap |
|
457 | 457 | $fields = array(); |
458 | - $filter[$this->distri_id]=$ids; |
|
459 | - if (count($dl_allowed)) $filter[$this->distri_key]=$dl_allowed; |
|
460 | - $distri_view = str_replace(') d_view',' and '.$this->distri_id.' in ('.implode(',',$ids).')) d_view',$this->distributionlist_view); |
|
458 | + $filter[$this->distri_id] = $ids; |
|
459 | + if (count($dl_allowed)) $filter[$this->distri_key] = $dl_allowed; |
|
460 | + $distri_view = str_replace(') d_view', ' and '.$this->distri_id.' in ('.implode(',', $ids).')) d_view', $this->distributionlist_view); |
|
461 | 461 | #_debug_array($this->distributionlist_tabledef); |
462 | - foreach($this->db->select($distri_view, '*', $filter, __LINE__, __FILE__, |
|
462 | + foreach ($this->db->select($distri_view, '*', $filter, __LINE__, __FILE__, |
|
463 | 463 | false, 'ORDER BY '.$this->distri_id, false, 0, '', $this->distributionlist_tabledef) as $row) |
464 | 464 | { |
465 | - if ((isset($row[$this->distri_id])&&strlen($row[$this->distri_value])>0)) |
|
465 | + if ((isset($row[$this->distri_id]) && strlen($row[$this->distri_value]) > 0)) |
|
466 | 466 | { |
467 | 467 | $fields[$row[$this->distri_id]][$row[$this->distri_key]] = $row[$this->distri_value].' ('. |
468 | 468 | Api\Accounts::username($row[$this->distri_owner]).')'; |
@@ -504,7 +504,7 @@ discard block |
||
504 | 504 | * @param int $check_etag =null |
505 | 505 | * @return boolean|int true on success or false on failiure, 0 if etag does not match |
506 | 506 | */ |
507 | - function delete($contact,$check_etag=null) |
|
507 | + function delete($contact, $check_etag = null) |
|
508 | 508 | { |
509 | 509 | if (is_array($contact)) $contact = $contact['id']; |
510 | 510 | |
@@ -515,7 +515,7 @@ discard block |
||
515 | 515 | if ($this->somain->delete($where)) |
516 | 516 | { |
517 | 517 | // delete customfields, can return 0 if there are no customfields |
518 | - if(!($this->somain instanceof Sql)) |
|
518 | + if (!($this->somain instanceof Sql)) |
|
519 | 519 | { |
520 | 520 | $this->soextra->delete_customfields(array($this->extra_id => $contact)); |
521 | 521 | } |
@@ -535,7 +535,7 @@ discard block |
||
535 | 535 | } |
536 | 536 | return true; |
537 | 537 | } |
538 | - return $check_etag ? 0 : false; // if etag given, we return 0 on failure, thought it could also mean the whole contact does not exist |
|
538 | + return $check_etag ? 0 : false; // if etag given, we return 0 on failure, thought it could also mean the whole contact does not exist |
|
539 | 539 | } |
540 | 540 | |
541 | 541 | /** |
@@ -586,9 +586,9 @@ discard block |
||
586 | 586 | } |
587 | 587 | } |
588 | 588 | } |
589 | - if($error_nr) return $error_nr; |
|
589 | + if ($error_nr) return $error_nr; |
|
590 | 590 | |
591 | - return false; // no error |
|
591 | + return false; // no error |
|
592 | 592 | } |
593 | 593 | |
594 | 594 | /** |
@@ -601,20 +601,20 @@ discard block |
||
601 | 601 | { |
602 | 602 | if (empty($contact_id)) |
603 | 603 | { |
604 | - return false; // no need to pass to backend, will fail anyway |
|
604 | + return false; // no need to pass to backend, will fail anyway |
|
605 | 605 | } |
606 | - if (!is_array($contact_id) && substr($contact_id,0,8) == 'account:') |
|
606 | + if (!is_array($contact_id) && substr($contact_id, 0, 8) == 'account:') |
|
607 | 607 | { |
608 | - $contact_id = array('account_id' => (int) substr($contact_id,8)); |
|
608 | + $contact_id = array('account_id' => (int)substr($contact_id, 8)); |
|
609 | 609 | } |
610 | 610 | // read main data |
611 | - $backend =& $this->get_backend($contact_id); |
|
611 | + $backend = & $this->get_backend($contact_id); |
|
612 | 612 | if (!($contact = $backend->read($contact_id))) |
613 | 613 | { |
614 | 614 | return $contact; |
615 | 615 | } |
616 | - $dl_list=$this->read_distributionlist(array($contact['id'])); |
|
617 | - if (count($dl_list)) $contact['distrib_lists']=implode("\n",$dl_list[$contact['id']]); |
|
616 | + $dl_list = $this->read_distributionlist(array($contact['id'])); |
|
617 | + if (count($dl_list)) $contact['distrib_lists'] = implode("\n", $dl_list[$contact['id']]); |
|
618 | 618 | return $this->db2data($contact); |
619 | 619 | } |
620 | 620 | |
@@ -637,18 +637,18 @@ discard block |
||
637 | 637 | * @param boolean $ignore_acl =false true: no acl check |
638 | 638 | * @return array of matching rows (the row is an array of the cols) or False |
639 | 639 | */ |
640 | - function &search($criteria,$only_keys=True,$order_by='',$extra_cols='',$wildcard='',$empty=False,$op='AND',$start=false,$filter=null,$join='', $ignore_acl=false) |
|
640 | + function &search($criteria, $only_keys = True, $order_by = '', $extra_cols = '', $wildcard = '', $empty = False, $op = 'AND', $start = false, $filter = null, $join = '', $ignore_acl = false) |
|
641 | 641 | { |
642 | 642 | //error_log(__METHOD__.'('.array2string($criteria,true).','.array2string($only_keys).",'$order_by','$extra_cols','$wildcard','$empty','$op',".array2string($start).','.array2string($filter,true).",'$join')"); |
643 | 643 | |
644 | 644 | // Handle 'None' country option |
645 | - if(is_array($filter) && $filter['adr_one_countrycode'] == '-custom-') |
|
645 | + if (is_array($filter) && $filter['adr_one_countrycode'] == '-custom-') |
|
646 | 646 | { |
647 | 647 | $filter[] = 'adr_one_countrycode IS NULL'; |
648 | 648 | unset($filter['adr_one_countrycode']); |
649 | 649 | } |
650 | 650 | // Hide deleted items unless type is specifically deleted |
651 | - if(!is_array($filter)) $filter = $filter ? (array) $filter : array(); |
|
651 | + if (!is_array($filter)) $filter = $filter ? (array)$filter : array(); |
|
652 | 652 | |
653 | 653 | if (isset($filter['cols_to_search'])) |
654 | 654 | { |
@@ -657,22 +657,22 @@ discard block |
||
657 | 657 | } |
658 | 658 | |
659 | 659 | // if no tid set or tid==='' do NOT return deleted entries ($tid === null returns all entries incl. deleted) |
660 | - if(!array_key_exists('tid', $filter) || $filter['tid'] === '') |
|
660 | + if (!array_key_exists('tid', $filter) || $filter['tid'] === '') |
|
661 | 661 | { |
662 | - if ($join && strpos($join,'RIGHT JOIN') !== false) // used eg. to search for groups |
|
662 | + if ($join && strpos($join, 'RIGHT JOIN') !== false) // used eg. to search for groups |
|
663 | 663 | { |
664 | - $filter[] = '(contact_tid != \'' . self::DELETED_TYPE . '\' OR contact_tid IS NULL)'; |
|
664 | + $filter[] = '(contact_tid != \''.self::DELETED_TYPE.'\' OR contact_tid IS NULL)'; |
|
665 | 665 | } |
666 | 666 | else |
667 | 667 | { |
668 | - $filter[] = 'contact_tid != \'' . self::DELETED_TYPE . '\''; |
|
668 | + $filter[] = 'contact_tid != \''.self::DELETED_TYPE.'\''; |
|
669 | 669 | } |
670 | 670 | } |
671 | - elseif(is_null($filter['tid'])) |
|
671 | + elseif (is_null($filter['tid'])) |
|
672 | 672 | { |
673 | - unset($filter['tid']); // return all entries incl. deleted |
|
673 | + unset($filter['tid']); // return all entries incl. deleted |
|
674 | 674 | } |
675 | - $backend = $this->get_backend(null,$filter['owner']); |
|
675 | + $backend = $this->get_backend(null, $filter['owner']); |
|
676 | 676 | // single string to search for --> create so_sql conformant search criterial for the standard search columns |
677 | 677 | if ($criteria && !is_array($criteria)) |
678 | 678 | { |
@@ -693,34 +693,34 @@ discard block |
||
693 | 693 | { |
694 | 694 | $cols = $this->account_cols_to_search; |
695 | 695 | } |
696 | - if($backend instanceof Sql) |
|
696 | + if ($backend instanceof Sql) |
|
697 | 697 | { |
698 | 698 | // Keep a string, let the parent handle it |
699 | 699 | $criteria = $search; |
700 | 700 | |
701 | - foreach($cols as $key => &$col) |
|
701 | + foreach ($cols as $key => &$col) |
|
702 | 702 | { |
703 | - if($col != Sql::EXTRA_VALUE && |
|
703 | + if ($col != Sql::EXTRA_VALUE && |
|
704 | 704 | $col != Sql::EXTRA_TABLE.'.'.Sql::EXTRA_VALUE && |
705 | 705 | !array_key_exists($col, $backend->db_cols)) |
706 | 706 | { |
707 | - if(!($col = array_search($col, $backend->db_cols))) |
|
707 | + if (!($col = array_search($col, $backend->db_cols))) |
|
708 | 708 | { |
709 | 709 | // Can't search this column, it will error if we try |
710 | 710 | unset($cols[$key]); |
711 | 711 | } |
712 | 712 | } |
713 | - if ($col=='contact_id') $col='egw_addressbook.contact_id'; |
|
713 | + if ($col == 'contact_id') $col = 'egw_addressbook.contact_id'; |
|
714 | 714 | } |
715 | 715 | |
716 | 716 | $backend->columns_to_search = $cols; |
717 | 717 | } |
718 | 718 | else |
719 | 719 | { |
720 | - foreach($cols as $col) |
|
720 | + foreach ($cols as $col) |
|
721 | 721 | { |
722 | 722 | // remove from LDAP backend not understood use-AND-syntax |
723 | - $criteria[$col] = str_replace(' +',' ',$search); |
|
723 | + $criteria[$col] = str_replace(' +', ' ', $search); |
|
724 | 724 | } |
725 | 725 | } |
726 | 726 | } |
@@ -744,7 +744,7 @@ discard block |
||
744 | 744 | |
745 | 745 | if ($rows) |
746 | 746 | { |
747 | - foreach($rows as $n => $row) |
|
747 | + foreach ($rows as $n => $row) |
|
748 | 748 | { |
749 | 749 | $rows[$n] = $this->db2data($row); |
750 | 750 | } |
@@ -767,7 +767,7 @@ discard block |
||
767 | 767 | */ |
768 | 768 | function organisations($param) |
769 | 769 | { |
770 | - if (!method_exists($this->somain,'organisations')) |
|
770 | + if (!method_exists($this->somain, 'organisations')) |
|
771 | 771 | { |
772 | 772 | $this->total = 0; |
773 | 773 | return false; |
@@ -776,16 +776,16 @@ discard block |
||
776 | 776 | { |
777 | 777 | $search = $param['search']; |
778 | 778 | $param['search'] = array(); |
779 | - if($this->somain instanceof Sql) |
|
779 | + if ($this->somain instanceof Sql) |
|
780 | 780 | { |
781 | 781 | // Keep the string, let the parent deal with it |
782 | 782 | $param['search'] = $search; |
783 | 783 | } |
784 | 784 | else |
785 | 785 | { |
786 | - foreach($this->columns_to_search as $col) |
|
786 | + foreach ($this->columns_to_search as $col) |
|
787 | 787 | { |
788 | - if ($col != 'contact_value') $param['search'][$col] = $search; // we dont search the customfields |
|
788 | + if ($col != 'contact_value') $param['search'][$col] = $search; // we dont search the customfields |
|
789 | 789 | } |
790 | 790 | } |
791 | 791 | } |
@@ -793,13 +793,13 @@ discard block |
||
793 | 793 | { |
794 | 794 | $param['search'] = $this->data2db($param['search']); |
795 | 795 | } |
796 | - if(!array_key_exists('tid', $param['col_filter']) || $param['col_filter']['tid'] === '') |
|
796 | + if (!array_key_exists('tid', $param['col_filter']) || $param['col_filter']['tid'] === '') |
|
797 | 797 | { |
798 | - $param['col_filter'][] = 'contact_tid != \'' . self::DELETED_TYPE . '\''; |
|
798 | + $param['col_filter'][] = 'contact_tid != \''.self::DELETED_TYPE.'\''; |
|
799 | 799 | } |
800 | - elseif(is_null($param['col_filter']['tid'])) |
|
800 | + elseif (is_null($param['col_filter']['tid'])) |
|
801 | 801 | { |
802 | - unset($param['col_filter']['tid']); // return all entries incl. deleted |
|
802 | + unset($param['col_filter']['tid']); // return all entries incl. deleted |
|
803 | 803 | } |
804 | 804 | |
805 | 805 | $rows = $this->somain->organisations($param); |
@@ -807,11 +807,11 @@ discard block |
||
807 | 807 | |
808 | 808 | if (!$rows) return array(); |
809 | 809 | |
810 | - foreach($rows as $n => $row) |
|
810 | + foreach ($rows as $n => $row) |
|
811 | 811 | { |
812 | - if (strpos($row['org_name'],'&')!==false) $row['org_name'] = str_replace('&','*AND*',$row['org_name']); |
|
812 | + if (strpos($row['org_name'], '&') !== false) $row['org_name'] = str_replace('&', '*AND*', $row['org_name']); |
|
813 | 813 | $rows[$n]['id'] = 'org_name:'.$row['org_name']; |
814 | - foreach(array( |
|
814 | + foreach (array( |
|
815 | 815 | 'org_unit' => lang('departments'), |
816 | 816 | 'adr_one_locality' => lang('locations'), |
817 | 817 | ) as $by => $by_label) |
@@ -822,7 +822,7 @@ discard block |
||
822 | 822 | } |
823 | 823 | else |
824 | 824 | { |
825 | - if (strpos($row[$by],'&')!==false) $row[$by] = str_replace('&','*AND*',$row[$by]); |
|
825 | + if (strpos($row[$by], '&') !== false) $row[$by] = str_replace('&', '*AND*', $row[$by]); |
|
826 | 826 | $rows[$n]['id'] .= '|||'.$by.':'.$row[$by]; |
827 | 827 | } |
828 | 828 | } |
@@ -846,7 +846,7 @@ discard block |
||
846 | 846 | */ |
847 | 847 | public function duplicates($param) |
848 | 848 | { |
849 | - if (!method_exists($this->somain,'duplicates')) |
|
849 | + if (!method_exists($this->somain, 'duplicates')) |
|
850 | 850 | { |
851 | 851 | $this->total = 0; |
852 | 852 | return false; |
@@ -855,14 +855,14 @@ discard block |
||
855 | 855 | { |
856 | 856 | $search = $param['search']; |
857 | 857 | $param['search'] = array(); |
858 | - if($this->somain instanceof Sql) |
|
858 | + if ($this->somain instanceof Sql) |
|
859 | 859 | { |
860 | 860 | // Keep the string, let the parent deal with it |
861 | 861 | $param['search'] = $search; |
862 | 862 | } |
863 | 863 | else |
864 | 864 | { |
865 | - foreach($this->columns_to_search as $col) |
|
865 | + foreach ($this->columns_to_search as $col) |
|
866 | 866 | { |
867 | 867 | // we don't search the customfields |
868 | 868 | if ($col != 'contact_value') $param['search'][$col] = $search; |
@@ -873,21 +873,21 @@ discard block |
||
873 | 873 | { |
874 | 874 | $param['search'] = $this->data2db($param['search']); |
875 | 875 | } |
876 | - if(!array_key_exists('tid', $param['col_filter']) || $param['col_filter']['tid'] === '') |
|
876 | + if (!array_key_exists('tid', $param['col_filter']) || $param['col_filter']['tid'] === '') |
|
877 | 877 | { |
878 | - $param['col_filter'][] = $this->somain->table_name.'.contact_tid != \'' . self::DELETED_TYPE . '\''; |
|
878 | + $param['col_filter'][] = $this->somain->table_name.'.contact_tid != \''.self::DELETED_TYPE.'\''; |
|
879 | 879 | } |
880 | - elseif(is_null($param['col_filter']['tid'])) |
|
880 | + elseif (is_null($param['col_filter']['tid'])) |
|
881 | 881 | { |
882 | 882 | // return all entries including deleted |
883 | 883 | unset($param['col_filter']['tid']); |
884 | 884 | } |
885 | - if(array_key_exists('filter', $param) && $param['filter'] != '') |
|
885 | + if (array_key_exists('filter', $param) && $param['filter'] != '') |
|
886 | 886 | { |
887 | 887 | $param['owner'] = $param['filter']; |
888 | 888 | unset($param['filter']); |
889 | 889 | } |
890 | - if(array_key_exists('owner', $param['col_filter']) && $param['col_filter']['owner'] != '') |
|
890 | + if (array_key_exists('owner', $param['col_filter']) && $param['col_filter']['owner'] != '') |
|
891 | 891 | { |
892 | 892 | $param['owner'] = $param['col_filter']['owner']; |
893 | 893 | unset($param['col_filter']['owner']); |
@@ -899,13 +899,13 @@ discard block |
||
899 | 899 | |
900 | 900 | if (!$rows) return array(); |
901 | 901 | |
902 | - foreach($rows as $n => $row) |
|
902 | + foreach ($rows as $n => $row) |
|
903 | 903 | { |
904 | 904 | $rows[$n]['id'] = 'duplicate:'; |
905 | - foreach(array_keys(static::$duplicate_fields) as $by) |
|
905 | + foreach (array_keys(static::$duplicate_fields) as $by) |
|
906 | 906 | { |
907 | - if (strpos($row[$by],'&')!==false) $row[$by] = str_replace('&','*AND*',$row[$by]); |
|
908 | - if($row[$by]) |
|
907 | + if (strpos($row[$by], '&') !== false) $row[$by] = str_replace('&', '*AND*', $row[$by]); |
|
908 | + if ($row[$by]) |
|
909 | 909 | { |
910 | 910 | $rows[$n]['id'] .= '|||'.$by.':'.$row[$by]; |
911 | 911 | } |
@@ -939,11 +939,11 @@ discard block |
||
939 | 939 | function deleteaccount($data) |
940 | 940 | { |
941 | 941 | $account_id = $data['account_id']; |
942 | - $new_owner = $data['new_owner']; |
|
942 | + $new_owner = $data['new_owner']; |
|
943 | 943 | |
944 | 944 | if (!$new_owner) |
945 | 945 | { |
946 | - $this->somain->delete(array('owner' => $account_id)); // so_sql_cf::delete() takes care of cfs too |
|
946 | + $this->somain->delete(array('owner' => $account_id)); // so_sql_cf::delete() takes care of cfs too |
|
947 | 947 | |
948 | 948 | if (method_exists($this->somain, 'get_lists') && |
949 | 949 | ($lists = $this->somain->get_lists($account_id))) |
@@ -953,7 +953,7 @@ discard block |
||
953 | 953 | } |
954 | 954 | else |
955 | 955 | { |
956 | - $this->somain->change_owner($account_id,$new_owner); |
|
956 | + $this->somain->change_owner($account_id, $new_owner); |
|
957 | 957 | } |
958 | 958 | } |
959 | 959 | |
@@ -964,16 +964,15 @@ discard block |
||
964 | 964 | * @param int $owner =null account_id of owner or 0 for accounts |
965 | 965 | * @return Sql|Ldap|Ads|Univention |
966 | 966 | */ |
967 | - function get_backend($keys=null,$owner=null) |
|
967 | + function get_backend($keys = null, $owner = null) |
|
968 | 968 | { |
969 | 969 | if ($owner === '') $owner = null; |
970 | 970 | |
971 | - $contact_id = !is_array($keys) ? $keys : |
|
972 | - (isset($keys['id']) ? $keys['id'] : $keys['contact_id']); |
|
971 | + $contact_id = !is_array($keys) ? $keys : (isset($keys['id']) ? $keys['id'] : $keys['contact_id']); |
|
973 | 972 | |
974 | 973 | if ($this->contact_repository != $this->account_repository && is_object($this->so_accounts) && |
975 | 974 | (!is_null($owner) && !$owner || is_array($keys) && $keys['account_id'] || !is_null($contact_id) && |
976 | - ($this->contact_repository == 'sql' && (!is_numeric($contact_id) && !is_array($contact_id) )|| |
|
975 | + ($this->contact_repository == 'sql' && (!is_numeric($contact_id) && !is_array($contact_id)) || |
|
977 | 976 | $this->contact_repository == 'ldap' && is_numeric($contact_id)))) |
978 | 977 | { |
979 | 978 | return $this->so_accounts; |
@@ -989,20 +988,20 @@ discard block |
||
989 | 988 | * @param int $owner =null account_id of owner or 0 for accounts |
990 | 989 | * @return array with eGW contact field names |
991 | 990 | */ |
992 | - function get_fields($type='all',$contact_id=null,$owner=null) |
|
991 | + function get_fields($type = 'all', $contact_id = null, $owner = null) |
|
993 | 992 | { |
994 | - $def = $this->db->get_table_definitions('api','egw_addressbook'); |
|
993 | + $def = $this->db->get_table_definitions('api', 'egw_addressbook'); |
|
995 | 994 | |
996 | 995 | $all_fields = array(); |
997 | - foreach(array_keys($def['fd']) as $field) |
|
996 | + foreach (array_keys($def['fd']) as $field) |
|
998 | 997 | { |
999 | - $all_fields[] = substr($field,0,8) == 'contact_' ? substr($field,8) : $field; |
|
998 | + $all_fields[] = substr($field, 0, 8) == 'contact_' ? substr($field, 8) : $field; |
|
1000 | 999 | } |
1001 | 1000 | if ($type == 'all') |
1002 | 1001 | { |
1003 | 1002 | return $all_fields; |
1004 | 1003 | } |
1005 | - $backend = $this->get_backend($contact_id,$owner); |
|
1004 | + $backend = $this->get_backend($contact_id, $owner); |
|
1006 | 1005 | |
1007 | 1006 | $supported_fields = method_exists($backend, 'supported_fields') ? $backend->supported_fields() : $all_fields; |
1008 | 1007 | |
@@ -1010,7 +1009,7 @@ discard block |
||
1010 | 1009 | { |
1011 | 1010 | return $supported_fields; |
1012 | 1011 | } |
1013 | - return array_diff($all_fields,$supported_fields); |
|
1012 | + return array_diff($all_fields, $supported_fields); |
|
1014 | 1013 | } |
1015 | 1014 | |
1016 | 1015 | /** |
@@ -1026,7 +1025,7 @@ discard block |
||
1026 | 1025 | function migrate2ldap($type) |
1027 | 1026 | { |
1028 | 1027 | //error_log(__METHOD__."(".array2string($type).")"); |
1029 | - $sql_contacts = new Sql(); |
|
1028 | + $sql_contacts = new Sql(); |
|
1030 | 1029 | if ($type == 'accounts-back-ads') |
1031 | 1030 | { |
1032 | 1031 | $ldap_contacts = new Ads(); |
@@ -1049,10 +1048,10 @@ discard block |
||
1049 | 1048 | $filter = count($do) == 2 ? null : |
1050 | 1049 | array($do[0] == 'contacts' ? 'contact_owner != 0' : 'contact_owner = 0'); |
1051 | 1050 | |
1052 | - while (($contacts = $sql_contacts->search(false,false,'n_family,n_given','','',false,'AND', |
|
1053 | - array($start,$num),$filter))) |
|
1051 | + while (($contacts = $sql_contacts->search(false, false, 'n_family,n_given', '', '', false, 'AND', |
|
1052 | + array($start, $num), $filter))) |
|
1054 | 1053 | { |
1055 | - foreach($contacts as $contact) |
|
1054 | + foreach ($contacts as $contact) |
|
1056 | 1055 | { |
1057 | 1056 | if ($contact['account_id']) $contact['id'] = $GLOBALS['egw']->accounts->id2name($contact['account_id']); |
1058 | 1057 | |
@@ -1073,12 +1072,12 @@ discard block |
||
1073 | 1072 | } |
1074 | 1073 | } |
1075 | 1074 | // direction LDAP --> SQL: either "sql" (contacts and accounts) or "accounts-back" (only accounts) |
1076 | - if (($do = array_intersect(array('accounts-back','sql'), $type))) |
|
1075 | + if (($do = array_intersect(array('accounts-back', 'sql'), $type))) |
|
1077 | 1076 | { |
1078 | 1077 | //error_log(__METHOD__."(".array2string($type).") do=".array2string($type)); |
1079 | 1078 | $filter = in_array('sql', $do) ? null : array('owner' => 0); |
1080 | 1079 | |
1081 | - foreach($ldap_contacts->search(false,false,'n_family,n_given','','',false,'AND', |
|
1080 | + foreach ($ldap_contacts->search(false, false, 'n_family,n_given', '', '', false, 'AND', |
|
1082 | 1081 | false, $filter) as $contact) |
1083 | 1082 | { |
1084 | 1083 | //error_log(__METHOD__."(".array2string($type).") do=".array2string($type)." migrating ".array2string($contact)); |
@@ -1087,7 +1086,7 @@ discard block |
||
1087 | 1086 | $contact = $ldap_contacts->read($contact['id']); |
1088 | 1087 | } |
1089 | 1088 | $old_contact_id = $contact['id']; |
1090 | - unset($contact['id']); // ldap uid/account_lid |
|
1089 | + unset($contact['id']); // ldap uid/account_lid |
|
1091 | 1090 | if ($contact['account_id'] && ($old = $sql_contacts->read(array('account_id' => $contact['account_id'])))) |
1092 | 1091 | { |
1093 | 1092 | $contact['id'] = $old['id']; |
@@ -1099,24 +1098,24 @@ discard block |
||
1099 | 1098 | { |
1100 | 1099 | echo '<p style="margin: 0px;">'.$n.': '.$contact['n_fn']. |
1101 | 1100 | ($contact['org_name'] ? ' ('.$contact['org_name'].')' : '')." --> SQL (". |
1102 | - ($contact['owner']?lang('User'):lang('Contact')).")<br>\n"; |
|
1101 | + ($contact['owner'] ?lang('User') : lang('Contact')).")<br>\n"; |
|
1103 | 1102 | |
1104 | 1103 | $new_contact_id = $sql_contacts->data['id']; |
1105 | - echo " " . $old_contact_id . " --> " . $new_contact_id . " / "; |
|
1104 | + echo " ".$old_contact_id." --> ".$new_contact_id." / "; |
|
1106 | 1105 | |
1107 | - $this->db->update('egw_links',array( |
|
1106 | + $this->db->update('egw_links', array( |
|
1108 | 1107 | 'link_id1' => $new_contact_id, |
1109 | - ),array( |
|
1108 | + ), array( |
|
1110 | 1109 | 'link_app1' => 'addressbook', |
1111 | 1110 | 'link_id1' => $old_contact_id |
1112 | - ),__LINE__,__FILE__); |
|
1111 | + ), __LINE__, __FILE__); |
|
1113 | 1112 | |
1114 | - $this->db->update('egw_links',array( |
|
1113 | + $this->db->update('egw_links', array( |
|
1115 | 1114 | 'link_id2' => $new_contact_id, |
1116 | - ),array( |
|
1115 | + ), array( |
|
1117 | 1116 | 'link_app2' => 'addressbook', |
1118 | 1117 | 'link_id2' => $old_contact_id |
1119 | - ),__LINE__,__FILE__); |
|
1118 | + ), __LINE__, __FILE__); |
|
1120 | 1119 | echo "</p>\n"; |
1121 | 1120 | } |
1122 | 1121 | else |
@@ -1136,25 +1135,25 @@ discard block |
||
1136 | 1135 | * @param string $extra_labels =null first labels if given (already translated) |
1137 | 1136 | * @return array with id => label pairs or false if backend does not support lists |
1138 | 1137 | */ |
1139 | - function get_lists($required=Api\Acl::READ,$extra_labels=null) |
|
1138 | + function get_lists($required = Api\Acl::READ, $extra_labels = null) |
|
1140 | 1139 | { |
1141 | 1140 | $lists = is_array($extra_labels) ? $extra_labels : array(); |
1142 | 1141 | |
1143 | - if (method_exists($this->somain,'get_lists')) |
|
1142 | + if (method_exists($this->somain, 'get_lists')) |
|
1144 | 1143 | { |
1145 | 1144 | $uids = array(); |
1146 | - foreach($this->grants as $uid => $rights) |
|
1145 | + foreach ($this->grants as $uid => $rights) |
|
1147 | 1146 | { |
1148 | 1147 | // only requests groups / list in accounts addressbook for read |
1149 | 1148 | if (!$uid && $required != Api\Acl::READ) continue; |
1150 | 1149 | |
1151 | - if (($rights & $required) == $required) |
|
1150 | + if (($rights&$required) == $required) |
|
1152 | 1151 | { |
1153 | 1152 | $uids[] = $uid; |
1154 | 1153 | } |
1155 | 1154 | } |
1156 | 1155 | |
1157 | - foreach($this->somain->get_lists($uids) as $list_id => $data) |
|
1156 | + foreach ($this->somain->get_lists($uids) as $list_id => $data) |
|
1158 | 1157 | { |
1159 | 1158 | $lists[$list_id] = $data['list_name']; |
1160 | 1159 | if ($data['list_owner'] != $this->user) |
@@ -1169,7 +1168,7 @@ discard block |
||
1169 | 1168 | if ($GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts'] !== '1' && |
1170 | 1169 | $GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_groups_as_lists'] == '0') |
1171 | 1170 | { |
1172 | - foreach($GLOBALS['egw']->accounts->search(array( |
|
1171 | + foreach ($GLOBALS['egw']->accounts->search(array( |
|
1173 | 1172 | 'type' => 'groups' |
1174 | 1173 | )) as $account_id => $group) |
1175 | 1174 | { |
@@ -1188,12 +1187,12 @@ discard block |
||
1188 | 1187 | * @param boolean $limit_in_ab =false if true only return members from the same owners addressbook |
1189 | 1188 | * @return array with list_id => array(list_id,list_name,list_owner,...) pairs |
1190 | 1189 | */ |
1191 | - function read_lists($keys,$member_attr=null,$limit_in_ab=false) |
|
1190 | + function read_lists($keys, $member_attr = null, $limit_in_ab = false) |
|
1192 | 1191 | { |
1193 | 1192 | $backend = (string)$limit_in_ab === '0' && $this->so_accounts ? $this->so_accounts : $this->somain; |
1194 | 1193 | if (!method_exists($backend, 'get_lists')) return false; |
1195 | 1194 | |
1196 | - return $backend->get_lists($keys,null,$member_attr,$limit_in_ab); |
|
1195 | + return $backend->get_lists($keys, null, $member_attr, $limit_in_ab); |
|
1197 | 1196 | } |
1198 | 1197 | |
1199 | 1198 | /** |
@@ -1205,12 +1204,12 @@ discard block |
||
1205 | 1204 | * @param array &$data=array() values for keys 'list_uid', 'list_carddav_name', 'list_name' |
1206 | 1205 | * @return int|boolean integer list_id or false on error |
1207 | 1206 | */ |
1208 | - function add_list($keys,$owner,$contacts=array(),array &$data=array()) |
|
1207 | + function add_list($keys, $owner, $contacts = array(), array &$data = array()) |
|
1209 | 1208 | { |
1210 | 1209 | $backend = (string)$owner === '0' && $this->so_accounts ? $this->so_accounts : $this->somain; |
1211 | 1210 | if (!method_exists($backend, 'add_list')) return false; |
1212 | 1211 | |
1213 | - return $backend->add_list($keys,$owner,$contacts,$data); |
|
1212 | + return $backend->add_list($keys, $owner, $contacts, $data); |
|
1214 | 1213 | } |
1215 | 1214 | |
1216 | 1215 | /** |
@@ -1221,11 +1220,11 @@ discard block |
||
1221 | 1220 | * @param array $existing =null array of existing contact-id(s) of list, to not reread it, eg. array() |
1222 | 1221 | * @return false on error |
1223 | 1222 | */ |
1224 | - function add2list($contact,$list,array $existing=null) |
|
1223 | + function add2list($contact, $list, array $existing = null) |
|
1225 | 1224 | { |
1226 | - if (!method_exists($this->somain,'add2list')) return false; |
|
1225 | + if (!method_exists($this->somain, 'add2list')) return false; |
|
1227 | 1226 | |
1228 | - return $this->somain->add2list($contact,$list,$existing); |
|
1227 | + return $this->somain->add2list($contact, $list, $existing); |
|
1229 | 1228 | } |
1230 | 1229 | |
1231 | 1230 | /** |
@@ -1235,11 +1234,11 @@ discard block |
||
1235 | 1234 | * @param int $list =null list-id or null to remove from all lists |
1236 | 1235 | * @return false on error |
1237 | 1236 | */ |
1238 | - function remove_from_list($contact,$list=null) |
|
1237 | + function remove_from_list($contact, $list = null) |
|
1239 | 1238 | { |
1240 | - if (!method_exists($this->somain,'remove_from_list')) return false; |
|
1239 | + if (!method_exists($this->somain, 'remove_from_list')) return false; |
|
1241 | 1240 | |
1242 | - return $this->somain->remove_from_list($contact,$list); |
|
1241 | + return $this->somain->remove_from_list($contact, $list); |
|
1243 | 1242 | } |
1244 | 1243 | |
1245 | 1244 | /** |
@@ -1250,7 +1249,7 @@ discard block |
||
1250 | 1249 | */ |
1251 | 1250 | function delete_list($list) |
1252 | 1251 | { |
1253 | - if (!method_exists($this->somain,'delete_list')) return false; |
|
1252 | + if (!method_exists($this->somain, 'delete_list')) return false; |
|
1254 | 1253 | |
1255 | 1254 | return $this->somain->delete_list($list); |
1256 | 1255 | } |
@@ -1263,7 +1262,7 @@ discard block |
||
1263 | 1262 | */ |
1264 | 1263 | function read_list($list) |
1265 | 1264 | { |
1266 | - if (!method_exists($this->somain,'read_list')) return false; |
|
1265 | + if (!method_exists($this->somain, 'read_list')) return false; |
|
1267 | 1266 | |
1268 | 1267 | return $this->somain->read_list($list); |
1269 | 1268 | } |
@@ -1274,11 +1273,11 @@ discard block |
||
1274 | 1273 | * @param int|string $owner ='' addressbook (eg. 0 = accounts), default '' = "all" addressbook (uses the main backend) |
1275 | 1274 | * @return boolean |
1276 | 1275 | */ |
1277 | - function lists_available($owner='') |
|
1276 | + function lists_available($owner = '') |
|
1278 | 1277 | { |
1279 | - $backend =& $this->get_backend(null,$owner); |
|
1278 | + $backend = & $this->get_backend(null, $owner); |
|
1280 | 1279 | |
1281 | - return method_exists($backend,'read_list'); |
|
1280 | + return method_exists($backend, 'read_list'); |
|
1282 | 1281 | } |
1283 | 1282 | |
1284 | 1283 | /** |
@@ -1287,9 +1286,9 @@ discard block |
||
1287 | 1286 | * @param int|array $owner =null null for all lists user has access too |
1288 | 1287 | * @return int |
1289 | 1288 | */ |
1290 | - function lists_ctag($owner=null) |
|
1289 | + function lists_ctag($owner = null) |
|
1291 | 1290 | { |
1292 | - if (!method_exists($this->somain,'lists_ctag')) return 0; |
|
1291 | + if (!method_exists($this->somain, 'lists_ctag')) return 0; |
|
1293 | 1292 | |
1294 | 1293 | return $this->somain->lists_ctag($owner); |
1295 | 1294 | } |
@@ -348,7 +348,10 @@ discard block |
||
348 | 348 | */ |
349 | 349 | function get_grants($user, $contact_app='addressbook', $preferences=null) |
350 | 350 | { |
351 | - if (!isset($preferences)) $preferences = $GLOBALS['egw_info']['user']['preferences']; |
|
351 | + if (!isset($preferences)) |
|
352 | + { |
|
353 | + $preferences = $GLOBALS['egw_info']['user']['preferences']; |
|
354 | + } |
|
352 | 355 | |
353 | 356 | if ($user) |
354 | 357 | { |
@@ -376,12 +379,25 @@ discard block |
||
376 | 379 | $grants[0] = Api\Acl::READ; |
377 | 380 | } |
378 | 381 | // add account grants for admins (only for current user!) |
379 | - if ($user == $this->user && $this->is_admin()) // admin rights can be limited by ACL! |
|
382 | + if ($user == $this->user && $this->is_admin()) |
|
383 | + { |
|
384 | + // admin rights can be limited by ACL! |
|
380 | 385 | { |
381 | - $grants[0] = Api\Acl::READ; // admins always have read-access |
|
382 | - if (!$GLOBALS['egw']->acl->check('account_access',16,'admin')) $grants[0] |= Api\Acl::EDIT; |
|
383 | - if (!$GLOBALS['egw']->acl->check('account_access',4,'admin')) $grants[0] |= Api\Acl::ADD; |
|
384 | - if (!$GLOBALS['egw']->acl->check('account_access',32,'admin')) $grants[0] |= Api\Acl::DELETE; |
|
386 | + $grants[0] = Api\Acl::READ; |
|
387 | + } |
|
388 | + // admins always have read-access |
|
389 | + if (!$GLOBALS['egw']->acl->check('account_access',16,'admin')) |
|
390 | + { |
|
391 | + $grants[0] |= Api\Acl::EDIT; |
|
392 | + } |
|
393 | + if (!$GLOBALS['egw']->acl->check('account_access',4,'admin')) |
|
394 | + { |
|
395 | + $grants[0] |= Api\Acl::ADD; |
|
396 | + } |
|
397 | + if (!$GLOBALS['egw']->acl->check('account_access',32,'admin')) |
|
398 | + { |
|
399 | + $grants[0] |= Api\Acl::DELETE; |
|
400 | + } |
|
385 | 401 | } |
386 | 402 | // allow certain groups to edit contact-data of accounts |
387 | 403 | if (self::allow_account_edit($user)) |
@@ -451,12 +467,22 @@ discard block |
||
451 | 467 | } |
452 | 468 | foreach($ids as $key => $id) |
453 | 469 | { |
454 | - if (!is_numeric($id)) unset($ids[$key]); |
|
470 | + if (!is_numeric($id)) |
|
471 | + { |
|
472 | + unset($ids[$key]); |
|
473 | + } |
|
474 | + } |
|
475 | + if (!$ids) |
|
476 | + { |
|
477 | + return array(); |
|
455 | 478 | } |
456 | - if (!$ids) return array(); // nothing to do, eg. all these contacts are in ldap |
|
479 | + // nothing to do, eg. all these contacts are in ldap |
|
457 | 480 | $fields = array(); |
458 | 481 | $filter[$this->distri_id]=$ids; |
459 | - if (count($dl_allowed)) $filter[$this->distri_key]=$dl_allowed; |
|
482 | + if (count($dl_allowed)) |
|
483 | + { |
|
484 | + $filter[$this->distri_key]=$dl_allowed; |
|
485 | + } |
|
460 | 486 | $distri_view = str_replace(') d_view',' and '.$this->distri_id.' in ('.implode(',',$ids).')) d_view',$this->distributionlist_view); |
461 | 487 | #_debug_array($this->distributionlist_tabledef); |
462 | 488 | foreach($this->db->select($distri_view, '*', $filter, __LINE__, __FILE__, |
@@ -506,10 +532,16 @@ discard block |
||
506 | 532 | */ |
507 | 533 | function delete($contact,$check_etag=null) |
508 | 534 | { |
509 | - if (is_array($contact)) $contact = $contact['id']; |
|
535 | + if (is_array($contact)) |
|
536 | + { |
|
537 | + $contact = $contact['id']; |
|
538 | + } |
|
510 | 539 | |
511 | 540 | $where = array('id' => $contact); |
512 | - if ($check_etag) $where['etag'] = $check_etag; |
|
541 | + if ($check_etag) |
|
542 | + { |
|
543 | + $where['etag'] = $check_etag; |
|
544 | + } |
|
513 | 545 | |
514 | 546 | // delete mainfields |
515 | 547 | if ($this->somain->delete($where)) |
@@ -586,7 +618,10 @@ discard block |
||
586 | 618 | } |
587 | 619 | } |
588 | 620 | } |
589 | - if($error_nr) return $error_nr; |
|
621 | + if($error_nr) |
|
622 | + { |
|
623 | + return $error_nr; |
|
624 | + } |
|
590 | 625 | |
591 | 626 | return false; // no error |
592 | 627 | } |
@@ -614,7 +649,10 @@ discard block |
||
614 | 649 | return $contact; |
615 | 650 | } |
616 | 651 | $dl_list=$this->read_distributionlist(array($contact['id'])); |
617 | - if (count($dl_list)) $contact['distrib_lists']=implode("\n",$dl_list[$contact['id']]); |
|
652 | + if (count($dl_list)) |
|
653 | + { |
|
654 | + $contact['distrib_lists']=implode("\n",$dl_list[$contact['id']]); |
|
655 | + } |
|
618 | 656 | return $this->db2data($contact); |
619 | 657 | } |
620 | 658 | |
@@ -648,7 +686,10 @@ discard block |
||
648 | 686 | unset($filter['adr_one_countrycode']); |
649 | 687 | } |
650 | 688 | // Hide deleted items unless type is specifically deleted |
651 | - if(!is_array($filter)) $filter = $filter ? (array) $filter : array(); |
|
689 | + if(!is_array($filter)) |
|
690 | + { |
|
691 | + $filter = $filter ? (array) $filter : array(); |
|
692 | + } |
|
652 | 693 | |
653 | 694 | if (isset($filter['cols_to_search'])) |
654 | 695 | { |
@@ -659,10 +700,13 @@ discard block |
||
659 | 700 | // if no tid set or tid==='' do NOT return deleted entries ($tid === null returns all entries incl. deleted) |
660 | 701 | if(!array_key_exists('tid', $filter) || $filter['tid'] === '') |
661 | 702 | { |
662 | - if ($join && strpos($join,'RIGHT JOIN') !== false) // used eg. to search for groups |
|
703 | + if ($join && strpos($join,'RIGHT JOIN') !== false) |
|
704 | + { |
|
705 | + // used eg. to search for groups |
|
663 | 706 | { |
664 | 707 | $filter[] = '(contact_tid != \'' . self::DELETED_TYPE . '\' OR contact_tid IS NULL)'; |
665 | 708 | } |
709 | + } |
|
666 | 710 | else |
667 | 711 | { |
668 | 712 | $filter[] = 'contact_tid != \'' . self::DELETED_TYPE . '\''; |
@@ -710,7 +754,10 @@ discard block |
||
710 | 754 | unset($cols[$key]); |
711 | 755 | } |
712 | 756 | } |
713 | - if ($col=='contact_id') $col='egw_addressbook.contact_id'; |
|
757 | + if ($col=='contact_id') |
|
758 | + { |
|
759 | + $col='egw_addressbook.contact_id'; |
|
760 | + } |
|
714 | 761 | } |
715 | 762 | |
716 | 763 | $backend->columns_to_search = $cols; |
@@ -785,7 +832,11 @@ discard block |
||
785 | 832 | { |
786 | 833 | foreach($this->columns_to_search as $col) |
787 | 834 | { |
788 | - if ($col != 'contact_value') $param['search'][$col] = $search; // we dont search the customfields |
|
835 | + if ($col != 'contact_value') |
|
836 | + { |
|
837 | + $param['search'][$col] = $search; |
|
838 | + } |
|
839 | + // we dont search the customfields |
|
789 | 840 | } |
790 | 841 | } |
791 | 842 | } |
@@ -805,11 +856,17 @@ discard block |
||
805 | 856 | $rows = $this->somain->organisations($param); |
806 | 857 | $this->total = $this->somain->total; |
807 | 858 | |
808 | - if (!$rows) return array(); |
|
859 | + if (!$rows) |
|
860 | + { |
|
861 | + return array(); |
|
862 | + } |
|
809 | 863 | |
810 | 864 | foreach($rows as $n => $row) |
811 | 865 | { |
812 | - if (strpos($row['org_name'],'&')!==false) $row['org_name'] = str_replace('&','*AND*',$row['org_name']); |
|
866 | + if (strpos($row['org_name'],'&')!==false) |
|
867 | + { |
|
868 | + $row['org_name'] = str_replace('&','*AND*',$row['org_name']); |
|
869 | + } |
|
813 | 870 | $rows[$n]['id'] = 'org_name:'.$row['org_name']; |
814 | 871 | foreach(array( |
815 | 872 | 'org_unit' => lang('departments'), |
@@ -822,7 +879,10 @@ discard block |
||
822 | 879 | } |
823 | 880 | else |
824 | 881 | { |
825 | - if (strpos($row[$by],'&')!==false) $row[$by] = str_replace('&','*AND*',$row[$by]); |
|
882 | + if (strpos($row[$by],'&')!==false) |
|
883 | + { |
|
884 | + $row[$by] = str_replace('&','*AND*',$row[$by]); |
|
885 | + } |
|
826 | 886 | $rows[$n]['id'] .= '|||'.$by.':'.$row[$by]; |
827 | 887 | } |
828 | 888 | } |
@@ -865,7 +925,10 @@ discard block |
||
865 | 925 | foreach($this->columns_to_search as $col) |
866 | 926 | { |
867 | 927 | // we don't search the customfields |
868 | - if ($col != 'contact_value') $param['search'][$col] = $search; |
|
928 | + if ($col != 'contact_value') |
|
929 | + { |
|
930 | + $param['search'][$col] = $search; |
|
931 | + } |
|
869 | 932 | } |
870 | 933 | } |
871 | 934 | } |
@@ -897,14 +960,20 @@ discard block |
||
897 | 960 | $rows = $this->somain->duplicates($param); |
898 | 961 | $this->total = $this->somain->total; |
899 | 962 | |
900 | - if (!$rows) return array(); |
|
963 | + if (!$rows) |
|
964 | + { |
|
965 | + return array(); |
|
966 | + } |
|
901 | 967 | |
902 | 968 | foreach($rows as $n => $row) |
903 | 969 | { |
904 | 970 | $rows[$n]['id'] = 'duplicate:'; |
905 | 971 | foreach(array_keys(static::$duplicate_fields) as $by) |
906 | 972 | { |
907 | - if (strpos($row[$by],'&')!==false) $row[$by] = str_replace('&','*AND*',$row[$by]); |
|
973 | + if (strpos($row[$by],'&')!==false) |
|
974 | + { |
|
975 | + $row[$by] = str_replace('&','*AND*',$row[$by]); |
|
976 | + } |
|
908 | 977 | if($row[$by]) |
909 | 978 | { |
910 | 979 | $rows[$n]['id'] .= '|||'.$by.':'.$row[$by]; |
@@ -966,7 +1035,10 @@ discard block |
||
966 | 1035 | */ |
967 | 1036 | function get_backend($keys=null,$owner=null) |
968 | 1037 | { |
969 | - if ($owner === '') $owner = null; |
|
1038 | + if ($owner === '') |
|
1039 | + { |
|
1040 | + $owner = null; |
|
1041 | + } |
|
970 | 1042 | |
971 | 1043 | $contact_id = !is_array($keys) ? $keys : |
972 | 1044 | (isset($keys['id']) ? $keys['id'] : $keys['contact_id']); |
@@ -1038,7 +1110,10 @@ discard block |
||
1038 | 1110 | $ldap_contacts = new Ldap(null, $ds); |
1039 | 1111 | } |
1040 | 1112 | |
1041 | - if (!is_array($type)) $type = explode(',', $type); |
|
1113 | + if (!is_array($type)) |
|
1114 | + { |
|
1115 | + $type = explode(',', $type); |
|
1116 | + } |
|
1042 | 1117 | |
1043 | 1118 | $start = $n = 0; |
1044 | 1119 | $num = 100; |
@@ -1054,7 +1129,10 @@ discard block |
||
1054 | 1129 | { |
1055 | 1130 | foreach($contacts as $contact) |
1056 | 1131 | { |
1057 | - if ($contact['account_id']) $contact['id'] = $GLOBALS['egw']->accounts->id2name($contact['account_id']); |
|
1132 | + if ($contact['account_id']) |
|
1133 | + { |
|
1134 | + $contact['id'] = $GLOBALS['egw']->accounts->id2name($contact['account_id']); |
|
1135 | + } |
|
1058 | 1136 | |
1059 | 1137 | $ldap_contacts->data = $contact; |
1060 | 1138 | $n++; |
@@ -1082,10 +1160,13 @@ discard block |
||
1082 | 1160 | false, $filter) as $contact) |
1083 | 1161 | { |
1084 | 1162 | //error_log(__METHOD__."(".array2string($type).") do=".array2string($type)." migrating ".array2string($contact)); |
1085 | - if ($contact['jpegphoto']) // photo is NOT read by LDAP backend on search, need to do an extra read |
|
1163 | + if ($contact['jpegphoto']) |
|
1164 | + { |
|
1165 | + // photo is NOT read by LDAP backend on search, need to do an extra read |
|
1086 | 1166 | { |
1087 | 1167 | $contact = $ldap_contacts->read($contact['id']); |
1088 | 1168 | } |
1169 | + } |
|
1089 | 1170 | $old_contact_id = $contact['id']; |
1090 | 1171 | unset($contact['id']); // ldap uid/account_lid |
1091 | 1172 | if ($contact['account_id'] && ($old = $sql_contacts->read(array('account_id' => $contact['account_id'])))) |
@@ -1146,7 +1227,10 @@ discard block |
||
1146 | 1227 | foreach($this->grants as $uid => $rights) |
1147 | 1228 | { |
1148 | 1229 | // only requests groups / list in accounts addressbook for read |
1149 | - if (!$uid && $required != Api\Acl::READ) continue; |
|
1230 | + if (!$uid && $required != Api\Acl::READ) |
|
1231 | + { |
|
1232 | + continue; |
|
1233 | + } |
|
1150 | 1234 | |
1151 | 1235 | if (($rights & $required) == $required) |
1152 | 1236 | { |
@@ -1191,7 +1275,10 @@ discard block |
||
1191 | 1275 | function read_lists($keys,$member_attr=null,$limit_in_ab=false) |
1192 | 1276 | { |
1193 | 1277 | $backend = (string)$limit_in_ab === '0' && $this->so_accounts ? $this->so_accounts : $this->somain; |
1194 | - if (!method_exists($backend, 'get_lists')) return false; |
|
1278 | + if (!method_exists($backend, 'get_lists')) |
|
1279 | + { |
|
1280 | + return false; |
|
1281 | + } |
|
1195 | 1282 | |
1196 | 1283 | return $backend->get_lists($keys,null,$member_attr,$limit_in_ab); |
1197 | 1284 | } |
@@ -1208,7 +1295,10 @@ discard block |
||
1208 | 1295 | function add_list($keys,$owner,$contacts=array(),array &$data=array()) |
1209 | 1296 | { |
1210 | 1297 | $backend = (string)$owner === '0' && $this->so_accounts ? $this->so_accounts : $this->somain; |
1211 | - if (!method_exists($backend, 'add_list')) return false; |
|
1298 | + if (!method_exists($backend, 'add_list')) |
|
1299 | + { |
|
1300 | + return false; |
|
1301 | + } |
|
1212 | 1302 | |
1213 | 1303 | return $backend->add_list($keys,$owner,$contacts,$data); |
1214 | 1304 | } |
@@ -1223,7 +1313,10 @@ discard block |
||
1223 | 1313 | */ |
1224 | 1314 | function add2list($contact,$list,array $existing=null) |
1225 | 1315 | { |
1226 | - if (!method_exists($this->somain,'add2list')) return false; |
|
1316 | + if (!method_exists($this->somain,'add2list')) |
|
1317 | + { |
|
1318 | + return false; |
|
1319 | + } |
|
1227 | 1320 | |
1228 | 1321 | return $this->somain->add2list($contact,$list,$existing); |
1229 | 1322 | } |
@@ -1237,7 +1330,10 @@ discard block |
||
1237 | 1330 | */ |
1238 | 1331 | function remove_from_list($contact,$list=null) |
1239 | 1332 | { |
1240 | - if (!method_exists($this->somain,'remove_from_list')) return false; |
|
1333 | + if (!method_exists($this->somain,'remove_from_list')) |
|
1334 | + { |
|
1335 | + return false; |
|
1336 | + } |
|
1241 | 1337 | |
1242 | 1338 | return $this->somain->remove_from_list($contact,$list); |
1243 | 1339 | } |
@@ -1250,7 +1346,10 @@ discard block |
||
1250 | 1346 | */ |
1251 | 1347 | function delete_list($list) |
1252 | 1348 | { |
1253 | - if (!method_exists($this->somain,'delete_list')) return false; |
|
1349 | + if (!method_exists($this->somain,'delete_list')) |
|
1350 | + { |
|
1351 | + return false; |
|
1352 | + } |
|
1254 | 1353 | |
1255 | 1354 | return $this->somain->delete_list($list); |
1256 | 1355 | } |
@@ -1263,7 +1362,10 @@ discard block |
||
1263 | 1362 | */ |
1264 | 1363 | function read_list($list) |
1265 | 1364 | { |
1266 | - if (!method_exists($this->somain,'read_list')) return false; |
|
1365 | + if (!method_exists($this->somain,'read_list')) |
|
1366 | + { |
|
1367 | + return false; |
|
1368 | + } |
|
1267 | 1369 | |
1268 | 1370 | return $this->somain->read_list($list); |
1269 | 1371 | } |
@@ -1289,7 +1391,10 @@ discard block |
||
1289 | 1391 | */ |
1290 | 1392 | function lists_ctag($owner=null) |
1291 | 1393 | { |
1292 | - if (!method_exists($this->somain,'lists_ctag')) return 0; |
|
1394 | + if (!method_exists($this->somain,'lists_ctag')) |
|
1395 | + { |
|
1396 | + return 0; |
|
1397 | + } |
|
1293 | 1398 | |
1294 | 1399 | return $this->somain->lists_ctag($owner); |
1295 | 1400 | } |