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