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 *
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'];
[387]89
[325]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;
[2]104                $contacts_result = array();
105                $contacts_result['field'] = $field;
106                $contacts_result['ID'] = $ID;
[387]107
[2]108                // follow the referral
109                $this->ldapConnect(true);
[387]110
[2]111                if ($this->ds)
[342]112                {
113                        if (($field != 'null') && ($ID != 'null'))
[325]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");
[342]117                        }
[37]118                        else
[342]119                        {
[271]120                                $filter="(& (phpgwAccountType=u)(cn=*$search_for*) (!(phpgwaccountvisible=-1)) )";
[342]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;
[325]126                        $count_entries = ldap_count_entries($this->ds,$sr);
[342]127
[387]128                        // Get user org dn.
[271]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);
[387]134
[271]135                        // New search only on user sector
[342]136                        if ($count_entries > $this->max_result)
137                        {
[108]138                                // Close old ldap conection
139                                ldap_close($this->ds);
[387]140
[108]141                                // Reopen a local ldap connection, following referral
142                                $this->ldapRootConnect(true);
[387]143
[342]144                                $sr= ldap_search($this->ds, $user_sector_dn, $filter, $justthese);
145                                if(!$sr)
146                                        return null;
[108]147                                $count_entries = ldap_count_entries($this->ds,$sr);
[387]148
[342]149                                if ($count_entries > $this->max_result){
[108]150                                        $return = array();
151                                        $return['status'] = false;
[387]152                                        $return['error'] = "many results";
[108]153                                        return $return;
154                                }
[95]155                                else
156                                {
157                                        $quickSearch_only_in_userSector = true;
158                                }
159                        }
[387]160
[37]161                        $info = ldap_get_entries($this->ds, $sr);
[387]162
[2]163                        $tmp = array();
[271]164                        $tmp_users_from_user_org = array();
[387]165
[342]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"]) {
[325]170                                                $this->ldapConnect(true,$i);
171                                                $filter="(|(cn=*$search_for*)(mail=*$search_for*))";
[342]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;
[325]176                                                $count_entries = ldap_count_entries($this->ds,$sr);
177                                                $search = ldap_get_entries($this->ds, $sr);
[387]178                                                for ($j=0; $j<$search["count"]; $j++) {
179                                                        $info[] = $search[$j];
[342]180                                                }
[325]181                                                $info["count"] = count($info)-1;
182                                        }
[271]183                                }
[342]184                        }
185
[325]186                        for ($i=0; $i<$info["count"]; $i++)
[342]187                        {
188                                if ($quickSearch_only_in_userSector)
[271]189                                {
[325]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]);
[342]191                                }
[325]192                                else
[342]193                                {
194                                        if (preg_match("/$user_sector_dn/i", $info[$i]['dn']))
[325]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]);
[342]197                                        }
[271]198                                        else
[342]199                                        {
[325]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]);
[271]201                                        }
202                                }
[342]203                        }
[271]204                        natcasesort($tmp_users_from_user_org);
[2]205                        natcasesort($tmp);
[387]206
[37]207                        if (($field != 'null') && ($ID != 'null'))
[2]208                        {
[271]209                                $i = 0;
[387]210
[271]211                                $tmp = array_merge($tmp, $tmp_users_from_user_org);
212                                natcasesort($tmp);
[387]213
[37]214                                foreach ($tmp as $info => $cn)
215                                {
216                                        $contacts_result[$i] = array();
217                                        $contacts_result[$i]["cn"] = $cn;
[325]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);
[37]219                                        $i++;
220                                }
[95]221                                $contacts_result['quickSearch_only_in_userSector'] = $quickSearch_only_in_userSector;
[2]222                        }
[37]223                        else
224                        {
[271]225                                $options_users_from_user_org = '';
[37]226                                $options = '';
[271]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 */
[37]238                                foreach ($tmp as $info => $cn)
239                                {
240                                        $contacts_result[$i] = array();
[271]241                                        $options .= $this->make_quicksearch_card($info, $cn);
[37]242                                        $i++;
243                                }
[387]244
[95]245                                if ($quickSearch_only_in_userSector)
246                                {
[271]247                                        if ($options != '')
248                                        {
249                                                $head_option =
250                                                        '<tr class="quicksearchcontacts_unselected">' .
251                                                                '<td colspan="2" width="100%" align="center">' .
[342]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') . '.';
[271]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                                        }
[108]265                                }
[271]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>' .
[342]273                                                                        $this->functions->getLang('Users from your organization') . '</B> ['.count($tmp_users_from_user_org).']';
274                                                                '</td>' .
[271]275                                                        '</tr>';
276
277                                                $head_option1 =
278                                                        '<tr class="quicksearchcontacts_unselected">' .
279                                                                '<td colspan="2" width="100%" align="center" style="background:#EEEEEE"><B>' .
[342]280                                                                        $this->functions->getLang('Users from others organizations') . '</B> ['.count($tmp).']';
281                                                                '</td>' .
[271]282                                                        '</tr>';
283                                        }
284                                        $contacts_result = $head_option0 . $options_users_from_user_org . $head_option1 . $options;
285                                }
[37]286                        }
[2]287                }
288                ldap_close($this->ds);
289                return $contacts_result;
290        }
291
[271]292        function make_quicksearch_card($info, $cn)
293        {
294                include_once("class.functions.inc.php");
[387]295                $functions = new functions;
296
[271]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);
[387]300
[271]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">';
[387]305
[271]306                $phoneUser = $contacts_result['phone'];
[387]307
[271]308                if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['voip_enabled'] && $phoneUser) {
[342]309                        $phoneUser = '<a title="'.$this->functions->getLang("Call to Comercial Number").'" href="#" onclick="InfoContact.connectVoip(\''.$phoneUser.'\',\'com\')">'.$phoneUser.'</a>';
[271]310                        if($contacts_result['mobile']){
[342]311                                $phoneUser .= ' / <a title="'.$this->functions->getLang("Call to Mobile Number").'" href="#" onclick="InfoContact.connectVoip(\''.$contacts_result['mobile'].'\',\'mob\')">'.$contacts_result['mobile'].'</a>';
[271]312                        }
313                }
314                $option =
315                        '<tr class="quicksearchcontacts_unselected">' .
316                                '<td class="cc" width="1%">' .
[342]317                                        '<a title="'.$this->functions->getLang("Write message").'" onClick="javascript:QuickSearchUser.create_new_message(\''.$contacts_result["cn"].'\', \''.$contacts_result["mail"].'\')">' .
[271]318                                                $photo_link .
319                                        '</a>' .
320                                '</td>' .
321                                '<td class="cc">' .
322                                        '<span name="cn">' . $contacts_result['cn'] . '</span>' . '<br>' .
[342]323                                        '<a title="'.$this->functions->getLang("Write message").'" onClick="javascript:QuickSearchUser.create_new_message(\''.$contacts_result["cn"].'\', \''.$contacts_result["mail"].'\')">' .
[271]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
[387]334        function get_catalogs(){
[325]335                $catalogs = array();
[387]336                $catalogs[0] = $this->functions->getLang("Global Catalog");
337                if($this->external_srcs)
[342]338                        foreach ($this->external_srcs as $key => $valor ){
[325]339                        $catalogs[$key] = $valor['name'];
340                }
341                return $catalogs;
342        }
[2]343        function get_organizations($params){
344                $organizations = array();
[325]345                $params['referral']?$referral = $params['referral']:$referral = false;
346                $cat = $params['catalog'];
[2]347
[325]348                $this->ldapConnect($referral,$cat);
349
350                        if($this->branch != '') {
351                                $filter=$this->branch."=*";
352                                $justthese = array("$this->branch");
[342]353                        $sr = ldap_list($this->ds, $this->ldap_context, $filter, $justthese);
354                        $info = ldap_get_entries($this->ds, $sr);
[387]355
[342]356                        for ($i=0; $i<$info["count"]; $i++)
357                                $organizations[$i] = $info[$i]["ou"][0];
[325]358
[342]359                        ldap_close($this->ds);
[387]360                        sort($organizations);
[342]361                return $organizations;
[325]362                        }else{
363                        return null;
[2]364        }
[342]365        }
[2]366        function get_organizations2($params){
367                $organizations = array();
368                $referral = $params['referral'];
369                $this->ldapRootConnect($referral);
370                if ($this->ds) {
[387]371                        $filter="ou=*";
[2]372                        $justthese = array("ou");
373                        $sr = ldap_list($this->ds, $this->ldap_context, $filter, $justthese);
374                        $info = ldap_get_entries($this->ds, $sr);
[387]375
[2]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                        }
[387]381
[2]382                        ldap_close($this->ds);
[387]383                        sort($organizations);
[2]384                }
385                return $organizations;
386        }
387
388        function catalogsearch($params)
[387]389        {
[325]390                $cn     = $params['search_for'] ? "*".utf8_encode($params['search_for'])."*" : "*";
[387]391                $max_result       = $params['max_result'] ? $params['max_result'] : $this->max_result;
[325]392                $catalog = $params['catalog'];
[2]393                $error = False;
[387]394
[381]395                $this->ldapConnect(true,$catalog);
[387]396
397                $params['organization'] == 'all' ? $user_context = $this->ldap_context :$user_context = $this->branch."=".$params['organization'].",".$this->ldap_context;
398
399                if ($this->ds) {
[325]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                        }
[387]411
[381]412                        $sr=@ldap_search($this->ds, $user_context, $filter, $justthese, 0, $max_result+1);
[342]413                        if(!$sr)
414                                return null;
[2]415                        $count_entries = ldap_count_entries($this->ds,$sr);
[381]416                        if ($count_entries > $max_result){
[2]417                                $info = null;
[387]418                                $error = True;
[2]419                        }
420                        else
[387]421                                $info = ldap_get_entries($this->ds, $sr);
422
423                        ldap_close($this->ds);
424
[2]425                        $u_tmp = array();
426                        $g_tmp = array();
[387]427
[2]428                        for ($i=0; $i<$info["count"]; $i++){
[325]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];
[387]432                                if((!$catalog==0)||(strtoupper($info[$i]["phpgwaccounttype"][0]) == 'L') && ($info[$i]["phpgwaccountvisible"][0] != '-1'))
[325]433                                        $g_tmp[$info[$i]["mail"][0]] = utf8_decode($info[$i]["cn"][0]);
[387]434                        }
435
[2]436                        natcasesort($u_tmp);
437                        natcasesort($g_tmp);
[387]438
[2]439                        $i = 0;
[387]440                        $users = array();
[325]441
[387]442                        foreach ($u_tmp as $mail => $cn){
443
[325]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
[2]449                        }
450                        unset($u_tmp);
[387]451
452                        $i = 0;
[2]453                        $groups = array();
[387]454
455                        foreach ($g_tmp as $mail => $cn){
[2]456                                $groups[$i++] = array("name" => $cn, "email" => $mail);
457                        }
458                        unset($g_tmp);
[387]459
[2]460                        return  array('users' => $users, 'groups' => $groups, 'error' => $error);
[387]461                }else
[2]462                return null;
463        }
[387]464
[2]465        function get_emails_ldap(){
466
467                $result['mail']= array();
[387]468                $result['mailalter']= array();
[2]469                $user = $_SESSION['phpgw_info']['expressomail']['user']['account_lid'];
470                $this->ldapRootConnect(false);
471                if ($this->ds) {
[387]472                        $filter="uid=".$user;
[2]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);
[387]477
[2]478                        for ($i=0; $i<$ent["count"]; $i++){
479                                $result['mail'][] = $ent[$i]["mail"][0];
[387]480                                $result['mailalter'][] = $ent[$i]["mailalternateaddress"][0];
[2]481                        }
482                }
483                return $result;
484        }
[387]485
[342]486        //Busca usuarios de um contexto e ja retorna as options do select;
[2]487        function get_available_users($params)
[37]488    {
489        $this->ldapRootConnect();
[342]490        //Monta lista de Grupos e Usuarios
[37]491        $users = Array();
492        $groups = Array();
493        $user_context= $params['context'];
494        $owner = $_SESSION['phpgw_info']['expressomail']['user']['owner'];
[2]495
[37]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++)
[387]505                $groups[$uids=$info[$i]["gidnumber"][0]] = Array('name'    =>    $uids=$info[$i]["cn"][0], 'type'    =>    g);
[37]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);
[2]511
[37]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);
[387]521
[37]522        @asort($users);
[387]523        @reset($users);
[37]524        @asort($groups);
525        @reset($groups);
526        $user_options ='';
527        $group_options ='';
[2]528
[37]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
[342]542        //Busca usuarios de um contexto e ja retorna as options do select;
[2]543        function get_available_users2($params)
544        {
545                $this->ldapRootConnect();
[387]546
[2]547                $context= $params['context'];
548                $justthese = array("cn", "uid", "cn");
[21]549                $filter = "(&(phpgwaccounttype=u)(!(phpgwaccountvisible=-1)))";
[2]550
[387]551            if ($this->ds)
[2]552            {
553                        $sr=ldap_search($this->ds, $context, $filter, $justthese);
554                        $entries = ldap_get_entries($this->ds, $sr);
[387]555
[2]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                        }
[387]561
[2]562                        natcasesort($u_tmp);
563
564                        $i = 0;
565                        $users = array();
[387]566
[2]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        }
[387]580
[2]581        function uid2cn($uid)
[387]582        {
[2]583                // do not follow the referral
584                $this->ldapRootConnect(false);
585                if ($this->ds)
586                {
[387]587                        $filter="(&(phpgwAccountType=u)(uid=$uid))";
[2]588                        $justthese = array("cn");
[344]589                        $sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese);
590                        if(!$sr)
591                                return false;
[2]592                        $info = ldap_get_entries($this->ds, $sr);
[325]593                        return utf8_decode($info[0]["cn"][0]);
[2]594                }
595                return false;
596        }
[387]597        function getSharedUsersFrom($params){
[2]598                $filter = '';
[371]599                $i = 0;
600                if($params['uids']) {
[387]601                        $uids = explode(";",$params['uids']);
602                        $this->imap = new imap_functions();
[371]603                        foreach($uids as $index => $uid){
[387]604                                $params = array();
[371]605                                $acl = $this->imap->getacltouser($uid);
606                                if(preg_match("/a/",$acl))
607                                        $filter .= "(uid=$uid)";
608                        }
[2]609                }
[387]610
611                $this->ldapRootConnect(false);
[371]612                if ($this->ds) {
[2]613                        $justthese = array("cn","mail");
[371]614                        if($filter) {
615                                $filter="(&(phpgwAccountType=u)(|$filter))";
616                                $sr             =       ldap_search($this->ds, $this->ldap_context, $filter, $justthese);
[387]617                                ldap_sort($this->ds,$sr,"cn");
618                                $info   =       ldap_get_entries($this->ds, $sr);
[371]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'];
[387]623
[371]624                        //Find institucional_account.
625                        $filter="(&(phpgwAccountType=i)(mailForwardingAddress=".$_SESSION['phpgw_info']['expressomail']['user']['email']."))";
[387]626                        $sr     = ldap_search($this->ds, $this->ldap_context, $filter, $justthese);
[448]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                                }
[371]640                        }
[448]641
642                        $_SESSION['phpgw_info']['expressomail']['user']['shared_mailboxes'] = $info;
643
[2]644                        return $info;
645                }
646        }
[27]647
[205]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
[27]654                // Follow the referral
[205]655                $ds = $this->ldapConnect2(true);
656                if ($ds)
[387]657                {
[342]658                        $sr=@ldap_search($ds, $ldap_context, $filter, $justthese);
[387]659
[205]660                        if (!$sr)
661                                return null;
[387]662
[205]663                        $entry = ldap_first_entry($ds, $sr);
[387]664
665                        if($entry) {
[381]666                                $obj =  array("cn" => utf8_decode(current(ldap_get_values($ds, $entry, "cn"))),
[205]667                                                  "email" => $params['email'],
668                                                  "uid" => ldap_get_values($ds, $entry, "uid"),
[27]669                                                  "type" => "global",
[205]670                                                  "mobile" =>  @ldap_get_values($ds, $entry, "mobile"),
671                                                  "telefone" =>  @ldap_get_values($ds, $entry, "telephonenumber")
672                                        );
[27]673
[320]674                                $_SESSION['phpgw_info']['expressomail']['contact_photo'] = @ldap_get_values_len($ds, $entry, "jpegphoto");
[205]675                                ldap_close($ds);
[27]676                                return $obj;
[205]677                        }
[27]678                }
679                return null;
680        }
[2]681}
[108]682?>
Note: See TracBrowser for help on using the repository browser.