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

Revision 881, 23.8 KB checked in by niltonneto, 15 years ago (diff)

Ticket #480 - Inclusão dos grupos LDAP na busca rápida existente em nova mensagem.

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