Changeset 3530


Ignore:
Timestamp:
11/23/10 15:22:12 (13 years ago)
Author:
brunocosta
Message:

Ticket #1325 - Adapta buscas LDAP para casos que não existem OUs.

Location:
branches/2.2
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2/admin/inc/class.sovoip.inc.php

    r395 r3530  
    4646                if ( $this->ldap )       
    4747                { 
    48                         $filter = "ou=*"; 
     48                        $filter = "objectClass=organizationalUnit"; 
    4949                        $justthese = array("ou"); 
    5050                        $search = ldap_list($this->ldap, $this->ldap_context, $filter, $justthese); 
     
    5252                } 
    5353 
    54                 if( $entry ) 
     54                //$result_ou[] = ""; 
     55 
     56                if( $entry['count'] > 0 ) 
    5557                { 
    5658                        foreach($entry as $tmp) 
    5759                                if( $tmp['ou'][0] != "" ) 
    5860                                        $result_ou[] = $tmp['ou'][0]; 
     61                }else{ 
     62                    $result_ou[] = $this->ldap_context; 
    5963                } 
    6064                 
     
    6670        public final function getGroupsLdap($pOrg) 
    6771        { 
    68                 $organization = 'ou=' . $pOrg['ou'] .",". $this->ldap_context; 
     72                if($pOrg['ou'] == $this->ldap_context) 
     73                    $organization = $this->ldap_context; 
     74                else 
     75                    $organization = 'ou=' . $pOrg['ou'] .",". $this->ldap_context; 
    6976                 
    7077                $this->ldap = $this->common->ldapConnect($this->ldap_host,$this->ldap_root_dn,$this->ldap_root_pw); 
     
    7481                        $filter = "(&(phpgwAccountType=g)(objectClass=posixGroup))"; 
    7582                        $justthese = array("cn","gidNumber"); 
    76                         $search = ldap_list($this->ldap, $organization, $filter, $justthese); 
     83                        $search = ldap_search($this->ldap, $organization, $filter, $justthese); 
    7784                        $entry = ldap_get_entries( $this->ldap, $search ); 
    7885 
  • branches/2.2/expressoAdmin1_2/inc/class.functions.inc.php

    r3456 r3530  
    562562                         
    563563                        $justthese = array("dn","diskQuota","usersQuota","actualDiskQuota"); 
    564                         $filter = "(ou=*)"; 
     564                        $filter = "(objectClass=organizationalUnit)"; 
    565565                        foreach ($contexts as $context) { 
    566566                                $search=ldap_search($ldap_conn, $context, $filter, $justthese); 
     
    575575                                        $dn = $info[$i]["dn"]; 
    576576                                         
    577                                         // Necessário, pq em uma busca com ldapsearch ou=*, traz tb o próprio ou.  
     577                                        // Necessário, pq em uma busca com ldapsearch objectClass=organizationalUnit, traz tb o próprio ou. 
    578578                                        //if (strtolower($dn) == $context) 
    579579                                                //continue; 
     
    731731                         
    732732                        $justthese = array("dn"); 
    733                         $filter = "(ou=*)"; 
     733                        $filter = "(objectClass=organizationalUnit)"; 
    734734                         
    735735                        $systemName = strtolower($GLOBALS['phpgw_info']['server']['system_name']); 
  • branches/2.2/expressoAdmin1_2/inc/class.ldap_functions.inc.php

    r3396 r3530  
    338338                                */ 
    339339                                 
    340                                 $filter = "(ou=*)"; 
     340                                $filter = "(objectClass=organizationalUnit)"; 
    341341                                $justthese = array("ou"); 
    342342                                $search = ldap_list($ldap_connection2, $context, $filter, $justthese); 
  • branches/2.2/expressoMail1_2/inc/class.ldap_functions.inc.php

    r3388 r3530  
    405405                        $info = ldap_get_entries($this->ds, $sr); 
    406406 
     407                        if($info["count"] == 0) 
     408                        { 
     409                            $organizations[0]['ou'] = $this->ldap_context; 
     410                        } 
     411 
    407412                        for ($i=0; $i<$info["count"]; $i++) 
    408413                                $organizations[$i] = $info[$i]["ou"][0]; 
     
    420425                $this->ldapRootConnect($referral); 
    421426                if ($this->ds) { 
    422                         $filter="(&(ou=*)(!(phpgwAccountVisible=-1)))"; 
     427                        $filter="(&(objectClass=organizationalUnit)(!(phpgwAccountVisible=-1)))"; 
    423428                        $justthese = array("ou"); 
    424429                        $sr = ldap_list($this->ds, $this->ldap_context, $filter, $justthese); 
    425430                        $info = ldap_get_entries($this->ds, $sr); 
    426431 
    427                         for ($i=0; $i<$info["count"]; $i++) 
    428                         { 
    429                                 $organizations[$i]['ou'] = $info[$i]["ou"][0]; 
    430                                 $organizations[$i]['dn'] = $info[$i]["dn"]; 
    431                         } 
    432  
     432 
     433                        if($info["count"] == 0) 
     434                        { 
     435                            $organizations[0]['ou'] = $this->ldap_context; 
     436                            $organizations[0]['dn'] = $this->ldap_context; 
     437                        } 
     438                        else{ 
     439                            for ($i=0; $i<$info["count"]; $i++) 
     440                            { 
     441                                    $organizations[$i]['ou'] = $info[$i]["ou"][0]; 
     442                                    $organizations[$i]['dn'] = $info[$i]["dn"]; 
     443                            } 
     444                        } 
    433445                        ldap_close($this->ds); 
    434446                        sort($organizations); 
  • branches/2.2/expressoMail1_2/js/sharemailbox.js

    r1913 r3530  
    201201                        for(i = 0; i < data.length; i++) { 
    202202                                Element('em_combo_org').options[i] = new Option(data[i].ou,data[i].dn); 
    203                                 if(user_organization.toUpperCase() == data[i].ou.toUpperCase()) 
     203                                if(data[i].ou.indexOf("dc=") != -1 || user_organization.toUpperCase() == data[i].ou.toUpperCase()) 
    204204                                { 
    205205                                        Element('em_combo_org').options[i].selected = true; 
  • branches/2.2/jabberit_messenger/inc/class.contacts_im.inc.php

    r3406 r3530  
    119119                        foreach($users as $tmp) 
    120120                        { 
    121                                 if ( !array_key_exists($tmp['ou'], $order) ) 
     121                            if ( !array_key_exists($tmp['ou'], $order) ) 
    122122                                        $order[$tmp['ou']] = array(); 
    123123 
  • branches/2.2/jabberit_messenger/inc/class.ldap_im.inc.php

    r3266 r3530  
    340340                if( $this->ldap ) 
    341341                { 
    342                         $filter = "(ou=*)"; 
     342                        $filter = "(objectClass=organizationalUnit)"; 
    343343                        $justthese = array("dn"); 
    344344                        $search = ldap_search($this->ldap, $this->ldap_context, $filter, $justthese); 
     
    464464                                $result[$j]['uid']                      = $entry[$i][$this->attribute][0]; 
    465465                                $result[$j]['jid']                      = $entry[$i][$this->attribute][0]; 
    466                                  
    467                                 $ou = explode("dc=", $entry[$i]['dn']); 
    468                                 $ou = explode("ou=",$ou[0]); 
    469                                 $ou = array_pop($ou); 
    470                                 $result[$j]['ou']       = strtoupper(substr($ou,0,strlen($ou)-1)); 
     466 
     467                                if(!strpos($entry[$i]['dn'],"ou=") === FALSE){ 
     468                                    $ou = explode("dc=", $entry[$i]['dn']); 
     469                                    $ou = explode("ou=",$ou[0]); 
     470                                    $ou = array_pop($ou); 
     471                                    $result[$j]['ou']   = strtoupper(substr($ou,0,strlen($ou)-1)); 
     472                                }else{ 
     473                                    $ou = explode("dc=", $entry[$i]['dn']); 
     474                                    $result[$j]['ou'] = strtoupper(substr($ou[1],0,strlen($ou[1])-1)); 
     475                                } 
    471476                                 
    472477                                if( $pOrg === "*" ) 
  • branches/2.2/jabberit_messenger/jmessenger/inc/class.LdapIM.inc.php

    r3326 r3530  
    339339                if( $this->ldap ) 
    340340                { 
    341                         $filter = "(ou=*)"; 
     341                        $filter = "(objectClass=organizationalUnit)"; 
    342342                        $justthese = array("dn"); 
    343343                        $search = ldap_search($this->ldap, $this->ldap_context, $filter, $justthese); 
  • branches/2.2/phpgwapi/inc/class.sector_search_ldap.inc.php

    r207 r3530  
    11<?php 
    2         /**************************************************************************\ 
    3         * phpGroupWare API - Accounts manager for LDAP                             * 
    4         * Written by Joao Alfredo Knopik Junior <jakje@celepar.pr.gov.br>          * 
    5         * View and manipulate account records using LDAP                           * 
    6         * Copyright (C) 2000 - 2002 Joseph Engo, Lars Kneschke                     * 
    7         * Copyright (C) 2003 Lars Kneschke, Bettina Gille                          * 
    8         * ------------------------------------------------------------------------ * 
    9         * This library is part of the phpGroupWare API                             * 
    10         * http://www.phpgroupware.org                                              * 
    11         * ------------------------------------------------------------------------ * 
    12         * This library is free software; you can redistribute it and/or modify it  * 
    13         * under the terms of the GNU Lesser General Public License as published by * 
    14         * the Free Software Foundation; either version 2.1 of the License,         * 
    15         * or any later version.                                                    * 
    16         * This library is distributed in the hope that it will be useful, but      * 
    17         * WITHOUT ANY WARRANTY; without even the implied warranty of               * 
    18         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     * 
    19         * See the GNU Lesser General Public License for more details.              * 
    20         * You should have received a copy of the GNU Lesser General Public License * 
    21         * along with this library; if not, write to the Free Software Foundation,  * 
    22         * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA            * 
    23         \**************************************************************************/ 
    24          
    25         include_once('class.common.inc.php'); 
    26          
    27         class sector_search_ldap  
    28         { 
    29                 var $common; 
    30                 var $ldap_connection; 
    31                 var $sector_name; 
    32                 var $sector_context; 
    33                 var $sector_level; 
    34                 var $sector_leaf; 
    35                          
    36                 function sector_search_ldap($sector_name="", $sector_context="", $sector_level="", $sector_leaf="", $ldap_conn="") 
    37                 { 
    38                         if ($ldap_conn == "") 
    39                         { 
    40                                 $this->common = new common; 
    41                                 $this->ldap_connection = $this->common->ldapConnect(); 
    42                         } 
    43                         else 
    44                                 $this->ldap_connection = $ldap_conn; 
    45                                  
    46                         $this->sector_name = $sector_name; 
    47                         $this->sector_context = $sector_context; 
    48                         $this->sector_level = $sector_level; 
    49                         $this->sector_leaf = $sector_leaf; 
     2 
     3/* * ************************************************************************\ 
     4 * phpGroupWare API - Accounts manager for LDAP                             * 
     5 * Written by Joao Alfredo Knopik Junior <jakje@celepar.pr.gov.br>          * 
     6 * View and manipulate account records using LDAP                           * 
     7 * Copyright (C) 2000 - 2002 Joseph Engo, Lars Kneschke                     * 
     8 * Copyright (C) 2003 Lars Kneschke, Bettina Gille                          * 
     9 * ------------------------------------------------------------------------ * 
     10 * This library is part of the phpGroupWare API                             * 
     11 * http://www.phpgroupware.org                                              * 
     12 * ------------------------------------------------------------------------ * 
     13 * This library is free software; you can redistribute it and/or modify it  * 
     14 * under the terms of the GNU Lesser General Public License as published by * 
     15 * the Free Software Foundation; either version 2.1 of the License,         * 
     16 * or any later version.                                                    * 
     17 * This library is distributed in the hope that it will be useful, but      * 
     18 * WITHOUT ANY WARRANTY; without even the implied warranty of               * 
     19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     * 
     20 * See the GNU Lesser General Public License for more details.              * 
     21 * You should have received a copy of the GNU Lesser General Public License * 
     22 * along with this library; if not, write to the Free Software Foundation,  * 
     23 * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA            * 
     24  \************************************************************************* */ 
     25 
     26include_once('class.common.inc.php'); 
     27 
     28class sector_search_ldap { 
     29 
     30    var $common; 
     31    var $ldap_connection; 
     32    var $sector_name; 
     33    var $sector_context; 
     34    var $sector_level; 
     35    var $sector_leaf; 
     36 
     37    function sector_search_ldap($sector_name="", $sector_context="", $sector_level="", $sector_leaf="", $ldap_conn="") { 
     38        if ($ldap_conn == "") { 
     39            $this->common = new common; 
     40            $this->ldap_connection = $this->common->ldapConnect(); 
     41        } 
     42        else 
     43            $this->ldap_connection = $ldap_conn; 
     44 
     45        $this->sector_name = $sector_name; 
     46        $this->sector_context = $sector_context; 
     47        $this->sector_level = $sector_level; 
     48        $this->sector_leaf = $sector_leaf; 
     49    } 
     50 
     51    // All levels of ouŽs, organizations (first level) and sectors (rest levels) 
     52    function sector_search($ldap_context, $clear_static_vars=true) { 
     53        static $sectors_list = array(); 
     54        static $level = 0; 
     55 
     56        if ($clear_static_vars) { 
     57            $sectors_list = array(); 
     58            $level = 0; 
     59        } 
     60 
     61        $filter = "objectClass=organizationalUnit"; 
     62        $justthese = array("ou"); 
     63        $sr = ldap_list($this->ldap_connection, $ldap_context, $filter, $justthese); 
     64        ldap_sort($this->ldap_connection, $sr, "ou"); 
     65        $info = ldap_get_entries($this->ldap_connection, $sr); 
     66 
     67        for ($i = 0; $i < $info["count"]; $i++) { 
     68            $level++; 
     69            $next_ldap_context[$i] = $info[$i]["dn"]; 
     70 
     71            $obj = new sector_search_ldap($info[$i]["ou"][0], $next_ldap_context[$i], $level, 'False', $this->ldap_connection); 
     72            array_push($sectors_list, $obj); 
     73 
     74            $this->sector_search($next_ldap_context[$i], false); 
     75        } 
     76        $level--; 
     77        return $sectors_list; 
     78    } 
     79 
     80    // Just the first level, or the organizations 
     81    function organization_search($ldap_context) { 
     82        $filter = "objectClass=organizationalUnit"; 
     83        $justthese = array("ou"); 
     84 
     85        $sr = ldap_list($this->ldap_connection, $ldap_context, $filter, $justthese); 
     86        $info = ldap_get_entries($this->ldap_connection, $sr); 
     87 
     88        if ($info["count"] == 0) { 
     89            $sectors_list[0] = $ldap_context; 
     90        } else { 
     91 
     92            for ($i = 0; $i < $info["count"]; $i++) { 
     93                $sectors_list[$i] = $info[$i]["ou"][0]; 
     94            } 
     95        } 
     96        sort($sectors_list); 
     97        return $sectors_list; 
     98    } 
     99 
     100    // Retorna os organizações com os options prontos 
     101    // Parametro master: realiza ldap_connect utilizando dados do Contact Center, permitindo buscas completas em todos os ldaps. 
     102    function get_organizations($context, $selected='', $referral=false, $show_invisible_ou=false, $master=false) { 
     103        if ($master) { 
     104            $ldap_cc_info = CreateObject('contactcenter.bo_ldap_manager'); 
     105            $ldap_cc_info = $ldap_cc_info ? $ldap_cc_info->srcs[1] : null; 
     106            $dn = $ldap_cc_info['acc']; 
     107            $passwd = $ldap_cc_info['pw']; 
     108            $host = $ldap_cc_info['host']; 
     109        } else { 
     110            $dn = $GLOBALS['phpgw_info']['server']['ldap_root_dn']; 
     111            $passwd = $GLOBALS['phpgw_info']['server']['ldap_root_pw']; 
     112            $host = $GLOBALS['phpgw_info']['server']['ldap_host']; 
     113        } 
     114 
     115        $ldap_conn = ldap_connect($host); 
     116 
     117        ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3); 
     118 
     119        if ($referral) 
     120            ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 1); 
     121        else 
     122            ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 0); 
     123 
     124        ldap_bind($ldap_conn, $dn, $passwd); 
     125 
     126        $justthese = array("dn"); 
     127        $filter = $show_invisible_ou ? "(objectClass=organizationalUnit)" : "(& (objectClass=organizationalUnit) (!(phpgwAccountVisible=-1)) )"; 
     128        $search = ldap_search($ldap_conn, $context, $filter, $justthese); 
     129 
     130        ldap_sort($ldap_conn, $search, "ou"); 
     131        $info = ldap_get_entries($ldap_conn, $search); 
     132        ldap_close($ldap_conn); 
     133 
     134        // Retiro o count do array info e inverto o array para ordenação. 
     135 
     136        if ($info["count"] == 0) { 
     137            return $options = "<option value='$context' selected=\"selected\"> $context </option>"; 
     138        } 
     139 
     140        for ($i = 0; $i < $info["count"]; $i++) { 
     141            $dn = $info[$i]["dn"]; 
     142 
     143            // Necessário, pq em uma busca com ldapsearch objectClass=organizationalUnit, traz tb o próprio ou. 
     144            if (strtolower($dn) == $context) 
     145                continue; 
     146 
     147            $array_dn = ldap_explode_dn($dn, 1); 
     148 
     149            $array_dn_reverse = array_reverse($array_dn, true); 
     150 
     151            // Retirar o indice count do array. 
     152            array_pop($array_dn_reverse); 
     153 
     154            $inverted_dn[$dn] = implode("#", $array_dn_reverse); 
     155        } 
     156 
     157        if (is_array($inverted_dn)) { 
     158            // Ordenação 
     159            natcasesort($inverted_dn); 
     160 
     161            // Construção do select 
     162            $level = 0; 
     163            foreach ($inverted_dn as $dn => $invert_ufn) { 
     164                $display = ''; 
     165 
     166                $array_dn_reverse = explode("#", $invert_ufn); 
     167                $array_dn = array_reverse($array_dn_reverse, true); 
     168 
     169                $level = count($array_dn) - (int) (count(explode(",", $GLOBALS['phpgw_info']['server']['ldap_context'])) + 1); 
     170 
     171                if ($level == 0) 
     172                    $display .= '+'; 
     173                else { 
     174                    for ($i = 0; $i < $level; $i++) 
     175                        $display .= '---'; 
    50176                } 
    51          
    52                 // All levels of ouŽs, organizations (first level) and sectors (rest levels) 
    53                 function sector_search($ldap_context, $clear_static_vars=true) 
    54                 { 
    55                         static $sectors_list = array(); 
    56                         static $level = 0; 
    57                          
    58                         if ($clear_static_vars) 
    59                         { 
    60                                 $sectors_list = array(); 
    61                                 $level = 0; 
    62                         } 
    63                          
    64                         $filter="ou=*";          
    65                         $justthese = array("ou"); 
    66                         $sr=ldap_list($this->ldap_connection, $ldap_context, $filter, $justthese); 
    67                         ldap_sort($this->ldap_connection ,$sr, "ou"); 
    68                         $info = ldap_get_entries($this->ldap_connection, $sr); 
    69  
    70                         for ($i=0; $i<$info["count"]; $i++) 
    71                         { 
    72                                 $level++; 
    73                                 $next_ldap_context[$i] = $info[$i]["dn"]; 
    74                                  
    75                                 $obj = new sector_search_ldap($info[$i]["ou"][0], $next_ldap_context[$i], $level, 'False', $this->ldap_connection); 
    76                                 array_push($sectors_list, $obj); 
    77  
    78                                 $this->sector_search($next_ldap_context[$i], false); 
    79                         } 
    80                         $level--; 
    81                         return $sectors_list; 
    82                 } 
    83                  
    84                 // Just the first level, or the organizations 
    85                 function organization_search($ldap_context) 
    86                 { 
    87                         $filter="ou=*";          
    88                         $justthese = array("ou"); 
    89                          
    90                         $sr=ldap_list($this->ldap_connection, $ldap_context, $filter, $justthese); 
    91                         $info = ldap_get_entries($this->ldap_connection, $sr); 
    92                          
    93                         for ($i=0; $i<$info["count"]; $i++) 
    94                         { 
    95                                 $sectors_list[$i] = $info[$i]["ou"][0]; 
    96                         }                                
    97                         sort($sectors_list); 
    98                         return $sectors_list; 
    99                 } 
    100                  
    101                 // Retorna os organizações com os options prontos 
    102                 // Parametro master: realiza ldap_connect utilizando dados do Contact Center, permitindo buscas completas em todos os ldaps. 
    103                 function get_organizations($context, $selected='', $referral=false ,$show_invisible_ou=false, $master=false) 
    104                 { 
    105                         if ($master) 
    106                         { 
    107                                 $ldap_cc_info = CreateObject('contactcenter.bo_ldap_manager'); 
    108                                 $ldap_cc_info = $ldap_cc_info ? $ldap_cc_info->srcs[1] : null; 
    109                                 $dn                     = $ldap_cc_info['acc']; 
    110                                 $passwd         = $ldap_cc_info['pw']; 
    111                                 $host           = $ldap_cc_info['host']; 
    112                         } 
    113                         else 
    114                         { 
    115                                 $dn                     = $GLOBALS['phpgw_info']['server']['ldap_root_dn']; 
    116                                 $passwd         = $GLOBALS['phpgw_info']['server']['ldap_root_pw']; 
    117                                 $host           = $GLOBALS['phpgw_info']['server']['ldap_host']; 
    118                         } 
    119                          
    120                         $ldap_conn      = ldap_connect($host); 
    121                          
    122                         ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3); 
    123                          
    124                         if ($referral) 
    125                                 ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 1); 
    126                         else 
    127                                 ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 0); 
    128                          
    129                         ldap_bind($ldap_conn,$dn,$passwd); 
    130                          
    131                         $justthese = array("dn"); 
    132                         $filter = $show_invisible_ou ? "(ou=*)" : "(& (ou=*) (!(phpgwAccountVisible=-1)) )"; 
    133                         $search=ldap_search($ldap_conn, $context, $filter, $justthese); 
    134                  
    135                 ldap_sort($ldap_conn, $search, "ou"); 
    136                 $info = ldap_get_entries($ldap_conn, $search); 
    137                         ldap_close($ldap_conn); 
    138  
    139                         // Retiro o count do array info e inverto o array para ordenação. 
    140                 for ($i=0; $i<$info["count"]; $i++) 
    141             { 
    142                                 $dn = $info[$i]["dn"]; 
    143                                  
    144                                 // Necessário, pq em uma busca com ldapsearch ou=*, traz tb o próprio ou.  
    145                                 if (strtolower($dn) == $context) 
    146                                         continue; 
    147  
    148                                 $array_dn = ldap_explode_dn ( $dn, 1 ); 
    149  
    150                 $array_dn_reverse  = array_reverse ( $array_dn, true ); 
    151  
    152                                 // Retirar o indice count do array. 
    153                                 array_pop ( $array_dn_reverse ); 
    154  
    155                                 $inverted_dn[$dn] = implode ( "#", $array_dn_reverse ); 
    156                         } 
    157  
    158                         if (is_array($inverted_dn)) 
    159                         { 
    160                                 // Ordenação 
    161                                 natcasesort($inverted_dn); 
    162                          
    163                                 // Construção do select 
    164                                 $level = 0; 
    165                                 foreach ($inverted_dn as $dn=>$invert_ufn) 
    166                                 { 
    167                         $display = ''; 
    168  
    169                     $array_dn_reverse = explode ( "#", $invert_ufn ); 
    170                         $array_dn  = array_reverse ( $array_dn_reverse, true ); 
    171  
    172                         $level = count( $array_dn ) - (int)(count(explode(",", $GLOBALS['phpgw_info']['server']['ldap_context'])) + 1); 
    173  
    174                     if ($level == 0) 
    175                                                 $display .= '+'; 
    176                         else  
    177                         { 
    178                                                 for ($i=0; $i<$level; $i++) 
    179                                                         $display .= '---'; 
    180                         } 
    181  
    182                         reset ( $array_dn ); 
    183                         $display .= ' ' . (current ( $array_dn ) ); 
    184                                  
    185                                         $dn = trim(strtolower($dn)); 
    186                                         if ( $dn == $selected ) 
    187                                                 $select = ' selected'; 
    188                                         else 
    189                                                 $select = ''; 
    190                         $options .= "<option value='$dn'$select>$display</option>"; 
    191                         } 
    192                         } 
    193  
    194                         // Cria a primeira entrada na combo  
    195                         $first_sector_ufn = ldap_dn2ufn($context); 
    196                         $first_sector_string = split(",", $first_sector_ufn); 
    197                          
    198                         if ($context == $selected) 
    199                                 $select_first_entrie = ' selected'; 
    200                         $options = "<option value='$context'$select_first_entrie>+ " . strtoupper($first_sector_string[0]) . "</option>" . $options; 
    201  
    202             return $options; 
    203                 } 
    204  
    205                 // Retorna os setores (somente OUs de primeiro nivel) com as options prontas 
    206                 function get_sectors($selected='', $referral=false ,$show_invisible_ou=false) 
    207                 { 
    208                         $dn                     = $GLOBALS['phpgw_info']['server']['ldap_root_dn']; 
    209                         $passwd         = $GLOBALS['phpgw_info']['server']['ldap_root_pw']; 
    210                         $context        = $GLOBALS['phpgw_info']['server']['ldap_context']; 
    211                         $ldap_conn      = ldap_connect($GLOBALS['phpgw_info']['server']['ldap_host']); 
    212                          
    213                         ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3); 
    214                          
    215                         if ($referral) 
    216                                 ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 1); 
    217                         else 
    218                                 ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 0); 
    219                          
    220                         ldap_bind($ldap_conn,$dn,$passwd); 
    221                          
    222                         $justthese = array("dn", "ou"); 
    223                         $filter = $show_invisible_ou ? "(ou=*)" : "(&(ou=*)(!(phpgwAccountVisible=-1)))"; 
    224                          
    225                         $search=ldap_list($ldap_conn, $context, $filter, $justthese); 
    226                  
    227                 ldap_sort($ldap_conn, $search, "ou"); 
    228                 $info = ldap_get_entries($ldap_conn, $search); 
    229                  
    230                         ldap_close($ldap_conn); 
    231                 $options = ''; 
    232                 for ($i=0; $i<$info["count"]; $i++) 
    233             { 
    234                 $dn = trim(strtolower($info[$i]['dn'])); 
    235                                 if ( $dn == $selected ) 
    236                                         $select = ' selected'; 
    237                                 else 
    238                                         $select = ''; 
    239                                 $display = strtoupper($info[$i]['ou'][0]); 
    240                                 $options .= "<option value='$dn'$select>$display</option>"; 
    241             } 
    242                  
    243                         return $options; 
    244                 } 
    245         } 
     177 
     178                reset($array_dn); 
     179                $display .= ' ' . (current($array_dn) ); 
     180 
     181                $dn = trim(strtolower($dn)); 
     182                if ($dn == $selected) 
     183                    $select = ' selected'; 
     184                else 
     185                    $select = ''; 
     186                $options .= "<option value='$dn'$select>$display</option>"; 
     187            } 
     188        } 
     189 
     190        // Cria a primeira entrada na combo 
     191        $first_sector_ufn = ldap_dn2ufn($context); 
     192        $first_sector_string = split(",", $first_sector_ufn); 
     193 
     194        if ($context == $selected) 
     195            $select_first_entrie = ' selected'; 
     196        $options = "<option value='$context'$select_first_entrie>+ " . strtoupper($first_sector_string[0]) . "</option>" . $options; 
     197 
     198        return $options; 
     199    } 
     200 
     201    // Retorna os setores (somente OUs de primeiro nivel) com as options prontas 
     202    function get_sectors($selected='', $referral=false, $show_invisible_ou=false) { 
     203        $dn = $GLOBALS['phpgw_info']['server']['ldap_root_dn']; 
     204        $passwd = $GLOBALS['phpgw_info']['server']['ldap_root_pw']; 
     205        $context = $GLOBALS['phpgw_info']['server']['ldap_context']; 
     206        $ldap_conn = ldap_connect($GLOBALS['phpgw_info']['server']['ldap_host']); 
     207 
     208        ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3); 
     209 
     210        if ($referral) 
     211            ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 1); 
     212        else 
     213            ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 0); 
     214 
     215        ldap_bind($ldap_conn, $dn, $passwd); 
     216 
     217        $justthese = array("dn", "ou"); 
     218        $filter = $show_invisible_ou ? "(objectClass=organizationalUnit)" : "(&(objectClass=organizationalUnit)(!(phpgwAccountVisible=-1)))"; 
     219 
     220        $search = ldap_list($ldap_conn, $context, $filter, $justthese); 
     221 
     222        ldap_sort($ldap_conn, $search, "ou"); 
     223        $info = ldap_get_entries($ldap_conn, $search); 
     224 
     225        ldap_close($ldap_conn); 
     226        $options = ''; 
     227 
     228        if ($info["count"] == 0) { 
     229            return $options = "<option value='$context' selected> $context </option>"; 
     230        } 
     231 
     232        for ($i = 0; $i < $info["count"]; $i++) { 
     233            $dn = trim(strtolower($info[$i]['dn'])); 
     234            if ($dn == $selected) 
     235                $select = ' selected'; 
     236            else 
     237                $select = ''; 
     238            $display = strtoupper($info[$i]['ou'][0]); 
     239            $options .= "<option value='$dn'$select>$display</option>"; 
     240        } 
     241 
     242        return $options; 
     243    } 
     244 
     245} 
     246 
    246247?> 
  • branches/2.2/reports1_0/inc/class.functions.inc.php

    r3471 r3530  
    651651                         
    652652                        $justthese = array("ou", "dn"); 
    653                         $filter = "(&(objectClass=organizationalUnit)(|(ou=*)))"; 
     653                        $filter = "(&(objectClass=organizationalUnit)(|(objectClass=organizationalUnit)))"; 
    654654                         
    655655                        foreach ($contexts as $context) 
  • branches/2.2/reports1_0/inc/class.ldap_functions.inc.php

    r3471 r3530  
    238238                                */ 
    239239                                 
    240                                 $filter = "(ou=*)"; 
     240                                $filter = "(objectClass=organizationalUnit)"; 
    241241                                $justthese = array("ou"); 
    242242                                $search = ldap_list($ldap_connection2, $context, $filter, $justthese); 
Note: See TracChangeset for help on using the changeset viewer.