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

Revision 8171, 45.5 KB checked in by angelo, 11 years ago (diff)

Ticket #3458 - Problema na criacao de contas institucionais

  • Property svn:eol-style set to native
  • Property svn:executable set to *
RevLine 
[387]1<?php
[5509]2                /***************************************************************************
3                * Expresso Livre                                                           *
4                * http://www.expressolivre.org                                             *
5                * --------------------------------------------                             *
6                *  This program is free software; you can redistribute it and/or modify it *
7                *  under the terms of the GNU General Public License as published by the   *
8                *  Free Software Foundation; either version 2 of the License, or (at your  *
9                *  option) any later version.                                              *
10                \**************************************************************************/
11               
[5399]12require_once(dirname(__FILE__).'/../../services/class.servicelocator.php');
[176]13include_once("class.imap_functions.inc.php");
[342]14include_once("class.functions.inc.php");
[176]15
16function ldapRebind($ldap_connection, $ldap_url)
17{
18        @ldap_bind($ldap_connection, $_SESSION['phpgw_info']['expressomail']['ldap_server']['acc'],$_SESSION['phpgw_info']['expressomail']['ldap_server']['pw']);
19}
[387]20
[2]21class ldap_functions
22{
23        var $ds;
24        var $ldap_host;
25        var $ldap_context;
26        var $imap;
[342]27        var $external_srcs;
28        var $max_result;
29        var $functions;
[4457]30        var $ldapService;
31       
[342]32        function ldap_functions(){
33        // todo: Page Configuration for External Catalogs.
34                @include("../contactcenter/setup/external_catalogs.inc.php");
[4457]35                $this->ldapService = ServiceLocator::getService('ldap');
[5134]36                if(isset($external_srcs))
[4457]37                $this->external_srcs = $external_srcs;
38                $this->max_result = $this->ldapService->limit;
[387]39                $this->functions = new functions();
40        }
[342]41        // Using ContactCenter configuration.
42        function ldapConnect($refer = false,$catalog = 0){
43                if ($catalog > 0 && is_array($this->external_srcs)){
44                        $this->ldap_host        = $this->external_srcs[$catalog]['host'];
45                        $this->ldap_context = $this->external_srcs[$catalog]['dn'];
46                        $this->bind_dn          = $this->external_srcs[$catalog]['acc'];
47                        $this->bind_dn_pw       = $this->external_srcs[$catalog]['pw'];
48                        $this->object_class = $this->external_srcs[$catalog]['obj'];
49                        $this->base_dn          = $this->external_srcs[$catalog]['dn'];
50                        $this->branch           = $this->external_srcs[$catalog]['branch'];
51                }else {
[325]52                        $this->ldap_host        = $_SESSION['phpgw_info']['expressomail']['ldap_server']['host'];
53                        $this->ldap_context = $_SESSION['phpgw_info']['expressomail']['ldap_server']['dn'];
54                        $this->bind_dn = $_SESSION['phpgw_info']['expressomail']['ldap_server']['acc'];
55                        $this->bind_dn_pw = $_SESSION['phpgw_info']['expressomail']['ldap_server']['pw'];
[387]56                        $this->branch = 'ou';
[325]57                }
[387]58
[325]59                $this->ds = ldap_connect($this->ldap_host);
[2]60                ldap_set_option($this->ds, LDAP_OPT_PROTOCOL_VERSION, 3);
[37]61                ldap_set_option($this->ds, LDAP_OPT_REFERRALS, $refer);
[342]62                if ($refer)     {
[176]63                        ldap_set_rebind_proc($this->ds, ldapRebind);
64                }
[387]65                @ldap_bind($this->ds,$this->bind_dn,$this->bind_dn_pw );
[2]66        }
67
[205]68        //Teste jakjr retornando o DS
69        function ldapConnect2($refer = false){
70                $ds = ldap_connect($_SESSION['phpgw_info']['expressomail']['ldap_server']['host']);
[387]71
[205]72                if (!$ds)
73                        return false;
[387]74
[205]75                ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
76                ldap_set_option($ds, LDAP_OPT_REFERRALS, $refer);
77                if ($refer)
[5134]78                        ldap_set_rebind_proc($ds, 'rebind');
[205]79                @ldap_bind($ds, $_SESSION['phpgw_info']['expressomail']['ldap_server']['acc'],$_SESSION['phpgw_info']['expressomail']['ldap_server']['pw']);
[387]80
81                return $ds;
[205]82        }
83
84
[108]85        // usa o host e context do setup.
[2]86        function ldapRootConnect($refer = false){
87                $this->ldap_host        = $_SESSION['phpgw_info']['expressomail']['server']['ldap_host'];
88                $this->ldap_context = $_SESSION['phpgw_info']['expressomail']['server']['ldap_context'];
89
[6848]90                if( isset($_SESSION['phpgw_info']['expressomail']['server']['ldap_master_host']) &&
91                        isset($_SESSION['phpgw_info']['expressomail']['server']['ldap_master_root_dn']) &&
92                        isset($_SESSION['phpgw_info']['expressomail']['server']['ldap_master_root_pw']) &&
93                        $_SESSION['phpgw_info']['expressomail']['server']['ldap_master_host'] &&
[5821]94                        $_SESSION['phpgw_info']['expressomail']['server']['ldap_master_root_dn'] &&
95                        $_SESSION['phpgw_info']['expressomail']['server']['ldap_master_root_pw']) {
96                        $this->ds = ldap_connect($_SESSION['phpgw_info']['expressomail']['server']['ldap_master_host']);
97                        ldap_set_option($this->ds, LDAP_OPT_PROTOCOL_VERSION, 3);
98                        ldap_set_option($this->ds, LDAP_OPT_REFERRALS,0);
99                        ldap_bind($this->ds, $_SESSION['phpgw_info']['expressomail']['server']['ldap_master_root_dn'], $_SESSION['phpgw_info']['expressomail']['server']['ldap_master_root_pw']);
100                }else{
101                        $this->ds = ldap_connect($this->ldap_host);
102                        ldap_set_option($this->ds, LDAP_OPT_PROTOCOL_VERSION, 3);
103                        ldap_set_option($this->ds, LDAP_OPT_REFERRALS, $refer);
104                        ldap_bind($this->ds, $_SESSION['phpgw_info']['expressomail']['server']['ldap_root_dn'],$_SESSION['phpgw_info']['expressomail']['server']['ldap_root_pw']);
105                }
[2]106        }
107
108        function quicksearch($params)
[387]109        {
[95]110                include_once("class.functions.inc.php");
[387]111                $functions = new functions;
[4929]112
[2]113                $field          = $params['field'];
114                $ID                     = $params['ID'];
[4929]115               
[7062]116                $ldapService = ServiceLocator::getService('ldap');
117                $filter =  $ldapService->getSearchFilter($params['search_for']);
[4929]118
[2]119                $contacts_result = array();
120                $contacts_result['field'] = $field;
121                $contacts_result['ID'] = $ID;
[5199]122                $search_for = utf8_encode($params['search_for']);
123               
124                if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['extended_info'])
125                        $extendedinfo=true;
126                else
127                        $extendedinfo=false;
[5237]128
[2]129                // follow the referral
130                $this->ldapConnect(true);
[4929]131
[2]132                if ($this->ds)
[4929]133                {
[7062]134                        $ldapService->connection = $this->ds;
135                        if($extendedinfo)
136                                $justthese = array("cn", "mail", "telephonenumber", "uid","uidNumber", "mobile", "phpgwaccountvisible", "employeenumber", "ou");
137                        else
138                                $justthese = array("cn", "mail", "telephoneNumber", "phpgwAccountVisible", "uidNumber","uid");
139                        $types = false;
[387]140
[7062]141                        if( $field == 'null' || $ID == 'null' )
[4929]142                        {
[7062]143                                $justthese[] = "jpegphoto";
144                                $types = 'u';
145                        }
[387]146
[4457]147                $filter = $ldapService->getSearchFilter( $params['search_for'], $types );
[387]148
[4457]149                $sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese, 0, $this->max_result);
150
[7062]151                if(!$sr)
152                        return null;
[4457]153
[7062]154                $count_entries = ldap_count_entries($this->ds,$sr);
[4457]155
[7062]156                $info = ldap_get_entries($this->ds, $sr);
157
[4457]158            // New search only on user sector
[5238]159            if ($count_entries == $this->max_result)
[4457]160            {
[7062]161                        $overload = $count_entries;
162                }
163                else
164                {
165                        $catalogsNum=count($this->external_srcs);
[7655]166                                for ($i=0; $i<=$catalogsNum; ++$i)      {
[5245]167                                        if ($this->external_srcs[$i]["quicksearch"]) {
[4929]168                                                $this->ldapConnect(true,$i);
169                                                $filter="(|(cn=*$search_for*)(mail=*$search_for*))";
[5199]170                                                if($extendedinfo)
[7062]171                                                        $justthese = array("cn", "mail", "telephonenumber", "uid","uidNumber", "mobile", "phpgwaccountvisible", "employeenumber", "ou");
[5199]172                                                else
[5245]173                                                        $justthese = array("cn", "mail", "telephoneNumber", "phpgwAccountVisible","uidNumber", "uid");
[4929]174                                                $sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese, 0, $this->max_result+1);
175                                                if(!$sr)
176                                                        return null;
177                                                $count_entries = ldap_count_entries($this->ds,$sr);
178                                                $search = ldap_get_entries($this->ds, $sr);
[7655]179                                                for ($j=0; $j<$search["count"]; ++$j) {
[4929]180                                                        $info[] = $search[$j];
181                                                }
182                                                $info["count"] = count($info)-1;
183                                        }
[108]184                                }
[95]185                        }
[387]186
[7062]187                $tmp = array();
188                $tmp_users_from_user_org = array();
[387]189
[7655]190                for ($i=0; $i<$info["count"]; ++$i)
[7062]191                {
192                        $key = $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];
193
194                        if (/*(!$quickSearch_only_in_userSector) &&*/ preg_match("/$user_sector_dn/i", $info[$i]['dn']))
[4929]195                        {
[7062]196                                $tmp_users_from_user_org[$key] = utf8_decode($info[$i]["cn"][0]);
197                                continue;
198                        }
[387]199
[7062]200                        $tmp[$key] = utf8_decode($info[$i]["cn"][0]);
201                }
[342]202
[4929]203                        natcasesort($tmp_users_from_user_org);
204                        natcasesort($tmp);
[387]205
[4929]206                        if (($field != 'null') && ($ID != 'null'))
207                        {
208                                $i = 0;
[387]209
[4929]210                                $tmp = array_merge($tmp, $tmp_users_from_user_org);
211                                natcasesort($tmp);
[271]212
[4929]213                                foreach ($tmp as $info => $cn)
214                                {
215                                        $contacts_result[$i] = array();
216                                        $contacts_result[$i]["cn"] = $cn;
[6057]217                                        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"]) = preg_split('/%/', $info);
[7655]218                                        ++$i;
[4929]219                                }
220                                $contacts_result['quickSearch_only_in_userSector'] = $quickSearch_only_in_userSector;
[7062]221                                $contacts_result['maxResult'] = $ldapService->limit;
[4929]222                        }
223                        else
224                        {
225                                $options_users_from_user_org = '';
226                                $options = '';
[271]227
[4457]228           
[4929]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);
[7655]234                                        ++$i;
[4929]235                                }
[387]236
[4457]237           
[4929]238                                foreach ($tmp as $info => $cn)
239                                {
240                                        $contacts_result[$i] = array();
241                                        $options .= $this->make_quicksearch_card($info, $cn);
[7655]242                                        ++$i;
[4929]243                                }
[271]244
[4457]245
[4929]246                                        if (($options_users_from_user_org != '') && ($options != ''))
247                                        {
248                                                $head_option0 =
249                                                        '<tr class="quicksearchcontacts_unselected">' .
250                                                                '<td colspan="2" width="100%" align="center" style="background:#EEEEEE"><B>' .
251                                                                        $this->functions->getLang('Users from your organization') . '</B> ['.count($tmp_users_from_user_org).']';
252                                                                '</td>' .
253                                                        '</tr>';
[4457]254
[4929]255                                                $head_option1 =
256                                                        '<tr class="quicksearchcontacts_unselected">' .
257                                                                '<td colspan="2" width="100%" align="center" style="background:#EEEEEE"><B>' .
258                                                                        $this->functions->getLang('Users from others organizations') . '</B> ['.count($tmp).']';
259                                                                '</td>' .
260                                                        '</tr>';
261                                        }
[4457]262                   
263                    $head_option = '';
264
265                    if( $overload )
266                    $head_option = '<tr class="quicksearchcontacts_unselected">' .
267                                    '<td colspan="2" width="100%" align="center" style="background:#EEEEEE; color: red;"><B>' .str_replace('%1', $this->max_result, $this->functions->getLang('More than %1 results. Please, try to refine your search.')) . '</B> '.
268                                    '</td>' .
269                                    '</tr>';
270
271                    $contacts_result = $head_option.$head_option0 . $options_users_from_user_org . $head_option1. $options;
272
[4929]273                                }
274                        }
[4457]275
[4929]276                ldap_close($this->ds);
277                return $contacts_result;
[2]278        }
279
[5075]280       
281         /**
282        * Método que faz o roteamento entre os métodos de busca (Catálogo pessoal, global e todos)
283        * @license    http://www.gnu.org/copyleft/gpl.html GPL
284        * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
285        * @sponsor    Caixa Econômica Federal
286        * @author     Prognus Software Livre <airton@prognus.com.br | prognus@prognus.com.br>
287        * @param      <array> <$param> <parametros vindos do cliente>
288        */
289        function quicksearchcontact($params)
290        {
[5209]291            if(array_key_exists('Type', $params)){
[5196]292                return $this->quickSearch($params);
293            }
[5202]294           
[5075]295            $modal = false;
296            if($params['catalog'])
297                $modal = true;
298             
[5316]299            include_once dirname(__FILE__). '/../../header.inc.php';
[5075]300           
301            if($modal)
302            {
303                if($params['catalog'] == "global")
304                {       
305                    return $this->quickSearchGlobal($params);
306                }
307                else
308                {
309                    if($params['catalog'] == "personal")
310                        return $this->quickSearchPersonal($params);
311                    else
312                        return $this->quickSearchAll($params);
313                }
314            }
315            else
316            {
317                if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['catalog_search'] == "global")
318                {
319                    return $this->quickSearchGlobal($params);
320                }
321                else
322                {   
323                    if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['catalog_search'] == "personal")
324                        return $this->quickSearchPersonal($params);                   
325                    else
326                                                //Veirifica se quem chamou foi o campo de pesquisa rápida Expresso_Mail
327                                                if(($params['field'] == 'null') && ($params['ID'] == 'null'))
328                                                        return $this->quickSearch($params);
329                                                else
[7062]330                                                        return $this->quickSearchAll($params);
[5075]331                }
332            }
333        }
334       
335       
336
337        /**
338        * Método que faz a busca de usuários em todos os catálogos
339        * @license    http://www.gnu.org/copyleft/gpl.html GPL
340        * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
341        * @sponsor    Caixa Econômica Federal
[7225]342        * @author     ProgquickSearchAllnus Software Livre <airton@prognus.com.br | prognus@prognus.com.br>
[5075]343        * @param      <array> <$param> <parametros vindos do cliente>
344        * @return     <array> <$retorno> <Array com os usuários de todos os catálogos, de acordo com o parâmetro>
345        */
346        function quickSearchAll($params)
347        {
348            $retorno_personal = $this->quickSearchPersonal($params);
349            $retorno_global   = $this->quickSearchGlobal($params);
350            //$retorno = $retorno_personal + $retorno_global;
[7756]351            if ($retorno_global){
352                $retorno = array_merge($retorno_personal, $retorno_global);
353            }else{
354                $retorno = $retorno_personal;
355            }
356
[5075]357                        $retorno['type_catalog'] = "A";
[5172]358                        $retorno['search_for'] = $params['search_for'];
[5075]359            return $retorno;
360        }
361       
362       
363        /**
364        * Método que faz a busca de usuários no Catálogo Pessoal
365        * @license    http://www.gnu.org/copyleft/gpl.html GPL
366        * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
367        * @sponsor    Caixa Econômica Federal
368        * @author     Prognus Software Livre <airton@prognus.com.br | prognus@prognus.com.br>
369        * @param      <array> <$param> <parametros vindos do cliente>
370        * @return     <array> <$retorno> <Array com os usuários do Catálogo Pessoal, de acordo com o parâmetro>
371        */
372        function quickSearchPersonal($params, $all=false)
373        {
374            $results = array();
375            $DBService = ServiceLocator::getService('db');
376            $results   = $DBService->search_contacts($params['search_for']);
[5209]377                        $results2 = array();
[5172]378            $results2   = $DBService->search_groups($params['search_for']);
[5075]379           
[5209]380            if(is_array($results)){
381                if(is_array($results2)){
382                        $results   = array_merge($results, $results2);
383                }
384            }
385            else if(is_array($results2)){
386                $results = $results2;
387            }
388           
[5075]389            if(!$all)
390                $results['type_catalog'] = "P";
[5134]391                       
392                        foreach($results as $i=>$value)
393                                $results[$i]['type_contact'] = "P";
394                       
[5172]395                        $results['search_for'] = $params['search_for'];
[5209]396                       
[5075]397                        return $results;
398        }
399       
400       
401        /**
402        * Método que faz a busca de usuários no Catálogo Geral
403        * @license    http://www.gnu.org/copyleft/gpl.html GPL
404        * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
405        * @sponsor    Caixa Econômica Federal
406        * @author     Prognus Software Livre <airton@prognus.com.br | prognus@prognus.com.br>
407        * @param      <array> <$param> <parametros vindos do cliente>
408        * @return     <array> <$retorno> <Array com os usuários do Catálogo Global, de acordo com o parâmetro>
409        */
[7225]410        function quickSearchGlobal($params, $all=false)
[5075]411        {             
[5316]412            include_once dirname(__FILE__). '/../../header.inc.php';
[5075]413            $c = CreateObject('phpgwapi.config','contactcenter');
414            $all_data = $c->read_repository();
415           
416            $searchable_fields = array();           
417            foreach($all_data as $index => $value)
418            {
419                $parts = explode('_', $index);
420                if (is_numeric($parts[3]) && $parts[1]=='attribute')
421                {   
[5134]422                    if($parts[2] == 'searchable' /*&& $value == 'true'*/)
[5075]423                        $searchable_fields[$all_data['cc_attribute_ldapname_' . $parts[3]]] = $all_data['cc_attribute_name_' . $parts[3]];   
424                }
425            }   
426            include_once("class.functions.inc.php");
427            $functions      = new functions;
428            $field          = $params['field'];
429            $ID             = $params['ID'];
430            $ldapService    = ServiceLocator::getService('ldap');
431            $filter         = $ldapService->getSearchFilter($params['search_for']);
432 
433            $contacts_result          = array();
434            $contacts_result['field'] = $field;
435            $contacts_result['ID']    = $ID;
436            $search_for               = utf8_encode($params['search_for']);
437           
438            $this->ldapConnect(true);
439            if ($this->ds)
440            {
441                $ldapService->connection = $this->ds;
442                $campos_extras = '';
[6459]443                $justthese = array("cn", "mail", "telephonenumber", "mobile", "phpgwaccountvisible", "uid", "employeenumber", "ou","vacationActive","vacationInfo");
[5075]444                foreach($searchable_fields as $fields_ldap => $value_field)
445                {   
446                    $campos_extras .= $fields_ldap . "|" . $value_field . "#";
447                    array_push($justthese, $fields_ldap);   
448                }
449                $types = false;
450
451                $campos_extras = substr($campos_extras,0,-1);
452               
453                if($field == 'null' || $ID == 'null')
454                {
455                    $justthese[] = "jpegphoto";
456                    $types = 'u';
457                } 
458                $filter = $ldapService->getSearchFilter($params['search_for'], $types);
[5513]459                // Retirei o this->max_result, que limitava a busca. Agora ta retornando tudo amigo.
460                $sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese, 0, $this->max_result);
[5075]461                 
462                if(!$sr)
463                    return null;
464               
465                $count_entries = ldap_count_entries($this->ds,$sr);
466                $info          = ldap_get_entries($this->ds, $sr);
467                $info_return   = $info;
468                //if($campos_extras != '')
469                //array_push($info_return, $campos_extras);
470                        }
471                        ldap_close($this->ds);     
[5199]472
[5075]473                        //Busca em Catalagos externos
474                        $catalogsNum=count($this->external_srcs);
[7655]475                        for ($i=0; $i<=$catalogsNum; ++$i)      {
[5075]476                                if ($this->external_srcs[$i]["quicksearch"])
477                                {
478                                        $this->ldapConnect(true,$i);
479                                        $filter="(|(cn=*$search_for*)(mail=*$search_for*))";
[6459]480                                        $justthese = array("cn", "mail", "telephoneNumber", "mobile", "phpgwAccountVisible", "uid","employeeNumber", "ou","vacationActive","vacationInfo");
[5075]481                                        $sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese, 0, $this->max_result+1);
482                                        if(!$sr)
483                                                return null;
484                                        $count_entries = ldap_count_entries($this->ds,$sr);
485                                        $search = ldap_get_entries($this->ds, $sr);
[7655]486                                        for ($j=0; $j<$search["count"]; ++$j) {
[7225]487                                                $search[$j]['isExternal'] = true;
488                        $info_return[] = $search[$j];
[5075]489                                        }
490                                        $info_return["count"] = count($info_return)-1;
491                                }
492                        }
493                        //---------------------------------------------------------------//
[7062]494
[5075]495            if($all == false)
496                $info_return['type_catalog'] = "G";
497           
498                        $info_return['extra_ldap_fields'] = $campos_extras;
[5134]499                       
[7062]500                        foreach($info_return as &$value){
501                                $value['type_contact'] = "G";
502
503                                //Converte a descrição dos filtros para ISO8859 corrigindo inconsitências com caractéres especiais
504                                if(isset($value['vacationinfo']) && isset($value['vacationinfo'][0]) && $value['vacationinfo'][0] != '')
505                                        $value['vacationinfo'][0] = $this->toISO8859($value['vacationinfo'][0]);
506                        }
507
[5172]508                        $info_return['search_for'] = $params['search_for'];
[7756]509            return $info_return;
[5075]510        }
511       
[6459]512    /*Converte um parametro de UTF-8 para ISO8859*/
513    function toISO8859($data)
514    {
515        if(!is_array($data))
516          return mb_convert_encoding( $data , 'ISO-8859-1' , 'UTF-8 , ISO-8859-1' );
517        $return = array();
518        foreach ($data as $i => $v)
519          $return[$this->toISO8859($i)] = $this->toISO8859($v);
520        return $return;
521    }
522
[271]523        function make_quicksearch_card($info, $cn)
524        {
525                include_once("class.functions.inc.php");
[387]526                $functions = new functions;
527
[271]528                $contacts_result = array();
529                $contacts_result["cn"] = $cn;
[3388]530                if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['extended_info'])
531                    $extendedinfo=true;
532                else
533                    $extendedinfo=false;
[387]534
[6057]535                list ($contacts_result["mail"], $contacts_result["phone"], $contacts_result["mobile"], $contacts_result["uid"], $contacts_result["jpegphoto"], $contacts_result["employeenumber"], $contacts_result["ou"]) = preg_split('/%/', $info);
[3388]536
[271]537                if ($contacts_result['jpegphoto'])
538                        $photo_link = '<img src="./inc/show_user_photo.php?mail='.$contacts_result['mail'].'">';
539                else
[1495]540                        $photo_link = '<img src="./templates/default/images/photo.jpg">';
[387]541
[271]542                $phoneUser = $contacts_result['phone'];
[6139]543                $mobileUser = $contacts_result["mobile"];
544                if($mobileUser){
545                        $phoneUser .= " / $mobileUser";
546                }
547               
548                if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['voip_enabled']) {
549                        $phoneUser = $contacts_result['phone'];
550                        if($phoneUser)
551                                $phoneUser = '<a title="'.$this->functions->getLang("Call to Comercial Number").'" href="#" onclick="InfoContact.connectVoip(\''.$phoneUser.'\',\'com\')">'.$phoneUser.'</a>';
552                        if($mobileUser)
553                                $phoneUser .= ' / <a title="'.$this->functions->getLang("Call to Mobile Number").'" href="#" onclick="InfoContact.connectVoip(\''.$mobileUser.'\',\'mob\')">'.$mobileUser.'</a>';
554                }
[387]555
[6139]556                $empNumber = $contacts_result["employeenumber"];
557                if($empNumber) {
558                        $empNumber = "$empNumber - ";
[271]559                }
[6139]560                $ou = $contacts_result["ou"];
561                if($ou) {
562                        $ou = "<br/>$ou" ;
563                }
[3388]564
[644]565                // Begin: nickname, firstname and lastname for QuickAdd.
566                $fn = $contacts_result["cn"];
567                $array_name = explode(" ", $fn);
568                if(count($array_name) > 1){                     
569                        $fn = $array_name[0];
570                        array_shift($array_name);
571                        $sn = implode(" ",$array_name);
572                }
573                // End:
[271]574                $option =
575                        '<tr class="quicksearchcontacts_unselected">' .
576                                '<td class="cc" width="1%">' .
[6528]577                                        '<a title="'.$this->functions->getLang("Write message").'" onClick="javascript:QuickSearchUser.create_new_message(\''.$contacts_result["cn"].'\', \''.$contacts_result["mail"].'\', \''.$contacts_result["uid"].'\')">' .
[271]578                                                $photo_link .
579                                        '</a>' .
580                                '</td>' .
581                                '<td class="cc">' .
[5245]582                                        '<span name="cn">' . ($empNumber != "" ? $empNumber : $uid) . $contacts_result['cn'] . '</span>' . '<br>' .
[6528]583                                        '<a title="'.$functions->getLang("Write message").'" onClick="javascript:QuickSearchUser.create_new_message(\''.$contacts_result["cn"].'\', \''.$contacts_result["mail"].'\', \''.$contacts_result["uid"].'\')">' .
[271]584                                                '<font color=blue>' .
[644]585                                                '<span name="mail">' . $contacts_result['mail'] . '</span></a></font>'.
586                                                '<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"].'\')">'.
587                                        '<br>' .
[271]588                                        $phoneUser .
[3388]589                                        $ou .
[271]590                                '</td>' .
[644]591                                '</tr>';
[271]592                return $option;
593        }
594
[387]595        function get_catalogs(){
[325]596                $catalogs = array();
[387]597                $catalogs[0] = $this->functions->getLang("Global Catalog");
598                if($this->external_srcs)
[342]599                        foreach ($this->external_srcs as $key => $valor ){
[325]600                        $catalogs[$key] = $valor['name'];
601                }
602                return $catalogs;
603        }
[2]604        function get_organizations($params){
605                $organizations = array();
[325]606                $params['referral']?$referral = $params['referral']:$referral = false;
607                $cat = $params['catalog'];
[2]608
[325]609                $this->ldapConnect($referral,$cat);
610
611                        if($this->branch != '') {
[1363]612                                $filter="(&(".$this->branch."=*)(!(phpgwAccountVisible=-1)))";
[325]613                                $justthese = array("$this->branch");
[342]614                        $sr = ldap_list($this->ds, $this->ldap_context, $filter, $justthese);
615                        $info = ldap_get_entries($this->ds, $sr);
[387]616
[3530]617                        if($info["count"] == 0)
618                        {
619                            $organizations[0]['ou'] = $this->ldap_context;
620                        }
621
[7655]622                        for ($i=0; $i<$info["count"]; ++$i)
[342]623                                $organizations[$i] = $info[$i]["ou"][0];
[325]624
[342]625                        ldap_close($this->ds);
[387]626                        sort($organizations);
[342]627                return $organizations;
[325]628                        }else{
629                        return null;
[2]630        }
[342]631        }
[2]632        function get_organizations2($params){
633                $organizations = array();
634                $referral = $params['referral'];
635                $this->ldapRootConnect($referral);
636                if ($this->ds) {
[3530]637                        $filter="(&(objectClass=organizationalUnit)(!(phpgwAccountVisible=-1)))";
[2]638                        $justthese = array("ou");
639                        $sr = ldap_list($this->ds, $this->ldap_context, $filter, $justthese);
640                        $info = ldap_get_entries($this->ds, $sr);
[387]641
[3530]642
643                        if($info["count"] == 0)
[2]644                        {
[3530]645                            $organizations[0]['ou'] = $this->ldap_context;
646                            $organizations[0]['dn'] = $this->ldap_context;
[2]647                        }
[3530]648                        else{
[7655]649                            for ($i=0; $i<$info["count"]; ++$i)
[3530]650                            {
651                                    $organizations[$i]['ou'] = $info[$i]["ou"][0];
652                                    $organizations[$i]['dn'] = $info[$i]["dn"];
653                            }
654                        }
[2]655                        ldap_close($this->ds);
[387]656                        sort($organizations);
[2]657                }
658                return $organizations;
659        }
[925]660        //Busca usuarios de um contexto e ja retorna as options do select - usado por template serpro;
661        function search_users($params)
[4929]662        {
663                $owner = $_SESSION['phpgw_info']['expressomail']['user']['owner'];
[4457]664                        $ldapService = ServiceLocator::getService('ldap');
665                        $ldapService->connect($_SESSION['phpgw_info']['expressomail']['server']['ldap_host'],
666                        $_SESSION['phpgw_info']['expressomail']['server']['ldap_root_dn'],
667                        $_SESSION['phpgw_info']['expressomail']['server']['ldap_root_pw']);
[4929]668
[5134]669                        $groups = $ldapService->accountSearch($params['filter'], array("gidNumber","cn", 'uid'), $params['context'] , 'g', 'cn');
670                        $users = $ldapService->accountSearch($params['filter'], array("uidNumber","cn", 'uid'), $params['context'] , 'u', 'cn');
671                        $compartilhadas = $ldapService->accountSearch($params['filter'], array("uidNumber","cn",'uid'), $params['context'] , 's', 'cn');
672                       
673
[4457]674                        $group_options = array();
675                        $user_options  = array();
[5134]676                        $shared_options = array();
677
[4457]678                        foreach($groups as $group)
[4929]679                {
[5134]680                                $group_options[] = '"'.$group['gidnumber'].'U'.'":"'.$group['cn'].' ('.$group['uid'].')"';
[925]681                }
[4457]682                foreach($users as $user)
[4929]683                    {
[5134]684                                if($owner != $user['uidnumber']) 
685                                        $user_options[] = '"'.$user['uidnumber'].'U'.'":"'.$user['cn'].' ('.$user['uid'].')"';
686                        }       
687                        foreach($compartilhadas as $shared)
688                        {
689                                if($owner != $shared['uidnumber']) 
690                                        $shared_options[] = '"'.$shared['uidnumber'].'U'.'":"'.$shared['cn'].' ('.$shared['uid'].')"';
[4929]691                    }
692       
[4457]693                        $user_options = '{'.implode( ',', $user_options ).'}';
694                        $group_options = '{'.implode( ',', $group_options ).'}';
[5134]695                        $shared_options = '{'.implode( ',', $shared_options ).'}';
[4929]696
[5134]697                 return '{"users":'.$user_options.',"groups":'.$group_options.',"shared":'. $shared_options .'}';
[4929]698        }
[925]699
[2]700        function catalogsearch($params)
[387]701        {
[4457]702                $ldapService = ServiceLocator::getService('ldap');
703                $filter =  $ldapService->getSearchFilter($params['search_for'],array('u','l','s'));
704               
[325]705                $catalog = $params['catalog'];
[2]706                $error = False;
[4929]707
[4457]708                //if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['extended_info'])
709                    //$extendedinfo=true;
710                //else
711                    //$extendedinfo=false;
[387]712
[3388]713
[381]714                $this->ldapConnect(true,$catalog);
[387]715
716                $params['organization'] == 'all' ? $user_context = $this->ldap_context :$user_context = $this->branch."=".$params['organization'].",".$this->ldap_context;
717
718                if ($this->ds) {
[4929]719                                $justthese = array("cn", "mail", "phpgwaccounttype", "phpgwAccountVisible", "employeeNumber", "ou");
[4457]720                        $sr=@ldap_search($this->ds, $user_context, $filter, $justthese, 0, $ldapService->limit+1);
[4929]721
[342]722                        if(!$sr)
723                                return null;
[2]724                        $count_entries = ldap_count_entries($this->ds,$sr);
[4457]725                        if ($count_entries > $ldapService->limit){
[2]726                                $info = null;
[387]727                                $error = True;
[2]728                        }
729                        else
[387]730                                $info = ldap_get_entries($this->ds, $sr);
731
732                        ldap_close($this->ds);
733
[2]734                        $u_tmp = array();
735                        $g_tmp = array();
[387]736
[7655]737                        for ($i=0; $i<$info["count"]; ++$i){
[325]738                                if((!$catalog==0)||(strtoupper($info[$i]["phpgwaccounttype"][0]) == 'U') && ($info[$i]["phpgwaccountvisible"][0] != '-1'))
739                                        //aqui eh feita a concatenacao do departamento ao cn;
740                                        $u_tmp[$info[$i]["mail"][0]] = utf8_decode($info[$i]["cn"][0]). '%' . $info[$i]["ou"][0];
[387]741                                if((!$catalog==0)||(strtoupper($info[$i]["phpgwaccounttype"][0]) == 'L') && ($info[$i]["phpgwaccountvisible"][0] != '-1'))
[325]742                                        $g_tmp[$info[$i]["mail"][0]] = utf8_decode($info[$i]["cn"][0]);
[387]743                        }
744
[2]745                        natcasesort($u_tmp);
746                        natcasesort($g_tmp);
[387]747
[2]748                        $i = 0;
[387]749                        $users = array();
[325]750
[387]751                        foreach ($u_tmp as $mail => $cn){
752
[325]753                                $tmp = explode("%", $cn); //explode o cn pelo caracter "%" e joga em $tmp;
754                                $name = $tmp[0]; //pega o primeiro item (cn) do vetor resultante do explode acima;
755                                $department = $tmp[1]; //pega o segundo item (ou) do vetor resultanto do explode acima;
[7655]756                                $users[++$i] = array("name" => $name, "email" => $mail, "department" => $department);
[325]757
[2]758                        }
759                        unset($u_tmp);
[387]760
761                        $i = 0;
[2]762                        $groups = array();
[387]763
764                        foreach ($g_tmp as $mail => $cn){
[7655]765                                $groups[++$i] = array("name" => $cn, "email" => $mail);
[2]766                        }
767                        unset($g_tmp);
[387]768
[4457]769                        return  array('users' => $users, 'groups' => $groups, 'error' => $error,'maxResult' => $ldapService->limit);
[387]770                }else
[2]771                return null;
772        }
[387]773
[2]774        function get_emails_ldap(){
775
776                $result['mail']= array();
[387]777                $result['mailalter']= array();
[2]778                $user = $_SESSION['phpgw_info']['expressomail']['user']['account_lid'];
779                $this->ldapRootConnect(false);
780                if ($this->ds) {
[387]781                        $filter="uid=".$user;
[2]782                        $justthese = array("mail","mailAlternateAddress");
783                        $sr = ldap_search($this->ds,$this->ldap_context, $filter, $justthese);
784                        $ent = ldap_get_entries($this->ds, $sr);
785                        ldap_close($this->ds);
[387]786
[7655]787                        for ($i=0; $i<$ent["count"]; ++$i){
[2]788                                $result['mail'][] = $ent[$i]["mail"][0];
[387]789                                $result['mailalter'][] = $ent[$i]["mailalternateaddress"][0];
[2]790                        }
791                }
792                return $result;
793        }
[387]794
[342]795        //Busca usuarios de um contexto e ja retorna as options do select;
[2]796        function get_available_users($params)
[37]797    {
798        $this->ldapRootConnect();
[342]799        //Monta lista de Grupos e Usuarios
[37]800        $users = Array();
801        $groups = Array();
802        $user_context= $params['context'];
803        $owner = $_SESSION['phpgw_info']['expressomail']['user']['owner'];
[2]804
[37]805        if ($this->ds)
806        {
807            $justthese = array("gidNumber","cn");
808            if ($params['type'] == 'search')
809                $sr=ldap_search($this->ds, $user_context, ("(&(cn=*)(phpgwaccounttype=g)(!(phpgwaccountvisible=-1)))"),$justthese);
810            else
811                $sr=ldap_list($this->ds, $user_context, ("(&(cn=*)(phpgwaccounttype=g)(!(phpgwaccountvisible=-1)))"),$justthese);
812            $info = ldap_get_entries($this->ds, $sr);
[7655]813            for ($i=0; $i<$info["count"]; ++$i)
[387]814                $groups[$uids=$info[$i]["gidnumber"][0]] = Array('name'    =>    $uids=$info[$i]["cn"][0], 'type'    =>    g);
[37]815            $justthese = array("phpgwaccountvisible","uidNumber","cn");
816            if ($params['type'] == 'search')
817                $sr=ldap_search($this->ds, $user_context, ("(&(cn=*)(phpgwaccounttype=u)(!(phpgwaccountvisible=-1)))"),$justthese);
818            else
819                $sr=ldap_list($this->ds, $user_context, ("(&(cn=*)(phpgwaccounttype=u)(!(phpgwaccountvisible=-1)))"),$justthese);
[2]820
[37]821            $info = ldap_get_entries($this->ds, $sr);
[7655]822            for ($i=0; $i<$info["count"]; ++$i)
[37]823            {
824                if ($info[$i]["phpgwaccountvisible"][0] == '-1')
825                    continue;
826                $users[$uids=$info[$i]["uidnumber"][0]] = Array('name'    =>    $uids=$info[$i]["cn"][0], 'type'    =>    u);
827            }
828        }
829        ldap_close($this->ds);
[387]830
[37]831        @asort($users);
[387]832        @reset($users);
[37]833        @asort($groups);
834        @reset($groups);
835        $user_options ='';
836        $group_options ='';
[2]837
[37]838        foreach($groups as $id => $user_array) {
839                $newId = $id.'U';
840                $group_options .= '<option  value="'.$newId.'">'.utf8_decode($user_array['name']).'</option>'."\n";
841        }
842        foreach($users as $id => $user_array) {
843            if($owner != $id){
844                $newId = $id.'U';
845                $user_options .= '<option  value="'.$newId.'">'.utf8_decode($user_array['name']).'</option>'."\n";
846            }
847        }
848        return array("users" => $user_options, "groups" => $group_options);
849    }
850
[342]851        //Busca usuarios de um contexto e ja retorna as options do select;
[2]852        function get_available_users2($params)
853        {
[4457]854                $ldapService = ServiceLocator::getService('ldap');
855                $ldapService->connect($_SESSION['phpgw_info']['expressomail']['server']['ldap_host'],
856                $_SESSION['phpgw_info']['expressomail']['server']['ldap_root_dn'],
857                $_SESSION['phpgw_info']['expressomail']['server']['ldap_root_pw']);
[4929]858
[4457]859                $entries = $ldapService->accountSearch($params['sentence'], array('cn', 'uid'), $params['context'], 'u', 'cn');
[4929]860
[4457]861                $options = array();
[4929]862
[4457]863                foreach ($entries as $value)
864                        $options[] = '"'.$value['uid'].'"'.':'.'"'.$value['cn'].'"';
[4929]865
[4457]866                return "{".implode(',',$options)."}";           
[4929]867                                }
[387]868
[2]869        function uid2cn($uid)
[387]870        {
[2]871                // do not follow the referral
872                $this->ldapRootConnect(false);
873                if ($this->ds)
874                {
[387]875                        $filter="(&(phpgwAccountType=u)(uid=$uid))";
[2]876                        $justthese = array("cn");
[344]877                        $sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese);
878                        if(!$sr)
879                                return false;
[2]880                        $info = ldap_get_entries($this->ds, $sr);
[325]881                        return utf8_decode($info[0]["cn"][0]);
[2]882                }
883                return false;
884        }
[757]885        function uidnumber2uid($uidnumber)
886        {
887                // do not follow the referral
888                $this->ldapRootConnect(false);
889                if ($this->ds)
890                {
891                        $filter="(&(phpgwAccountType=u)(uidnumber=$uidnumber))";
892                        $justthese = array("uid");
893                        $sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese);
894                        if(!$sr)
895                                return false;
896                        $info = ldap_get_entries($this->ds, $sr);
897                        return $info[0]["uid"][0];
898                }
899                return false;
900        }
[387]901        function getSharedUsersFrom($params){
[2]902                $filter = '';
[6877]903        $i = 0;         
904        //Added to save if must save sent messages in shared folder
905        $acl_save_sent_in_shared = array();
906       
907        if($params['uids']) {
908                $uids = explode(";",$params['uids']);
909                $this->imap = new imap_functions();                     
910                foreach($uids as $index => $uid){
911                        $params = array();
912                        //Added to save if user has create permission
913                        $acl_create_message = array();
914                        $acl = $this->imap->getacltouser($uid ,true);
915 
916                        if ( preg_match("/p/",$acl )){                         
917                            $filter .= "(uid=$uid)";                                                   
918                            $acl_save_sent_in_shared[ $i ] =$uid;
[7655]919                            ++$i;
[6877]920                                                                       
921                        }                                                       
922                }                       
923        }
[1912]924               
[387]925                $this->ldapRootConnect(false);
[371]926                if ($this->ds) {
[1912]927                        $justthese = array("cn","mail","uid");
[371]928                        if($filter) {
[1912]929                                $filter="(&(|(phpgwAccountType=u)(phpgwAccountType=s))(|$filter))";
[371]930                                $sr             =       ldap_search($this->ds, $this->ldap_context, $filter, $justthese);
[387]931                                ldap_sort($this->ds,$sr,"cn");
932                                $info   =       ldap_get_entries($this->ds, $sr);
[1912]933                                $var = print_r($acl_save_sent_in_shared, true);                         
[7655]934                                for ($i = 0;$i < $info["count"]; ++$i){
[371]935                                        $info[$i]['cn'][0] = utf8_decode($info[$i]['cn'][0]);
[1912]936                                        //verify if user has permission to save sent messages in a shared folder
937                                        if ( in_array( $info[$i]['uid'][0],$acl_save_sent_in_shared) ){                                         
938                                                $info[$i]['save_shared'][0] = 'y';
939                                        } else $info[$i]['save_shared'][0] = 'n';
940                                }
[371]941                        }
[6877]942
[371]943                        $info['myname'] = $_SESSION['phpgw_info']['expressomail']['user']['fullname'];
[387]944
[371]945                        //Find institucional_account.
946                        $filter="(&(phpgwAccountType=i)(mailForwardingAddress=".$_SESSION['phpgw_info']['expressomail']['user']['email']."))";
[387]947                        $sr     = ldap_search($this->ds, $this->ldap_context, $filter, $justthese);
[448]948                        ##
949                        # @AUTHOR Rodrigo Souza dos Santos
950                        # @DATE 2008/09/17
951                        # @BRIEF Changing to ensure that the variable session is always with due value.
952                        ##
953                        if(ldap_count_entries($this->ds,$sr))
954                        {
955                                ldap_sort($this->ds,$sr,"cn");
956                                $result = ldap_get_entries($this->ds, $sr);
[7655]957                                for ($j = 0;$j < $result["count"]; ++$j){
[6877]958                                        $result[$j]['cn'][0] = utf8_decode($result[$j]['cn'][0]);
959                                        $result[$j]['mail'][0] = $result[$j]['mail'][0];
960                                        $result[$j]['save_shared'][0] = 'n';
[8171]961                                        $info[(int)$info['count']] = $result[$j];
[6877]962                                        $info['count'] = (int)$info['count'] + 1;                       
[448]963                                }
[371]964                        }
[448]965
966                        $_SESSION['phpgw_info']['expressomail']['user']['shared_mailboxes'] = $info;
[6877]967
[2]968                        return $info;
969                }
970        }
[27]971
[205]972        function getUserByEmail($params)
973        {
[3163]974                $expires = 60*60*24*30; /* 30 days */
975                header("Cache-Control: maxage=".$expires);
976                header("Pragma: public");
977                header("Expires: ".gmdate('D, d M Y H:i:s', time()+$expires)); 
[205]978                $filter="(&(phpgwAccountType=u)(mail=" . $params['email'] . "))";
979                $ldap_context = $_SESSION['phpgw_info']['expressomail']['ldap_server']['dn'];
[3388]980                if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['extended_info'])
981                    $extendedinfo=true;
982                else
983                    $extendedinfo=false;
[205]984
[3388]985                if($extendedinfo)
986                    $justthese = array("cn","uid","telephoneNumber","jpegPhoto","mobile","ou","employeeNumber");
987                else
[6139]988                    $justthese = array("cn","uid","telephoneNumber","jpegPhoto");
[3388]989
[27]990                // Follow the referral
[205]991                $ds = $this->ldapConnect2(true);
992                if ($ds)
[387]993                {
[342]994                        $sr=@ldap_search($ds, $ldap_context, $filter, $justthese);
[387]995
[205]996                        if (!$sr)
997                                return null;
[387]998
[205]999                        $entry = ldap_first_entry($ds, $sr);
[387]1000
1001                        if($entry) {
[381]1002                                $obj =  array("cn" => utf8_decode(current(ldap_get_values($ds, $entry, "cn"))),
[205]1003                                                  "email" => $params['email'],
1004                                                  "uid" => ldap_get_values($ds, $entry, "uid"),
[27]1005                                                  "type" => "global",
[205]1006                                                  "mobile" =>  @ldap_get_values($ds, $entry, "mobile"),
[3388]1007                                                  "telefone" =>  @ldap_get_values($ds, $entry, "telephonenumber"),
1008                                                  "ou" =>  @ldap_get_values($ds, $entry, "ou"),
1009                                                  "employeeNumber" =>  @ldap_get_values($ds, $entry, "employeeNumber")
[205]1010                                        );
[27]1011
[320]1012                                $_SESSION['phpgw_info']['expressomail']['contact_photo'] = @ldap_get_values_len($ds, $entry, "jpegphoto");
[205]1013                                ldap_close($ds);
[27]1014                                return $obj;
[205]1015                        }
[27]1016                }
1017                return null;
1018        }
[1500]1019       
1020        function uid2uidnumber($uid)
1021        {
1022                // do not follow the referral
1023                $this->ldapRootConnect(false);
1024                if ($this->ds)
1025                {
1026                        $filter="(&(phpgwAccountType=u)(uid=$uid))";
1027                        $justthese = array("uidnumber");
1028                        $sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese);
1029                        if(!$sr)
1030                                return false;
1031                        $info = ldap_get_entries($this->ds, $sr);
1032                        return $info[0]["uidnumber"][0];
1033                }
1034                return false;
1035        }
[5134]1036       
1037        function get_user_groups($uid)
1038        {
1039
1040                $organizations = array();
1041       
1042                $this->ldapRootConnect();
1043
1044                $justthese = array("gidnumber","cn");
1045                $filter="(&(phpgwAccountType=g)(memberuid=".$uid."))";
1046
1047                $search = ldap_search($this->ds, $this->ldap_context, $filter, $justthese);
1048
1049                $result = array();
1050                $entries = ldap_get_entries($this->ds, $search);
1051
1052
[7655]1053                for ($i=0; $i<$entries['count']; ++$i)
[5134]1054                {
1055                        $result[ $entries[$i]['gidnumber'][0] ] = $entries[$i]['cn'][0];
1056                }
1057
1058                return $result;
1059        }
1060       
1061       function getMailByUid($pUid)
1062        {
1063                // do not follow the referral
1064                $this->ldapRootConnect(false);
1065                if ($this->ds)
1066                {
1067                        $filter="(&(|(phpgwAccountType=u)(phpgwAccountType=s)(phpgwAccountType=l))(uid=$pUid))";
1068                        $justthese = array("mail");
1069                        $sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese);
1070                        if(!$sr)
1071                                return false;
1072                        $info = ldap_get_entries($this->ds, $sr);
1073
1074
1075                        return utf8_decode($info[0]["mail"][0]);
1076                }
1077                return false;
1078        }
1079 
1080        function mail2uid($mail)
1081        {
1082                if(!$this-ds)
1083                    $this->ldapRootConnect(false);
1084
1085                $filter="(&(|(phpgwAccountType=u)(phpgwAccountType=s)(phpgwAccountType=i)(phpgwAccountType=g))(mail=$mail))";
1086                $justthese = array("uid");
1087                $sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese);
1088                if(!$sr)
1089                    return false;
1090                $info = ldap_get_entries($this->ds, $sr);
1091                return $info[0]["uid"][0];
1092        }
1093
1094       
1095        /**
1096         * Retorna as contas compartilhas
1097         * @param string $toaddress emails
1098         * @param string $ccaddress emails
1099         * @param string $ccoaddress emails
1100         * @param array $groups array com os grupos que o usuario pertence
1101         * @return array
1102         */
1103        function returnSharedsAccounts($toaddress,$ccaddress,$ccoaddress)
1104        {
1105
1106          $arrayAllAddres = array();
1107          $arrayAllAddres =  array_merge($arrayAllAddres , explode(',',$toaddress));
1108          $arrayAllAddres =  array_merge($arrayAllAddres, explode(',',$ccaddress));
1109          $arrayAllAddres = array_merge($arrayAllAddres, explode(',',$ccoaddress));
1110
1111          $mailsArray = array();
1112
1113           foreach ($arrayAllAddres as $toAddres)
1114           {
1115
1116               if(strchr($toAddres,'@') && strchr($toAddres,'<') && strchr($toAddres,'>'))
1117               {
1118                    $alias = substr($toAddres, strpos($toAddres,'<'), strpos($toAddres,'>'));
1119                    $alias = str_replace('<','', str_replace('>','',$alias));
1120                    array_push($mailsArray, $alias);
1121               }
1122               else if(strchr($toAddres,'@'))
1123               {
1124                    array_push($mailsArray, $toAddres);
1125               }
1126           }
1127           $arraySharedAccounts = array();
1128
1129           $conexao = $this->ldapConnect2(true);
1130
1131
1132           $mailFilter = '';
1133
1134           foreach ($mailsArray as $mail)
1135             $mailFilter .= '(|(mail='.$mail.')(mailAlternateAddress='.$mail.'))';
1136
1137
1138           $filter = '(&(phpgwAccountType=s)(|'.$mailFilter.') )';
1139           $ldap_context = $_SESSION['phpgw_info']['expressomail']['server']['ldap_context'];
1140           $justthese = array('cn','uid','mail');
1141
1142           if ($conexao)
1143           {
1144                $search = @ldap_search($conexao, $ldap_context, $filter, $justthese);
1145                if($search)
1146                {
1147                    $results = ldap_get_entries($conexao, $search);
1148
1149                    foreach ($results as $result)
1150                    {
1151                        if($result['mail'][0])
1152                            array_push($arraySharedAccounts, $result['mail'][0]);
1153                    }
1154                }
1155
1156           }
1157
1158           return $arraySharedAccounts;
1159        }
1160        /**
1161        * Verifica se um email é uma conta compartilhada
1162        *
1163        * @license    http://www.gnu.org/copyleft/gpl.html GPL
1164        * @author     Cons?rcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
1165        * @author     Cristiano Corrêa Schmidt
1166        * @param      String $mail Email a ser verificado
1167        * @return     bolean
1168        * @access     public
1169        */
1170        function isSharedAccountByMail($mail)
1171        {
1172            $return = false;
1173            $conexao = $this->ldapConnect2(true);
1174            $filter = '(&(phpgwAccountType=s)(mail='.$mail.'))';
1175            $ldap_context = $_SESSION['phpgw_info']['expressomail']['server']['ldap_context'];
1176            $justthese = array('cn','uid','mail');
1177            if ($conexao)
1178            {
1179                $search = @ldap_search($conexao, $ldap_context, $filter, $justthese);
1180                if(ldap_count_entries ($conexao , $search))
1181                    $return = true;
1182            }
1183
1184            return $return;
1185        }
[5821]1186
1187        function save_telephoneNumber($params){
1188                $return = array();
1189                if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['blockpersonaldata']){
1190                        $return['error'] = $this->functions->getLang("You can't modify your Commercial Telephone.");
1191                        return $return;
1192                }
1193                $old_telephone = 0;
1194                $pattern = '/\([0-9]{2,3}\)[0-9]{4}-[0-9]{4}$/';
1195                if ((strlen($params['number']) != 0) && (!preg_match($pattern, $params['number'])))
1196                        {
1197                        $return['error'] = $this->functions->getLang('The format of telephone number is invalid');
1198                        return $return;
1199                }
1200                if($params['number'] != $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['telephone_number']) {
1201                        $old_telephone = $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['telephone_number'];
1202                        $this->ldapRootConnect(false);
1203                        if(strlen($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['telephone_number']) == 0) {
1204                                $info['telephonenumber'] = $params['number'];
1205                                $result = @ldap_mod_add($this->ds, $_SESSION['phpgw_info']['expressomail']['user']['account_dn'], $info);
1206                        }
1207                        else {
1208                                $info['telephonenumber'] = $params['number'];
1209                                $result = @ldap_mod_replace($this->ds, $_SESSION['phpgw_info']['expressomail']['user']['account_dn'], $info);
1210                        }
1211                        $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['telephone_number'] = $info['telephonenumber'];
1212                                //      Log updated telephone number by user action
1213                                include_once('class.db_functions.inc.php');
1214                                $db_functions = new db_functions();
1215                        $db_functions->write_log('modified user telephone',"User changed its own telephone number in preferences $old_telephone => ".$info['telephonenumber']);
1216                        unset($info['telephonenumber']);
1217                }
1218                return $return['ok'] = true;
1219        }       
[2]1220}
[108]1221?>
Note: See TracBrowser for help on using the repository browser.