source: sandbox/webservice/api/rest/catalog/Catalog.php @ 6112

Revision 6112, 3.1 KB checked in by niltonneto, 12 years ago (diff)

Ticket #2507 - Corrigido método getUserId() que foi impactado pelo commit anterior.

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