Completed
Push — master ( cd694a...673bd3 )
by Nathan
15:56
created
api/src/Contacts.php 1 patch
Spacing   +290 added lines, -292 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
 
17 17
 namespace EGroupware\Api;
18 18
 
19
-use calendar_bo;	// to_do: do NOT require it, just use if there
19
+use calendar_bo; // to_do: do NOT require it, just use if there
20 20
 
21 21
 /**
22 22
  * Business object for contacts
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 	/**
39 39
 	 * @var array $timestamps timestamps
40 40
 	 */
41
-	var $timestamps = array('modified','created');
41
+	var $timestamps = array('modified', 'created');
42 42
 
43 43
 	/**
44 44
 	 * @var array $fileas_types
@@ -173,32 +173,32 @@  discard block
 block discarded – undo
173 173
 	 * @param string $contact_app ='addressbook' used for acl->get_grants()
174 174
 	 * @param Db $db =null
175 175
 	 */
176
-	function __construct($contact_app='addressbook',Db $db=null)
176
+	function __construct($contact_app = 'addressbook', Db $db = null)
177 177
 	{
178
-		parent::__construct($contact_app,$db);
178
+		parent::__construct($contact_app, $db);
179 179
 		if ($this->log)
180 180
 		{
181 181
 			$this->logfile = $GLOBALS['egw_info']['server']['temp_dir'].'/log-addressbook_bo';
182
-			error_log(__FILE__.'['.__LINE__.'] '.__METHOD__."($contact_app)\n", 3 ,$this->logfile);
182
+			error_log(__FILE__.'['.__LINE__.'] '.__METHOD__."($contact_app)\n", 3, $this->logfile);
183 183
 		}
184 184
 
185
-		$this->now_su = DateTime::to('now','ts');
185
+		$this->now_su = DateTime::to('now', 'ts');
186 186
 
187
-		$this->prefs =& $GLOBALS['egw_info']['user']['preferences']['addressbook'];
188
-		if(!isset($this->prefs['hide_accounts']))
187
+		$this->prefs = & $GLOBALS['egw_info']['user']['preferences']['addressbook'];
188
+		if (!isset($this->prefs['hide_accounts']))
189 189
 		{
190 190
 			$this->prefs['hide_accounts'] = '0';
191 191
 		}
192 192
 		// get the default addressbook from the users prefs
193 193
 		$this->default_addressbook = $GLOBALS['egw_info']['user']['preferences']['addressbook']['add_default'] ?
194 194
 			(int)$GLOBALS['egw_info']['user']['preferences']['addressbook']['add_default'] : $this->user;
195
-		$this->default_private = substr($GLOBALS['egw_info']['user']['preferences']['addressbook']['add_default'],-1) == 'p';
195
+		$this->default_private = substr($GLOBALS['egw_info']['user']['preferences']['addressbook']['add_default'], -1) == 'p';
196 196
 		if ($this->default_addressbook > 0 && $this->default_addressbook != $this->user &&
197 197
 			($this->default_private ||
198 198
 			$this->default_addressbook == (int)$GLOBALS['egw']->preferences->forced['addressbook']['add_default'] ||
199 199
 			$this->default_addressbook == (int)$GLOBALS['egw']->preferences->default['addressbook']['add_default']))
200 200
 		{
201
-			$this->default_addressbook = $this->user;	// admin set a default or forced pref for personal addressbook
201
+			$this->default_addressbook = $this->user; // admin set a default or forced pref for personal addressbook
202 202
 		}
203 203
 		$this->private_addressbook = self::private_addressbook($this->contact_repository == 'sql', $this->prefs);
204 204
 
@@ -303,27 +303,27 @@  discard block
 block discarded – undo
303 303
 		$this->own_account_acl = $GLOBALS['egw_info']['server']['own_account_acl'];
304 304
 		if (!is_array($this->own_account_acl)) $this->own_account_acl = json_php_unserialize($this->own_account_acl, true);
305 305
 		// we have only one acl (n_fn) for the whole name, as not all backends store every part in an own field
306
-		if ($this->own_account_acl && in_array('n_fn',$this->own_account_acl))
306
+		if ($this->own_account_acl && in_array('n_fn', $this->own_account_acl))
307 307
 		{
308
-			$this->own_account_acl = array_merge($this->own_account_acl,array('n_prefix','n_given','n_middle','n_family','n_suffix'));
308
+			$this->own_account_acl = array_merge($this->own_account_acl, array('n_prefix', 'n_given', 'n_middle', 'n_family', 'n_suffix'));
309 309
 		}
310 310
 		if ($GLOBALS['egw_info']['server']['org_fileds_to_update'])
311 311
 		{
312
-			$this->org_fields =  $GLOBALS['egw_info']['server']['org_fileds_to_update'];
312
+			$this->org_fields = $GLOBALS['egw_info']['server']['org_fileds_to_update'];
313 313
 			if (!is_array($this->org_fields)) $this->org_fields = unserialize($this->org_fields);
314 314
 
315 315
 			// Set country code if country name is selected
316
-			$supported_fields = $this->get_fields('supported',null,0);
317
-			if(in_array('adr_one_countrycode', $supported_fields) && in_array('adr_one_countryname',$this->org_fields))
316
+			$supported_fields = $this->get_fields('supported', null, 0);
317
+			if (in_array('adr_one_countrycode', $supported_fields) && in_array('adr_one_countryname', $this->org_fields))
318 318
 			{
319 319
 				$this->org_fields[] = 'adr_one_countrycode';
320 320
 			}
321
-			if(in_array('adr_two_countrycode', $supported_fields) && in_array('adr_two_countryname',$this->org_fields))
321
+			if (in_array('adr_two_countrycode', $supported_fields) && in_array('adr_two_countryname', $this->org_fields))
322 322
 			{
323 323
 				$this->org_fields[] = 'adr_two_countrycode';
324 324
 			}
325 325
 		}
326
-		$this->categories = new Categories($this->user,'addressbook');
326
+		$this->categories = new Categories($this->user, 'addressbook');
327 327
 
328 328
 		$this->delete_history = $GLOBALS['egw_info']['server']['history'];
329 329
 	}
@@ -337,7 +337,7 @@  discard block
 block discarded – undo
337 337
 	 * @param array $prefs addressbook preferences
338 338
 	 * @return boolean
339 339
 	 */
340
-	public static function private_addressbook($contact_repository, array $prefs=null)
340
+	public static function private_addressbook($contact_repository, array $prefs = null)
341 341
 	{
342 342
 		return $contact_repository == 'sql' && $prefs['private_addressbook'];
343 343
 	}
@@ -351,7 +351,7 @@  discard block
 block discarded – undo
351 351
 	 * @param int $user =null account_id or null for current user
352 352
 	 * @return array with owner => label pairs
353 353
 	 */
354
-	function get_addressbooks($required=Acl::READ,$extra_label=null,$user=null)
354
+	function get_addressbooks($required = Acl::READ, $extra_label = null, $user = null)
355 355
 	{
356 356
 		if (is_null($user))
357 357
 		{
@@ -370,11 +370,11 @@  discard block
 block discarded – undo
370 370
 		if ($extra_label) $addressbooks[''] = $extra_label;
371 371
 		$addressbooks[$user] = lang('Personal');
372 372
 		// add all group addressbooks the user has the necessary rights too
373
-		foreach($grants as $uid => $rights)
373
+		foreach ($grants as $uid => $rights)
374 374
 		{
375
-			if (($rights & $required) == $required && $GLOBALS['egw']->accounts->get_type($uid) == 'g')
375
+			if (($rights&$required) == $required && $GLOBALS['egw']->accounts->get_type($uid) == 'g')
376 376
 			{
377
-				$to_sort[$uid] = lang('Group %1',$GLOBALS['egw']->accounts->id2name($uid));
377
+				$to_sort[$uid] = lang('Group %1', $GLOBALS['egw']->accounts->id2name($uid));
378 378
 			}
379 379
 		}
380 380
 		if ($to_sort)
@@ -382,19 +382,19 @@  discard block
 block discarded – undo
382 382
 			asort($to_sort);
383 383
 			$addressbooks += $to_sort;
384 384
 		}
385
-		if ($required != Acl::ADD &&	// do NOT allow to set accounts as default addressbook (AB can add accounts)
385
+		if ($required != Acl::ADD && // do NOT allow to set accounts as default addressbook (AB can add accounts)
386 386
 			$preferences['addressbook']['hide_accounts'] !== '1' && (
387
-				($grants[0] & $required) == $required ||
387
+				($grants[0]&$required) == $required ||
388 388
 				$preferences['common']['account_selection'] == 'groupmembers' &&
389
-				$this->account_repository != 'ldap' && ($required & Acl::READ)))
389
+				$this->account_repository != 'ldap' && ($required&Acl::READ)))
390 390
 		{
391 391
 			$addressbooks[0] = lang('Accounts');
392 392
 		}
393 393
 		// add all other user addressbooks the user has the necessary rights too
394 394
 		$to_sort = array();
395
-		foreach($grants as $uid => $rights)
395
+		foreach ($grants as $uid => $rights)
396 396
 		{
397
-			if ($uid != $user && ($rights & $required) == $required && $GLOBALS['egw']->accounts->get_type($uid) == 'u')
397
+			if ($uid != $user && ($rights&$required) == $required && $GLOBALS['egw']->accounts->get_type($uid) == 'u')
398 398
 			{
399 399
 				$to_sort[$uid] = Accounts::username($uid);
400 400
 			}
@@ -419,22 +419,22 @@  discard block
 block discarded – undo
419 419
 	 * @param boolean $isUpdate =false If true, reads the old record for any not set fields
420 420
 	 * @return string
421 421
 	 */
422
-	function fileas($contact,$type=null, $isUpdate=false)
422
+	function fileas($contact, $type = null, $isUpdate = false)
423 423
 	{
424 424
 		if (is_null($type)) $type = $contact['fileas_type'];
425 425
 		if (!$type) $type = $this->prefs['fileas_default'] ? $this->prefs['fileas_default'] : $this->fileas_types[0];
426 426
 
427
-		if (strpos($type,'n_fn') !== false) $contact['n_fn'] = $this->fullname($contact);
427
+		if (strpos($type, 'n_fn') !== false) $contact['n_fn'] = $this->fullname($contact);
428 428
 
429
-		if($isUpdate)
429
+		if ($isUpdate)
430 430
 		{
431
-			$fileas_fields = array('n_prefix','n_given','n_middle','n_family','n_suffix','n_fn','org_name','org_unit','adr_one_locality','bday');
431
+			$fileas_fields = array('n_prefix', 'n_given', 'n_middle', 'n_family', 'n_suffix', 'n_fn', 'org_name', 'org_unit', 'adr_one_locality', 'bday');
432 432
 			$old = null;
433
-			foreach($fileas_fields as $field)
433
+			foreach ($fileas_fields as $field)
434 434
 			{
435
-				if(!isset($contact[$field]))
435
+				if (!isset($contact[$field]))
436 436
 				{
437
-					if(is_null($old)) $old = $this->read($contact['id']);
437
+					if (is_null($old)) $old = $this->read($contact['id']);
438 438
 					$contact[$field] = $old[$field];
439 439
 				}
440 440
 			}
@@ -442,8 +442,8 @@  discard block
 block discarded – undo
442 442
 		}
443 443
 
444 444
 		// removing empty delimiters, caused by empty contact fields
445
-		$fileas = str_replace(array(', , : ',', : ',': , ',', , ',': : ',' ()'),
446
-			array(': ',': ',': ',', ',': ',''),
445
+		$fileas = str_replace(array(', , : ', ', : ', ': , ', ', , ', ': : ', ' ()'),
446
+			array(': ', ': ', ': ', ', ', ': ', ''),
447 447
 			strtr($type, array(
448 448
 				'n_prefix' => $contact['n_prefix'],
449 449
 				'n_given'  => $contact['n_given'],
@@ -457,13 +457,13 @@  discard block
 block discarded – undo
457 457
 				'bday'     => (int)$contact['bday'] ? DateTime::to($contact['bday'], true) : $contact['bday'],
458 458
 			)));
459 459
 
460
-		while ($fileas[0] == ':' ||  $fileas[0] == ',')
460
+		while ($fileas[0] == ':' || $fileas[0] == ',')
461 461
 		{
462
-			$fileas = substr($fileas,2);
462
+			$fileas = substr($fileas, 2);
463 463
 		}
464
-		while (substr($fileas,-2) == ': ' || substr($fileas,-2) == ', ')
464
+		while (substr($fileas, -2) == ': ' || substr($fileas, -2) == ', ')
465 465
 		{
466
-			$fileas = substr($fileas,0,-2);
466
+			$fileas = substr($fileas, 0, -2);
467 467
 		}
468 468
 		return $fileas;
469 469
 	}
@@ -475,15 +475,15 @@  discard block
 block discarded – undo
475 475
 	 * @param string $file_as =null file_as type, default null to read it from the contact, unknown/not set type default to the first one
476 476
 	 * @return string
477 477
 	 */
478
-	function fileas_type($contact,$file_as=null)
478
+	function fileas_type($contact, $file_as = null)
479 479
 	{
480 480
 		if (is_null($file_as)) $file_as = $contact['n_fileas'];
481 481
 
482 482
 		if ($file_as)
483 483
 		{
484
-			foreach($this->fileas_types as $type)
484
+			foreach ($this->fileas_types as $type)
485 485
 			{
486
-				if ($this->fileas($contact,$type) == $file_as)
486
+				if ($this->fileas($contact, $type) == $file_as)
487 487
 				{
488 488
 					return $type;
489 489
 				}
@@ -500,10 +500,10 @@  discard block
 block discarded – undo
500 500
 	 */
501 501
 	public static function cf_options()
502 502
 	{
503
-		$cf_fields = Storage\Customfields::get('addressbook',TRUE);
504
-		foreach ($cf_fields as $key => $value )
503
+		$cf_fields = Storage\Customfields::get('addressbook', TRUE);
504
+		foreach ($cf_fields as $key => $value)
505 505
 		{
506
-			$options[$key]= $value['label'];
506
+			$options[$key] = $value['label'];
507 507
 		}
508 508
 		return $options;
509 509
 	}
@@ -514,7 +514,7 @@  discard block
 block discarded – undo
514 514
 	 * @param array $contact =null real content to use, default none
515 515
 	 * @return array with options: fileas type => label pairs
516 516
 	 */
517
-	function fileas_options($contact=null)
517
+	function fileas_options($contact = null)
518 518
 	{
519 519
 		$labels = array(
520 520
 			'n_prefix' => lang('prefix'),
@@ -528,13 +528,13 @@  discard block
 block discarded – undo
528 528
 			'adr_one_locality' => lang('city'),
529 529
 			'bday'     => lang('Birthday'),
530 530
 		);
531
-		foreach(array_keys($labels) as $name)
531
+		foreach (array_keys($labels) as $name)
532 532
 		{
533 533
 			if ($contact[$name]) $labels[$name] = $contact[$name];
534 534
 		}
535
-		foreach($this->fileas_types as $fileas_type)
535
+		foreach ($this->fileas_types as $fileas_type)
536 536
 		{
537
-			$options[$fileas_type] = $this->fileas($labels,$fileas_type);
537
+			$options[$fileas_type] = $this->fileas($labels, $fileas_type);
538 538
 		}
539 539
 		return $options;
540 540
 	}
@@ -549,7 +549,7 @@  discard block
 block discarded – undo
549 549
 	 * @param int &$errors=null on return number of errors
550 550
 	 * @return int|boolean number of contacts updated, false for wrong fileas type
551 551
 	 */
552
-	function set_all_fileas($fileas_type,$all=false,&$errors=null,$ignore_acl=false)
552
+	function set_all_fileas($fileas_type, $all = false, &$errors = null, $ignore_acl = false)
553 553
 	{
554 554
 		if ($fileas_type != '' && !in_array($fileas_type, $this->fileas_types))
555 555
 		{
@@ -557,17 +557,17 @@  discard block
 block discarded – undo
557 557
 		}
558 558
 		if ($ignore_acl)
559 559
 		{
560
-			unset($this->somain->grants);	// to NOT limit search to contacts readable by current user
560
+			unset($this->somain->grants); // to NOT limit search to contacts readable by current user
561 561
 		}
562 562
 		// to be able to work on huge contact repositories we read the contacts in chunks of 100
563
-		for($n = $updated = $errors = 0; ($contacts = parent::search($all ? array() : array(
563
+		for ($n = $updated = $errors = 0; ($contacts = parent::search($all ? array() : array(
564 564
 			'n_fileas IS NULL',
565 565
 			"n_fileas=''",
566 566
 			'n_fn IS NULL',
567 567
 			"n_fn=''",
568
-		),false,'','','',false,'OR',array($n*100,100))); ++$n)
568
+		), false, '', '', '', false, 'OR', array($n * 100, 100))); ++$n)
569 569
 		{
570
-			foreach($contacts as $contact)
570
+			foreach ($contacts as $contact)
571 571
 			{
572 572
 				$old_fn     = $contact['n_fn'];
573 573
 				$old_fileas = $contact['n_fileas'];
@@ -575,19 +575,19 @@  discard block
 block discarded – undo
575 575
 				// only update fileas if type is given AND (all should be updated or n_fileas is empty)
576 576
 				if ($fileas_type && ($all || empty($contact['n_fileas'])))
577 577
 				{
578
-					$contact['n_fileas'] = $this->fileas($contact,$fileas_type);
578
+					$contact['n_fileas'] = $this->fileas($contact, $fileas_type);
579 579
 				}
580 580
 				if ($old_fileas != $contact['n_fileas'] || $old_fn != $contact['n_fn'])
581 581
 				{
582 582
 					// only specify/write updated fields plus "keys"
583
-					$contact = array_intersect_key($contact,array(
583
+					$contact = array_intersect_key($contact, array(
584 584
 						'id' => true,
585 585
 						'owner' => true,
586 586
 						'private' => true,
587 587
 						'account_id' => true,
588 588
 						'uid' => true,
589
-					)+($old_fileas != $contact['n_fileas'] ? array('n_fileas' => true) : array())+($old_fn != $contact['n_fn'] ? array('n_fn' => true) : array()));
590
-					if ($this->save($contact,$ignore_acl))
589
+					) + ($old_fileas != $contact['n_fileas'] ? array('n_fileas' => true) : array()) + ($old_fn != $contact['n_fn'] ? array('n_fn' => true) : array()));
590
+					if ($this->save($contact, $ignore_acl))
591 591
 					{
592 592
 						$updated++;
593 593
 					}
@@ -610,11 +610,11 @@  discard block
 block discarded – undo
610 610
 	 * @param int &$errors=null on return number of errors
611 611
 	 * @return int|boolean number of contacts updated
612 612
 	 */
613
-	function set_all_cleanup(&$errors=null,$ignore_acl=false)
613
+	function set_all_cleanup(&$errors = null, $ignore_acl = false)
614 614
 	{
615 615
 		if ($ignore_acl)
616 616
 		{
617
-			unset($this->somain->grants);	// to NOT limit search to contacts readable by current user
617
+			unset($this->somain->grants); // to NOT limit search to contacts readable by current user
618 618
 		}
619 619
 
620 620
 		// fields that must not be touched
@@ -636,14 +636,14 @@  discard block
 block discarded – undo
636 636
 		);
637 637
 
638 638
 		// to be able to work on huge contact repositories we read the contacts in chunks of 100
639
-		for($n = $updated = $errors = 0; ($contacts = parent::search(array(),false,'','','',false,'OR',array($n*100,100))); ++$n)
639
+		for ($n = $updated = $errors = 0; ($contacts = parent::search(array(), false, '', '', '', false, 'OR', array($n * 100, 100))); ++$n)
640 640
 		{
641
-			foreach($contacts as $contact)
641
+			foreach ($contacts as $contact)
642 642
 			{
643 643
 				$fields_to_update = array();
644
-				foreach($contact as $field_name => $field_value)
644
+				foreach ($contact as $field_name => $field_value)
645 645
 				{
646
-					if($fields_exclude[$field_name] === true) continue; // dont touch specified field
646
+					if ($fields_exclude[$field_name] === true) continue; // dont touch specified field
647 647
 
648 648
 					if (is_string($field_value) && $field_name != 'pubkey' && $field_name != 'jpegphoto')
649 649
 					{
@@ -653,9 +653,9 @@  discard block
 block discarded – undo
653 653
 							$fields_to_update[$field_name] = $field_value = trim($field_value);
654 654
 						}
655 655
 						// check if field contains a carriage return - exclude notes
656
-						if ($field_name != 'note' && strpos($field_value,"\x0D\x0A") !== false)
656
+						if ($field_name != 'note' && strpos($field_value, "\x0D\x0A") !== false)
657 657
 						{
658
-							$fields_to_update[$field_name] = $field_value = str_replace("\x0D\x0A"," ",$field_value);
658
+							$fields_to_update[$field_name] = $field_value = str_replace("\x0D\x0A", " ", $field_value);
659 659
 						}
660 660
 					}
661 661
 					// check if a field contains an empty string
@@ -665,13 +665,13 @@  discard block
 block discarded – undo
665 665
 					}
666 666
 					// check for valid birthday date
667 667
 					if ($field_name == 'bday' && $field_value != null &&
668
-						!preg_match('/^(18|19|20|21|22)\d{2}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/',$field_value))
668
+						!preg_match('/^(18|19|20|21|22)\d{2}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $field_value))
669 669
 					{
670 670
 						$fields_to_update[$field_name] = $field_value = null;
671 671
 					}
672 672
 				}
673 673
 
674
-				if(count($fields_to_update) > 0)
674
+				if (count($fields_to_update) > 0)
675 675
 				{
676 676
 					$contact_to_save = array(
677 677
 						'id' => $contact['id'],
@@ -680,7 +680,7 @@  discard block
 block discarded – undo
680 680
 						'account_id' => $contact['account_id'],
681 681
 						'uid' => $contact['uid']) + $fields_to_update;
682 682
 
683
-					if ($this->save($contact_to_save,$ignore_acl))
683
+					if ($this->save($contact_to_save, $ignore_acl))
684 684
 					{
685 685
 						$updated++;
686 686
 					}
@@ -705,14 +705,14 @@  discard block
 block discarded – undo
705 705
 		if (empty($contact['n_family']) && empty($contact['n_given'])) {
706 706
 			$cpart = array('org_name');
707 707
 		} else {
708
-			$cpart = array('n_prefix','n_given','n_middle','n_family','n_suffix');
708
+			$cpart = array('n_prefix', 'n_given', 'n_middle', 'n_family', 'n_suffix');
709 709
 		}
710 710
 		$parts = array();
711
-		foreach($cpart as $n)
711
+		foreach ($cpart as $n)
712 712
 		{
713 713
 			if ($contact[$n]) $parts[] = $contact[$n];
714 714
 		}
715
-		return implode(' ',$parts);
715
+		return implode(' ', $parts);
716 716
 	}
717 717
 
718 718
 	/**
@@ -726,7 +726,7 @@  discard block
 block discarded – undo
726 726
 	 *
727 727
 	 * @return array updated data
728 728
 	 */
729
-	function db2data($data, $date_format='ts')
729
+	function db2data($data, $date_format = 'ts')
730 730
 	{
731 731
 		static $fb_url = false;
732 732
 
@@ -738,7 +738,7 @@  discard block
 block discarded – undo
738 738
 				$data[$name] = DateTime::server2user($data[$name], $date_format);
739 739
 			}
740 740
 		}
741
-		$data['photo'] = $this->photo_src($data['id'],$data['jpegphoto'] || ($data['files'] & self::FILES_BIT_PHOTO), '', $data['etag']);
741
+		$data['photo'] = $this->photo_src($data['id'], $data['jpegphoto'] || ($data['files']&self::FILES_BIT_PHOTO), '', $data['etag']);
742 742
 
743 743
 		// set freebusy_uri for accounts
744 744
 		if (!$data['freebusy_uri'] && !$data['owner'] && $data['account_id'] && !is_object($GLOBALS['egw_setup']))
@@ -761,12 +761,12 @@  discard block
 block discarded – undo
761 761
 	 * @param string $etag =null etag to set in url to allow caching with Expires header
762 762
 	 * @return string
763 763
 	 */
764
-	function photo_src($id,$jpeg,$default='',$etag=null)
764
+	function photo_src($id, $jpeg, $default = '', $etag = null)
765 765
 	{
766 766
 		//error_log(__METHOD__."($id, ..., etag=$etag) ".  function_backtrace());
767 767
 		return $jpeg || !$default ? Egw::link('/api/avatar.php', array(
768 768
 			'contact_id' => $id
769
-		)+(isset($etag) ? array(
769
+		) + (isset($etag) ? array(
770 770
 			'etag'       => $etag,
771 771
 		) : array())) : $default;
772 772
 	}
@@ -782,7 +782,7 @@  discard block
 block discarded – undo
782 782
 	 *
783 783
 	 * @return array upated data
784 784
 	 */
785
-	function data2db($data, $date_format='ts')
785
+	function data2db($data, $date_format = 'ts')
786 786
 	{
787 787
 		// convert timestamps from user-time to server-time in the db
788 788
 		foreach ($this->timestamps as $name)
@@ -803,7 +803,7 @@  discard block
 block discarded – undo
803 803
 	* @param int $check_etag =null
804 804
 	* @return boolean|int true on success or false on failiure, 0 if etag does not match
805 805
 	*/
806
-	function delete($contact,$deny_account_delete=true,$check_etag=null)
806
+	function delete($contact, $deny_account_delete = true, $check_etag = null)
807 807
 	{
808 808
 		if (is_array($contact) && isset($contact['id']))
809 809
 		{
@@ -813,12 +813,12 @@  discard block
 block discarded – undo
813 813
 		{
814 814
 			$contact = array($contact);
815 815
 		}
816
-		foreach($contact as $c)
816
+		foreach ($contact as $c)
817 817
 		{
818 818
 			$id = is_array($c) ? $c['id'] : $c;
819 819
 
820 820
 			$ok = false;
821
-			if ($this->check_perms(Acl::DELETE,$c,$deny_account_delete))
821
+			if ($this->check_perms(Acl::DELETE, $c, $deny_account_delete))
822 822
 			{
823 823
 				if (!($old = $this->read($id))) return false;
824 824
 				// check if we only mark contacts as deleted, or really delete them
@@ -829,12 +829,12 @@  discard block
 block discarded – undo
829 829
 					$delete = $old;
830 830
 					$delete['tid'] = self::DELETED_TYPE;
831 831
 					if ($check_etag) $delete['etag'] = $check_etag;
832
-					if (($ok = $this->save($delete))) $ok = true;	// we have to return true or false
833
-					Link::unlink(0,'addressbook',$id,'','','',true);
832
+					if (($ok = $this->save($delete))) $ok = true; // we have to return true or false
833
+					Link::unlink(0, 'addressbook', $id, '', '', '', true);
834 834
 				}
835
-				elseif (($ok = parent::delete($id,$check_etag)))
835
+				elseif (($ok = parent::delete($id, $check_etag)))
836 836
 				{
837
-					Link::unlink(0,'addressbook',$id);
837
+					Link::unlink(0, 'addressbook', $id);
838 838
 				}
839 839
 
840 840
 				// Don't notify of final purge
@@ -861,11 +861,11 @@  discard block
 block discarded – undo
861 861
 	* @param boolean $touch_modified =true should modified/r be updated
862 862
 	* @return int/string/boolean id on success, false on failure, the error-message is in $this->error
863 863
 	*/
864
-	function save(&$contact, $ignore_acl=false, $touch_modified=true)
864
+	function save(&$contact, $ignore_acl = false, $touch_modified = true)
865 865
 	{
866 866
 		// Make sure photo remains unchanged unless its purposely set to be false
867 867
 		// which means photo has changed.
868
-		if (!array_key_exists('photo_unchanged',$contact)) $contact['photo_unchanged'] = true;
868
+		if (!array_key_exists('photo_unchanged', $contact)) $contact['photo_unchanged'] = true;
869 869
 
870 870
 		// remember if we add or update a entry
871 871
 		if (($isUpdate = $contact['id']))
@@ -874,11 +874,11 @@  discard block
 block discarded – undo
874 874
 			{
875 875
 				if (($old = $this->read($contact['id'])))	// --> try reading the old entry and set it from there
876 876
 				{
877
-					if(!isset($contact['owner']))
877
+					if (!isset($contact['owner']))
878 878
 					{
879 879
 						$contact['owner'] = $old['owner'];
880 880
 					}
881
-					if(!isset($contact['private']))
881
+					if (!isset($contact['private']))
882 882
 					{
883 883
 						$contact['private'] = $old['private'];
884 884
 					}
@@ -910,7 +910,7 @@  discard block
 block discarded – undo
910 910
 		{
911 911
 			$contact['private'] = 0;
912 912
 		}
913
-		if(!$ignore_acl && !$this->check_perms($isUpdate ? Acl::EDIT : Acl::ADD,$contact))
913
+		if (!$ignore_acl && !$this->check_perms($isUpdate ? Acl::EDIT : Acl::ADD, $contact))
914 914
 		{
915 915
 			$this->error = 'access denied';
916 916
 			return false;
@@ -923,15 +923,15 @@  discard block
 block discarded – undo
923 923
 		// convert categories
924 924
 		if (is_array($contact['cat_id']))
925 925
 		{
926
-			$contact['cat_id'] = implode(',',$contact['cat_id']);
926
+			$contact['cat_id'] = implode(',', $contact['cat_id']);
927 927
 		}
928 928
 
929 929
 		// Update country codes
930
-		foreach(array('adr_one_', 'adr_two_') as $c_prefix) {
931
-			if($contact[$c_prefix.'countryname'] && !$contact[$c_prefix.'countrycode'] &&
930
+		foreach (array('adr_one_', 'adr_two_') as $c_prefix) {
931
+			if ($contact[$c_prefix.'countryname'] && !$contact[$c_prefix.'countrycode'] &&
932 932
 				$code = Country::country_code($contact[$c_prefix.'countryname']))
933 933
 			{
934
-				if(strlen($code) == 2)
934
+				if (strlen($code) == 2)
935 935
 				{
936 936
 					$contact[$c_prefix.'countrycode'] = $code;
937 937
 				}
@@ -940,7 +940,7 @@  discard block
 block discarded – undo
940 940
 					$contact[$c_prefix.'countrycode'] = null;
941 941
 				}
942 942
 			}
943
-			if($contact[$c_prefix.'countrycode'] != null)
943
+			if ($contact[$c_prefix.'countrycode'] != null)
944 944
 			{
945 945
 				$contact[$c_prefix.'countryname'] = null;
946 946
 			}
@@ -968,9 +968,9 @@  discard block
 block discarded – undo
968 968
 		// (non-admin) user editing his own account, make sure he does not change fields he is not allowed to (eg. via SyncML or xmlrpc)
969 969
 		if (!$ignore_acl && !$contact['owner'] && !($this->is_admin($contact) || $this->allow_account_edit()))
970 970
 		{
971
-			foreach(array_keys($contact) as $field)
971
+			foreach (array_keys($contact) as $field)
972 972
 			{
973
-				if (!in_array($field,$this->own_account_acl) && !in_array($field,array('id','owner','account_id','modified','modifier', 'photo_unchanged')))
973
+				if (!in_array($field, $this->own_account_acl) && !in_array($field, array('id', 'owner', 'account_id', 'modified', 'modifier', 'photo_unchanged')))
974 974
 				{
975 975
 					// user is not allowed to change that
976 976
 					if ($old)
@@ -991,12 +991,12 @@  discard block
 block discarded – undo
991 991
 		{
992 992
 			if (isset($to_write['owner']) && !empty($to_write['owner']))
993 993
 			{
994
-				error_log(__METHOD__.__LINE__." Trying to change account to owner:". $to_write['owner'].' Account affected:'.array2string($old).' Data send:'.array2string($to_write));
994
+				error_log(__METHOD__.__LINE__." Trying to change account to owner:".$to_write['owner'].' Account affected:'.array2string($old).' Data send:'.array2string($to_write));
995 995
 				unset($to_write['owner']);
996 996
 			}
997 997
 		}
998 998
 
999
-		if(!($this->error = parent::save($to_write)))
999
+		if (!($this->error = parent::save($to_write)))
1000 1000
 		{
1001 1001
 			$contact['id'] = $to_write['id'];
1002 1002
 			$contact['uid'] = $to_write['uid'];
@@ -1005,9 +1005,9 @@  discard block
 block discarded – undo
1005 1005
 
1006 1006
 			// Clear any files saved with new entries
1007 1007
 			// They've been dealt with already and they cause errors with linking
1008
-			foreach(array_keys($this->customfields) as $field)
1008
+			foreach (array_keys($this->customfields) as $field)
1009 1009
 			{
1010
-				if(is_array($to_write[Storage::CF_PREFIX.$field]))
1010
+				if (is_array($to_write[Storage::CF_PREFIX.$field]))
1011 1011
 				{
1012 1012
 					unset($to_write[Storage::CF_PREFIX.$field]);
1013 1013
 				}
@@ -1021,27 +1021,27 @@  discard block
 block discarded – undo
1021 1021
 				$GLOBALS['egw']->accounts->cache_invalidate($contact['account_id']);
1022 1022
 				// call edit-accout hook, to let other apps know about changed account (names or email)
1023 1023
 				$GLOBALS['hook_values'] = (array)$GLOBALS['egw']->accounts->read($contact['account_id']);
1024
-				Hooks::process($GLOBALS['hook_values']+array(
1024
+				Hooks::process($GLOBALS['hook_values'] + array(
1025 1025
 					'location' => 'editaccount',
1026
-				),False,True);	// called for every app now, not only enabled ones)
1026
+				), False, True); // called for every app now, not only enabled ones)
1027 1027
 			}
1028 1028
 			// notify interested apps about changes in the account-contact data
1029 1029
 			if (!$to_write['owner'] && $to_write['account_id'] && $isUpdate)
1030 1030
 			{
1031 1031
 				$to_write['location'] = 'editaccountcontact';
1032
-				Hooks::process($to_write,False,True);	// called for every app now, not only enabled ones));
1032
+				Hooks::process($to_write, False, True); // called for every app now, not only enabled ones));
1033 1033
 			}
1034 1034
 			// Notify linked apps about changes in the contact data
1035
-			Link::notify_update('addressbook',  $contact['id'], $contact);
1035
+			Link::notify_update('addressbook', $contact['id'], $contact);
1036 1036
 
1037 1037
 			// Check for restore of deleted contact, restore held links
1038
-			if($old && $old['tid'] == self::DELETED_TYPE && $contact['tid'] != self::DELETED_TYPE)
1038
+			if ($old && $old['tid'] == self::DELETED_TYPE && $contact['tid'] != self::DELETED_TYPE)
1039 1039
 			{
1040 1040
 				Link::restore('addressbook', $contact['id']);
1041 1041
 			}
1042 1042
 
1043 1043
 			// Record change history for sql - doesn't work for LDAP accounts
1044
-			if(!$contact['account_id'] || $contact['account_id'] && $this->account_repository == 'sql')
1044
+			if (!$contact['account_id'] || $contact['account_id'] && $this->account_repository == 'sql')
1045 1045
 			{
1046 1046
 				$deleted = ($old['tid'] == self::DELETED_TYPE || $contact['tid'] == self::DELETED_TYPE);
1047 1047
 				if (!isset($this->tracking)) $this->tracking = new Contacts\Tracking($this);
@@ -1049,9 +1049,9 @@  discard block
 block discarded – undo
1049 1049
 			}
1050 1050
 
1051 1051
 			// Expire birthday cache for this year and next if birthday changed
1052
-			if($isUpdate && $old['bday'] !== $to_write['bday'] || !$isUpdate && $to_write['bday'])
1052
+			if ($isUpdate && $old['bday'] !== $to_write['bday'] || !$isUpdate && $to_write['bday'])
1053 1053
 			{
1054
-				$year = (int) date('Y',time());
1054
+				$year = (int)date('Y', time());
1055 1055
 				$this->clear_birthday_cache($year, $to_write['owner']);
1056 1056
 				$year++;
1057 1057
 				$this->clear_birthday_cache($year, $to_write['owner']);
@@ -1070,9 +1070,9 @@  discard block
 block discarded – undo
1070 1070
 	protected function clear_birthday_cache($year, $owner)
1071 1071
 	{
1072 1072
 		// Cache is kept per-language, so clear them all
1073
-		foreach(array_keys(Translation::get_installed_langs()) as $lang)
1073
+		foreach (array_keys(Translation::get_installed_langs()) as $lang)
1074 1074
 		{
1075
-			Cache::unsetInstance(__CLASS__,"birthday-$year-{$owner}-$lang");
1075
+			Cache::unsetInstance(__CLASS__, "birthday-$year-{$owner}-$lang");
1076 1076
 		}
1077 1077
 	}
1078 1078
 
@@ -1085,7 +1085,7 @@  discard block
 block discarded – undo
1085 1085
 	 * @param int $dst_w =240 max width to resize to
1086 1086
 	 * @return string with resized jpeg photo, null on error
1087 1087
 	 */
1088
-	public static function resize_photo($photo, $dst_w=240)
1088
+	public static function resize_photo($photo, $dst_w = 240)
1089 1089
 	{
1090 1090
 		if (is_resource($photo))
1091 1091
 		{
@@ -1101,15 +1101,15 @@  discard block
 block discarded – undo
1101 1101
 		//error_log(__METHOD__."() got image $src_w * $src_h, is_jpeg=".array2string(substr($photo,0,2) === "\377\330"));
1102 1102
 
1103 1103
 		// if $photo is to width or not a jpeg image --> resize it
1104
-		if ($src_w > $dst_w || cut_bytes($photo,0,2) !== "\377\330")
1104
+		if ($src_w > $dst_w || cut_bytes($photo, 0, 2) !== "\377\330")
1105 1105
 		{
1106 1106
 			//error_log(__METHOD__."(,dst_w=$dst_w) src_w=$src_w, cut_bytes(photo,0,2)=".array2string(cut_bytes($photo,0,2)).' --> resizing');
1107 1107
 			// scale the image to a width of 60 and a height according to the proportion of the source image
1108
-			$resized = imagecreatetruecolor($dst_w,$dst_h = round($src_h * $dst_w / $src_w));
1109
-			imagecopyresized($resized,$image,0,0,0,0,$dst_w,$dst_h,$src_w,$src_h);
1108
+			$resized = imagecreatetruecolor($dst_w, $dst_h = round($src_h * $dst_w / $src_w));
1109
+			imagecopyresized($resized, $image, 0, 0, 0, 0, $dst_w, $dst_h, $src_w, $src_h);
1110 1110
 
1111 1111
 			ob_start();
1112
-			imagejpeg($resized,null,90);
1112
+			imagejpeg($resized, null, 90);
1113 1113
 			$photo = ob_get_contents();
1114 1114
 			ob_end_clean();
1115 1115
 
@@ -1130,7 +1130,7 @@  discard block
 block discarded – undo
1130 1130
 	* @param boolean $ignore_acl =false true: no acl check
1131 1131
 	* @return array|boolean array with contact data, null if not found or false on no view perms
1132 1132
 	*/
1133
-	function read($contact_id, $ignore_acl=false)
1133
+	function read($contact_id, $ignore_acl = false)
1134 1134
 	{
1135 1135
 		// get so_sql_cf to read private customfields too, if we ignore acl
1136 1136
 		if ($ignore_acl && is_a($this->somain, __CLASS__.'\\Sql'))
@@ -1140,11 +1140,11 @@  discard block
 block discarded – undo
1140 1140
 		}
1141 1141
 		if (!($data = parent::read($contact_id)))
1142 1142
 		{
1143
-			$data = null;	// not found
1143
+			$data = null; // not found
1144 1144
 		}
1145
-		elseif (!$ignore_acl && !$this->check_perms(Acl::READ,$data))
1145
+		elseif (!$ignore_acl && !$this->check_perms(Acl::READ, $data))
1146 1146
 		{
1147
-			$data = false;	// no view perms
1147
+			$data = false; // no view perms
1148 1148
 		}
1149 1149
 		else
1150 1150
 		{
@@ -1152,10 +1152,10 @@  discard block
 block discarded – undo
1152 1152
 			$data['fileas_type'] = $this->fileas_type($data);
1153 1153
 
1154 1154
 			// Update country name from code
1155
-			if($data['adr_one_countrycode'] != null) {
1155
+			if ($data['adr_one_countrycode'] != null) {
1156 1156
 				$data['adr_one_countryname'] = Country::get_full_name($data['adr_one_countrycode'], true);
1157 1157
 			}
1158
-			if($data['adr_two_countrycode'] != null) {
1158
+			if ($data['adr_two_countrycode'] != null) {
1159 1159
 				$data['adr_two_countryname'] = Country::get_full_name($data['adr_two_countrycode'], true);
1160 1160
 			}
1161 1161
 		}
@@ -1179,7 +1179,7 @@  discard block
 block discarded – undo
1179 1179
 	 * @param int $user =null for which user to check, default current user
1180 1180
 	 * @return boolean true permission granted, false for permission denied, null for contact does not exist
1181 1181
 	 */
1182
-	function check_perms($needed,$contact,$deny_account_delete=false,$user=null)
1182
+	function check_perms($needed, $contact, $deny_account_delete = false, $user = null)
1183 1183
 	{
1184 1184
 		if (!$user) $user = $this->user;
1185 1185
 		if ($user == $this->user)
@@ -1190,7 +1190,7 @@  discard block
 block discarded – undo
1190 1190
 		else
1191 1191
 		{
1192 1192
 			$grants = $this->get_grants($user);
1193
-			$memberships =  $GLOBALS['egw']->accounts->memberships($user,true);
1193
+			$memberships = $GLOBALS['egw']->accounts->memberships($user, true);
1194 1194
 		}
1195 1195
 
1196 1196
 		if ((!is_array($contact) || !isset($contact['owner'])) &&
@@ -1216,7 +1216,7 @@  discard block
 block discarded – undo
1216 1216
 			$GLOBALS['egw_info']['user']['preferences']['common']['account_selection'] == 'groupmembers' &&
1217 1217
 			!isset($GLOBALS['egw_info']['user']['apps']['admin']))
1218 1218
 		{
1219
-			$access = !!array_intersect($memberships,$GLOBALS['egw']->accounts->memberships($contact['account_id'],true));
1219
+			$access = !!array_intersect($memberships, $GLOBALS['egw']->accounts->memberships($contact['account_id'], true));
1220 1220
 		}
1221 1221
 		else if ($contact['id'] && $GLOBALS['egw']->acl->check('A'.$contact['id'], $needed, 'addressbook'))
1222 1222
 		{
@@ -1224,8 +1224,8 @@  discard block
 block discarded – undo
1224 1224
 		}
1225 1225
 		else
1226 1226
 		{
1227
-			$access = ($grants[$owner] & $needed) &&
1228
-				(!$contact['private'] || ($grants[$owner] & Acl::PRIVAT) || in_array($owner,$memberships));
1227
+			$access = ($grants[$owner]&$needed) &&
1228
+				(!$contact['private'] || ($grants[$owner]&Acl::PRIVAT) || in_array($owner, $memberships));
1229 1229
 		}
1230 1230
 		//error_log(__METHOD__."($needed,$contact[id],$deny_account_delete,$user) returning ".array2string($access));
1231 1231
 		return $access;
@@ -1240,11 +1240,11 @@  discard block
 block discarded – undo
1240 1240
 	 * @param int $user =null for which user to check, default current user
1241 1241
 	 * @return boolean true if access is granted or false otherwise
1242 1242
 	 */
1243
-	function file_access($id,$check,$rel_path=null,$user=null)
1243
+	function file_access($id, $check, $rel_path = null, $user = null)
1244 1244
 	{
1245
-		unset($rel_path);	// not used, but required by function signature
1245
+		unset($rel_path); // not used, but required by function signature
1246 1246
 
1247
-		return $this->check_perms($check,$id,false,$user);
1247
+		return $this->check_perms($check, $id, false, $user);
1248 1248
 	}
1249 1249
 
1250 1250
 	/**
@@ -1256,18 +1256,18 @@  discard block
 block discarded – undo
1256 1256
 	function read_org($org_id)
1257 1257
 	{
1258 1258
 		if (!$org_id) return false;
1259
-		if (strpos($org_id,'*AND*')!== false) $org_id = str_replace('*AND*','&',$org_id);
1259
+		if (strpos($org_id, '*AND*') !== false) $org_id = str_replace('*AND*', '&', $org_id);
1260 1260
 		$org = array();
1261
-		foreach(explode('|||',$org_id) as $part)
1261
+		foreach (explode('|||', $org_id) as $part)
1262 1262
 		{
1263
-			list($name,$value) = explode(':',$part,2);
1263
+			list($name, $value) = explode(':', $part, 2);
1264 1264
 			$org[$name] = $value;
1265 1265
 		}
1266
-		$csvs = array('cat_id');	// fields with comma-separated-values
1266
+		$csvs = array('cat_id'); // fields with comma-separated-values
1267 1267
 
1268 1268
 		// split regular fields and custom fields
1269 1269
 		$custom_fields = $regular_fields = array();
1270
-		foreach($this->org_fields as $name)
1270
+		foreach ($this->org_fields as $name)
1271 1271
 		{
1272 1272
 			if ($name[0] != '#')
1273 1273
 			{
@@ -1275,9 +1275,9 @@  discard block
 block discarded – undo
1275 1275
 			}
1276 1276
 			else
1277 1277
 			{
1278
-				$custom_fields[] = $name = substr($name,1);
1278
+				$custom_fields[] = $name = substr($name, 1);
1279 1279
 				$regular_fields['id'] = 'id';
1280
-				if (substr($this->customfields[$name]['type'],0,6)=='select' && $this->customfields[$name]['rows'] ||	// multiselection
1280
+				if (substr($this->customfields[$name]['type'], 0, 6) == 'select' && $this->customfields[$name]['rows'] || // multiselection
1281 1281
 					$this->customfields[$name]['type'] == 'radio')
1282 1282
 				{
1283 1283
 					$csvs[] = '#'.$name;
@@ -1285,24 +1285,24 @@  discard block
 block discarded – undo
1285 1285
 			}
1286 1286
 		}
1287 1287
 		// read the regular fields
1288
-		$contacts = parent::search('',$regular_fields,'','','',false,'AND',false,$org);
1288
+		$contacts = parent::search('', $regular_fields, '', '', '', false, 'AND', false, $org);
1289 1289
 		if (!$contacts) return false;
1290 1290
 
1291 1291
 		// if we have custom fields, read and merge them in
1292 1292
 		if ($custom_fields)
1293 1293
 		{
1294
-			foreach($contacts as $contact)
1294
+			foreach ($contacts as $contact)
1295 1295
 			{
1296 1296
 				$ids[] = $contact['id'];
1297 1297
 			}
1298
-			if (($cfs = $this->read_customfields($ids,$custom_fields)))
1298
+			if (($cfs = $this->read_customfields($ids, $custom_fields)))
1299 1299
 			{
1300 1300
 				foreach ($contacts as &$contact)
1301 1301
 				{
1302 1302
 					$id = $contact['id'];
1303 1303
 					if (isset($cfs[$id]))
1304 1304
 					{
1305
-						foreach($cfs[$id] as $name => $value)
1305
+						foreach ($cfs[$id] as $name => $value)
1306 1306
 						{
1307 1307
 							$contact['#'.$name] = $value;
1308 1308
 						}
@@ -1314,34 +1314,34 @@  discard block
 block discarded – undo
1314 1314
 
1315 1315
 		// create a statistic about the commonness of each fields values
1316 1316
 		$fields = array();
1317
-		foreach($contacts as $contact)
1317
+		foreach ($contacts as $contact)
1318 1318
 		{
1319
-			foreach($contact as $name => $value)
1319
+			foreach ($contact as $name => $value)
1320 1320
 			{
1321
-				if (!in_array($name,$csvs))
1321
+				if (!in_array($name, $csvs))
1322 1322
 				{
1323 1323
 					$fields[$name][$value]++;
1324 1324
 				}
1325 1325
 				else
1326 1326
 				{
1327 1327
 					// for comma separated fields, we have to use each single value
1328
-					foreach(explode(',',$value) as $val)
1328
+					foreach (explode(',', $value) as $val)
1329 1329
 					{
1330 1330
 						$fields[$name][$val]++;
1331 1331
 					}
1332 1332
 				}
1333 1333
 			}
1334 1334
 		}
1335
-		foreach($fields as $name => $values)
1335
+		foreach ($fields as $name => $values)
1336 1336
 		{
1337
-			if (!in_array($name,$this->org_fields)) continue;
1337
+			if (!in_array($name, $this->org_fields)) continue;
1338 1338
 
1339
-			arsort($values,SORT_NUMERIC);
1339
+			arsort($values, SORT_NUMERIC);
1340 1340
 			$value = key($values);
1341 1341
 			$num = current($values);
1342
-			if ($value && $num / (double) count($contacts) >= $this->org_common_factor)
1342
+			if ($value && $num / (double)count($contacts) >= $this->org_common_factor)
1343 1343
 			{
1344
-				if (!in_array($name,$csvs))
1344
+				if (!in_array($name, $csvs))
1345 1345
 				{
1346 1346
 					$org[$name] = $value;
1347 1347
 				}
@@ -1350,12 +1350,12 @@  discard block
 block discarded – undo
1350 1350
 					$org[$name] = array();
1351 1351
 					foreach ($values as $value => $num)
1352 1352
 					{
1353
-						if ($value && $num / (double) count($contacts) >= $this->org_common_factor)
1353
+						if ($value && $num / (double)count($contacts) >= $this->org_common_factor)
1354 1354
 						{
1355 1355
 							$org[$name][] = $value;
1356 1356
 						}
1357 1357
 					}
1358
-					$org[$name] = implode(',',$org[$name]);
1358
+					$org[$name] = implode(',', $org[$name]);
1359 1359
 				}
1360 1360
 			}
1361 1361
 		}
@@ -1369,10 +1369,10 @@  discard block
 block discarded – undo
1369 1369
 	 * @param array $fields field-name => value pairs
1370 1370
 	 * @return array with contacts
1371 1371
 	 */
1372
-	function org_similar($org_name,$fields)
1372
+	function org_similar($org_name, $fields)
1373 1373
 	{
1374 1374
 		$criteria = array();
1375
-		foreach($this->org_fields as $name)
1375
+		foreach ($this->org_fields as $name)
1376 1376
 		{
1377 1377
 			if (isset($fields[$name]))
1378 1378
 			{
@@ -1386,7 +1386,7 @@  discard block
 block discarded – undo
1386 1386
 				}
1387 1387
 			}
1388 1388
 		}
1389
-		return parent::search($criteria,false,'n_family,n_given','','',false,'OR',false,array('org_name'=>$org_name));
1389
+		return parent::search($criteria, false, 'n_family,n_given', '', '', false, 'OR', false, array('org_name'=>$org_name));
1390 1390
 	}
1391 1391
 
1392 1392
 	/**
@@ -1397,10 +1397,10 @@  discard block
 block discarded – undo
1397 1397
 	 * @param boolean $only_org_fields =true check and return only org_fields, default true
1398 1398
 	 * @return array with field-name => value from $from
1399 1399
 	 */
1400
-	function changed_fields($from,$to,$only_org_fields=true)
1400
+	function changed_fields($from, $to, $only_org_fields = true)
1401 1401
 	{
1402 1402
 		// we only care about countryname, if contrycode is empty
1403
-		foreach(array(
1403
+		foreach (array(
1404 1404
 			'adr_one_countryname' => 'adr_one_countrycode',
1405 1405
 			'adr_two_countryname' => 'adr_one_countrycode',
1406 1406
 		) as $name => $code)
@@ -1409,13 +1409,13 @@  discard block
 block discarded – undo
1409 1409
 			if (!empty($to[$code])) $to[$name] = '';
1410 1410
 		}
1411 1411
 		$changed = array();
1412
-		foreach($only_org_fields ? $this->org_fields : array_keys($this->contact_fields) as $name)
1412
+		foreach ($only_org_fields ? $this->org_fields : array_keys($this->contact_fields) as $name)
1413 1413
 		{
1414
-			if (in_array($name,array('modified','modifier')))	// never count these
1414
+			if (in_array($name, array('modified', 'modifier')))	// never count these
1415 1415
 			{
1416 1416
 				continue;
1417 1417
 			}
1418
-			if ((string) $from[$name] != (string) $to[$name])
1418
+			if ((string)$from[$name] != (string)$to[$name])
1419 1419
 			{
1420 1420
 				$changed[$name] = $from[$name];
1421 1421
 			}
@@ -1432,35 +1432,35 @@  discard block
 block discarded – undo
1432 1432
 	 * @param array $members =null org-members to change, default null --> function queries them itself
1433 1433
 	 * @return array/boolean (changed-members,changed-fields,failed-members) or false if no org_fields changed or no (other) members matching that fields
1434 1434
 	 */
1435
-	function change_org($org_name,$from,$to,$members=null)
1435
+	function change_org($org_name, $from, $to, $members = null)
1436 1436
 	{
1437
-		if (!($changed = $this->changed_fields($from,$to,true))) return false;
1437
+		if (!($changed = $this->changed_fields($from, $to, true))) return false;
1438 1438
 
1439 1439
 		if (is_null($members) || !is_array($members))
1440 1440
 		{
1441
-			$members = $this->org_similar($org_name,$changed);
1441
+			$members = $this->org_similar($org_name, $changed);
1442 1442
 		}
1443 1443
 		if (!$members) return false;
1444 1444
 
1445 1445
 		$ids = array();
1446
-		foreach($members as $member)
1446
+		foreach ($members as $member)
1447 1447
 		{
1448 1448
 			$ids[] = $member['id'];
1449 1449
 		}
1450 1450
 		$customfields = $this->read_customfields($ids);
1451 1451
 
1452 1452
 		$changed_members = $changed_fields = $failed_members = 0;
1453
-		foreach($members as $member)
1453
+		foreach ($members as $member)
1454 1454
 		{
1455 1455
 			if (isset($customfields[$member['id']]))
1456 1456
 			{
1457
-				foreach(array_keys($this->customfields) as $name)
1457
+				foreach (array_keys($this->customfields) as $name)
1458 1458
 				{
1459 1459
 					$member['#'.$name] = $customfields[$member['id']][$name];
1460 1460
 				}
1461 1461
 			}
1462 1462
 			$fields = 0;
1463
-			foreach($changed as $name => $value)
1463
+			foreach ($changed as $name => $value)
1464 1464
 			{
1465 1465
 				if ((string)$value == (string)$member[$name])
1466 1466
 				{
@@ -1470,7 +1470,7 @@  discard block
 block discarded – undo
1470 1470
 			}
1471 1471
 			if ($fields)
1472 1472
 			{
1473
-				if (!$this->check_perms(Acl::EDIT,$member) || !$this->save($member))
1473
+				if (!$this->check_perms(Acl::EDIT, $member) || !$this->save($member))
1474 1474
 				{
1475 1475
 					++$failed_members;
1476 1476
 				}
@@ -1481,7 +1481,7 @@  discard block
 block discarded – undo
1481 1481
 				}
1482 1482
 			}
1483 1483
 		}
1484
-		return array($changed_members,$changed_fields,$failed_members);
1484
+		return array($changed_members, $changed_fields, $failed_members);
1485 1485
 	}
1486 1486
 
1487 1487
 	/**
@@ -1508,20 +1508,20 @@  discard block
 block discarded – undo
1508 1508
 			if ($contact['n_fileas']) return $contact['n_fileas'];
1509 1509
 			$type = null;
1510 1510
 		}
1511
-		$title =  $this->fileas($contact,$type);
1511
+		$title = $this->fileas($contact, $type);
1512 1512
 
1513 1513
 		if (!empty($this->prefs['link_title_cf']))
1514 1514
 		{
1515 1515
 			$field_list = is_string($this->prefs['link_title_cf']) ? explode(',', $this->prefs['link_title_cf']) : $this->prefs['link_title_cf'];
1516 1516
 			foreach ($field_list as $field)
1517 1517
 			{
1518
-				if($contact['#'.$field])
1518
+				if ($contact['#'.$field])
1519 1519
 				{
1520
-				   $title .= ', ' . $contact['#'.$field];
1520
+				   $title .= ', '.$contact['#'.$field];
1521 1521
 				}
1522 1522
 			}
1523 1523
 		}
1524
-		return $title ;
1524
+		return $title;
1525 1525
 	}
1526 1526
 
1527 1527
 	/**
@@ -1535,21 +1535,21 @@  discard block
 block discarded – undo
1535 1535
 	function link_titles(array $ids)
1536 1536
 	{
1537 1537
 		$titles = array();
1538
-		if (($contacts =& $this->search(array('contact_id' => $ids),false,'',$extra_cols='','',False,'AND',False,array('tid'=>null))))
1538
+		if (($contacts = & $this->search(array('contact_id' => $ids), false, '', $extra_cols = '', '', False, 'AND', False, array('tid'=>null))))
1539 1539
 		{
1540 1540
 			$ids = array();
1541
-			foreach($contacts as $contact)
1541
+			foreach ($contacts as $contact)
1542 1542
 			{
1543 1543
 				$ids[] = $contact['id'];
1544 1544
 			}
1545 1545
 			$cfs = $this->read_customfields($ids);
1546
-			foreach($contacts as $contact)
1546
+			foreach ($contacts as $contact)
1547 1547
 			{
1548
-			   	$titles[$contact['id']] = $this->link_title($contact+(array)$cfs[$contact['id']]);
1548
+			   	$titles[$contact['id']] = $this->link_title($contact + (array)$cfs[$contact['id']]);
1549 1549
 			}
1550 1550
 		}
1551 1551
 		// we assume all not returned contacts are not readable for the user (as we report all deleted contacts to egw_link)
1552
-		foreach($ids as $id)
1552
+		foreach ($ids as $id)
1553 1553
 		{
1554 1554
 			if (!isset($titles[$id]))
1555 1555
 			{
@@ -1576,23 +1576,23 @@  discard block
 block discarded – undo
1576 1576
 		{
1577 1577
 			$criteria = is_array($pattern) ? $pattern['search'] : $pattern;
1578 1578
 		}
1579
-		if($options['start'] || $options['num_rows'])
1579
+		if ($options['start'] || $options['num_rows'])
1580 1580
 		{
1581 1581
 			$limit = array($options['start'], $options['num_rows']);
1582 1582
 		}
1583 1583
 		$filter = (array)$options['filter'];
1584 1584
 		if ($GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts'] === '1') $filter['account_id'] = null;
1585
-		if (($contacts =& parent::search($criteria,false,'org_name,n_family,n_given,cat_id,contact_email','','%',false,'OR', $limit, $filter)))
1585
+		if (($contacts = & parent::search($criteria, false, 'org_name,n_family,n_given,cat_id,contact_email', '', '%', false, 'OR', $limit, $filter)))
1586 1586
 		{
1587 1587
 			$ids = array();
1588
-			foreach($contacts as $contact)
1588
+			foreach ($contacts as $contact)
1589 1589
 			{
1590 1590
 				$ids[] = $contact['id'];
1591 1591
 			}
1592 1592
 			$cfs = $this->read_customfields($ids);
1593
-			foreach($contacts as $contact)
1593
+			foreach ($contacts as $contact)
1594 1594
 			{
1595
-				$result[$contact['id']] = $this->link_title($contact+(array)$cfs[$contact['id']]);
1595
+				$result[$contact['id']] = $this->link_title($contact + (array)$cfs[$contact['id']]);
1596 1596
 				// make sure to return a correctly quoted rfc822 address, if requested
1597 1597
 				if ($options['type'] === 'email')
1598 1598
 				{
@@ -1633,7 +1633,7 @@  discard block
 block discarded – undo
1633 1633
 		// let link query know, to append email to list
1634 1634
 		$options['type'] = 'email';
1635 1635
 
1636
-		return $this->link_query($pattern,$options);
1636
+		return $this->link_query($pattern, $options);
1637 1637
 	}
1638 1638
 
1639 1639
 	/**
@@ -1647,14 +1647,14 @@  discard block
 block discarded – undo
1647 1647
 		if (!$ids) return null;
1648 1648
 
1649 1649
 		$data = array();
1650
-		foreach(!is_array($ids) ? array($ids) : $ids as $id)
1650
+		foreach (!is_array($ids) ? array($ids) : $ids as $id)
1651 1651
 		{
1652 1652
 			if (!($contact = $this->read($id))) continue;
1653 1653
 
1654 1654
 			$data[] = array(
1655 1655
 				'res_id' => $id,
1656 1656
 				'email' => $contact['email'] ? $contact['email'] : $contact['email_home'],
1657
-				'rights' => Acl::CUSTOM1|Acl::CUSTOM3,	// calendar_bo::ACL_READ_FOR_PARTICIPANTS|ACL_INVITE
1657
+				'rights' => Acl::CUSTOM1|Acl::CUSTOM3, // calendar_bo::ACL_READ_FOR_PARTICIPANTS|ACL_INVITE
1658 1658
 				'name' => $this->link_title($contact),
1659 1659
 				'cn' => trim($contact['n_given'].' '.$contact['n_family']),
1660 1660
 			);
@@ -1669,37 +1669,37 @@  discard block
 block discarded – undo
1669 1669
 	 * @param boolean $extra_title =true if true, use a short date only title and put the full title as extra_title (tooltip)
1670 1670
 	 * @return array
1671 1671
 	 */
1672
-	function read_calendar($uids,$extra_title=true)
1672
+	function read_calendar($uids, $extra_title = true)
1673 1673
 	{
1674 1674
 		if (!$GLOBALS['egw_info']['user']['apps']['calendar']) return array();
1675 1675
 
1676 1676
 		$split_uids = array();
1677 1677
 		$events = array();
1678 1678
 
1679
-		foreach($uids as $id => $uid)
1679
+		foreach ($uids as $id => $uid)
1680 1680
 		{
1681 1681
 			$type = is_numeric($uid[0]) ? 'u' : $uid[0];
1682
-			if($GLOBALS['egw_info']['server']['disable_event_column'] == 'contacts' && $type == 'u')
1682
+			if ($GLOBALS['egw_info']['server']['disable_event_column'] == 'contacts' && $type == 'u')
1683 1683
 			{
1684 1684
 				continue;
1685 1685
 			}
1686 1686
 			$split_uids[$type][$id] = str_replace($type, '', $uid);
1687 1687
 		}
1688 1688
 
1689
-		foreach($split_uids as $type => $s_uids)
1689
+		foreach ($split_uids as $type => $s_uids)
1690 1690
 		{
1691 1691
 			$events += $this->read_calendar_type($s_uids, $type, $extra_title);
1692 1692
 		}
1693 1693
 		return $events;
1694 1694
 	}
1695 1695
 
1696
-	private function read_calendar_type($uids, $type='c', $extra_title = true)
1696
+	private function read_calendar_type($uids, $type = 'c', $extra_title = true)
1697 1697
 	{
1698 1698
 		$calendars = array();
1699 1699
 		$bocal = new calendar_bo();
1700
-		$type_field = $type=='u' ? 'account_id' : 'contact_id';
1700
+		$type_field = $type == 'u' ? 'account_id' : 'contact_id';
1701 1701
 		$type_field_varchar = $this->db->to_varchar($type_field);
1702
-		$concat_start_id_recurrance = $this->db->concat('cal_start',"':'",'egw_cal_user.cal_id',"':'",'cal_recur_date');
1702
+		$concat_start_id_recurrance = $this->db->concat('cal_start', "':'", 'egw_cal_user.cal_id', "':'", 'cal_recur_date');
1703 1703
 		$now = $this->db->unix_timestamp('NOW()');
1704 1704
 		$sql = "SELECT n_fn,org_name,$type_field AS user_id,
1705 1705
 			(
@@ -1708,7 +1708,7 @@  discard block
 block discarded – undo
1708 1708
 				JOIN egw_cal_dates on egw_cal_dates.cal_id=egw_cal_user.cal_id and (cal_recur_date=0 or cal_recur_date=cal_start)
1709 1709
 				JOIN egw_cal ON egw_cal.cal_id=egw_cal_user.cal_id AND egw_cal.cal_deleted IS NULL
1710 1710
 				WHERE cal_user_type='$type' and cal_user_id=$type_field_varchar and cal_start < $now";
1711
-		if ( !$GLOBALS['egw_info']['user']['preferences']['calendar']['show_rejected'])
1711
+		if (!$GLOBALS['egw_info']['user']['preferences']['calendar']['show_rejected'])
1712 1712
 		{
1713 1713
 			$sql .= " AND egw_cal_user.cal_status != 'R'";
1714 1714
 		}
@@ -1721,7 +1721,7 @@  discard block
 block discarded – undo
1721 1721
 				JOIN egw_cal_dates on egw_cal_dates.cal_id=egw_cal_user.cal_id and (cal_recur_date=0 or cal_recur_date=cal_start)
1722 1722
 				JOIN egw_cal ON egw_cal.cal_id=egw_cal_user.cal_id AND egw_cal.cal_deleted IS NULL
1723 1723
 				WHERE cal_user_type='$type' and cal_user_id=$type_field_varchar and cal_start > $now";
1724
-		if ( !$GLOBALS['egw_info']['user']['preferences']['calendar']['show_rejected'])
1724
+		if (!$GLOBALS['egw_info']['user']['preferences']['calendar']['show_rejected'])
1725 1725
 		{
1726 1726
 			$sql .= " AND egw_cal_user.cal_status != 'R'";
1727 1727
 		}
@@ -1732,7 +1732,7 @@  discard block
 block discarded – undo
1732 1732
 			WHERE '.$this->db->expression('egw_addressbook', array($type_field => $uids));
1733 1733
 
1734 1734
 
1735
-		$contacts =& $this->db->query($sql, __LINE__, __FILE__);
1735
+		$contacts = & $this->db->query($sql, __LINE__, __FILE__);
1736 1736
 
1737 1737
 		if (!$contacts) return array();
1738 1738
 
@@ -1742,11 +1742,11 @@  discard block
 block discarded – undo
1742 1742
 			list($start, $cal_id, $recur_date) = explode(':', $contact[$key.'_event']);
1743 1743
 
1744 1744
 			$link = array(
1745
-				'id' => $cal_id,//.':'.$start,
1745
+				'id' => $cal_id, //.':'.$start,
1746 1746
 				'app' => 'calendar',
1747
-				'title' => $bocal->link_title($cal_id . ($start ? '-'.$start : '')),
1747
+				'title' => $bocal->link_title($cal_id.($start ? '-'.$start : '')),
1748 1748
 				'extra_args' => array(
1749
-					'date' => \EGroupware\Api\DateTime::server2user($start,\EGroupware\Api\DateTime::ET2),
1749
+					'date' => \EGroupware\Api\DateTime::server2user($start, \EGroupware\Api\DateTime::ET2),
1750 1750
 					'exception'=> 1
1751 1751
 				),
1752 1752
 			);
@@ -1755,18 +1755,18 @@  discard block
 block discarded – undo
1755 1755
 				$link['extra_title'] = $link['title'];
1756 1756
 				$link['title'] = \EGroupware\Api\DateTime::server2user($start, true);
1757 1757
 			}
1758
-			$user_id = ($type == 'u' ? '' : $type) . $contact['user_id'];
1758
+			$user_id = ($type == 'u' ? '' : $type).$contact['user_id'];
1759 1759
 			$calendars[$user_id][$key.'_event'] = $start;
1760 1760
 			$calendars[$user_id][$key.'_link'] = $link;
1761 1761
 		};
1762 1762
 
1763
-		foreach($contacts as $contact)
1763
+		foreach ($contacts as $contact)
1764 1764
 		{
1765
-			if($contact['last_event'])
1765
+			if ($contact['last_event'])
1766 1766
 			{
1767 1767
 				$do_event('last', $contact);
1768 1768
 			}
1769
-			if($contact['next_event'])
1769
+			if ($contact['next_event'])
1770 1770
 			{
1771 1771
 				$do_event('next', $contact);
1772 1772
 			}
@@ -1783,7 +1783,7 @@  discard block
 block discarded – undo
1783 1783
 	 */
1784 1784
 	public function read_birthdays($addressbook, $year)
1785 1785
 	{
1786
-		if (($birthdays = Cache::getInstance(__CLASS__,"birthday-$year-$addressbook-".$GLOBALS['egw_info']['user']['preferences']['common']['lang'])) !== null)
1786
+		if (($birthdays = Cache::getInstance(__CLASS__, "birthday-$year-$addressbook-".$GLOBALS['egw_info']['user']['preferences']['common']['lang'])) !== null)
1787 1787
 		{
1788 1788
 			return $birthdays;
1789 1789
 		}
@@ -1794,7 +1794,7 @@  discard block
 block discarded – undo
1794 1794
 			'n_family' => "!''",
1795 1795
 			'bday' => "!''",
1796 1796
 		);
1797
-		$bdays =& $this->search('',array('id','n_family','n_given','n_prefix','n_middle','bday'),
1797
+		$bdays = & $this->search('', array('id', 'n_family', 'n_given', 'n_prefix', 'n_middle', 'bday'),
1798 1798
 			'contact_bday ASC', '', '', false, 'AND', false, $filter);
1799 1799
 
1800 1800
 		if ($bdays)
@@ -1802,35 +1802,34 @@  discard block
 block discarded – undo
1802 1802
 			// sort by month and day only
1803 1803
 			usort($bdays, function($a, $b)
1804 1804
 			{
1805
-				return (int) $a['bday'] == (int) $b['bday'] ?
1806
-					strcmp($a['bday'], $b['bday']) :
1807
-					(int) $a['bday'] - (int) $b['bday'];
1805
+				return (int)$a['bday'] == (int)$b['bday'] ?
1806
+					strcmp($a['bday'], $b['bday']) : (int)$a['bday'] - (int)$b['bday'];
1808 1807
 			});
1809
-			foreach($bdays as $pers)
1808
+			foreach ($bdays as $pers)
1810 1809
 			{
1811
-				if (empty($pers['bday']) || $pers['bday']=='0000-00-00 0' || $pers['bday']=='0000-00-00' || $pers['bday']=='0.0.00')
1810
+				if (empty($pers['bday']) || $pers['bday'] == '0000-00-00 0' || $pers['bday'] == '0000-00-00' || $pers['bday'] == '0.0.00')
1812 1811
 				{
1813 1812
 					//error_log(__METHOD__.__LINE__.' Skipping entry for invalid birthday:'.array2string($pers));
1814 1813
 					continue;
1815 1814
 				}
1816
-				list($y,$m,$d) = explode('-',$pers['bday']);
1815
+				list($y, $m, $d) = explode('-', $pers['bday']);
1817 1816
 				if ($y > $year)
1818 1817
 				{
1819 1818
 					// not yet born
1820 1819
 					continue;
1821 1820
 				}
1822
-				$birthdays[sprintf('%04d%02d%02d',$year,$m,$d)][] = array(
1821
+				$birthdays[sprintf('%04d%02d%02d', $year, $m, $d)][] = array(
1823 1822
 					'day'       => $d,
1824 1823
 					'month'     => $m,
1825 1824
 					'occurence' => 0,
1826
-					'name'      => implode(' ', array_filter(array(lang('Birthday'),($pers['n_given'] ? $pers['n_given'] : $pers['n_prefix']), $pers['n_middle'],
1827
-						$pers['n_family'], ($GLOBALS['egw_info']['server']['hide_birthdays'] == 'age' ? ($year - $y): '')))).
1828
-						($y && in_array($GLOBALS['egw_info']['server']['hide_birthdays'], array('','age')) ? ' ('.$y.')' : ''),
1829
-					'birthyear' => $y,	// this can be used to identify birthdays from holidays
1825
+					'name'      => implode(' ', array_filter(array(lang('Birthday'), ($pers['n_given'] ? $pers['n_given'] : $pers['n_prefix']), $pers['n_middle'],
1826
+						$pers['n_family'], ($GLOBALS['egw_info']['server']['hide_birthdays'] == 'age' ? ($year - $y) : '')))).
1827
+						($y && in_array($GLOBALS['egw_info']['server']['hide_birthdays'], array('', 'age')) ? ' ('.$y.')' : ''),
1828
+					'birthyear' => $y, // this can be used to identify birthdays from holidays
1830 1829
 				);
1831 1830
 			}
1832 1831
 		}
1833
-		Cache::setInstance(__CLASS__,"birthday-$year-$addressbook-".$GLOBALS['egw_info']['user']['preferences']['common']['lang'], $birthdays, self::BIRTHDAY_CACHE_TIME);
1832
+		Cache::setInstance(__CLASS__, "birthday-$year-$addressbook-".$GLOBALS['egw_info']['user']['preferences']['common']['lang'], $birthdays, self::BIRTHDAY_CACHE_TIME);
1834 1833
 		return $birthdays;
1835 1834
 	}
1836 1835
 
@@ -1853,7 +1852,7 @@  discard block
 block discarded – undo
1853 1852
 	{
1854 1853
 		// get all cats if you want to drop sub cats
1855 1854
 		$drop_subs = ($data['drop_subs'] && !$data['modify_subs']);
1856
-		if($drop_subs)
1855
+		if ($drop_subs)
1857 1856
 		{
1858 1857
 			$cats = new Categories('', 'addressbook');
1859 1858
 			$cat_ids = $cats->return_all_children($data['cat_id']);
@@ -1864,14 +1863,14 @@  discard block
 block discarded – undo
1864 1863
 		}
1865 1864
 
1866 1865
 		// Get addresses that use the category
1867
-		@set_time_limit( 0 );
1868
-		foreach($cat_ids as $cat_id)
1866
+		@set_time_limit(0);
1867
+		foreach ($cat_ids as $cat_id)
1869 1868
 		{
1870 1869
 			if (($ids = $this->search(array('cat_id' => $cat_id), false)))
1871 1870
 			{
1872
-				foreach($ids as &$info)
1871
+				foreach ($ids as &$info)
1873 1872
 				{
1874
-					$info['cat_id'] = implode(',',array_diff(explode(',',$info['cat_id']), $cat_ids));
1873
+					$info['cat_id'] = implode(',', array_diff(explode(',', $info['cat_id']), $cat_ids));
1875 1874
 					$this->save($info);
1876 1875
 				}
1877 1876
 			}
@@ -1893,14 +1892,14 @@  discard block
 block discarded – undo
1893 1892
 		$account = null;
1894 1893
 		$custom_fields = Storage\Customfields::get('addressbook', true);
1895 1894
 		$custom_field_list = $this->read_customfields($ids);
1896
-		foreach(parent::search(array('id'=>$ids),false) as $contact)	// $this->search calls the extended search from ui!
1895
+		foreach (parent::search(array('id'=>$ids), false) as $contact)	// $this->search calls the extended search from ui!
1897 1896
 		{
1898 1897
 			if ($contact['account_id'])
1899 1898
 			{
1900 1899
 				if (!is_null($account))
1901 1900
 				{
1902 1901
 					echo $this->error = 'Can not merge more then one account!';
1903
-					return false;	// we dont deal with two accounts!
1902
+					return false; // we dont deal with two accounts!
1904 1903
 				}
1905 1904
 				$account = $contact;
1906 1905
 				continue;
@@ -1908,7 +1907,7 @@  discard block
 block discarded – undo
1908 1907
 			// Add in custom fields
1909 1908
 			if (is_array($custom_field_list[$contact['id']])) $contact = array_merge($contact, $custom_field_list[$contact['id']]);
1910 1909
 
1911
-			$pos = array_search($contact['id'],$ids);
1910
+			$pos = array_search($contact['id'], $ids);
1912 1911
 			$contacts[$pos] = $contact;
1913 1912
 		}
1914 1913
 		if (!is_null($account))	// we found an account, so we merge the contacts into it
@@ -1921,38 +1920,38 @@  discard block
 block discarded – undo
1921 1920
 			$target = $contacts[0];
1922 1921
 			unset($contacts[0]);
1923 1922
 		}
1924
-		if (!$this->check_perms(Acl::EDIT,$target))
1923
+		if (!$this->check_perms(Acl::EDIT, $target))
1925 1924
 		{
1926 1925
 			echo $this->error = 'No edit permission for the target contact!';
1927 1926
 			return 0;
1928 1927
 		}
1929
-		foreach($contacts as $contact)
1928
+		foreach ($contacts as $contact)
1930 1929
 		{
1931
-			foreach($contact as $name => $value)
1930
+			foreach ($contact as $name => $value)
1932 1931
 			{
1933 1932
 				if (!$value) continue;
1934 1933
 
1935
-				switch($name)
1934
+				switch ($name)
1936 1935
 				{
1937 1936
 					case 'id':
1938 1937
 					case 'tid':
1939 1938
 					case 'owner':
1940 1939
 					case 'private':
1941 1940
 					case 'etag';
1942
-						break;	// ignored
1941
+						break; // ignored
1943 1942
 
1944 1943
 					case 'cat_id':	// cats are all merged together
1945
-						if (!is_array($target['cat_id'])) $target['cat_id'] = $target['cat_id'] ? explode(',',$target['cat_id']) : array();
1946
-						$target['cat_id'] = array_unique(array_merge($target['cat_id'],is_array($value)?$value:explode(',',$value)));
1944
+						if (!is_array($target['cat_id'])) $target['cat_id'] = $target['cat_id'] ? explode(',', $target['cat_id']) : array();
1945
+						$target['cat_id'] = array_unique(array_merge($target['cat_id'], is_array($value) ? $value : explode(',', $value)));
1947 1946
 						break;
1948 1947
 
1949 1948
 					default:
1950 1949
 						// Multi-select custom fields can also be merged
1951
-						if($name[0] == '#') {
1950
+						if ($name[0] == '#') {
1952 1951
 							$c_name = substr($name, 1);
1953
-							if($custom_fields[$c_name]['type'] == 'select' && $custom_fields[$c_name]['rows'] > 1) {
1954
-								if (!is_array($target[$name])) $target[$name] = $target[$name] ? explode(',',$target[$name]) : array();
1955
-								$target[$name] = implode(',',array_unique(array_merge($target[$name],is_array($value)?$value:explode(',',$value))));
1952
+							if ($custom_fields[$c_name]['type'] == 'select' && $custom_fields[$c_name]['rows'] > 1) {
1953
+								if (!is_array($target[$name])) $target[$name] = $target[$name] ? explode(',', $target[$name]) : array();
1954
+								$target[$name] = implode(',', array_unique(array_merge($target[$name], is_array($value) ? $value : explode(',', $value))));
1956 1955
 							}
1957 1956
 						}
1958 1957
 						if (!$target[$name]) $target[$name] = $value;
@@ -1962,7 +1961,7 @@  discard block
 block discarded – undo
1962 1961
 
1963 1962
 			// Merge distribution lists
1964 1963
 			$lists = $this->read_distributionlist(array($contact['id']));
1965
-			foreach($lists[$contact['id']] as $list_id => $list_name)
1964
+			foreach ($lists[$contact['id']] as $list_id => $list_name)
1966 1965
 			{
1967 1966
 				parent::add2list($target['id'], $list_id);
1968 1967
 			}
@@ -1970,29 +1969,29 @@  discard block
 block discarded – undo
1970 1969
 		if (!$this->save($target)) return 0;
1971 1970
 
1972 1971
 		$success = 1;
1973
-		foreach($contacts as $contact)
1972
+		foreach ($contacts as $contact)
1974 1973
 		{
1975
-			if (!$this->check_perms(Acl::DELETE,$contact))
1974
+			if (!$this->check_perms(Acl::DELETE, $contact))
1976 1975
 			{
1977 1976
 				continue;
1978 1977
 			}
1979
-			foreach(Link::get_links('addressbook',$contact['id']) as $data)
1978
+			foreach (Link::get_links('addressbook', $contact['id']) as $data)
1980 1979
 			{
1981 1980
 				//_debug_array(array('function'=>__METHOD__,'line'=>__LINE__,'app'=>'addressbook','id'=>$contact['id'],'data:'=>$data,'target'=>$target['id']));
1982 1981
 				// info_from and info_link_id (main link)
1983
-				$newlinkID = Link::link('addressbook',$target['id'],$data['app'],$data['id'],$data['remark'],$target['owner']);
1982
+				$newlinkID = Link::link('addressbook', $target['id'], $data['app'], $data['id'], $data['remark'], $target['owner']);
1984 1983
 				//_debug_array(array('newLinkID'=>$newlinkID));
1985 1984
 				if ($newlinkID)
1986 1985
 				{
1987 1986
 					// update egw_infolog set info_link_id=$newlinkID where info_id=$data['id'] and info_link_id=$data['link_id']
1988
-					if ($data['app']=='infolog')
1987
+					if ($data['app'] == 'infolog')
1989 1988
 					{
1990
-						$this->db->update('egw_infolog',array(
1989
+						$this->db->update('egw_infolog', array(
1991 1990
 								'info_link_id' => $newlinkID
1992
-							),array(
1991
+							), array(
1993 1992
 								'info_id' => $data['id'],
1994 1993
 								'info_link_id' => $data['link_id']
1995
-							),__LINE__,__FILE__,'infolog');
1994
+							), __LINE__, __FILE__, 'infolog');
1996 1995
 					}
1997 1996
 					unset($newlinkID);
1998 1997
 				}
@@ -2015,7 +2014,7 @@  discard block
 block discarded – undo
2015 2014
 	protected function merge_calendar($old_id, $new_id)
2016 2015
 	{
2017 2016
 		static $bo;
2018
-		if(!is_object($bo))
2017
+		if (!is_object($bo))
2019 2018
 		{
2020 2019
 			$bo = new \calendar_boupdate();
2021 2020
 		}
@@ -2023,7 +2022,7 @@  discard block
 block discarded – undo
2023 2022
 		// Find all events with this contact
2024 2023
 		$events = $bo->search(array('users' => $old_id, 'ignore_acl' => true));
2025 2024
 
2026
-		foreach($events as $event)
2025
+		foreach ($events as $event)
2027 2026
 		{
2028 2027
 			$event['participants'][$new_id] = $event['participants'][$old_id];
2029 2028
 			unset($event['participants'][$old_id]);
@@ -2048,14 +2047,14 @@  discard block
 block discarded – undo
2048 2047
 	 * @param int $owner =null
2049 2048
 	 * @return boolean
2050 2049
 	 */
2051
-	function check_list($list,$required,$owner=null)
2050
+	function check_list($list, $required, $owner = null)
2052 2051
 	{
2053 2052
 		if ($list && ($list_data = $this->read_list($list)))
2054 2053
 		{
2055 2054
 			$owner = $list_data['list_owner'];
2056 2055
 		}
2057 2056
 		//error_log(__METHOD__."($list, $required, $owner) grants[$owner]=".$this->grants[$owner]." returning ".array2string(!!($this->grants[$owner] & $required)));
2058
-		return !!($this->grants[$owner] & $required);
2057
+		return !!($this->grants[$owner]&$required);
2059 2058
 	}
2060 2059
 
2061 2060
 	/**
@@ -2067,17 +2066,17 @@  discard block
 block discarded – undo
2067 2066
 	 * @param array &$data=array() values for keys 'list_uid', 'list_carddav_name', 'list_name'
2068 2067
 	 * @return int|boolean integer list_id or false on error
2069 2068
 	 */
2070
-	function add_list($keys,$owner,$contacts=array(),array &$data=array())
2069
+	function add_list($keys, $owner, $contacts = array(), array &$data = array())
2071 2070
 	{
2072
-		if (!$this->check_list(null,Acl::ADD|Acl::EDIT,$owner)) return false;
2071
+		if (!$this->check_list(null, Acl::ADD|Acl::EDIT, $owner)) return false;
2073 2072
 
2074 2073
 		try {
2075
-			$ret = parent::add_list($keys,$owner,$contacts,$data);
2074
+			$ret = parent::add_list($keys, $owner, $contacts, $data);
2076 2075
 			if ($ret) unset(self::$list_cache[$ret]);
2077 2076
 		}
2078 2077
 		// catch sql error, as creating same name&owner list gives a sql error doublicate key
2079
-		catch(Db\Exception\InvalidSql $e) {
2080
-			unset($e);	// not used
2078
+		catch (Db\Exception\InvalidSql $e) {
2079
+			unset($e); // not used
2081 2080
 			return false;
2082 2081
 		}
2083 2082
 		return $ret;
@@ -2091,13 +2090,13 @@  discard block
 block discarded – undo
2091 2090
 	 * @param array $existing =null array of existing contact-id(s) of list, to not reread it, eg. array()
2092 2091
 	 * @return false on error
2093 2092
 	 */
2094
-	function add2list($contact,$list,array $existing=null)
2093
+	function add2list($contact, $list, array $existing = null)
2095 2094
 	{
2096
-		if (!$this->check_list($list,Acl::EDIT)) return false;
2095
+		if (!$this->check_list($list, Acl::EDIT)) return false;
2097 2096
 
2098 2097
 		unset(self::$list_cache[$list]);
2099 2098
 
2100
-		return parent::add2list($contact,$list,$existing);
2099
+		return parent::add2list($contact, $list, $existing);
2101 2100
 	}
2102 2101
 
2103 2102
 	/**
@@ -2107,9 +2106,9 @@  discard block
 block discarded – undo
2107 2106
 	 * @param int $list list-id
2108 2107
 	 * @return false on error
2109 2108
 	 */
2110
-	function remove_from_list($contact,$list=null)
2109
+	function remove_from_list($contact, $list = null)
2111 2110
 	{
2112
-		if ($list && !$this->check_list($list,Acl::EDIT)) return false;
2111
+		if ($list && !$this->check_list($list, Acl::EDIT)) return false;
2113 2112
 
2114 2113
 		if ($list)
2115 2114
 		{
@@ -2120,7 +2119,7 @@  discard block
 block discarded – undo
2120 2119
 			self::$list_cache = array();
2121 2120
 		}
2122 2121
 
2123
-		return parent::remove_from_list($contact,$list);
2122
+		return parent::remove_from_list($contact, $list);
2124 2123
 	}
2125 2124
 
2126 2125
 	/**
@@ -2131,7 +2130,7 @@  discard block
 block discarded – undo
2131 2130
 	 */
2132 2131
 	function delete_list($list)
2133 2132
 	{
2134
-		foreach((array)$list as $l)
2133
+		foreach ((array)$list as $l)
2135 2134
 		{
2136 2135
 			if (!$this->check_list($l, Acl::DELETE)) return false;
2137 2136
 
@@ -2169,7 +2168,7 @@  discard block
 block discarded – undo
2169 2168
 	{
2170 2169
 		$code = Country::country_code($country);
2171 2170
 
2172
-		switch($code)
2171
+		switch ($code)
2173 2172
 		{
2174 2173
 			case 'AU':
2175 2174
 			case 'CA':
@@ -2233,12 +2232,12 @@  discard block
 block discarded – undo
2233 2232
 	 *  by the ones the user normally does not see due to category permissions - used to preserve categories
2234 2233
 	 * @return array category ids (found, added and preserved categories)
2235 2234
 	 */
2236
-	function find_or_add_categories($catname_list, $contact_id=null)
2235
+	function find_or_add_categories($catname_list, $contact_id = null)
2237 2236
 	{
2238 2237
 		if ($contact_id && $contact_id > 0 && ($old_contact = $this->read($contact_id)))
2239 2238
 		{
2240 2239
 			// preserve categories without users read access
2241
-			$old_categories = explode(',',$old_contact['cat_id']);
2240
+			$old_categories = explode(',', $old_contact['cat_id']);
2242 2241
 			$old_cats_preserve = array();
2243 2242
 			if (is_array($old_categories) && count($old_categories) > 0)
2244 2243
 			{
@@ -2292,15 +2291,15 @@  discard block
 block discarded – undo
2292 2291
 	{
2293 2292
 		if (!is_object($this->categories))
2294 2293
 		{
2295
-			$this->categories = new Categories($this->user,'addressbook');
2294
+			$this->categories = new Categories($this->user, 'addressbook');
2296 2295
 		}
2297 2296
 
2298 2297
 		if (!is_array($cat_id_list))
2299 2298
 		{
2300
-			$cat_id_list = explode(',',$cat_id_list);
2299
+			$cat_id_list = explode(',', $cat_id_list);
2301 2300
 		}
2302 2301
 		$cat_list = array();
2303
-		foreach($cat_id_list as $cat_id)
2302
+		foreach ($cat_id_list as $cat_id)
2304 2303
 		{
2305 2304
 			if ($cat_id && $this->categories->check_perms(Acl::READ, $cat_id) &&
2306 2305
 					($cat_name = $this->categories->id2name($cat_id)) && $cat_name != '--')
@@ -2332,14 +2331,14 @@  discard block
 block discarded – undo
2332 2331
 	 * @param boolean $relax =false if asked to relax, we only match against some key fields
2333 2332
 	 * @return array od matching contact_ids
2334 2333
 	 */
2335
-	function find_contact($contact, $relax=false)
2334
+	function find_contact($contact, $relax = false)
2336 2335
 	{
2337 2336
 		$empty_addr_one = $empty_addr_two = true;
2338 2337
 
2339 2338
 		if ($this->log)
2340 2339
 		{
2341 2340
 			error_log(__FILE__.'['.__LINE__.'] '.__METHOD__
2342
-				. '('. ($relax ? 'RELAX': 'EXACT') . ')[ContactData]:'
2341
+				. '('.($relax ? 'RELAX' : 'EXACT').')[ContactData]:'
2343 2342
 				. array2string($contact)
2344 2343
 				. "\n", 3, $this->logfile);
2345 2344
 		}
@@ -2350,7 +2349,7 @@  discard block
 block discarded – undo
2350 2349
 			if ($this->log)
2351 2350
 			{
2352 2351
 				error_log(__FILE__.'['.__LINE__.'] '.__METHOD__
2353
-					. '()[ContactID]: ' . $contact['id']
2352
+					. '()[ContactID]: '.$contact['id']
2354 2353
 					. "\n", 3, $this->logfile);
2355 2354
 			}
2356 2355
 			// We only do a simple consistency check
@@ -2368,11 +2367,11 @@  discard block
 block discarded – undo
2368 2367
 			if ($this->log)
2369 2368
 			{
2370 2369
 				error_log(__FILE__.'['.__LINE__.'] '.__METHOD__
2371
-					. '()[ContactUID]: ' . $contact['uid']
2370
+					. '()[ContactUID]: '.$contact['uid']
2372 2371
 					. "\n", 3, $this->logfile);
2373 2372
 			}
2374 2373
 			// Try the given UID first
2375
-			$criteria = array ('contact_uid' => $contact['uid']);
2374
+			$criteria = array('contact_uid' => $contact['uid']);
2376 2375
 			if (($foundContacts = parent::search($criteria)))
2377 2376
 			{
2378 2377
 				foreach ($foundContacts as $egwContact)
@@ -2455,7 +2454,7 @@  discard block
 block discarded – undo
2455 2454
 		{
2456 2455
 			error_log(__FILE__.'['.__LINE__.'] '.__METHOD__
2457 2456
 				. '()[Addressbook FIND Step 1]: '
2458
-				. 'CRITERIA = ' . array2string($criteria)
2457
+				. 'CRITERIA = '.array2string($criteria)
2459 2458
 				. "\n", 3, $this->logfile);
2460 2459
 		}
2461 2460
 
@@ -2484,7 +2483,7 @@  discard block
 block discarded – undo
2484 2483
 			{
2485 2484
 				error_log(__FILE__.'['.__LINE__.'] '.__METHOD__
2486 2485
 					. '()[Addressbook FIND Step 2]: '
2487
-					. 'CRITERIA = ' . array2string($criteria)
2486
+					. 'CRITERIA = '.array2string($criteria)
2488 2487
 					. "\n", 3, $this->logfile);
2489 2488
 			}
2490 2489
 
@@ -2508,7 +2507,7 @@  discard block
 block discarded – undo
2508 2507
 				{
2509 2508
 					error_log(__FILE__.'['.__LINE__.'] '.__METHOD__
2510 2509
 						. '()[Addressbook FIND Step 3]: '
2511
-						. 'CRITERIA = ' . array2string($criteria)
2510
+						. 'CRITERIA = '.array2string($criteria)
2512 2511
 						. "\n", 3, $this->logfile);
2513 2512
 				}
2514 2513
 
@@ -2534,7 +2533,7 @@  discard block
 block discarded – undo
2534 2533
 			{
2535 2534
 				error_log(__FILE__.'['.__LINE__.'] '.__METHOD__
2536 2535
 					. '()[Addressbook FIND Step 4]: '
2537
-					. 'CRITERIA = ' . array2string($criteria)
2536
+					. 'CRITERIA = '.array2string($criteria)
2538 2537
 					. "\n", 3, $this->logfile);
2539 2538
 			}
2540 2539
 			if (($foundContacts = parent::search($criteria, true, '', '', '', true)))
@@ -2548,7 +2547,7 @@  discard block
 block discarded – undo
2548 2547
 		if ($this->log)
2549 2548
 		{
2550 2549
 			error_log(__FILE__.'['.__LINE__.'] '.__METHOD__
2551
-				. '()[FOUND]: ' . array2string($matchingContacts)
2550
+				. '()[FOUND]: '.array2string($matchingContacts)
2552 2551
 				. "\n", 3, $this->logfile);
2553 2552
 		}
2554 2553
 		return $matchingContacts;
@@ -2565,9 +2564,9 @@  discard block
 block discarded – undo
2565 2564
 	 * @param int|array $owner =null 0=accounts, null=all addressbooks or integer account_id of user or group
2566 2565
 	 * @return string
2567 2566
 	 */
2568
-	public function get_ctag($owner=null)
2567
+	public function get_ctag($owner = null)
2569 2568
 	{
2570
-		$filter = array('tid' => null);	// tid=null --> use all entries incl. deleted (tid='D')
2569
+		$filter = array('tid' => null); // tid=null --> use all entries incl. deleted (tid='D')
2571 2570
 		// show addressbook of a single user?
2572 2571
 		if (!is_null($owner)) $filter['owner'] = $owner;
2573 2572
 
@@ -2576,11 +2575,11 @@  discard block
 block discarded – undo
2576 2575
 		{
2577 2576
 			$filter['account_id'] = null;
2578 2577
 		}
2579
-		$result = $this->search(array(),'contact_modified','contact_modified DESC','','',false,'AND',array(0,1),$filter);
2578
+		$result = $this->search(array(), 'contact_modified', 'contact_modified DESC', '', '', false, 'AND', array(0, 1), $filter);
2580 2579
 
2581 2580
 		if (!$result || !isset($result[0]['modified']))
2582 2581
 		{
2583
-			$ctag = 'empty';	// ctag for empty addressbook
2582
+			$ctag = 'empty'; // ctag for empty addressbook
2584 2583
 		}
2585 2584
 		else
2586 2585
 		{
@@ -2599,25 +2598,24 @@  discard block
 block discarded – undo
2599 2598
 	{
2600 2599
 		ob_start();
2601 2600
 
2602
-		$contact_id = isset($_GET['contact_id']) ? $_GET['contact_id'] :
2603
-			(isset($_GET['account_id']) ? 'account:'.$_GET['account_id'] : 0);
2601
+		$contact_id = isset($_GET['contact_id']) ? $_GET['contact_id'] : (isset($_GET['account_id']) ? 'account:'.$_GET['account_id'] : 0);
2604 2602
 
2605
-		if (substr($contact_id,0,8) == 'account:')
2603
+		if (substr($contact_id, 0, 8) == 'account:')
2606 2604
 		{
2607
-			$contact_id = $GLOBALS['egw']->accounts->id2name(substr($contact_id,8),'person_id');
2605
+			$contact_id = $GLOBALS['egw']->accounts->id2name(substr($contact_id, 8), 'person_id');
2608 2606
 		}
2609 2607
 
2610 2608
 		$contact = $this->read($contact_id);
2611 2609
 
2612 2610
 		if (!($contact) ||
2613
-			empty($contact['jpegphoto']) &&                           // LDAP/AD (not updated SQL)
2614
-			!(($contact['files'] & \EGroupware\Api\Contacts::FILES_BIT_PHOTO) && // new SQL in VFS
2615
-				($size = filesize($url= \EGroupware\Api\Link::vfs_path('addressbook', $contact_id, \EGroupware\Api\Contacts::FILES_PHOTO)))))
2611
+			empty($contact['jpegphoto']) && // LDAP/AD (not updated SQL)
2612
+			!(($contact['files']&\EGroupware\Api\Contacts::FILES_BIT_PHOTO) && // new SQL in VFS
2613
+				($size = filesize($url = \EGroupware\Api\Link::vfs_path('addressbook', $contact_id, \EGroupware\Api\Contacts::FILES_PHOTO)))))
2616 2614
 		{
2617 2615
 			if (is_array($contact))
2618 2616
 			{
2619 2617
 				header('Content-type: image/jpeg');
2620
-				$contact['jpegphoto'] =  \EGroupware\Api\avatar::lavatar(array(
2618
+				$contact['jpegphoto'] = \EGroupware\Api\avatar::lavatar(array(
2621 2619
 					'id' => $contact['id'],
2622 2620
 					'firstname' => $contact['n_given'],
2623 2621
 					'lastname' => $contact['n_family'])
@@ -2635,14 +2633,14 @@  discard block
 block discarded – undo
2635 2633
 			// different url with different etag parameter will force a reload
2636 2634
 			if (isset($_GET['etag']))
2637 2635
 			{
2638
-				\EGroupware\Api\Session::cache_control(30*86400);	// cache for 30 days
2636
+				\EGroupware\Api\Session::cache_control(30 * 86400); // cache for 30 days
2639 2637
 			}
2640 2638
 			// if servers send a If-None-Match header, response with 304 Not Modified, if etag matches
2641 2639
 			if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] === $etag)
2642 2640
 			{
2643 2641
 				header("HTTP/1.1 304 Not Modified");
2644 2642
 			}
2645
-			elseif(!empty($contact['jpegphoto']))
2643
+			elseif (!empty($contact['jpegphoto']))
2646 2644
 			{
2647 2645
 				header('Content-length: '.bytes($contact['jpegphoto']));
2648 2646
 				echo $contact['jpegphoto'];
@@ -2654,6 +2652,6 @@  discard block
 block discarded – undo
2654 2652
 			}
2655 2653
 			exit();
2656 2654
 		}
2657
-		Egw::redirect(\EGroupware\Api\Image::find('addressbook','photo'));
2655
+		Egw::redirect(\EGroupware\Api\Image::find('addressbook', 'photo'));
2658 2656
 	}
2659 2657
 }
Please login to merge, or discard this patch.
admin/inc/class.admin_cmd.inc.php 2 patches
Spacing   +125 added lines, -126 removed lines patch added patch discarded remove patch
@@ -60,14 +60,14 @@  discard block
 block discarded – undo
60 60
 	const successful = 2;
61 61
 	const failed     = 3;
62 62
 	const pending    = 4;
63
-	const queued     = 5;	// command waits to be fetched from remote
63
+	const queued     = 5; // command waits to be fetched from remote
64 64
 
65 65
 	/**
66 66
 	 * Status which stil need passwords available
67 67
 	 *
68 68
 	 * @var array
69 69
 	 */
70
-	static $require_pw_stati = array(self::scheduled,self::pending,self::queued);
70
+	static $require_pw_stati = array(self::scheduled, self::pending, self::queued);
71 71
 
72 72
 	/**
73 73
 	 * The status of the command, one of either scheduled, successful, failed or deleted
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
 	 * @return string success message
154 154
 	 * @throws Exception()
155 155
 	 */
156
-	protected abstract function exec($check_only=false);
156
+	protected abstract function exec($check_only = false);
157 157
 
158 158
 	/**
159 159
 	 * Return a title / string representation for a given command, eg. to display it
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
 
191 191
 		$this->type = get_class($this);
192 192
 
193
-		foreach($data as $name => $value)
193
+		foreach ($data as $name => $value)
194 194
 		{
195 195
 			$this->$name = $name == 'data' && !is_array($value) ? json_php_unserialize($value) : $value;
196 196
 		}
@@ -209,13 +209,13 @@  discard block
 block discarded – undo
209 209
 	 * @return mixed return value of the command
210 210
 	 * @throws Exceptions on error
211 211
 	 */
212
-	function run($time=null,$set_modifier=true,$skip_checks=false,$dry_run=false)
212
+	function run($time = null, $set_modifier = true, $skip_checks = false, $dry_run = false)
213 213
 	{
214 214
 		if (!is_null($time))
215 215
 		{
216 216
 			$this->scheduled = $time;
217 217
 			$this->status = admin_cmd::scheduled;
218
-			$ret = lang('Command scheduled to run at %1',date('Y-m-d H:i',$time));
218
+			$ret = lang('Command scheduled to run at %1', date('Y-m-d H:i', $time));
219 219
 			// running the checks of the arguments for local commands, if not explicitly requested to not run them
220 220
 			if (!$this->remote_id && !$skip_checks)
221 221
 			{
@@ -281,21 +281,21 @@  discard block
 block discarded – undo
281 281
 	{
282 282
 		if (!($remote = $this->read_remote($this->remote_id)))
283 283
 		{
284
-			throw new Api\Exception\WrongUserinput(lang('Invalid remote id or name "%1"!',$this->remote_id),997);
284
+			throw new Api\Exception\WrongUserinput(lang('Invalid remote id or name "%1"!', $this->remote_id), 997);
285 285
 		}
286 286
 		if (!$this->uid)
287 287
 		{
288
-			$this->save();	// to get the uid
288
+			$this->save(); // to get the uid
289 289
 		}
290 290
 		$secret = md5($this->uid.$remote['remote_hash']);
291 291
 
292 292
 		$postdata = $this->as_array();
293 293
 		if (is_object($GLOBALS['egw']->translation))
294 294
 		{
295
-			$postdata = Api\Translation::convert($postdata,Api\Translation::charset(),'utf-8');
295
+			$postdata = Api\Translation::convert($postdata, Api\Translation::charset(), 'utf-8');
296 296
 		}
297 297
 		// dont send the id's which have no meaning on the remote install
298
-		foreach(array('id','creator','modifier','requested','remote_id') as $name)
298
+		foreach (array('id', 'creator', 'modifier', 'requested', 'remote_id') as $name)
299 299
 		{
300 300
 			unset($postdata[$name]);
301 301
 		}
@@ -321,12 +321,12 @@  discard block
 block discarded – undo
321 321
 		}
322 322
 		if (is_object($GLOBALS['egw']->translation))
323 323
 		{
324
-			$message = Api\Translation::convert($message,'utf-8');
324
+			$message = Api\Translation::convert($message, 'utf-8');
325 325
 		}
326 326
 		$matches = null;
327
-		if (is_string($message) && preg_match('/^([0-9]+) (.*)$/',$message,$matches))
327
+		if (is_string($message) && preg_match('/^([0-9]+) (.*)$/', $message, $matches))
328 328
 		{
329
-			throw new Api\Exception($matches[2],(int)$matches[1]);
329
+			throw new Api\Exception($matches[2], (int)$matches[1]);
330 330
 		}
331 331
 		return $message;
332 332
 	}
@@ -352,7 +352,7 @@  discard block
 block discarded – undo
352 352
 	 * @param boolean $set_modifier =true set the current user as modifier or 0 (= run by the system)
353 353
 	 * @return boolean true on success, false otherwise
354 354
 	 */
355
-	function save($set_modifier=true)
355
+	function save($set_modifier = true)
356 356
 	{
357 357
 		admin_cmd::_instanciate_sql();
358 358
 
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
 			$this->modifier = $set_modifier ? $GLOBALS['egw_info']['user']['account_id'] : 0;
368 368
 			if ($set_modifier) $this->modifier_email = admin_cmd::user_email();
369 369
 		}
370
-		$vars = get_object_vars($this);	// does not work in php5.1.2 due a bug
370
+		$vars = get_object_vars($this); // does not work in php5.1.2 due a bug
371 371
 
372 372
 		// data is stored serialized
373 373
 		// paswords are masked / removed, if we dont need them anymore
@@ -406,7 +406,7 @@  discard block
 block discarded – undo
406 406
 			$this->set_periodic_job();
407 407
 		}
408 408
 		// existing object with no rrule, cancle evtl. running periodic job
409
-		elseif($vars['id'])
409
+		elseif ($vars['id'])
410 410
 		{
411 411
 			$this->cancel_periodic_job();
412 412
 		}
@@ -420,13 +420,13 @@  discard block
 block discarded – undo
420 420
 	 * @param boolean $return_serialized =true true: return json serialized string, false: return array
421 421
 	 * @return string|array see $return_serialized
422 422
 	 */
423
-	static function mask_passwords($data, $return_serialized=true)
423
+	static function mask_passwords($data, $return_serialized = true)
424 424
 	{
425 425
 		if (!is_array($data))
426 426
 		{
427 427
 			$data = json_php_unserialize($data);
428 428
 		}
429
-		foreach($data as $key => &$value)
429
+		foreach ($data as $key => &$value)
430 430
 		{
431 431
 			if (is_array($value))
432 432
 			{
@@ -474,10 +474,10 @@  discard block
 block discarded – undo
474 474
 		{
475 475
 			$data['data'] = json_php_unserialize($data['data']);
476 476
 		}
477
-		if (!(class_exists($class = 'EGroupware\\'.$data['type']) ||	// namespaced class
477
+		if (!(class_exists($class = 'EGroupware\\'.$data['type']) || // namespaced class
478 478
 			class_exists($class = $data['type'])) || $data['type'] == 'admin_cmd')
479 479
 		{
480
-			throw new Api\Exception\WrongParameter(lang('Unknown command %1!',$class), 10);
480
+			throw new Api\Exception\WrongParameter(lang('Unknown command %1!', $class), 10);
481 481
 		}
482 482
 		$cmd = new $class($data);
483 483
 
@@ -485,7 +485,7 @@  discard block
 block discarded – undo
485 485
 		{
486 486
 			return $cmd;
487 487
 		}
488
-		throw new Api\Exception\WrongParameter(lang('%1 is no command!',$class), 10);
488
+		throw new Api\Exception\WrongParameter(lang('%1 is no command!', $class), 10);
489 489
 	}
490 490
 
491 491
 	/**
@@ -497,7 +497,7 @@  discard block
 block discarded – undo
497 497
 	 * @param array $readonlys
498 498
 	 * @return int
499 499
 	 */
500
-	static function get_rows($query,&$rows,$readonlys)
500
+	static function get_rows($query, &$rows, $readonlys)
501 501
 	{
502 502
 		admin_cmd::_instanciate_sql();
503 503
 
@@ -514,21 +514,21 @@  discard block
 block discarded – undo
514 514
 			$query['col_filter'][] = 'cmd_rrule IS NOT NULL';
515 515
 		}
516 516
 		unset($query['col_filter']['periodic']);
517
-		if($query['col_filter']['parent'])
517
+		if ($query['col_filter']['parent'])
518 518
 		{
519 519
 			$query['col_filter']['parent'] = (int)$query['col_filter']['parent'];
520 520
 		}
521 521
 
522
-		$total = admin_cmd::$sql->get_rows($query,$rows,$readonlys);
522
+		$total = admin_cmd::$sql->get_rows($query, $rows, $readonlys);
523 523
 
524 524
 		if (!$rows) return 0;
525 525
 
526 526
 		$async = new Api\Asyncservice();
527
-		foreach($rows as &$row)
527
+		foreach ($rows as &$row)
528 528
 		{
529 529
 			try {
530 530
 				$cmd = admin_cmd::instanciate($row);
531
-				$row['title'] = $cmd->__tostring();	// we call __tostring explicit, as a cast to string requires php5.2+
531
+				$row['title'] = $cmd->__tostring(); // we call __tostring explicit, as a cast to string requires php5.2+
532 532
 			}
533 533
 			catch (Exception $e) {
534 534
 				$row['title'] = $e->getMessage();
@@ -536,25 +536,24 @@  discard block
 block discarded – undo
536 536
 
537 537
 			$row['value'] = $cmd->value;
538 538
 
539
-			if(method_exists($cmd, 'summary'))
539
+			if (method_exists($cmd, 'summary'))
540 540
 			{
541 541
 				$row['data'] = $cmd->summary();
542 542
 			}
543 543
 			else
544 544
 			{
545
-				$row['data'] = !($data = json_php_unserialize($row['data'])) ? '' :
546
-					json_encode($data+(empty($row['rrule'])?array():array('rrule' => $row['rrule'])),
545
+				$row['data'] = !($data = json_php_unserialize($row['data'])) ? '' : json_encode($data + (empty($row['rrule']) ? array() : array('rrule' => $row['rrule'])),
547 546
 						JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
548 547
 			}
549
-			if($row['rrule'])
548
+			if ($row['rrule'])
550 549
 			{
551
-				$rrule = calendar_rrule::event2rrule(calendar_rrule::parseRrule($row['rrule'],true)+array(
550
+				$rrule = calendar_rrule::event2rrule(calendar_rrule::parseRrule($row['rrule'], true) + array(
552 551
 					'start' => time(),
553 552
 					'tzid'=> Api\DateTime::$server_timezone->getName()
554 553
 				));
555 554
 				$row['rrule'] = ''.$rrule;
556 555
 			}
557
-			if(!$row['scheduled'] && $cmd && $cmd->async_job_id)
556
+			if (!$row['scheduled'] && $cmd && $cmd->async_job_id)
558 557
 			{
559 558
 				$job = $async->read($cmd->async_job_id);
560 559
 
@@ -580,11 +579,11 @@  discard block
 block discarded – undo
580 579
 			admin_cmd::_instanciate_sql();
581 580
 
582 581
 			// Need a new one to avoid column name modification
583
-			$sql = new Api\Storage\Base('admin','egw_admin_queue',null);
582
+			$sql = new Api\Storage\Base('admin', 'egw_admin_queue', null);
584 583
 			$labels = $sql->query_list('cmd_type');
585 584
 
586 585
 			// for admin app we also add all available cmd objects
587
-			foreach(scandir(__DIR__) as $file)
586
+			foreach (scandir(__DIR__) as $file)
588 587
 			{
589 588
 				$matches = null;
590 589
 				if (preg_match('/^class\.(admin_cmd_.*)\.inc\.php$/', $file, $matches))
@@ -595,15 +594,15 @@  discard block
 block discarded – undo
595 594
 					}
596 595
 				}
597 596
 			}
598
-			foreach($labels as $class => &$label)
597
+			foreach ($labels as $class => &$label)
599 598
 			{
600
-				if(class_exists($class))
599
+				if (class_exists($class))
601 600
 				{
602 601
 					$label = $class::name();
603 602
 				}
604
-				elseif (class_exists('EGroupware\\' . $class))
603
+				elseif (class_exists('EGroupware\\'.$class))
605 604
 				{
606
-					$class = 'EGroupware\\' . $class;
605
+					$class = 'EGroupware\\'.$class;
607 606
 					$label = $class::name();
608 607
 				}
609 608
 			}
@@ -634,11 +633,11 @@  discard block
 block discarded – undo
634 633
 	 * @param array $filter =null if set (!=null) col-data pairs, to be and-ed (!) into the query without wildcards
635 634
 	 * @return array
636 635
 	 */
637
-	static function &search($criteria,$only_keys=True,$order_by='',$extra_cols='',$wildcard='',$empty=False,$op='AND',$start=false,$filter=null)
636
+	static function &search($criteria, $only_keys = True, $order_by = '', $extra_cols = '', $wildcard = '', $empty = False, $op = 'AND', $start = false, $filter = null)
638 637
 	{
639 638
 		admin_cmd::_instanciate_sql();
640 639
 
641
-		return admin_cmd::$sql->search($criteria,$only_keys,$order_by,$extra_cols,$wildcard,$empty,$op,$start,$filter);
640
+		return admin_cmd::$sql->search($criteria, $only_keys, $order_by, $extra_cols, $wildcard, $empty, $op, $start, $filter);
642 641
 	}
643 642
 
644 643
 	/**
@@ -650,7 +649,7 @@  discard block
 block discarded – undo
650 649
 	{
651 650
 		if (is_null(admin_cmd::$sql))
652 651
 		{
653
-			admin_cmd::$sql = new Api\Storage\Base('admin','egw_admin_queue',null,'cmd_');
652
+			admin_cmd::$sql = new Api\Storage\Base('admin', 'egw_admin_queue', null, 'cmd_');
654 653
 		}
655 654
 	}
656 655
 
@@ -663,7 +662,7 @@  discard block
 block discarded – undo
663 662
 	{
664 663
 		if (is_null(admin_cmd::$remote))
665 664
 		{
666
-			admin_cmd::$remote = new Api\Storage\Base('admin','egw_admin_remote');
665
+			admin_cmd::$remote = new Api\Storage\Base('admin', 'egw_admin_remote');
667 666
 		}
668 667
 	}
669 668
 
@@ -675,11 +674,11 @@  discard block
 block discarded – undo
675 674
 	 */
676 675
 	function __get($property)
677 676
 	{
678
-		if (property_exists('admin_cmd',$property))
677
+		if (property_exists('admin_cmd', $property))
679 678
 		{
680
-			return $this->$property;	// making all (non static) class vars readonly available
679
+			return $this->$property; // making all (non static) class vars readonly available
681 680
 		}
682
-		switch($property)
681
+		switch ($property)
683 682
 		{
684 683
 			case 'accounts':
685 684
 				self::_instanciate_accounts();
@@ -698,9 +697,9 @@  discard block
 block discarded – undo
698 697
 	 */
699 698
 	function __isset($property)
700 699
 	{
701
-		if (property_exists('admin_cmd',$property))
700
+		if (property_exists('admin_cmd', $property))
702 701
 		{
703
-			return isset($this->$property);	// making all (non static) class vars readonly available
702
+			return isset($this->$property); // making all (non static) class vars readonly available
704 703
 		}
705 704
 		return isset($this->data[$property]);
706 705
 	}
@@ -712,7 +711,7 @@  discard block
 block discarded – undo
712 711
 	 * @param mixed $value
713 712
 	 * @return mixed
714 713
 	 */
715
-	function __set($property,$value)
714
+	function __set($property, $value)
716 715
 	{
717 716
 		$this->data[$property] = $value;
718 717
 	}
@@ -734,19 +733,19 @@  discard block
 block discarded – undo
734 733
 	 */
735 734
 	function as_array()
736 735
 	{
737
-		if (version_compare(PHP_VERSION,'5.1.2','>'))
736
+		if (version_compare(PHP_VERSION, '5.1.2', '>'))
738 737
 		{
739
-			$vars = get_object_vars($this);	// does not work in php5.1.2 due a bug
738
+			$vars = get_object_vars($this); // does not work in php5.1.2 due a bug
740 739
 		}
741 740
 		else
742 741
 		{
743
-			foreach(array_keys(get_class_vars(__CLASS__)) as $name)
742
+			foreach (array_keys(get_class_vars(__CLASS__)) as $name)
744 743
 			{
745 744
 				$vars[$name] = $this->$name;
746 745
 			}
747 746
 		}
748 747
 		unset($vars['data']);
749
-		if ($this->data) $vars = array_merge($this->data,$vars);
748
+		if ($this->data) $vars = array_merge($this->data, $vars);
750 749
 
751 750
 		return $vars;
752 751
 	}
@@ -758,14 +757,14 @@  discard block
 block discarded – undo
758 757
 	 * @param int $extra_deny =null further admin rights to check, eg. 16 = deny edit Api\Accounts
759 758
 	 * @throws Api\Exception\NoPermission\Admin
760 759
 	 */
761
-	protected function _check_admin($extra_acl=null,$extra_deny=null)
760
+	protected function _check_admin($extra_acl = null, $extra_deny = null)
762 761
 	{
763 762
 		if ($this->creator)
764 763
 		{
765 764
 			admin_cmd::_instanciate_acl($this->creator);
766 765
 			// todo: check only if and with $this->creator
767
-			if (!admin_cmd::$acl->check('run',1,'admin') &&		// creator is no longer admin
768
-				$extra_acl && $extra_deny && admin_cmd::$acl->check($extra_acl,$extra_deny,'admin'))	// creator is explicitly forbidden to do something
766
+			if (!admin_cmd::$acl->check('run', 1, 'admin') && // creator is no longer admin
767
+				$extra_acl && $extra_deny && admin_cmd::$acl->check($extra_acl, $extra_deny, 'admin'))	// creator is explicitly forbidden to do something
769 768
 			{
770 769
 				throw new Api\Exception\NoPermission\Admin();
771 770
 			}
@@ -781,13 +780,13 @@  discard block
 block discarded – undo
781 780
 	 */
782 781
 	static function parse_apps(array $apps)
783 782
 	{
784
-		foreach($apps as $key => $name)
783
+		foreach ($apps as $key => $name)
785 784
 		{
786 785
 			if (!isset($GLOBALS['egw_info']['apps'][$name]))
787 786
 			{
788
-				foreach($GLOBALS['egw_info']['apps'] as $app => $data)	// check against title and localised name
787
+				foreach ($GLOBALS['egw_info']['apps'] as $app => $data)	// check against title and localised name
789 788
 				{
790
-					if (!strcasecmp($name,$data['title']) || !strcasecmp($name,lang($app)))
789
+					if (!strcasecmp($name, $data['title']) || !strcasecmp($name, lang($app)))
791 790
 					{
792 791
 						$apps[$key] = $name = $app;
793 792
 						break;
@@ -796,7 +795,7 @@  discard block
 block discarded – undo
796 795
 			}
797 796
 			if (!isset($GLOBALS['egw_info']['apps'][$name]))
798 797
 			{
799
-				throw new Api\Exception\WrongUserinput(lang("Application '%1' not found (maybe not installed or misspelled)!",$name),8);
798
+				throw new Api\Exception\WrongUserinput(lang("Application '%1' not found (maybe not installed or misspelled)!", $name), 8);
800 799
 			}
801 800
 		}
802 801
 		return $apps;
@@ -811,20 +810,20 @@  discard block
 block discarded – undo
811 810
 	 * @throws Api\Exception\WrongUserinput(lang("Unknown account: %1 !!!",$account), 15);
812 811
 	 * @throws Api\Exception\WrongUserinput(lang("Wrong account type: %1 is NO %2 !!!",$account,$allow_only_user?lang('user'):lang('group')), 16);
813 812
 	 */
814
-	static function parse_account($account,$allow_only_user=null)
813
+	static function parse_account($account, $allow_only_user = null)
815 814
 	{
816 815
 		admin_cmd::_instanciate_accounts();
817 816
 
818 817
 		if (!($type = admin_cmd::$accounts->exists($account)) ||
819
-			!is_numeric($id=$account) && !($id = admin_cmd::$accounts->name2id($account)))
818
+			!is_numeric($id = $account) && !($id = admin_cmd::$accounts->name2id($account)))
820 819
 		{
821
-			throw new Api\Exception\WrongUserinput(lang("Unknown account: %1 !!!",$account), 15);
820
+			throw new Api\Exception\WrongUserinput(lang("Unknown account: %1 !!!", $account), 15);
822 821
 		}
823 822
 		if (!is_null($allow_only_user) && $allow_only_user !== ($type == 1))
824 823
 		{
825
-			throw new Api\Exception\WrongUserinput(lang("Wrong account type: %1 is NO %2 !!!",$account,$allow_only_user?lang('user'):lang('group')), 16);
824
+			throw new Api\Exception\WrongUserinput(lang("Wrong account type: %1 is NO %2 !!!", $account, $allow_only_user ?lang('user') : lang('group')), 16);
826 825
 		}
827
-		if ($type == 2 && $id > 0) $id = -$id;	// groups use negative id's internally, fix it, if user given the wrong sign
826
+		if ($type == 2 && $id > 0) $id = -$id; // groups use negative id's internally, fix it, if user given the wrong sign
828 827
 
829 828
 		return $id;
830 829
 	}
@@ -838,14 +837,14 @@  discard block
 block discarded – undo
838 837
 	 * @throws Api\Exception\WrongUserinput(lang("Unknown account: %1 !!!",$account), 15);
839 838
 	 * @throws Api\Exception\WrongUserinput(lang("Wrong account type: %1 is NO %2 !!!",$account,$allow_only?lang('user'):lang('group')), 16);
840 839
 	 */
841
-	static function parse_accounts($accounts,$allow_only_user=null)
840
+	static function parse_accounts($accounts, $allow_only_user = null)
842 841
 	{
843 842
 		if (!$accounts) return null;
844 843
 
845 844
 		$ids = array();
846
-		foreach(is_array($accounts) ? $accounts : explode(',',$accounts) as $account)
845
+		foreach (is_array($accounts) ? $accounts : explode(',', $accounts) as $account)
847 846
 		{
848
-			$ids[] = admin_cmd::parse_account($account,$allow_only_user);
847
+			$ids[] = admin_cmd::parse_account($account, $allow_only_user);
849 848
 		}
850 849
 		return $ids;
851 850
 	}
@@ -863,11 +862,11 @@  discard block
 block discarded – undo
863 862
 		{
864 863
 			$datein = $date;
865 864
 			// convert german DD.MM.YYYY format into ISO YYYY-MM-DD format
866
-			$date = preg_replace('/^([0-9]{1,2})\.([0-9]{1,2})\.([0-9]{4})$/','\3-\2-\1',$date);
865
+			$date = preg_replace('/^([0-9]{1,2})\.([0-9]{1,2})\.([0-9]{4})$/', '\3-\2-\1', $date);
867 866
 
868
-			if (($date = strtotime($date))  === false)
867
+			if (($date = strtotime($date)) === false)
869 868
 			{
870
-				throw new Api\Exception\WrongUserinput(lang('Invalid formated date "%1"!',$datein),6);
869
+				throw new Api\Exception\WrongUserinput(lang('Invalid formated date "%1"!', $datein), 6);
871 870
 			}
872 871
 		}
873 872
 		return (int)$date;
@@ -881,7 +880,7 @@  discard block
 block discarded – undo
881 880
 	 * @return boolean
882 881
 	 * @throws Api\Exception\WrongUserinput(lang('Invalid value "%1" use yes or no!',$value),998);
883 882
 	 */
884
-	static function parse_boolean($value,$default=null)
883
+	static function parse_boolean($value, $default = null)
885 884
 	{
886 885
 		if (is_bool($value) || is_int($value))
887 886
 		{
@@ -891,15 +890,15 @@  discard block
 block discarded – undo
891 890
 		{
892 891
 			return $default;
893 892
 		}
894
-		if (in_array($value,array('1','yes','true',lang('yes'),lang('true'))))
893
+		if (in_array($value, array('1', 'yes', 'true', lang('yes'), lang('true'))))
895 894
 		{
896 895
 			return true;
897 896
 		}
898
-		if (in_array($value,array('0','no','false',lang('no'),lang('false'))))
897
+		if (in_array($value, array('0', 'no', 'false', lang('no'), lang('false'))))
899 898
 		{
900 899
 			return false;
901 900
 		}
902
-		throw new Api\Exception\WrongUserinput(lang('Invalid value "%1" use yes or no!',$value),998);
901
+		throw new Api\Exception\WrongUserinput(lang('Invalid value "%1" use yes or no!', $value), 998);
903 902
 	}
904 903
 
905 904
 	/**
@@ -917,9 +916,9 @@  discard block
 block discarded – undo
917 916
 			'remote_id' => $id_or_name,
918 917
 			'remote_name' => $id_or_name,
919 918
 			'remote_domain' => $id_or_name,
920
-		),true,'','','',false,'OR')) || count($remotes) != 1)
919
+		), true, '', '', '', false, 'OR')) || count($remotes) != 1)
921 920
 		{
922
-			throw new Api\Exception\WrongUserinput(lang('Invalid remote id or name "%1"!',$id_or_name),997);
921
+			throw new Api\Exception\WrongUserinput(lang('Invalid remote id or name "%1"!', $id_or_name), 997);
923 922
 		}
924 923
 		return $remotes[0]['remote_id'];
925 924
 	}
@@ -936,7 +935,7 @@  discard block
 block discarded – undo
936 935
 		{
937 936
 			if (!is_object($GLOBALS['egw']->accounts))
938 937
 			{
939
-				throw new Api\Exception\AssertionFailed(lang('%1 class not instanciated','accounts'),999);
938
+				throw new Api\Exception\AssertionFailed(lang('%1 class not instanciated', 'accounts'), 999);
940 939
 			}
941 940
 			admin_cmd::$accounts = $GLOBALS['egw']->accounts;
942 941
 		}
@@ -949,13 +948,13 @@  discard block
 block discarded – undo
949 948
 	 * @param int $account =null account_id the class needs to be instanciated for, default need only account-independent methods
950 949
 	 * @throws Api\Exception\AssertionFailed(lang('%1 class not instanciated','acl'),999);
951 950
 	 */
952
-	protected function _instanciate_acl($account=null)
951
+	protected function _instanciate_acl($account = null)
953 952
 	{
954 953
 		if (!is_object(admin_cmd::$acl) || $account && admin_cmd::$acl->account_id != $account)
955 954
 		{
956 955
 			if (!is_object($GLOBALS['egw']->acl))
957 956
 			{
958
-				throw new Api\Exception\AssertionFailed(lang('%1 class not instanciated','acl'),999);
957
+				throw new Api\Exception\AssertionFailed(lang('%1 class not instanciated', 'acl'), 999);
959 958
 			}
960 959
 			if ($account && $GLOBALS['egw']->acl->account_id != $account)
961 960
 			{
@@ -975,20 +974,20 @@  discard block
 block discarded – undo
975 974
 	 * @param $account_id =null account_id, default current user
976 975
 	 * @return string
977 976
 	 */
978
-	static function user_email($account_id=null)
977
+	static function user_email($account_id = null)
979 978
 	{
980 979
 		if ($account_id)
981 980
 		{
982 981
 			admin_cmd::_instanciate_accounts();
983
-			$fullname = admin_cmd::$accounts->id2name($account_id,'account_fullname');
984
-			$email = admin_cmd::$accounts->id2name($account_id,'account_email');
982
+			$fullname = admin_cmd::$accounts->id2name($account_id, 'account_fullname');
983
+			$email = admin_cmd::$accounts->id2name($account_id, 'account_email');
985 984
 		}
986 985
 		else
987 986
 		{
988 987
 			$fullname = $GLOBALS['egw_info']['user']['account_fullname'];
989 988
 			$email = $GLOBALS['egw_info']['user']['account_email'];
990 989
 		}
991
-		return $fullname . ($email ? ' <'.$email.'>' : '');
990
+		return $fullname.($email ? ' <'.$email.'>' : '');
992 991
 	}
993 992
 
994 993
 	/**
@@ -1012,11 +1011,11 @@  discard block
 block discarded – undo
1012 1011
 		{
1013 1012
 			return false;
1014 1013
 		}
1015
-		if (!($jobs = admin_cmd::search(array(),false,'cmd_scheduled','','',false,'AND',array(0,1),array(
1014
+		if (!($jobs = admin_cmd::search(array(), false, 'cmd_scheduled', '', '', false, 'AND', array(0, 1), array(
1016 1015
 			'cmd_status' => admin_cmd::scheduled,
1017 1016
 		))))
1018 1017
 		{
1019
-			return false;		// no schduled command, no need to setup the job
1018
+			return false; // no schduled command, no need to setup the job
1020 1019
 		}
1021 1020
 		$next = $jobs[0];
1022 1021
 		if (($time = $next['scheduled']) < time())	// should run immediatly
@@ -1026,11 +1025,11 @@  discard block
 block discarded – undo
1026 1025
 		$async = new Api\Asyncservice();
1027 1026
 
1028 1027
 		// we cant use this class as callback, as it's abstract and ExecMethod used by the async service instanciated the class!
1029
-		list($app) = explode('_',$class=$next['type']);
1028
+		list($app) = explode('_', $class = $next['type']);
1030 1029
 		$callback = $app.'.'.$class.'.run_queued_jobs';
1031 1030
 
1032
-		$async->cancel_timer(admin_cmd::async_job_id);	// we delete it in case a job already exists
1033
-		return $async->set_timer($time,admin_cmd::async_job_id,$callback,null,$next['creator']);
1031
+		$async->cancel_timer(admin_cmd::async_job_id); // we delete it in case a job already exists
1032
+		return $async->set_timer($time, admin_cmd::async_job_id, $callback, null, $next['creator']);
1034 1033
 	}
1035 1034
 
1036 1035
 	/**
@@ -1040,20 +1039,20 @@  discard block
 block discarded – undo
1040 1039
 	 */
1041 1040
 	static function run_queued_jobs()
1042 1041
 	{
1043
-		if (!($jobs = admin_cmd::search(array(),false,'cmd_scheduled','','',false,'AND',false,array(
1042
+		if (!($jobs = admin_cmd::search(array(), false, 'cmd_scheduled', '', '', false, 'AND', false, array(
1044 1043
 			'cmd_status' => admin_cmd::scheduled,
1045 1044
 			'cmd_scheduled <= '.time(),
1046 1045
 		))))
1047 1046
 		{
1048
-			return false;		// no schduled commands, no need to setup the job
1047
+			return false; // no schduled commands, no need to setup the job
1049 1048
 		}
1050
-		admin_cmd::$running_queued_jobs = true;	// stop admin_cmd::run() which calls admin_cmd::save() to install a new job
1049
+		admin_cmd::$running_queued_jobs = true; // stop admin_cmd::run() which calls admin_cmd::save() to install a new job
1051 1050
 
1052
-		foreach($jobs as $job)
1051
+		foreach ($jobs as $job)
1053 1052
 		{
1054 1053
 			try {
1055 1054
 				$cmd = admin_cmd::instanciate($job);
1056
-				$cmd->run(null,false);	// false = dont set current user as modifier, as job is run by the queue/system itself
1055
+				$cmd->run(null, false); // false = dont set current user as modifier, as job is run by the queue/system itself
1057 1056
 			}
1058 1057
 			catch (Exception $e) {	// we need to mark that command as failed, to prevent further execution
1059 1058
 				_egw_log_exception($e);
@@ -1083,13 +1082,13 @@  discard block
 block discarded – undo
1083 1082
 		if (empty($this->rrule)) return false;
1084 1083
 
1085 1084
 		// parse rrule and calculate next execution time
1086
-		$event = calendar_rrule::parseRrule($this->rrule, true);	// true: allow HOURLY or MINUTELY
1085
+		$event = calendar_rrule::parseRrule($this->rrule, true); // true: allow HOURLY or MINUTELY
1087 1086
 		// rrule can depend on start-time, use policy creation time by default, if rrule_start is not set
1088 1087
 		$event['start'] = empty($this->rrule_start) ? $this->created : $this->rrule_start;
1089 1088
 		$event['tzid'] = Api\DateTime::$server_timezone->getName();
1090
-		$rrule = calendar_rrule::event2rrule($event, false);	// false = server timezone
1089
+		$rrule = calendar_rrule::event2rrule($event, false); // false = server timezone
1091 1090
 		$rrule->rewind();
1092
-		while((($time = $rrule->current()->format('ts'))) <= time())
1091
+		while ((($time = $rrule->current()->format('ts'))) <= time())
1093 1092
 		{
1094 1093
 			$rrule->next();
1095 1094
 		}
@@ -1097,7 +1096,7 @@  discard block
 block discarded – undo
1097 1096
 		// schedule run_periodic_job to run at that time
1098 1097
 		$async = new Api\Asyncservice();
1099 1098
 		$job_id = empty($this->async_job_id) ? self::PERIOD_ASYNC_ID_PREFIX.$this->id : $this->async_job_id;
1100
-		$async->cancel_timer($job_id);	// we delete it in case a job already exists
1099
+		$async->cancel_timer($job_id); // we delete it in case a job already exists
1101 1100
 		return $async->set_timer($time, $job_id, __CLASS__.'::run_periodic_job', $this->as_array(), $this->creator);
1102 1101
 	}
1103 1102
 
@@ -1110,7 +1109,7 @@  discard block
 block discarded – undo
1110 1109
 	{
1111 1110
 		$async = new Api\Asyncservice();
1112 1111
 		$job_id = empty($this->async_job_id) ? self::PERIOD_ASYNC_ID_PREFIX.$this->id : $this->async_job_id;
1113
-		$async->cancel_timer($job_id);	// we delete it in case a job already exists
1112
+		$async->cancel_timer($job_id); // we delete it in case a job already exists
1114 1113
 	}
1115 1114
 
1116 1115
 	/**
@@ -1127,10 +1126,10 @@  discard block
 block discarded – undo
1127 1126
 		$single = $cmd->as_array();
1128 1127
 		$single['parent'] = $single['id'];
1129 1128
 		$single = array_diff_key($single, array_flip(array(
1130
-			'id','uid',
1131
-			'created','modified','modifier',
1132
-			'async_job_id','rrule','scheduled',
1133
-			'status', 'set', 'old','value','result'
1129
+			'id', 'uid',
1130
+			'created', 'modified', 'modifier',
1131
+			'async_job_id', 'rrule', 'scheduled',
1132
+			'status', 'set', 'old', 'value', 'result'
1134 1133
 		)));
1135 1134
 
1136 1135
 		$periodic = admin_cmd::instanciate($single);
@@ -1156,9 +1155,9 @@  discard block
 block discarded – undo
1156 1155
 		admin_cmd::_instanciate_remote();
1157 1156
 
1158 1157
 		$sites = array(lang('local'));
1159
-		if (($remote = admin_cmd::$remote->query_list('remote_name','remote_id')))
1158
+		if (($remote = admin_cmd::$remote->query_list('remote_name', 'remote_id')))
1160 1159
 		{
1161
-			$sites = array_merge($sites,$remote);
1160
+			$sites = array_merge($sites, $remote);
1162 1161
 		}
1163 1162
 		return $sites;
1164 1163
 	}
@@ -1171,11 +1170,11 @@  discard block
 block discarded – undo
1171 1170
 	 * @param array &$readonlys
1172 1171
 	 * @return int
1173 1172
 	 */
1174
-	static function get_remotes($query,&$rows,&$readonlys)
1173
+	static function get_remotes($query, &$rows, &$readonlys)
1175 1174
 	{
1176 1175
 		admin_cmd::_instanciate_remote();
1177 1176
 
1178
-		return admin_cmd::$remote->get_rows($query,$rows,$readonlys);
1177
+		return admin_cmd::$remote->get_rows($query, $rows, $readonlys);
1179 1178
 	}
1180 1179
 
1181 1180
 	/**
@@ -1203,7 +1202,7 @@  discard block
 block discarded – undo
1203 1202
 
1204 1203
 		if ($data['install_id'] && $data['config_passwd'])	// calculate hash
1205 1204
 		{
1206
-			$data['remote_hash'] = self::remote_hash($data['install_id'],$data['config_passwd']);
1205
+			$data['remote_hash'] = self::remote_hash($data['install_id'], $data['config_passwd']);
1207 1206
 		}
1208 1207
 		elseif (!$data['remote_hash'] && !($data['install_id'] && $data['config_passwd']))
1209 1208
 		{
@@ -1215,12 +1214,12 @@  discard block
 block discarded – undo
1215 1214
 		// check if a unique key constrain would be violated by saving the entry
1216 1215
 		if (($num = admin_cmd::$remote->not_unique()))
1217 1216
 		{
1218
-			$col = admin_cmd::$remote->table_def['uc'][$num-1];	// $num is 1 based!
1219
-			throw new egw_exception_db_not_unique(lang('Value for column %1 is not unique!',$this->table_name.'.'.$col),$num);
1217
+			$col = admin_cmd::$remote->table_def['uc'][$num - 1]; // $num is 1 based!
1218
+			throw new egw_exception_db_not_unique(lang('Value for column %1 is not unique!', $this->table_name.'.'.$col), $num);
1220 1219
 		}
1221 1220
 		if (admin_cmd::$remote->save() != 0)
1222 1221
 		{
1223
-			throw new Api\Db\Exception(lang('Error saving to db:').' '.$this->sql->db->Error.' ('.$this->sql->db->Errno.')',$this->sql->db->Errno);
1222
+			throw new Api\Db\Exception(lang('Error saving to db:').' '.$this->sql->db->Error.' ('.$this->sql->db->Errno.')', $this->sql->db->Errno);
1224 1223
 		}
1225 1224
 		return admin_cmd::$remote->data['remote_id'];
1226 1225
 	}
@@ -1232,11 +1231,11 @@  discard block
 block discarded – undo
1232 1231
 	 * @param string $config_passwd
1233 1232
 	 * @return string 32char md5 hash
1234 1233
 	 */
1235
-	static function remote_hash($install_id,$config_passwd)
1234
+	static function remote_hash($install_id, $config_passwd)
1236 1235
 	{
1237 1236
 		if (empty($config_passwd) || !self::is_md5($install_id))
1238 1237
 		{
1239
-			throw new Api\Exception\WrongParameter(empty($config_passwd)?'Empty Api\Config password':'install_id no md5 hash');
1238
+			throw new Api\Exception\WrongParameter(empty($config_passwd) ? 'Empty Api\Config password' : 'install_id no md5 hash');
1240 1239
 		}
1241 1240
 		if (!self::is_md5($config_passwd)) $config_passwd = md5($config_passwd);
1242 1241
 
@@ -1266,7 +1265,7 @@  discard block
 block discarded – undo
1266 1265
 	 */
1267 1266
 	static function is_md5($str)
1268 1267
 	{
1269
-		return preg_match('/^[0-9a-f]{32}$/',$str);
1268
+		return preg_match('/^[0-9a-f]{32}$/', $str);
1270 1269
 	}
1271 1270
 
1272 1271
 	/**
@@ -1283,26 +1282,26 @@  discard block
 block discarded – undo
1283 1282
 	 * @param string $config_passwd of the current domain
1284 1283
 	 * @throws Api\Exception\NoPermission
1285 1284
 	 */
1286
-	function check_remote_access($secret,$config_passwd)
1285
+	function check_remote_access($secret, $config_passwd)
1287 1286
 	{
1288 1287
 		// as a security measure remote administration need to be enabled under Admin > Site configuration
1289
-		list(,$remote_admin_install_id) = explode('-',$this->uid);
1290
-		$allowed_remote_admin_ids = $GLOBALS['egw_info']['server']['allow_remote_admin'] ? explode(',',$GLOBALS['egw_info']['server']['allow_remote_admin']) : array();
1288
+		list(,$remote_admin_install_id) = explode('-', $this->uid);
1289
+		$allowed_remote_admin_ids = $GLOBALS['egw_info']['server']['allow_remote_admin'] ? explode(',', $GLOBALS['egw_info']['server']['allow_remote_admin']) : array();
1291 1290
 
1292 1291
 		// to authenticate with the installation we use a secret, which is a md5 hash build from the uid
1293 1292
 		// of the command (to not allow to send new commands with an earsdroped secret) and the md5 hash
1294 1293
 		// of the md5 hash of the Api\Config password and the install_id (egw_admin_remote.remote_hash)
1295
-		if (is_null($config_passwd) || is_numeric($this->uid) || !in_array($remote_admin_install_id,$allowed_remote_admin_ids) ||
1296
-			$secret != ($md5=md5($this->uid.$this->remote_hash($GLOBALS['egw_info']['server']['install_id'],$config_passwd))))
1294
+		if (is_null($config_passwd) || is_numeric($this->uid) || !in_array($remote_admin_install_id, $allowed_remote_admin_ids) ||
1295
+			$secret != ($md5 = md5($this->uid.$this->remote_hash($GLOBALS['egw_info']['server']['install_id'], $config_passwd))))
1297 1296
 		{
1298 1297
 			//die("secret='$secret' != '$md5', is_null($config_passwd)=".is_null($config_passwd).", uid=$this->uid, remote_install_id=$remote_admin_install_id, allowed: ".implode(', ',$allowed_remote_admin_ids));
1299 1298
 			unset($md5);
1300 1299
 			$msg = lang('Permission denied!');
1301
-			if (!in_array($remote_admin_install_id,$allowed_remote_admin_ids))
1300
+			if (!in_array($remote_admin_install_id, $allowed_remote_admin_ids))
1302 1301
 			{
1303 1302
 				$msg .= "\n".lang('Remote administration need to be enabled in the remote instance under Admin > Site configuration!');
1304 1303
 			}
1305
-			throw new Api\Exception\NoPermission($msg,0);
1304
+			throw new Api\Exception\NoPermission($msg, 0);
1306 1305
 		}
1307 1306
 	}
1308 1307
 
@@ -1312,7 +1311,7 @@  discard block
 block discarded – undo
1312 1311
 	 * @param int $len =16
1313 1312
 	 * @return string
1314 1313
 	 */
1315
-	static function randomstring($len=16)
1314
+	static function randomstring($len = 16)
1316 1315
 	{
1317 1316
 		return Api\Auth::randomstring($len);
1318 1317
 	}
@@ -1334,7 +1333,7 @@  discard block
 block discarded – undo
1334 1333
 	 */
1335 1334
 	protected function get_etemplate()
1336 1335
 	{
1337
-		static $tpl = null;	// some caching to not instanciate it twice
1336
+		static $tpl = null; // some caching to not instanciate it twice
1338 1337
 
1339 1338
 		if (!isset($tpl))
1340 1339
 		{
@@ -1364,7 +1363,7 @@  discard block
 block discarded – undo
1364 1363
 		{
1365 1364
 			$tpl->run(function($cname, $expand, $widget) use (&$labels, &$label)
1366 1365
 			{
1367
-				switch($widget->type)
1366
+				switch ($widget->type)
1368 1367
 				{
1369 1368
 					// remember label from last description widget
1370 1369
 					case 'description':
@@ -1407,7 +1406,7 @@  discard block
 block discarded – undo
1407 1406
 		{
1408 1407
 			$tpl->run(function($cname, $expand, $widget) use (&$widgets, &$last_select, $selectboxes)
1409 1408
 			{
1410
-				switch($widget->type)
1409
+				switch ($widget->type)
1411 1410
 				{
1412 1411
 					// ignore non input-widgets
1413 1412
 					case 'hbox': case 'vbox': case 'box': case 'groupbox':
@@ -1472,12 +1471,12 @@  discard block
 block discarded – undo
1472 1471
 	 */
1473 1472
 	public function get_result()
1474 1473
 	{
1475
-		if($this->result)
1474
+		if ($this->result)
1476 1475
 		{
1477 1476
 			return is_array($this->result) ? implode("\n", $this->result) : $this->result;
1478 1477
 		}
1479 1478
 		return lang("Command was run %1 on %2",
1480
-				static::$stati[ $this->status ],
1479
+				static::$stati[$this->status],
1481 1480
 				Api\DateTime::to($this->created));
1482 1481
 	}
1483 1482
 }
Please login to merge, or discard this patch.
Braces   +85 added lines, -21 removed lines patch added patch discarded remove patch
@@ -172,7 +172,10 @@  discard block
 block discarded – undo
172 172
 	 */
173 173
 	public static function name()
174 174
 	{
175
-		if (self::NAME) return self::NAME;
175
+		if (self::NAME)
176
+		{
177
+			return self::NAME;
178
+		}
176 179
 
177 180
 		return ucfirst(str_replace(['_cmd_', '_', '\\'], ' ', get_called_class()));
178 181
 	}
@@ -242,7 +245,10 @@  discard block
 block discarded – undo
242 245
 				{
243 246
 					$ret = $this->remote_exec($dry_run);
244 247
 				}
245
-				if (is_null($this->status)) $this->status = admin_cmd::successful;
248
+				if (is_null($this->status))
249
+				{
250
+					$this->status = admin_cmd::successful;
251
+				}
246 252
 			}
247 253
 			catch (Exception $e) {
248 254
 				_egw_log_exception($e);
@@ -339,7 +345,10 @@  discard block
 block discarded – undo
339 345
 	function delete()
340 346
 	{
341 347
 		$this->cancel_periodic_job();
342
-		if ($this->status != admin_cmd::scheduled) return false;
348
+		if ($this->status != admin_cmd::scheduled)
349
+		{
350
+			return false;
351
+		}
343 352
 
344 353
 		$this->status = admin_cmd::deleted;
345 354
 
@@ -365,7 +374,10 @@  discard block
 block discarded – undo
365 374
 		{
366 375
 			$this->modified = time();
367 376
 			$this->modifier = $set_modifier ? $GLOBALS['egw_info']['user']['account_id'] : 0;
368
-			if ($set_modifier) $this->modifier_email = admin_cmd::user_email();
377
+			if ($set_modifier)
378
+			{
379
+				$this->modifier_email = admin_cmd::user_email();
380
+			}
369 381
 		}
370 382
 		$vars = get_object_vars($this);	// does not work in php5.1.2 due a bug
371 383
 
@@ -481,10 +493,13 @@  discard block
 block discarded – undo
481 493
 		}
482 494
 		$cmd = new $class($data);
483 495
 
484
-		if ($cmd instanceof admin_cmd)	// dont allow others classes to be executed that way!
496
+		if ($cmd instanceof admin_cmd)
497
+		{
498
+			// dont allow others classes to be executed that way!
485 499
 		{
486 500
 			return $cmd;
487 501
 		}
502
+		}
488 503
 		throw new Api\Exception\WrongParameter(lang('%1 is no command!',$class), 10);
489 504
 	}
490 505
 
@@ -521,7 +536,10 @@  discard block
 block discarded – undo
521 536
 
522 537
 		$total = admin_cmd::$sql->get_rows($query,$rows,$readonlys);
523 538
 
524
-		if (!$rows) return 0;
539
+		if (!$rows)
540
+		{
541
+			return 0;
542
+		}
525 543
 
526 544
 		$async = new Api\Asyncservice();
527 545
 		foreach($rows as &$row)
@@ -746,7 +764,10 @@  discard block
 block discarded – undo
746 764
 			}
747 765
 		}
748 766
 		unset($vars['data']);
749
-		if ($this->data) $vars = array_merge($this->data,$vars);
767
+		if ($this->data)
768
+		{
769
+			$vars = array_merge($this->data,$vars);
770
+		}
750 771
 
751 772
 		return $vars;
752 773
 	}
@@ -765,10 +786,13 @@  discard block
 block discarded – undo
765 786
 			admin_cmd::_instanciate_acl($this->creator);
766 787
 			// todo: check only if and with $this->creator
767 788
 			if (!admin_cmd::$acl->check('run',1,'admin') &&		// creator is no longer admin
768
-				$extra_acl && $extra_deny && admin_cmd::$acl->check($extra_acl,$extra_deny,'admin'))	// creator is explicitly forbidden to do something
789
+				$extra_acl && $extra_deny && admin_cmd::$acl->check($extra_acl,$extra_deny,'admin'))
790
+			{
791
+				// creator is explicitly forbidden to do something
769 792
 			{
770 793
 				throw new Api\Exception\NoPermission\Admin();
771 794
 			}
795
+			}
772 796
 		}
773 797
 	}
774 798
 
@@ -785,11 +809,14 @@  discard block
 block discarded – undo
785 809
 		{
786 810
 			if (!isset($GLOBALS['egw_info']['apps'][$name]))
787 811
 			{
788
-				foreach($GLOBALS['egw_info']['apps'] as $app => $data)	// check against title and localised name
812
+				foreach($GLOBALS['egw_info']['apps'] as $app => $data)
813
+				{
814
+					// check against title and localised name
789 815
 				{
790 816
 					if (!strcasecmp($name,$data['title']) || !strcasecmp($name,lang($app)))
791 817
 					{
792 818
 						$apps[$key] = $name = $app;
819
+				}
793 820
 						break;
794 821
 					}
795 822
 				}
@@ -824,7 +851,11 @@  discard block
 block discarded – undo
824 851
 		{
825 852
 			throw new Api\Exception\WrongUserinput(lang("Wrong account type: %1 is NO %2 !!!",$account,$allow_only_user?lang('user'):lang('group')), 16);
826 853
 		}
827
-		if ($type == 2 && $id > 0) $id = -$id;	// groups use negative id's internally, fix it, if user given the wrong sign
854
+		if ($type == 2 && $id > 0)
855
+		{
856
+			$id = -$id;
857
+		}
858
+		// groups use negative id's internally, fix it, if user given the wrong sign
828 859
 
829 860
 		return $id;
830 861
 	}
@@ -840,7 +871,10 @@  discard block
 block discarded – undo
840 871
 	 */
841 872
 	static function parse_accounts($accounts,$allow_only_user=null)
842 873
 	{
843
-		if (!$accounts) return null;
874
+		if (!$accounts)
875
+		{
876
+			return null;
877
+		}
844 878
 
845 879
 		$ids = array();
846 880
 		foreach(is_array($accounts) ? $accounts : explode(',',$accounts) as $account)
@@ -859,9 +893,12 @@  discard block
 block discarded – undo
859 893
 	 */
860 894
 	static function parse_date($date)
861 895
 	{
862
-		if (!is_numeric($date))	// we allow to input a timestamp
896
+		if (!is_numeric($date))
897
+		{
898
+			// we allow to input a timestamp
863 899
 		{
864 900
 			$datein = $date;
901
+		}
865 902
 			// convert german DD.MM.YYYY format into ISO YYYY-MM-DD format
866 903
 			$date = preg_replace('/^([0-9]{1,2})\.([0-9]{1,2})\.([0-9]{4})$/','\3-\2-\1',$date);
867 904
 
@@ -1019,10 +1056,13 @@  discard block
 block discarded – undo
1019 1056
 			return false;		// no schduled command, no need to setup the job
1020 1057
 		}
1021 1058
 		$next = $jobs[0];
1022
-		if (($time = $next['scheduled']) < time())	// should run immediatly
1059
+		if (($time = $next['scheduled']) < time())
1060
+		{
1061
+			// should run immediatly
1023 1062
 		{
1024 1063
 			return admin_cmd::run_queued_jobs();
1025 1064
 		}
1065
+		}
1026 1066
 		$async = new Api\Asyncservice();
1027 1067
 
1028 1068
 		// we cant use this class as callback, as it's abstract and ExecMethod used by the async service instanciated the class!
@@ -1080,7 +1120,10 @@  discard block
 block discarded – undo
1080 1120
 	 */
1081 1121
 	public function set_periodic_job()
1082 1122
 	{
1083
-		if (empty($this->rrule)) return false;
1123
+		if (empty($this->rrule))
1124
+		{
1125
+			return false;
1126
+		}
1084 1127
 
1085 1128
 		// parse rrule and calculate next execution time
1086 1129
 		$event = calendar_rrule::parseRrule($this->rrule, true);	// true: allow HOURLY or MINUTELY
@@ -1201,10 +1244,13 @@  discard block
 block discarded – undo
1201 1244
 	{
1202 1245
 		admin_cmd::_instanciate_remote();
1203 1246
 
1204
-		if ($data['install_id'] && $data['config_passwd'])	// calculate hash
1247
+		if ($data['install_id'] && $data['config_passwd'])
1248
+		{
1249
+			// calculate hash
1205 1250
 		{
1206 1251
 			$data['remote_hash'] = self::remote_hash($data['install_id'],$data['config_passwd']);
1207 1252
 		}
1253
+		}
1208 1254
 		elseif (!$data['remote_hash'] && !($data['install_id'] && $data['config_passwd']))
1209 1255
 		{
1210 1256
 			throw new Api\Exception\WrongUserinput(lang('Either Install ID AND Api\Config password needed OR the remote hash!'));
@@ -1238,7 +1284,10 @@  discard block
 block discarded – undo
1238 1284
 		{
1239 1285
 			throw new Api\Exception\WrongParameter(empty($config_passwd)?'Empty Api\Config password':'install_id no md5 hash');
1240 1286
 		}
1241
-		if (!self::is_md5($config_passwd)) $config_passwd = md5($config_passwd);
1287
+		if (!self::is_md5($config_passwd))
1288
+		{
1289
+			$config_passwd = md5($config_passwd);
1290
+		}
1242 1291
 
1243 1292
 		return md5($config_passwd.$install_id);
1244 1293
 	}
@@ -1368,7 +1417,10 @@  discard block
 block discarded – undo
1368 1417
 				{
1369 1418
 					// remember label from last description widget
1370 1419
 					case 'description':
1371
-						if (!empty($widget->attrs['value'])) $label = $widget->attrs['value'];
1420
+						if (!empty($widget->attrs['value']))
1421
+						{
1422
+							$label = $widget->attrs['value'];
1423
+						}
1372 1424
 						break;
1373 1425
 					// ignore non input-widgets
1374 1426
 					case 'hbox': case 'vbox': case 'box': case 'groupbox':
@@ -1380,8 +1432,14 @@  discard block
 block discarded – undo
1380 1432
 					default:
1381 1433
 						if (!empty($widget->id))
1382 1434
 						{
1383
-							if (!empty($widget->attrs['label'])) $label = $widget->attrs['label'];
1384
-							if (!empty($label)) $labels[$widget->id] = $label;
1435
+							if (!empty($widget->attrs['label']))
1436
+							{
1437
+								$label = $widget->attrs['label'];
1438
+							}
1439
+							if (!empty($label))
1440
+							{
1441
+								$labels[$widget->id] = $label;
1442
+							}
1385 1443
 							$label = null;
1386 1444
 						}
1387 1445
 						break;
@@ -1419,7 +1477,10 @@  discard block
 block discarded – undo
1419 1477
 					case 'button': case 'buttononly': case 'taglist-thumbnail':
1420 1478
 						break;
1421 1479
 					case 'radio':
1422
-						if (!is_array($widgets[$widget->id])) $widgets[$widget->id] = [];
1480
+						if (!is_array($widgets[$widget->id]))
1481
+						{
1482
+							$widgets[$widget->id] = [];
1483
+						}
1423 1484
 						$label = (string)$widget->attrs['label'];
1424 1485
 						// translate "{something} {else}" type options
1425 1486
 						if (strpos($label, '{') !== false)
@@ -1433,7 +1494,10 @@  discard block
 block discarded – undo
1433 1494
 						break;
1434 1495
 					// config templates have options in the template
1435 1496
 					case 'option':
1436
-						if (!is_array($widgets[$last_select])) $widgets[$last_select] = [];
1497
+						if (!is_array($widgets[$last_select]))
1498
+						{
1499
+							$widgets[$last_select] = [];
1500
+						}
1437 1501
 						$label = (string)$widget->attrs['#text'];
1438 1502
 						// translate "{something} {else}" type options
1439 1503
 						if (strpos($label, '{') !== false)
Please login to merge, or discard this patch.