Completed
Push — 16.1 ( d34917...a71f8e )
by Hadi
40:44 queued 26:00
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 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 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 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
 
@@ -1382,9 +1381,9 @@  discard block
 block discarded – undo
1382 1381
 		}
1383 1382
 
1384 1383
 		// add colum prefix 'cal_' if there's not already a 'recur_' prefix
1385
-		foreach($event as $col => $val)
1384
+		foreach ($event as $col => $val)
1386 1385
 		{
1387
-			if ($col[0] != '#' && substr($col,0,6) != 'recur_' && substr($col,0,6) != 'range_' && $col != 'alarm' && $col != 'tz_id' && $col != 'caldav_name')
1386
+			if ($col[0] != '#' && substr($col, 0, 6) != 'recur_' && substr($col, 0, 6) != 'range_' && $col != 'alarm' && $col != 'tz_id' && $col != 'caldav_name')
1388 1387
 			{
1389 1388
 				$event['cal_'.$col] = $val;
1390 1389
 				unset($event[$col]);
@@ -1394,13 +1393,12 @@  discard block
 block discarded – undo
1394 1393
 		if (isset($event['cal_start'])) $event['range_start'] = $event['cal_start'];
1395 1394
 		if (isset($event['cal_end']))
1396 1395
 		{
1397
-			$event['range_end'] = $event['recur_type'] == MCAL_RECUR_NONE ? $event['cal_end'] :
1398
-				($event['recur_enddate'] ? $event['recur_enddate'] : null);
1396
+			$event['range_end'] = $event['recur_type'] == MCAL_RECUR_NONE ? $event['cal_end'] : ($event['recur_enddate'] ? $event['recur_enddate'] : null);
1399 1397
 		}
1400 1398
 		// ensure that we find mathing entries later on
1401 1399
 		if (!is_array($event['cal_category']))
1402 1400
 		{
1403
-			$categories = array_unique(explode(',',$event['cal_category']));
1401
+			$categories = array_unique(explode(',', $event['cal_category']));
1404 1402
 			sort($categories);
1405 1403
 		}
1406 1404
 		else
@@ -1409,7 +1407,7 @@  discard block
 block discarded – undo
1409 1407
 		}
1410 1408
 		sort($categories, SORT_NUMERIC);
1411 1409
 
1412
-		$event['cal_category'] = implode(',',$categories);
1410
+		$event['cal_category'] = implode(',', $categories);
1413 1411
 
1414 1412
 		// make sure recurring events never reference to an other recurrent event
1415 1413
 		if ($event['recur_type'] != MCAL_RECUR_NONE) $event['cal_reference'] = 0;
@@ -1427,18 +1425,18 @@  discard block
 block discarded – undo
1427 1425
 			// read only timezone id, to check if it is changed
1428 1426
 			if ($event['recur_type'] != MCAL_RECUR_NONE)
1429 1427
 			{
1430
-				$old_tz_id = $this->db->select($this->cal_table,'tz_id',$where,__LINE__,__FILE__,'calendar')->fetchColumn();
1428
+				$old_tz_id = $this->db->select($this->cal_table, 'tz_id', $where, __LINE__, __FILE__, 'calendar')->fetchColumn();
1431 1429
 			}
1432 1430
 			if (!is_null($etag)) $where['cal_etag'] = $etag;
1433 1431
 
1434 1432
 			unset($event['cal_etag']);
1435
-			$event[] = 'cal_etag=cal_etag+1';	// always update the etag, even if none given to check
1433
+			$event[] = 'cal_etag=cal_etag+1'; // always update the etag, even if none given to check
1436 1434
 
1437
-			$this->db->update($this->cal_table,$event,$where,__LINE__,__FILE__,'calendar');
1435
+			$this->db->update($this->cal_table, $event, $where, __LINE__, __FILE__, 'calendar');
1438 1436
 
1439 1437
 			if (!is_null($etag) && $this->db->affected_rows() < 1)
1440 1438
 			{
1441
-				return 0;	// wrong etag, someone else updated the entry
1439
+				return 0; // wrong etag, someone else updated the entry
1442 1440
 			}
1443 1441
 			if (!is_null($etag)) ++$etag;
1444 1442
 		}
@@ -1447,10 +1445,10 @@  discard block
 block discarded – undo
1447 1445
 			// new event
1448 1446
 			if (!$event['cal_owner']) $event['cal_owner'] = $GLOBALS['egw_info']['user']['account_id'];
1449 1447
 
1450
-			if (!$event['cal_id'] && !isset($event['cal_uid'])) $event['cal_uid'] = '';	// uid is NOT NULL!
1448
+			if (!$event['cal_id'] && !isset($event['cal_uid'])) $event['cal_uid'] = ''; // uid is NOT NULL!
1451 1449
 
1452
-			$this->db->insert($this->cal_table,$event,false,__LINE__,__FILE__,'calendar');
1453
-			if (!($cal_id = $this->db->get_last_insert_id($this->cal_table,'cal_id')))
1450
+			$this->db->insert($this->cal_table, $event, false, __LINE__, __FILE__, 'calendar');
1451
+			if (!($cal_id = $this->db->get_last_insert_id($this->cal_table, 'cal_id')))
1454 1452
 			{
1455 1453
 				return false;
1456 1454
 			}
@@ -1460,7 +1458,7 @@  discard block
 block discarded – undo
1460 1458
 		// event without uid or not strong enough uid
1461 1459
 		if (!isset($event['cal_uid']) || strlen($event['cal_uid']) < $minimum_uid_length)
1462 1460
 		{
1463
-			$update['cal_uid'] = $event['cal_uid'] = Api\CalDAV::generate_uid('calendar',$cal_id);
1461
+			$update['cal_uid'] = $event['cal_uid'] = Api\CalDAV::generate_uid('calendar', $cal_id);
1464 1462
 		}
1465 1463
 		// set caldav_name, if not given by caller
1466 1464
 		if (empty($event['caldav_name']) && version_compare($GLOBALS['egw_info']['apps']['calendar']['version'], '1.9.003', '>='))
@@ -1469,37 +1467,37 @@  discard block
 block discarded – undo
1469 1467
 		}
1470 1468
 		if ($update)
1471 1469
 		{
1472
-			$this->db->update($this->cal_table, $update, array('cal_id' => $cal_id),__LINE__,__FILE__,'calendar');
1470
+			$this->db->update($this->cal_table, $update, array('cal_id' => $cal_id), __LINE__, __FILE__, 'calendar');
1473 1471
 		}
1474 1472
 
1475 1473
 		if ($event['recur_type'] == MCAL_RECUR_NONE)
1476 1474
 		{
1477
-			$this->db->delete($this->dates_table,array(
1475
+			$this->db->delete($this->dates_table, array(
1478 1476
 				'cal_id' => $cal_id),
1479
-				__LINE__,__FILE__,'calendar');
1477
+				__LINE__, __FILE__, 'calendar');
1480 1478
 
1481 1479
 			// delete all user-records, with recur-date != 0
1482
-			$this->db->delete($this->user_table,array(
1480
+			$this->db->delete($this->user_table, array(
1483 1481
 				'cal_id' => $cal_id, 'cal_recur_date != 0'),
1484
-				__LINE__,__FILE__,'calendar');
1482
+				__LINE__, __FILE__, 'calendar');
1485 1483
 
1486
-			$this->db->delete($this->repeats_table,array(
1484
+			$this->db->delete($this->repeats_table, array(
1487 1485
 				'cal_id' => $cal_id),
1488
-				__LINE__,__FILE__,'calendar');
1486
+				__LINE__, __FILE__, 'calendar');
1489 1487
 
1490 1488
 			// add exception marker to master, so participants added to exceptions *only* get found
1491 1489
 			if ($event['cal_reference'])
1492 1490
 			{
1493 1491
 				$master_participants = array();
1494
-				foreach($this->db->select($this->user_table, 'cal_user_type,cal_user_id,cal_user_attendee', array(
1492
+				foreach ($this->db->select($this->user_table, 'cal_user_type,cal_user_id,cal_user_attendee', array(
1495 1493
 					'cal_id' => $event['cal_reference'],
1496 1494
 					'cal_recur_date' => 0,
1497
-					"cal_status != 'X'",	// deleted need to be replaced with exception marker too
1495
+					"cal_status != 'X'", // deleted need to be replaced with exception marker too
1498 1496
 				), __LINE__, __FILE__, 'calendar') as $row)
1499 1497
 				{
1500 1498
 					$master_participants[] = self::combine_user($row['cal_user_type'], $row['cal_user_id'], $row['cal_user_attendee']);
1501 1499
 				}
1502
-				foreach(array_diff(array_keys((array)$event['cal_participants']), $master_participants) as $uid)
1500
+				foreach (array_diff(array_keys((array)$event['cal_participants']), $master_participants) as $uid)
1503 1501
 				{
1504 1502
 					$user_type = $user_id = null;
1505 1503
 					self::split_user($uid, $user_type, $user_id, true);
@@ -1518,10 +1516,10 @@  discard block
 block discarded – undo
1518 1516
 		else // write information about recuring event, if recur_type is present in the array
1519 1517
 		{
1520 1518
 			// fetch information about the currently saved (old) event
1521
-			$old_min = (int) $this->db->select($this->dates_table,'MIN(cal_start)',array('cal_id'=>$cal_id),__LINE__,__FILE__,false,'','calendar')->fetchColumn();
1522
-			$old_duration = (int) $this->db->select($this->dates_table,'MIN(cal_end)',array('cal_id'=>$cal_id),__LINE__,__FILE__,false,'','calendar')->fetchColumn() - $old_min;
1519
+			$old_min = (int)$this->db->select($this->dates_table, 'MIN(cal_start)', array('cal_id'=>$cal_id), __LINE__, __FILE__, false, '', 'calendar')->fetchColumn();
1520
+			$old_duration = (int)$this->db->select($this->dates_table, 'MIN(cal_end)', array('cal_id'=>$cal_id), __LINE__, __FILE__, false, '', 'calendar')->fetchColumn() - $old_min;
1523 1521
 			$old_exceptions = array();
1524
-			foreach($this->db->select($this->dates_table, 'cal_start', array(
1522
+			foreach ($this->db->select($this->dates_table, 'cal_start', array(
1525 1523
 				'cal_id' => $cal_id,
1526 1524
 				'recur_exception' => true
1527 1525
 			), __LINE__, __FILE__, false, 'ORDER BY cal_start', 'calendar') as $row)
@@ -1540,8 +1538,8 @@  discard block
 block discarded – undo
1540 1538
 				'cal_recur_date' => 0,
1541 1539
 			);
1542 1540
 			$old_participants = array();
1543
-			foreach ($this->db->select($this->user_table,'cal_user_type,cal_user_id,cal_user_attendee,cal_status,cal_quantity,cal_role', $where,
1544
-				__LINE__,__FILE__,false,'','calendar') as $row)
1541
+			foreach ($this->db->select($this->user_table, 'cal_user_type,cal_user_id,cal_user_attendee,cal_status,cal_quantity,cal_role', $where,
1542
+				__LINE__, __FILE__, false, '', 'calendar') as $row)
1545 1543
 			{
1546 1544
 				$uid = self::combine_user($row['cal_user_type'], $row['cal_user_id'], $row['cal_user_attendee']);
1547 1545
 				$status = self::combine_status($row['cal_status'], $row['cal_quantity'], $row['cal_role']);
@@ -1551,7 +1549,7 @@  discard block
 block discarded – undo
1551 1549
 			// re-check: did so much recurrence data change that we have to rebuild it from scratch?
1552 1550
 			if (!$set_recurrences)
1553 1551
 			{
1554
-				$set_recurrences = (isset($event['cal_start']) && (int)$old_min != (int) $event['cal_start']) ||
1552
+				$set_recurrences = (isset($event['cal_start']) && (int)$old_min != (int)$event['cal_start']) ||
1555 1553
 				    $event['recur_type'] != $old_repeats['recur_type'] || $event['recur_data'] != $old_repeats['recur_data'] ||
1556 1554
 					(int)$event['recur_interval'] != (int)$old_repeats['recur_interval'] || $event['tz_id'] != $old_tz_id;
1557 1555
 			}
@@ -1560,22 +1558,22 @@  discard block
 block discarded – undo
1560 1558
 			{
1561 1559
 				// too much recurrence data has changed, we have to do a rebuild from scratch
1562 1560
 				// delete all, but the lowest dates record
1563
-				$this->db->delete($this->dates_table,array(
1561
+				$this->db->delete($this->dates_table, array(
1564 1562
 					'cal_id' => $cal_id,
1565 1563
 					'cal_start > '.(int)$old_min,
1566
-				),__LINE__,__FILE__,'calendar');
1564
+				), __LINE__, __FILE__, 'calendar');
1567 1565
 
1568 1566
 				// delete all user-records, with recur-date != 0
1569
-				$this->db->delete($this->user_table,array(
1567
+				$this->db->delete($this->user_table, array(
1570 1568
 					'cal_id' => $cal_id,
1571 1569
 					'cal_recur_date != 0',
1572
-				),__LINE__,__FILE__,'calendar');
1570
+				), __LINE__, __FILE__, 'calendar');
1573 1571
 			}
1574 1572
 			else
1575 1573
 			{
1576 1574
 				// we adjust some possibly changed recurrences manually
1577 1575
 				// deleted exceptions: re-insert recurrences into the user and dates table
1578
-				if (count($deleted_exceptions = array_diff($old_exceptions,$event['recur_exception'])))
1576
+				if (count($deleted_exceptions = array_diff($old_exceptions, $event['recur_exception'])))
1579 1577
 				{
1580 1578
 					if (isset($event['cal_participants']))
1581 1579
 					{
@@ -1586,7 +1584,7 @@  discard block
 block discarded – undo
1586 1584
 						// use old default
1587 1585
 						$participants = $old_participants;
1588 1586
 					}
1589
-					foreach($deleted_exceptions as $id => $deleted_exception)
1587
+					foreach ($deleted_exceptions as $id => $deleted_exception)
1590 1588
 					{
1591 1589
 						// rebuild participants for the re-inserted recurrence
1592 1590
 						$this->recurrence($cal_id, $deleted_exception, $deleted_exception + $old_duration, $participants);
@@ -1594,24 +1592,24 @@  discard block
 block discarded – undo
1594 1592
 				}
1595 1593
 
1596 1594
 				// check if recurrence enddate was adjusted
1597
-				if(isset($event['recur_enddate']))
1595
+				if (isset($event['recur_enddate']))
1598 1596
 				{
1599 1597
 					// recurrences need to be truncated
1600
-					if((int)$event['recur_enddate'] > 0 &&
1598
+					if ((int)$event['recur_enddate'] > 0 &&
1601 1599
 						((int)$old_repeats['recur_enddate'] == 0 || (int)$old_repeats['recur_enddate'] > (int)$event['recur_enddate'])
1602 1600
 					)
1603 1601
 					{
1604
-						$this->db->delete($this->user_table,array('cal_id' => $cal_id,'cal_recur_date >= '.($event['recur_enddate'] + 1*DAY_s)),__LINE__,__FILE__,'calendar');
1605
-						$this->db->delete($this->dates_table,array('cal_id' => $cal_id,'cal_start >= '.($event['recur_enddate'] + 1*DAY_s)),__LINE__,__FILE__,'calendar');
1602
+						$this->db->delete($this->user_table, array('cal_id' => $cal_id, 'cal_recur_date >= '.($event['recur_enddate'] + 1 * DAY_s)), __LINE__, __FILE__, 'calendar');
1603
+						$this->db->delete($this->dates_table, array('cal_id' => $cal_id, 'cal_start >= '.($event['recur_enddate'] + 1 * DAY_s)), __LINE__, __FILE__, 'calendar');
1606 1604
 					}
1607 1605
 
1608 1606
 					// recurrences need to be expanded
1609
-					if(((int)$event['recur_enddate'] == 0 && (int)$old_repeats['recur_enddate'] > 0)
1607
+					if (((int)$event['recur_enddate'] == 0 && (int)$old_repeats['recur_enddate'] > 0)
1610 1608
 						|| ((int)$event['recur_enddate'] > 0 && (int)$old_repeats['recur_enddate'] > 0 && (int)$old_repeats['recur_enddate'] < (int)$event['recur_enddate'])
1611 1609
 					)
1612 1610
 					{
1613 1611
 						$set_recurrences = true;
1614
-						$set_recurrences_start = ($old_repeats['recur_enddate'] + 1*DAY_s);
1612
+						$set_recurrences_start = ($old_repeats['recur_enddate'] + 1 * DAY_s);
1615 1613
 					}
1616 1614
 					//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");
1617 1615
 				}
@@ -1620,9 +1618,9 @@  discard block
 block discarded – undo
1620 1618
 				if (count($event['recur_exception']))
1621 1619
 				{
1622 1620
 					// added and existing exceptions: delete the execeptions from the user table, it could be the first time
1623
-					$this->db->delete($this->user_table,array('cal_id' => $cal_id,'cal_recur_date' => $event['recur_exception']),__LINE__,__FILE__,'calendar');
1621
+					$this->db->delete($this->user_table, array('cal_id' => $cal_id, 'cal_recur_date' => $event['recur_exception']), __LINE__, __FILE__, 'calendar');
1624 1622
 					// update recur_exception flag based on current exceptions
1625
-					$this->db->update($this->dates_table, 'recur_exception='.$this->db->expression($this->dates_table,array(
1623
+					$this->db->update($this->dates_table, 'recur_exception='.$this->db->expression($this->dates_table, array(
1626 1624
 						'cal_start' => $event['recur_exception'],
1627 1625
 					)), array(
1628 1626
 						'cal_id' => $cal_id,
@@ -1631,25 +1629,25 @@  discard block
 block discarded – undo
1631 1629
 			}
1632 1630
 
1633 1631
 			// write the repeats table
1634
-			unset($event[0]);	// unset the 'etag=etag+1', as it's not in the repeats table
1635
-			$this->db->insert($this->repeats_table,$event,array('cal_id' => $cal_id),__LINE__,__FILE__,'calendar');
1632
+			unset($event[0]); // unset the 'etag=etag+1', as it's not in the repeats table
1633
+			$this->db->insert($this->repeats_table, $event, array('cal_id' => $cal_id), __LINE__, __FILE__, 'calendar');
1636 1634
 		}
1637 1635
 		// update start- and endtime if present in the event-array, evtl. we need to move all recurrences
1638 1636
 		if (isset($event['cal_start']) && isset($event['cal_end']))
1639 1637
 		{
1640
-			$this->move($cal_id,$event['cal_start'],$event['cal_end'],!$cal_id ? false : $change_since, $old_min, $old_min +  $old_duration);
1638
+			$this->move($cal_id, $event['cal_start'], $event['cal_end'], !$cal_id ? false : $change_since, $old_min, $old_min + $old_duration);
1641 1639
 		}
1642 1640
 		// update participants if present in the event-array
1643 1641
 		if (isset($event['cal_participants']))
1644 1642
 		{
1645
-			$this->participants($cal_id,$event['cal_participants'],!$cal_id ? false : $change_since);
1643
+			$this->participants($cal_id, $event['cal_participants'], !$cal_id ? false : $change_since);
1646 1644
 		}
1647 1645
 		// Custom fields
1648
-		foreach($event as $name => $value)
1646
+		foreach ($event as $name => $value)
1649 1647
 		{
1650 1648
 			if ($name[0] == '#')
1651 1649
 			{
1652
-				if (is_array($value) && array_key_exists('id',$value))
1650
+				if (is_array($value) && array_key_exists('id', $value))
1653 1651
 				{
1654 1652
 					//error_log(__METHOD__.__LINE__."$name => ".array2string($value).function_backtrace());
1655 1653
 					$value = $value['id'];
@@ -1657,19 +1655,19 @@  discard block
 block discarded – undo
1657 1655
 				}
1658 1656
 				if ($value)
1659 1657
 				{
1660
-					$this->db->insert($this->extra_table,array(
1661
-						'cal_extra_value'	=> is_array($value) ? implode(',',$value) : $value,
1662
-					),array(
1658
+					$this->db->insert($this->extra_table, array(
1659
+						'cal_extra_value'	=> is_array($value) ? implode(',', $value) : $value,
1660
+					), array(
1663 1661
 						'cal_id'			=> $cal_id,
1664
-						'cal_extra_name'	=> substr($name,1),
1665
-					),__LINE__,__FILE__,'calendar');
1662
+						'cal_extra_name'	=> substr($name, 1),
1663
+					), __LINE__, __FILE__, 'calendar');
1666 1664
 				}
1667 1665
 				else
1668 1666
 				{
1669
-					$this->db->delete($this->extra_table,array(
1667
+					$this->db->delete($this->extra_table, array(
1670 1668
 						'cal_id'			=> $cal_id,
1671
-						'cal_extra_name'	=> substr($name,1),
1672
-					),__LINE__,__FILE__,'calendar');
1669
+						'cal_extra_name'	=> substr($name, 1),
1670
+					), __LINE__, __FILE__, 'calendar');
1673 1671
 				}
1674 1672
 			}
1675 1673
 		}
@@ -1680,9 +1678,9 @@  discard block
 block discarded – undo
1680 1678
 			{
1681 1679
 				if ($alarm['id'] && strpos($alarm['id'], 'cal:'.$cal_id.':') !== 0)
1682 1680
 				{
1683
-					unset($alarm['id']);	// unset the temporary id to add the alarm
1681
+					unset($alarm['id']); // unset the temporary id to add the alarm
1684 1682
 				}
1685
-				if(!isset($alarm['offset']))
1683
+				if (!isset($alarm['offset']))
1686 1684
 				{
1687 1685
 					$alarm['offset'] = $event['cal_start'] - $alarm['time'];
1688 1686
 				}
@@ -1693,14 +1691,14 @@  discard block
 block discarded – undo
1693 1691
 
1694 1692
 				if ($alarm['time'] < time() && !self::shift_alarm($event, $alarm))
1695 1693
 				{
1696
-					continue;	// pgoerzen: don't add alarm in the past
1694
+					continue; // pgoerzen: don't add alarm in the past
1697 1695
 				}
1698
-				$this->save_alarm($cal_id, $alarm, false);	// false: not update modified, we do it anyway
1696
+				$this->save_alarm($cal_id, $alarm, false); // false: not update modified, we do it anyway
1699 1697
 			}
1700 1698
 		}
1701 1699
 		if (is_null($etag))
1702 1700
 		{
1703
-			$etag = $this->db->select($this->cal_table,'cal_etag',array('cal_id' => $cal_id),__LINE__,__FILE__,false,'','calendar')->fetchColumn();
1701
+			$etag = $this->db->select($this->cal_table, 'cal_etag', array('cal_id' => $cal_id), __LINE__, __FILE__, false, '', 'calendar')->fetchColumn();
1704 1702
 		}
1705 1703
 
1706 1704
 		// if event is an exception: update modified of master, to force etag, ctag and sync-token change
@@ -1720,7 +1718,7 @@  discard block
 block discarded – undo
1720 1718
 	 *	are dealing with, default is now.
1721 1719
 	 * @return boolean true if alarm could be shifted, false if not
1722 1720
 	 */
1723
-	public static function shift_alarm(array $_event, array &$alarm, $timestamp=null)
1721
+	public static function shift_alarm(array $_event, array &$alarm, $timestamp = null)
1724 1722
 	{
1725 1723
 		if ($_event['recur_type'] == MCAL_RECUR_NONE)
1726 1724
 		{
@@ -1731,7 +1729,7 @@  discard block
 block discarded – undo
1731 1729
 		$rrule = calendar_rrule::event2rrule($event, false);
1732 1730
 		foreach ($rrule as $time)
1733 1731
 		{
1734
-			if ($start < ($ts = Api\DateTime::to($time,'server')))
1732
+			if ($start < ($ts = Api\DateTime::to($time, 'server')))
1735 1733
 			{
1736 1734
 				$alarm['time'] = $ts - $alarm['offset'];
1737 1735
 				return true;
@@ -1752,34 +1750,34 @@  discard block
 block discarded – undo
1752 1750
 	 * @todo Recalculate recurrences, if timezone changes
1753 1751
 	 * @return int|boolean number of moved recurrences or false on error
1754 1752
 	 */
1755
-	function move($cal_id,$start,$end,$change_since=0,$old_start=0,$old_end=0)
1753
+	function move($cal_id, $start, $end, $change_since = 0, $old_start = 0, $old_end = 0)
1756 1754
 	{
1757 1755
 		//echo "<p>socal::move($cal_id,$start,$end,$change_since,$old_start,$old_end)</p>\n";
1758 1756
 
1759
-		if (!(int) $cal_id) return false;
1757
+		if (!(int)$cal_id) return false;
1760 1758
 
1761 1759
 		if (!$old_start)
1762 1760
 		{
1763
-			if ($change_since !== false) $row = $this->db->select($this->dates_table,'MIN(cal_start) AS cal_start,MIN(cal_end) AS cal_end',
1764
-				array('cal_id'=>$cal_id),__LINE__,__FILE__,false,'','calendar')->fetch();
1761
+			if ($change_since !== false) $row = $this->db->select($this->dates_table, 'MIN(cal_start) AS cal_start,MIN(cal_end) AS cal_end',
1762
+				array('cal_id'=>$cal_id), __LINE__, __FILE__, false, '', 'calendar')->fetch();
1765 1763
 			// if no recurrence found, create one with the new dates
1766 1764
 			if ($change_since === false || !$row || !$row['cal_start'] || !$row['cal_end'])
1767 1765
 			{
1768
-				$this->db->insert($this->dates_table,array(
1766
+				$this->db->insert($this->dates_table, array(
1769 1767
 					'cal_id'    => $cal_id,
1770 1768
 					'cal_start' => $start,
1771 1769
 					'cal_end'   => $end,
1772
-				),false,__LINE__,__FILE__,'calendar');
1770
+				), false, __LINE__, __FILE__, 'calendar');
1773 1771
 
1774 1772
 				return 1;
1775 1773
 			}
1776
-			$move_start = (int) ($start-$row['cal_start']);
1777
-			$move_end   = (int) ($end-$row['cal_end']);
1774
+			$move_start = (int)($start - $row['cal_start']);
1775
+			$move_end   = (int)($end - $row['cal_end']);
1778 1776
 		}
1779 1777
 		else
1780 1778
 		{
1781
-			$move_start = (int) ($start-$old_start);
1782
-			$move_end   = (int) ($end-$old_end);
1779
+			$move_start = (int)($start - $old_start);
1780
+			$move_end   = (int)($end - $old_end);
1783 1781
 		}
1784 1782
 		$where = 'cal_id='.(int)$cal_id;
1785 1783
 
@@ -1787,13 +1785,13 @@  discard block
 block discarded – undo
1787 1785
 		{
1788 1786
 			// move the recur-date of the participants
1789 1787
 			$this->db->query("UPDATE $this->user_table SET cal_recur_date=cal_recur_date+$move_start WHERE $where AND cal_recur_date ".
1790
-				((int)$change_since ? '>= '.(int)$change_since : '!= 0'),__LINE__,__FILE__);
1788
+				((int)$change_since ? '>= '.(int)$change_since : '!= 0'), __LINE__, __FILE__);
1791 1789
 		}
1792 1790
 		if ($move_start || $move_end)
1793 1791
 		{
1794 1792
 			// move the event and it's recurrences
1795 1793
 			$this->db->query("UPDATE $this->dates_table SET cal_start=cal_start+$move_start,cal_end=cal_end+$move_end WHERE $where".
1796
-				((int) $change_since ? ' AND cal_start >= '.(int) $change_since : ''),__LINE__,__FILE__);
1794
+				((int)$change_since ? ' AND cal_start >= '.(int)$change_since : ''), __LINE__, __FILE__);
1797 1795
 		}
1798 1796
 		return $this->db->affected_rows();
1799 1797
 	}
@@ -1812,8 +1810,7 @@  discard block
 block discarded – undo
1812 1810
 		}
1813 1811
 		if (is_array($attendee))
1814 1812
 		{
1815
-			$email = !empty($attendee['email']) ? $user_attendee['email'] :
1816
-				(strtolower(substr($attendee['url'], 0, 7)) == 'mailto:' ? substr($user_attendee['url'], 7) : $attendee['url']);
1813
+			$email = !empty($attendee['email']) ? $user_attendee['email'] : (strtolower(substr($attendee['url'], 0, 7)) == 'mailto:' ? substr($user_attendee['url'], 7) : $attendee['url']);
1817 1814
 			$attendee = !empty($attendee['cn']) ? $attendee['cn'].' <'.$email.'>' : $email;
1818 1815
 		}
1819 1816
 		return $attendee;
@@ -1826,11 +1823,11 @@  discard block
 block discarded – undo
1826 1823
 	 * @param string|array $attendee attendee information: email, json or array with attr cn and url
1827 1824
 	 * @return string|int combined id
1828 1825
 	 */
1829
-	static function combine_user($user_type, $user_id, $attendee=null)
1826
+	static function combine_user($user_type, $user_id, $attendee = null)
1830 1827
 	{
1831 1828
 		if (!$user_type || $user_type == 'u')
1832 1829
 		{
1833
-			return (int) $user_id;
1830
+			return (int)$user_id;
1834 1831
 		}
1835 1832
 		if ($user_type == 'e' && $attendee)
1836 1833
 		{
@@ -1850,12 +1847,12 @@  discard block
 block discarded – undo
1850 1847
 	 * @param string|int &$user_id id
1851 1848
 	 * @param boolean $md5_email =false md5 hash user_id for email / user_type=="e"
1852 1849
 	 */
1853
-	static function split_user($uid, &$user_type, &$user_id, $md5_email=false)
1850
+	static function split_user($uid, &$user_type, &$user_id, $md5_email = false)
1854 1851
 	{
1855 1852
 		if (is_numeric($uid))
1856 1853
 		{
1857 1854
 			$user_type = 'u';
1858
-			$user_id = (int) $uid;
1855
+			$user_id = (int)$uid;
1859 1856
 		}
1860 1857
 		// create md5 hash from lowercased and trimed raw email ("[email protected]", not "Ralf Becker <[email protected]>")
1861 1858
 		elseif ($md5_email && $uid[0] == 'e')
@@ -1869,7 +1866,7 @@  discard block
 block discarded – undo
1869 1866
 		else
1870 1867
 		{
1871 1868
 			$user_type = $uid[0];
1872
-			$user_id = substr($uid,1);
1869
+			$user_id = substr($uid, 1);
1873 1870
 		}
1874 1871
 	}
1875 1872
 
@@ -1881,7 +1878,7 @@  discard block
 block discarded – undo
1881 1878
 	 * @param string $role ='REQ-PARTICIPANT'
1882 1879
 	 * @return string
1883 1880
 	 */
1884
-	static function combine_status($status,$quantity=1,$role='REQ-PARTICIPANT')
1881
+	static function combine_status($status, $quantity = 1, $role = 'REQ-PARTICIPANT')
1885 1882
 	{
1886 1883
 		if ((int)$quantity > 1) $status .= (int)$quantity;
1887 1884
 		if ($role != 'REQ-PARTICIPANT') $status .= $role;
@@ -1897,13 +1894,13 @@  discard block
 block discarded – undo
1897 1894
 	 * @param string &$role=null only O: role
1898 1895
 	 * @return string status U, T, A or R, same as $status parameter on return
1899 1896
 	 */
1900
-	static function split_status(&$status,&$quantity=null,&$role=null)
1897
+	static function split_status(&$status, &$quantity = null, &$role = null)
1901 1898
 	{
1902 1899
 		$quantity = 1;
1903 1900
 		$role = 'REQ-PARTICIPANT';
1904 1901
 		//error_log(__METHOD__.__LINE__.array2string($status));
1905 1902
 		$matches = null;
1906
-		if (is_string($status) && strlen($status) > 1 && preg_match('/^.([0-9]*)(.*)$/',$status,$matches))
1903
+		if (is_string($status) && strlen($status) > 1 && preg_match('/^.([0-9]*)(.*)$/', $status, $matches))
1907 1904
 		{
1908 1905
 			if ((int)$matches[1] > 0) $quantity = (int)$matches[1];
1909 1906
 			if ($matches[2]) $role = $matches[2];
@@ -1930,14 +1927,14 @@  discard block
 block discarded – undo
1930 1927
 	 *		true = only add participants if needed, no participant will be deleted (participants to check/add required in $participants)
1931 1928
 	 * @return int|boolean number of updated recurrences or false on error
1932 1929
 	 */
1933
-	function participants($cal_id,$participants,$change_since=0,$add_only=false)
1930
+	function participants($cal_id, $participants, $change_since = 0, $add_only = false)
1934 1931
 	{
1935 1932
 		//error_log(__METHOD__."($cal_id,".array2string($participants).",$change_since,$add_only");
1936 1933
 
1937 1934
 		$recurrences = array();
1938 1935
 
1939 1936
 		// remove group-invitations, they are NOT stored in the db
1940
-		foreach($participants as $uid => $status)
1937
+		foreach ($participants as $uid => $status)
1941 1938
 		{
1942 1939
 			if ($status[0] == 'G')
1943 1940
 			{
@@ -1946,7 +1943,7 @@  discard block
 block discarded – undo
1946 1943
 		}
1947 1944
 		$where = array('cal_id' => $cal_id);
1948 1945
 
1949
-		if ((int) $change_since)
1946
+		if ((int)$change_since)
1950 1947
 		{
1951 1948
 			$where[] = '(cal_recur_date=0 OR cal_recur_date >= '.(int)$change_since.')';
1952 1949
 		}
@@ -1954,31 +1951,31 @@  discard block
 block discarded – undo
1954 1951
 		if ($change_since !== false)
1955 1952
 		{
1956 1953
 			// find all existing recurrences
1957
-			foreach($this->db->select($this->user_table,'DISTINCT cal_recur_date',$where,__LINE__,__FILE__,false,'','calendar') as $row)
1954
+			foreach ($this->db->select($this->user_table, 'DISTINCT cal_recur_date', $where, __LINE__, __FILE__, false, '', 'calendar') as $row)
1958 1955
 			{
1959 1956
 				$recurrences[] = $row['cal_recur_date'];
1960 1957
 			}
1961 1958
 
1962 1959
 			// update existing entries
1963
-			$existing_entries = $this->db->select($this->user_table,'*',$where,__LINE__,__FILE__,false,'ORDER BY cal_recur_date DESC','calendar');
1960
+			$existing_entries = $this->db->select($this->user_table, '*', $where, __LINE__, __FILE__, false, 'ORDER BY cal_recur_date DESC', 'calendar');
1964 1961
 
1965 1962
 			// create a full list of participants which already exist in the db
1966 1963
 			// with status, quantity and role of the earliest recurence
1967 1964
 			$old_participants = array();
1968
-			foreach($existing_entries as $row)
1965
+			foreach ($existing_entries as $row)
1969 1966
 			{
1970 1967
 				$uid = self::combine_user($row['cal_user_type'], $row['cal_user_id'], $row['cal_user_attendee']);
1971 1968
 				if ($row['cal_recur_date'] || !isset($old_participants[$uid]))
1972 1969
 				{
1973
-					$old_participants[$uid] = self::combine_status($row['cal_status'],$row['cal_quantity'],$row['cal_role']);
1970
+					$old_participants[$uid] = self::combine_status($row['cal_status'], $row['cal_quantity'], $row['cal_role']);
1974 1971
 				}
1975 1972
 			}
1976 1973
 
1977 1974
 			// tag participants which should be deleted
1978
-			if($add_only === false)
1975
+			if ($add_only === false)
1979 1976
 			{
1980 1977
 				$deleted = array();
1981
-				foreach($existing_entries as $row)
1978
+				foreach ($existing_entries as $row)
1982 1979
 				{
1983 1980
 					$uid = self::combine_user($row['cal_user_type'], $row['cal_user_id'], $row['cal_user_attendee']);
1984 1981
 					// delete not longer set participants
@@ -1991,7 +1988,7 @@  discard block
 block discarded – undo
1991 1988
 
1992 1989
 			// only keep added OR status (incl. quantity!) changed participants for further steps
1993 1990
 			// we do not touch unchanged (!) existing ones
1994
-			foreach($participants as $uid => $status)
1991
+			foreach ($participants as $uid => $status)
1995 1992
 			{
1996 1993
 				if ($old_participants[$uid] === $status)
1997 1994
 				{
@@ -2003,46 +2000,46 @@  discard block
 block discarded – undo
2003 2000
 			if ($add_only === false && count($deleted))
2004 2001
 			{
2005 2002
 				$to_or = array();
2006
-				$table_def = $this->db->get_table_definitions('calendar',$this->user_table);
2007
-				foreach($deleted as $type => $ids)
2003
+				$table_def = $this->db->get_table_definitions('calendar', $this->user_table);
2004
+				foreach ($deleted as $type => $ids)
2008 2005
 				{
2009
-					$to_or[] = $this->db->expression($table_def,array(
2006
+					$to_or[] = $this->db->expression($table_def, array(
2010 2007
 						'cal_user_type' => $type,
2011 2008
 						'cal_user_id'   => $ids,
2012 2009
 					));
2013 2010
 				}
2014
-				$where[] = '('.implode(' OR ',$to_or).')';
2015
-				$where[] = "cal_status!='E'";	// do NOT delete exception marker
2016
-				$this->db->update($this->user_table,array('cal_status'=>'X'),$where,__LINE__,__FILE__,'calendar');
2011
+				$where[] = '('.implode(' OR ', $to_or).')';
2012
+				$where[] = "cal_status!='E'"; // do NOT delete exception marker
2013
+				$this->db->update($this->user_table, array('cal_status'=>'X'), $where, __LINE__, __FILE__, 'calendar');
2017 2014
 			}
2018 2015
 		}
2019 2016
 
2020 2017
 		if (count($participants))	// participants which need to be added
2021 2018
 		{
2022
-			if (!count($recurrences)) $recurrences[] = 0;   // insert the default recurrence
2019
+			if (!count($recurrences)) $recurrences[] = 0; // insert the default recurrence
2023 2020
 
2024 2021
 			$delete_deleted = array();
2025 2022
 
2026 2023
 			// update participants
2027
-			foreach($participants as $uid => $status)
2024
+			foreach ($participants as $uid => $status)
2028 2025
 			{
2029 2026
 				$type = $id = $quantity = $role = null;
2030 2027
 				self::split_user($uid, $type, $id, true);
2031
-				self::split_status($status,$quantity,$role);
2028
+				self::split_status($status, $quantity, $role);
2032 2029
 				$set = array(
2033 2030
 					'cal_status'	  => $status,
2034 2031
 					'cal_quantity'	  => $quantity,
2035 2032
 					'cal_role'        => $role,
2036 2033
 					'cal_user_attendee' => $type == 'e' ? substr($uid, 1) : null,
2037 2034
 				);
2038
-				foreach($recurrences as $recur_date)
2035
+				foreach ($recurrences as $recur_date)
2039 2036
 				{
2040
-					$this->db->insert($this->user_table,$set,array(
2037
+					$this->db->insert($this->user_table, $set, array(
2041 2038
 						'cal_id'	      => $cal_id,
2042 2039
 						'cal_recur_date'  => $recur_date,
2043 2040
 						'cal_user_type'   => $type,
2044 2041
 						'cal_user_id' 	  => $id,
2045
-					),__LINE__,__FILE__,'calendar');
2042
+					), __LINE__, __FILE__, 'calendar');
2046 2043
 				}
2047 2044
 				// for new or changed group-invitations, remove previously deleted members, so they show up again
2048 2045
 				if ($uid < 0)
@@ -2052,13 +2049,13 @@  discard block
 block discarded – undo
2052 2049
 			}
2053 2050
 			if ($delete_deleted)
2054 2051
 			{
2055
-				$this->db->delete($this->user_table, $where=array(
2052
+				$this->db->delete($this->user_table, $where = array(
2056 2053
 					'cal_id' => $cal_id,
2057 2054
 					'cal_recur_date' => $recurrences,
2058 2055
 					'cal_user_type' => 'u',
2059 2056
 					'cal_user_id' => array_unique($delete_deleted),
2060 2057
 					'cal_status' => 'X',
2061
-				),__LINE__,__FILE__,'calendar');
2058
+				), __LINE__, __FILE__, 'calendar');
2062 2059
 				//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');
2063 2060
 			}
2064 2061
 		}
@@ -2077,7 +2074,7 @@  discard block
 block discarded – undo
2077 2074
 	 * @param string $attendee =null extra attendee information to set for all types (incl. accounts!)
2078 2075
 	 * @return int number of changed recurrences
2079 2076
 	 */
2080
-	function set_status($cal_id,$user_type,$user_id,$status,$recur_date=0,$role=null,$attendee=null)
2077
+	function set_status($cal_id, $user_type, $user_id, $status, $recur_date = 0, $role = null, $attendee = null)
2081 2078
 	{
2082 2079
 		static $status_code_short = array(
2083 2080
 			REJECTED 	=> 'R',
@@ -2102,7 +2099,7 @@  discard block
 block discarded – undo
2102 2099
 			'cal_user_type'	=> $user_type,
2103 2100
 			'cal_user_id'   => $user_id_md5,
2104 2101
 		);
2105
-		if ((int) $recur_date)
2102
+		if ((int)$recur_date)
2106 2103
 		{
2107 2104
 			$where['cal_recur_date'] = $recur_date;
2108 2105
 		}
@@ -2113,7 +2110,7 @@  discard block
 block discarded – undo
2113 2110
 
2114 2111
 		if ($status == 'G')		// remove group invitations, as we dont store them in the db
2115 2112
 		{
2116
-			$this->db->delete($this->user_table,$where,__LINE__,__FILE__,'calendar');
2113
+			$this->db->delete($this->user_table, $where, __LINE__, __FILE__, 'calendar');
2117 2114
 			$ret = $this->db->affected_rows();
2118 2115
 		}
2119 2116
 		else
@@ -2121,7 +2118,7 @@  discard block
 block discarded – undo
2121 2118
 			$set = array('cal_status' => $status);
2122 2119
 			if ($user_type == 'e' || $attendee) $set['cal_user_attendee'] = $attendee ? $attendee : $user_id;
2123 2120
 			if (!is_null($role) && $role != 'REQ-PARTICIPANT') $set['cal_role'] = $role;
2124
-			$this->db->insert($this->user_table,$set,$where,__LINE__,__FILE__,'calendar');
2121
+			$this->db->insert($this->user_table, $set, $where, __LINE__, __FILE__, 'calendar');
2125 2122
 			// for new or changed group-invitations, remove previously deleted members, so they show up again
2126 2123
 			if (($ret = $this->db->affected_rows()) && $user_type == 'u' && $user_id < 0)
2127 2124
 			{
@@ -2134,7 +2131,7 @@  discard block
 block discarded – undo
2134 2131
 		// update modified and modifier in main table
2135 2132
 		if ($ret)
2136 2133
 		{
2137
-			$this->updateModified($cal_id, true);	// true = update series master too
2134
+			$this->updateModified($cal_id, true); // true = update series master too
2138 2135
 		}
2139 2136
 		//error_log(__METHOD__."($cal_id,$user_type,$user_id,$status,$recur_date) = $ret");
2140 2137
 		return $ret;
@@ -2149,7 +2146,7 @@  discard block
 block discarded – undo
2149 2146
 	 * @param array $participants uid => status pairs
2150 2147
 	 * @param boolean $exception =null true or false to set recure_exception flag, null leave it unchanged (new are by default no exception)
2151 2148
 	 */
2152
-	function recurrence($cal_id,$start,$end,$participants,$exception=null)
2149
+	function recurrence($cal_id, $start, $end, $participants, $exception = null)
2153 2150
 	{
2154 2151
 		//error_log(__METHOD__."($cal_id, $start, $end, ".array2string($participants).", ".array2string($exception));
2155 2152
 		$update = array('cal_end' => $end);
@@ -2158,7 +2155,7 @@  discard block
 block discarded – undo
2158 2155
 		$this->db->insert($this->dates_table, $update, array(
2159 2156
 			'cal_id' => $cal_id,
2160 2157
 			'cal_start'  => $start,
2161
-		),__LINE__,__FILE__,'calendar');
2158
+		), __LINE__, __FILE__, 'calendar');
2162 2159
 
2163 2160
 		if (!is_array($participants))
2164 2161
 		{
@@ -2166,26 +2163,26 @@  discard block
 block discarded – undo
2166 2163
 		}
2167 2164
 		if ($exception !== true)
2168 2165
 		{
2169
-			foreach($participants as $uid => $status)
2166
+			foreach ($participants as $uid => $status)
2170 2167
 			{
2171
-				if ($status == 'G') continue;	// dont save group-invitations
2168
+				if ($status == 'G') continue; // dont save group-invitations
2172 2169
 
2173 2170
 				$type = '';
2174 2171
 				$id = null;
2175 2172
 				self::split_user($uid, $type, $id, true);
2176 2173
 				$quantity = $role = null;
2177
-				self::split_status($status,$quantity,$role);
2178
-				$this->db->insert($this->user_table,array(
2174
+				self::split_status($status, $quantity, $role);
2175
+				$this->db->insert($this->user_table, array(
2179 2176
 					'cal_status'	=> $status,
2180 2177
 					'cal_quantity'	=> $quantity,
2181 2178
 					'cal_role'		=> $role,
2182 2179
 					'cal_user_attendee' => $type == 'e' ? substr($uid, 1) : null,
2183
-				),array(
2180
+				), array(
2184 2181
 					'cal_id'		 => $cal_id,
2185 2182
 					'cal_recur_date' => $start,
2186 2183
 					'cal_user_type'  => $type,
2187 2184
 					'cal_user_id' 	 => $id,
2188
-				),__LINE__,__FILE__,'calendar');
2185
+				), __LINE__, __FILE__, 'calendar');
2189 2186
 			}
2190 2187
 		}
2191 2188
 	}
@@ -2199,7 +2196,7 @@  discard block
 block discarded – undo
2199 2196
 	function unfinished_recuring($time)
2200 2197
 	{
2201 2198
 		$ids = array();
2202
-		foreach($rs=$this->db->select($this->repeats_table, "$this->repeats_table.cal_id,MAX(cal_start) AS cal_start",
2199
+		foreach ($rs = $this->db->select($this->repeats_table, "$this->repeats_table.cal_id,MAX(cal_start) AS cal_start",
2203 2200
 			'(range_end IS NULL OR range_end > '.(int)$time.')',
2204 2201
 			__LINE__, __FILE__, false, "GROUP BY $this->repeats_table.cal_id,range_end", 'calendar', 0,
2205 2202
 			" JOIN $this->cal_table ON $this->repeats_table.cal_id=$this->cal_table.cal_id".
@@ -2225,9 +2222,9 @@  discard block
 block discarded – undo
2225 2222
 		// update timestamp of series master, updates own timestamp too, which does not hurt ;-)
2226 2223
 		$this->updateModified($cal_id, true);
2227 2224
 
2228
-		foreach($this->all_tables as $table)
2225
+		foreach ($this->all_tables as $table)
2229 2226
 		{
2230
-			$this->db->delete($table,array('cal_id'=>$cal_id),__LINE__,__FILE__,'calendar');
2227
+			$this->db->delete($table, array('cal_id'=>$cal_id), __LINE__, __FILE__, 'calendar');
2231 2228
 		}
2232 2229
 	}
2233 2230
 
@@ -2243,19 +2240,19 @@  discard block
 block discarded – undo
2243 2240
 	function purge($date)
2244 2241
 	{
2245 2242
 		// with new range_end we simple delete all with range_end < $date (range_end NULL is never returned)
2246
-		foreach($this->db->select($this->cal_table, 'cal_id', 'range_end < '.(int)$date, __LINE__, __FILE__, false, '', 'calendar') as $row)
2243
+		foreach ($this->db->select($this->cal_table, 'cal_id', 'range_end < '.(int)$date, __LINE__, __FILE__, false, '', 'calendar') as $row)
2247 2244
 		{
2248 2245
 			//echo __METHOD__." About to delete".$row['cal_id']."\r\n";
2249
-			foreach($this->all_tables as $table)
2246
+			foreach ($this->all_tables as $table)
2250 2247
 			{
2251 2248
 				$this->db->delete($table, array('cal_id'=>$row['cal_id']), __LINE__, __FILE__, 'calendar');
2252 2249
 			}
2253 2250
 			// handle sync
2254
-			$this->db->update('egw_api_content_history',array(
2251
+			$this->db->update('egw_api_content_history', array(
2255 2252
 				'sync_deleted' => time(),
2256
-			),array(
2253
+			), array(
2257 2254
 				'sync_appname' => 'calendar',
2258
-				'sync_contentid' => $row['cal_id'],	// sync_contentid is varchar(60)!
2255
+				'sync_contentid' => $row['cal_id'], // sync_contentid is varchar(60)!
2259 2256
 			), __LINE__, __FILE__);
2260 2257
 			// handle links
2261 2258
 			Link::unlink('', 'calendar', $row['cal_id']);
@@ -2278,23 +2275,23 @@  discard block
 block discarded – undo
2278 2275
 	 * @param boolean $update_cache =null true: re-read given $cal_id, false: delete given $cal_id
2279 2276
 	 * @return array of (cal_id => array of) alarms with alarm-id as key
2280 2277
 	 */
2281
-	function read_alarms($cal_id, $update_cache=null)
2278
+	function read_alarms($cal_id, $update_cache = null)
2282 2279
 	{
2283 2280
 		if (!isset(self::$alarm_cache) && is_array($cal_id))
2284 2281
 		{
2285 2282
 			self::$alarm_cache = array();
2286 2283
 			if (($jobs = $this->async->read('cal:%')))
2287 2284
 			{
2288
-				foreach($jobs as $id => $job)
2285
+				foreach ($jobs as $id => $job)
2289 2286
 				{
2290
-					$alarm         = $job['data'];	// text, enabled
2287
+					$alarm         = $job['data']; // text, enabled
2291 2288
 					$alarm['id']   = $id;
2292 2289
 					$alarm['time'] = $job['next'];
2293 2290
 
2294 2291
 					self::$alarm_cache[$alarm['cal_id']][$id] = $alarm;
2295 2292
 				}
2296 2293
 			}
2297
-			unset($update_cache);	// just done
2294
+			unset($update_cache); // just done
2298 2295
 		}
2299 2296
 		$alarms = array();
2300 2297
 
@@ -2302,13 +2299,13 @@  discard block
 block discarded – undo
2302 2299
 		{
2303 2300
 			if (isset($update_cache))
2304 2301
 			{
2305
-				foreach((array)$cal_id as $id)
2302
+				foreach ((array)$cal_id as $id)
2306 2303
 				{
2307 2304
 					if ($update_cache === false)
2308 2305
 					{
2309 2306
 						unset(self::$alarm_cache[$cal_id]);
2310 2307
 					}
2311
-					elseif($update_cache === true)
2308
+					elseif ($update_cache === true)
2312 2309
 					{
2313 2310
 						self::$alarm_cache[$cal_id] = $this->read_alarms_nocache($cal_id);
2314 2311
 					}
@@ -2320,7 +2317,7 @@  discard block
 block discarded – undo
2320 2317
 			}
2321 2318
 			else
2322 2319
 			{
2323
-				foreach($cal_id as $id)
2320
+				foreach ($cal_id as $id)
2324 2321
 				{
2325 2322
 					$alarms[$id] = (array)self::$alarm_cache[$id];
2326 2323
 				}
@@ -2335,9 +2332,9 @@  discard block
 block discarded – undo
2335 2332
 	{
2336 2333
 		if (($jobs = $this->async->read('cal:'.(int)$cal_id.':%')))
2337 2334
 		{
2338
-			foreach($jobs as $id => $job)
2335
+			foreach ($jobs as $id => $job)
2339 2336
 			{
2340
-				$alarm         = $job['data'];	// text, enabled
2337
+				$alarm         = $job['data']; // text, enabled
2341 2338
 				$alarm['id']   = $id;
2342 2339
 				$alarm['time'] = $job['next'];
2343 2340
 
@@ -2360,8 +2357,8 @@  discard block
 block discarded – undo
2360 2357
 		{
2361 2358
 			return False;
2362 2359
 		}
2363
-		list($alarm_id,$job) = each($jobs);
2364
-		$alarm         = $job['data'];	// text, enabled
2360
+		list($alarm_id, $job) = each($jobs);
2361
+		$alarm         = $job['data']; // text, enabled
2365 2362
 		$alarm['id']   = $alarm_id;
2366 2363
 		$alarm['time'] = $job['next'];
2367 2364
 
@@ -2377,12 +2374,12 @@  discard block
 block discarded – undo
2377 2374
 	 * @param boolean $update_modified =true call update modified, default true
2378 2375
 	 * @return string id of the alarm
2379 2376
 	 */
2380
-	function save_alarm($cal_id, $alarm, $update_modified=true)
2377
+	function save_alarm($cal_id, $alarm, $update_modified = true)
2381 2378
 	{
2382 2379
 		//error_log(__METHOD__."($cal_id, ".array2string($alarm).', '.array2string($update_modified).') '.function_backtrace());
2383 2380
 		if (!($id = $alarm['id']))
2384 2381
 		{
2385
-			$alarms = $this->read_alarms($cal_id);	// find a free alarm#
2382
+			$alarms = $this->read_alarms($cal_id); // find a free alarm#
2386 2383
 			$n = count($alarms);
2387 2384
 			do
2388 2385
 			{
@@ -2395,12 +2392,12 @@  discard block
 block discarded – undo
2395 2392
 		{
2396 2393
 			$this->async->cancel_timer($id);
2397 2394
 		}
2398
-		$alarm['cal_id'] = $cal_id;		// we need the back-reference
2395
+		$alarm['cal_id'] = $cal_id; // we need the back-reference
2399 2396
 		// add an alarm uid, if none is given
2400 2397
 		if (empty($alarm['uid']) && class_exists('Horde_Support_Uuid')) $alarm['uid'] = (string)new Horde_Support_Uuid;
2401 2398
 		//error_log(__METHOD__.__LINE__.' Save Alarm for CalID:'.$cal_id.'->'.array2string($alarm).'-->'.$id.'#'.function_backtrace());
2402 2399
 		// allways store job with the alarm owner as job-owner to get eg. the correct from address
2403
-		if (!$this->async->set_timer($alarm['time'],$id,'calendar.calendar_boupdate.send_alarm',$alarm,$alarm['owner']))
2400
+		if (!$this->async->set_timer($alarm['time'], $id, 'calendar.calendar_boupdate.send_alarm', $alarm, $alarm['owner']))
2404 2401
 		{
2405 2402
 			return False;
2406 2403
 		}
@@ -2427,7 +2424,7 @@  discard block
 block discarded – undo
2427 2424
 		//error_log(__METHOD__."($cal_id) ".function_backtrace());
2428 2425
 		if (($alarms = $this->read_alarms($cal_id)))
2429 2426
 		{
2430
-			foreach(array_keys($alarms) as $id)
2427
+			foreach (array_keys($alarms) as $id)
2431 2428
 			{
2432 2429
 				$this->async->cancel_timer($id);
2433 2430
 			}
@@ -2447,7 +2444,7 @@  discard block
 block discarded – undo
2447 2444
 	{
2448 2445
 		//error_log(__METHOD__."('$id') ".function_backtrace());
2449 2446
 		// update the modification information of the related event
2450
-		list(,$cal_id) = explode(':',$id);
2447
+		list(,$cal_id) = explode(':', $id);
2451 2448
 		if ($cal_id)
2452 2449
 		{
2453 2450
 			$this->updateModified($cal_id, true);
@@ -2466,7 +2463,7 @@  discard block
 block discarded – undo
2466 2463
 	 * @param array|int $old_user integer old user or array with keys 'account_id' and 'new_owner' as the deleteaccount hook uses it
2467 2464
 	 * @param int $new_user =null
2468 2465
 	 */
2469
-	function deleteaccount($old_user, $new_user=null)
2466
+	function deleteaccount($old_user, $new_user = null)
2470 2467
 	{
2471 2468
 		if (is_array($old_user))
2472 2469
 		{
@@ -2477,52 +2474,52 @@  discard block
 block discarded – undo
2477 2474
 		{
2478 2475
 			$user_type = '';
2479 2476
 			$user_id = null;
2480
-			self::split_user($old_user,$user_type,$user_id);
2477
+			self::split_user($old_user, $user_type, $user_id);
2481 2478
 
2482 2479
 			if ($user_type == 'u')	// only accounts can be owners of events
2483 2480
 			{
2484
-				foreach($this->db->select($this->cal_table,'cal_id',array('cal_owner' => $old_user),__LINE__,__FILE__,false,'','calendar') as $row)
2481
+				foreach ($this->db->select($this->cal_table, 'cal_id', array('cal_owner' => $old_user), __LINE__, __FILE__, false, '', 'calendar') as $row)
2485 2482
 				{
2486 2483
 					$this->delete($row['cal_id']);
2487 2484
 				}
2488 2485
 			}
2489
-			$this->db->delete($this->user_table,array(
2486
+			$this->db->delete($this->user_table, array(
2490 2487
 				'cal_user_type' => $user_type,
2491 2488
 				'cal_user_id'   => $user_id,
2492
-			),__LINE__,__FILE__,'calendar');
2489
+			), __LINE__, __FILE__, 'calendar');
2493 2490
 
2494 2491
 			// delete calendar entries without participants (can happen if the deleted user is the only participants, but not the owner)
2495
-			foreach($this->db->select($this->cal_table,"DISTINCT $this->cal_table.cal_id",'cal_user_id IS NULL',__LINE__,__FILE__,
2496
-				False,'','calendar',0,"LEFT JOIN $this->user_table ON $this->cal_table.cal_id=$this->user_table.cal_id") as $row)
2492
+			foreach ($this->db->select($this->cal_table, "DISTINCT $this->cal_table.cal_id", 'cal_user_id IS NULL', __LINE__, __FILE__,
2493
+				False, '', 'calendar', 0, "LEFT JOIN $this->user_table ON $this->cal_table.cal_id=$this->user_table.cal_id") as $row)
2497 2494
 			{
2498 2495
 				$this->delete($row['cal_id']);
2499 2496
 			}
2500 2497
 		}
2501 2498
 		else
2502 2499
 		{
2503
-			$this->db->update($this->cal_table,array('cal_owner' => $new_user),array('cal_owner' => $old_user),__LINE__,__FILE__,'calendar');
2500
+			$this->db->update($this->cal_table, array('cal_owner' => $new_user), array('cal_owner' => $old_user), __LINE__, __FILE__, 'calendar');
2504 2501
 			// delete participation of old user, if new user is already a participant
2505 2502
 			$ids = array();
2506
-			foreach($this->db->select($this->user_table,'cal_id',array(		// MySQL does NOT allow to run this as delete!
2503
+			foreach ($this->db->select($this->user_table, 'cal_id', array(		// MySQL does NOT allow to run this as delete!
2507 2504
 				'cal_user_type' => 'u',
2508 2505
 				'cal_user_id' => $old_user,
2509 2506
 				"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')",
2510
-			),__LINE__,__FILE__,false,'','calendar') as $row)
2507
+			), __LINE__, __FILE__, false, '', 'calendar') as $row)
2511 2508
 			{
2512 2509
 				$ids[] = $row['cal_id'];
2513 2510
 			}
2514
-			if ($ids) $this->db->delete($this->user_table,array(
2511
+			if ($ids) $this->db->delete($this->user_table, array(
2515 2512
 				'cal_user_type' => 'u',
2516 2513
 				'cal_user_id' => $old_user,
2517 2514
 				'cal_id' => $ids,
2518
-			),__LINE__,__FILE__,'calendar');
2515
+			), __LINE__, __FILE__, 'calendar');
2519 2516
 			// now change participant in the rest to contain new user instead of old user
2520
-			$this->db->update($this->user_table,array(
2517
+			$this->db->update($this->user_table, array(
2521 2518
 				'cal_user_id' => $new_user,
2522
-			),array(
2519
+			), array(
2523 2520
 				'cal_user_type' => 'u',
2524 2521
 				'cal_user_id' => $old_user,
2525
-			),__LINE__,__FILE__,'calendar');
2522
+			), __LINE__, __FILE__, 'calendar');
2526 2523
 		}
2527 2524
 	}
2528 2525
 
@@ -2536,18 +2533,18 @@  discard block
 block discarded – undo
2536 2533
 	 *
2537 2534
 	 * @return array recur_date => status pairs (index 0 => main status)
2538 2535
 	 */
2539
-	function get_recurrences($cal_id, $uid=null, $start=0, $end=0)
2536
+	function get_recurrences($cal_id, $uid = null, $start = 0, $end = 0)
2540 2537
 	{
2541 2538
 		$participant_status = array();
2542 2539
 		$where = array('cal_id' => $cal_id);
2543
-		if ($start != 0 && $end == 0) $where[] = '(cal_recur_date = 0 OR cal_recur_date >= ' . (int)$start . ')';
2544
-		if ($start == 0 && $end != 0) $where[] = '(cal_recur_date = 0 OR cal_recur_date <= ' . (int)$end . ')';
2540
+		if ($start != 0 && $end == 0) $where[] = '(cal_recur_date = 0 OR cal_recur_date >= '.(int)$start.')';
2541
+		if ($start == 0 && $end != 0) $where[] = '(cal_recur_date = 0 OR cal_recur_date <= '.(int)$end.')';
2545 2542
 		if ($start != 0 && $end != 0)
2546 2543
 		{
2547
-			$where[] = '(cal_recur_date = 0 OR (cal_recur_date >= ' . (int)$start .
2548
-						' AND cal_recur_date <= ' . (int)$end . '))';
2544
+			$where[] = '(cal_recur_date = 0 OR (cal_recur_date >= '.(int)$start.
2545
+						' AND cal_recur_date <= '.(int)$end.'))';
2549 2546
 		}
2550
-		foreach($this->db->select($this->user_table,'DISTINCT cal_recur_date',$where,__LINE__,__FILE__,false,'','calendar') as $row)
2547
+		foreach ($this->db->select($this->user_table, 'DISTINCT cal_recur_date', $where, __LINE__, __FILE__, false, '', 'calendar') as $row)
2551 2548
 		{
2552 2549
 			// inititalize the array
2553 2550
 			$participant_status[$row['cal_recur_date']] = null;
@@ -2561,17 +2558,17 @@  discard block
 block discarded – undo
2561 2558
 			'cal_user_type'	=> $user_type ? $user_type : 'u',
2562 2559
 			'cal_user_id'   => $user_id,
2563 2560
 		);
2564
-		if ($start != 0 && $end == 0) $where2[] = '(cal_recur_date = 0 OR cal_recur_date >= ' . (int)$start . ')';
2565
-		if ($start == 0 && $end != 0) $where2[] = '(cal_recur_date = 0 OR cal_recur_date <= ' . (int)$end . ')';
2561
+		if ($start != 0 && $end == 0) $where2[] = '(cal_recur_date = 0 OR cal_recur_date >= '.(int)$start.')';
2562
+		if ($start == 0 && $end != 0) $where2[] = '(cal_recur_date = 0 OR cal_recur_date <= '.(int)$end.')';
2566 2563
 		if ($start != 0 && $end != 0)
2567 2564
 		{
2568
-			$where2[] = '(cal_recur_date = 0 OR (cal_recur_date >= ' . (int)$start .
2569
-						' AND cal_recur_date <= ' . (int)$end . '))';
2565
+			$where2[] = '(cal_recur_date = 0 OR (cal_recur_date >= '.(int)$start.
2566
+						' AND cal_recur_date <= '.(int)$end.'))';
2570 2567
 		}
2571
-		foreach ($this->db->select($this->user_table,'cal_recur_date,cal_status,cal_quantity,cal_role',$where2,
2572
-				__LINE__,__FILE__,false,'','calendar') as $row)
2568
+		foreach ($this->db->select($this->user_table, 'cal_recur_date,cal_status,cal_quantity,cal_role', $where2,
2569
+				__LINE__, __FILE__, false, '', 'calendar') as $row)
2573 2570
 		{
2574
-			$status = self::combine_status($row['cal_status'],$row['cal_quantity'],$row['cal_role']);
2571
+			$status = self::combine_status($row['cal_status'], $row['cal_quantity'], $row['cal_role']);
2575 2572
 			$participant_status[$row['cal_recur_date']] = $status;
2576 2573
 		}
2577 2574
 		return $participant_status;
@@ -2620,8 +2617,8 @@  discard block
 block discarded – undo
2620 2617
 			'cal_uid'		=> $uid,
2621 2618
 		);
2622 2619
 		$related = array();
2623
-		foreach ($this->db->select($this->cal_table,'cal_id,cal_reference',$where,
2624
-				__LINE__,__FILE__,false,'','calendar') as $row)
2620
+		foreach ($this->db->select($this->cal_table, 'cal_id,cal_reference', $where,
2621
+				__LINE__, __FILE__, false, '', 'calendar') as $row)
2625 2622
 		{
2626 2623
 			if ($row['cal_reference'] != 0)
2627 2624
 			{
@@ -2650,10 +2647,10 @@  discard block
 block discarded – undo
2650 2647
 	 *
2651 2648
 	 * @return array		Array of exception days (false for non-recurring events).
2652 2649
 	 */
2653
-	function get_recurrence_exceptions($event, $tz_id=null, $start=0, $end=0, $filter='all')
2650
+	function get_recurrence_exceptions($event, $tz_id = null, $start = 0, $end = 0, $filter = 'all')
2654 2651
 	{
2655 2652
 		if (!is_array($event)) return false;
2656
-		$cal_id = (int) $event['id'];
2653
+		$cal_id = (int)$event['id'];
2657 2654
 		//error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2658 2655
 		//		"($cal_id, $tz_id, $filter): " . $event['tzid']);
2659 2656
 		if (!$cal_id || $event['recur_type'] == MCAL_RECUR_NONE) return false;
@@ -2677,27 +2674,27 @@  discard block
 block discarded – undo
2677 2674
 		while ($egw_rrule->valid())
2678 2675
 		{
2679 2676
 			while ($egw_rrule->exceptions &&
2680
-				in_array($egw_rrule->current->format('Ymd'),$egw_rrule->exceptions))
2677
+				in_array($egw_rrule->current->format('Ymd'), $egw_rrule->exceptions))
2681 2678
 			{
2682
-				if (in_array($filter, array('map','tz_map','rrule','tz_rrule')))
2679
+				if (in_array($filter, array('map', 'tz_map', 'rrule', 'tz_rrule')))
2683 2680
 				{
2684 2681
 					 // real exception
2685
-					$locts = (int)Api\DateTime::to($egw_rrule->current(),'server');
2682
+					$locts = (int)Api\DateTime::to($egw_rrule->current(), 'server');
2686 2683
 					if ($expand_all)
2687 2684
 					{
2688
-						$remts = (int)Api\DateTime::to($remote_rrule->current(),'server');
2685
+						$remts = (int)Api\DateTime::to($remote_rrule->current(), 'server');
2689 2686
 						if ($remote)
2690 2687
 						{
2691
-							$days[$locts]= $remts;
2688
+							$days[$locts] = $remts;
2692 2689
 						}
2693 2690
 						else
2694 2691
 						{
2695
-							$days[$remts]= $locts;
2692
+							$days[$remts] = $locts;
2696 2693
 						}
2697 2694
 					}
2698 2695
 					else
2699 2696
 					{
2700
-						$days[$locts]= $locts;
2697
+						$days[$locts] = $locts;
2701 2698
 					}
2702 2699
 				}
2703 2700
 				if ($expand_all)
@@ -2708,14 +2705,14 @@  discard block
 block discarded – undo
2708 2705
 				if (!$egw_rrule->valid()) return $days;
2709 2706
 			}
2710 2707
 			$day = $egw_rrule->current();
2711
-			$locts = (int)Api\DateTime::to($day,'server');
2708
+			$locts = (int)Api\DateTime::to($day, 'server');
2712 2709
 			$tz_exception = ($filter == 'tz_rrule');
2713 2710
 			//error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2714 2711
 			//	'()[EVENT Server]: ' . $day->format('Ymd\THis') . " ($locts)");
2715 2712
 			if ($expand_all)
2716 2713
 			{
2717 2714
 				$remote_day = $remote_rrule->current();
2718
-				$remts = (int)Api\DateTime::to($remote_day,'server');
2715
+				$remts = (int)Api\DateTime::to($remote_day, 'server');
2719 2716
 			//	error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2720 2717
 			//	'()[EVENT Device]: ' . $remote_day->format('Ymd\THis') . " ($remts)");
2721 2718
 			}
@@ -2734,11 +2731,11 @@  discard block
 block discarded – undo
2734 2731
 						//	'() tz exception: ' . $day->format('Ymd\THis'));
2735 2732
 						if ($remote)
2736 2733
 						{
2737
-							$days[$locts]= $remts;
2734
+							$days[$locts] = $remts;
2738 2735
 						}
2739 2736
 						else
2740 2737
 						{
2741
-							$days[$remts]= $locts;
2738
+							$days[$remts] = $locts;
2742 2739
 						}
2743 2740
 					}
2744 2741
 				}
@@ -2760,18 +2757,18 @@  discard block
 block discarded – undo
2760 2757
 							{
2761 2758
 								if ($remote)
2762 2759
 								{
2763
-									$days[$locts]= $remts;
2760
+									$days[$locts] = $remts;
2764 2761
 								}
2765 2762
 								else
2766 2763
 								{
2767
-									$days[$remts]= $locts;
2764
+									$days[$remts] = $locts;
2768 2765
 								}
2769 2766
 							}
2770 2767
 						}
2771 2768
 					}
2772 2769
 					elseif ($filter != 'map')
2773 2770
 					{
2774
-						$days[$locts]= $locts;
2771
+						$days[$locts] = $locts;
2775 2772
 					}
2776 2773
 				}
2777 2774
 				elseif (($filter == 'map' || filter == 'tz_map') &&
@@ -2781,11 +2778,11 @@  discard block
 block discarded – undo
2781 2778
 					if ($expand_all)
2782 2779
 					{
2783 2780
 
2784
-						$days[$remts]= $locts;
2781
+						$days[$remts] = $locts;
2785 2782
 					}
2786 2783
 					else
2787 2784
 					{
2788
-						$days[$locts]= $locts;
2785
+						$days[$locts] = $locts;
2789 2786
 					}
2790 2787
 				}
2791 2788
 			}
@@ -2809,9 +2806,9 @@  discard block
 block discarded – undo
2809 2806
 	 */
2810 2807
 	function status_pseudo_exception($cal_id, $recur_date, $filter)
2811 2808
 	{
2812
-		static $recurrence_zero=null;
2813
-		static $cached_id=null;
2814
-		static $user=null;
2809
+		static $recurrence_zero = null;
2810
+		static $cached_id = null;
2811
+		static $user = null;
2815 2812
 
2816 2813
 		if (!isset($cached_id) || $cached_id != $cal_id)
2817 2814
 		{
@@ -2822,8 +2819,8 @@  discard block
 block discarded – undo
2822 2819
 				'cal_id' => $cal_id,
2823 2820
 				'cal_recur_date' => 0,
2824 2821
 			);
2825
-			foreach ($this->db->select($this->user_table,'cal_user_type,cal_user_id,cal_user_attendee,cal_status',$where,
2826
-				__LINE__,__FILE__,false,'','calendar') as $row)
2822
+			foreach ($this->db->select($this->user_table, 'cal_user_type,cal_user_id,cal_user_attendee,cal_status', $where,
2823
+				__LINE__, __FILE__, false, '', 'calendar') as $row)
2827 2824
 			{
2828 2825
 				switch ($row['cal_user_type'])
2829 2826
 				{
@@ -2846,8 +2843,8 @@  discard block
 block discarded – undo
2846 2843
 			'cal_id' => $cal_id,
2847 2844
 			'cal_recur_date' => $recur_date,
2848 2845
 		);
2849
-		foreach ($this->db->select($this->user_table,'cal_user_type,cal_user_id,cal_user_attendee,cal_status',$where,
2850
-			__LINE__,__FILE__,false,'','calendar') as $row)
2846
+		foreach ($this->db->select($this->user_table, 'cal_user_type,cal_user_id,cal_user_attendee,cal_status', $where,
2847
+			__LINE__, __FILE__, false, '', 'calendar') as $row)
2851 2848
 		{
2852 2849
 			switch ($row['cal_user_type'])
2853 2850
 			{
@@ -2944,14 +2941,14 @@  discard block
 block discarded – undo
2944 2941
 			}
2945 2942
 			$timezone = self::$tz_cache[$event['tzid']];
2946 2943
 		}
2947
-		$start_time = new Api\DateTime($event['start'],Api\DateTime::$server_timezone);
2944
+		$start_time = new Api\DateTime($event['start'], Api\DateTime::$server_timezone);
2948 2945
 		$start_time->setTimezone($timezone);
2949
-		$end_time = new Api\DateTime($event['end'],Api\DateTime::$server_timezone);
2946
+		$end_time = new Api\DateTime($event['end'], Api\DateTime::$server_timezone);
2950 2947
 		$end_time->setTimezone($timezone);
2951 2948
 		//error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2952 2949
 		//	'(): ' . $start . '-' . $end);
2953
-		$start = Api\DateTime::to($start_time,'array');
2954
-		$end = Api\DateTime::to($end_time,'array');
2950
+		$start = Api\DateTime::to($start_time, 'array');
2951
+		$end = Api\DateTime::to($end_time, 'array');
2955 2952
 
2956 2953
 
2957 2954
 		return !$start['hour'] && !$start['minute'] && $end['hour'] == 23 && $end['minute'] == 59;
@@ -2965,7 +2962,7 @@  discard block
 block discarded – undo
2965 2962
 	 *
2966 2963
 	 * @return DateTime
2967 2964
 	 */
2968
-	function &startOfDay(Api\DateTime $time, $tz_id=null)
2965
+	function &startOfDay(Api\DateTime $time, $tz_id = null)
2969 2966
 	{
2970 2967
 		if (empty($tz_id))
2971 2968
 		{
@@ -2990,14 +2987,14 @@  discard block
 block discarded – undo
2990 2987
 	 * @param int $time =null new timestamp, default current (server-)time
2991 2988
 	 * @param int $modifier =null uid of the modifier, default current user
2992 2989
 	 */
2993
-	function updateModified($id, $update_master=false, $time=null, $modifier=null)
2990
+	function updateModified($id, $update_master = false, $time = null, $modifier = null)
2994 2991
 	{
2995 2992
 		if (is_null($time) || !$time) $time = time();
2996 2993
 		if (is_null($modifier)) $modifier = $GLOBALS['egw_info']['user']['account_id'];
2997 2994
 
2998 2995
 		$this->db->update($this->cal_table,
2999 2996
 			array('cal_modified' => $time, 'cal_modifier' => $modifier),
3000
-			array('cal_id' => $id), __LINE__,__FILE__, 'calendar');
2997
+			array('cal_id' => $id), __LINE__, __FILE__, 'calendar');
3001 2998
 
3002 2999
 		// if event is an exception: update modified of master, to force etag, ctag and sync-token change
3003 3000
 		if ($update_master)
Please login to merge, or discard this patch.