source: sandbox/2.2.0.2/expressoMail1_2/inc/class.ldap_functions.inc.php @ 4457

Revision 4457, 25.6 KB checked in by airton, 13 years ago (diff)

Ticket #1991 - Parametrizacao das buscas LDAP no ExpressoMail?

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2require_once($_SESSION['rootPath'].'/API/class.servicelocator.php');
3include_once("class.imap_functions.inc.php");
4include_once("class.functions.inc.php");
5
6function ldapRebind($ldap_connection, $ldap_url)
7{
8        @ldap_bind($ldap_connection, $_SESSION['phpgw_info']['expressomail']['ldap_server']['acc'],$_SESSION['phpgw_info']['expressomail']['ldap_server']['pw']);
9}
10
11class ldap_functions
12{
13        var $ds;
14        var $ldap_host;
15        var $ldap_context;
16        var $imap;
17        var $external_srcs;
18        var $max_result;
19        var $functions;
20        var $ldapService;
21       
22        function ldap_functions(){
23        // todo: Page Configuration for External Catalogs.
24                @include("../contactcenter/setup/external_catalogs.inc.php");
25                $this->ldapService = ServiceLocator::getService('ldap');
26                $this->external_srcs = $external_srcs;
27                $this->max_result = $this->ldapService->limit;
28                $this->functions = new functions();
29        }
30        // Using ContactCenter configuration.
31        function ldapConnect($refer = false,$catalog = 0){
32                if ($catalog > 0 && is_array($this->external_srcs)){
33                        $this->ldap_host        = $this->external_srcs[$catalog]['host'];
34                        $this->ldap_context = $this->external_srcs[$catalog]['dn'];
35                        $this->bind_dn          = $this->external_srcs[$catalog]['acc'];
36                        $this->bind_dn_pw       = $this->external_srcs[$catalog]['pw'];
37                        $this->object_class = $this->external_srcs[$catalog]['obj'];
38                        $this->base_dn          = $this->external_srcs[$catalog]['dn'];
39                        $this->branch           = $this->external_srcs[$catalog]['branch'];
40                }else {
41                        $this->ldap_host        = $_SESSION['phpgw_info']['expressomail']['ldap_server']['host'];
42                        $this->ldap_context = $_SESSION['phpgw_info']['expressomail']['ldap_server']['dn'];
43                        $this->bind_dn = $_SESSION['phpgw_info']['expressomail']['ldap_server']['acc'];
44                        $this->bind_dn_pw = $_SESSION['phpgw_info']['expressomail']['ldap_server']['pw'];
45                        $this->branch = 'ou';
46                }
47
48                $this->ds = ldap_connect($this->ldap_host);
49                ldap_set_option($this->ds, LDAP_OPT_PROTOCOL_VERSION, 3);
50                ldap_set_option($this->ds, LDAP_OPT_REFERRALS, $refer);
51                if ($refer)     {
52                        ldap_set_rebind_proc($this->ds, ldapRebind);
53                }
54                @ldap_bind($this->ds,$this->bind_dn,$this->bind_dn_pw );
55        }
56
57        //Teste jakjr retornando o DS
58        function ldapConnect2($refer = false){
59                $ds = ldap_connect($_SESSION['phpgw_info']['expressomail']['ldap_server']['host']);
60
61                if (!$ds)
62                        return false;
63
64                ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
65                ldap_set_option($ds, LDAP_OPT_REFERRALS, $refer);
66                if ($refer)
67                        ldap_set_rebind_proc($ds, ldapRebind);
68                @ldap_bind($ds, $_SESSION['phpgw_info']['expressomail']['ldap_server']['acc'],$_SESSION['phpgw_info']['expressomail']['ldap_server']['pw']);
69
70                return $ds;
71        }
72
73
74        // usa o host e context do setup.
75        function ldapRootConnect($refer = false){
76                $this->ldap_host        = $_SESSION['phpgw_info']['expressomail']['server']['ldap_host'];
77                $this->ldap_context = $_SESSION['phpgw_info']['expressomail']['server']['ldap_context'];
78                $this->ds                       = ldap_connect($this->ldap_host);
79                ldap_set_option($this->ds, LDAP_OPT_PROTOCOL_VERSION, 3);
80                ldap_set_option($this->ds, LDAP_OPT_REFERRALS, $refer);
81                ldap_bind($this->ds, $_SESSION['phpgw_info']['expressomail']['server']['ldap_root_dn'],$_SESSION['phpgw_info']['expressomail']['server']['ldap_root_pw']);
82
83        }
84
85        function quicksearch($params)
86        {
87                include_once("class.functions.inc.php");
88                $functions = new functions;
89               
90                $field          = $params['field'];
91                $ID                     = $params['ID'];
92
93                $ldapService = ServiceLocator::getService('ldap');
94                $filter =  $ldapService->getSearchFilter($params['search_for']);
95       
96                $contacts_result = array();
97                $contacts_result['field'] = $field;
98                $contacts_result['ID'] = $ID;
99                $search_for = utf8_encode($params['search_for']);
100
101                // follow the referral
102                $this->ldapConnect(true);
103               
104                if ($this->ds)
105        {
106                $ldapService->connection = $this->ds;
107
108                $justthese = array("cn", "mail", "telephonenumber", "mobile", "phpgwaccountvisible", "uid", "employeenumber", "ou");
109                $types = false;
110
111                if( $field == 'null' || $ID == 'null' )
112                {
113                    $justthese[] = "jpegphoto";
114                    $types = 'u';
115                }
116
117                $filter = $ldapService->getSearchFilter( $params['search_for'], $types );
118
119                $sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese, 0, $this->max_result);
120                       
121                if(!$sr)
122                    return null;
123
124                $count_entries = ldap_count_entries($this->ds,$sr);
125
126                $info = ldap_get_entries($this->ds, $sr);
127
128            // New search only on user sector
129            if ($count_entries == $this->max_result)
130            {
131                $overload = $count_entries;
132            }
133            else
134            {
135                $catalogsNum=count($this->external_srcs);
136                for ($i=0; $i<=$catalogsNum; $i++)      {
137                        if ($this->external_srcs[$i]["quicksearch"]) {
138                                $this->ldapConnect(true,$i);
139                                $filter="(|(cn=*$search_for*)(mail=*$search_for*))";
140                                $justthese = array("cn", "mail", "telephoneNumber", "mobile", "phpgwAccountVisible", "uid","employeeNumber", "ou");
141                                $sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese, 0, $this->max_result+1);
142                                if(!$sr)
143                                        return null;
144                                $count_entries = ldap_count_entries($this->ds,$sr);
145                                $search = ldap_get_entries($this->ds, $sr);
146                                for ($j=0; $j<$search["count"]; $j++) {
147                                        $info[] = $search[$j];
148                                }
149                                $info["count"] = count($info)-1;
150                        }
151                }
152            }
153
154            $tmp = array();
155            $tmp_users_from_user_org = array();
156
157            for ($i=0; $i<$info["count"]; $i++)
158            {
159                $key = $info[$i]["mail"][0] . '%' . $info[$i]["telephonenumber"][0] . '%'. $info[$i]["mobile"][0] . '%' .                       $info[$i]["uid"][0] . '%' . $info[$i]["jpegphoto"]['count'] . '%' . $info[$i]["employeenumber"][0] . '%' .      $info[$i]["ou"][0];
160
161                if (/*(!$quickSearch_only_in_userSector) &&*/ preg_match("/$user_sector_dn/i", $info[$i]['dn']))
162                {
163                        $tmp_users_from_user_org[$key] = utf8_decode($info[$i]["cn"][0]);
164                        continue;
165                }
166
167                $tmp[$key] = utf8_decode($info[$i]["cn"][0]);
168            }
169
170            natcasesort($tmp_users_from_user_org);
171            natcasesort($tmp);
172
173            if (($field != 'null') && ($ID != 'null'))
174            {
175                    $i = 0;
176
177                    $tmp = array_merge($tmp, $tmp_users_from_user_org);
178                    natcasesort($tmp);
179
180                    foreach ($tmp as $info => $cn)
181                    {
182                            $contacts_result[$i] = array();
183                            $contacts_result[$i]["cn"] = $cn;
184                            list ($contacts_result[$i]["mail"], $contacts_result[$i]["phone"], $contacts_result[$i]["mobile"], $contacts_result[$i]["uid"], $contacts_result[$i]["jpegphoto"], $contacts_result[$i]["employeenumber"], $contacts_result[$i]["ou"]) = split ('%', $info);
185                            $i++;
186                    }
187                    $contacts_result['quickSearch_only_in_userSector'] = $quickSearch_only_in_userSector;
188                    $contacts_result['maxResult'] = $ldapService->limit;
189            }
190            else
191            {
192                    $options_users_from_user_org = '';
193                    $options = '';
194
195           
196                    $i = 0;
197                    foreach ($tmp_users_from_user_org as $info => $cn)
198                    {
199                            $contacts_result[$i] = array();
200                            $options_users_from_user_org .= $this->make_quicksearch_card($info, $cn);
201                            $i++;
202                    }
203
204           
205                    foreach ($tmp as $info => $cn)
206                    {
207                            $contacts_result[$i] = array();
208                            $options .= $this->make_quicksearch_card($info, $cn);
209                            $i++;
210                    }
211
212
213                    if (($options_users_from_user_org != '') && ($options != ''))
214                    {                                   
215                            $head_option0 =
216                                    '<tr class="quicksearchcontacts_unselected">' .
217                                            '<td colspan="2" width="100%" align="center" style="background:#EEEEEE"><B>' .
218                                                    $this->functions->getLang('Users from your organization') . '</B> ['.count($tmp_users_from_user_org).']';
219                                            '</td>' .
220                                    '</tr>';
221
222                            $head_option1 =
223                                    '<tr class="quicksearchcontacts_unselected">' .
224                                            '<td colspan="2" width="100%" align="center" style="background:#EEEEEE"><B>' .
225                                                    $this->functions->getLang('Users from others organizations') . '</B> ['.count($tmp).']';
226                                            '</td>' .
227                                    '</tr>';
228                    }
229                   
230                    $head_option = '';
231
232                    if( $overload )
233                    $head_option = '<tr class="quicksearchcontacts_unselected">' .
234                                    '<td colspan="2" width="100%" align="center" style="background:#EEEEEE; color: red;"><B>' .str_replace('%1', $this->max_result, $this->functions->getLang('More than %1 results. Please, try to refine your search.')) . '</B> '.
235                                    '</td>' .
236                                    '</tr>';
237
238                    $contacts_result = $head_option.$head_option0 . $options_users_from_user_org . $head_option1. $options;
239
240                }
241            }
242
243            ldap_close($this->ds);
244
245            return $contacts_result;
246        }
247
248        function make_quicksearch_card($info, $cn)
249        {
250                include_once("class.functions.inc.php");
251                $functions = new functions;
252
253                $contacts_result = array();
254                $contacts_result["cn"] = $cn;
255                if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['extended_info'])
256                    $extendedinfo=true;
257                else
258                    $extendedinfo=false;
259
260                list ($contacts_result["mail"], $contacts_result["phone"], $contacts_result["mobile"], $contacts_result["uid"], $contacts_result["jpegphoto"], $contacts_result["employeenumber"], $contacts_result["ou"]) = split ('%', $info);
261
262                if ($contacts_result['jpegphoto'])
263                        $photo_link = '<img src="./inc/show_user_photo.php?mail='.$contacts_result['mail'].'">';
264                else
265                        $photo_link = '<img src="./templates/default/images/photo.jpg">';
266
267                $phoneUser = $contacts_result['phone'];
268
269                if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['voip_enabled'] && $phoneUser) {
270                        $phoneUser = '<a title="'.$this->functions->getLang("Call to Comercial Number").'" href="#" onclick="InfoContact.connectVoip(\''.$phoneUser.'\',\'com\')">'.$phoneUser.'</a>';
271                        if($contacts_result['mobile']){
272                                $phoneUser .= ' / <a title="'.$this->functions->getLang("Call to Mobile Number").'" href="#" onclick="InfoContact.connectVoip(\''.$contacts_result['mobile'].'\',\'mob\')">'.$contacts_result['mobile'].'</a>';
273                        }
274                }
275                //verifica de existe o celular do funcionario ($contacts_result["mobile"]), se nao, $phoneUser fica vazia;
276
277                    $mobileUser = $contacts_result["mobile"];
278                    if($mobileUser && !$voipMobile) {
279                            $phoneUser .= " / $mobileUser";
280                    }
281                    $empNumber = $contacts_result["employeenumber"];
282                    if($empNumber) {
283                            $empNumber = "$empNumber - ";
284                    }
285                    $ou = $contacts_result["ou"];
286                    if($ou) {
287                            $ou = "<br/>$ou" ;
288                    }
289
290                // Begin: nickname, firstname and lastname for QuickAdd.
291                $fn = $contacts_result["cn"];
292                $array_name = explode(" ", $fn);
293                if(count($array_name) > 1){                     
294                        $fn = $array_name[0];
295                        array_shift($array_name);
296                        $sn = implode(" ",$array_name);
297                }
298                // End:
299                $option =
300                        '<tr class="quicksearchcontacts_unselected">' .
301                                '<td class="cc" width="1%">' .
302                                        '<a title="'.$this->functions->getLang("Write message").'" onClick="javascript:QuickSearchUser.create_new_message(\''.$contacts_result["cn"].'\', \''.$contacts_result["mail"].'\')">' .
303                                                $photo_link .
304                                        '</a>' .
305                                '</td>' .
306                                '<td class="cc">' .
307                                        '<span name="cn">' . $empNumber . $contacts_result['cn'] . '</span>' . '<br>' .
308                                        '<a title="'.$functions->getLang("Write message").'" onClick="javascript:QuickSearchUser.create_new_message(\''.$contacts_result["cn"].'\', \''.$contacts_result["mail"].'\')">' .
309                                                '<font color=blue>' .
310                                                '<span name="mail">' . $contacts_result['mail'] . '</span></a></font>'.
311                                                '<img src="templates/default/images/user_card.png" style="cursor: pointer;" title="'.$this->functions->getLang("Add Contact").'" onclick="javascript:connector.loadScript(\'ccQuickAdd\');ccQuickAddOne.showList(\''.$fn.','.$fn.','.$sn.','.$contacts_result["mail"].'\')">'.
312                                        '<br>' .
313                                        $phoneUser .
314                                        $ou .
315                                '</td>' .
316                                '</tr>';
317                return $option;
318        }
319
320        function get_catalogs(){
321                $catalogs = array();
322                $catalogs[0] = $this->functions->getLang("Global Catalog");
323                if($this->external_srcs)
324                        foreach ($this->external_srcs as $key => $valor ){
325                        $catalogs[$key] = $valor['name'];
326                }
327                return $catalogs;
328        }
329        function get_organizations($params){
330                $organizations = array();
331                $params['referral']?$referral = $params['referral']:$referral = false;
332                $cat = $params['catalog'];
333
334                $this->ldapConnect($referral,$cat);
335
336                        if($this->branch != '') {
337                                $filter="(&(".$this->branch."=*)(!(phpgwAccountVisible=-1)))";
338                                $justthese = array("$this->branch");
339                        $sr = ldap_list($this->ds, $this->ldap_context, $filter, $justthese);
340                        $info = ldap_get_entries($this->ds, $sr);
341
342                        if($info["count"] == 0)
343                        {
344                            $organizations[0]['ou'] = $this->ldap_context;
345                        }
346
347                        for ($i=0; $i<$info["count"]; $i++)
348                                $organizations[$i] = $info[$i]["ou"][0];
349
350                        ldap_close($this->ds);
351                        sort($organizations);
352                return $organizations;
353                        }else{
354                        return null;
355        }
356        }
357        function get_organizations2($params){
358                $organizations = array();
359                $referral = $params['referral'];
360                $this->ldapRootConnect($referral);
361                if ($this->ds) {
362                        $filter="(&(objectClass=organizationalUnit)(!(phpgwAccountVisible=-1)))";
363                        $justthese = array("ou");
364                        $sr = ldap_list($this->ds, $this->ldap_context, $filter, $justthese);
365                        $info = ldap_get_entries($this->ds, $sr);
366
367
368                        if($info["count"] == 0)
369                        {
370                            $organizations[0]['ou'] = $this->ldap_context;
371                            $organizations[0]['dn'] = $this->ldap_context;
372                        }
373                        else{
374                            for ($i=0; $i<$info["count"]; $i++)
375                            {
376                                    $organizations[$i]['ou'] = $info[$i]["ou"][0];
377                                    $organizations[$i]['dn'] = $info[$i]["dn"];
378                            }
379                        }
380                        ldap_close($this->ds);
381                        sort($organizations);
382                }
383                return $organizations;
384        }
385        //Busca usuarios de um contexto e ja retorna as options do select - usado por template serpro;
386        function search_users($params)
387    {
388                $owner = $_SESSION['phpgw_info']['expressomail']['user']['owner'];
389                        $ldapService = ServiceLocator::getService('ldap');
390                        $ldapService->connect($_SESSION['phpgw_info']['expressomail']['server']['ldap_host'],
391                        $_SESSION['phpgw_info']['expressomail']['server']['ldap_root_dn'],
392                        $_SESSION['phpgw_info']['expressomail']['server']['ldap_root_pw']);
393                       
394                        $groups = $ldapService->accountSearch($params['filter'], array("gidNumber","cn"), $params['context'] , 'g', 'cn');
395                        $users = $ldapService->accountSearch($params['filter'], array("uidNumber","cn"), $params['context'] , 'u', 'cn');
396                        $group_options = array();
397                        $user_options  = array();
398                        foreach($groups as $group)
399                        {
400                                $group_options[] = '"'.$group['gidNumber'].'U'.'":"'.$group['cn'].'"';
401                }
402                       
403                foreach($users as $user)
404                {
405                                if($owner != $user['uidNumber'])
406                                        $user_options[] = '"'.$user['uidNumber'].'U'.'":"'.$user['cn'].'"';
407                        }
408                       
409                        $user_options = '{'.implode( ',', $user_options ).'}';
410                        $group_options = '{'.implode( ',', $group_options ).'}';
411               
412                return array("users" => $user_options, "groups" => $group_options);
413    }
414
415        function catalogsearch($params)
416        {
417                $ldapService = ServiceLocator::getService('ldap');
418                $filter =  $ldapService->getSearchFilter($params['search_for'],array('u','l','s'));
419               
420                $catalog = $params['catalog'];
421                $error = False;
422               
423                //if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['extended_info'])
424                    //$extendedinfo=true;
425                //else
426                    //$extendedinfo=false;
427
428
429                $this->ldapConnect(true,$catalog);
430
431                $params['organization'] == 'all' ? $user_context = $this->ldap_context :$user_context = $this->branch."=".$params['organization'].",".$this->ldap_context;
432
433                if ($this->ds) {
434                        $justthese = array("cn", "mail", "phpgwaccounttype", "phpgwAccountVisible", "employeeNumber", "ou");
435                        $sr=@ldap_search($this->ds, $user_context, $filter, $justthese, 0, $ldapService->limit+1);
436                       
437                        if(!$sr)
438                                return null;
439                        $count_entries = ldap_count_entries($this->ds,$sr);
440                        if ($count_entries > $ldapService->limit){
441                                $info = null;
442                                $error = True;
443                        }
444                        else
445                                $info = ldap_get_entries($this->ds, $sr);
446
447                        ldap_close($this->ds);
448
449                        $u_tmp = array();
450                        $g_tmp = array();
451
452                        for ($i=0; $i<$info["count"]; $i++){
453                                if((!$catalog==0)||(strtoupper($info[$i]["phpgwaccounttype"][0]) == 'U') && ($info[$i]["phpgwaccountvisible"][0] != '-1'))
454                                        //aqui eh feita a concatenacao do departamento ao cn;
455                                        $u_tmp[$info[$i]["mail"][0]] = utf8_decode($info[$i]["cn"][0]). '%' . $info[$i]["ou"][0];
456                                if((!$catalog==0)||(strtoupper($info[$i]["phpgwaccounttype"][0]) == 'L') && ($info[$i]["phpgwaccountvisible"][0] != '-1'))
457                                        $g_tmp[$info[$i]["mail"][0]] = utf8_decode($info[$i]["cn"][0]);
458                        }
459
460                        natcasesort($u_tmp);
461                        natcasesort($g_tmp);
462
463                        $i = 0;
464                        $users = array();
465
466                        foreach ($u_tmp as $mail => $cn){
467
468                                $tmp = explode("%", $cn); //explode o cn pelo caracter "%" e joga em $tmp;
469                                $name = $tmp[0]; //pega o primeiro item (cn) do vetor resultante do explode acima;
470                                $department = $tmp[1]; //pega o segundo item (ou) do vetor resultanto do explode acima;
471                                $users[$i++] = array("name" => $name, "email" => $mail, "department" => $department);
472
473                        }
474                        unset($u_tmp);
475
476                        $i = 0;
477                        $groups = array();
478
479                        foreach ($g_tmp as $mail => $cn){
480                                $groups[$i++] = array("name" => $cn, "email" => $mail);
481                        }
482                        unset($g_tmp);
483
484                        return  array('users' => $users, 'groups' => $groups, 'error' => $error,'maxResult' => $ldapService->limit);
485                }else
486                return null;
487        }
488
489        function get_emails_ldap(){
490
491                $result['mail']= array();
492                $result['mailalter']= array();
493                $user = $_SESSION['phpgw_info']['expressomail']['user']['account_lid'];
494                $this->ldapRootConnect(false);
495                if ($this->ds) {
496                        $filter="uid=".$user;
497                        $justthese = array("mail","mailAlternateAddress");
498                        $sr = ldap_search($this->ds,$this->ldap_context, $filter, $justthese);
499                        $ent = ldap_get_entries($this->ds, $sr);
500                        ldap_close($this->ds);
501
502                        for ($i=0; $i<$ent["count"]; $i++){
503                                $result['mail'][] = $ent[$i]["mail"][0];
504                                $result['mailalter'][] = $ent[$i]["mailalternateaddress"][0];
505                        }
506                }
507                return $result;
508        }
509
510        //Busca usuarios de um contexto e ja retorna as options do select;
511        function get_available_users($params)
512    {
513        $this->ldapRootConnect();
514        //Monta lista de Grupos e Usuarios
515        $users = Array();
516        $groups = Array();
517        $user_context= $params['context'];
518        $owner = $_SESSION['phpgw_info']['expressomail']['user']['owner'];
519
520        if ($this->ds)
521        {
522            $justthese = array("gidNumber","cn");
523            if ($params['type'] == 'search')
524                $sr=ldap_search($this->ds, $user_context, ("(&(cn=*)(phpgwaccounttype=g)(!(phpgwaccountvisible=-1)))"),$justthese);
525            else
526                $sr=ldap_list($this->ds, $user_context, ("(&(cn=*)(phpgwaccounttype=g)(!(phpgwaccountvisible=-1)))"),$justthese);
527            $info = ldap_get_entries($this->ds, $sr);
528            for ($i=0; $i<$info["count"]; $i++)
529                $groups[$uids=$info[$i]["gidnumber"][0]] = Array('name'    =>    $uids=$info[$i]["cn"][0], 'type'    =>    g);
530            $justthese = array("phpgwaccountvisible","uidNumber","cn");
531            if ($params['type'] == 'search')
532                $sr=ldap_search($this->ds, $user_context, ("(&(cn=*)(phpgwaccounttype=u)(!(phpgwaccountvisible=-1)))"),$justthese);
533            else
534                $sr=ldap_list($this->ds, $user_context, ("(&(cn=*)(phpgwaccounttype=u)(!(phpgwaccountvisible=-1)))"),$justthese);
535
536            $info = ldap_get_entries($this->ds, $sr);
537            for ($i=0; $i<$info["count"]; $i++)
538            {
539                if ($info[$i]["phpgwaccountvisible"][0] == '-1')
540                    continue;
541                $users[$uids=$info[$i]["uidnumber"][0]] = Array('name'    =>    $uids=$info[$i]["cn"][0], 'type'    =>    u);
542            }
543        }
544        ldap_close($this->ds);
545
546        @asort($users);
547        @reset($users);
548        @asort($groups);
549        @reset($groups);
550        $user_options ='';
551        $group_options ='';
552
553        foreach($groups as $id => $user_array) {
554                $newId = $id.'U';
555                $group_options .= '<option  value="'.$newId.'">'.utf8_decode($user_array['name']).'</option>'."\n";
556        }
557        foreach($users as $id => $user_array) {
558            if($owner != $id){
559                $newId = $id.'U';
560                $user_options .= '<option  value="'.$newId.'">'.utf8_decode($user_array['name']).'</option>'."\n";
561            }
562        }
563        return array("users" => $user_options, "groups" => $group_options);
564    }
565
566        //Busca usuarios de um contexto e ja retorna as options do select;
567        function get_available_users2($params)
568        {
569                $ldapService = ServiceLocator::getService('ldap');
570                $ldapService->connect($_SESSION['phpgw_info']['expressomail']['server']['ldap_host'],
571                $_SESSION['phpgw_info']['expressomail']['server']['ldap_root_dn'],
572                $_SESSION['phpgw_info']['expressomail']['server']['ldap_root_pw']);
573               
574                $entries = $ldapService->accountSearch($params['sentence'], array('cn', 'uid'), $params['context'], 'u', 'cn');
575               
576                $options = array();
577               
578                foreach ($entries as $value)
579                        $options[] = '"'.$value['uid'].'"'.':'.'"'.$value['cn'].'"';
580               
581                return "{".implode(',',$options)."}";           
582        }
583
584        function uid2cn($uid)
585        {
586                // do not follow the referral
587                $this->ldapRootConnect(false);
588                if ($this->ds)
589                {
590                        $filter="(&(phpgwAccountType=u)(uid=$uid))";
591                        $justthese = array("cn");
592                        $sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese);
593                        if(!$sr)
594                                return false;
595                        $info = ldap_get_entries($this->ds, $sr);
596                        return utf8_decode($info[0]["cn"][0]);
597                }
598                return false;
599        }
600        function uidnumber2uid($uidnumber)
601        {
602                // do not follow the referral
603                $this->ldapRootConnect(false);
604                if ($this->ds)
605                {
606                        $filter="(&(phpgwAccountType=u)(uidnumber=$uidnumber))";
607                        $justthese = array("uid");
608                        $sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese);
609                        if(!$sr)
610                                return false;
611                        $info = ldap_get_entries($this->ds, $sr);
612                        return $info[0]["uid"][0];
613                }
614                return false;
615        }
616        function getSharedUsersFrom($params){
617                $filter = '';
618                $i = 0;         
619                //Added to save if must save sent messages in shared folder
620                $acl_save_sent_in_shared = array();
621               
622                if($params['uids']) {
623                        $uids = explode(";",$params['uids']);
624                        $this->imap = new imap_functions();                     
625                        foreach($uids as $index => $uid){
626                                $params = array();
627                                //Added to save if user has create permission
628                                $acl_create_message = array();
629                                $acl = $this->imap->getacltouser($uid);
630                                if ( preg_match("/a/",$acl )){                         
631                                        $filter .= "(uid=$uid)";                                       
632                                        if ( preg_match("/p/",$acl )){                         
633                                                $acl_save_sent_in_shared[ $i ] =$uid;
634                                                $i++;
635                                        }                                       
636                                }                                                       
637                        }                       
638                }
639               
640                $this->ldapRootConnect(false);
641                if ($this->ds) {
642                        $justthese = array("cn","mail","uid");
643                        if($filter) {
644                                $filter="(&(|(phpgwAccountType=u)(phpgwAccountType=s))(|$filter))";
645                                $sr             =       ldap_search($this->ds, $this->ldap_context, $filter, $justthese);
646                                ldap_sort($this->ds,$sr,"cn");
647                                $info   =       ldap_get_entries($this->ds, $sr);
648                                $var = print_r($acl_save_sent_in_shared, true);                         
649                                for ($i = 0;$i < $info["count"]; $i++){
650                                        $info[$i]['cn'][0] = utf8_decode($info[$i]['cn'][0]);
651                                        //verify if user has permission to save sent messages in a shared folder
652                                        if ( in_array( $info[$i]['uid'][0],$acl_save_sent_in_shared) ){                                         
653                                                $info[$i]['save_shared'][0] = 'y';
654                                        } else $info[$i]['save_shared'][0] = 'n';
655                                }
656                        }
657               
658                        $info['myname'] = $_SESSION['phpgw_info']['expressomail']['user']['fullname'];
659
660                        //Find institucional_account.
661                        $filter="(&(phpgwAccountType=i)(mailForwardingAddress=".$_SESSION['phpgw_info']['expressomail']['user']['email']."))";
662                        $sr     = ldap_search($this->ds, $this->ldap_context, $filter, $justthese);
663                        ##
664                        # @AUTHOR Rodrigo Souza dos Santos
665                        # @DATE 2008/09/17
666                        # @BRIEF Changing to ensure that the variable session is always with due value.
667                        ##
668                        if(ldap_count_entries($this->ds,$sr))
669                        {
670                                ldap_sort($this->ds,$sr,"cn");
671                                $result = ldap_get_entries($this->ds, $sr);
672                                for ($j = 0;$j < $result["count"]; $j++){
673                                        $info[$i]['cn'][0] = utf8_decode($result[$j]['cn'][0]);
674                                        $info[$i]['mail'][0] = $result[$j]['mail'][0];
675                                        $info[$i]['save_shared'][0] = 'n';
676                                        $info[$i++]['uid'][0] = $result[$j]['uid'][0];                                 
677                                }
678                        }
679
680                        $_SESSION['phpgw_info']['expressomail']['user']['shared_mailboxes'] = $info;
681                       
682                        return $info;
683                }
684        }
685
686        function getUserByEmail($params)
687        {
688                $expires = 60*60*24*30; /* 30 days */
689                header("Cache-Control: maxage=".$expires);
690                header("Pragma: public");
691                header("Expires: ".gmdate('D, d M Y H:i:s', time()+$expires)); 
692                $filter="(&(phpgwAccountType=u)(mail=" . $params['email'] . "))";
693                $ldap_context = $_SESSION['phpgw_info']['expressomail']['ldap_server']['dn'];
694                if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['extended_info'])
695                    $extendedinfo=true;
696                else
697                    $extendedinfo=false;
698
699                if($extendedinfo)
700                    $justthese = array("cn","uid","telephoneNumber","jpegPhoto","mobile","ou","employeeNumber");
701                else
702                    $justthese = array("cn","uid","telephoneNumber","jpegPhoto","mobile");
703
704                // Follow the referral
705                $ds = $this->ldapConnect2(true);
706                if ($ds)
707                {
708                        $sr=@ldap_search($ds, $ldap_context, $filter, $justthese);
709
710                        if (!$sr)
711                                return null;
712
713                        $entry = ldap_first_entry($ds, $sr);
714
715                        if($entry) {
716                                $obj =  array("cn" => utf8_decode(current(ldap_get_values($ds, $entry, "cn"))),
717                                                  "email" => $params['email'],
718                                                  "uid" => ldap_get_values($ds, $entry, "uid"),
719                                                  "type" => "global",
720                                                  "mobile" =>  @ldap_get_values($ds, $entry, "mobile"),
721                                                  "telefone" =>  @ldap_get_values($ds, $entry, "telephonenumber"),
722                                                  "ou" =>  @ldap_get_values($ds, $entry, "ou"),
723                                                  "employeeNumber" =>  @ldap_get_values($ds, $entry, "employeeNumber")
724                                        );
725
726                                $_SESSION['phpgw_info']['expressomail']['contact_photo'] = @ldap_get_values_len($ds, $entry, "jpegphoto");
727                                ldap_close($ds);
728                                return $obj;
729                        }
730                }
731                return null;
732        }
733       
734        function uid2uidnumber($uid)
735        {
736                // do not follow the referral
737                $this->ldapRootConnect(false);
738                if ($this->ds)
739                {
740                        $filter="(&(phpgwAccountType=u)(uid=$uid))";
741                        $justthese = array("uidnumber");
742                        $sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese);
743                        if(!$sr)
744                                return false;
745                        $info = ldap_get_entries($this->ds, $sr);
746                        return $info[0]["uidnumber"][0];
747                }
748                return false;
749        }
750}
751?>
Note: See TracBrowser for help on using the repository browser.