Completed
Push — 16.1 ( c1c7ba...a77ba1 )
by Ralf
63:07 queued 47:45
created
calendar/inc/class.calendar_so.inc.php 1 patch
Spacing   +391 added lines, -394 removed lines patch added patch discarded remove patch
@@ -19,40 +19,40 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
 		$this->db = $GLOBALS['egw']->db;
137 137
 
138 138
 		$this->all_tables = array($this->cal_table);
139
-		foreach(array('extra','repeats','user','dates') as $name)
139
+		foreach (array('extra', 'repeats', 'user', 'dates') as $name)
140 140
 		{
141 141
 			$vname = $name.'_table';
142 142
 			$this->all_tables[] = $this->$vname = $this->cal_table.'_'.$name;
@@ -152,11 +152,11 @@  discard block
 block discarded – undo
152 152
 	 * @param boolean $deleted =false
153 153
 	 * @return string
154 154
 	 */
155
-	protected function cal_range_view($start, $end, array $_where=null, $deleted=false)
155
+	protected function cal_range_view($start, $end, array $_where = null, $deleted = false)
156 156
 	{
157 157
 		if ($GLOBALS['egw_info']['server']['no_timerange_views'] || !$start)	// using view without start-date is slower!
158 158
 		{
159
-			return $this->cal_table;	// no need / use for a view
159
+			return $this->cal_table; // no need / use for a view
160 160
 		}
161 161
 
162 162
 		$where = array();
@@ -182,11 +182,11 @@  discard block
 block discarded – undo
182 182
 	 * @param boolean $deleted =false
183 183
 	 * @return string
184 184
 	 */
185
-	protected function dates_range_view($start, $end, array $_where=null, $deleted=false)
185
+	protected function dates_range_view($start, $end, array $_where = null, $deleted = false)
186 186
 	{
187 187
 		if ($GLOBALS['egw_info']['server']['no_timerange_views'] || !$start || !$end)	// using view without start- AND end-date is slower!
188 188
 		{
189
-			return $this->dates_table;	// no need / use for a view
189
+			return $this->dates_table; // no need / use for a view
190 190
 		}
191 191
 
192 192
 		$where = array();
@@ -231,14 +231,14 @@  discard block
 block discarded – undo
231 231
 	 * @param int $remove_rejected_by_user =null add join to remove entry, if given user has rejected it
232 232
 	 * @return array of events
233 233
 	 */
234
-	function &events($start,$end,$users,$cat_id=0,$filter='all',$offset=False,$num_rows=0,array $params=array(),$remove_rejected_by_user=null)
234
+	function &events($start, $end, $users, $cat_id = 0, $filter = 'all', $offset = False, $num_rows = 0, array $params = array(), $remove_rejected_by_user = null)
235 235
 	{
236
-		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());
236
+		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());
237 237
 		$start_time = microtime(true);
238 238
 		// not everything is supported by now
239 239
 		if (!$start || !$end || is_string($params['query']) ||
240 240
 			//in_array($filter,array('owner','deleted')) ||
241
-			$params['enum_recuring']===false)
241
+			$params['enum_recuring'] === false)
242 242
 		{
243 243
 			throw new Api\Exception\AssertionFailed("Unsupported value for parameters!");
244 244
 		}
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
 		{
266 266
 			// fix $users to also prefix system users and groups (with 'u')
267 267
 			if (!is_array($users)) $users = $users ? (array)$users : array();
268
-			foreach($users as &$uid)
268
+			foreach ($users as &$uid)
269 269
 			{
270 270
 				$user_type = $user_id = null;
271 271
 				self::split_user($uid, $user_type, $user_id, true);
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
 
287 287
 		if ($params['order'])	// only order if requested
288 288
 		{
289
-			if (!preg_match('/^[a-z_ ,c]+$/i',$params['order'])) $params['order'] = 'cal_start';		// gard against SQL injection
289
+			if (!preg_match('/^[a-z_ ,c]+$/i', $params['order'])) $params['order'] = 'cal_start'; // gard against SQL injection
290 290
 			$sql .= "\nORDER BY ".$params['order'];
291 291
 		}
292 292
 
@@ -295,8 +295,8 @@  discard block
 block discarded – undo
295 295
 			$offset = 0;
296 296
 			$num_rows = -1;
297 297
 		}
298
-		$events =& $this->get_events($this->db->query($sql, __LINE__, __FILE__, $offset, $num_rows));
299
-		error_log(__METHOD__."(...) $sql --> ".number_format(microtime(true)-$start_time, 3));
298
+		$events = & $this->get_events($this->db->query($sql, __LINE__, __FILE__, $offset, $num_rows));
299
+		error_log(__METHOD__."(...) $sql --> ".number_format(microtime(true) - $start_time, 3));
300 300
 		return $events;
301 301
 	}
302 302
 
@@ -309,12 +309,12 @@  discard block
 block discarded – undo
309 309
 	 * @param int $recur_date =0 if set read the next recurrence at or after the timestamp, default 0 = read the initital one
310 310
 	 * @return array|boolean array with cal_id => event array pairs or false if entry not found
311 311
 	 */
312
-	function read($ids,$recur_date=0)
312
+	function read($ids, $recur_date = 0)
313 313
 	{
314 314
 		//error_log(__METHOD__.'('.array2string($ids).",$recur_date) ".function_backtrace());
315 315
 		$cols = self::get_columns('calendar', $this->cal_table);
316 316
 		$cols[0] = $this->db->to_varchar($this->cal_table.'.cal_id');
317
-		$cols = "$this->repeats_table.recur_type,$this->repeats_table.recur_interval,$this->repeats_table.recur_data,".implode(',',$cols);
317
+		$cols = "$this->repeats_table.recur_type,$this->repeats_table.recur_interval,$this->repeats_table.recur_data,".implode(',', $cols);
318 318
 		$join = "LEFT JOIN $this->repeats_table ON $this->cal_table.cal_id=$this->repeats_table.cal_id";
319 319
 
320 320
 		$where = array();
@@ -324,23 +324,23 @@  discard block
 block discarded – undo
324 324
 			$where['cal_uid'] = $ids;
325 325
 			$where['cal_reference'] = 0;
326 326
 		}
327
-		elseif(is_array($ids) && isset($ids[count($ids)-1]) || is_scalar($ids))	// one or more cal_id's
327
+		elseif (is_array($ids) && isset($ids[count($ids) - 1]) || is_scalar($ids))	// one or more cal_id's
328 328
 		{
329 329
 			$where['cal_id'] = $ids;
330 330
 		}
331 331
 		else	// array with column => value pairs
332 332
 		{
333 333
 			$where = $ids;
334
-			unset($ids);	// otherwise users get not read!
334
+			unset($ids); // otherwise users get not read!
335 335
 		}
336 336
 		if (isset($where['cal_id']))	// prevent non-unique column-name cal_id
337 337
 		{
338
-			$where[] = $this->db->expression($this->cal_table, $this->cal_table.'.',array(
338
+			$where[] = $this->db->expression($this->cal_table, $this->cal_table.'.', array(
339 339
 				'cal_id' => $where['cal_id'],
340 340
 			));
341 341
 			unset($where['cal_id']);
342 342
 		}
343
-		if ((int) $recur_date)
343
+		if ((int)$recur_date)
344 344
 		{
345 345
 			$where[] = 'cal_start >= '.(int)$recur_date;
346 346
 			$group_by = 'GROUP BY '.$cols;
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
 		}
354 354
 		$cols .= ',range_end-1 AS recur_enddate';
355 355
 
356
-		$events =& $this->get_events($this->db->select($this->cal_table, $cols, $where, __LINE__, __FILE__, false, $group_by, 'calendar', 0, $join), $recur_date);
356
+		$events = & $this->get_events($this->db->select($this->cal_table, $cols, $where, __LINE__, __FILE__, false, $group_by, 'calendar', 0, $join), $recur_date);
357 357
 
358 358
 		return $events ? $events : false;
359 359
 	}
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
 	 * @param int $recur_date =0
366 366
 	 * @return array
367 367
 	 */
368
-	protected function &get_events($rs, $recur_date=0)
368
+	protected function &get_events($rs, $recur_date = 0)
369 369
 	{
370 370
 		if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length']))
371 371
 		{
@@ -377,7 +377,7 @@  discard block
 block discarded – undo
377 377
 		}
378 378
 
379 379
 		$events = array();
380
-		foreach($rs as $row)
380
+		foreach ($rs as $row)
381 381
 		{
382 382
 			if (!$row['recur_type'])
383 383
 			{
@@ -385,7 +385,7 @@  discard block
 block discarded – undo
385 385
 				unset($row['recur_enddate']);
386 386
 			}
387 387
 			$row['recur_exception'] = $row['alarm'] = array();
388
-			$events[$row['cal_id']] = Api\Db::strip_array_keys($row,'cal_');
388
+			$events[$row['cal_id']] = Api\Db::strip_array_keys($row, 'cal_');
389 389
 		}
390 390
 		if (!$events) return $events;
391 391
 
@@ -397,26 +397,26 @@  discard block
 block discarded – undo
397 397
 			if (!isset($event['uid']) || strlen($event['uid']) < $minimum_uid_length)
398 398
 			{
399 399
 				// event (without uid), not strong enough uid => create new uid
400
-				$event['uid'] = Api\CalDAV::generate_uid('calendar',$event['id']);
400
+				$event['uid'] = Api\CalDAV::generate_uid('calendar', $event['id']);
401 401
 				$this->db->update($this->cal_table, array('cal_uid' => $event['uid']),
402
-					array('cal_id' => $event['id']),__LINE__,__FILE__,'calendar');
402
+					array('cal_id' => $event['id']), __LINE__, __FILE__, 'calendar');
403 403
 			}
404 404
 			if (!(int)$recur_date && $event['recur_type'] != MCAL_RECUR_NONE)
405 405
 			{
406
-				foreach($this->db->select($this->dates_table, 'cal_id,cal_start', array(
406
+				foreach ($this->db->select($this->dates_table, 'cal_id,cal_start', array(
407 407
 					'cal_id' => $ids,
408 408
 					'recur_exception' => true,
409 409
 				), __LINE__, __FILE__, false, 'ORDER BY cal_id,cal_start', 'calendar') as $row)
410 410
 				{
411 411
 					$events[$row['cal_id']]['recur_exception'][] = $row['cal_start'];
412 412
 				}
413
-				break;	// as above select read all exceptions (and I dont think too short uid problem still exists)
413
+				break; // as above select read all exceptions (and I dont think too short uid problem still exists)
414 414
 			}
415 415
 			// make sure we fetch only real exceptions (deleted occurrences of a series should not show up)
416
-			if (($recur_date &&	$event['recur_type'] != MCAL_RECUR_NONE))
416
+			if (($recur_date && $event['recur_type'] != MCAL_RECUR_NONE))
417 417
 			{
418 418
 				//_debug_array(__METHOD__.__LINE__.' recur_date:'.$recur_date.' check cal_start:'.$event['start']);
419
-				foreach($this->db->select($this->dates_table, 'cal_id,cal_start', array(
419
+				foreach ($this->db->select($this->dates_table, 'cal_id,cal_start', array(
420 420
 					'cal_id' => $event['id'],
421 421
 					'cal_start' => $event['start'],
422 422
 					'recur_exception' => true,
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
 						'cal_deleted' => NULL
433 433
 					), __LINE__, __FILE__, false, '', 'calendar')->fetchColumn())
434 434
 					{
435
-						$e = $this->read($event['id'],$event['start']+1);
435
+						$e = $this->read($event['id'], $event['start'] + 1);
436 436
 						$event = $e[$event['id']];
437 437
 						break;
438 438
 					}
@@ -454,21 +454,21 @@  discard block
 block discarded – undo
454 454
 			if ($recur_date)
455 455
 			{
456 456
 				// also remember recur_date, maybe we need it later, duno now
457
-				$recur_date = array(0,$events[$ids]['recur_date'] = $events[$ids]['start']);
457
+				$recur_date = array(0, $events[$ids]['recur_date'] = $events[$ids]['start']);
458 458
 			}
459 459
 		}
460 460
 
461 461
 		// participants, if a recur_date give, we read that recurance, plus the one users from the default entry with recur_date=0
462 462
 		// sorting by cal_recur_date ASC makes sure recurence status always overwrites series status
463
-		foreach($this->db->select($this->user_table,'*',array(
463
+		foreach ($this->db->select($this->user_table, '*', array(
464 464
 			'cal_id'      => $ids,
465 465
 			'cal_recur_date' => $recur_date,
466 466
 			"cal_status NOT IN ('X','E')",
467
-		),__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
467
+		), __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
468 468
 		{
469 469
 			// combine all participant data in uid and status values
470 470
 			$uid    = self::combine_user($row['cal_user_type'], $row['cal_user_id'], $row['cal_user_attendee']);
471
-			$status = self::combine_status($row['cal_status'],$row['cal_quantity'],$row['cal_role']);
471
+			$status = self::combine_status($row['cal_status'], $row['cal_quantity'], $row['cal_role']);
472 472
 
473 473
 			$events[$row['cal_id']]['participants'][$uid] = $status;
474 474
 			$events[$row['cal_id']]['participant_types'][$row['cal_user_type']][is_numeric($uid) ? $uid : substr($uid, 1)] = $status;
@@ -477,7 +477,7 @@  discard block
 block discarded – undo
477 477
 		}
478 478
 
479 479
 		// custom fields
480
-		foreach($this->db->select($this->extra_table,'*',array('cal_id'=>$ids),__LINE__,__FILE__,false,'','calendar') as $row)
480
+		foreach ($this->db->select($this->extra_table, '*', array('cal_id'=>$ids), __LINE__, __FILE__, false, '', 'calendar') as $row)
481 481
 		{
482 482
 			$events[$row['cal_id']]['#'.$row['cal_extra_name']] = $row['cal_extra_value'];
483 483
 		}
@@ -485,7 +485,7 @@  discard block
 block discarded – undo
485 485
 		// alarms
486 486
 		if (is_array($ids))
487 487
 		{
488
-			foreach($this->read_alarms((array)$ids) as $cal_id => $alarms)
488
+			foreach ($this->read_alarms((array)$ids) as $cal_id => $alarms)
489 489
 			{
490 490
 				$events[$cal_id]['alarm'] = $alarms;
491 491
 			}
@@ -514,11 +514,11 @@  discard block
 block discarded – undo
514 514
 	 * @param boolean $master_only =false only check recurance master (egw_cal_user.recur_date=0)
515 515
 	 * @return int maximum modification timestamp
516 516
 	 */
517
-	function get_ctag($users, $owner_too=false,$master_only=false)
517
+	function get_ctag($users, $owner_too = false, $master_only = false)
518 518
 	{
519
-		static $ctags = array();	// some per-request caching
519
+		static $ctags = array(); // some per-request caching
520 520
 		static $last_request = null;
521
-		if (!isset($last_request) || time()-$last_request > self::MAX_CTAG_CACHE_TIME)
521
+		if (!isset($last_request) || time() - $last_request > self::MAX_CTAG_CACHE_TIME)
522 522
 		{
523 523
 			$ctags = array();
524 524
 			$last_request = time();
@@ -527,13 +527,13 @@  discard block
 block discarded – undo
527 527
 		if (isset($ctags[$signature])) return $ctags[$signature];
528 528
 
529 529
 		$types = array();
530
-		foreach((array)$users as $uid)
530
+		foreach ((array)$users as $uid)
531 531
 		{
532 532
 			$type = $id = null;
533 533
 			self::split_user($uid, $type, $id, true);
534 534
 			$types[$type][] = $id;
535 535
 		}
536
-		foreach($types as $type => $ids)
536
+		foreach ($types as $type => $ids)
537 537
 		{
538 538
 			$where = array(
539 539
 				'cal_user_type' => $type,
@@ -555,17 +555,17 @@  discard block
 block discarded – undo
555 555
 		if ($owner_too)
556 556
 		{
557 557
 			// owner can only by users, no groups or resources
558
-			foreach($users as $key => $user)
558
+			foreach ($users as $key => $user)
559 559
 			{
560 560
 				if (!($user > 0)) unset($users[$key]);
561 561
 			}
562 562
 			$where = $this->db->expression($this->user_table, '(', $where, ' OR ').
563 563
 				$this->db->expression($this->cal_table, array(
564 564
 					'cal_owner' => $users,
565
-				),')');
565
+				), ')');
566 566
 		}
567
-		return $ctags[$signature] = $this->db->select($this->user_table,'MAX(cal_modified)',
568
-			$where,__LINE__,__FILE__,false,'','calendar',0,'JOIN egw_cal ON egw_cal.cal_id=egw_cal_user.cal_id')->fetchColumn();
567
+		return $ctags[$signature] = $this->db->select($this->user_table, 'MAX(cal_modified)',
568
+			$where, __LINE__, __FILE__, false, '', 'calendar', 0, 'JOIN egw_cal ON egw_cal.cal_id=egw_cal_user.cal_id')->fetchColumn();
569 569
 	}
570 570
 
571 571
 	/**
@@ -577,7 +577,7 @@  discard block
 block discarded – undo
577 577
 	 * @param string|array $cols ='cal_id,cal_reference,cal_etag,cal_modified,cal_user_modified' cols to query
578 578
 	 * @return Iterator as Api\Db::select
579 579
 	 */
580
-	function get_cal_data(array $query, $cols='cal_id,cal_reference,cal_etag,cal_modified,cal_user_modified')
580
+	function get_cal_data(array $query, $cols = 'cal_id,cal_reference,cal_etag,cal_modified,cal_user_modified')
581 581
 	{
582 582
 		if (!is_array($cols)) $cols = explode(',', $cols);
583 583
 
@@ -603,12 +603,12 @@  discard block
 block discarded – undo
603 603
 		if ($cat_id)
604 604
 		{
605 605
 			$cats = $GLOBALS['egw']->categories->return_all_children($cat_id);
606
-			array_walk($cats,create_function('&$val,$key','$val = (int) $val;'));
607
-			if (is_array($cat_id) && count($cat_id)==1) $cat_id = $cat_id[0];
608
-			$sql = '(cal_category'.(count($cats) > 1 ? " IN ('".implode("','",$cats)."')" : '='.$this->db->quote((int)$cat_id));
609
-			foreach($cats as $cat)
606
+			array_walk($cats, create_function('&$val,$key', '$val = (int) $val;'));
607
+			if (is_array($cat_id) && count($cat_id) == 1) $cat_id = $cat_id[0];
608
+			$sql = '(cal_category'.(count($cats) > 1 ? " IN ('".implode("','", $cats)."')" : '='.$this->db->quote((int)$cat_id));
609
+			foreach ($cats as $cat)
610 610
 			{
611
-				$sql .= ' OR '.$this->db->concat("','",'cal_category',"','").' LIKE '.$this->db->quote('%,'.$cat.',%');
611
+				$sql .= ' OR '.$this->db->concat("','", 'cal_category', "','").' LIKE '.$this->db->quote('%,'.$cat.',%');
612 612
 			}
613 613
 			$sql .= ') ';
614 614
 		}
@@ -623,13 +623,13 @@  discard block
 block discarded – undo
623 623
 	 * @param array $where =array() array to add filters too
624 624
 	 * @return array
625 625
 	 */
626
-	protected function status_filter($filter, $enum_recuring=true, array $where=array())
626
+	protected function status_filter($filter, $enum_recuring = true, array $where = array())
627 627
 	{
628
-		if($filter != 'deleted' && $filter != 'everything')
628
+		if ($filter != 'deleted' && $filter != 'everything')
629 629
 		{
630 630
 			$where[] = 'cal_deleted IS NULL';
631 631
 		}
632
-		switch($filter)
632
+		switch ($filter)
633 633
 		{
634 634
 			case 'everything':	// no filter at all
635 635
 				break;
@@ -703,7 +703,7 @@  discard block
 block discarded – undo
703 703
 	 * @param int $remove_rejected_by_user =null add join to remove entry, if given user has rejected it
704 704
 	 * @return Iterator|array of events
705 705
 	 */
706
-	function &search($start,$end,$users,$cat_id=0,$filter='all',$offset=False,$num_rows=0,array $params=array(),$remove_rejected_by_user=null)
706
+	function &search($start, $end, $users, $cat_id = 0, $filter = 'all', $offset = False, $num_rows = 0, array $params = array(), $remove_rejected_by_user = null)
707 707
 	{
708 708
 		//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());
709 709
 
@@ -726,7 +726,7 @@  discard block
 block discarded – undo
726 726
 		{
727 727
 			$all_cols = self::get_columns('calendar', $this->cal_table);
728 728
 			$all_cols[0] = $this->db->to_varchar($this->cal_table.'.cal_id');
729
-			$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";
729
+			$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";
730 730
 		}
731 731
 		$where = array();
732 732
 		if (is_array($params['query']))
@@ -735,26 +735,26 @@  discard block
 block discarded – undo
735 735
 		}
736 736
 		elseif ($params['query'])
737 737
 		{
738
-			if(is_numeric($params['query']))
738
+			if (is_numeric($params['query']))
739 739
 			{
740
-				$where[] = $this->cal_table.'.cal_id = ' . (int)$params['query'];
740
+				$where[] = $this->cal_table.'.cal_id = '.(int)$params['query'];
741 741
 			}
742 742
 			else
743 743
 			{
744
-				foreach(array('cal_title','cal_description','cal_location') as $col)
744
+				foreach (array('cal_title', 'cal_description', 'cal_location') as $col)
745 745
 				{
746 746
 					$to_or[] = $col.' '.$this->db->capabilities[Api\Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.$this->db->quote('%'.$params['query'].'%');
747 747
 				}
748
-				$where[] = '('.implode(' OR ',$to_or).')';
748
+				$where[] = '('.implode(' OR ', $to_or).')';
749 749
 			}
750 750
 
751 751
 			// Searching - restrict private to own or private grant
752 752
 			if (!isset($params['private_grants']))
753 753
 			{
754 754
 				$params['private_grants'] = $GLOBALS['egw']->acl->get_ids_for_location($GLOBALS['egw_info']['user']['account_id'], Acl::PRIVAT, 'calendar');
755
-				$params['private_grants'][] = $GLOBALS['egw_info']['user']['account_id'];	// db query does NOT return current user
755
+				$params['private_grants'][] = $GLOBALS['egw_info']['user']['account_id']; // db query does NOT return current user
756 756
 			}
757
-			$private_filter = '(cal_public=1 OR cal_public=0 AND '.$this->db->expression($this->cal_table, array('cal_owner' => $params['private_grants'])) . ')';
757
+			$private_filter = '(cal_public=1 OR cal_public=0 AND '.$this->db->expression($this->cal_table, array('cal_owner' => $params['private_grants'])).')';
758 758
 			$where[] = $private_filter;
759 759
 		}
760 760
 		if (!empty($params['sql_filter']))
@@ -763,7 +763,7 @@  discard block
 block discarded – undo
763 763
 			{
764 764
 				$where[] = $params['sql_filter'];
765 765
 			}
766
-			elseif(is_array($params['sql_filter']))
766
+			elseif (is_array($params['sql_filter']))
767 767
 			{
768 768
 				$where = array_merge($where, $params['sql_filter']);
769 769
 			}
@@ -772,11 +772,11 @@  discard block
 block discarded – undo
772 772
 		if ($users)
773 773
 		{
774 774
 			$users_by_type = array();
775
-			foreach((array)$users as $user)
775
+			foreach ((array)$users as $user)
776 776
 			{
777 777
 				if (is_numeric($user))
778 778
 				{
779
-					$users_by_type['u'][] = (int) $user;
779
+					$users_by_type['u'][] = (int)$user;
780 780
 				}
781 781
 				else
782 782
 				{
@@ -787,45 +787,45 @@  discard block
 block discarded – undo
787 787
 			}
788 788
 			$to_or = $user_or = array();
789 789
 			$owner_or = null;
790
-			$table_def = $this->db->get_table_definitions('calendar',$this->user_table);
791
-			foreach($users_by_type as $type => $ids)
790
+			$table_def = $this->db->get_table_definitions('calendar', $this->user_table);
791
+			foreach ($users_by_type as $type => $ids)
792 792
 			{
793 793
 				// 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
794 794
 				if ($useUnionQuery)
795 795
 				{
796
-					$user_or[] = $this->db->expression($table_def,$this->user_table.'.',array(
796
+					$user_or[] = $this->db->expression($table_def, $this->user_table.'.', array(
797 797
 						'cal_user_type' => $type,
798
-					),' AND '.$this->user_table.'.',array(
798
+					), ' AND '.$this->user_table.'.', array(
799 799
 						'cal_user_id'   => $ids,
800 800
 					));
801 801
 					if ($type == 'u' && $filter == 'owner')
802 802
 					{
803
-						$cal_table_def = $this->db->get_table_definitions('calendar',$this->cal_table);
803
+						$cal_table_def = $this->db->get_table_definitions('calendar', $this->cal_table);
804 804
 						// only users can be owners, no need to add groups
805 805
 						$user_ids = array();
806
-						foreach($ids as $user_id)
806
+						foreach ($ids as $user_id)
807 807
 						{
808 808
 							if ($GLOBALS['egw']->accounts->get_type($user_id) === 'u') $user_ids[] = $user_id;
809 809
 						}
810
-						$owner_or = $this->db->expression($cal_table_def,array('cal_owner' => $user_ids));
810
+						$owner_or = $this->db->expression($cal_table_def, array('cal_owner' => $user_ids));
811 811
 					}
812 812
 				}
813 813
 				else
814 814
 				{
815
-					$to_or[] = $this->db->expression($table_def,$this->user_table.'.',array(
815
+					$to_or[] = $this->db->expression($table_def, $this->user_table.'.', array(
816 816
 						'cal_user_type' => $type,
817
-					),' AND '.$this->user_table.'.',array(
817
+					), ' AND '.$this->user_table.'.', array(
818 818
 						'cal_user_id'   => $ids,
819 819
 					));
820 820
 					if ($type == 'u' && $filter == 'owner')
821 821
 					{
822
-						$cal_table_def = $this->db->get_table_definitions('calendar',$this->cal_table);
823
-						$to_or[] = $this->db->expression($cal_table_def,array('cal_owner' => $ids));
822
+						$cal_table_def = $this->db->get_table_definitions('calendar', $this->cal_table);
823
+						$to_or[] = $this->db->expression($cal_table_def, array('cal_owner' => $ids));
824 824
 					}
825 825
 				}
826 826
 			}
827 827
 			// this is only used, when we cannot use UNIONS
828
-			if (!$useUnionQuery) $where[] = '('.implode(' OR ',$to_or).')';
828
+			if (!$useUnionQuery) $where[] = '('.implode(' OR ', $to_or).')';
829 829
 
830 830
 			$where = $this->status_filter($filter, $params['enum_recuring'], $where);
831 831
 		}
@@ -844,15 +844,15 @@  discard block
 block discarded – undo
844 844
 				$where[] = '('.((int)$start).' < range_end OR range_end IS NULL)';
845 845
 			}
846 846
 		}
847
-		if (!preg_match('/^[a-z_ ,c]+$/i',$params['order'])) $params['order'] = 'cal_start';		// gard against SQL injection
847
+		if (!preg_match('/^[a-z_ ,c]+$/i', $params['order'])) $params['order'] = 'cal_start'; // gard against SQL injection
848 848
 
849 849
 		// if not enum recuring events, we have to use minimum start- AND end-dates, otherwise we get more then one event per cal_id!
850 850
 		if (!$params['enum_recuring'])
851 851
 		{
852 852
 			$where[] = "$this->user_table.cal_recur_date=0";
853
-			$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);
853
+			$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);
854 854
 			// in case cal_start is used in a query, eg. calendar_ical::find_event
855
-			$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);
855
+			$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);
856 856
 			$params['order'] = str_replace('cal_start', 'range_start', $params['order']);
857 857
 			if ($end) $where[] = (int)$end.' > range_start';
858 858
   		}
@@ -864,14 +864,13 @@  discard block
 block discarded – undo
864 864
 				" ON $this->cal_table.cal_id=rejected_by_user.cal_id".
865 865
 				" AND rejected_by_user.cal_user_type='u'".
866 866
 				" AND rejected_by_user.cal_user_id=".$this->db->quote($remove_rejected_by_user).
867
-				" AND ".(!$params['enum_recuring'] ? 'rejected_by_user.cal_recur_date=0' :
868
-					'(recur_type IS NULL AND rejected_by_user.cal_recur_date=0 OR cal_start=rejected_by_user.cal_recur_date)');
867
+				" 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)');
869 868
 			$or_required = array(
870 869
 				'rejected_by_user.cal_status IS NULL',
871 870
 				"rejected_by_user.cal_status NOT IN ('R','X')",
872 871
 			);
873 872
 			if ($filter == 'owner') $or_required[] = 'cal_owner='.(int)$remove_rejected_by_user;
874
-			$where[] = '('.implode(' OR ',$or_required).')';
873
+			$where[] = '('.implode(' OR ', $or_required).')';
875 874
 		}
876 875
 		// using a time-range and deleted attribute limited view instead of full table
877 876
 		$cal_table = $this->cal_range_view($start, $end, null, $filter == 'everything' ? null : $filter != 'deleted');
@@ -883,18 +882,18 @@  discard block
 block discarded – undo
883 882
 		// dates table join only needed to enum recuring events, we use a time-range limited view here too
884 883
 		if ($params['enum_recuring'])
885 884
 		{
886
-			$join = "JOIN ".$this->dates_table.	// using dates_table direct seems quicker then an other view
885
+			$join = "JOIN ".$this->dates_table.// using dates_table direct seems quicker then an other view
887 886
 				//$this->dates_range_view($start, $end, null, $filter == 'everything' ? null : $filter == 'deleted').
888 887
 				" ON $this->cal_table.cal_id=$this->dates_table.cal_id ".$join;
889 888
 		}
890 889
 
891 890
 		// Check for some special sorting, used by planner views
892
-		if($params['order'] == 'participants , cal_non_blocking DESC')
891
+		if ($params['order'] == 'participants , cal_non_blocking DESC')
893 892
 		{
894 893
 			$order = ($GLOBALS['egw_info']['user']['preferences']['common']['account_display'] == 'lastname' ? 'n_family' : 'n_fileas');
895 894
 			$cols .= ",egw_addressbook.{$order}";
896 895
 			$join .= "LEFT JOIN egw_addressbook ON ".
897
-					($this->db->Type == 'pgsql'? "egw_addressbook.account_id::varchar = ":"egw_addressbook.account_id = ").
896
+					($this->db->Type == 'pgsql' ? "egw_addressbook.account_id::varchar = " : "egw_addressbook.account_id = ").
898 897
 					"{$this->user_table}.cal_user_id";
899 898
 			$params['order'] = "$order, cal_non_blocking DESC";
900 899
 		}
@@ -927,29 +926,29 @@  discard block
 block discarded – undo
927 926
 			// as replace the OR by construction of a suitable UNION for performance reasons
928 927
 			if ($owner_or || $user_or)
929 928
 			{
930
-				foreach($user_or as $user_sql)
929
+				foreach ($user_or as $user_sql)
931 930
 				{
932 931
 					$selects[] = $select;
933
-					$selects[count($selects)-1]['where'][] = $user_sql;
932
+					$selects[count($selects) - 1]['where'][] = $user_sql;
934 933
 					if ($params['enum_recuring'])
935 934
 					{
936
-						$selects[count($selects)-1]['where'][] = "recur_type IS NULL AND $this->user_table.cal_recur_date=0";
935
+						$selects[count($selects) - 1]['where'][] = "recur_type IS NULL AND $this->user_table.cal_recur_date=0";
937 936
 						$selects[] = $select;
938
-						$selects[count($selects)-1]['where'][] = $user_sql;
939
-						$selects[count($selects)-1]['where'][] = "$this->user_table.cal_recur_date=cal_start";
937
+						$selects[count($selects) - 1]['where'][] = $user_sql;
938
+						$selects[count($selects) - 1]['where'][] = "$this->user_table.cal_recur_date=cal_start";
940 939
 					}
941 940
 				}
942 941
 				// if the query is to be filtered by owner we need to add more selects for the union
943 942
 				if ($owner_or)
944 943
 				{
945 944
 					$selects[] = $select;
946
-					$selects[count($selects)-1]['where'][] = $owner_or;
945
+					$selects[count($selects) - 1]['where'][] = $owner_or;
947 946
 					if ($params['enum_recuring'])
948 947
 					{
949
-						$selects[count($selects)-1]['where'][] = "recur_type IS NULL AND $this->user_table.cal_recur_date=0";
948
+						$selects[count($selects) - 1]['where'][] = "recur_type IS NULL AND $this->user_table.cal_recur_date=0";
950 949
 						$selects[] = $select;
951
-						$selects[count($selects)-1]['where'][] = $owner_or;
952
-						$selects[count($selects)-1]['where'][] = "$this->user_table.cal_recur_date=cal_start";
950
+						$selects[count($selects) - 1]['where'][] = $owner_or;
951
+						$selects[count($selects) - 1]['where'][] = "$this->user_table.cal_recur_date=cal_start";
953 952
 					}
954 953
 				}
955 954
 			}
@@ -959,34 +958,34 @@  discard block
 block discarded – undo
959 958
 				$selects[] = $select;
960 959
 				if ($params['enum_recuring'])
961 960
 				{
962
-					$selects[count($selects)-1]['where'][] = "recur_type IS NULL AND $this->user_table.cal_recur_date=0";
961
+					$selects[count($selects) - 1]['where'][] = "recur_type IS NULL AND $this->user_table.cal_recur_date=0";
963 962
 					$selects[] = $select;
964
-					$selects[count($selects)-1]['where'][] = "$this->user_table.cal_recur_date=cal_start";
963
+					$selects[count($selects) - 1]['where'][] = "$this->user_table.cal_recur_date=cal_start";
965 964
 				}
966 965
 			}
967 966
 			if (is_numeric($offset) && !$params['no_total'])	// get the total too
968 967
 			{
969 968
 				$save_selects = $selects;
970 969
 				// 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)
971
-				foreach(array_keys($selects) as $key)
970
+				foreach (array_keys($selects) as $key)
972 971
 				{
973 972
 					$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";
974 973
 					if (!$params['enum_recuring'])
975 974
 					{
976
-						$selects[$key]['cols'] = str_replace(array('cal_start','cal_end'),
977
-							array('range_start AS cal_start','range_end AS cal_end'), $selects[$key]['cols']);
975
+						$selects[$key]['cols'] = str_replace(array('cal_start', 'cal_end'),
976
+							array('range_start AS cal_start', 'range_end AS cal_end'), $selects[$key]['cols']);
978 977
 					}
979 978
 				}
980
-				if (!isset($params['cols']) && !$params['no_integration']) self::get_union_selects($selects,$start,$end,$users,$cat_id,$filter,$params['query'],$params['users']);
979
+				if (!isset($params['cols']) && !$params['no_integration']) self::get_union_selects($selects, $start, $end, $users, $cat_id, $filter, $params['query'], $params['users']);
981 980
 
982
-				$this->total = $this->db->union($selects,__LINE__,__FILE__)->NumRows();
981
+				$this->total = $this->db->union($selects, __LINE__, __FILE__)->NumRows();
983 982
 
984 983
 				// restore original cols / selects
985 984
 				$selects = $save_selects; unset($save_selects);
986 985
 			}
987
-			if (!isset($params['cols']) && !$params['no_integration']) self::get_union_selects($selects,$start,$end,$users,$cat_id,$filter,$params['query'],$params['users']);
986
+			if (!isset($params['cols']) && !$params['no_integration']) self::get_union_selects($selects, $start, $end, $users, $cat_id, $filter, $params['query'], $params['users']);
988 987
 
989
-			$rs = $this->db->union($selects,__LINE__,__FILE__,$params['order'],$offset,$num_rows);
988
+			$rs = $this->db->union($selects, __LINE__, __FILE__, $params['order'], $offset, $num_rows);
990 989
 		}
991 990
 		else	// MsSQL oder MySQL 3.23
992 991
 		{
@@ -1009,27 +1008,27 @@  discard block
 block discarded – undo
1009 1008
 				$selects[0]['cols'] = "$this->cal_table.cal_id,cal_start";
1010 1009
 				if (!isset($params['cols']) && !$params['no_integration'] && $this->db->capabilities['union'])
1011 1010
 				{
1012
-					self::get_union_selects($selects,$start,$end,$users,$cat_id,$filter,$params['query'],$params['users']);
1011
+					self::get_union_selects($selects, $start, $end, $users, $cat_id, $filter, $params['query'], $params['users']);
1013 1012
 				}
1014 1013
 				$this->total = $this->db->union($selects, __LINE__, __FILE__)->NumRows();
1015 1014
 				$selects = $save_selects;
1016 1015
 			}
1017 1016
 			if (!isset($params['cols']) && !$params['no_integration'] && $this->db->capabilities['union'])
1018 1017
 			{
1019
-				self::get_union_selects($selects,$start,$end,$users,$cat_id,$filter,$params['query'],$params['users']);
1018
+				self::get_union_selects($selects, $start, $end, $users, $cat_id, $filter, $params['query'], $params['users']);
1020 1019
 			}
1021
-			$rs = $this->db->union($selects,__LINE__,__FILE__,$params['order'],$offset,$num_rows);
1020
+			$rs = $this->db->union($selects, __LINE__, __FILE__, $params['order'], $offset, $num_rows);
1022 1021
 		}
1023 1022
 		//error_log(__METHOD__."() useUnionQuery=$useUnionQuery --> query took ".(microtime(true)-$starttime).'s '.$rs->sql);
1024 1023
 
1025 1024
 		if (isset($params['cols']))
1026 1025
 		{
1027
-			return $rs;	// if colums are specified we return the recordset / iterator
1026
+			return $rs; // if colums are specified we return the recordset / iterator
1028 1027
 		}
1029 1028
 		// Todo: return $this->get_events($rs);
1030 1029
 
1031 1030
 		$events = $ids = $recur_dates = $recur_ids = array();
1032
-		foreach($rs as $row)
1031
+		foreach ($rs as $row)
1033 1032
 		{
1034 1033
 			$id = $row['cal_id'];
1035 1034
 			if (is_numeric($id)) $ids[] = $id;
@@ -1041,9 +1040,9 @@  discard block
 block discarded – undo
1041 1040
 			}
1042 1041
 			if ($row['participants'])
1043 1042
 			{
1044
-				$row['participants'] = explode(',',$row['participants']);
1043
+				$row['participants'] = explode(',', $row['participants']);
1045 1044
 				$row['participants'] = array_combine($row['participants'],
1046
-					array_fill(0,count($row['participants']),''));
1045
+					array_fill(0, count($row['participants']), ''));
1047 1046
 			}
1048 1047
 			else
1049 1048
 			{
@@ -1052,9 +1051,9 @@  discard block
 block discarded – undo
1052 1051
 			$row['recur_exception'] = $row['alarm'] = array();
1053 1052
 
1054 1053
 			// compile a list of recurrences per cal_id
1055
-			if (!in_array($id,(array)$recur_ids[$row['cal_id']])) $recur_ids[$row['cal_id']][] = $id;
1054
+			if (!in_array($id, (array)$recur_ids[$row['cal_id']])) $recur_ids[$row['cal_id']][] = $id;
1056 1055
 
1057
-			$events[$id] = Api\Db::strip_array_keys($row,'cal_');
1056
+			$events[$id] = Api\Db::strip_array_keys($row, 'cal_');
1058 1057
 		}
1059 1058
 		//_debug_array($events);
1060 1059
 		if (count($ids))
@@ -1064,26 +1063,26 @@  discard block
 block discarded – undo
1064 1063
 			// now ready all users with the given cal_id AND (cal_recur_date=0 or the fitting recur-date)
1065 1064
 			// This will always read the first entry of each recuring event too, we eliminate it later
1066 1065
 			$recur_dates[] = 0;
1067
-			$utcal_id_view = " (SELECT * FROM ".$this->user_table." WHERE cal_id IN (".implode(',',$ids).")".
1066
+			$utcal_id_view = " (SELECT * FROM ".$this->user_table." WHERE cal_id IN (".implode(',', $ids).")".
1068 1067
 				($filter != 'everything' ? " AND cal_status NOT IN ('X','E')" : '').") utcalid ";
1069 1068
 			//$utrecurdate_view = " (select * from ".$this->user_table." where cal_recur_date in (".implode(',',array_unique($recur_dates)).")) utrecurdates ";
1070
-			foreach($this->db->select($utcal_id_view,'*',array(
1069
+			foreach ($this->db->select($utcal_id_view, '*', array(
1071 1070
 					//'cal_id' => array_unique($ids),
1072 1071
 					'cal_recur_date' => $recur_dates,
1073
-				),__LINE__,__FILE__,false,'ORDER BY cal_id,cal_user_type DESC,'.self::STATUS_SORT,'calendar',-1,$join='',
1074
-				$this->db->get_table_definitions('calendar',$this->user_table)) as $row)	// DESC puts users before resources and contacts
1072
+				), __LINE__, __FILE__, false, 'ORDER BY cal_id,cal_user_type DESC,'.self::STATUS_SORT, 'calendar', -1, $join = '',
1073
+				$this->db->get_table_definitions('calendar', $this->user_table)) as $row)	// DESC puts users before resources and contacts
1075 1074
 			{
1076 1075
 				$id = $row['cal_id'];
1077 1076
 				if ($row['cal_recur_date']) $id .= '-'.$row['cal_recur_date'];
1078 1077
 
1079 1078
 				// combine all participant data in uid and status values
1080 1079
 				$uid = self::combine_user($row['cal_user_type'], $row['cal_user_id'], $row['cal_user_attendee']);
1081
-				$status = self::combine_status($row['cal_status'],$row['cal_quantity'],$row['cal_role']);
1080
+				$status = self::combine_status($row['cal_status'], $row['cal_quantity'], $row['cal_role']);
1082 1081
 
1083 1082
 				// set accept/reject/tentative of series for all recurrences
1084 1083
 				if (!$row['cal_recur_date'])
1085 1084
 				{
1086
-					foreach((array)$recur_ids[$row['cal_id']] as $i)
1085
+					foreach ((array)$recur_ids[$row['cal_id']] as $i)
1087 1086
 					{
1088 1087
 						if (isset($events[$i]) && !isset($events[$i]['participants'][$uid]))
1089 1088
 						{
@@ -1098,16 +1097,16 @@  discard block
 block discarded – undo
1098 1097
 			// query recurrance exceptions, if needed: enum_recuring && !daywise is used in calendar_groupdav::get_series($uid,...)
1099 1098
 			if (!$params['enum_recuring'] || !$params['daywise'])
1100 1099
 			{
1101
-				foreach($this->db->select($this->dates_table, 'cal_id,cal_start', array(
1100
+				foreach ($this->db->select($this->dates_table, 'cal_id,cal_start', array(
1102 1101
 					'cal_id' => $ids,
1103 1102
 					'recur_exception' => true,
1104 1103
 				), __LINE__, __FILE__, false, 'ORDER BY cal_id,cal_start', 'calendar') as $row)
1105 1104
 				{
1106 1105
 					// for enum_recurring events are not indexed by cal_id, but $cal_id.'-'.$cal_start
1107 1106
 					// find master, which is first recurrence
1108
-					if (!isset($events[$id=$row['cal_id']]))
1107
+					if (!isset($events[$id = $row['cal_id']]))
1109 1108
 					{
1110
-						foreach($events as $id => $event)
1109
+						foreach ($events as $id => $event)
1111 1110
 						{
1112 1111
 							if ($event['id'] == $row['cal_id']) break;
1113 1112
 						}
@@ -1120,10 +1119,10 @@  discard block
 block discarded – undo
1120 1119
 			{
1121 1120
 				$where = array('cal_id' => $ids);
1122 1121
 				if ($params['cfs']) $where['cal_extra_name'] = $params['cfs'];
1123
-				foreach($this->db->select($this->extra_table,'*',$where,
1124
-					__LINE__,__FILE__,false,'','calendar') as $row)
1122
+				foreach ($this->db->select($this->extra_table, '*', $where,
1123
+					__LINE__, __FILE__, false, '', 'calendar') as $row)
1125 1124
 				{
1126
-					foreach((array)$recur_ids[$row['cal_id']] as $id)
1125
+					foreach ((array)$recur_ids[$row['cal_id']] as $id)
1127 1126
 					{
1128 1127
 						if (isset($events[$id]))
1129 1128
 						{
@@ -1133,9 +1132,9 @@  discard block
 block discarded – undo
1133 1132
 				}
1134 1133
 			}
1135 1134
 			// alarms
1136
-			foreach($this->read_alarms($ids) as $cal_id => $alarms)
1135
+			foreach ($this->read_alarms($ids) as $cal_id => $alarms)
1137 1136
 			{
1138
-				foreach($alarms as $id => $alarm)
1137
+				foreach ($alarms as $id => $alarm)
1139 1138
 				{
1140 1139
 					$event_start = $alarm['time'] + $alarm['offset'];
1141 1140
 
@@ -1172,16 +1171,16 @@  discard block
 block discarded – undo
1172 1171
 	 * @param $query
1173 1172
 	 * @param $users_raw as passed to calendar_bo::search (no members and memberships added)
1174 1173
 	 */
1175
-	private static function get_union_selects(array &$selects,$start,$end,$users,$cat_id,$filter,$query,$users_raw)
1174
+	private static function get_union_selects(array &$selects, $start, $end, $users, $cat_id, $filter, $query, $users_raw)
1176 1175
 	{
1177
-		if (in_array(basename($_SERVER['SCRIPT_FILENAME']),array('groupdav.php','rpc.php','xmlrpc.php','/activesync/index.php')) ||
1178
-			!in_array($GLOBALS['egw_info']['flags']['currentapp'],array('calendar','home')))
1176
+		if (in_array(basename($_SERVER['SCRIPT_FILENAME']), array('groupdav.php', 'rpc.php', 'xmlrpc.php', '/activesync/index.php')) ||
1177
+			!in_array($GLOBALS['egw_info']['flags']['currentapp'], array('calendar', 'home')))
1179 1178
 		{
1180
-			return;    // disable integration for GroupDAV, SyncML, ...
1179
+			return; // disable integration for GroupDAV, SyncML, ...
1181 1180
 		}
1182 1181
 		self::$integration_data = Api\Hooks::process(array(
1183 1182
 			'location' => 'calendar_search_union',
1184
-			'cols'  => $selects[0]['cols'],    // cols to return
1183
+			'cols'  => $selects[0]['cols'], // cols to return
1185 1184
 			'start' => $start,
1186 1185
 			'end'   => $end,
1187 1186
 			'users' => $users,
@@ -1190,12 +1189,12 @@  discard block
 block discarded – undo
1190 1189
 			'filter'=> $filter,
1191 1190
 			'query' => $query,
1192 1191
 		));
1193
-		foreach(self::$integration_data as $data)
1192
+		foreach (self::$integration_data as $data)
1194 1193
 		{
1195 1194
 			if (is_array($data['selects']))
1196 1195
 			{
1197 1196
 				//echo $app; _debug_array($data);
1198
-				$selects = array_merge($selects,$data['selects']);
1197
+				$selects = array_merge($selects, $data['selects']);
1199 1198
 			}
1200 1199
 		}
1201 1200
 	}
@@ -1220,35 +1219,35 @@  discard block
 block discarded – undo
1220 1219
 	 * @param string $required_app ='calendar'
1221 1220
 	 * @return string cols for union query to match ones supplied in $required
1222 1221
 	 */
1223
-	public static function union_cols(array $app_cols,$required,$required_app='calendar')
1222
+	public static function union_cols(array $app_cols, $required, $required_app = 'calendar')
1224 1223
 	{
1225 1224
 		// remove evtl. used DISTINCT, we currently dont need it
1226
-		if (($distinct = substr($required,0,9) == 'DISTINCT '))
1225
+		if (($distinct = substr($required, 0, 9) == 'DISTINCT '))
1227 1226
 		{
1228
-			$required = substr($required,9);
1227
+			$required = substr($required, 9);
1229 1228
 		}
1230 1229
 		$return_cols = array();
1231
-		foreach(is_array($required) ? $required : explode(',',$required) as $cols)
1230
+		foreach (is_array($required) ? $required : explode(',', $required) as $cols)
1232 1231
 		{
1233 1232
 			$matches = null;
1234
-			if (substr($cols,-2) == '.*')
1233
+			if (substr($cols, -2) == '.*')
1235 1234
 			{
1236
-				$cols = self::get_columns($required_app,substr($cols,0,-2));
1235
+				$cols = self::get_columns($required_app, substr($cols, 0, -2));
1237 1236
 			}
1238 1237
 			// remove CAST added for PostgreSQL from eg. "CAST(egw_cal.cal_id AS varchar)"
1239 1238
 			elseif (preg_match('/CAST\(([a-z0-9_.]+) AS [a-z0-9_]+\)/i', $cols, $matches))
1240 1239
 			{
1241 1240
 				$cols = $matches[1];
1242 1241
 			}
1243
-			elseif (strpos($cols,' AS ') !== false)
1242
+			elseif (strpos($cols, ' AS ') !== false)
1244 1243
 			{
1245
-				list(,$cols) = explode(' AS ',$cols);
1244
+				list(,$cols) = explode(' AS ', $cols);
1246 1245
 			}
1247
-			foreach((array)$cols as $col)
1246
+			foreach ((array)$cols as $col)
1248 1247
 			{
1249
-				if (substr($col,0,7) == 'egw_cal')	// remove table name
1248
+				if (substr($col, 0, 7) == 'egw_cal')	// remove table name
1250 1249
 				{
1251
-					$col = preg_replace('/^egw_cal[a-z_]*\./','',$col);
1250
+					$col = preg_replace('/^egw_cal[a-z_]*\./', '', $col);
1252 1251
 				}
1253 1252
 				if (isset($app_cols[$col]))
1254 1253
 				{
@@ -1261,7 +1260,7 @@  discard block
 block discarded – undo
1261 1260
 			}
1262 1261
 		}
1263 1262
 		//error_log(__METHOD__."(".array2string($app_cols).", ".array2string($required).", '$required_app') returning ".array2string(implode(',',$return_cols)));
1264
-		return implode(',',$return_cols);
1263
+		return implode(',', $return_cols);
1265 1264
 	}
1266 1265
 
1267 1266
 	/**
@@ -1271,21 +1270,21 @@  discard block
 block discarded – undo
1271 1270
 	 * @param string $table
1272 1271
 	 * @return array of column names
1273 1272
 	 */
1274
-	static private function get_columns($app,$table)
1273
+	static private function get_columns($app, $table)
1275 1274
 	{
1276 1275
 		if ($table != 'egw_cal')
1277 1276
 		{
1278
-			$table_def = $GLOBALS['egw']->db->get_table_definitions($app,$table);
1277
+			$table_def = $GLOBALS['egw']->db->get_table_definitions($app, $table);
1279 1278
 			$cols = array_keys($table_def['fd']);
1280 1279
 		}
1281 1280
 		else
1282 1281
 		{
1283 1282
 			// special handling for egw_cal, as old databases have a different column order!!!
1284
-			$cols =& Api\Cache::getSession(__CLASS__,$table);
1283
+			$cols = & Api\Cache::getSession(__CLASS__, $table);
1285 1284
 
1286 1285
 			if (is_null($cols))
1287 1286
 			{
1288
-				$meta = $GLOBALS['egw']->db->metadata($table,true);
1287
+				$meta = $GLOBALS['egw']->db->metadata($table, true);
1289 1288
 				$cols = array_keys($meta['meta']);
1290 1289
 			}
1291 1290
 		}
@@ -1338,12 +1337,12 @@  discard block
 block discarded – undo
1338 1337
 	 * @param int &$etag etag=null etag to check or null, on return new etag
1339 1338
 	 * @return boolean|int false on error, 0 if etag does not match, cal_id otherwise
1340 1339
 	 */
1341
-	function save($event,&$set_recurrences,&$set_recurrences_start=0,$change_since=0,&$etag=null)
1340
+	function save($event, &$set_recurrences, &$set_recurrences_start = 0, $change_since = 0, &$etag = null)
1342 1341
 	{
1343 1342
 		if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length']))
1344 1343
 		{
1345 1344
 			$minimum_uid_length = $GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'];
1346
-			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!
1345
+			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!
1347 1346
 		}
1348 1347
 		else
1349 1348
 		{
@@ -1354,7 +1353,7 @@  discard block
 block discarded – undo
1354 1353
 
1355 1354
 		//error_log(__METHOD__.'('.array2string($event).",$set_recurrences,$change_since,$etag) ".function_backtrace());
1356 1355
 
1357
-		$cal_id = (int) $event['id'];
1356
+		$cal_id = (int)$event['id'];
1358 1357
 		unset($event['id']);
1359 1358
 		$set_recurrences = $set_recurrences || !$cal_id && $event['recur_type'] != MCAL_RECUR_NONE;
1360 1359
 
@@ -1365,9 +1364,9 @@  discard block
 block discarded – undo
1365 1364
 		}
1366 1365
 
1367 1366
 		// add colum prefix 'cal_' if there's not already a 'recur_' prefix
1368
-		foreach($event as $col => $val)
1367
+		foreach ($event as $col => $val)
1369 1368
 		{
1370
-			if ($col[0] != '#' && substr($col,0,6) != 'recur_' && substr($col,0,6) != 'range_' && $col != 'alarm' && $col != 'tz_id' && $col != 'caldav_name')
1369
+			if ($col[0] != '#' && substr($col, 0, 6) != 'recur_' && substr($col, 0, 6) != 'range_' && $col != 'alarm' && $col != 'tz_id' && $col != 'caldav_name')
1371 1370
 			{
1372 1371
 				$event['cal_'.$col] = $val;
1373 1372
 				unset($event[$col]);
@@ -1377,13 +1376,12 @@  discard block
 block discarded – undo
1377 1376
 		if (isset($event['cal_start'])) $event['range_start'] = $event['cal_start'];
1378 1377
 		if (isset($event['cal_end']))
1379 1378
 		{
1380
-			$event['range_end'] = $event['recur_type'] == MCAL_RECUR_NONE ? $event['cal_end'] :
1381
-				($event['recur_enddate'] ? $event['recur_enddate'] : null);
1379
+			$event['range_end'] = $event['recur_type'] == MCAL_RECUR_NONE ? $event['cal_end'] : ($event['recur_enddate'] ? $event['recur_enddate'] : null);
1382 1380
 		}
1383 1381
 		// ensure that we find mathing entries later on
1384 1382
 		if (!is_array($event['cal_category']))
1385 1383
 		{
1386
-			$categories = array_unique(explode(',',$event['cal_category']));
1384
+			$categories = array_unique(explode(',', $event['cal_category']));
1387 1385
 			sort($categories);
1388 1386
 		}
1389 1387
 		else
@@ -1392,7 +1390,7 @@  discard block
 block discarded – undo
1392 1390
 		}
1393 1391
 		sort($categories, SORT_NUMERIC);
1394 1392
 
1395
-		$event['cal_category'] = implode(',',$categories);
1393
+		$event['cal_category'] = implode(',', $categories);
1396 1394
 
1397 1395
 		// make sure recurring events never reference to an other recurrent event
1398 1396
 		if ($event['recur_type'] != MCAL_RECUR_NONE) $event['cal_reference'] = 0;
@@ -1410,18 +1408,18 @@  discard block
 block discarded – undo
1410 1408
 			// read only timezone id, to check if it is changed
1411 1409
 			if ($event['recur_type'] != MCAL_RECUR_NONE)
1412 1410
 			{
1413
-				$old_tz_id = $this->db->select($this->cal_table,'tz_id',$where,__LINE__,__FILE__,'calendar')->fetchColumn();
1411
+				$old_tz_id = $this->db->select($this->cal_table, 'tz_id', $where, __LINE__, __FILE__, 'calendar')->fetchColumn();
1414 1412
 			}
1415 1413
 			if (!is_null($etag)) $where['cal_etag'] = $etag;
1416 1414
 
1417 1415
 			unset($event['cal_etag']);
1418
-			$event[] = 'cal_etag=cal_etag+1';	// always update the etag, even if none given to check
1416
+			$event[] = 'cal_etag=cal_etag+1'; // always update the etag, even if none given to check
1419 1417
 
1420
-			$this->db->update($this->cal_table,$event,$where,__LINE__,__FILE__,'calendar');
1418
+			$this->db->update($this->cal_table, $event, $where, __LINE__, __FILE__, 'calendar');
1421 1419
 
1422 1420
 			if (!is_null($etag) && $this->db->affected_rows() < 1)
1423 1421
 			{
1424
-				return 0;	// wrong etag, someone else updated the entry
1422
+				return 0; // wrong etag, someone else updated the entry
1425 1423
 			}
1426 1424
 			if (!is_null($etag)) ++$etag;
1427 1425
 		}
@@ -1430,10 +1428,10 @@  discard block
 block discarded – undo
1430 1428
 			// new event
1431 1429
 			if (!$event['cal_owner']) $event['cal_owner'] = $GLOBALS['egw_info']['user']['account_id'];
1432 1430
 
1433
-			if (!$event['cal_id'] && !isset($event['cal_uid'])) $event['cal_uid'] = '';	// uid is NOT NULL!
1431
+			if (!$event['cal_id'] && !isset($event['cal_uid'])) $event['cal_uid'] = ''; // uid is NOT NULL!
1434 1432
 
1435
-			$this->db->insert($this->cal_table,$event,false,__LINE__,__FILE__,'calendar');
1436
-			if (!($cal_id = $this->db->get_last_insert_id($this->cal_table,'cal_id')))
1433
+			$this->db->insert($this->cal_table, $event, false, __LINE__, __FILE__, 'calendar');
1434
+			if (!($cal_id = $this->db->get_last_insert_id($this->cal_table, 'cal_id')))
1437 1435
 			{
1438 1436
 				return false;
1439 1437
 			}
@@ -1443,7 +1441,7 @@  discard block
 block discarded – undo
1443 1441
 		// event without uid or not strong enough uid
1444 1442
 		if (!isset($event['cal_uid']) || strlen($event['cal_uid']) < $minimum_uid_length)
1445 1443
 		{
1446
-			$update['cal_uid'] = $event['cal_uid'] = Api\CalDAV::generate_uid('calendar',$cal_id);
1444
+			$update['cal_uid'] = $event['cal_uid'] = Api\CalDAV::generate_uid('calendar', $cal_id);
1447 1445
 		}
1448 1446
 		// set caldav_name, if not given by caller
1449 1447
 		if (empty($event['caldav_name']) && version_compare($GLOBALS['egw_info']['apps']['calendar']['version'], '1.9.003', '>='))
@@ -1452,37 +1450,37 @@  discard block
 block discarded – undo
1452 1450
 		}
1453 1451
 		if ($update)
1454 1452
 		{
1455
-			$this->db->update($this->cal_table, $update, array('cal_id' => $cal_id),__LINE__,__FILE__,'calendar');
1453
+			$this->db->update($this->cal_table, $update, array('cal_id' => $cal_id), __LINE__, __FILE__, 'calendar');
1456 1454
 		}
1457 1455
 
1458 1456
 		if ($event['recur_type'] == MCAL_RECUR_NONE)
1459 1457
 		{
1460
-			$this->db->delete($this->dates_table,array(
1458
+			$this->db->delete($this->dates_table, array(
1461 1459
 				'cal_id' => $cal_id),
1462
-				__LINE__,__FILE__,'calendar');
1460
+				__LINE__, __FILE__, 'calendar');
1463 1461
 
1464 1462
 			// delete all user-records, with recur-date != 0
1465
-			$this->db->delete($this->user_table,array(
1463
+			$this->db->delete($this->user_table, array(
1466 1464
 				'cal_id' => $cal_id, 'cal_recur_date != 0'),
1467
-				__LINE__,__FILE__,'calendar');
1465
+				__LINE__, __FILE__, 'calendar');
1468 1466
 
1469
-			$this->db->delete($this->repeats_table,array(
1467
+			$this->db->delete($this->repeats_table, array(
1470 1468
 				'cal_id' => $cal_id),
1471
-				__LINE__,__FILE__,'calendar');
1469
+				__LINE__, __FILE__, 'calendar');
1472 1470
 
1473 1471
 			// add exception marker to master, so participants added to exceptions *only* get found
1474 1472
 			if ($event['cal_reference'])
1475 1473
 			{
1476 1474
 				$master_participants = array();
1477
-				foreach($this->db->select($this->user_table, 'cal_user_type,cal_user_id,cal_user_attendee', array(
1475
+				foreach ($this->db->select($this->user_table, 'cal_user_type,cal_user_id,cal_user_attendee', array(
1478 1476
 					'cal_id' => $event['cal_reference'],
1479 1477
 					'cal_recur_date' => 0,
1480
-					"cal_status != 'X'",	// deleted need to be replaced with exception marker too
1478
+					"cal_status != 'X'", // deleted need to be replaced with exception marker too
1481 1479
 				), __LINE__, __FILE__, 'calendar') as $row)
1482 1480
 				{
1483 1481
 					$master_participants[] = self::combine_user($row['cal_user_type'], $row['cal_user_id'], $row['cal_user_attendee']);
1484 1482
 				}
1485
-				foreach(array_diff(array_keys((array)$event['cal_participants']), $master_participants) as $uid)
1483
+				foreach (array_diff(array_keys((array)$event['cal_participants']), $master_participants) as $uid)
1486 1484
 				{
1487 1485
 					$user_type = $user_id = null;
1488 1486
 					self::split_user($uid, $user_type, $user_id, true);
@@ -1501,10 +1499,10 @@  discard block
 block discarded – undo
1501 1499
 		else // write information about recuring event, if recur_type is present in the array
1502 1500
 		{
1503 1501
 			// fetch information about the currently saved (old) event
1504
-			$old_min = (int) $this->db->select($this->dates_table,'MIN(cal_start)',array('cal_id'=>$cal_id),__LINE__,__FILE__,false,'','calendar')->fetchColumn();
1505
-			$old_duration = (int) $this->db->select($this->dates_table,'MIN(cal_end)',array('cal_id'=>$cal_id),__LINE__,__FILE__,false,'','calendar')->fetchColumn() - $old_min;
1502
+			$old_min = (int)$this->db->select($this->dates_table, 'MIN(cal_start)', array('cal_id'=>$cal_id), __LINE__, __FILE__, false, '', 'calendar')->fetchColumn();
1503
+			$old_duration = (int)$this->db->select($this->dates_table, 'MIN(cal_end)', array('cal_id'=>$cal_id), __LINE__, __FILE__, false, '', 'calendar')->fetchColumn() - $old_min;
1506 1504
 			$old_exceptions = array();
1507
-			foreach($this->db->select($this->dates_table, 'cal_start', array(
1505
+			foreach ($this->db->select($this->dates_table, 'cal_start', array(
1508 1506
 				'cal_id' => $cal_id,
1509 1507
 				'recur_exception' => true
1510 1508
 			), __LINE__, __FILE__, false, 'ORDER BY cal_start', 'calendar') as $row)
@@ -1523,8 +1521,8 @@  discard block
 block discarded – undo
1523 1521
 				'cal_recur_date' => 0,
1524 1522
 			);
1525 1523
 			$old_participants = array();
1526
-			foreach ($this->db->select($this->user_table,'cal_user_type,cal_user_id,cal_user_attendee,cal_status,cal_quantity,cal_role', $where,
1527
-				__LINE__,__FILE__,false,'','calendar') as $row)
1524
+			foreach ($this->db->select($this->user_table, 'cal_user_type,cal_user_id,cal_user_attendee,cal_status,cal_quantity,cal_role', $where,
1525
+				__LINE__, __FILE__, false, '', 'calendar') as $row)
1528 1526
 			{
1529 1527
 				$uid = self::combine_user($row['cal_user_type'], $row['cal_user_id'], $row['cal_user_attendee']);
1530 1528
 				$status = self::combine_status($row['cal_status'], $row['cal_quantity'], $row['cal_role']);
@@ -1534,7 +1532,7 @@  discard block
 block discarded – undo
1534 1532
 			// re-check: did so much recurrence data change that we have to rebuild it from scratch?
1535 1533
 			if (!$set_recurrences)
1536 1534
 			{
1537
-				$set_recurrences = (isset($event['cal_start']) && (int)$old_min != (int) $event['cal_start']) ||
1535
+				$set_recurrences = (isset($event['cal_start']) && (int)$old_min != (int)$event['cal_start']) ||
1538 1536
 				    $event['recur_type'] != $old_repeats['recur_type'] || $event['recur_data'] != $old_repeats['recur_data'] ||
1539 1537
 					(int)$event['recur_interval'] != (int)$old_repeats['recur_interval'] || $event['tz_id'] != $old_tz_id;
1540 1538
 			}
@@ -1543,22 +1541,22 @@  discard block
 block discarded – undo
1543 1541
 			{
1544 1542
 				// too much recurrence data has changed, we have to do a rebuild from scratch
1545 1543
 				// delete all, but the lowest dates record
1546
-				$this->db->delete($this->dates_table,array(
1544
+				$this->db->delete($this->dates_table, array(
1547 1545
 					'cal_id' => $cal_id,
1548 1546
 					'cal_start > '.(int)$old_min,
1549
-				),__LINE__,__FILE__,'calendar');
1547
+				), __LINE__, __FILE__, 'calendar');
1550 1548
 
1551 1549
 				// delete all user-records, with recur-date != 0
1552
-				$this->db->delete($this->user_table,array(
1550
+				$this->db->delete($this->user_table, array(
1553 1551
 					'cal_id' => $cal_id,
1554 1552
 					'cal_recur_date != 0',
1555
-				),__LINE__,__FILE__,'calendar');
1553
+				), __LINE__, __FILE__, 'calendar');
1556 1554
 			}
1557 1555
 			else
1558 1556
 			{
1559 1557
 				// we adjust some possibly changed recurrences manually
1560 1558
 				// deleted exceptions: re-insert recurrences into the user and dates table
1561
-				if (count($deleted_exceptions = array_diff($old_exceptions,$event['recur_exception'])))
1559
+				if (count($deleted_exceptions = array_diff($old_exceptions, $event['recur_exception'])))
1562 1560
 				{
1563 1561
 					if (isset($event['cal_participants']))
1564 1562
 					{
@@ -1569,7 +1567,7 @@  discard block
 block discarded – undo
1569 1567
 						// use old default
1570 1568
 						$participants = $old_participants;
1571 1569
 					}
1572
-					foreach($deleted_exceptions as $id => $deleted_exception)
1570
+					foreach ($deleted_exceptions as $id => $deleted_exception)
1573 1571
 					{
1574 1572
 						// rebuild participants for the re-inserted recurrence
1575 1573
 						$this->recurrence($cal_id, $deleted_exception, $deleted_exception + $old_duration, $participants);
@@ -1577,24 +1575,24 @@  discard block
 block discarded – undo
1577 1575
 				}
1578 1576
 
1579 1577
 				// check if recurrence enddate was adjusted
1580
-				if(isset($event['recur_enddate']))
1578
+				if (isset($event['recur_enddate']))
1581 1579
 				{
1582 1580
 					// recurrences need to be truncated
1583
-					if((int)$event['recur_enddate'] > 0 &&
1581
+					if ((int)$event['recur_enddate'] > 0 &&
1584 1582
 						((int)$old_repeats['recur_enddate'] == 0 || (int)$old_repeats['recur_enddate'] > (int)$event['recur_enddate'])
1585 1583
 					)
1586 1584
 					{
1587
-						$this->db->delete($this->user_table,array('cal_id' => $cal_id,'cal_recur_date >= '.($event['recur_enddate'] + 1*DAY_s)),__LINE__,__FILE__,'calendar');
1588
-						$this->db->delete($this->dates_table,array('cal_id' => $cal_id,'cal_start >= '.($event['recur_enddate'] + 1*DAY_s)),__LINE__,__FILE__,'calendar');
1585
+						$this->db->delete($this->user_table, array('cal_id' => $cal_id, 'cal_recur_date >= '.($event['recur_enddate'] + 1 * DAY_s)), __LINE__, __FILE__, 'calendar');
1586
+						$this->db->delete($this->dates_table, array('cal_id' => $cal_id, 'cal_start >= '.($event['recur_enddate'] + 1 * DAY_s)), __LINE__, __FILE__, 'calendar');
1589 1587
 					}
1590 1588
 
1591 1589
 					// recurrences need to be expanded
1592
-					if(((int)$event['recur_enddate'] == 0 && (int)$old_repeats['recur_enddate'] > 0)
1590
+					if (((int)$event['recur_enddate'] == 0 && (int)$old_repeats['recur_enddate'] > 0)
1593 1591
 						|| ((int)$event['recur_enddate'] > 0 && (int)$old_repeats['recur_enddate'] > 0 && (int)$old_repeats['recur_enddate'] < (int)$event['recur_enddate'])
1594 1592
 					)
1595 1593
 					{
1596 1594
 						$set_recurrences = true;
1597
-						$set_recurrences_start = ($old_repeats['recur_enddate'] + 1*DAY_s);
1595
+						$set_recurrences_start = ($old_repeats['recur_enddate'] + 1 * DAY_s);
1598 1596
 					}
1599 1597
 					//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");
1600 1598
 				}
@@ -1603,9 +1601,9 @@  discard block
 block discarded – undo
1603 1601
 				if (count($event['recur_exception']))
1604 1602
 				{
1605 1603
 					// added and existing exceptions: delete the execeptions from the user table, it could be the first time
1606
-					$this->db->delete($this->user_table,array('cal_id' => $cal_id,'cal_recur_date' => $event['recur_exception']),__LINE__,__FILE__,'calendar');
1604
+					$this->db->delete($this->user_table, array('cal_id' => $cal_id, 'cal_recur_date' => $event['recur_exception']), __LINE__, __FILE__, 'calendar');
1607 1605
 					// update recur_exception flag based on current exceptions
1608
-					$this->db->update($this->dates_table, 'recur_exception='.$this->db->expression($this->dates_table,array(
1606
+					$this->db->update($this->dates_table, 'recur_exception='.$this->db->expression($this->dates_table, array(
1609 1607
 						'cal_start' => $event['recur_exception'],
1610 1608
 					)), array(
1611 1609
 						'cal_id' => $cal_id,
@@ -1614,27 +1612,27 @@  discard block
 block discarded – undo
1614 1612
 			}
1615 1613
 
1616 1614
 			// write the repeats table
1617
-			unset($event[0]);	// unset the 'etag=etag+1', as it's not in the repeats table
1618
-			$this->db->insert($this->repeats_table,$event,array('cal_id' => $cal_id),__LINE__,__FILE__,'calendar');
1615
+			unset($event[0]); // unset the 'etag=etag+1', as it's not in the repeats table
1616
+			$this->db->insert($this->repeats_table, $event, array('cal_id' => $cal_id), __LINE__, __FILE__, 'calendar');
1619 1617
 		}
1620 1618
 		// update start- and endtime if present in the event-array, evtl. we need to move all recurrences
1621 1619
 		if (isset($event['cal_start']) && isset($event['cal_end']))
1622 1620
 		{
1623
-			$this->move($cal_id,$event['cal_start'],$event['cal_end'],!$cal_id ? false : $change_since, $old_min, $old_min +  $old_duration);
1621
+			$this->move($cal_id, $event['cal_start'], $event['cal_end'], !$cal_id ? false : $change_since, $old_min, $old_min + $old_duration);
1624 1622
 		}
1625 1623
 		// update participants if present in the event-array
1626 1624
 		if (isset($event['cal_participants']))
1627 1625
 		{
1628
-			$this->participants($cal_id,$event['cal_participants'],!$cal_id ? false : $change_since);
1626
+			$this->participants($cal_id, $event['cal_participants'], !$cal_id ? false : $change_since);
1629 1627
 		}
1630 1628
 		// Custom fields
1631 1629
 		Api\Storage\Customfields::handle_files('calendar', $cal_id, $event);
1632 1630
 
1633
-		foreach($event as $name => $value)
1631
+		foreach ($event as $name => $value)
1634 1632
 		{
1635 1633
 			if ($name[0] == '#')
1636 1634
 			{
1637
-				if (is_array($value) && array_key_exists('id',$value))
1635
+				if (is_array($value) && array_key_exists('id', $value))
1638 1636
 				{
1639 1637
 					//error_log(__METHOD__.__LINE__."$name => ".array2string($value).function_backtrace());
1640 1638
 					$value = $value['id'];
@@ -1642,19 +1640,19 @@  discard block
 block discarded – undo
1642 1640
 				}
1643 1641
 				if ($value)
1644 1642
 				{
1645
-					$this->db->insert($this->extra_table,array(
1646
-						'cal_extra_value'	=> is_array($value) ? implode(',',$value) : $value,
1647
-					),array(
1643
+					$this->db->insert($this->extra_table, array(
1644
+						'cal_extra_value'	=> is_array($value) ? implode(',', $value) : $value,
1645
+					), array(
1648 1646
 						'cal_id'			=> $cal_id,
1649
-						'cal_extra_name'	=> substr($name,1),
1650
-					),__LINE__,__FILE__,'calendar');
1647
+						'cal_extra_name'	=> substr($name, 1),
1648
+					), __LINE__, __FILE__, 'calendar');
1651 1649
 				}
1652 1650
 				else
1653 1651
 				{
1654
-					$this->db->delete($this->extra_table,array(
1652
+					$this->db->delete($this->extra_table, array(
1655 1653
 						'cal_id'			=> $cal_id,
1656
-						'cal_extra_name'	=> substr($name,1),
1657
-					),__LINE__,__FILE__,'calendar');
1654
+						'cal_extra_name'	=> substr($name, 1),
1655
+					), __LINE__, __FILE__, 'calendar');
1658 1656
 				}
1659 1657
 			}
1660 1658
 		}
@@ -1665,9 +1663,9 @@  discard block
 block discarded – undo
1665 1663
 			{
1666 1664
 				if ($alarm['id'] && strpos($alarm['id'], 'cal:'.$cal_id.':') !== 0)
1667 1665
 				{
1668
-					unset($alarm['id']);	// unset the temporary id to add the alarm
1666
+					unset($alarm['id']); // unset the temporary id to add the alarm
1669 1667
 				}
1670
-				if(!isset($alarm['offset']))
1668
+				if (!isset($alarm['offset']))
1671 1669
 				{
1672 1670
 					$alarm['offset'] = $event['cal_start'] - $alarm['time'];
1673 1671
 				}
@@ -1678,14 +1676,14 @@  discard block
 block discarded – undo
1678 1676
 
1679 1677
 				if ($alarm['time'] < time() && !self::shift_alarm($event, $alarm))
1680 1678
 				{
1681
-					continue;	// pgoerzen: don't add alarm in the past
1679
+					continue; // pgoerzen: don't add alarm in the past
1682 1680
 				}
1683
-				$this->save_alarm($cal_id, $alarm, false);	// false: not update modified, we do it anyway
1681
+				$this->save_alarm($cal_id, $alarm, false); // false: not update modified, we do it anyway
1684 1682
 			}
1685 1683
 		}
1686 1684
 		if (is_null($etag))
1687 1685
 		{
1688
-			$etag = $this->db->select($this->cal_table,'cal_etag',array('cal_id' => $cal_id),__LINE__,__FILE__,false,'','calendar')->fetchColumn();
1686
+			$etag = $this->db->select($this->cal_table, 'cal_etag', array('cal_id' => $cal_id), __LINE__, __FILE__, false, '', 'calendar')->fetchColumn();
1689 1687
 		}
1690 1688
 
1691 1689
 		// if event is an exception: update modified of master, to force etag, ctag and sync-token change
@@ -1705,7 +1703,7 @@  discard block
 block discarded – undo
1705 1703
 	 *	are dealing with, default is now.
1706 1704
 	 * @return boolean true if alarm could be shifted, false if not
1707 1705
 	 */
1708
-	public static function shift_alarm(array $_event, array &$alarm, $timestamp=null)
1706
+	public static function shift_alarm(array $_event, array &$alarm, $timestamp = null)
1709 1707
 	{
1710 1708
 		if ($_event['recur_type'] == MCAL_RECUR_NONE)
1711 1709
 		{
@@ -1716,7 +1714,7 @@  discard block
 block discarded – undo
1716 1714
 		$rrule = calendar_rrule::event2rrule($event, false);
1717 1715
 		foreach ($rrule as $time)
1718 1716
 		{
1719
-			if ($start < ($ts = Api\DateTime::to($time,'server')))
1717
+			if ($start < ($ts = Api\DateTime::to($time, 'server')))
1720 1718
 			{
1721 1719
 				$alarm['time'] = $ts - $alarm['offset'];
1722 1720
 				return true;
@@ -1737,34 +1735,34 @@  discard block
 block discarded – undo
1737 1735
 	 * @todo Recalculate recurrences, if timezone changes
1738 1736
 	 * @return int|boolean number of moved recurrences or false on error
1739 1737
 	 */
1740
-	function move($cal_id,$start,$end,$change_since=0,$old_start=0,$old_end=0)
1738
+	function move($cal_id, $start, $end, $change_since = 0, $old_start = 0, $old_end = 0)
1741 1739
 	{
1742 1740
 		//echo "<p>socal::move($cal_id,$start,$end,$change_since,$old_start,$old_end)</p>\n";
1743 1741
 
1744
-		if (!(int) $cal_id) return false;
1742
+		if (!(int)$cal_id) return false;
1745 1743
 
1746 1744
 		if (!$old_start)
1747 1745
 		{
1748
-			if ($change_since !== false) $row = $this->db->select($this->dates_table,'MIN(cal_start) AS cal_start,MIN(cal_end) AS cal_end',
1749
-				array('cal_id'=>$cal_id),__LINE__,__FILE__,false,'','calendar')->fetch();
1746
+			if ($change_since !== false) $row = $this->db->select($this->dates_table, 'MIN(cal_start) AS cal_start,MIN(cal_end) AS cal_end',
1747
+				array('cal_id'=>$cal_id), __LINE__, __FILE__, false, '', 'calendar')->fetch();
1750 1748
 			// if no recurrence found, create one with the new dates
1751 1749
 			if ($change_since === false || !$row || !$row['cal_start'] || !$row['cal_end'])
1752 1750
 			{
1753
-				$this->db->insert($this->dates_table,array(
1751
+				$this->db->insert($this->dates_table, array(
1754 1752
 					'cal_id'    => $cal_id,
1755 1753
 					'cal_start' => $start,
1756 1754
 					'cal_end'   => $end,
1757
-				),false,__LINE__,__FILE__,'calendar');
1755
+				), false, __LINE__, __FILE__, 'calendar');
1758 1756
 
1759 1757
 				return 1;
1760 1758
 			}
1761
-			$move_start = (int) ($start-$row['cal_start']);
1762
-			$move_end   = (int) ($end-$row['cal_end']);
1759
+			$move_start = (int)($start - $row['cal_start']);
1760
+			$move_end   = (int)($end - $row['cal_end']);
1763 1761
 		}
1764 1762
 		else
1765 1763
 		{
1766
-			$move_start = (int) ($start-$old_start);
1767
-			$move_end   = (int) ($end-$old_end);
1764
+			$move_start = (int)($start - $old_start);
1765
+			$move_end   = (int)($end - $old_end);
1768 1766
 		}
1769 1767
 		$where = 'cal_id='.(int)$cal_id;
1770 1768
 
@@ -1772,13 +1770,13 @@  discard block
 block discarded – undo
1772 1770
 		{
1773 1771
 			// move the recur-date of the participants
1774 1772
 			$this->db->query("UPDATE $this->user_table SET cal_recur_date=cal_recur_date+$move_start WHERE $where AND cal_recur_date ".
1775
-				((int)$change_since ? '>= '.(int)$change_since : '!= 0'),__LINE__,__FILE__);
1773
+				((int)$change_since ? '>= '.(int)$change_since : '!= 0'), __LINE__, __FILE__);
1776 1774
 		}
1777 1775
 		if ($move_start || $move_end)
1778 1776
 		{
1779 1777
 			// move the event and it's recurrences
1780 1778
 			$this->db->query("UPDATE $this->dates_table SET cal_start=cal_start+$move_start,cal_end=cal_end+$move_end WHERE $where".
1781
-				((int) $change_since ? ' AND cal_start >= '.(int) $change_since : ''),__LINE__,__FILE__);
1779
+				((int)$change_since ? ' AND cal_start >= '.(int)$change_since : ''), __LINE__, __FILE__);
1782 1780
 		}
1783 1781
 		return $this->db->affected_rows();
1784 1782
 	}
@@ -1797,8 +1795,7 @@  discard block
 block discarded – undo
1797 1795
 		}
1798 1796
 		if (is_array($attendee))
1799 1797
 		{
1800
-			$email = !empty($attendee['email']) ? $user_attendee['email'] :
1801
-				(strtolower(substr($attendee['url'], 0, 7)) == 'mailto:' ? substr($user_attendee['url'], 7) : $attendee['url']);
1798
+			$email = !empty($attendee['email']) ? $user_attendee['email'] : (strtolower(substr($attendee['url'], 0, 7)) == 'mailto:' ? substr($user_attendee['url'], 7) : $attendee['url']);
1802 1799
 			$attendee = !empty($attendee['cn']) ? $attendee['cn'].' <'.$email.'>' : $email;
1803 1800
 		}
1804 1801
 		return $attendee;
@@ -1811,11 +1808,11 @@  discard block
 block discarded – undo
1811 1808
 	 * @param string|array $attendee attendee information: email, json or array with attr cn and url
1812 1809
 	 * @return string|int combined id
1813 1810
 	 */
1814
-	static function combine_user($user_type, $user_id, $attendee=null)
1811
+	static function combine_user($user_type, $user_id, $attendee = null)
1815 1812
 	{
1816 1813
 		if (!$user_type || $user_type == 'u')
1817 1814
 		{
1818
-			return (int) $user_id;
1815
+			return (int)$user_id;
1819 1816
 		}
1820 1817
 		if ($user_type == 'e' && $attendee)
1821 1818
 		{
@@ -1835,12 +1832,12 @@  discard block
 block discarded – undo
1835 1832
 	 * @param string|int &$user_id id
1836 1833
 	 * @param boolean $md5_email =false md5 hash user_id for email / user_type=="e"
1837 1834
 	 */
1838
-	static function split_user($uid, &$user_type, &$user_id, $md5_email=false)
1835
+	static function split_user($uid, &$user_type, &$user_id, $md5_email = false)
1839 1836
 	{
1840 1837
 		if (is_numeric($uid))
1841 1838
 		{
1842 1839
 			$user_type = 'u';
1843
-			$user_id = (int) $uid;
1840
+			$user_id = (int)$uid;
1844 1841
 		}
1845 1842
 		// create md5 hash from lowercased and trimed raw email ("[email protected]", not "Ralf Becker <[email protected]>")
1846 1843
 		elseif ($md5_email && $uid[0] == 'e')
@@ -1854,7 +1851,7 @@  discard block
 block discarded – undo
1854 1851
 		else
1855 1852
 		{
1856 1853
 			$user_type = $uid[0];
1857
-			$user_id = substr($uid,1);
1854
+			$user_id = substr($uid, 1);
1858 1855
 		}
1859 1856
 	}
1860 1857
 
@@ -1866,7 +1863,7 @@  discard block
 block discarded – undo
1866 1863
 	 * @param string $role ='REQ-PARTICIPANT'
1867 1864
 	 * @return string
1868 1865
 	 */
1869
-	static function combine_status($status,$quantity=1,$role='REQ-PARTICIPANT')
1866
+	static function combine_status($status, $quantity = 1, $role = 'REQ-PARTICIPANT')
1870 1867
 	{
1871 1868
 		if ((int)$quantity > 1) $status .= (int)$quantity;
1872 1869
 		if ($role != 'REQ-PARTICIPANT') $status .= $role;
@@ -1882,13 +1879,13 @@  discard block
 block discarded – undo
1882 1879
 	 * @param string &$role=null only O: role
1883 1880
 	 * @return string status U, T, A or R, same as $status parameter on return
1884 1881
 	 */
1885
-	static function split_status(&$status,&$quantity=null,&$role=null)
1882
+	static function split_status(&$status, &$quantity = null, &$role = null)
1886 1883
 	{
1887 1884
 		$quantity = 1;
1888 1885
 		$role = 'REQ-PARTICIPANT';
1889 1886
 		//error_log(__METHOD__.__LINE__.array2string($status));
1890 1887
 		$matches = null;
1891
-		if (is_string($status) && strlen($status) > 1 && preg_match('/^.([0-9]*)(.*)$/',$status,$matches))
1888
+		if (is_string($status) && strlen($status) > 1 && preg_match('/^.([0-9]*)(.*)$/', $status, $matches))
1892 1889
 		{
1893 1890
 			if ((int)$matches[1] > 0) $quantity = (int)$matches[1];
1894 1891
 			if ($matches[2]) $role = $matches[2];
@@ -1915,14 +1912,14 @@  discard block
 block discarded – undo
1915 1912
 	 *		true = only add participants if needed, no participant will be deleted (participants to check/add required in $participants)
1916 1913
 	 * @return int|boolean number of updated recurrences or false on error
1917 1914
 	 */
1918
-	function participants($cal_id,$participants,$change_since=0,$add_only=false)
1915
+	function participants($cal_id, $participants, $change_since = 0, $add_only = false)
1919 1916
 	{
1920 1917
 		//error_log(__METHOD__."($cal_id,".array2string($participants).",$change_since,$add_only");
1921 1918
 
1922 1919
 		$recurrences = array();
1923 1920
 
1924 1921
 		// remove group-invitations, they are NOT stored in the db
1925
-		foreach($participants as $uid => $status)
1922
+		foreach ($participants as $uid => $status)
1926 1923
 		{
1927 1924
 			if ($status[0] == 'G')
1928 1925
 			{
@@ -1931,7 +1928,7 @@  discard block
 block discarded – undo
1931 1928
 		}
1932 1929
 		$where = array('cal_id' => $cal_id);
1933 1930
 
1934
-		if ((int) $change_since)
1931
+		if ((int)$change_since)
1935 1932
 		{
1936 1933
 			$where[] = '(cal_recur_date=0 OR cal_recur_date >= '.(int)$change_since.')';
1937 1934
 		}
@@ -1939,31 +1936,31 @@  discard block
 block discarded – undo
1939 1936
 		if ($change_since !== false)
1940 1937
 		{
1941 1938
 			// find all existing recurrences
1942
-			foreach($this->db->select($this->user_table,'DISTINCT cal_recur_date',$where,__LINE__,__FILE__,false,'','calendar') as $row)
1939
+			foreach ($this->db->select($this->user_table, 'DISTINCT cal_recur_date', $where, __LINE__, __FILE__, false, '', 'calendar') as $row)
1943 1940
 			{
1944 1941
 				$recurrences[] = $row['cal_recur_date'];
1945 1942
 			}
1946 1943
 
1947 1944
 			// update existing entries
1948
-			$existing_entries = $this->db->select($this->user_table,'*',$where,__LINE__,__FILE__,false,'ORDER BY cal_recur_date DESC','calendar');
1945
+			$existing_entries = $this->db->select($this->user_table, '*', $where, __LINE__, __FILE__, false, 'ORDER BY cal_recur_date DESC', 'calendar');
1949 1946
 
1950 1947
 			// create a full list of participants which already exist in the db
1951 1948
 			// with status, quantity and role of the earliest recurence
1952 1949
 			$old_participants = array();
1953
-			foreach($existing_entries as $row)
1950
+			foreach ($existing_entries as $row)
1954 1951
 			{
1955 1952
 				$uid = self::combine_user($row['cal_user_type'], $row['cal_user_id'], $row['cal_user_attendee']);
1956 1953
 				if ($row['cal_recur_date'] || !isset($old_participants[$uid]))
1957 1954
 				{
1958
-					$old_participants[$uid] = self::combine_status($row['cal_status'],$row['cal_quantity'],$row['cal_role']);
1955
+					$old_participants[$uid] = self::combine_status($row['cal_status'], $row['cal_quantity'], $row['cal_role']);
1959 1956
 				}
1960 1957
 			}
1961 1958
 
1962 1959
 			// tag participants which should be deleted
1963
-			if($add_only === false)
1960
+			if ($add_only === false)
1964 1961
 			{
1965 1962
 				$deleted = array();
1966
-				foreach($existing_entries as $row)
1963
+				foreach ($existing_entries as $row)
1967 1964
 				{
1968 1965
 					$uid = self::combine_user($row['cal_user_type'], $row['cal_user_id'], $row['cal_user_attendee']);
1969 1966
 					// delete not longer set participants
@@ -1976,7 +1973,7 @@  discard block
 block discarded – undo
1976 1973
 
1977 1974
 			// only keep added OR status (incl. quantity!) changed participants for further steps
1978 1975
 			// we do not touch unchanged (!) existing ones
1979
-			foreach($participants as $uid => $status)
1976
+			foreach ($participants as $uid => $status)
1980 1977
 			{
1981 1978
 				if ($old_participants[$uid] === $status)
1982 1979
 				{
@@ -1988,46 +1985,46 @@  discard block
 block discarded – undo
1988 1985
 			if ($add_only === false && count($deleted))
1989 1986
 			{
1990 1987
 				$to_or = array();
1991
-				$table_def = $this->db->get_table_definitions('calendar',$this->user_table);
1992
-				foreach($deleted as $type => $ids)
1988
+				$table_def = $this->db->get_table_definitions('calendar', $this->user_table);
1989
+				foreach ($deleted as $type => $ids)
1993 1990
 				{
1994
-					$to_or[] = $this->db->expression($table_def,array(
1991
+					$to_or[] = $this->db->expression($table_def, array(
1995 1992
 						'cal_user_type' => $type,
1996 1993
 						'cal_user_id'   => $ids,
1997 1994
 					));
1998 1995
 				}
1999
-				$where[] = '('.implode(' OR ',$to_or).')';
2000
-				$where[] = "cal_status!='E'";	// do NOT delete exception marker
2001
-				$this->db->update($this->user_table,array('cal_status'=>'X'),$where,__LINE__,__FILE__,'calendar');
1996
+				$where[] = '('.implode(' OR ', $to_or).')';
1997
+				$where[] = "cal_status!='E'"; // do NOT delete exception marker
1998
+				$this->db->update($this->user_table, array('cal_status'=>'X'), $where, __LINE__, __FILE__, 'calendar');
2002 1999
 			}
2003 2000
 		}
2004 2001
 
2005 2002
 		if (count($participants))	// participants which need to be added
2006 2003
 		{
2007
-			if (!count($recurrences)) $recurrences[] = 0;   // insert the default recurrence
2004
+			if (!count($recurrences)) $recurrences[] = 0; // insert the default recurrence
2008 2005
 
2009 2006
 			$delete_deleted = array();
2010 2007
 
2011 2008
 			// update participants
2012
-			foreach($participants as $uid => $status)
2009
+			foreach ($participants as $uid => $status)
2013 2010
 			{
2014 2011
 				$type = $id = $quantity = $role = null;
2015 2012
 				self::split_user($uid, $type, $id, true);
2016
-				self::split_status($status,$quantity,$role);
2013
+				self::split_status($status, $quantity, $role);
2017 2014
 				$set = array(
2018 2015
 					'cal_status'	  => $status,
2019 2016
 					'cal_quantity'	  => $quantity,
2020 2017
 					'cal_role'        => $role,
2021 2018
 					'cal_user_attendee' => $type == 'e' ? substr($uid, 1) : null,
2022 2019
 				);
2023
-				foreach($recurrences as $recur_date)
2020
+				foreach ($recurrences as $recur_date)
2024 2021
 				{
2025
-					$this->db->insert($this->user_table,$set,array(
2022
+					$this->db->insert($this->user_table, $set, array(
2026 2023
 						'cal_id'	      => $cal_id,
2027 2024
 						'cal_recur_date'  => $recur_date,
2028 2025
 						'cal_user_type'   => $type,
2029 2026
 						'cal_user_id' 	  => $id,
2030
-					),__LINE__,__FILE__,'calendar');
2027
+					), __LINE__, __FILE__, 'calendar');
2031 2028
 				}
2032 2029
 				// for new or changed group-invitations, remove previously deleted members, so they show up again
2033 2030
 				if ($uid < 0)
@@ -2037,13 +2034,13 @@  discard block
 block discarded – undo
2037 2034
 			}
2038 2035
 			if ($delete_deleted)
2039 2036
 			{
2040
-				$this->db->delete($this->user_table, $where=array(
2037
+				$this->db->delete($this->user_table, $where = array(
2041 2038
 					'cal_id' => $cal_id,
2042 2039
 					'cal_recur_date' => $recurrences,
2043 2040
 					'cal_user_type' => 'u',
2044 2041
 					'cal_user_id' => array_unique($delete_deleted),
2045 2042
 					'cal_status' => 'X',
2046
-				),__LINE__,__FILE__,'calendar');
2043
+				), __LINE__, __FILE__, 'calendar');
2047 2044
 				//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');
2048 2045
 			}
2049 2046
 		}
@@ -2062,7 +2059,7 @@  discard block
 block discarded – undo
2062 2059
 	 * @param string $attendee =null extra attendee information to set for all types (incl. accounts!)
2063 2060
 	 * @return int number of changed recurrences
2064 2061
 	 */
2065
-	function set_status($cal_id,$user_type,$user_id,$status,$recur_date=0,$role=null,$attendee=null)
2062
+	function set_status($cal_id, $user_type, $user_id, $status, $recur_date = 0, $role = null, $attendee = null)
2066 2063
 	{
2067 2064
 		static $status_code_short = array(
2068 2065
 			REJECTED 	=> 'R',
@@ -2087,7 +2084,7 @@  discard block
 block discarded – undo
2087 2084
 			'cal_user_type'	=> $user_type,
2088 2085
 			'cal_user_id'   => $user_id_md5,
2089 2086
 		);
2090
-		if ((int) $recur_date)
2087
+		if ((int)$recur_date)
2091 2088
 		{
2092 2089
 			$where['cal_recur_date'] = $recur_date;
2093 2090
 		}
@@ -2098,7 +2095,7 @@  discard block
 block discarded – undo
2098 2095
 
2099 2096
 		if ($status == 'G')		// remove group invitations, as we dont store them in the db
2100 2097
 		{
2101
-			$this->db->delete($this->user_table,$where,__LINE__,__FILE__,'calendar');
2098
+			$this->db->delete($this->user_table, $where, __LINE__, __FILE__, 'calendar');
2102 2099
 			$ret = $this->db->affected_rows();
2103 2100
 		}
2104 2101
 		else
@@ -2106,7 +2103,7 @@  discard block
 block discarded – undo
2106 2103
 			$set = array('cal_status' => $status);
2107 2104
 			if ($user_type == 'e' || $attendee) $set['cal_user_attendee'] = $attendee ? $attendee : $user_id;
2108 2105
 			if (!is_null($role) && $role != 'REQ-PARTICIPANT') $set['cal_role'] = $role;
2109
-			$this->db->insert($this->user_table,$set,$where,__LINE__,__FILE__,'calendar');
2106
+			$this->db->insert($this->user_table, $set, $where, __LINE__, __FILE__, 'calendar');
2110 2107
 			// for new or changed group-invitations, remove previously deleted members, so they show up again
2111 2108
 			if (($ret = $this->db->affected_rows()) && $user_type == 'u' && $user_id < 0)
2112 2109
 			{
@@ -2119,7 +2116,7 @@  discard block
 block discarded – undo
2119 2116
 		// update modified and modifier in main table
2120 2117
 		if ($ret)
2121 2118
 		{
2122
-			$this->updateModified($cal_id, true);	// true = update series master too
2119
+			$this->updateModified($cal_id, true); // true = update series master too
2123 2120
 		}
2124 2121
 		//error_log(__METHOD__."($cal_id,$user_type,$user_id,$status,$recur_date) = $ret");
2125 2122
 		return $ret;
@@ -2134,7 +2131,7 @@  discard block
 block discarded – undo
2134 2131
 	 * @param array $participants uid => status pairs
2135 2132
 	 * @param boolean $exception =null true or false to set recure_exception flag, null leave it unchanged (new are by default no exception)
2136 2133
 	 */
2137
-	function recurrence($cal_id,$start,$end,$participants,$exception=null)
2134
+	function recurrence($cal_id, $start, $end, $participants, $exception = null)
2138 2135
 	{
2139 2136
 		//error_log(__METHOD__."($cal_id, $start, $end, ".array2string($participants).", ".array2string($exception));
2140 2137
 		$update = array('cal_end' => $end);
@@ -2143,7 +2140,7 @@  discard block
 block discarded – undo
2143 2140
 		$this->db->insert($this->dates_table, $update, array(
2144 2141
 			'cal_id' => $cal_id,
2145 2142
 			'cal_start'  => $start,
2146
-		),__LINE__,__FILE__,'calendar');
2143
+		), __LINE__, __FILE__, 'calendar');
2147 2144
 
2148 2145
 		if (!is_array($participants))
2149 2146
 		{
@@ -2151,26 +2148,26 @@  discard block
 block discarded – undo
2151 2148
 		}
2152 2149
 		if ($exception !== true)
2153 2150
 		{
2154
-			foreach($participants as $uid => $status)
2151
+			foreach ($participants as $uid => $status)
2155 2152
 			{
2156
-				if ($status == 'G') continue;	// dont save group-invitations
2153
+				if ($status == 'G') continue; // dont save group-invitations
2157 2154
 
2158 2155
 				$type = '';
2159 2156
 				$id = null;
2160 2157
 				self::split_user($uid, $type, $id, true);
2161 2158
 				$quantity = $role = null;
2162
-				self::split_status($status,$quantity,$role);
2163
-				$this->db->insert($this->user_table,array(
2159
+				self::split_status($status, $quantity, $role);
2160
+				$this->db->insert($this->user_table, array(
2164 2161
 					'cal_status'	=> $status,
2165 2162
 					'cal_quantity'	=> $quantity,
2166 2163
 					'cal_role'		=> $role,
2167 2164
 					'cal_user_attendee' => $type == 'e' ? substr($uid, 1) : null,
2168
-				),array(
2165
+				), array(
2169 2166
 					'cal_id'		 => $cal_id,
2170 2167
 					'cal_recur_date' => $start,
2171 2168
 					'cal_user_type'  => $type,
2172 2169
 					'cal_user_id' 	 => $id,
2173
-				),__LINE__,__FILE__,'calendar');
2170
+				), __LINE__, __FILE__, 'calendar');
2174 2171
 			}
2175 2172
 		}
2176 2173
 	}
@@ -2184,7 +2181,7 @@  discard block
 block discarded – undo
2184 2181
 	function unfinished_recuring($time)
2185 2182
 	{
2186 2183
 		$ids = array();
2187
-		foreach($rs=$this->db->select($this->repeats_table, "$this->repeats_table.cal_id,MAX(cal_start) AS cal_start",
2184
+		foreach ($rs = $this->db->select($this->repeats_table, "$this->repeats_table.cal_id,MAX(cal_start) AS cal_start",
2188 2185
 			'(range_end IS NULL OR range_end > '.(int)$time.')',
2189 2186
 			__LINE__, __FILE__, false, "GROUP BY $this->repeats_table.cal_id,range_end", 'calendar', 0,
2190 2187
 			" JOIN $this->cal_table ON $this->repeats_table.cal_id=$this->cal_table.cal_id".
@@ -2210,9 +2207,9 @@  discard block
 block discarded – undo
2210 2207
 		// update timestamp of series master, updates own timestamp too, which does not hurt ;-)
2211 2208
 		$this->updateModified($cal_id, true);
2212 2209
 
2213
-		foreach($this->all_tables as $table)
2210
+		foreach ($this->all_tables as $table)
2214 2211
 		{
2215
-			$this->db->delete($table,array('cal_id'=>$cal_id),__LINE__,__FILE__,'calendar');
2212
+			$this->db->delete($table, array('cal_id'=>$cal_id), __LINE__, __FILE__, 'calendar');
2216 2213
 		}
2217 2214
 	}
2218 2215
 
@@ -2228,19 +2225,19 @@  discard block
 block discarded – undo
2228 2225
 	function purge($date)
2229 2226
 	{
2230 2227
 		// with new range_end we simple delete all with range_end < $date (range_end NULL is never returned)
2231
-		foreach($this->db->select($this->cal_table, 'cal_id', 'range_end < '.(int)$date, __LINE__, __FILE__, false, '', 'calendar') as $row)
2228
+		foreach ($this->db->select($this->cal_table, 'cal_id', 'range_end < '.(int)$date, __LINE__, __FILE__, false, '', 'calendar') as $row)
2232 2229
 		{
2233 2230
 			//echo __METHOD__." About to delete".$row['cal_id']."\r\n";
2234
-			foreach($this->all_tables as $table)
2231
+			foreach ($this->all_tables as $table)
2235 2232
 			{
2236 2233
 				$this->db->delete($table, array('cal_id'=>$row['cal_id']), __LINE__, __FILE__, 'calendar');
2237 2234
 			}
2238 2235
 			// handle sync
2239
-			$this->db->update('egw_api_content_history',array(
2236
+			$this->db->update('egw_api_content_history', array(
2240 2237
 				'sync_deleted' => time(),
2241
-			),array(
2238
+			), array(
2242 2239
 				'sync_appname' => 'calendar',
2243
-				'sync_contentid' => $row['cal_id'],	// sync_contentid is varchar(60)!
2240
+				'sync_contentid' => $row['cal_id'], // sync_contentid is varchar(60)!
2244 2241
 			), __LINE__, __FILE__, 'calendar');
2245 2242
 			// handle links
2246 2243
 			Link::unlink('', 'calendar', $row['cal_id']);
@@ -2263,23 +2260,23 @@  discard block
 block discarded – undo
2263 2260
 	 * @param boolean $update_cache =null true: re-read given $cal_id, false: delete given $cal_id
2264 2261
 	 * @return array of (cal_id => array of) alarms with alarm-id as key
2265 2262
 	 */
2266
-	function read_alarms($cal_id, $update_cache=null)
2263
+	function read_alarms($cal_id, $update_cache = null)
2267 2264
 	{
2268 2265
 		if (!isset(self::$alarm_cache) && is_array($cal_id))
2269 2266
 		{
2270 2267
 			self::$alarm_cache = array();
2271 2268
 			if (($jobs = $this->async->read('cal:%')))
2272 2269
 			{
2273
-				foreach($jobs as $id => $job)
2270
+				foreach ($jobs as $id => $job)
2274 2271
 				{
2275
-					$alarm         = $job['data'];	// text, enabled
2272
+					$alarm         = $job['data']; // text, enabled
2276 2273
 					$alarm['id']   = $id;
2277 2274
 					$alarm['time'] = $job['next'];
2278 2275
 
2279 2276
 					self::$alarm_cache[$alarm['cal_id']][$id] = $alarm;
2280 2277
 				}
2281 2278
 			}
2282
-			unset($update_cache);	// just done
2279
+			unset($update_cache); // just done
2283 2280
 		}
2284 2281
 		$alarms = array();
2285 2282
 
@@ -2287,13 +2284,13 @@  discard block
 block discarded – undo
2287 2284
 		{
2288 2285
 			if (isset($update_cache))
2289 2286
 			{
2290
-				foreach((array)$cal_id as $id)
2287
+				foreach ((array)$cal_id as $id)
2291 2288
 				{
2292 2289
 					if ($update_cache === false)
2293 2290
 					{
2294 2291
 						unset(self::$alarm_cache[$cal_id]);
2295 2292
 					}
2296
-					elseif($update_cache === true)
2293
+					elseif ($update_cache === true)
2297 2294
 					{
2298 2295
 						self::$alarm_cache[$cal_id] = $this->read_alarms_nocache($cal_id);
2299 2296
 					}
@@ -2305,7 +2302,7 @@  discard block
 block discarded – undo
2305 2302
 			}
2306 2303
 			else
2307 2304
 			{
2308
-				foreach($cal_id as $id)
2305
+				foreach ($cal_id as $id)
2309 2306
 				{
2310 2307
 					$alarms[$id] = (array)self::$alarm_cache[$id];
2311 2308
 				}
@@ -2320,9 +2317,9 @@  discard block
 block discarded – undo
2320 2317
 	{
2321 2318
 		if (($jobs = $this->async->read('cal:'.(int)$cal_id.':%')))
2322 2319
 		{
2323
-			foreach($jobs as $id => $job)
2320
+			foreach ($jobs as $id => $job)
2324 2321
 			{
2325
-				$alarm         = $job['data'];	// text, enabled
2322
+				$alarm         = $job['data']; // text, enabled
2326 2323
 				$alarm['id']   = $id;
2327 2324
 				$alarm['time'] = $job['next'];
2328 2325
 
@@ -2345,8 +2342,8 @@  discard block
 block discarded – undo
2345 2342
 		{
2346 2343
 			return False;
2347 2344
 		}
2348
-		list($alarm_id,$job) = each($jobs);
2349
-		$alarm         = $job['data'];	// text, enabled
2345
+		list($alarm_id, $job) = each($jobs);
2346
+		$alarm         = $job['data']; // text, enabled
2350 2347
 		$alarm['id']   = $alarm_id;
2351 2348
 		$alarm['time'] = $job['next'];
2352 2349
 
@@ -2362,12 +2359,12 @@  discard block
 block discarded – undo
2362 2359
 	 * @param boolean $update_modified =true call update modified, default true
2363 2360
 	 * @return string id of the alarm
2364 2361
 	 */
2365
-	function save_alarm($cal_id, $alarm, $update_modified=true)
2362
+	function save_alarm($cal_id, $alarm, $update_modified = true)
2366 2363
 	{
2367 2364
 		//error_log(__METHOD__."($cal_id, ".array2string($alarm).', '.array2string($update_modified).') '.function_backtrace());
2368 2365
 		if (!($id = $alarm['id']))
2369 2366
 		{
2370
-			$alarms = $this->read_alarms($cal_id);	// find a free alarm#
2367
+			$alarms = $this->read_alarms($cal_id); // find a free alarm#
2371 2368
 			$n = count($alarms);
2372 2369
 			do
2373 2370
 			{
@@ -2380,12 +2377,12 @@  discard block
 block discarded – undo
2380 2377
 		{
2381 2378
 			$this->async->cancel_timer($id);
2382 2379
 		}
2383
-		$alarm['cal_id'] = $cal_id;		// we need the back-reference
2380
+		$alarm['cal_id'] = $cal_id; // we need the back-reference
2384 2381
 		// add an alarm uid, if none is given
2385 2382
 		if (empty($alarm['uid']) && class_exists('Horde_Support_Uuid')) $alarm['uid'] = (string)new Horde_Support_Uuid;
2386 2383
 		//error_log(__METHOD__.__LINE__.' Save Alarm for CalID:'.$cal_id.'->'.array2string($alarm).'-->'.$id.'#'.function_backtrace());
2387 2384
 		// allways store job with the alarm owner as job-owner to get eg. the correct from address
2388
-		if (!$this->async->set_timer($alarm['time'],$id,'calendar.calendar_boupdate.send_alarm',$alarm,$alarm['owner']))
2385
+		if (!$this->async->set_timer($alarm['time'], $id, 'calendar.calendar_boupdate.send_alarm', $alarm, $alarm['owner']))
2389 2386
 		{
2390 2387
 			return False;
2391 2388
 		}
@@ -2412,7 +2409,7 @@  discard block
 block discarded – undo
2412 2409
 		//error_log(__METHOD__."($cal_id) ".function_backtrace());
2413 2410
 		if (($alarms = $this->read_alarms($cal_id)))
2414 2411
 		{
2415
-			foreach(array_keys($alarms) as $id)
2412
+			foreach (array_keys($alarms) as $id)
2416 2413
 			{
2417 2414
 				$this->async->cancel_timer($id);
2418 2415
 			}
@@ -2432,7 +2429,7 @@  discard block
 block discarded – undo
2432 2429
 	{
2433 2430
 		//error_log(__METHOD__."('$id') ".function_backtrace());
2434 2431
 		// update the modification information of the related event
2435
-		list(,$cal_id) = explode(':',$id);
2432
+		list(,$cal_id) = explode(':', $id);
2436 2433
 		if ($cal_id)
2437 2434
 		{
2438 2435
 			$this->updateModified($cal_id, true);
@@ -2451,7 +2448,7 @@  discard block
 block discarded – undo
2451 2448
 	 * @param array|int $old_user integer old user or array with keys 'account_id' and 'new_owner' as the deleteaccount hook uses it
2452 2449
 	 * @param int $new_user =null
2453 2450
 	 */
2454
-	function deleteaccount($old_user, $new_user=null)
2451
+	function deleteaccount($old_user, $new_user = null)
2455 2452
 	{
2456 2453
 		if (is_array($old_user))
2457 2454
 		{
@@ -2462,52 +2459,52 @@  discard block
 block discarded – undo
2462 2459
 		{
2463 2460
 			$user_type = '';
2464 2461
 			$user_id = null;
2465
-			self::split_user($old_user,$user_type,$user_id);
2462
+			self::split_user($old_user, $user_type, $user_id);
2466 2463
 
2467 2464
 			if ($user_type == 'u')	// only accounts can be owners of events
2468 2465
 			{
2469
-				foreach($this->db->select($this->cal_table,'cal_id',array('cal_owner' => $old_user),__LINE__,__FILE__,false,'','calendar') as $row)
2466
+				foreach ($this->db->select($this->cal_table, 'cal_id', array('cal_owner' => $old_user), __LINE__, __FILE__, false, '', 'calendar') as $row)
2470 2467
 				{
2471 2468
 					$this->delete($row['cal_id']);
2472 2469
 				}
2473 2470
 			}
2474
-			$this->db->delete($this->user_table,array(
2471
+			$this->db->delete($this->user_table, array(
2475 2472
 				'cal_user_type' => $user_type,
2476 2473
 				'cal_user_id'   => $user_id,
2477
-			),__LINE__,__FILE__,'calendar');
2474
+			), __LINE__, __FILE__, 'calendar');
2478 2475
 
2479 2476
 			// delete calendar entries without participants (can happen if the deleted user is the only participants, but not the owner)
2480
-			foreach($this->db->select($this->cal_table,"DISTINCT $this->cal_table.cal_id",'cal_user_id IS NULL',__LINE__,__FILE__,
2481
-				False,'','calendar',0,"LEFT JOIN $this->user_table ON $this->cal_table.cal_id=$this->user_table.cal_id") as $row)
2477
+			foreach ($this->db->select($this->cal_table, "DISTINCT $this->cal_table.cal_id", 'cal_user_id IS NULL', __LINE__, __FILE__,
2478
+				False, '', 'calendar', 0, "LEFT JOIN $this->user_table ON $this->cal_table.cal_id=$this->user_table.cal_id") as $row)
2482 2479
 			{
2483 2480
 				$this->delete($row['cal_id']);
2484 2481
 			}
2485 2482
 		}
2486 2483
 		else
2487 2484
 		{
2488
-			$this->db->update($this->cal_table,array('cal_owner' => $new_user),array('cal_owner' => $old_user),__LINE__,__FILE__,'calendar');
2485
+			$this->db->update($this->cal_table, array('cal_owner' => $new_user), array('cal_owner' => $old_user), __LINE__, __FILE__, 'calendar');
2489 2486
 			// delete participation of old user, if new user is already a participant
2490 2487
 			$ids = array();
2491
-			foreach($this->db->select($this->user_table,'cal_id',array(		// MySQL does NOT allow to run this as delete!
2488
+			foreach ($this->db->select($this->user_table, 'cal_id', array(		// MySQL does NOT allow to run this as delete!
2492 2489
 				'cal_user_type' => 'u',
2493 2490
 				'cal_user_id' => $old_user,
2494 2491
 				"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')",
2495
-			),__LINE__,__FILE__,false,'','calendar') as $row)
2492
+			), __LINE__, __FILE__, false, '', 'calendar') as $row)
2496 2493
 			{
2497 2494
 				$ids[] = $row['cal_id'];
2498 2495
 			}
2499
-			if ($ids) $this->db->delete($this->user_table,array(
2496
+			if ($ids) $this->db->delete($this->user_table, array(
2500 2497
 				'cal_user_type' => 'u',
2501 2498
 				'cal_user_id' => $old_user,
2502 2499
 				'cal_id' => $ids,
2503
-			),__LINE__,__FILE__,'calendar');
2500
+			), __LINE__, __FILE__, 'calendar');
2504 2501
 			// now change participant in the rest to contain new user instead of old user
2505
-			$this->db->update($this->user_table,array(
2502
+			$this->db->update($this->user_table, array(
2506 2503
 				'cal_user_id' => $new_user,
2507
-			),array(
2504
+			), array(
2508 2505
 				'cal_user_type' => 'u',
2509 2506
 				'cal_user_id' => $old_user,
2510
-			),__LINE__,__FILE__,'calendar');
2507
+			), __LINE__, __FILE__, 'calendar');
2511 2508
 		}
2512 2509
 	}
2513 2510
 
@@ -2521,18 +2518,18 @@  discard block
 block discarded – undo
2521 2518
 	 *
2522 2519
 	 * @return array recur_date => status pairs (index 0 => main status)
2523 2520
 	 */
2524
-	function get_recurrences($cal_id, $uid=null, $start=0, $end=0)
2521
+	function get_recurrences($cal_id, $uid = null, $start = 0, $end = 0)
2525 2522
 	{
2526 2523
 		$participant_status = array();
2527 2524
 		$where = array('cal_id' => $cal_id);
2528
-		if ($start != 0 && $end == 0) $where[] = '(cal_recur_date = 0 OR cal_recur_date >= ' . (int)$start . ')';
2529
-		if ($start == 0 && $end != 0) $where[] = '(cal_recur_date = 0 OR cal_recur_date <= ' . (int)$end . ')';
2525
+		if ($start != 0 && $end == 0) $where[] = '(cal_recur_date = 0 OR cal_recur_date >= '.(int)$start.')';
2526
+		if ($start == 0 && $end != 0) $where[] = '(cal_recur_date = 0 OR cal_recur_date <= '.(int)$end.')';
2530 2527
 		if ($start != 0 && $end != 0)
2531 2528
 		{
2532
-			$where[] = '(cal_recur_date = 0 OR (cal_recur_date >= ' . (int)$start .
2533
-						' AND cal_recur_date <= ' . (int)$end . '))';
2529
+			$where[] = '(cal_recur_date = 0 OR (cal_recur_date >= '.(int)$start.
2530
+						' AND cal_recur_date <= '.(int)$end.'))';
2534 2531
 		}
2535
-		foreach($this->db->select($this->user_table,'DISTINCT cal_recur_date',$where,__LINE__,__FILE__,false,'','calendar') as $row)
2532
+		foreach ($this->db->select($this->user_table, 'DISTINCT cal_recur_date', $where, __LINE__, __FILE__, false, '', 'calendar') as $row)
2536 2533
 		{
2537 2534
 			// inititalize the array
2538 2535
 			$participant_status[$row['cal_recur_date']] = null;
@@ -2546,17 +2543,17 @@  discard block
 block discarded – undo
2546 2543
 			'cal_user_type'	=> $user_type ? $user_type : 'u',
2547 2544
 			'cal_user_id'   => $user_id,
2548 2545
 		);
2549
-		if ($start != 0 && $end == 0) $where2[] = '(cal_recur_date = 0 OR cal_recur_date >= ' . (int)$start . ')';
2550
-		if ($start == 0 && $end != 0) $where2[] = '(cal_recur_date = 0 OR cal_recur_date <= ' . (int)$end . ')';
2546
+		if ($start != 0 && $end == 0) $where2[] = '(cal_recur_date = 0 OR cal_recur_date >= '.(int)$start.')';
2547
+		if ($start == 0 && $end != 0) $where2[] = '(cal_recur_date = 0 OR cal_recur_date <= '.(int)$end.')';
2551 2548
 		if ($start != 0 && $end != 0)
2552 2549
 		{
2553
-			$where2[] = '(cal_recur_date = 0 OR (cal_recur_date >= ' . (int)$start .
2554
-						' AND cal_recur_date <= ' . (int)$end . '))';
2550
+			$where2[] = '(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,'cal_recur_date,cal_status,cal_quantity,cal_role',$where2,
2557
-				__LINE__,__FILE__,false,'','calendar') as $row)
2553
+		foreach ($this->db->select($this->user_table, 'cal_recur_date,cal_status,cal_quantity,cal_role', $where2,
2554
+				__LINE__, __FILE__, false, '', 'calendar') as $row)
2558 2555
 		{
2559
-			$status = self::combine_status($row['cal_status'],$row['cal_quantity'],$row['cal_role']);
2556
+			$status = self::combine_status($row['cal_status'], $row['cal_quantity'], $row['cal_role']);
2560 2557
 			$participant_status[$row['cal_recur_date']] = $status;
2561 2558
 		}
2562 2559
 		return $participant_status;
@@ -2605,8 +2602,8 @@  discard block
 block discarded – undo
2605 2602
 			'cal_uid'		=> $uid,
2606 2603
 		);
2607 2604
 		$related = array();
2608
-		foreach ($this->db->select($this->cal_table,'cal_id,cal_reference',$where,
2609
-				__LINE__,__FILE__,false,'','calendar') as $row)
2605
+		foreach ($this->db->select($this->cal_table, 'cal_id,cal_reference', $where,
2606
+				__LINE__, __FILE__, false, '', 'calendar') as $row)
2610 2607
 		{
2611 2608
 			if ($row['cal_reference'] != 0)
2612 2609
 			{
@@ -2635,10 +2632,10 @@  discard block
 block discarded – undo
2635 2632
 	 *
2636 2633
 	 * @return array		Array of exception days (false for non-recurring events).
2637 2634
 	 */
2638
-	function get_recurrence_exceptions($event, $tz_id=null, $start=0, $end=0, $filter='all')
2635
+	function get_recurrence_exceptions($event, $tz_id = null, $start = 0, $end = 0, $filter = 'all')
2639 2636
 	{
2640 2637
 		if (!is_array($event)) return false;
2641
-		$cal_id = (int) $event['id'];
2638
+		$cal_id = (int)$event['id'];
2642 2639
 		//error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2643 2640
 		//		"($cal_id, $tz_id, $filter): " . $event['tzid']);
2644 2641
 		if (!$cal_id || $event['recur_type'] == MCAL_RECUR_NONE) return false;
@@ -2662,27 +2659,27 @@  discard block
 block discarded – undo
2662 2659
 		while ($egw_rrule->valid())
2663 2660
 		{
2664 2661
 			while ($egw_rrule->exceptions &&
2665
-				in_array($egw_rrule->current->format('Ymd'),$egw_rrule->exceptions))
2662
+				in_array($egw_rrule->current->format('Ymd'), $egw_rrule->exceptions))
2666 2663
 			{
2667
-				if (in_array($filter, array('map','tz_map','rrule','tz_rrule')))
2664
+				if (in_array($filter, array('map', 'tz_map', 'rrule', 'tz_rrule')))
2668 2665
 				{
2669 2666
 					 // real exception
2670
-					$locts = (int)Api\DateTime::to($egw_rrule->current(),'server');
2667
+					$locts = (int)Api\DateTime::to($egw_rrule->current(), 'server');
2671 2668
 					if ($expand_all)
2672 2669
 					{
2673
-						$remts = (int)Api\DateTime::to($remote_rrule->current(),'server');
2670
+						$remts = (int)Api\DateTime::to($remote_rrule->current(), 'server');
2674 2671
 						if ($remote)
2675 2672
 						{
2676
-							$days[$locts]= $remts;
2673
+							$days[$locts] = $remts;
2677 2674
 						}
2678 2675
 						else
2679 2676
 						{
2680
-							$days[$remts]= $locts;
2677
+							$days[$remts] = $locts;
2681 2678
 						}
2682 2679
 					}
2683 2680
 					else
2684 2681
 					{
2685
-						$days[$locts]= $locts;
2682
+						$days[$locts] = $locts;
2686 2683
 					}
2687 2684
 				}
2688 2685
 				if ($expand_all)
@@ -2693,14 +2690,14 @@  discard block
 block discarded – undo
2693 2690
 				if (!$egw_rrule->valid()) return $days;
2694 2691
 			}
2695 2692
 			$day = $egw_rrule->current();
2696
-			$locts = (int)Api\DateTime::to($day,'server');
2693
+			$locts = (int)Api\DateTime::to($day, 'server');
2697 2694
 			$tz_exception = ($filter == 'tz_rrule');
2698 2695
 			//error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2699 2696
 			//	'()[EVENT Server]: ' . $day->format('Ymd\THis') . " ($locts)");
2700 2697
 			if ($expand_all)
2701 2698
 			{
2702 2699
 				$remote_day = $remote_rrule->current();
2703
-				$remts = (int)Api\DateTime::to($remote_day,'server');
2700
+				$remts = (int)Api\DateTime::to($remote_day, 'server');
2704 2701
 			//	error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2705 2702
 			//	'()[EVENT Device]: ' . $remote_day->format('Ymd\THis') . " ($remts)");
2706 2703
 			}
@@ -2719,11 +2716,11 @@  discard block
 block discarded – undo
2719 2716
 						//	'() tz exception: ' . $day->format('Ymd\THis'));
2720 2717
 						if ($remote)
2721 2718
 						{
2722
-							$days[$locts]= $remts;
2719
+							$days[$locts] = $remts;
2723 2720
 						}
2724 2721
 						else
2725 2722
 						{
2726
-							$days[$remts]= $locts;
2723
+							$days[$remts] = $locts;
2727 2724
 						}
2728 2725
 					}
2729 2726
 				}
@@ -2745,18 +2742,18 @@  discard block
 block discarded – undo
2745 2742
 							{
2746 2743
 								if ($remote)
2747 2744
 								{
2748
-									$days[$locts]= $remts;
2745
+									$days[$locts] = $remts;
2749 2746
 								}
2750 2747
 								else
2751 2748
 								{
2752
-									$days[$remts]= $locts;
2749
+									$days[$remts] = $locts;
2753 2750
 								}
2754 2751
 							}
2755 2752
 						}
2756 2753
 					}
2757 2754
 					elseif ($filter != 'map')
2758 2755
 					{
2759
-						$days[$locts]= $locts;
2756
+						$days[$locts] = $locts;
2760 2757
 					}
2761 2758
 				}
2762 2759
 				elseif (($filter == 'map' || filter == 'tz_map') &&
@@ -2766,11 +2763,11 @@  discard block
 block discarded – undo
2766 2763
 					if ($expand_all)
2767 2764
 					{
2768 2765
 
2769
-						$days[$remts]= $locts;
2766
+						$days[$remts] = $locts;
2770 2767
 					}
2771 2768
 					else
2772 2769
 					{
2773
-						$days[$locts]= $locts;
2770
+						$days[$locts] = $locts;
2774 2771
 					}
2775 2772
 				}
2776 2773
 			}
@@ -2794,9 +2791,9 @@  discard block
 block discarded – undo
2794 2791
 	 */
2795 2792
 	function status_pseudo_exception($cal_id, $recur_date, $filter)
2796 2793
 	{
2797
-		static $recurrence_zero=null;
2798
-		static $cached_id=null;
2799
-		static $user=null;
2794
+		static $recurrence_zero = null;
2795
+		static $cached_id = null;
2796
+		static $user = null;
2800 2797
 
2801 2798
 		if (!isset($cached_id) || $cached_id != $cal_id)
2802 2799
 		{
@@ -2807,8 +2804,8 @@  discard block
 block discarded – undo
2807 2804
 				'cal_id' => $cal_id,
2808 2805
 				'cal_recur_date' => 0,
2809 2806
 			);
2810
-			foreach ($this->db->select($this->user_table,'cal_user_type,cal_user_id,cal_user_attendee,cal_status',$where,
2811
-				__LINE__,__FILE__,false,'','calendar') as $row)
2807
+			foreach ($this->db->select($this->user_table, 'cal_user_type,cal_user_id,cal_user_attendee,cal_status', $where,
2808
+				__LINE__, __FILE__, false, '', 'calendar') as $row)
2812 2809
 			{
2813 2810
 				switch ($row['cal_user_type'])
2814 2811
 				{
@@ -2831,8 +2828,8 @@  discard block
 block discarded – undo
2831 2828
 			'cal_id' => $cal_id,
2832 2829
 			'cal_recur_date' => $recur_date,
2833 2830
 		);
2834
-		foreach ($this->db->select($this->user_table,'cal_user_type,cal_user_id,cal_user_attendee,cal_status',$where,
2835
-			__LINE__,__FILE__,false,'','calendar') as $row)
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)
2836 2833
 		{
2837 2834
 			switch ($row['cal_user_type'])
2838 2835
 			{
@@ -2929,14 +2926,14 @@  discard block
 block discarded – undo
2929 2926
 			}
2930 2927
 			$timezone = self::$tz_cache[$event['tzid']];
2931 2928
 		}
2932
-		$start_time = new Api\DateTime($event['start'],Api\DateTime::$server_timezone);
2929
+		$start_time = new Api\DateTime($event['start'], Api\DateTime::$server_timezone);
2933 2930
 		$start_time->setTimezone($timezone);
2934
-		$end_time = new Api\DateTime($event['end'],Api\DateTime::$server_timezone);
2931
+		$end_time = new Api\DateTime($event['end'], Api\DateTime::$server_timezone);
2935 2932
 		$end_time->setTimezone($timezone);
2936 2933
 		//error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2937 2934
 		//	'(): ' . $start . '-' . $end);
2938
-		$start = Api\DateTime::to($start_time,'array');
2939
-		$end = Api\DateTime::to($end_time,'array');
2935
+		$start = Api\DateTime::to($start_time, 'array');
2936
+		$end = Api\DateTime::to($end_time, 'array');
2940 2937
 
2941 2938
 
2942 2939
 		return !$start['hour'] && !$start['minute'] && $end['hour'] == 23 && $end['minute'] == 59;
@@ -2950,7 +2947,7 @@  discard block
 block discarded – undo
2950 2947
 	 *
2951 2948
 	 * @return DateTime
2952 2949
 	 */
2953
-	function &startOfDay(Api\DateTime $time, $tz_id=null)
2950
+	function &startOfDay(Api\DateTime $time, $tz_id = null)
2954 2951
 	{
2955 2952
 		if (empty($tz_id))
2956 2953
 		{
@@ -2975,14 +2972,14 @@  discard block
 block discarded – undo
2975 2972
 	 * @param int $time =null new timestamp, default current (server-)time
2976 2973
 	 * @param int $modifier =null uid of the modifier, default current user
2977 2974
 	 */
2978
-	function updateModified($id, $update_master=false, $time=null, $modifier=null)
2975
+	function updateModified($id, $update_master = false, $time = null, $modifier = null)
2979 2976
 	{
2980 2977
 		if (is_null($time) || !$time) $time = time();
2981 2978
 		if (is_null($modifier)) $modifier = $GLOBALS['egw_info']['user']['account_id'];
2982 2979
 
2983 2980
 		$this->db->update($this->cal_table,
2984 2981
 			array('cal_modified' => $time, 'cal_modifier' => $modifier),
2985
-			array('cal_id' => $id), __LINE__,__FILE__, 'calendar');
2982
+			array('cal_id' => $id), __LINE__, __FILE__, 'calendar');
2986 2983
 
2987 2984
 		// if event is an exception: update modified of master, to force etag, ctag and sync-token change
2988 2985
 		if ($update_master)
Please login to merge, or discard this patch.