Ignore:
Timestamp:
11/03/11 13:24:28 (12 years ago)
Author:
wmerlotto
Message:

Ticket #2305 - Enviando alteracoes, desenvolvidas internamente na Prognus, do modulo ExpressoMail?.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/expressoMail1_2/inc/class.ldap_functions.inc.php

    r5075 r5134  
    2424                @include("../contactcenter/setup/external_catalogs.inc.php"); 
    2525                $this->ldapService = ServiceLocator::getService('ldap'); 
     26                if(isset($external_srcs)) 
    2627                $this->external_srcs = $external_srcs; 
    2728                $this->max_result = $this->ldapService->limit; 
     
    6566                ldap_set_option($ds, LDAP_OPT_REFERRALS, $refer); 
    6667                if ($refer) 
    67                         ldap_set_rebind_proc($ds, ldapRebind); 
     68                        ldap_set_rebind_proc($ds, 'rebind'); 
    6869                @ldap_bind($ds, $_SESSION['phpgw_info']['expressomail']['ldap_server']['acc'],$_SESSION['phpgw_info']['expressomail']['ldap_server']['pw']); 
    6970 
     
    8889                $functions = new functions; 
    8990 
    90 //              $search_for     = utf8_encode($params['search_for']); 
    91   //Testa se a busca foi realizada com aspas 
    92                 $search_for     = utf8_encode($params['search_for']); 
    93                 $search_len = (strlen($search_for)) - 1; 
    94                 $quote_status=false; 
    95  
    96                 if((($search_for{0}) == "\"") && (($search_for{$search_len}) == "\"")){ 
    97                     $search_for{0} = " "; 
    98                     $search_for{$search_len} = " "; 
    99                     $quote_status=true; 
    100                 } 
    101  
    102  
    103  
    10491                $field          = $params['field']; 
    10592                $ID                     = $params['ID']; 
     
    118105                if ($this->ds) 
    119106                { 
    120                         if (($field != 'null') && ($ID != 'null')) 
    121                         { 
    122                                 $filter="(& (&(|(phpgwAccountType=u)(phpgwAccountType=g)(phpgwAccountType=l))(mail=*)) (|(cn=*$search_for*)(mail=*$search_for*)) (!(phpgwaccountvisible=-1)) )"; 
    123                                 if($extendedinfo) 
    124                                 $justthese = array("cn", "mail", "telephoneNumber", "mobile", "phpgwAccountVisible", "uid", "employeeNumber", "ou"); 
    125                                 else 
    126                                     $justthese = array("cn", "mail", "telephoneNumber", "mobile", "phpgwAccountVisible", "uid"); 
    127                         } 
    128                         else 
    129                         { 
    130                                 if($quote_status){ 
    131                                         $filter="(& (phpgwAccountType=u) (|(cn=* $search_for *)(cn=$search_for *)(cn=* $search_for)) (!(phpgwaccountvisible=-1)) )"; 
    132                                 } 
    133                                 else{ 
    134                                         $filter="(& (phpgwAccountType=u)(cn=*$search_for*) (!(phpgwaccountvisible=-1)) )"; 
    135                                 } 
    136                         //      $filter="(& (phpgwAccountType=u)(cn=*$search_for*) (!(phpgwaccountvisible=-1)) )"; 
    137                                 if($extendedinfo) 
    138                                 $justthese = array("cn", "mail", "telephoneNumber", "mobile", "phpgwAccountVisible","jpegPhoto", "uid", "employeeNumber", "ou"); 
    139                                 else 
    140                                     $justthese = array("cn", "mail", "telephoneNumber", "mobile", "phpgwAccountVisible","jpegPhoto", "uid"); 
    141                         } 
    142                         $sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese, 0, $this->max_result + 1); 
    143                         if(!$sr) 
    144                                 return null; 
    145                         $count_entries = ldap_count_entries($this->ds,$sr); 
     107                    $ldapService->connection = $this->ds; 
    146108 
    147109                $justthese = array("cn", "mail", "telephonenumber", "mobile", "phpgwaccountvisible", "uid", "employeenumber", "ou"); 
     
    301263              
    302264            include_once $_SESSION['rootPath']. '/header.inc.php'; 
    303              
    304                        
    305             if (stripos( $params['search_for'] , '@' ) !== false)  
    306                 $params['search_for'] = substr($params['search_for'], 0 , stripos( $params['search_for'] , '@' ) );  
    307              
    308265             
    309266            if($modal) 
     
    383340                $results['type_catalog'] = "P"; 
    384341            $results['search_for'] = $params['search_for']; 
     342                         
     343                        foreach($results as $i=>$value) 
     344                                $results[$i]['type_contact'] = "P"; 
     345                         
    385346                        return $results; 
    386347        }  
     
    408369                if (is_numeric($parts[3]) && $parts[1]=='attribute') 
    409370                {     
    410                     if($parts[2] == 'searchable' && $value == 'true') 
     371                    if($parts[2] == 'searchable' /*&& $value == 'true'*/) 
    411372                        $searchable_fields[$all_data['cc_attribute_ldapname_' . $parts[3]]] = $all_data['cc_attribute_name_' . $parts[3]];    
    412373                } 
     
    485446            $info_return['search_for'] = $params['search_for']; 
    486447                        $info_return['extra_ldap_fields'] = $campos_extras;  
     448                         
     449                        foreach($info_return as $i=>$value) 
     450                                $info_return[$i]['type_contact'] = "G"; 
    487451            return $info_return; 
    488452        }  
     
    640604                        $_SESSION['phpgw_info']['expressomail']['server']['ldap_root_pw']); 
    641605 
    642                         $groups = $ldapService->accountSearch($params['filter'], array("gidNumber","cn"), $params['context'] , 'g', 'cn');  
    643                         $users = $ldapService->accountSearch($params['filter'], array("uidNumber","cn"), $params['context'] , 'u', 'cn'); 
     606                        $groups = $ldapService->accountSearch($params['filter'], array("gidNumber","cn", 'uid'), $params['context'] , 'g', 'cn');  
     607                        $users = $ldapService->accountSearch($params['filter'], array("uidNumber","cn", 'uid'), $params['context'] , 'u', 'cn'); 
     608                        $compartilhadas = $ldapService->accountSearch($params['filter'], array("uidNumber","cn",'uid'), $params['context'] , 's', 'cn'); 
     609                         
     610 
    644611                        $group_options = array(); 
    645612                        $user_options  = array(); 
     613                        $shared_options = array(); 
     614 
    646615                        foreach($groups as $group) 
    647616                { 
    648                                 $group_options[] = '"'.$group['gidNumber'].'U'.'":"'.$group['cn'].'"'; 
     617                                $group_options[] = '"'.$group['gidnumber'].'U'.'":"'.$group['cn'].' ('.$group['uid'].')"'; 
    649618                } 
    650  
    651619                foreach($users as $user)  
    652620                    { 
    653                                 if($owner != $user['uidNumber']) 
    654                                         $user_options[] = '"'.$user['uidNumber'].'U'.'":"'.$user['cn'].'"'; 
     621                                if($owner != $user['uidnumber'])   
     622                                        $user_options[] = '"'.$user['uidnumber'].'U'.'":"'.$user['cn'].' ('.$user['uid'].')"'; 
     623                        }        
     624                        foreach($compartilhadas as $shared) 
     625                        { 
     626                                if($owner != $shared['uidnumber'])   
     627                                        $shared_options[] = '"'.$shared['uidnumber'].'U'.'":"'.$shared['cn'].' ('.$shared['uid'].')"'; 
    655628                    } 
    656629         
    657630                        $user_options = '{'.implode( ',', $user_options ).'}'; 
    658631                        $group_options = '{'.implode( ',', $group_options ).'}'; 
    659  
    660                 return array("users" => $user_options, "groups" => $group_options); 
     632                        $shared_options = '{'.implode( ',', $shared_options ).'}'; 
     633 
     634                 return '{"users":'.$user_options.',"groups":'.$group_options.',"shared":'. $shared_options .'}'; 
    661635        } 
    662636 
     
    996970                return false; 
    997971        } 
     972         
     973        function get_user_groups($uid) 
     974        { 
     975 
     976                $organizations = array(); 
     977         
     978                $this->ldapRootConnect(); 
     979 
     980                $justthese = array("gidnumber","cn"); 
     981                $filter="(&(phpgwAccountType=g)(memberuid=".$uid."))"; 
     982 
     983                $search = ldap_search($this->ds, $this->ldap_context, $filter, $justthese); 
     984 
     985                $result = array(); 
     986                $entries = ldap_get_entries($this->ds, $search); 
     987 
     988 
     989                for ($i=0; $i<$entries['count']; $i++) 
     990                { 
     991                        $result[ $entries[$i]['gidnumber'][0] ] = $entries[$i]['cn'][0]; 
     992                } 
     993 
     994                return $result; 
     995        } 
     996         
     997       function getMailByUid($pUid) 
     998        { 
     999                // do not follow the referral 
     1000                $this->ldapRootConnect(false); 
     1001                if ($this->ds) 
     1002                { 
     1003                        $filter="(&(|(phpgwAccountType=u)(phpgwAccountType=s)(phpgwAccountType=l))(uid=$pUid))"; 
     1004                        $justthese = array("mail"); 
     1005                        $sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese); 
     1006                        if(!$sr) 
     1007                                return false; 
     1008                        $info = ldap_get_entries($this->ds, $sr); 
     1009 
     1010 
     1011                        return utf8_decode($info[0]["mail"][0]); 
     1012                } 
     1013                return false; 
     1014        }  
     1015   
     1016        function mail2uid($mail) 
     1017        { 
     1018                if(!$this-ds) 
     1019                    $this->ldapRootConnect(false); 
     1020 
     1021                $filter="(&(|(phpgwAccountType=u)(phpgwAccountType=s)(phpgwAccountType=i)(phpgwAccountType=g))(mail=$mail))"; 
     1022                $justthese = array("uid"); 
     1023                $sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese); 
     1024                if(!$sr) 
     1025                    return false; 
     1026                $info = ldap_get_entries($this->ds, $sr); 
     1027                return $info[0]["uid"][0]; 
     1028        } 
     1029 
     1030         
     1031        /** 
     1032         * Retorna as contas compartilhas 
     1033         * @param string $toaddress emails 
     1034         * @param string $ccaddress emails 
     1035         * @param string $ccoaddress emails 
     1036         * @param array $groups array com os grupos que o usuario pertence 
     1037         * @return array 
     1038         */ 
     1039        function returnSharedsAccounts($toaddress,$ccaddress,$ccoaddress) 
     1040        { 
     1041 
     1042          $arrayAllAddres = array(); 
     1043          $arrayAllAddres =  array_merge($arrayAllAddres , explode(',',$toaddress)); 
     1044          $arrayAllAddres =  array_merge($arrayAllAddres, explode(',',$ccaddress)); 
     1045          $arrayAllAddres = array_merge($arrayAllAddres, explode(',',$ccoaddress)); 
     1046 
     1047          $mailsArray = array(); 
     1048 
     1049           foreach ($arrayAllAddres as $toAddres) 
     1050           { 
     1051 
     1052               if(strchr($toAddres,'@') && strchr($toAddres,'<') && strchr($toAddres,'>')) 
     1053               { 
     1054                    $alias = substr($toAddres, strpos($toAddres,'<'), strpos($toAddres,'>')); 
     1055                    $alias = str_replace('<','', str_replace('>','',$alias)); 
     1056                    array_push($mailsArray, $alias); 
     1057               } 
     1058               else if(strchr($toAddres,'@')) 
     1059               { 
     1060                    array_push($mailsArray, $toAddres); 
     1061               } 
     1062           } 
     1063           $arraySharedAccounts = array(); 
     1064 
     1065           $conexao = $this->ldapConnect2(true); 
     1066 
     1067 
     1068           $mailFilter = ''; 
     1069 
     1070           foreach ($mailsArray as $mail) 
     1071             $mailFilter .= '(|(mail='.$mail.')(mailAlternateAddress='.$mail.'))'; 
     1072 
     1073 
     1074           $filter = '(&(phpgwAccountType=s)(|'.$mailFilter.') )'; 
     1075           $ldap_context = $_SESSION['phpgw_info']['expressomail']['server']['ldap_context']; 
     1076           $justthese = array('cn','uid','mail'); 
     1077 
     1078           if ($conexao) 
     1079           { 
     1080                $search = @ldap_search($conexao, $ldap_context, $filter, $justthese); 
     1081                if($search) 
     1082                { 
     1083                    $results = ldap_get_entries($conexao, $search); 
     1084 
     1085                    foreach ($results as $result) 
     1086                    { 
     1087                        if($result['mail'][0]) 
     1088                            array_push($arraySharedAccounts, $result['mail'][0]); 
     1089                    } 
     1090                } 
     1091 
     1092           } 
     1093 
     1094           return $arraySharedAccounts; 
     1095        } 
     1096        /** 
     1097        * Verifica se um email é uma conta compartilhada 
     1098        * 
     1099        * @license    http://www.gnu.org/copyleft/gpl.html GPL 
     1100        * @author     Cons?rcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
     1101        * @author     Cristiano Corrêa Schmidt 
     1102        * @param      String $mail Email a ser verificado 
     1103        * @return     bolean 
     1104        * @access     public 
     1105        */ 
     1106        function isSharedAccountByMail($mail) 
     1107        { 
     1108            $return = false; 
     1109            $conexao = $this->ldapConnect2(true); 
     1110            $filter = '(&(phpgwAccountType=s)(mail='.$mail.'))'; 
     1111            $ldap_context = $_SESSION['phpgw_info']['expressomail']['server']['ldap_context']; 
     1112            $justthese = array('cn','uid','mail'); 
     1113            if ($conexao) 
     1114            { 
     1115                $search = @ldap_search($conexao, $ldap_context, $filter, $justthese); 
     1116                if(ldap_count_entries ($conexao , $search)) 
     1117                    $return = true; 
     1118            } 
     1119 
     1120            return $return; 
     1121        } 
    9981122} 
    9991123?> 
Note: See TracChangeset for help on using the changeset viewer.