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

Revision 396, 4.4 KB checked in by niltonneto, 16 years ago (diff)

Modificações referente a opção de configurar um ldap_master
no setup do Expresso, usado somente para escrita.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
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;
15                var $ldap_connection;
16               
17                function sosectors()
18                {
19                        $this->functions = createobject('expressoAdmin1_2.functions');
20                       
21                        if ( (!empty($GLOBALS['phpgw_info']['server']['ldap_master_host'])) &&
22                                 (!empty($GLOBALS['phpgw_info']['server']['ldap_master_root_dn'])) &&
23                                 (!empty($GLOBALS['phpgw_info']['server']['ldap_master_root_pw'])) )
24                        {
25                                $this->ldap_connection = $GLOBALS['phpgw']->common->ldapConnect($GLOBALS['phpgw_info']['server']['ldap_master_host'],
26                                                                                                   $GLOBALS['phpgw_info']['server']['ldap_master_root_dn'],
27                                                                                                   $GLOBALS['phpgw_info']['server']['ldap_master_root_pw']);
28                        }
29                        else
30                        {
31                                $this->ldap_connection = $GLOBALS['phpgw']->common->ldapConnect();
32                        }
33                }
34               
35                function exist_sector_name($sector_name, $context)
36                {
37                        $search = ldap_list($this->ldap_connection, $context, "ou=" . $sector_name);
38                        $result = ldap_get_entries($this->ldap_connection, $search);
39                       
40                        if ($result['count'] == 0)
41                                return false;
42                        else
43                                return true;
44                }
45               
46                function write_ldap($dn, $info)
47                {
48                        if (ldap_add($this->ldap_connection, $dn, $info))
49                        {
50                                //Escreve no log
51                                $this->functions->write_log2($GLOBALS['phpgw']->accounts->data['account_lid'], 'write in ldap', $dn,'','','');
52                                ldap_close($this->ldap_connection);
53                                return true;
54                        }
55                        else
56                        {
57                                echo 'Erro na escrita no LDAP, funcao write_ldap';
58                                ldap_close($this->ldap_connection);
59                                return false;
60                        }
61                }
62               
63                function get_sector_users($context)
64                {
65                        $justthese = array("cn", "uidNumber", "uid");
66                        $filter="(&(phpgwAccountType=u)(uid=*))";
67                        $search=ldap_search($this->ldap_connection, $context, $filter, $justthese);
68                        $result = ldap_get_entries($this->ldap_connection, $search);
69                        return $result;
70                }
71               
72                function get_sector_groups($context)
73                {
74                        $justthese = array("cn", "gidnumber");
75                        $filter="(&(phpgwAccountType=g)(cn=*))";
76                        $search=ldap_search($this->ldap_connection, $context, $filter, $justthese);
77                        $result = ldap_get_entries($this->ldap_connection, $search);
78                        return $result;
79                }
80
81                function get_sector_subsectors($context)
82                {
83                        $justthese = array("ou");
84                        $filter="(objectClass=organizationalUnit)";
85                        $search=ldap_search($this->ldap_connection, $context, $filter, $justthese);
86                        $result = ldap_get_entries($this->ldap_connection, $search);
87                        return $result;
88                }
89               
90                function delete_sector_ldap_recursively($connection, $dn)
91                {
92                        //searching for sub entries
93                        $search=ldap_list($connection,$dn,"ObjectClass=organizationalUnit",array(""));
94                        $info = ldap_get_entries($connection, $search);
95                       
96                        for($i=0;$i<$info['count'];$i++)
97                        {
98                                //deleting recursively sub entries
99                                $result=$this->delete_sector_ldap_recursively($connection,$info[$i]['dn']);
100                                        if(!$result)
101                                        {
102                                                //return result code, if delete fails
103                                                return($result);
104                                        }
105                        }
106                        return(ldap_delete($connection,$dn));
107                }
108               
109                function get_info($context)
110                {
111                        $filter="(objectClass=organizationalUnit)";
112                        $search=ldap_search($this->ldap_connection, $context, $filter);
113                        $result = ldap_get_entries($this->ldap_connection, $search);
114                        return $result;
115                }
116               
117                function add_attribute($dn, $info)
118                {
119                        if (ldap_mod_add($this->ldap_connection, $dn, $info))
120                        {
121                                ldap_close($this->ldap_connection);
122                                return true;
123                        }
124                        else
125                        {
126                                echo 'Erro na escrita no LDAP, funcao add_attribute: ' . ldap_error($this->ldap_connection);
127                                ldap_close($this->ldap_connection);
128                                return false;
129                        }
130                }
131               
132                function remove_attribute($dn, $info)
133                {
134                        if (ldap_mod_del($this->ldap_connection, $dn, $info))
135                        {
136                                ldap_close($this->ldap_connection);
137                                return true;
138                        }
139                        else
140                        {
141                                echo 'Erro na escrita no LDAP, funcao remove_attribute: ' . ldap_error($this->ldap_connection);
142                                ldap_close($this->ldap_connection);
143                                return false;
144                        }
145                }
146        }
147?>
Note: See TracBrowser for help on using the repository browser.