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

Revision 7673, 7.1 KB checked in by douglasz, 11 years ago (diff)

Ticket #3236 - Correcoes para Performance: Function Within Loop Declaration.

  • 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->group = createobject('expressoAdmin1_2.group');
30                        $this->user = createobject('expressoAdmin1_2.user');
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'][]   = 'top';
48                        $sector_info['objectClass'][]   = 'organizationalUnit';
49                        $sector_info['objectClass'][]   = 'phpgwQuotaControlled';
50                        /*Insere as informações sobre quota total por usuários e por gigabytes de espaço em disco 
51              Se não vierem os dados, ele coloca 0 (Caso não exista controle de cota).
52             */
53                $sector_info['diskQuota'] = isset($_POST['disk_quota']) ? (int)$_POST['disk_quota'] : 0;
54                $sector_info['usersQuota'] = isset($_POST['users_quota']) ? (int)$_POST['users_quota'] : 0;
55
56                if( isset($_POST['associated_domain']) )
57                {
58                    if ( $_POST['associated_domain'] != "") {
59                        $sector_info['objectClass'][]  = 'domainRelatedObject';
60                        $sector_info['associatedDomain'] = trim($_POST['associated_domain']);
61                    }
62                }
63
64                        $systemName = $GLOBALS['phpgw_info']['server']['system_name'];
65                        if ($systemName != '')
66                                $sector_info['phpgwSystem'] = strtolower($systemName);
67                       
68                        if ($_POST['sector_visible'])
69                        {
70                                $sector_info['objectClass'][]   = 'phpgwAccount';
71                                $sector_info['phpgwaccountvisible'] = '-1';
72                        }
73                       
74                        // Chama funcao para escrever no OpenLDAP, case de erro, volta com msg de erro.
75                        if (!$this->so->write_ldap($dn, $sector_info))
76                        {
77                                $_POST['error_messages'] = lang('Error in OpenLDAP recording.');
78                                ExecMethod('expressoAdmin1_2.uisectors.add_sector');
79                                return false;
80                        }
81                       
82                        //Escreve no log
83                        $this->db_functions->write_log("created sector", "$dn");
84                       
85                        // Volta para o ListSectors
86                        $url = ($GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uisectors.list_sectors'));
87                        $GLOBALS['phpgw']->redirect($url);
88                }
89
90        function save_sector()
91                {
92                $context = utf8_encode($_POST['context']);
93
94                        $sector_info = $this->so->get_info($context);
95                       
96                        if (($_POST['sector_visible'] == 'on') && ($sector_info['phpgwaccountvisible'] != '-1'))
97                        {
98                                foreach ($sector_info[0]['objectclass'] as $objectClass)
99                                {
100                                        if ($objectClass == 'phpgwAccount')
101                                                $phpgwAccount = true;
102                                        else
103                                                $phpgwAccount = false;
104                                }
105                               
106                                if (!$phpgwAccount)
107                                {
108                                        $ldap_mod_add['objectClass'][] = 'phpgwAccount';
109                                }
110                               
111                                $ldap_mod_add['phpgwaccountvisible'] = '-1';
112                                $this->so->add_attribute($sector_info[0]['dn'], $ldap_mod_add);
113                        }
114                        elseif($sector_info['phpgwaccountvisible'] == '-1')
115                        {
116                                $ldap_mod_del['objectClass'] = 'phpgwAccount';
117                                $ldap_mod_del['phpgwaccountvisible'] = array();
118                                $this->so->remove_attribute($sector_info[0]['dn'], $ldap_mod_del);
119                        }
120
121                        if(!in_array('phpgwQuotaControlled',$sector_info[0]['objectclass'] ))
122                        {
123                                $ldap_mod_add = array();
124                                $ldap_mod_add['objectClass'][] = 'phpgwQuotaControlled';
125                                $ldap_mod_add['diskQuota'] = isset($_POST['disk_quota']) ? (int)$_POST['disk_quota'] : 0;
126                                $ldap_mod_add['usersQuota'] = isset($_POST['users_quota']) ? (int)$_POST['users_quota'] : 0;
127
128                                $this->so->add_attribute($sector_info[0]['dn'], $ldap_mod_add);
129                        }
130                        else
131                        {
132                                $ldap_mod_replace = array();
133                                if(isset($_POST['disk_quota']))
134                                        $ldap_mod_replace['diskQuota'] = (int)$_POST['disk_quota'];
135
136                                if(isset($_POST['users_quota']))
137                                        $ldap_mod_replace['usersQuota'] = (int)$_POST['users_quota'];
138
139                                if(count($ldap_mod_replace) > 0)
140                                        $this->so->replace_attribute($sector_info[0]['dn'], $ldap_mod_replace);
141                        }
142                        // Volta para o ListSectors
143                        ExecMethod('expressoAdmin1_2.uisectors.list_sectors');
144                }
145
146                function delete_sector()
147                {
148
149                        // Verifica o acesso do gerente
150                        if (!$this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'delete_sectors'))
151                        {
152                                $return['status'] = false;
153                                $return['msg'] = lang('you do not have access to delete sectors') . '.';
154                                return $return;
155                        }
156
157                        $sector_dn = $_POST['dn'];
158                        $manager_context = $_POST['manager_context'];
159
160                        $sector_dn = $sector_dn;
161
162                        $sector_users = $this->so->get_sector_users($sector_dn);
163
164            $sector_users_count = count($sector_users)-1;
165                        for ($i=0; $i<$sector_users_count; ++$i)
166                        {
167                                //_debug_array($user);
168                                // Pega o UID e os grupos que o usuario fz parte.
169                                $uid = $sector_users[$i]['uid'][0];
170                                $account_id = $sector_users[$i]['uidnumber'][0];
171                                $dn = $sector_users[$i]['dn'];
172                                $this->user->delete(Array('uid' =>  $uid , 'uidnumber' => $account_id));
173                        }
174
175
176                        $sector_groups = $this->so->get_sector_groups($sector_dn);
177            $sector_groups_count = count($sector_groups)-1;
178                        for ($i=0; $i<$sector_groups_count; ++$i)
179                        {
180                                $dn = $sector_groups[$i]['dn'];
181                                $gidnumber = $sector_groups[$i]['gidnumber'][0];
182
183                                //Delete group
184                                $this->group->delete(Array('gidnumber' => $gidnumber, 'cn' => $dn));
185                        }
186                       
187                        if ( (!empty($GLOBALS['phpgw_info']['server']['ldap_master_host'])) &&
188                                 (!empty($GLOBALS['phpgw_info']['server']['ldap_master_root_dn'])) &&
189                                 (!empty($GLOBALS['phpgw_info']['server']['ldap_master_root_pw'])) )
190                        {
191                                $connection = $GLOBALS['phpgw']->common->ldapConnect($GLOBALS['phpgw_info']['server']['ldap_master_host'],
192                                                                                                   $GLOBALS['phpgw_info']['server']['ldap_master_root_dn'],
193                                                                                                   $GLOBALS['phpgw_info']['server']['ldap_master_root_pw']);
194                        }
195                        else
196                        {
197                                $connection = $GLOBALS['phpgw']->common->ldapConnect();
198                        }
199                       
200                        $this->so->delete_sector_ldap_recursively($connection, $sector_dn);
201                        ldap_close($connection);
202                       
203                        // Volta para o ListGroups
204                        $url = ($GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uisectors.list_sectors'));
205                        $GLOBALS['phpgw']->redirect($url);
206                }
207        }
208?>
Note: See TracBrowser for help on using the repository browser.