source: trunk/expressoAdmin1_2/inc/class.sosectors.inc.php @ 1850

Revision 1850, 4.8 KB checked in by alexandrecorreia, 14 years ago (diff)

Ticket #828 - Corrigida opcao de controle de quotas por OUs no Ldap.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
RevLine 
[2]1<?php
2        /**********************************************************************************\
3        * Expresso Administração                                                                                                *
4        * by Joao Alfredo Knopik Junior (joao.alfredo@gmail.com, jakjr@celepar.pr.gov.br)   *
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
12        class sosectors
13        {
14                var $functions;
[396]15                var $ldap_connection;
[471]16                var $db_functions;
[2]17               
18                function sosectors()
19                {
20                        $this->functions = createobject('expressoAdmin1_2.functions');
[471]21                        $this->db_functions = CreateObject('expressoAdmin1_2.db_functions');
[396]22                       
23                        if ( (!empty($GLOBALS['phpgw_info']['server']['ldap_master_host'])) &&
24                                 (!empty($GLOBALS['phpgw_info']['server']['ldap_master_root_dn'])) &&
25                                 (!empty($GLOBALS['phpgw_info']['server']['ldap_master_root_pw'])) )
26                        {
27                                $this->ldap_connection = $GLOBALS['phpgw']->common->ldapConnect($GLOBALS['phpgw_info']['server']['ldap_master_host'],
28                                                                                                   $GLOBALS['phpgw_info']['server']['ldap_master_root_dn'],
29                                                                                                   $GLOBALS['phpgw_info']['server']['ldap_master_root_pw']);
30                        }
31                        else
32                        {
33                                $this->ldap_connection = $GLOBALS['phpgw']->common->ldapConnect();
34                        }
[2]35                }
36               
37                function exist_sector_name($sector_name, $context)
38                {
[396]39                        $search = ldap_list($this->ldap_connection, $context, "ou=" . $sector_name);
40                        $result = ldap_get_entries($this->ldap_connection, $search);
[2]41                       
42                        if ($result['count'] == 0)
43                                return false;
44                        else
45                                return true;
46                }
47               
48                function write_ldap($dn, $info)
49                {
[1850]50                        if ( @ldap_add($this->ldap_connection, $dn, $info) )
[2]51                        {
[414]52                                $this->db_functions->write_log("write on ldap", "$dn");
[396]53                                ldap_close($this->ldap_connection);
[2]54                                return true;
55                        }
56                        else
57                        {
[1850]58                                $this->db_functions->write_log("Error write on ldap", "$dn");
[396]59                                ldap_close($this->ldap_connection);
[2]60                                return false;
61                        }
62                }
63               
64                function get_sector_users($context)
65                {
66                        $justthese = array("cn", "uidNumber", "uid");
67                        $filter="(&(phpgwAccountType=u)(uid=*))";
[396]68                        $search=ldap_search($this->ldap_connection, $context, $filter, $justthese);
69                        $result = ldap_get_entries($this->ldap_connection, $search);
[2]70                        return $result;
71                }
72               
73                function get_sector_groups($context)
74                {
75                        $justthese = array("cn", "gidnumber");
76                        $filter="(&(phpgwAccountType=g)(cn=*))";
[396]77                        $search=ldap_search($this->ldap_connection, $context, $filter, $justthese);
78                        $result = ldap_get_entries($this->ldap_connection, $search);
[2]79                        return $result;
80                }
81
82                function get_sector_subsectors($context)
83                {
84                        $justthese = array("ou");
85                        $filter="(objectClass=organizationalUnit)";
[396]86                        $search=ldap_search($this->ldap_connection, $context, $filter, $justthese);
87                        $result = ldap_get_entries($this->ldap_connection, $search);
[2]88                        return $result;
89                }
90               
91                function delete_sector_ldap_recursively($connection, $dn)
92                {
93                        //searching for sub entries
[1394]94                        $search=ldap_list($connection,$dn,"ObjectClass=*",array(""));
[2]95                        $info = ldap_get_entries($connection, $search);
96                       
97                        for($i=0;$i<$info['count'];$i++)
98                        {
99                                //deleting recursively sub entries
100                                $result=$this->delete_sector_ldap_recursively($connection,$info[$i]['dn']);
101                                        if(!$result)
102                                        {
103                                                //return result code, if delete fails
104                                                return($result);
105                                        }
106                        }
107                        return(ldap_delete($connection,$dn));
108                }
[32]109               
110                function get_info($context)
111                {
112                        $filter="(objectClass=organizationalUnit)";
[396]113                        $search=ldap_search($this->ldap_connection, $context, $filter);
114                        $result = ldap_get_entries($this->ldap_connection, $search);
[32]115                        return $result;
116                }
117               
118                function add_attribute($dn, $info)
119                {
[396]120                        if (ldap_mod_add($this->ldap_connection, $dn, $info))
[32]121                        {
[396]122                                ldap_close($this->ldap_connection);
[32]123                                return true;
124                        }
125                        else
126                        {
[493]127                                echo lang('Error written in LDAP, function add_attribute'). ldap_error($this->ldap_connection);
[396]128                                ldap_close($this->ldap_connection);
[32]129                                return false;
130                        }
131                }
[1516]132
133                function replace_attribute($dn, $info)
134                {
135                        $connection = $GLOBALS['phpgw']->common->ldapConnect();
136                       
137                        if (ldap_mod_replace($connection, $dn, $info))
138                        {
139                                ldap_close($connection);
140                                return true;
141                        }
142                        else
143                        {
144                                echo 'Erro na escrita no LDAP, funcao replace_attribute: ' . ldap_error($connection);
145                                ldap_close($connection);
146                                return false;
147                        }
148                }               
[32]149               
150                function remove_attribute($dn, $info)
151                {
[396]152                        if (ldap_mod_del($this->ldap_connection, $dn, $info))
[32]153                        {
[396]154                                ldap_close($this->ldap_connection);
[32]155                                return true;
156                        }
157                        else
158                        {
[493]159                                echo lang('Error written in LDAP, function remove_attribute'). ldap_error($this->ldap_connection);
[396]160                                ldap_close($this->ldap_connection);
[32]161                                return false;
162                        }
163                }
[2]164        }
[1394]165?>
Note: See TracBrowser for help on using the repository browser.