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