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