source: trunk/expressoMail1_2/inc/class.ldap_functions.inc.php @ 644

Revision 644, 23.3 KB checked in by niltonneto, 15 years ago (diff)

Resolve #271

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