[2] | 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'; |
---|
[32] | 47 | $sector_info['objectClass'][2] = 'phpgwAccount'; |
---|
[2] | 48 | |
---|
[32] | 49 | if ($_POST['sector_visible']) |
---|
| 50 | $sector_info['phpgwaccountvisible'] = '-1'; |
---|
| 51 | |
---|
[2] | 52 | // Chama funcao para escrever no OpenLDAP, case de erro, volta com msg de erro. |
---|
| 53 | if (!$this->so->write_ldap($dn, $sector_info)) |
---|
| 54 | { |
---|
| 55 | $_POST['error_messages'] = lang('Error in OpenLDAP recording.'); |
---|
| 56 | ExecMethod('expressoAdmin1_2.uisectors.add_sector'); |
---|
| 57 | return false; |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | //Escreve no log |
---|
| 61 | $this->functions->write_log2('Sector created', '','','',$dn); |
---|
| 62 | |
---|
| 63 | // Volta para o ListSectors |
---|
| 64 | $url = ($GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uisectors.list_sectors')); |
---|
| 65 | $GLOBALS['phpgw']->redirect($url); |
---|
| 66 | } |
---|
[32] | 67 | |
---|
[2] | 68 | function save_sector() |
---|
| 69 | { |
---|
[32] | 70 | $sector_info = $this->so->get_info($_POST['context']); |
---|
| 71 | |
---|
| 72 | if (($_POST['sector_visible'] == 'on') && ($sector_info['phpgwaccountvisible'] != '-1')) |
---|
| 73 | { |
---|
| 74 | foreach ($sector_info[0]['objectclass'] as $objectClass) |
---|
| 75 | { |
---|
| 76 | if ($objectClass == 'phpgwAccount') |
---|
| 77 | $phpgwAccount = true; |
---|
| 78 | else |
---|
| 79 | $phpgwAccount = false; |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | if (!$phpgwAccount) |
---|
| 83 | { |
---|
| 84 | $ldap_mod_add['objectClass'][] = 'phpgwAccount'; |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | $ldap_mod_add['phpgwaccountvisible'] = '-1'; |
---|
| 88 | $this->so->add_attribute($sector_info[0]['dn'], $ldap_mod_add); |
---|
| 89 | } |
---|
| 90 | else |
---|
| 91 | { |
---|
| 92 | $ldap_mod_del['phpgwaccountvisible'] = array(); |
---|
| 93 | $this->so->remove_attribute($sector_info[0]['dn'], $ldap_mod_del); |
---|
| 94 | } |
---|
| 95 | |
---|
[2] | 96 | // Volta para o ListSectors |
---|
[32] | 97 | ExecMethod('expressoAdmin1_2.uisectors.list_sectors'); |
---|
[2] | 98 | } |
---|
[32] | 99 | |
---|
[2] | 100 | function delete_sector() |
---|
| 101 | { |
---|
| 102 | // Verifica o acesso do gerente |
---|
| 103 | if (!$this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'delete_sectors')) |
---|
| 104 | { |
---|
| 105 | $return['status'] = false; |
---|
| 106 | $return['msg'] = 'Você não tem acesso para deletar setores.'; |
---|
| 107 | return $return; |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | $sector_dn = $_POST['dn']; |
---|
| 111 | $manager_context = $_POST['manager_context']; |
---|
| 112 | |
---|
| 113 | $sector_users = $this->so->get_sector_users($sector_dn); |
---|
| 114 | |
---|
| 115 | for ($i=0; $i<count($sector_users)-1; $i++) |
---|
| 116 | { |
---|
| 117 | //_debug_array($user); |
---|
| 118 | // Pega o UID e os grupos que o usuario fz parte. |
---|
| 119 | $uid = $sector_users[$i]['uid'][0]; |
---|
| 120 | $account_id = $sector_users[$i]['uidnumber'][0]; |
---|
| 121 | $dn = $sector_users[$i]['dn']; |
---|
| 122 | |
---|
| 123 | $memberships = $this->soaccounts->get_user_memberships($account_id, $manager_context); |
---|
| 124 | $memberships = explode("|", $memberships); |
---|
| 125 | |
---|
| 126 | // Deleta os memberUid dos grupos que o usuario pertence. |
---|
| 127 | foreach ($memberships as $group_dn) |
---|
| 128 | $this->soaccounts->delete_memberuid($group_dn, $uid); |
---|
| 129 | |
---|
| 130 | // Deleta o cn do usuarios no ldap. |
---|
| 131 | $this->soaccounts->delete_user_ldap($dn); |
---|
| 132 | |
---|
| 133 | // Deleta user dos grupos no BD |
---|
| 134 | $this->soaccounts->delete_group_user_pgsql($account_id); |
---|
| 135 | |
---|
| 136 | // Deleta apps do user |
---|
| 137 | $this->soaccounts->delete_apps_pgsql($account_id); |
---|
| 138 | |
---|
| 139 | // Deleta permissao para alterar senha no pgsql |
---|
| 140 | $this->soaccounts->delete_changepassword_pgsql($account_id); |
---|
| 141 | |
---|
| 142 | // Deleta conta imap-cyrus do usuarios. |
---|
| 143 | $this->soaccounts->delete_account_imap($uid); |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | |
---|
| 147 | $sector_groups = $this->so->get_sector_groups($sector_dn); |
---|
| 148 | for ($i=0; $i<count($sector_groups)-1; $i++) |
---|
| 149 | { |
---|
| 150 | $dn = $sector_groups[$i]['dn']; |
---|
| 151 | $gidnumber = $sector_groups[$i]['gidnumber'][0]; |
---|
| 152 | |
---|
| 153 | //Delete cn of the group from ldap. |
---|
| 154 | if (!$this->sogroups->delete_group_ldap($dn)) |
---|
| 155 | { |
---|
| 156 | $_POST['error_messages'] = lang('Error delete Group in OpenLDAP.'); |
---|
| 157 | ExecMethod('expressoAdmin1_2.uisectors.list_sectors'); |
---|
| 158 | return false; |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | //Delete all users of the group from BD. |
---|
| 162 | $this->sogroups->delete_all_users_pgsql($gidnumber); |
---|
| 163 | |
---|
| 164 | //Delete all apps of the group from BD. |
---|
| 165 | $this->sogroups->delete_all_apps_pgsql($gidnumber); |
---|
| 166 | } |
---|
| 167 | |
---|
| 168 | $connection = $GLOBALS['phpgw']->common->ldapConnect(); |
---|
| 169 | $this->so->delete_sector_ldap_recursively($connection, $sector_dn); |
---|
| 170 | ldap_close($connection); |
---|
| 171 | |
---|
| 172 | // Volta para o ListGroups |
---|
| 173 | $url = ($GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uisectors.list_sectors')); |
---|
| 174 | $GLOBALS['phpgw']->redirect($url); |
---|
| 175 | } |
---|
| 176 | } |
---|
| 177 | ?> |
---|