Changeset 6019 for sandbox/webservice/api/rest/catalog/Catalog.php
- Timestamp:
- 04/24/12 17:07:07 (12 years ago)
- Location:
- sandbox/webservice/api/rest
- Files:
-
- 2 added
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
sandbox/webservice/api/rest/catalog/Catalog.php
r5956 r6019 1 1 <?php 2 2 3 include_once("Expresso.php");4 3 5 4 class Catalog extends Expresso { 6 var $ searchCharactersNumber;5 var $minArgumentSearch; 7 6 var $userId; 8 7 … … 10 9 parent::__construct($id); 11 10 $prefs = $GLOBALS['phpgw']->preferences->read(); 12 $this-> se archCharactersNumber = $prefs['expressoMail']['search_characters_number'];11 $this-> setMinArgumentSearch($prefs['expressoMail']['search_characters_number']); 13 12 } 14 13 15 private function getUserId(){ 14 protected function setMinArgumentSearch($minArgumentSearch){ 15 $this->minArgumentSearch = $minArgumentSearch; 16 } 17 18 protected function getMinArgumentSearch(){ 19 return $this-> minArgumentSearch; 20 } 21 22 protected function getUserId(){ 16 23 $userProfile = $this->getUserProfile(); 17 24 return $userProfile['contactID']; 18 } 19 20 public function getUserContacts($params){ 21 if($this->isLoggedIn($params)) { 22 $search = ""; 23 if($params) { 24 $search = trim($params['search']); 25 if($search != "") { 26 $search = mb_convert_encoding($search,"ISO_8859-1", "UTF8"); 27 } 28 29 if($params['contactID'] > 0 && $params['contactType'] == 1){ 30 $query_contact = 'A.id_contact='.$params['contactID'].' and'; 31 } 32 elseif($params['contactType'] == 2){ 33 if($this-> searchCharactersNumber <= strlen($search)) 34 return $this->getGlobalContacts($search, $params['contactID']); 35 else{ 36 $this-> error = Errors::get(Errors::CATALOG_MIN_ARGUMENT_SEARCH); 37 $this-> error = str_replace("%1",$this-> searchCharactersNumber,$this->error); 38 return $this->getResponse(); 39 } 40 } 41 } 42 43 $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, '. 44 'phpgw_cc_contact_conns B, phpgw_cc_connections C where A.id_contact = B.id_contact and B.id_connection = C.id_connection '. 45 ' and '.$query_contact.' A.id_owner='.$this -> getUserId().' group by '. 46 ' 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)'; 47 48 if (!$this->getDb()->query($query)) 49 return false; 50 51 $contacts = array(); 52 while($this->getDb()->next_record()) { 53 $row = $this->getDb()->row(); 54 $id = $row['id_contact']; 55 $contactType = ($row['id_typeof_contact_connection'] == 2 ? 'contactPhones' : 'contactMails'); 56 57 if($contacts[$id] != null){ 58 $contacts[$id][$contactType][] = $row['connection_value']; 59 } 60 else{ 61 $contacts[$id] = array( 62 'contactID' => $row['id_contact'], 63 $contactType => array($row['connection_value']), 64 'contactAlias' => ($row['alias'] != null ? mb_convert_encoding($row['alias'],"UTF8", "ISO_8859-1") : ""), 65 'contactFirstName' => ($row['given_names'] != null ? mb_convert_encoding($row['given_names'],"UTF8", "ISO_8859-1") : ""), 66 'contactLastName' => ($row['family_names'] != null ? mb_convert_encoding($row['family_names'],"UTF8", "ISO_8859-1") : ""), 67 'contactFullName' => ($row['names_ordered'] != null ? mb_convert_encoding($row['names_ordered'],"UTF8", "ISO_8859-1") : ""), 68 'contactBirthDate' => ($row['birthdate'] != null ? $row['birthdate'] : ""), 69 'contactNotes' => ($row['notes'] != null ? mb_convert_encoding($row['notes'],"UTF8", "ISO_8859-1") : ""), 70 'contactHasImagePicture' => ($row['photo'] != null ? 1 : 0), 71 ); 72 if($search != null && 73 stristr($contacts[$id]['contactAlias'], $search) == null && 74 stristr($contacts[$id]['contactFirstName'], $search) == null && 75 stristr($contacts[$id]['contactLastName'], $search) == null && 76 stristr($contacts[$id]['contactFullName'], $search) == null && 77 stristr($contacts[$id]['contactBirthDate'], $search) == null && 78 stristr($contacts[$id]['contactNotes'], $search) == null){ 79 unset($contacts[$id]); 80 } 81 } 82 } 83 $this->result = array ('contacts' => array_values($contacts)); 84 } 85 return $this->getResponse(); 86 } 87 88 public function getImagePicture($params){ 89 if($this->isLoggedIn($params) && $params['contactID'] != null) { 90 $contact = array(); 91 // User Contact 92 if($params['contactType'] == 1){ 93 $query = 'select A.id_contact, A.photo from phpgw_cc_contact A where A.id_contact='.$params['contactID'].' and A.id_owner='.$this -> getUserId(); 94 if (!$this->getDb()->query($query)) 95 return false; 96 if($this->getDb()->next_record()) { 97 $row = $this->getDb()->row(); 98 if($row['photo'] != null) { 99 $contact[] = array( 100 'contactID' => $row['id_contact'], 101 'contactImagePicture' => ($row['photo'] != null ? base64_encode($row['photo']) : "") 102 ); 103 } 104 } 105 } 106 // Global Catalog 107 elseif($params['contactType'] == 2){ 108 $photo = $this->getUserLdapPhoto(urldecode($params['contactID'])); 109 $contact[] = array( 110 'contactID' => $params['contactID'], 111 'contactImagePicture' => ($photo != null ? base64_encode($photo[0]) : "") 112 ); 113 114 } 115 $this->result = array ('contacts' => $contact); 116 } 117 return $this->getResponse(); 118 } 25 } 119 26 120 pr ivatefunction getUserLdapAttrs($mail)27 protected function getUserLdapAttrs($mail) 121 28 { 122 29 $filter="(&(phpgwAccountType=u)(mail=".$mail."))"; … … 146 53 } 147 54 148 pr ivatefunction getUserLdapPhoto($contactID) {55 protected function getUserLdapPhoto($contactID) { 149 56 $ldap_context = $_SESSION['phpgw_info']['expressomail']['ldap_server']['dn']; 150 57 $justthese = array("dn", 'jpegPhoto','givenName', 'sn'); … … 168 75 } 169 76 170 pr ivatefunction getGlobalContacts($search, $uidNumber){77 protected function getGlobalContacts($search, $uidNumber){ 171 78 $contacts = array(); 172 79 $params = array ("search_for" => $search); … … 188 95 } 189 96 } 190 $ this->result = array ('contacts' => $contacts);191 97 $result = array ('contacts' => $contacts); 98 $this->setResult($result); 192 99 return $this->getResponse(); 193 100 }
Note: See TracChangeset
for help on using the changeset viewer.