[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 uimanagers |
---|
| 13 | { |
---|
| 14 | var $public_functions = array |
---|
| 15 | ( |
---|
| 16 | 'list_managers' => True, |
---|
| 17 | 'add_managers' => True, |
---|
| 18 | 'delete_managers' => True, |
---|
| 19 | 'edit_managers' => True, |
---|
[64] | 20 | 'copy_managers' => True, |
---|
[2] | 21 | 'validate' => True |
---|
| 22 | ); |
---|
| 23 | |
---|
| 24 | var $functions; |
---|
| 25 | var $config; |
---|
| 26 | |
---|
| 27 | function uimanagers() |
---|
| 28 | { |
---|
| 29 | $this->functions = CreateObject('expressoAdmin1_2.functions'); |
---|
| 30 | $c = CreateObject('phpgwapi.config','expressoAdmin1_2'); |
---|
| 31 | $c->read_repository(); |
---|
| 32 | $this->config = $c->config_data; |
---|
[64] | 33 | |
---|
| 34 | if(!@is_object($GLOBALS['phpgw']->js)) |
---|
| 35 | { |
---|
| 36 | $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript'); |
---|
| 37 | } |
---|
| 38 | $GLOBALS['phpgw']->js->validate_file('jscode','connector','expressoAdmin1_2');#diretorio, arquivo.js, aplicacao |
---|
| 39 | $GLOBALS['phpgw']->js->validate_file('jscode','managers','expressoAdmin1_2'); |
---|
[2] | 40 | } |
---|
| 41 | |
---|
| 42 | function row_action($lang,$link,$manager_lid,$context) |
---|
| 43 | { |
---|
| 44 | return '<a href="'.$GLOBALS['phpgw']->link('/index.php',Array( |
---|
| 45 | 'menuaction' => 'expressoAdmin1_2.uimanagers.'.$link, |
---|
| 46 | 'action' => $lang, |
---|
| 47 | 'manager_lid' => $manager_lid, |
---|
| 48 | 'context' => $context |
---|
| 49 | )).'" onmouseover="window.status=\''.lang($lang).' Manager\'; return true;" onmouseout="window.status=\'\';" >'.lang($lang).' </a>'; |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | function list_managers() |
---|
| 53 | { |
---|
| 54 | // Caso nao seja admin, sai. |
---|
| 55 | if ($GLOBALS['phpgw']->acl->check('group_access',1,'admin')) |
---|
| 56 | { |
---|
| 57 | $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/admin/index.php')); |
---|
| 58 | } |
---|
| 59 | // Imprime o NavBar |
---|
| 60 | unset($GLOBALS['phpgw_info']['flags']['nonavbar']); |
---|
| 61 | $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('List Managers'); |
---|
| 62 | $GLOBALS['phpgw']->common->phpgw_header(); |
---|
| 63 | |
---|
| 64 | // Seta o template |
---|
| 65 | $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL); |
---|
| 66 | $p->set_file(array('managers' => 'managers.tpl')); |
---|
| 67 | $p->set_block('managers','body','body'); |
---|
| 68 | $p->set_block('managers','row','row'); |
---|
| 69 | $p->set_block('managers','row_empty','row_empty'); |
---|
[64] | 70 | $tpl_vars = $p->get_undefined('body'); |
---|
[2] | 71 | |
---|
| 72 | $var = Array( |
---|
| 73 | 'action' => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uimanagers.add_managers'), |
---|
| 74 | 'tr_color' => '#DDDDDD', |
---|
[64] | 75 | 'th_bg' => $GLOBALS['phpgw_info']['theme']['th_bg'] |
---|
[2] | 76 | ); |
---|
| 77 | |
---|
[64] | 78 | // Cria dinamicamente os langs |
---|
| 79 | foreach ($tpl_vars as $atribute) |
---|
| 80 | { |
---|
| 81 | $lang = strstr($atribute, 'lang_'); |
---|
| 82 | if($lang !== false) |
---|
| 83 | { |
---|
| 84 | $p->set_var($atribute, $this->make_lang($atribute)); |
---|
| 85 | } |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | // Le BD para pegar os administradors. |
---|
[2] | 89 | $query = 'SELECT manager_lid,context FROM phpgw_expressoadmin ORDER by manager_lid'; |
---|
| 90 | $GLOBALS['phpgw']->db->query($query); |
---|
| 91 | while($GLOBALS['phpgw']->db->next_record()) |
---|
| 92 | { |
---|
| 93 | $managers[] = $GLOBALS['phpgw']->db->row(); |
---|
| 94 | } |
---|
| 95 | $ldap_conn = $GLOBALS['phpgw']->common->ldapConnect(); |
---|
| 96 | $justthese = array("cn"); |
---|
| 97 | // Loop para listar os administradores |
---|
| 98 | if (count($managers)) |
---|
| 99 | { |
---|
| 100 | foreach($managers as $array_managers) |
---|
| 101 | { |
---|
[64] | 102 | $managers_context = ""; |
---|
| 103 | $a_managers_context = split("%", $array_managers['context']); |
---|
| 104 | |
---|
| 105 | foreach ($a_managers_context as $context) |
---|
| 106 | { |
---|
| 107 | $managers_context .= "$context<br>"; |
---|
| 108 | } |
---|
| 109 | |
---|
[2] | 110 | $filter="(&(phpgwAccountType=u)(uid=".$array_managers['manager_lid']."))"; |
---|
| 111 | $ldap_search = ldap_search($ldap_conn, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
| 112 | $ldap_result = ldap_get_entries($ldap_conn, $ldap_search); |
---|
| 113 | $p->set_var('manager_lid', $array_managers[manager_lid]); |
---|
| 114 | $p->set_var('manager_cn', $ldap_result[0]['cn'][0] == '' ? '<font color=red>NAO ENCONTRADO NO LDAP</font>' : $ldap_result[0]['cn'][0]); |
---|
[64] | 115 | $p->set_var('context', $managers_context); |
---|
[2] | 116 | $p->set_var('link_edit',$this->row_action('edit','edit_managers',$array_managers[manager_lid],$array_managers[context])); |
---|
| 117 | $p->set_var('link_delete',$this->row_action('delete','delete_managers',$array_managers[manager_lid],$array_managers[context])); |
---|
[64] | 118 | $p->set_var('link_copy',"<a href='#' onClick='javascript:copy_manager(\"".$array_managers['manager_lid']."\");'>Copiar</a>"); |
---|
[2] | 119 | $p->fp('rows','row',True); |
---|
| 120 | } |
---|
| 121 | } |
---|
| 122 | $p->set_var($var); |
---|
| 123 | $p->pfp('out','body'); |
---|
| 124 | ldap_close($ldap_conn); |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | |
---|
| 128 | function add_managers() |
---|
| 129 | { |
---|
| 130 | // Caso nao seja admin, sai. |
---|
| 131 | if ($GLOBALS['phpgw']->acl->check('group_access',1,'admin')) |
---|
| 132 | { |
---|
| 133 | $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/admin/index.php')); |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | // Seta o template |
---|
| 137 | $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL); |
---|
| 138 | $p->set_file(array('managers' => 'managers_form.tpl')); |
---|
| 139 | $p->set_block('managers','form','form'); |
---|
[64] | 140 | $tpl_vars = $p->get_undefined('form'); |
---|
[2] | 141 | |
---|
| 142 | // Imprime o NavBar |
---|
| 143 | unset($GLOBALS['phpgw_info']['flags']['nonavbar']); |
---|
| 144 | $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Add Managers'); |
---|
| 145 | $GLOBALS['phpgw']->common->phpgw_header(); |
---|
| 146 | |
---|
[64] | 147 | // Seta variaveis javascript necessárias |
---|
[2] | 148 | $webserver_url = $GLOBALS['phpgw_info']['server']['webserver_url']; |
---|
[64] | 149 | $scripts_java = '<script type="text/javascript" src="'.$webserver_url.'/expressoAdmin1_2/js/jscode/expressoadmin.js"></script>'; |
---|
[2] | 150 | |
---|
| 151 | // App, create list of available apps |
---|
[64] | 152 | $applications_list = $this->make_app_list(); |
---|
| 153 | |
---|
| 154 | $input_context_fields = '<input type="text" size=60></input><br>'; |
---|
| 155 | |
---|
[2] | 156 | // Seta variaveis que estao no TPL |
---|
| 157 | $var = Array( |
---|
| 158 | 'scripts_java' => $scripts_java, |
---|
| 159 | 'action' => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uimanagers.validate'), |
---|
| 160 | 'display_samba_suport' => $this->config['expressoAdmin_samba_support'] == 'true' ? '' : 'display:none', |
---|
| 161 | 'type' => "add", |
---|
| 162 | 'color_bg1' => "#E8F0F0", |
---|
| 163 | 'color_bg2' => "#D3DCE3", |
---|
| 164 | 'color_font1' => "#DDDDDD", |
---|
| 165 | 'color_font2' => "#EEEEEE", |
---|
[64] | 166 | 'input_context_fields' => $input_context_fields, |
---|
| 167 | 'error_messages' => $_POST['error_messages'] == '' ? '' : '<script language="JavaScript">alert("'.$_POST['error_messages'].'");</script>', |
---|
| 168 | 'manager_lid' => $_POST['manager_lid'], |
---|
| 169 | 'context' => $_POST['context'], |
---|
| 170 | 'app_list' => $applications_list |
---|
[2] | 171 | ); |
---|
| 172 | $p->set_var($var); |
---|
[64] | 173 | |
---|
| 174 | // Cria dinamicamente os langs e seta acls |
---|
| 175 | foreach ($tpl_vars as $atribute) |
---|
| 176 | { |
---|
| 177 | $acl = strstr($atribute, 'acl_'); |
---|
| 178 | $lang = strstr($atribute, 'lang_'); |
---|
| 179 | // Recuperar os valores das ACLS |
---|
| 180 | if ($acl !== false) |
---|
| 181 | { |
---|
| 182 | $p->set_var($atribute, $_POST[$atribute] != '' ? 'checked' : ''); |
---|
| 183 | } |
---|
| 184 | // Setar os langs do tpl. |
---|
| 185 | elseif($lang !== false) |
---|
| 186 | { |
---|
| 187 | $p->set_var($atribute, $this->make_lang($atribute)); |
---|
| 188 | } |
---|
| 189 | } |
---|
| 190 | |
---|
[2] | 191 | echo $p->fp('out','form'); |
---|
| 192 | } |
---|
| 193 | |
---|
| 194 | function delete_managers() |
---|
| 195 | { |
---|
| 196 | // Criar uma verificação e jogar a query para o BO. |
---|
| 197 | $context = $_GET['context']; |
---|
| 198 | $manager_lid = $_GET['manager_lid']; |
---|
| 199 | |
---|
| 200 | $query = "DELETE FROM phpgw_expressoadmin WHERE manager_lid = '".$manager_lid."' AND context = '" . $context ."'"; |
---|
| 201 | $GLOBALS['phpgw']->db->query($query); |
---|
| 202 | |
---|
| 203 | // Remove Gerente da tabela dos apps |
---|
| 204 | $query = "DELETE FROM phpgw_expressoadmin_apps WHERE " |
---|
| 205 | . "manager_lid = '".$manager_lid."' AND " |
---|
| 206 | . "context = '".$context."'"; |
---|
| 207 | $GLOBALS['phpgw']->db->query($query); |
---|
| 208 | |
---|
| 209 | // Remove Gerente na ACL do expressoadmin |
---|
| 210 | $accounts = CreateObject('phpgwapi.accounts'); |
---|
| 211 | $manager_id = $accounts->name2id($_GET['manager_lid']); |
---|
| 212 | $sql = "DELETE FROM phpgw_acl WHERE acl_appname = 'expressoadmin' AND acl_account = '" . $manager_id . "'"; |
---|
| 213 | $GLOBALS['phpgw']->db->query($sql); |
---|
| 214 | |
---|
| 215 | ExecMethod('expressoAdmin1_2.uimanagers.list_managers'); |
---|
| 216 | } |
---|
| 217 | |
---|
| 218 | function edit_managers() |
---|
| 219 | { |
---|
| 220 | // Caso nao seja admin, sai. |
---|
| 221 | if ($GLOBALS['phpgw']->acl->check('group_access',1,'admin')) |
---|
| 222 | { |
---|
| 223 | $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/admin/index.php')); |
---|
| 224 | } |
---|
| 225 | |
---|
| 226 | // Verifica se eh a primeira entrada, ai eu tenho o get, senao pego o post. |
---|
| 227 | if ($_GET['manager_lid'] != '') |
---|
| 228 | { |
---|
[64] | 229 | $first_time = true; |
---|
[2] | 230 | $_POST['manager_lid'] = $_GET['manager_lid']; |
---|
| 231 | $_POST['context'] = $_GET['context']; |
---|
| 232 | $old_manager_lid = $_GET['manager_lid']; |
---|
| 233 | $old_context = $_GET['context']; |
---|
| 234 | } |
---|
| 235 | elseif ($_POST['manager_lid'] != '') |
---|
| 236 | { |
---|
[64] | 237 | $first_time = false; |
---|
[2] | 238 | $old_manager_lid = $_POST['old_manager_lid']; |
---|
| 239 | $old_context = $_POST['old_context']; |
---|
| 240 | } |
---|
| 241 | |
---|
| 242 | if ($first_time) |
---|
| 243 | { |
---|
[64] | 244 | //Pego ACL do gerente |
---|
| 245 | $manager = $this->functions->read_acl($_GET['manager_lid']); |
---|
| 246 | //Cria vetor da ACL |
---|
| 247 | $manager_acl = $this->functions->make_array_acl($manager['acl']); |
---|
| 248 | |
---|
[2] | 249 | //Pesquisa no Banco e pega os valores dos apps. |
---|
| 250 | $query = "SELECT * FROM phpgw_expressoadmin_apps WHERE manager_lid = '" . $_GET['manager_lid'] . "' AND context = '" . $_GET['context'] . "'"; |
---|
| 251 | $GLOBALS['phpgw']->db->query($query); |
---|
| 252 | $i=0; |
---|
| 253 | $manager[0]['apps'] = array(); |
---|
| 254 | while($GLOBALS['phpgw']->db->next_record()) |
---|
| 255 | { |
---|
| 256 | $tmp[$i] = $GLOBALS['phpgw']->db->row(); |
---|
| 257 | $_POST['applications_list'][$tmp[$i]['app']] = 1; |
---|
| 258 | $manager[0]['apps'][$tmp[$i]['app']] = 1; |
---|
| 259 | $i++; |
---|
| 260 | } |
---|
| 261 | } |
---|
| 262 | |
---|
| 263 | // Seta o template |
---|
| 264 | $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL); |
---|
| 265 | $p->set_file(array('managers' => 'managers_form.tpl')); |
---|
| 266 | $p->set_block('managers','form','form'); |
---|
[64] | 267 | $tpl_vars = $p->get_undefined('form'); |
---|
[2] | 268 | |
---|
| 269 | // Imprime o NavBar |
---|
| 270 | unset($GLOBALS['phpgw_info']['flags']['nonavbar']); |
---|
| 271 | $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Edit Managers'); |
---|
| 272 | $GLOBALS['phpgw']->common->phpgw_header(); |
---|
| 273 | |
---|
| 274 | // Seta variaveis javas necessárias |
---|
| 275 | $webserver_url = $GLOBALS['phpgw_info']['server']['webserver_url']; |
---|
[64] | 276 | $scripts_java = '<script type="text/javascript" src="'.$webserver_url.'/expressoAdmin1_2/js/jscode/expressoadmin.js"></script>'; |
---|
[2] | 277 | |
---|
| 278 | // App, create list of available apps |
---|
[64] | 279 | $applications_list = $this->make_app_list($manager[0]['apps']); |
---|
[2] | 280 | |
---|
[64] | 281 | $a_context = split("%", $_POST['context']); |
---|
| 282 | foreach ($a_context as $context) |
---|
| 283 | $input_context_fields .= '<input type="text" value="'.$context.'" size=60></input><br>'; |
---|
[2] | 284 | |
---|
| 285 | $var = Array( |
---|
[64] | 286 | 'scripts_java' => $scripts_java, |
---|
| 287 | 'action' => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uimanagers.validate'), |
---|
[2] | 288 | 'display_samba_suport' => $this->config['expressoAdmin_samba_support'] == 'true' ? '' : 'display:none', |
---|
[64] | 289 | 'color_bg1' => "#E8F0F0", |
---|
| 290 | 'color_bg2' => "#D3DCE3", |
---|
[2] | 291 | 'color_font1' => "#DDDDDD", |
---|
| 292 | 'color_font2' => "#EEEEEE", |
---|
| 293 | 'type' => "edit", |
---|
[64] | 294 | 'error_messages'=> $_POST['error_messages'] == '' ? '' : '<script language="JavaScript1.3">alert("'.$_POST['error_messages'].'");</script>', |
---|
| 295 | 'manager_lid' => $_POST['manager_lid'], |
---|
| 296 | 'context' => $_POST['context'], |
---|
[2] | 297 | |
---|
[64] | 298 | 'input_context_fields' => $input_context_fields, |
---|
| 299 | |
---|
[2] | 300 | // Para o update no banco, preciso saber oq foi alterado e para que. |
---|
| 301 | // Talvez so o manager e o contexto. |
---|
| 302 | 'old_manager_lid' => $old_manager_lid, |
---|
| 303 | 'old_context' => $old_context, |
---|
| 304 | 'app_list' => $applications_list |
---|
| 305 | ); |
---|
| 306 | $p->set_var($var); |
---|
[64] | 307 | |
---|
| 308 | // Cria dinamicamente os langs e seta acls |
---|
| 309 | foreach ($tpl_vars as $atribute) |
---|
| 310 | { |
---|
| 311 | $acl = strstr($atribute, 'acl_'); |
---|
| 312 | $lang = strstr($atribute, 'lang_'); |
---|
| 313 | // Recuperar os valores das ACLS |
---|
| 314 | if ($acl !== false) |
---|
| 315 | { |
---|
| 316 | if ($first_time) |
---|
| 317 | $p->set_var($atribute, $manager_acl[$atribute] != '' ? 'checked' : ''); |
---|
| 318 | else |
---|
| 319 | $p->set_var($atribute, $_POST[$atribute] != '' ? 'checked' : ''); |
---|
| 320 | } |
---|
| 321 | // Setar os langs do tpl. |
---|
| 322 | elseif($lang !== false) |
---|
| 323 | { |
---|
| 324 | $p->set_var($atribute, $this->make_lang($atribute)); |
---|
| 325 | } |
---|
| 326 | } |
---|
| 327 | |
---|
[2] | 328 | echo $p->fp('out','form'); |
---|
| 329 | } |
---|
| 330 | |
---|
| 331 | function validate() |
---|
| 332 | { |
---|
| 333 | $accounts = CreateObject('phpgwapi.accounts'); |
---|
| 334 | $errors = array(); |
---|
| 335 | |
---|
| 336 | // verifica se o manager existe. caso retorne 1 existe e eh uma conta de usuario. |
---|
| 337 | $manager_lid_exists = $accounts->exists($_POST['manager_lid']); |
---|
| 338 | if ($manager_lid_exists != 1) |
---|
| 339 | { |
---|
| 340 | $_POST['error_messages'] = lang("Manager LID don't exist."); |
---|
| 341 | if ($_POST['type'] == 'add') |
---|
| 342 | $this->add_managers(); |
---|
| 343 | elseif ($_POST['type'] == 'edit') |
---|
| 344 | $this->edit_managers(); |
---|
| 345 | return; |
---|
| 346 | } |
---|
| 347 | |
---|
| 348 | // Verifica se o contexto existe. |
---|
| 349 | $dn = $GLOBALS['phpgw_info']['server']['ldap_root_dn']; |
---|
| 350 | $passwd = $GLOBALS['phpgw_info']['server']['ldap_root_pw']; |
---|
| 351 | $ldap_conn = ldap_connect($GLOBALS['phpgw_info']['server']['ldap_host']); |
---|
| 352 | ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3); |
---|
| 353 | ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 0); |
---|
| 354 | ldap_bind($ldap_conn,$dn,$passwd); |
---|
[64] | 355 | |
---|
| 356 | $contexts = split("%", $_POST['context']); |
---|
[2] | 357 | |
---|
[64] | 358 | foreach ($contexts as $index=>$context) |
---|
[2] | 359 | { |
---|
[64] | 360 | $sr=@ldap_list($ldap_conn, $context, "cn=*"); |
---|
| 361 | if (!$sr) |
---|
| 362 | { |
---|
| 363 | $_POST['error_messages'] = lang("Context don't exist") . ": $context"; |
---|
| 364 | ldap_close($ldap_conn); |
---|
| 365 | if ($_POST['type'] == 'add') |
---|
| 366 | $this->add_managers(); |
---|
| 367 | elseif ($_POST['type'] == 'edit') |
---|
| 368 | $this->edit_managers(); |
---|
| 369 | return; |
---|
| 370 | } |
---|
[2] | 371 | } |
---|
| 372 | |
---|
| 373 | if ($_POST['type'] == 'add') |
---|
| 374 | { |
---|
| 375 | //Verifica se ja existe o manager com aquele contexto cadastrado |
---|
| 376 | $query = "SELECT manager_lid FROM phpgw_expressoadmin WHERE manager_lid = '" . $_POST['manager_lid'] . "' AND context = '" . $_POST['context'] . "'"; |
---|
| 377 | $GLOBALS['phpgw']->db->query($query); |
---|
| 378 | $num_registros = 0; |
---|
| 379 | while($GLOBALS['phpgw']->db->next_record()) |
---|
| 380 | { |
---|
| 381 | $tmp[] = $GLOBALS['phpgw']->db->row(); |
---|
| 382 | $num_registros++; |
---|
| 383 | } |
---|
| 384 | if ($num_registros != 0) |
---|
| 385 | { |
---|
[46] | 386 | $_POST['error_messages'] = lang('Este Gerente, neste contexto já exite !!'); |
---|
[2] | 387 | $this->add_managers(); |
---|
| 388 | return; |
---|
| 389 | } |
---|
| 390 | } |
---|
| 391 | |
---|
| 392 | if ($_POST['type'] == 'add') |
---|
| 393 | ExecMethod('expressoAdmin1_2.bomanagers.add_managers'); |
---|
| 394 | elseif ($_POST['type'] == 'edit') |
---|
| 395 | ExecMethod('expressoAdmin1_2.bomanagers.edit_managers'); |
---|
| 396 | |
---|
| 397 | return true; |
---|
| 398 | } |
---|
[64] | 399 | |
---|
| 400 | function copy_managers() |
---|
| 401 | { |
---|
| 402 | |
---|
| 403 | |
---|
| 404 | |
---|
| 405 | /* |
---|
| 406 | echo '<pre>'; |
---|
| 407 | print_r($_GET); |
---|
| 408 | $manager_lid = $_GET['manager_lid']; |
---|
| 409 | |
---|
| 410 | //Pego ACL do gerente |
---|
| 411 | $manager = $this->functions->read_acl($manager_lid); |
---|
| 412 | //Cria vetor da ACL |
---|
| 413 | $manager_acl = $this->functions->make_array_acl($manager[0]['acl']); |
---|
| 414 | |
---|
| 415 | //Pesquisa no Banco e pega os valores dos apps. |
---|
| 416 | $query = "SELECT * FROM phpgw_expressoadmin_apps WHERE manager_lid = '" . $manager_lid . "' AND context = '" . $_GET['context'] . "'"; |
---|
| 417 | $GLOBALS['phpgw']->db->query($query); |
---|
| 418 | $i=0; |
---|
| 419 | $manager[0]['apps'] = array(); |
---|
| 420 | while($GLOBALS['phpgw']->db->next_record()) |
---|
| 421 | { |
---|
| 422 | $tmp[$i] = $GLOBALS['phpgw']->db->row(); |
---|
| 423 | $_POST['applications_list'][$tmp[$i]['app']] = 1; |
---|
| 424 | $manager[0]['apps'][$tmp[$i]['app']] = 1; |
---|
| 425 | $i++; |
---|
| 426 | } |
---|
| 427 | |
---|
| 428 | print_r($manager); |
---|
| 429 | |
---|
| 430 | */ |
---|
| 431 | } |
---|
| 432 | |
---|
| 433 | function make_lang($ram_lang) |
---|
| 434 | { |
---|
| 435 | $a_lang = split("_", $ram_lang); |
---|
| 436 | $a_lang_reverse = array_reverse ( $a_lang, true ); |
---|
| 437 | //Retira o lang do array. |
---|
| 438 | array_pop ( $a_lang_reverse ); |
---|
| 439 | $a_lang = array_reverse ( $a_lang_reverse, true ); |
---|
| 440 | $a_new_lang = implode ( " ", $a_lang ); |
---|
| 441 | return lang($a_new_lang); |
---|
| 442 | } |
---|
| 443 | |
---|
| 444 | function make_app_list($manager_app_list) |
---|
| 445 | { |
---|
| 446 | $this->nextmatchs = createobject('phpgwapi.nextmatchs'); |
---|
| 447 | $apps = CreateObject('phpgwapi.applications',$_account_id); |
---|
| 448 | $db_perms = $apps->read_account_specific(); |
---|
| 449 | $availableApps = $GLOBALS['phpgw_info']['apps']; |
---|
| 450 | |
---|
| 451 | uasort($availableApps,create_function('$a,$b','return strcasecmp($a["title"],$b["title"]);')); |
---|
| 452 | |
---|
| 453 | // Loop para criar dinamicamente uma tabela com 3 colunas, cada coluna com um aplicativo e um check box. |
---|
| 454 | $applications_list = ''; |
---|
| 455 | $app_col1 = ''; |
---|
| 456 | $app_col2 = ''; |
---|
| 457 | $app_col3 = ''; |
---|
| 458 | $total_apps = count($availableApps); |
---|
| 459 | $i = 0; |
---|
| 460 | |
---|
| 461 | foreach($availableApps as $app => $data) |
---|
| 462 | { |
---|
| 463 | // 1 coluna |
---|
| 464 | if (($i +1) % 3 == 1) |
---|
| 465 | { |
---|
| 466 | if ($manager_app_list[$app] == 1) |
---|
| 467 | $checked = 'checked'; |
---|
| 468 | else |
---|
| 469 | $checked = ''; |
---|
| 470 | $app_col1 = sprintf("<td>%s</td><td width='10'><input type='checkbox' name='applications_list[%s]' value='1' %s %s></td>\n", |
---|
| 471 | $data['title'],$app,$checked, $disabled); |
---|
| 472 | |
---|
| 473 | if ($i == ($total_apps-1)) |
---|
| 474 | $applications_list .= sprintf('<tr bgcolor="%s">%s</tr>',$this->nextmatchs->alternate_row_color(), $app_col1); |
---|
| 475 | } |
---|
| 476 | // 2 coluna |
---|
| 477 | if (($i +1) % 3 == 2) |
---|
| 478 | { |
---|
| 479 | if ($manager_app_list[$app] == 1) |
---|
| 480 | $checked = 'checked'; |
---|
| 481 | else |
---|
| 482 | $checked = ''; |
---|
| 483 | $app_col2 = sprintf("<td>%s</td><td width='10'><input type='checkbox' name='applications_list[%s]' value='1' %s %s></td>\n", |
---|
| 484 | $data['title'],$app,$checked, $disabled); |
---|
| 485 | |
---|
| 486 | if ($i == ($total_apps-1)) |
---|
| 487 | $applications_list .= sprintf('<tr bgcolor="%s">%s%s</tr>',$this->nextmatchs->alternate_row_color(), $app_col1,$app_col2); |
---|
| 488 | } |
---|
| 489 | // 3 coluna |
---|
| 490 | if (($i +1) % 3 == 0) |
---|
| 491 | { |
---|
| 492 | if ($manager_app_list[$app] == 1) |
---|
| 493 | $checked = 'checked'; |
---|
| 494 | else |
---|
| 495 | $checked = ''; |
---|
| 496 | $app_col3 = sprintf("<td>%s</td><td width='10'><input type='checkbox' name='applications_list[%s]' value='1' %s %s></td>\n", |
---|
| 497 | $data['title'],$app,$checked, $disabled); |
---|
| 498 | |
---|
| 499 | // Cria nova linha |
---|
| 500 | $applications_list .= sprintf('<tr bgcolor="%s">%s%s%s</tr>',$this->nextmatchs->alternate_row_color(), $app_col1, $app_col2, $app_col3); |
---|
| 501 | } |
---|
| 502 | $i++; |
---|
| 503 | } |
---|
| 504 | return $applications_list; |
---|
| 505 | } |
---|
[2] | 506 | } |
---|
| 507 | ?> |
---|