source: branches/2.2/expressoMail1_2/inc/class.ldap_functions.inc.php @ 3163

Revision 3163, 28.2 KB checked in by amuller, 14 years ago (diff)

Ticket #1163 - Mudando data de expiração das fotos

  • 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");
[1740]22                $this->external_srcs= ( isset( $external_srcs ) ) ? $external_srcs : NULL;
[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                        {
[1918]123                                $filter="(& (&(|(phpgwAccountType=u)(phpgwAccountType=g)(phpgwAccountType=l)(phpgwAccountType=i)(phpgwAccountType=s))(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
[1495]312                        $photo_link = '<img src="./templates/default/images/photo.jpg">';
[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 != '') {
[1363]368                                $filter="(&(".$this->branch."=*)(!(phpgwAccountVisible=-1)))";
[325]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) {
[1363]388                        $filter="(&(ou=*)(!(phpgwAccountVisible=-1)))";
[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        }
[925]404       
405        //Busca usuarios de um contexto e ja retorna as options do select - usado por template serpro;
406        function search_users($params)
407        {
408                $this->ldapConnect(false,0);
409                //Monta lista de Grupos e Usuarios
410                $users = Array();
411                $groups = Array();
412                $user_context= $this->ldap_context;
413                $owner = $_SESSION['phpgw_info']['expressomail']['user']['owner'];
414                $filtro =utf8_encode($params['filter']);
415                $context =utf8_encode($params['context']);//adicionado
[2]416
[925]417                if ($this->ds)
418                {
419                    $justthese = array("gidNumber","cn");
420                    if ($params['type'] == 'search')
[1633]421                        $sr=ldap_search($this->ds, $context, ("(&(phpgwaccounttype=g)(!(phpgwaccountvisible=-1))(cn=*$filtro*))"),$justthese);
[925]422                    else
[1639]423                        $sr=ldap_list($this->ds,  $context ? $context : $user_context, ("(&(phpgwaccounttype=g)(!(phpgwaccountvisible=-1))(cn=*".$filtro."*))"),$justthese);
[925]424                    $info = ldap_get_entries($this->ds, $sr);
425                    for ($i=0; $i<$info["count"]; $i++)
426                        $groups[$uids=$info[$i]["gidnumber"][0]] = Array('name'    =>    $uids=$info[$i]["cn"][0], 'type'    =>    g);
427                    $justthese = array("phpgwaccountvisible","uidNumber","cn");
428                    if ($params['type'] == 'search')
429                       // $sr=ldap_search($this->ds, $user_context, ("(&(phpgwaccounttype=u)(!(phpgwaccountvisible=-1))(phpgwaccountstatus=A)(|(cn=*$filtro*)(mail=$filtro*)))"),$justthese);
430                       $sr=ldap_search($this->ds, $context, ("(&(phpgwaccounttype=u)(!(phpgwaccountvisible=-1))(phpgwaccountstatus=A)(|(cn=*$filtro*)(mail=$filtro*)))"),$justthese);
431                    else
[1639]432                        $sr=ldap_list($this->ds, $context ? $context : $user_context, ("(&(phpgwaccounttype=u)(!(phpgwaccountvisible=-1))(phpgwaccountstatus=A)(|(cn=*$filtro*)(mail=$filtro*)))"),$justthese);
[925]433
434                    $info = ldap_get_entries($this->ds, $sr);
435                    for ($i=0; $i<$info["count"]; $i++)
436                    {
437                        if ($info[$i]["phpgwaccountvisible"][0] == '-1')
438                      continue;
439                        $users[$uids=$info[$i]["uidnumber"][0]] = Array('name'    =>    $uids=$info[$i]["cn"][0], 'type'    =>    u);
440                    }
441                }
442                ldap_close($this->ds);
443       
444                @asort($users);
445                @reset($users);
446                @asort($groups);
447                @reset($groups);
448                $user_options ='';
449                $group_options ='';
450
451                foreach($groups as $id => $user_array) {
452                        $newId = $id.'U';
453                        $group_options .= '<option  value="'.$newId.'">'.utf8_decode($user_array['name']).'</option>'."\n";
454                }
455                foreach($users as $id => $user_array) {
456                    if($owner != $id){
457                        $newId = $id.'U';
458                        $user_options .= '<option  value="'.$newId.'">'.utf8_decode($user_array['name']).'</option>'."\n";
459                    }
460                }
461                return array("users" => $user_options, "groups" => $group_options);
462        }
463
[2]464        function catalogsearch($params)
[387]465        {
[325]466                $cn     = $params['search_for'] ? "*".utf8_encode($params['search_for'])."*" : "*";
[387]467                $max_result       = $params['max_result'] ? $params['max_result'] : $this->max_result;
[325]468                $catalog = $params['catalog'];
[2]469                $error = False;
[387]470
[381]471                $this->ldapConnect(true,$catalog);
[387]472
473                $params['organization'] == 'all' ? $user_context = $this->ldap_context :$user_context = $this->branch."=".$params['organization'].",".$this->ldap_context;
474
475                if ($this->ds) {
[325]476                        if ($catalog == 0){
477                                //os atributos "employeeNumber" e "ou" foram adicionado ao vetor de busca;
478                                $justthese = array("cn", "mail", "phpgwaccounttype", "phpgwAccountVisible", "employeeNumber", "ou");
479                                $filter="(&(|(phpgwAccountType=u)(phpgwAccountType=l))(cn=".$cn."))";
480                                //$user_context = "ou=".$params['organization'].",".$this->ldap_context;
481                        }else {
482                                //os atributos "employeeNumber" e "ou" foram adicionado ao vetor de busca;
483                                $justthese = array("cn", "mail", "employeeNumber", "ou");
484                                $filter="(&(objectClass=".$this->object_class.")(cn=".$cn."))";
485                                //$user_context = $this->branch."=".$params['organization'].",".$external_srcs[$catalog]['dn'];
486                        }
[387]487
[381]488                        $sr=@ldap_search($this->ds, $user_context, $filter, $justthese, 0, $max_result+1);
[342]489                        if(!$sr)
490                                return null;
[2]491                        $count_entries = ldap_count_entries($this->ds,$sr);
[381]492                        if ($count_entries > $max_result){
[2]493                                $info = null;
[387]494                                $error = True;
[2]495                        }
496                        else
[387]497                                $info = ldap_get_entries($this->ds, $sr);
498
499                        ldap_close($this->ds);
500
[2]501                        $u_tmp = array();
502                        $g_tmp = array();
[387]503
[2]504                        for ($i=0; $i<$info["count"]; $i++){
[325]505                                if((!$catalog==0)||(strtoupper($info[$i]["phpgwaccounttype"][0]) == 'U') && ($info[$i]["phpgwaccountvisible"][0] != '-1'))
506                                        //aqui eh feita a concatenacao do departamento ao cn;
507                                        $u_tmp[$info[$i]["mail"][0]] = utf8_decode($info[$i]["cn"][0]). '%' . $info[$i]["ou"][0];
[387]508                                if((!$catalog==0)||(strtoupper($info[$i]["phpgwaccounttype"][0]) == 'L') && ($info[$i]["phpgwaccountvisible"][0] != '-1'))
[325]509                                        $g_tmp[$info[$i]["mail"][0]] = utf8_decode($info[$i]["cn"][0]);
[387]510                        }
511
[2]512                        natcasesort($u_tmp);
513                        natcasesort($g_tmp);
[387]514
[2]515                        $i = 0;
[387]516                        $users = array();
[325]517
[387]518                        foreach ($u_tmp as $mail => $cn){
519
[325]520                                $tmp = explode("%", $cn); //explode o cn pelo caracter "%" e joga em $tmp;
521                                $name = $tmp[0]; //pega o primeiro item (cn) do vetor resultante do explode acima;
522                                $department = $tmp[1]; //pega o segundo item (ou) do vetor resultanto do explode acima;
523                                $users[$i++] = array("name" => $name, "email" => $mail, "department" => $department);
524
[2]525                        }
526                        unset($u_tmp);
[387]527
528                        $i = 0;
[2]529                        $groups = array();
[387]530
531                        foreach ($g_tmp as $mail => $cn){
[2]532                                $groups[$i++] = array("name" => $cn, "email" => $mail);
533                        }
534                        unset($g_tmp);
[387]535
[2]536                        return  array('users' => $users, 'groups' => $groups, 'error' => $error);
[387]537                }else
[2]538                return null;
539        }
[387]540
[2]541        function get_emails_ldap(){
542
543                $result['mail']= array();
[387]544                $result['mailalter']= array();
[2]545                $user = $_SESSION['phpgw_info']['expressomail']['user']['account_lid'];
546                $this->ldapRootConnect(false);
547                if ($this->ds) {
[387]548                        $filter="uid=".$user;
[2]549                        $justthese = array("mail","mailAlternateAddress");
550                        $sr = ldap_search($this->ds,$this->ldap_context, $filter, $justthese);
551                        $ent = ldap_get_entries($this->ds, $sr);
552                        ldap_close($this->ds);
[387]553
[2]554                        for ($i=0; $i<$ent["count"]; $i++){
555                                $result['mail'][] = $ent[$i]["mail"][0];
[387]556                                $result['mailalter'][] = $ent[$i]["mailalternateaddress"][0];
[2]557                        }
558                }
559                return $result;
560        }
[387]561
[342]562        //Busca usuarios de um contexto e ja retorna as options do select;
[2]563        function get_available_users($params)
[37]564    {
565        $this->ldapRootConnect();
[342]566        //Monta lista de Grupos e Usuarios
[37]567        $users = Array();
568        $groups = Array();
569        $user_context= $params['context'];
570        $owner = $_SESSION['phpgw_info']['expressomail']['user']['owner'];
[2]571
[37]572        if ($this->ds)
573        {
574            $justthese = array("gidNumber","cn");
575            if ($params['type'] == 'search')
576                $sr=ldap_search($this->ds, $user_context, ("(&(cn=*)(phpgwaccounttype=g)(!(phpgwaccountvisible=-1)))"),$justthese);
577            else
578                $sr=ldap_list($this->ds, $user_context, ("(&(cn=*)(phpgwaccounttype=g)(!(phpgwaccountvisible=-1)))"),$justthese);
579            $info = ldap_get_entries($this->ds, $sr);
580            for ($i=0; $i<$info["count"]; $i++)
[387]581                $groups[$uids=$info[$i]["gidnumber"][0]] = Array('name'    =>    $uids=$info[$i]["cn"][0], 'type'    =>    g);
[37]582            $justthese = array("phpgwaccountvisible","uidNumber","cn");
583            if ($params['type'] == 'search')
584                $sr=ldap_search($this->ds, $user_context, ("(&(cn=*)(phpgwaccounttype=u)(!(phpgwaccountvisible=-1)))"),$justthese);
585            else
586                $sr=ldap_list($this->ds, $user_context, ("(&(cn=*)(phpgwaccounttype=u)(!(phpgwaccountvisible=-1)))"),$justthese);
[2]587
[37]588            $info = ldap_get_entries($this->ds, $sr);
589            for ($i=0; $i<$info["count"]; $i++)
590            {
591                if ($info[$i]["phpgwaccountvisible"][0] == '-1')
592                    continue;
593                $users[$uids=$info[$i]["uidnumber"][0]] = Array('name'    =>    $uids=$info[$i]["cn"][0], 'type'    =>    u);
594            }
595        }
596        ldap_close($this->ds);
[387]597
[37]598        @asort($users);
[387]599        @reset($users);
[37]600        @asort($groups);
601        @reset($groups);
602        $user_options ='';
603        $group_options ='';
[2]604
[37]605        foreach($groups as $id => $user_array) {
606                $newId = $id.'U';
607                $group_options .= '<option  value="'.$newId.'">'.utf8_decode($user_array['name']).'</option>'."\n";
608        }
609        foreach($users as $id => $user_array) {
610            if($owner != $id){
611                $newId = $id.'U';
612                $user_options .= '<option  value="'.$newId.'">'.utf8_decode($user_array['name']).'</option>'."\n";
613            }
614        }
615        return array("users" => $user_options, "groups" => $group_options);
616    }
617
[342]618        //Busca usuarios de um contexto e ja retorna as options do select;
[2]619        function get_available_users2($params)
620        {
621                $this->ldapRootConnect();
[387]622
[2]623                $context= $params['context'];
624                $justthese = array("cn", "uid", "cn");
[21]625                $filter = "(&(phpgwaccounttype=u)(!(phpgwaccountvisible=-1)))";
[2]626
[387]627            if ($this->ds)
[2]628            {
629                        $sr=ldap_search($this->ds, $context, $filter, $justthese);
630                        $entries = ldap_get_entries($this->ds, $sr);
[387]631
[2]632                        for ($i=0; $i<$entries["count"]; $i++){
633                                if($_SESSION['phpgw_info']['expressomail']['user']['account_lid'] != $entries[$i]["uid"][0]){
634                                        $u_tmp[$entries[$i]["uid"][0]] = $entries[$i]["cn"][0];
635                                }
636                        }
[387]637
[2]638                        natcasesort($u_tmp);
639
640                        $i = 0;
641                        $users = array();
[387]642
[2]643                        if (count($u_tmp))
644                        {
645                                foreach ($u_tmp as $uidnumber => $cn)
646                                {
647                                        $options .= "<option value=$uidnumber>$cn</option>";
648                                }
649                                unset($u_tmp);
650                        }
651
652                        ldap_close($this->ds);
653                return $options;
654                }
655        }
[387]656
[2]657        function uid2cn($uid)
[387]658        {
[2]659                // do not follow the referral
660                $this->ldapRootConnect(false);
661                if ($this->ds)
662                {
[387]663                        $filter="(&(phpgwAccountType=u)(uid=$uid))";
[2]664                        $justthese = array("cn");
[344]665                        $sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese);
666                        if(!$sr)
667                                return false;
[2]668                        $info = ldap_get_entries($this->ds, $sr);
[325]669                        return utf8_decode($info[0]["cn"][0]);
[2]670                }
671                return false;
672        }
[757]673        function uidnumber2uid($uidnumber)
674        {
675                // do not follow the referral
676                $this->ldapRootConnect(false);
677                if ($this->ds)
678                {
679                        $filter="(&(phpgwAccountType=u)(uidnumber=$uidnumber))";
680                        $justthese = array("uid");
681                        $sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese);
682                        if(!$sr)
683                                return false;
684                        $info = ldap_get_entries($this->ds, $sr);
685                        return $info[0]["uid"][0];
686                }
687                return false;
688        }
[387]689        function getSharedUsersFrom($params){
[2]690                $filter = '';
[1912]691                $i = 0;         
692                //Added to save if must save sent messages in shared folder
693                $acl_save_sent_in_shared = array();
694               
[371]695                if($params['uids']) {
[387]696                        $uids = explode(";",$params['uids']);
[1912]697                        $this->imap = new imap_functions();                     
[371]698                        foreach($uids as $index => $uid){
[387]699                                $params = array();
[1912]700                                //Added to save if user has create permission
701                                $acl_create_message = array();
[371]702                                $acl = $this->imap->getacltouser($uid);
[1912]703                                if ( preg_match("/a/",$acl )){                         
704                                        $filter .= "(uid=$uid)";                                       
705                                        if ( preg_match("/p/",$acl )){                         
706                                                $acl_save_sent_in_shared[ $i ] =$uid;
707                                                $i++;
708                                        }                                       
709                                }                                                       
710                        }                       
[2]711                }
[1912]712               
[387]713                $this->ldapRootConnect(false);
[371]714                if ($this->ds) {
[1912]715                        $justthese = array("cn","mail","uid");
[371]716                        if($filter) {
[1912]717                                $filter="(&(|(phpgwAccountType=u)(phpgwAccountType=s))(|$filter))";
[371]718                                $sr             =       ldap_search($this->ds, $this->ldap_context, $filter, $justthese);
[387]719                                ldap_sort($this->ds,$sr,"cn");
720                                $info   =       ldap_get_entries($this->ds, $sr);
[1912]721                                $var = print_r($acl_save_sent_in_shared, true);                         
722                                for ($i = 0;$i < $info["count"]; $i++){
[371]723                                        $info[$i]['cn'][0] = utf8_decode($info[$i]['cn'][0]);
[1912]724                                        //verify if user has permission to save sent messages in a shared folder
725                                        if ( in_array( $info[$i]['uid'][0],$acl_save_sent_in_shared) ){                                         
726                                                $info[$i]['save_shared'][0] = 'y';
727                                        } else $info[$i]['save_shared'][0] = 'n';
728                                }
[371]729                        }
[1912]730               
[371]731                        $info['myname'] = $_SESSION['phpgw_info']['expressomail']['user']['fullname'];
[387]732
[371]733                        //Find institucional_account.
734                        $filter="(&(phpgwAccountType=i)(mailForwardingAddress=".$_SESSION['phpgw_info']['expressomail']['user']['email']."))";
[387]735                        $sr     = ldap_search($this->ds, $this->ldap_context, $filter, $justthese);
[448]736                        ##
737                        # @AUTHOR Rodrigo Souza dos Santos
738                        # @DATE 2008/09/17
739                        # @BRIEF Changing to ensure that the variable session is always with due value.
740                        ##
741                        if(ldap_count_entries($this->ds,$sr))
742                        {
743                                ldap_sort($this->ds,$sr,"cn");
744                                $result = ldap_get_entries($this->ds, $sr);
745                                for ($j = 0;$j < $result["count"]; $j++){
746                                        $info[$i]['cn'][0] = utf8_decode($result[$j]['cn'][0]);
[1912]747                                        $info[$i]['mail'][0] = $result[$j]['mail'][0];
748                                        $info[$i]['save_shared'][0] = 'n';
749                                        $info[$i++]['uid'][0] = $result[$j]['uid'][0];                                 
[448]750                                }
[371]751                        }
[448]752
753                        $_SESSION['phpgw_info']['expressomail']['user']['shared_mailboxes'] = $info;
[1912]754                       
[2]755                        return $info;
756                }
757        }
[27]758
[205]759        function getUserByEmail($params)
760        {
[3163]761                $expires = 60*60*24*30; /* 30 days */
762                header("Cache-Control: maxage=".$expires);
763                header("Pragma: public");
764                header("Expires: ".gmdate('D, d M Y H:i:s', time()+$expires)); 
[205]765                $filter="(&(phpgwAccountType=u)(mail=" . $params['email'] . "))";
766                $ldap_context = $_SESSION['phpgw_info']['expressomail']['ldap_server']['dn'];
767                $justthese = array("cn","uid","telephoneNumber","jpegPhoto","mobile");
768
[27]769                // Follow the referral
[205]770                $ds = $this->ldapConnect2(true);
771                if ($ds)
[387]772                {
[342]773                        $sr=@ldap_search($ds, $ldap_context, $filter, $justthese);
[387]774
[205]775                        if (!$sr)
776                                return null;
[387]777
[205]778                        $entry = ldap_first_entry($ds, $sr);
[387]779
780                        if($entry) {
[381]781                                $obj =  array("cn" => utf8_decode(current(ldap_get_values($ds, $entry, "cn"))),
[205]782                                                  "email" => $params['email'],
783                                                  "uid" => ldap_get_values($ds, $entry, "uid"),
[27]784                                                  "type" => "global",
[205]785                                                  "mobile" =>  @ldap_get_values($ds, $entry, "mobile"),
786                                                  "telefone" =>  @ldap_get_values($ds, $entry, "telephonenumber")
787                                        );
[27]788
[320]789                                $_SESSION['phpgw_info']['expressomail']['contact_photo'] = @ldap_get_values_len($ds, $entry, "jpegphoto");
[205]790                                ldap_close($ds);
[27]791                                return $obj;
[205]792                        }
[27]793                }
794                return null;
795        }
[1500]796       
797        function uid2uidnumber($uid)
798        {
799                // do not follow the referral
800                $this->ldapRootConnect(false);
801                if ($this->ds)
802                {
803                        $filter="(&(phpgwAccountType=u)(uid=$uid))";
804                        $justthese = array("uidnumber");
805                        $sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese);
806                        if(!$sr)
807                                return false;
808                        $info = ldap_get_entries($this->ds, $sr);
809                        return $info[0]["uidnumber"][0];
810                }
811                return false;
812        }
[2]813}
[108]814?>
Note: See TracBrowser for help on using the repository browser.