True,
'list_users' => True,
'add_group' => True,
'add_user' => True,
'delete_group' => True,
'delete_user' => True,
'edit_user' => True,
'edit_user_hook' => True,
'edit_group' => True,
'view_user' => True,
'edit_view_user_hook' => True,
'group_manager' => True,
);
var $bo;
var $nextmatchs;
var $apps_with_acl = array(
'addressbook' => True,
'todo' => True,
'calendar' => True,
'notes' => True,
'projects' => True,
'phonelog' => True,
'infolog' => True,
'filemanager' => True,
'tts' => True,
'bookmarks' => True,
'img' => True,
'netsaint' => True,
'inv' => True,
'phpbrain' => True,
);
function uiaccounts()
{
$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('/admin/index.php'));
}
$GLOBALS['cd'] = ($_GET['cd']?$_GET['cd']:0);
if(isset($_POST['query']))
{
// limit query to limit characters
if(preg_match('/^[a-z_0-9]+$/i',$_POST['query']))
$GLOBALS['query'] = $_POST['query'];
}
if(isset($_POST['start']))
{
$start = (int)$_POST['start'];
}
else
{
$start = 0;
}
switch($_GET['order'])
{
case 'account_lid':
$order = $_GET['order'];
break;
default:
$order = 'account_lid';
break;
}
switch($_GET['sort'])
{
case 'ASC':
case 'DESC':
$sort = $_GET['sort'];
break;
default:
$sort = 'ASC';
break;
}
unset($GLOBALS['phpgw_info']['flags']['noheader']);
unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
if(!@is_object($GLOBALS['phpgw']->js))
{
$GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript');
}
$GLOBALS['phpgw']->js->validate_file('jscode','openwindow','admin');
$GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['admin']['title'].' - '.
lang('User groups');
$GLOBALS['phpgw']->common->phpgw_header();
$p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
$p->set_file(
array(
'groups' => 'groups.tpl'
)
);
$p->set_block('groups','list','list');
$p->set_block('groups','row','row');
$p->set_block('groups','row_empty','row_empty');
if (! $GLOBALS['phpgw']->acl->check('account_access',2,'admin'))
{
$account_info = $GLOBALS['phpgw']->accounts->get_list('groups',$start,$sort, $order, $GLOBALS['query']);
}
else
{
$account_info = $GLOBALS['phpgw']->accounts->get_list('groups',$start,$sort, $order);
}
$total = $GLOBALS['phpgw']->accounts->total;
$var = Array(
'th_bg' => $GLOBALS['phpgw_info']['theme']['th_bg'],
'left_next_matchs' => $this->nextmatchs->left('/index.php',$start,$total,'menuaction=admin.uiaccounts.list_groups'),
'right_next_matchs' => $this->nextmatchs->right('/index.php',$start,$total,'menuaction=admin.uiaccounts.list_groups'),
'lang_groups' => lang('%1 - %2 of %3 user groups',$start+1,$start+count($account_info),$total),
'sort_name' => $this->nextmatchs->show_sort_order($sort,'account_lid',$order,'/index.php',lang('name'),'menuaction=admin.uiaccounts.list_groups'),
'header_edit' => lang('Edit'),
'header_delete' => lang('Delete')
);
$p->set_var($var);
if (!count($account_info) || !$total)
{
$p->set_var('message',lang('No matches found'));
$p->parse('rows','row_empty',True);
}
else
{
if (! $GLOBALS['phpgw']->acl->check('group_access',8,'admin'))
{
$can_view = True;
}
if (! $GLOBALS['phpgw']->acl->check('group_access',16,'admin'))
{
$can_edit = True;
}
if (! $GLOBALS['phpgw']->acl->check('group_access',32,'admin'))
{
$can_delete = True;
}
foreach($account_info as $account)
{
$tr_color = $this->nextmatchs->alternate_row_color($tr_color);
$var = Array(
'tr_color' => $tr_color,
'group_name' => (!$account['account_lid']?' ':$account['account_lid']),
'delete_link' => $this->row_action('delete','group',$account['account_id'])
);
$p->set_var($var);
if ($can_edit)
{
$p->set_var('edit_link',$this->row_action('edit','group',$account['account_id']));
}
else
{
$p->set_var('edit_link',' ');
}
if ($can_delete)
{
$p->set_var('delete_link',$this->row_action('delete','group',$account['account_id']));
}
else
{
$p->set_var('delete_link',' ');
}
$p->fp('rows','row',True);
}
}
$var = Array(
'new_action' => $GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiaccounts.add_group'),
'search_action' => $GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiaccounts.list_groups')
);
$p->set_var($var);
if (! $GLOBALS['phpgw']->acl->check('group_access',4,'admin'))
{
$p->set_var('input_add','');
}
if (! $GLOBALS['phpgw']->acl->check('group_access',2,'admin'))
{
$p->set_var('input_search',lang('Search') . ' ');
}
$p->pfp('out','list');
}
function list_users($param_cd='')
{
if ($GLOBALS['phpgw']->acl->check('account_access',1,'admin'))
{
$GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/admin/index.php'));
}
if (!is_object($GLOBALS['phpgw']->html))
{
$GLOBALS['phpgw']->html = CreateObject('phpgwapi.html');
}
if($param_cd)
{
$cd = $param_cd;
}
if(isset($_REQUEST['query']))
{
// limit query to limit characters
if(preg_match('/^[a-z_0-9]+$/i',$_REQUEST['query']))
$GLOBALS['query'] = $_REQUEST['query'];
}
if(isset($_REQUEST['start']))
{
$start = (int)$_REQUEST['start'];
}
else
{
$start = 0;
}
switch($_REQUEST['order'])
{
case 'account_lastname':
case 'account_firstname':
case 'account_lid':
case 'account_email':
$order = $_REQUEST['order'];
break;
default:
$order = 'account_lid';
break;
}
switch($_REQUEST['sort'])
{
case 'ASC':
case 'DESC':
$sort = $_REQUEST['sort'];
break;
default:
$sort = 'ASC';
break;
}
unset($GLOBALS['phpgw_info']['flags']['noheader']);
unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
if(!@is_object($GLOBALS['phpgw']->js))
{
$GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript');
}
$GLOBALS['phpgw']->js->validate_file('jscode','openwindow','admin');
$GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['admin']['title'].' - '.
lang('User accounts');
$GLOBALS['phpgw']->common->phpgw_header();
$p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
$p->set_file(
Array(
'list' => 'accounts.tpl'
)
);
$p->set_block('list','row','rows');
$p->set_block('list','row_empty','row_empty');
$p->set_block('list','letter_search','letter_search_cells');
$search_param = array(
'type' => (int)$_REQUEST['group_id'] > 0 ? $_REQUEST['group_id'] : 'accounts',
'start' => $start,
'sort' => $sort,
'order' => $order,
'query_type' => $_REQUEST['query_type'],
);
if (!$GLOBALS['phpgw']->acl->check('account_access',2,'admin'))
{
$search_param['query'] = $GLOBALS['query'];
}
$account_info = $GLOBALS['phpgw']->accounts->search($search_param);
$total = $GLOBALS['phpgw']->accounts->total;
$link_data = array(
'menuaction' => 'admin.uiaccounts.list_users',
'group_id' => $_REQUEST['group_id'],
'query_type' => $_REQUEST['query_type'],
);
$uiaccountsel = CreateObject('phpgwapi.uiaccountsel');
$p->set_var(array(
'left_next_matchs' => $this->nextmatchs->left('/index.php',$start,$total,$link_data),
'lang_showing' => ($_REQUEST['group_id'] ? $GLOBALS['phpgw']->common->grab_owner_name($_REQUEST['group_id']).': ' : '').
($GLOBALS['query'] ? lang("Search %1 '%2'",lang($uiaccountsel->query_types[$_REQUEST['query_type']]),$GLOBALS['query']).': ' : '')
.$this->nextmatchs->show_hits($total,$start),
'right_next_matchs' => $this->nextmatchs->right('/index.php',$start,$total,$link_data),
'lang_loginid' => $this->nextmatchs->show_sort_order($sort,'account_lid',$order,'/index.php',lang('LoginID'),$link_data),
'lang_lastname' => $this->nextmatchs->show_sort_order($sort,'account_lastname',$order,'/index.php',lang('last name'),$link_data),
'lang_firstname' => $this->nextmatchs->show_sort_order($sort,'account_firstname',$order,'/index.php',lang('first name'),$link_data),
'lang_email' => $this->nextmatchs->show_sort_order($sort,'account_email',$order,'/index.php',lang('email'),$link_data),
'lang_edit' => lang('edit'),
'lang_delete' => lang('delete'),
'lang_view' => lang('view'),
'lang_search' => lang('search')
));
$link_data += array(
'order' => $order,
'sort' => $sort,
);
$p->set_var(array(
'query_type' => is_array($uiaccountsel->query_types) ? $GLOBALS['phpgw']->html->select('query_type',$_REQUEST['query_type'],$uiaccountsel->query_types) : '',
'lang_group' => lang('group'),
'group' => $uiaccountsel->selection('group_id','admin_uiaccount_listusers_group_id',$_REQUEST['group_id'],'groups',0,False,'','this.form.submit();',lang('all')),
'accounts_url' => $GLOBALS['phpgw']->link('/index.php',$link_data),
));
$letters = lang('alphabet');
$letters = explode(',',substr($letters,-1) != '*' ? $letters : 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z');
$link_data['query_type'] = 'start';
foreach($letters as $letter)
{
$link_data['query'] = $letter;
$p->set_var(array(
'letter' => $letter,
'link' => $GLOBALS['phpgw']->link('/index.php',$link_data),
'class' => $GLOBALS['query'] == $letter && $_REQUEST['query_type'] == 'start' ? 'letter_box_active' : 'letter_box',
));
$p->fp('letter_search_cells','letter_search',True);
}
unset($link_data['query']);
unset($link_data['query_type']);
$p->set_var(array(
'letter' => lang('all'),
'link' => $GLOBALS['phpgw']->link('/index.php',$link_data),
'class' => $_REQUEST['query_type'] != 'start' || !in_array($GLOBALS['query'],$letters) ? 'letter_box_active' : 'letter_box',
));
$p->fp('letter_search_cells','letter_search',True);
if (! $GLOBALS['phpgw']->acl->check('account_access',4,'admin'))
{
$p->set_var('new_action',$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiaccounts.add_user'));
$p->set_var('input_add','');
}
if (!count($account_info) || !$total)
{
$p->set_var('message',lang('No matches found'));
$p->parse('rows','row_empty',True);
}
else
{
if (! $GLOBALS['phpgw']->acl->check('account_access',8,'admin'))
{
$can_view = True;
}
if (! $GLOBALS['phpgw']->acl->check('account_access',16,'admin'))
{
$can_edit = True;
}
if (! $GLOBALS['phpgw']->acl->check('account_access',32,'admin'))
{
$can_delete = True;
}
foreach($account_info as $account)
{
$p->set_var('class',$this->nextmatchs->alternate_row_color('',True));
$p->set_var($account);
if ($can_edit)
{
$p->set_var('row_edit',$this->row_action('edit','user',$account['account_id']));
}
else
{
$p->set_var('row_edit',' ');
}
if ($can_delete)
{
$p->set_var('row_delete',($GLOBALS['phpgw_info']['user']['userid'] != $account['account_lid']?$this->row_action('delete','user',$account['account_id']):' '));
}
else
{
$p->set_var('row_delete',' ');
}
if ($can_view)
{
$p->set_var('row_view',$this->row_action('view','user',$account['account_id']));
}
else
{
$p->set_var('row_view',' ');
}
$p->parse('rows','row',True);
}
} // End else
$p->pfp('out','list');
}
function add_group()
{
if ($GLOBALS['phpgw']->acl->check('group_access',4,'admin'))
{
$this->list_groups();
return False;
}
$group_info = Array(
'account_id' => $_GET['account_id'],
'account_name' => '',
'account_user' => Array(),
'account_apps' => Array()
);
$this->create_edit_group($group_info);
}
function add_user()
{
if ($GLOBALS['phpgw']->acl->check('account_access',4,'admin'))
{
$this->list_users();
}
else
{
$this->create_edit_user(0);
}
}
function delete_group()
{
if ($_POST['no'] || $_POST['yes'] || !@isset($_GET['account_id']) || !@$_GET['account_id'] || $GLOBALS['phpgw']->acl->check('group_access',32,'admin'))
{
if ($_POST['yes'])
{
$this->bo->delete_group();
}
$this->list_groups();
return False;
}
unset($GLOBALS['phpgw_info']['flags']['noheader']);
unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
if(!@is_object($GLOBALS['phpgw']->js))
{
$GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript');
}
$GLOBALS['phpgw']->js->validate_file('jscode','openwindow','admin');
$GLOBALS['phpgw']->common->phpgw_header();
$p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
$p->set_file(
Array(
'body' => 'delete_common.tpl',
'message_row' => 'message_row.tpl',
'form_button' => 'form_button_script.tpl'
)
);
$p->set_var('message_display',lang('Are you sure you want to delete this group ?'));
$p->parse('messages','message_row');
$old_group_list = $GLOBALS['phpgw']->acl->get_ids_for_location((int)$_GET['account_id'],1,'phpgw_group');
if($old_group_list)
{
$group_name = $GLOBALS['phpgw']->accounts->id2name($_GET['account_id']);
$p->set_var('message_display','
');
$p->parse('messages','message_row',True);
$user_list = '';
while (list(,$id) = each($old_group_list))
{
$user_list .= '' . $GLOBALS['phpgw']->common->grab_owner_name($id) . '
';
}
$p->set_var('message_display',$user_list);
$p->parse('messages','message_row',True);
$p->set_var('message_display',lang("Sorry, the above users are still a member of the group %1",$group_name)
. '.
' . lang('They must be removed before you can continue'). '.
' . lang('Remove all users from this group').'?');
$p->parse('messages','message_row',True);
}
$var = Array(
'form_action' => $GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiaccounts.delete_group'),
'hidden_vars' => '',
'yes' => lang('Yes'),
'no' => lang('No')
);
$p->set_var($var);
/*
$p->parse('yes','form_button');
$var = Array(
'submit_button' => lang('Submit'),
'action_url_button' => $GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiaccounts.list_groups'),
'action_text_button' => ' '.lang('No'),
'action_confirm_button' => '',
'action_extra_field' => ''
);
$p->set_var($var);
$p->parse('no','form_button');
*/
$p->pparse('phpgw_body','body');
}
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']);
if(!@is_object($GLOBALS['phpgw']->js))
{
$GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript');
}
$GLOBALS['phpgw']->js->validate_file('jscode','openwindow','admin');
$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($cd='',$account_id='')
{
if ($GLOBALS['phpgw']->acl->check('group_access',16,'admin'))
{
$this->list_groups();
return False;
}
$cdid = $cd;
settype($cd,'integer');
$cd = ($_GET['cd']?$_GET['cd']:(int)$cdid);
$accountid = $account_id;
settype($account_id,'integer');
$account_id = ($_GET['account_id'] ? $_GET['account_id'] : (int)$accountid);
// todo
// not needed if i use the same file for new groups too
if (! $account_id)
{
$this->list_groups();
}
else
{
$group_info = Array(
'account_id' => (int)$_GET['account_id'],
'account_name' => $GLOBALS['phpgw']->accounts->id2name($_GET['account_id']),
'account_user' => $this->bo->load_group_users($_GET['account_id']),
'account_apps' => $this->bo->load_group_apps($_GET['account_id'])
);
$this->create_edit_group($group_info);
}
}
function edit_view_user_hook()
{
if (!$GLOBALS['phpgw']->acl->check('current_sessions_access',1,'admin')) // no rights to view
{
$GLOBALS['menuData'][] = array(
'description' => 'Login History',
'url' => '/index.php',
'extradata' => 'menuaction=admin.uiaccess_history.list_history'
);
}
// not sure if this realy belongs here, or only in edit_user
if ($_GET['account_id'] && // can't set it on add
!$GLOBALS['phpgw']->acl->check('account_access',64,'admin')) // no rights to set ACL-rights
{
$GLOBALS['menuData'][] = array(
'description' => 'ACL Rights',
'url' => '/index.php',
'extradata' => 'menuaction=admin.uiaclmanager.list_apps'
);
}
}
function edit_user($cd='',$account_id='')
{
if ($GLOBALS['phpgw']->acl->check('account_access',16,'admin'))
{
$this->list_users();
return False;
}
$cdid = $cd;
settype($cd,'integer');
$cd = ($_GET['cd']?$_GET['cd']:(int)$cdid);
$accountid = $account_id;
settype($account_id,'integer');
$account_id = (int)($_GET['account_id'] ? $_GET['account_id'] : $accountid);
// todo
// not needed if i use the same file for new users too
if (! $account_id)
{
$this->list_users();
return False;
}
else
{
$this->create_edit_user($account_id);
}
}
function view_user()
{
if ($GLOBALS['phpgw']->acl->check('account_access',8,'admin') || ! $_GET['account_id'])
{
$this->list_users();
return False;
}
unset($GLOBALS['phpgw_info']['flags']['noheader']);
unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
if(!@is_object($GLOBALS['phpgw']->js))
{
$GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript');
}
$GLOBALS['phpgw']->js->validate_file('jscode','openwindow','admin');
$GLOBALS['phpgw']->common->phpgw_header();
$t = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
$t->set_unknowns('remove');
$t->set_file(
Array(
'account' => 'account_form.tpl'
)
);
$t->set_block('account','form','form');
$t->set_block('account','form_logininfo');
$t->set_block('account','link_row');
$var = Array(
'th_bg' => $GLOBALS['phpgw_info']['theme']['th_bg'],
'tr_color1' => $GLOBALS['phpgw_info']['theme']['row_on'],
'tr_color2' => $GLOBALS['phpgw_info']['theme']['row_off'],
'lang_action' => lang('View user account'),
'lang_loginid' => lang('LoginID'),
'lang_account_active' => lang('Account active'),
'lang_lastname' => lang('Last Name'),
'lang_groups' => lang('Groups'),
'lang_anonymous' => lang('Anonymous user (not shown in list sessions)'),
'lang_changepassword'=> lang('Can change password'),
'lang_firstname' => lang('First Name'),
'lang_lastlogin' => lang('Last login'),
'lang_lastloginfrom' => lang('Last login from'),
'lang_expires' => lang('Expires')
);
$t->parse('password_fields','form_logininfo',True);
$account = CreateObject('phpgwapi.accounts',(int)$_GET['account_id'],'u');
$userData = $account->read_repository();
$var['account_lid'] = $userData['account_lid'];
$var['account_firstname'] = $userData['firstname'];
$var['account_lastname'] = $userData['lastname'];
$acl = CreateObject('phpgwapi.acl',(int)$_GET['account_id']);
$var['anonymous'] = $acl->check('anonymous',1,'phpgwapi') ? ' X' : ' ';
$var['changepassword'] = $acl->check('changepassword',0xFFFF,'preferences') ? ' X' : ' ';
unset($acl);
if ($userData['status'])
{
$var['account_status'] = lang('Enabled');
}
else
{
$var['account_status'] = '' . lang('Disabled') . '';
}
// Last login time
if ($userData['lastlogin'])
{
$var['account_lastlogin'] = $GLOBALS['phpgw']->common->show_date($userData['lastlogin']);
}
else
{
$var['account_lastlogin'] = lang('Never');
}
// Last login IP
if ($userData['lastloginfrom'])
{
$var['account_lastloginfrom'] = $userData['lastloginfrom'];
}
else
{
$var['account_lastloginfrom'] = lang('Never');
}
// Account expires
if ($userData['expires'] != -1)
{
$var['input_expires'] = $GLOBALS['phpgw']->common->show_date($userData['expires']);
}
else
{
$var['input_expires'] = lang('Never');
}
// Find out which groups they are members of
$usergroups = $account->membership((int)$_GET['account_id']);
if(!@is_array($usergroups))
{
$var['groups_select'] = lang('None');
}
else
{
while (list(,$group) = each($usergroups))
{
$group_names[] = $group['account_name'];
}
$var['groups_select'] = implode(', ',$group_names);
}
$account_lastlogin = $userData['account_lastlogin'];
$account_lastloginfrom = $userData['account_lastloginfrom'];
$account_status = $userData['account_status'];
// create list of available app
$i = 0;
$availableApps = $GLOBALS['phpgw_info']['apps'];
@asort($availableApps);
@reset($availableApps);
foreach($availableApps as $app => $data)
{
if ($data['enabled'] && $data['status'] != 2)
{
$perm_display[$i]['appName'] = $app;
$perm_display[$i]['title'] = $data['title'];
++$i;
}
}
// create apps output
$apps = CreateObject('phpgwapi.applications',(int)$_GET['account_id']);
$db_perms = $apps->read_account_specific();
@reset($db_perms);
$perm_display_count = count($perm_display);
for ($i=0;$i<$perm_display_count;++$i)
{
if ($perm_display[$i]['title'])
{
$part1 = sprintf("