Completed
Push — 16.1 ( a3dd6a...89fc87 )
by Ralf
50:00 queued 35:26
created
api/src/Contacts/Ldap.php 2 patches
Spacing   +183 added lines, -185 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 	 *
39 39
 	 * @var string
40 40
 	 */
41
-	var $contacts_id='id';
41
+	var $contacts_id = 'id';
42 42
 
43 43
 	/**
44 44
 	* @var string $accountName holds the accountname of the current user
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
 	 *
87 87
 	 * @var string
88 88
 	 */
89
-	var $dn_attribute='uid';
89
+	var $dn_attribute = 'uid';
90 90
 
91 91
 	/**
92 92
 	 * Do NOT attempt to change DN (dn-attribute can NOT be part of schemas used in addressbook!)
@@ -113,9 +113,9 @@  discard block
 block discarded – undo
113 113
 	 * minimum: $this->columns_to_search = array('n_family','n_given','org_name','email');
114 114
 	 */
115 115
 	var $search_attributes = array(
116
-		'n_family','n_middle','n_given','org_name','org_unit',
117
-		'adr_one_locality','adr_two_locality','note',
118
-		'email','mozillasecondemail','uidnumber',
116
+		'n_family', 'n_middle', 'n_given', 'org_name', 'org_unit',
117
+		'adr_one_locality', 'adr_two_locality', 'note',
118
+		'email', 'mozillasecondemail', 'uidnumber',
119 119
 	);
120 120
 
121 121
 	/**
@@ -171,8 +171,8 @@  discard block
 block discarded – undo
171 171
 		#postOfficeBox
172 172
 		'mozillaabpersonalpha' => array(
173 173
 			'adr_one_street2'	=> 'mozillaworkstreet2',
174
-			'adr_one_countryname'	=> 'c',	// 2 letter country code
175
-			'adr_one_countrycode'	=> 'c',	// 2 letter country code
174
+			'adr_one_countryname'	=> 'c', // 2 letter country code
175
+			'adr_one_countrycode'	=> 'c', // 2 letter country code
176 176
 			'adr_two_street'	=> 'mozillahomestreet',
177 177
 			'adr_two_street2'	=> 'mozillahomestreet2',
178 178
 			'adr_two_locality'	=> 'mozillahomelocalityname',
@@ -186,8 +186,8 @@  discard block
 block discarded – undo
186 186
 		// similar to the newer mozillaAbPerson, but uses mozillaPostalAddress2 instead of mozillaStreet2
187 187
 		'mozillaorgperson' => array(
188 188
 			'adr_one_street2'	=> 'mozillapostaladdress2',
189
-			'adr_one_countrycode'	=> 'c',	// 2 letter country code
190
-			'adr_one_countryname'	=> 'co',	// human readable country name, must be after 'c' to take precedence on read!
189
+			'adr_one_countrycode'	=> 'c', // 2 letter country code
190
+			'adr_one_countryname'	=> 'co', // human readable country name, must be after 'c' to take precedence on read!
191 191
 			'adr_two_street'	=> 'mozillahomestreet',
192 192
 			'adr_two_street2'	=> 'mozillahomepostaladdress2',
193 193
 			'adr_two_locality'	=> 'mozillahomelocalityname',
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
 			'note'			=> 'note',
214 214
 			'tel_car'		=> 'carphone',
215 215
 			'tel_prefer'	=> 'primaryphone',
216
-			'cat_id'		=> 'category',	// special handling in _egw2evolutionperson method
216
+			'cat_id'		=> 'category', // special handling in _egw2evolutionperson method
217 217
 			'role'			=> 'businessrole',
218 218
 			'tel_assistent'	=> 'assistantphone',
219 219
 			'assistent'		=> 'assistantname',
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
 			'freebusy_uri'	=> 'freeBusyuri',
223 223
 			'calendar_uri'	=> 'calendaruri',
224 224
 			'tel_other'		=> 'otherphone',
225
-			'tel_cell_private' => 'callbackphone',	// not the best choice, but better then nothing
225
+			'tel_cell_private' => 'callbackphone', // not the best choice, but better then nothing
226 226
 		),
227 227
 		// additional schema can be added here, including special functions
228 228
 
@@ -270,10 +270,10 @@  discard block
 block discarded – undo
270 270
 	 * @param array $ldap_config =null default use from $GLOBALS['egw_info']['server']
271 271
 	 * @param resource $ds =null ldap connection to use
272 272
 	 */
273
-	function __construct(array $ldap_config=null, $ds=null)
273
+	function __construct(array $ldap_config = null, $ds = null)
274 274
 	{
275 275
 		//$this->db_data_cols 	= $this->stock_contact_fields + $this->non_contact_fields;
276
-		$this->accountName 		= $GLOBALS['egw_info']['user']['account_lid'];
276
+		$this->accountName = $GLOBALS['egw_info']['user']['account_lid'];
277 277
 
278 278
 		if ($ldap_config)
279 279
 		{
@@ -281,12 +281,12 @@  discard block
 block discarded – undo
281 281
 		}
282 282
 		else
283 283
 		{
284
-			$this->ldap_config =& $GLOBALS['egw_info']['server'];
284
+			$this->ldap_config = & $GLOBALS['egw_info']['server'];
285 285
 		}
286 286
 		$this->accountContactsDN	= $this->ldap_config['ldap_context'];
287
-		$this->allContactsDN		= $this->ldap_config['ldap_contact_context'];
288
-		$this->personalContactsDN	= 'ou=personal,ou=contacts,'. $this->allContactsDN;
289
-		$this->sharedContactsDN		= 'ou=shared,ou=contacts,'. $this->allContactsDN;
287
+		$this->allContactsDN = $this->ldap_config['ldap_contact_context'];
288
+		$this->personalContactsDN = 'ou=personal,ou=contacts,'.$this->allContactsDN;
289
+		$this->sharedContactsDN		= 'ou=shared,ou=contacts,'.$this->allContactsDN;
290 290
 
291 291
 		if ($ds)
292 292
 		{
@@ -298,9 +298,9 @@  discard block
 block discarded – undo
298 298
 		}
299 299
 		$this->ldapServerInfo = $GLOBALS['egw']->ldap->getLDAPServerInfo($this->ldap_config['ldap_contact_host']);
300 300
 
301
-		foreach($this->schema2egw as $attributes)
301
+		foreach ($this->schema2egw as $attributes)
302 302
 		{
303
-			$this->all_attributes = array_merge($this->all_attributes,array_values($attributes));
303
+			$this->all_attributes = array_merge($this->all_attributes, array_values($attributes));
304 304
 		}
305 305
 		$this->all_attributes = array_values(array_unique($this->all_attributes));
306 306
 
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
 			$this->ds = Api\Ldap::factory();
328 328
 		}
329 329
 		// if ldap is NOT the contact repository, we only do accounts and need to use the account-data
330
-		elseif (substr($GLOBALS['egw_info']['server']['contact_repository'],-4) != 'ldap')	// not (ldap or sql-ldap)
330
+		elseif (substr($GLOBALS['egw_info']['server']['contact_repository'], -4) != 'ldap')	// not (ldap or sql-ldap)
331 331
 		{
332 332
 			$this->ldap_config['ldap_contact_host'] = $this->ldap_config['ldap_host'];
333 333
 			$this->allContactsDN = $this->ldap_config['ldap_context'];
@@ -351,17 +351,17 @@  discard block
 block discarded – undo
351 351
 	function supported_fields()
352 352
 	{
353 353
 		$fields = array(
354
-			'id','tid','owner',
355
-			'n_middle','n_prefix','n_suffix',	// stored in the cn
356
-			'created','modified',				// automatic timestamps
357
-			'creator','modifier',				// automatic for non accounts
358
-			'private',							// true for personal addressbooks, false otherwise
354
+			'id', 'tid', 'owner',
355
+			'n_middle', 'n_prefix', 'n_suffix', // stored in the cn
356
+			'created', 'modified', // automatic timestamps
357
+			'creator', 'modifier', // automatic for non accounts
358
+			'private', // true for personal addressbooks, false otherwise
359 359
 		);
360
-		foreach($this->schema2egw as $objectclass => $mapping)
360
+		foreach ($this->schema2egw as $objectclass => $mapping)
361 361
 		{
362
-			if($this->ldapServerInfo->supportsObjectClass($objectclass))
362
+			if ($this->ldapServerInfo->supportsObjectClass($objectclass))
363 363
 			{
364
-				$fields = array_merge($fields,array_keys($mapping));
364
+				$fields = array_merge($fields, array_keys($mapping));
365 365
 			}
366 366
 		}
367 367
 		return array_values(array_unique($fields));
@@ -391,7 +391,7 @@  discard block
 block discarded – undo
391 391
 			return $this->id_filter(is_array($ids) ? array_shift($ids) : $ids);
392 392
 		}
393 393
 		$filter = array();
394
-		foreach($ids as $id)
394
+		foreach ($ids as $id)
395 395
 		{
396 396
 			$filter[] = $this->id_filter($id);
397 397
 		}
@@ -407,9 +407,9 @@  discard block
 block discarded – undo
407 407
 	function read($contact_id)
408 408
 	{
409 409
 		if (is_array($contact_id) && isset($contact_id['account_id']) ||
410
-			!is_array($contact_id) && substr($contact_id,0,8) == 'account:')
410
+			!is_array($contact_id) && substr($contact_id, 0, 8) == 'account:')
411 411
 		{
412
-			$filter = 'uidNumber='.(int)(is_array($contact_id) ? $contact_id['account_id'] : substr($contact_id,8));
412
+			$filter = 'uidNumber='.(int)(is_array($contact_id) ? $contact_id['account_id'] : substr($contact_id, 8));
413 413
 		}
414 414
 		else
415 415
 		{
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
 		// never allow to change the uidNumber (account_id) on update, as it could be misused by eg. xmlrpc or syncml
433 433
 		unset($ldapContact['uidnumber']);
434 434
 
435
-		unset($ldapContact['entryuuid']);	// not allowed to modify that, no need either
435
+		unset($ldapContact['entryuuid']); // not allowed to modify that, no need either
436 436
 
437 437
 		unset($ldapContact['objectClass']);
438 438
 	}
@@ -443,28 +443,28 @@  discard block
 block discarded – undo
443 443
 	 * @param array $keys if given $keys are copied to data before saveing => allows a save as
444 444
 	 * @return int 0 on success and errno != 0 else
445 445
 	 */
446
-	function save($keys=null)
446
+	function save($keys = null)
447 447
 	{
448 448
 		//error_log(__METHOD__."(".array2string($keys).") this->data=".array2string($this->data));
449
-		if(is_array($keys))
449
+		if (is_array($keys))
450 450
 		{
451
-			$this->data = is_array($this->data) ? array_merge($this->data,$keys) : $keys;
451
+			$this->data = is_array($this->data) ? array_merge($this->data, $keys) : $keys;
452 452
 		}
453 453
 
454
-		$data =& $this->data;
454
+		$data = & $this->data;
455 455
 		$isUpdate = false;
456 456
 		$ldapContact = array();
457 457
 
458 458
 		// generate addressbook dn
459
-		if((int)$data['owner'])
459
+		if ((int)$data['owner'])
460 460
 		{
461 461
 			// group address book
462
-			if(!($cn = strtolower($GLOBALS['egw']->accounts->id2name((int)$data['owner']))))
462
+			if (!($cn = strtolower($GLOBALS['egw']->accounts->id2name((int)$data['owner']))))
463 463
 			{
464 464
 				error_log('Unknown owner');
465 465
 				return true;
466 466
 			}
467
-			$baseDN = 'cn='. $cn .','.($data['owner'] < 0 ? $this->sharedContactsDN : $this->personalContactsDN);
467
+			$baseDN = 'cn='.$cn.','.($data['owner'] < 0 ? $this->sharedContactsDN : $this->personalContactsDN);
468 468
 		}
469 469
 		// only an admin or the user itself is allowed to change the data of an account
470 470
 		elseif ($data['account_id'] && ($GLOBALS['egw_info']['user']['apps']['admin'] ||
@@ -472,7 +472,7 @@  discard block
 block discarded – undo
472 472
 		{
473 473
 			// account
474 474
 			$baseDN = $this->accountContactsDN;
475
-			$cn	= false;
475
+			$cn = false;
476 476
 			// we need an admin connection
477 477
 			$this->connect(true);
478 478
 
@@ -485,7 +485,7 @@  discard block
 block discarded – undo
485 485
 		else
486 486
 		{
487 487
 			error_log("Permission denied, to write: data[owner]=$data[owner], data[account_id]=$data[account_id], account_id=".$GLOBALS['egw_info']['user']['account_id']);
488
-			return lang('Permission denied !!!');	// only admin or the user itself is allowd to write accounts!
488
+			return lang('Permission denied !!!'); // only admin or the user itself is allowd to write accounts!
489 489
 		}
490 490
 		// check if $baseDN exists. If not create it
491 491
 		if (($err = $this->_check_create_dn($baseDN)))
@@ -494,55 +494,54 @@  discard block
 block discarded – undo
494 494
 		}
495 495
 		// check the existing objectclasses of an entry, none = array() for new ones
496 496
 		$oldObjectclasses = array();
497
-		$attributes = array('dn','cn','objectClass',$this->dn_attribute,'mail');
497
+		$attributes = array('dn', 'cn', 'objectClass', $this->dn_attribute, 'mail');
498 498
 
499 499
 		$contactUID	= $this->data[$this->contacts_id];
500 500
 		if (!empty($contactUID) &&
501
-			($result = ldap_search($this->ds, $base=$this->allContactsDN, $this->id_filter($contactUID), $attributes)) &&
501
+			($result = ldap_search($this->ds, $base = $this->allContactsDN, $this->id_filter($contactUID), $attributes)) &&
502 502
 			($oldContactInfo = ldap_get_entries($this->ds, $result)) && $oldContactInfo['count'])
503 503
 		{
504 504
 			unset($oldContactInfo[0]['objectclass']['count']);
505
-			foreach($oldContactInfo[0]['objectclass'] as $objectclass)
505
+			foreach ($oldContactInfo[0]['objectclass'] as $objectclass)
506 506
 			{
507
-				$oldObjectclasses[]	= strtolower($objectclass);
507
+				$oldObjectclasses[] = strtolower($objectclass);
508 508
 			}
509 509
 		   	$isUpdate = true;
510 510
 		}
511 511
 
512
-		if(empty($contactUID))
512
+		if (empty($contactUID))
513 513
 		{
514 514
 			$ldapContact[$this->dn_attribute] = $this->data[$this->contacts_id] = $contactUID = md5(Api\Auth::randomstring(15));
515 515
 		}
516 516
 		//error_log(__METHOD__."() contactUID='$contactUID', isUpdate=".array2string($isUpdate).", oldContactInfo=".array2string($oldContactInfo));
517 517
 		// add for all supported objectclasses the objectclass and it's attributes
518
-		foreach($this->schema2egw as $objectclass => $mapping)
518
+		foreach ($this->schema2egw as $objectclass => $mapping)
519 519
 		{
520
-			if(!$this->ldapServerInfo->supportsObjectClass($objectclass)) continue;
520
+			if (!$this->ldapServerInfo->supportsObjectClass($objectclass)) continue;
521 521
 
522
-			if($objectclass != 'posixaccount' && !in_array($objectclass, $oldObjectclasses))
522
+			if ($objectclass != 'posixaccount' && !in_array($objectclass, $oldObjectclasses))
523 523
 			{
524 524
 				$ldapContact['objectClass'][] = $objectclass;
525 525
 			}
526 526
 			if (isset($this->required_subs[$objectclass]))
527 527
 			{
528
-				foreach($this->required_subs[$objectclass] as $sub)
528
+				foreach ($this->required_subs[$objectclass] as $sub)
529 529
 				{
530
-					if(!in_array($sub, $oldObjectclasses))
530
+					if (!in_array($sub, $oldObjectclasses))
531 531
 					{
532 532
 						$ldapContact['objectClass'][] = $sub;
533 533
 					}
534 534
 				}
535 535
 			}
536
-			foreach($mapping as $egwFieldName => $ldapFieldName)
536
+			foreach ($mapping as $egwFieldName => $ldapFieldName)
537 537
 			{
538 538
 				if (is_int($egwFieldName)) continue;
539
-				if(!empty($data[$egwFieldName]))
539
+				if (!empty($data[$egwFieldName]))
540 540
 				{
541 541
 					// dont convert the (binary) jpegPhoto!
542
-					$ldapContact[$ldapFieldName] = $ldapFieldName == 'jpegphoto' ? $data[$egwFieldName] :
543
-						Api\Translation::convert(trim($data[$egwFieldName]),$this->charset,'utf-8');
542
+					$ldapContact[$ldapFieldName] = $ldapFieldName == 'jpegphoto' ? $data[$egwFieldName] : Api\Translation::convert(trim($data[$egwFieldName]), $this->charset, 'utf-8');
544 543
 				}
545
-				elseif($isUpdate && isset($data[$egwFieldName]))
544
+				elseif ($isUpdate && isset($data[$egwFieldName]))
546 545
 				{
547 546
 					$ldapContact[$ldapFieldName] = array();
548 547
 				}
@@ -550,9 +549,9 @@  discard block
 block discarded – undo
550 549
 			}
551 550
 			// handling of special attributes, like cat_id in evolutionPerson
552 551
 			$egw2objectclass = '_egw2'.$objectclass;
553
-			if (method_exists($this,$egw2objectclass))
552
+			if (method_exists($this, $egw2objectclass))
554 553
 			{
555
-				$this->$egw2objectclass($ldapContact,$data,$isUpdate);
554
+				$this->$egw2objectclass($ldapContact, $data, $isUpdate);
556 555
 			}
557 556
 		}
558 557
 		if ($isUpdate)
@@ -570,11 +569,11 @@  discard block
 block discarded – undo
570 569
 			$needRecreation = false;
571 570
 
572 571
 			// add missing objectclasses
573
-			if($ldapContact['objectClass'] && ($missing=array_diff($ldapContact['objectClass'],$oldObjectclasses)))
572
+			if ($ldapContact['objectClass'] && ($missing = array_diff($ldapContact['objectClass'], $oldObjectclasses)))
574 573
 			{
575 574
 				if (!@ldap_mod_add($this->ds, $dn, array('objectClass' => $ldapContact['objectClass'])))
576 575
 				{
577
-					if(in_array(ldap_errno($this->ds),array(69,20)))
576
+					if (in_array(ldap_errno($this->ds), array(69, 20)))
578 577
 					{
579 578
 						// need to modify structural objectclass
580 579
 						$needRecreation = true;
@@ -583,15 +582,15 @@  discard block
 block discarded – undo
583 582
 					else
584 583
 					{
585 584
 						//echo "<p>ldap_mod_add($this->ds,'$dn',array(objectClass =>".print_r($ldapContact['objectClass'],true)."))</p>\n";
586
-						error_log(__METHOD__.'() '.__LINE__.' update of '. $dn .' failed errorcode: '. ldap_errno($this->ds) .' ('. ldap_error($this->ds) .')');
585
+						error_log(__METHOD__.'() '.__LINE__.' update of '.$dn.' failed errorcode: '.ldap_errno($this->ds).' ('.ldap_error($this->ds).')');
587 586
 						return $this->_error(__LINE__);
588 587
 					}
589 588
 				}
590 589
 			}
591 590
 
592 591
 			// check if we need to rename the DN or need to recreate the contact
593
-			$newRDN = $this->dn_attribute.'='. $ldapContact[$this->dn_attribute];
594
-			$newDN = $newRDN .','. $baseDN;
592
+			$newRDN = $this->dn_attribute.'='.$ldapContact[$this->dn_attribute];
593
+			$newDN = $newRDN.','.$baseDN;
595 594
 			if ($needRecreation)
596 595
 			{
597 596
 				$result = ldap_read($this->ds, $dn, 'objectclass=*');
@@ -602,20 +601,20 @@  discard block
 block discarded – undo
602 601
 				$newContact = $oldContact;
603 602
 				$newContact[$this->dn_attribute] = $ldapContact[$this->dn_attribute];
604 603
 
605
-				if(is_array($ldapContact['objectClass']) && count($ldapContact['objectClass']) > 0)
604
+				if (is_array($ldapContact['objectClass']) && count($ldapContact['objectClass']) > 0)
606 605
 				{
607
-					$newContact['objectclass'] = array_unique(array_map('strtolower',	// objectclasses my have different case
606
+					$newContact['objectclass'] = array_unique(array_map('strtolower', // objectclasses my have different case
608 607
 						array_merge($newContact['objectclass'], $ldapContact['objectClass'])));
609 608
 				}
610 609
 
611
-				if(!ldap_delete($this->ds, $dn))
610
+				if (!ldap_delete($this->ds, $dn))
612 611
 				{
613
-					error_log(__METHOD__.'() '.__LINE__.' delete of old '. $dn .' failed errorcode: '. ldap_errno($this->ds) .' ('. ldap_error($this->ds) .')');
612
+					error_log(__METHOD__.'() '.__LINE__.' delete of old '.$dn.' failed errorcode: '.ldap_errno($this->ds).' ('.ldap_error($this->ds).')');
614 613
 					return $this->_error(__LINE__);
615 614
 				}
616
-				if(!@ldap_add($this->ds, $newDN, $newContact))
615
+				if (!@ldap_add($this->ds, $newDN, $newContact))
617 616
 				{
618
-					error_log(__METHOD__.'() '.__LINE__.' re-create contact as '. $newDN .' failed errorcode: '. ldap_errno($this->ds) .' ('. ldap_error($this->ds) .') newContact='.array2string($newContact));
617
+					error_log(__METHOD__.'() '.__LINE__.' re-create contact as '.$newDN.' failed errorcode: '.ldap_errno($this->ds).' ('.ldap_error($this->ds).') newContact='.array2string($newContact));
619 618
 					// if adding with new objectclass or dn fails, re-add deleted contact
620 619
 					@ldap_add($this->ds, $dn, $oldContact);
621 620
 					return $this->_error(__LINE__);
@@ -644,22 +643,22 @@  discard block
 block discarded – undo
644 643
 
645 644
 			if (!@ldap_modify($this->ds, $dn, $ldapContact))
646 645
 			{
647
-				error_log(__METHOD__.'() '.__LINE__.' update of '. $dn .' failed errorcode: '. ldap_errno($this->ds) .' ('. ldap_error($this->ds) .') ldapContact='.array2string($ldapContact));
646
+				error_log(__METHOD__.'() '.__LINE__.' update of '.$dn.' failed errorcode: '.ldap_errno($this->ds).' ('.ldap_error($this->ds).') ldapContact='.array2string($ldapContact));
648 647
 				return $this->_error(__LINE__);
649 648
 			}
650 649
 		}
651 650
 		else
652 651
 		{
653
-			$dn = $this->dn_attribute.'='. $ldapContact[$this->dn_attribute] .','. $baseDN;
654
-			unset($ldapContact['entryuuid']);	// trying to write it, gives an error
652
+			$dn = $this->dn_attribute.'='.$ldapContact[$this->dn_attribute].','.$baseDN;
653
+			unset($ldapContact['entryuuid']); // trying to write it, gives an error
655 654
 
656 655
 			if (!@ldap_add($this->ds, $dn, $ldapContact))
657 656
 			{
658
-				error_log(__METHOD__.'() '.__LINE__.' add of '. $dn .' failed errorcode: '. ldap_errno($this->ds) .' ('. ldap_error($this->ds) .') ldapContact='.array2string($ldapContact));
657
+				error_log(__METHOD__.'() '.__LINE__.' add of '.$dn.' failed errorcode: '.ldap_errno($this->ds).' ('.ldap_error($this->ds).') ldapContact='.array2string($ldapContact));
659 658
 				return $this->_error(__LINE__);
660 659
 			}
661 660
 		}
662
-		return 0;	// Ok, no error
661
+		return 0; // Ok, no error
663 662
 	}
664 663
 
665 664
 	/**
@@ -668,28 +667,28 @@  discard block
 block discarded – undo
668 667
 	 * @param array $keys if given array with col => value pairs to characterise the rows to delete
669 668
 	 * @return int affected rows, should be 1 if ok, 0 if an error
670 669
 	 */
671
-	function delete($keys=null)
670
+	function delete($keys = null)
672 671
 	{
673 672
 		// single entry
674
-		if($keys[$this->contacts_id]) $keys = array( 0 => $keys);
673
+		if ($keys[$this->contacts_id]) $keys = array(0 => $keys);
675 674
 
676
-		if(!is_array($keys))
675
+		if (!is_array($keys))
677 676
 		{
678
-			$keys = array( $keys);
677
+			$keys = array($keys);
679 678
 		}
680 679
 
681 680
 		$ret = 0;
682 681
 
683 682
 		$attributes = array('dn');
684 683
 
685
-		foreach($keys as $entry)
684
+		foreach ($keys as $entry)
686 685
 		{
687 686
 			$entry = Api\Ldap::quote(is_array($entry) ? $entry['id'] : $entry);
688
-			if(($result = ldap_search($this->ds, $this->allContactsDN,
687
+			if (($result = ldap_search($this->ds, $this->allContactsDN,
689 688
 				"(|(entryUUID=$entry)(uid=$entry))", $attributes)))
690 689
 			{
691 690
 				$contactInfo = ldap_get_entries($this->ds, $result);
692
-				if(@ldap_delete($this->ds, $contactInfo[0]['dn']))
691
+				if (@ldap_delete($this->ds, $contactInfo[0]['dn']))
693 692
 				{
694 693
 					$ret++;
695 694
 				}
@@ -717,10 +716,10 @@  discard block
 block discarded – undo
717 716
 	 * @param boolean $need_full_no_count =false If true an unlimited query is run to determine the total number of rows, default false
718 717
 	 * @return array of matching rows (the row is an array of the cols) or False
719 718
 	 */
720
-	function &search($criteria,$only_keys=True,$order_by='',$extra_cols='',$wildcard='',$empty=False,$op='AND',$start=false,$filter=null,$join='',$need_full_no_count=false)
719
+	function &search($criteria, $only_keys = True, $order_by = '', $extra_cols = '', $wildcard = '', $empty = False, $op = 'AND', $start = false, $filter = null, $join = '', $need_full_no_count = false)
721 720
 	{
722 721
 		//error_log(__METHOD__."(".array2string($criteria).", ".array2string($only_keys).", '$order_by', ".array2string($extra_cols).", '$wildcard', '$empty', '$op', ".array2string($start).", ".array2string($filter).")");
723
-		unset($only_keys, $extra_cols, $empty, $join, $need_full_no_count);	// not used, but required by function signature
722
+		unset($only_keys, $extra_cols, $empty, $join, $need_full_no_count); // not used, but required by function signature
724 723
 
725 724
 		if (is_array($filter['owner']))
726 725
 		{
@@ -742,7 +741,7 @@  discard block
 block discarded – undo
742 741
 			'created' => 'createtimestamp',
743 742
 			'modified' => 'modifytimestamp',
744 743
 		);
745
-		foreach($filter as $key => $value)
744
+		foreach ($filter as $key => $value)
746 745
 		{
747 746
 			$matches = null;
748 747
 			if (is_int($key) && preg_match('/^(contact_)?(modified|created)([<=>]+)([0-9]+)$/', $value, $matches))
@@ -758,11 +757,11 @@  discard block
 block discarded – undo
758 757
 			}
759 758
 		}
760 759
 
761
-		if((int)$filter['owner'])
760
+		if ((int)$filter['owner'])
762 761
 		{
763 762
 			if (!($accountName = $GLOBALS['egw']->accounts->id2name($filter['owner']))) return false;
764 763
 
765
-			$searchDN = 'cn='. Api\Ldap::quote(strtolower($accountName)) .',';
764
+			$searchDN = 'cn='.Api\Ldap::quote(strtolower($accountName)).',';
766 765
 
767 766
 			if ($filter['owner'] < 0)
768 767
 			{
@@ -786,7 +785,7 @@  discard block
 block discarded – undo
786 785
 			$addressbookType = self::ACCOUNTS;
787 786
 		}
788 787
 		// create the search filter
789
-		switch($addressbookType)
788
+		switch ($addressbookType)
790 789
 		{
791 790
 			case self::ACCOUNTS:
792 791
 				$objectFilter = $this->accountsFilter;
@@ -801,28 +800,28 @@  discard block
 block discarded – undo
801 800
 		// shadowExpire>= does NOT work, as shadow schema only specifies integerMatch and not integerOrderingMatch :-(
802 801
 
803 802
 		$searchFilter = '';
804
-		if(is_array($criteria) && count($criteria) > 0)
803
+		if (is_array($criteria) && count($criteria) > 0)
805 804
 		{
806 805
 			$wildcard = $wildcard === '%' ? '*' : '';
807 806
 			$searchFilter = '';
808
-			foreach($criteria as $egwSearchKey => $searchValue)
807
+			foreach ($criteria as $egwSearchKey => $searchValue)
809 808
 			{
810
-				if (in_array($egwSearchKey, array('id','contact_id')))
809
+				if (in_array($egwSearchKey, array('id', 'contact_id')))
811 810
 				{
812 811
 					$searchFilter .= $this->ids_filter($searchValue);
813 812
 					continue;
814 813
 				}
815
-				foreach($this->schema2egw as $mapping)
814
+				foreach ($this->schema2egw as $mapping)
816 815
 				{
817
-					if(($ldapSearchKey = $mapping[$egwSearchKey]))
816
+					if (($ldapSearchKey = $mapping[$egwSearchKey]))
818 817
 					{
819
-						$searchString = Api\Translation::convert($searchValue,$this->charset,'utf-8');
818
+						$searchString = Api\Translation::convert($searchValue, $this->charset, 'utf-8');
820 819
 						$searchFilter .= '('.$ldapSearchKey.'='.$wildcard.Api\Ldap::quote($searchString).$wildcard.')';
821 820
 						break;
822 821
 					}
823 822
 				}
824 823
 			}
825
-			if($op == 'AND')
824
+			if ($op == 'AND')
826 825
 			{
827 826
 				$searchFilter = "(&$searchFilter)";
828 827
 			}
@@ -841,9 +840,9 @@  discard block
 block discarded – undo
841 840
 		// only return certain owners --> unset not matching ones
842 841
 		if ($owner_filter)
843 842
 		{
844
-			foreach($rows as $k => $row)
843
+			foreach ($rows as $k => $row)
845 844
 			{
846
-				if (!in_array($row['owner'],$owner_filter))
845
+				if (!in_array($row['owner'], $owner_filter))
847 846
 				{
848 847
 					unset($rows[$k]);
849 848
 					--$this->total;
@@ -854,18 +853,18 @@  discard block
 block discarded – undo
854 853
 		{
855 854
 			$order = array();
856 855
 			$sort = 'ASC';
857
-			foreach(explode(',',$order_by) as $o)
856
+			foreach (explode(',', $order_by) as $o)
858 857
 			{
859
-				if (substr($o,0,8) == 'contact_') $o = substr($o,8);
860
-				if (substr($o,-4) == ' ASC')
858
+				if (substr($o, 0, 8) == 'contact_') $o = substr($o, 8);
859
+				if (substr($o, -4) == ' ASC')
861 860
 				{
862 861
 					$sort = 'ASC';
863
-					$order[] = substr($o,0,-4);
862
+					$order[] = substr($o, 0, -4);
864 863
 				}
865
-				elseif (substr($o,-5) == ' DESC')
864
+				elseif (substr($o, -5) == ' DESC')
866 865
 				{
867 866
 					$sort = 'DESC';
868
-					$order[] = substr($o,0,-5);
867
+					$order[] = substr($o, 0, -5);
869 868
 				}
870 869
 				elseif ($o)
871 870
 				{
@@ -874,9 +873,9 @@  discard block
 block discarded – undo
874 873
 			}
875 874
 			usort($rows, function($a, $b) use ($order, $sort)
876 875
 			{
877
-				foreach($order as $f)
876
+				foreach ($order as $f)
878 877
 				{
879
-					if($sort == 'ASC')
878
+					if ($sort == 'ASC')
880 879
 					{
881 880
 						$strc = strcmp($a[$f], $b[$f]);
882 881
 					}
@@ -892,13 +891,13 @@  discard block
 block discarded – undo
892 891
 		// if requested ($start !== false) return only limited resultset
893 892
 		if (is_array($start))
894 893
 		{
895
-			list($start,$offset) = $start;
894
+			list($start, $offset) = $start;
896 895
 		}
897
-		if(is_numeric($start) && is_numeric($offset) && $offset >= 0)
896
+		if (is_numeric($start) && is_numeric($offset) && $offset >= 0)
898 897
 		{
899 898
 			return array_slice($rows, $start, $offset);
900 899
 		}
901
-		elseif(is_numeric($start))
900
+		elseif (is_numeric($start))
902 901
 		{
903 902
 			return array_slice($rows, $start, $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']);
904 903
 		}
@@ -916,11 +915,11 @@  discard block
 block discarded – undo
916 915
 		if (!is_array($filter)) return '';
917 916
 
918 917
 		$filters = '';
919
-		foreach($filter as $key => $value)
918
+		foreach ($filter as $key => $value)
920 919
 		{
921 920
 			if ($key != 'cat_id' && $key != 'account_id' && !$value) continue;
922 921
 
923
-			switch((string) $key)
922
+			switch ((string)$key)
924 923
 			{
925 924
 				case 'owner':	// already handled
926 925
 				case 'tid':		// ignored
@@ -934,7 +933,7 @@  discard block
 block discarded – undo
934 933
 					elseif ($value)
935 934
 					{
936 935
 						if (is_array($value)) $filters .= '(|';
937
-						foreach((array)$value as $value)
936
+						foreach ((array)$value as $value)
938 937
 						{
939 938
 							$filters .= '(uidNumber='.(int)$value.')';
940 939
 						}
@@ -947,7 +946,7 @@  discard block
 block discarded – undo
947 946
 					{
948 947
 						$filters .= '(!(category=*))';
949 948
 					}
950
-					elseif((int)$value)
949
+					elseif ((int)$value)
951 950
 					{
952 951
 						if (!is_object($GLOBALS['egw']->categories))
953 952
 						{
@@ -955,10 +954,10 @@  discard block
 block discarded – undo
955 954
 						}
956 955
 						$cats = $GLOBALS['egw']->categories->return_all_children((int)$value);
957 956
 						if (count($cats) > 1) $filters .= '(|';
958
-						foreach($cats as $cat)
957
+						foreach ($cats as $cat)
959 958
 						{
960 959
 							$catName = Api\Translation::convert(
961
-								$GLOBALS['egw']->categories->id2name($cat),$this->charset,'utf-8');
960
+								$GLOBALS['egw']->categories->id2name($cat), $this->charset, 'utf-8');
962 961
 							$filters .= '(category='.Api\Ldap::quote($catName).')';
963 962
 						}
964 963
 						if (count($cats) > 1) $filters .= ')';
@@ -967,7 +966,7 @@  discard block
 block discarded – undo
967 966
 
968 967
 				case 'carddav_name':
969 968
 					if (!is_array($value)) $value = array($value);
970
-					foreach($value as &$v)
969
+					foreach ($value as &$v)
971 970
 					{
972 971
 						$v = basename($v, '.vcf');
973 972
 					}
@@ -985,28 +984,27 @@  discard block
 block discarded – undo
985 984
 					$matches = null;
986 985
 					if (!is_int($key))
987 986
 					{
988
-						foreach($this->schema2egw as $mapping)
987
+						foreach ($this->schema2egw as $mapping)
989 988
 						{
990 989
 							if (isset($mapping[$key]))
991 990
 							{
992 991
 								// todo: value = "!''"
993
-								$filters .= '('.$mapping[$key].'='.($value === "!''" ? '*' :
994
-									Api\Ldap::quote(Api\Translation::convert($value,$this->charset,'utf-8'))).')';
992
+								$filters .= '('.$mapping[$key].'='.($value === "!''" ? '*' : Api\Ldap::quote(Api\Translation::convert($value, $this->charset, 'utf-8'))).')';
995 993
 								break;
996 994
 							}
997 995
 						}
998 996
 					}
999 997
 					// filter for letter-search
1000
-					elseif (preg_match("/^([^ ]+) ".preg_quote($GLOBALS['egw']->db->capabilities[Api\Db::CAPABILITY_CASE_INSENSITIV_LIKE])." '(.*)%'$/",$value,$matches))
998
+					elseif (preg_match("/^([^ ]+) ".preg_quote($GLOBALS['egw']->db->capabilities[Api\Db::CAPABILITY_CASE_INSENSITIV_LIKE])." '(.*)%'$/", $value, $matches))
1001 999
 					{
1002
-						list(,$name,$value) = $matches;
1003
-						if (strpos($name,'.') !== false) list(,$name) = explode('.',$name);
1004
-						foreach($this->schema2egw as $mapping)
1000
+						list(,$name, $value) = $matches;
1001
+						if (strpos($name, '.') !== false) list(,$name) = explode('.', $name);
1002
+						foreach ($this->schema2egw as $mapping)
1005 1003
 						{
1006 1004
 							if (isset($mapping[$name]))
1007 1005
 							{
1008 1006
 								$filters .= '('.$mapping[$name].'='.Api\Ldap::quote(
1009
-									Api\Translation::convert($value,$this->charset,'utf-8')).'*)';
1007
+									Api\Translation::convert($value, $this->charset, 'utf-8')).'*)';
1010 1008
 								break;
1011 1009
 							}
1012 1010
 						}
@@ -1030,7 +1028,7 @@  discard block
 block discarded – undo
1030 1028
 		{
1031 1029
 			$filter .= '(|';
1032 1030
 			// unfortunately we have no group-membership attribute in LDAP, like in AD
1033
-			foreach($GLOBALS['egw']->accounts->members($gid, true) as $account_id)
1031
+			foreach ($GLOBALS['egw']->accounts->members($gid, true) as $account_id)
1034 1032
 			{
1035 1033
 				$filter .= '(uidNumber='.(int)$account_id.')';
1036 1034
 			}
@@ -1052,7 +1050,7 @@  discard block
 block discarded – undo
1052 1050
 	 * @param array $_skipPlugins =null schema-plugins to skip
1053 1051
 	 * @return array/boolean with eGW contacts or false on error
1054 1052
 	 */
1055
-	function _searchLDAP($_ldapContext, $_filter, $_attributes, $_addressbooktype, array $_skipPlugins=null)
1053
+	function _searchLDAP($_ldapContext, $_filter, $_attributes, $_addressbooktype, array $_skipPlugins = null)
1056 1054
 	{
1057 1055
 		$this->total = 0;
1058 1056
 
@@ -1065,7 +1063,7 @@  discard block
 block discarded – undo
1065 1063
 
1066 1064
 		//error_log(__METHOD__."('$_ldapContext', '$_filter', ".array2string($_attributes).", $_addressbooktype)");
1067 1065
 
1068
-		if($_addressbooktype == self::ALL || $_ldapContext == $this->allContactsDN)
1066
+		if ($_addressbooktype == self::ALL || $_ldapContext == $this->allContactsDN)
1069 1067
 		{
1070 1068
 			$result = ldap_search($this->ds, $_ldapContext, $_filter, $_attributes, 0, $this->ldapLimit);
1071 1069
 		}
@@ -1073,36 +1071,36 @@  discard block
 block discarded – undo
1073 1071
 		{
1074 1072
 			$result = @ldap_list($this->ds, $_ldapContext, $_filter, $_attributes, 0, $this->ldapLimit);
1075 1073
 		}
1076
-		if(!$result || !$entries = ldap_get_entries($this->ds, $result)) return array();
1074
+		if (!$result || !$entries = ldap_get_entries($this->ds, $result)) return array();
1077 1075
 		//error_log(__METHOD__."('$_ldapContext', '$_filter', ".array2string($_attributes).", $_addressbooktype) result of $entries[count]");
1078 1076
 
1079 1077
 		$this->total = $entries['count'];
1080
-		foreach($entries as $i => $entry)
1078
+		foreach ($entries as $i => $entry)
1081 1079
 		{
1082
-			if (!is_int($i)) continue;	// eg. count
1080
+			if (!is_int($i)) continue; // eg. count
1083 1081
 
1084 1082
 			$contact = array(
1085 1083
 				'id'  => $entry['uid'][0] ? $entry['uid'][0] : $entry['entryuuid'][0],
1086
-				'tid' => 'n',	// the type id for the addressbook
1084
+				'tid' => 'n', // the type id for the addressbook
1087 1085
 			);
1088
-			foreach($entry['objectclass'] as $ii => $objectclass)
1086
+			foreach ($entry['objectclass'] as $ii => $objectclass)
1089 1087
 			{
1090 1088
 				$objectclass = strtolower($objectclass);
1091 1089
 				if (!is_int($ii) || !isset($this->schema2egw[$objectclass]))
1092 1090
 				{
1093
-					continue;	// eg. count or unsupported objectclass
1091
+					continue; // eg. count or unsupported objectclass
1094 1092
 				}
1095
-				foreach($this->schema2egw[$objectclass] as $egwFieldName => $ldapFieldName)
1093
+				foreach ($this->schema2egw[$objectclass] as $egwFieldName => $ldapFieldName)
1096 1094
 				{
1097
-					if(!empty($entry[$ldapFieldName][0]) && !is_int($egwFieldName) && !isset($contact[$egwFieldName]))
1095
+					if (!empty($entry[$ldapFieldName][0]) && !is_int($egwFieldName) && !isset($contact[$egwFieldName]))
1098 1096
 					{
1099
-						$contact[$egwFieldName] = Api\Translation::convert($entry[$ldapFieldName][0],'utf-8');
1097
+						$contact[$egwFieldName] = Api\Translation::convert($entry[$ldapFieldName][0], 'utf-8');
1100 1098
 					}
1101 1099
 				}
1102 1100
 				$objectclass2egw = '_'.$objectclass.'2egw';
1103
-				if (!in_array($objectclass2egw, (array)$_skipPlugins) &&method_exists($this,$objectclass2egw))
1101
+				if (!in_array($objectclass2egw, (array)$_skipPlugins) && method_exists($this, $objectclass2egw))
1104 1102
 				{
1105
-					if (($ret=$this->$objectclass2egw($contact,$entry)) === false)
1103
+					if (($ret = $this->$objectclass2egw($contact, $entry)) === false)
1106 1104
 					{
1107 1105
 						--$this->total;
1108 1106
 						continue 2;
@@ -1112,20 +1110,20 @@  discard block
 block discarded – undo
1112 1110
 			// read binary jpegphoto only for one result == call by read
1113 1111
 			if ($this->total == 1 && isset($entry['jpegphoto'][0]))
1114 1112
 			{
1115
-				$bin = ldap_get_values_len($this->ds,ldap_first_entry($this->ds,$result),'jpegphoto');
1113
+				$bin = ldap_get_values_len($this->ds, ldap_first_entry($this->ds, $result), 'jpegphoto');
1116 1114
 				$contact['jpegphoto'] = $bin[0];
1117 1115
 			}
1118 1116
 			$matches = null;
1119
-			if(preg_match('/cn=([^,]+),'.preg_quote($this->personalContactsDN,'/').'$/i',$entry['dn'],$matches))
1117
+			if (preg_match('/cn=([^,]+),'.preg_quote($this->personalContactsDN, '/').'$/i', $entry['dn'], $matches))
1120 1118
 			{
1121 1119
 				// personal addressbook
1122
-				$contact['owner'] = $GLOBALS['egw']->accounts->name2id($matches[1],'account_lid','u');
1120
+				$contact['owner'] = $GLOBALS['egw']->accounts->name2id($matches[1], 'account_lid', 'u');
1123 1121
 				$contact['private'] = 0;
1124 1122
 			}
1125
-			elseif(preg_match('/cn=([^,]+),'.preg_quote($this->sharedContactsDN,'/').'$/i',$entry['dn'],$matches))
1123
+			elseif (preg_match('/cn=([^,]+),'.preg_quote($this->sharedContactsDN, '/').'$/i', $entry['dn'], $matches))
1126 1124
 			{
1127 1125
 				// group addressbook
1128
-				$contact['owner'] = $GLOBALS['egw']->accounts->name2id($matches[1],'account_lid','g');
1126
+				$contact['owner'] = $GLOBALS['egw']->accounts->name2id($matches[1], 'account_lid', 'g');
1129 1127
 				$contact['private'] = 0;
1130 1128
 			}
1131 1129
 			else
@@ -1134,12 +1132,12 @@  discard block
 block discarded – undo
1134 1132
 				$contact['owner'] = 0;
1135 1133
 				$contact['private'] = 0;
1136 1134
 			}
1137
-			foreach(array(
1135
+			foreach (array(
1138 1136
 				'createtimestamp' => 'created',
1139 1137
 				'modifytimestamp' => 'modified',
1140 1138
 			) as $ldapFieldName => $egwFieldName)
1141 1139
 			{
1142
-				if(!empty($entry[$ldapFieldName][0]))
1140
+				if (!empty($entry[$ldapFieldName][0]))
1143 1141
 				{
1144 1142
 					$contact[$egwFieldName] = $this->_ldap2ts($entry[$ldapFieldName][0]);
1145 1143
 				}
@@ -1158,8 +1156,8 @@  discard block
 block discarded – undo
1158 1156
 	 */
1159 1157
 	static function _ldap2ts($date)
1160 1158
 	{
1161
-		return gmmktime(substr($date,8,2),substr($date,10,2),substr($date,12,2),
1162
-			substr($date,4,2),substr($date,6,2),substr($date,0,4));
1159
+		return gmmktime(substr($date, 8, 2), substr($date, 10, 2), substr($date, 12, 2),
1160
+			substr($date, 4, 2), substr($date, 6, 2), substr($date, 0, 4));
1163 1161
 	}
1164 1162
 
1165 1163
 	/**
@@ -1182,22 +1180,22 @@  discard block
 block discarded – undo
1182 1180
 	function _check_create_dn($baseDN)
1183 1181
 	{
1184 1182
 		// check if $baseDN exists. If not create new one
1185
-		if(@ldap_read($this->ds, $baseDN, 'objectclass=*'))
1183
+		if (@ldap_read($this->ds, $baseDN, 'objectclass=*'))
1186 1184
 		{
1187 1185
 			return false;
1188 1186
 		}
1189 1187
 		//error_log(__METHOD__."('$baseDN') !ldap_read({$this->ds}, '$baseDN', 'objectclass=*') ldap_errno()=".ldap_errno($this->ds).', ldap_error()='.ldap_error($this->ds).get_class($this));
1190
-		if(ldap_errno($this->ds) != 32 || substr($baseDN,0,3) != 'cn=')
1188
+		if (ldap_errno($this->ds) != 32 || substr($baseDN, 0, 3) != 'cn=')
1191 1189
 		{
1192 1190
 			error_log(__METHOD__."('$baseDN') baseDN does NOT exist and we cant/wont create it! ldap_errno()=".ldap_errno($this->ds).', ldap_error()='.ldap_error($this->ds));
1193
-			return $this->_error(__LINE__);	// baseDN does NOT exist and we cant/wont create it
1191
+			return $this->_error(__LINE__); // baseDN does NOT exist and we cant/wont create it
1194 1192
 		}
1195 1193
 		// create a admin connection to add the needed DN
1196 1194
 		$adminLDAP = new ldap;
1197 1195
 		$adminDS = $adminLDAP->ldapConnect();
1198 1196
 
1199
-		list(,$ou) = explode(',',$baseDN);
1200
-		foreach(array(
1197
+		list(,$ou) = explode(',', $baseDN);
1198
+		foreach (array(
1201 1199
 			'ou=contacts,'.$this->allContactsDN,
1202 1200
 			$ou.',ou=contacts,'.$this->allContactsDN,
1203 1201
 			$baseDN,
@@ -1206,16 +1204,16 @@  discard block
 block discarded – undo
1206 1204
 			if (!@ldap_read($this->ds, $dn, 'objectclass=*') && ldap_errno($this->ds) == 32)
1207 1205
 			{
1208 1206
 				// entry does not exist, lets try to create it
1209
-				list($top) = explode(',',$dn);
1210
-				list($var,$val) = explode('=',$top);
1207
+				list($top) = explode(',', $dn);
1208
+				list($var, $val) = explode('=', $top);
1211 1209
 				$data = array(
1212 1210
 					'objectClass' => $var == 'cn' ? 'organizationalRole' : 'organizationalUnit',
1213 1211
 					$var => $val,
1214 1212
 				);
1215
-				if(!@ldap_add($adminDS, $dn, $data))
1213
+				if (!@ldap_add($adminDS, $dn, $data))
1216 1214
 				{
1217 1215
 					//echo "<p>ldap_add($adminDS,'$dn',".print_r($data,true).")</p>\n";
1218
-					$err = lang("Can't create dn %1",$dn).': '.$this->_error(__LINE__,$adminDS);
1216
+					$err = lang("Can't create dn %1", $dn).': '.$this->_error(__LINE__, $adminDS);
1219 1217
 					$adminLDAP->ldapDisconnect();
1220 1218
 					return $err;
1221 1219
 				}
@@ -1232,7 +1230,7 @@  discard block
 block discarded – undo
1232 1230
 	 * @param int $line
1233 1231
 	 * @return string
1234 1232
 	 */
1235
-	function _error($line,$ds=null)
1233
+	function _error($line, $ds = null)
1236 1234
 	{
1237 1235
 		return ldap_error($ds ? $ds : $this->ds).': '.__CLASS__.': '.$line;
1238 1236
 	}
@@ -1247,27 +1245,27 @@  discard block
 block discarded – undo
1247 1245
 	 * @param array $data eGW contact data
1248 1246
 	 * @param boolean $isUpdate
1249 1247
 	 */
1250
-	function _egw2evolutionperson(&$ldapContact,$data,$isUpdate)
1248
+	function _egw2evolutionperson(&$ldapContact, $data, $isUpdate)
1251 1249
 	{
1252
-		if(!empty($data['cat_id']))
1250
+		if (!empty($data['cat_id']))
1253 1251
 		{
1254 1252
 			$ldapContact['category'] = array();
1255
-			foreach(is_array($data['cat_id']) ? $data['cat_id'] : explode(',',$data['cat_id'])  as $cat)
1253
+			foreach (is_array($data['cat_id']) ? $data['cat_id'] : explode(',', $data['cat_id'])  as $cat)
1256 1254
 			{
1257 1255
 				$ldapContact['category'][] = Api\Translation::convert(
1258
-					Api\Categories::id2name($cat),$this->charset,'utf-8');
1256
+					Api\Categories::id2name($cat), $this->charset, 'utf-8');
1259 1257
 			}
1260 1258
 		}
1261
-		foreach(array(
1262
-			'postaladdress' => $data['adr_one_street'] .'$'. $data['adr_one_locality'] .', '. $data['adr_one_region'] .'$'. $data['adr_one_postalcode'] .'$$'. $data['adr_one_countryname'],
1263
-			'homepostaladdress' => $data['adr_two_street'] .'$'. $data['adr_two_locality'] .', '. $data['adr_two_region'] .'$'. $data['adr_two_postalcode'] .'$$'. $data['adr_two_countryname'],
1259
+		foreach (array(
1260
+			'postaladdress' => $data['adr_one_street'].'$'.$data['adr_one_locality'].', '.$data['adr_one_region'].'$'.$data['adr_one_postalcode'].'$$'.$data['adr_one_countryname'],
1261
+			'homepostaladdress' => $data['adr_two_street'].'$'.$data['adr_two_locality'].', '.$data['adr_two_region'].'$'.$data['adr_two_postalcode'].'$$'.$data['adr_two_countryname'],
1264 1262
 		) as $attr => $value)
1265 1263
 		{
1266
-			if($value != '$, $$$')
1264
+			if ($value != '$, $$$')
1267 1265
 			{
1268
-				$ldapContact[$attr] = Api\Translation::convert($value,$this->charset,'utf-8');
1266
+				$ldapContact[$attr] = Api\Translation::convert($value, $this->charset, 'utf-8');
1269 1267
 			}
1270
-			elseif($isUpdate)
1268
+			elseif ($isUpdate)
1271 1269
 			{
1272 1270
 				$ldapContact[$attr] = array();
1273 1271
 			}
@@ -1277,7 +1275,7 @@  discard block
 block discarded – undo
1277 1275
 		{
1278 1276
 			$ldapContact['primaryphone'] = $data[$data['tel_prefer']];
1279 1277
 		}
1280
-		elseif($isUpdate)
1278
+		elseif ($isUpdate)
1281 1279
 		{
1282 1280
 			$ldapContact['primaryphone'] = array();
1283 1281
 		}
@@ -1292,23 +1290,23 @@  discard block
 block discarded – undo
1292 1290
 	 * @param array &$contact already copied fields according to the mapping
1293 1291
 	 * @param array $data eGW contact data
1294 1292
 	 */
1295
-	function _evolutionperson2egw(&$contact,$data)
1293
+	function _evolutionperson2egw(&$contact, $data)
1296 1294
 	{
1297 1295
 		if ($data['category'] && is_array($data['category']))
1298 1296
 		{
1299 1297
 			$contact['cat_id'] = array();
1300
-			foreach($data['category'] as $iii => $cat)
1298
+			foreach ($data['category'] as $iii => $cat)
1301 1299
 			{
1302 1300
 				if (!is_int($iii)) continue;
1303 1301
 
1304 1302
 				$contact['cat_id'][] = $GLOBALS['egw']->categories->name2id($cat);
1305 1303
 			}
1306
-			if ($contact['cat_id']) $contact['cat_id'] = implode(',',$contact['cat_id']);
1304
+			if ($contact['cat_id']) $contact['cat_id'] = implode(',', $contact['cat_id']);
1307 1305
 		}
1308 1306
 		if ($data['primaryphone'])
1309 1307
 		{
1310
-			unset($contact['tel_prefer']);	// to not find itself
1311
-			$contact['tel_prefer'] = array_search($data['primaryphone'][0],$contact);
1308
+			unset($contact['tel_prefer']); // to not find itself
1309
+			$contact['tel_prefer'] = array_search($data['primaryphone'][0], $contact);
1312 1310
 		}
1313 1311
 	}
1314 1312
 
@@ -1321,10 +1319,10 @@  discard block
 block discarded – undo
1321 1319
 	 * @param array &$contact already copied fields according to the mapping
1322 1320
 	 * @param array $data eGW contact data
1323 1321
 	 */
1324
-	function _inetorgperson2egw(&$contact, $data, $cn='cn')
1322
+	function _inetorgperson2egw(&$contact, $data, $cn = 'cn')
1325 1323
 	{
1326 1324
 		$matches = null;
1327
-		if(empty($data['givenname'][0]))
1325
+		if (empty($data['givenname'][0]))
1328 1326
 		{
1329 1327
 			$parts = explode($data['sn'][0], $data[$cn][0]);
1330 1328
 			$contact['n_prefix'] = trim($parts[0]);
@@ -1332,8 +1330,8 @@  discard block
 block discarded – undo
1332 1330
 		}
1333 1331
 		// iOS addressbook either use "givenname surname" or "surname givenname" depending on contact preference display-order
1334 1332
 		// in full name, so we need to check for both when trying to parse prefix, middle name and suffix form full name
1335
-		elseif (preg_match($preg='/^(.*) *'.preg_quote($data['givenname'][0], '/').' *(.*) *'.preg_quote($data['sn'][0], '/').' *(.*)$/', $data[$cn][0], $matches) ||
1336
-			preg_match($preg='/^(.*) *'.preg_quote($data['sn'][0], '/').'[, ]*(.*) *'.preg_quote($data['givenname'][0], '/').' *(.*)$/', $data[$cn][0], $matches))
1333
+		elseif (preg_match($preg = '/^(.*) *'.preg_quote($data['givenname'][0], '/').' *(.*) *'.preg_quote($data['sn'][0], '/').' *(.*)$/', $data[$cn][0], $matches) ||
1334
+			preg_match($preg = '/^(.*) *'.preg_quote($data['sn'][0], '/').'[, ]*(.*) *'.preg_quote($data['givenname'][0], '/').' *(.*)$/', $data[$cn][0], $matches))
1337 1335
 		{
1338 1336
 			list(,$contact['n_prefix'], $contact['n_middle'], $contact['n_suffix']) = $matches;
1339 1337
 			//error_log(__METHOD__."() preg_match('$preg', '{$data[$cn][0]}') = ".array2string($matches));
@@ -1354,11 +1352,11 @@  discard block
 block discarded – undo
1354 1352
 	 * @param array &$contact already copied fields according to the mapping
1355 1353
 	 * @param array $data eGW contact data
1356 1354
 	 */
1357
-	function _posixaccount2egw(&$contact,$data)
1355
+	function _posixaccount2egw(&$contact, $data)
1358 1356
 	{
1359
-		unset($contact);	// not used, but required by function signature
1360
-		static $shadowExpireNow=null;
1361
-		if (!isset($shadowExpireNow)) $shadowExpireNow = floor((time()-date('Z'))/86400);
1357
+		unset($contact); // not used, but required by function signature
1358
+		static $shadowExpireNow = null;
1359
+		if (!isset($shadowExpireNow)) $shadowExpireNow = floor((time() - date('Z')) / 86400);
1362 1360
 
1363 1361
 		// exclude expired or deactivated accounts
1364 1362
 		if (isset($data['shadowexpire']) && $data['shadowexpire'][0] <= $shadowExpireNow)
@@ -1376,7 +1374,7 @@  discard block
 block discarded – undo
1376 1374
 	 * @param array &$contact already copied fields according to the mapping
1377 1375
 	 * @param array $data eGW contact data
1378 1376
 	 */
1379
-	function _mozillaabpersonalpha2egw(&$contact,$data)
1377
+	function _mozillaabpersonalpha2egw(&$contact, $data)
1380 1378
 	{
1381 1379
 		if ($data['c'])
1382 1380
 		{
@@ -1394,7 +1392,7 @@  discard block
 block discarded – undo
1394 1392
 	 * @param array $data eGW contact data
1395 1393
 	 * @param boolean $isUpdate
1396 1394
 	 */
1397
-	function _egw2mozillaabpersonalpha(&$ldapContact,$data,$isUpdate)
1395
+	function _egw2mozillaabpersonalpha(&$ldapContact, $data, $isUpdate)
1398 1396
 	{
1399 1397
 		if ($data['adr_one_countrycode'])
1400 1398
 		{
@@ -1423,9 +1421,9 @@  discard block
 block discarded – undo
1423 1421
 	 * @param array &$contact already copied fields according to the mapping
1424 1422
 	 * @param array $data eGW contact data
1425 1423
 	 */
1426
-	function _mozillaorgperson2egw(&$contact,$data)
1424
+	function _mozillaorgperson2egw(&$contact, $data)
1427 1425
 	{
1428
-		unset($contact, $data);	// not used, but required by function signature
1426
+		unset($contact, $data); // not used, but required by function signature
1429 1427
 		// no special handling necessary, as it supports two distinct attributes: c, cn
1430 1428
 	}
1431 1429
 
@@ -1439,7 +1437,7 @@  discard block
 block discarded – undo
1439 1437
 	 * @param array $data eGW contact data
1440 1438
 	 * @param boolean $isUpdate
1441 1439
 	 */
1442
-	function _egw2mozillaorgperson(&$ldapContact,$data,$isUpdate)
1440
+	function _egw2mozillaorgperson(&$ldapContact, $data, $isUpdate)
1443 1441
 	{
1444 1442
 		if ($data['adr_one_countrycode'])
1445 1443
 		{
@@ -1467,7 +1465,7 @@  discard block
 block discarded – undo
1467 1465
 	 * @param int $account_id account-id of the old owner
1468 1466
 	 * @param int $new_owner account-id of the new owner
1469 1467
 	 */
1470
-	function change_owner($account_id,$new_owner)
1468
+	function change_owner($account_id, $new_owner)
1471 1469
 	{
1472 1470
 		error_log(__METHOD__."($account_id,$new_owner) not yet implemented");
1473 1471
 	}
Please login to merge, or discard this patch.
Braces   +101 added lines, -26 removed lines patch added patch discarded remove patch
@@ -327,9 +327,12 @@  discard block
 block discarded – undo
327 327
 			$this->ds = Api\Ldap::factory();
328 328
 		}
329 329
 		// if ldap is NOT the contact repository, we only do accounts and need to use the account-data
330
-		elseif (substr($GLOBALS['egw_info']['server']['contact_repository'],-4) != 'ldap')	// not (ldap or sql-ldap)
330
+		elseif (substr($GLOBALS['egw_info']['server']['contact_repository'],-4) != 'ldap')
331
+		{
332
+			// not (ldap or sql-ldap)
331 333
 		{
332 334
 			$this->ldap_config['ldap_contact_host'] = $this->ldap_config['ldap_host'];
335
+		}
333 336
 			$this->allContactsDN = $this->ldap_config['ldap_context'];
334 337
 			$this->ds = Api\Ldap::factory();
335 338
 		}
@@ -413,7 +416,10 @@  discard block
 block discarded – undo
413 416
 		}
414 417
 		else
415 418
 		{
416
-			if (is_array($contact_id)) $contact_id = isset ($contact_id['id']) ? $contact_id['id'] : $contact_id['uid'];
419
+			if (is_array($contact_id))
420
+			{
421
+				$contact_id = isset ($contact_id['id']) ? $contact_id['id'] : $contact_id['uid'];
422
+			}
417 423
 			$filter = $this->id_filter($contact_id);
418 424
 		}
419 425
 		$rows = $this->_searchLDAP($this->allContactsDN,
@@ -517,7 +523,10 @@  discard block
 block discarded – undo
517 523
 		// add for all supported objectclasses the objectclass and it's attributes
518 524
 		foreach($this->schema2egw as $objectclass => $mapping)
519 525
 		{
520
-			if(!$this->ldapServerInfo->supportsObjectClass($objectclass)) continue;
526
+			if(!$this->ldapServerInfo->supportsObjectClass($objectclass))
527
+			{
528
+				continue;
529
+			}
521 530
 
522 531
 			if($objectclass != 'posixaccount' && !in_array($objectclass, $oldObjectclasses))
523 532
 			{
@@ -535,7 +544,10 @@  discard block
 block discarded – undo
535 544
 			}
536 545
 			foreach($mapping as $egwFieldName => $ldapFieldName)
537 546
 			{
538
-				if (is_int($egwFieldName)) continue;
547
+				if (is_int($egwFieldName))
548
+				{
549
+					continue;
550
+				}
539 551
 				if(!empty($data[$egwFieldName]))
540 552
 				{
541 553
 					// dont convert the (binary) jpegPhoto!
@@ -671,7 +683,10 @@  discard block
 block discarded – undo
671 683
 	function delete($keys=null)
672 684
 	{
673 685
 		// single entry
674
-		if($keys[$this->contacts_id]) $keys = array( 0 => $keys);
686
+		if($keys[$this->contacts_id])
687
+		{
688
+			$keys = array( 0 => $keys);
689
+		}
675 690
 
676 691
 		if(!is_array($keys))
677 692
 		{
@@ -760,7 +775,10 @@  discard block
 block discarded – undo
760 775
 
761 776
 		if((int)$filter['owner'])
762 777
 		{
763
-			if (!($accountName = $GLOBALS['egw']->accounts->id2name($filter['owner']))) return false;
778
+			if (!($accountName = $GLOBALS['egw']->accounts->id2name($filter['owner'])))
779
+			{
780
+				return false;
781
+			}
764 782
 
765 783
 			$searchDN = 'cn='. Api\Ldap::quote(strtolower($accountName)) .',';
766 784
 
@@ -856,7 +874,10 @@  discard block
 block discarded – undo
856 874
 			$sort = 'ASC';
857 875
 			foreach(explode(',',$order_by) as $o)
858 876
 			{
859
-				if (substr($o,0,8) == 'contact_') $o = substr($o,8);
877
+				if (substr($o,0,8) == 'contact_')
878
+				{
879
+					$o = substr($o,8);
880
+				}
860 881
 				if (substr($o,-4) == ' ASC')
861 882
 				{
862 883
 					$sort = 'ASC';
@@ -884,7 +905,10 @@  discard block
 block discarded – undo
884 905
 					{
885 906
 						$strc = strcmp($b[$f], $a[$f]);
886 907
 					}
887
-					if ($strc) return $strc;
908
+					if ($strc)
909
+					{
910
+						return $strc;
911
+					}
888 912
 				}
889 913
 				return 0;
890 914
 			});
@@ -913,12 +937,18 @@  discard block
 block discarded – undo
913 937
 	 */
914 938
 	function _colFilter($filter)
915 939
 	{
916
-		if (!is_array($filter)) return '';
940
+		if (!is_array($filter))
941
+		{
942
+			return '';
943
+		}
917 944
 
918 945
 		$filters = '';
919 946
 		foreach($filter as $key => $value)
920 947
 		{
921
-			if ($key != 'cat_id' && $key != 'account_id' && !$value) continue;
948
+			if ($key != 'cat_id' && $key != 'account_id' && !$value)
949
+			{
950
+				continue;
951
+			}
922 952
 
923 953
 			switch((string) $key)
924 954
 			{
@@ -933,12 +963,18 @@  discard block
 block discarded – undo
933 963
 					}
934 964
 					elseif ($value)
935 965
 					{
936
-						if (is_array($value)) $filters .= '(|';
966
+						if (is_array($value))
967
+						{
968
+							$filters .= '(|';
969
+						}
937 970
 						foreach((array)$value as $value)
938 971
 						{
939 972
 							$filters .= '(uidNumber='.(int)$value.')';
940 973
 						}
941
-						if (is_array($value)) $filters .= ')';
974
+						if (is_array($value))
975
+						{
976
+							$filters .= ')';
977
+						}
942 978
 					}
943 979
 					break;
944 980
 
@@ -954,19 +990,28 @@  discard block
 block discarded – undo
954 990
 							$GLOBALS['egw']->categories = new Api\Categories();
955 991
 						}
956 992
 						$cats = $GLOBALS['egw']->categories->return_all_children((int)$value);
957
-						if (count($cats) > 1) $filters .= '(|';
993
+						if (count($cats) > 1)
994
+						{
995
+							$filters .= '(|';
996
+						}
958 997
 						foreach($cats as $cat)
959 998
 						{
960 999
 							$catName = Api\Translation::convert(
961 1000
 								$GLOBALS['egw']->categories->id2name($cat),$this->charset,'utf-8');
962 1001
 							$filters .= '(category='.Api\Ldap::quote($catName).')';
963 1002
 						}
964
-						if (count($cats) > 1) $filters .= ')';
1003
+						if (count($cats) > 1)
1004
+						{
1005
+							$filters .= ')';
1006
+						}
965 1007
 					}
966 1008
 					break;
967 1009
 
968 1010
 				case 'carddav_name':
969
-					if (!is_array($value)) $value = array($value);
1011
+					if (!is_array($value))
1012
+					{
1013
+						$value = array($value);
1014
+					}
970 1015
 					foreach($value as &$v)
971 1016
 					{
972 1017
 						$v = basename($v, '.vcf');
@@ -1000,7 +1045,10 @@  discard block
 block discarded – undo
1000 1045
 					elseif (preg_match("/^([^ ]+) ".preg_quote($GLOBALS['egw']->db->capabilities[Api\Db::CAPABILITY_CASE_INSENSITIV_LIKE])." '(.*)%'$/",$value,$matches))
1001 1046
 					{
1002 1047
 						list(,$name,$value) = $matches;
1003
-						if (strpos($name,'.') !== false) list(,$name) = explode('.',$name);
1048
+						if (strpos($name,'.') !== false)
1049
+						{
1050
+							list(,$name) = explode('.',$name);
1051
+						}
1004 1052
 						foreach($this->schema2egw as $mapping)
1005 1053
 						{
1006 1054
 							if (isset($mapping[$name]))
@@ -1073,13 +1121,20 @@  discard block
 block discarded – undo
1073 1121
 		{
1074 1122
 			$result = @ldap_list($this->ds, $_ldapContext, $_filter, $_attributes, 0, $this->ldapLimit);
1075 1123
 		}
1076
-		if(!$result || !$entries = ldap_get_entries($this->ds, $result)) return array();
1124
+		if(!$result || !$entries = ldap_get_entries($this->ds, $result))
1125
+		{
1126
+			return array();
1127
+		}
1077 1128
 		//error_log(__METHOD__."('$_ldapContext', '$_filter', ".array2string($_attributes).", $_addressbooktype) result of $entries[count]");
1078 1129
 
1079 1130
 		$this->total = $entries['count'];
1080 1131
 		foreach($entries as $i => $entry)
1081 1132
 		{
1082
-			if (!is_int($i)) continue;	// eg. count
1133
+			if (!is_int($i))
1134
+			{
1135
+				continue;
1136
+			}
1137
+			// eg. count
1083 1138
 
1084 1139
 			$contact = array(
1085 1140
 				'id'  => $entry['uid'][0] ? $entry['uid'][0] : $entry['entryuuid'][0],
@@ -1299,11 +1354,17 @@  discard block
 block discarded – undo
1299 1354
 			$contact['cat_id'] = array();
1300 1355
 			foreach($data['category'] as $iii => $cat)
1301 1356
 			{
1302
-				if (!is_int($iii)) continue;
1357
+				if (!is_int($iii))
1358
+				{
1359
+					continue;
1360
+				}
1303 1361
 
1304 1362
 				$contact['cat_id'][] = $GLOBALS['egw']->categories->name2id($cat);
1305 1363
 			}
1306
-			if ($contact['cat_id']) $contact['cat_id'] = implode(',',$contact['cat_id']);
1364
+			if ($contact['cat_id'])
1365
+			{
1366
+				$contact['cat_id'] = implode(',',$contact['cat_id']);
1367
+			}
1307 1368
 		}
1308 1369
 		if ($data['primaryphone'])
1309 1370
 		{
@@ -1358,7 +1419,10 @@  discard block
 block discarded – undo
1358 1419
 	{
1359 1420
 		unset($contact);	// not used, but required by function signature
1360 1421
 		static $shadowExpireNow=null;
1361
-		if (!isset($shadowExpireNow)) $shadowExpireNow = floor((time()-date('Z'))/86400);
1422
+		if (!isset($shadowExpireNow))
1423
+		{
1424
+			$shadowExpireNow = floor((time()-date('Z'))/86400);
1425
+		}
1362 1426
 
1363 1427
 		// exclude expired or deactivated accounts
1364 1428
 		if (isset($data['shadowexpire']) && $data['shadowexpire'][0] <= $shadowExpireNow)
@@ -1403,9 +1467,13 @@  discard block
 block discarded – undo
1403 1467
 		elseif ($data['adr_one_countryname'])
1404 1468
 		{
1405 1469
 			$ldapContact['c'] = Api\Country::country_code($data['adr_one_countryname']);
1406
-			if ($ldapContact['c'] && strlen($ldapContact['c']) > 2)	// Bad countryname when "custom" selected!
1470
+			if ($ldapContact['c'] && strlen($ldapContact['c']) > 2)
1407 1471
 			{
1408
-				$ldapContact['c'] = array(); // should return error...
1472
+				// Bad countryname when "custom" selected!
1473
+			{
1474
+				$ldapContact['c'] = array();
1475
+			}
1476
+			// should return error...
1409 1477
 			}
1410 1478
 		}
1411 1479
 		elseif ($isUpdate)
@@ -1444,14 +1512,21 @@  discard block
 block discarded – undo
1444 1512
 		if ($data['adr_one_countrycode'])
1445 1513
 		{
1446 1514
 			$ldapContact['c'] = $data['adr_one_countrycode'];
1447
-			if ($isUpdate) $ldapContact['co'] = array();
1515
+			if ($isUpdate)
1516
+			{
1517
+				$ldapContact['co'] = array();
1518
+			}
1448 1519
 		}
1449 1520
 		elseif ($data['adr_one_countryname'])
1450 1521
 		{
1451 1522
 			$ldapContact['c'] = Api\Country::country_code($data['adr_one_countryname']);
1452
-			if ($ldapContact['c'] && strlen($ldapContact['c']) > 2)	// Bad countryname when "custom" selected!
1523
+			if ($ldapContact['c'] && strlen($ldapContact['c']) > 2)
1524
+			{
1525
+				// Bad countryname when "custom" selected!
1453 1526
 			{
1454
-				$ldapContact['c'] = array(); // should return error...
1527
+				$ldapContact['c'] = array();
1528
+			}
1529
+			// should return error...
1455 1530
 			}
1456 1531
 		}
1457 1532
 		elseif ($isUpdate)
Please login to merge, or discard this patch.