[5595] | 1 | <?php |
---|
| 2 | |
---|
| 3 | |
---|
| 4 | class Catalog extends Expresso { |
---|
[6019] | 5 | var $minArgumentSearch; |
---|
[5889] | 6 | var $userId; |
---|
| 7 | |
---|
[5956] | 8 | public function __construct($id){ |
---|
| 9 | parent::__construct($id); |
---|
[5954] | 10 | $prefs = $GLOBALS['phpgw']->preferences->read(); |
---|
[6019] | 11 | $this-> setMinArgumentSearch($prefs['expressoMail']['search_characters_number']); |
---|
[5889] | 12 | } |
---|
[5595] | 13 | |
---|
[6019] | 14 | protected function setMinArgumentSearch($minArgumentSearch){ |
---|
| 15 | $this->minArgumentSearch = $minArgumentSearch; |
---|
[5889] | 16 | } |
---|
| 17 | |
---|
[6019] | 18 | protected function getMinArgumentSearch(){ |
---|
| 19 | return $this-> minArgumentSearch; |
---|
| 20 | } |
---|
[5687] | 21 | |
---|
[6019] | 22 | protected function getUserId(){ |
---|
| 23 | $userProfile = $this->getUserProfile(); |
---|
| 24 | return $userProfile['contactID']; |
---|
| 25 | } |
---|
[5707] | 26 | |
---|
[6019] | 27 | protected function getUserLdapAttrs($mail) |
---|
[5707] | 28 | { |
---|
| 29 | $filter="(&(phpgwAccountType=u)(mail=".$mail."))"; |
---|
| 30 | $ldap_context = $_SESSION['phpgw_info']['expressomail']['ldap_server']['dn']; |
---|
| 31 | $justthese = array("dn", 'jpegPhoto','givenName', 'sn'); |
---|
| 32 | $this->getLdapCatalog()->ldapConnect(true); |
---|
| 33 | $ds = $this->getLdapCatalog()->ds; |
---|
| 34 | if ($ds){ |
---|
| 35 | $sr = @ldap_search($ds, $ldap_context, $filter, $justthese); |
---|
| 36 | if ($sr) { |
---|
| 37 | $entry = ldap_first_entry($ds, $sr); |
---|
| 38 | if($entry) { |
---|
| 39 | $givenName = @ldap_get_values_len($ds, $entry, "givenname"); |
---|
| 40 | $sn = @ldap_get_values_len($ds, $entry, "sn"); |
---|
| 41 | $contactHasImagePicture = (@ldap_get_values_len($ds, $entry, "jpegphoto") ? 1 : 0); |
---|
| 42 | $dn = ldap_get_dn($ds, $entry); |
---|
| 43 | return array( |
---|
[5714] | 44 | "contactID" => urlencode($dn), |
---|
[5707] | 45 | "contactFirstName" => $givenName[0], |
---|
| 46 | "contactLastName" => $sn[0], |
---|
| 47 | "contactHasImagePicture" => $contactHasImagePicture |
---|
| 48 | ); |
---|
| 49 | } |
---|
| 50 | } |
---|
| 51 | } |
---|
| 52 | return false; |
---|
[5712] | 53 | } |
---|
| 54 | |
---|
[6019] | 55 | protected function getUserLdapPhoto($contactID) { |
---|
[5712] | 56 | $ldap_context = $_SESSION['phpgw_info']['expressomail']['ldap_server']['dn']; |
---|
| 57 | $justthese = array("dn", 'jpegPhoto','givenName', 'sn'); |
---|
| 58 | $this->getLdapCatalog()->ldapConnect(true); |
---|
| 59 | $ds = $this->getLdapCatalog()->ds; |
---|
| 60 | |
---|
| 61 | if ($ds){ |
---|
[5722] | 62 | $resource = @ldap_read($ds, $contactID, "phpgwaccounttype=u"); |
---|
| 63 | $n_entries = @ldap_count_entries($ds, $resource); |
---|
| 64 | |
---|
[5712] | 65 | if ( $n_entries == 1) { |
---|
| 66 | $first_entry = ldap_first_entry($ds, $resource); |
---|
| 67 | $obj = ldap_get_attributes($ds, $first_entry); |
---|
| 68 | |
---|
| 69 | if($obj['jpegPhoto']){ |
---|
| 70 | return ldap_get_values_len( $ds, $first_entry, "jpegPhoto"); |
---|
| 71 | } |
---|
| 72 | } |
---|
| 73 | } |
---|
| 74 | return false; |
---|
[5707] | 75 | } |
---|
[5595] | 76 | |
---|
[6019] | 77 | protected function getGlobalContacts($search, $uidNumber){ |
---|
[5707] | 78 | $contacts = array(); |
---|
| 79 | $params = array ("search_for" => $search); |
---|
| 80 | $result = $this->getLdapCatalog()->quicksearch($params); |
---|
| 81 | |
---|
| 82 | foreach($result as $i => $row) { |
---|
| 83 | if(is_int($i)) { |
---|
| 84 | $contacts[$i] = array( |
---|
| 85 | 'contactMails' => array($result[$i]['mail']), |
---|
| 86 | 'contactPhones' => array($result[$i]['phone']), |
---|
| 87 | 'contactAlias' => "", |
---|
| 88 | 'contactFullName' => ($result[$i]['cn'] != null ? mb_convert_encoding($row['cn'],"UTF8", "ISO_8859-1") : ""), |
---|
| 89 | 'contactBirthDate' => "", |
---|
| 90 | 'contactNotes' => "" |
---|
| 91 | ); |
---|
| 92 | // Buscar atributos faltantes. |
---|
[5712] | 93 | if(is_array($this->getUserLdapAttrs($result[$i]['mail']))) |
---|
| 94 | $contacts[$i] = array_merge($this->getUserLdapAttrs($result[$i]['mail']), $contacts[$i]); |
---|
[5707] | 95 | } |
---|
| 96 | } |
---|
[6019] | 97 | $result = array ('contacts' => $contacts); |
---|
| 98 | $this->setResult($result); |
---|
[5595] | 99 | return $this->getResponse(); |
---|
| 100 | } |
---|
[5681] | 101 | } |
---|