Changeset 5712


Ignore:
Timestamp:
03/13/12 11:45:33 (12 years ago)
Author:
niltonneto
Message:

Ticket #2507 - Adicionado em getImagePicture() busca para foto de usuário LDAP.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sandbox/webservice/api/json-rpc/Catalog.php

    r5707 r5712  
    6969         
    7070        public function getImagePicture($params){                
    71                 if($this->isLoggedIn($params) && $params['contactID'] > 0) {                     
    72                         $query = 'select A.id_contact, A.photo from phpgw_cc_contact A where A.id_contact='.$params['contactID'].' and A.id_owner='.$this -> getUserId();                
    73                         if (!$this->getDb()->query($query)) 
    74                                 return false; 
    75  
     71                if($this->isLoggedIn($params) && $params['contactID'] != null) { 
    7672                        $contact = array(); 
    77                         if($this->getDb()->next_record()) { 
    78                                 $row = $this->getDb()->row(); 
    79                                 if($row['photo'] != null) { 
    80                                         $contact[] = array( 
    81                                                 'contactID'             => $row['id_contact'], 
    82                                                 'contactImagePicture'   => ($row['photo'] != null ? base64_encode($row['photo']) : "") 
    83                                         ); 
    84                                 }                        
     73                        // User Contact  
     74                        if($params['contactType'] == 1){ 
     75                                $query = 'select A.id_contact, A.photo from phpgw_cc_contact A where A.id_contact='.$params['contactID'].' and A.id_owner='.$this -> getUserId();                
     76                                if (!$this->getDb()->query($query)) 
     77                                        return false; 
     78                                if($this->getDb()->next_record()) { 
     79                                        $row = $this->getDb()->row(); 
     80                                        if($row['photo'] != null) { 
     81                                                $contact[] = array( 
     82                                                        'contactID'             => $row['id_contact'], 
     83                                                        'contactImagePicture'   => ($row['photo'] != null ? base64_encode($row['photo']) : "") 
     84                                                ); 
     85                                        } 
     86                                } 
    8587                        } 
     88                        // Global Catalog                        
     89                        elseif($params['contactType'] == 2){ 
     90                                $photo = $this->getUserLdapPhoto($params['contactID']); 
     91                                $contact[] = array( 
     92                                                'contactID'             => $params['contactID'], 
     93                                                'contactImagePicture'   => ($photo != null ? base64_encode($photo[0]) : "") 
     94                                ); 
     95                                 
     96                        }                        
    8697                        $this->result = array ('contacts' => $contact); 
    8798                } 
     
    115126                } 
    116127                return false; 
     128        } 
     129         
     130        private function getUserLdapPhoto($contactID) {          
     131                $ldap_context = $_SESSION['phpgw_info']['expressomail']['ldap_server']['dn']; 
     132                $justthese = array("dn", 'jpegPhoto','givenName', 'sn'); 
     133                $this->getLdapCatalog()->ldapConnect(true); 
     134                $ds = $this->getLdapCatalog()->ds;               
     135                 
     136                if ($ds){ 
     137                        $resource = ldap_read($ds, $contactID, "phpgwaccounttype=u"); 
     138                        $n_entries = ldap_count_entries($ds, $resource); 
     139                        error_log("entrou foto =".$n_entries); 
     140                        if ( $n_entries == 1) {                  
     141                                $first_entry = ldap_first_entry($ds, $resource); 
     142                                $obj = ldap_get_attributes($ds, $first_entry); 
     143                                 
     144                                if($obj['jpegPhoto']){ 
     145                                        return ldap_get_values_len( $ds, $first_entry, "jpegPhoto"); 
     146                                } 
     147                        }                                                                
     148                } 
     149                return false; 
    117150        }        
    118151         
     
    133166                                ); 
    134167                                // Buscar atributos faltantes.  
    135                                 $contacts[$i] = array_merge($this->getUserLdapAttrs($result[$i]['mail']), $contacts[$i]);                                
     168                                if(is_array($this->getUserLdapAttrs($result[$i]['mail']))) 
     169                                        $contacts[$i] = array_merge($this->getUserLdapAttrs($result[$i]['mail']), $contacts[$i]);                                
    136170                        } 
    137171                } 
Note: See TracChangeset for help on using the changeset viewer.