@@ -38,7 +38,7 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
@@ -943,7 +942,7 @@ discard block |
||
| 943 | 942 | { |
| 944 | 943 | $filters .= '(!(category=*))'; |
| 945 | 944 | } |
| 946 | - elseif((int)$value) |
|
| 945 | + elseif ((int)$value) |
|
| 947 | 946 | { |
| 948 | 947 | if (!is_object($GLOBALS['egw']->categories)) |
| 949 | 948 | { |
@@ -951,10 +950,10 @@ discard block |
||
| 951 | 950 | } |
| 952 | 951 | $cats = $GLOBALS['egw']->categories->return_all_children((int)$value); |
| 953 | 952 | if (count($cats) > 1) $filters .= '(|'; |
| 954 | - foreach($cats as $cat) |
|
| 953 | + foreach ($cats as $cat) |
|
| 955 | 954 | { |
| 956 | 955 | $catName = Api\Translation::convert( |
| 957 | - $GLOBALS['egw']->categories->id2name($cat),$this->charset,'utf-8'); |
|
| 956 | + $GLOBALS['egw']->categories->id2name($cat), $this->charset, 'utf-8'); |
|
| 958 | 957 | $filters .= '(category='.Api\Ldap::quote($catName).')'; |
| 959 | 958 | } |
| 960 | 959 | if (count($cats) > 1) $filters .= ')'; |
@@ -963,7 +962,7 @@ discard block |
||
| 963 | 962 | |
| 964 | 963 | case 'carddav_name': |
| 965 | 964 | if (!is_array($value)) $value = array($value); |
| 966 | - foreach($value as &$v) |
|
| 965 | + foreach ($value as &$v) |
|
| 967 | 966 | { |
| 968 | 967 | $v = basename($v, '.vcf'); |
| 969 | 968 | } |
@@ -981,28 +980,27 @@ discard block |
||
| 981 | 980 | $matches = null; |
| 982 | 981 | if (!is_int($key)) |
| 983 | 982 | { |
| 984 | - foreach($this->schema2egw as $mapping) |
|
| 983 | + foreach ($this->schema2egw as $mapping) |
|
| 985 | 984 | { |
| 986 | 985 | if (isset($mapping[$key])) |
| 987 | 986 | { |
| 988 | 987 | // todo: value = "!''" |
| 989 | - $filters .= '('.$mapping[$key].'='.($value === "!''" ? '*' : |
|
| 990 | - Api\Ldap::quote(Api\Translation::convert($value,$this->charset,'utf-8'))).')'; |
|
| 988 | + $filters .= '('.$mapping[$key].'='.($value === "!''" ? '*' : Api\Ldap::quote(Api\Translation::convert($value, $this->charset, 'utf-8'))).')'; |
|
| 991 | 989 | break; |
| 992 | 990 | } |
| 993 | 991 | } |
| 994 | 992 | } |
| 995 | 993 | // filter for letter-search |
| 996 | - elseif (preg_match("/^([^ ]+) ".preg_quote($GLOBALS['egw']->db->capabilities[Api\Db::CAPABILITY_CASE_INSENSITIV_LIKE])." '(.*)%'$/",$value,$matches)) |
|
| 994 | + elseif (preg_match("/^([^ ]+) ".preg_quote($GLOBALS['egw']->db->capabilities[Api\Db::CAPABILITY_CASE_INSENSITIV_LIKE])." '(.*)%'$/", $value, $matches)) |
|
| 997 | 995 | { |
| 998 | - list(,$name,$value) = $matches; |
|
| 999 | - if (strpos($name,'.') !== false) list(,$name) = explode('.',$name); |
|
| 1000 | - foreach($this->schema2egw as $mapping) |
|
| 996 | + list(,$name, $value) = $matches; |
|
| 997 | + if (strpos($name, '.') !== false) list(,$name) = explode('.', $name); |
|
| 998 | + foreach ($this->schema2egw as $mapping) |
|
| 1001 | 999 | { |
| 1002 | 1000 | if (isset($mapping[$name])) |
| 1003 | 1001 | { |
| 1004 | 1002 | $filters .= '('.$mapping[$name].'='.Api\Ldap::quote( |
| 1005 | - Api\Translation::convert($value,$this->charset,'utf-8')).'*)'; |
|
| 1003 | + Api\Translation::convert($value, $this->charset, 'utf-8')).'*)'; |
|
| 1006 | 1004 | break; |
| 1007 | 1005 | } |
| 1008 | 1006 | } |
@@ -1026,7 +1024,7 @@ discard block |
||
| 1026 | 1024 | { |
| 1027 | 1025 | $filter .= '(|'; |
| 1028 | 1026 | // unfortunately we have no group-membership attribute in LDAP, like in AD |
| 1029 | - foreach($GLOBALS['egw']->accounts->members($gid, true) as $account_id) |
|
| 1027 | + foreach ($GLOBALS['egw']->accounts->members($gid, true) as $account_id) |
|
| 1030 | 1028 | { |
| 1031 | 1029 | $filter .= '(uidNumber='.(int)$account_id.')'; |
| 1032 | 1030 | } |
@@ -1048,7 +1046,7 @@ discard block |
||
| 1048 | 1046 | * @param array $_skipPlugins =null schema-plugins to skip |
| 1049 | 1047 | * @return array/boolean with eGW contacts or false on error |
| 1050 | 1048 | */ |
| 1051 | - function _searchLDAP($_ldapContext, $_filter, $_attributes, $_addressbooktype, array $_skipPlugins=null) |
|
| 1049 | + function _searchLDAP($_ldapContext, $_filter, $_attributes, $_addressbooktype, array $_skipPlugins = null) |
|
| 1052 | 1050 | { |
| 1053 | 1051 | $this->total = 0; |
| 1054 | 1052 | |
@@ -1061,7 +1059,7 @@ discard block |
||
| 1061 | 1059 | |
| 1062 | 1060 | //error_log(__METHOD__."('$_ldapContext', '$_filter', ".array2string($_attributes).", $_addressbooktype)"); |
| 1063 | 1061 | |
| 1064 | - if($_addressbooktype == self::ALL || $_ldapContext == $this->allContactsDN) |
|
| 1062 | + if ($_addressbooktype == self::ALL || $_ldapContext == $this->allContactsDN) |
|
| 1065 | 1063 | { |
| 1066 | 1064 | $result = ldap_search($this->ds, $_ldapContext, $_filter, $_attributes, 0, $this->ldapLimit); |
| 1067 | 1065 | } |
@@ -1069,36 +1067,36 @@ discard block |
||
| 1069 | 1067 | { |
| 1070 | 1068 | $result = @ldap_list($this->ds, $_ldapContext, $_filter, $_attributes, 0, $this->ldapLimit); |
| 1071 | 1069 | } |
| 1072 | - if(!$result || !$entries = ldap_get_entries($this->ds, $result)) return array(); |
|
| 1070 | + if (!$result || !$entries = ldap_get_entries($this->ds, $result)) return array(); |
|
| 1073 | 1071 | //error_log(__METHOD__."('$_ldapContext', '$_filter', ".array2string($_attributes).", $_addressbooktype) result of $entries[count]"); |
| 1074 | 1072 | |
| 1075 | 1073 | $this->total = $entries['count']; |
| 1076 | - foreach($entries as $i => $entry) |
|
| 1074 | + foreach ($entries as $i => $entry) |
|
| 1077 | 1075 | { |
| 1078 | - if (!is_int($i)) continue; // eg. count |
|
| 1076 | + if (!is_int($i)) continue; // eg. count |
|
| 1079 | 1077 | |
| 1080 | 1078 | $contact = array( |
| 1081 | 1079 | 'id' => $entry['uid'][0] ? $entry['uid'][0] : $entry['entryuuid'][0], |
| 1082 | - 'tid' => 'n', // the type id for the addressbook |
|
| 1080 | + 'tid' => 'n', // the type id for the addressbook |
|
| 1083 | 1081 | ); |
| 1084 | - foreach($entry['objectclass'] as $ii => $objectclass) |
|
| 1082 | + foreach ($entry['objectclass'] as $ii => $objectclass) |
|
| 1085 | 1083 | { |
| 1086 | 1084 | $objectclass = strtolower($objectclass); |
| 1087 | 1085 | if (!is_int($ii) || !isset($this->schema2egw[$objectclass])) |
| 1088 | 1086 | { |
| 1089 | - continue; // eg. count or unsupported objectclass |
|
| 1087 | + continue; // eg. count or unsupported objectclass |
|
| 1090 | 1088 | } |
| 1091 | - foreach($this->schema2egw[$objectclass] as $egwFieldName => $ldapFieldName) |
|
| 1089 | + foreach ($this->schema2egw[$objectclass] as $egwFieldName => $ldapFieldName) |
|
| 1092 | 1090 | { |
| 1093 | - if(!empty($entry[$ldapFieldName][0]) && !is_int($egwFieldName) && !isset($contact[$egwFieldName])) |
|
| 1091 | + if (!empty($entry[$ldapFieldName][0]) && !is_int($egwFieldName) && !isset($contact[$egwFieldName])) |
|
| 1094 | 1092 | { |
| 1095 | - $contact[$egwFieldName] = Api\Translation::convert($entry[$ldapFieldName][0],'utf-8'); |
|
| 1093 | + $contact[$egwFieldName] = Api\Translation::convert($entry[$ldapFieldName][0], 'utf-8'); |
|
| 1096 | 1094 | } |
| 1097 | 1095 | } |
| 1098 | 1096 | $objectclass2egw = '_'.$objectclass.'2egw'; |
| 1099 | - if (!in_array($objectclass2egw, (array)$_skipPlugins) &&method_exists($this,$objectclass2egw)) |
|
| 1097 | + if (!in_array($objectclass2egw, (array)$_skipPlugins) && method_exists($this, $objectclass2egw)) |
|
| 1100 | 1098 | { |
| 1101 | - if (($ret=$this->$objectclass2egw($contact,$entry)) === false) |
|
| 1099 | + if (($ret = $this->$objectclass2egw($contact, $entry)) === false) |
|
| 1102 | 1100 | { |
| 1103 | 1101 | --$this->total; |
| 1104 | 1102 | continue 2; |
@@ -1108,20 +1106,20 @@ discard block |
||
| 1108 | 1106 | // read binary jpegphoto only for one result == call by read |
| 1109 | 1107 | if ($this->total == 1 && isset($entry['jpegphoto'][0])) |
| 1110 | 1108 | { |
| 1111 | - $bin = ldap_get_values_len($this->ds,ldap_first_entry($this->ds,$result),'jpegphoto'); |
|
| 1109 | + $bin = ldap_get_values_len($this->ds, ldap_first_entry($this->ds, $result), 'jpegphoto'); |
|
| 1112 | 1110 | $contact['jpegphoto'] = $bin[0]; |
| 1113 | 1111 | } |
| 1114 | 1112 | $matches = null; |
| 1115 | - if(preg_match('/cn=([^,]+),'.preg_quote($this->personalContactsDN,'/').'$/i',$entry['dn'],$matches)) |
|
| 1113 | + if (preg_match('/cn=([^,]+),'.preg_quote($this->personalContactsDN, '/').'$/i', $entry['dn'], $matches)) |
|
| 1116 | 1114 | { |
| 1117 | 1115 | // personal addressbook |
| 1118 | - $contact['owner'] = $GLOBALS['egw']->accounts->name2id($matches[1],'account_lid','u'); |
|
| 1116 | + $contact['owner'] = $GLOBALS['egw']->accounts->name2id($matches[1], 'account_lid', 'u'); |
|
| 1119 | 1117 | $contact['private'] = 0; |
| 1120 | 1118 | } |
| 1121 | - elseif(preg_match('/cn=([^,]+),'.preg_quote($this->sharedContactsDN,'/').'$/i',$entry['dn'],$matches)) |
|
| 1119 | + elseif (preg_match('/cn=([^,]+),'.preg_quote($this->sharedContactsDN, '/').'$/i', $entry['dn'], $matches)) |
|
| 1122 | 1120 | { |
| 1123 | 1121 | // group addressbook |
| 1124 | - $contact['owner'] = $GLOBALS['egw']->accounts->name2id($matches[1],'account_lid','g'); |
|
| 1122 | + $contact['owner'] = $GLOBALS['egw']->accounts->name2id($matches[1], 'account_lid', 'g'); |
|
| 1125 | 1123 | $contact['private'] = 0; |
| 1126 | 1124 | } |
| 1127 | 1125 | else |
@@ -1130,12 +1128,12 @@ discard block |
||
| 1130 | 1128 | $contact['owner'] = 0; |
| 1131 | 1129 | $contact['private'] = 0; |
| 1132 | 1130 | } |
| 1133 | - foreach(array( |
|
| 1131 | + foreach (array( |
|
| 1134 | 1132 | 'createtimestamp' => 'created', |
| 1135 | 1133 | 'modifytimestamp' => 'modified', |
| 1136 | 1134 | ) as $ldapFieldName => $egwFieldName) |
| 1137 | 1135 | { |
| 1138 | - if(!empty($entry[$ldapFieldName][0])) |
|
| 1136 | + if (!empty($entry[$ldapFieldName][0])) |
|
| 1139 | 1137 | { |
| 1140 | 1138 | $contact[$egwFieldName] = $this->_ldap2ts($entry[$ldapFieldName][0]); |
| 1141 | 1139 | } |
@@ -1154,8 +1152,8 @@ discard block |
||
| 1154 | 1152 | */ |
| 1155 | 1153 | static function _ldap2ts($date) |
| 1156 | 1154 | { |
| 1157 | - return gmmktime(substr($date,8,2),substr($date,10,2),substr($date,12,2), |
|
| 1158 | - substr($date,4,2),substr($date,6,2),substr($date,0,4)); |
|
| 1155 | + return gmmktime(substr($date, 8, 2), substr($date, 10, 2), substr($date, 12, 2), |
|
| 1156 | + substr($date, 4, 2), substr($date, 6, 2), substr($date, 0, 4)); |
|
| 1159 | 1157 | } |
| 1160 | 1158 | |
| 1161 | 1159 | /** |
@@ -1178,22 +1176,22 @@ discard block |
||
| 1178 | 1176 | function _check_create_dn($baseDN) |
| 1179 | 1177 | { |
| 1180 | 1178 | // check if $baseDN exists. If not create new one |
| 1181 | - if(@ldap_read($this->ds, $baseDN, 'objectclass=*')) |
|
| 1179 | + if (@ldap_read($this->ds, $baseDN, 'objectclass=*')) |
|
| 1182 | 1180 | { |
| 1183 | 1181 | return false; |
| 1184 | 1182 | } |
| 1185 | 1183 | //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)); |
| 1186 | - if(ldap_errno($this->ds) != 32 || substr($baseDN,0,3) != 'cn=') |
|
| 1184 | + if (ldap_errno($this->ds) != 32 || substr($baseDN, 0, 3) != 'cn=') |
|
| 1187 | 1185 | { |
| 1188 | 1186 | 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)); |
| 1189 | - return $this->_error(__LINE__); // baseDN does NOT exist and we cant/wont create it |
|
| 1187 | + return $this->_error(__LINE__); // baseDN does NOT exist and we cant/wont create it |
|
| 1190 | 1188 | } |
| 1191 | 1189 | // create a admin connection to add the needed DN |
| 1192 | 1190 | $adminLDAP = new ldap; |
| 1193 | 1191 | $adminDS = $adminLDAP->ldapConnect(); |
| 1194 | 1192 | |
| 1195 | - list(,$ou) = explode(',',$baseDN); |
|
| 1196 | - foreach(array( |
|
| 1193 | + list(,$ou) = explode(',', $baseDN); |
|
| 1194 | + foreach (array( |
|
| 1197 | 1195 | 'ou=contacts,'.$this->allContactsDN, |
| 1198 | 1196 | $ou.',ou=contacts,'.$this->allContactsDN, |
| 1199 | 1197 | $baseDN, |
@@ -1202,16 +1200,16 @@ discard block |
||
| 1202 | 1200 | if (!@ldap_read($this->ds, $dn, 'objectclass=*') && ldap_errno($this->ds) == 32) |
| 1203 | 1201 | { |
| 1204 | 1202 | // entry does not exist, lets try to create it |
| 1205 | - list($top) = explode(',',$dn); |
|
| 1206 | - list($var,$val) = explode('=',$top); |
|
| 1203 | + list($top) = explode(',', $dn); |
|
| 1204 | + list($var, $val) = explode('=', $top); |
|
| 1207 | 1205 | $data = array( |
| 1208 | 1206 | 'objectClass' => $var == 'cn' ? 'organizationalRole' : 'organizationalUnit', |
| 1209 | 1207 | $var => $val, |
| 1210 | 1208 | ); |
| 1211 | - if(!@ldap_add($adminDS, $dn, $data)) |
|
| 1209 | + if (!@ldap_add($adminDS, $dn, $data)) |
|
| 1212 | 1210 | { |
| 1213 | 1211 | //echo "<p>ldap_add($adminDS,'$dn',".print_r($data,true).")</p>\n"; |
| 1214 | - $err = lang("Can't create dn %1",$dn).': '.$this->_error(__LINE__,$adminDS); |
|
| 1212 | + $err = lang("Can't create dn %1", $dn).': '.$this->_error(__LINE__, $adminDS); |
|
| 1215 | 1213 | $adminLDAP->ldapDisconnect(); |
| 1216 | 1214 | return $err; |
| 1217 | 1215 | } |
@@ -1228,7 +1226,7 @@ discard block |
||
| 1228 | 1226 | * @param int $line |
| 1229 | 1227 | * @return string |
| 1230 | 1228 | */ |
| 1231 | - function _error($line,$ds=null) |
|
| 1229 | + function _error($line, $ds = null) |
|
| 1232 | 1230 | { |
| 1233 | 1231 | return ldap_error($ds ? $ds : $this->ds).': '.__CLASS__.': '.$line; |
| 1234 | 1232 | } |
@@ -1243,27 +1241,27 @@ discard block |
||
| 1243 | 1241 | * @param array $data eGW contact data |
| 1244 | 1242 | * @param boolean $isUpdate |
| 1245 | 1243 | */ |
| 1246 | - function _egw2evolutionperson(&$ldapContact,$data,$isUpdate) |
|
| 1244 | + function _egw2evolutionperson(&$ldapContact, $data, $isUpdate) |
|
| 1247 | 1245 | { |
| 1248 | - if(!empty($data['cat_id'])) |
|
| 1246 | + if (!empty($data['cat_id'])) |
|
| 1249 | 1247 | { |
| 1250 | 1248 | $ldapContact['category'] = array(); |
| 1251 | - foreach(is_array($data['cat_id']) ? $data['cat_id'] : explode(',',$data['cat_id']) as $cat) |
|
| 1249 | + foreach (is_array($data['cat_id']) ? $data['cat_id'] : explode(',', $data['cat_id']) as $cat) |
|
| 1252 | 1250 | { |
| 1253 | 1251 | $ldapContact['category'][] = Api\Translation::convert( |
| 1254 | - Api\Categories::id2name($cat),$this->charset,'utf-8'); |
|
| 1252 | + Api\Categories::id2name($cat), $this->charset, 'utf-8'); |
|
| 1255 | 1253 | } |
| 1256 | 1254 | } |
| 1257 | - foreach(array( |
|
| 1258 | - 'postaladdress' => $data['adr_one_street'] .'$'. $data['adr_one_locality'] .', '. $data['adr_one_region'] .'$'. $data['adr_one_postalcode'] .'$$'. $data['adr_one_countryname'], |
|
| 1259 | - 'homepostaladdress' => $data['adr_two_street'] .'$'. $data['adr_two_locality'] .', '. $data['adr_two_region'] .'$'. $data['adr_two_postalcode'] .'$$'. $data['adr_two_countryname'], |
|
| 1255 | + foreach (array( |
|
| 1256 | + 'postaladdress' => $data['adr_one_street'].'$'.$data['adr_one_locality'].', '.$data['adr_one_region'].'$'.$data['adr_one_postalcode'].'$$'.$data['adr_one_countryname'], |
|
| 1257 | + 'homepostaladdress' => $data['adr_two_street'].'$'.$data['adr_two_locality'].', '.$data['adr_two_region'].'$'.$data['adr_two_postalcode'].'$$'.$data['adr_two_countryname'], |
|
| 1260 | 1258 | ) as $attr => $value) |
| 1261 | 1259 | { |
| 1262 | - if($value != '$, $$$') |
|
| 1260 | + if ($value != '$, $$$') |
|
| 1263 | 1261 | { |
| 1264 | - $ldapContact[$attr] = Api\Translation::convert($value,$this->charset,'utf-8'); |
|
| 1262 | + $ldapContact[$attr] = Api\Translation::convert($value, $this->charset, 'utf-8'); |
|
| 1265 | 1263 | } |
| 1266 | - elseif($isUpdate) |
|
| 1264 | + elseif ($isUpdate) |
|
| 1267 | 1265 | { |
| 1268 | 1266 | $ldapContact[$attr] = array(); |
| 1269 | 1267 | } |
@@ -1273,7 +1271,7 @@ discard block |
||
| 1273 | 1271 | { |
| 1274 | 1272 | $ldapContact['primaryphone'] = $data[$data['tel_prefer']]; |
| 1275 | 1273 | } |
| 1276 | - elseif($isUpdate) |
|
| 1274 | + elseif ($isUpdate) |
|
| 1277 | 1275 | { |
| 1278 | 1276 | $ldapContact['primaryphone'] = array(); |
| 1279 | 1277 | } |
@@ -1288,23 +1286,23 @@ discard block |
||
| 1288 | 1286 | * @param array &$contact already copied fields according to the mapping |
| 1289 | 1287 | * @param array $data eGW contact data |
| 1290 | 1288 | */ |
| 1291 | - function _evolutionperson2egw(&$contact,$data) |
|
| 1289 | + function _evolutionperson2egw(&$contact, $data) |
|
| 1292 | 1290 | { |
| 1293 | 1291 | if ($data['category'] && is_array($data['category'])) |
| 1294 | 1292 | { |
| 1295 | 1293 | $contact['cat_id'] = array(); |
| 1296 | - foreach($data['category'] as $iii => $cat) |
|
| 1294 | + foreach ($data['category'] as $iii => $cat) |
|
| 1297 | 1295 | { |
| 1298 | 1296 | if (!is_int($iii)) continue; |
| 1299 | 1297 | |
| 1300 | 1298 | $contact['cat_id'][] = $GLOBALS['egw']->categories->name2id($cat); |
| 1301 | 1299 | } |
| 1302 | - if ($contact['cat_id']) $contact['cat_id'] = implode(',',$contact['cat_id']); |
|
| 1300 | + if ($contact['cat_id']) $contact['cat_id'] = implode(',', $contact['cat_id']); |
|
| 1303 | 1301 | } |
| 1304 | 1302 | if ($data['primaryphone']) |
| 1305 | 1303 | { |
| 1306 | - unset($contact['tel_prefer']); // to not find itself |
|
| 1307 | - $contact['tel_prefer'] = array_search($data['primaryphone'][0],$contact); |
|
| 1304 | + unset($contact['tel_prefer']); // to not find itself |
|
| 1305 | + $contact['tel_prefer'] = array_search($data['primaryphone'][0], $contact); |
|
| 1308 | 1306 | } |
| 1309 | 1307 | } |
| 1310 | 1308 | |
@@ -1317,10 +1315,10 @@ discard block |
||
| 1317 | 1315 | * @param array &$contact already copied fields according to the mapping |
| 1318 | 1316 | * @param array $data eGW contact data |
| 1319 | 1317 | */ |
| 1320 | - function _inetorgperson2egw(&$contact, $data, $cn='cn') |
|
| 1318 | + function _inetorgperson2egw(&$contact, $data, $cn = 'cn') |
|
| 1321 | 1319 | { |
| 1322 | 1320 | $matches = null; |
| 1323 | - if(empty($data['givenname'][0])) |
|
| 1321 | + if (empty($data['givenname'][0])) |
|
| 1324 | 1322 | { |
| 1325 | 1323 | $parts = explode($data['sn'][0], $data[$cn][0]); |
| 1326 | 1324 | $contact['n_prefix'] = trim($parts[0]); |
@@ -1328,8 +1326,8 @@ discard block |
||
| 1328 | 1326 | } |
| 1329 | 1327 | // iOS addressbook either use "givenname surname" or "surname givenname" depending on contact preference display-order |
| 1330 | 1328 | // in full name, so we need to check for both when trying to parse prefix, middle name and suffix form full name |
| 1331 | - elseif (preg_match($preg='/^(.*) *'.preg_quote($data['givenname'][0], '/').' *(.*) *'.preg_quote($data['sn'][0], '/').' *(.*)$/', $data[$cn][0], $matches) || |
|
| 1332 | - preg_match($preg='/^(.*) *'.preg_quote($data['sn'][0], '/').'[, ]*(.*) *'.preg_quote($data['givenname'][0], '/').' *(.*)$/', $data[$cn][0], $matches)) |
|
| 1329 | + elseif (preg_match($preg = '/^(.*) *'.preg_quote($data['givenname'][0], '/').' *(.*) *'.preg_quote($data['sn'][0], '/').' *(.*)$/', $data[$cn][0], $matches) || |
|
| 1330 | + preg_match($preg = '/^(.*) *'.preg_quote($data['sn'][0], '/').'[, ]*(.*) *'.preg_quote($data['givenname'][0], '/').' *(.*)$/', $data[$cn][0], $matches)) |
|
| 1333 | 1331 | { |
| 1334 | 1332 | list(,$contact['n_prefix'], $contact['n_middle'], $contact['n_suffix']) = $matches; |
| 1335 | 1333 | //error_log(__METHOD__."() preg_match('$preg', '{$data[$cn][0]}') = ".array2string($matches)); |
@@ -1350,11 +1348,11 @@ discard block |
||
| 1350 | 1348 | * @param array &$contact already copied fields according to the mapping |
| 1351 | 1349 | * @param array $data eGW contact data |
| 1352 | 1350 | */ |
| 1353 | - function _posixaccount2egw(&$contact,$data) |
|
| 1351 | + function _posixaccount2egw(&$contact, $data) |
|
| 1354 | 1352 | { |
| 1355 | - unset($contact); // not used, but required by function signature |
|
| 1356 | - static $shadowExpireNow=null; |
|
| 1357 | - if (!isset($shadowExpireNow)) $shadowExpireNow = floor((time()-date('Z'))/86400); |
|
| 1353 | + unset($contact); // not used, but required by function signature |
|
| 1354 | + static $shadowExpireNow = null; |
|
| 1355 | + if (!isset($shadowExpireNow)) $shadowExpireNow = floor((time() - date('Z')) / 86400); |
|
| 1358 | 1356 | |
| 1359 | 1357 | // exclude expired or deactivated accounts |
| 1360 | 1358 | if (isset($data['shadowexpire']) && $data['shadowexpire'][0] <= $shadowExpireNow) |
@@ -1372,7 +1370,7 @@ discard block |
||
| 1372 | 1370 | * @param array &$contact already copied fields according to the mapping |
| 1373 | 1371 | * @param array $data eGW contact data |
| 1374 | 1372 | */ |
| 1375 | - function _mozillaabpersonalpha2egw(&$contact,$data) |
|
| 1373 | + function _mozillaabpersonalpha2egw(&$contact, $data) |
|
| 1376 | 1374 | { |
| 1377 | 1375 | if ($data['c']) |
| 1378 | 1376 | { |
@@ -1390,7 +1388,7 @@ discard block |
||
| 1390 | 1388 | * @param array $data eGW contact data |
| 1391 | 1389 | * @param boolean $isUpdate |
| 1392 | 1390 | */ |
| 1393 | - function _egw2mozillaabpersonalpha(&$ldapContact,$data,$isUpdate) |
|
| 1391 | + function _egw2mozillaabpersonalpha(&$ldapContact, $data, $isUpdate) |
|
| 1394 | 1392 | { |
| 1395 | 1393 | if ($data['adr_one_countrycode']) |
| 1396 | 1394 | { |
@@ -1419,9 +1417,9 @@ discard block |
||
| 1419 | 1417 | * @param array &$contact already copied fields according to the mapping |
| 1420 | 1418 | * @param array $data eGW contact data |
| 1421 | 1419 | */ |
| 1422 | - function _mozillaorgperson2egw(&$contact,$data) |
|
| 1420 | + function _mozillaorgperson2egw(&$contact, $data) |
|
| 1423 | 1421 | { |
| 1424 | - unset($contact, $data); // not used, but required by function signature |
|
| 1422 | + unset($contact, $data); // not used, but required by function signature |
|
| 1425 | 1423 | // no special handling necessary, as it supports two distinct attributes: c, cn |
| 1426 | 1424 | } |
| 1427 | 1425 | |
@@ -1435,7 +1433,7 @@ discard block |
||
| 1435 | 1433 | * @param array $data eGW contact data |
| 1436 | 1434 | * @param boolean $isUpdate |
| 1437 | 1435 | */ |
| 1438 | - function _egw2mozillaorgperson(&$ldapContact,$data,$isUpdate) |
|
| 1436 | + function _egw2mozillaorgperson(&$ldapContact, $data, $isUpdate) |
|
| 1439 | 1437 | { |
| 1440 | 1438 | if ($data['adr_one_countrycode']) |
| 1441 | 1439 | { |
@@ -1463,7 +1461,7 @@ discard block |
||
| 1463 | 1461 | * @param int $account_id account-id of the old owner |
| 1464 | 1462 | * @param int $new_owner account-id of the new owner |
| 1465 | 1463 | */ |
| 1466 | - function change_owner($account_id,$new_owner) |
|
| 1464 | + function change_owner($account_id, $new_owner) |
|
| 1467 | 1465 | { |
| 1468 | 1466 | error_log(__METHOD__."($account_id,$new_owner) not yet implemented"); |
| 1469 | 1467 | } |
@@ -327,9 +327,12 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 | { |
@@ -950,19 +980,28 @@ discard block |
||
| 950 | 980 | $GLOBALS['egw']->categories = new Api\Categories(); |
| 951 | 981 | } |
| 952 | 982 | $cats = $GLOBALS['egw']->categories->return_all_children((int)$value); |
| 953 | - if (count($cats) > 1) $filters .= '(|'; |
|
| 983 | + if (count($cats) > 1) |
|
| 984 | + { |
|
| 985 | + $filters .= '(|'; |
|
| 986 | + } |
|
| 954 | 987 | foreach($cats as $cat) |
| 955 | 988 | { |
| 956 | 989 | $catName = Api\Translation::convert( |
| 957 | 990 | $GLOBALS['egw']->categories->id2name($cat),$this->charset,'utf-8'); |
| 958 | 991 | $filters .= '(category='.Api\Ldap::quote($catName).')'; |
| 959 | 992 | } |
| 960 | - if (count($cats) > 1) $filters .= ')'; |
|
| 993 | + if (count($cats) > 1) |
|
| 994 | + { |
|
| 995 | + $filters .= ')'; |
|
| 996 | + } |
|
| 961 | 997 | } |
| 962 | 998 | break; |
| 963 | 999 | |
| 964 | 1000 | case 'carddav_name': |
| 965 | - if (!is_array($value)) $value = array($value); |
|
| 1001 | + if (!is_array($value)) |
|
| 1002 | + { |
|
| 1003 | + $value = array($value); |
|
| 1004 | + } |
|
| 966 | 1005 | foreach($value as &$v) |
| 967 | 1006 | { |
| 968 | 1007 | $v = basename($v, '.vcf'); |
@@ -996,7 +1035,10 @@ discard block |
||
| 996 | 1035 | elseif (preg_match("/^([^ ]+) ".preg_quote($GLOBALS['egw']->db->capabilities[Api\Db::CAPABILITY_CASE_INSENSITIV_LIKE])." '(.*)%'$/",$value,$matches)) |
| 997 | 1036 | { |
| 998 | 1037 | list(,$name,$value) = $matches; |
| 999 | - if (strpos($name,'.') !== false) list(,$name) = explode('.',$name); |
|
| 1038 | + if (strpos($name,'.') !== false) |
|
| 1039 | + { |
|
| 1040 | + list(,$name) = explode('.',$name); |
|
| 1041 | + } |
|
| 1000 | 1042 | foreach($this->schema2egw as $mapping) |
| 1001 | 1043 | { |
| 1002 | 1044 | if (isset($mapping[$name])) |
@@ -1069,13 +1111,20 @@ discard block |
||
| 1069 | 1111 | { |
| 1070 | 1112 | $result = @ldap_list($this->ds, $_ldapContext, $_filter, $_attributes, 0, $this->ldapLimit); |
| 1071 | 1113 | } |
| 1072 | - if(!$result || !$entries = ldap_get_entries($this->ds, $result)) return array(); |
|
| 1114 | + if(!$result || !$entries = ldap_get_entries($this->ds, $result)) |
|
| 1115 | + { |
|
| 1116 | + return array(); |
|
| 1117 | + } |
|
| 1073 | 1118 | //error_log(__METHOD__."('$_ldapContext', '$_filter', ".array2string($_attributes).", $_addressbooktype) result of $entries[count]"); |
| 1074 | 1119 | |
| 1075 | 1120 | $this->total = $entries['count']; |
| 1076 | 1121 | foreach($entries as $i => $entry) |
| 1077 | 1122 | { |
| 1078 | - if (!is_int($i)) continue; // eg. count |
|
| 1123 | + if (!is_int($i)) |
|
| 1124 | + { |
|
| 1125 | + continue; |
|
| 1126 | + } |
|
| 1127 | + // eg. count |
|
| 1079 | 1128 | |
| 1080 | 1129 | $contact = array( |
| 1081 | 1130 | 'id' => $entry['uid'][0] ? $entry['uid'][0] : $entry['entryuuid'][0], |
@@ -1295,11 +1344,17 @@ discard block |
||
| 1295 | 1344 | $contact['cat_id'] = array(); |
| 1296 | 1345 | foreach($data['category'] as $iii => $cat) |
| 1297 | 1346 | { |
| 1298 | - if (!is_int($iii)) continue; |
|
| 1347 | + if (!is_int($iii)) |
|
| 1348 | + { |
|
| 1349 | + continue; |
|
| 1350 | + } |
|
| 1299 | 1351 | |
| 1300 | 1352 | $contact['cat_id'][] = $GLOBALS['egw']->categories->name2id($cat); |
| 1301 | 1353 | } |
| 1302 | - if ($contact['cat_id']) $contact['cat_id'] = implode(',',$contact['cat_id']); |
|
| 1354 | + if ($contact['cat_id']) |
|
| 1355 | + { |
|
| 1356 | + $contact['cat_id'] = implode(',',$contact['cat_id']); |
|
| 1357 | + } |
|
| 1303 | 1358 | } |
| 1304 | 1359 | if ($data['primaryphone']) |
| 1305 | 1360 | { |
@@ -1354,7 +1409,10 @@ discard block |
||
| 1354 | 1409 | { |
| 1355 | 1410 | unset($contact); // not used, but required by function signature |
| 1356 | 1411 | static $shadowExpireNow=null; |
| 1357 | - if (!isset($shadowExpireNow)) $shadowExpireNow = floor((time()-date('Z'))/86400); |
|
| 1412 | + if (!isset($shadowExpireNow)) |
|
| 1413 | + { |
|
| 1414 | + $shadowExpireNow = floor((time()-date('Z'))/86400); |
|
| 1415 | + } |
|
| 1358 | 1416 | |
| 1359 | 1417 | // exclude expired or deactivated accounts |
| 1360 | 1418 | if (isset($data['shadowexpire']) && $data['shadowexpire'][0] <= $shadowExpireNow) |
@@ -1399,9 +1457,13 @@ discard block |
||
| 1399 | 1457 | elseif ($data['adr_one_countryname']) |
| 1400 | 1458 | { |
| 1401 | 1459 | $ldapContact['c'] = Api\Country::country_code($data['adr_one_countryname']); |
| 1402 | - if ($ldapContact['c'] && strlen($ldapContact['c']) > 2) // Bad countryname when "custom" selected! |
|
| 1460 | + if ($ldapContact['c'] && strlen($ldapContact['c']) > 2) |
|
| 1461 | + { |
|
| 1462 | + // Bad countryname when "custom" selected! |
|
| 1403 | 1463 | { |
| 1404 | - $ldapContact['c'] = array(); // should return error... |
|
| 1464 | + $ldapContact['c'] = array(); |
|
| 1465 | + } |
|
| 1466 | + // should return error... |
|
| 1405 | 1467 | } |
| 1406 | 1468 | } |
| 1407 | 1469 | elseif ($isUpdate) |
@@ -1440,14 +1502,21 @@ discard block |
||
| 1440 | 1502 | if ($data['adr_one_countrycode']) |
| 1441 | 1503 | { |
| 1442 | 1504 | $ldapContact['c'] = $data['adr_one_countrycode']; |
| 1443 | - if ($isUpdate) $ldapContact['co'] = array(); |
|
| 1505 | + if ($isUpdate) |
|
| 1506 | + { |
|
| 1507 | + $ldapContact['co'] = array(); |
|
| 1508 | + } |
|
| 1444 | 1509 | } |
| 1445 | 1510 | elseif ($data['adr_one_countryname']) |
| 1446 | 1511 | { |
| 1447 | 1512 | $ldapContact['c'] = Api\Country::country_code($data['adr_one_countryname']); |
| 1448 | - if ($ldapContact['c'] && strlen($ldapContact['c']) > 2) // Bad countryname when "custom" selected! |
|
| 1513 | + if ($ldapContact['c'] && strlen($ldapContact['c']) > 2) |
|
| 1449 | 1514 | { |
| 1450 | - $ldapContact['c'] = array(); // should return error... |
|
| 1515 | + // Bad countryname when "custom" selected! |
|
| 1516 | + { |
|
| 1517 | + $ldapContact['c'] = array(); |
|
| 1518 | + } |
|
| 1519 | + // should return error... |
|
| 1451 | 1520 | } |
| 1452 | 1521 | } |
| 1453 | 1522 | elseif ($isUpdate) |