source: trunk/expressoAdmin1_2/inc/class.bosectors.inc.php @ 1120

Revision 1120, 6.4 KB checked in by rodsouza, 15 years ago (diff)

Ticket #575 - Alterado a insercao/remocao do atributo objectClass(phpgwAccount) presente na organizacao

  • 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 bosectors
13        {
14                var $public_functions = array(
15                        'create_sector' => True,
16                        'save_sector'   => True,
17                        'delete_sector' => True
18                );
19       
20                var $so;
21                var $functions;
22                var $db_functions;
23       
24                function bosectors()
25                {
26                        $this->so = createobject('expressoAdmin1_2.sosectors');
27                        $this->functions = $this->so->functions;
28                        $this->db_functions = $this->so->db_functions;
29                        $this->soaccounts = createobject('expressoAdmin1_2.soaccounts');
30                        $this->sogroups = createobject('expressoAdmin1_2.sogroups');
31                }
32
33                function create_sector()
34                {
35                        // Verifica o acesso do gerente
36                        if (!$this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'create_sectors'))
37                        {
38                                $return['status'] = false;
39                                $return['msg'] = lang('you do not have access to create sectors') . '.';
40                                return $return;
41                        }
42
43                        // Cria array para incluir no LDAP
44                        $dn = 'ou=' . $_POST['sector'] . ',' . $_POST['context'];                       
45                        $sector_info = array();
46                        $sector_info['ou']                              = $_POST['sector']; 
47                        $sector_info['objectClass'][0]  = 'top';
48                        $sector_info['objectClass'][1]  = 'organizationalUnit';
49                       
50                        $systemName = $GLOBALS['phpgw_info']['server']['system_name'];
51                        if ($systemName != '')
52                                $sector_info['phpgwSystem'] = strtolower($systemName);
53                       
54                        if ($_POST['sector_visible'])
55                        {
56                                $sector_info['objectClass'][2]  = 'phpgwAccount';
57                                $sector_info['phpgwaccountvisible'] = '-1';
58                        }
59                       
60                        // Chama funcao para escrever no OpenLDAP, case de erro, volta com msg de erro.
61                        if (!$this->so->write_ldap($dn, $sector_info))
62                        {
63                                $_POST['error_messages'] = lang('Error in OpenLDAP recording.');
64                                ExecMethod('expressoAdmin1_2.uisectors.add_sector');
65                                return false;
66                        }
67                       
68                        //Escreve no log
69                        $this->db_functions->write_log("created sector", "$dn");
70                       
71                        // Volta para o ListSectors
72                        $url = ($GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uisectors.list_sectors'));
73                        $GLOBALS['phpgw']->redirect($url);
74                }
75
76                function save_sector()
77                {
78                        $sector_info = $this->so->get_info($_POST['context']);
79                       
80                        if (($_POST['sector_visible'] == 'on') && ($sector_info['phpgwaccountvisible'] != '-1'))
81                        {
82                                foreach ($sector_info[0]['objectclass'] as $objectClass)
83                                {
84                                        if ($objectClass == 'phpgwAccount')
85                                                $phpgwAccount = true;
86                                        else
87                                                $phpgwAccount = false;
88                                }
89                               
90                                if (!$phpgwAccount)
91                                {
92                                        $ldap_mod_add['objectClass'][] = 'phpgwAccount';
93                                }
94                               
95                                $ldap_mod_add['phpgwaccountvisible'] = '-1';
96                                $this->so->add_attribute($sector_info[0]['dn'], $ldap_mod_add);
97                        }
98                        else
99                        {
100                                $ldap_mod_del['objectClass'] = 'phpgwAccount';
101                                $ldap_mod_del['phpgwaccountvisible'] = array();
102                                $this->so->remove_attribute($sector_info[0]['dn'], $ldap_mod_del);
103                        }
104                               
105                        // Volta para o ListSectors
106                        ExecMethod('expressoAdmin1_2.uisectors.list_sectors');
107                }
108
109                function delete_sector()
110                {
111                        // Verifica o acesso do gerente
112                        if (!$this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'delete_sectors'))
113                        {
114                                $return['status'] = false;
115                                $return['msg'] = lang('you do not have access to delete sectors') . '.';
116                                return $return;
117                        }
118
119                        $sector_dn = $_POST['dn'];
120                        $manager_context = $_POST['manager_context'];
121
122                        $sector_users = $this->so->get_sector_users($sector_dn);
123                       
124                        for ($i=0; $i<count($sector_users)-1; $i++)
125                        {
126                                //_debug_array($user);
127                                // Pega o UID e os grupos que o usuario fz parte.
128                                $uid = $sector_users[$i]['uid'][0];
129                                $account_id = $sector_users[$i]['uidnumber'][0];
130                                $dn = $sector_users[$i]['dn'];
131
132                                $memberships = $this->soaccounts->get_user_memberships($account_id, $manager_context);
133                                $memberships = explode("|", $memberships);
134                               
135                                // Deleta os memberUid dos grupos que o usuario pertence.
136                                foreach ($memberships as $group_dn)
137                                        $this->soaccounts->delete_memberuid($group_dn, $uid);
138                       
139                                // Deleta o cn do usuarios no ldap.
140                                $this->soaccounts->delete_user_ldap($dn);
141                       
142                                // Deleta user dos grupos no BD
143                                $this->soaccounts->delete_group_user_pgsql($account_id);
144                       
145                                // Deleta apps do user
146                                $this->soaccounts->delete_apps_pgsql($account_id);
147               
148                                // Deleta permissao para alterar senha no pgsql
149                                $this->soaccounts->delete_changepassword_pgsql($account_id);
150
151                                // Deleta conta imap-cyrus do usuarios.
152                                $this->soaccounts->delete_account_imap($uid);
153                        }
154
155
156                        $sector_groups = $this->so->get_sector_groups($sector_dn);
157                        for ($i=0; $i<count($sector_groups)-1; $i++)
158                        {
159                                $dn = $sector_groups[$i]['dn'];
160                                $gidnumber = $sector_groups[$i]['gidnumber'][0];
161
162                                //Delete cn of the group from ldap.
163                                if (!$this->sogroups->delete_group_ldap($dn))
164                                {
165                                        $_POST['error_messages'] = lang('Error delete Group in OpenLDAP.');
166                                        ExecMethod('expressoAdmin1_2.uisectors.list_sectors');
167                                        return false;
168                                }
169                       
170                                //Delete all users of the group from BD.
171                                $this->sogroups->delete_all_users_pgsql($gidnumber);
172                       
173                                //Delete all apps of the group from BD.
174                                $this->sogroups->delete_all_apps_pgsql($gidnumber);
175                        }
176                       
177                        if ( (!empty($GLOBALS['phpgw_info']['server']['ldap_master_host'])) &&
178                                 (!empty($GLOBALS['phpgw_info']['server']['ldap_master_root_dn'])) &&
179                                 (!empty($GLOBALS['phpgw_info']['server']['ldap_master_root_pw'])) )
180                        {
181                                $connection = $GLOBALS['phpgw']->common->ldapConnect($GLOBALS['phpgw_info']['server']['ldap_master_host'],
182                                                                                                   $GLOBALS['phpgw_info']['server']['ldap_master_root_dn'],
183                                                                                                   $GLOBALS['phpgw_info']['server']['ldap_master_root_pw']);
184                        }
185                        else
186                        {
187                                $connection = $GLOBALS['phpgw']->common->ldapConnect();
188                        }
189                       
190                        $this->so->delete_sector_ldap_recursively($connection, $sector_dn);
191                        ldap_close($connection);
192                       
193                        // Volta para o ListGroups
194                        $url = ($GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uisectors.list_sectors'));
195                        $GLOBALS['phpgw']->redirect($url);
196                }
197        }
198?>
Note: See TracBrowser for help on using the repository browser.