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 | |
---|
23 | function bosectors() |
---|
24 | { |
---|
25 | $this->so = createobject('expressoAdmin1_2.sosectors'); |
---|
26 | $this->functions = $this->so->functions; |
---|
27 | $this->soaccounts = createobject('expressoAdmin1_2.soaccounts'); |
---|
28 | $this->sogroups = createobject('expressoAdmin1_2.sogroups'); |
---|
29 | } |
---|
30 | |
---|
31 | function create_sector() |
---|
32 | { |
---|
33 | // Verifica o acesso do gerente |
---|
34 | if (!$this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'create_sectors')) |
---|
35 | { |
---|
36 | $return['status'] = false; |
---|
37 | $return['msg'] = 'Você não tem acesso para criar setores.'; |
---|
38 | return $return; |
---|
39 | } |
---|
40 | |
---|
41 | // Cria array para incluir no LDAP |
---|
42 | $dn = 'ou=' . $_POST['sector'] . ',' . $_POST['context']; |
---|
43 | $sector_info = array(); |
---|
44 | $sector_info['ou'] = $_POST['sector']; |
---|
45 | $sector_info['objectClass'][0] = 'top'; |
---|
46 | $sector_info['objectClass'][1] = 'organizationalUnit'; |
---|
47 | |
---|
48 | // Chama funcao para escrever no OpenLDAP, case de erro, volta com msg de erro. |
---|
49 | if (!$this->so->write_ldap($dn, $sector_info)) |
---|
50 | { |
---|
51 | $_POST['error_messages'] = lang('Error in OpenLDAP recording.'); |
---|
52 | ExecMethod('expressoAdmin1_2.uisectors.add_sector'); |
---|
53 | return false; |
---|
54 | } |
---|
55 | |
---|
56 | //Escreve no log |
---|
57 | $this->functions->write_log2('Sector created', '','','',$dn); |
---|
58 | |
---|
59 | // Volta para o ListSectors |
---|
60 | $url = ($GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uisectors.list_sectors')); |
---|
61 | $GLOBALS['phpgw']->redirect($url); |
---|
62 | } |
---|
63 | |
---|
64 | function save_sector() |
---|
65 | { |
---|
66 | // Volta para o ListSectors |
---|
67 | $url = ($GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uisectors.list_sectors')); |
---|
68 | $GLOBALS['phpgw']->redirect($url); |
---|
69 | } |
---|
70 | |
---|
71 | function delete_sector() |
---|
72 | { |
---|
73 | // Verifica o acesso do gerente |
---|
74 | if (!$this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'delete_sectors')) |
---|
75 | { |
---|
76 | $return['status'] = false; |
---|
77 | $return['msg'] = 'Você não tem acesso para deletar setores.'; |
---|
78 | return $return; |
---|
79 | } |
---|
80 | |
---|
81 | $sector_dn = $_POST['dn']; |
---|
82 | $manager_context = $_POST['manager_context']; |
---|
83 | |
---|
84 | $sector_users = $this->so->get_sector_users($sector_dn); |
---|
85 | |
---|
86 | for ($i=0; $i<count($sector_users)-1; $i++) |
---|
87 | { |
---|
88 | //_debug_array($user); |
---|
89 | // Pega o UID e os grupos que o usuario fz parte. |
---|
90 | $uid = $sector_users[$i]['uid'][0]; |
---|
91 | $account_id = $sector_users[$i]['uidnumber'][0]; |
---|
92 | $dn = $sector_users[$i]['dn']; |
---|
93 | |
---|
94 | $memberships = $this->soaccounts->get_user_memberships($account_id, $manager_context); |
---|
95 | $memberships = explode("|", $memberships); |
---|
96 | |
---|
97 | // Deleta os memberUid dos grupos que o usuario pertence. |
---|
98 | foreach ($memberships as $group_dn) |
---|
99 | $this->soaccounts->delete_memberuid($group_dn, $uid); |
---|
100 | |
---|
101 | // Deleta o cn do usuarios no ldap. |
---|
102 | $this->soaccounts->delete_user_ldap($dn); |
---|
103 | |
---|
104 | // Deleta user dos grupos no BD |
---|
105 | $this->soaccounts->delete_group_user_pgsql($account_id); |
---|
106 | |
---|
107 | // Deleta apps do user |
---|
108 | $this->soaccounts->delete_apps_pgsql($account_id); |
---|
109 | |
---|
110 | // Deleta permissao para alterar senha no pgsql |
---|
111 | $this->soaccounts->delete_changepassword_pgsql($account_id); |
---|
112 | |
---|
113 | // Deleta conta imap-cyrus do usuarios. |
---|
114 | $this->soaccounts->delete_account_imap($uid); |
---|
115 | } |
---|
116 | |
---|
117 | |
---|
118 | $sector_groups = $this->so->get_sector_groups($sector_dn); |
---|
119 | for ($i=0; $i<count($sector_groups)-1; $i++) |
---|
120 | { |
---|
121 | $dn = $sector_groups[$i]['dn']; |
---|
122 | $gidnumber = $sector_groups[$i]['gidnumber'][0]; |
---|
123 | |
---|
124 | //Delete cn of the group from ldap. |
---|
125 | if (!$this->sogroups->delete_group_ldap($dn)) |
---|
126 | { |
---|
127 | $_POST['error_messages'] = lang('Error delete Group in OpenLDAP.'); |
---|
128 | ExecMethod('expressoAdmin1_2.uisectors.list_sectors'); |
---|
129 | return false; |
---|
130 | } |
---|
131 | |
---|
132 | //Delete all users of the group from BD. |
---|
133 | $this->sogroups->delete_all_users_pgsql($gidnumber); |
---|
134 | |
---|
135 | //Delete all apps of the group from BD. |
---|
136 | $this->sogroups->delete_all_apps_pgsql($gidnumber); |
---|
137 | } |
---|
138 | |
---|
139 | $connection = $GLOBALS['phpgw']->common->ldapConnect(); |
---|
140 | $this->so->delete_sector_ldap_recursively($connection, $sector_dn); |
---|
141 | ldap_close($connection); |
---|
142 | |
---|
143 | // Volta para o ListGroups |
---|
144 | $url = ($GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uisectors.list_sectors')); |
---|
145 | $GLOBALS['phpgw']->redirect($url); |
---|
146 | } |
---|
147 | } |
---|
148 | ?> |
---|