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

Revision 448, 22.8 KB checked in by niltonneto, 16 years ago (diff)

Ocorrência #333 - Validação do remetente na classe PHP.

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