[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 uigroups |
---|
| 13 | { |
---|
| 14 | var $public_functions = array |
---|
| 15 | ( |
---|
[64] | 16 | 'list_groups' => True, |
---|
| 17 | 'add_groups' => True, |
---|
| 18 | 'edit_groups' => True, |
---|
| 19 | 'css' => True |
---|
[2] | 20 | ); |
---|
| 21 | |
---|
| 22 | var $nextmatchs; |
---|
| 23 | var $group; |
---|
| 24 | var $functions; |
---|
[33] | 25 | var $ldap_functions; |
---|
| 26 | var $db_functions; |
---|
[2] | 27 | |
---|
| 28 | function uigroups() |
---|
| 29 | { |
---|
| 30 | $this->group = CreateObject('expressoAdmin1_2.group'); |
---|
| 31 | $this->nextmatchs = createobject('phpgwapi.nextmatchs'); |
---|
| 32 | $this->functions = CreateObject('expressoAdmin1_2.functions'); |
---|
[33] | 33 | $this->ldap_functions = CreateObject('expressoAdmin1_2.ldap_functions'); |
---|
| 34 | $this->db_functions = CreateObject('expressoAdmin1_2.db_functions'); |
---|
[2] | 35 | |
---|
| 36 | $c = CreateObject('phpgwapi.config','expressoAdmin1_2'); |
---|
| 37 | $c->read_repository(); |
---|
| 38 | $this->current_config = $c->config_data; |
---|
| 39 | |
---|
| 40 | if(!@is_object($GLOBALS['phpgw']->js)) |
---|
| 41 | { |
---|
| 42 | $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript'); |
---|
| 43 | } |
---|
| 44 | $GLOBALS['phpgw']->js->validate_file('jscode','connector','expressoAdmin1_2');#diretorio, arquivo.js, aplicacao |
---|
[5133] | 45 | $GLOBALS['phpgw']->js->validate_file('jscode','finder','expressoAdmin1_2'); |
---|
[2] | 46 | $GLOBALS['phpgw']->js->validate_file('jscode','expressoadmin','expressoAdmin1_2'); |
---|
| 47 | $GLOBALS['phpgw']->js->validate_file('jscode','groups','expressoAdmin1_2'); |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | function list_groups() |
---|
| 51 | { |
---|
| 52 | $account_lid = $GLOBALS['phpgw']->accounts->data['account_lid']; |
---|
[64] | 53 | $manager_acl = $this->functions->read_acl($account_lid); |
---|
| 54 | $raw_context = $acl['raw_context']; |
---|
| 55 | $contexts = $manager_acl['contexts']; |
---|
| 56 | foreach ($manager_acl['contexts_display'] as $index=>$tmp_context) |
---|
| 57 | { |
---|
| 58 | $context_display .= '<br>'.$tmp_context; |
---|
| 59 | } |
---|
[2] | 60 | |
---|
| 61 | // Verifica se tem acesso a este modulo |
---|
| 62 | if (!$this->functions->check_acl($account_lid,'list_groups')) |
---|
| 63 | { |
---|
| 64 | $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php')); |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | if(isset($_POST['query'])) |
---|
| 68 | { |
---|
| 69 | // limit query to limit characters |
---|
[5593] | 70 | if(preg_match('/^[a-z_0-9_-].+$/i',$_POST['query'])) |
---|
[2] | 71 | $GLOBALS['query'] = $_POST['query']; |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | unset($GLOBALS['phpgw_info']['flags']['noheader']); |
---|
| 75 | unset($GLOBALS['phpgw_info']['flags']['nonavbar']); |
---|
| 76 | |
---|
| 77 | $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('User groups'); |
---|
| 78 | $GLOBALS['phpgw']->common->phpgw_header(); |
---|
| 79 | |
---|
| 80 | $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL); |
---|
| 81 | $p->set_file(array('groups' => 'groups.tpl')); |
---|
| 82 | $p->set_block('groups','list','list'); |
---|
| 83 | $p->set_block('groups','row','row'); |
---|
| 84 | $p->set_block('groups','row_empty','row_empty'); |
---|
| 85 | |
---|
| 86 | // Seta as variaveis padroes. |
---|
| 87 | $var = Array( |
---|
| 88 | 'th_bg' => $GLOBALS['phpgw_info']['theme']['th_bg'], |
---|
| 89 | 'back_url' => $GLOBALS['phpgw']->link('/expressoAdmin1_2/index.php'), |
---|
| 90 | 'add_action' => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uigroups.add_groups'), |
---|
| 91 | 'add_group_disabled' => $this->functions->check_acl($account_lid,'add_groups') ? '' : 'disabled', |
---|
[414] | 92 | 'context_display' => $context_display |
---|
[2] | 93 | ); |
---|
| 94 | $p->set_var($var); |
---|
[414] | 95 | $p->set_var($this->functions->make_dinamic_lang($p, 'list')); |
---|
[2] | 96 | |
---|
| 97 | // Save query |
---|
| 98 | $p->set_var('query', $GLOBALS['query']); |
---|
| 99 | |
---|
| 100 | //Admin make a search |
---|
| 101 | if ($GLOBALS['query'] != '') |
---|
| 102 | { |
---|
[64] | 103 | $groups_info = $this->functions->get_list('groups', $GLOBALS['query'], $contexts); |
---|
[2] | 104 | } |
---|
[309] | 105 | $total = count($groups_info); |
---|
[2] | 106 | |
---|
[309] | 107 | if (!count($total) && $GLOBALS['query'] != '') |
---|
[2] | 108 | { |
---|
| 109 | $p->set_var('message',lang('No matches found')); |
---|
| 110 | } |
---|
[309] | 111 | else if ($total) |
---|
[2] | 112 | { |
---|
| 113 | if ($this->functions->check_acl($account_lid,'edit_groups')) |
---|
| 114 | { |
---|
| 115 | $can_edit = True; |
---|
| 116 | } |
---|
| 117 | if ($this->functions->check_acl($account_lid,'delete_groups')) |
---|
| 118 | { |
---|
| 119 | $can_delete = True; |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | foreach($groups_info as $group) |
---|
| 123 | { |
---|
| 124 | $tr_color = $this->nextmatchs->alternate_row_color($tr_color); |
---|
| 125 | $var = Array( |
---|
| 126 | 'tr_color' => $tr_color, |
---|
| 127 | 'row_cn' => $group['cn'], |
---|
| 128 | 'row_description' => $group['description'] |
---|
| 129 | ); |
---|
| 130 | $p->set_var($var); |
---|
| 131 | |
---|
| 132 | if ($can_edit) |
---|
| 133 | { |
---|
| 134 | $p->set_var('edit_link',$this->row_action('edit','groups',$group['gidnumber'],$group['cn'])); |
---|
| 135 | } |
---|
| 136 | else |
---|
| 137 | { |
---|
| 138 | $p->set_var('edit_link',' '); |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | if ($can_delete) |
---|
| 142 | { |
---|
[493] | 143 | $p->set_var('delete_link',"<a href='#' onClick='javascript:delete_group(\"".$group['cn']."\",\"".$group['gidnumber']."\");'>".lang('to delete')."</a>"); |
---|
[2] | 144 | } |
---|
| 145 | else |
---|
| 146 | { |
---|
| 147 | $p->set_var('delete_link',' '); |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | $p->fp('rows','row',True); |
---|
| 151 | } |
---|
| 152 | } |
---|
| 153 | $p->parse('rows','row_empty',True); |
---|
[309] | 154 | $p->set_var($var); |
---|
[2] | 155 | |
---|
[1847] | 156 | if (! $GLOBALS['phpgw']->acl->check('run',4,'admin')) |
---|
[2] | 157 | { |
---|
| 158 | $p->set_var('input_add','<input type="submit" value="' . lang('Add') . '">'); |
---|
| 159 | } |
---|
[1847] | 160 | if (! $GLOBALS['phpgw']->acl->check('run',2,'admin')) |
---|
[2] | 161 | { |
---|
| 162 | $p->set_var('input_search',lang('Search') . ' <input name="query" value="'.htmlspecialchars(stripslashes($GLOBALS['query'])).'">'); |
---|
| 163 | } |
---|
| 164 | $p->pfp('out','list'); |
---|
| 165 | } |
---|
| 166 | |
---|
| 167 | function add_groups() |
---|
| 168 | { |
---|
[33] | 169 | if ($this->current_config['expressoAdmin_samba_support'] == 'true') |
---|
| 170 | $GLOBALS['phpgw']->js->set_onload('get_available_sambadomains(document.forms[0].context.value, \'create_group\');'); |
---|
| 171 | |
---|
[64] | 172 | $manager_lid = $GLOBALS['phpgw']->accounts->data['account_lid']; |
---|
| 173 | $manager_acl = $this->functions->read_acl($manager_lid); |
---|
| 174 | $manager_contexts = $manager_acl['contexts']; |
---|
[2] | 175 | |
---|
| 176 | // Verifica se tem acesso a este modulo |
---|
[64] | 177 | if (!$this->functions->check_acl($manager_lid,'add_groups')) |
---|
[2] | 178 | { |
---|
| 179 | $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php')); |
---|
| 180 | } |
---|
| 181 | |
---|
| 182 | unset($GLOBALS['phpgw_info']['flags']['noheader']); |
---|
| 183 | unset($GLOBALS['phpgw_info']['flags']['nonavbar']); |
---|
[309] | 184 | $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Create Group'); |
---|
[2] | 185 | $GLOBALS['phpgw']->common->phpgw_header(); |
---|
| 186 | |
---|
| 187 | // Set o template |
---|
| 188 | $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL); |
---|
| 189 | $p->set_file(Array('create_group' => 'groups_form.tpl')); |
---|
[414] | 190 | $p->set_block('create_group','list','list'); |
---|
[2] | 191 | |
---|
| 192 | // Pega combo das organizações e seleciona um dos setores em caso de um erro na validaçao dos dados. |
---|
[64] | 193 | //$combo_manager_org = $this->functions->get_organizations($manager_context, trim(strtolower($group_info['context']))); |
---|
| 194 | foreach ($manager_contexts as $index=>$context) |
---|
| 195 | $combo_manager_org .= $this->functions->get_organizations($context, trim(strtolower($group_info['context']))); |
---|
[23] | 196 | $combo_all_orgs = $this->functions->get_organizations($GLOBALS['phpgw_info']['server']['ldap_context'], trim(strtolower($group_info['context']))); |
---|
[2] | 197 | |
---|
| 198 | // Chama funcao para criar lista de aplicativos disponiveis. |
---|
[64] | 199 | $apps = $this->functions->make_list_app($manager_lid); |
---|
[2] | 200 | |
---|
[33] | 201 | // Cria combo de dominio samba |
---|
| 202 | if ($this->current_config['expressoAdmin_samba_support'] == 'true') |
---|
| 203 | { |
---|
| 204 | $a_sambadomains = $this->db_functions->get_sambadomains_list(); |
---|
| 205 | $sambadomainname_options = ''; |
---|
| 206 | if (count($a_sambadomains)) |
---|
| 207 | { |
---|
| 208 | foreach ($a_sambadomains as $a_sambadomain) |
---|
| 209 | { |
---|
| 210 | // So mostra os sambaDomainName do contexto do manager |
---|
[64] | 211 | if ($this->ldap_functions->exist_sambadomains($manager_contexts, $a_sambadomain['samba_domain_name'])) |
---|
[33] | 212 | $sambadomainname_options .= "<option value='" . $a_sambadomain['samba_domain_sid'] . "'>" . $a_sambadomain['samba_domain_name'] . "</option>"; |
---|
| 213 | } |
---|
| 214 | } |
---|
| 215 | } |
---|
| 216 | |
---|
[2] | 217 | // Seta variaveis utilizadas pelo tpl. |
---|
| 218 | $var = Array( |
---|
| 219 | 'color_bg1' => "#E8F0F0", |
---|
| 220 | 'color_bg2' => "#D3DCE3", |
---|
| 221 | 'type' => 'create_group', |
---|
| 222 | 'cn' => '', |
---|
| 223 | 'restrictionsOnGroup' => $this->current_config['expressoAdmin_restrictionsOnGroup'], |
---|
[33] | 224 | 'type' => 'create_group', |
---|
[2] | 225 | 'ldap_context' => $GLOBALS['phpgw_info']['server']['ldap_context'], |
---|
[46] | 226 | 'ufn_ldap_context' => ldap_dn2ufn($GLOBALS['phpgw_info']['server']['ldap_context']), |
---|
| 227 | 'concatenateDomain' => $this->current_config['expressoAdmin_concatenateDomain'], |
---|
| 228 | 'defaultDomain' => $this->current_config['expressoAdmin_defaultDomain'], |
---|
[309] | 229 | 'apps' => $apps, |
---|
[33] | 230 | 'use_attrs_samba_checked' => '', |
---|
| 231 | 'disabled_samba' => 'disabled', |
---|
| 232 | 'display_samba_options' => $this->current_config['expressoAdmin_samba_support'] == 'true' ? '' : '"display:none"', |
---|
[64] | 233 | 'disable_email_groups' => $this->functions->check_acl($manager_lid,'edit_email_groups') ? '' : 'disabled', |
---|
[33] | 234 | 'sambadomainname_options' => $sambadomainname_options, |
---|
[2] | 235 | 'back_url' => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uigroups.list_groups'), |
---|
| 236 | 'combo_manager_org' => $combo_manager_org, |
---|
[309] | 237 | 'combo_all_orgs' => $combo_all_orgs |
---|
[2] | 238 | ); |
---|
| 239 | $p->set_var($var); |
---|
[414] | 240 | $p->set_var($this->functions->make_dinamic_lang($p, 'list')); |
---|
| 241 | |
---|
[2] | 242 | $p->pfp('out','create_group'); |
---|
| 243 | } |
---|
| 244 | |
---|
| 245 | function edit_groups() |
---|
| 246 | { |
---|
[64] | 247 | $manager_lid = $GLOBALS['phpgw']->accounts->data['account_lid']; |
---|
| 248 | $manager_acl = $this->functions->read_acl($manager_lid); |
---|
| 249 | $manager_contexts = $manager_acl['contexts']; |
---|
| 250 | |
---|
[2] | 251 | // Verifica se tem acesso a este modulo |
---|
[64] | 252 | if (!$this->functions->check_acl($manager_lid,'edit_groups')) |
---|
[2] | 253 | { |
---|
| 254 | $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php')); |
---|
| 255 | } |
---|
| 256 | |
---|
| 257 | // GET all infomations about the group. |
---|
[64] | 258 | $group_info = $this->group->get_info($_GET['gidnumber']); |
---|
[2] | 259 | |
---|
| 260 | unset($GLOBALS['phpgw_info']['flags']['noheader']); |
---|
| 261 | unset($GLOBALS['phpgw_info']['flags']['nonavbar']); |
---|
[309] | 262 | $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Edit Group'); |
---|
[2] | 263 | $GLOBALS['phpgw']->common->phpgw_header(); |
---|
| 264 | |
---|
| 265 | // Set o template |
---|
| 266 | $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL); |
---|
| 267 | $p->set_file(Array('create_group' => 'groups_form.tpl')); |
---|
[414] | 268 | $p->set_block('create_group','list','list'); |
---|
[2] | 269 | |
---|
[180] | 270 | // Obtem combo das organizações e seleciona a org do grupo. |
---|
[64] | 271 | foreach ($manager_contexts as $index=>$context) |
---|
| 272 | $combo_manager_org .= $this->functions->get_organizations($context, trim(strtolower($group_info['context']))); |
---|
[23] | 273 | $combo_all_orgs = $this->functions->get_organizations($GLOBALS['phpgw_info']['server']['ldap_context'], trim(strtolower($group_info['context']))); |
---|
[2] | 274 | |
---|
| 275 | // Usuarios do grupo. |
---|
[24] | 276 | $user_count = 0; |
---|
[2] | 277 | if (count($group_info['memberuid_info']) > 0) |
---|
| 278 | { |
---|
[24] | 279 | foreach ($group_info['memberuid_info'] as $uid=>$user_data) |
---|
[2] | 280 | { |
---|
[283] | 281 | if ($user_data['uidnumber']) |
---|
| 282 | { |
---|
[309] | 283 | $array_users[$user_data['uidnumber']] = $user_data['cn']; |
---|
| 284 | $array_users_uid[$user_data['uidnumber']] = $uid; |
---|
| 285 | $array_users_type[$user_data['uidnumber']] = $user_data['type']; |
---|
| 286 | } |
---|
[283] | 287 | else |
---|
| 288 | { |
---|
| 289 | $array_users[$uid] = $user_data['cn']; |
---|
| 290 | } |
---|
| 291 | } |
---|
[2] | 292 | natcasesort($array_users); |
---|
[283] | 293 | |
---|
[2] | 294 | foreach ($array_users as $uidnumber=>$cn) |
---|
| 295 | { |
---|
[7655] | 296 | ++$user_count; |
---|
[24] | 297 | if ($array_users_type[$uidnumber] == 'u') |
---|
| 298 | { |
---|
[5133] | 299 | $users .= "<option value=" . $uidnumber . ">" . utf8_decode($cn) . " (" . $array_users_uid[$uidnumber] . ")</option>"; |
---|
[24] | 300 | } |
---|
[5133] | 301 | /* else |
---|
[24] | 302 | { |
---|
[5133] | 303 | $unknow .= "<option value=-1>" . utf8_decode($cn) . " (Corrigir manualmente)</option>"; |
---|
| 304 | }*/ |
---|
[2] | 305 | } |
---|
[24] | 306 | |
---|
[493] | 307 | $opt_tmp_users = '<option value="-1" disabled>----------------------------- '.lang('users').' ---------------------------- </option>'."\n"; |
---|
| 308 | $opt_tmp_unknow = '<option value="-1" disabled>------------ '.lang('users did not find on DB, only on ldap').' ------------</option>'."\n"; |
---|
[24] | 309 | $ea_select_usersInGroup = $unknow != '' ? $opt_tmp_unknow . $unknow . $opt_tmp_users . $users : $opt_tmp_users . $users; |
---|
[2] | 310 | } |
---|
| 311 | |
---|
| 312 | // Chama funcao para criar lista de aplicativos disponiveis. |
---|
[64] | 313 | $apps = $this->functions->make_list_app($manager_lid, $group_info['apps']); |
---|
[2] | 314 | |
---|
[33] | 315 | // Cria combo de dominios do samba |
---|
| 316 | if ($this->current_config['expressoAdmin_samba_support'] == 'true') |
---|
| 317 | { |
---|
| 318 | $a_sambadomains = $this->db_functions->get_sambadomains_list(); |
---|
| 319 | $sambadomainname_options = ''; |
---|
| 320 | if (count($a_sambadomains)) |
---|
| 321 | { |
---|
| 322 | foreach ($a_sambadomains as $a_sambadomain) |
---|
| 323 | { |
---|
| 324 | if ($a_sambadomain['samba_domain_sid'] == $group_info['sambasid']) |
---|
| 325 | $sambadomainname_options .= "<option value='" . $a_sambadomain['samba_domain_sid'] . "' SELECTED>" . $a_sambadomain['samba_domain_name'] . "</option>"; |
---|
| 326 | else |
---|
| 327 | $sambadomainname_options .= "<option value='" . $a_sambadomain['samba_domain_sid'] . "'>" . $a_sambadomain['samba_domain_name'] . "</option>"; |
---|
| 328 | } |
---|
| 329 | } |
---|
| 330 | } |
---|
| 331 | |
---|
[2] | 332 | // Seta variaveis utilizadas pelo tpl. |
---|
| 333 | $var = Array( |
---|
[309] | 334 | 'color_bg1' => "#E8F0F0", |
---|
| 335 | 'color_bg2' => "#D3DCE3", |
---|
| 336 | 'type' => 'edit_group', |
---|
| 337 | 'ldap_context' => $GLOBALS['phpgw_info']['server']['ldap_context'], |
---|
[2] | 338 | 'gidnumber' => $group_info['gidnumber'], |
---|
| 339 | 'cn' => $group_info['cn'], |
---|
[24] | 340 | 'user_count' => $user_count, |
---|
[46] | 341 | 'email' => $group_info['email'], |
---|
[2] | 342 | 'description' => $group_info['description'], |
---|
| 343 | 'apps' => $apps, |
---|
| 344 | 'use_attrs_samba_checked' => $group_info['sambaGroup'] ? 'CHECKED' : '', |
---|
[33] | 345 | 'disabled_samba' => $group_info['sambaGroup'] ? '' : 'disabled', |
---|
[64] | 346 | 'disable_email_groups' => $this->functions->check_acl($manager_lid,'edit_email_groups') ? '' : 'disabled', |
---|
[33] | 347 | 'sambadomainname_options' => $sambadomainname_options, |
---|
[23] | 348 | 'phpgwaccountvisible_checked' => $group_info['phpgwaccountvisible'] == '-1' ? 'CHECKED' : '', |
---|
[2] | 349 | 'back_url' => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uigroups.list_groups'), |
---|
| 350 | 'combo_manager_org' => $combo_manager_org, |
---|
| 351 | 'combo_all_orgs' => $combo_all_orgs, |
---|
[309] | 352 | 'ea_select_usersInGroup' => $ea_select_usersInGroup |
---|
[2] | 353 | ); |
---|
| 354 | $p->set_var($var); |
---|
[414] | 355 | $p->set_var($this->functions->make_dinamic_lang($p, 'list')); |
---|
[2] | 356 | $p->pfp('out','create_group'); |
---|
| 357 | } |
---|
| 358 | |
---|
| 359 | function row_action($action,$type,$gidnumber,$group_name) |
---|
| 360 | { |
---|
| 361 | return '<a href="'.$GLOBALS['phpgw']->link('/index.php',Array( |
---|
| 362 | 'menuaction' => 'expressoAdmin1_2.uigroups.'.$action.'_'.$type, |
---|
| 363 | 'gidnumber' => $gidnumber, |
---|
| 364 | 'group_name' => $group_name |
---|
| 365 | )).'"> '.lang($action).' </a>'; |
---|
| 366 | } |
---|
| 367 | |
---|
| 368 | function css() |
---|
| 369 | { |
---|
| 370 | $appCSS = ''; |
---|
| 371 | return $appCSS; |
---|
| 372 | } |
---|
| 373 | |
---|
| 374 | } |
---|
| 375 | ?> |
---|