Completed
Push — 16.1 ( 69790c...2ab113 )
by Hadi
39:59 queued 21:42
created
api/src/Preferences.php 1 patch
Spacing   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
 	const TABLE = 'egw_preferences';
96 96
 	var $table = self::TABLE;
97 97
 
98
-	var $values,$vars;	// standard notify substitues, will be set by standard_substitues()
98
+	var $values, $vars; // standard notify substitues, will be set by standard_substitues()
99 99
 
100 100
 	/**
101 101
 	 * Contstructor
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
 			case self::FORCED_ID:
164 164
 				return 'forced';
165 165
 		}
166
-		return $this->account_id < self::DEFAULT_ID ? $this->account_id-self::DEFAULT_ID : $this->account_id;
166
+		return $this->account_id < self::DEFAULT_ID ? $this->account_id - self::DEFAULT_ID : $this->account_id;
167 167
 	}
168 168
 
169 169
 	/**
@@ -193,21 +193,21 @@  discard block
 block discarded – undo
193 193
 	{
194 194
 		$prefs = Cache::getInstance(__CLASS__, $ids);
195 195
 		$db_read = array();
196
-		foreach((array)$ids as $id)
196
+		foreach ((array)$ids as $id)
197 197
 		{
198 198
 			// if prefs are not returned, null or not an array, read them from db
199 199
 			if (!isset($prefs[$id]) && !is_array($prefs[$id])) $db_read[] = $id;
200 200
 		}
201 201
 		if ($db_read)
202 202
 		{
203
-			foreach($this->db->select($this->table,'*',array('preference_owner' => $db_read),__LINE__,__FILE__) as $row)
203
+			foreach ($this->db->select($this->table, '*', array('preference_owner' => $db_read), __LINE__, __FILE__) as $row)
204 204
 			{
205 205
 				// The following replacement is required for PostgreSQL to work
206 206
 				$app = trim($row['preference_app']);
207 207
 
208 208
 				$prefs[$row['preference_owner']][$app] = self::unserialize($row['preference_value']);
209 209
 			}
210
-			foreach($db_read as $id)
210
+			foreach ($db_read as $id)
211 211
 			{
212 212
 				if (!isset($prefs[$id])) $prefs[$id] = array();
213 213
 				Cache::setInstance(__CLASS__, $id, $prefs[$id]);
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
 	 * @param boolean $use_standard_values =true should the standard values are used
227 227
 	 * @return string with parsed notify-msg
228 228
 	 */
229
-	function parse_notify($msg,$values=array(),$use_standard_values=True)
229
+	function parse_notify($msg, $values = array(), $use_standard_values = True)
230 230
 	{
231 231
 		$vals = $values ? $values : array();
232 232
 
@@ -235,13 +235,13 @@  discard block
 block discarded – undo
235 235
 			$vals += $this->values;
236 236
 		}
237 237
 		$replace = $with = array();
238
-		foreach($vals as $key => $val)
238
+		foreach ($vals as $key => $val)
239 239
 		{
240 240
 			if ($this->debug) error_log(__METHOD__." replacing \$\$$key\$\$ with $val  ");
241 241
 			$replace[] = '$$'.$key.'$$';
242 242
 			$with[]    = $val;
243 243
 		}
244
-		return str_replace($replace,$with,$msg);
244
+		return str_replace($replace, $with, $msg);
245 245
 	}
246 246
 
247 247
 	/**
@@ -253,9 +253,9 @@  discard block
 block discarded – undo
253 253
 	 * @param boolean $un_lang =false if true translate back
254 254
 	 * @return string
255 255
 	 */
256
-	function lang_notify($msg,$vals=array(),$un_lang=False)
256
+	function lang_notify($msg, $vals = array(), $un_lang = False)
257 257
 	{
258
-		foreach(array_keys($vals) as $key)
258
+		foreach (array_keys($vals) as $key)
259 259
 		{
260 260
 			$lname = ($lname = lang($key)) == $key.'*' ? $key : $lname;
261 261
 			if ($un_lang)
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
 				$langs[$key] = '$$'.$lname.'$$';
268 268
 			}
269 269
 		}
270
-		return $this->parse_notify($msg,$langs,False);
270
+		return $this->parse_notify($msg, $langs, False);
271 271
 	}
272 272
 
273 273
 	/**
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
 		if ($this->debug) error_log(__METHOD__." is called ");
279 279
 		if (!is_array(@$GLOBALS['egw_info']['user']['preferences']))
280 280
 		{
281
-			$GLOBALS['egw_info']['user']['preferences'] = $this->data;	// else no lang()
281
+			$GLOBALS['egw_info']['user']['preferences'] = $this->data; // else no lang()
282 282
 		}
283 283
 		// we cant use egw_info/user/fullname, as it's not set when we run
284 284
 		$this->values = array(	// standard notify replacements
@@ -287,37 +287,37 @@  discard block
 block discarded – undo
287 287
 			'lastname'  => Accounts::id2name($this->account_id, 'account_lastname'),
288 288
 			'domain'    => $GLOBALS['egw_info']['server']['mail_suffix'],
289 289
 			'email'     => $this->email_address($this->account_id),
290
-			'date'      => DateTime::to('now',$GLOBALS['egw_info']['user']['preferences']['common']['dateformat']),
290
+			'date'      => DateTime::to('now', $GLOBALS['egw_info']['user']['preferences']['common']['dateformat']),
291 291
 		);
292 292
 		// do this first, as it might be already contain some substitues
293 293
 		//
294 294
 		$this->values['email'] = $this->parse_notify($this->values['email']);
295 295
 
296 296
 		$this->vars = array(	// langs have to be in common !!!
297
-			'fullname'  => lang('name of the user, eg. "%1"',$this->values['fullname']),
298
-			'firstname' => lang('first name of the user, eg. "%1"',$this->values['firstname']),
299
-			'lastname'  => lang('last name of the user, eg. "%1"',$this->values['lastname']),
300
-			'domain'    => lang('domain name for mail-address, eg. "%1"',$this->values['domain']),
301
-			'email'     => lang('email-address of the user, eg. "%1"',$this->values['email']),
302
-			'date'      => lang('todays date, eg. "%1"',$this->values['date']),
297
+			'fullname'  => lang('name of the user, eg. "%1"', $this->values['fullname']),
298
+			'firstname' => lang('first name of the user, eg. "%1"', $this->values['firstname']),
299
+			'lastname'  => lang('last name of the user, eg. "%1"', $this->values['lastname']),
300
+			'domain'    => lang('domain name for mail-address, eg. "%1"', $this->values['domain']),
301
+			'email'     => lang('email-address of the user, eg. "%1"', $this->values['email']),
302
+			'date'      => lang('todays date, eg. "%1"', $this->values['date']),
303 303
 		);
304
-		if ($this->debug) error_log(__METHOD__.print_r($this->vars,true));
304
+		if ($this->debug) error_log(__METHOD__.print_r($this->vars, true));
305 305
 		// do the substituetion in the effective prefs (data)
306 306
 		//
307
-		foreach($this->data as $app => $data)
307
+		foreach ($this->data as $app => $data)
308 308
 		{
309
-			if(!is_array($data)) continue;
310
-			foreach($data as $key => $val)
309
+			if (!is_array($data)) continue;
310
+			foreach ($data as $key => $val)
311 311
 			{
312
-				if (!is_array($val) && strpos($val,'$$') !== False)
312
+				if (!is_array($val) && strpos($val, '$$') !== False)
313 313
 				{
314 314
 					$this->data[$app][$key] = $this->parse_notify($val);
315 315
 				}
316 316
 				elseif (is_array($val))
317 317
 				{
318
-					foreach($val as $k => $v)
318
+					foreach ($val as $k => $v)
319 319
 					{
320
-						if (!is_array($v) && strpos($v,'$$') !== False)
320
+						if (!is_array($v) && strpos($v, '$$') !== False)
321 321
 						{
322 322
 							$this->data[$app][$key][$k] = $this->parse_notify($v);
323 323
 						}
@@ -342,12 +342,12 @@  discard block
 block discarded – undo
342 342
 		}
343 343
 		// handling of old PHP serialized and addslashed prefs
344 344
 		$data = php_safe_unserialize($str);
345
-		if($data === false)
345
+		if ($data === false)
346 346
 		{
347 347
 			// manually retrieve the string lengths of the serialized array if unserialize failed
348 348
 			$data = php_safe_unserialize(preg_replace_callback('!s:(\d+):"(.*?)";!s', function($matches)
349 349
 			{
350
-				return 's:'.mb_strlen($matches[2],'8bit').':"'.$matches[2].'";';
350
+				return 's:'.mb_strlen($matches[2], '8bit').':"'.$matches[2].'";';
351 351
 			}, $str));
352 352
 		}
353 353
 		self::unquote($data);
@@ -366,7 +366,7 @@  discard block
 block discarded – undo
366 366
 			$arr = stripslashes($arr);
367 367
 			return;
368 368
 		}
369
-		foreach($arr as $key => $value)
369
+		foreach ($arr as $key => $value)
370 370
 		{
371 371
 			if (is_array($value))
372 372
 			{
@@ -387,27 +387,27 @@  discard block
 block discarded – undo
387 387
 	 * @param boolean $use_session =true should the session prefs get used (default true) or not (false)
388 388
 	 * @return array with effective prefs ($this->data)
389 389
 	 */
390
-	function read_repository($use_session=true)
390
+	function read_repository($use_session = true)
391 391
 	{
392
-		$this->session = $use_session ? Cache::getSession('preferences','preferences') : array();
392
+		$this->session = $use_session ? Cache::getSession('preferences', 'preferences') : array();
393 393
 		if (!is_array($this->session))
394 394
 		{
395 395
 			$this->session = array();
396 396
 		}
397 397
 		$this->forced = $this->default = $this->user = $this->group = array();
398
-		$to_read = array(self::DEFAULT_ID,self::FORCED_ID,$this->account_id);
398
+		$to_read = array(self::DEFAULT_ID, self::FORCED_ID, $this->account_id);
399 399
 		if ($this->account_id > 0)
400 400
 		{
401 401
 			$primary_group = Accounts::id2name($this->account_id, 'account_primary_group');
402
-			foreach((array)$GLOBALS['egw']->accounts->memberships($this->account_id, true) as $gid)
402
+			foreach ((array)$GLOBALS['egw']->accounts->memberships($this->account_id, true) as $gid)
403 403
 			{
404
-				if ($gid != $primary_group) $to_read[] = $gid + self::DEFAULT_ID;	// need to offset it with DEFAULT_ID = -2!
404
+				if ($gid != $primary_group) $to_read[] = $gid + self::DEFAULT_ID; // need to offset it with DEFAULT_ID = -2!
405 405
 			}
406 406
 			$to_read[] = $primary_group + self::DEFAULT_ID;
407 407
 		}
408
-		foreach($this->cache_read($to_read) as $id => $values)
408
+		foreach ($this->cache_read($to_read) as $id => $values)
409 409
 		{
410
-			switch($id)
410
+			switch ($id)
411 411
 			{
412 412
 				case self::FORCED_ID:
413 413
 					$this->forced = $values;
@@ -419,7 +419,7 @@  discard block
 block discarded – undo
419 419
 					$this->user = $values;
420 420
 					break;
421 421
 				default:
422
-					foreach($values as $app => $vals)
422
+					foreach ($values as $app => $vals)
423 423
 					{
424 424
 						$this->group[$app] = (array)$vals + (array)$this->group[$app];
425 425
 					}
@@ -430,9 +430,9 @@  discard block
 block discarded – undo
430 430
 
431 431
 		// let the (temp.) session prefs. override the user prefs.
432 432
 		//
433
-		foreach($this->session as $app => $values)
433
+		foreach ($this->session as $app => $values)
434 434
 		{
435
-			foreach($values as $var => $value)
435
+			foreach ($values as $var => $value)
436 436
 			{
437 437
 				$this->data[$app][$var] = $value;
438 438
 			}
@@ -440,9 +440,9 @@  discard block
 block discarded – undo
440 440
 
441 441
 		// now use (primary) group defaults if needed (user-value unset or empty)
442 442
 		//
443
-		foreach((array)$this->group as $app => $values)
443
+		foreach ((array)$this->group as $app => $values)
444 444
 		{
445
-			foreach((array)$values as $var => $value)
445
+			foreach ((array)$values as $var => $value)
446 446
 			{
447 447
 				if (!isset($this->data[$app][$var]) || $this->data[$app][$var] === '')
448 448
 				{
@@ -452,9 +452,9 @@  discard block
 block discarded – undo
452 452
 		}
453 453
 		// now use defaults if needed (user-value unset or empty)
454 454
 		//
455
-		foreach((array)$this->default as $app => $values)
455
+		foreach ((array)$this->default as $app => $values)
456 456
 		{
457
-			foreach((array)$values as $var => $value)
457
+			foreach ((array)$values as $var => $value)
458 458
 			{
459 459
 				if (!isset($this->data[$app][$var]) || $this->data[$app][$var] === '')
460 460
 				{
@@ -465,9 +465,9 @@  discard block
 block discarded – undo
465 465
 		}
466 466
 		// now set/force forced values
467 467
 		//
468
-		foreach((array)$this->forced as $app => $values)
468
+		foreach ((array)$this->forced as $app => $values)
469 469
 		{
470
-			foreach((array)$values as $var => $value)
470
+			foreach ((array)$values as $var => $value)
471 471
 			{
472 472
 				$this->data[$app][$var] = $value;
473 473
 			}
@@ -483,12 +483,12 @@  discard block
 block discarded – undo
483 483
 		{
484 484
 			reset($this->data);
485 485
 		}
486
-		if (isset($this->debug) && substr($GLOBALS['egw_info']['flags']['currentapp'],0,3) != 'log')
486
+		if (isset($this->debug) && substr($GLOBALS['egw_info']['flags']['currentapp'], 0, 3) != 'log')
487 487
 		{
488
-			echo 'user<pre>';     print_r($this->user); echo "</pre>\n";
489
-			echo 'forced<pre>';   print_r($this->forced); echo "</pre>\n";
490
-			echo 'default<pre>';  print_r($this->default); echo "</pre>\n";
491
-			echo 'group<pre>';    print_r($this->group); echo "</pre>\n";
488
+			echo 'user<pre>'; print_r($this->user); echo "</pre>\n";
489
+			echo 'forced<pre>'; print_r($this->forced); echo "</pre>\n";
490
+			echo 'default<pre>'; print_r($this->default); echo "</pre>\n";
491
+			echo 'group<pre>'; print_r($this->group); echo "</pre>\n";
492 492
 			echo 'effectiv<pre>'; print_r($this->data); echo "</pre>\n";
493 493
 		}
494 494
 		$this->check_set_tz_offset();
@@ -503,7 +503,7 @@  discard block
 block discarded – undo
503 503
 	 * @param string $name =null
504 504
 	 * @return mixed
505 505
 	 */
506
-	function default_prefs($app=null,$name=null)
506
+	function default_prefs($app = null, $name = null)
507 507
 	{
508 508
 		// Etemplate::complete_array_merge() is identical to PHP >= 5.3 array_replace_recursive()
509 509
 		$default = Etemplate::complete_array_merge($this->default, $this->forced);
@@ -521,13 +521,13 @@  discard block
 block discarded – undo
521 521
 	 */
522 522
 	function check_set_tz_offset()
523 523
 	{
524
-		$prefs =& $this->data['common'];
524
+		$prefs = & $this->data['common'];
525 525
 
526 526
 		if (!empty($prefs['tz']))
527 527
 		{
528
-			DateTime::setUserPrefs($prefs['tz'],$prefs['dateformat'],$prefs['timeformat']);
528
+			DateTime::setUserPrefs($prefs['tz'], $prefs['dateformat'], $prefs['timeformat']);
529 529
 			// set the old preference for compatibilty with old code
530
-			$prefs['tz_offset'] = DateTime::tz_offset_s()/3600;
530
+			$prefs['tz_offset'] = DateTime::tz_offset_s() / 3600;
531 531
 		}
532 532
 	}
533 533
 
@@ -551,7 +551,7 @@  discard block
 block discarded – undo
551 551
 		{
552 552
 			$this->read_repository();
553 553
 		}
554
-		reset ($this->data);
554
+		reset($this->data);
555 555
 		return $this->data;
556 556
 	}
557 557
 
@@ -566,7 +566,7 @@  discard block
 block discarded – undo
566 566
 	 * @param string $type ='user' of preference to set: forced, default, user
567 567
 	 * @return array with new effective prefs (even when forced or default prefs are set !)
568 568
 	 */
569
-	function add($app_name,$var,$value = '##undef##',$type='user')
569
+	function add($app_name, $var, $value = '##undef##', $type = 'user')
570 570
 	{
571 571
 		//echo "<p>add('$app_name','$var','$value')</p>\n";
572 572
 		if ($value === '##undef##')
@@ -580,10 +580,10 @@  discard block
 block discarded – undo
580 580
 				if (!isset($this->forced[$app_name][$var]) || $this->forced[$app_name][$var] === '')
581 581
 				{
582 582
 					$this->session[$app_name][$var] = $this->data[$app_name][$var] = $value;
583
-					Cache::setSession('preferences','preferences',$this->session);
584
-					if (method_exists($GLOBALS['egw'],'invalidate_session_cache'))	// egw object in setup is limited
583
+					Cache::setSession('preferences', 'preferences', $this->session);
584
+					if (method_exists($GLOBALS['egw'], 'invalidate_session_cache'))	// egw object in setup is limited
585 585
 					{
586
-						$GLOBALS['egw']->invalidate_session_cache();	// in case with cache the egw_info array in the session
586
+						$GLOBALS['egw']->invalidate_session_cache(); // in case with cache the egw_info array in the session
587 587
 					}
588 588
 				}
589 589
 				break;
@@ -624,13 +624,13 @@  discard block
 block discarded – undo
624 624
 	 * @param string $type ='user' of preference to set: forced, default, user
625 625
 	 * @return array with new effective prefs (even when forced or default prefs are deleted!)
626 626
 	 */
627
-	function delete($app_name, $var = False,$type = 'user')
627
+	function delete($app_name, $var = False, $type = 'user')
628 628
 	{
629 629
 		//echo "<p>delete('$app_name','$var','$type')</p>\n";
630 630
 		$set_via = array(
631
-			'forced'  => array('user','default'),
632
-			'default' => array('forced','user'),
633
-			'user'    => array('forced','group','default'),
631
+			'forced'  => array('user', 'default'),
632
+			'default' => array('forced', 'user'),
633
+			'user'    => array('forced', 'group', 'default'),
634 634
 			'group'   => array('forced'),
635 635
 		);
636 636
 		if (!isset($set_via[$type]))
@@ -664,7 +664,7 @@  discard block
 block discarded – undo
664 664
 			}
665 665
 			else
666 666
 			{
667
-				if($var && @isset($arr[$app_name][$var]) && $arr[$app_name][$var] !== '')
667
+				if ($var && @isset($arr[$app_name][$var]) && $arr[$app_name][$var] !== '')
668 668
 				{
669 669
 					$this->data[$app_name][$var] = $arr[$app_name][$var];
670 670
 					break;
@@ -672,7 +672,7 @@  discard block
 block discarded – undo
672 672
 			}
673 673
 			unset($arr);
674 674
 		}
675
-		reset ($this->data);
675
+		reset($this->data);
676 676
 		return $this->data;
677 677
 	}
678 678
 
@@ -685,7 +685,7 @@  discard block
 block discarded – undo
685 685
 	{
686 686
 		if ($accountid > 0)
687 687
 		{
688
-			$this->db->delete($this->table,array('preference_owner' => $accountid),__LINE__,__FILE__);
688
+			$this->db->delete($this->table, array('preference_owner' => $accountid), __LINE__, __FILE__);
689 689
 
690 690
 			Cache::unsetInstance(__CLASS__, $accountid);
691 691
 		}
@@ -700,9 +700,9 @@  discard block
 block discarded – undo
700 700
 	{
701 701
 		if ($accountid < 0)
702 702
 		{
703
-			$this->db->delete($this->table,array('preference_owner' => $accountid+self::DEFAULT_ID),__LINE__,__FILE__);
703
+			$this->db->delete($this->table, array('preference_owner' => $accountid + self::DEFAULT_ID), __LINE__, __FILE__);
704 704
 
705
-			Cache::unsetInstance(__CLASS__, $accountid+self::DEFAULT_ID);
705
+			Cache::unsetInstance(__CLASS__, $accountid + self::DEFAULT_ID);
706 706
 		}
707 707
 	}
708 708
 
@@ -715,14 +715,14 @@  discard block
 block discarded – undo
715 715
 	 * @param string $old_value if given, only change if that's current value
716 716
 	 * @param string $type if given limit to "user", "forced", "default", "group"
717 717
 	 */
718
-	public static function change_preference($app, $name, $value, $old_value=null, $type=null)
718
+	public static function change_preference($app, $name, $value, $old_value = null, $type = null)
719 719
 	{
720 720
 		$db = isset($GLOBALS['egw_setup']->db) ? $GLOBALS['egw_setup']->db : $GLOBALS['egw']->db;
721 721
 
722 722
 		$where = array();
723 723
 		if ($app) $where['preference_app'] = $app;
724 724
 
725
-		switch($type)
725
+		switch ($type)
726 726
 		{
727 727
 			case 'forced':
728 728
 				$where['preference_owner'] = self::FORCED_ID;
@@ -737,10 +737,10 @@  discard block
 block discarded – undo
737 737
 				$where[] = 'preference_owner < '.self::DEFAULT_ID;
738 738
 				break;
739 739
 		}
740
-		foreach($db->select(self::TABLE, '*', $where, __LINE__, __FILE__) as $row)
740
+		foreach ($db->select(self::TABLE, '*', $where, __LINE__, __FILE__) as $row)
741 741
 		{
742 742
 			$prefs = self::unserialize($row['preference_value']);
743
-			if (!is_array($prefs)) $prefs = array();	// would stall update otherwise
743
+			if (!is_array($prefs)) $prefs = array(); // would stall update otherwise
744 744
 
745 745
 			if ($name[0] == '/' && substr($name, -1) == '/')
746 746
 			{
@@ -755,7 +755,7 @@  discard block
 block discarded – undo
755 755
 			}
756 756
 
757 757
 			$updated = false;
758
-			foreach($attrs as $attr)
758
+			foreach ($attrs as $attr)
759 759
 			{
760 760
 				if (isset($old_value) && $prefs[$attr] != $old_value) continue;
761 761
 
@@ -784,7 +784,7 @@  discard block
 block discarded – undo
784 784
 
785 785
 				// update instance-wide cache
786 786
 				$cached = Cache::getInstance(__CLASS__, $row['preference_owner']);
787
-				if($cached && $cached[$row['preference_app']])
787
+				if ($cached && $cached[$row['preference_app']])
788 788
 				{
789 789
 					$cached[$row['preference_app']] = $prefs;
790 790
 					Cache::setInstance(__CLASS__, $row['preference_owner'], $cached);
@@ -800,7 +800,7 @@  discard block
 block discarded – undo
800 800
 	 * @param string $name Preference name
801 801
 	 * @param string $type ='user' of preference to set: forced, default, user
802 802
 	 */
803
-	public static function delete_preference($app, $name, $type='user')
803
+	public static function delete_preference($app, $name, $type = 'user')
804 804
 	{
805 805
 		self::change_preference($app, $name, null, null, $type);
806 806
 	}
@@ -812,12 +812,12 @@  discard block
 block discarded – undo
812 812
 	 * @param string $to_app
813 813
 	 * @param array $names =null array of names to copy or null for all
814 814
 	 */
815
-	public static function copy_preferences($from_app, $to_app, array $names=null)
815
+	public static function copy_preferences($from_app, $to_app, array $names = null)
816 816
 	{
817 817
 		//error_log(__METHOD__."('$from_app', '$to_app', ".array2string($names).')');
818 818
 		$db = isset($GLOBALS['egw_setup']->db) ? $GLOBALS['egw_setup']->db : $GLOBALS['egw']->db;
819 819
 
820
-		foreach($db->select(self::TABLE, '*', array('preference_app' => $from_app), __LINE__, __FILE__) as $row)
820
+		foreach ($db->select(self::TABLE, '*', array('preference_app' => $from_app), __LINE__, __FILE__) as $row)
821 821
 		{
822 822
 			$prefs = self::unserialize($row['preference_value']);
823 823
 
@@ -825,7 +825,7 @@  discard block
 block discarded – undo
825 825
 			{
826 826
 				$prefs = array_intersect_key($prefs, array_flip($names));
827 827
 			}
828
-			if (!$prefs) continue;	// nothing to change, as nothing set
828
+			if (!$prefs) continue; // nothing to change, as nothing set
829 829
 
830 830
 			$row['preference_app'] = $to_app;
831 831
 			unset($row['preference_value']);
@@ -859,11 +859,11 @@  discard block
 block discarded – undo
859 859
 	 * @param boolean $invalid_cache =true should we invalidate the cache, default true (not used anymore)
860 860
 	 * @return array with new effective prefs (even when forced or default prefs are deleted!)
861 861
 	 */
862
-	function save_repository($update_session_info = False,$type='user',$invalid_cache=true)
862
+	function save_repository($update_session_info = False, $type = 'user', $invalid_cache = true)
863 863
 	{
864
-		unset($update_session_info, $invalid_cache);	// no longer used
864
+		unset($update_session_info, $invalid_cache); // no longer used
865 865
 
866
-		switch($type)
866
+		switch ($type)
867 867
 		{
868 868
 			case 'forced':
869 869
 				$account_id = self::FORCED_ID;
@@ -878,17 +878,17 @@  discard block
 block discarded – undo
878 878
 
879 879
 			default:
880 880
 				$account_id = (int)$this->account_id;
881
-				$prefs = &$this->user;	// we use the user-array as data contains default values too
881
+				$prefs = &$this->user; // we use the user-array as data contains default values too
882 882
 				break;
883 883
 		}
884 884
 		//echo "<p>preferences::save_repository(,$type): account_id=$account_id, prefs="; print_r($prefs); echo "</p>\n";
885 885
 
886
-		if (isset($GLOBALS['egw_setup']) || !$GLOBALS['egw']->acl->check('session_only_preferences',1,'preferences') &&
886
+		if (isset($GLOBALS['egw_setup']) || !$GLOBALS['egw']->acl->check('session_only_preferences', 1, 'preferences') &&
887 887
 			(!($old_prefs = $this->cache_read($account_id)) || $old_prefs != $prefs))
888 888
 		{
889 889
 			//error_log(__METHOD__."(type=$type) saved, because old_prefs[$account_id] != prefs=".array2string($prefs));
890 890
 			$changed = 0;
891
-			foreach($prefs as $app => $value)
891
+			foreach ($prefs as $app => $value)
892 892
 			{
893 893
 				// check if app preferences have changed, if not no need to save them
894 894
 				if ($old_prefs && $old_prefs[$app] == $value) continue;
@@ -905,12 +905,12 @@  discard block
 block discarded – undo
905 905
 				}
906 906
 				else
907 907
 				{
908
-					$this->db->insert($this->table,array(
908
+					$this->db->insert($this->table, array(
909 909
 						'preference_value' => json_encode($value),
910
-					),array(
910
+					), array(
911 911
 						'preference_owner' => $account_id,
912 912
 						'preference_app'   => $app,
913
-					),__LINE__,__FILE__);
913
+					), __LINE__, __FILE__);
914 914
 				}
915 915
 			}
916 916
 			if ($changed)
@@ -937,21 +937,21 @@  discard block
 block discarded – undo
937 937
 	 * @param int $account_id as determined in and/or passed to "create_email_preferences"
938 938
 	 * @return string with email-address
939 939
 	 */
940
-	function email_address($account_id='')
940
+	function email_address($account_id = '')
941 941
 	{
942 942
 		if (isset($this->data['email']['address']))
943 943
 		{
944 944
 			return $this->data['email']['address'];
945 945
 		}
946 946
 		// if email-address is set in the account, return it
947
-		if (($email = Accounts::id2name($account_id,'account_email')))
947
+		if (($email = Accounts::id2name($account_id, 'account_email')))
948 948
 		{
949 949
 			return $email;
950 950
 		}
951 951
 		$prefs_email_address = Accounts::id2name($account_id);
952
-		if ($prefs_email_address && strpos($prefs_email_address,'@') === False)
952
+		if ($prefs_email_address && strpos($prefs_email_address, '@') === False)
953 953
 		{
954
-			$prefs_email_address .= '@' . $GLOBALS['egw_info']['server']['mail_suffix'];
954
+			$prefs_email_address .= '@'.$GLOBALS['egw_info']['server']['mail_suffix'];
955 955
 		}
956 956
 		return $prefs_email_address;
957 957
 	}
@@ -965,7 +965,7 @@  discard block
 block discarded – undo
965 965
 	 * @param $charset =null default system charset
966 966
 	 * @return string the local (or best estimate) set
967 967
 	 */
968
-	static function setlocale($category=LC_MESSAGES,$charset=null)
968
+	static function setlocale($category = LC_MESSAGES, $charset = null)
969 969
 	{
970 970
 		$lang = $GLOBALS['egw_info']['user']['preferences']['common']['lang'];
971 971
 		$country = $GLOBALS['egw_info']['user']['preferences']['common']['country'];
@@ -976,12 +976,12 @@  discard block
 block discarded – undo
976 976
 		}
977 977
 		else
978 978
 		{
979
-			list($lang,$lang2) = explode('-',$lang);
979
+			list($lang, $lang2) = explode('-', $lang);
980 980
 			$country_from_lang = strtoupper($lang2);
981 981
 		}
982 982
 		if (is_null($charset)) $charset = Translation::charset();
983 983
 
984
-		foreach(array(
984
+		foreach (array(
985 985
 			$lang.'_'.$country,
986 986
 			$lang.'_'.$country_from_lang,
987 987
 			$lang.'_'.$country.'.utf8',
@@ -991,14 +991,14 @@  discard block
 block discarded – undo
991 991
 			'C',
992 992
 		) as $local)
993 993
 		{
994
-			if (($ret = setlocale($category,$local.'@'.$charset)) ||
995
-				($ret = setlocale($category,$local)))
994
+			if (($ret = setlocale($category, $local.'@'.$charset)) ||
995
+				($ret = setlocale($category, $local)))
996 996
 			{
997 997
 				//error_log(__METHOD__."($category,$charset) lang=$lang, country=$country, country_from_lang=$country_from_lang: returning '$ret'");
998 998
 				return $ret;
999 999
 			}
1000 1000
 		}
1001 1001
 		error_log(__METHOD__."($category,$charset) lang=$lang, country=$country, country_from_lang=$country_from_lang: Could not set local!");
1002
-		return false;	// should not happen, as the 'C' local should at least be available everywhere
1002
+		return false; // should not happen, as the 'C' local should at least be available everywhere
1003 1003
 	}
1004 1004
 }
Please login to merge, or discard this patch.