Completed
Push — 16.1 ( e6fac0...4b5176 )
by Ralf
30:23 queued 15:56
created
preferences/inc/class.preferences_settings.inc.php 1 patch
Spacing   +56 added lines, -57 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 	 * @param array $content =null
46 46
 	 * @param string $msg =''
47 47
 	 */
48
-	function index(array $content=null, $msg='')
48
+	function index(array $content = null, $msg = '')
49 49
 	{
50 50
 		$tpl = new Etemplate('preferences.settings');
51 51
 		if (!is_array($content))
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
 			{
71 71
 				list($button) = each($content['button']);
72 72
 				$appname = $content['old_appname'] ? $content['old_appname'] : 'common';
73
-				switch($button)
73
+				switch ($button)
74 74
 				{
75 75
 					case 'save':
76 76
 					case 'apply':
@@ -79,10 +79,10 @@  discard block
 block discarded – undo
79 79
 						{
80 80
 							throw new Api\Exception\NoPermission\Admin;
81 81
 						}
82
-						list($type,$account_id) = explode(':', $content['old_type']);
82
+						list($type, $account_id) = explode(':', $content['old_type']);
83 83
 						// merge prefs of all tabs together again
84 84
 						$prefs = array();
85
-						foreach($content as $name => $val)
85
+						foreach ($content as $name => $val)
86 86
 						{
87 87
 							if (is_array($val) && strpos($name, 'tab') === 0)
88 88
 							{
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 						$old_values = array_intersect_key($GLOBALS['egw_info']['user']['preferences']['common'], array_flip($require_reload));
101 101
 
102 102
 						$attribute = $type == 'group' ? 'user' : $type;
103
-						if (!($msg=$this->process_array($GLOBALS['egw']->preferences->$attribute, $prefs, $content['types'], $appname, $attribute)))
103
+						if (!($msg = $this->process_array($GLOBALS['egw']->preferences->$attribute, $prefs, $content['types'], $appname, $attribute)))
104 104
 						{
105 105
 							$msg_type = 'success';
106 106
 							$msg = lang('Preferences saved.');
@@ -124,14 +124,14 @@  discard block
 block discarded – undo
124 124
 						// update client-side Api\Preferences in response
125 125
 						Framework::ajax_get_preference($appname);
126 126
 				}
127
-				if (in_array($button, array('save','cancel')))
127
+				if (in_array($button, array('save', 'cancel')))
128 128
 				{
129 129
 					Api\Json\Response::get()->call('egw.message', $msg, $msg_type);
130 130
 					Framework::window_close();
131 131
 				}
132 132
 			}
133 133
 			$appname = $content['appname'] ? $content['appname'] : 'common';
134
-			list($type,$account_id) = explode(':', $content['type']);
134
+			list($type, $account_id) = explode(':', $content['type']);
135 135
 			//_debug_array($prefs);
136 136
 		}
137 137
 		if ($account_id && $account_id != $GLOBALS['egw']->preferences->get_account_id())
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 		$preserve['current_app'] = $content['current_app'];
151 151
 		$GLOBALS['egw_info']['flags']['currentapp'] = $content['current_app'] == 'common' ?
152 152
 			'preferences' : $content['current_app'];
153
-		Framework::includeCSS('preferences','app');
153
+		Framework::includeCSS('preferences', 'app');
154 154
 
155 155
 		// if not just saved, call validation before, to be able to show failed validation of current prefs
156 156
 		if (!isset($button))
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
 	 * @param boolean $only_verify =false
183 183
 	 * @return string with verification error or null on success
184 184
 	 */
185
-	function process_array(array &$repository, array $values, array $types, $appname, $type, $only_verify=false)
185
+	function process_array(array &$repository, array $values, array $types, $appname, $type, $only_verify = false)
186 186
 	{
187 187
 		//fetch application specific settings from a hook
188 188
 		$settings = Api\Hooks::single(array(
@@ -195,10 +195,10 @@  discard block
 block discarded – undo
195 195
 
196 196
 		unset($prefs['']);
197 197
 		//_debug_array($values);exit;
198
-		foreach($values as $var => $value)
198
+		foreach ($values as $var => $value)
199 199
 		{
200 200
 			// type specific validation
201
-			switch((string)$types[$var])
201
+			switch ((string)$types[$var])
202 202
 			{
203 203
 				case 'password':	// dont write empty password-fields
204 204
 					if (empty($value)) continue 2;
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
 						// empty is always allowed
212 212
 
213 213
 						// If forced, empty == not set
214
-						if($type == 'forced')
214
+						if ($type == 'forced')
215 215
 						{
216 216
 							unset($prefs[$var]);
217 217
 							// need to call preferences::delete, to also set affective prefs!
@@ -223,19 +223,19 @@  discard block
 block discarded – undo
223 223
 					{
224 224
 						if ($value[0] != '/' || !Vfs::stat($value) || Vfs::is_dir($value))
225 225
 						{
226
-							$error = lang('%1 is no existing vfs file!',htmlspecialchars($value));
226
+							$error = lang('%1 is no existing vfs file!', htmlspecialchars($value));
227 227
 						}
228 228
 					}
229 229
 					else
230 230
 					{
231 231
 						// split multiple comma or whitespace separated directories
232 232
 						// to still allow space or comma in dirnames, we also use the trailing slash of all pathes to split
233
-						foreach($types[$var] == 'vfs_dir' ? array($value) : preg_split('/[,\s]+\//', $value) as $n => $dir)
233
+						foreach ($types[$var] == 'vfs_dir' ? array($value) : preg_split('/[,\s]+\//', $value) as $n => $dir)
234 234
 						{
235
-							if ($n) $dir = '/'.$dir;	// re-adding trailing slash removed by split
235
+							if ($n) $dir = '/'.$dir; // re-adding trailing slash removed by split
236 236
 							if ($dir[0] != '/' || !Vfs::stat($dir) || !Vfs::is_dir($dir))
237 237
 							{
238
-								$error .= ($error ? ' ' : '').lang('%1 is no existing vfs directory!',$dir);
238
+								$error .= ($error ? ' ' : '').lang('%1 is no existing vfs directory!', $dir);
239 239
 							}
240 240
 						}
241 241
 					}
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
 
250 250
 			if (isset($value) && $value !== '' && $value !== '**NULL**' && $value !== array())
251 251
 			{
252
-				if (is_array($value) && !$settings[$var]['no_sel_options']) $value = implode(',',$value);	// multiselect
252
+				if (is_array($value) && !$settings[$var]['no_sel_options']) $value = implode(',', $value); // multiselect
253 253
 
254 254
 				$prefs[$var] = $value;
255 255
 
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
 		// if you return something else than False, it is treated as an error-msg and
270 270
 		// displayed to the user (the prefs are not saved)
271 271
 		//
272
-		if(($error .= Api\Hooks::single(array(
272
+		if (($error .= Api\Hooks::single(array(
273 273
 				'location' => 'verify_settings',
274 274
 				'prefs'    => &$repository[$appname],
275 275
 				'type'     => $type,
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
 			return $error;
282 282
 		}
283 283
 
284
-		if (!$only_verify) $GLOBALS['egw']->preferences->save_repository(True,$type);
284
+		if (!$only_verify) $GLOBALS['egw']->preferences->save_repository(True, $type);
285 285
 
286 286
 		// certain common prefs (language, template, ...) require the session to be re-created
287 287
 		if ($appname == 'common' && !$only_verify)
@@ -317,19 +317,19 @@  discard block
 block discarded – undo
317 317
 		$sel_options = $readonlys = $content = $tabs = array();
318 318
 		// disable all but first tab and name current tab "tab1", for apps not using sections
319 319
 		$tab = 'tab1';
320
-		foreach($this->settings as $setting)
320
+		foreach ($this->settings as $setting)
321 321
 		{
322 322
 			if (!is_array($setting)) continue;
323 323
 			if ($type != 'forced' && (string)$GLOBALS['egw']->preferences->forced[$appname][$setting['name']] !== '')
324 324
 			{
325
-				continue;	// forced preferences are not displayed, unless we edit them
325
+				continue; // forced preferences are not displayed, unless we edit them
326 326
 			}
327 327
 			$types[$setting['name']] = $old_type = $setting['type'];
328 328
 
329
-			switch($old_type)
329
+			switch ($old_type)
330 330
 			{
331 331
 				case 'section':
332
-					$tab = 'tab'.(1+count($tabs));
332
+					$tab = 'tab'.(1 + count($tabs));
333 333
 					$tabs[] = array(
334 334
 						'id' => $tab,
335 335
 						'template' => 'preferences.settings.tab1',
@@ -344,24 +344,24 @@  discard block
 block discarded – undo
344 344
 					if (is_array($setting['values'])) $vars += $setting['values'];
345 345
 					$GLOBALS['egw']->preferences->{$attribute}[$appname][$setting['name']] =
346 346
 						$GLOBALS['egw']->preferences->lang_notify($GLOBALS['egw']->preferences->{$attribute}[$appname][$setting['name']], $vars);
347
-					$types[$setting['name']] = $vars;	// store vars for re-translation, instead type "notify"
347
+					$types[$setting['name']] = $vars; // store vars for re-translation, instead type "notify"
348 348
 					if ($setting['help'] && ($setting['run_lang'] || !isset($setting['run_lang'])))
349 349
 					{
350 350
 						$setting['help'] = lang($setting['help']);
351 351
 					}
352 352
 					$setting['help'] .= '<p><b>'.lang('Substitutions and their meanings:').'</b>';
353
-					foreach($vars as $var => $var_help)
353
+					foreach ($vars as $var => $var_help)
354 354
 					{
355 355
 						$lname = ($lname = lang($var)) == $var.'*' ? $var : $lname;
356 356
 						$setting['help'] .= "<br>\n".'<b>$$'.$lname.'$$</b>: '.$var_help;
357 357
 					}
358 358
 					$setting['help'] .= "</p>\n";
359
-					$setting['run_lang'] = false;	// already done now
359
+					$setting['run_lang'] = false; // already done now
360 360
 					// handle as textarea
361 361
 				case 'textarea':
362 362
 					$setting['type'] = is_a($tpl, 'etemplate') ? 'textarea' : 'textbox';
363 363
 					$tpl->setElementAttribute($tab.'['.$setting['name'].']', 'multiline', 'true');
364
-					$tpl->setElementAttribute($tab. '[' . $setting['name'] . ']','width', '99%' );
364
+					$tpl->setElementAttribute($tab.'['.$setting['name'].']', 'width', '99%');
365 365
 					// anyway setting via css: width: 99%, height: 5em
366 366
 					// for old eT use size attribute
367 367
 					if (is_a($tpl, 'etemplate') && (!empty($setting['cols']) || !empty($setting['rows'])))
@@ -383,7 +383,7 @@  discard block
 block discarded – undo
383 383
 				case 'multiselect':
384 384
 					$setting['type'] = 'select';
385 385
 					$tpl->setElementAttribute($tab.'['.$setting['name'].']', 'rows', 5);
386
-					if (!isset($setting['size'])) $setting['size'] = '5';	// old eT
386
+					if (!isset($setting['size'])) $setting['size'] = '5'; // old eT
387 387
 					break;
388 388
 				case 'color':
389 389
 					$setting['type'] = 'colorpicker';
@@ -391,7 +391,7 @@  discard block
 block discarded – undo
391 391
 				case 'date-duration':
392 392
 					if (!isset($setting['size'])) $setting['size'] = 'm,dhm,24,1';
393 393
 					$attrs = explode(',', $setting['size']);
394
-					foreach(array("data_format","display_format", "hours_per_day", "empty_not_0", "short_labels") as $n => $name)
394
+					foreach (array("data_format", "display_format", "hours_per_day", "empty_not_0", "short_labels") as $n => $name)
395 395
 					{
396 396
 						if ((string)$attrs[$n] !== '') $tpl->setElementAttribute($tab.'['.$setting['name'].']', $name, $attrs[$n]);
397 397
 					}
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
 				case 'taglist':
400 400
 					if ($setting['no_sel_options'])
401 401
 					{
402
-						$tpl->setElementAttribute ($tab.'['.$setting['name'].']', 'autocomplete_url', '');
402
+						$tpl->setElementAttribute($tab.'['.$setting['name'].']', 'autocomplete_url', '');
403 403
 					}
404 404
 					break;
405 405
 			}
@@ -408,17 +408,17 @@  discard block
 block discarded – undo
408 408
 			{
409 409
 				if ($old_type != 'multiselect' && $old_type != 'notify')
410 410
 				{
411
-					switch($type)
411
+					switch ($type)
412 412
 					{
413 413
 						case 'user':
414
-							$setting['values'] = array('' => lang('Use default'))+$setting['values'];
414
+							$setting['values'] = array('' => lang('Use default')) + $setting['values'];
415 415
 							break;
416 416
 						case 'default':
417 417
 						case 'group':
418
-							$setting['values'] = array('' => lang('No default'))+$setting['values'];
418
+							$setting['values'] = array('' => lang('No default')) + $setting['values'];
419 419
 							break;
420 420
 						case 'forced';
421
-							$setting['values'] = array('**NULL**' => lang('Users choice'))+$setting['values'];
421
+							$setting['values'] = array('**NULL**' => lang('Users choice')) + $setting['values'];
422 422
 							break;
423 423
 					}
424 424
 				}
@@ -427,8 +427,7 @@  discard block
 block discarded – undo
427 427
 			if ($type == 'user')
428 428
 			{
429 429
 				$default = $GLOBALS['egw']->preferences->group[$appname][$setting['name']] ?
430
-					$GLOBALS['egw']->preferences->group[$appname][$setting['name']] :
431
-					$GLOBALS['egw']->preferences->default[$appname][$setting['name']];
430
+					$GLOBALS['egw']->preferences->group[$appname][$setting['name']] : $GLOBALS['egw']->preferences->default[$appname][$setting['name']];
432 431
 
433 432
 				// replace default value(s) for selectboxes with selectbox labels
434 433
 				if (isset($setting['values']) && is_array($setting['values']))
@@ -448,7 +447,7 @@  discard block
 block discarded – undo
448 447
 				'name' => $setting['name'],
449 448
 				'type' => $setting['type'],
450 449
 				'label' => preg_replace('|<br[ /]*>|i', "\n", $setting['label']),
451
-				'help' => lang($setting['help']),	// is html
450
+				'help' => lang($setting['help']), // is html
452 451
 				'default' => (string)$default !== '' ? lang('Default').': '.$default : null,
453 452
 				'onchange' => $setting['onchange'],
454 453
 			);
@@ -473,7 +472,7 @@  discard block
 block discarded – undo
473 472
 
474 473
 		$content['appname'] = $appname;
475 474
 		$sel_options['appname'] = array();
476
-		foreach(Api\Hooks::implemented('settings') as $app)
475
+		foreach (Api\Hooks::implemented('settings') as $app)
477 476
 		{
478 477
 			if ($app != 'preferences' && $GLOBALS['egw_info']['user']['apps'][$app])
479 478
 			{
@@ -499,7 +498,7 @@  discard block
 block discarded – undo
499 498
 				$user_apps = $GLOBALS['egw']->acl->get_user_applications($id);
500 499
 				$sel_options['appname'] = array_intersect_key($sel_options['appname'], $user_apps);
501 500
 			}
502
-			foreach($GLOBALS['egw']->accounts->search(array('type' => 'groups', 'order' => 'account_lid')) as $account_id => $group)
501
+			foreach ($GLOBALS['egw']->accounts->search(array('type' => 'groups', 'order' => 'account_lid')) as $account_id => $group)
503 502
 			{
504 503
 				$sel_options['type']['group:'.$account_id] = lang('Preferences').' '.Api\Accounts::format_username($group['account_lid'], '', '', $account_id);
505 504
 			}
@@ -522,7 +521,7 @@  discard block
 block discarded – undo
522 521
 	 * @param boolean $lang =true
523 522
 	 * @return string comma-separated and translated labels
524 523
 	 */
525
-	protected static function get_default_label($default, array $values, $lang=true)
524
+	protected static function get_default_label($default, array $values, $lang = true)
526 525
 	{
527 526
 		// explode comma-separated multiple default values
528 527
 		if (!is_array($default) && !isset($values[$default]) && strpos($default, ',') !== false)
@@ -533,7 +532,7 @@  discard block
 block discarded – undo
533 532
 		{
534 533
 			$labels = (array)$default;
535 534
 		}
536
-		foreach($labels as &$def)
535
+		foreach ($labels as &$def)
537 536
 		{
538 537
 			if (isset($values[$def]))
539 538
 			{
@@ -541,7 +540,7 @@  discard block
 block discarded – undo
541 540
 			}
542 541
 			else	// value could be in an optgroup
543 542
 			{
544
-				foreach($values as $value)
543
+				foreach ($values as $value)
545 544
 				{
546 545
 					if (is_array($value) && !isset($value['label']) && isset($value[$def]))
547 546
 					{
@@ -567,16 +566,16 @@  discard block
 block discarded – undo
567 566
 	 * @param int|string $account_id =null account_id for user or group prefs, or "forced" or "default"
568 567
 	 * @return boolean
569 568
 	 */
570
-	protected function call_hook($appname, $type='user', $account_id=null)
569
+	protected function call_hook($appname, $type = 'user', $account_id = null)
571 570
 	{
572 571
 		$this->appname = $appname == 'common' ? 'preferences' : $appname;
573 572
 
574 573
 		// Set framework here to make sure we get the right settings for user's [newly] selected template
575 574
 		$GLOBALS['egw_info']['server']['template_set'] = $GLOBALS['egw']->preferences->data['common']['template_set'];
576 575
 		Api\Translation::add_app($this->appname);
577
-		if($this->appname != 'preferences')
576
+		if ($this->appname != 'preferences')
578 577
 		{
579
-			Api\Translation::add_app('preferences');	// we need the prefs translations too
578
+			Api\Translation::add_app('preferences'); // we need the prefs translations too
580 579
 		}
581 580
 
582 581
 		// make type available, to hooks from Egw\Applications can use it, eg. activesync
@@ -585,7 +584,7 @@  discard block
 block discarded – undo
585 584
 			'type' => $type,
586 585
 			'account_id' => $account_id,
587 586
 		);
588
-		$GLOBALS['type'] = $type;	// old global variable
587
+		$GLOBALS['type'] = $type; // old global variable
589 588
 
590 589
 		// calling app specific settings hook
591 590
 		$settings = Api\Hooks::single($hook_data, $this->appname);
@@ -594,30 +593,30 @@  discard block
 block discarded – undo
594 593
 		{
595 594
 			$this->settings = array_merge($this->settings, $settings);
596 595
 		}
597
-		elseif(isset($GLOBALS['settings']) && is_array($GLOBALS['settings']) && $GLOBALS['settings'])
596
+		elseif (isset($GLOBALS['settings']) && is_array($GLOBALS['settings']) && $GLOBALS['settings'])
598 597
 		{
599 598
 			$this->settings = array_merge($this->settings, $GLOBALS['settings']);
600 599
 		}
601 600
 		else
602 601
 		{
603
-			return False;	// no settings returned
602
+			return False; // no settings returned
604 603
 		}
605 604
 
606 605
 		// calling settings hook all apps can answer (for a specific app)
607 606
 		$hook_data['location'] = 'settings_'.$this->appname;
608
-		foreach(Api\Hooks::process($hook_data, $this->appname,true) as $settings)
607
+		foreach (Api\Hooks::process($hook_data, $this->appname, true) as $settings)
609 608
 		{
610 609
 			if (isset($settings) && is_array($settings) && $settings)
611 610
 			{
612
-				$this->settings = array_merge($this->settings,$settings);
611
+				$this->settings = array_merge($this->settings, $settings);
613 612
 			}
614 613
 		}
615 614
 		/* Remove ui-only settings */
616
-		if($this->xmlrpc)
615
+		if ($this->xmlrpc)
617 616
 		{
618
-			foreach($this->settings as $key => $valarray)
617
+			foreach ($this->settings as $key => $valarray)
619 618
 			{
620
-				if(!$valarray['xmlrpc'])
619
+				if (!$valarray['xmlrpc'])
621 620
 				{
622 621
 					unset($this->settings[$key]);
623 622
 				}
@@ -629,10 +628,10 @@  discard block
 block discarded – undo
629 628
 			 This is not handled by the hooks class and is only valid if not using xml-rpc.
630 629
 			*/
631 630
 			$tmpl_settings = EGW_SERVER_ROOT.$GLOBALS['egw']->framework->template_dir.'/hook_settings.inc.php';
632
-			if($this->appname == 'preferences' && file_exists($tmpl_settings))
631
+			if ($this->appname == 'preferences' && file_exists($tmpl_settings))
633 632
 			{
634 633
 				include($tmpl_settings);
635
-				$this->settings = array_merge($this->settings,$GLOBALS['settings']);
634
+				$this->settings = array_merge($this->settings, $GLOBALS['settings']);
636 635
 			}
637 636
 		}
638 637
 		// check if we have a default/forced value from the settings hook,
@@ -653,9 +652,9 @@  discard block
 block discarded – undo
653 652
 		}
654 653
 		if ($need_update)
655 654
 		{
656
-			$GLOBALS['egw']->preferences->save_repository(false,'default',true);
655
+			$GLOBALS['egw']->preferences->save_repository(false, 'default', true);
657 656
 		}
658
-		if($this->debug)
657
+		if ($this->debug)
659 658
 		{
660 659
 			_debug_array($this->settings);
661 660
 		}
Please login to merge, or discard this patch.