[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 uisectors |
---|
| 13 | { |
---|
| 14 | var $public_functions = array |
---|
| 15 | ( |
---|
| 16 | 'list_sectors' => True, |
---|
| 17 | 'add_sector' => True, |
---|
| 18 | 'validate_data_sectors_add' => True, |
---|
[32] | 19 | 'edit_sector' => True, |
---|
| 20 | 'validate_data_sectors_edit' => True, |
---|
[2] | 21 | 'delete_sector' => True, |
---|
[5133] | 22 | 'css' => True |
---|
[2] | 23 | ); |
---|
| 24 | |
---|
| 25 | var $bo; |
---|
| 26 | var $nextmatchs; |
---|
| 27 | var $functions; |
---|
| 28 | |
---|
| 29 | function uisectors() |
---|
| 30 | { |
---|
| 31 | $this->bo = CreateObject('expressoAdmin1_2.bosectors'); |
---|
| 32 | $this->so = $this->bo->so; |
---|
| 33 | $this->functions = $this->bo->functions; |
---|
| 34 | $this->nextmatchs = createobject('phpgwapi.nextmatchs'); |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | function list_sectors() |
---|
| 38 | { |
---|
[64] | 39 | $manager_lid = $GLOBALS['phpgw']->accounts->data['account_lid']; |
---|
| 40 | $acl = $this->functions->read_acl($manager_lid); |
---|
| 41 | $contexts = $acl['contexts']; |
---|
| 42 | foreach ($acl['contexts_display'] as $index=>$tmp_context) |
---|
| 43 | { |
---|
| 44 | $context_display .= '<br>'.$tmp_context; |
---|
| 45 | } |
---|
| 46 | |
---|
[2] | 47 | // Verifica se o administrador tem acesso. |
---|
[5133] | 48 | if (!$this->functions->check_acl($manager_lid,'list_sectors')) |
---|
| 49 | { |
---|
| 50 | $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php')); |
---|
| 51 | } |
---|
[2] | 52 | |
---|
| 53 | unset($GLOBALS['phpgw_info']['flags']['noheader']); |
---|
| 54 | unset($GLOBALS['phpgw_info']['flags']['nonavbar']); |
---|
| 55 | |
---|
| 56 | $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Sectors'); |
---|
| 57 | $GLOBALS['phpgw']->common->phpgw_header(); |
---|
| 58 | |
---|
| 59 | $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL); |
---|
| 60 | $p->set_file(array('sectors' => 'sectors.tpl')); |
---|
| 61 | $p->set_block('sectors','list','list'); |
---|
| 62 | $p->set_block('sectors','row','row'); |
---|
| 63 | $p->set_block('sectors','row_empty','row_empty'); |
---|
| 64 | |
---|
[5133] | 65 | $sectors_info = $this->functions->get_sectors_list($contexts); |
---|
[2] | 66 | |
---|
| 67 | $var = Array( |
---|
| 68 | 'th_bg' => $GLOBALS['phpgw_info']['theme']['th_bg'], |
---|
| 69 | 'back_url' => $GLOBALS['phpgw']->link('/expressoAdmin1_2/index.php'), |
---|
[548] | 70 | 'context_display' => $context_display, |
---|
[5133] | 71 | 'lang_inactives' => lang('list inactives') |
---|
[2] | 72 | ); |
---|
[5133] | 73 | |
---|
[2] | 74 | $p->set_var($var); |
---|
[414] | 75 | $p->set_var($this->functions->make_dinamic_lang($p, 'list')); |
---|
[2] | 76 | |
---|
| 77 | if (!count($sectors_info)) |
---|
| 78 | { |
---|
| 79 | $p->set_var('message',lang('No matches found')); |
---|
| 80 | $p->parse('rows','row_empty',True); |
---|
| 81 | } |
---|
| 82 | else |
---|
| 83 | { |
---|
[64] | 84 | if ($this->functions->check_acl($manager_lid,'edit_sectors')) |
---|
[2] | 85 | { |
---|
| 86 | $can_edit = True; |
---|
| 87 | } |
---|
| 88 | |
---|
[64] | 89 | if ($this->functions->check_acl($manager_lid,'delete_sectors')) |
---|
[2] | 90 | { |
---|
| 91 | $can_delete = True; |
---|
| 92 | } |
---|
| 93 | |
---|
[46] | 94 | foreach($sectors_info as $context=>$sector) |
---|
[2] | 95 | { |
---|
| 96 | $tr_color = $this->nextmatchs->alternate_row_color($tr_color); |
---|
| 97 | |
---|
| 98 | $var = Array( |
---|
| 99 | 'tr_color' => $tr_color, |
---|
[5133] | 100 | 'sector_name' => $sector, |
---|
| 101 | 'add_link' => $this->row_action('add','sector',$context) |
---|
[3359] | 102 | ); |
---|
| 103 | |
---|
[5133] | 104 | $var['sector_name'] = utf8_decode($var['sector_name']); |
---|
| 105 | |
---|
[3359] | 106 | |
---|
[548] | 107 | if(isset($GLOBALS['phpgw_info']['server']['time_to_account_expires'])) |
---|
[5133] | 108 | $var['inactives_link'] = $this->row_action('list_inactive','users',$context,'uiaccounts'); |
---|
[548] | 109 | else |
---|
[597] | 110 | $var['inactives_link'] = lang('disabled'); |
---|
[548] | 111 | |
---|
[2] | 112 | $p->set_var($var); |
---|
| 113 | |
---|
[32] | 114 | if ($can_edit) |
---|
| 115 | { |
---|
[5133] | 116 | $p->set_var('edit_link',$this->row_action('edit','sector',utf8_decode($context))); |
---|
[32] | 117 | } |
---|
| 118 | else |
---|
| 119 | { |
---|
| 120 | $p->set_var('edit_link',' '); |
---|
| 121 | } |
---|
| 122 | |
---|
[2] | 123 | if ($can_delete) |
---|
| 124 | { |
---|
[5133] | 125 | $p->set_var('delete_link',$this->row_action('delete','sector',utf8_decode($context))); |
---|
[2] | 126 | } |
---|
| 127 | else |
---|
| 128 | { |
---|
| 129 | $p->set_var('delete_link',' '); |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | $p->fp('rows','row',True); |
---|
| 133 | } |
---|
| 134 | } |
---|
| 135 | $var = Array( |
---|
| 136 | 'action' => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uisectors.add_sector') |
---|
| 137 | ); |
---|
| 138 | $p->set_var($var); |
---|
| 139 | |
---|
[3359] | 140 | $p->set_var('input_add','<input type="submit" value="' . lang('Add Sectors') . '">'); |
---|
| 141 | |
---|
[2] | 142 | $p->parse('rows','row_empty',True); |
---|
| 143 | $p->pfp('out','list'); |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | |
---|
| 147 | function add_sector($context='') |
---|
| 148 | { |
---|
[64] | 149 | $manager_lid = $GLOBALS['phpgw']->accounts->data['account_lid']; |
---|
| 150 | $acl = $this->functions->read_acl($manager_lid); |
---|
[1145] | 151 | |
---|
| 152 | $manager_contexts = $acl['contexts']; |
---|
| 153 | $combo_manager_org = ''; |
---|
| 154 | |
---|
[1394] | 155 | if ( array_key_exists( 'context', $_GET ) ) |
---|
| 156 | { |
---|
| 157 | $context = $_GET['context']; |
---|
| 158 | $combo_manager_org = $this->functions->get_organizations( $context, '', true, true, true ); |
---|
[5133] | 159 | $combo_manager_org = preg_replace("/\\\([0-9A-Fa-f]{2})/e", "''.chr(hexdec('\\1')).''",$combo_manager_org); |
---|
| 160 | $combo_manager_org = utf8_decode($combo_manager_org); |
---|
[1394] | 161 | } |
---|
| 162 | else |
---|
| 163 | { |
---|
| 164 | foreach ($manager_contexts as $index=>$context) |
---|
| 165 | $combo_manager_org .= $this->functions->get_organizations( $context ); |
---|
| 166 | } |
---|
| 167 | |
---|
[2] | 168 | // Verifica se tem acesso a este modulo |
---|
[64] | 169 | if (!$this->functions->check_acl($manager_lid,'create_sectors')) |
---|
[2] | 170 | { |
---|
| 171 | $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php')); |
---|
| 172 | } |
---|
| 173 | |
---|
| 174 | unset($GLOBALS['phpgw_info']['flags']['noheader']); |
---|
| 175 | unset($GLOBALS['phpgw_info']['flags']['nonavbar']); |
---|
[309] | 176 | $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Create Sector'); |
---|
[2] | 177 | $GLOBALS['phpgw']->common->phpgw_header(); |
---|
| 178 | |
---|
| 179 | // Set o template |
---|
| 180 | $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL); |
---|
| 181 | $p->set_file(Array('create_sector' => 'sectors_form.tpl')); |
---|
[414] | 182 | $p->set_block('create_sector','list','list'); |
---|
[396] | 183 | |
---|
[2] | 184 | // Seta variaveis utilizadas pelo tpl. |
---|
| 185 | $var = Array( |
---|
[32] | 186 | 'action' => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uisectors.validate_data_sectors_add'), |
---|
| 187 | 'back_url' => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uisectors.list_sectors'), |
---|
| 188 | 'th_bg' => $GLOBALS['phpgw_info']['theme']['th_bg'], |
---|
[64] | 189 | 'context' => $context == '' ? $GLOBALS['phpgw_info']['server']['ldap_context'] : $context, |
---|
[32] | 190 | 'sector' => $_POST['sector'], |
---|
[1145] | 191 | 'manager_org' => $combo_manager_org, |
---|
[309] | 192 | 'sector_visible_checked'=> $_POST['sector_visible'] ? 'checked' : '', |
---|
[32] | 193 | 'error_messages' => $_POST['error_messages'] == '' ? '' : "<script type='text/javascript'>alert('".$_POST['error_messages']."')</script>", |
---|
[2] | 194 | ); |
---|
[1516] | 195 | |
---|
[5133] | 196 | $var['sector'] = preg_replace("/\\\([0-9A-Fa-f]{2})/e", "''.chr(hexdec('\\1')).''",$var['sector']); |
---|
| 197 | $var['sector'] = utf8_decode($var['sector']); |
---|
[1516] | 198 | |
---|
[2] | 199 | $p->set_var($var); |
---|
[414] | 200 | $p->set_var($this->functions->make_dinamic_lang($p, 'list')); |
---|
[2] | 201 | |
---|
| 202 | $p->pfp('out','create_sector'); |
---|
| 203 | } |
---|
| 204 | |
---|
[32] | 205 | function edit_sector() |
---|
| 206 | { |
---|
| 207 | $account_lid = $GLOBALS['phpgw']->accounts->data['account_lid']; |
---|
| 208 | $acl = $this->functions->read_acl($account_lid); |
---|
| 209 | $manager_context = $acl[0]['context']; |
---|
| 210 | |
---|
| 211 | $context = $_GET['context']; |
---|
[1145] | 212 | |
---|
[5133] | 213 | $context = utf8_encode($context); |
---|
| 214 | $context = preg_replace("/\\\([0-9A-Fa-f]{2})/e", "''.chr(hexdec('\\1')).''",$context); |
---|
| 215 | |
---|
| 216 | $combo_manager_org = $this->functions->get_organizations($context, '', true, true, true); |
---|
| 217 | |
---|
| 218 | $combo_manager_org = utf8_decode(preg_replace("/\\\([0-9A-Fa-f]{2})/e", "''.chr(hexdec('\\1')).''",$combo_manager_org)); |
---|
| 219 | |
---|
[1145] | 220 | $combo_manager_org = substr( $combo_manager_org, 0, ( strpos($combo_manager_org, '</option>') + 9 ) ); |
---|
| 221 | |
---|
[32] | 222 | $a_tmp = explode(",", ldap_dn2ufn($context)); |
---|
| 223 | $sector_name = $a_tmp[0]; |
---|
| 224 | |
---|
| 225 | // Verifica se tem acesso a este modulo |
---|
| 226 | if (!$this->functions->check_acl($account_lid,'edit_sectors')) |
---|
| 227 | { |
---|
| 228 | $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php')); |
---|
| 229 | } |
---|
| 230 | |
---|
| 231 | unset($GLOBALS['phpgw_info']['flags']['noheader']); |
---|
| 232 | unset($GLOBALS['phpgw_info']['flags']['nonavbar']); |
---|
[309] | 233 | $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Edit Sector'); |
---|
[32] | 234 | $GLOBALS['phpgw']->common->phpgw_header(); |
---|
| 235 | |
---|
| 236 | // Set o template |
---|
| 237 | $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL); |
---|
| 238 | $p->set_file(Array('edit_sector' => 'sectors_form.tpl')); |
---|
[414] | 239 | $p->set_block('edit_sector','list','list'); |
---|
[32] | 240 | |
---|
| 241 | if (!$_POST) |
---|
| 242 | { |
---|
| 243 | $sector_info = $this->so->get_info($context); |
---|
| 244 | $_POST['sector_visible'] = $sector_info[0]['phpgwaccountvisible'][0]; |
---|
| 245 | } |
---|
| 246 | |
---|
| 247 | // Seta variaveis utilizadas pelo tpl. |
---|
| 248 | $var = Array( |
---|
| 249 | 'action' => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.bosectors.save_sector'), |
---|
| 250 | 'back_url' => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uisectors.list_sectors'), |
---|
| 251 | 'th_bg' => $GLOBALS['phpgw_info']['theme']['th_bg'], |
---|
| 252 | 'context' => $context == '' ? $manager_context : $context, |
---|
[1145] | 253 | 'sector' => $_POST['sector'] == '' ? $sector_name : $_POST['sector'], |
---|
| 254 | 'manager_org' => $combo_manager_org, |
---|
[309] | 255 | 'sector_visible_checked'=> $_POST['sector_visible'] ? 'checked' : '', |
---|
[5133] | 256 | |
---|
[32] | 257 | 'lang_add' => lang('Add'), |
---|
| 258 | 'disable' => 'disabled', |
---|
| 259 | 'error_messages' => $_POST['error_messages'] == '' ? '' : "<script type='text/javascript'>alert('".$_POST['error_messages']."')</script>", |
---|
| 260 | ); |
---|
[1516] | 261 | |
---|
[5133] | 262 | $var['sector'] = preg_replace("/\\\([0-9A-Fa-f]{2})/e", "''.chr(hexdec('\\1')).''",$var['sector']); |
---|
| 263 | $var['sector'] = utf8_decode($var['sector']); |
---|
[1516] | 264 | |
---|
| 265 | $p->set_var($var); |
---|
[5133] | 266 | $p->set_var($this->functions->make_dinamic_lang($p, 'list')); |
---|
[1516] | 267 | |
---|
[5133] | 268 | $p->pfp('out','edit_sector'); |
---|
[1516] | 269 | } |
---|
| 270 | |
---|
[2] | 271 | function validate_data_sectors_add() |
---|
| 272 | { |
---|
| 273 | $sector_name = $_POST['sector']; |
---|
[396] | 274 | $context = $_POST['context']; |
---|
[2] | 275 | |
---|
| 276 | // Verifica se o nome do sector nao esta vazio. |
---|
| 277 | if ($sector_name == '') |
---|
| 278 | { |
---|
[309] | 279 | $_POST['error_messages'] = lang('Sector name is empty.'); |
---|
[2] | 280 | ExecMethod('expressoAdmin1_2.uisectors.add_sector'); |
---|
| 281 | return; |
---|
| 282 | } |
---|
| 283 | |
---|
| 284 | // Verifica se o nome do setor existe no contexto atual. |
---|
| 285 | if ($this->so->exist_sector_name($sector_name, $context)) |
---|
| 286 | { |
---|
| 287 | $_POST['error_messages'] = lang('Sector name already exist.'); |
---|
| 288 | ExecMethod('expressoAdmin1_2.uisectors.add_sector'); |
---|
| 289 | return; |
---|
| 290 | } |
---|
| 291 | |
---|
| 292 | ExecMethod('expressoAdmin1_2.bosectors.create_sector'); |
---|
| 293 | } |
---|
[32] | 294 | |
---|
[2] | 295 | function delete_sector() |
---|
| 296 | { |
---|
| 297 | $account_lid = $GLOBALS['phpgw']->accounts->data['account_lid']; |
---|
| 298 | $acl = $this->functions->read_acl($account_lid); |
---|
| 299 | $manager_context = $acl[0]['context']; |
---|
| 300 | |
---|
[5133] | 301 | $manager_context = utf8_encode($manager_context); |
---|
| 302 | $manager_context = preg_replace("/\\\([0-9A-Fa-f]{2})/e", "''.chr(hexdec('\\1')).''",$manager_context); |
---|
| 303 | |
---|
[2] | 304 | // Verifica se tem acesso a este modulo |
---|
| 305 | if (!$this->functions->check_acl($account_lid,'delete_sectors')) |
---|
| 306 | { |
---|
| 307 | $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php')); |
---|
| 308 | } |
---|
| 309 | |
---|
| 310 | unset($GLOBALS['phpgw_info']['flags']['noheader']); |
---|
| 311 | unset($GLOBALS['phpgw_info']['flags']['nonavbar']); |
---|
[309] | 312 | $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Delete Sectors'); |
---|
[2] | 313 | $GLOBALS['phpgw']->common->phpgw_header(); |
---|
| 314 | |
---|
| 315 | // Set o template |
---|
| 316 | $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL); |
---|
| 317 | $p->set_file(Array('delete_sector' => 'sectors_delete.tpl')); |
---|
[414] | 318 | $p->set_block('delete_sector','list','list'); |
---|
[2] | 319 | |
---|
| 320 | $tmp_sector_name = $_GET['context']; |
---|
| 321 | $tmp_sector_name = explode(",",$tmp_sector_name); |
---|
| 322 | $tmp_sector_name = $tmp_sector_name[0]; |
---|
| 323 | $tmp_sector_name = explode("=", $tmp_sector_name); |
---|
| 324 | $sector_name = $tmp_sector_name[1]; |
---|
| 325 | |
---|
[5133] | 326 | |
---|
[2] | 327 | // Get users of sector |
---|
[5133] | 328 | $sector_users = $this->so->get_sector_users(utf8_encode($_GET['context'])); |
---|
| 329 | $sector_groups = $this->so->get_sector_groups(utf8_encode($_GET['context'])); |
---|
| 330 | $sector_subsectors = $this->so->get_sector_subsectors(utf8_encode($_GET['context'])); |
---|
[2] | 331 | |
---|
| 332 | $users_list = ''; |
---|
| 333 | foreach ($sector_users as $user) |
---|
| 334 | { |
---|
| 335 | $users_list .= $user['cn'][0] . '<br>'; |
---|
| 336 | } |
---|
| 337 | |
---|
| 338 | $groups_list = ''; |
---|
| 339 | foreach ($sector_groups as $group) |
---|
| 340 | { |
---|
| 341 | $groups_list .= $group['cn'][0] . '<br>'; |
---|
| 342 | } |
---|
| 343 | |
---|
| 344 | $subsectors_list = ''; |
---|
| 345 | foreach ($sector_subsectors as $subsector) |
---|
| 346 | { |
---|
| 347 | if ($subsector['dn'] != $_GET['context']) |
---|
[5133] | 348 | $subsectors_list .= utf8_decode($subsector['ou'][0] . '<br>'); |
---|
[2] | 349 | } |
---|
| 350 | |
---|
| 351 | // Seta variaveis utilizadas pelo tpl. |
---|
| 352 | $var = Array( |
---|
| 353 | 'color_bg1' => "#E8F0F0", |
---|
| 354 | 'manager_context' => $manager_context, |
---|
| 355 | 'dn' => $_GET['context'], |
---|
| 356 | 'back_url' => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uisectors.list_sectors'), |
---|
| 357 | 'action' => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.bosectors.delete_sector'), |
---|
| 358 | |
---|
| 359 | 'sector_name' => $sector_name, |
---|
| 360 | 'users_list' => $users_list, |
---|
| 361 | 'groups_list' => $groups_list, |
---|
| 362 | 'sectors_list' => $subsectors_list |
---|
| 363 | ); |
---|
[5133] | 364 | $var['sector_name'] = preg_replace("/\\\([0-9A-Fa-f]{2})/e", "''.chr(hexdec('\\1')).''",$var['sector_name']); |
---|
| 365 | |
---|
[2] | 366 | $p->set_var($var); |
---|
[414] | 367 | $p->set_var($this->functions->make_dinamic_lang($p, 'list')); |
---|
[2] | 368 | $p->pfp('out','delete_sector'); |
---|
| 369 | } |
---|
| 370 | |
---|
[548] | 371 | function row_action($action,$type,$context,$class='uisectors') |
---|
[2] | 372 | { |
---|
| 373 | return '<a href="'.$GLOBALS['phpgw']->link('/index.php',Array( |
---|
[548] | 374 | 'menuaction' => 'expressoAdmin1_2.'.$class.'.'.$action.'_'.$type, |
---|
[2] | 375 | 'context' => $context |
---|
| 376 | )).'"> '.lang($action).' </a>'; |
---|
| 377 | } |
---|
| 378 | |
---|
| 379 | function css() |
---|
| 380 | { |
---|
| 381 | $appCSS = ''; |
---|
| 382 | return $appCSS; |
---|
| 383 | } |
---|
| 384 | |
---|
| 385 | } |
---|
[548] | 386 | ?> |
---|