[7419] | 1 | <?php |
---|
| 2 | |
---|
| 3 | |
---|
| 4 | class CatalogAdapter extends ExpressoAdapter { |
---|
| 5 | private $minArgumentSearch; |
---|
| 6 | private $userId; |
---|
| 7 | private $ldapCatalog; |
---|
| 8 | |
---|
| 9 | public function __construct($id){ |
---|
| 10 | parent::__construct($id); |
---|
| 11 | $prefs = $GLOBALS['phpgw']->preferences->read(); |
---|
| 12 | $this-> setMinArgumentSearch($prefs['expressoMail']['search_characters_number'] ? $prefs['expressoMail']['search_characters_number'] : "4"); |
---|
| 13 | } |
---|
| 14 | |
---|
| 15 | protected function setMinArgumentSearch($minArgumentSearch){ |
---|
| 16 | $this->minArgumentSearch = $minArgumentSearch; |
---|
| 17 | } |
---|
| 18 | |
---|
| 19 | protected function getMinArgumentSearch(){ |
---|
| 20 | return $this-> minArgumentSearch; |
---|
| 21 | } |
---|
| 22 | |
---|
| 23 | protected function getUserId(){ |
---|
| 24 | return $GLOBALS['phpgw_info']['user']['account_id']; |
---|
| 25 | } |
---|
| 26 | |
---|
| 27 | |
---|
| 28 | protected function getLdapCatalog(){ |
---|
| 29 | if(!$this->ldapCatalog) { |
---|
| 30 | $catalog_config = CreateObject("contactcenter.bo_ldap_manager"); |
---|
| 31 | $_SESSION['phpgw_info']['expressomail']['ldap_server'] = $catalog_config ? $catalog_config->srcs[1] : null; |
---|
| 32 | $this->ldapCatalog = CreateObject("expressoMail1_2.ldap_functions"); |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | return $this->ldapCatalog; |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | protected function getDb(){ |
---|
| 39 | return $GLOBALS['phpgw']->db; |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | protected function getUserLdapAttrs($mail) |
---|
| 43 | { |
---|
| 44 | $filter="(&(phpgwAccountType=u)(mail=".$mail."))"; |
---|
| 45 | $ldap_context = $_SESSION['phpgw_info']['expressomail']['ldap_server']['dn']; |
---|
| 46 | $justthese = array("dn", 'jpegPhoto','givenName', 'sn'); |
---|
| 47 | $ds = $this->getLdapCatalog()->ds; |
---|
| 48 | if ($ds){ |
---|
| 49 | $sr = @ldap_search($ds, $ldap_context, $filter, $justthese); |
---|
| 50 | if ($sr) { |
---|
| 51 | $entry = ldap_first_entry($ds, $sr); |
---|
| 52 | if($entry) { |
---|
| 53 | $givenName = @ldap_get_values_len($ds, $entry, "givenname"); |
---|
| 54 | $sn = @ldap_get_values_len($ds, $entry, "sn"); |
---|
| 55 | $contactHasImagePicture = (@ldap_get_values_len($ds, $entry, "jpegphoto") ? 1 : 0); |
---|
| 56 | $dn = ldap_get_dn($ds, $entry); |
---|
| 57 | return array( |
---|
| 58 | "contactID" => urlencode($dn), |
---|
| 59 | "contactFirstName" => $givenName[0], |
---|
| 60 | "contactLastName" => $sn[0], |
---|
| 61 | "contactHasImagePicture" => $contactHasImagePicture |
---|
| 62 | ); |
---|
| 63 | } |
---|
| 64 | } |
---|
| 65 | } |
---|
| 66 | return false; |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | protected function getUserLdapPhoto($contactID) { |
---|
| 70 | $ldap_context = $_SESSION['phpgw_info']['expressomail']['ldap_server']['dn']; |
---|
| 71 | $justthese = array("dn", 'jpegPhoto','givenName', 'sn'); |
---|
| 72 | $this->getLdapCatalog()->ldapConnect(true); |
---|
| 73 | $ds = $this->getLdapCatalog()->ds; |
---|
| 74 | |
---|
| 75 | if ($ds){ |
---|
| 76 | $resource = @ldap_read($ds, $contactID, "phpgwaccounttype=u"); |
---|
| 77 | $n_entries = @ldap_count_entries($ds, $resource); |
---|
| 78 | |
---|
| 79 | if ( $n_entries == 1) { |
---|
| 80 | $first_entry = ldap_first_entry($ds, $resource); |
---|
| 81 | $obj = ldap_get_attributes($ds, $first_entry); |
---|
| 82 | |
---|
| 83 | if($obj['jpegPhoto']){ |
---|
| 84 | return ldap_get_values_len( $ds, $first_entry, "jpegPhoto"); |
---|
| 85 | } |
---|
| 86 | } |
---|
| 87 | } |
---|
| 88 | return false; |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | protected function getGlobalContacts($search, $uidNumber){ |
---|
| 92 | $contacts = array(); |
---|
| 93 | $params = array ("search_for" => $search); |
---|
| 94 | $result = $this->getLdapCatalog()->quicksearch($params); |
---|
| 95 | // Reconnect for searching other attributes. |
---|
| 96 | $this->getLdapCatalog()->ldapConnect(true); |
---|
| 97 | foreach($result as $i => $row) { |
---|
| 98 | if(is_int($i)) { |
---|
| 99 | $contacts[$i] = array( |
---|
| 100 | 'contactMails' => array($result[$i]['mail']), |
---|
| 101 | 'contactPhones' => array($result[$i]['phone']), |
---|
| 102 | 'contactAlias' => "", |
---|
| 103 | 'contactFullName' => ($result[$i]['cn'] != null ? mb_convert_encoding($row['cn'],"UTF8", "ISO_8859-1") : ""), |
---|
| 104 | 'contactBirthDate' => "", |
---|
| 105 | 'contactNotes' => "" |
---|
| 106 | ); |
---|
| 107 | // Buscar atributos faltantes. |
---|
| 108 | $otherAttrs = $this->getUserLdapAttrs($result[$i]['mail']); |
---|
| 109 | if(is_array($otherAttrs)) |
---|
| 110 | $contacts[$i] = array_merge($otherAttrs, $contacts[$i]); |
---|
| 111 | } |
---|
| 112 | } |
---|
| 113 | // Force ldap close |
---|
| 114 | ldap_close($this->getLdapCatalog()->ds); |
---|
| 115 | $result = array ('contacts' => $contacts); |
---|
| 116 | $this->setResult($result); |
---|
| 117 | return $this->getResponse(); |
---|
| 118 | } |
---|
| 119 | } |
---|