Completed
Pull Request — master (#43)
by Marcel
27:43
created
calendar/inc/class.calendar_boupdate.inc.php 2 patches
Spacing   +310 added lines, -312 removed lines patch added patch discarded remove patch
@@ -16,15 +16,15 @@  discard block
 block discarded – undo
16 16
 use EGroupware\Api\Acl;
17 17
 
18 18
 // types of messsages send by calendar_boupdate::send_update
19
-define('MSG_DELETED',0);
20
-define('MSG_MODIFIED',1);
21
-define('MSG_ADDED',2);
22
-define('MSG_REJECTED',3);
23
-define('MSG_TENTATIVE',4);
24
-define('MSG_ACCEPTED',5);
25
-define('MSG_ALARM',6);
26
-define('MSG_DISINVITE',7);
27
-define('MSG_DELEGATED',8);
19
+define('MSG_DELETED', 0);
20
+define('MSG_MODIFIED', 1);
21
+define('MSG_ADDED', 2);
22
+define('MSG_REJECTED', 3);
23
+define('MSG_TENTATIVE', 4);
24
+define('MSG_ACCEPTED', 5);
25
+define('MSG_ALARM', 6);
26
+define('MSG_DISINVITE', 7);
27
+define('MSG_DELEGATED', 8);
28 28
 
29 29
 /**
30 30
  * Class to access AND manipulate all calendar data (business object)
@@ -91,13 +91,13 @@  discard block
 block discarded – undo
91 91
 	 */
92 92
 	function __construct()
93 93
 	{
94
-		if ($this->debug > 0) $this->debug_message('calendar_boupdate::__construct() started',True);
94
+		if ($this->debug > 0) $this->debug_message('calendar_boupdate::__construct() started', True);
95 95
 
96
-		parent::__construct();	// calling the parent constructor
96
+		parent::__construct(); // calling the parent constructor
97 97
 		
98 98
 		$this->resources_so = new resources_so();
99 99
 
100
-		if ($this->debug > 0) $this->debug_message('calendar_boupdate::__construct() finished',True);
100
+		if ($this->debug > 0) $this->debug_message('calendar_boupdate::__construct() finished', True);
101 101
 	}
102 102
 
103 103
 	/**
@@ -124,16 +124,16 @@  discard block
 block discarded – undo
124 124
 	 * +      + +  C   +	which is clearly wrong for everything with a maximum quantity > 1
125 125
 	 * ++++++++ ++++++++
126 126
 	 */
127
-	function update(&$event,$ignore_conflicts=false,$touch_modified=true,$ignore_acl=false,$updateTS=true,&$messages=null, $skip_notification=false)
127
+	function update(&$event, $ignore_conflicts = false, $touch_modified = true, $ignore_acl = false, $updateTS = true, &$messages = null, $skip_notification = false)
128 128
 	{
129
-		unset($updateTS);	// ignored, as updating timestamps is required for sync!
129
+		unset($updateTS); // ignored, as updating timestamps is required for sync!
130 130
 		//error_log(__METHOD__."(".array2string($event).",$ignore_conflicts,$touch_modified,$ignore_acl)");
131 131
 		if (!is_array($messages)) $messages = $messages ? (array)$messages : array();
132 132
 
133 133
 		if ($this->debug > 1 || $this->debug == 'update')
134 134
 		{
135 135
 			$this->debug_message('calendar_boupdate::update(%1,ignore_conflict=%2,touch_modified=%3,ignore_acl=%4)',
136
-				false,$event,$ignore_conflicts,$touch_modified,$ignore_acl);
136
+				false, $event, $ignore_conflicts, $touch_modified, $ignore_acl);
137 137
 		}
138 138
 		// check some minimum requirements:
139 139
 		// - new events need start, end and title
@@ -161,11 +161,11 @@  discard block
 block discarded – undo
161 161
 		}
162 162
 
163 163
 		// check if user has the permission to update / create the event
164
-		if (!$ignore_acl && (!$new_event && !$this->check_perms(Acl::EDIT,$event['id']) ||
165
-			$new_event && !$this->check_perms(Acl::EDIT,0,$event['owner'])) &&
166
-			!$this->check_perms(Acl::ADD,0,$event['owner']))
164
+		if (!$ignore_acl && (!$new_event && !$this->check_perms(Acl::EDIT, $event['id']) ||
165
+			$new_event && !$this->check_perms(Acl::EDIT, 0, $event['owner'])) &&
166
+			!$this->check_perms(Acl::ADD, 0, $event['owner']))
167 167
 		{
168
-			$messages[] = lang('Access to calendar of %1 denied!',Api\Accounts::username($event['owner']));
168
+			$messages[] = lang('Access to calendar of %1 denied!', Api\Accounts::username($event['owner']));
169 169
 			return false;
170 170
 		}
171 171
 		if ($new_event)
@@ -174,24 +174,24 @@  discard block
 block discarded – undo
174 174
 		}
175 175
 		else
176 176
 		{
177
-			$old_event = $this->read((int)$event['id'],null,$ignore_acl);
177
+			$old_event = $this->read((int)$event['id'], null, $ignore_acl);
178 178
 		}
179 179
 
180 180
 		// do we need to check, if user is allowed to invite the invited participants
181
-		if ($this->require_acl_invite && ($removed = $this->remove_no_acl_invite($event,$old_event)))
181
+		if ($this->require_acl_invite && ($removed = $this->remove_no_acl_invite($event, $old_event)))
182 182
 		{
183 183
 			// report removed participants back to user
184
-			foreach($removed as $key => $account_id)
184
+			foreach ($removed as $key => $account_id)
185 185
 			{
186 186
 				$removed[$key] = $this->participant_name($account_id);
187 187
 			}
188
-			$messages[] = lang('%1 participants removed because of missing invite grants',count($removed)).
189
-				': '.implode(', ',$removed);
188
+			$messages[] = lang('%1 participants removed because of missing invite grants', count($removed)).
189
+				': '.implode(', ', $removed);
190 190
 		}
191 191
 		// check category based ACL
192 192
 		if ($event['category'])
193 193
 		{
194
-			if (!is_array($event['category'])) $event['category'] = explode(',',$event['category']);
194
+			if (!is_array($event['category'])) $event['category'] = explode(',', $event['category']);
195 195
 			if (!$old_event || !isset($old_event['category']))
196 196
 			{
197 197
 				$old_event['category'] = array();
@@ -200,38 +200,38 @@  discard block
 block discarded – undo
200 200
 			{
201 201
 				$old_event['category'] = explode(',', $old_event['category']);
202 202
 			}
203
-			foreach($event['category'] as $key => $cat_id)
203
+			foreach ($event['category'] as $key => $cat_id)
204 204
 			{
205 205
 				// check if user is allowed to update event categories
206
-				if ((!$old_event || !in_array($cat_id,$old_event['category'])) &&
207
-					self::has_cat_right(self::CAT_ACL_ADD,$cat_id,$this->user) === false)
206
+				if ((!$old_event || !in_array($cat_id, $old_event['category'])) &&
207
+					self::has_cat_right(self::CAT_ACL_ADD, $cat_id, $this->user) === false)
208 208
 				{
209 209
 					unset($event['category'][$key]);
210 210
 					// report removed category to user
211 211
 					$removed_cats[$cat_id] = $this->categories->id2name($cat_id);
212
-					continue;	// no further check, as cat was removed
212
+					continue; // no further check, as cat was removed
213 213
 				}
214 214
 				// for new or moved events check status of participants, if no category status right --> set all status to 'U' = unknown
215 215
 				if (!$status_reset_to_unknown &&
216
-					self::has_cat_right(self::CAT_ACL_STATUS,$cat_id,$this->user) === false &&
216
+					self::has_cat_right(self::CAT_ACL_STATUS, $cat_id, $this->user) === false &&
217 217
 					(!$old_event || $old_event['start'] != $event['start'] || $old_event['end'] != $event['end']))
218 218
 				{
219
-					foreach((array)$event['participants'] as $uid => $status)
219
+					foreach ((array)$event['participants'] as $uid => $status)
220 220
 					{
221 221
 						$q = $r = null;
222
-						calendar_so::split_status($status,$q,$r);
222
+						calendar_so::split_status($status, $q, $r);
223 223
 						if ($status != 'U')
224 224
 						{
225
-							$event['participants'][$uid] = calendar_so::combine_status('U',$q,$r);
225
+							$event['participants'][$uid] = calendar_so::combine_status('U', $q, $r);
226 226
 							// todo: report reset status to user
227 227
 						}
228 228
 					}
229
-					$status_reset_to_unknown = true;	// once is enough
229
+					$status_reset_to_unknown = true; // once is enough
230 230
 				}
231 231
 			}
232 232
 			if ($removed_cats)
233 233
 			{
234
-				$messages[] = lang('Category %1 removed because of missing rights',implode(', ',$removed_cats));
234
+				$messages[] = lang('Category %1 removed because of missing rights', implode(', ', $removed_cats));
235 235
 			}
236 236
 			if ($status_reset_to_unknown)
237 237
 			{
@@ -267,30 +267,30 @@  discard block
 block discarded – undo
267 267
 		$event = $this->read($cal_id, null, $ignore_acl, 'ts', $new_event && !$event['public'] ? $this->user : null);
268 268
 		//error_log("new $cal_id=". array2string($event));
269 269
 
270
-		if($old_event['deleted'] && $event['deleted'] == null)
270
+		if ($old_event['deleted'] && $event['deleted'] == null)
271 271
 		{
272 272
 			// Restored, bring back links
273 273
 			Link::restore('calendar', $cal_id);
274 274
 		}
275 275
 		if ($this->log_file)
276 276
 		{
277
-			$this->log2file($event2save,$event,$old_event);
277
+			$this->log2file($event2save, $event, $old_event);
278 278
 		}
279 279
 		// send notifications
280
-		if(!$skip_notification)
280
+		if (!$skip_notification)
281 281
 		{
282 282
 			if ($new_event)
283 283
 			{
284
-				$this->send_update(MSG_ADDED,$event['participants'],'',$event);
284
+				$this->send_update(MSG_ADDED, $event['participants'], '', $event);
285 285
 			}
286 286
 			else // update existing event
287 287
 			{
288
-				$this->check4update($event,$old_event);
288
+				$this->check4update($event, $old_event);
289 289
 			}
290 290
 		}
291 291
 
292 292
 		// notify the link-class about the update, as other apps may be subscribt to it
293
-		Link::notify_update('calendar',$cal_id,$event);
293
+		Link::notify_update('calendar', $cal_id, $event);
294 294
 
295 295
 		return $cal_id;
296 296
 	}
@@ -308,27 +308,27 @@  discard block
 block discarded – undo
308 308
 	 * @param Api\DateTime& $checked_excluding =null time until which (excluding) recurrences have been checked
309 309
 	 * @return array or events
310 310
 	 */
311
-	function conflicts(array $event, &$checked_excluding=null)
311
+	function conflicts(array $event, &$checked_excluding = null)
312 312
 	{
313 313
 		$types_with_quantity = array();
314
-		foreach($this->resources as $type => $data)
314
+		foreach ($this->resources as $type => $data)
315 315
 		{
316 316
 			if ($data['max_quantity']) $types_with_quantity[] = $type;
317 317
 		}
318 318
 		// get all NOT rejected participants and evtl. their quantity
319 319
 		$quantity = $users = array();
320
-		foreach($event['participants'] as $uid => $status)
320
+		foreach ($event['participants'] as $uid => $status)
321 321
 		{
322 322
 			$q = $role = null;
323 323
 			calendar_so::split_status($status, $q, $role);
324
-			if ($status == 'R' || $role == 'NON-PARTICIPANT') continue;	// ignore rejected or non-participants
324
+			if ($status == 'R' || $role == 'NON-PARTICIPANT') continue; // ignore rejected or non-participants
325 325
 
326 326
 			if ($uid < 0)	// group, check it's members too
327 327
 			{
328
-				$users = array_unique(array_merge($users, (array)$GLOBALS['egw']->accounts->members($uid,true)));
328
+				$users = array_unique(array_merge($users, (array)$GLOBALS['egw']->accounts->members($uid, true)));
329 329
 			}
330 330
 			$users[] = $uid;
331
-			if (in_array($uid[0],$types_with_quantity))
331
+			if (in_array($uid[0], $types_with_quantity))
332 332
 			{
333 333
 				$quantity[$uid] = $q;
334 334
 			}
@@ -351,58 +351,58 @@  discard block
 block discarded – undo
351 351
 		}
352 352
 		$checked = 0;
353 353
 		$start = microtime(true);
354
-		$duration = $event['end']-$event['start'];
355
-		foreach($recurences as $date)
354
+		$duration = $event['end'] - $event['start'];
355
+		foreach ($recurences as $date)
356 356
 		{
357 357
 			$startts = $date->format('ts');
358 358
 
359 359
 			// skip past events or recurrences
360
-			if ($startts+$duration < $this->now_su) continue;
360
+			if ($startts + $duration < $this->now_su) continue;
361 361
 
362 362
 			// abort check if configured limits are exceeded
363 363
 			if ($event['recur_type'] &&
364 364
 				(++$checked > $max_checked && $max_checked > 0 || // maximum number of checked recurrences exceeded
365
-				microtime(true) > $start+$max_check_time ||	// max check time exceeded
365
+				microtime(true) > $start + $max_check_time || // max check time exceeded
366 366
 				$startts > $this->config['horizont']))	// we are behind horizon for which recurrences are rendered
367 367
 			{
368 368
 				if ($this->debug > 2 || $this->debug == 'conflicts')
369 369
 				{
370 370
 					$this->debug_message(__METHOD__.'() conflict check limited to %1 recurrences, %2 seconds, until (excluding) %3',
371
-						$checked, microtime(true)-$start, $date);
371
+						$checked, microtime(true) - $start, $date);
372 372
 				}
373 373
 				$checked_excluding = $date;
374 374
 				break;
375 375
 			}
376
-			$overlapping_events =& $this->search(array(
376
+			$overlapping_events = & $this->search(array(
377 377
 				'start' => $startts,
378
-				'end'   => $startts+$duration,
378
+				'end'   => $startts + $duration,
379 379
 				'users' => $users,
380
-				'ignore_acl' => true,	// otherwise we get only events readable by the user
381
-				'enum_groups' => true,	// otherwise group-events would not block time
380
+				'ignore_acl' => true, // otherwise we get only events readable by the user
381
+				'enum_groups' => true, // otherwise group-events would not block time
382 382
 				'query' => array(
383 383
 					'cal_non_blocking' => 0,
384 384
 				),
385
-				'no_integration' => true,	// do NOT use integration of other apps
385
+				'no_integration' => true, // do NOT use integration of other apps
386 386
 			));
387 387
 			if ($this->debug > 2 || $this->debug == 'conflicts')
388 388
 			{
389
-				$this->debug_message(__METHOD__.'() checking for potential overlapping events for users %1 from %2 to %3',false,$users,$startts,$startts+$duration);
389
+				$this->debug_message(__METHOD__.'() checking for potential overlapping events for users %1 from %2 to %3', false, $users, $startts, $startts + $duration);
390 390
 			}
391
-			foreach((array) $overlapping_events as $k => $overlap)
391
+			foreach ((array)$overlapping_events as $k => $overlap)
392 392
 			{
393
-				if ($overlap['id'] == $event['id'] ||	// that's the event itself
394
-					$overlap['id'] == $event['reference'] ||	// event is an exception of overlap
393
+				if ($overlap['id'] == $event['id'] || // that's the event itself
394
+					$overlap['id'] == $event['reference'] || // event is an exception of overlap
395 395
 					$overlap['non_blocking'])			// that's a non_blocking event
396 396
 				{
397 397
 					continue;
398 398
 				}
399 399
 				if ($this->debug > 3 || $this->debug == 'conflicts')
400 400
 				{
401
-					$this->debug_message(__METHOD__.'() checking overlapping event %1',false,$overlap);
401
+					$this->debug_message(__METHOD__.'() checking overlapping event %1', false, $overlap);
402 402
 				}
403 403
 				// check if the overlap is with a rejected participant or within the allowed quantity
404
-				$common_parts = array_intersect($users,array_keys($overlap['participants']));
405
-				foreach($common_parts as $n => $uid)
404
+				$common_parts = array_intersect($users, array_keys($overlap['participants']));
405
+				foreach ($common_parts as $n => $uid)
406 406
 				{
407 407
 					$status = $overlap['participants'][$uid];
408 408
 					calendar_so::split_status($status, $q, $role);
@@ -411,9 +411,9 @@  discard block
 block discarded – undo
411 411
 						unset($common_parts[$n]);
412 412
 						continue;
413 413
 					}
414
-					if (is_numeric($uid) || !in_array($uid[0],$types_with_quantity))
414
+					if (is_numeric($uid) || !in_array($uid[0], $types_with_quantity))
415 415
 					{
416
-						continue;	// no quantity check: quantity allways 1 ==> conflict
416
+						continue; // no quantity check: quantity allways 1 ==> conflict
417 417
 					}
418 418
 					if (!isset($max_quantity[$uid]))
419 419
 					{
@@ -423,7 +423,7 @@  discard block
 block discarded – undo
423 423
 					$quantity[$uid] += $q;
424 424
 					if ($quantity[$uid] <= $max_quantity[$uid])
425 425
 					{
426
-						$possible_quantity_conflicts[$uid][] =& $overlapping_events[$k];	// an other event can give the conflict
426
+						$possible_quantity_conflicts[$uid][] = & $overlapping_events[$k]; // an other event can give the conflict
427 427
 						unset($common_parts[$n]);
428 428
 						continue;
429 429
 					}
@@ -433,22 +433,22 @@  discard block
 block discarded – undo
433 433
 				{
434 434
 					if ($this->debug > 3 || $this->debug == 'conflicts')
435 435
 					{
436
-						$this->debug_message(__METHOD__.'() conflicts with the following participants found %1',false,$common_parts);
436
+						$this->debug_message(__METHOD__.'() conflicts with the following participants found %1', false, $common_parts);
437 437
 					}
438
-					$conflicts[$overlap['id'].'-'.$this->date2ts($overlap['start'])] =& $overlapping_events[$k];
438
+					$conflicts[$overlap['id'].'-'.$this->date2ts($overlap['start'])] = & $overlapping_events[$k];
439 439
 				}
440 440
 			}
441 441
 		}
442 442
 		//error_log(__METHOD__."() conflict check took ".number_format(microtime(true)-$start, 3).'s');
443 443
 		// check if we are withing the allowed quantity and if not add all events using that resource
444 444
 		// seems this function is doing very strange things, it gives empty conflicts
445
-		foreach($max_quantity as $uid => $max)
445
+		foreach ($max_quantity as $uid => $max)
446 446
 		{
447 447
 			if ($quantity[$uid] > $max)
448 448
 			{
449
-				foreach((array)$possible_quantity_conflicts[$uid] as $conflict)
449
+				foreach ((array)$possible_quantity_conflicts[$uid] as $conflict)
450 450
 				{
451
-					$conflicts[$conflict['id'].'-'.$this->date2ts($conflict['start'])] =& $possible_quantity_conflicts[$k];
451
+					$conflicts[$conflict['id'].'-'.$this->date2ts($conflict['start'])] = & $possible_quantity_conflicts[$k];
452 452
 				}
453 453
 			}
454 454
 		}
@@ -456,10 +456,10 @@  discard block
 block discarded – undo
456 456
 
457 457
 		if (count($conflicts))
458 458
 		{
459
-			foreach($conflicts as $key => $conflict)
459
+			foreach ($conflicts as $key => $conflict)
460 460
 			{
461
-					$conflict['participants'] = array_intersect_key((array)$conflict['participants'],$event['participants']);
462
-				if (!$this->check_perms(Acl::READ,$conflict))
461
+					$conflict['participants'] = array_intersect_key((array)$conflict['participants'], $event['participants']);
462
+				if (!$this->check_perms(Acl::READ, $conflict))
463 463
 				{
464 464
 					$conflicts[$key] = array(
465 465
 						'id'    => $conflict['id'],
@@ -472,7 +472,7 @@  discard block
 block discarded – undo
472 472
 			}
473 473
 			if ($this->debug > 2 || $this->debug == 'conflicts')
474 474
 			{
475
-				$this->debug_message(__METHOD__.'() %1 conflicts found %2',false,count($conflicts),$conflicts);
475
+				$this->debug_message(__METHOD__.'() %1 conflicts found %2', false, count($conflicts), $conflicts);
476 476
 			}
477 477
 		}
478 478
 		return $conflicts;
@@ -484,22 +484,22 @@  discard block
 block discarded – undo
484 484
 	 * @param array $old_event =null old event with already invited participants
485 485
 	 * @return array removed participants because of missing invite grants
486 486
 	 */
487
-	public function remove_no_acl_invite(array &$event,array $old_event=null)
487
+	public function remove_no_acl_invite(array &$event, array $old_event = null)
488 488
 	{
489 489
 		if (!$this->require_acl_invite)
490 490
 		{
491
-			return array();	// nothing to check, everyone can invite everyone else
491
+			return array(); // nothing to check, everyone can invite everyone else
492 492
 		}
493 493
 		if ($event['id'] && is_null($old_event))
494 494
 		{
495 495
 			$old_event = $this->read($event['id']);
496 496
 		}
497 497
 		$removed = array();
498
-		foreach(array_keys((array)$event['participants']) as $uid)
498
+		foreach (array_keys((array)$event['participants']) as $uid)
499 499
 		{
500 500
 			if ((is_null($old_event) || !isset($old_event['participants'][$uid])) && !$this->check_acl_invite($uid))
501 501
 			{
502
-				unset($event['participants'][$uid]);	// remove participant
502
+				unset($event['participants'][$uid]); // remove participant
503 503
 				$removed[] = $uid;
504 504
 			}
505 505
 		}
@@ -529,15 +529,15 @@  discard block
 block discarded – undo
529 529
 		}
530 530
 		elseif (!$this->require_acl_invite)
531 531
 		{
532
-			$ret = true;	// no grant required
532
+			$ret = true; // no grant required
533 533
 		}
534 534
 		elseif ($this->require_acl_invite == 'groups' && $GLOBALS['egw']->accounts->get_type($uid) != 'g')
535 535
 		{
536
-			$ret = true;	// grant only required for groups
536
+			$ret = true; // grant only required for groups
537 537
 		}
538 538
 		else
539 539
 		{
540
-			$ret = $this->check_perms(self::ACL_INVITE,0,$uid);
540
+			$ret = $this->check_perms(self::ACL_INVITE, 0, $uid);
541 541
 		}
542 542
 		//error_log(__METHOD__."($uid) = ".array2string($ret));
543 543
 		//echo "<p>".__METHOD__."($uid) require_acl_invite=$this->require_acl_invite returning ".array2string($ret)."</p>\n";
@@ -551,7 +551,7 @@  discard block
 block discarded – undo
551 551
 	 * @param array $old_event the event before the update
552 552
 	 * @todo check if there is a real change, not assume every save is a change
553 553
 	 */
554
-	function check4update($new_event,$old_event)
554
+	function check4update($new_event, $old_event)
555 555
 	{
556 556
 		//error_log(__METHOD__."($new_event[title])");
557 557
 		$modified = $added = $deleted = array();
@@ -559,9 +559,9 @@  discard block
 block discarded – undo
559 559
 		//echo "<p>calendar_boupdate::check4update() new participants = ".print_r($new_event['participants'],true).", old participants =".print_r($old_event['participants'],true)."</p>\n";
560 560
 
561 561
 		// Find modified and deleted participants ...
562
-		foreach($old_event['participants'] as $old_userid => $old_status)
562
+		foreach ($old_event['participants'] as $old_userid => $old_status)
563 563
 		{
564
-			if(isset($new_event['participants'][$old_userid]))
564
+			if (isset($new_event['participants'][$old_userid]))
565 565
 			{
566 566
 				$modified[$old_userid] = $new_event['participants'][$old_userid];
567 567
 			}
@@ -571,27 +571,27 @@  discard block
 block discarded – undo
571 571
 			}
572 572
 		}
573 573
 		// Find new participants ...
574
-		foreach(array_keys((array)$new_event['participants']) as $new_userid)
574
+		foreach (array_keys((array)$new_event['participants']) as $new_userid)
575 575
 		{
576
-			if(!isset($old_event['participants'][$new_userid]))
576
+			if (!isset($old_event['participants'][$new_userid]))
577 577
 			{
578 578
 				$added[$new_userid] = 'U';
579 579
 			}
580 580
 		}
581 581
 		//echo "<p>calendar_boupdate::check4update() added=".print_r($added,true).", modified=".print_r($modified,true).", deleted=".print_r($deleted,true)."</p>\n";
582
-		if(count($added) || count($modified) || count($deleted))
582
+		if (count($added) || count($modified) || count($deleted))
583 583
 		{
584
-			if(count($added))
584
+			if (count($added))
585 585
 			{
586
-				$this->send_update(MSG_ADDED,$added,$old_event,$new_event);
586
+				$this->send_update(MSG_ADDED, $added, $old_event, $new_event);
587 587
 			}
588
-			if(count($modified))
588
+			if (count($modified))
589 589
 			{
590
-				$this->send_update(MSG_MODIFIED,$modified,$old_event,$new_event);
590
+				$this->send_update(MSG_MODIFIED, $modified, $old_event, $new_event);
591 591
 			}
592
-			if(count($deleted))
592
+			if (count($deleted))
593 593
 			{
594
-				$this->send_update(MSG_DISINVITE,$deleted,$new_event);
594
+				$this->send_update(MSG_DISINVITE, $deleted, $new_event);
595 595
 			}
596 596
 		}
597 597
 	}
@@ -608,11 +608,11 @@  discard block
 block discarded – undo
608 608
 	 * @param string $status of current user
609 609
 	 * @return boolean true = update requested, false otherwise
610 610
 	 */
611
-	public static function update_requested($userid, $part_prefs, &$msg_type, $old_event ,$new_event, $role, $status=null)
611
+	public static function update_requested($userid, $part_prefs, &$msg_type, $old_event, $new_event, $role, $status = null)
612 612
 	{
613 613
 		if ($msg_type == MSG_ALARM)
614 614
 		{
615
-			return True;	// always True for now
615
+			return True; // always True for now
616 616
 		}
617 617
 		$want_update = 0;
618 618
 
@@ -625,13 +625,13 @@  discard block
 block discarded – undo
625 625
 		if (!is_numeric($userid) && $role == 'CHAIR' &&
626 626
 			($msg_is_response || in_array($msg_type, array(MSG_ADDED, MSG_DELETED))))
627 627
 		{
628
-			switch($msg_type)
628
+			switch ($msg_type)
629 629
 			{
630 630
 				case MSG_DELETED:	// treat deleting event as rejection to organizer
631 631
 					$msg_type = MSG_REJECTED;
632 632
 					break;
633 633
 				case MSG_ADDED:		// new events use added, but organizer needs status
634
-					switch($status[0])
634
+					switch ($status[0])
635 635
 					{
636 636
 						case 'A': $msg_type = MSG_ACCEPTED; break;
637 637
 						case 'R': $msg_type = MSG_REJECTED; break;
@@ -644,7 +644,7 @@  discard block
 block discarded – undo
644 644
 		}
645 645
 		else
646 646
 		{
647
-			switch($ru = $part_prefs['calendar']['receive_updates'])
647
+			switch ($ru = $part_prefs['calendar']['receive_updates'])
648 648
 			{
649 649
 				case 'responses':
650 650
 					++$want_update;
@@ -658,8 +658,8 @@  discard block
 block discarded – undo
658 658
 				default:
659 659
 					if (is_array($new_event) && is_array($old_event))
660 660
 					{
661
-						$diff = max(abs(self::date2ts($old_event['start'])-self::date2ts($new_event['start'])),
662
-							abs(self::date2ts($old_event['end'])-self::date2ts($new_event['end'])));
661
+						$diff = max(abs(self::date2ts($old_event['start']) - self::date2ts($new_event['start'])),
662
+							abs(self::date2ts($old_event['end']) - self::date2ts($new_event['end'])));
663 663
 						$check = $ru == 'time_change_4h' ? 4 * 60 * 60 - 1 : 0;
664 664
 						if ($msg_type == MSG_MODIFIED && $diff > $check)
665 665
 						{
@@ -687,7 +687,7 @@  discard block
 block discarded – undo
687 687
 	 * @param string $role ='REQ-PARTICIPANT'
688 688
 	 * @return boolean true if user requested to be notified, false if not
689 689
 	 */
690
-	static public function email_update_requested($user_or_email, $ical_method='REQUEST', $role='REQ-PARTICIPANT')
690
+	static public function email_update_requested($user_or_email, $ical_method = 'REQUEST', $role = 'REQ-PARTICIPANT')
691 691
 	{
692 692
 		// check if email is from a user
693 693
 		if (is_numeric($user_or_email))
@@ -711,7 +711,7 @@  discard block
 block discarded – undo
711 711
 				)
712 712
 			);
713 713
 		}
714
-		switch($ical_method)
714
+		switch ($ical_method)
715 715
 		{
716 716
 			default:
717 717
 			case 'REQUEST':
@@ -736,9 +736,9 @@  discard block
 block discarded – undo
736 736
 	 * @param string& $action=null on return verbose name
737 737
 	 * @param string& $msg=null on return notification message
738 738
 	 */
739
-	function msg_type2ical_method($msg_type, &$action=null, &$msg=null)
739
+	function msg_type2ical_method($msg_type, &$action = null, &$msg = null)
740 740
 	{
741
-		switch($msg_type)
741
+		switch ($msg_type)
742 742
 		{
743 743
 			case MSG_DELETED:
744 744
 				$action = 'Canceled';
@@ -790,7 +790,7 @@  discard block
 block discarded – undo
790 790
 		$msg = $this->cal_prefs['notify'.$pref];
791 791
 		if (empty($msg))
792 792
 		{
793
-			$msg = $this->cal_prefs['notifyAdded'];	// use a default
793
+			$msg = $this->cal_prefs['notifyAdded']; // use a default
794 794
 		}
795 795
 		//error_log(__METHOD__."($msg_type) action='$action', $msg='$msg' returning '$method'");
796 796
 		return $method;
@@ -806,7 +806,7 @@  discard block
 block discarded – undo
806 806
 	 * @param int $user =0 User who started the notify, default current user
807 807
 	 * @return bool true/false
808 808
 	 */
809
-	function send_update($msg_type,$to_notify,$old_event,$new_event=null,$user=0)
809
+	function send_update($msg_type, $to_notify, $old_event, $new_event = null, $user = 0)
810 810
 	{
811 811
 		//error_log(__METHOD__."($msg_type,".array2string($to_notify).",...) ".array2string($new_event));
812 812
 		if (!is_array($to_notify))
@@ -818,11 +818,11 @@  discard block
 block discarded – undo
818 818
 		$owner = $old_event ? $old_event['owner'] : $new_event['owner'];
819 819
 		if ($owner && !isset($to_notify[$owner]) && $msg_type != MSG_ALARM)
820 820
 		{
821
-			$to_notify[$owner] = 'OCHAIR';	// always include the event-owner
821
+			$to_notify[$owner] = 'OCHAIR'; // always include the event-owner
822 822
 		}
823 823
 
824 824
 		// ignore events in the past (give a tolerance of 10 seconds for the script)
825
-		if($old_event && $this->date2ts($old_event['start']) < ($this->now_su - 10))
825
+		if ($old_event && $this->date2ts($old_event['start']) < ($this->now_su - 10))
826 826
 		{
827 827
 			return False;
828 828
 		}
@@ -832,7 +832,7 @@  discard block
 block discarded – undo
832 832
 			$restore_tz = $tz;
833 833
 			date_default_timezone_set($GLOBALS['egw_info']['server']['server_timezone']);
834 834
 		}
835
-		$temp_user = $GLOBALS['egw_info']['user'];	// save user-date of the enviroment to restore it after
835
+		$temp_user = $GLOBALS['egw_info']['user']; // save user-date of the enviroment to restore it after
836 836
 
837 837
 		if (!$user)
838 838
 		{
@@ -848,16 +848,16 @@  discard block
 block discarded – undo
848 848
 		$event = $msg_type == MSG_ADDED || $msg_type == MSG_MODIFIED ? $new_event : $old_event;
849 849
 
850 850
 		// add all group-members to the notification, unless they are already participants
851
-		foreach($to_notify as $userid => $statusid)
851
+		foreach ($to_notify as $userid => $statusid)
852 852
 		{
853 853
 			if (is_numeric($userid) && $GLOBALS['egw']->accounts->get_type($userid) == 'g' &&
854 854
 				($members = $GLOBALS['egw']->accounts->members($userid, true)))
855 855
 			{
856
-				foreach($members as $member)
856
+				foreach ($members as $member)
857 857
 				{
858 858
 					if (!isset($to_notify[$member]))
859 859
 					{
860
-						$to_notify[$member] = 'G';	// Group-invitation
860
+						$to_notify[$member] = 'G'; // Group-invitation
861 861
 					}
862 862
 				}
863 863
 			}
@@ -868,7 +868,7 @@  discard block
 block discarded – undo
868 868
 		{
869 869
 			// check if we have *only* an external chair
870 870
 			$chair = null;
871
-			foreach($to_notify as $userid => $statusid)
871
+			foreach ($to_notify as $userid => $statusid)
872 872
 			{
873 873
 				$res_info = $quantity = $role = null;
874 874
 				calendar_so::split_status($statusid, $quantity, $role);
@@ -880,7 +880,7 @@  discard block
 block discarded – undo
880 880
 			// *only* an external chair --> do not notify anyone, but the external chair and the current user
881 881
 			if (!empty($chair) && !is_numeric($chair))
882 882
 			{
883
-				$to_notify = array($chair => $to_notify[$chair])+
883
+				$to_notify = array($chair => $to_notify[$chair]) +
884 884
 					(isset($to_notify[$user]) ? array($user => $to_notify[$user]) : array());
885 885
 			}
886 886
 		}
@@ -891,7 +891,7 @@  discard block
 block discarded – undo
891 891
 		if ($old_event) $olddate = new Api\DateTime($old_event['start']);
892 892
 		//error_log(__METHOD__."() date_default_timezone_get()=".date_default_timezone_get().", user-timezone=".Api\DateTime::$user_timezone->getName().", startdate=".$startdate->format().", enddate=".$enddate->format().", updated=".$modified->format().", olddate=".($olddate ? $olddate->format() : ''));
893 893
 		$owner_prefs = $ics = null;
894
-		foreach($to_notify as $userid => $statusid)
894
+		foreach ($to_notify as $userid => $statusid)
895 895
 		{
896 896
 			$res_info = $quantity = $role = null;
897 897
 			calendar_so::split_status($statusid, $quantity, $role);
@@ -914,14 +914,14 @@  discard block
 block discarded – undo
914 914
 
915 915
 				if (!isset($userid))
916 916
 				{
917
-					if (empty($res_info['email'])) continue;	// no way to notify
917
+					if (empty($res_info['email'])) continue; // no way to notify
918 918
 					// check if event-owner wants non-EGroupware users notified
919 919
 					if (is_null($owner_prefs))
920 920
 					{
921 921
 						$preferences = new Api\Preferences($owner);
922 922
 						$owner_prefs = $preferences->read_repository();
923 923
 					}
924
-					if ($role != 'CHAIR' &&		// always notify externals CHAIRs
924
+					if ($role != 'CHAIR' && // always notify externals CHAIRs
925 925
 						(empty($owner_prefs['calendar']['notify_externals']) ||
926 926
 						$owner_prefs['calendar']['notify_externals'] == 'no'))
927 927
 					{
@@ -933,12 +933,12 @@  discard block
 block discarded – undo
933 933
 
934 934
 			if ($statusid == 'R' || $GLOBALS['egw']->accounts->get_type($userid) == 'g')
935 935
 			{
936
-				continue;	// dont notify rejected participants or groups
936
+				continue; // dont notify rejected participants or groups
937 937
 			}
938 938
 
939
-			if($userid != $GLOBALS['egw_info']['user']['account_id'] ||
939
+			if ($userid != $GLOBALS['egw_info']['user']['account_id'] ||
940 940
 				($userid == $GLOBALS['egw_info']['user']['account_id'] &&
941
-					$user_prefs['calendar']['receive_own_updates']==1) ||
941
+					$user_prefs['calendar']['receive_own_updates'] == 1) ||
942 942
 				$msg_type == MSG_ALARM)
943 943
 			{
944 944
 				$tfn = $tln = $lid = null; //cleanup of lastname and fullname (in case they are set in a previous loop)
@@ -947,8 +947,8 @@  discard block
 block discarded – undo
947 947
 					$preferences = new Api\Preferences($userid);
948 948
 					$GLOBALS['egw_info']['user']['preferences'] = $part_prefs = $preferences->read_repository();
949 949
 					$fullname = Api\Accounts::username($userid);
950
-					$tfn = Api\Accounts::id2name($userid,'account_firstname');
951
-					$tln = Api\Accounts::id2name($userid,'account_lastname');
950
+					$tfn = Api\Accounts::id2name($userid, 'account_firstname');
951
+					$tln = Api\Accounts::id2name($userid, 'account_lastname');
952 952
 				}
953 953
 				else	// external email address: use Api\Preferences of event-owner, plus some hardcoded settings (eg. ical notification)
954 954
 				{
@@ -959,7 +959,7 @@  discard block
 block discarded – undo
959 959
 					}
960 960
 					$part_prefs = $owner_prefs;
961 961
 					$part_prefs['calendar']['receive_updates'] = $owner_prefs['calendar']['notify_externals'];
962
-					$part_prefs['calendar']['update_format'] = 'ical';	// use ical format
962
+					$part_prefs['calendar']['update_format'] = 'ical'; // use ical format
963 963
 					$fullname = $res_info && !empty($res_info['name']) ? $res_info['name'] : $userid;
964 964
 				}
965 965
 				$m_type = $msg_type;
@@ -984,14 +984,14 @@  discard block
 block discarded – undo
984 984
 				$details = $this->_get_event_details(isset($cleared_event) ? $cleared_event : $event,
985 985
 					$action, $event_arr, $disinvited);
986 986
 				$details['to-fullname'] = $fullname;
987
-				$details['to-firstname'] = isset($tfn)? $tfn: '';
988
-				$details['to-lastname'] = isset($tln)? $tln: '';
987
+				$details['to-firstname'] = isset($tfn) ? $tfn : '';
988
+				$details['to-lastname'] = isset($tln) ? $tln : '';
989 989
 
990 990
 				// event is in user-time of current user, now we need to calculate the tz-difference to the notified user and take it into account
991 991
 				if (!isset($part_prefs['common']['tz'])) $part_prefs['common']['tz'] = $GLOBALS['egw_info']['server']['server_timezone'];
992 992
 				$timezone = new DateTimeZone($part_prefs['common']['tz']);
993 993
 				$timeformat = $part_prefs['common']['timeformat'];
994
-				switch($timeformat)
994
+				switch ($timeformat)
995 995
 				{
996 996
 			  		case '24':
997 997
 						$timeformat = 'H:i';
@@ -1000,7 +1000,7 @@  discard block
 block discarded – undo
1000 1000
 						$timeformat = 'h:i a';
1001 1001
 						break;
1002 1002
 				}
1003
-				$timeformat = $part_prefs['common']['dateformat'] . ', ' . $timeformat;
1003
+				$timeformat = $part_prefs['common']['dateformat'].', '.$timeformat;
1004 1004
 
1005 1005
 				$startdate->setTimezone($timezone);
1006 1006
 				$details['startdate'] = $startdate->format($timeformat);
@@ -1009,7 +1009,7 @@  discard block
 block discarded – undo
1009 1009
 				$details['enddate'] = $enddate->format($timeformat);
1010 1010
 
1011 1011
 				$modified->setTimezone($timezone);
1012
-				$details['updated'] = $modified->format($timeformat) . ', ' . Api\Accounts::username($event['modifier']);
1012
+				$details['updated'] = $modified->format($timeformat).', '.Api\Accounts::username($event['modifier']);
1013 1013
 
1014 1014
 				if ($old_event != False)
1015 1015
 				{
@@ -1018,15 +1018,14 @@  discard block
 block discarded – undo
1018 1018
 				}
1019 1019
 				//error_log(__METHOD__."() userid=$userid, timezone=".$timezone->getName().", startdate=$details[startdate], enddate=$details[enddate], updated=$details[updated], olddate=$details[olddate]");
1020 1020
 
1021
-				list($subject,$notify_body) = explode("\n",$GLOBALS['egw']->preferences->parse_notify($notify_msg,$details),2);
1021
+				list($subject, $notify_body) = explode("\n", $GLOBALS['egw']->preferences->parse_notify($notify_msg, $details), 2);
1022 1022
 				// alarm is NOT an iCal method, therefore we have to use extened (no iCal)
1023
-				switch($msg_type == MSG_ALARM ? 'extended' : $part_prefs['calendar']['update_format'])
1023
+				switch ($msg_type == MSG_ALARM ? 'extended' : $part_prefs['calendar']['update_format'])
1024 1024
 				{
1025
-					case 'ical':
1026
-						if (is_null($ics) || $m_type != $msg_type)	// need different ical for organizer notification
1025
+					case 'ical' : if (is_null($ics) || $m_type != $msg_type)	// need different ical for organizer notification
1027 1026
 						{
1028 1027
 							$calendar_ical = new calendar_ical();
1029
-							$calendar_ical->setSupportedFields('full');	// full iCal fields+event TZ
1028
+							$calendar_ical->setSupportedFields('full'); // full iCal fields+event TZ
1030 1029
 							// we need to pass $event[id] so iCal class reads event again,
1031 1030
 							// as event is in user TZ, but iCal class expects server TZ!
1032 1031
 							$ics = $calendar_ical->exportVCal(array(isset($cleared_event) ? $cleared_event : $event['id']),
@@ -1047,11 +1046,11 @@  discard block
 block discarded – undo
1047 1046
 					case 'extended':
1048 1047
 
1049 1048
 						$details_body = lang('Event Details follow').":\n";
1050
-						foreach($event_arr as $key => $val)
1049
+						foreach ($event_arr as $key => $val)
1051 1050
 						{
1052
-							if(!empty($details[$key]))
1051
+							if (!empty($details[$key]))
1053 1052
 							{
1054
-								switch($key)
1053
+								switch ($key)
1055 1054
 								{
1056 1055
 							 		case 'access':
1057 1056
 									case 'priority':
@@ -1060,7 +1059,7 @@  discard block
 block discarded – undo
1060 1059
 									case 'title':
1061 1060
 										break;
1062 1061
 									default:
1063
-										$details_body .= sprintf("%-20s %s\n",$val['field'].':',$details[$key]);
1062
+										$details_body .= sprintf("%-20s %s\n", $val['field'].':', $details[$key]);
1064 1063
 										break;
1065 1064
 							 	}
1066 1065
 							}
@@ -1068,7 +1067,7 @@  discard block
 block discarded – undo
1068 1067
 						break;
1069 1068
 				}
1070 1069
 				// send via notification_app
1071
-				if($GLOBALS['egw_info']['apps']['notifications']['enabled'])
1070
+				if ($GLOBALS['egw_info']['apps']['notifications']['enabled'])
1072 1071
 				{
1073 1072
 					try {
1074 1073
 						//error_log(__METHOD__."() notifying $userid from $senderid: $subject");
@@ -1090,7 +1089,7 @@  discard block
 block discarded – undo
1090 1089
 						// popup notifiactions: set subject, different message (without separator) and (always) links
1091 1090
 						$notification->set_popupsubject($subject);
1092 1091
 
1093
-						if ($method =='REQUEST')
1092
+						if ($method == 'REQUEST')
1094 1093
 						{
1095 1094
 							// Add ACCEPT|REHECT|TENTATIVE actions
1096 1095
 							$notification->set_popupdata('calendar', array(
@@ -1100,11 +1099,11 @@  discard block
 block discarded – undo
1100 1099
 						}
1101 1100
 						if ($m_type === MSG_ALARM) $notification->set_popupdata('calendar', array('egw_pr_notify' => 1));
1102 1101
 						$notification->set_popupmessage($subject."\n\n".$notify_body."\n\n".$details['description']."\n\n".$details_body."\n\n");
1103
-						$notification->set_popuplinks(array($details['link_arr']+array('app'=>'calendar')));
1102
+						$notification->set_popuplinks(array($details['link_arr'] + array('app'=>'calendar')));
1104 1103
 
1105
-						if(is_array($attachment)) { $notification->set_attachments(array($attachment)); }
1104
+						if (is_array($attachment)) { $notification->set_attachments(array($attachment)); }
1106 1105
 						$notification->send();
1107
-						foreach(notifications::errors(true) as $error)
1106
+						foreach (notifications::errors(true) as $error)
1108 1107
 						{
1109 1108
 							error_log(__METHOD__."() Error notifying $userid from $senderid: $subject: $error");
1110 1109
 						}
@@ -1143,14 +1142,14 @@  discard block
 block discarded – undo
1143 1142
 		return true;
1144 1143
 	}
1145 1144
 
1146
-	function get_update_message($event,$added)
1145
+	function get_update_message($event, $added)
1147 1146
 	{
1148 1147
 		$nul = null;
1149
-		$details = $this->_get_event_details($event,$added ? lang('Added') : lang('Modified'),$nul);
1148
+		$details = $this->_get_event_details($event, $added ? lang('Added') : lang('Modified'), $nul);
1150 1149
 
1151 1150
 		$notify_msg = $this->cal_prefs[$added || empty($this->cal_prefs['notifyModified']) ? 'notifyAdded' : 'notifyModified'];
1152 1151
 
1153
-		return explode("\n",$GLOBALS['egw']->preferences->parse_notify($notify_msg,$details),2);
1152
+		return explode("\n", $GLOBALS['egw']->preferences->parse_notify($notify_msg, $details), 2);
1154 1153
 	}
1155 1154
 
1156 1155
 	/**
@@ -1164,37 +1163,37 @@  discard block
 block discarded – undo
1164 1163
 		//echo "<p>bocalendar::send_alarm("; print_r($alarm); echo ")</p>\n";
1165 1164
 		$GLOBALS['egw_info']['user']['account_id'] = $this->owner = $alarm['owner'];
1166 1165
 
1167
-		$event_time_user = Api\DateTime::server2user($alarm['time'] + $alarm['offset']);	// alarm[time] is in server-time, read requires user-time
1168
-		if (!$alarm['owner'] || !$alarm['cal_id'] || !($event = $this->read($alarm['cal_id'],$event_time_user)))
1166
+		$event_time_user = Api\DateTime::server2user($alarm['time'] + $alarm['offset']); // alarm[time] is in server-time, read requires user-time
1167
+		if (!$alarm['owner'] || !$alarm['cal_id'] || !($event = $this->read($alarm['cal_id'], $event_time_user)))
1169 1168
 		{
1170
-			return False;	// event not found
1169
+			return False; // event not found
1171 1170
 		}
1172 1171
 		if ($alarm['all'])
1173 1172
 		{
1174 1173
 			$to_notify = $event['participants'];
1175 1174
 		}
1176
-		elseif ($this->check_perms(Acl::READ,$event))	// checks agains $this->owner set to $alarm[owner]
1175
+		elseif ($this->check_perms(Acl::READ, $event))	// checks agains $this->owner set to $alarm[owner]
1177 1176
 		{
1178 1177
 			$to_notify[$alarm['owner']] = 'A';
1179 1178
 		}
1180 1179
 		else
1181 1180
 		{
1182
-			return False;	// no rights
1181
+			return False; // no rights
1183 1182
 		}
1184 1183
 		// need to load calendar translations and set currentapp, so calendar can reload a different lang
1185 1184
 		Api\Translation::add_app('calendar');
1186 1185
 		$GLOBALS['egw_info']['flags']['currentapp'] = 'calendar';
1187 1186
 
1188
-		$ret = $this->send_update(MSG_ALARM,$to_notify,$event,False,$alarm['owner']);
1187
+		$ret = $this->send_update(MSG_ALARM, $to_notify, $event, False, $alarm['owner']);
1189 1188
 
1190 1189
 		// create a new alarm for recuring events for the next event, if one exists
1191
-		if ($event['recur_type'] != MCAL_RECUR_NONE && ($event = $this->read($alarm['cal_id'],$event_time_user+1)))
1190
+		if ($event['recur_type'] != MCAL_RECUR_NONE && ($event = $this->read($alarm['cal_id'], $event_time_user + 1)))
1192 1191
 		{
1193 1192
 			$alarm['time'] = $this->date2ts($event['start']) - $alarm['offset'];
1194 1193
 			unset($alarm['times']);
1195 1194
 			unset($alarm['next']);
1196 1195
 			//error_log(__METHOD__."() moving alarm to next recurrence ".array2string($alarm));
1197
-			$this->save_alarm($alarm['cal_id'], $alarm, false);	// false = do NOT update timestamp, as nothing changed for iCal clients
1196
+			$this->save_alarm($alarm['cal_id'], $alarm, false); // false = do NOT update timestamp, as nothing changed for iCal clients
1198 1197
 		}
1199 1198
 		return $ret;
1200 1199
 	}
@@ -1210,14 +1209,14 @@  discard block
 block discarded – undo
1210 1209
 	 * Please note: you should ALLWAYS update timestamps, as they are required for sync!
1211 1210
 	 * @return int|boolean $cal_id > 0 or false on error (eg. permission denied)
1212 1211
 	 */
1213
-	function save($event,$ignore_acl=false,$updateTS=true)
1212
+	function save($event, $ignore_acl = false, $updateTS = true)
1214 1213
 	{
1215 1214
 		//error_log(__METHOD__.'('.array2string($event).", $ignore_acl, $updateTS)");
1216 1215
 
1217 1216
 		// check if user has the permission to update / create the event
1218
-		if (!$ignore_acl && ($event['id'] && !$this->check_perms(Acl::EDIT,$event['id']) ||
1219
-			!$event['id'] && !$this->check_perms(Acl::EDIT,0,$event['owner']) &&
1220
-			!$this->check_perms(Acl::ADD,0,$event['owner'])))
1217
+		if (!$ignore_acl && ($event['id'] && !$this->check_perms(Acl::EDIT, $event['id']) ||
1218
+			!$event['id'] && !$this->check_perms(Acl::EDIT, 0, $event['owner']) &&
1219
+			!$this->check_perms(Acl::ADD, 0, $event['owner'])))
1221 1220
 		{
1222 1221
 			return false;
1223 1222
 		}
@@ -1238,7 +1237,7 @@  discard block
 block discarded – undo
1238 1237
 		if ($event['recur_type'] != MCAL_RECUR_NONE && $event['recur_enddate'] && $event['start'])
1239 1238
 		{
1240 1239
 			$event['recur_enddate'] = new Api\DateTime($event['recur_enddate'], calendar_timezones::DateTimeZone($event['tzid']));
1241
-			$event['recur_enddate']->setTime(23,59,59);
1240
+			$event['recur_enddate']->setTime(23, 59, 59);
1242 1241
 			$rrule = calendar_rrule::event2rrule($event, true, Api\DateTime::$user_timezone->getName());
1243 1242
 			$rrule->rewind();
1244 1243
 			$enddate = $rrule->current();
@@ -1297,19 +1296,19 @@  discard block
 block discarded – undo
1297 1296
 
1298 1297
 				$event['recur_enddate'] = $save_event['recur_enddate'] = $time;
1299 1298
 			}
1300
-			$timestamps = array('modified','created');
1299
+			$timestamps = array('modified', 'created');
1301 1300
 			// all-day events are handled in server time
1302 1301
 		//	$event['tzid'] = $save_event['tzid'] = Api\DateTime::$server_timezone->getName();
1303 1302
 		}
1304 1303
 		else
1305 1304
 		{
1306
-			$timestamps = array('start','end','modified','created','recur_enddate','recurrence');
1305
+			$timestamps = array('start', 'end', 'modified', 'created', 'recur_enddate', 'recurrence');
1307 1306
 		}
1308 1307
 		// we run all dates through date2ts, to adjust to server-time and the possible date-formats
1309
-		foreach($timestamps as $ts)
1308
+		foreach ($timestamps as $ts)
1310 1309
 		{
1311 1310
 			// we convert here from user-time to timestamps in server-time!
1312
-			if (isset($event[$ts])) $event[$ts] = $event[$ts] ? $this->date2ts($event[$ts],true) : 0;
1311
+			if (isset($event[$ts])) $event[$ts] = $event[$ts] ? $this->date2ts($event[$ts], true) : 0;
1313 1312
 		}
1314 1313
 		// convert tzid name to integer tz_id, of set user default
1315 1314
 		if (empty($event['tzid']) || !($event['tz_id'] = calendar_timezones::tz2id($event['tzid'])))
@@ -1319,7 +1318,7 @@  discard block
 block discarded – undo
1319 1318
 		// same with the recur exceptions
1320 1319
 		if (isset($event['recur_exception']) && is_array($event['recur_exception']))
1321 1320
 		{
1322
-			foreach($event['recur_exception'] as &$date)
1321
+			foreach ($event['recur_exception'] as &$date)
1323 1322
 			{
1324 1323
 				if ($event['whole_day'])
1325 1324
 				{
@@ -1328,7 +1327,7 @@  discard block
 block discarded – undo
1328 1327
 				}
1329 1328
 				else
1330 1329
 				{
1331
-					$date = $this->date2ts($date,true);
1330
+					$date = $this->date2ts($date, true);
1332 1331
 				}
1333 1332
 			}
1334 1333
 			unset($date);
@@ -1336,7 +1335,7 @@  discard block
 block discarded – undo
1336 1335
 		// same with the alarms
1337 1336
 		if (isset($event['alarm']) && is_array($event['alarm']) && isset($event['start']))
1338 1337
 		{
1339
-			foreach($event['alarm'] as $id => &$alarm)
1338
+			foreach ($event['alarm'] as $id => &$alarm)
1340 1339
 			{
1341 1340
 				// remove alarms belonging to not longer existing or rejected participants
1342 1341
 				if ($alarm['owner'] && isset($event['participants']))
@@ -1349,21 +1348,20 @@  discard block
 block discarded – undo
1349 1348
 						//error_log(__LINE__.': '.__METHOD__."(".array2string($event).") deleting alarm=".array2string($alarm).", $status=".array2string($alarm));
1350 1349
 					}
1351 1350
 				}
1352
-				$alarm['time'] = $this->date2ts($alarm['time'],true);	// user to server-time
1351
+				$alarm['time'] = $this->date2ts($alarm['time'], true); // user to server-time
1353 1352
 			}
1354 1353
 		}
1355 1354
 		// update all existing alarm times, in case alarm got moved and alarms are not include in $event
1356 1355
 		if ($old_event && is_array($old_event['alarm']) && isset($event['start']))
1357 1356
 		{
1358
-			foreach($old_event['alarm'] as $id => &$alarm)
1357
+			foreach ($old_event['alarm'] as $id => &$alarm)
1359 1358
 			{
1360 1359
 				if (!isset($event['alarm'][$id]))
1361 1360
 				{
1362 1361
 					$alarm['time'] = $event['start'] - $alarm['offset'];
1363 1362
 					if ($alarm['time'] < time()) calendar_so::shift_alarm($event, $alarm);
1364 1363
 						// remove (not store) alarms belonging to not longer existing or rejected participants
1365
-					$status = isset($event['participants']) ? $event['participants'][$alarm['owner']] :
1366
-						$old_event['participants'][$alarm['owner']];
1364
+					$status = isset($event['participants']) ? $event['participants'][$alarm['owner']] : $old_event['participants'][$alarm['owner']];
1367 1365
 					if (!$alarm['owner'] || isset($status) && calendar_so::split_status($status) !== 'R')
1368 1366
 					{
1369 1367
 						$this->so->save_alarm($event['id'], $alarm);
@@ -1392,7 +1390,7 @@  discard block
 block discarded – undo
1392 1390
 		}
1393 1391
 		$set_recurrences = $old_event ? abs($event['recur_enddate'] - $old_event['recur_enddate']) > 1 : false;
1394 1392
 		$set_recurrences_start = 0;
1395
-		if (($cal_id = $this->so->save($event,$set_recurrences,$set_recurrences_start,0,$event['etag'])) && $set_recurrences && $event['recur_type'] != MCAL_RECUR_NONE)
1393
+		if (($cal_id = $this->so->save($event, $set_recurrences, $set_recurrences_start, 0, $event['etag'])) && $set_recurrences && $event['recur_type'] != MCAL_RECUR_NONE)
1396 1394
 		{
1397 1395
 			$save_event['id'] = $cal_id;
1398 1396
 			// unset participants to enforce the default stati for all added recurrences
@@ -1403,7 +1401,7 @@  discard block
 block discarded – undo
1403 1401
 		// create links for new participants from addressbook, if configured
1404 1402
 		if ($cal_id && $GLOBALS['egw_info']['server']['link_contacts'] && $event['participants'])
1405 1403
 		{
1406
-			foreach($event['participants'] as $uid => $status)
1404
+			foreach ($event['participants'] as $uid => $status)
1407 1405
 			{
1408 1406
 				$user_type = $user_id = null;
1409 1407
 				calendar_so::split_user($uid, $user_type, $user_id);
@@ -1416,7 +1414,7 @@  discard block
 block discarded – undo
1416 1414
 
1417 1415
 		// Update history
1418 1416
 		$tracking = new calendar_tracking($this);
1419
-		if (empty($event['id']) && !empty($cal_id)) $event['id']=$cal_id;
1417
+		if (empty($event['id']) && !empty($cal_id)) $event['id'] = $cal_id;
1420 1418
 		$tracking->track($event, $old_event);
1421 1419
 
1422 1420
 		return $cal_id;
@@ -1431,16 +1429,16 @@  discard block
 block discarded – undo
1431 1429
 	 * @param array|int $event event array or id of the event
1432 1430
 	 * @return boolean
1433 1431
 	 */
1434
-	function check_status_perms($uid,$event)
1432
+	function check_status_perms($uid, $event)
1435 1433
 	{
1436 1434
 		if ($uid[0] == 'c' || $uid[0] == 'e')	// for contact we use the owner of the event
1437 1435
 		{
1438 1436
 			if (!is_array($event) && !($event = $this->read($event))) return false;
1439 1437
 
1440
-			return $this->check_perms(Acl::EDIT,0,$event['owner']);
1438
+			return $this->check_perms(Acl::EDIT, 0, $event['owner']);
1441 1439
 		}
1442 1440
 		// check if we have a category Acl for the event or not (null)
1443
-		$access = $this->check_cat_acl(self::CAT_ACL_STATUS,$event);
1441
+		$access = $this->check_cat_acl(self::CAT_ACL_STATUS, $event);
1444 1442
 		if (!is_null($access))
1445 1443
 		{
1446 1444
 			return $access;
@@ -1457,10 +1455,10 @@  discard block
 block discarded – undo
1457 1455
 		// regular user and groups (need to check memberships too)
1458 1456
 		if (!isset($event['participants'][$uid]))
1459 1457
 		{
1460
-			$memberships = $GLOBALS['egw']->accounts->memberships($uid,true);
1458
+			$memberships = $GLOBALS['egw']->accounts->memberships($uid, true);
1461 1459
 		}
1462 1460
 		$memberships[] = $uid;
1463
-		return array_intersect($memberships, array_keys($event['participants'])) && $this->check_perms(Acl::EDIT,0,$uid);
1461
+		return array_intersect($memberships, array_keys($event['participants'])) && $this->check_perms(Acl::EDIT, 0, $uid);
1464 1462
 	}
1465 1463
 
1466 1464
 	/**
@@ -1474,16 +1472,16 @@  discard block
 block discarded – undo
1474 1472
 	 * @return boolean false=access denied because of cat acl, true access granted because of cat acl,
1475 1473
 	 * 	null = cat has no acl
1476 1474
 	 */
1477
-	function check_cat_acl($right,$event)
1475
+	function check_cat_acl($right, $event)
1478 1476
 	{
1479 1477
 		if (!is_array($event)) $event = $this->read($event);
1480 1478
 
1481 1479
 		$ret = null;
1482 1480
 		if ($event['category'])
1483 1481
 		{
1484
-			foreach(is_array($event['category']) ? $event['category'] : explode(',',$event['category']) as $cat_id)
1482
+			foreach (is_array($event['category']) ? $event['category'] : explode(',', $event['category']) as $cat_id)
1485 1483
 			{
1486
-				$access = self::has_cat_right($right,$cat_id,$this->user);
1484
+				$access = self::has_cat_right($right, $cat_id, $this->user);
1487 1485
 				if ($access === true)
1488 1486
 				{
1489 1487
 					$ret = true;
@@ -1491,7 +1489,7 @@  discard block
 block discarded – undo
1491 1489
 				}
1492 1490
 				if ($access === false)
1493 1491
 				{
1494
-					$ret = false;	// cat denies access --> check further cats
1492
+					$ret = false; // cat denies access --> check further cats
1495 1493
 				}
1496 1494
 			}
1497 1495
 		}
@@ -1512,12 +1510,12 @@  discard block
 block discarded – undo
1512 1510
 	 * @param int $cat_id =null null to return array with all cats
1513 1511
 	 * @return array with account_id => right pairs
1514 1512
 	 */
1515
-	public static function get_cat_rights($cat_id=null)
1513
+	public static function get_cat_rights($cat_id = null)
1516 1514
 	{
1517 1515
 		if (!isset(self::$cat_rights_cache))
1518 1516
 		{
1519
-			self::$cat_rights_cache = Api\Cache::getSession('calendar','cat_rights',
1520
-				array($GLOBALS['egw']->acl,'get_location_grants'),array('L%','calendar'));
1517
+			self::$cat_rights_cache = Api\Cache::getSession('calendar', 'cat_rights',
1518
+				array($GLOBALS['egw']->acl, 'get_location_grants'), array('L%', 'calendar'));
1521 1519
 		}
1522 1520
 		//echo "<p>".__METHOD__."($cat_id) = ".array2string($cat_id ? self::$cat_rights_cache['L'.$cat_id] : self::$cat_rights_cache)."</p>\n";
1523 1521
 		return $cat_id ? self::$cat_rights_cache['L'.$cat_id] : self::$cat_rights_cache;
@@ -1530,7 +1528,7 @@  discard block
 block discarded – undo
1530 1528
 	 * @param int $user
1531 1529
 	 * @param int $rights self::CAT_ACL_{ADD|STATUS} or'ed together
1532 1530
 	 */
1533
-	public static function set_cat_rights($cat_id,$user,$rights)
1531
+	public static function set_cat_rights($cat_id, $user, $rights)
1534 1532
 	{
1535 1533
 		//echo "<p>".__METHOD__."($cat_id,$user,$rights)</p>\n";
1536 1534
 		if (!isset(self::$cat_rights_cache)) self::get_cat_rights($cat_id);
@@ -1540,15 +1538,15 @@  discard block
 block discarded – undo
1540 1538
 			if ($rights)
1541 1539
 			{
1542 1540
 				self::$cat_rights_cache['L'.$cat_id][$user] = $rights;
1543
-				$GLOBALS['egw']->acl->add_repository('calendar','L'.$cat_id,$user,$rights);
1541
+				$GLOBALS['egw']->acl->add_repository('calendar', 'L'.$cat_id, $user, $rights);
1544 1542
 			}
1545 1543
 			else
1546 1544
 			{
1547 1545
 				unset(self::$cat_rights_cache['L'.$cat_id][$user]);
1548 1546
 				if (!self::$cat_rights_cache['L'.$cat_id]) unset(self::$cat_rights_cache['L'.$cat_id]);
1549
-				$GLOBALS['egw']->acl->delete_repository('calendar','L'.$cat_id,$user);
1547
+				$GLOBALS['egw']->acl->delete_repository('calendar', 'L'.$cat_id, $user);
1550 1548
 			}
1551
-			Api\Cache::setSession('calendar','cat_rights',self::$cat_rights_cache);
1549
+			Api\Cache::setSession('calendar', 'cat_rights', self::$cat_rights_cache);
1552 1550
 		}
1553 1551
 	}
1554 1552
 
@@ -1559,9 +1557,9 @@  discard block
 block discarded – undo
1559 1557
 	 * @return boolean false=access denied because of cat acl, true access granted because of cat acl,
1560 1558
 	 * 	null = cat has no acl
1561 1559
 	 */
1562
-	public static function has_cat_right($right,$cat_id,$user)
1560
+	public static function has_cat_right($right, $cat_id, $user)
1563 1561
 	{
1564
-		static $cache=null;
1562
+		static $cache = null;
1565 1563
 
1566 1564
 		if (!isset($cache[$cat_id]))
1567 1565
 		{
@@ -1569,21 +1567,21 @@  discard block
 block discarded – undo
1569 1567
 			$cat_rights = self::get_cat_rights($cat_id);
1570 1568
 			if (!is_null($cat_rights))
1571 1569
 			{
1572
-				static $memberships=null;
1570
+				static $memberships = null;
1573 1571
 				if (is_null($memberships))
1574 1572
 				{
1575
-					$memberships = $GLOBALS['egw']->accounts->memberships($user,true);
1573
+					$memberships = $GLOBALS['egw']->accounts->memberships($user, true);
1576 1574
 					$memberships[] = $user;
1577 1575
 				}
1578
-				foreach($cat_rights as $uid => $value)
1576
+				foreach ($cat_rights as $uid => $value)
1579 1577
 				{
1580 1578
 					$all |= $value;
1581
-					if (in_array($uid,$memberships)) $own |= $value;
1579
+					if (in_array($uid, $memberships)) $own |= $value;
1582 1580
 				}
1583 1581
 			}
1584
-			foreach(array(self::CAT_ACL_ADD,self::CAT_ACL_STATUS) as $mask)
1582
+			foreach (array(self::CAT_ACL_ADD, self::CAT_ACL_STATUS) as $mask)
1585 1583
 			{
1586
-				$cache[$cat_id][$mask] = !($all & $mask) ? null : !!($own & $mask);
1584
+				$cache[$cat_id][$mask] = !($all&$mask) ? null : !!($own&$mask);
1587 1585
 			}
1588 1586
 		}
1589 1587
 		//echo "<p>".__METHOD__."($right,$cat_id) all=$all, own=$own returning ".array2string($cache[$cat_id][$right])."</p>\n";
@@ -1603,13 +1601,13 @@  discard block
 block discarded – undo
1603 1601
 	 * @param boolean $skip_notification =false true: do not send notification messages
1604 1602
 	 * @return int number of changed recurrences
1605 1603
 	 */
1606
-	function set_status($event,$uid,$status,$recur_date=0,$ignore_acl=false,$updateTS=true,$skip_notification=false)
1604
+	function set_status($event, $uid, $status, $recur_date = 0, $ignore_acl = false, $updateTS = true, $skip_notification = false)
1607 1605
 	{
1608 1606
 		unset($updateTS);
1609 1607
 
1610 1608
 		$cal_id = is_array($event) ? $event['id'] : $event;
1611 1609
 		//echo "<p>calendar_boupdate::set_status($cal_id,$uid,$status,$recur_date)</p>\n";
1612
-		if (!$cal_id || (!$ignore_acl && !$this->check_status_perms($uid,$event)))
1610
+		if (!$cal_id || (!$ignore_acl && !$this->check_status_perms($uid, $event)))
1613 1611
 		{
1614 1612
 			return false;
1615 1613
 		}
@@ -1618,16 +1616,16 @@  discard block
 block discarded – undo
1618 1616
 		if ($this->log)
1619 1617
 		{
1620 1618
 			error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
1621
-				"($cal_id, $uid, $status, $recur_date)\n",3,$this->logfile);
1619
+				"($cal_id, $uid, $status, $recur_date)\n", 3, $this->logfile);
1622 1620
 		}
1623 1621
 		$old_event = $this->read($cal_id, $recur_date, $ignore_acl, 'server');
1624
-		if (($Ok = $this->so->set_status($cal_id,is_numeric($uid)?'u':$uid[0],
1625
-				is_numeric($uid)?$uid:substr($uid,1),$status,
1626
-				$recur_date?$this->date2ts($recur_date,true):0,$role)))
1622
+		if (($Ok = $this->so->set_status($cal_id, is_numeric($uid) ? 'u' : $uid[0],
1623
+				is_numeric($uid) ? $uid : substr($uid, 1), $status,
1624
+				$recur_date ? $this->date2ts($recur_date, true) : 0, $role)))
1627 1625
 		{
1628 1626
 			if ($status == 'R')	// remove alarms belonging to rejected participants
1629 1627
 			{
1630
-				foreach(is_array($event) && isset($event['alarm']) ? $event['alarm'] : $old_event['alarm'] as $id => $alarm)
1628
+				foreach (is_array($event) && isset($event['alarm']) ? $event['alarm'] : $old_event['alarm'] as $id => $alarm)
1631 1629
 				{
1632 1630
 					if ((string)$alarm['owner'] === (string)$uid)
1633 1631
 					{
@@ -1649,8 +1647,8 @@  discard block
 block discarded – undo
1649 1647
 			if (isset($status2msg[$status]) && !$skip_notification)
1650 1648
 			{
1651 1649
 				if (!is_array($event)) $event = $this->read($cal_id);
1652
-				if (isset($recur_date)) $event = $this->read($event['id'],$recur_date); //re-read the actually edited recurring event
1653
-				$this->send_update($status2msg[$status],$event['participants'],$event);
1650
+				if (isset($recur_date)) $event = $this->read($event['id'], $recur_date); //re-read the actually edited recurring event
1651
+				$this->send_update($status2msg[$status], $event['participants'], $event);
1654 1652
 			}
1655 1653
 
1656 1654
 			// Update history
@@ -1670,14 +1668,14 @@  discard block
 block discarded – undo
1670 1668
 	 * @param int $recur_date =0 date to change, or 0 = all since now
1671 1669
 	 * @param boolean $skip_notification Do not send notifications.  Parameter passed on to set_status().
1672 1670
 	 */
1673
-	function update_status($new_event, $old_event , $recur_date=0, $skip_notification=false)
1671
+	function update_status($new_event, $old_event, $recur_date = 0, $skip_notification = false)
1674 1672
 	{
1675 1673
 		if (!isset($new_event['participants'])) return;
1676 1674
 
1677 1675
 		// check the old list against the new list
1678 1676
 		foreach ($old_event['participants'] as $userid => $status)
1679 1677
   		{
1680
-            if (!isset($new_event['participants'][$userid])){
1678
+            if (!isset($new_event['participants'][$userid])) {
1681 1679
             	// Attendee will be deleted this way
1682 1680
             	$new_event['participants'][$userid] = 'G';
1683 1681
             }
@@ -1690,7 +1688,7 @@  discard block
 block discarded – undo
1690 1688
 		// write the changes
1691 1689
 		foreach ($new_event['participants'] as $userid => $status)
1692 1690
 		{
1693
-			$this->set_status($old_event, $userid, $status, $recur_date, true, false,$skip_notification);
1691
+			$this->set_status($old_event, $userid, $status, $recur_date, true, false, $skip_notification);
1694 1692
 		}
1695 1693
     }
1696 1694
 
@@ -1705,43 +1703,43 @@  discard block
 block discarded – undo
1705 1703
 	 * @param int &$exceptions_kept=null on return number of kept exceptions
1706 1704
 	 * @return boolean true on success, false on error (usually permission denied)
1707 1705
 	 */
1708
-	function delete($cal_id, $recur_date=0, $ignore_acl=false, $skip_notification=false,
1709
-		$delete_exceptions=true, &$exceptions_kept=null)
1706
+	function delete($cal_id, $recur_date = 0, $ignore_acl = false, $skip_notification = false,
1707
+		$delete_exceptions = true, &$exceptions_kept = null)
1710 1708
 	{
1711 1709
 		//error_log(__METHOD__."(cal_id=$cal_id, recur_date=$recur_date, ignore_acl=$ignore_acl, skip_notifications=$skip_notification)");
1712
-		if (!($event = $this->read($cal_id,$recur_date)) ||
1713
-			!$ignore_acl && !$this->check_perms(Acl::DELETE,$event))
1710
+		if (!($event = $this->read($cal_id, $recur_date)) ||
1711
+			!$ignore_acl && !$this->check_perms(Acl::DELETE, $event))
1714 1712
 		{
1715 1713
 			return false;
1716 1714
 		}
1717 1715
 
1718 1716
 		// Don't send notification if the event has already been deleted
1719
-		if(!$event['deleted'] && !$skip_notification)
1717
+		if (!$event['deleted'] && !$skip_notification)
1720 1718
 		{
1721
-			$this->send_update(MSG_DELETED,$event['participants'],$event);
1719
+			$this->send_update(MSG_DELETED, $event['participants'], $event);
1722 1720
 		}
1723 1721
 
1724 1722
 		if (!$recur_date || $event['recur_type'] == MCAL_RECUR_NONE)
1725 1723
 		{
1726 1724
 			$config = Api\Config::read('phpgwapi');
1727
-			if(!$config['calendar_delete_history'] || $event['deleted'])
1725
+			if (!$config['calendar_delete_history'] || $event['deleted'])
1728 1726
 			{
1729 1727
 				$this->so->delete($cal_id);
1730 1728
 
1731 1729
 				// delete all links to the event
1732
-				Link::unlink(0,'calendar',$cal_id);
1730
+				Link::unlink(0, 'calendar', $cal_id);
1733 1731
 			}
1734 1732
 			elseif ($config['calendar_delete_history'])
1735 1733
 			{
1736 1734
 				// mark all links to the event as deleted, but keep them
1737
-				Link::unlink(0,'calendar',$cal_id,'','','',true);
1735
+				Link::unlink(0, 'calendar', $cal_id, '', '', '', true);
1738 1736
 
1739 1737
 				$event['deleted'] = $this->now;
1740 1738
 				$this->save($event, $ignore_acl);
1741 1739
 				// Actually delete alarms
1742 1740
 				if (isset($event['alarm']) && is_array($event['alarm']))
1743 1741
 				{
1744
-					foreach($event['alarm'] as $id => $alarm)
1742
+					foreach ($event['alarm'] as $id => $alarm)
1745 1743
 					{
1746 1744
 						$this->delete_alarm($id);
1747 1745
 					}
@@ -1763,7 +1761,7 @@  discard block
 block discarded – undo
1763 1761
 						if (!($exception = $this->read($id))) continue;
1764 1762
 						$exception['uid'] = Api\CalDAV::generate_uid('calendar', $id);
1765 1763
 						$exception['reference'] = $exception['recurrence'] = 0;
1766
-						$this->update($exception, true, true, false, true, $msg=null, true);
1764
+						$this->update($exception, true, true, false, true, $msg = null, true);
1767 1765
 						++$exceptions_kept;
1768 1766
 					}
1769 1767
 				}
@@ -1775,9 +1773,9 @@  discard block
 block discarded – undo
1775 1773
 			if ($event['alarm'])
1776 1774
 			{
1777 1775
 				$next_recurrance = null;
1778
-				foreach($event['alarm'] as &$alarm)
1776
+				foreach ($event['alarm'] as &$alarm)
1779 1777
 				{
1780
-					if (($alarm['time'] == $recur_date) || ($alarm['time']+$alarm['offset'] == $recur_date))
1778
+					if (($alarm['time'] == $recur_date) || ($alarm['time'] + $alarm['offset'] == $recur_date))
1781 1779
 					{
1782 1780
 						//error_log(__METHOD__.__LINE__.'->'.array2string($recur_date));
1783 1781
 						//error_log(__METHOD__.__LINE__.array2string($event));
@@ -1785,12 +1783,12 @@  discard block
 block discarded – undo
1785 1783
 						{
1786 1784
 							$checkdate = $recur_date;
1787 1785
 							//if ($alarm['time']+$alarm['offset'] == $recur_date) $checkdate = $recur_date + $alarm['offset'];
1788
-							if (($e = $this->read($cal_id,$checkdate+1)))
1786
+							if (($e = $this->read($cal_id, $checkdate + 1)))
1789 1787
 							{
1790 1788
 								$next_recurrance = $this->date2ts($e['start']);
1791 1789
 							}
1792 1790
 						}
1793
-						$alarm['time'] = $this->date2ts($next_recurrance, true);	// user to server-time
1791
+						$alarm['time'] = $this->date2ts($next_recurrance, true); // user to server-time
1794 1792
 						$alarm['cal_id'] = $cal_id;
1795 1793
 						unset($alarm['times']);
1796 1794
 						unset($alarm['next']);
@@ -1804,7 +1802,7 @@  discard block
 block discarded – undo
1804 1802
 			$event = $this->read($cal_id);
1805 1803
 			//if (isset($alarmbuffer)) $event['alarm'] = $alarmbuffer;
1806 1804
 			$event['recur_exception'][] = $recur_date;
1807
-			$this->save($event);// updates the content-history
1805
+			$this->save($event); // updates the content-history
1808 1806
 		}
1809 1807
 		if ($event['reference'])
1810 1808
 		{
@@ -1822,19 +1820,19 @@  discard block
 block discarded – undo
1822 1820
 	 * @param array $disinvited
1823 1821
 	 * @return array
1824 1822
 	 */
1825
-	function _get_event_details($event,$action,&$event_arr,$disinvited=array())
1823
+	function _get_event_details($event, $action, &$event_arr, $disinvited = array())
1826 1824
 	{
1827 1825
 		$details = array(			// event-details for the notify-msg
1828 1826
 			'id'          => $event['id'],
1829 1827
 			'action'      => lang($action),
1830 1828
 		);
1831 1829
 		$event_arr = $this->event2array($event);
1832
-		foreach($event_arr as $key => $val)
1830
+		foreach ($event_arr as $key => $val)
1833 1831
 		{
1834 1832
 			if ($key == 'recur_type') $key = 'repetition';
1835 1833
 			$details[$key] = $val['data'];
1836 1834
 		}
1837
-		$details['participants'] = $details['participants'] ? implode("\n",$details['participants']) : '';
1835
+		$details['participants'] = $details['participants'] ? implode("\n", $details['participants']) : '';
1838 1836
 
1839 1837
 		$event_arr['link']['field'] = lang('URL');
1840 1838
 		$eventStart_arr = $this->date2array($event['start']); // give this as 'date' to the link to pick the right recurrence for the participants state
@@ -1850,7 +1848,7 @@  discard block
 block discarded – undo
1850 1848
 		 */
1851 1849
 		$link_arr = array();
1852 1850
 		$link_arr['text'] = $event['title'];
1853
-		$link_arr['view'] = array(	'menuaction' => 'calendar.calendar_uiforms.edit',
1851
+		$link_arr['view'] = array('menuaction' => 'calendar.calendar_uiforms.edit',
1854 1852
 									'cal_id' => $event['id'],
1855 1853
 									'date' => $eventStart_arr['full'],
1856 1854
 									'ajax' => true
@@ -1859,11 +1857,11 @@  discard block
 block discarded – undo
1859 1857
 		$details['link_arr'] = $link_arr;
1860 1858
 
1861 1859
 		$dis = array();
1862
-		foreach($disinvited as $uid)
1860
+		foreach ($disinvited as $uid)
1863 1861
 		{
1864 1862
 			$dis[] = $this->participant_name($uid);
1865 1863
 		}
1866
-		$details['disinvited'] = implode(', ',$dis);
1864
+		$details['disinvited'] = implode(', ', $dis);
1867 1865
 		return $details;
1868 1866
 	}
1869 1867
 
@@ -1887,13 +1885,13 @@  discard block
 block discarded – undo
1887 1885
 			'data'	=> $event['description']
1888 1886
 		);
1889 1887
 
1890
-		foreach(explode(',',$event['category']) as $cat_id)
1888
+		foreach (explode(',', $event['category']) as $cat_id)
1891 1889
 		{
1892 1890
 			$cat_string[] = stripslashes(Api\Categories::id2name($cat_id));
1893 1891
 		}
1894 1892
 		$var['category'] = Array(
1895 1893
 			'field'	=> lang('Category'),
1896
-			'data'	=> implode(', ',$cat_string)
1894
+			'data'	=> implode(', ', $cat_string)
1897 1895
 		);
1898 1896
 
1899 1897
 		$var['location'] = Array(
@@ -1939,7 +1937,7 @@  discard block
 block discarded – undo
1939 1937
 
1940 1938
 		if (isset($event['participants']) && is_array($event['participants']) && !empty($event['participants']))
1941 1939
 		{
1942
-			$participants = $this->participants($event,true);
1940
+			$participants = $this->participants($event, true);
1943 1941
 		}
1944 1942
 		$var['participants'] = Array(
1945 1943
 			'field'	=> lang('Participants'),
@@ -1962,26 +1960,26 @@  discard block
 block discarded – undo
1962 1960
 	 * @param array $old_event =null event-data in the DB before calling save
1963 1961
 	 * @param string $type ='update'
1964 1962
 	 */
1965
-	function log2file($event2save,$event_saved,$old_event=null,$type='update')
1963
+	function log2file($event2save, $event_saved, $old_event = null, $type = 'update')
1966 1964
 	{
1967
-		if (!($f = fopen($this->log_file,'a')))
1965
+		if (!($f = fopen($this->log_file, 'a')))
1968 1966
 		{
1969 1967
 			echo "<p>error opening '$this->log_file' !!!</p>\n";
1970 1968
 			return false;
1971 1969
 		}
1972
-		fwrite($f,$type.': '.Api\Accounts::username($this->user).': '.date('r')."\n");
1973
-		fwrite($f,"Time: time to save / saved time read back / old time before save\n");
1974
-		foreach(array('start','end') as $name)
1970
+		fwrite($f, $type.': '.Api\Accounts::username($this->user).': '.date('r')."\n");
1971
+		fwrite($f, "Time: time to save / saved time read back / old time before save\n");
1972
+		foreach (array('start', 'end') as $name)
1975 1973
 		{
1976
-			fwrite($f,$name.': '.(isset($event2save[$name]) ? $this->format_date($event2save[$name]) : 'not set').' / '.
1977
-				$this->format_date($event_saved[$name]) .' / '.
1974
+			fwrite($f, $name.': '.(isset($event2save[$name]) ? $this->format_date($event2save[$name]) : 'not set').' / '.
1975
+				$this->format_date($event_saved[$name]).' / '.
1978 1976
 				(is_null($old_event) ? 'no old event' : $this->format_date($old_event[$name]))."\n");
1979 1977
 		}
1980
-		foreach(array('event2save','event_saved','old_event') as $name)
1978
+		foreach (array('event2save', 'event_saved', 'old_event') as $name)
1981 1979
 		{
1982
-			fwrite($f,$name.' = '.print_r($$name,true));
1980
+			fwrite($f, $name.' = '.print_r($$name, true));
1983 1981
 		}
1984
-		fwrite($f,"\n");
1982
+		fwrite($f, "\n");
1985 1983
 		fclose($f);
1986 1984
 
1987 1985
 		return true;
@@ -2002,14 +2000,14 @@  discard block
 block discarded – undo
2002 2000
 		if ($old_event !== null && $event['start'] == $old_event['start']) return;
2003 2001
 
2004 2002
 		$time = new Api\DateTime($event['start']);
2005
-		if(!is_array($event['alarm']))
2003
+		if (!is_array($event['alarm']))
2006 2004
 		{
2007 2005
 			$event['alarm'] = $this->so->read_alarms($event['id']);
2008 2006
 		}
2009 2007
 
2010
-		foreach($event['alarm'] as &$alarm)
2008
+		foreach ($event['alarm'] as &$alarm)
2011 2009
 		{
2012
-			if($event['recur_type'] != MCAL_RECUR_NONE && is_object($instance_date))
2010
+			if ($event['recur_type'] != MCAL_RECUR_NONE && is_object($instance_date))
2013 2011
 			{
2014 2012
 				calendar_so::shift_alarm($event, $alarm, $instance_date->format('ts'));
2015 2013
 			}
@@ -2029,14 +2027,14 @@  discard block
 block discarded – undo
2029 2027
 	 * @param boolean $update_modified =true call update modified, default true
2030 2028
 	 * @return string id of the alarm, or false on error (eg. no perms)
2031 2029
 	 */
2032
-	function save_alarm($cal_id, $alarm, $update_modified=true)
2030
+	function save_alarm($cal_id, $alarm, $update_modified = true)
2033 2031
 	{
2034
-		if (!$cal_id || !$this->check_perms(Acl::EDIT,$alarm['all'] ? $cal_id : 0,!$alarm['all'] ? $alarm['owner'] : 0))
2032
+		if (!$cal_id || !$this->check_perms(Acl::EDIT, $alarm['all'] ? $cal_id : 0, !$alarm['all'] ? $alarm['owner'] : 0))
2035 2033
 		{
2036 2034
 			//echo "<p>no rights to save the alarm=".print_r($alarm,true)." to event($cal_id)</p>";
2037
-			return false;	// no rights to add the alarm
2035
+			return false; // no rights to add the alarm
2038 2036
 		}
2039
-		$alarm['time'] = $this->date2ts($alarm['time'],true);	// user to server-time
2037
+		$alarm['time'] = $this->date2ts($alarm['time'], true); // user to server-time
2040 2038
 
2041 2039
 		return $this->so->save_alarm($cal_id, $alarm, $update_modified);
2042 2040
 	}
@@ -2049,11 +2047,11 @@  discard block
 block discarded – undo
2049 2047
 	 */
2050 2048
 	function delete_alarm($id)
2051 2049
 	{
2052
-		list(,$cal_id) = explode(':',$id);
2050
+		list(,$cal_id) = explode(':', $id);
2053 2051
 
2054
-		if (!($alarm = $this->so->read_alarm($id)) || !$cal_id || !$this->check_perms(Acl::EDIT,$alarm['all'] ? $cal_id : 0,!$alarm['all'] ? $alarm['owner'] : 0))
2052
+		if (!($alarm = $this->so->read_alarm($id)) || !$cal_id || !$this->check_perms(Acl::EDIT, $alarm['all'] ? $cal_id : 0, !$alarm['all'] ? $alarm['owner'] : 0))
2055 2053
 		{
2056
-			return false;	// no rights to delete the alarm
2054
+			return false; // no rights to delete the alarm
2057 2055
 		}
2058 2056
 
2059 2057
 		return $this->so->delete_alarm($id);
@@ -2068,13 +2066,13 @@  discard block
 block discarded – undo
2068 2066
 	 *  by the ones the user normally does not see due to category permissions - used to preserve categories
2069 2067
 	 * @return array category ids (found, added and preserved categories)
2070 2068
 	 */
2071
-	function find_or_add_categories($catname_list, $old_event=null)
2069
+	function find_or_add_categories($catname_list, $old_event = null)
2072 2070
 	{
2073 2071
 		if (is_array($old_event) || $old_event > 0)
2074 2072
 		{
2075 2073
 			// preserve categories without users read access
2076 2074
 			if (!is_array($old_event)) $old_event = $this->read($old_event);
2077
-			$old_categories = explode(',',$old_event['category']);
2075
+			$old_categories = explode(',', $old_event['category']);
2078 2076
 			$old_cats_preserve = array();
2079 2077
 			if (is_array($old_categories) && count($old_categories) > 0)
2080 2078
 			{
@@ -2128,7 +2126,7 @@  discard block
 block discarded – undo
2128 2126
 	{
2129 2127
 		if (!is_array($cat_id_list))
2130 2128
 		{
2131
-			$cat_id_list = explode(',',$cat_id_list);
2129
+			$cat_id_list = explode(',', $cat_id_list);
2132 2130
 		}
2133 2131
 		$cat_list = array();
2134 2132
 		foreach ($cat_id_list as $cat_id)
@@ -2153,7 +2151,7 @@  discard block
 block discarded – undo
2153 2151
 	 *                              master	-> try to find a releated series master
2154 2152
 	 * @return array calendar_ids of matching entries
2155 2153
 	 */
2156
-	function find_event($event, $filter='exact')
2154
+	function find_event($event, $filter = 'exact')
2157 2155
 	{
2158 2156
 		$matchingEvents = array();
2159 2157
 		$query = array();
@@ -2161,14 +2159,14 @@  discard block
 block discarded – undo
2161 2159
 		if ($this->log)
2162 2160
 		{
2163 2161
 			error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2164
-				"($filter)[EVENT]:" . array2string($event)."\n",3,$this->logfile);
2162
+				"($filter)[EVENT]:".array2string($event)."\n", 3, $this->logfile);
2165 2163
 		}
2166 2164
 
2167 2165
 		if (!isset($event['recurrence'])) $event['recurrence'] = 0;
2168 2166
 
2169 2167
 		if ($filter == 'master')
2170 2168
 		{
2171
-			$query[] = 'recur_type!='. MCAL_RECUR_NONE;
2169
+			$query[] = 'recur_type!='.MCAL_RECUR_NONE;
2172 2170
 			$query['cal_recurrence'] = 0;
2173 2171
 		}
2174 2172
 		elseif ($filter == 'exact')
@@ -2189,14 +2187,14 @@  discard block
 block discarded – undo
2189 2187
 			if ($this->log)
2190 2188
 			{
2191 2189
 				error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2192
-					'(' . $event['id'] . ")[EventID]\n",3,$this->logfile);
2190
+					'('.$event['id'].")[EventID]\n", 3, $this->logfile);
2193 2191
 			}
2194 2192
 			if (($egwEvent = $this->read($event['id'], 0, false, 'server')))
2195 2193
 			{
2196 2194
 				if ($this->log)
2197 2195
 				{
2198 2196
 					error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2199
-						'()[FOUND]:' . array2string($egwEvent)."\n",3,$this->logfile);
2197
+						'()[FOUND]:'.array2string($egwEvent)."\n", 3, $this->logfile);
2200 2198
 				}
2201 2199
 				if ($egwEvent['recur_type'] != MCAL_RECUR_NONE &&
2202 2200
 					(empty($event['uid']) || $event['uid'] == $egwEvent['uid']))
@@ -2215,7 +2213,7 @@  discard block
 block discarded – undo
2215 2213
 						$exceptions = $this->so->get_recurrence_exceptions($egwEvent, $event['tzid']);
2216 2214
 						if (in_array($event['recurrence'], $exceptions))
2217 2215
 						{
2218
-							$matchingEvents[] = $egwEvent['id'] . ':' . (int)$event['recurrence'];
2216
+							$matchingEvents[] = $egwEvent['id'].':'.(int)$event['recurrence'];
2219 2217
 						}
2220 2218
 					}
2221 2219
 				} elseif ($filter != 'master' && ($filter == 'exact' ||
@@ -2234,19 +2232,19 @@  discard block
 block discarded – undo
2234 2232
 
2235 2233
 		// only query calendars of users, we have READ-grants from
2236 2234
 		$users = array();
2237
-		foreach(array_keys($this->grants) as $user)
2235
+		foreach (array_keys($this->grants) as $user)
2238 2236
 		{
2239 2237
 			$user = trim($user);
2240
-			if ($this->check_perms(Acl::READ|self::ACL_READ_FOR_PARTICIPANTS|self::ACL_FREEBUSY,0,$user))
2238
+			if ($this->check_perms(Acl::READ|self::ACL_READ_FOR_PARTICIPANTS|self::ACL_FREEBUSY, 0, $user))
2241 2239
 			{
2242
-				if ($user && !in_array($user,$users))	// already added?
2240
+				if ($user && !in_array($user, $users))	// already added?
2243 2241
 				{
2244 2242
 					$users[] = $user;
2245 2243
 				}
2246 2244
 			}
2247 2245
 			elseif ($GLOBALS['egw']->accounts->get_type($user) != 'g')
2248 2246
 			{
2249
-				continue;	// for non-groups (eg. users), we stop here if we have no read-rights
2247
+				continue; // for non-groups (eg. users), we stop here if we have no read-rights
2250 2248
 			}
2251 2249
 			// the further code is only for real users
2252 2250
 			if (!is_numeric($user)) continue;
@@ -2257,7 +2255,7 @@  discard block
 block discarded – undo
2257 2255
 				$members = $GLOBALS['egw']->accounts->members($user, true);
2258 2256
 				if (is_array($members))
2259 2257
 				{
2260
-					foreach($members as $member)
2258
+					foreach ($members as $member)
2261 2259
 					{
2262 2260
 						// use only members which gave the user a read-grant
2263 2261
 						if (!in_array($member, $users) &&
@@ -2273,7 +2271,7 @@  discard block
 block discarded – undo
2273 2271
 				$memberships = $GLOBALS['egw']->accounts->memberships($user, true);
2274 2272
 				if (is_array($memberships))
2275 2273
 				{
2276
-					foreach($memberships as $group)
2274
+					foreach ($memberships as $group)
2277 2275
 					{
2278 2276
 						if (!in_array($group, $users))
2279 2277
 						{
@@ -2299,24 +2297,24 @@  discard block
 block discarded – undo
2299 2297
 
2300 2298
 				// check length with some tolerance
2301 2299
 				$length = $event['end'] - $event['start'] - $delta;
2302
-				$query[] = ('(cal_end-cal_start)>' . $length);
2300
+				$query[] = ('(cal_end-cal_start)>'.$length);
2303 2301
 				$length += 2 * $delta;
2304
-				$query[] = ('(cal_end-cal_start)<' . $length);
2305
-				$query[] = ('cal_start>' . ($event['start'] - 86400));
2306
-				$query[] = ('cal_start<' . ($event['start'] + 86400));
2302
+				$query[] = ('(cal_end-cal_start)<'.$length);
2303
+				$query[] = ('cal_start>'.($event['start'] - 86400));
2304
+				$query[] = ('cal_start<'.($event['start'] + 86400));
2307 2305
 			}
2308 2306
 			elseif (isset($event['start']))
2309 2307
 			{
2310 2308
 				if ($filter == 'relax')
2311 2309
 				{
2312
-					$query[] = ('cal_start>' . ($event['start'] - 3600));
2313
-					$query[] = ('cal_start<' . ($event['start'] + 3600));
2310
+					$query[] = ('cal_start>'.($event['start'] - 3600));
2311
+					$query[] = ('cal_start<'.($event['start'] + 3600));
2314 2312
 				}
2315 2313
 				else
2316 2314
 				{
2317 2315
 					// we accept a tiny tolerance
2318
-					$query[] = ('cal_start>' . ($event['start'] - 2));
2319
-					$query[] = ('cal_start<' . ($event['start'] + 2));
2316
+					$query[] = ('cal_start>'.($event['start'] - 2));
2317
+					$query[] = ('cal_start<'.($event['start'] + 2));
2320 2318
 				}
2321 2319
 			}
2322 2320
 			if ($filter == 'relax')
@@ -2339,14 +2337,14 @@  discard block
 block discarded – undo
2339 2337
 			if ($this->log)
2340 2338
 			{
2341 2339
 				error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2342
-					'(' . $event['uid'] . ")[EventUID]\n",3,$this->logfile);
2340
+					'('.$event['uid'].")[EventUID]\n", 3, $this->logfile);
2343 2341
 			}
2344 2342
 		}
2345 2343
 
2346 2344
 		if ($this->log)
2347 2345
 		{
2348 2346
 			error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2349
-				'[QUERY]: ' . array2string($query)."\n",3,$this->logfile);
2347
+				'[QUERY]: '.array2string($query)."\n", 3, $this->logfile);
2350 2348
 		}
2351 2349
 		if (!count($users) || !($foundEvents =
2352 2350
 			$this->so->search(null, null, $users, 0, 'owner', false, 0, array('query' => $query))))
@@ -2354,19 +2352,19 @@  discard block
 block discarded – undo
2354 2352
 			if ($this->log)
2355 2353
 			{
2356 2354
 				error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2357
-				"[NO MATCH]\n",3,$this->logfile);
2355
+				"[NO MATCH]\n", 3, $this->logfile);
2358 2356
 			}
2359 2357
 			return $matchingEvents;
2360 2358
 		}
2361 2359
 
2362 2360
 		$pseudos = array();
2363 2361
 
2364
-		foreach($foundEvents as $egwEvent)
2362
+		foreach ($foundEvents as $egwEvent)
2365 2363
 		{
2366 2364
 			if ($this->log)
2367 2365
 			{
2368 2366
 				error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2369
-					'[FOUND]: ' . array2string($egwEvent)."\n",3,$this->logfile);
2367
+					'[FOUND]: '.array2string($egwEvent)."\n", 3, $this->logfile);
2370 2368
 			}
2371 2369
 
2372 2370
 			if (in_array($egwEvent['id'], $matchingEvents)) continue;
@@ -2440,7 +2438,7 @@  discard block
 block discarded – undo
2440 2438
 						if (in_array($event['recurrence'], $exceptions))
2441 2439
 						{
2442 2440
 							// We found a pseudo exception
2443
-							$matchingEvents = array($egwEvent['id'] . ':' . (int)$event['recurrence']);
2441
+							$matchingEvents = array($egwEvent['id'].':'.(int)$event['recurrence']);
2444 2442
 							break;
2445 2443
 						}
2446 2444
 					}
@@ -2458,7 +2456,7 @@  discard block
 block discarded – undo
2458 2456
 						if ($this->log)
2459 2457
 						{
2460 2458
 							error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2461
-							"() egwEvent length does not match!\n",3,$this->logfile);
2459
+							"() egwEvent length does not match!\n", 3, $this->logfile);
2462 2460
 						}
2463 2461
 						continue;
2464 2462
 					}
@@ -2470,7 +2468,7 @@  discard block
 block discarded – undo
2470 2468
 						if ($this->log)
2471 2469
 						{
2472 2470
 							error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2473
-							"() egwEvent is not a whole-day event!\n",3,$this->logfile);
2471
+							"() egwEvent is not a whole-day event!\n", 3, $this->logfile);
2474 2472
 						}
2475 2473
 						continue;
2476 2474
 					}
@@ -2491,8 +2489,8 @@  discard block
 block discarded – undo
2491 2489
 					if ($this->log)
2492 2490
 					{
2493 2491
 						error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2494
-							"() event[$key] differ: '" . $event[$key] .
2495
-							"' <> '" . $egwEvent[$key] . "'\n",3,$this->logfile);
2492
+							"() event[$key] differ: '".$event[$key].
2493
+							"' <> '".$egwEvent[$key]."'\n", 3, $this->logfile);
2496 2494
 					}
2497 2495
 					continue 2; // next foundEvent
2498 2496
 				}
@@ -2510,7 +2508,7 @@  discard block
 block discarded – undo
2510 2508
 						if ($this->log)
2511 2509
 						{
2512 2510
 							error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2513
-							"() egwEvent category $cat_id is missing!\n",3,$this->logfile);
2511
+							"() egwEvent category $cat_id is missing!\n", 3, $this->logfile);
2514 2512
 						}
2515 2513
 						continue 2;
2516 2514
 					}
@@ -2522,7 +2520,7 @@  discard block
 block discarded – undo
2522 2520
 					{
2523 2521
 						error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2524 2522
 							'() event has additional categories:'
2525
-							. array2string($newCategories)."\n",3,$this->logfile);
2523
+							. array2string($newCategories)."\n", 3, $this->logfile);
2526 2524
 					}
2527 2525
 					continue;
2528 2526
 				}
@@ -2542,7 +2540,7 @@  discard block
 block discarded – undo
2542 2540
 							if ($this->log)
2543 2541
 							{
2544 2542
 								error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2545
-								"() additional event['participants']: $attendee\n",3,$this->logfile);
2543
+								"() additional event['participants']: $attendee\n", 3, $this->logfile);
2546 2544
 							}
2547 2545
 							continue 2;
2548 2546
 						}
@@ -2565,8 +2563,8 @@  discard block
 block discarded – undo
2565 2563
 						if ($this->log)
2566 2564
 						{
2567 2565
 							error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2568
-								'() missing event[participants]: ' .
2569
-								array2string($egwEvent['participants'])."\n",3,$this->logfile);
2566
+								'() missing event[participants]: '.
2567
+								array2string($egwEvent['participants'])."\n", 3, $this->logfile);
2570 2568
 						}
2571 2569
 						continue;
2572 2570
 					}
@@ -2578,7 +2576,7 @@  discard block
 block discarded – undo
2578 2576
 				if ($egwEvent['recur_type'] != MCAL_RECUR_NONE)
2579 2577
 				{
2580 2578
 					// We found a pseudo Exception
2581
-					$pseudos[] = $egwEvent['id'] . ':' . $event['start'];
2579
+					$pseudos[] = $egwEvent['id'].':'.$event['start'];
2582 2580
 					continue;
2583 2581
 				}
2584 2582
 			}
@@ -2600,7 +2598,7 @@  discard block
 block discarded – undo
2600 2598
 							if ($this->log)
2601 2599
 							{
2602 2600
 								error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2603
-								"() additional event['recur_exception']: $day\n",3,$this->logfile);
2601
+								"() additional event['recur_exception']: $day\n", 3, $this->logfile);
2604 2602
 							}
2605 2603
 							continue 2;
2606 2604
 						}
@@ -2610,8 +2608,8 @@  discard block
 block discarded – undo
2610 2608
 						if ($this->log)
2611 2609
 						{
2612 2610
 							error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2613
-								'() missing event[recur_exception]: ' .
2614
-								array2string($event['recur_exception'])."\n",3,$this->logfile);
2611
+								'() missing event[recur_exception]: '.
2612
+								array2string($event['recur_exception'])."\n", 3, $this->logfile);
2615 2613
 						}
2616 2614
 						continue;
2617 2615
 					}
@@ -2626,8 +2624,8 @@  discard block
 block discarded – undo
2626 2624
 						if ($this->log)
2627 2625
 						{
2628 2626
 							error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2629
-								"() events[$key] differ: " . $event[$key] .
2630
-								' <> ' . $egwEvent[$key]."\n",3,$this->logfile);
2627
+								"() events[$key] differ: ".$event[$key].
2628
+								' <> '.$egwEvent[$key]."\n", 3, $this->logfile);
2631 2629
 						}
2632 2630
 						continue 2;
2633 2631
 					}
@@ -2643,7 +2641,7 @@  discard block
 block discarded – undo
2643 2641
 			if ($this->log)
2644 2642
 			{
2645 2643
 				error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2646
-					"() new exception for series found.\n",3,$this->logfile);
2644
+					"() new exception for series found.\n", 3, $this->logfile);
2647 2645
 			}
2648 2646
 			$matchingEvents = array();
2649 2647
 		}
@@ -2654,7 +2652,7 @@  discard block
 block discarded – undo
2654 2652
 		if ($this->log)
2655 2653
 		{
2656 2654
 			error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2657
-				'[MATCHES]:' . array2string($matches)."\n",3,$this->logfile);
2655
+				'[MATCHES]:'.array2string($matches)."\n", 3, $this->logfile);
2658 2656
 		}
2659 2657
 		return $matches;
2660 2658
 	}
@@ -2727,7 +2725,7 @@  discard block
 block discarded – undo
2727 2725
 				if ($this->log)
2728 2726
 				{
2729 2727
 					error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2730
-					"()[MASTER]: $eventID\n",3,$this->logfile);
2728
+					"()[MASTER]: $eventID\n", 3, $this->logfile);
2731 2729
 				}
2732 2730
 				$type = 'SERIES-EXCEPTION';
2733 2731
 				if (($master_event = $this->read($eventID, 0, false, 'server')))
@@ -2748,7 +2746,7 @@  discard block
 block discarded – undo
2748 2746
 					}
2749 2747
 					elseif (in_array($event['start'], $master_event['recur_exception']))
2750 2748
 					{
2751
-						$type='SERIES-PSEUDO-EXCEPTION'; // new pseudo exception?
2749
+						$type = 'SERIES-PSEUDO-EXCEPTION'; // new pseudo exception?
2752 2750
 						$recurrence_event = $master_event;
2753 2751
 						$recurrence_event['start'] = $event['start'];
2754 2752
 						$recurrence_event['end'] -= $master_event['start'] - $event['start'];
@@ -2765,8 +2763,8 @@  discard block
 block discarded – undo
2765 2763
 							if ($this->log)
2766 2764
 							{
2767 2765
 								error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2768
-									'() try occurrence ' . $egw_rrule->current()
2769
-									. " ($occurrence)\n",3,$this->logfile);
2766
+									'() try occurrence '.$egw_rrule->current()
2767
+									. " ($occurrence)\n", 3, $this->logfile);
2770 2768
 							}
2771 2769
 							if ($event['start'] == $occurrence)
2772 2770
 							{
@@ -2799,8 +2797,8 @@  discard block
 block discarded – undo
2799 2797
 			// default if we cannot find a proof for a fundamental change
2800 2798
 			// the recurrence_event is the master event with start and end adjusted to the recurrence
2801 2799
 			// check for changed data
2802
-			foreach (array('start','end','uid','title','location','description',
2803
-				'priority','public','special','non_blocking') as $key)
2800
+			foreach (array('start', 'end', 'uid', 'title', 'location', 'description',
2801
+				'priority', 'public', 'special', 'non_blocking') as $key)
2804 2802
 			{
2805 2803
 				if (!empty($event[$key]) && $recurrence_event[$key] != $event[$key])
2806 2804
 				{
@@ -2858,10 +2856,10 @@  discard block
 block discarded – undo
2858 2856
      * @param &$event	the event we are working on
2859 2857
      *
2860 2858
      */
2861
-    function server2usertime (&$event)
2859
+    function server2usertime(&$event)
2862 2860
     {
2863 2861
 		// we run all dates through date2usertime, to adjust to user-time
2864
-		foreach(array('start','end','recur_enddate','recurrence') as $ts)
2862
+		foreach (array('start', 'end', 'recur_enddate', 'recurrence') as $ts)
2865 2863
 		{
2866 2864
 			// we convert here from server-time to timestamps in user-time!
2867 2865
 			if (isset($event[$ts])) $event[$ts] = $event[$ts] ? $this->date2usertime($event[$ts]) : 0;
@@ -2869,7 +2867,7 @@  discard block
 block discarded – undo
2869 2867
 		// same with the recur exceptions
2870 2868
 		if (isset($event['recur_exception']) && is_array($event['recur_exception']))
2871 2869
 		{
2872
-			foreach($event['recur_exception'] as $n => $date)
2870
+			foreach ($event['recur_exception'] as $n => $date)
2873 2871
 			{
2874 2872
 				$event['recur_exception'][$n] = $this->date2usertime($date);
2875 2873
 			}
@@ -2877,7 +2875,7 @@  discard block
 block discarded – undo
2877 2875
 		// same with the alarms
2878 2876
 		if (isset($event['alarm']) && is_array($event['alarm']))
2879 2877
 		{
2880
-			foreach($event['alarm'] as $id => $alarm)
2878
+			foreach ($event['alarm'] as $id => $alarm)
2881 2879
 			{
2882 2880
 				$event['alarm'][$id]['time'] = $this->date2usertime($alarm['time']);
2883 2881
 			}
@@ -2894,7 +2892,7 @@  discard block
 block discarded – undo
2894 2892
 	{
2895 2893
 		if (is_numeric($age) && $age > 0)	// just make sure bogus values dont delete everything
2896 2894
 		{
2897
-			$this->so->purge(time() - 365*24*3600*(float)$age);
2895
+			$this->so->purge(time() - 365 * 24 * 3600 * (float)$age);
2898 2896
 		}
2899 2897
 	}
2900 2898
 }
Please login to merge, or discard this patch.
Braces   +221 added lines, -57 removed lines patch added patch discarded remove patch
@@ -91,13 +91,19 @@  discard block
 block discarded – undo
91 91
 	 */
92 92
 	function __construct()
93 93
 	{
94
-		if ($this->debug > 0) $this->debug_message('calendar_boupdate::__construct() started',True);
94
+		if ($this->debug > 0)
95
+		{
96
+			$this->debug_message('calendar_boupdate::__construct() started',True);
97
+		}
95 98
 
96 99
 		parent::__construct();	// calling the parent constructor
97 100
 		
98 101
 		$this->resources_so = new resources_so();
99 102
 
100
-		if ($this->debug > 0) $this->debug_message('calendar_boupdate::__construct() finished',True);
103
+		if ($this->debug > 0)
104
+		{
105
+			$this->debug_message('calendar_boupdate::__construct() finished',True);
106
+		}
101 107
 	}
102 108
 
103 109
 	/**
@@ -128,7 +134,10 @@  discard block
 block discarded – undo
128 134
 	{
129 135
 		unset($updateTS);	// ignored, as updating timestamps is required for sync!
130 136
 		//error_log(__METHOD__."(".array2string($event).",$ignore_conflicts,$touch_modified,$ignore_acl)");
131
-		if (!is_array($messages)) $messages = $messages ? (array)$messages : array();
137
+		if (!is_array($messages))
138
+		{
139
+			$messages = $messages ? (array)$messages : array();
140
+		}
132 141
 
133 142
 		if ($this->debug > 1 || $this->debug == 'update')
134 143
 		{
@@ -148,10 +157,13 @@  discard block
 block discarded – undo
148 157
 
149 158
 		$status_reset_to_unknown = false;
150 159
 
151
-		if (($new_event = !$event['id']))	// some defaults for new entries
160
+		if (($new_event = !$event['id']))
161
+		{
162
+			// some defaults for new entries
152 163
 		{
153 164
 			// if no owner given, set user to owner
154 165
 			if (!$event['owner']) $event['owner'] = $this->user;
166
+		}
155 167
 			// set owner as participant if none is given
156 168
 			if (!is_array($event['participants']) || !count($event['participants']))
157 169
 			{
@@ -191,7 +203,10 @@  discard block
 block discarded – undo
191 203
 		// check category based ACL
192 204
 		if ($event['category'])
193 205
 		{
194
-			if (!is_array($event['category'])) $event['category'] = explode(',',$event['category']);
206
+			if (!is_array($event['category']))
207
+			{
208
+				$event['category'] = explode(',',$event['category']);
209
+			}
195 210
 			if (!$old_event || !isset($old_event['category']))
196 211
 			{
197 212
 				$old_event['category'] = array();
@@ -243,13 +258,16 @@  discard block
 block discarded – undo
243 258
 		if (!$ignore_conflicts && !$event['non_blocking'] && isset($event['start']) && isset($event['end']) &&
244 259
 			(($conflicts = $this->conflicts($event, $checked_excluding)) || $checked_excluding))
245 260
 		{
246
-			if ($checked_excluding)	// warn user if not all recurrences have been checked
261
+			if ($checked_excluding)
262
+			{
263
+				// warn user if not all recurrences have been checked
247 264
 			{
248 265
 				$conflicts['warning'] = array(
249 266
 					'start' => $checked_excluding,
250 267
 					'title' => lang('Only recurrences until %1 (excluding) have been checked!', $checked_excluding->format(true)),
251 268
 				);
252 269
 			}
270
+			}
253 271
 			return $conflicts;
254 272
 		}
255 273
 
@@ -313,7 +331,10 @@  discard block
 block discarded – undo
313 331
 		$types_with_quantity = array();
314 332
 		foreach($this->resources as $type => $data)
315 333
 		{
316
-			if ($data['max_quantity']) $types_with_quantity[] = $type;
334
+			if ($data['max_quantity'])
335
+			{
336
+				$types_with_quantity[] = $type;
337
+			}
317 338
 		}
318 339
 		// get all NOT rejected participants and evtl. their quantity
319 340
 		$quantity = $users = array();
@@ -321,12 +342,19 @@  discard block
 block discarded – undo
321 342
 		{
322 343
 			$q = $role = null;
323 344
 			calendar_so::split_status($status, $q, $role);
324
-			if ($status == 'R' || $role == 'NON-PARTICIPANT') continue;	// ignore rejected or non-participants
345
+			if ($status == 'R' || $role == 'NON-PARTICIPANT')
346
+			{
347
+				continue;
348
+			}
349
+			// ignore rejected or non-participants
325 350
 
326
-			if ($uid < 0)	// group, check it's members too
351
+			if ($uid < 0)
352
+			{
353
+				// group, check it's members too
327 354
 			{
328 355
 				$users = array_unique(array_merge($users, (array)$GLOBALS['egw']->accounts->members($uid,true)));
329 356
 			}
357
+			}
330 358
 			$users[] = $uid;
331 359
 			if (in_array($uid[0],$types_with_quantity))
332 360
 			{
@@ -357,18 +385,24 @@  discard block
 block discarded – undo
357 385
 			$startts = $date->format('ts');
358 386
 
359 387
 			// skip past events or recurrences
360
-			if ($startts+$duration < $this->now_su) continue;
388
+			if ($startts+$duration < $this->now_su)
389
+			{
390
+				continue;
391
+			}
361 392
 
362 393
 			// abort check if configured limits are exceeded
363 394
 			if ($event['recur_type'] &&
364 395
 				(++$checked > $max_checked && $max_checked > 0 || // maximum number of checked recurrences exceeded
365 396
 				microtime(true) > $start+$max_check_time ||	// max check time exceeded
366
-				$startts > $this->config['horizont']))	// we are behind horizon for which recurrences are rendered
397
+				$startts > $this->config['horizont']))
398
+			{
399
+				// we are behind horizon for which recurrences are rendered
367 400
 			{
368 401
 				if ($this->debug > 2 || $this->debug == 'conflicts')
369 402
 				{
370 403
 					$this->debug_message(__METHOD__.'() conflict check limited to %1 recurrences, %2 seconds, until (excluding) %3',
371 404
 						$checked, microtime(true)-$start, $date);
405
+			}
372 406
 				}
373 407
 				$checked_excluding = $date;
374 408
 				break;
@@ -392,10 +426,13 @@  discard block
 block discarded – undo
392 426
 			{
393 427
 				if ($overlap['id'] == $event['id'] ||	// that's the event itself
394 428
 					$overlap['id'] == $event['reference'] ||	// event is an exception of overlap
395
-					$overlap['non_blocking'])			// that's a non_blocking event
429
+					$overlap['non_blocking'])
430
+				{
431
+					// that's a non_blocking event
396 432
 				{
397 433
 					continue;
398 434
 				}
435
+				}
399 436
 				if ($this->debug > 3 || $this->debug == 'conflicts')
400 437
 				{
401 438
 					$this->debug_message(__METHOD__.'() checking overlapping event %1',false,$overlap);
@@ -518,7 +555,8 @@  discard block
 block discarded – undo
518 555
 		if (!is_numeric($uid))
519 556
 		{
520 557
 			$resources_config = Api\Config::read('resources');
521
-			if ($resources_config['bookingrequests'] === 'disabled') {
558
+			if ($resources_config['bookingrequests'] === 'disabled')
559
+			{
522 560
 				$cat_id = $this->resources_so->get_value('cat_id', intval(substr($uid, 1)));
523 561
 				return resources_acl_bo::is_permitted($cat_id, resources_acl_bo::DIRECT_BOOKING);
524 562
 			}
@@ -888,14 +926,20 @@  discard block
 block discarded – undo
888 926
 		$startdate = new Api\DateTime($event['start']);
889 927
 		$enddate = new Api\DateTime($event['end']);
890 928
 		$modified = new Api\DateTime($event['modified']);
891
-		if ($old_event) $olddate = new Api\DateTime($old_event['start']);
929
+		if ($old_event)
930
+		{
931
+			$olddate = new Api\DateTime($old_event['start']);
932
+		}
892 933
 		//error_log(__METHOD__."() date_default_timezone_get()=".date_default_timezone_get().", user-timezone=".Api\DateTime::$user_timezone->getName().", startdate=".$startdate->format().", enddate=".$enddate->format().", updated=".$modified->format().", olddate=".($olddate ? $olddate->format() : ''));
893 934
 		$owner_prefs = $ics = null;
894 935
 		foreach($to_notify as $userid => $statusid)
895 936
 		{
896 937
 			$res_info = $quantity = $role = null;
897 938
 			calendar_so::split_status($statusid, $quantity, $role);
898
-			if ($this->debug > 0) error_log(__METHOD__." trying to notify $userid, with $statusid ($role)");
939
+			if ($this->debug > 0)
940
+			{
941
+				error_log(__METHOD__." trying to notify $userid, with $statusid ($role)");
942
+			}
899 943
 
900 944
 			if (!is_numeric($userid))
901 945
 			{
@@ -914,7 +958,11 @@  discard block
 block discarded – undo
914 958
 
915 959
 				if (!isset($userid))
916 960
 				{
917
-					if (empty($res_info['email'])) continue;	// no way to notify
961
+					if (empty($res_info['email']))
962
+					{
963
+						continue;
964
+					}
965
+					// no way to notify
918 966
 					// check if event-owner wants non-EGroupware users notified
919 967
 					if (is_null($owner_prefs))
920 968
 					{
@@ -988,7 +1036,10 @@  discard block
 block discarded – undo
988 1036
 				$details['to-lastname'] = isset($tln)? $tln: '';
989 1037
 
990 1038
 				// event is in user-time of current user, now we need to calculate the tz-difference to the notified user and take it into account
991
-				if (!isset($part_prefs['common']['tz'])) $part_prefs['common']['tz'] = $GLOBALS['egw_info']['server']['server_timezone'];
1039
+				if (!isset($part_prefs['common']['tz']))
1040
+				{
1041
+					$part_prefs['common']['tz'] = $GLOBALS['egw_info']['server']['server_timezone'];
1042
+				}
992 1043
 				$timezone = new DateTimeZone($part_prefs['common']['tz']);
993 1044
 				$timeformat = $part_prefs['common']['timeformat'];
994 1045
 				switch($timeformat)
@@ -1023,9 +1074,12 @@  discard block
 block discarded – undo
1023 1074
 				switch($msg_type == MSG_ALARM ? 'extended' : $part_prefs['calendar']['update_format'])
1024 1075
 				{
1025 1076
 					case 'ical':
1026
-						if (is_null($ics) || $m_type != $msg_type)	// need different ical for organizer notification
1077
+						if (is_null($ics) || $m_type != $msg_type)
1078
+						{
1079
+							// need different ical for organizer notification
1027 1080
 						{
1028 1081
 							$calendar_ical = new calendar_ical();
1082
+						}
1029 1083
 							$calendar_ical->setSupportedFields('full');	// full iCal fields+event TZ
1030 1084
 							// we need to pass $event[id] so iCal class reads event again,
1031 1085
 							// as event is in user TZ, but iCal class expects server TZ!
@@ -1041,7 +1095,10 @@  discard block
 block discarded – undo
1041 1095
 							'encoding' => '8bit',
1042 1096
 							'type' => 'text/calendar; method='.$method,
1043 1097
 						);
1044
-						if ($m_type != $msg_type) unset($ics);
1098
+						if ($m_type != $msg_type)
1099
+						{
1100
+							unset($ics);
1101
+						}
1045 1102
 						$subject = isset($cleared_event) ? $cleared_event['title'] : $event['title'];
1046 1103
 						// fall through
1047 1104
 					case 'extended':
@@ -1098,11 +1155,16 @@  discard block
 block discarded – undo
1098 1155
 								'user_id' => $userid
1099 1156
 							));
1100 1157
 						}
1101
-						if ($m_type === MSG_ALARM) $notification->set_popupdata('calendar', array('egw_pr_notify' => 1));
1158
+						if ($m_type === MSG_ALARM)
1159
+						{
1160
+							$notification->set_popupdata('calendar', array('egw_pr_notify' => 1));
1161
+						}
1102 1162
 						$notification->set_popupmessage($subject."\n\n".$notify_body."\n\n".$details['description']."\n\n".$details_body."\n\n");
1103 1163
 						$notification->set_popuplinks(array($details['link_arr']+array('app'=>'calendar')));
1104 1164
 
1105
-						if(is_array($attachment)) { $notification->set_attachments(array($attachment)); }
1165
+						if(is_array($attachment))
1166
+						{
1167
+$notification->set_attachments(array($attachment)); }
1106 1168
 						$notification->send();
1107 1169
 						foreach(notifications::errors(true) as $error)
1108 1170
 						{
@@ -1138,7 +1200,10 @@  discard block
 block discarded – undo
1138 1200
 			Api\Translation::init();
1139 1201
 		}
1140 1202
 		// restore timezone, in case we had to reset it to server-timezone
1141
-		if ($restore_tz) date_default_timezone_set($restore_tz);
1203
+		if ($restore_tz)
1204
+		{
1205
+			date_default_timezone_set($restore_tz);
1206
+		}
1142 1207
 
1143 1208
 		return true;
1144 1209
 	}
@@ -1173,10 +1238,13 @@  discard block
 block discarded – undo
1173 1238
 		{
1174 1239
 			$to_notify = $event['participants'];
1175 1240
 		}
1176
-		elseif ($this->check_perms(Acl::READ,$event))	// checks agains $this->owner set to $alarm[owner]
1241
+		elseif ($this->check_perms(Acl::READ,$event))
1242
+		{
1243
+			// checks agains $this->owner set to $alarm[owner]
1177 1244
 		{
1178 1245
 			$to_notify[$alarm['owner']] = 'A';
1179 1246
 		}
1247
+		}
1180 1248
 		else
1181 1249
 		{
1182 1250
 			return False;	// no rights
@@ -1225,14 +1293,20 @@  discard block
 block discarded – undo
1225 1293
 		if ($event['id'])
1226 1294
 		{
1227 1295
 			// invalidate the read-cache if it contains the event we store now
1228
-			if ($event['id'] == self::$cached_event['id']) self::$cached_event = array();
1296
+			if ($event['id'] == self::$cached_event['id'])
1297
+			{
1298
+				self::$cached_event = array();
1299
+			}
1229 1300
 			$old_event = $this->read($event['id'], $event['recurrence'], false, 'server');
1230 1301
 		}
1231 1302
 		else
1232 1303
 		{
1233 1304
 			$old_event = null;
1234 1305
 		}
1235
-		if (!isset($event['whole_day'])) $event['whole_day'] = $this->isWholeDay($event);
1306
+		if (!isset($event['whole_day']))
1307
+		{
1308
+			$event['whole_day'] = $this->isWholeDay($event);
1309
+		}
1236 1310
 
1237 1311
 		// set recur-enddate/range-end to real end-date of last recurrence
1238 1312
 		if ($event['recur_type'] != MCAL_RECUR_NONE && $event['recur_enddate'] && $event['start'])
@@ -1309,7 +1383,10 @@  discard block
 block discarded – undo
1309 1383
 		foreach($timestamps as $ts)
1310 1384
 		{
1311 1385
 			// we convert here from user-time to timestamps in server-time!
1312
-			if (isset($event[$ts])) $event[$ts] = $event[$ts] ? $this->date2ts($event[$ts],true) : 0;
1386
+			if (isset($event[$ts]))
1387
+			{
1388
+				$event[$ts] = $event[$ts] ? $this->date2ts($event[$ts],true) : 0;
1389
+			}
1313 1390
 		}
1314 1391
 		// convert tzid name to integer tz_id, of set user default
1315 1392
 		if (empty($event['tzid']) || !($event['tz_id'] = calendar_timezones::tz2id($event['tzid'])))
@@ -1360,7 +1437,10 @@  discard block
 block discarded – undo
1360 1437
 				if (!isset($event['alarm'][$id]))
1361 1438
 				{
1362 1439
 					$alarm['time'] = $event['start'] - $alarm['offset'];
1363
-					if ($alarm['time'] < time()) calendar_so::shift_alarm($event, $alarm);
1440
+					if ($alarm['time'] < time())
1441
+					{
1442
+						calendar_so::shift_alarm($event, $alarm);
1443
+					}
1364 1444
 						// remove (not store) alarms belonging to not longer existing or rejected participants
1365 1445
 					$status = isset($event['participants']) ? $event['participants'][$alarm['owner']] :
1366 1446
 						$old_event['participants'][$alarm['owner']];
@@ -1416,7 +1496,10 @@  discard block
 block discarded – undo
1416 1496
 
1417 1497
 		// Update history
1418 1498
 		$tracking = new calendar_tracking($this);
1419
-		if (empty($event['id']) && !empty($cal_id)) $event['id']=$cal_id;
1499
+		if (empty($event['id']) && !empty($cal_id))
1500
+		{
1501
+			$event['id']=$cal_id;
1502
+		}
1420 1503
 		$tracking->track($event, $old_event);
1421 1504
 
1422 1505
 		return $cal_id;
@@ -1433,9 +1516,12 @@  discard block
 block discarded – undo
1433 1516
 	 */
1434 1517
 	function check_status_perms($uid,$event)
1435 1518
 	{
1436
-		if ($uid[0] == 'c' || $uid[0] == 'e')	// for contact we use the owner of the event
1519
+		if ($uid[0] == 'c' || $uid[0] == 'e')
1520
+		{
1521
+			// for contact we use the owner of the event
1437 1522
 		{
1438 1523
 			if (!is_array($event) && !($event = $this->read($event))) return false;
1524
+		}
1439 1525
 
1440 1526
 			return $this->check_perms(Acl::EDIT,0,$event['owner']);
1441 1527
 		}
@@ -1446,13 +1532,19 @@  discard block
 block discarded – undo
1446 1532
 			return $access;
1447 1533
 		}
1448 1534
 		// no access or denied access because of category acl --> regular check
1449
-		if (!is_numeric($uid))	// this is eg. for resources (r123)
1535
+		if (!is_numeric($uid))
1536
+		{
1537
+			// this is eg. for resources (r123)
1450 1538
 		{
1451 1539
 			$resource = $this->resource_info($uid);
1540
+		}
1452 1541
 
1453 1542
 			return Acl::EDIT & $resource['rights'];
1454 1543
 		}
1455
-		if (!is_array($event) && !($event = $this->read($event))) return false;
1544
+		if (!is_array($event) && !($event = $this->read($event)))
1545
+		{
1546
+			return false;
1547
+		}
1456 1548
 
1457 1549
 		// regular user and groups (need to check memberships too)
1458 1550
 		if (!isset($event['participants'][$uid]))
@@ -1476,7 +1568,10 @@  discard block
 block discarded – undo
1476 1568
 	 */
1477 1569
 	function check_cat_acl($right,$event)
1478 1570
 	{
1479
-		if (!is_array($event)) $event = $this->read($event);
1571
+		if (!is_array($event))
1572
+		{
1573
+			$event = $this->read($event);
1574
+		}
1480 1575
 
1481 1576
 		$ret = null;
1482 1577
 		if ($event['category'])
@@ -1533,7 +1628,10 @@  discard block
 block discarded – undo
1533 1628
 	public static function set_cat_rights($cat_id,$user,$rights)
1534 1629
 	{
1535 1630
 		//echo "<p>".__METHOD__."($cat_id,$user,$rights)</p>\n";
1536
-		if (!isset(self::$cat_rights_cache)) self::get_cat_rights($cat_id);
1631
+		if (!isset(self::$cat_rights_cache))
1632
+		{
1633
+			self::get_cat_rights($cat_id);
1634
+		}
1537 1635
 
1538 1636
 		if ((int)$rights != (int)self::$cat_rights_cache['L'.$cat_id][$user])
1539 1637
 		{
@@ -1545,7 +1643,10 @@  discard block
 block discarded – undo
1545 1643
 			else
1546 1644
 			{
1547 1645
 				unset(self::$cat_rights_cache['L'.$cat_id][$user]);
1548
-				if (!self::$cat_rights_cache['L'.$cat_id]) unset(self::$cat_rights_cache['L'.$cat_id]);
1646
+				if (!self::$cat_rights_cache['L'.$cat_id])
1647
+				{
1648
+					unset(self::$cat_rights_cache['L'.$cat_id]);
1649
+				}
1549 1650
 				$GLOBALS['egw']->acl->delete_repository('calendar','L'.$cat_id,$user);
1550 1651
 			}
1551 1652
 			Api\Cache::setSession('calendar','cat_rights',self::$cat_rights_cache);
@@ -1578,7 +1679,10 @@  discard block
 block discarded – undo
1578 1679
 				foreach($cat_rights as $uid => $value)
1579 1680
 				{
1580 1681
 					$all |= $value;
1581
-					if (in_array($uid,$memberships)) $own |= $value;
1682
+					if (in_array($uid,$memberships))
1683
+					{
1684
+						$own |= $value;
1685
+					}
1582 1686
 				}
1583 1687
 			}
1584 1688
 			foreach(array(self::CAT_ACL_ADD,self::CAT_ACL_STATUS) as $mask)
@@ -1625,13 +1729,16 @@  discard block
 block discarded – undo
1625 1729
 				is_numeric($uid)?$uid:substr($uid,1),$status,
1626 1730
 				$recur_date?$this->date2ts($recur_date,true):0,$role)))
1627 1731
 		{
1628
-			if ($status == 'R')	// remove alarms belonging to rejected participants
1732
+			if ($status == 'R')
1733
+			{
1734
+				// remove alarms belonging to rejected participants
1629 1735
 			{
1630 1736
 				foreach(is_array($event) && isset($event['alarm']) ? $event['alarm'] : $old_event['alarm'] as $id => $alarm)
1631 1737
 				{
1632 1738
 					if ((string)$alarm['owner'] === (string)$uid)
1633 1739
 					{
1634 1740
 						$this->so->delete_alarm($id);
1741
+			}
1635 1742
 						//error_log(__LINE__.': '.__METHOD__."(".array2string($event).", '$uid', '$status', ...) deleting alarm=".array2string($alarm).", $status=".array2string($alarm));
1636 1743
 					}
1637 1744
 				}
@@ -1648,8 +1755,15 @@  discard block
 block discarded – undo
1648 1755
 
1649 1756
 			if (isset($status2msg[$status]) && !$skip_notification)
1650 1757
 			{
1651
-				if (!is_array($event)) $event = $this->read($cal_id);
1652
-				if (isset($recur_date)) $event = $this->read($event['id'],$recur_date); //re-read the actually edited recurring event
1758
+				if (!is_array($event))
1759
+				{
1760
+					$event = $this->read($cal_id);
1761
+				}
1762
+				if (isset($recur_date))
1763
+				{
1764
+					$event = $this->read($event['id'],$recur_date);
1765
+				}
1766
+				//re-read the actually edited recurring event
1653 1767
 				$this->send_update($status2msg[$status],$event['participants'],$event);
1654 1768
 			}
1655 1769
 
@@ -1672,12 +1786,16 @@  discard block
 block discarded – undo
1672 1786
 	 */
1673 1787
 	function update_status($new_event, $old_event , $recur_date=0, $skip_notification=false)
1674 1788
 	{
1675
-		if (!isset($new_event['participants'])) return;
1789
+		if (!isset($new_event['participants']))
1790
+		{
1791
+			return;
1792
+		}
1676 1793
 
1677 1794
 		// check the old list against the new list
1678 1795
 		foreach ($old_event['participants'] as $userid => $status)
1679
-  		{
1680
-            if (!isset($new_event['participants'][$userid])){
1796
+		{
1797
+            if (!isset($new_event['participants'][$userid]))
1798
+            {
1681 1799
             	// Attendee will be deleted this way
1682 1800
             	$new_event['participants'][$userid] = 'G';
1683 1801
             }
@@ -1760,7 +1878,10 @@  discard block
 block discarded – undo
1760 1878
 					}
1761 1879
 					else
1762 1880
 					{
1763
-						if (!($exception = $this->read($id))) continue;
1881
+						if (!($exception = $this->read($id)))
1882
+						{
1883
+							continue;
1884
+						}
1764 1885
 						$exception['uid'] = Api\CalDAV::generate_uid('calendar', $id);
1765 1886
 						$exception['reference'] = $exception['recurrence'] = 0;
1766 1887
 						$this->update($exception, true, true, false, true, $msg=null, true);
@@ -1831,7 +1952,10 @@  discard block
 block discarded – undo
1831 1952
 		$event_arr = $this->event2array($event);
1832 1953
 		foreach($event_arr as $key => $val)
1833 1954
 		{
1834
-			if ($key == 'recur_type') $key = 'repetition';
1955
+			if ($key == 'recur_type')
1956
+			{
1957
+				$key = 'repetition';
1958
+			}
1835 1959
 			$details[$key] = $val['data'];
1836 1960
 		}
1837 1961
 		$details['participants'] = $details['participants'] ? implode("\n",$details['participants']) : '';
@@ -1840,7 +1964,10 @@  discard block
 block discarded – undo
1840 1964
 		$eventStart_arr = $this->date2array($event['start']); // give this as 'date' to the link to pick the right recurrence for the participants state
1841 1965
 		$link = $GLOBALS['egw_info']['server']['webserver_url'].'/index.php?menuaction=calendar.calendar_uiforms.edit&cal_id='.$event['id'].'&date='.$eventStart_arr['full'].'&no_popup=1&ajax=true';
1842 1966
 		// if url is only a path, try guessing the rest ;-)
1843
-		if ($link[0] == '/') $link = Api\Framework::getUrl($link);
1967
+		if ($link[0] == '/')
1968
+		{
1969
+			$link = Api\Framework::getUrl($link);
1970
+		}
1844 1971
 		$event_arr['link']['data'] = $details['link'] = $link;
1845 1972
 
1846 1973
 		/* this is needed for notification-app
@@ -1999,7 +2126,10 @@  discard block
 block discarded – undo
1999 2126
 	 */
2000 2127
 	function check_move_alarms(Array &$event, Array $old_event = null, Api\DateTime $instance_date = null)
2001 2128
 	{
2002
-		if ($old_event !== null && $event['start'] == $old_event['start']) return;
2129
+		if ($old_event !== null && $event['start'] == $old_event['start'])
2130
+		{
2131
+			return;
2132
+		}
2003 2133
 
2004 2134
 		$time = new Api\DateTime($event['start']);
2005 2135
 		if(!is_array($event['alarm']))
@@ -2073,7 +2203,10 @@  discard block
 block discarded – undo
2073 2203
 		if (is_array($old_event) || $old_event > 0)
2074 2204
 		{
2075 2205
 			// preserve categories without users read access
2076
-			if (!is_array($old_event)) $old_event = $this->read($old_event);
2206
+			if (!is_array($old_event))
2207
+			{
2208
+				$old_event = $this->read($old_event);
2209
+			}
2077 2210
 			$old_categories = explode(',',$old_event['category']);
2078 2211
 			$old_cats_preserve = array();
2079 2212
 			if (is_array($old_categories) && count($old_categories) > 0)
@@ -2164,7 +2297,10 @@  discard block
 block discarded – undo
2164 2297
 				"($filter)[EVENT]:" . array2string($event)."\n",3,$this->logfile);
2165 2298
 		}
2166 2299
 
2167
-		if (!isset($event['recurrence'])) $event['recurrence'] = 0;
2300
+		if (!isset($event['recurrence']))
2301
+		{
2302
+			$event['recurrence'] = 0;
2303
+		}
2168 2304
 
2169 2305
 		if ($filter == 'master')
2170 2306
 		{
@@ -2218,19 +2354,26 @@  discard block
 block discarded – undo
2218 2354
 							$matchingEvents[] = $egwEvent['id'] . ':' . (int)$event['recurrence'];
2219 2355
 						}
2220 2356
 					}
2221
-				} elseif ($filter != 'master' && ($filter == 'exact' ||
2357
+				}
2358
+				elseif ($filter != 'master' && ($filter == 'exact' ||
2222 2359
 							$event['recur_type'] == $egwEvent['recur_type'] &&
2223 2360
 							strpos($egwEvent['title'], $event['title']) === 0))
2224 2361
 				{
2225 2362
 					$matchingEvents[] = $egwEvent['id']; // we found the event
2226 2363
 				}
2227 2364
 			}
2228
-			if (!empty($matchingEvents) || $filter == 'exact') return $matchingEvents;
2365
+			if (!empty($matchingEvents) || $filter == 'exact')
2366
+			{
2367
+				return $matchingEvents;
2368
+			}
2229 2369
 		}
2230 2370
 		unset($event['id']);
2231 2371
 
2232 2372
 		// No chance to find a master without [U]ID
2233
-		if ($filter == 'master' && empty($event['uid'])) return $matchingEvents;
2373
+		if ($filter == 'master' && empty($event['uid']))
2374
+		{
2375
+			return $matchingEvents;
2376
+		}
2234 2377
 
2235 2378
 		// only query calendars of users, we have READ-grants from
2236 2379
 		$users = array();
@@ -2239,17 +2382,23 @@  discard block
 block discarded – undo
2239 2382
 			$user = trim($user);
2240 2383
 			if ($this->check_perms(Acl::READ|self::ACL_READ_FOR_PARTICIPANTS|self::ACL_FREEBUSY,0,$user))
2241 2384
 			{
2242
-				if ($user && !in_array($user,$users))	// already added?
2385
+				if ($user && !in_array($user,$users))
2386
+				{
2387
+					// already added?
2243 2388
 				{
2244 2389
 					$users[] = $user;
2245 2390
 				}
2391
+				}
2246 2392
 			}
2247 2393
 			elseif ($GLOBALS['egw']->accounts->get_type($user) != 'g')
2248 2394
 			{
2249 2395
 				continue;	// for non-groups (eg. users), we stop here if we have no read-rights
2250 2396
 			}
2251 2397
 			// the further code is only for real users
2252
-			if (!is_numeric($user)) continue;
2398
+			if (!is_numeric($user))
2399
+			{
2400
+				continue;
2401
+			}
2253 2402
 
2254 2403
 			// for groups we have to include the members
2255 2404
 			if ($GLOBALS['egw']->accounts->get_type($user) == 'g')
@@ -2329,7 +2478,10 @@  discard block
 block discarded – undo
2329 2478
 			}
2330 2479
 			foreach ($matchFields as $key)
2331 2480
 			{
2332
-				if (isset($event[$key])) $query['cal_'.$key] = $event[$key];
2481
+				if (isset($event[$key]))
2482
+				{
2483
+					$query['cal_'.$key] = $event[$key];
2484
+				}
2333 2485
 			}
2334 2486
 		}
2335 2487
 
@@ -2369,7 +2521,10 @@  discard block
 block discarded – undo
2369 2521
 					'[FOUND]: ' . array2string($egwEvent)."\n",3,$this->logfile);
2370 2522
 			}
2371 2523
 
2372
-			if (in_array($egwEvent['id'], $matchingEvents)) continue;
2524
+			if (in_array($egwEvent['id'], $matchingEvents))
2525
+			{
2526
+				continue;
2527
+			}
2373 2528
 
2374 2529
 			// convert timezone id of event to tzid (iCal id like 'Europe/Berlin')
2375 2530
 			if (!$egwEvent['tz_id'] || !($egwEvent['tzid'] = calendar_timezones::id2tz($egwEvent['tz_id'])))
@@ -2536,13 +2691,16 @@  discard block
 block discarded – undo
2536 2691
 					foreach ($event['participants'] as $attendee => $status)
2537 2692
 					{
2538 2693
 						if (!isset($egwEvent['participants'][$attendee]) &&
2539
-								$attendee != $egwEvent['owner']) // ||
2694
+								$attendee != $egwEvent['owner'])
2695
+						{
2696
+							// ||
2540 2697
 							//(!$relax && $egw_event['participants'][$attendee] != $status))
2541 2698
 						{
2542 2699
 							if ($this->log)
2543 2700
 							{
2544 2701
 								error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2545 2702
 								"() additional event['participants']: $attendee\n",3,$this->logfile);
2703
+						}
2546 2704
 							}
2547 2705
 							continue 2;
2548 2706
 						}
@@ -2864,7 +3022,10 @@  discard block
 block discarded – undo
2864 3022
 		foreach(array('start','end','recur_enddate','recurrence') as $ts)
2865 3023
 		{
2866 3024
 			// we convert here from server-time to timestamps in user-time!
2867
-			if (isset($event[$ts])) $event[$ts] = $event[$ts] ? $this->date2usertime($event[$ts]) : 0;
3025
+			if (isset($event[$ts]))
3026
+			{
3027
+				$event[$ts] = $event[$ts] ? $this->date2usertime($event[$ts]) : 0;
3028
+			}
2868 3029
 		}
2869 3030
 		// same with the recur exceptions
2870 3031
 		if (isset($event['recur_exception']) && is_array($event['recur_exception']))
@@ -2892,9 +3053,12 @@  discard block
 block discarded – undo
2892 3053
 	 */
2893 3054
 	function purge($age)
2894 3055
 	{
2895
-		if (is_numeric($age) && $age > 0)	// just make sure bogus values dont delete everything
3056
+		if (is_numeric($age) && $age > 0)
3057
+		{
3058
+			// just make sure bogus values dont delete everything
2896 3059
 		{
2897 3060
 			$this->so->purge(time() - 365*24*3600*(float)$age);
2898 3061
 		}
3062
+		}
2899 3063
 	}
2900 3064
 }
Please login to merge, or discard this patch.