source: branches/2.4/expressoMail1_2/inc/class.ldap_functions.inc.php @ 7020

Revision 7020, 45.4 KB checked in by eduardow, 12 years ago (diff)

Ticket #3009 - Problema com acentos na busca F9 do Ldap.

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