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