Completed
Push — 16.1 ( a61395...f8fa80 )
by Nathan
17:04
created
api/src/Accounts.php 1 patch
Spacing   +101 added lines, -102 removed lines patch added patch discarded remove patch
@@ -57,8 +57,8 @@  discard block
 block discarded – undo
57 57
 	 *
58 58
 	 * @var array
59 59
 	 */
60
-	var $depricated_names = array('firstname','lastname','fullname','email','type',
61
-		'status','expires','lastlogin','lastloginfrom','lastpasswd_change');
60
+	var $depricated_names = array('firstname', 'lastname', 'fullname', 'email', 'type',
61
+		'status', 'expires', 'lastlogin', 'lastloginfrom', 'lastpasswd_change');
62 62
 
63 63
 	/**
64 64
 	 * List of all config vars accounts depend on and therefore should be passed in when calling contructor with array syntax
@@ -66,11 +66,11 @@  discard block
 block discarded – undo
66 66
 	 * @var array
67 67
 	 */
68 68
 	static public $config_vars = array(
69
-		'account_repository', 'auth_type',	// auth_type if fallback if account_repository is not set
70
-		'install_id',	// instance-specific caching
71
-		'auto_create_expire', 'default_group_lid',	// auto-creation of accounts
72
-		'ldap_host','ldap_root_dn','ldap_root_pw','ldap_context','ldap_group_context','ldap_search_filter',	// ldap backend
73
-		'ads_domain', 'ads_host', 'ads_admin_user', 'ads_admin_passwd', 'ads_connection', 'ads_context',	// ads backend
69
+		'account_repository', 'auth_type', // auth_type if fallback if account_repository is not set
70
+		'install_id', // instance-specific caching
71
+		'auto_create_expire', 'default_group_lid', // auto-creation of accounts
72
+		'ldap_host', 'ldap_root_dn', 'ldap_root_pw', 'ldap_context', 'ldap_group_context', 'ldap_search_filter', // ldap backend
73
+		'ads_domain', 'ads_host', 'ads_admin_user', 'ads_admin_passwd', 'ads_connection', 'ads_context', // ads backend
74 74
 	);
75 75
 
76 76
 	/**
@@ -135,18 +135,18 @@  discard block
 block discarded – undo
135 135
 	 *
136 136
 	 * @param string|array $backend =null string with backend 'sql'|'ldap', or whole config array, default read from global egw_info
137 137
 	 */
138
-	public function __construct($backend=null)
138
+	public function __construct($backend = null)
139 139
 	{
140 140
 		if (is_array($backend))
141 141
 		{
142 142
 			$this->config = $backend;
143 143
 			$backend = null;
144
-			self::$_instance = $this;	// also set instance returned by singleton
145
-			self::$cache = array();		// and empty our internal (session) cache
144
+			self::$_instance = $this; // also set instance returned by singleton
145
+			self::$cache = array(); // and empty our internal (session) cache
146 146
 		}
147 147
 		else
148 148
 		{
149
-			$this->config =& $GLOBALS['egw_info']['server'];
149
+			$this->config = & $GLOBALS['egw_info']['server'];
150 150
 
151 151
 			if (!isset(self::$_instance)) self::$_instance = $this;
152 152
 		}
@@ -195,11 +195,11 @@  discard block
 block discarded – undo
195 195
 	function search($param)
196 196
 	{
197 197
 		//error_log(__METHOD__.'('.array2string($param).') '.function_backtrace());
198
-		if (!isset($param['active'])) $param['active'] = true;	// default is true = only return active accounts
198
+		if (!isset($param['active'])) $param['active'] = true; // default is true = only return active accounts
199 199
 
200 200
 		// Check for lang(Group) in search - if there, we search all groups
201
-		$group_index = array_search(strtolower(lang('Group')), array_map('strtolower', $query = explode(' ',$param['query'])));
202
-		if($group_index !== FALSE && !(
201
+		$group_index = array_search(strtolower(lang('Group')), array_map('strtolower', $query = explode(' ', $param['query'])));
202
+		if ($group_index !== FALSE && !(
203 203
 				in_array($param['type'], array('accounts', 'groupmembers')) || is_int($param['type'])
204 204
 		))
205 205
 		{
@@ -227,8 +227,8 @@  discard block
 block discarded – undo
227 227
 		}
228 228
 		// no backend understands $param['app'], only sql understands type owngroups or groupmemember[+memberships]
229 229
 		// --> do an full search first and then filter and limit that search
230
-		elseif($param['app'] || $this->config['account_repository'] != 'sql' &&
231
-			in_array($param['type'], array('owngroups','groupmembers','groupmembers+memberships')))
230
+		elseif ($param['app'] || $this->config['account_repository'] != 'sql' &&
231
+			in_array($param['type'], array('owngroups', 'groupmembers', 'groupmembers+memberships')))
232 232
 		{
233 233
 			$app = $param['app'];
234 234
 			unset($param['app']);
@@ -240,15 +240,15 @@  discard block
 block discarded – undo
240 240
 
241 241
 			if ($param['type'] == 'owngroups')
242 242
 			{
243
-				$members = $this->memberships($GLOBALS['egw_info']['user']['account_id'],true);
243
+				$members = $this->memberships($GLOBALS['egw_info']['user']['account_id'], true);
244 244
 				$param['type'] = 'groups';
245 245
 			}
246
-			elseif(in_array($param['type'],array('groupmembers','groupmembers+memberships')))
246
+			elseif (in_array($param['type'], array('groupmembers', 'groupmembers+memberships')))
247 247
 			{
248 248
 				$members = array();
249
-				foreach((array)$this->memberships($GLOBALS['egw_info']['user']['account_id'],true) as $grp)
249
+				foreach ((array)$this->memberships($GLOBALS['egw_info']['user']['account_id'], true) as $grp)
250 250
 				{
251
-					$members = array_unique(array_merge($members, (array)$this->members($grp,true,$param['active'])));
251
+					$members = array_unique(array_merge($members, (array)$this->members($grp, true, $param['active'])));
252 252
 					if ($param['type'] == 'groupmembers+memberships') $members[] = $grp;
253 253
 				}
254 254
 				$param['type'] = $param['type'] == 'groupmembers+memberships' ? 'both' : 'accounts';
@@ -261,20 +261,20 @@  discard block
 block discarded – undo
261 261
 			if ($app)
262 262
 			{
263 263
 				// we want the result merged, whatever it takes, as we only care for the ids
264
-				$valid = $this->split_accounts($app,!in_array($param['type'],array('accounts','groups')) ? 'merge' : $param['type'],$param['active']);
264
+				$valid = $this->split_accounts($app, !in_array($param['type'], array('accounts', 'groups')) ? 'merge' : $param['type'], $param['active']);
265 265
 			}
266 266
 			if (isset($members))
267 267
 			{
268 268
 				//error_log(__METHOD__.'() members='.array2string($members));
269 269
 				if (!$members) $members = array();
270
-				$valid = !$app ? $members : array_intersect($valid,$members);	// use the intersection
270
+				$valid = !$app ? $members : array_intersect($valid, $members); // use the intersection
271 271
 			}
272 272
 			//error_log(__METHOD__."() limiting result to app='$app' and/or group=$group valid-ids=".array2string($valid));
273 273
 			$n = 0;
274 274
 			$account_search[$serial]['data'] = array();
275 275
 			foreach ($full_search as $id => $data)
276 276
 			{
277
-				if (!in_array($id,$valid))
277
+				if (!in_array($id, $valid))
278 278
 				{
279 279
 					$this->total--;
280 280
 					continue;
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
 			$account_search[$serial]['data'] = $this->backend->search($param);
295 295
 			if ($param['type'] !== 'accounts')
296 296
 			{
297
-				foreach($account_search[$serial]['data'] as &$account)
297
+				foreach ($account_search[$serial]['data'] as &$account)
298 298
 				{
299 299
 					// add default description for Admins and Default group
300 300
 					if ($account['account_type'] === 'g')
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
 		{
324 324
 			$options['filter'] = (array)$options['filter'];
325 325
 		}
326
-		switch($GLOBALS['egw_info']['user']['preferences']['common']['account_display'])
326
+		switch ($GLOBALS['egw_info']['user']['preferences']['common']['account_display'])
327 327
 		{
328 328
 			case 'firstname':
329 329
 			case 'firstall':
@@ -339,7 +339,7 @@  discard block
 block discarded – undo
339 339
 		}
340 340
 		$only_own = $GLOBALS['egw_info']['user']['preferences']['common']['account_selection'] === 'groupmembers' &&
341 341
 			!isset($GLOBALS['egw_info']['user']['apps']['admin']);
342
-		switch($options['account_type'])
342
+		switch ($options['account_type'])
343 343
 		{
344 344
 			case 'accounts':
345 345
 				$type = $only_own ? 'groupmembers' : 'accounts';
@@ -360,7 +360,7 @@  discard block
 block discarded – undo
360 360
 				break;
361 361
 		}
362 362
 		$accounts = array();
363
-		foreach(self::getInstance()->search(array(
363
+		foreach (self::getInstance()->search(array(
364 364
 			'type' => $options['filter']['group'] < 0 ? $options['filter']['group'] : $type,
365 365
 			'query' => $pattern,
366 366
 			'query_type' => 'all',
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
 		)) as $account)
369 369
 		{
370 370
 			$accounts[$account['account_id']] = self::format_username($account['account_lid'],
371
-				$account['account_firstname'],$account['account_lastname'],$account['account_id']);
371
+				$account['account_firstname'], $account['account_lastname'], $account['account_id']);
372 372
 		}
373 373
 		return $accounts;
374 374
 	}
@@ -383,7 +383,7 @@  discard block
 block discarded – undo
383 383
 	 * @param boolean $set_depricated_names =false set _additionaly_ the depricated keys without 'account_' prefix
384 384
 	 * @return array/boolean array with account data (keys: account_id, account_lid, ...) or false if account not found
385 385
 	 */
386
-	function read($id, $set_depricated_names=false)
386
+	function read($id, $set_depricated_names = false)
387 387
 	{
388 388
 		if (!is_int($id) && !is_numeric($id))
389 389
 		{
@@ -401,9 +401,9 @@  discard block
 block discarded – undo
401 401
 
402 402
 		if ($set_depricated_names && $data)
403 403
 		{
404
-			foreach($this->depricated_names as $name)
404
+			foreach ($this->depricated_names as $name)
405 405
 			{
406
-				$data[$name] =& $data['account_'.$name];
406
+				$data[$name] = & $data['account_'.$name];
407 407
 			}
408 408
 		}
409 409
 		return $data;
@@ -420,8 +420,8 @@  discard block
 block discarded – undo
420 420
 	function json($id)
421 421
 	{
422 422
 		static $keys = array(
423
-			'account_id','account_lid','person_id','account_status',
424
-			'account_firstname','account_lastname','account_email','account_fullname','account_phone',
423
+			'account_id', 'account_lid', 'person_id', 'account_status',
424
+			'account_firstname', 'account_lastname', 'account_email', 'account_fullname', 'account_phone',
425 425
 		);
426 426
 		if (($account = $this->read($id)))
427 427
 		{
@@ -430,9 +430,9 @@  discard block
 block discarded – undo
430 430
 		// for current user, add the apps available to him
431 431
 		if ($id == $GLOBALS['egw_info']['user']['account_id'])
432 432
 		{
433
-			foreach((array)$GLOBALS['egw_info']['user']['apps'] as $app => $data)
433
+			foreach ((array)$GLOBALS['egw_info']['user']['apps'] as $app => $data)
434 434
 			{
435
-				unset($data['table_defs']);	// no need for that on the client
435
+				unset($data['table_defs']); // no need for that on the client
436 436
 				$account['apps'][$app] = $data;
437 437
 			}
438 438
 		}
@@ -447,7 +447,7 @@  discard block
 block discarded – undo
447 447
 	 * @param $lastname ='' lastname
448 448
 	 * @param $accountid =0 id, to check if it's a user or group, otherwise the lid will be used
449 449
 	 */
450
-	static function format_username($lid = '', $firstname = '', $lastname = '', $accountid=0)
450
+	static function format_username($lid = '', $firstname = '', $lastname = '', $accountid = 0)
451 451
 	{
452 452
 		if (!$lid && !$firstname && !$lastname)
453 453
 		{
@@ -460,7 +460,7 @@  discard block
 block discarded – undo
460 460
 		if (empty($firstname)) $firstname = $lid;
461 461
 		if (empty($lastname) || $is_group)
462 462
 		{
463
-			$lastname  = $is_group ? lang('Group') : lang('User');
463
+			$lastname = $is_group ? lang('Group') : lang('User');
464 464
 		}
465 465
 		$display = $GLOBALS['egw_info']['user']['preferences']['common']['account_display'];
466 466
 
@@ -474,30 +474,30 @@  discard block
 block discarded – undo
474 474
 		}
475 475
 
476 476
 		$name = '';
477
-		switch($display)
477
+		switch ($display)
478 478
 		{
479 479
 			case 'firstname':
480
-				$name = $firstname . ' ' . $lastname;
480
+				$name = $firstname.' '.$lastname;
481 481
 				break;
482 482
 			case 'lastname':
483
-				$name = $lastname . $delimiter . $firstname;
483
+				$name = $lastname.$delimiter.$firstname;
484 484
 				break;
485 485
 			case 'username':
486 486
 				$name = $lid;
487 487
 				break;
488 488
 			case 'firstall':
489
-				$name = $firstname . ' ' . $lastname . ' ['.$lid.']';
489
+				$name = $firstname.' '.$lastname.' ['.$lid.']';
490 490
 				break;
491 491
 			case 'lastall':
492
-				$name = $lastname . $delimiter . $firstname . ' ['.$lid.']';
492
+				$name = $lastname.$delimiter.$firstname.' ['.$lid.']';
493 493
 				break;
494 494
 			case 'allfirst':
495
-				$name = '['.$lid.'] ' . $firstname . ' ' . $lastname;
495
+				$name = '['.$lid.'] '.$firstname.' '.$lastname;
496 496
 				break;
497 497
 			case 'all':
498 498
 				/* fall through */
499 499
 			default:
500
-				$name = '['.$lid.'] ' . $lastname . $delimiter . $firstname;
500
+				$name = '['.$lid.'] '.$lastname.$delimiter.$firstname;
501 501
 		}
502 502
 		return $name;
503 503
 	}
@@ -508,14 +508,14 @@  discard block
 block discarded – undo
508 508
 	 * @param string $account_id =null account id
509 509
 	 * @return string full name of user or "#$accountid" if user not found
510 510
 	 */
511
-	static function username($account_id=null)
511
+	static function username($account_id = null)
512 512
 	{
513 513
 		if ($account_id && !($account = self::cache_read((int)$account_id)))
514 514
 		{
515 515
 			return '#'.$account_id;
516 516
 		}
517 517
 		return self::format_username($account['account_lid'],
518
-			$account['account_firstname'] , $account['account_lastname'], $account_id);
518
+			$account['account_firstname'], $account['account_lastname'], $account_id);
519 519
 	}
520 520
 
521 521
 	/**
@@ -529,9 +529,9 @@  discard block
 block discarded – undo
529 529
 	 * @param string $domain =null domain-name or null to use eGW's default domain $GLOBALS['egw_info']['server']['mail_suffix]
530 530
 	 * @return string with email address
531 531
 	 */
532
-	static function email($first,$last,$account,$domain=null)
532
+	static function email($first, $last, $account, $domain = null)
533 533
 	{
534
-		foreach (array('first','last','account') as $name)
534
+		foreach (array('first', 'last', 'account') as $name)
535 535
 		{
536 536
 			$$name = Translation::to_ascii($$name);
537 537
 		}
@@ -553,8 +553,8 @@  discard block
 block discarded – undo
553 553
 		if (!$domain) $domain = $GLOBALS['egw_info']['server']['mail_suffix'];
554 554
 		if (!$domain) $domain = $_SERVER['SERVER_NAME'];
555 555
 
556
-		$email = str_replace(array('first','last','initial','account','dot','underscore','-'),
557
-			array($first,$last,substr($first,0,1),$account,$dot,$underscore,''),
556
+		$email = str_replace(array('first', 'last', 'initial', 'account', 'dot', 'underscore', '-'),
557
+			array($first, $last, substr($first, 0, 1), $account, $dot, $underscore, ''),
558 558
 			$GLOBALS['egw_info']['server']['email_address_format'] ? $GLOBALS['egw_info']['server']['email_address_format'] : 'first-dot-last').
559 559
 			($domain ? '@'.$domain : '');
560 560
 		//echo " = '$email'</p>\n";
@@ -570,7 +570,7 @@  discard block
 block discarded – undo
570 570
 	{
571 571
 		if (empty($data['account_description']))
572 572
 		{
573
-			switch($data['account_lid'])
573
+			switch ($data['account_lid'])
574 574
 			{
575 575
 				case 'Default':
576 576
 					$data['account_description'] = lang('EGroupware all users group, do NOT delete');
@@ -598,15 +598,15 @@  discard block
 block discarded – undo
598 598
 	 * @param boolean $check_depricated_names =false check _additionaly_ the depricated keys without 'account_' prefix
599 599
 	 * @return int|boolean the account_id or false on error
600 600
 	 */
601
-	function save(&$data,$check_depricated_names=false)
601
+	function save(&$data, $check_depricated_names = false)
602 602
 	{
603 603
 		if ($check_depricated_names)
604 604
 		{
605
-			foreach($this->depricated_names as $name)
605
+			foreach ($this->depricated_names as $name)
606 606
 			{
607 607
 				if (isset($data[$name]) && !isset($data['account_'.$name]))
608 608
 				{
609
-					$data['account_'.$name] =& $data[$name];
609
+					$data['account_'.$name] = & $data[$name];
610 610
 				}
611 611
 			}
612 612
 		}
@@ -619,7 +619,7 @@  discard block
 block discarded – undo
619 619
 		{
620 620
 			// if we are not on a pure LDAP system, we have to write the account-date via the contacts class now
621 621
 			if (($this->config['account_repository'] == 'sql' || $this->config['contact_repository'] == 'sql-ldap') &&
622
-				(!($old = $this->read($data['account_id'])) ||	// only for new account or changed contact-data
622
+				(!($old = $this->read($data['account_id'])) || // only for new account or changed contact-data
623 623
 				$old['account_firstname'] != $data['account_firstname'] ||
624 624
 				$old['account_lastname'] != $data['account_lastname'] ||
625 625
 				$old['account_email'] != $data['account_email']))
@@ -634,14 +634,14 @@  discard block
 block discarded – undo
634 634
 					'id'         => $data['person_id'],
635 635
 					'owner'      => 0,
636 636
 				);
637
-				$GLOBALS['egw']->contacts->save($contact,true);		// true = ignore addressbook acl
637
+				$GLOBALS['egw']->contacts->save($contact, true); // true = ignore addressbook acl
638 638
 			}
639 639
 			// save primary group if necessary
640
-			if ($data['account_primary_group'] && (!($memberships = $this->memberships($id,true)) ||
641
-				!in_array($data['account_primary_group'],$memberships)))
640
+			if ($data['account_primary_group'] && (!($memberships = $this->memberships($id, true)) ||
641
+				!in_array($data['account_primary_group'], $memberships)))
642 642
 			{
643 643
 				$memberships[] = $data['account_primary_group'];
644
-				$this->set_memberships($memberships, $id);	// invalidates cache for account_id and primary group
644
+				$this->set_memberships($memberships, $id); // invalidates cache for account_id and primary group
645 645
 			}
646 646
 		}
647 647
 		// as some backends set (group-)members in save, we need to invalidate their members too!
@@ -733,10 +733,10 @@  discard block
 block discarded – undo
733 733
 	 * @param string $account_type =null u = user or g = group, or default null = try both
734 734
 	 * @return int|false numeric account_id or false on error ($name not found)
735 735
 	 */
736
-	function name2id($name,$which='account_lid',$account_type=null)
736
+	function name2id($name, $which = 'account_lid', $account_type = null)
737 737
 	{
738 738
 		// Don't bother searching for empty or non-scalar account_lid
739
-		if(empty($name) || !is_scalar($name))
739
+		if (empty($name) || !is_scalar($name))
740 740
 		{
741 741
 			return False;
742 742
 		}
@@ -744,12 +744,12 @@  discard block
 block discarded – undo
744 744
 		self::setup_cache();
745 745
 		$name_list = &self::$cache['name_list'];
746 746
 
747
-		if(@isset($name_list[$which][$name]) && $name_list[$which][$name])
747
+		if (@isset($name_list[$which][$name]) && $name_list[$which][$name])
748 748
 		{
749 749
 			return $name_list[$which][$name];
750 750
 		}
751 751
 
752
-		return $name_list[$which][$name] = $this->backend->name2id($name,$which,$account_type);
752
+		return $name_list[$which][$name] = $this->backend->name2id($name, $which, $account_type);
753 753
 	}
754 754
 
755 755
 	/**
@@ -762,7 +762,7 @@  discard block
 block discarded – undo
762 762
 	 * @param boolean $generate_email =false true: generate an email address, if user has none
763 763
 	 * @return string|boolean converted value or false on error ($account_id not found)
764 764
 	 */
765
-	static function id2name($account_id, $which='account_lid', $generate_email=false)
765
+	static function id2name($account_id, $which = 'account_lid', $generate_email = false)
766 766
 	{
767 767
 		if (!is_numeric($account_id) && !($account_id = self::getInstance()->name2id($account_id)))
768 768
 		{
@@ -838,13 +838,13 @@  discard block
 block discarded – undo
838 838
 				$account_lid != $GLOBALS['egw_info']['user']['account_lid'] ||
839 839
 			// only allow group-members for account-selection is groupmembers
840 840
 			$GLOBALS['egw_info']['user']['preferences']['common']['account_selection'] == 'groupmembers' &&
841
-				!array_intersect((array)$this->memberships($account_id,true),
842
-					(array)$this->memberships($GLOBALS['egw_info']['user']['account_id'],true))))
841
+				!array_intersect((array)$this->memberships($account_id, true),
842
+					(array)$this->memberships($GLOBALS['egw_info']['user']['account_id'], true))))
843 843
 		{
844 844
 			//error_log(__METHOD__."($account_id='$account_lid') returning FALSE");
845
-			return false;	// user is not allowed to see given account
845
+			return false; // user is not allowed to see given account
846 846
 		}
847
-		return true;	// user allowed to see given account
847
+		return true; // user allowed to see given account
848 848
 	}
849 849
 
850 850
 	/**
@@ -854,11 +854,11 @@  discard block
 block discarded – undo
854 854
 	 * @param boolean $just_id =false return just account_id's or account_id => account_lid pairs
855 855
 	 * @return array with account_id's ($just_id) or account_id => account_lid pairs (!$just_id)
856 856
 	 */
857
-	function memberships($account_id, $just_id=false)
857
+	function memberships($account_id, $just_id = false)
858 858
 	{
859 859
 		if (!is_int($account_id) && !is_numeric($account_id))
860 860
 		{
861
-			$account_id = $this->name2id($account_id,'account_lid','u');
861
+			$account_id = $this->name2id($account_id, 'account_lid', 'u');
862 862
 		}
863 863
 		if ($account_id && ($data = self::cache_read($account_id)))
864 864
 		{
@@ -874,7 +874,7 @@  discard block
 block discarded – undo
874 874
 	 * @param array $groups array with gidnumbers
875 875
 	 * @param int $account_id uidnumber
876 876
 	 */
877
-	function set_memberships($groups,$account_id)
877
+	function set_memberships($groups, $account_id)
878 878
 	{
879 879
 		if (!is_int($account_id) && !is_numeric($account_id))
880 880
 		{
@@ -902,7 +902,7 @@  discard block
 block discarded – undo
902 902
 	 * @param boolean $active =false true: return only active (not expired or deactived) members, false: return all accounts
903 903
 	 * @return array with account_id ($just_id) or account_id => account_lid pairs (!$just_id)
904 904
 	 */
905
-	function members($account_id, $just_id=false, $active=true)
905
+	function members($account_id, $just_id = false, $active = true)
906 906
 	{
907 907
 		if (!is_int($account_id) && !is_numeric($account_id))
908 908
 		{
@@ -923,7 +923,7 @@  discard block
 block discarded – undo
923 923
 	 * @param array $members array with uidnumber or uid's
924 924
 	 * @param int $gid gidnumber of group to set
925 925
 	 */
926
-	function set_members($members,$gid)
926
+	function set_members($members, $gid)
927 927
 	{
928 928
 		if (($old_members = $this->members($gid, true, false)) != $members)
929 929
 		{
@@ -947,7 +947,7 @@  discard block
 block discarded – undo
947 947
 	 * @param boolean $active =false true: return only active (not expired or deactived) members, false: return all accounts
948 948
 	 * @return array/boolean see $use, false on error (wront $use)
949 949
 	 */
950
-	function split_accounts($app_users,$use='both',$active=true)
950
+	function split_accounts($app_users, $use = 'both', $active = true)
951 951
 	{
952 952
 		if (!is_array($app_users))
953 953
 		{
@@ -958,21 +958,21 @@  discard block
 block discarded – undo
958 958
 			{
959 959
 				return $cache;
960 960
 			}
961
-			$app_users = $GLOBALS['egw']->acl->get_ids_for_location('run',1,$app_users);
961
+			$app_users = $GLOBALS['egw']->acl->get_ids_for_location('run', 1, $app_users);
962 962
 		}
963 963
 		$accounts = array(
964 964
 			'accounts' => array(),
965 965
 			'groups' => array(),
966 966
 		);
967
-		foreach($app_users as $id)
967
+		foreach ($app_users as $id)
968 968
 		{
969 969
 			$type = $this->get_type($id);
970
-			if($type == 'g')
970
+			if ($type == 'g')
971 971
 			{
972 972
 				$accounts['groups'][$id] = $id;
973 973
 				if ($use != 'groups')
974 974
 				{
975
-					foreach((array)$this->members($id, true, $active) as $id)
975
+					foreach ((array)$this->members($id, true, $active) as $id)
976 976
 					{
977 977
 						$accounts['accounts'][$id] = $id;
978 978
 					}
@@ -993,7 +993,7 @@  discard block
 block discarded – undo
993 993
 			$cache = $accounts;
994 994
 		}
995 995
 
996
-		switch($use)
996
+		switch ($use)
997 997
 		{
998 998
 			case 'both':
999 999
 				return $accounts;
@@ -1002,7 +1002,7 @@  discard block
 block discarded – undo
1002 1002
 			case 'accounts':
1003 1003
 				return $accounts['accounts'];
1004 1004
 			case 'merge':
1005
-				return array_merge($accounts['accounts'],$accounts['groups']);
1005
+				return array_merge($accounts['accounts'], $accounts['groups']);
1006 1006
 		}
1007 1007
 		return False;
1008 1008
 	}
@@ -1020,21 +1020,20 @@  discard block
 block discarded – undo
1020 1020
 	function auto_add($account_lid, $passwd)
1021 1021
 	{
1022 1022
 		$expires = !isset($this->config['auto_create_expire']) ||
1023
-			$this->config['auto_create_expire'] == 'never' ? -1 :
1024
-			time() + $this->config['auto_create_expire'] + 2;
1023
+			$this->config['auto_create_expire'] == 'never' ? -1 : time() + $this->config['auto_create_expire'] + 2;
1025 1024
 
1026 1025
 		$memberships = array();
1027 1026
 		$default_group_id = null;
1028 1027
 		// check if we have a comma or semicolon delimited list of groups --> add first as primary and rest as memberships
1029
-		foreach(preg_split('/[,;] */',$this->config['default_group_lid']) as $group_lid)
1028
+		foreach (preg_split('/[,;] */', $this->config['default_group_lid']) as $group_lid)
1030 1029
 		{
1031
-			if (($group_id = $this->name2id($group_lid,'account_lid','g')))
1030
+			if (($group_id = $this->name2id($group_lid, 'account_lid', 'g')))
1032 1031
 			{
1033 1032
 				if (!$default_group_id) $default_group_id = $group_id;
1034 1033
 				$memberships[] = $group_id;
1035 1034
 			}
1036 1035
 		}
1037
-		if (!$default_group_id && ($default_group_id = $this->name2id('Default','account_lid','g')))
1036
+		if (!$default_group_id && ($default_group_id = $this->name2id('Default', 'account_lid', 'g')))
1038 1037
 		{
1039 1038
 			$memberships[] = $default_group_id;
1040 1039
 		}
@@ -1071,25 +1070,25 @@  discard block
 block discarded – undo
1071 1070
 		// set memberships if given
1072 1071
 		if ($memberships)
1073 1072
 		{
1074
-			$this->set_memberships($memberships,$data['account_id']);
1073
+			$this->set_memberships($memberships, $data['account_id']);
1075 1074
 		}
1076 1075
 		// set the appropriate value for the can change password flag (assume users can, if the admin requires users to change their password)
1077 1076
 		$data['changepassword'] = (bool)$GLOBALS['egw_info']['server']['change_pwd_every_x_days'];
1078
-		if(!$data['changepassword'])
1077
+		if (!$data['changepassword'])
1079 1078
 		{
1080
-			$GLOBALS['egw']->acl->add_repository('preferences','nopasswordchange',$data['account_id'],1);
1079
+			$GLOBALS['egw']->acl->add_repository('preferences', 'nopasswordchange', $data['account_id'], 1);
1081 1080
 		}
1082 1081
 		else
1083 1082
 		{
1084
-			$GLOBALS['egw']->acl->delete_repository('preferences','nopasswordchange',$data['account_id']);
1083
+			$GLOBALS['egw']->acl->delete_repository('preferences', 'nopasswordchange', $data['account_id']);
1085 1084
 		}
1086 1085
 		// call hook to notify interested apps about the new account
1087 1086
 		$GLOBALS['hook_values'] = $data;
1088
-		Hooks::process($data+array(
1087
+		Hooks::process($data + array(
1089 1088
 			'location' => 'addaccount',
1090 1089
 			// at login-time only the hooks from the following apps will be called
1091
-			'order' => array('felamimail','fudforum'),
1092
-		),False,True);  // called for every app now, not only enabled ones
1090
+			'order' => array('felamimail', 'fudforum'),
1091
+		), False, True); // called for every app now, not only enabled ones
1093 1092
 		unset($data['changepassword']);
1094 1093
 
1095 1094
 		return $data['account_id'];
@@ -1136,14 +1135,14 @@  discard block
 block discarded – undo
1136 1135
 	 *
1137 1136
 	 * @param int|array $account_ids user- or group-id(s) for which cache should be invalidated, default 0 = only search/name2id cache
1138 1137
 	 */
1139
-	static function cache_invalidate($account_ids=0)
1138
+	static function cache_invalidate($account_ids = 0)
1140 1139
 	{
1141 1140
 		//error_log(__METHOD__.'('.array2string($account_ids).')');
1142 1141
 
1143 1142
 		// instance-wide cache
1144 1143
 		if ($account_ids)
1145 1144
 		{
1146
-			foreach((array)$account_ids as $account_id)
1145
+			foreach ((array)$account_ids as $account_id)
1147 1146
 			{
1148 1147
 				$instance = self::getInstance();
1149 1148
 
@@ -1155,11 +1154,11 @@  discard block
 block discarded – undo
1155 1154
 
1156 1155
 		// session-cache
1157 1156
 		if (self::$cache) self::$cache = array();
1158
-		Cache::unsetSession('accounts_cache','phpgwapi');
1157
+		Cache::unsetSession('accounts_cache', 'phpgwapi');
1159 1158
 
1160
-		if (method_exists($GLOBALS['egw'],'invalidate_session_cache'))	// egw object in setup is limited
1159
+		if (method_exists($GLOBALS['egw'], 'invalidate_session_cache'))	// egw object in setup is limited
1161 1160
 		{
1162
-			Egw::invalidate_session_cache();	// invalidates whole egw-enviroment if stored in the session
1161
+			Egw::invalidate_session_cache(); // invalidates whole egw-enviroment if stored in the session
1163 1162
 		}
1164 1163
 	}
1165 1164
 
@@ -1183,11 +1182,11 @@  discard block
 block discarded – undo
1183 1182
 	 * @return array
1184 1183
 	 * @throws Exception\WrongParameter if no integer was passed as $account_id
1185 1184
 	 */
1186
-	static function cache_read($account_id, $need_active=false)
1185
+	static function cache_read($account_id, $need_active = false)
1187 1186
 	{
1188 1187
 		if (!is_numeric($account_id)) throw new Exception\WrongParameter('Not an integer!');
1189 1188
 
1190
-		$account =& self::$request_cache[$account_id];
1189
+		$account = & self::$request_cache[$account_id];
1191 1190
 
1192 1191
 		if (!isset($account))	// not in request cache --> try instance cache
1193 1192
 		{
@@ -1218,7 +1217,7 @@  discard block
 block discarded – undo
1218 1217
 		{
1219 1218
 			$instance = self::getInstance();
1220 1219
 			$account['members-active'] = array();
1221
-			foreach((array)$account['members'] as $id => $lid)
1220
+			foreach ((array)$account['members'] as $id => $lid)
1222 1221
 			{
1223 1222
 				if ($instance->is_active($id)) $account['members-active'][$id] = $lid;
1224 1223
 			}
@@ -1244,11 +1243,11 @@  discard block
 block discarded – undo
1244 1243
 	 */
1245 1244
 	private static function setup_cache()
1246 1245
 	{
1247
-		if (is_array(self::$cache)) return;	// cache is already setup
1246
+		if (is_array(self::$cache)) return; // cache is already setup
1248 1247
 
1249 1248
 		if (self::$use_session_cache && is_object($GLOBALS['egw']->session))
1250 1249
 		{
1251
-			self::$cache =& Cache::getSession('accounts_cache','phpgwapi');
1250
+			self::$cache = & Cache::getSession('accounts_cache', 'phpgwapi');
1252 1251
 		}
1253 1252
 		//error_log(__METHOD__."() use_session_cache=".array2string(self::$use_session_cache).", is_array(self::\$cache)=".array2string(is_array(self::$cache)));
1254 1253
 
Please login to merge, or discard this patch.
timesheet/inc/class.timesheet_ui.inc.php 2 patches
Spacing   +180 added lines, -183 removed lines patch added patch discarded remove patch
@@ -55,10 +55,10 @@  discard block
 block discarded – undo
55 55
 
56 56
 	function view()
57 57
 	{
58
-		$this->edit(null,true);
58
+		$this->edit(null, true);
59 59
 	}
60 60
 
61
-	function edit($content = null,$view = false)
61
+	function edit($content = null, $view = false)
62 62
 	{
63 63
 		$etpl = new Etemplate('timesheet.edit');
64 64
 		if (!is_array($content))
@@ -80,35 +80,34 @@  discard block
 block discarded – undo
80 80
 			{
81 81
 				$this->data = array(
82 82
 					'ts_start' => $this->today,
83
-					'start_time' => '',	// force empty start-time
84
-					'end_time' => Api\DateTime::to($this->now,'H:i'),
83
+					'start_time' => '', // force empty start-time
84
+					'end_time' => Api\DateTime::to($this->now, 'H:i'),
85 85
 					'ts_owner' => $GLOBALS['egw_info']['user']['account_id'],
86
-					'cat_id'   => (int) $_REQUEST['cat_id'],
86
+					'cat_id'   => (int)$_REQUEST['cat_id'],
87 87
 					'ts_status'=> $GLOBALS['egw_info']['user']['preferences']['timesheet']['predefined_status'],
88 88
 					'ts_project' => $_REQUEST['ts_project'],
89 89
 					'ts_title_blur' => $_REQUEST['ts_project'],
90 90
 				);
91
-				if(!is_numeric($_REQUEST['ts_project']))
91
+				if (!is_numeric($_REQUEST['ts_project']))
92 92
 				{
93 93
 					$this->data['pm_id'] = $this->find_pm_id($_REQUEST['ts_project']);
94 94
 				}
95 95
 			}
96 96
 			$matches = null;
97
-			$referer = preg_match('/menuaction=([^&]+)/',$_SERVER['HTTP_REFERER'],$matches) ? $matches[1] :
98
-				(strpos($_SERVER['HTTP_REFERER'],'/infolog/index.php') !== false ? 'infolog.infolog_ui.index' : TIMESHEET_APP.'.timesheet_ui.index');
97
+			$referer = preg_match('/menuaction=([^&]+)/', $_SERVER['HTTP_REFERER'], $matches) ? $matches[1] : (strpos($_SERVER['HTTP_REFERER'], '/infolog/index.php') !== false ? 'infolog.infolog_ui.index' : TIMESHEET_APP.'.timesheet_ui.index');
99 98
 
100
-			if($_GET['action'] == 'copy')
99
+			if ($_GET['action'] == 'copy')
101 100
 			{
102 101
 				$this->create_copy();
103
-				$msg = lang('%1 copied - the copy can now be edited', lang(Link::get_registry(TIMESHEET_APP,'entry')));
102
+				$msg = lang('%1 copied - the copy can now be edited', lang(Link::get_registry(TIMESHEET_APP, 'entry')));
104 103
 			}
105 104
 			if (!$this->check_statusForEditRights($this->data))
106 105
 			{
107
-				$view = true;  //only admin can edit with this status
106
+				$view = true; //only admin can edit with this status
108 107
 				$only_admin_edit = true;
109 108
 				$msg = lang('only Admin can edit this status');
110 109
 			}
111
-			if(!$this->data['ts_project_blur'])
110
+			if (!$this->data['ts_project_blur'])
112 111
 			{
113 112
 				$this->data['ts_project_blur'] = $this->data['pm_id'] ? Link::title('projectmanager', $this->data['pm_id']) : '';
114 113
 			}
@@ -120,7 +119,7 @@  discard block
 block discarded – undo
120 119
 			{
121 120
 				if ($this->status_labels_config[$content['ts_status']]['admin'])
122 121
 				{
123
-					$view = true;  //only admin can edit with this status
122
+					$view = true; //only admin can edit with this status
124 123
 					$only_admin_edit = true;
125 124
 					$msg = lang('only Admin can edit this status');
126 125
 				}
@@ -134,29 +133,29 @@  discard block
 block discarded – undo
134 133
 			{
135 134
 				//$content['ts_start'] += $content['start_time'];
136 135
 				$start = new Api\DateTime($content['ts_start']);
137
-				$start_time = explode(':',$content['start_time']);
138
-				$start->setTime($start_time[0],$start_time[1]);
136
+				$start_time = explode(':', $content['start_time']);
137
+				$start->setTime($start_time[0], $start_time[1]);
139 138
 				$content['ts_start'] = $start->format('ts');
140 139
 			}
141 140
 			if (isset($content['end_time']))		// end-time specified
142 141
 			{
143 142
 				$end = new Api\DateTime($content['ts_start']);
144
-				$end_time = explode(':',$content['end_time']);
145
-				$end->setTime($end_time[0],$end_time[1]);
143
+				$end_time = explode(':', $content['end_time']);
144
+				$end->setTime($end_time[0], $end_time[1]);
146 145
 			}
147 146
 			if ($end && $start)	// start- & end-time --> calculate the duration
148 147
 			{
149 148
 				$content['ts_duration'] = ($end->format('ts') - $start->format('ts')) / 60;
150 149
 				// check if negative duration is caused by wrap over midnight
151
-				if ($content['ts_duration'] < 0 && $content['ts_duration'] > -24*60)
150
+				if ($content['ts_duration'] < 0 && $content['ts_duration'] > -24 * 60)
152 151
 				{
153
-					$content['ts_duration'] += 24*60;
152
+					$content['ts_duration'] += 24 * 60;
154 153
 				}
155 154
 				//echo "<p>end_time=$content[end_time], start_time=$content[start_time] --> duration=$content[ts_duration]</p>\n";
156 155
 			}
157 156
 			elseif ($content['ts_duration'] && $end)	// no start, calculate from end and duration
158 157
 			{
159
-				$content['ts_start'] = $end->format('ts') - 60*$content['ts_duration'];
158
+				$content['ts_start'] = $end->format('ts') - 60 * $content['ts_duration'];
160 159
 				//echo "<p>end_time=$content[end_time], duration=$content[ts_duration] --> ts_start=$content[ts_start]=".Api\DateTime::to($content['ts_start'])."</p>\n";
161 160
 			}
162 161
 			if ($content['ts_duration'] > 0) unset($content['end_time']);
@@ -166,18 +165,18 @@  discard block
 block discarded – undo
166 165
 			$referer = $content['referer'];
167 166
 			$content['ts_project_blur'] = $content['pm_id'] ? Link::title('projectmanager', $content['pm_id']) : '';
168 167
 			$this->data = $content;
169
-			foreach(array('button','view','referer','tabs','start_time') as $key)
168
+			foreach (array('button', 'view', 'referer', 'tabs', 'start_time') as $key)
170 169
 			{
171 170
 				unset($this->data[$key]);
172 171
 			}
173
-			switch($button)
172
+			switch ($button)
174 173
 			{
175 174
 				case 'edit':
176 175
 					if ($this->check_acl(Acl::EDIT) && !$only_admin_edit) $view = false;
177 176
 					break;
178 177
 
179 178
 				case 'undelete':
180
-					if($content['ts_status'] == self::DELETED_STATUS)
179
+					if ($content['ts_status'] == self::DELETED_STATUS)
181 180
 					{
182 181
 						unset($content['ts_status']);
183 182
 						$this->data['ts_status'] = '';
@@ -195,18 +194,17 @@  discard block
 block discarded – undo
195 194
 					}
196 195
 					if (!$this->data['ts_quantity'])
197 196
 					{
198
-						$etpl->set_validation_error('ts_quantity',lang('Field must not be empty !!!'));
197
+						$etpl->set_validation_error('ts_quantity', lang('Field must not be empty !!!'));
199 198
 					}
200 199
 					if ($this->data['ts_duration'] < 0)
201 200
 					{
202
-						$etpl->set_validation_error('start_time',lang('Starttime has to be before endtime !!!'));
201
+						$etpl->set_validation_error('start_time', lang('Starttime has to be before endtime !!!'));
203 202
 					}
204 203
 					// set ts_title to ts_project if short viewtype (title is not editable)
205
-					if($this->ts_viewtype == 'short')
204
+					if ($this->ts_viewtype == 'short')
206 205
 					{
207 206
 						$this->data['ts_title'] = $this->data['ts_project'] = $this->data['pm_id'] ?
208
-								Link::title('projectmanager', $this->data['pm_id']) :
209
-								$this->data['ts_project'];
207
+								Link::title('projectmanager', $this->data['pm_id']) : $this->data['ts_project'];
210 208
 					}
211 209
 					if (!$this->data['ts_title'])
212 210
 					{
@@ -215,9 +213,9 @@  discard block
 block discarded – undo
215 213
 
216 214
 						if (!$this->data['ts_title'])
217 215
 						{
218
-							$etpl->set_validation_error('ts_title',lang('Field must not be empty !!!'));
216
+							$etpl->set_validation_error('ts_title', lang('Field must not be empty !!!'));
219 217
 						}
220
-						elseif($button != 'save_new')
218
+						elseif ($button != 'save_new')
221 219
 						{
222 220
 							// remove title-blur for same behavior after apply, as for opening the saved entry again
223 221
 							unset($this->data['ts_title_blur']);
@@ -226,26 +224,26 @@  discard block
 block discarded – undo
226 224
 							unset($content['ts_project_blur']);
227 225
 						}
228 226
 					}
229
-					if ($etpl->validation_errors()) break;	// the user need to fix the error, before we can save the entry
227
+					if ($etpl->validation_errors()) break; // the user need to fix the error, before we can save the entry
230 228
 
231 229
 					// account for changed project --> remove old one from links and add new one
232
-					if ((int) $this->data['pm_id'] != (int) $this->data['old_pm_id'])
230
+					if ((int)$this->data['pm_id'] != (int)$this->data['old_pm_id'])
233 231
 					{
234 232
 						// update links accordingly
235 233
 						if ($this->data['pm_id'])
236 234
 						{
237
-							Link::link(TIMESHEET_APP,$content['link_to']['to_id'],'projectmanager',$this->data['pm_id']);
235
+							Link::link(TIMESHEET_APP, $content['link_to']['to_id'], 'projectmanager', $this->data['pm_id']);
238 236
 						}
239 237
 						if ($this->data['old_pm_id'])
240 238
 						{
241
-							Link::unlink2(0,TIMESHEET_APP,$content['link_to']['to_id'],0,'projectmanager',$this->data['old_pm_id']);
239
+							Link::unlink2(0, TIMESHEET_APP, $content['link_to']['to_id'], 0, 'projectmanager', $this->data['old_pm_id']);
242 240
 							unset($this->data['old_pm_id']);
243 241
 						}
244 242
 					}
245 243
 					// check if we are linked to a project, but that is NOT set as project
246 244
 					if (!$this->data['pm_id'] && is_array($content['link_to']['to_id']))
247 245
 					{
248
-						foreach($content['link_to']['to_id'] as $data)
246
+						foreach ($content['link_to']['to_id'] as $data)
249 247
 						{
250 248
 							if ($data['app'] == 'projectmanager')
251 249
 							{
@@ -266,32 +264,32 @@  discard block
 block discarded – undo
266 264
 						$msg = lang('Entry saved');
267 265
 						if (is_array($content['link_to']['to_id']) && count($content['link_to']['to_id']))
268 266
 						{
269
-							Link::link(TIMESHEET_APP,$this->data['ts_id'],$content['link_to']['to_id']);
267
+							Link::link(TIMESHEET_APP, $this->data['ts_id'], $content['link_to']['to_id']);
270 268
 						}
271 269
 					}
272 270
 					Framework::refresh_opener($msg, 'timesheet', $this->data['ts_id'], $content['ts_id'] ? 'edit' : 'add');
273 271
 					if ($button == 'apply') break;
274 272
 					if ($button == 'save_new')
275 273
 					{
276
-						$msg .= ', '.lang('creating new entry');		// giving some feedback to the user
274
+						$msg .= ', '.lang('creating new entry'); // giving some feedback to the user
277 275
 
278 276
 						if (!is_array($content['link_to']['to_id']))	// set links again, so new entry gets the same links as the existing one
279 277
 						{
280 278
 							$content['link_to']['to_id'] = 0;
281
-							foreach(Link::get_links(TIMESHEET_APP,$this->data['ts_id'],'!'.Link::VFS_APPNAME) as $link)
279
+							foreach (Link::get_links(TIMESHEET_APP, $this->data['ts_id'], '!'.Link::VFS_APPNAME) as $link)
282 280
 							{
283
-								Link::link(TIMESHEET_APP,$content['link_to']['to_id'],$link['app'],$link['id'],$link['remark']);
281
+								Link::link(TIMESHEET_APP, $content['link_to']['to_id'], $link['app'], $link['id'], $link['remark']);
284 282
 							}
285 283
 						}
286 284
 						// create a new entry
287 285
 						$this->data['ts_start'] += 60 * $this->data['ts_duration'];
288
-						foreach(array('ts_id','ts_title','ts_description','ts_duration','ts_quantity','ts_modified','ts_modifier','link_to') as $name)
286
+						foreach (array('ts_id', 'ts_title', 'ts_description', 'ts_duration', 'ts_quantity', 'ts_modified', 'ts_modifier', 'link_to') as $name)
289 287
 						{
290 288
 							unset($this->data[$name]);
291 289
 						}
292 290
 						// save the selected project, to delete the project-link, if the user changes the project
293 291
 						$this->data['old_pm_id'] = $this->data['pm_id'];
294
-						if($this->pm_integration == 'none')
292
+						if ($this->pm_integration == 'none')
295 293
 						{
296 294
 							unset($this->data['pm_id']);
297 295
 						}
@@ -309,7 +307,7 @@  discard block
 block discarded – undo
309 307
 						else
310 308
 						{
311 309
 							$msg = lang('Error deleting the entry!!!');
312
-							break;	// dont close window
310
+							break; // dont close window
313 311
 						}
314 312
 					}
315 313
 					// fall-through for save
@@ -322,17 +320,16 @@  discard block
 block discarded – undo
322 320
 			'referer' => $referer,
323 321
 			'ts_title_blur' => $content['ts_title_blur'],
324 322
 		);
325
-		$content = array_merge($this->data,array(
323
+		$content = array_merge($this->data, array(
326 324
 			'msg'  => $msg,
327 325
 			'view' => $view,
328 326
 			'tabs'  => $content['tabs'],
329 327
 			'link_to' => array(
330
-				'to_id' => $this->data['ts_id'] ? $this->data['ts_id'] :
331
-					($this->data['link_to']['to_id'] ? $this->data['link_to']['to_id'] : $content['link_to']['to_id']),
328
+				'to_id' => $this->data['ts_id'] ? $this->data['ts_id'] : ($this->data['link_to']['to_id'] ? $this->data['link_to']['to_id'] : $content['link_to']['to_id']),
332 329
 				'to_app' => TIMESHEET_APP,
333 330
 			),
334
-			'ts_quantity_blur' => $this->data['ts_duration'] ? round($this->data['ts_duration'] / 60.0,3) : '',
335
-			'ts_quantity' => $this->data['ts_duration']/60.0 == $this->data['ts_quantity'] ? null : $this->data['ts_quantity'],
331
+			'ts_quantity_blur' => $this->data['ts_duration'] ? round($this->data['ts_duration'] / 60.0, 3) : '',
332
+			'ts_quantity' => $this->data['ts_duration'] / 60.0 == $this->data['ts_quantity'] ? null : $this->data['ts_quantity'],
336 333
 			'start_time' => isset($this->data['start_time']) ? $this->data['start_time'] : $this->data['ts_start'],
337 334
 			'pm_integration' => $this->pm_integration,
338 335
 			'no_ts_status' => !$this->status_labels && ($this->data['ts_status'] != self::DELETED_STATUS),
@@ -342,10 +339,10 @@  discard block
 block discarded – undo
342 339
 		if (!$this->data['ts_id'] && isset($_REQUEST['link_app']) && isset($_REQUEST['link_id']) && !is_array($content['link_to']['to_id']))
343 340
 		{
344 341
 			$link_ids = is_array($_REQUEST['link_id']) ? $_REQUEST['link_id'] : array($_REQUEST['link_id']);
345
-			foreach(is_array($_REQUEST['link_app']) ? $_REQUEST['link_app'] : array($_REQUEST['link_app']) as $n => $link_app)
342
+			foreach (is_array($_REQUEST['link_app']) ? $_REQUEST['link_app'] : array($_REQUEST['link_app']) as $n => $link_app)
346 343
 			{
347 344
 				$link_id = $link_ids[$n];
348
-				if (preg_match('/^[a-z_0-9-]+:[:a-z_0-9-]+$/i',$link_app.':'.$link_id))	// gard against XSS
345
+				if (preg_match('/^[a-z_0-9-]+:[:a-z_0-9-]+$/i', $link_app.':'.$link_id))	// gard against XSS
349 346
 				{
350 347
 					switch ($link_app)
351 348
 					{
@@ -353,33 +350,33 @@  discard block
 block discarded – undo
353 350
 							$links[] = $link_id;
354 351
 							// fall-through;
355 352
 						default:
356
-							if(!$n)
353
+							if (!$n)
357 354
 							{
358 355
 								// get title from first linked app
359
-								$preserv['ts_title_blur'] = Link::title($link_app,$link_id);
356
+								$preserv['ts_title_blur'] = Link::title($link_app, $link_id);
360 357
 								// ask first linked app via "timesheet_set" hook, for further data to set, incl. links
361
-								if (($set = Api\Hooks::single(array('location'=>'timesheet_set','id'=>$link_id),$link_app)))
358
+								if (($set = Api\Hooks::single(array('location'=>'timesheet_set', 'id'=>$link_id), $link_app)))
362 359
 								{
363
-									foreach((array)$set['link_app'] as $i => $l_app)
360
+									foreach ((array)$set['link_app'] as $i => $l_app)
364 361
 									{
365
-										if (($l_id=$set['link_id'][$i])) Link::link(TIMESHEET_APP,$content['link_to']['to_id'],$l_app,$l_id);
362
+										if (($l_id = $set['link_id'][$i])) Link::link(TIMESHEET_APP, $content['link_to']['to_id'], $l_app, $l_id);
366 363
 										if ($l_app == 'projectmanager') $links[] = $l_id;
367 364
 									}
368 365
 									unset($set['link_app']);
369 366
 									unset($set['link_id']);
370 367
 
371
-									$content = array_merge($content,$set);
368
+									$content = array_merge($content, $set);
372 369
 								}
373 370
 							}
374 371
 							break;
375 372
 					}
376
-					Link::link(TIMESHEET_APP,$content['link_to']['to_id'],$link_app,$link_id);
373
+					Link::link(TIMESHEET_APP, $content['link_to']['to_id'], $link_app, $link_id);
377 374
 				}
378 375
 			}
379 376
 		}
380 377
 		elseif ($this->data['ts_id'])
381 378
 		{
382
-			$links = Link::get_links(TIMESHEET_APP,$this->data['ts_id'],'projectmanager');
379
+			$links = Link::get_links(TIMESHEET_APP, $this->data['ts_id'], 'projectmanager');
383 380
 		}
384 381
 		// make all linked projects availible for the pm-pricelist widget, to be able to choose prices from all
385 382
 		$content['all_pm_ids'] = array_values($links);
@@ -422,7 +419,7 @@  discard block
 block discarded – undo
422 419
 
423 420
 		if ($view)
424 421
 		{
425
-			foreach(array_merge(array_keys($this->data),array('pm_id','pl_id','link_to')) as $key)
422
+			foreach (array_merge(array_keys($this->data), array('pm_id', 'pl_id', 'link_to')) as $key)
426 423
 			{
427 424
 				$readonlys[$key] = true;
428 425
 			}
@@ -439,9 +436,9 @@  discard block
 block discarded – undo
439 436
 		{
440 437
 			$edit_grants[$content['ts_owner']] = Api\Accounts::username($content['ts_owner']);
441 438
 		}
442
-		$sel_options['ts_owner']  = $edit_grants;
443
-		$sel_options['ts_status']  = $this->status_labels;
444
-		if($this->config_data['history'] && $content['ts_status'] == self::DELETED_STATUS)
439
+		$sel_options['ts_owner'] = $edit_grants;
440
+		$sel_options['ts_status'] = $this->status_labels;
441
+		if ($this->config_data['history'] && $content['ts_status'] == self::DELETED_STATUS)
445 442
 		{
446 443
 			$sel_options['ts_status'][self::DELETED_STATUS] = 'Deleted';
447 444
 		}
@@ -451,23 +448,23 @@  discard block
 block discarded – undo
451 448
 		// supress unknow widget 'projectmanager-*', if projectmanager is not installed or old
452 449
 		if (!@file_exists(EGW_INCLUDE_ROOT.'/projectmanager/inc/class.projectmanager_widget.inc.php'))
453 450
 		{
454
-			$etpl->set_cell_attribute('pm_id','disabled',true);
455
-			$etpl->set_cell_attribute('pl_id','disabled',true);
451
+			$etpl->set_cell_attribute('pm_id', 'disabled', true);
452
+			$etpl->set_cell_attribute('pl_id', 'disabled', true);
456 453
 		}
457 454
 
458
-		if($this->ts_viewtype == 'short')
455
+		if ($this->ts_viewtype == 'short')
459 456
 		{
460 457
 			$content['ts_viewtype'] = $readonlys['tabs']['notes'] = true;
461 458
 			$content['ts_description_short'] = $content['ts_description'];
462
-			if(!$content['pm_id'] && $this->pm_integration != 'full' && $content['ts_project'])
459
+			if (!$content['pm_id'] && $this->pm_integration != 'full' && $content['ts_project'])
463 460
 			{
464
-				$etpl->setElementAttribute('pm_id','blur',$content['ts_project']);
461
+				$etpl->setElementAttribute('pm_id', 'blur', $content['ts_project']);
465 462
 			}
466 463
 		}
467
-		if (!$this->customfields) $readonlys['tabs']['customfields'] = true;	// suppress tab if there are not customfields
468
-		if (!$this->data['ts_id']) $readonlys['tabs']['history']    = true;   //suppress history for the first loading without ID
464
+		if (!$this->customfields) $readonlys['tabs']['customfields'] = true; // suppress tab if there are not customfields
465
+		if (!$this->data['ts_id']) $readonlys['tabs']['history'] = true; //suppress history for the first loading without ID
469 466
 
470
-		return $etpl->exec(TIMESHEET_APP.'.timesheet_ui.edit',$content,$sel_options,$readonlys,$preserv,2);
467
+		return $etpl->exec(TIMESHEET_APP.'.timesheet_ui.edit', $content, $sel_options, $readonlys, $preserv, 2);
471 468
 	}
472 469
 
473 470
 	/**
@@ -480,7 +477,7 @@  discard block
 block discarded – undo
480 477
 	{
481 478
 		if (!$datetime) return 0;
482 479
 
483
-		return $datetime - mktime(0,0,0,date('m',$datetime),date('d',$datetime),date('Y',$datetime));
480
+		return $datetime - mktime(0, 0, 0, date('m', $datetime), date('d', $datetime), date('Y', $datetime));
484 481
 	}
485 482
 
486 483
 	/**
@@ -494,23 +491,23 @@  discard block
 block discarded – undo
494 491
 	 * @param boolean $id_only if true only return (via $rows) an array of contact-ids, dont save state to session
495 492
 	 * @return int total number of contacts matching the selection
496 493
 	 */
497
-	function get_rows(&$query_in,&$rows,&$readonlys,$id_only=false)
494
+	function get_rows(&$query_in, &$rows, &$readonlys, $id_only = false)
498 495
 	{
499 496
 		$this->show_sums = false;
500 497
 		$end_date = false;
501 498
 
502 499
 		// Date filter
503
-		if($query_in['filter'] === 'custom')
500
+		if ($query_in['filter'] === 'custom')
504 501
 		{
505 502
 			$end_date = $query_in['enddate'] ? $query_in['enddate'] : false;
506 503
 			$query_in['startdate'] = $query_in['startdate'] ? $query_in['startdate'] : 1;
507 504
 		}
508
-		$date_filter = $this->date_filter($query_in['filter'],$query_in['startdate'],$end_date);
505
+		$date_filter = $this->date_filter($query_in['filter'], $query_in['startdate'], $end_date);
509 506
 
510 507
 		if ($query_in['startdate'])
511 508
 		{
512
-			$start = explode('-',date('Y-m-d',$query_in['startdate']+12*60*60));
513
-			$end   = explode('-',date('Y-m-d',$end_date ? $end_date : $query_in['startdate']+7.5*24*60*60));
509
+			$start = explode('-', date('Y-m-d', $query_in['startdate'] + 12 * 60 * 60));
510
+			$end   = explode('-', date('Y-m-d', $end_date ? $end_date : $query_in['startdate'] + 7.5 * 24 * 60 * 60));
514 511
 
515 512
 			// show year-sums, if we are year-aligned (show full years)?
516 513
 			if ((int)$start[2] == 1 && (int)$start[1] == 1 && (int)$end[2] == 31 && (int)$end[1] == 12)
@@ -518,28 +515,28 @@  discard block
 block discarded – undo
518 515
 				$this->show_sums[] = 'year';
519 516
 			}
520 517
 			// show month-sums, if we are month-aligned (show full monthes)?
521
-			if ((int)$start[2] == 1 && (int)$end[2] == (int)date('d',mktime(12,0,0,$end[1]+1,0,$end[0])))
518
+			if ((int)$start[2] == 1 && (int)$end[2] == (int)date('d', mktime(12, 0, 0, $end[1] + 1, 0, $end[0])))
522 519
 			{
523 520
 				$this->show_sums[] = 'month';
524 521
 			}
525 522
 			// show week-sums, if we are week-aligned (show full weeks)?
526 523
 			$week_start_day = $GLOBALS['egw_info']['user']['preferences']['calendar']['weekdaystarts'];
527 524
 			if (!$week_start_day) $week_start_day = 'Sunday';
528
-			switch($week_start_day)
525
+			switch ($week_start_day)
529 526
 			{
530 527
 				case 'Sunday': $week_end_day = 'Saturday'; break;
531 528
 				case 'Monday': $week_end_day = 'Sunday'; break;
532 529
 				case 'Saturday': $week_end_day = 'Friday'; break;
533 530
 			}
534
-			$filter_start_day = date('l',$query_in['startdate']+12*60*60);
535
-			$filter_end_day   = $end_date ? date('l',$end_date+12*60*60) : false;
531
+			$filter_start_day = date('l', $query_in['startdate'] + 12 * 60 * 60);
532
+			$filter_end_day   = $end_date ? date('l', $end_date + 12 * 60 * 60) : false;
536 533
 			//echo "<p align=right>prefs: $week_start_day - $week_end_day, filter: $filter_start_day - $filter_end_day</p>\n";
537 534
 			if ($filter_start_day == $week_start_day && (!$filter_end_day || $filter_end_day == $week_end_day))
538 535
 			{
539 536
 				$this->show_sums[] = 'week';
540 537
 			}
541 538
 			// show day-sums, if range <= 5 weeks
542
-			if (!$end_date || $end_date - $query_in['startdate'] < 36*24*60*60)
539
+			if (!$end_date || $end_date - $query_in['startdate'] < 36 * 24 * 60 * 60)
543 540
 			{
544 541
 				$this->show_sums[] = 'day';
545 542
 			}
@@ -550,10 +547,10 @@  discard block
 block discarded – undo
550 547
 		// Refresh actions (undelete needs this)
551 548
 		$query_in['actions'] = $this->get_actions($query_in);
552 549
 
553
-		$query = $query_in;	// keep the original query
550
+		$query = $query_in; // keep the original query
554 551
 		$query['enddate'] = $end_date;
555 552
 
556
-		if($this->ts_viewtype == 'short') $query_in['options-selectcols'] = array('ts_quantity'=>false,'ts_unitprice'=>false,'ts_total'=>false);
553
+		if ($this->ts_viewtype == 'short') $query_in['options-selectcols'] = array('ts_quantity'=>false, 'ts_unitprice'=>false, 'ts_total'=>false);
557 554
 		if ($query['no_status']) $query_in['options-selectcols']['ts_status'] = false;
558 555
 
559 556
 		//_debug_array($query['col_filter']);
@@ -580,18 +577,18 @@  discard block
 block discarded – undo
580 577
 		// handle linked filter (show only entries linked to a certain other entry)
581 578
 		if ($query['col_filter']['linked'])
582 579
 		{
583
-			if(!is_array($query['col_filter']['linked']))
580
+			if (!is_array($query['col_filter']['linked']))
584 581
 			{
585
-				list($app,$id) = explode(':',$query['col_filter']['linked']);
582
+				list($app, $id) = explode(':', $query['col_filter']['linked']);
586 583
 			}
587 584
 			else
588 585
 			{
589 586
 				$app = $query['col_filter']['linked']['app'];
590 587
 				$id = $query['col_filter']['linked']['id'];
591 588
 			}
592
-			if (!($links = Link::get_links($app,$id,'timesheet')))
589
+			if (!($links = Link::get_links($app, $id, 'timesheet')))
593 590
 			{
594
-				$rows = array();	// no infologs linked to project --> no rows to return
591
+				$rows = array(); // no infologs linked to project --> no rows to return
595 592
 				return 0;
596 593
 			}
597 594
 			if (!$query['col_filter']['ts_id'])
@@ -599,9 +596,9 @@  discard block
 block discarded – undo
599 596
 				$query['col_filter']['ts_id'] = array_values(array_unique($links));
600 597
 			}
601 598
 			// allow to combine with other filters using ts_id --> intersect ids
602
-			elseif (!($query['col_filter']['ts_id'] = array_intersect((array)$query['col_filter']['ts_id'],array_values(array_unique($links)))))
599
+			elseif (!($query['col_filter']['ts_id'] = array_intersect((array)$query['col_filter']['ts_id'], array_values(array_unique($links)))))
603 600
 			{
604
-				$rows = array();	// no infologs linked to project --> no rows to return
601
+				$rows = array(); // no infologs linked to project --> no rows to return
605 602
 				return 0;
606 603
 			}
607 604
 		}
@@ -625,13 +622,13 @@  discard block
 block discarded – undo
625 622
 			{
626 623
 				if (isset($this->status_labels_substatus['2level'][$status_id]))
627 624
 				{
628
-					$query['col_filter']['ts_status'] = array_merge($query['col_filter']['ts_status'],$this->status_labels_substatus[$status_id]);
625
+					$query['col_filter']['ts_status'] = array_merge($query['col_filter']['ts_status'], $this->status_labels_substatus[$status_id]);
629 626
 				}
630 627
 			}
631 628
 		}
632 629
 		if ((int)$query['filter2'] != (int)$GLOBALS['egw_info']['user']['preferences'][TIMESHEET_APP]['show_details'])
633 630
 		{
634
-			$GLOBALS['egw']->preferences->add(TIMESHEET_APP,'show_details',(int)$query['filter2']);
631
+			$GLOBALS['egw']->preferences->add(TIMESHEET_APP, 'show_details', (int)$query['filter2']);
635 632
 			$GLOBALS['egw']->preferences->save_repository(true);
636 633
 		}
637 634
 		// category filter: cat_id or ''=All cats or 0=No cat
@@ -654,7 +651,7 @@  discard block
 block discarded – undo
654 651
 			$GLOBALS['egw_info']['flags']['app_header'] .= ': '.Api\Accounts::username($query['col_filter']['ts_owner']);
655 652
 			#if ($GLOBALS['egw']->accounts->get_type($query['col_filter']['ts_owner']) == 'g') $GLOBALS['egw_info']['flags']['app_header'] .= ' '. lang("and its members");
656 653
 			#_debug_array($GLOBALS['egw']->accounts->members($query['col_filter']['ts_owner'],true));
657
-			if ($query['col_filter']['ts_owner']<0) $query['col_filter']['ts_owner'] = array_merge(array($query['col_filter']['ts_owner']),$GLOBALS['egw']->accounts->members($query['col_filter']['ts_owner'],true));
654
+			if ($query['col_filter']['ts_owner'] < 0) $query['col_filter']['ts_owner'] = array_merge(array($query['col_filter']['ts_owner']), $GLOBALS['egw']->accounts->members($query['col_filter']['ts_owner'], true));
658 655
 		}
659 656
 		else
660 657
 		{
@@ -667,60 +664,60 @@  discard block
 block discarded – undo
667 664
 			// generate a meaningful app-header / report title
668 665
 			if ($this->show_sums['month'])
669 666
 			{
670
-				if ((int)$start[1] == 1 && (int) $end[1] == 12)		// whole year(s)
667
+				if ((int)$start[1] == 1 && (int)$end[1] == 12)		// whole year(s)
671 668
 				{
672
-					$GLOBALS['egw_info']['flags']['app_header'] .= ': ' . $start[0] . ($start[0] != $end[0] ? ' - '.$end[0] : '');
669
+					$GLOBALS['egw_info']['flags']['app_header'] .= ': '.$start[0].($start[0] != $end[0] ? ' - '.$end[0] : '');
673 670
 				}
674 671
 				else
675 672
 				{
676
-					$GLOBALS['egw_info']['flags']['app_header'] .= ': ' . lang(date('F',$query['startdate']+12*60*60)) . ' ' . $start[0];
673
+					$GLOBALS['egw_info']['flags']['app_header'] .= ': '.lang(date('F', $query['startdate'] + 12 * 60 * 60)).' '.$start[0];
677 674
 					if ($start[0] != $end[0] || $start[1] != $end[1])
678 675
 					{
679
-						$GLOBALS['egw_info']['flags']['app_header'] .= ' - ' . lang(date('F',$query['enddate']+12*60*60)) . ' ' . $end[0];
676
+						$GLOBALS['egw_info']['flags']['app_header'] .= ' - '.lang(date('F', $query['enddate'] + 12 * 60 * 60)).' '.$end[0];
680 677
 					}
681 678
 				}
682 679
 			}
683 680
 			elseif ($this->show_sums['week'])
684 681
 			{
685
-				$GLOBALS['egw_info']['flags']['app_header'] .= ': ' . lang('week') . ' ' . date('W',$query['startdate']+36*60*60) . '/' . $start[0];
686
-				if ($query['enddate'] && $query['enddate'] - $query['startdate'] > 10*24*60*60)
682
+				$GLOBALS['egw_info']['flags']['app_header'] .= ': '.lang('week').' '.date('W', $query['startdate'] + 36 * 60 * 60).'/'.$start[0];
683
+				if ($query['enddate'] && $query['enddate'] - $query['startdate'] > 10 * 24 * 60 * 60)
687 684
 				{
688
-					$GLOBALS['egw_info']['flags']['app_header'] .= ' - ' . date('W',$query['enddate']-36*60*60) . '/' . $end[0];
685
+					$GLOBALS['egw_info']['flags']['app_header'] .= ' - '.date('W', $query['enddate'] - 36 * 60 * 60).'/'.$end[0];
689 686
 				}
690 687
 			}
691 688
 			elseif ($query['startdate'])
692 689
 			{
693 690
 				$df = $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'];
694
-				$GLOBALS['egw_info']['flags']['app_header'] .= ': ' . Api\DateTime::to($query['startdate']+12*60*60, $df);
691
+				$GLOBALS['egw_info']['flags']['app_header'] .= ': '.Api\DateTime::to($query['startdate'] + 12 * 60 * 60, $df);
695 692
 				if ($start != $end)
696 693
 				{
697
-					$GLOBALS['egw_info']['flags']['app_header'] .= ' - '.Api\DateTime::to($query['enddate'] ? $query['enddate']+12*60*60:'now', $df);
694
+					$GLOBALS['egw_info']['flags']['app_header'] .= ' - '.Api\DateTime::to($query['enddate'] ? $query['enddate'] + 12 * 60 * 60 : 'now', $df);
698 695
 				}
699 696
 			}
700 697
 		}
701 698
 		// Update start / end dates for custom
702
-		if($query_in['filter'] != 'custom')
699
+		if ($query_in['filter'] != 'custom')
703 700
 		{
704 701
 			Api\Json\Response::get()->call(
705 702
 				'app.timesheet.update_timespan',
706
-				Api\DateTime::to($query['startdate'] ? $query['startdate'] : 'now' , Api\DateTime::ET2),
703
+				Api\DateTime::to($query['startdate'] ? $query['startdate'] : 'now', Api\DateTime::ET2),
707 704
 				$query['filter'] ? Api\DateTime::to($query['enddate'], Api\DateTime::ET2) : null
708 705
 			);
709 706
 		}
710
-		$total = parent::get_rows($query,$rows,$readonlys);
707
+		$total = parent::get_rows($query, $rows, $readonlys);
711 708
 
712 709
 		$ids = array();
713
-		foreach($rows as &$row)
710
+		foreach ($rows as &$row)
714 711
 		{
715 712
 			if ($row['ts_id'] > 0) $ids[] = $row['ts_id'];
716 713
 		}
717 714
 		if ($id_only)
718 715
 		{
719 716
 			$rows = $ids;
720
-			return $this->total;	// no need to set other fields or $readonlys
717
+			return $this->total; // no need to set other fields or $readonlys
721 718
 		}
722 719
 		$links = array();
723
-		$links3 = Link::get_links_multiple(TIMESHEET_APP,$ids,true,'projectmanager');	// only check for pm links!
720
+		$links3 = Link::get_links_multiple(TIMESHEET_APP, $ids, true, 'projectmanager'); // only check for pm links!
724 721
 		//as the full array is expected, we must supply the missing but needed (since expected further down) information
725 722
 		if (is_array($links3))
726 723
 		{
@@ -740,14 +737,14 @@  discard block
 block discarded – undo
740 737
 
741 738
 		$readonlys = array();
742 739
 		$have_cats = false;
743
-		foreach($rows as &$row)
740
+		foreach ($rows as &$row)
744 741
 		{
745 742
 			if ($row['cat_id']) $have_cats = true;
746 743
 
747 744
 			$row['class'] = 'row';
748 745
 			if ($row['ts_id'] <= 0)	// sums
749 746
 			{
750
-				if ($query['sort'] == 'ASC') $row['ts_start'] -= 7200;	// fix for DSL change
747
+				if ($query['sort'] == 'ASC') $row['ts_start'] -= 7200; // fix for DSL change
751 748
 
752 749
 				// Remove fake modified date, it breaks nextmatch checks
753 750
 				unset($row['ts_modified']);
@@ -755,22 +752,22 @@  discard block
 block discarded – undo
755 752
 				// Set flag to avoid actions on these rows
756 753
 				$row['no_actions'] = true;
757 754
 
758
-				switch($row['ts_id'])
755
+				switch ($row['ts_id'])
759 756
 				{
760 757
 					case 0:	// day-sum
761
-						$row['ts_title'] = lang('Sum %1:',lang(date('l',$row['ts_start'])).' '.Api\DateTime::to($row['ts_start'], $GLOBALS['egw_info']['user']['preferences']['common']['dateformat']));
758
+						$row['ts_title'] = lang('Sum %1:', lang(date('l', $row['ts_start'])).' '.Api\DateTime::to($row['ts_start'], $GLOBALS['egw_info']['user']['preferences']['common']['dateformat']));
762 759
 						$row['ts_id'] = 'sum-day-'.$row['ts_start'];
763 760
 						break;
764 761
 					case -1:	// week-sum
765
-						$row['ts_title'] = lang('Sum %1:',lang('week').' '.substr($row['ts_week'],4).'/'.substr($row['ts_week'],0,4));
762
+						$row['ts_title'] = lang('Sum %1:', lang('week').' '.substr($row['ts_week'], 4).'/'.substr($row['ts_week'], 0, 4));
766 763
 						$row['ts_id'] = 'sum-week-'.$row['ts_week'];
767 764
 						break;
768 765
 					case -2:	// month-sum
769
-						$row['ts_title'] = lang('Sum %1:',lang(date('F',$row['ts_start'])).' '.substr($row['ts_month'],0,4));
766
+						$row['ts_title'] = lang('Sum %1:', lang(date('F', $row['ts_start'])).' '.substr($row['ts_month'], 0, 4));
770 767
 						$row['ts_id'] = 'sum-month-'.$row['ts_month'];
771 768
 						break;
772 769
 					case -3:	// year-sum
773
-						$row['ts_title'] = lang('Sum %1:',$row['ts_year']);
770
+						$row['ts_title'] = lang('Sum %1:', $row['ts_year']);
774 771
 						$row['ts_id'] = 'sum-year-'.$row['ts_year'];
775 772
 						break;
776 773
 				}
@@ -780,11 +777,11 @@  discard block
 block discarded – undo
780 777
 				$row['titleClass'] = 'timesheet_titleSum';
781 778
 				continue;
782 779
 			}
783
-			if($row['ts_quantity'])
780
+			if ($row['ts_quantity'])
784 781
 			{
785 782
 				$row['ts_quantity'] = round($row['ts_quantity'], 2);
786 783
 			}
787
-			if (!$this->check_acl(Acl::EDIT,$row))
784
+			if (!$this->check_acl(Acl::EDIT, $row))
788 785
 			{
789 786
 				$row['class'] .= ' rowNoEdit ';
790 787
 			}
@@ -792,21 +789,21 @@  discard block
 block discarded – undo
792 789
 			{
793 790
 				$row['class'] .= ' rowNoEdit ';
794 791
 			}
795
-			if (!$this->check_acl(Acl::DELETE,$row))
792
+			if (!$this->check_acl(Acl::DELETE, $row))
796 793
 			{
797 794
 				$row['class'] .= ' rowNoDelete ';
798 795
 			}
799
-			if($row['ts_status'] != self::DELETED_STATUS)
796
+			if ($row['ts_status'] != self::DELETED_STATUS)
800 797
 			{
801 798
 				$row['class'] .= ' rowNoUndelete ';
802 799
 			}
803 800
 			if ($query['col_filter']['ts_project'])
804 801
 			{
805
-				unset($row['ts_project']);	// dont need or want to show it
802
+				unset($row['ts_project']); // dont need or want to show it
806 803
 			}
807 804
 			elseif ($links[$row['ts_id']])
808 805
 			{
809
-				foreach($links[$row['ts_id']] as $link)
806
+				foreach ($links[$row['ts_id']] as $link)
810 807
 				{
811 808
 					if ($link['app'] == 'projectmanager')
812 809
 					{
@@ -817,13 +814,13 @@  discard block
 block discarded – undo
817 814
 				}
818 815
 			}
819 816
 
820
-			if(!$row['titleClass']) $row['titleClass'] = 'timesheet_titleDetails';
817
+			if (!$row['titleClass']) $row['titleClass'] = 'timesheet_titleDetails';
821 818
 
822 819
 		}
823 820
 		$rows['no_cat_id'] = (!$have_cats || $query['cat_id']);
824 821
 		if ($query['col_filter']['ts_owner']) $rows['ownerClass'] = 'noPrint';
825 822
 		$rows['no_owner_col'] = $query['no_owner_col'];
826
-		if(is_string($query['selectcols']))
823
+		if (is_string($query['selectcols']))
827 824
 		{
828 825
 			$query['selectcols'] = explode(',', $query['selectcols']);
829 826
 		}
@@ -835,17 +832,17 @@  discard block
 block discarded – undo
835 832
 		$rows += $this->summary;
836 833
 
837 834
 		$rows['pm_integration'] = $this->pm_integration;
838
-		$rows['ts_viewtype'] =  $rows['no_ts_quantity'] =  $rows['no_ts_unitprice'] =  $rows['no_ts_total'] = $this->ts_viewtype == 'short';
835
+		$rows['ts_viewtype'] = $rows['no_ts_quantity'] = $rows['no_ts_unitprice'] = $rows['no_ts_total'] = $this->ts_viewtype == 'short';
839 836
 		if (!$rows['ts_viewtype'])
840 837
 		{
841 838
 			#_debug_array($query['selectcols']);
842
-			if(!is_array($query['selectcols'])){
843
-				$query['selectcols'] = explode(',',$query['selectcols']);
839
+			if (!is_array($query['selectcols'])) {
840
+				$query['selectcols'] = explode(',', $query['selectcols']);
844 841
 			}
845 842
 			#ts_quantity,ts_unitprice,ts_total
846
-			if ($query['selectcols'] && in_array('ts_quantity_quantity',$query['selectcols'])===false) $rows['no_ts_quantity'] = 1;
847
-			if ($query['selectcols'] && in_array('ts_unitprice', $query['selectcols'])===false) $rows['no_ts_unitprice'] = 1;
848
-			if ($query['selectcols'] && in_array('ts_total_price',$query['selectcols'])===false) $rows['no_ts_total'] = 1;
843
+			if ($query['selectcols'] && in_array('ts_quantity_quantity', $query['selectcols']) === false) $rows['no_ts_quantity'] = 1;
844
+			if ($query['selectcols'] && in_array('ts_unitprice', $query['selectcols']) === false) $rows['no_ts_unitprice'] = 1;
845
+			if ($query['selectcols'] && in_array('ts_total_price', $query['selectcols']) === false) $rows['no_ts_total'] = 1;
849 846
 		}
850 847
 		$rows['no_ts_status'] = in_array('ts_status', $query['selectcols']) === false && !$this->config_data['history'] ||
851 848
 			$query['no_status'];
@@ -864,7 +861,7 @@  discard block
 block discarded – undo
864 861
 	 * @param array $content
865 862
 	 * @param string $msg
866 863
 	 */
867
-	function index($content = null,$msg='')
864
+	function index($content = null, $msg = '')
868 865
 	{
869 866
 		$etpl = new Etemplate('timesheet.index');
870 867
 
@@ -901,14 +898,14 @@  discard block
 block discarded – undo
901 898
 			else
902 899
 			{
903 900
 				$success = $failed = $action_msg = null;
904
-				if ($this->action($content['nm']['action'],$content['nm']['selected'],$content['nm']['select_all'],
905
-					$success,$failed,$action_msg,'index',$msg))
901
+				if ($this->action($content['nm']['action'], $content['nm']['selected'], $content['nm']['select_all'],
902
+					$success, $failed, $action_msg, 'index', $msg))
906 903
 				{
907
-					$msg .= lang('%1 timesheets(s) %2',$success,$action_msg);
904
+					$msg .= lang('%1 timesheets(s) %2', $success, $action_msg);
908 905
 				}
909
-				elseif(empty($msg))
906
+				elseif (empty($msg))
910 907
 				{
911
-					$msg .= lang('%1 timesheets(s) %2, %3 failed because of insufficent rights !!!',$success,$action_msg,$failed);
908
+					$msg .= lang('%1 timesheets(s) %2, %3 failed because of insufficent rights !!!', $success, $action_msg, $failed);
912 909
 				}
913 910
 			}
914 911
 		}
@@ -920,7 +917,7 @@  discard block
 block discarded – undo
920 917
 		if (!is_array($content['nm']))
921 918
 		{
922 919
 			$date_filters = array('All');
923
-			foreach(array_keys($this->date_filters) as $name)
920
+			foreach (array_keys($this->date_filters) as $name)
924 921
 			{
925 922
 				$date_filters[$name] = $name;
926 923
 			}
@@ -929,26 +926,26 @@  discard block
 block discarded – undo
929 926
 			$content['nm'] = array(
930 927
 				'get_rows'       =>	TIMESHEET_APP.'.timesheet_ui.get_rows',
931 928
 				'options-filter' => $date_filters,
932
-				'options-filter2' => array('No details','Details'),
933
-				'order'          =>	'ts_start',// IO name of the column to sort after (optional for the sortheaders)
934
-				'sort'           =>	'DESC',// IO direction of the sort: 'ASC' or 'DESC'
929
+				'options-filter2' => array('No details', 'Details'),
930
+				'order'          =>	'ts_start', // IO name of the column to sort after (optional for the sortheaders)
931
+				'sort'           =>	'DESC', // IO direction of the sort: 'ASC' or 'DESC'
935 932
 				'filter_onchange' => "app.timesheet.filter_change();",
936 933
 				'filter2_onchange' => "app.timesheet.filter2_change();",
937 934
 				'filter2'        => (int)$GLOBALS['egw_info']['user']['preferences'][TIMESHEET_APP]['show_details'],
938 935
 				'row_id'         => 'ts_id',
939 936
 				'row_modified'   => 'ts_modified',
940 937
 				//'actions'        => $this->get_actions(),
941
-				'default_cols'   => '!legacy_actions',	// switch legacy actions column and row off by default
938
+				'default_cols'   => '!legacy_actions', // switch legacy actions column and row off by default
942 939
 				'pm_integration' => $this->pm_integration,
943 940
 				'placeholder_actions' => array('add')
944 941
 			);
945 942
 		}
946 943
 
947
-		if($_GET['search'])
944
+		if ($_GET['search'])
948 945
 		{
949 946
 			$content['nm']['search'] = $_GET['search'];
950 947
 		}
951
-		if($_GET['link_app'] && Link::get_registry($_GET['link_app'], 'query') && $_GET['link_id'])
948
+		if ($_GET['link_app'] && Link::get_registry($_GET['link_app'], 'query') && $_GET['link_id'])
952 949
 		{
953 950
 			$content['nm']['col_filter']['linked'] = array(
954 951
 				'app' => $_GET['link_app'],
@@ -962,25 +959,25 @@  discard block
 block discarded – undo
962 959
 			'ts_owner'   => $read_grants,
963 960
 			'pm_id'      => array(lang('No project')),
964 961
 			'cat_id'     => array(array('value' => '', 'label' => lang('all categories')), array('value' => 0, 'label'=>lang('None'))),
965
-			'ts_status'  => $this->status_labels+array(lang('No status')),
962
+			'ts_status'  => $this->status_labels + array(lang('No status')),
966 963
 		);
967
-		if($this->config_data['history'])
964
+		if ($this->config_data['history'])
968 965
 		{
969 966
 			$sel_options['ts_status'][self::DELETED_STATUS] = 'Deleted';
970 967
 		}
971
-		$content['nm']['no_status'] = count($sel_options['ts_status']) <= 1;	// 1 because of 'No status'
972
-		$content['nm']['favorites'] = true;		//Enable favorite
968
+		$content['nm']['no_status'] = count($sel_options['ts_status']) <= 1; // 1 because of 'No status'
969
+		$content['nm']['favorites'] = true; //Enable favorite
973 970
 
974 971
 		if ($this->pm_integration != 'full')
975 972
 		{
976
-			$projects =& $this->query_list('ts_project');
973
+			$projects = & $this->query_list('ts_project');
977 974
 			if (!is_array($projects)) $projects = array();
978 975
 			$sel_options['ts_project'] = $projects + array(lang('No project'));
979 976
 		}
980 977
 
981 978
 		// dont show [Export] button if app is not availible to the user or we are on php4
982
-		$readonlys['export'] = !$GLOBALS['egw_info']['user']['apps']['importexport'] || (int) phpversion() < 5;
983
-		return $etpl->exec(TIMESHEET_APP.'.timesheet_ui.index',$content,$sel_options,$readonlys);
979
+		$readonlys['export'] = !$GLOBALS['egw_info']['user']['apps']['importexport'] || (int)phpversion() < 5;
980
+		return $etpl->exec(TIMESHEET_APP.'.timesheet_ui.index', $content, $sel_options, $readonlys);
984 981
 	}
985 982
 
986 983
 	/**
@@ -999,9 +996,9 @@  discard block
 block discarded – undo
999 996
 				'allowOnMultiple' => false,
1000 997
 				'url' => 'menuaction=timesheet.timesheet_ui.edit&ts_id=$id',
1001 998
 				'popup' => Link::get_registry('timesheet', 'add_popup'),
1002
-				'group' => $group=1,
999
+				'group' => $group = 1,
1003 1000
 				'disableClass' => 'th',
1004
-				'onExecute' => Api\Header\UserAgent::mobile()?'javaScript:app.timesheet.viewEntry':'',
1001
+				'onExecute' => Api\Header\UserAgent::mobile() ? 'javaScript:app.timesheet.viewEntry' : '',
1005 1002
 				'mobileViewTemplate' => 'view?'.filemtime(Api\Etemplate\Widget\Template::rel2path('/timesheet/templates/mobile/view.xet'))
1006 1003
 			),
1007 1004
 /*
@@ -1041,7 +1038,7 @@  discard block
 block discarded – undo
1041 1038
 				)
1042 1039
 			),
1043 1040
 			'cat' => Etemplate\Widget\Nextmatch::category_action(
1044
-				'timesheet',++$group,'Change category','cat_'
1041
+				'timesheet', ++$group, 'Change category', 'cat_'
1045 1042
 			),
1046 1043
 			'status' => array(
1047 1044
 				'icon' => 'apply',
@@ -1093,7 +1090,7 @@  discard block
 block discarded – undo
1093 1090
 			);
1094 1091
 		}
1095 1092
 		// enable additonal edit check for following actions, if they are generally available
1096
-		foreach(array('cat','status') as $action)
1093
+		foreach (array('cat', 'status') as $action)
1097 1094
 		{
1098 1095
 			if ($actions[$action]['enabled'])
1099 1096
 			{
@@ -1116,7 +1113,7 @@  discard block
 block discarded – undo
1116 1113
 	 * @param string/array $session_name 'index' or 'email', or array with session-data depending if we are in the main list or the popup
1117 1114
 	 * @return boolean true if all actions succeded, false otherwise
1118 1115
 	 */
1119
-	function action($action,$checked,$use_all,&$success,&$failed,&$action_msg,$session_name,&$msg)
1116
+	function action($action, $checked, $use_all, &$success, &$failed, &$action_msg, $session_name, &$msg)
1120 1117
 	{
1121 1118
 		$success = $failed = 0;
1122 1119
 		if ($use_all)
@@ -1126,17 +1123,17 @@  discard block
 block discarded – undo
1126 1123
 
1127 1124
 			if ($use_all)
1128 1125
 			{
1129
-				@set_time_limit(0);			// switch off the execution time limit, as it's for big selections to small
1130
-				$query['num_rows'] = -1;	// all
1126
+				@set_time_limit(0); // switch off the execution time limit, as it's for big selections to small
1127
+				$query['num_rows'] = -1; // all
1131 1128
 				$readonlys = null;
1132
-				$this->get_rows($query,$checked,$readonlys,true);	// true = only return the id's
1129
+				$this->get_rows($query, $checked, $readonlys, true); // true = only return the id's
1133 1130
 			}
1134 1131
 		}
1135 1132
 		//error_log(__METHOD__."('$action', ".array2string($checked).', '.array2string($use_all).",,, '$session_name')");
1136 1133
 
1137
-		if (substr($action,0,9) == 'to_status')
1134
+		if (substr($action, 0, 9) == 'to_status')
1138 1135
 		{
1139
-			$to_status = (int)substr($action,10);
1136
+			$to_status = (int)substr($action, 10);
1140 1137
 			$action = 'to_status';
1141 1138
 		}
1142 1139
 		else
@@ -1145,11 +1142,11 @@  discard block
 block discarded – undo
1145 1142
 			list($action, $settings) = explode('_', $action, 2);
1146 1143
 		}
1147 1144
 
1148
-		switch($action)
1145
+		switch ($action)
1149 1146
 		{
1150 1147
 			case 'delete':
1151 1148
 				$action_msg = lang('deleted');
1152
-				foreach((array)$checked as $n => $id)
1149
+				foreach ((array)$checked as $n => $id)
1153 1150
 				{
1154 1151
 					if ($this->delete($id))
1155 1152
 					{
@@ -1162,10 +1159,10 @@  discard block
 block discarded – undo
1162 1159
 				}
1163 1160
 				break;
1164 1161
 			case 'undelete':
1165
-				$action_msg =lang('recovered');
1166
-				foreach((array)$checked as $n => $id)
1162
+				$action_msg = lang('recovered');
1163
+				foreach ((array)$checked as $n => $id)
1167 1164
 				{
1168
-					if ($this->set_status($id,''))
1165
+					if ($this->set_status($id, ''))
1169 1166
 					{
1170 1167
 						$success++;
1171 1168
 					}
@@ -1176,10 +1173,10 @@  discard block
 block discarded – undo
1176 1173
 				}
1177 1174
 				break;
1178 1175
 			case 'to_status':
1179
-				$action_msg =lang('changed status');
1180
-				foreach((array)$checked as $n => $id)
1176
+				$action_msg = lang('changed status');
1177
+				foreach ((array)$checked as $n => $id)
1181 1178
 				{
1182
-					if ($this->set_status($id,$to_status))
1179
+					if ($this->set_status($id, $to_status))
1183 1180
 					{
1184 1181
 						$success++;
1185 1182
 					}
@@ -1192,7 +1189,7 @@  discard block
 block discarded – undo
1192 1189
 			case 'cat':
1193 1190
 				$cat_name = Api\Categories::id2name($settings);
1194 1191
 				$action_msg = lang('changed category to %1', $cat_name);
1195
-				foreach((array)$checked as $n => $id) {
1192
+				foreach ((array)$checked as $n => $id) {
1196 1193
 					if (($entry = $this->read($id)) &&
1197 1194
 						($entry['cat_id'] = $settings) &&
1198 1195
 						$this->save($entry) == 0)
@@ -1223,7 +1220,7 @@  discard block
 block discarded – undo
1223 1220
 	 * @param conetnt
1224 1221
 	 * @param view
1225 1222
 	 */
1226
-	function editstatus($content = null,$msg='')
1223
+	function editstatus($content = null, $msg = '')
1227 1224
 	{
1228 1225
 		// this function requires admin rights
1229 1226
 		$GLOBALS['egw_info']['flags']['admin_only'] = true;
@@ -1234,13 +1231,13 @@  discard block
 block discarded – undo
1234 1231
 			list($button) = @each($content['button']);
1235 1232
 			unset ($content['button']);
1236 1233
 
1237
-			switch($button)
1234
+			switch ($button)
1238 1235
 			{
1239 1236
 				case 'delete':
1240 1237
 					break;
1241 1238
 				case 'apply':
1242 1239
 				case 'save':
1243
-					foreach($content['statis'] as &$cat)
1240
+					foreach ($content['statis'] as &$cat)
1244 1241
 					{
1245 1242
 						$id = $cat['id'];
1246 1243
 						if (($cat ['name'] !== $this->status_labels_config[$id]) && ($cat ['name'] !== '') || ($cat ['parent'] !== $this->status_labels_config[$id]['parent']) && ($cat ['parent'] !== ''))
@@ -1254,7 +1251,7 @@  discard block
 block discarded – undo
1254 1251
 					}
1255 1252
 					if ($need_update)
1256 1253
 					{
1257
-						Api\Config::save_value('status_labels',$this->status_labels_config,TIMESHEET_APP);
1254
+						Api\Config::save_value('status_labels', $this->status_labels_config, TIMESHEET_APP);
1258 1255
 						$this->config_data = Api\Config::read(TIMESHEET_APP);
1259 1256
 						$this->load_statuses();
1260 1257
 						$msg .= lang('Status updated.');
@@ -1271,7 +1268,7 @@  discard block
 block discarded – undo
1271 1268
 			if (isset($this->status_labels_config[$id]))
1272 1269
 			{
1273 1270
 				unset($this->status_labels_config[$id]);
1274
-				Api\Config::save_value('status_labels',$this->status_labels_config,TIMESHEET_APP);
1271
+				Api\Config::save_value('status_labels', $this->status_labels_config, TIMESHEET_APP);
1275 1272
 				unset($this->status_labels[$id]);
1276 1273
 				$msg .= lang('Status deleted.');
1277 1274
 			}
@@ -1280,12 +1277,12 @@  discard block
 block discarded – undo
1280 1277
 		$i = 1;
1281 1278
 		$max_id = 0;
1282 1279
 		unset($content['statis']);
1283
-		foreach($this->status_labels_config as $id => $label)
1280
+		foreach ($this->status_labels_config as $id => $label)
1284 1281
 		{
1285
-			$content['statis'][$i]['name']= $label['name'];
1286
-			$content['statis'][$i]['id']= $id;
1287
-			$content['statis'][$i]['parent']= $label['parent'];
1288
-			$content['statis'][$i]['admin']= $label['admin'];
1282
+			$content['statis'][$i]['name'] = $label['name'];
1283
+			$content['statis'][$i]['id'] = $id;
1284
+			$content['statis'][$i]['parent'] = $label['parent'];
1285
+			$content['statis'][$i]['admin'] = $label['admin'];
1289 1286
 			$i++;
1290 1287
 			$max_id = max($id, $max_id);
1291 1288
 		}
@@ -1297,7 +1294,7 @@  discard block
 block discarded – undo
1297 1294
 		$preserv = $content;
1298 1295
 		$sel_options['parent'] = $this->status_labels;
1299 1296
 		$etpl = new Etemplate('timesheet.editstatus');
1300
-		$etpl->exec('timesheet.timesheet_ui.editstatus',$content,$sel_options,array(),$preserv);
1297
+		$etpl->exec('timesheet.timesheet_ui.editstatus', $content, $sel_options, array(), $preserv);
1301 1298
 	}
1302 1299
 
1303 1300
 	/**
@@ -1308,14 +1305,14 @@  discard block
 block discarded – undo
1308 1305
 	protected function find_pm_id($project)
1309 1306
 	{
1310 1307
 		list($pm_number, $pm_title) = explode(': ', $project, 2);
1311
-		if(!$pm_number || !$pm_title)
1308
+		if (!$pm_number || !$pm_title)
1312 1309
 		{
1313 1310
 			return false;
1314 1311
 		}
1315 1312
 
1316 1313
 		$pm = new projectmanager_bo();
1317 1314
 		$pm_ids = $pm->search(array('pm_number' => $pm_number, 'pm_title' => $pm_title));
1318
-		if($pm_ids && count($pm_ids) >= 1)
1315
+		if ($pm_ids && count($pm_ids) >= 1)
1319 1316
 		{
1320 1317
 			return $pm_ids[0]['pm_id'];
1321 1318
 		}
@@ -1331,17 +1328,17 @@  discard block
 block discarded – undo
1331 1328
 		$original_id = $this->data['ts_id'];
1332 1329
 		unset($this->data['ts_id']);
1333 1330
 
1334
-		$this->data['ts_title'] = lang('Copy of:') . ' ' .$this->data['ts_title'];
1331
+		$this->data['ts_title'] = lang('Copy of:').' '.$this->data['ts_title'];
1335 1332
 		unset($this->data['ts_modified']);
1336 1333
 		unset($this->data['ts_modifier']);
1337
-		$this->data['ts_owner'] = !(int)$this->data['ts_owner'] || !$this->check_acl(Acl::ADD,NULL,$this->data['ts_owner']) ? $this->user : $this->data['ts_owner'];
1334
+		$this->data['ts_owner'] = !(int)$this->data['ts_owner'] || !$this->check_acl(Acl::ADD, NULL, $this->data['ts_owner']) ? $this->user : $this->data['ts_owner'];
1338 1335
 
1339 1336
 		// Copy links
1340
-		if(!is_array($this->data['link_to'])) $this->data['link_to'] = array();
1337
+		if (!is_array($this->data['link_to'])) $this->data['link_to'] = array();
1341 1338
 		$this->data['link_to']['to_app'] = 'timesheet';
1342 1339
 		$this->data['link_to']['to_id'] = 0;
1343 1340
 
1344
-		foreach(Link::get_links($this->data['link_to']['to_app'], $original_id) as $link)
1341
+		foreach (Link::get_links($this->data['link_to']['to_app'], $original_id) as $link)
1345 1342
 		{
1346 1343
 			if ($link['app'] != Link::VFS_APPNAME)
1347 1344
 			{
Please login to merge, or discard this patch.
Braces   +177 added lines, -45 removed lines patch added patch discarded remove patch
@@ -63,7 +63,10 @@  discard block
 block discarded – undo
63 63
 		$etpl = new Etemplate('timesheet.edit');
64 64
 		if (!is_array($content))
65 65
 		{
66
-			if ($_GET['msg']) $msg = strip_tags($_GET['msg']);
66
+			if ($_GET['msg'])
67
+			{
68
+				$msg = strip_tags($_GET['msg']);
69
+			}
67 70
 
68 71
 			if ($view || (int)$_GET['ts_id'])
69 72
 			{
@@ -130,23 +133,32 @@  discard block
 block discarded – undo
130 133
 				$content['ts_description'] = $content['ts_description_short'];
131 134
 			}
132 135
 			// we only need 2 out of 3 values from start-, end-time or duration (the date in ts_start is always required!)
133
-			if (isset($content['start_time']))		// start-time specified
136
+			if (isset($content['start_time']))
137
+			{
138
+				// start-time specified
134 139
 			{
135 140
 				//$content['ts_start'] += $content['start_time'];
136 141
 				$start = new Api\DateTime($content['ts_start']);
142
+			}
137 143
 				$start_time = explode(':',$content['start_time']);
138 144
 				$start->setTime($start_time[0],$start_time[1]);
139 145
 				$content['ts_start'] = $start->format('ts');
140 146
 			}
141
-			if (isset($content['end_time']))		// end-time specified
147
+			if (isset($content['end_time']))
148
+			{
149
+				// end-time specified
142 150
 			{
143 151
 				$end = new Api\DateTime($content['ts_start']);
152
+			}
144 153
 				$end_time = explode(':',$content['end_time']);
145 154
 				$end->setTime($end_time[0],$end_time[1]);
146 155
 			}
147
-			if ($end && $start)	// start- & end-time --> calculate the duration
156
+			if ($end && $start)
157
+			{
158
+				// start- & end-time --> calculate the duration
148 159
 			{
149 160
 				$content['ts_duration'] = ($end->format('ts') - $start->format('ts')) / 60;
161
+			}
150 162
 				// check if negative duration is caused by wrap over midnight
151 163
 				if ($content['ts_duration'] < 0 && $content['ts_duration'] > -24*60)
152 164
 				{
@@ -154,12 +166,18 @@  discard block
 block discarded – undo
154 166
 				}
155 167
 				//echo "<p>end_time=$content[end_time], start_time=$content[start_time] --> duration=$content[ts_duration]</p>\n";
156 168
 			}
157
-			elseif ($content['ts_duration'] && $end)	// no start, calculate from end and duration
169
+			elseif ($content['ts_duration'] && $end)
170
+			{
171
+				// no start, calculate from end and duration
158 172
 			{
159 173
 				$content['ts_start'] = $end->format('ts') - 60*$content['ts_duration'];
174
+			}
160 175
 				//echo "<p>end_time=$content[end_time], duration=$content[ts_duration] --> ts_start=$content[ts_start]=".Api\DateTime::to($content['ts_start'])."</p>\n";
161 176
 			}
162
-			if ($content['ts_duration'] > 0) unset($content['end_time']);
177
+			if ($content['ts_duration'] > 0)
178
+			{
179
+				unset($content['end_time']);
180
+			}
163 181
 			// now we only deal with start (date+time) and duration
164 182
 			list($button) = @each($content['button']);
165 183
 			$view = $content['view'];
@@ -173,7 +191,10 @@  discard block
 block discarded – undo
173 191
 			switch($button)
174 192
 			{
175 193
 				case 'edit':
176
-					if ($this->check_acl(Acl::EDIT) && !$only_admin_edit) $view = false;
194
+					if ($this->check_acl(Acl::EDIT) && !$only_admin_edit)
195
+					{
196
+						$view = false;
197
+					}
177 198
 					break;
178 199
 
179 200
 				case 'undelete':
@@ -187,12 +208,15 @@  discard block
 block discarded – undo
187 208
 				case 'save':
188 209
 				case 'save_new':
189 210
 				case 'apply':
190
-					if ((!$this->data['ts_quantity'] || $this->ts_viewtype == 'short') && $this->data['ts_duration'])	// set the quantity (in h) from the duration (in min)
211
+					if ((!$this->data['ts_quantity'] || $this->ts_viewtype == 'short') && $this->data['ts_duration'])
212
+					{
213
+						// set the quantity (in h) from the duration (in min)
191 214
 					{
192 215
 						// We need to keep the actual value of ts_quantity when we are storing it, as it is used in price calculation
193 216
 						// and rounding it causes miscalculation on prices
194 217
 						$this->data['ts_quantity'] = $this->data['ts_duration'] / 60.0;
195 218
 					}
219
+					}
196 220
 					if (!$this->data['ts_quantity'])
197 221
 					{
198 222
 						$etpl->set_validation_error('ts_quantity',lang('Field must not be empty !!!'));
@@ -226,7 +250,11 @@  discard block
 block discarded – undo
226 250
 							unset($content['ts_project_blur']);
227 251
 						}
228 252
 					}
229
-					if ($etpl->validation_errors()) break;	// the user need to fix the error, before we can save the entry
253
+					if ($etpl->validation_errors())
254
+					{
255
+						break;
256
+					}
257
+					// the user need to fix the error, before we can save the entry
230 258
 
231 259
 					// account for changed project --> remove old one from links and add new one
232 260
 					if ((int) $this->data['pm_id'] != (int) $this->data['old_pm_id'])
@@ -270,14 +298,20 @@  discard block
 block discarded – undo
270 298
 						}
271 299
 					}
272 300
 					Framework::refresh_opener($msg, 'timesheet', $this->data['ts_id'], $content['ts_id'] ? 'edit' : 'add');
273
-					if ($button == 'apply') break;
301
+					if ($button == 'apply')
302
+					{
303
+						break;
304
+					}
274 305
 					if ($button == 'save_new')
275 306
 					{
276 307
 						$msg .= ', '.lang('creating new entry');		// giving some feedback to the user
277 308
 
278
-						if (!is_array($content['link_to']['to_id']))	// set links again, so new entry gets the same links as the existing one
309
+						if (!is_array($content['link_to']['to_id']))
310
+						{
311
+							// set links again, so new entry gets the same links as the existing one
279 312
 						{
280 313
 							$content['link_to']['to_id'] = 0;
314
+						}
281 315
 							foreach(Link::get_links(TIMESHEET_APP,$this->data['ts_id'],'!'.Link::VFS_APPNAME) as $link)
282 316
 							{
283 317
 								Link::link(TIMESHEET_APP,$content['link_to']['to_id'],$link['app'],$link['id'],$link['remark']);
@@ -345,12 +379,15 @@  discard block
 block discarded – undo
345 379
 			foreach(is_array($_REQUEST['link_app']) ? $_REQUEST['link_app'] : array($_REQUEST['link_app']) as $n => $link_app)
346 380
 			{
347 381
 				$link_id = $link_ids[$n];
348
-				if (preg_match('/^[a-z_0-9-]+:[:a-z_0-9-]+$/i',$link_app.':'.$link_id))	// gard against XSS
382
+				if (preg_match('/^[a-z_0-9-]+:[:a-z_0-9-]+$/i',$link_app.':'.$link_id))
383
+				{
384
+					// gard against XSS
349 385
 				{
350 386
 					switch ($link_app)
351 387
 					{
352 388
 						case 'projectmanager':
353 389
 							$links[] = $link_id;
390
+				}
354 391
 							// fall-through;
355 392
 						default:
356 393
 							if(!$n)
@@ -362,8 +399,14 @@  discard block
 block discarded – undo
362 399
 								{
363 400
 									foreach((array)$set['link_app'] as $i => $l_app)
364 401
 									{
365
-										if (($l_id=$set['link_id'][$i])) Link::link(TIMESHEET_APP,$content['link_to']['to_id'],$l_app,$l_id);
366
-										if ($l_app == 'projectmanager') $links[] = $l_id;
402
+										if (($l_id=$set['link_id'][$i]))
403
+										{
404
+											Link::link(TIMESHEET_APP,$content['link_to']['to_id'],$l_app,$l_id);
405
+										}
406
+										if ($l_app == 'projectmanager')
407
+										{
408
+											$links[] = $l_id;
409
+										}
367 410
 									}
368 411
 									unset($set['link_app']);
369 412
 									unset($set['link_id']);
@@ -464,8 +507,16 @@  discard block
 block discarded – undo
464 507
 				$etpl->setElementAttribute('pm_id','blur',$content['ts_project']);
465 508
 			}
466 509
 		}
467
-		if (!$this->customfields) $readonlys['tabs']['customfields'] = true;	// suppress tab if there are not customfields
468
-		if (!$this->data['ts_id']) $readonlys['tabs']['history']    = true;   //suppress history for the first loading without ID
510
+		if (!$this->customfields)
511
+		{
512
+			$readonlys['tabs']['customfields'] = true;
513
+		}
514
+		// suppress tab if there are not customfields
515
+		if (!$this->data['ts_id'])
516
+		{
517
+			$readonlys['tabs']['history']    = true;
518
+		}
519
+		//suppress history for the first loading without ID
469 520
 
470 521
 		return $etpl->exec(TIMESHEET_APP.'.timesheet_ui.edit',$content,$sel_options,$readonlys,$preserv,2);
471 522
 	}
@@ -478,7 +529,10 @@  discard block
 block discarded – undo
478 529
 	 */
479 530
 	function datetime2time($datetime)
480 531
 	{
481
-		if (!$datetime) return 0;
532
+		if (!$datetime)
533
+		{
534
+			return 0;
535
+		}
482 536
 
483 537
 		return $datetime - mktime(0,0,0,date('m',$datetime),date('d',$datetime),date('Y',$datetime));
484 538
 	}
@@ -524,7 +578,10 @@  discard block
 block discarded – undo
524 578
 			}
525 579
 			// show week-sums, if we are week-aligned (show full weeks)?
526 580
 			$week_start_day = $GLOBALS['egw_info']['user']['preferences']['calendar']['weekdaystarts'];
527
-			if (!$week_start_day) $week_start_day = 'Sunday';
581
+			if (!$week_start_day)
582
+			{
583
+				$week_start_day = 'Sunday';
584
+			}
528 585
 			switch($week_start_day)
529 586
 			{
530 587
 				case 'Sunday': $week_end_day = 'Saturday'; break;
@@ -545,7 +602,10 @@  discard block
 block discarded – undo
545 602
 			}
546 603
 		}
547 604
 		//echo "<p align=right>show_sums=".print_r($this->show_sums,true)."</p>\n";
548
-		if (!$id_only && !$query_in['csv_export']) Api\Cache::setSession(TIMESHEET_APP, 'index', $query_in);
605
+		if (!$id_only && !$query_in['csv_export'])
606
+		{
607
+			Api\Cache::setSession(TIMESHEET_APP, 'index', $query_in);
608
+		}
549 609
 
550 610
 		// Refresh actions (undelete needs this)
551 611
 		$query_in['actions'] = $this->get_actions($query_in);
@@ -553,8 +613,14 @@  discard block
 block discarded – undo
553 613
 		$query = $query_in;	// keep the original query
554 614
 		$query['enddate'] = $end_date;
555 615
 
556
-		if($this->ts_viewtype == 'short') $query_in['options-selectcols'] = array('ts_quantity'=>false,'ts_unitprice'=>false,'ts_total'=>false);
557
-		if ($query['no_status']) $query_in['options-selectcols']['ts_status'] = false;
616
+		if($this->ts_viewtype == 'short')
617
+		{
618
+			$query_in['options-selectcols'] = array('ts_quantity'=>false,'ts_unitprice'=>false,'ts_total'=>false);
619
+		}
620
+		if ($query['no_status'])
621
+		{
622
+			$query_in['options-selectcols']['ts_status'] = false;
623
+		}
558 624
 
559 625
 		//_debug_array($query['col_filter']);
560 626
 		//echo "PM Integration:".$this->pm_integration.'<br>';
@@ -567,8 +633,14 @@  discard block
 block discarded – undo
567 633
 		{
568 634
 			//$query['col_filter']['ts_id'] = Link::get_links('projectmanager',$query['col_filter']['pm_id'],'timesheet');
569 635
 			$query['col_filter']['ts_id'] = $this->get_ts_links($query['col_filter']['pm_id']);
570
-			if (empty($query['col_filter']['ts_id'])) $query['col_filter']['ts_id'] = -1;
571
-			if (!$query['col_filter']['ts_id']) $query['col_filter']['ts_id'] = 0;
636
+			if (empty($query['col_filter']['ts_id']))
637
+			{
638
+				$query['col_filter']['ts_id'] = -1;
639
+			}
640
+			if (!$query['col_filter']['ts_id'])
641
+			{
642
+				$query['col_filter']['ts_id'] = 0;
643
+			}
572 644
 		}
573 645
 		if ((string)$query['col_filter']['pm_id'] != '' && (string)$query['col_filter']['pm_id'] == '0')
574 646
 		{
@@ -640,10 +712,13 @@  discard block
 block discarded – undo
640 712
 			$cats = $GLOBALS['egw']->categories->return_all_children((int)$query['cat_id']);
641 713
 			$query['col_filter']['cat_id'] = count($cats) > 1 ? $cats : $query['cat_id'];
642 714
 		}
643
-		elseif ((string)$query['cat_id'] == '0')	// no category
715
+		elseif ((string)$query['cat_id'] == '0')
716
+		{
717
+			// no category
644 718
 		{
645 719
 			$query['col_filter']['cat_id'] = null;
646 720
 		}
721
+		}
647 722
 		else	// all cats --> no filter
648 723
 		{
649 724
 			unset($query['col_filter']['cat_id']);
@@ -654,7 +729,10 @@  discard block
 block discarded – undo
654 729
 			$GLOBALS['egw_info']['flags']['app_header'] .= ': '.Api\Accounts::username($query['col_filter']['ts_owner']);
655 730
 			#if ($GLOBALS['egw']->accounts->get_type($query['col_filter']['ts_owner']) == 'g') $GLOBALS['egw_info']['flags']['app_header'] .= ' '. lang("and its members");
656 731
 			#_debug_array($GLOBALS['egw']->accounts->members($query['col_filter']['ts_owner'],true));
657
-			if ($query['col_filter']['ts_owner']<0) $query['col_filter']['ts_owner'] = array_merge(array($query['col_filter']['ts_owner']),$GLOBALS['egw']->accounts->members($query['col_filter']['ts_owner'],true));
732
+			if ($query['col_filter']['ts_owner']<0)
733
+			{
734
+				$query['col_filter']['ts_owner'] = array_merge(array($query['col_filter']['ts_owner']),$GLOBALS['egw']->accounts->members($query['col_filter']['ts_owner'],true));
735
+			}
658 736
 		}
659 737
 		else
660 738
 		{
@@ -667,10 +745,13 @@  discard block
 block discarded – undo
667 745
 			// generate a meaningful app-header / report title
668 746
 			if ($this->show_sums['month'])
669 747
 			{
670
-				if ((int)$start[1] == 1 && (int) $end[1] == 12)		// whole year(s)
748
+				if ((int)$start[1] == 1 && (int) $end[1] == 12)
749
+				{
750
+					// whole year(s)
671 751
 				{
672 752
 					$GLOBALS['egw_info']['flags']['app_header'] .= ': ' . $start[0] . ($start[0] != $end[0] ? ' - '.$end[0] : '');
673 753
 				}
754
+				}
674 755
 				else
675 756
 				{
676 757
 					$GLOBALS['egw_info']['flags']['app_header'] .= ': ' . lang(date('F',$query['startdate']+12*60*60)) . ' ' . $start[0];
@@ -712,7 +793,10 @@  discard block
 block discarded – undo
712 793
 		$ids = array();
713 794
 		foreach($rows as &$row)
714 795
 		{
715
-			if ($row['ts_id'] > 0) $ids[] = $row['ts_id'];
796
+			if ($row['ts_id'] > 0)
797
+			{
798
+				$ids[] = $row['ts_id'];
799
+			}
716 800
 		}
717 801
 		if ($id_only)
718 802
 		{
@@ -742,12 +826,19 @@  discard block
 block discarded – undo
742 826
 		$have_cats = false;
743 827
 		foreach($rows as &$row)
744 828
 		{
745
-			if ($row['cat_id']) $have_cats = true;
829
+			if ($row['cat_id'])
830
+			{
831
+				$have_cats = true;
832
+			}
746 833
 
747 834
 			$row['class'] = 'row';
748
-			if ($row['ts_id'] <= 0)	// sums
835
+			if ($row['ts_id'] <= 0)
749 836
 			{
750
-				if ($query['sort'] == 'ASC') $row['ts_start'] -= 7200;	// fix for DSL change
837
+				// sums
838
+			{
839
+				if ($query['sort'] == 'ASC') $row['ts_start'] -= 7200;
840
+			}
841
+			// fix for DSL change
751 842
 
752 843
 				// Remove fake modified date, it breaks nextmatch checks
753 844
 				unset($row['ts_modified']);
@@ -775,7 +866,10 @@  discard block
 block discarded – undo
775 866
 						break;
776 867
 				}
777 868
 				$row['ts_start'] = $row['ts_unitprice'] = '';
778
-				if (!$this->quantity_sum) $row['ts_quantity'] = '';
869
+				if (!$this->quantity_sum)
870
+				{
871
+					$row['ts_quantity'] = '';
872
+				}
779 873
 				$row['class'] = 'th rowNoEdit rowNoDelete rowNoUndelete';
780 874
 				$row['titleClass'] = 'timesheet_titleSum';
781 875
 				continue;
@@ -817,11 +911,17 @@  discard block
 block discarded – undo
817 911
 				}
818 912
 			}
819 913
 
820
-			if(!$row['titleClass']) $row['titleClass'] = 'timesheet_titleDetails';
914
+			if(!$row['titleClass'])
915
+			{
916
+				$row['titleClass'] = 'timesheet_titleDetails';
917
+			}
821 918
 
822 919
 		}
823 920
 		$rows['no_cat_id'] = (!$have_cats || $query['cat_id']);
824
-		if ($query['col_filter']['ts_owner']) $rows['ownerClass'] = 'noPrint';
921
+		if ($query['col_filter']['ts_owner'])
922
+		{
923
+			$rows['ownerClass'] = 'noPrint';
924
+		}
825 925
 		$rows['no_owner_col'] = $query['no_owner_col'];
826 926
 		if(is_string($query['selectcols']))
827 927
 		{
@@ -839,13 +939,23 @@  discard block
 block discarded – undo
839 939
 		if (!$rows['ts_viewtype'])
840 940
 		{
841 941
 			#_debug_array($query['selectcols']);
842
-			if(!is_array($query['selectcols'])){
942
+			if(!is_array($query['selectcols']))
943
+			{
843 944
 				$query['selectcols'] = explode(',',$query['selectcols']);
844 945
 			}
845 946
 			#ts_quantity,ts_unitprice,ts_total
846
-			if ($query['selectcols'] && in_array('ts_quantity_quantity',$query['selectcols'])===false) $rows['no_ts_quantity'] = 1;
847
-			if ($query['selectcols'] && in_array('ts_unitprice', $query['selectcols'])===false) $rows['no_ts_unitprice'] = 1;
848
-			if ($query['selectcols'] && in_array('ts_total_price',$query['selectcols'])===false) $rows['no_ts_total'] = 1;
947
+			if ($query['selectcols'] && in_array('ts_quantity_quantity',$query['selectcols'])===false)
948
+			{
949
+				$rows['no_ts_quantity'] = 1;
950
+			}
951
+			if ($query['selectcols'] && in_array('ts_unitprice', $query['selectcols'])===false)
952
+			{
953
+				$rows['no_ts_unitprice'] = 1;
954
+			}
955
+			if ($query['selectcols'] && in_array('ts_total_price',$query['selectcols'])===false)
956
+			{
957
+				$rows['no_ts_total'] = 1;
958
+			}
849 959
 		}
850 960
 		$rows['no_ts_status'] = in_array('ts_status', $query['selectcols']) === false && !$this->config_data['history'] ||
851 961
 			$query['no_status'];
@@ -868,7 +978,10 @@  discard block
 block discarded – undo
868 978
 	{
869 979
 		$etpl = new Etemplate('timesheet.index');
870 980
 
871
-		if ($_GET['msg']) $msg = $_GET['msg'];
981
+		if ($_GET['msg'])
982
+		{
983
+			$msg = $_GET['msg'];
984
+		}
872 985
 		if ($content['nm']['rows']['delete'])
873 986
 		{
874 987
 			list($ts_id) = each($content['nm']['rows']['delete']);
@@ -881,9 +994,12 @@  discard block
 block discarded – undo
881 994
 				$msg = lang('Error deleting the entry!!!');
882 995
 			}
883 996
 		}
884
-		if (is_array($content) && isset($content['nm']['rows']['document']))  // handle insert in default document button like an action
997
+		if (is_array($content) && isset($content['nm']['rows']['document']))
998
+		{
999
+			// handle insert in default document button like an action
885 1000
 		{
886 1001
 			list($id) = @each($content['nm']['rows']['document']);
1002
+		}
887 1003
 			$content['nm']['action'] = 'document';
888 1004
 			$content['nm']['selected'] = array($id);
889 1005
 		}
@@ -957,7 +1073,10 @@  discard block
 block discarded – undo
957 1073
 		}
958 1074
 		$read_grants = $this->grant_list(Acl::READ);
959 1075
 		$content['nm']['no_owner_col'] = count($read_grants) == 1;
960
-		if ($GLOBALS['egw_info']['user']['preferences']['timesheet']['nextmatch-timesheet.index.rows']) $content['nm']['selectcols'] = $GLOBALS['egw_info']['user']['preferences']['timesheet']['nextmatch-timesheet.index.rows'];
1076
+		if ($GLOBALS['egw_info']['user']['preferences']['timesheet']['nextmatch-timesheet.index.rows'])
1077
+		{
1078
+			$content['nm']['selectcols'] = $GLOBALS['egw_info']['user']['preferences']['timesheet']['nextmatch-timesheet.index.rows'];
1079
+		}
961 1080
 		$sel_options = array(
962 1081
 			'ts_owner'   => $read_grants,
963 1082
 			'pm_id'      => array(lang('No project')),
@@ -974,7 +1093,10 @@  discard block
 block discarded – undo
974 1093
 		if ($this->pm_integration != 'full')
975 1094
 		{
976 1095
 			$projects =& $this->query_list('ts_project');
977
-			if (!is_array($projects)) $projects = array();
1096
+			if (!is_array($projects))
1097
+			{
1098
+				$projects = array();
1099
+			}
978 1100
 			$sel_options['ts_project'] = $projects + array(lang('No project'));
979 1101
 		}
980 1102
 
@@ -1192,7 +1314,8 @@  discard block
 block discarded – undo
1192 1314
 			case 'cat':
1193 1315
 				$cat_name = Api\Categories::id2name($settings);
1194 1316
 				$action_msg = lang('changed category to %1', $cat_name);
1195
-				foreach((array)$checked as $n => $id) {
1317
+				foreach((array)$checked as $n => $id)
1318
+				{
1196 1319
 					if (($entry = $this->read($id)) &&
1197 1320
 						($entry['cat_id'] = $settings) &&
1198 1321
 						$this->save($entry) == 0)
@@ -1207,7 +1330,10 @@  discard block
 block discarded – undo
1207 1330
 				break;
1208 1331
 
1209 1332
 			case 'document':
1210
-				if (!$settings) $settings = $GLOBALS['egw_info']['user']['preferences']['timesheet']['default_document'];
1333
+				if (!$settings)
1334
+				{
1335
+					$settings = $GLOBALS['egw_info']['user']['preferences']['timesheet']['default_document'];
1336
+				}
1211 1337
 				$document_merge = new timesheet_merge();
1212 1338
 				$msg = $document_merge->download($settings, $checked, '', $GLOBALS['egw_info']['user']['preferences']['timesheet']['document_dir']);
1213 1339
 				$failed = count($checked);
@@ -1259,7 +1385,10 @@  discard block
 block discarded – undo
1259 1385
 						$this->load_statuses();
1260 1386
 						$msg .= lang('Status updated.');
1261 1387
 					}
1262
-					if ($button == 'apply') break;
1388
+					if ($button == 'apply')
1389
+					{
1390
+						break;
1391
+					}
1263 1392
 					// fall-through
1264 1393
 				case 'cancel':
1265 1394
 					$GLOBALS['egw']->redirect_link('/admin/index.php', null, 'admin');
@@ -1337,7 +1466,10 @@  discard block
 block discarded – undo
1337 1466
 		$this->data['ts_owner'] = !(int)$this->data['ts_owner'] || !$this->check_acl(Acl::ADD,NULL,$this->data['ts_owner']) ? $this->user : $this->data['ts_owner'];
1338 1467
 
1339 1468
 		// Copy links
1340
-		if(!is_array($this->data['link_to'])) $this->data['link_to'] = array();
1469
+		if(!is_array($this->data['link_to']))
1470
+		{
1471
+			$this->data['link_to'] = array();
1472
+		}
1341 1473
 		$this->data['link_to']['to_app'] = 'timesheet';
1342 1474
 		$this->data['link_to']['to_id'] = 0;
1343 1475
 
Please login to merge, or discard this patch.