isLoggedIn($params)) { $search = ""; if($params) { $search = trim($params['search']); if($params['contactID'] > 0){ $query_contact = 'A.id_contact='.$params['contactID'].' and'; } elseif($search != "") { $search = mb_convert_encoding($search,"ISO_8859-1", "UTF8"); } if(($search || $params['contactID']) && $params['contactType'] == 2){ return $this->getGlobalContacts($search, $params['contactID']); } } $query = 'select B.id_typeof_contact_connection, A.photo, A.id_contact, A.alias, A.given_names, A.family_names, A.names_ordered, A.birthdate, A.notes, C.connection_value from phpgw_cc_contact A, '. 'phpgw_cc_contact_conns B, phpgw_cc_connections C where A.id_contact = B.id_contact and B.id_connection = C.id_connection '. ' and '.$query_contact.' A.id_owner='.$this -> getUserId().' group by '. ' B.id_typeof_contact_connection, A.photo, A.id_contact, A.alias, A.given_names, A.family_names,A.names_ordered,A.birthdate, A.notes,C.connection_value order by lower(A.names_ordered)'; if (!$this->getDb()->query($query)) return false; $contacts = array(); while($this->getDb()->next_record()) { $row = $this->getDb()->row(); $id = $row['id_contact']; $contactType = ($row['id_typeof_contact_connection'] == 2 ? 'contactPhones' : 'contactMails'); if($contacts[$id] != null){ $contacts[$id][$contactType][] = $row['connection_value']; } else{ $contacts[$id] = array( 'contactID' => $row['id_contact'], $contactType => array($row['connection_value']), 'contactAlias' => ($row['alias'] != null ? mb_convert_encoding($row['alias'],"UTF8", "ISO_8859-1") : ""), 'contactFirstName' => ($row['given_names'] != null ? mb_convert_encoding($row['given_names'],"UTF8", "ISO_8859-1") : ""), 'contactLastName' => ($row['family_names'] != null ? mb_convert_encoding($row['family_names'],"UTF8", "ISO_8859-1") : ""), 'contactFullName' => ($row['names_ordered'] != null ? mb_convert_encoding($row['names_ordered'],"UTF8", "ISO_8859-1") : ""), 'contactBirthDate' => ($row['birthdate'] != null ? $row['birthdate'] : ""), 'contactNotes' => ($row['notes'] != null ? mb_convert_encoding($row['notes'],"UTF8", "ISO_8859-1") : ""), 'contactHasImagePicture' => ($row['photo'] != null ? 1 : 0), ); if($search != null && stristr($contacts[$id]['contactAlias'], $search) == null && stristr($contacts[$id]['contactFirstName'], $search) == null && stristr($contacts[$id]['contactLastName'], $search) == null && stristr($contacts[$id]['contactFullName'], $search) == null && stristr($contacts[$id]['contactBirthDate'], $search) == null && stristr($contacts[$id]['contactNotes'], $search) == null){ unset($contacts[$id]); } } } $this->result = array ('contacts' => array_values($contacts)); } return $this->getResponse(); } public function getImagePicture($params){ if($this->isLoggedIn($params) && $params['contactID'] != null) { $contact = array(); // User Contact if($params['contactType'] == 1){ $query = 'select A.id_contact, A.photo from phpgw_cc_contact A where A.id_contact='.$params['contactID'].' and A.id_owner='.$this -> getUserId(); if (!$this->getDb()->query($query)) return false; if($this->getDb()->next_record()) { $row = $this->getDb()->row(); if($row['photo'] != null) { $contact[] = array( 'contactID' => $row['id_contact'], 'contactImagePicture' => ($row['photo'] != null ? base64_encode($row['photo']) : "") ); } } } // Global Catalog elseif($params['contactType'] == 2){ $photo = $this->getUserLdapPhoto($params['contactID']); $contact[] = array( 'contactID' => $params['contactID'], 'contactImagePicture' => ($photo != null ? base64_encode($photo[0]) : "") ); } $this->result = array ('contacts' => $contact); } return $this->getResponse(); } private function getUserLdapAttrs($mail) { $filter="(&(phpgwAccountType=u)(mail=".$mail."))"; $ldap_context = $_SESSION['phpgw_info']['expressomail']['ldap_server']['dn']; $justthese = array("dn", 'jpegPhoto','givenName', 'sn'); $this->getLdapCatalog()->ldapConnect(true); $ds = $this->getLdapCatalog()->ds; if ($ds){ $sr = @ldap_search($ds, $ldap_context, $filter, $justthese); if ($sr) { $entry = ldap_first_entry($ds, $sr); if($entry) { $givenName = @ldap_get_values_len($ds, $entry, "givenname"); $sn = @ldap_get_values_len($ds, $entry, "sn"); $contactHasImagePicture = (@ldap_get_values_len($ds, $entry, "jpegphoto") ? 1 : 0); $dn = ldap_get_dn($ds, $entry); return array( "contactID" => $dn, "contactFirstName" => $givenName[0], "contactLastName" => $sn[0], "contactHasImagePicture" => $contactHasImagePicture ); } } } return false; } private function getUserLdapPhoto($contactID) { $ldap_context = $_SESSION['phpgw_info']['expressomail']['ldap_server']['dn']; $justthese = array("dn", 'jpegPhoto','givenName', 'sn'); $this->getLdapCatalog()->ldapConnect(true); $ds = $this->getLdapCatalog()->ds; if ($ds){ $resource = ldap_read($ds, $contactID, "phpgwaccounttype=u"); $n_entries = ldap_count_entries($ds, $resource); error_log("entrou foto =".$n_entries); if ( $n_entries == 1) { $first_entry = ldap_first_entry($ds, $resource); $obj = ldap_get_attributes($ds, $first_entry); if($obj['jpegPhoto']){ return ldap_get_values_len( $ds, $first_entry, "jpegPhoto"); } } } return false; } private function getGlobalContacts($search, $uidNumber){ $contacts = array(); $params = array ("search_for" => $search); $result = $this->getLdapCatalog()->quicksearch($params); foreach($result as $i => $row) { if(is_int($i)) { $contacts[$i] = array( 'contactMails' => array($result[$i]['mail']), 'contactPhones' => array($result[$i]['phone']), 'contactAlias' => "", 'contactFullName' => ($result[$i]['cn'] != null ? mb_convert_encoding($row['cn'],"UTF8", "ISO_8859-1") : ""), 'contactBirthDate' => "", 'contactNotes' => "" ); // Buscar atributos faltantes. if(is_array($this->getUserLdapAttrs($result[$i]['mail']))) $contacts[$i] = array_merge($this->getUserLdapAttrs($result[$i]['mail']), $contacts[$i]); } } $this->result = array ('contacts' => $contacts); return $this->getResponse(); } }