Completed
Push — 16.1 ( 2b6741...abc73d )
by Nathan
50:22 queued 36:36
created
addressbook/inc/class.addressbook_ui.inc.php 1 patch
Spacing   +412 added lines, -418 removed lines patch added patch discarded remove patch
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
 	 *
80 80
 	 * @param string $contact_app
81 81
 	 */
82
-	function __construct($contact_app='addressbook')
82
+	function __construct($contact_app = 'addressbook')
83 83
 	{
84 84
 		parent::__construct($contact_app);
85 85
 
@@ -92,23 +92,23 @@  discard block
 block discarded – undo
92 92
 		);
93 93
 
94 94
 		// make sure the hook for export_limit is registered
95
-		if (!Api\Hooks::exists('export_limit','addressbook')) Api\Hooks::read(true);
95
+		if (!Api\Hooks::exists('export_limit', 'addressbook')) Api\Hooks::read(true);
96 96
 
97
-		$this->config =& $GLOBALS['egw_info']['server'];
97
+		$this->config = & $GLOBALS['egw_info']['server'];
98 98
 
99 99
 		// check if a contact specific export limit is set, if yes use it also for etemplate's csv export
100
-		$this->config['export_limit'] = $this->config['contact_export_limit'] = Api\Storage\Merge::getExportLimit($app='addressbook');
100
+		$this->config['export_limit'] = $this->config['contact_export_limit'] = Api\Storage\Merge::getExportLimit($app = 'addressbook');
101 101
 
102 102
 		if ($this->config['copy_fields'] && ($fields = is_array($this->config['copy_fields']) ?
103 103
 			$this->config['copy_fields'] : unserialize($this->config['copy_fields'])))
104 104
 		{
105 105
 			// Set country code if country name is selected
106
-			$supported_fields = $this->get_fields('supported',null,0);
107
-			if(in_array('adr_one_countrycode', $supported_fields) && in_array('adr_one_countryname',$fields))
106
+			$supported_fields = $this->get_fields('supported', null, 0);
107
+			if (in_array('adr_one_countrycode', $supported_fields) && in_array('adr_one_countryname', $fields))
108 108
 			{
109 109
 				$fields[] = 'adr_one_countrycode';
110 110
 			}
111
-			if(in_array('adr_two_countrycode', $supported_fields) && in_array('adr_two_countryname',$fields))
111
+			if (in_array('adr_two_countrycode', $supported_fields) && in_array('adr_two_countryname', $fields))
112 112
 			{
113 113
 				$fields[] = 'adr_two_countrycode';
114 114
 			}
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
 	 * @param string $msg =null	message to show
125 125
 	 * @param boolean $do_email =false do an email-selection popup or the regular index-page
126 126
 	 */
127
-	function index($_content=null,$msg=null,$do_email=false)
127
+	function index($_content = null, $msg = null, $do_email = false)
128 128
 	{
129 129
 		//echo "<p>uicontacts::index(".print_r($_content,true).",'$msg')</p>\n";
130 130
 		if (($re_submit = is_array($_content)))
@@ -156,16 +156,16 @@  discard block
 block discarded – undo
156 156
 				else
157 157
 				{
158 158
 					$success = $failed = $action_msg = null;
159
-					if ($this->action($_content['nm']['action'],$_content['nm']['selected'],$_content['nm']['select_all'],
160
-						$success,$failed,$action_msg,$_content['do_email'] ? 'email' : 'index',$msg,$_content['nm']['checkboxes']))
159
+					if ($this->action($_content['nm']['action'], $_content['nm']['selected'], $_content['nm']['select_all'],
160
+						$success, $failed, $action_msg, $_content['do_email'] ? 'email' : 'index', $msg, $_content['nm']['checkboxes']))
161 161
 					{
162
-						$msg .= lang('%1 contact(s) %2',$success,$action_msg);
162
+						$msg .= lang('%1 contact(s) %2', $success, $action_msg);
163 163
 						Framework::message($msg);
164 164
 					}
165
-					elseif(is_null($msg))
165
+					elseif (is_null($msg))
166 166
 					{
167
-						$msg .= lang('%1 contact(s) %2, %3 failed because of insufficent rights !!!',$success,$action_msg,$failed);
168
-						Framework::message($msg,'error');
167
+						$msg .= lang('%1 contact(s) %2, %3 failed because of insufficent rights !!!', $success, $action_msg, $failed);
168
+						Framework::message($msg, 'error');
169 169
 					}
170 170
 					$msg = '';
171 171
 				}
@@ -185,9 +185,9 @@  discard block
 block discarded – undo
185 185
 			}
186 186
 			$typeselection = $_content['nm']['col_filter']['tid'];
187 187
 		}
188
-		elseif($_GET['add_list'])
188
+		elseif ($_GET['add_list'])
189 189
 		{
190
-			$list = $this->add_list($_GET['add_list'],$_GET['owner']?$_GET['owner']:$this->user);
190
+			$list = $this->add_list($_GET['add_list'], $_GET['owner'] ? $_GET['owner'] : $this->user);
191 191
 			if ($list === true)
192 192
 			{
193 193
 				$msg = lang('List already exists!');
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
 		);
207 207
 		$to = $_content['nm']['to'];
208 208
 		$content = array();
209
-		if($msg || $_GET['msg'])
209
+		if ($msg || $_GET['msg'])
210 210
 		{
211 211
 			Framework::message($msg ? $msg : $_GET['msg']);
212 212
 		}
@@ -215,23 +215,23 @@  discard block
 block discarded – undo
215 215
 		if (!is_array($content['nm']))
216 216
 		{
217 217
 			$content['nm'] = array(
218
-				'get_rows'       =>	'addressbook.addressbook_ui.get_rows',	// I  method/callback to request the data for the rows eg. 'notes.bo.get_rows'
219
-				'bottom_too'     => false,		// I  show the nextmatch-line (arrows, filters, search, ...) again after the rows
220
-				'never_hide'     => True,		// I  never hide the nextmatch-line if less then maxmatch entrie
221
-				'start'          =>	0,			// IO position in list
222
-				'cat_id'         =>	'',			// IO category, if not 'no_cat' => True
223
-				'search'         =>	'',			// IO search pattern
224
-				'order'          =>	'n_family',	// IO name of the column to sort after (optional for the sortheaders)
225
-				'sort'           =>	'ASC',		// IO direction of the sort: 'ASC' or 'DESC'
226
-				'col_filter'     =>	array(),	// IO array of column-name value pairs (optional for the filterheaders)
218
+				'get_rows'       =>	'addressbook.addressbook_ui.get_rows', // I  method/callback to request the data for the rows eg. 'notes.bo.get_rows'
219
+				'bottom_too'     => false, // I  show the nextmatch-line (arrows, filters, search, ...) again after the rows
220
+				'never_hide'     => True, // I  never hide the nextmatch-line if less then maxmatch entrie
221
+				'start'          =>	0, // IO position in list
222
+				'cat_id'         =>	'', // IO category, if not 'no_cat' => True
223
+				'search'         =>	'', // IO search pattern
224
+				'order'          =>	'n_family', // IO name of the column to sort after (optional for the sortheaders)
225
+				'sort'           =>	'ASC', // IO direction of the sort: 'ASC' or 'DESC'
226
+				'col_filter'     =>	array(), // IO array of column-name value pairs (optional for the filterheaders)
227 227
 				//'cat_id_label' => lang('Categories'),
228 228
 				//'filter_label' => lang('Addressbook'),	// I  label for filter    (optional)
229
-				'filter'         =>	'',	// =All	// IO filter, if not 'no_filter' => True
230
-				'filter_no_lang' => True,		// I  set no_lang for filter (=dont translate the options)
231
-				'no_filter2'     => True,		// I  disable the 2. filter (params are the same as for filter)
229
+				'filter'         =>	'', // =All	// IO filter, if not 'no_filter' => True
230
+				'filter_no_lang' => True, // I  set no_lang for filter (=dont translate the options)
231
+				'no_filter2'     => True, // I  disable the 2. filter (params are the same as for filter)
232 232
 				//'filter2_label'=>	lang('Distribution lists'),			// IO filter2, if not 'no_filter2' => True
233
-				'filter2'        =>	'',			// IO filter2, if not 'no_filter2' => True
234
-				'filter2_no_lang'=> True,		// I  set no_lang for filter2 (=dont translate the options)
233
+				'filter2'        =>	'', // IO filter2, if not 'no_filter2' => True
234
+				'filter2_no_lang'=> True, // I  set no_lang for filter2 (=dont translate the options)
235 235
 				'lettersearch'   => true,
236 236
 				'do_email'       => $do_email ? 1 : 0,
237 237
 				// using a positiv list now, as we constantly adding new columns in addressbook, but not removing them from default
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
 				/* old negative list
242 242
 				'default_cols'   => '!cat_id,contact_created_contact_modified,distribution_list,contact_id,owner,room',*/
243 243
 				'filter2_onchange' => "return app.addressbook.filter2_onchange();",
244
-				'manual'         => $do_email ? ' ' : false,	// space for the manual icon
244
+				'manual'         => $do_email ? ' ' : false, // space for the manual icon
245 245
 				//'actions'        => $this->get_actions(),		// set on each request, as it depends on some filters
246 246
 				'row_id'         => 'id',
247 247
 				'row_modified'   => 'modified',
@@ -258,13 +258,13 @@  discard block
 block discarded – undo
258 258
 			// use the state of the last session stored in the user prefs
259 259
 			if (($state = @unserialize($this->prefs[$do_email ? 'email_state' : 'index_state'])))
260 260
 			{
261
-				$content['nm'] = array_merge($content['nm'],$state);
261
+				$content['nm'] = array_merge($content['nm'], $state);
262 262
 			}
263 263
 		}
264 264
 		$sel_options['cat_id'] = array('' => lang('All categories'), '0' => lang('None'));
265 265
 
266 266
 		// Edit and delete list actions depends on permissions
267
-		if($this->get_lists(Acl::EDIT))
267
+		if ($this->get_lists(Acl::EDIT))
268 268
 		{
269 269
 			$content['nm']['placeholder_actions'][] = 'rename_list';
270 270
 			$content['nm']['placeholder_actions'][] = 'delete_list';
@@ -277,11 +277,11 @@  discard block
 block discarded – undo
277 277
 		if (isset($typeselection)) $content['nm']['col_filter']['tid'] = $typeselection;
278 278
 		// save the tid for use in creating new addressbook entrys via UI. Current tid is to be used as type of new entrys
279 279
 		//error_log(__METHOD__.__LINE__.' '.$content['nm']['col_filter']['tid']);
280
-		Api\Cache::setSession('addressbook','active_tid',$content['nm']['col_filter']['tid']);
280
+		Api\Cache::setSession('addressbook', 'active_tid', $content['nm']['col_filter']['tid']);
281 281
 		if ($this->lists_available())
282 282
 		{
283
-			$sel_options['filter2'] = $this->get_lists(Acl::READ,array('' => lang('No distribution list')));
284
-			$sel_options['filter2']['add'] = lang('Add a new list').'...';	// put it at the end
283
+			$sel_options['filter2'] = $this->get_lists(Acl::READ, array('' => lang('No distribution list')));
284
+			$sel_options['filter2']['add'] = lang('Add a new list').'...'; // put it at the end
285 285
 		}
286 286
 		if ($do_email)
287 287
 		{
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
 			$content['nm']['header_left'] = 'addressbook.email.left';
300 300
 		}
301 301
 		// Organisation stuff is not (yet) availible with ldap
302
-		elseif($GLOBALS['egw_info']['server']['contact_repository'] != 'ldap')
302
+		elseif ($GLOBALS['egw_info']['server']['contact_repository'] != 'ldap')
303 303
 		{
304 304
 			$content['nm']['header_left'] = 'addressbook.index.left';
305 305
 		}
@@ -312,12 +312,12 @@  discard block
 block discarded – undo
312 312
 		$sel_options['adr_one_countrycode']['-custom-'] = lang('No country selected');
313 313
 
314 314
 		// if there is any export limit set, pass it on to the nextmatch, to be evaluated by the export
315
-		if (isset($this->config['contact_export_limit']) && (int)$this->config['contact_export_limit']) $content['nm']['export_limit']=$this->config['contact_export_limit'];
315
+		if (isset($this->config['contact_export_limit']) && (int)$this->config['contact_export_limit']) $content['nm']['export_limit'] = $this->config['contact_export_limit'];
316 316
 
317 317
 		// dont show tid-selection if we have only one content_type
318 318
 		// be a bit more sophisticated about it
319 319
 		$availabletypes = array_keys($this->content_types);
320
-		if ($content['nm']['col_filter']['tid'] && !in_array($content['nm']['col_filter']['tid'],$availabletypes))
320
+		if ($content['nm']['col_filter']['tid'] && !in_array($content['nm']['col_filter']['tid'], $availabletypes))
321 321
 		{
322 322
 			//_debug_array(array('Typefilter:'=> $content['nm']['col_filter']['tid'],'Available Types:'=>$availabletypes,'action:'=>'remove invalid filter'));
323 323
 			unset($content['nm']['col_filter']['tid']);
@@ -325,7 +325,7 @@  discard block
 block discarded – undo
325 325
 		if (!isset($content['nm']['col_filter']['tid'])) $content['nm']['col_filter']['tid'] = $availabletypes[0];
326 326
 		if (count($this->content_types) > 1)
327 327
 		{
328
-			foreach($this->content_types as $tid => $data)
328
+			foreach ($this->content_types as $tid => $data)
329 329
 			{
330 330
 				$sel_options['tid'][$tid] = $data['name'];
331 331
 			}
@@ -343,22 +343,22 @@  discard block
 block discarded – undo
343 343
 
344 344
 		$content['nm']['actions'] = $this->get_actions($content['nm']['col_filter']['tid'], $content['nm']['org_view']);
345 345
 
346
-		if (!isset($sel_options['org_view'][(string) $content['nm']['org_view']]))
346
+		if (!isset($sel_options['org_view'][(string)$content['nm']['org_view']]))
347 347
 		{
348 348
 			$sel_options['org_view'] += $this->_get_org_name((string)$content['nm']['org_view']);
349 349
 		}
350 350
 		// unset the filters regarding organisations, when there is no organisation selected
351
-		if (empty($sel_options['org_view'][(string) $content['nm']['org_view']]) || stripos($org_view,":") === false )
351
+		if (empty($sel_options['org_view'][(string)$content['nm']['org_view']]) || stripos($org_view, ":") === false)
352 352
 		{
353 353
 			unset($content['nm']['col_filter']['org_name']);
354 354
 			unset($content['nm']['col_filter']['org_unit']);
355 355
 			unset($content['nm']['col_filter']['adr_one_locality']);
356 356
 		}
357
-		$content['nm']['org_view_label'] = $sel_options['org_view'][(string) $content['nm']['org_view']];
357
+		$content['nm']['org_view_label'] = $sel_options['org_view'][(string)$content['nm']['org_view']];
358 358
 
359 359
 		$this->tmpl->read($do_email ? 'addressbook.email' : 'addressbook.index');
360 360
 		return $this->tmpl->exec($do_email ? 'addressbook.addressbook_ui.emailpopup' : 'addressbook.addressbook_ui.index',
361
-			$content,$sel_options,array(),$preserv,$do_email ? 2 : 0);
361
+			$content, $sel_options, array(), $preserv, $do_email ? 2 : 0);
362 362
 	}
363 363
 
364 364
 	/**
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
 	 * @param string $tid_filter =null
368 368
 	 * @return array see Etemplate\Widget\Nextmatch::get_actions()
369 369
 	 */
370
-	public function get_actions($tid_filter=null)
370
+	public function get_actions($tid_filter = null)
371 371
 	{
372 372
 		// Contact view
373 373
 		$actions = array(
@@ -375,7 +375,7 @@  discard block
 block discarded – undo
375 375
 				'caption' => 'CRM-View',
376 376
 				'default' => $GLOBALS['egw_info']['user']['preferences']['addressbook']['crm_list'] != '~edit~',
377 377
 				'allowOnMultiple' => false,
378
-				'group' => $group=1,
378
+				'group' => $group = 1,
379 379
 				'onExecute' => 'javaScript:app.addressbook.view',
380 380
 				'disableClass' => 'contact_organisation',
381 381
 				'hideOnDisabled' => true,
@@ -418,14 +418,14 @@  discard block
 block discarded – undo
418 418
 		);
419 419
 		// CRM view options
420 420
 		$crm_count = 0;
421
-		$crm_apps = array('infolog','tracker');
422
-		foreach($crm_apps as $app)
421
+		$crm_apps = array('infolog', 'tracker');
422
+		foreach ($crm_apps as $app)
423 423
 		{
424 424
 			if ($GLOBALS['egw_info']['user']['apps'][$app]) $crm_count++;
425 425
 		}
426
-		if($crm_count > 1)
426
+		if ($crm_count > 1)
427 427
 		{
428
-			foreach($crm_apps as $app)
428
+			foreach ($crm_apps as $app)
429 429
 			{
430 430
 				$actions['view']['children']["view-$app"] = array(
431 431
 					'caption' => $app,
@@ -440,7 +440,7 @@  discard block
 block discarded – undo
440 440
 				'caption' => 'View',
441 441
 				'default' => true,
442 442
 				'allowOnMultiple' => false,
443
-				'group' => $group=1,
443
+				'group' => $group = 1,
444 444
 				'disableClass' => 'contact_contact',
445 445
 				'hideOnDisabled' => true
446 446
 			),
@@ -455,23 +455,23 @@  discard block
 block discarded – undo
455 455
 			),
456 456
 		);
457 457
 
458
-		++$group;	// other AB related stuff group: lists, AB's, categories
458
+		++$group; // other AB related stuff group: lists, AB's, categories
459 459
 		// categories submenu
460 460
 		$actions['cat'] = array(
461 461
 			'caption' => 'Categories',
462 462
 			'group' => $group,
463 463
 			'children' => array(
464 464
 				'cat_add' => Etemplate\Widget\Nextmatch::category_action(
465
-					'addressbook',$group,'Add category', 'cat_add_',
466
-					true, 0,Etemplate\Widget\Nextmatch::DEFAULT_MAX_MENU_LENGTH,false
467
-				)+array(
465
+					'addressbook', $group, 'Add category', 'cat_add_',
466
+					true, 0, Etemplate\Widget\Nextmatch::DEFAULT_MAX_MENU_LENGTH, false
467
+				) + array(
468 468
 					'icon' => 'foldertree_nolines_plus',
469 469
 					'disableClass' => 'rowNoEdit',
470 470
 				),
471 471
 				'cat_del' => Etemplate\Widget\Nextmatch::category_action(
472
-					'addressbook',$group,'Delete category', 'cat_del_',
473
-					true, 0,Etemplate\Widget\Nextmatch::DEFAULT_MAX_MENU_LENGTH,false
474
-				)+array(
472
+					'addressbook', $group, 'Delete category', 'cat_del_',
473
+					true, 0, Etemplate\Widget\Nextmatch::DEFAULT_MAX_MENU_LENGTH, false
474
+				) + array(
475 475
 					'icon' => 'foldertree_nolines_minus',
476 476
 					'disableClass' => 'rowNoEdit',
477 477
 				),
@@ -498,7 +498,7 @@  discard block
 block discarded – undo
498 498
 					'children' => $add_lists,
499 499
 					'prefix' => 'to_list_',
500 500
 					'icon' => 'foldertree_nolines_plus',
501
-					'enabled' => ($add_lists?true:false), // if there are editable lists, allow to add a contact to one of them,
501
+					'enabled' => ($add_lists ? true : false), // if there are editable lists, allow to add a contact to one of them,
502 502
 					//'disableClass' => 'rowNoEdit',	  // wether you are allowed to edit the contact or not, as you alter a list, not the contact
503 503
 				),
504 504
 				'remove_from_list' => array(
@@ -507,14 +507,14 @@  discard block
 block discarded – undo
507 507
 					'icon' => 'foldertree_nolines_minus',
508 508
 					'enabled' => 'javaScript:app.addressbook.nm_compare_field',
509 509
 					'fieldId' => 'exec[nm][filter2]',
510
-					'fieldValue' => '!',	// enable if list != ''
510
+					'fieldValue' => '!', // enable if list != ''
511 511
 				),
512 512
 				'rename_list' => array(
513 513
 					'caption' => 'Rename selected distribution list',
514 514
 					'icon' => 'edit',
515 515
 					'enabled' => 'javaScript:app.addressbook.nm_compare_field',
516 516
 					'fieldId' => 'exec[nm][filter2]',
517
-					'fieldValue' => '!',	// enable if list != ''
517
+					'fieldValue' => '!', // enable if list != ''
518 518
 					'onExecute' => 'javaScript:app.addressbook.rename_list'
519 519
 				),
520 520
 				'delete_list' => array(
@@ -523,10 +523,10 @@  discard block
 block discarded – undo
523 523
 					'icon' => 'delete',
524 524
 					'enabled' => 'javaScript:app.addressbook.nm_compare_field',
525 525
 					'fieldId' => 'exec[nm][filter2]',
526
-					'fieldValue' => '!',	// enable if list != ''
526
+					'fieldValue' => '!', // enable if list != ''
527 527
 				),
528 528
 			);
529
-			if(is_subclass_of('etemplate', 'etemplate_new'))
529
+			if (is_subclass_of('etemplate', 'etemplate_new'))
530 530
 			{
531 531
 				$actions['lists']['children']['remove_from_list']['fieldId'] = 'filter2';
532 532
 				$actions['lists']['children']['rename_list']['fieldId'] = 'filter2';
@@ -536,18 +536,18 @@  discard block
 block discarded – undo
536 536
 		// move to AB
537 537
 		if (($move2addressbooks = $this->get_addressbooks(Acl::ADD)))	// do we have addressbooks, we should
538 538
 		{
539
-			unset($move2addressbooks[0]);	// do not offer action to move contact to an account, as we dont support that currrently
540
-			foreach($move2addressbooks as $owner => $label)
539
+			unset($move2addressbooks[0]); // do not offer action to move contact to an account, as we dont support that currrently
540
+			foreach ($move2addressbooks as $owner => $label)
541 541
 			{
542 542
 				$icon = $type_label = null;
543
-				$this->type_icon((int)$owner, substr($owner,-1) == 'p', 'n', $icon, $type_label);
543
+				$this->type_icon((int)$owner, substr($owner, -1) == 'p', 'n', $icon, $type_label);
544 544
 				$move2addressbooks[$owner] = array(
545 545
 					'icon' => $icon,
546 546
 					'caption' => $label,
547 547
 				);
548 548
 			}
549 549
 			// copy checkbox
550
-			$move2addressbooks= array(
550
+			$move2addressbooks = array(
551 551
 				'copy' =>array(
552 552
 					'id' => 'move_to_copy',
553 553
 					'caption' => 'Copy instead of move',
@@ -571,7 +571,7 @@  discard block
 block discarded – undo
571 571
 			'hideOnMobile' => true
572 572
 		);
573 573
 
574
-		++$group;	// integration with other apps: infolog, calendar, filemanager
574
+		++$group; // integration with other apps: infolog, calendar, filemanager
575 575
 		if ($GLOBALS['egw_info']['user']['apps']['infolog'])
576 576
 		{
577 577
 			$actions['infolog_app'] = array(
@@ -591,7 +591,7 @@  discard block
 block discarded – undo
591 591
 						'icon' => 'new',
592 592
 						'url' => 'menuaction=infolog.infolog_ui.edit&type=task&action=addressbook&action_id=$id',
593 593
 						'popup' => Link::get_registry('infolog', 'add_popup'),
594
-						'onExecute' => 'javaScript:app.addressbook.add_task',	// call server for org-view only
594
+						'onExecute' => 'javaScript:app.addressbook.add_task', // call server for org-view only
595 595
 					),
596 596
 				),
597 597
 				'hideOnMobile' => true
@@ -608,7 +608,7 @@  discard block
 block discarded – undo
608 608
 						'caption' => 'Show',
609 609
 						'icon' => 'view',
610 610
 						'onExecute' => 'javaScript:app.addressbook.view_calendar',
611
-						'targetapp' => 'calendar',	// open in calendar tab,
611
+						'targetapp' => 'calendar', // open in calendar tab,
612 612
 						'hideOnDisabled' => true,
613 613
 					),
614 614
 					'calendar_add' => array(
@@ -687,7 +687,7 @@  discard block
 block discarded – undo
687 687
 			'caption' => 'GeoLocation',
688 688
 			'icon' => 'map',
689 689
 			'group' => ++$group,
690
-			'children' => array (
690
+			'children' => array(
691 691
 				'private' => array(
692 692
 					'caption' => 'Private Address',
693 693
 					'enabled' => 'javaScript:app.addressbook.geoLocation_enabled',
@@ -704,7 +704,7 @@  discard block
 block discarded – undo
704 704
 		);
705 705
 		// check if user is an admin or the export is not generally turned off (contact_export_limit is non-numerical, eg. no)
706 706
 		$exception = Api\Storage\Merge::is_export_limit_excepted();
707
-		if ((isset($GLOBALS['egw_info']['user']['apps']['admin']) || $exception)  || !$this->config['contact_export_limit'] || (int)$this->config['contact_export_limit'])
707
+		if ((isset($GLOBALS['egw_info']['user']['apps']['admin']) || $exception) || !$this->config['contact_export_limit'] || (int)$this->config['contact_export_limit'])
708 708
 		{
709 709
 			$actions['export'] = array(
710 710
 				'caption' => 'Export',
@@ -719,7 +719,7 @@  discard block
 block discarded – undo
719 719
 					),
720 720
 					'vcard'  => array(
721 721
 						'caption' => 'Export as VCard',
722
-						'postSubmit' => true,	// download needs post submit (not Ajax) to work
722
+						'postSubmit' => true, // download needs post submit (not Ajax) to work
723 723
 						'icon' => Vfs::mime_icon('text/vcard'),
724 724
 					),
725 725
 				),
@@ -731,7 +731,7 @@  discard block
 block discarded – undo
731 731
 			$this->prefs['document_dir'], $group, 'Insert in document', 'document_',
732 732
 			$this->prefs['default_document'], $this->config['contact_export_limit']
733 733
 		);
734
-		if (isset($GLOBALS['egw_info']['apps']['stylite']) && ($GLOBALS['egw_info']['user']['apps']['felamimail']||$GLOBALS['egw_info']['user']['apps']['mail']))
734
+		if (isset($GLOBALS['egw_info']['apps']['stylite']) && ($GLOBALS['egw_info']['user']['apps']['felamimail'] || $GLOBALS['egw_info']['user']['apps']['mail']))
735 735
 		{
736 736
 			$actions['mail'] = array(
737 737
 				'caption' => lang('Mail VCard'),
@@ -754,7 +754,7 @@  discard block
 block discarded – undo
754 754
 				'disableClass' => 'rowNoDelete',
755 755
 			);
756 756
 		}
757
-		if ($this->grants[0] & Acl::DELETE)
757
+		if ($this->grants[0]&Acl::DELETE)
758 758
 		{
759 759
 			$actions['delete_account'] = array(
760 760
 				'caption' => 'Delete',
@@ -767,7 +767,7 @@  discard block
 block discarded – undo
767 767
 			);
768 768
 			$actions['delete']['hideOnDisabled'] = true;
769 769
 		}
770
-		if($tid_filter == 'D')
770
+		if ($tid_filter == 'D')
771 771
 		{
772 772
 			$actions['undelete'] = array(
773 773
 				'caption' => 'Un-delete',
@@ -778,7 +778,7 @@  discard block
 block discarded – undo
778 778
 		}
779 779
 		if (isset($actions['export']['children']['csv']) &&
780 780
 			(!isset($GLOBALS['egw_info']['user']['apps']['importexport']) ||
781
-			!importexport_helper_functions::has_definitions('addressbook','export')))
781
+			!importexport_helper_functions::has_definitions('addressbook', 'export')))
782 782
 		{
783 783
 			unset($actions['export']['children']['csv']);
784 784
 		}
@@ -811,13 +811,13 @@  discard block
 block discarded – undo
811 811
 	private function _get_org_name($org)
812 812
 	{
813 813
 		$org_name = array();
814
-		if (strpos($org,'*AND*')!== false) $org = str_replace('*AND*','&',$org);
815
-		foreach(explode('|||',$org) as $part)
814
+		if (strpos($org, '*AND*') !== false) $org = str_replace('*AND*', '&', $org);
815
+		foreach (explode('|||', $org) as $part)
816 816
 		{
817
-			list(,$name) = explode(':',$part,2);
817
+			list(,$name) = explode(':', $part, 2);
818 818
 			if ($name) $org_name[] = $name;
819 819
 		}
820
-		$name = implode(': ',$org_name);
820
+		$name = implode(': ', $org_name);
821 821
 		return $name ? array($org => $name) : array();
822 822
 	}
823 823
 
@@ -827,12 +827,12 @@  discard block
 block discarded – undo
827 827
 	 * @param array $content =null submitted content
828 828
 	 * @param string $msg =null	message to show
829 829
 	 */
830
-	function emailpopup($content=null,$msg=null)
830
+	function emailpopup($content = null, $msg = null)
831 831
 	{
832
-		if (strpos($GLOBALS['egw_info']['flags']['java_script'],'addEmail') === false)
832
+		if (strpos($GLOBALS['egw_info']['flags']['java_script'], 'addEmail') === false)
833 833
 		{
834 834
 			$handler = 'opener.addEmail(to,email)';
835
-			$GLOBALS['egw_info']['flags']['java_script'].= "
835
+			$GLOBALS['egw_info']['flags']['java_script'] .= "
836 836
 <script>
837 837
 window.egw_LAB.wait(function() {
838 838
 	window.focus();
@@ -862,7 +862,7 @@  discard block
 block discarded – undo
862 862
 </script>
863 863
 ";
864 864
 		}
865
-		return $this->index($content,$msg,true);
865
+		return $this->index($content, $msg, true);
866 866
 	}
867 867
 
868 868
 	/**
@@ -876,19 +876,19 @@  discard block
 block discarded – undo
876 876
 	{
877 877
 		$org_contacts = array();
878 878
 		$query = !$_query ? Api\Cache::getSession('addressbook', 'index') : $_query;
879
-		$query['num_rows'] = -1;	// all
880
-		if(!is_array($query['col_filter'])) $query['col_filter'] = array();
879
+		$query['num_rows'] = -1; // all
880
+		if (!is_array($query['col_filter'])) $query['col_filter'] = array();
881 881
 
882
-		if(!is_array($org)) $org = array($org);
883
-		foreach($org as $org_name)
882
+		if (!is_array($org)) $org = array($org);
883
+		foreach ($org as $org_name)
884 884
 		{
885 885
 			$query['org_view'] = $org_name;
886 886
 			$checked = array();
887 887
 			$readonlys = null;
888
-			$this->get_rows($query,$checked,$readonlys,true);	// true = only return the id's
889
-			if($checked[0])
888
+			$this->get_rows($query, $checked, $readonlys, true); // true = only return the id's
889
+			if ($checked[0])
890 890
 			{
891
-				$org_contacts = array_merge($org_contacts,$checked);
891
+				$org_contacts = array_merge($org_contacts, $checked);
892 892
 			}
893 893
 		}
894 894
 		Api\Json\Response::get()->data(array_unique($org_contacts));
@@ -902,33 +902,33 @@  discard block
 block discarded – undo
902 902
 	function infolog_org_view($org)
903 903
 	{
904 904
 		$query = Api\Cache::getSession('addressbook', 'index');
905
-		$query['num_rows'] = -1;	// all
905
+		$query['num_rows'] = -1; // all
906 906
 		$query['org_view'] = $org;
907 907
 		$query['searchletter'] = '';
908 908
 		$checked = $readonlys = null;
909
-		$this->get_rows($query,$checked,$readonlys,true);	// true = only return the id's
909
+		$this->get_rows($query, $checked, $readonlys, true); // true = only return the id's
910 910
 
911 911
 		if (count($checked) > 1)	// use a nicely formatted org-name as title in infolog
912 912
 		{
913 913
 			$parts = array();
914
-			if (strpos($org,'*AND*')!== false) $org = str_replace('*AND*','&',$org);
915
-			foreach(explode('|||',$org) as $part)
914
+			if (strpos($org, '*AND*') !== false) $org = str_replace('*AND*', '&', $org);
915
+			foreach (explode('|||', $org) as $part)
916 916
 			{
917
-				list(,$part) = explode(':',$part,2);
917
+				list(,$part) = explode(':', $part, 2);
918 918
 				if ($part) $parts[] = $part;
919 919
 			}
920
-			$org = implode(', ',$parts);
920
+			$org = implode(', ', $parts);
921 921
 		}
922 922
 		else
923 923
 		{
924
-			$org = '';	// use infolog default of link-title
924
+			$org = ''; // use infolog default of link-title
925 925
 		}
926
-		Egw::redirect_link('/index.php',array(
926
+		Egw::redirect_link('/index.php', array(
927 927
 			'menuaction' => 'infolog.infolog_ui.index',
928 928
 			'action' => 'addressbook',
929
-			'action_id' => implode(',',$checked),
929
+			'action_id' => implode(',', $checked),
930 930
 			'action_title' => $org,
931
-		),'infolog');
931
+		), 'infolog');
932 932
 	}
933 933
 
934 934
 	/**
@@ -953,31 +953,31 @@  discard block
 block discarded – undo
953 953
 			$owner = $this->default_addressbook;
954 954
 		}
955 955
 		// Check for valid list & permissions
956
-		if(!(int)$list_id && !$this->check_list(null,EGW_ACL_ADD|EGW_ACL_EDIT,$owner))
956
+		if (!(int)$list_id && !$this->check_list(null, EGW_ACL_ADD|EGW_ACL_EDIT, $owner))
957 957
 		{
958
-			Api\Json\Response::get()->apply('egw.message', array(  lang('List creation failed, no rights!'),'error'));
958
+			Api\Json\Response::get()->apply('egw.message', array(lang('List creation failed, no rights!'), 'error'));
959 959
 			return;
960 960
 		}
961 961
 		if ((int)$list_id && !$this->check_list((int)$list_id, Acl::EDIT, $owner))
962 962
 		{
963
-			Api\Json\Response::get()->apply('egw.message', array(  lang('Insufficent rights to edit this list!'),'error'));
963
+			Api\Json\Response::get()->apply('egw.message', array(lang('Insufficent rights to edit this list!'), 'error'));
964 964
 			return;
965 965
 		}
966 966
 
967 967
 		$list = array('list_owner' => $owner);
968 968
 
969 969
 		// Rename
970
-		if($list_id)
970
+		if ($list_id)
971 971
 		{
972 972
 			$list = $this->read_list((int)$list_id);
973 973
 		}
974 974
 		$list['list_name'] = $new_name;
975 975
 
976
-		$new_id = $this->add_list(array('list_id' => (int)$list_id), $list['list_owner'],array(),$list);
976
+		$new_id = $this->add_list(array('list_id' => (int)$list_id), $list['list_owner'], array(), $list);
977 977
 
978
-		if($contacts)
978
+		if ($contacts)
979 979
 		{
980
-			$this->add2list($contacts,$new_id);
980
+			$this->add2list($contacts, $new_id);
981 981
 		}
982 982
 		Api\Json\Response::get()->apply('egw.message', array(
983 983
 			$new_id == $list_id ? lang('Distribution list renamed') : lang('List created'),
@@ -992,7 +992,7 @@  discard block
 block discarded – undo
992 992
 	 *
993 993
 	 * @param string $account_id
994 994
 	 */
995
-	function ajax_get_contact ($account_id)
995
+	function ajax_get_contact($account_id)
996 996
 	{
997 997
 		$bo = new Api\Contacts();
998 998
 		$contact = $bo->read('account:'.$account_id);
@@ -1009,7 +1009,7 @@  discard block
 block discarded – undo
1009 1009
 	{
1010 1010
 		$query = Api\Cache::getSession('addressbook', 'index');
1011 1011
 		unset($query['advanced_search']);
1012
-		Api\Cache::setSession('addressbook','index',$query);
1012
+		Api\Cache::setSession('addressbook', 'index', $query);
1013 1013
 		Api\Cache::setSession('addressbook', 'advanced_search', false);
1014 1014
 	}
1015 1015
 
@@ -1025,78 +1025,78 @@  discard block
 block discarded – undo
1025 1025
 	 * @param string/array $session_name 'index' or 'email', or array with session-data depending if we are in the main list or the popup
1026 1026
 	 * @return boolean true if all actions succeded, false otherwise
1027 1027
 	 */
1028
-	function action($action,$checked,$use_all,&$success,&$failed,&$action_msg,$session_name,&$msg, $checkboxes = NULL)
1028
+	function action($action, $checked, $use_all, &$success, &$failed, &$action_msg, $session_name, &$msg, $checkboxes = NULL)
1029 1029
 	{
1030 1030
 		//echo "<p>uicontacts::action('$action',".print_r($checked,true).','.(int)$use_all.",...)</p>\n";
1031 1031
 		$success = $failed = 0;
1032
-		if ($use_all || in_array($action,array('remove_from_list','delete_list')))
1032
+		if ($use_all || in_array($action, array('remove_from_list', 'delete_list')))
1033 1033
 		{
1034 1034
 			// get the whole selection
1035 1035
 			$query = is_array($session_name) ? $session_name : Api\Cache::getSession('addressbook', $session_name);
1036 1036
 
1037 1037
 			if ($use_all)
1038 1038
 			{
1039
-				@set_time_limit(0);			// switch off the execution time limit, as it's for big selections to small
1040
-				$query['num_rows'] = -1;	// all
1039
+				@set_time_limit(0); // switch off the execution time limit, as it's for big selections to small
1040
+				$query['num_rows'] = -1; // all
1041 1041
 				$readonlys = null;
1042
-				$this->get_rows($query,$checked,$readonlys,true);	// true = only return the id's
1042
+				$this->get_rows($query, $checked, $readonlys, true); // true = only return the id's
1043 1043
 			}
1044 1044
 		}
1045 1045
 		// replace org_name:* id's with all id's of that org
1046 1046
 		$org_contacts = array();
1047
-		foreach((array)$checked as $n => $id)
1047
+		foreach ((array)$checked as $n => $id)
1048 1048
 		{
1049
-			if (substr($id,0,9) == 'org_name:')
1049
+			if (substr($id, 0, 9) == 'org_name:')
1050 1050
 			{
1051 1051
 				if (count($checked) == 1 && !count($org_contacts) && $action == 'infolog')
1052 1052
 				{
1053
-					return $this->infolog_org_view($id);	// uses the org-name, instead of 'selected contacts'
1053
+					return $this->infolog_org_view($id); // uses the org-name, instead of 'selected contacts'
1054 1054
 				}
1055 1055
 				unset($checked[$n]);
1056 1056
 				$query = Api\Cache::getSession('addressbook', $session_name);
1057
-				$query['num_rows'] = -1;	// all
1057
+				$query['num_rows'] = -1; // all
1058 1058
 				$query['org_view'] = $id;
1059 1059
 				unset($query['filter2']);
1060 1060
 				$extra = $readonlys = null;
1061
-				$this->get_rows($query,$extra,$readonlys,true);	// true = only return the id's
1062
-				if ($extra[0]) $org_contacts = array_merge($org_contacts,$extra);
1061
+				$this->get_rows($query, $extra, $readonlys, true); // true = only return the id's
1062
+				if ($extra[0]) $org_contacts = array_merge($org_contacts, $extra);
1063 1063
 			}
1064 1064
 		}
1065
-		if ($org_contacts) $checked = array_unique($checked ? array_merge($checked,$org_contacts) : $org_contacts);
1065
+		if ($org_contacts) $checked = array_unique($checked ? array_merge($checked, $org_contacts) : $org_contacts);
1066 1066
 		//_debug_array($checked); exit;
1067 1067
 
1068
-		if (substr($action,0,8) == 'move_to_')
1068
+		if (substr($action, 0, 8) == 'move_to_')
1069 1069
 		{
1070
-			$action = (int)substr($action,8).(substr($action,-1) == 'p' ? 'p' : '');
1070
+			$action = (int)substr($action, 8).(substr($action, -1) == 'p' ? 'p' : '');
1071 1071
 		}
1072
-		elseif (substr($action,0,8) == 'to_list_')
1072
+		elseif (substr($action, 0, 8) == 'to_list_')
1073 1073
 		{
1074
-			$to_list = (int)substr($action,8);
1074
+			$to_list = (int)substr($action, 8);
1075 1075
 			$action = 'to_list';
1076 1076
 		}
1077
-		elseif (substr($action,0,9) == 'document_')
1077
+		elseif (substr($action, 0, 9) == 'document_')
1078 1078
 		{
1079
-			$document = substr($action,9);
1079
+			$document = substr($action, 9);
1080 1080
 			$action = 'document';
1081 1081
 		}
1082
-		elseif(substr($action,0,4) == 'cat_')	// cat_add_123 or cat_del_456
1082
+		elseif (substr($action, 0, 4) == 'cat_')	// cat_add_123 or cat_del_456
1083 1083
 		{
1084 1084
 			$cat_id = (int)substr($action, 8);
1085
-			$action = substr($action,0,7);
1085
+			$action = substr($action, 0, 7);
1086 1086
 		}
1087 1087
 		// Security: stop non-admins to export more then the configured number of contacts
1088
-		if (in_array($action,array('csv','vcard')) && $this->config['contact_export_limit'] && !Api\Storage\Merge::is_export_limit_excepted() &&
1088
+		if (in_array($action, array('csv', 'vcard')) && $this->config['contact_export_limit'] && !Api\Storage\Merge::is_export_limit_excepted() &&
1089 1089
 			(!is_numeric($this->config['contact_export_limit']) || count($checked) > $this->config['contact_export_limit']))
1090 1090
 		{
1091 1091
 			$action_msg = lang('exported');
1092 1092
 			$failed = count($checked);
1093 1093
 			return false;
1094 1094
 		}
1095
-		switch($action)
1095
+		switch ($action)
1096 1096
 		{
1097 1097
 			case 'vcard':
1098 1098
 				$action_msg = lang('exported');
1099
-				$vcard = new addressbook_vcal('addressbook','text/vcard');
1099
+				$vcard = new addressbook_vcal('addressbook', 'text/vcard');
1100 1100
 				$vcard->export($checked);
1101 1101
 				// does not return!
1102 1102
 				$Ok = false;
@@ -1104,10 +1104,10 @@  discard block
 block discarded – undo
1104 1104
 
1105 1105
 			case 'merge':
1106 1106
 				$error_msg = null;
1107
-				$success = $this->merge($checked,$error_msg);
1107
+				$success = $this->merge($checked, $error_msg);
1108 1108
 				$failed = count($checked) - (int)$success;
1109 1109
 				$action_msg = lang('merged');
1110
-				$checked = array();	// to not start the single actions
1110
+				$checked = array(); // to not start the single actions
1111 1111
 				break;
1112 1112
 
1113 1113
 			case 'delete_list':
@@ -1115,7 +1115,7 @@  discard block
 block discarded – undo
1115 1115
 				{
1116 1116
 					$msg = lang('You need to select a distribution list');
1117 1117
 				}
1118
-				elseif($this->delete_list($query['filter2']) === false)
1118
+				elseif ($this->delete_list($query['filter2']) === false)
1119 1119
 				{
1120 1120
 					$msg = lang('Insufficent rights to delete this list!');
1121 1121
 				}
@@ -1135,49 +1135,49 @@  discard block
 block discarded – undo
1135 1135
 				return false;
1136 1136
 
1137 1137
 			case 'infolog_add':
1138
-				Framework::popup(Egw::link('/index.php',array(
1138
+				Framework::popup(Egw::link('/index.php', array(
1139 1139
 						'menuaction' => 'infolog.infolog_ui.edit',
1140 1140
 						'type' => 'task',
1141 1141
 						'action' => 'addressbook',
1142
-						'action_id' => implode(',',$checked),
1143
-					)),'_blank',Link::get_registry('infolog', 'add_popup'));
1144
-				$msg = '';	// no message, as we send none in javascript too and users sees opening popup
1142
+						'action_id' => implode(',', $checked),
1143
+					)), '_blank', Link::get_registry('infolog', 'add_popup'));
1144
+				$msg = ''; // no message, as we send none in javascript too and users sees opening popup
1145 1145
 				return false;
1146 1146
 
1147 1147
 			case 'calendar_add':	// add appointment for org-views, other views are handled directly in javascript
1148
-				Framework::popup(Egw::link('/index.php',array(
1148
+				Framework::popup(Egw::link('/index.php', array(
1149 1149
 						'menuaction' => 'calendar.calendar_uiforms.edit',
1150
-						'participants' => 'c'.implode(',c',$checked),
1151
-					)),'_blank',Link::get_registry('calendar', 'add_popup'));
1152
-				$msg = '';	// no message, as we send none in javascript too and users sees opening popup
1150
+						'participants' => 'c'.implode(',c', $checked),
1151
+					)), '_blank', Link::get_registry('calendar', 'add_popup'));
1152
+				$msg = ''; // no message, as we send none in javascript too and users sees opening popup
1153 1153
 				return false;
1154 1154
 
1155 1155
 			case 'calendar_view':	// show calendar for org-views, although all views are handled directly in javascript
1156
-				Egw::redirect_link('/index.php',array(
1156
+				Egw::redirect_link('/index.php', array(
1157 1157
 					'menuaction' => 'calendar.calendar_uiviews.index',
1158
-					'owner' => 'c'.implode(',c',$checked),
1158
+					'owner' => 'c'.implode(',c', $checked),
1159 1159
 				));
1160 1160
 		}
1161
-		foreach($checked as $id)
1161
+		foreach ($checked as $id)
1162 1162
 		{
1163
-			switch($action)
1163
+			switch ($action)
1164 1164
 			{
1165 1165
 				case 'cat_add':
1166 1166
 				case 'cat_del':
1167
-					if (($Ok = !!($contact = $this->read($id)) && $this->check_perms(Acl::EDIT,$contact)))
1167
+					if (($Ok = !!($contact = $this->read($id)) && $this->check_perms(Acl::EDIT, $contact)))
1168 1168
 					{
1169 1169
 						$action_msg = $action == 'cat_add' ? lang('categorie added') : lang('categorie delete');
1170
-						$cat_ids = $contact['cat_id'] ? explode(',', $contact['cat_id']) : array();   //existing Api\Categories
1170
+						$cat_ids = $contact['cat_id'] ? explode(',', $contact['cat_id']) : array(); //existing Api\Categories
1171 1171
 						if ($action == 'cat_add')
1172 1172
 						{
1173 1173
 							$cat_ids[] = $cat_id;
1174 1174
 							$cat_ids = array_unique($cat_ids);
1175 1175
 						}
1176
-						elseif ((($key = array_search($cat_id,$cat_ids))) !== false)
1176
+						elseif ((($key = array_search($cat_id, $cat_ids))) !== false)
1177 1177
 						{
1178 1178
 							unset($cat_ids[$key]);
1179 1179
 						}
1180
-						$ids = $cat_ids ? implode(',',$cat_ids) : null;
1180
+						$ids = $cat_ids ? implode(',', $cat_ids) : null;
1181 1181
 						if ($ids !== $contact['cat_id'])
1182 1182
 						{
1183 1183
 							$contact['cat_id'] = $ids;
@@ -1188,10 +1188,10 @@  discard block
 block discarded – undo
1188 1188
 
1189 1189
 				case 'delete':
1190 1190
 					$action_msg = lang('deleted');
1191
-					if (($Ok = !!($contact = $this->read($id)) && $this->check_perms(Acl::DELETE,$contact)))
1191
+					if (($Ok = !!($contact = $this->read($id)) && $this->check_perms(Acl::DELETE, $contact)))
1192 1192
 					{
1193
-						if ($contact['owner'] ||	// regular contact or
1194
-							empty($contact['account_id']) ||	// accounts without account_id
1193
+						if ($contact['owner'] || // regular contact or
1194
+							empty($contact['account_id']) || // accounts without account_id
1195 1195
 							// already deleted account (should no longer happen, but needed to allow for cleanup)
1196 1196
 							$contact['tid'] == self::DELETED_TYPE)
1197 1197
 						{
@@ -1200,7 +1200,7 @@  discard block
 block discarded – undo
1200 1200
 						// delete single account --> redirect to admin
1201 1201
 						elseif (count($checked) == 1 && $contact['account_id'])
1202 1202
 						{
1203
-							Egw::redirect_link('/index.php',array(
1203
+							Egw::redirect_link('/index.php', array(
1204 1204
 								'menuaction' => 'admin.admin_account.delete',
1205 1205
 								'account_id' => $contact['account_id'],
1206 1206
 							));
@@ -1262,7 +1262,7 @@  discard block
 block discarded – undo
1262 1262
 					}
1263 1263
 					else
1264 1264
 					{
1265
-						$Ok = $this->remove_from_list($id,$query['filter2']) !== false;
1265
+						$Ok = $this->remove_from_list($id, $query['filter2']) !== false;
1266 1266
 					}
1267 1267
 					break;
1268 1268
 
@@ -1275,28 +1275,28 @@  discard block
 block discarded – undo
1275 1275
 					}
1276 1276
 					else
1277 1277
 					{
1278
-						$Ok = $this->add2list($id,$to_list) !== false;
1278
+						$Ok = $this->add2list($id, $to_list) !== false;
1279 1279
 					}
1280 1280
 					break;
1281 1281
 
1282 1282
 				default:	// move to an other addressbook
1283
-					if (!(int)$action || !($this->grants[(string) (int) $action] & Acl::EDIT))	// might be ADD in the future
1283
+					if (!(int)$action || !($this->grants[(string)(int)$action]&Acl::EDIT))	// might be ADD in the future
1284 1284
 					{
1285 1285
 						return false;
1286 1286
 					}
1287 1287
 					if (!$checkboxes['move_to_copy'])
1288 1288
 					{
1289 1289
 						$action_msg = lang('moved');
1290
-						if (($Ok = !!($contact = $this->read($id)) && $this->check_perms(Acl::DELETE,$contact)))
1290
+						if (($Ok = !!($contact = $this->read($id)) && $this->check_perms(Acl::DELETE, $contact)))
1291 1291
 						{
1292 1292
 							if (!$contact['owner'])		// no (mass-)move of Api\Accounts
1293 1293
 							{
1294 1294
 								$Ok = false;
1295 1295
 							}
1296
-							elseif ($contact['owner'] != (int)$action || $contact['private'] != (int)(substr($action,-1) == 'p'))
1296
+							elseif ($contact['owner'] != (int)$action || $contact['private'] != (int)(substr($action, -1) == 'p'))
1297 1297
 							{
1298
-								$contact['owner'] = (int) $action;
1299
-								$contact['private'] = (int)(substr($action,-1) == 'p');
1298
+								$contact['owner'] = (int)$action;
1299
+								$contact['private'] = (int)(substr($action, -1) == 'p');
1300 1300
 								$Ok = $this->save($contact);
1301 1301
 							}
1302 1302
 						}
@@ -1304,14 +1304,14 @@  discard block
 block discarded – undo
1304 1304
 					else
1305 1305
 					{
1306 1306
 						$action_msg = lang('copied');
1307
-						if (($Ok = !!($contact = $this->read($id)) && $this->check_perms(Acl::READ,$contact)))
1307
+						if (($Ok = !!($contact = $this->read($id)) && $this->check_perms(Acl::READ, $contact)))
1308 1308
 						{
1309
-							if ($contact['owner'] != (int)$action || $contact['private'] != (int)(substr($action,-1) == 'p'))
1309
+							if ($contact['owner'] != (int)$action || $contact['private'] != (int)(substr($action, -1) == 'p'))
1310 1310
 							{
1311
-								$this->copy_contact($contact, false);	// do NOT use self::$copy_fields, copy everything but uid etc.
1311
+								$this->copy_contact($contact, false); // do NOT use self::$copy_fields, copy everything but uid etc.
1312 1312
 								$links = $contact['link_to']['to_id'];
1313
-								$contact['owner'] = (int) $action;
1314
-								$contact['private'] = (int)(substr($action,-1) == 'p');
1313
+								$contact['owner'] = (int)$action;
1314
+								$contact['private'] = (int)(substr($action, -1) == 'p');
1315 1315
 								$Ok = $this->save($contact);
1316 1316
 								if ($Ok && is_array($links))
1317 1317
 								{
@@ -1343,22 +1343,22 @@  discard block
 block discarded – undo
1343 1343
 	 * @param boolean $only_copy_fields =true true: only copy fields configured for copying (eg. no name),
1344 1344
 	 *		false: copy everything, but never to copy fields
1345 1345
 	 */
1346
-	function copy_contact(array &$content, $only_copy_fields=true)
1346
+	function copy_contact(array &$content, $only_copy_fields = true)
1347 1347
 	{
1348 1348
 		$content['link_to']['to_id'] = 0;
1349
-		Link::link('addressbook',$content['link_to']['to_id'],'addressbook',$content['id'],
1350
-			lang('Copied by %1, from record #%2.',Api\Accounts::format_username('',
1351
-			$GLOBALS['egw_info']['user']['account_firstname'],$GLOBALS['egw_info']['user']['account_lastname']),
1349
+		Link::link('addressbook', $content['link_to']['to_id'], 'addressbook', $content['id'],
1350
+			lang('Copied by %1, from record #%2.', Api\Accounts::format_username('',
1351
+			$GLOBALS['egw_info']['user']['account_firstname'], $GLOBALS['egw_info']['user']['account_lastname']),
1352 1352
 			$content['id']));
1353 1353
 		// create a new contact with the content of the old
1354
-		foreach(array_keys($content) as $key)
1354
+		foreach (array_keys($content) as $key)
1355 1355
 		{
1356
-			if($only_copy_fields && !in_array($key, self::$copy_fields) || in_array($key, array('id','etag','carddav_name','uid')))
1356
+			if ($only_copy_fields && !in_array($key, self::$copy_fields) || in_array($key, array('id', 'etag', 'carddav_name', 'uid')))
1357 1357
 			{
1358 1358
 				unset($content[$key]);
1359 1359
 			}
1360 1360
 		}
1361
-		if(!isset($content['owner']))
1361
+		if (!isset($content['owner']))
1362 1362
 		{
1363 1363
 			$content['owner'] = $this->default_private ? $this->user.'p' : $this->default_addressbook;
1364 1364
 		}
@@ -1376,7 +1376,7 @@  discard block
 block discarded – undo
1376 1376
 	 * @param boolean $id_only =false if true only return (via $rows) an array of contact-ids, dont save state to session
1377 1377
 	 * @return int total number of contacts matching the selection
1378 1378
 	 */
1379
-	function get_rows(&$query,&$rows,&$readonlys,$id_only=false)
1379
+	function get_rows(&$query, &$rows, &$readonlys, $id_only = false)
1380 1380
 	{
1381 1381
 		$do_email = $query['do_email'];
1382 1382
 		$what = $query['sitemgr_display'] ? $query['sitemgr_display'] : ($do_email ? 'email' : 'index');
@@ -1385,7 +1385,7 @@  discard block
 block discarded – undo
1385 1385
 		{
1386 1386
 			$store_query = $query;
1387 1387
 			// Do not store these
1388
-			foreach(array('options-cat_id','actions','action_links','placeholder_actions') as $key)
1388
+			foreach (array('options-cat_id', 'actions', 'action_links', 'placeholder_actions') as $key)
1389 1389
 			{
1390 1390
 				unset($store_query[$key]);
1391 1391
 			}
@@ -1396,22 +1396,22 @@  discard block
 block discarded – undo
1396 1396
 		{
1397 1397
 			$old_state = Api\Cache::getSession('addressbook', $what);
1398 1398
 		}
1399
-		if (!isset($this->org_views[(string) $query['org_view']]) || strpos($query['org_view'],':') === false)   // we dont have an org view, unset the according col_filters
1399
+		if (!isset($this->org_views[(string)$query['org_view']]) || strpos($query['org_view'], ':') === false)   // we dont have an org view, unset the according col_filters
1400 1400
 		{
1401 1401
 			if (isset($query['col_filter']['org_name'])) unset($query['col_filter']['org_name']);
1402 1402
 			if (isset($query['col_filter']['adr_one_locality'])) unset($query['col_filter']['adr_one_locality']);
1403 1403
 			if (isset($query['col_filter']['org_unit'])) unset($query['col_filter']['org_unit']);
1404 1404
 		}
1405 1405
 
1406
-		if (isset($this->org_views[(string) $query['org_view']]))	// we have an org view, reset the advanced search
1406
+		if (isset($this->org_views[(string)$query['org_view']]))	// we have an org view, reset the advanced search
1407 1407
 		{
1408 1408
 			//_debug_array(array('Search'=>$query['search'],
1409 1409
 			//	'AdvancedSearch'=>$query['advanced_search']));
1410 1410
 			//if (is_array($query['search'])) unset($query['search']);
1411 1411
 			//unset($query['advanced_search']);
1412
-			if(!$query['search'] && $old_state['advanced_search']) $query['advanced_search'] = $old_state['advanced_search'];
1412
+			if (!$query['search'] && $old_state['advanced_search']) $query['advanced_search'] = $old_state['advanced_search'];
1413 1413
 		}
1414
-		elseif(!$query['search'] && array_key_exists('advanced_search',$old_state))	// eg. paging in an advanced search
1414
+		elseif (!$query['search'] && array_key_exists('advanced_search', $old_state))	// eg. paging in an advanced search
1415 1415
 		{
1416 1416
 			$query['advanced_search'] = $old_state['advanced_search'];
1417 1417
 		}
@@ -1422,11 +1422,11 @@  discard block
 block discarded – undo
1422 1422
 		}*/
1423 1423
 
1424 1424
 		// Make sure old lettersearch filter doesn't stay - current letter filter will be added later
1425
-		foreach($query['col_filter'] as $key => $col_filter)
1425
+		foreach ($query['col_filter'] as $key => $col_filter)
1426 1426
 		{
1427
-			if(!is_numeric($key)) continue;
1428
-			if(preg_match('/'.$GLOBALS['egw']->db->capabilities['case_insensitive_like'].
1429
-				' '.$GLOBALS['egw']->db->quote('[a-z]%').'$/',$col_filter) == 1
1427
+			if (!is_numeric($key)) continue;
1428
+			if (preg_match('/'.$GLOBALS['egw']->db->capabilities['case_insensitive_like'].
1429
+				' '.$GLOBALS['egw']->db->quote('[a-z]%').'$/', $col_filter) == 1
1430 1430
 			)
1431 1431
 			{
1432 1432
 				unset($query['col_filter'][$key]);
@@ -1441,16 +1441,16 @@  discard block
 block discarded – undo
1441 1441
 			{
1442 1442
 				if ($old_state['filter'] === '0')	// user changed to org_view
1443 1443
 				{
1444
-					$query['filter'] = '';			// --> change filter to all contacts
1444
+					$query['filter'] = ''; // --> change filter to all contacts
1445 1445
 				}
1446 1446
 				else								// user changed to accounts
1447 1447
 				{
1448
-					$query['org_view'] = '';		// --> change to regular contacts view
1448
+					$query['org_view'] = ''; // --> change to regular contacts view
1449 1449
 				}
1450 1450
 			}
1451 1451
 			if ($query['org_view'] && isset($this->org_views[$old_state['org_view']]) && !isset($this->org_views[$query['org_view']]))
1452 1452
 			{
1453
-				$query['searchletter'] = '';		// reset lettersearch if viewing the contacts of one organisation
1453
+				$query['searchletter'] = ''; // reset lettersearch if viewing the contacts of one organisation
1454 1454
 			}
1455 1455
 			// save the state of the index in the user prefs
1456 1456
 			$state = serialize(array(
@@ -1463,9 +1463,9 @@  discard block
 block discarded – undo
1463 1463
 			));
1464 1464
 			if ($state != $this->prefs[$what.'_state'] && !$query['csv_export'])
1465 1465
 			{
1466
-				$GLOBALS['egw']->preferences->add('addressbook',$what.'_state',$state);
1466
+				$GLOBALS['egw']->preferences->add('addressbook', $what.'_state', $state);
1467 1467
 				// save prefs, but do NOT invalid the cache (unnecessary)
1468
-				$GLOBALS['egw']->preferences->save_repository(false,'user',false);
1468
+				$GLOBALS['egw']->preferences->save_repository(false, 'user', false);
1469 1469
 			}
1470 1470
 		}
1471 1471
 		unset($old_state);
@@ -1480,11 +1480,11 @@  discard block
 block discarded – undo
1480 1480
 		}
1481 1481
 		if ($query['filter'] !== '')	// not all addressbooks
1482 1482
 		{
1483
-			$query['col_filter']['owner'] = (string) (int) $query['filter'];
1483
+			$query['col_filter']['owner'] = (string)(int)$query['filter'];
1484 1484
 
1485 1485
 			if ($this->private_addressbook)
1486 1486
 			{
1487
-				$query['col_filter']['private'] = substr($query['filter'],-1) == 'p' ? 1 : 0;
1487
+				$query['col_filter']['private'] = substr($query['filter'], -1) == 'p' ? 1 : 0;
1488 1488
 			}
1489 1489
 		}
1490 1490
 		else
@@ -1494,7 +1494,7 @@  discard block
 block discarded – undo
1494 1494
 		}
1495 1495
 		if ((int)$query['filter2'])	// not no distribution list
1496 1496
 		{
1497
-			$query['col_filter']['list'] = (string) (int) $query['filter2'];
1497
+			$query['col_filter']['list'] = (string)(int)$query['filter2'];
1498 1498
 		}
1499 1499
 		else
1500 1500
 		{
@@ -1507,18 +1507,18 @@  discard block
 block discarded – undo
1507 1507
 		// all backends allow now at least to use groups as distribution lists
1508 1508
 		$query['no_filter2'] = false;
1509 1509
 
1510
-		if (isset($this->org_views[(string) $query['org_view']]) && !$query['col_filter']['parent_id'])	// we have an org view
1510
+		if (isset($this->org_views[(string)$query['org_view']]) && !$query['col_filter']['parent_id'])	// we have an org view
1511 1511
 		{
1512 1512
 			// Query doesn't like empties
1513 1513
 			unset($query['col_filter']['parent_id']);
1514 1514
 
1515
-			if($query['actions'] && $query['actions']['open'])
1515
+			if ($query['actions'] && $query['actions']['open'])
1516 1516
 			{
1517 1517
 				// Just switched from contact view, update actions
1518 1518
 				$query['actions'] = $this->get_actions($query['col_filter']['tid'], $query['org_view']);
1519 1519
 			}
1520
-			unset($query['col_filter']['list']);	// does not work together
1521
-			$query['no_filter2'] = true;			// switch the distribution list selection off
1520
+			unset($query['col_filter']['list']); // does not work together
1521
+			$query['no_filter2'] = true; // switch the distribution list selection off
1522 1522
 
1523 1523
 			$query['template'] = 'addressbook.index.org_rows';
1524 1524
 
@@ -1556,7 +1556,7 @@  discard block
 block discarded – undo
1556 1556
 			{
1557 1557
 				$query['template'] = $do_email ? 'addressbook.email.rows' : 'addressbook.index.rows';
1558 1558
 			}
1559
-			if($query['col_filter']['parent_id'])
1559
+			if ($query['col_filter']['parent_id'])
1560 1560
 			{
1561 1561
 				$query['org_view'] = $query['col_filter']['parent_id'];
1562 1562
 				$query['template'] = 'addressbook.index.org_rows';
@@ -1565,25 +1565,25 @@  discard block
 block discarded – undo
1565 1565
 			unset($query['col_filter']['parent_id']);
1566 1566
 			if ($query['org_view'])	// view the contacts of one organisation only
1567 1567
 			{
1568
-				if (strpos($query['org_view'],'*AND*') !== false) $query['org_view'] = str_replace('*AND*','&',$query['org_view']);
1569
-				foreach(explode('|||',$query['org_view']) as $part)
1568
+				if (strpos($query['org_view'], '*AND*') !== false) $query['org_view'] = str_replace('*AND*', '&', $query['org_view']);
1569
+				foreach (explode('|||', $query['org_view']) as $part)
1570 1570
 				{
1571
-					list($name,$value) = explode(':',$part,2);
1571
+					list($name, $value) = explode(':', $part, 2);
1572 1572
 					// do NOT set invalid column, as this gives an SQL error ("AND AND" in sql)
1573
-					if (in_array($name, array('org_name','org_unit','adr_one_location')))
1573
+					if (in_array($name, array('org_name', 'org_unit', 'adr_one_location')))
1574 1574
 					{
1575 1575
 						$query['col_filter'][$name] = $value;
1576 1576
 					}
1577 1577
 				}
1578 1578
 			}
1579
-			else if($query['actions'] && !$query['actions']['edit'])
1579
+			else if ($query['actions'] && !$query['actions']['edit'])
1580 1580
 			{
1581 1581
 				// Just switched from org view, update actions
1582 1582
 				$query['actions'] = $this->get_actions($query['col_filter']['tid'], $query['org_view']);
1583 1583
 			}
1584 1584
 			// translate the select order to the really used over all 3 columns
1585 1585
 			$sort = $query['sort'];
1586
-			switch($query['order'])		// "xxx<>'' DESC" sorts contacts with empty order-criteria always at the end
1586
+			switch ($query['order'])		// "xxx<>'' DESC" sorts contacts with empty order-criteria always at the end
1587 1587
 			{							// we don't exclude them, as the total would otherwise depend on the order-criteria
1588 1588
 				case 'org_name':
1589 1589
 					$order = "egw_addressbook.org_name<>''DESC,egw_addressbook.org_name $sort,n_family $sort,n_given $sort";
@@ -1617,8 +1617,8 @@  discard block
 block discarded – undo
1617 1617
 			}
1618 1618
 			if ($query['searchletter'])	// only show contacts if the order-criteria starts with the given letter
1619 1619
 			{
1620
-				$no_letter_search = array('adr_one_postalcode', 'adr_two_postalcode', 'contact_id', 'contact_created','contact_modified');
1621
-				$query['col_filter'][] = (in_array($query['order'],$no_letter_search) ? 'org_name' : (substr($query['order'],0,1)=='#'?'':'egw_addressbook.').$query['order']).' '.
1620
+				$no_letter_search = array('adr_one_postalcode', 'adr_two_postalcode', 'contact_id', 'contact_created', 'contact_modified');
1621
+				$query['col_filter'][] = (in_array($query['order'], $no_letter_search) ? 'org_name' : (substr($query['order'], 0, 1) == '#' ? '' : 'egw_addressbook.').$query['order']).' '.
1622 1622
 					$GLOBALS['egw']->db->capabilities['case_insensitive_like'].' '.$GLOBALS['egw']->db->quote(strtolower($query['searchletter']).'%');
1623 1623
 			}
1624 1624
 			$wildcard = '%';
@@ -1632,41 +1632,41 @@  discard block
 block discarded – undo
1632 1632
 				unset($query['advanced_search']['meth_select']);
1633 1633
 			}
1634 1634
 			//if ($do_email ) $email_only = array('id','owner','tid','n_fn','n_family','n_given','org_name','email','email_home');
1635
-			$rows = parent::search($query['advanced_search'] ? $query['advanced_search'] : $query['search'],$id_only,
1636
-				$order,'',$wildcard,false,$op,array((int)$query['start'],(int) $query['num_rows']),$query['col_filter']);
1635
+			$rows = parent::search($query['advanced_search'] ? $query['advanced_search'] : $query['search'], $id_only,
1636
+				$order, '', $wildcard, false, $op, array((int)$query['start'], (int)$query['num_rows']), $query['col_filter']);
1637 1637
 
1638 1638
 			// do we need to read the custom fields, depends on the column is enabled and customfields exist
1639 1639
 			// $query['csv_export'] allways needs to read ALL cf's
1640 1640
 			$columsel = $this->prefs['nextmatch-addressbook.'.($do_email ? 'email' : 'index').'.rows'];
1641
-			$available_distib_lists=$this->get_lists(Acl::READ);
1642
-			$columselection = $columsel && !$query['csv_export'] ? explode(',',$columsel) : array();
1641
+			$available_distib_lists = $this->get_lists(Acl::READ);
1642
+			$columselection = $columsel && !$query['csv_export'] ? explode(',', $columsel) : array();
1643 1643
 			$ids = $calendar_participants = array();
1644 1644
 			if (!$id_only && $rows)
1645 1645
 			{
1646
-				$show_custom_fields = (!$columselection || in_array('customfields',$columselection) || $query['csv_export']) && $this->customfields;
1647
-				$show_calendar = !$columselection || in_array('calendar_calendar',$columselection);
1648
-				$show_distributionlist = !$columselection || in_array('distrib_lists',$columselection) || count($available_distib_lists);
1646
+				$show_custom_fields = (!$columselection || in_array('customfields', $columselection) || $query['csv_export']) && $this->customfields;
1647
+				$show_calendar = !$columselection || in_array('calendar_calendar', $columselection);
1648
+				$show_distributionlist = !$columselection || in_array('distrib_lists', $columselection) || count($available_distib_lists);
1649 1649
 				if ($show_calendar || $show_custom_fields || $show_distributionlist)
1650 1650
 				{
1651
-					foreach($rows as $val)
1651
+					foreach ($rows as $val)
1652 1652
 					{
1653 1653
 						$ids[] = $val['id'];
1654 1654
 						$calendar_participants[$val['id']] = $val['account_id'] ? $val['account_id'] : 'c'.$val['id'];
1655 1655
 					}
1656 1656
 					if ($show_custom_fields)
1657 1657
 					{
1658
-						foreach($columselection as $col)
1658
+						foreach ($columselection as $col)
1659 1659
 						{
1660
-							if ($col[0] == '#') $selected_cfs[] = substr($col,1);
1660
+							if ($col[0] == '#') $selected_cfs[] = substr($col, 1);
1661 1661
 						}
1662
-						$customfields = $this->read_customfields($ids,$selected_cfs);
1662
+						$customfields = $this->read_customfields($ids, $selected_cfs);
1663 1663
 					}
1664 1664
 					if ($show_calendar && !empty($ids)) $calendar = $this->read_calendar($calendar_participants);
1665 1665
 					// distributionlist memership for the entrys
1666 1666
 					//_debug_array($this->get_lists(Acl::EDIT));
1667 1667
 					if ($show_distributionlist && $available_distib_lists)
1668 1668
 					{
1669
-						$distributionlist = $this->read_distributionlist($ids,array_keys($available_distib_lists));
1669
+						$distributionlist = $this->read_distributionlist($ids, array_keys($available_distib_lists));
1670 1670
 					}
1671 1671
 				}
1672 1672
 			}
@@ -1675,20 +1675,20 @@  discard block
 block discarded – undo
1675 1675
 
1676 1676
 		if ($id_only)
1677 1677
 		{
1678
-			foreach($rows as $n => $row)
1678
+			foreach ($rows as $n => $row)
1679 1679
 			{
1680 1680
 				$rows[$n] = $row['id'];
1681 1681
 			}
1682
-			return $this->total;	// no need to set other fields or $readonlys
1682
+			return $this->total; // no need to set other fields or $readonlys
1683 1683
 		}
1684 1684
 		$order = $query['order'];
1685 1685
 
1686 1686
 		$readonlys = array();
1687
-		foreach($rows as $n => &$row)
1687
+		foreach ($rows as $n => &$row)
1688 1688
 		{
1689 1689
 			$given = $row['n_given'] ? $row['n_given'] : ($row['n_prefix'] ? $row['n_prefix'] : '');
1690 1690
 
1691
-			switch($order)
1691
+			switch ($order)
1692 1692
 			{
1693 1693
 				default:	// postalcode, created, modified, ...
1694 1694
 				case 'org_name':
@@ -1705,43 +1705,43 @@  discard block
 block discarded – undo
1705 1705
 					break;
1706 1706
 				case 'n_fileas':
1707 1707
 					if (!$row['n_fileas']) $row['n_fileas'] = $this->fileas($row);
1708
-					list($row['line1'],$row['line2']) = explode(': ',$row['n_fileas']);
1708
+					list($row['line1'], $row['line2']) = explode(': ', $row['n_fileas']);
1709 1709
 					break;
1710 1710
 			}
1711
-			if (isset($this->org_views[(string) $query['org_view']]))
1711
+			if (isset($this->org_views[(string)$query['org_view']]))
1712 1712
 			{
1713 1713
 				$row['type'] = 'home';
1714 1714
 				$row['type_label'] = lang('Organisation');
1715 1715
 
1716
-				if ($query['filter'] && !($this->grants[(int)$query['filter']] & Acl::DELETE))
1716
+				if ($query['filter'] && !($this->grants[(int)$query['filter']]&Acl::DELETE))
1717 1717
 				{
1718 1718
 					$row['class'] .= 'rowNoDelete ';
1719 1719
 				}
1720
-				$row['class'] .= 'rowNoEdit ';	// no edit in OrgView
1720
+				$row['class'] .= 'rowNoEdit '; // no edit in OrgView
1721 1721
 				$row['class'] .= 'contact_organisation ';
1722 1722
 			}
1723 1723
 			else
1724 1724
 			{
1725
-				$this->type_icon($row['owner'],$row['private'],$row['tid'],$row['type'],$row['type_label']);
1725
+				$this->type_icon($row['owner'], $row['private'], $row['tid'], $row['type'], $row['type_label']);
1726 1726
 
1727
-				static $tel2show = array('tel_work','tel_cell','tel_home','tel_fax');
1727
+				static $tel2show = array('tel_work', 'tel_cell', 'tel_home', 'tel_fax');
1728 1728
 				static $prefer_marker = null;
1729 1729
 				if (is_null($prefer_marker))
1730 1730
 				{
1731 1731
 					// as et2 adds options with .text(), it can't be entities, but php knows no string literals with utf-8
1732 1732
 					$prefer_marker = html_entity_decode(' &#9734;', ENT_NOQUOTES, 'utf-8');
1733 1733
 				}
1734
-				foreach($tel2show as $name)
1734
+				foreach ($tel2show as $name)
1735 1735
 				{
1736
-					$row[$name] .= ' '.($row['tel_prefer'] == $name ? $prefer_marker : '');		// .' ' to NOT remove the field
1736
+					$row[$name] .= ' '.($row['tel_prefer'] == $name ? $prefer_marker : ''); // .' ' to NOT remove the field
1737 1737
 				}
1738 1738
 				// allways show the prefered phone, if not already shown
1739
-				if (!in_array($row['tel_prefer'],$tel2show) && $row[$row['tel_prefer']])
1739
+				if (!in_array($row['tel_prefer'], $tel2show) && $row[$row['tel_prefer']])
1740 1740
 				{
1741 1741
 					$row['tel_prefered'] = $row[$row['tel_prefer']].$prefer_marker;
1742 1742
 				}
1743 1743
 				// Show nice name as status text
1744
-				if($row['tel_prefer'])
1744
+				if ($row['tel_prefer'])
1745 1745
 				{
1746 1746
 					$row['tel_prefer_label'] = $this->contact_fields[$row['tel_prefer']];
1747 1747
 				}
@@ -1749,33 +1749,33 @@  discard block
 block discarded – undo
1749 1749
 				{
1750 1750
 					$row['class'] .= 'rowAccount rowNoDelete ';
1751 1751
 				}
1752
-				elseif (!$this->check_perms(Acl::DELETE,$row) || (!$GLOBALS['egw_info']['user']['apps']['admin'] && $this->config['history'] != 'userpurge' && $query['col_filter']['tid'] == self::DELETED_TYPE))
1752
+				elseif (!$this->check_perms(Acl::DELETE, $row) || (!$GLOBALS['egw_info']['user']['apps']['admin'] && $this->config['history'] != 'userpurge' && $query['col_filter']['tid'] == self::DELETED_TYPE))
1753 1753
 				{
1754 1754
 					$row['class'] .= 'rowNoDelete ';
1755 1755
 				}
1756
-				if (!$this->check_perms(Acl::EDIT,$row))
1756
+				if (!$this->check_perms(Acl::EDIT, $row))
1757 1757
 				{
1758 1758
 					$row['class'] .= 'rowNoEdit ';
1759 1759
 				}
1760 1760
 				$row['class'] .= 'contact_contact ';
1761 1761
 
1762
-				unset($row['jpegphoto']);	// unused and messes up json encoding (not utf-8)
1762
+				unset($row['jpegphoto']); // unused and messes up json encoding (not utf-8)
1763 1763
 
1764 1764
 				if (isset($customfields[$row['id']]))
1765 1765
 				{
1766
-					foreach($this->customfields as $name => $data)
1766
+					foreach ($this->customfields as $name => $data)
1767 1767
 					{
1768 1768
 						$row['#'.$name] = $customfields[$row['id']]['#'.$name];
1769 1769
 					}
1770 1770
 				}
1771 1771
 				if (isset($distributionlist[$row['id']]))
1772 1772
 				{
1773
-					$row['distrib_lists'] = implode("\n",array_values($distributionlist[$row['id']]));
1773
+					$row['distrib_lists'] = implode("\n", array_values($distributionlist[$row['id']]));
1774 1774
 					//if ($show_distributionlist) $readonlys['distrib_lists'] =true;
1775 1775
 				}
1776 1776
 				if (isset($calendar[$calendar_participants[$row['id']]]))
1777 1777
 				{
1778
-					foreach($calendar[$calendar_participants[$row['id']]] as $name => $data)
1778
+					foreach ($calendar[$calendar_participants[$row['id']]] as $name => $data)
1779 1779
 					{
1780 1780
 						$row[$name] = $data;
1781 1781
 					}
@@ -1783,13 +1783,13 @@  discard block
 block discarded – undo
1783 1783
 			}
1784 1784
 
1785 1785
 			// hide region for address format 'postcode_city'
1786
-			if (($row['addr_format']  = $this->addr_format_by_country($row['adr_one_countryname']))=='postcode_city') unset($row['adr_one_region']);
1787
-			if (($row['addr_format2'] = $this->addr_format_by_country($row['adr_two_countryname']))=='postcode_city') unset($row['adr_two_region']);
1786
+			if (($row['addr_format']  = $this->addr_format_by_country($row['adr_one_countryname'])) == 'postcode_city') unset($row['adr_one_region']);
1787
+			if (($row['addr_format2'] = $this->addr_format_by_country($row['adr_two_countryname'])) == 'postcode_city') unset($row['adr_two_region']);
1788 1788
 
1789 1789
 			// respect category permissions
1790
-			if(!empty($row['cat_id']))
1790
+			if (!empty($row['cat_id']))
1791 1791
 			{
1792
-				$row['cat_id'] = $this->categories->check_list(Acl::READ,$row['cat_id']);
1792
+				$row['cat_id'] = $this->categories->check_list(Acl::READ, $row['cat_id']);
1793 1793
 			}
1794 1794
 		}
1795 1795
 		$rows['no_distribution_list'] = (bool)$query['filter2'];
@@ -1805,23 +1805,21 @@  discard block
 block discarded – undo
1805 1805
 		$header = array();
1806 1806
 		if ($query['filter'] !== '' && !isset($this->org_views[$query['org_view']]))
1807 1807
 		{
1808
-			$header[] = ($query['filter'] == '0' ? lang('accounts') :
1809
-				($GLOBALS['egw']->accounts->get_type($query['filter']) == 'g' ?
1810
-					lang('Group %1',$GLOBALS['egw']->accounts->id2name($query['filter'])) :
1811
-					Api\Accounts::username((int)$query['filter']).
1812
-						(substr($query['filter'],-1) == 'p' ? ' ('.lang('private').')' : '')));
1808
+			$header[] = ($query['filter'] == '0' ? lang('accounts') : ($GLOBALS['egw']->accounts->get_type($query['filter']) == 'g' ?
1809
+					lang('Group %1', $GLOBALS['egw']->accounts->id2name($query['filter'])) : Api\Accounts::username((int)$query['filter']).
1810
+						(substr($query['filter'], -1) == 'p' ? ' ('.lang('private').')' : '')));
1813 1811
 		}
1814 1812
 		if ($query['org_view'])
1815 1813
 		{
1816 1814
 			$header[] = $query['org_view_label'];
1817 1815
 			// Make sure option is there
1818
-			if(!array_key_exists($query['org_view'], $this->org_views))
1816
+			if (!array_key_exists($query['org_view'], $this->org_views))
1819 1817
 			{
1820 1818
 				$this->org_views += $this->_get_org_name($query['org_view']);
1821 1819
 				$rows['sel_options']['org_view'] = $this->org_views;
1822 1820
 			}
1823 1821
 		}
1824
-		if($query['advanced_search'])
1822
+		if ($query['advanced_search'])
1825 1823
 		{
1826 1824
 			$header[] = lang('Advanced search');
1827 1825
 		}
@@ -1832,11 +1830,11 @@  discard block
 block discarded – undo
1832 1830
 		if ($query['searchletter'])
1833 1831
 		{
1834 1832
 			$order = $order == 'n_given' ? lang('first name') : ($order == 'n_family' ? lang('last name') : lang('Organisation'));
1835
-			$header[] = lang("%1 starts with '%2'",$order,$query['searchletter']);
1833
+			$header[] = lang("%1 starts with '%2'", $order, $query['searchletter']);
1836 1834
 		}
1837 1835
 		if ($query['search'] && !$query['advanced_search']) // do not add that, if we have advanced search active
1838 1836
 		{
1839
-			$header[] = lang("Search for '%1'",$query['search']);
1837
+			$header[] = lang("Search for '%1'", $query['search']);
1840 1838
 		}
1841 1839
 		$GLOBALS['egw_info']['flags']['app_header'] = implode(': ', $header);
1842 1840
 
@@ -1852,7 +1850,7 @@  discard block
 block discarded – undo
1852 1850
 	 * @param string &$icon icon-name
1853 1851
 	 * @param string &$label translated label
1854 1852
 	 */
1855
-	function type_icon($owner,$private,$tid,&$icon,&$label)
1853
+	function type_icon($owner, $private, $tid, &$icon, &$label)
1856 1854
 	{
1857 1855
 		if (!$owner)
1858 1856
 		{
@@ -1867,7 +1865,7 @@  discard block
 block discarded – undo
1867 1865
 		elseif ($GLOBALS['egw']->accounts->get_type($owner) == 'g')
1868 1866
 		{
1869 1867
 			$icon = 'group';
1870
-			$label = lang('group %1',$GLOBALS['egw']->accounts->id2name($owner));
1868
+			$label = lang('group %1', $GLOBALS['egw']->accounts->id2name($owner));
1871 1869
 		}
1872 1870
 		else
1873 1871
 		{
@@ -1875,9 +1873,9 @@  discard block
 block discarded – undo
1875 1873
 			$label = $owner == $this->user ? lang('personal') : Api\Accounts::username($owner);
1876 1874
 		}
1877 1875
 		// show tid icon for tid!='n' AND only if one is defined
1878
-		if ($tid != 'n' && Api\Image::find('addressbook',$this->content_types[$tid]['name']))
1876
+		if ($tid != 'n' && Api\Image::find('addressbook', $this->content_types[$tid]['name']))
1879 1877
 		{
1880
-			$icon = Api\Image::find('addressbook',$this->content_types[$tid]['name']);
1878
+			$icon = Api\Image::find('addressbook', $this->content_types[$tid]['name']);
1881 1879
 		}
1882 1880
 
1883 1881
 		// Legacy - from when icons could be anywhere
@@ -1895,19 +1893,19 @@  discard block
 block discarded – undo
1895 1893
 	* @param int $_GET['contact_id'] contact_id mainly for popup use
1896 1894
 	* @param bool $_GET['makecp'] true if you want to copy the contact given by $_GET['contact_id']
1897 1895
 	*/
1898
-	function edit($content=null)
1896
+	function edit($content = null)
1899 1897
 	{
1900 1898
 		if (is_array($content))
1901 1899
 		{
1902 1900
 			list($button) = @each($content['button']);
1903 1901
 			unset($content['button']);
1904
-			$content['private'] = (int) ($content['owner'] && substr($content['owner'],-1) == 'p');
1905
-			$content['owner'] = (string) (int) $content['owner'];
1902
+			$content['private'] = (int)($content['owner'] && substr($content['owner'], -1) == 'p');
1903
+			$content['owner'] = (string)(int)$content['owner'];
1906 1904
 			$content['cat_id'] = $this->config['cat_tab'] === 'Tree' ? $content['cat_id_tree'] : $content['cat_id'];
1907 1905
 			if ($this->config['private_cf_tab']) $content = (array)$content['private_cfs'] + $content;
1908 1906
 			unset($content['private_cfs']);
1909 1907
 
1910
-			switch($button)
1908
+			switch ($button)
1911 1909
 			{
1912 1910
 				case 'save':
1913 1911
 				case 'apply':
@@ -1923,7 +1921,7 @@  discard block
 block discarded – undo
1923 1921
 					}
1924 1922
 					if (is_array($content['upload_photo']) && !empty($content['upload_photo']['tmp_name']) &&
1925 1923
 						$content['upload_photo']['tmp_name'] != 'none' &&
1926
-						($f = fopen($content['upload_photo']['tmp_name'],'r')))
1924
+						($f = fopen($content['upload_photo']['tmp_name'], 'r')))
1927 1925
 					{
1928 1926
 						$content['jpegphoto'] = $this->resize_photo($f);
1929 1927
 						fclose($f);
@@ -1940,12 +1938,12 @@  discard block
 block discarded – undo
1940 1938
 						$old_org_entry = $this->read($content['id']);
1941 1939
 						$old_fullname = ($old_org_entry['n_fn'] ? $old_org_entry['n_fn'] : parent::fullname($old_org_entry));
1942 1940
 					}
1943
-					if ( $content['n_fn'] != $fullname ||  $fullname != $old_fullname)
1941
+					if ($content['n_fn'] != $fullname || $fullname != $old_fullname)
1944 1942
 					{
1945 1943
 						unset($content['n_fn']);
1946 1944
 					}
1947 1945
 					// Country codes
1948
-					foreach(array('adr_one', 'adr_two') as $c_prefix)
1946
+					foreach (array('adr_one', 'adr_two') as $c_prefix)
1949 1947
 					{
1950 1948
 						if ($content[$c_prefix.'_countrycode'] == '-custom-')
1951 1949
 						{
@@ -1954,7 +1952,7 @@  discard block
 block discarded – undo
1954 1952
 					}
1955 1953
 					$content['msg'] = '';
1956 1954
 					$this->error = false;
1957
-					foreach((array)$content['pre_save_callbacks'] as $callback)
1955
+					foreach ((array)$content['pre_save_callbacks'] as $callback)
1958 1956
 					{
1959 1957
 						try {
1960 1958
 							if (($success_msg = call_user_func_array($callback, array(&$content))))
@@ -1964,7 +1962,7 @@  discard block
 block discarded – undo
1964 1962
 						}
1965 1963
 						catch (Exception $ex) {
1966 1964
 							$content['msg'] .= ($content['msg'] ? ', ' : '').$ex->getMessage();
1967
-							$button = 'apply';	// do not close dialog
1965
+							$button = 'apply'; // do not close dialog
1968 1966
 							$this->error = true;
1969 1967
 							break;
1970 1968
 						}
@@ -1977,7 +1975,7 @@  discard block
 block discarded – undo
1977 1975
 					{
1978 1976
 						$content['msg'] .= ($content['msg'] ? ', ' : '').lang('Contact saved');
1979 1977
 
1980
-						foreach((array)$content['post_save_callbacks'] as $callback)
1978
+						foreach ((array)$content['post_save_callbacks'] as $callback)
1981 1979
 						{
1982 1980
 							try {
1983 1981
 								if (($success_msg = call_user_func_array($callback, array(&$content))))
@@ -1985,58 +1983,58 @@  discard block
 block discarded – undo
1985 1983
 									$content['msg'] .= ', '.$success_msg;
1986 1984
 								}
1987 1985
 							}
1988
-							catch(Api\Exception\Redirect $r)
1986
+							catch (Api\Exception\Redirect $r)
1989 1987
 							{
1990 1988
 								// catch it to continue execution and rethrow it later
1991 1989
 							}
1992 1990
 							catch (Exception $ex) {
1993 1991
 								$content['msg'] .= ', '.$ex->getMessage();
1994
-								$button = 'apply';	// do not close dialog
1992
+								$button = 'apply'; // do not close dialog
1995 1993
 								$this->error = true;
1996 1994
 								break;
1997 1995
 							}
1998 1996
 						}
1999 1997
 
2000
-						if ($content['change_org'] && $old_org_entry && ($changed = $this->changed_fields($old_org_entry,$content,true)) &&
2001
-							($members = $this->org_similar($old_org_entry['org_name'],$changed)))
1998
+						if ($content['change_org'] && $old_org_entry && ($changed = $this->changed_fields($old_org_entry, $content, true)) &&
1999
+							($members = $this->org_similar($old_org_entry['org_name'], $changed)))
2002 2000
 						{
2003 2001
 							//foreach($changed as $name => $old_value) echo "<p>$name: '$old_value' --> '{$content[$name]}'</p>\n";
2004
-							list($changed_members,$changed_fields,$failed_members) = $this->change_org($old_org_entry['org_name'],$changed,$content,$members);
2002
+							list($changed_members, $changed_fields, $failed_members) = $this->change_org($old_org_entry['org_name'], $changed, $content, $members);
2005 2003
 							if ($changed_members)
2006 2004
 							{
2007
-								$content['msg'] .= ', '.lang('%1 fields in %2 other organisation member(s) changed',$changed_fields,$changed_members);
2005
+								$content['msg'] .= ', '.lang('%1 fields in %2 other organisation member(s) changed', $changed_fields, $changed_members);
2008 2006
 							}
2009 2007
 							if ($failed_members)
2010 2008
 							{
2011
-								$content['msg'] .= ', '.lang('failed to change %1 organisation member(s) (insufficent rights) !!!',$failed_members);
2009
+								$content['msg'] .= ', '.lang('failed to change %1 organisation member(s) (insufficent rights) !!!', $failed_members);
2012 2010
 							}
2013 2011
 						}
2014 2012
 					}
2015
-					elseif($this->error === true)
2013
+					elseif ($this->error === true)
2016 2014
 					{
2017 2015
 						$content['msg'] = lang('Error: the entry has been updated since you opened it for editing!').'<br />'.
2018
-							lang('Copy your changes to the clipboard, %1reload the entry%2 and merge them.','<a href="'.
2019
-								htmlspecialchars(Egw::link('/index.php',array(
2016
+							lang('Copy your changes to the clipboard, %1reload the entry%2 and merge them.', '<a href="'.
2017
+								htmlspecialchars(Egw::link('/index.php', array(
2020 2018
 									'menuaction' => 'addressbook.addressbook_ui.edit',
2021 2019
 									'contact_id' => $content['id'],
2022
-								))).'">','</a>');
2023
-						break;	// dont refresh the list
2020
+								))).'">', '</a>');
2021
+						break; // dont refresh the list
2024 2022
 					}
2025 2023
 					else
2026 2024
 					{
2027 2025
 						$content['msg'] = lang('Error saving the contact !!!').
2028 2026
 							($this->error ? ' '.$this->error : '');
2029
-						$button = 'apply';	// to not leave the dialog
2027
+						$button = 'apply'; // to not leave the dialog
2030 2028
 					}
2031 2029
 					// writing links for new entry, existing ones are handled by the widget itself
2032 2030
 					if ($links && $content['id'])
2033 2031
 					{
2034
-						Link::link('addressbook',$content['id'],$links);
2032
+						Link::link('addressbook', $content['id'], $links);
2035 2033
 					}
2036 2034
 					// Update client side global datastore
2037 2035
 					$response = Api\Json\Response::get();
2038 2036
 					$response->generic('data', array('uid' => 'addressbook::'.$content['id'], 'data' => $content));
2039
-					Framework::refresh_opener($content['msg'], 'addressbook', $content['id'],  $content['id'] ? 'edit' : 'add',
2037
+					Framework::refresh_opener($content['msg'], 'addressbook', $content['id'], $content['id'] ? 'edit' : 'add',
2040 2038
 						null, null, null, $this->error ? 'error' : 'success');
2041 2039
 
2042 2040
 					// re-throw redirect exception, if there's no error
@@ -2058,11 +2056,11 @@  discard block
 block discarded – undo
2058 2056
 
2059 2057
 				case 'delete':
2060 2058
 					$success = $failed = $action_msg = null;
2061
-					if($this->action('delete',array($content['id']),false,$success,$failed,$action_msg,'',$content['msg']))
2059
+					if ($this->action('delete', array($content['id']), false, $success, $failed, $action_msg, '', $content['msg']))
2062 2060
 					{
2063 2061
 						if ($GLOBALS['egw']->currentapp == 'addressbook')
2064 2062
 						{
2065
-							Framework::refresh_opener(lang('Contact deleted'), 'addressbook', $content['id'], 'delete' );
2063
+							Framework::refresh_opener(lang('Contact deleted'), 'addressbook', $content['id'], 'delete');
2066 2064
 							Framework::window_close();
2067 2065
 						}
2068 2066
 						else
@@ -2087,7 +2085,7 @@  discard block
 block discarded – undo
2087 2085
 			// new contact --> set some defaults
2088 2086
 			if ($contact_id && is_array($content = $this->read($contact_id)))
2089 2087
 			{
2090
-				$contact_id = $content['id'];	// it could have been: "account:$account_id"
2088
+				$contact_id = $content['id']; // it could have been: "account:$account_id"
2091 2089
 				if (!$this->check_perms(Acl::EDIT, $content))
2092 2090
 				{
2093 2091
 					$view = true;
@@ -2131,52 +2129,52 @@  discard block
 block discarded – undo
2131 2129
 				{
2132 2130
 					$content['owner'] = (string)$state['filter'];
2133 2131
 				}
2134
-				$content['private'] = (int) ($content['owner'] && substr($content['owner'],-1) == 'p');
2135
-				if ($content['owner'] === '' || !($this->grants[$content['owner'] = (string) (int) $content['owner']] & Acl::ADD))
2132
+				$content['private'] = (int)($content['owner'] && substr($content['owner'], -1) == 'p');
2133
+				if ($content['owner'] === '' || !($this->grants[$content['owner'] = (string)(int)$content['owner']]&Acl::ADD))
2136 2134
 				{
2137 2135
 					$content['owner'] = $this->default_addressbook;
2138 2136
 					$content['private'] = (int)$this->default_private;
2139 2137
 
2140
-					if (!($this->grants[$content['owner'] = (string) (int) $content['owner']] & Acl::ADD))
2138
+					if (!($this->grants[$content['owner'] = (string)(int)$content['owner']]&Acl::ADD))
2141 2139
 					{
2142
-						$content['owner'] = (string) $this->user;
2140
+						$content['owner'] = (string)$this->user;
2143 2141
 						$content['private'] = 0;
2144 2142
 					}
2145 2143
 				}
2146 2144
 				$new_type = array_keys($this->content_types);
2147 2145
 				// fetch active type to preset the type, if param typeid is not passed
2148
-				$active_tid = Api\Cache::getSession('addressbook','active_tid');
2146
+				$active_tid = Api\Cache::getSession('addressbook', 'active_tid');
2149 2147
 				if ($active_tid && strtoupper($active_tid) === 'D') unset($active_tid);
2150
-				$content['tid'] = $_GET['typeid'] ? $_GET['typeid'] : ($active_tid?$active_tid:$new_type[0]);
2151
-				foreach($this->get_contact_columns() as $field)
2148
+				$content['tid'] = $_GET['typeid'] ? $_GET['typeid'] : ($active_tid ? $active_tid : $new_type[0]);
2149
+				foreach ($this->get_contact_columns() as $field)
2152 2150
 				{
2153 2151
 					if ($_GET['presets'][$field])
2154 2152
 					{
2155
-						if ($field=='email'||$field=='email_home')
2153
+						if ($field == 'email' || $field == 'email_home')
2156 2154
 						{
2157
-							$singleAddress = imap_rfc822_parse_adrlist($_GET['presets'][$field],'');
2155
+							$singleAddress = imap_rfc822_parse_adrlist($_GET['presets'][$field], '');
2158 2156
 							//error_log(__METHOD__.__LINE__.' Address:'.$singleAddress[0]->mailbox."@".$singleAddress[0]->host.", ".$singleAddress[0]->personal);
2159
-							if (!(!is_array($singleAddress) || count($singleAddress)<1))
2157
+							if (!(!is_array($singleAddress) || count($singleAddress) < 1))
2160 2158
 							{
2161 2159
 								$content[$field] = $singleAddress[0]->mailbox."@".$singleAddress[0]->host;
2162 2160
 								if (!empty($singleAddress[0]->personal))
2163 2161
 								{
2164
-									if (strpos($singleAddress[0]->personal,',')===false)
2162
+									if (strpos($singleAddress[0]->personal, ',') === false)
2165 2163
 									{
2166
-										list($P_n_given,$P_n_family,$P_org_name)=explode(' ',$singleAddress[0]->personal,3);
2167
-										if (strlen(trim($P_n_given))>0) $content['n_given'] = trim($P_n_given);
2168
-										if (strlen(trim($P_n_family))>0) $content['n_family'] = trim($P_n_family);
2169
-										if (strlen(trim($P_org_name))>0) $content['org_name'] = trim($P_org_name);
2164
+										list($P_n_given, $P_n_family, $P_org_name) = explode(' ', $singleAddress[0]->personal, 3);
2165
+										if (strlen(trim($P_n_given)) > 0) $content['n_given'] = trim($P_n_given);
2166
+										if (strlen(trim($P_n_family)) > 0) $content['n_family'] = trim($P_n_family);
2167
+										if (strlen(trim($P_org_name)) > 0) $content['org_name'] = trim($P_org_name);
2170 2168
 									}
2171 2169
 									else
2172 2170
 									{
2173
-										list($P_n_family,$P_other)=explode(',',$singleAddress[0]->personal,2);
2174
-										if (strlen(trim($P_n_family))>0) $content['n_family'] = trim($P_n_family);
2175
-										if (strlen(trim($P_other))>0)
2171
+										list($P_n_family, $P_other) = explode(',', $singleAddress[0]->personal, 2);
2172
+										if (strlen(trim($P_n_family)) > 0) $content['n_family'] = trim($P_n_family);
2173
+										if (strlen(trim($P_other)) > 0)
2176 2174
 										{
2177
-											list($P_n_given,$P_org_name)=explode(',',$P_other,2);
2178
-											if (strlen(trim($P_n_given))>0) $content['n_given'] = trim($P_n_given);
2179
-											if (strlen(trim($P_org_name))>0) $content['org_name'] = trim($P_org_name);
2175
+											list($P_n_given, $P_org_name) = explode(',', $P_other, 2);
2176
+											if (strlen(trim($P_n_given)) > 0) $content['n_given'] = trim($P_n_given);
2177
+											if (strlen(trim($P_org_name)) > 0) $content['org_name'] = trim($P_org_name);
2180 2178
 										}
2181 2179
 									}
2182 2180
 								}
@@ -2194,13 +2192,13 @@  discard block
 block discarded – undo
2194 2192
 				}
2195 2193
 				if (isset($_GET['presets']))
2196 2194
 				{
2197
-					foreach(array('email','email_home','n_family','n_given','org_name') as $field)
2195
+					foreach (array('email', 'email_home', 'n_family', 'n_given', 'org_name') as $field)
2198 2196
 					{
2199 2197
 						if (!empty($content[$field]))
2200 2198
 						{
2201 2199
 							//Set the presets fields in content in order to be able to use them later in client side for checking duplication only on first time load
2202 2200
 							// after save/apply we unset them
2203
-							$content['presets_fields'][]= $field;
2201
+							$content['presets_fields'][] = $field;
2204 2202
 							break;
2205 2203
 						}
2206 2204
 					}
@@ -2212,12 +2210,12 @@  discard block
 block discarded – undo
2212 2210
 				//_debug_array($content);
2213 2211
 			}
2214 2212
 
2215
-			if ($_GET['msg']) $content['msg'] = strip_tags($_GET['msg']);	// dont allow HTML!
2213
+			if ($_GET['msg']) $content['msg'] = strip_tags($_GET['msg']); // dont allow HTML!
2216 2214
 
2217
-			if($content && $_GET['makecp'])	// copy the contact
2215
+			if ($content && $_GET['makecp'])	// copy the contact
2218 2216
 			{
2219 2217
 				$this->copy_contact($content);
2220
-				$content['msg'] = lang('%1 copied - the copy can now be edited', lang(Link::get_registry('addressbook','entry')));
2218
+				$content['msg'] = lang('%1 copied - the copy can now be edited', lang(Link::get_registry('addressbook', 'entry')));
2221 2219
 				$view = false;
2222 2220
 			}
2223 2221
 			else
@@ -2228,12 +2226,12 @@  discard block
 block discarded – undo
2228 2226
 			if (!$contact_id && isset($_REQUEST['link_app']) && isset($_REQUEST['link_id']) && !is_array($content['link_to']['to_id']))
2229 2227
 			{
2230 2228
 				$link_ids = is_array($_REQUEST['link_id']) ? $_REQUEST['link_id'] : array($_REQUEST['link_id']);
2231
-				foreach(is_array($_REQUEST['link_app']) ? $_REQUEST['link_app'] : array($_REQUEST['link_app']) as $n => $link_app)
2229
+				foreach (is_array($_REQUEST['link_app']) ? $_REQUEST['link_app'] : array($_REQUEST['link_app']) as $n => $link_app)
2232 2230
 				{
2233 2231
 					$link_id = $link_ids[$n];
2234
-					if (preg_match('/^[a-z_0-9-]+:[:a-z_0-9-]+$/i',$link_app.':'.$link_id))	// gard against XSS
2232
+					if (preg_match('/^[a-z_0-9-]+:[:a-z_0-9-]+$/i', $link_app.':'.$link_id))	// gard against XSS
2235 2233
 					{
2236
-						Link::link('addressbook',$content['link_to']['to_id'],$link_app,$link_id);
2234
+						Link::link('addressbook', $content['link_to']['to_id'], $link_app, $link_id);
2237 2235
 					}
2238 2236
 				}
2239 2237
 			}
@@ -2241,15 +2239,15 @@  discard block
 block discarded – undo
2241 2239
 		if ($content['id'])
2242 2240
 		{
2243 2241
 			// last and next calendar date
2244
-			list(,$dates) = each($this->read_calendar(array($content['account_id'] ? $content['account_id'] : 'c'.$content['id']),false));
2245
-			if(is_array($dates)) $content += $dates;
2242
+			list(,$dates) = each($this->read_calendar(array($content['account_id'] ? $content['account_id'] : 'c'.$content['id']), false));
2243
+			if (is_array($dates)) $content += $dates;
2246 2244
 		}
2247 2245
 		// Avoid ID conflict with tree & selectboxes
2248 2246
 		$content['cat_id_tree'] = $content['cat_id'];
2249 2247
 
2250 2248
 		// Avoid setting conflicts with private custom fields
2251 2249
 		$content['private_cfs'] = array();
2252
-		foreach(Api\Storage\Customfields::get('addressbook', true) as $name => $cf)
2250
+		foreach (Api\Storage\Customfields::get('addressbook', true) as $name => $cf)
2253 2251
 		{
2254 2252
 			if ($this->config['private_cf_tab'] && $cf['private'] && isset($content['#'.$name]))
2255 2253
 			{
@@ -2262,7 +2260,7 @@  discard block
 block discarded – undo
2262 2260
 		$content['addr_format2'] = $this->addr_format_by_country($content['adr_two_countryname']);
2263 2261
 
2264 2262
 		//_debug_array($content);
2265
-		$readonlys['button[delete]'] = !$content['owner'] || !$this->check_perms(Acl::DELETE,$content);
2263
+		$readonlys['button[delete]'] = !$content['owner'] || !$this->check_perms(Acl::DELETE, $content);
2266 2264
 		$readonlys['button[copy]'] = $readonlys['button[edit]'] = $readonlys['button[vcard]'] = true;
2267 2265
 		$readonlys['button[save]'] = $readonlys['button[apply]'] = $view;
2268 2266
 		if ($view)
@@ -2274,19 +2272,18 @@  discard block
 block discarded – undo
2274 2272
 		$sel_options['fileas_type'] = $this->fileas_options($content);
2275 2273
 		$sel_options['adr_one_countrycode']['-custom-'] = lang('Custom');
2276 2274
 		$sel_options['owner'] = $this->get_addressbooks(Acl::ADD);
2277
-		if ($content['owner']) unset($sel_options['owner'][0]);	// do not offer to switch to accounts, as we do not support moving contacts to accounts
2278
-		if ((string) $content['owner'] !== '')
2275
+		if ($content['owner']) unset($sel_options['owner'][0]); // do not offer to switch to accounts, as we do not support moving contacts to accounts
2276
+		if ((string)$content['owner'] !== '')
2279 2277
 		{
2280 2278
 			if (!isset($sel_options['owner'][(int)$content['owner']]))
2281 2279
 			{
2282
-				$sel_options['owner'][(int)$content['owner']] = !$content['owner'] ? lang('Accounts') :
2283
-					Api\Accounts::username($content['owner']);
2280
+				$sel_options['owner'][(int)$content['owner']] = !$content['owner'] ? lang('Accounts') : Api\Accounts::username($content['owner']);
2284 2281
 			}
2285
-			$readonlys['owner'] = !$content['owner'] || 		// dont allow to move accounts, as this mean deleting the user incl. all content he owns
2286
-				$content['id'] && !$this->check_perms(Acl::DELETE,$content);	// you need delete rights to move an existing contact into an other addressbook
2282
+			$readonlys['owner'] = !$content['owner'] || // dont allow to move accounts, as this mean deleting the user incl. all content he owns
2283
+				$content['id'] && !$this->check_perms(Acl::DELETE, $content); // you need delete rights to move an existing contact into an other addressbook
2287 2284
 		}
2288 2285
 		// set the unsupported fields from the backend to readonly
2289
-		foreach($this->get_fields('unsupported',$content['id'],$content['owner']) as $field)
2286
+		foreach ($this->get_fields('unsupported', $content['id'], $content['owner']) as $field)
2290 2287
 		{
2291 2288
 			$readonlys[$field] = true;
2292 2289
 		}
@@ -2296,7 +2293,7 @@  discard block
 block discarded – undo
2296 2293
 			$readonlys['__ALL__'] = true;
2297 2294
 			$readonlys['button[cancel]'] = false;
2298 2295
 
2299
-			foreach($this->own_account_acl as $field)
2296
+			foreach ($this->own_account_acl as $field)
2300 2297
 			{
2301 2298
 				$readonlys[$field] = false;
2302 2299
 			}
@@ -2312,9 +2309,9 @@  discard block
 block discarded – undo
2312 2309
 		if (isset($readonlys['n_fileas'])) $readonlys['fileas_type'] = $readonlys['n_fileas'];
2313 2310
 		// disable not needed tabs
2314 2311
 		$readonlys['tabs']['cats'] = !($content['cat_tab'] = $this->config['cat_tab']);
2315
-		$readonlys['tabs']['custom'] = !$this->customfields || $this->get_backend($content['id'],$content['owner']) == $this->so_accounts;
2312
+		$readonlys['tabs']['custom'] = !$this->customfields || $this->get_backend($content['id'], $content['owner']) == $this->so_accounts;
2316 2313
 		$readonlys['tabs']['custom_private'] = $readonlys['tabs']['custom'] || !$this->config['private_cf_tab'];
2317
-		$readonlys['tabs']['distribution_list'] = !$content['distrib_lists'];#false;
2314
+		$readonlys['tabs']['distribution_list'] = !$content['distrib_lists']; #false;
2318 2315
 		$readonlys['tabs']['history'] = $this->contact_repository != 'sql' || !$content['id'] ||
2319 2316
 			$this->account_repository != 'sql' && $content['account_id'];
2320 2317
 		if (!$content['id']) $readonlys['button[delete]'] = !$content['id'];
@@ -2326,7 +2323,7 @@  discard block
 block discarded – undo
2326 2323
 		{
2327 2324
 			$this->_set_readonlys_for_own_account_acl($readonlys, $content['id']);
2328 2325
 		}
2329
-		for($i = -23; $i<=23; $i++)
2326
+		for ($i = -23; $i <= 23; $i++)
2330 2327
 		{
2331 2328
 			$tz[$i] = ($i > 0 ? '+' : '').$i;
2332 2329
 		}
@@ -2334,11 +2331,11 @@  discard block
 block discarded – undo
2334 2331
 		$content['tz'] = $content['tz'] ? $content['tz'] : '0';
2335 2332
 		if (count($this->content_types) > 1)
2336 2333
 		{
2337
-			foreach($this->content_types as $type => $data)
2334
+			foreach ($this->content_types as $type => $data)
2338 2335
 			{
2339 2336
 				$sel_options['tid'][$type] = $data['name'];
2340 2337
 			}
2341
-			$content['typegfx'] = Api\Html::image('addressbook',$this->content_types[$content['tid']]['options']['icon'],'',' width="16px" height="16px"');
2338
+			$content['typegfx'] = Api\Html::image('addressbook', $this->content_types[$content['tid']]['options']['icon'], '', ' width="16px" height="16px"');
2342 2339
 		}
2343 2340
 		else
2344 2341
 		{
@@ -2352,10 +2349,10 @@  discard block
 block discarded – undo
2352 2349
 		);
2353 2350
 
2354 2351
 		// Links for deleted entries
2355
-		if($content['tid'] == self::DELETED_TYPE)
2352
+		if ($content['tid'] == self::DELETED_TYPE)
2356 2353
 		{
2357 2354
 			$content['link_to']['show_deleted'] = true;
2358
-			if(!$GLOBALS['egw_info']['user']['apps']['admin'] && $this->config['history'] != 'userpurge')
2355
+			if (!$GLOBALS['egw_info']['user']['apps']['admin'] && $this->config['history'] != 'userpurge')
2359 2356
 			{
2360 2357
 				$readonlys['button[delete]'] = true;
2361 2358
 			}
@@ -2364,33 +2361,33 @@  discard block
 block discarded – undo
2364 2361
 		// Enable history
2365 2362
 		$this->setup_history($content, $sel_options);
2366 2363
 
2367
-		$content['photo'] = $this->photo_src($content['id'],$content['jpegphoto'],'photo',$content['etag']);
2364
+		$content['photo'] = $this->photo_src($content['id'], $content['jpegphoto'], 'photo', $content['etag']);
2368 2365
 
2369 2366
 		if ($content['private']) $content['owner'] .= 'p';
2370 2367
 
2371 2368
 		// for custom types, check if we have a custom edit template named "addressbook.edit.$type", $type is the name
2372
-		if (in_array($content['tid'], array('n',self::DELETED_TYPE)) || !$this->tmpl->read('addressbook.edit.'.$this->content_types[$content['tid']]['name']))
2369
+		if (in_array($content['tid'], array('n', self::DELETED_TYPE)) || !$this->tmpl->read('addressbook.edit.'.$this->content_types[$content['tid']]['name']))
2373 2370
 		{
2374 2371
 			$this->tmpl->read('addressbook.edit');
2375 2372
 		}
2376 2373
 
2377 2374
 		// allow other apps to add tabs to addressbook edit
2378 2375
 		$preserve = $content;
2379
-		$content['jpegphoto'] = !empty($content['jpegphoto']);	// unused and messes up json encoding (not utf-8)
2376
+		$content['jpegphoto'] = !empty($content['jpegphoto']); // unused and messes up json encoding (not utf-8)
2380 2377
 		$this->tmpl->setElementAttribute('tabs', 'add_tabs', true);
2381
-		$tabs =& $this->tmpl->getElementAttribute('tabs', 'tabs');
2378
+		$tabs = & $this->tmpl->getElementAttribute('tabs', 'tabs');
2382 2379
 		if (($first_call = !isset($tabs)))
2383 2380
 		{
2384 2381
 			$tabs = array();
2385 2382
 		}
2386 2383
 		//error_log(__LINE__.': '.__METHOD__."() first_call=$first_call");
2387
-		$hook_data = Api\Hooks::process(array('location' => 'addressbook_edit')+$content);
2384
+		$hook_data = Api\Hooks::process(array('location' => 'addressbook_edit') + $content);
2388 2385
 		//error_log(__METHOD__."() hook_data=".array2string($hook_data));
2389
-		foreach($hook_data as $extra_tabs)
2386
+		foreach ($hook_data as $extra_tabs)
2390 2387
 		{
2391 2388
 			if (!$extra_tabs) continue;
2392 2389
 
2393
-			foreach(isset($extra_tabs[0]) ? $extra_tabs : array($extra_tabs) as $extra_tab)
2390
+			foreach (isset($extra_tabs[0]) ? $extra_tabs : array($extra_tabs) as $extra_tab)
2394 2391
 			{
2395 2392
 				if ($extra_tab['data'] && is_array($extra_tab['data']))
2396 2393
 				{
@@ -2435,15 +2432,15 @@  discard block
 block discarded – undo
2435 2432
 	 * @param array &$readonlys
2436 2433
 	 * @param int $id
2437 2434
 	 */
2438
-	function _set_readonlys_for_own_account_acl(&$readonlys,$id)
2435
+	function _set_readonlys_for_own_account_acl(&$readonlys, $id)
2439 2436
 	{
2440 2437
 		// regular fields depending on the backend
2441
-		foreach($this->get_fields('supported',$id,0) as $field)
2438
+		foreach ($this->get_fields('supported', $id, 0) as $field)
2442 2439
 		{
2443
-			if (!$this->own_account_acl || !in_array($field,$this->own_account_acl))
2440
+			if (!$this->own_account_acl || !in_array($field, $this->own_account_acl))
2444 2441
 			{
2445 2442
 				$readonlys[$field] = true;
2446
-				switch($field)
2443
+				switch ($field)
2447 2444
 				{
2448 2445
 					case 'tel_work':
2449 2446
 					case 'tel_cell':
@@ -2459,16 +2456,16 @@  discard block
 block discarded – undo
2459 2456
 		// custom fields
2460 2457
 		if ($this->customfields)
2461 2458
 		{
2462
-			foreach(array_keys($this->customfields) as $name)
2459
+			foreach (array_keys($this->customfields) as $name)
2463 2460
 			{
2464
-				if (!$this->own_account_acl || !in_array('#'.$name,$this->own_account_acl))
2461
+				if (!$this->own_account_acl || !in_array('#'.$name, $this->own_account_acl))
2465 2462
 				{
2466 2463
 					$readonlys['#'.$name] = true;
2467 2464
 				}
2468 2465
 			}
2469 2466
 		}
2470 2467
 		// links
2471
-		if (!$this->own_account_acl || !in_array('link_to',$this->own_account_acl))
2468
+		if (!$this->own_account_acl || !in_array('link_to', $this->own_account_acl))
2472 2469
 		{
2473 2470
 			$readonlys['link_to'] = true;
2474 2471
 		}
@@ -2486,10 +2483,10 @@  discard block
 block discarded – undo
2486 2483
 	 * 	'data' => array of id => "full name (addressbook)" pairs
2487 2484
 	 *  'fileas_options'
2488 2485
 	 */
2489
-	public function ajax_check_values($values, $name, $own_id=0)
2486
+	public function ajax_check_values($values, $name, $own_id = 0)
2490 2487
 	{
2491 2488
 		$matches = null;
2492
-		if (preg_match('/^exec\[([^\]]+)\]$/', $name, $matches)) $name = $matches[1];	// remove exec[ ]
2489
+		if (preg_match('/^exec\[([^\]]+)\]$/', $name, $matches)) $name = $matches[1]; // remove exec[ ]
2493 2490
 
2494 2491
 		$ret = array('doublicates' => array(), 'msg' => null);
2495 2492
 
@@ -2513,10 +2510,10 @@  discard block
 block discarded – undo
2513 2510
 
2514 2511
 			// if name, firstname or org changed and at least 2 are specified, check for doublicates
2515 2512
 			if (in_array($name, array('n_given', 'n_family', 'org_name')) &&
2516
-				!empty($values['n_given'])+!empty($values['n_family'])+!empty($values['org_name']) >= 2)
2513
+				!empty($values['n_given']) + !empty($values['n_family']) + !empty($values['org_name']) >= 2)
2517 2514
 			{
2518 2515
 				$filter = array();
2519
-				foreach(array('email', 'n_given', 'n_family', 'org_name') as $n)	// use email too, to exclude obvious false positives
2516
+				foreach (array('email', 'n_given', 'n_family', 'org_name') as $n)	// use email too, to exclude obvious false positives
2520 2517
 				{
2521 2518
 					if (!empty($values[$n])) $filter[$n] = $values[$n];
2522 2519
 				}
@@ -2525,7 +2522,7 @@  discard block
 block discarded – undo
2525 2522
 		}
2526 2523
 		if ($contacts)
2527 2524
 		{
2528
-			foreach($contacts as $contact)
2525
+			foreach ($contacts as $contact)
2529 2526
 			{
2530 2527
 				if ($own_id && $contact['id'] == $own_id) continue;
2531 2528
 
@@ -2549,26 +2546,24 @@  discard block
 block discarded – undo
2549 2546
 	 *
2550 2547
 	 * @param array $content
2551 2548
 	 */
2552
-	function view(array $content=null)
2549
+	function view(array $content = null)
2553 2550
 	{
2554 2551
 		// CRM list comes from content, request, or preference
2555
-		$crm_list = $content['crm_list'] ? $content['crm_list'] :
2556
-			($_GET['crm_list'] ? $_GET['crm_list'] : $GLOBALS['egw_info']['user']['preferences']['addressbook']['crm_list']);
2557
-		if(!$crm_list || $crm_list == '~edit~') $crm_list = 'infolog';
2552
+		$crm_list = $content['crm_list'] ? $content['crm_list'] : ($_GET['crm_list'] ? $_GET['crm_list'] : $GLOBALS['egw_info']['user']['preferences']['addressbook']['crm_list']);
2553
+		if (!$crm_list || $crm_list == '~edit~') $crm_list = 'infolog';
2558 2554
 
2559
-		if(is_array($content))
2555
+		if (is_array($content))
2560 2556
 		{
2561 2557
 			list($button) = each($content['button']);
2562 2558
 			switch ($content['toolbar'] ? $content['toolbar'] : $button)
2563 2559
 			{
2564
-				case 'vcard':
2565
-					Egw::redirect_link('/index.php','menuaction=addressbook.uivcard.out&ab_id=' .$content['id']);
2560
+				case 'vcard' : Egw::redirect_link('/index.php', 'menuaction=addressbook.uivcard.out&ab_id='.$content['id']);
2566 2561
 
2567 2562
 				case 'cancel':
2568
-					Egw::redirect_link('/index.php','menuaction=addressbook.addressbook_ui.index&ajax=true');
2563
+					Egw::redirect_link('/index.php', 'menuaction=addressbook.addressbook_ui.index&ajax=true');
2569 2564
 
2570 2565
 				case 'delete':
2571
-					Egw::redirect_link('/index.php',array(
2566
+					Egw::redirect_link('/index.php', array(
2572 2567
 						'menuaction' => 'addressbook.addressbook_ui.index',
2573 2568
 						'msg' => $this->delete($content) ? lang('Contact deleted') : lang('Error deleting the contact !!!'),
2574 2569
 					));
@@ -2586,9 +2581,9 @@  discard block
 block discarded – undo
2586 2581
 					$num_rows = $this->get_rows($query, $rows, $readonlys, true);
2587 2582
 					//error_log(__METHOD__."() get_rows()=$num_rows rows=".array2string($rows));
2588 2583
 					$contact_id = $rows[0];
2589
-					if(!$contact_id || !is_array($content = $this->read($contact_id)))
2584
+					if (!$contact_id || !is_array($content = $this->read($contact_id)))
2590 2585
 					{
2591
-						Egw::redirect_link('/index.php',array(
2586
+						Egw::redirect_link('/index.php', array(
2592 2587
 							'menuaction' => 'addressbook.addressbook_ui.index',
2593 2588
 							'msg' => $content,
2594 2589
 							'ajax' => 'true'
@@ -2597,14 +2592,14 @@  discard block
 block discarded – undo
2597 2592
 					$content['index'] = $query['start'];
2598 2593
 
2599 2594
 					// List nextmatch is already there, just update the filter
2600
-					if($contact_id && Api\Json\Request::isJSONRequest())
2595
+					if ($contact_id && Api\Json\Request::isJSONRequest())
2601 2596
 					{
2602
-						switch($crm_list)
2597
+						switch ($crm_list)
2603 2598
 						{
2604 2599
 							case 'infolog':
2605 2600
 							case 'tracker':
2606 2601
 							default:
2607
-								Api\Json\Response::get()->apply('app.addressbook.view_set_list',Array(Array('action'=>'addressbook', 'action_id' => $contact_id)));
2602
+								Api\Json\Response::get()->apply('app.addressbook.view_set_list', Array(Array('action'=>'addressbook', 'action_id' => $contact_id)));
2608 2603
 								break;
2609 2604
 						}
2610 2605
 
@@ -2635,13 +2630,13 @@  discard block
 block discarded – undo
2635 2630
 				$_GET['index'] = 0;
2636 2631
 			}
2637 2632
 			$contact_id = $_GET['contact_id'] ? $_GET['contact_id'] : ((int)$_GET['account_id'] ? 'account:'.(int)$_GET['account_id'] : 0);
2638
-			if(!$contact_id || !is_array($content = $this->read($contact_id)))
2633
+			if (!$contact_id || !is_array($content = $this->read($contact_id)))
2639 2634
 			{
2640
-				Egw::redirect_link('/index.php',array(
2635
+				Egw::redirect_link('/index.php', array(
2641 2636
 					'menuaction' => 'addressbook.addressbook_ui.index',
2642 2637
 					'msg' => $content,
2643 2638
 					'ajax' => 'true'
2644
-				)+(isset($_GET['search']) ? array('search' => $_GET['search']) : array()));
2639
+				) + (isset($_GET['search']) ? array('search' => $_GET['search']) : array()));
2645 2640
 			}
2646 2641
 			if (isset($_GET['index']))
2647 2642
 			{
@@ -2654,25 +2649,25 @@  discard block
 block discarded – undo
2654 2649
 				$num_rows = $this->get_rows($query, $rows, $readonlys, true);
2655 2650
 			}
2656 2651
 		}
2657
-		$content['jpegphoto'] = !empty($content['jpegphoto']);	// unused and messes up json encoding (not utf-8)
2652
+		$content['jpegphoto'] = !empty($content['jpegphoto']); // unused and messes up json encoding (not utf-8)
2658 2653
 
2659 2654
 		// make everything not explicit mentioned readonly
2660 2655
 		$readonlys['__ALL__'] = true;
2661 2656
 		$readonlys['photo'] = $readonlys['button[cancel]'] = $readonlys['button[copy]'] =
2662 2657
 			$readonlys['button[ok]'] = $readonlys['button[more]'] = $readonlys['toolbar'] = false;
2663 2658
 
2664
-		foreach(array_keys($this->contact_fields) as $key)
2659
+		foreach (array_keys($this->contact_fields) as $key)
2665 2660
 		{
2666
-			if (in_array($key,array('tel_home','tel_work','tel_cell','tel_fax')))
2661
+			if (in_array($key, array('tel_home', 'tel_work', 'tel_cell', 'tel_fax')))
2667 2662
 			{
2668 2663
 				$content[$key.'2'] = $content[$key];
2669 2664
 			}
2670 2665
 		}
2671 2666
 
2672 2667
 		// respect category permissions
2673
-		if(!empty($content['cat_id']))
2668
+		if (!empty($content['cat_id']))
2674 2669
 		{
2675
-			$content['cat_id'] = $this->categories->check_list(Acl::READ,$content['cat_id']);
2670
+			$content['cat_id'] = $this->categories->check_list(Acl::READ, $content['cat_id']);
2676 2671
 		}
2677 2672
 		$content['cat_id_tree'] = $content['cat_id'];
2678 2673
 
@@ -2682,12 +2677,12 @@  discard block
 block discarded – undo
2682 2677
 			'to_id'  => $content['id'],
2683 2678
 		);
2684 2679
 		// Links for deleted entries
2685
-		if($content['tid'] == self::DELETED_TYPE)
2680
+		if ($content['tid'] == self::DELETED_TYPE)
2686 2681
 		{
2687 2682
 			$content['link_to']['show_deleted'] = true;
2688 2683
 		}
2689
-		$readonlys['button[delete]'] = !$content['owner'] || !$this->check_perms(Acl::DELETE,$content);
2690
-		$readonlys['button[edit]'] = !$this->check_perms(Acl::EDIT,$content);
2684
+		$readonlys['button[delete]'] = !$content['owner'] || !$this->check_perms(Acl::DELETE, $content);
2685
+		$readonlys['button[edit]'] = !$this->check_perms(Acl::EDIT, $content);
2691 2686
 
2692 2687
 		// how to display addresses
2693 2688
 		$content['addr_format']  = $this->addr_format_by_country($content['adr_one_countryname']);
@@ -2695,7 +2690,7 @@  discard block
 block discarded – undo
2695 2690
 
2696 2691
 		$sel_options['fileas_type'][$content['fileas_type']] = $this->fileas($content);
2697 2692
 		$sel_options['owner'] = $this->get_addressbooks();
2698
-		for($i = -23; $i<=23; $i++)
2693
+		for ($i = -23; $i <= 23; $i++)
2699 2694
 		{
2700 2695
 			$tz[$i] = ($i > 0 ? '+' : '').$i;
2701 2696
 		}
@@ -2703,11 +2698,11 @@  discard block
 block discarded – undo
2703 2698
 		$content['tz'] = $content['tz'] ? $content['tz'] : 0;
2704 2699
 		if (count($this->content_types) > 1)
2705 2700
 		{
2706
-			foreach($this->content_types as $type => $data)
2701
+			foreach ($this->content_types as $type => $data)
2707 2702
 			{
2708 2703
 				$sel_options['tid'][$type] = $data['name'];
2709 2704
 			}
2710
-			$content['typegfx'] = Api\Html::image('addressbook',$this->content_types[$content['tid']]['options']['icon'],'',' width="16px" height="16px"');
2705
+			$content['typegfx'] = Api\Html::image('addressbook', $this->content_types[$content['tid']]['options']['icon'], '', ' width="16px" height="16px"');
2711 2706
 		}
2712 2707
 		else
2713 2708
 		{
@@ -2724,7 +2719,7 @@  discard block
 block discarded – undo
2724 2719
 		{
2725 2720
 			$content['owner'] .= 'p';
2726 2721
 		}
2727
-		$this->tmpl->set_cell_attribute('change_org','disabled',true);
2722
+		$this->tmpl->set_cell_attribute('change_org', 'disabled', true);
2728 2723
 
2729 2724
 		// Prevent double countries - invalid code blanks it, disabling doesn't work
2730 2725
 		$content['adr_one_countrycode'] = '-';
@@ -2737,14 +2732,14 @@  discard block
 block discarded – undo
2737 2732
 		$readonlys['tabs']['cats'] = !($content['cat_tab'] = $this->config['cat_tab']);
2738 2733
 		$readonlys['tabs']['custom'] = !$this->customfields;
2739 2734
 		$readonlys['tabs']['custom_private'] = !$this->customfields || !$this->config['private_cf_tab'];
2740
-		$readonlys['tabs']['distribution_list'] = !$content['distrib_lists'];#false;
2735
+		$readonlys['tabs']['distribution_list'] = !$content['distrib_lists']; #false;
2741 2736
 		$readonlys['tabs']['history'] = $this->contact_repository != 'sql' || !$content['id'] ||
2742 2737
 			$this->account_repository != 'sql' && $content['account_id'];
2743 2738
 		if ($this->config['private_cf_tab']) $content['no_private_cfs'] = 0;
2744 2739
 
2745 2740
 		// last and next calendar date
2746
-		if (!empty($content['id'])) list(,$dates) = each($this->read_calendar(array($content['account_id'] ? $content['account_id'] : 'c'.$content['id']),false));
2747
-		if(is_array($dates)) $content += $dates;
2741
+		if (!empty($content['id'])) list(,$dates) = each($this->read_calendar(array($content['account_id'] ? $content['account_id'] : 'c'.$content['id']), false));
2742
+		if (is_array($dates)) $content += $dates;
2748 2743
 
2749 2744
 		// Disable importexport
2750 2745
 		$GLOBALS['egw_info']['flags']['disable_importexport']['export'] = true;
@@ -2786,7 +2781,7 @@  discard block
 block discarded – undo
2786 2781
 		{
2787 2782
 			unset($actions['back']);
2788 2783
 		}
2789
-		if (!isset($content['index']) || $content['index'] >= $num_rows-1)
2784
+		if (!isset($content['index']) || $content['index'] >= $num_rows - 1)
2790 2785
 		{
2791 2786
 			unset($actions['next']);
2792 2787
 		}
@@ -2798,7 +2793,7 @@  discard block
 block discarded – undo
2798 2793
 		// need to load list's app.js now, as exec calls header before other app can include it
2799 2794
 		Framework::includeJS('/'.$crm_list.'/js/app.js');
2800 2795
 
2801
-		$this->tmpl->exec('addressbook.addressbook_ui.view',$content,$sel_options,$readonlys,array(
2796
+		$this->tmpl->exec('addressbook.addressbook_ui.view', $content, $sel_options, $readonlys, array(
2802 2797
 			'id' => $content['id'],
2803 2798
 			'index' => $content['index'],
2804 2799
 			'crm_list' => $crm_list
@@ -2806,12 +2801,12 @@  discard block
 block discarded – undo
2806 2801
 
2807 2802
 		// Only load this on first time - we're using AJAX, so it stays there through submits.
2808 2803
 		// Sending it again (via ajax) will break the addressbook.view etemplate2
2809
-		if($contact_id)
2804
+		if ($contact_id)
2810 2805
 		{
2811 2806
 			Api\Hooks::single(array(
2812 2807
 				'location' => 'addressbook_view',
2813 2808
 				'ab_id'    => $content['id']
2814
-			),$crm_list);
2809
+			), $crm_list);
2815 2810
 		}
2816 2811
 	}
2817 2812
 
@@ -2823,30 +2818,30 @@  discard block
 block discarded – undo
2823 2818
 	 */
2824 2819
 	function email2link($email)
2825 2820
 	{
2826
-		if (strpos($email,'@') == false) return '';
2821
+		if (strpos($email, '@') == false) return '';
2827 2822
 
2828
-		if($GLOBALS['egw_info']['user']['apps']['mail'])
2823
+		if ($GLOBALS['egw_info']['user']['apps']['mail'])
2829 2824
 		{
2830 2825
 			return array(
2831 2826
 				'menuaction' => 'mail.mail_compose.compose',
2832 2827
 				'send_to'    => base64_encode($email)
2833 2828
 			);
2834 2829
 		}
2835
-		if($GLOBALS['egw_info']['user']['apps']['felamimail'])
2830
+		if ($GLOBALS['egw_info']['user']['apps']['felamimail'])
2836 2831
 		{
2837 2832
 			return array(
2838 2833
 				'menuaction' => 'felamimail.uicompose.compose',
2839 2834
 				'send_to'    => base64_encode($email)
2840 2835
 			);
2841 2836
 		}
2842
-		if($GLOBALS['egw_info']['user']['apps']['email'])
2837
+		if ($GLOBALS['egw_info']['user']['apps']['email'])
2843 2838
 		{
2844 2839
 			return array(
2845 2840
 				'menuaction' => 'email.uicompose.compose',
2846 2841
 				'to' => $email,
2847 2842
 			);
2848 2843
 		}
2849
-		return 'mailto:' . $email;
2844
+		return 'mailto:'.$email;
2850 2845
 	}
2851 2846
 
2852 2847
 	/**
@@ -2855,9 +2850,9 @@  discard block
 block discarded – undo
2855 2850
 	 * @param array $_content
2856 2851
 	 * @return string
2857 2852
 	 */
2858
-	function search($_content=array())
2853
+	function search($_content = array())
2859 2854
 	{
2860
-		if(!empty($_content))
2855
+		if (!empty($_content))
2861 2856
 		{
2862 2857
 
2863 2858
 			$_content['cat_id'] = $this->config['cat_tab'] === 'Tree' ? $_content['cat_id_tree'] : $_content['cat_id'];
@@ -2872,10 +2867,10 @@  discard block
 block discarded – undo
2872 2867
 			}
2873 2868
 			else
2874 2869
 			{
2875
-				$query['advanced_search'] = array_intersect_key($_content,array_flip(array_merge($this->get_contact_columns(),array('operator','meth_select'))));
2870
+				$query['advanced_search'] = array_intersect_key($_content, array_flip(array_merge($this->get_contact_columns(), array('operator', 'meth_select'))));
2876 2871
 				foreach ($query['advanced_search'] as $key => $value)
2877 2872
 				{
2878
-					if(!$value) unset($query['advanced_search'][$key]);
2873
+					if (!$value) unset($query['advanced_search'][$key]);
2879 2874
 				}
2880 2875
 				// Skip n_fn, it causes problems in sql
2881 2876
 				unset($query['advanced_search']['n_fn']);
@@ -2891,7 +2886,7 @@  discard block
 block discarded – undo
2891 2886
 			$response->call("app.addressbook.adv_search", array('advanced_search' => $_content['button']['search'] ? $query['advanced_search'] : ''));
2892 2887
 			if ($_content['button']['cancelsearch'])
2893 2888
 			{
2894
-				Framework::window_close ();
2889
+				Framework::window_close();
2895 2890
 
2896 2891
 				// No need to reload popup
2897 2892
 				return;
@@ -2908,7 +2903,7 @@  discard block
 block discarded – undo
2908 2903
 		// Avoid ID conflict with tree & selectboxes
2909 2904
 		$content['cat_id_tree'] = $content['cat_id'];
2910 2905
 
2911
-		for($i = -23; $i<=23; $i++)
2906
+		for ($i = -23; $i <= 23; $i++)
2912 2907
 		{
2913 2908
 			$tz[$i] = ($i > 0 ? '+' : '').$i;
2914 2909
 		}
@@ -2917,8 +2912,8 @@  discard block
 block discarded – undo
2917 2912
 		//foreach($this->content_types as $type => $data) $sel_options['tid'][$type] = $data['name'];
2918 2913
 
2919 2914
 		// configure search options
2920
-		$sel_options['owner'] = $this->get_addressbooks(Acl::READ,lang('all'));
2921
-		$sel_options['operator'] =  array(
2915
+		$sel_options['owner'] = $this->get_addressbooks(Acl::READ, lang('all'));
2916
+		$sel_options['operator'] = array(
2922 2917
 			'AND' => 'AND',
2923 2918
 			'OR' => 'OR',
2924 2919
 		);
@@ -2928,12 +2923,12 @@  discard block
 block discarded – undo
2928 2923
 		);
2929 2924
 		if ($this->customfields)
2930 2925
 		{
2931
-			foreach($this->customfields as $name => $data)
2926
+			foreach ($this->customfields as $name => $data)
2932 2927
 			{
2933 2928
 				if (substr($data['type'], 0, 6) == 'select' && !($data['rows'] > 1))
2934 2929
 				{
2935 2930
 					if (!isset($content['#'.$name])) $content['#'.$name] = '';
2936
-					if(!isset($data['values'][''])) $sel_options['#'.$name][''] = lang('Select one');
2931
+					if (!isset($data['values'][''])) $sel_options['#'.$name][''] = lang('Select one');
2937 2932
 				}
2938 2933
 				// Make them not required, otherwise you can't search
2939 2934
 				$this->tmpl->setElementAttribute('#'.$name, 'needed', FALSE);
@@ -2959,8 +2954,8 @@  discard block
 block discarded – undo
2959 2954
 
2960 2955
 		if ($this->config['private_cf_tab']) $content['no_private_cfs'] = 0;
2961 2956
 
2962
-		$this->tmpl->set_cell_attribute('change_org','disabled',true);
2963
-		return $this->tmpl->exec('addressbook.addressbook_ui.search',$content,$sel_options,$readonlys,array(),2);
2957
+		$this->tmpl->set_cell_attribute('change_org', 'disabled', true);
2958
+		return $this->tmpl->exec('addressbook.addressbook_ui.search', $content, $sel_options, $readonlys, array(), 2);
2964 2959
 	}
2965 2960
 
2966 2961
 	/**
@@ -2969,16 +2964,15 @@  discard block
 block discarded – undo
2969 2964
 	function photo()
2970 2965
 	{
2971 2966
 		ob_start();
2972
-		$contact_id = isset($_GET['contact_id']) ? $_GET['contact_id'] :
2973
-			(isset($_GET['account_id']) ? 'account:'.$_GET['account_id'] : 0);
2967
+		$contact_id = isset($_GET['contact_id']) ? $_GET['contact_id'] : (isset($_GET['account_id']) ? 'account:'.$_GET['account_id'] : 0);
2974 2968
 
2975
-		if (substr($contact_id,0,8) == 'account:')
2969
+		if (substr($contact_id, 0, 8) == 'account:')
2976 2970
 		{
2977
-			$contact_id = $GLOBALS['egw']->accounts->id2name(substr($contact_id,8),'person_id');
2971
+			$contact_id = $GLOBALS['egw']->accounts->id2name(substr($contact_id, 8), 'person_id');
2978 2972
 		}
2979 2973
 		if (!($contact = $this->read($contact_id)) || !$contact['jpegphoto'])
2980 2974
 		{
2981
-			Egw::redirect(Api\Image::find('addressbook','photo'));
2975
+			Egw::redirect(Api\Image::find('addressbook', 'photo'));
2982 2976
 		}
2983 2977
 		// use an etag over the image mapp
2984 2978
 		$etag = '"'.$contact['id'].':'.$contact['etag'].'"';
@@ -2990,7 +2984,7 @@  discard block
 block discarded – undo
2990 2984
 			// different url with different etag parameter will force a reload
2991 2985
 			if (isset($_GET['etag']))
2992 2986
 			{
2993
-				Api\Session::cache_control(30*86400);	// cache for 30 days
2987
+				Api\Session::cache_control(30 * 86400); // cache for 30 days
2994 2988
 			}
2995 2989
 			// if servers send a If-None-Match header, response with 304 Not Modified, if etag matches
2996 2990
 			if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] === $etag)
@@ -3042,15 +3036,15 @@  discard block
 block discarded – undo
3042 3036
 		echo $GLOBALS['egw']->framework->navbar();
3043 3037
 
3044 3038
 		// check if user has admin rights AND if a valid fileas type is given (Security)
3045
-		if (!$this->is_admin() || $_GET['type'] != '' && !in_array($_GET['type'],$this->fileas_types))
3039
+		if (!$this->is_admin() || $_GET['type'] != '' && !in_array($_GET['type'], $this->fileas_types))
3046 3040
 		{
3047 3041
 			echo '<h1>'.lang('Permission denied !!!')."</h1>\n";
3048 3042
 		}
3049 3043
 		else
3050 3044
 		{
3051 3045
 			$errors = null;
3052
-			$updated = parent::set_all_fileas($_GET['type'],(boolean)$_GET['all'],$errors,true);	// true = ignore Acl
3053
-			echo '<p style="margin-top: 20px;"><b>'.lang('%1 contacts updated (%2 errors).',$updated,$errors)."</b></p>\n";
3046
+			$updated = parent::set_all_fileas($_GET['type'], (boolean)$_GET['all'], $errors, true); // true = ignore Acl
3047
+			echo '<p style="margin-top: 20px;"><b>'.lang('%1 contacts updated (%2 errors).', $updated, $errors)."</b></p>\n";
3054 3048
 		}
3055 3049
 		echo $GLOBALS['egw']->framework->footer();
3056 3050
 	}
@@ -3074,8 +3068,8 @@  discard block
 block discarded – undo
3074 3068
 		else
3075 3069
 		{
3076 3070
 			$errors = null;
3077
-			$updated = parent::set_all_cleanup($errors,true);	// true = ignore Acl
3078
-			echo '<p style="margin-top: 20px;"><b>'.lang('%1 contacts updated (%2 errors).',$updated,$errors)."</b></p>\n";
3071
+			$updated = parent::set_all_cleanup($errors, true); // true = ignore Acl
3072
+			echo '<p style="margin-top: 20px;"><b>'.lang('%1 contacts updated (%2 errors).', $updated, $errors)."</b></p>\n";
3079 3073
 		}
3080 3074
 		echo $GLOBALS['egw']->framework->footer();
3081 3075
 	}
@@ -3088,7 +3082,7 @@  discard block
 block discarded – undo
3088 3082
 		if ($this->contact_repository == 'ldap' || !$content['id'] ||
3089 3083
 			$this->account_repository == 'ldap' && $content['account_id'])
3090 3084
 		{
3091
-			return;	// no history for ldap as history table only allows integer id's
3085
+			return; // no history for ldap as history table only allows integer id's
3092 3086
 		}
3093 3087
 		$content['history'] = array(
3094 3088
 			'id'	=>	$content['id'],
@@ -3103,7 +3097,7 @@  discard block
 block discarded – undo
3103 3097
 			),
3104 3098
 		);
3105 3099
 
3106
-		foreach($this->content_types as $id => $settings)
3100
+		foreach ($this->content_types as $id => $settings)
3107 3101
 		{
3108 3102
 			$content['history']['status-widgets']['tid'][$id] = $settings['name'];
3109 3103
 		}
Please login to merge, or discard this patch.