Ignore:
Timestamp:
05/23/08 17:10:39 (16 years ago)
Author:
brunocosta
Message:

Correção dos problemas gerados no commit anterior, a funcionalidade citada no ticket #199 foram temporariamente desativadas.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/contactcenter/inc/class.bo_ldap_manager.inc.php

    r284 r285  
    1212  \***************************************************************************/ 
    1313 
    14  
     14         
    1515        /* 
    1616                This class is responsible for the LDAP control/generic functions and for 
     
    1919        include_once('class.Thread.inc.php'); 
    2020 
    21         class bo_ldap_manager 
     21        class bo_ldap_manager  
    2222        { 
    23  
     23                 
    2424                var $srcs; 
    2525 
     26                 
    2627                function bo_ldap_manager () 
    2728                { 
    28  
    2929                        if (!($this->srcs = $GLOBALS['phpgw']->session->appsession('bo_ldap_manager.srcs','contactcenter'))) 
    3030                        { 
    3131                                $c = CreateObject('phpgwapi.config','contactcenter'); 
    3232                                $data = $c->read_repository(); 
    33  
     33                                 
    3434                                if (!$data or $data['cc_global_source0'] !== 'ldap') 
    3535                                { 
     
    3737                                        return; 
    3838                                } 
    39  
     39                                 
    4040                                $this->srcs = array( 
    4141                                        1 => array( 
     
    4646                                                'pw'     => $data['cc_ldap_pw0'], 
    4747                                                'obj'    => 'inetOrgPerson', 
    48                                                 'branch' => strtolower('ou') 
     48                                                'branch' => strtolower('ou'), 
     49                                                'visible' => $data['cc_ldap_query_automatic'] 
    4950                                        ) 
    50  
    5151                                ); 
    5252                        } 
     
    5656                { 
    5757                } 
    58  
     58         
    5959                /* 
    60  
     60                 
    6161                        @function get_all_ldap_sources 
    6262                        @abstract Returns an array containing all LDAP sources informations 
    6363                        @author Raphael Derosso Pereira 
    64  
     64                 
    6565                        @return array All LDAP information 
    6666                                $return = array( 
     
    6969                                                'dn'   => (string), 
    7070                                                'acc'  => (string), 
    71                                                 'pw'   => (string) 
     71                                                'pw'   => (string)    
    7272                                        ), 
    7373                                        ... 
    7474                                ) 
    75  
     75                                 
    7676                        TODO: Return multiple sources... 
    7777                */ 
     
    8080                        return $this->srcs; 
    8181                } 
    82  
     82                 
    8383                /* 
    8484                * @function get_external_ldap_sources 
     
    102102                function get_ldap_fields_association ( $id_source ) 
    103103                { 
    104  
     104                         
    105105                        $op_iop = array( 
    106106                                'contact.id_contact'               => array('dn'), 
     
    111111                                'contact.family_names'             => array('sn'), 
    112112                                'contact.names_ordered'            => array('cn'),//,'displayName'), 
    113  
    114113                                'contact.suffixes.suffix'          => false, 
    115114                                'contact.birthdate'                => false, 
     
    117116                                'contact.pgp_key'                  => false, 
    118117                                'contact.notes'                    => false, 
    119                                 'contact.mail_forwarding_address'  => array('mailForwardingAddress'), 
    120                                 'contact.account_type'             => array('phpgwAccountType'), 
    121                                 'contact.account_status'           => array('phpgwAccountStatus'), 
    122                                 'contact.account_visible'          => array('phpgwAccountVisible'), 
     118                                'contact.mail_forwarding_address' => array('mailForwardingAddress'), 
     119                                'contact.account_type' => array('phpgwAccountType'), 
     120                'contact.account_status'           => array('phpgwAccountStatus'), 
     121                'contact.account_visible'          => array('phpgwAccountVisible'), 
    123122                                'contact.object_class'             => array('objectClass'), 
    124123                                'contact.business_info.title'      => array('title'), 
    125                                 'contact.business_info.department' => array('ou'), // Setor do empregado... 
    126                                 'contact.business_info.empNumber'  => array('employeeNumber'), // Matricula do empregado 
     124                                'contact.business_info.department' => array('ou'), 
    127125                                'contact.company.company_name'     => array('o'), 
    128126                                'contact.company.company_notes'    => array('businessCategory'), 
    129  
     127                                 
    130128                                'contact.contact_related.names_ordered' => 'contact.contact_related.typeof_relation.contact_relation_name', 
    131129                                'contact.contact_related.typeof_relation.contact_relation_name' =>  array( 
     
    133131                                        'secretary' => array('secretary') 
    134132                                ), 
    135  
     133                                 
    136134                                'contact.address.address1'         => 'contact.address.typeof_address.contact_address_type_name', 
    137135                                'contact.address.typeof_address.contact_address_type_name' => array( 
    138136                                        'home' => array('street', 'st', 'postalAddress', 'homePostalAddress'), 
    139137                                ), 
    140  
     138                                 
    141139                                'contact.address.postal_code'      => 'contact.address.typeof_address.contact_address_type_name', 
    142140                                'contact.address.typeof_address.contact_address_type_name' => array( 
    143141                                        'home' => array('PostalCode'), 
    144142                                ), 
    145  
     143                                 
    146144                                'contact.address.city.city_name'   => 'contact.address.typeof_address.contact_address_type_name', 
    147145                                'contact.address.typeof_address.contact_address_type_name' => array( 
    148146                                        'home' => array('l'), 
    149147                                ), 
    150  
     148                                 
    151149                                'contact.address.city.state.state_name'       => 'contact.address.typeof_address.contact_address_type_name', 
    152150                                'contact.address.typeof_address.contact_address_type_name' => array( 
    153151                                        'home' => false, 
    154152                                ), 
    155  
     153                                 
    156154                                'contact.address.city.country.id_country'     => 'contact.address.typeof_address.contact_address_type_name', 
    157155                                'contact.address.typeof_address.contact_address_type_name' => array( 
    158156                                        'home' => array('c') 
    159157                                ), 
    160  
     158                                 
    161159                                'contact.connection.connection_value'         => 'contact.connection.typeof_connection.contact_connection_type_name', 
    162160                                'contact.connection.typeof_connection.contact_connection_type_name' => array ( 
     
    169167                                ), 
    170168                        ); 
    171  
     169                         
    172170                        return $op_iop; 
    173  
    174171                } 
    175172 
     
    232229 
    233230                /*! 
    234  
     231                 
    235232                        @function get_ldap_tree 
    236233                        @abstract Returns the LDAP tree corresponding to the specified level 
    237234                        @author Raphael Derosso Pereira 
    238  
     235                         
    239236                        @param (integer) $id_source The ID of the LDAP source 
    240  
     237                         
    241238                        @param (string)  $context The context to be used as root branch 
    242  
     239                                 
    243240                        @param (boolean) $recursive Make it a recursive construction. 
    244241                                CAUTION! This is EXTREMELY SLOW on large LDAP databases, 
    245242                                specially when they're not indexed 
    246                 */ 
    247                 function get_ldap_tree($id_source, $context = false, $recursive = false) 
     243                */               
     244                function get_ldap_tree($id_source, $context = false, $recursive = false)  
    248245                { 
    249246                        if (!$this->srcs[$id_source]) 
     
    251248                                return null; 
    252249                        } 
    253  
     250                         
    254251                        $ldap = $GLOBALS['phpgw']->common->ldapConnect($this->srcs[$id_source]['host'], $this->srcs[$id_source]['acc'],$this->srcs[$id_source]['pw'], false); 
    255252                        if (!$ldap) 
     
    257254                                return false; 
    258255                        } 
    259  
     256                         
    260257                        if ($recursive) 
    261258                        { 
     
    265262                                return $tree; 
    266263                        } 
    267  
    268                         return $this->get_ldap_tree_level($id_source, $ldap, $context, $this->srcs[$id_source]['obj'],$this->srcs[$id_source]['branch'], 0); 
    269                 } 
     264                         
     265                        return $this->get_ldap_tree_level($id_source, $ldap, $context, $this->srcs[$id_source]['obj'],$this->srcs[$id_source]['branch']); 
     266                } 
     267                // SERPRO 
    270268 
    271269                /*! 
     
    336334                                return null; 
    337335                        } 
    338  
     336                         
    339337                        $count = ldap_count_entries($resource,$result_res); 
    340338                        if ( $count == 0 ) 
     
    353351                                } 
    354352                        } 
    355  
     353                         
    356354                        $entries = ldap_get_entries($resource, $result_res); 
    357  
     355                         
    358356                        for ($i = 0; $i < $entries['count']; $i++) 
    359357                        { 
    360358                                $subtree = $this->get_ldap_tree_recursive($resource, $entries[$i]['dn'], $objectClass); 
    361  
     359                                 
    362360                                $dn_parts=ldap_explode_dn($entries[$i]['dn'],1); 
    363  
    364  
    365  
    366                                 if ($subtree !== null and is_array($subtree)) 
     361                                 
     362                                if ($subtree !== null and is_array($subtree))  
    367363                                { 
    368364                                        $tree[$i]['name'] = $dn_parts[0]; 
     
    381377                                                'sub_branch' => false 
    382378                                        ); 
    383                                 } 
     379                                }  
    384380                        } 
    385381 
     
    393389                        } 
    394390                } 
    395  
     391                 
    396392                function get_ldap_referrals($ds, $dn, $filter) { 
    397  
     393                         
    398394                        ldap_set_option($ds, LDAP_OPT_REFERRALS, 0); 
    399395                        ldap_set_option($ds,LDAP_OPT_PROTOCOL_VERSION,3); 
    400  
     396                         
    401397                        if ($ds) { 
    402398                            ldap_bind($ds); 
    403                                 $sr=ldap_list($ds,$dn, $filter); 
     399                                $sr=ldap_list($ds,$dn, $filter);                     
    404400                                $ref = ldap_first_reference($ds, $sr); 
    405401                                $array_referral = array(); 
    406402                                $idx = 0; 
    407  
     403                                 
    408404                                 while ($ref) { 
    409405                                        $array_referral[$idx++] = ldap_get_dn($ds, $ref); 
     
    412408                                return $array_referral; 
    413409                        } 
    414                         else 
     410                        else  
    415411                                return false; 
    416412                } 
    417413 
    418414                function get_ldap_sub_branches_referrals($ds, $dn, $filter) { 
    419  
     415                         
    420416                        $referral = $this -> get_ldap_referrals($ds, $dn, $filter); 
    421417                        $sub_branches = array(); 
    422  
     418                         
    423419                        for($i = 0; $i <count($referral); $i++) { 
    424420                                $dn = str_replace("??base","",preg_replace('!^(ldap://[^/]+)/(.*$)!', '\\2', $referral[$i])); 
    425                                 $dn = explode(",",$dn); 
     421                                $dn = explode(",",$dn);                          
    426422                                $dn = strtoupper(str_replace("ou=", "",$dn[0])); 
    427423                                $dn = str_replace("DC=", "",$dn); 
    428  
     424                                                                                                                                                                                 
    429425                                $sub_branch = array( 
    430426                                                                                        'name' => $dn, 
    431427                                                                'type' => 'unknown', 
    432428                                                                'value' => $referral[$i], 
    433                                                                 'sub_branch' => false 
    434                                                                                 ); 
    435                                 $sub_branches[$i] = $sub_branch; 
     429                                                                'sub_branch' => false            
     430                                                                                );                                                                                                                       
     431                                $sub_branches[$i] = $sub_branch;                         
    436432                        } 
    437433                        return $sub_branches; 
    438434                } 
     435                 
    439436 
    440437                function translate_accentuation($text) 
     
    464461                        //$filter = '(!(objectClass='.$objectClass.'))'; 
    465462                        // Don't show OU's whith phpgwAccountVisible equal to '-1' 
    466  
    467463                        if ($external) 
    468464                        { 
     
    483479                        if ($result_res === false) 
    484480                        { 
    485                                 if (ldap_errno($resource) === 3) 
    486                                 { 
    487                                         return array('error_msg' => ldap_error($resource)); 
    488                                 } 
    489481                                return null; 
    490482                        } 
     
    591583                                $tree['ldap']       = array('id_source' => $id_source, 'context' => $context); 
    592584                        } 
     585                         
    593586                        usort($tree['sub_branch'], array($this, "compareTreeNodes")); 
    594587                        return $tree; 
     
    596589 
    597590                function compareTreeNodes($a, $b)       { 
    598  
     591                                                 
    599592                        return strnatcasecmp($a['name'], $b['name']); 
    600                 } 
     593                }        
    601594 
    602595        } 
Note: See TracChangeset for help on using the changeset viewer.