* * ----------------------------------------------------- * * This program is free software; you can redistribute it and/or modify it * * under the terms of the GNU General Public License as published by the * * Free Software Foundation; either version 2 of the License, or (at your * * option) any later version. * \**************************************************************************/ /* $Id$ */ class uiaccounts { var $public_functions = array ( 'list_groups' => True, 'list_users' => True, 'add_group' => True, 'add_user' => True, 'delete_group' => True, 'delete_user' => True, 'edit_user' => True, 'edit_group' => True, 'view_user' => True, 'group_manager' => True ); var $bo; var $nextmatchs; function uiaccounts() { $GLOBALS['phpgw_info']['flags']['xslt_app'] = True; $this->bo = createobject('admin.boaccounts'); $this->nextmatchs = createobject('phpgwapi.nextmatchs'); @set_time_limit(300); } function row_action($action,$type,$account_id) { return ' '.lang($action).' '; } function list_groups() { if ($GLOBALS['phpgw']->acl->check('group_access',1,'admin')) { $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/index.php','menuaction=admin.uimainscreen.mainscreen')); } $query = (isset($_POST['query'])?$_POST['query']:''); $GLOBALS['cd'] = ($_GET['cd']?$_GET['cd']:0); $GLOBALS['phpgw_info']['flags']['app_header'] = lang('administration') . ': ' . lang('list groups'); $GLOBALS['phpgw']->xslttpl->add_file(array('app_data','groups', $GLOBALS['phpgw']->common->get_tpl_dir('phpgwapi','default') . SEP . 'search_field', $GLOBALS['phpgw']->common->get_tpl_dir('phpgwapi','default') . SEP . 'nextmatchs')); /* what should this be for??? this is the same call for both cases! can this be removed? [ceb] */ if ($GLOBALS['phpgw']->acl->check('group_access',2,'admin')) { $account_info = $GLOBALS['phpgw']->accounts->get_list('groups',$start,$sort, $order, $query, $total); $total = $GLOBALS['phpgw']->accounts->total; } else { $account_info = $GLOBALS['phpgw']->accounts->get_list('groups',$start,$sort, $order, $query, $total); $total = $GLOBALS['phpgw']->accounts->total; } $group_header = array ( 'sort_name' => $this->nextmatchs->show_sort_order(array ( 'sort' => $sort, 'var' => 'account_lid', 'order' => $order, 'extra' => 'menuaction=admin.uiaccounts.list_groups' )), 'lang_name' => lang('name'), 'lang_edit' => lang('edit'), 'lang_delete' => lang('delete'), 'lang_sort_statustext' => lang('sort the entries') ); while (list($null,$account) = each($account_info)) { $group_data[] = Array ( 'edit_url' => ($this->bo->check_rights('edit')?$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiaccounts.edit_group&account_id=' . $account['account_id']):''), 'lang_edit' => ($this->bo->check_rights('edit')?lang('edit'):''), 'lang_edit_statustext' => ($this->bo->check_rights('edit')?lang('edit this group'):''), 'group_name' => (!$account['account_lid']?'':$account['account_lid']), 'delete_url' => ($this->bo->check_rights('delete')?$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiaccounts.delete_group&account_id=' . $account['account_id']):''), 'lang_delete_statustext' => ($this->bo->check_rights('delete')?lang('delete this group'):''), 'lang_delete' => ($this->bo->check_rights('delete')?lang('delete'):'') ); } $group_add = array ( 'lang_add' => lang('add'), 'lang_add_statustext' => lang('add a group'), 'add_url' => $GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiaccounts.edit_group'), 'lang_done' => lang('done'), 'lang_done_statustext' => lang('return to admin mainscreen'), 'done_url' => $GLOBALS['phpgw']->link('/index.php','menuaction=admin.uimainscreen.mainscreen'), 'add_access' => ($this->bo->check_rights('add')?'yes':''), ); $data = array ( 'start_record' => $start, 'record_limit' => $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'], 'num_records' => count($account_info), 'all_records' => $total, 'nextmatchs_url' => $GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiaccounts.list_groups'), 'nextmatchs_img_path' => $GLOBALS['phpgw']->common->get_image_path('phpgwapi','default'), 'select_url' => $GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiaccounts.list_groups'), 'lang_searchfield_statustext' => lang('Enter the search string. To show all entries, empty this field and press the SUBMIT button again'), 'lang_searchbutton_statustext' => lang('Submit the search string'), 'query' => $query, 'lang_search' => lang('search'), 'group_header' => $group_header, 'group_data' => $group_data, 'group_add' => $group_add, 'search_access' => ($this->bo->check_rights('search')?'yes':'') ); $GLOBALS['phpgw']->xslttpl->set_var('phpgw',array('group_list' => $data)); } function list_users($param_cd='') { if ($GLOBALS['phpgw']->acl->check('account_access',1,'admin')) { $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/index.php','menuaction=admin.uimainscreen.mainscreen')); } if($param_cd) { $cd = $param_cd; } $GLOBALS['query'] = (isset($GLOBALS['HTTP_POST_VARS']['query'])?$GLOBALS['HTTP_POST_VARS']['query']:''); $start = (isset($GLOBALS['HTTP_POST_VARS']['start'])?intval($GLOBALS['HTTP_POST_VARS']['start']):''); if(isset($_GET['order'])) { $order = $_GET['order']; } else { $order = 'account_lid'; } if(isset($_GET['sort'])) { $sort = $_GET['sort']; } else { $sort = 'ASC'; } $GLOBALS['phpgw_info']['flags']['app_header'] = lang('administration') . ': ' . lang('list users'); $GLOBALS['phpgw']->xslttpl->add_file(array('app_data','users', $GLOBALS['phpgw']->common->get_tpl_dir('phpgwapi','default') . SEP . 'search_field', $GLOBALS['phpgw']->common->get_tpl_dir('phpgwapi','default') . SEP . 'nextmatchs')); /* the same like in groups... we really should remove this... :) [ceb] */ if ($GLOBALS['phpgw']->acl->check('account_access',2,'admin')) { $account_info = $GLOBALS['phpgw']->accounts->get_list('accounts',$start,$sort,$order,$GLOBALS['query'],$total); $total = $GLOBALS['phpgw']->accounts->total; } else { $account_info = $GLOBALS['phpgw']->accounts->get_list('accounts',$start,$sort,$order,$GLOBALS['query'],$total); $total = $GLOBALS['phpgw']->accounts->total; } $user_header = array ( 'sort_lid' => $this->nextmatchs->show_sort_order(array ( 'sort' => $sort, 'var' => 'account_lid', 'order' => $order, 'extra' => 'menuaction=admin.uiaccounts.list_users' )), 'lang_lid' => lang('loginid'), 'sort_lastname' => $this->nextmatchs->show_sort_order(array ( 'sort' => $sort, 'var' => 'account_lastname', 'order' => $order, 'extra' => 'menuaction=admin.uiaccounts.list_users' )), 'lang_lastname' => lang('Lastname'), 'sort_firstname' => $this->nextmatchs->show_sort_order(array ( 'sort' => $sort, 'var' => 'account_firstname', 'order' => $order, 'extra' => 'menuaction=admin.uiaccounts.list_users' )), 'lang_firstname' => lang('firstname'), 'lang_view' => lang('view'), 'lang_edit' => lang('edit'), 'lang_delete' => lang('delete'), 'lang_sort_statustext' => lang('sort the entries') ); while (list($null,$account) = each($account_info)) { $user_data[] = Array ( 'view_url' => ($this->bo->check_rights('view','account_access')?$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiaccounts.view_user&account_id=' . $account['account_id']):''), 'lang_view' => ($this->bo->check_rights('view','account_access')?lang('view'):''), 'lang_view_statustext' => ($this->bo->check_rights('view','account_access')?lang('view this user'):''), 'edit_url' => ($this->bo->check_rights('edit','account_access')?$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiaccounts.edit_user&account_id=' . $account['account_id']):''), 'lang_edit' => ($this->bo->check_rights('edit','account_access')?lang('edit'):''), 'lang_edit_statustext' => ($this->bo->check_rights('edit','account_access')?lang('edit this user'):''), 'lid' => (!$account['account_lid']?'':$account['account_lid']), 'firstname' => (!$account['account_firstname']?'':$account['account_firstname']), 'lastname' => (!$account['account_lastname']?'':$account['account_lastname']), 'delete_url' => ($this->bo->check_rights('delete','account_access')?$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiaccounts.delete_user&account_id=' . $account['account_id']):''), 'lang_delete_statustext' => ($this->bo->check_rights('delete','account_access')?lang('delete this user'):''), 'lang_delete' => ($this->bo->check_rights('delete','account_access')?lang('delete'):'') ); } $user_add = array ( 'lang_add' => lang('add'), 'lang_add_statustext' => lang('add a user'), 'add_url' => $GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiaccounts.edit_user'), 'lang_done' => lang('done'), 'lang_done_statustext' => lang('return to admin mainscreen'), 'done_url' => $GLOBALS['phpgw']->link('/index.php','menuaction=admin.uimainscreen.mainscreen'), 'add_access' => ($this->bo->check_rights('add','account_access')?'yes':''), ); $data = array ( 'start_record' => $start, 'record_limit' => $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'], 'num_records' => count($account_info), 'all_records' => $total, 'nextmatchs_url' => $GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiaccounts.list_users'), 'nextmatchs_img_path' => $GLOBALS['phpgw']->common->get_image_path('phpgwapi','default'), 'select_url' => $GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiaccounts.list_users'), 'lang_searchfield_statustext' => lang('Enter the search string. To show all entries, empty this field and press the SUBMIT button again'), 'lang_searchbutton_statustext' => lang('Submit the search string'), 'query' => $query, 'lang_search' => lang('search'), 'user_header' => $user_header, 'user_data' => $user_data, 'user_add' => $user_add, 'search_access' => ($this->bo->check_rights('search','account_access')?'yes':'') ); $GLOBALS['phpgw']->xslttpl->set_var('phpgw',array('account_list' => $data)); } function add_user() { if ($GLOBALS['phpgw']->acl->check('account_access',4,'admin')) { $this->list_users(); } else { $this->create_edit_user(0); } } function delete_group() { $account_id = get_var('account_id',array('POST','GET')); if ($GLOBALS['phpgw']->acl->check('group_access',32,'admin')) { $this->list_groups(); return False; } if ($account_id && get_var('confirm',array('POST'))) { $this->bo->delete_group($account_id); $this->list_groups(); return False; } $GLOBALS['phpgw']->xslttpl->add_file(array('app_data',$GLOBALS['phpgw']->common->get_tpl_dir('phpgwapi','default') . SEP . 'app_delete')); $GLOBALS['phpgw_info']['flags']['app_header'] = lang('administration') . ': ' . lang('delete group'); $data = array ( 'delete_url' => $GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiaccounts.delete_group&account_id=' . $account_id), 'done_url' => $GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiaccounts.list_groups'), 'lang_yes' => lang('Yes'), 'lang_no' => lang('No'), 'lang_yes_statustext' => lang('Delete the entry'), 'lang_no_statustext' => lang('Back to the list'), 'lang_error_msg' => lang('are you sure you want to delete this group ?') ); $old_group_list = $GLOBALS['phpgw']->acl->get_ids_for_location(intval($account_id),1,'phpgw_group'); if($old_group_list) { $group_name = $GLOBALS['phpgw']->accounts->id2name($account_id); $user_list = ''; while (list(,$id) = each($old_group_list)) { $data['user_list'][] = array ( 'user_url' => $GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiaccounts.edit_user&account_id=' . $id), 'user_name' => $GLOBALS['phpgw']->common->grab_owner_name($id), 'lang_user_url_statustext' => lang('edit user') ); } $data['lang_confirm_msg'] = lang('the users bellow are still members of group %1',$group_name) . '. ' . lang('they must be removed before you can continue'); $data['lang_remove_user'] = lang('Remove all users from this group ?'); } $GLOBALS['phpgw']->xslttpl->set_var('phpgw',array('delete' => $data)); } function delete_user() { if ($GLOBALS['phpgw']->acl->check('account_access',32,'admin') || $GLOBALS['phpgw_info']['user']['account_id'] == $_GET['account_id']) { $this->list_users(); return False; } unset($GLOBALS['phpgw_info']['flags']['noheader']); unset($GLOBALS['phpgw_info']['flags']['nonavbar']); $GLOBALS['phpgw']->common->phpgw_header(); $t = CreateObject('phpgwapi.Template',PHPGW_APP_TPL); $t->set_file( Array( 'form' => 'delete_account.tpl' ) ); $var = Array( 'form_action' => $GLOBALS['phpgw']->link('/index.php','menuaction=admin.boaccounts.delete_user'), 'account_id' => $_GET['account_id'] ); // the account can have special chars/white spaces, if it is a ldap dn $account_id = rawurlencode($_GET['account_id']); // Find out who the new owner is of the deleted users records... $users = $GLOBALS['phpgw']->accounts->get_list('accounts'); $c_users = count($users); $str = ''; for($i=0;$i<$c_users;$i++) { $str .= ''."\n"; } $var['lang_new_owner'] = lang('Who would you like to transfer ALL records owned by the deleted user to?'); $var['new_owner_select'] = ''."\n"; $var['cancel'] = lang('cancel'); $var['delete'] = lang('delete'); $t->set_var($var); $t->pparse('out','form'); } function edit_group() { $account_id = get_var('account_id',array('POST','GET')); $values = get_var('values',array('POST')); $account_user = get_var('account_user',array('POST')); $account_apps = get_var('account_apps',array('POST')); if ($values['save']) { $error = $this->bo->validate_group($values); if (is_array($error)) { } else { if (is_array($account_user)) { $values['account_user'] = $account_user; } if (is_array($account_apps)) { $values['account_apps'] = $account_apps; } if ($values['account_id']) { $this->bo->edit_group($values); $account_id = $values['account_id']; } else { $this->bo->add_group($values); Header('Location: ' . $GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiaccounts.list_groups')); } } } if (!$account_id && $GLOBALS['phpgw']->acl->check('group_access',4,'admin')) { $this->list_groups(); return False; } if ($account_id && $GLOBALS['phpgw']->acl->check('group_access',16,'admin')) { $this->list_groups(); return False; } $cdid = $cd; settype($cd,'integer'); $cd = ($_GET['cd']?$_GET['cd']:intval($cdid)); if ($account_id) { $group_info = Array ( 'account_name' => $GLOBALS['phpgw']->accounts->id2name($account_id), 'account_user' => $this->bo->load_group_users($account_id), 'account_apps' => $this->bo->load_group_apps($account_id) ); } $apps_with_acl = Array ( 'addressbook' => True, 'bookmarks' => True, 'calendar' => True, 'filemanager' => True, 'img' => True, 'infolog' => True, 'inv' => True, 'netsaint' => True, 'notes' => True, 'phonelog' => True, 'phpwebhosting' => True, 'projects' => True, 'todo' => True, 'tts' => True ); $GLOBALS['phpgw']->xslttpl->add_file(array('app_data','groups')); $GLOBALS['phpgw_info']['flags']['app_header'] = lang('administration') . ': ' . ((intval($account_id) > 0)?lang('edit group'):lang('add group')); $accounts = CreateObject('phpgwapi.accounts',$account_id,'u'); $account_list = $accounts->get_list('accounts'); $account_num = count($account_list); $user_list = ''; while (list($key,$entry) = each($account_list)) { $user_list[] = array ( 'account_id' => $entry['account_id'], 'account_name' => $GLOBALS['phpgw']->common->display_fullname($entry['account_lid'],$entry['account_firstname'], $entry['account_lastname']), 'selected' => $group_info['account_user'][intval($entry['account_id'])] ); } $group_repository = $accounts->read_repository(); if (!$group_repository['file_space']) { $group_repository['file_space'] = $GLOBALS['phpgw_info']['server']['vfs_default_account_size_number'] . "-" . $GLOBALS['phpgw_info']['server']['vfs_default_account_size_type']; } /* $file_space_array = explode ('-', $group_repository['file_space']); $account_file_space_types = array ('gb', 'mb', 'kb', 'b'); while (list ($num, $type) = each ($account_file_space_types)) { $account_file_space_select .= ''."\n"; } $p->set_var ('lang_file_space', lang('File space')); $p->set_var ('account_file_space', ''); $p->set_var ('account_file_space_select',''."\n"); */ reset($GLOBALS['phpgw_info']['apps']); $sorted_apps = $GLOBALS['phpgw_info']['apps']; @asort($sorted_apps); @reset($sorted_apps); while ($permission = each($sorted_apps)) { if ($permission[1]['enabled'] && $permission[1]['status'] != 3) { $perm_display[] = array ( $permission[0], $permission[1]['title'] ); } } /*$perm_html = '