This changes the user accounts over to an n-tier layout. Still needing to add the group accounts into these classes.

This commit is contained in:
skeeter 2001-09-01 23:32:40 +00:00
parent 9b07da7075
commit 2df316073d
5 changed files with 1062 additions and 10 deletions

View File

@ -0,0 +1,435 @@
<?php
/**************************************************************************\
* phpGroupWare - account administration *
* http://www.phpgroupware.org *
* -------------------------------------------- *
* 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. *
\**************************************************************************/
class boaccounts
{
var $public_functions = array(
'add_user' => True,
'delete_user' => True,
'edit_user' => True
);
var $so;
function boaccounts()
{
$this->so = createobject('admin.soaccounts');
}
function account_total($query)
{
return $this->so->account_total($query);
}
function delete_user()
{
if(isset($GLOBALS['HTTP_POST_VARS']['cancel']))
{
Header('Location: '.$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiaccounts.list_users'));
$GLOBALS['phpgw']->common->phpgw_exit();
}
elseif($GLOBALS['HTTP_POST_VARS']['delete_account'])
{
$accountid = $GLOBALS['HTTP_POST_VARS']['account_id'];
settype($account_id,'integer');
$account_id = get_account_id($accountid);
$lid = $GLOBALS['phpgw']->accounts->id2name($account_id);
$db = $GLOBALS['phpgw']->db;
$db->query('SELECT app_name,app_order FROM phpgw_applications WHERE app_enabled!=0 ORDER BY app_order',__LINE__,__FILE__);
if($db->num_rows())
{
while($db->next_record())
{
$appname = $db->f('app_name');
if($appname <> 'admin')
{
$GLOBALS['phpgw']->common->hook_single('deleteaccount', $appname);
}
}
}
$GLOBALS['phpgw']->common->hook_single('deleteaccount','preferences');
$GLOBALS['phpgw']->common->hook_single('deleteaccount','admin');
$basedir = $GLOBALS['phpgw_info']['server']['files_dir'] . SEP . 'users' . SEP;
if (! @rmdir($basedir . $lid))
{
$cd = 34;
}
else
{
$cd = 29;
}
Header('Location: ' . $GLOBALS['phpgw']->link('/index.php',
Array(
'menuaction' => 'admin.uiaccounts.list_users',
'cd' => $cd
)
)
);
$GLOBALS['phpgw']->common->phpgw_exit();
}
}
function add_user()
{
if ($GLOBALS['HTTP_POST_VARS']['submit'])
{
$userData = array(
'account_type' => 'u',
'account_lid' => $GLOBALS['HTTP_POST_VARS']['account_lid'],
'account_firstname' => $GLOBALS['HTTP_POST_VARS']['account_firstname'],
'account_lastname' => $GLOBALS['HTTP_POST_VARS']['account_lastname'],
'account_passwd' => $GLOBALS['HTTP_POST_VARS']['account_passwd'],
'account_status' => ($GLOBALS['HTTP_POST_VARS']['account_status']?$GLOBALS['HTTP_POST_VARS']['account_status']:''),
'old_loginid' => ($GLOBALS['HTTP_GET_VARS']['old_loginid']?rawurldecode($GLOBALS['HTTP_GET_VARS']['old_loginid']):''),
'account_id' => ($GLOBALS['HTTP_GET_VARS']['account_id']?$GLOBALS['HTTP_GET_VARS']['account_id']:0),
'account_passwd_2' => $GLOBALS['HTTP_POST_VARS']['account_passwd_2'],
'account_groups' => $GLOBALS['HTTP_POST_VARS']['account_groups'],
'account_permissions' => $GLOBALS['HTTP_POST_VARS']['account_permissions'],
'homedirectory' => $GLOBALS['HTTP_POST_VARS']['homedirectory'],
'loginshell' => $GLOBALS['HTTP_POST_VARS']['loginshell'],
'account_expires_month' => $GLOBALS['HTTP_POST_VARS']['account_expires_month'],
'account_expires_day' => $GLOBALS['HTTP_POST_VARS']['account_expires_day'],
'account_expires_year' => $GLOBALS['HTTP_POST_VARS']['account_expires_year']
/* 'file_space' => $GLOBALS['HTTP_POST_VARS']['account_file_space_number'] . "-" . $GLOBALS['HTTP_POST_VARS']['account_file_space_type'] */
);
if (!$errors = $this->validate_user($userData))
{
$userData['account_expires'] = $userData['expires'];
$GLOBALS['phpgw']->db->lock(
Array(
'phpgw_accounts',
'phpgw_nextid',
'phpgw_preferences',
'phpgw_sessions',
'phpgw_acl',
'phpgw_applications'
)
);
$GLOBALS['phpgw']->accounts->create($userData);
$userData['account_id'] = $GLOBALS['phpgw']->accounts->name2id($userData['account_lid']);
$apps = CreateObject('phpgwapi.applications',array($userData['account_id'],'u'));
$apps->read_installed_apps();
// Read Group Apps
if ($GLOBALS['HTTP_POST_VARS']['account_groups'])
{
$apps->account_type = 'g';
reset($GLOBALS['HTTP_POST_VARS']['account_groups']);
while($groups = each($GLOBALS['HTTP_POST_VARS']['account_groups']))
{
$apps->account_id = $groups[0];
$old_app_groups = $apps->read_account_specific();
@reset($old_app_groups);
while($old_group_app = each($old_app_groups))
{
if (!$apps_after[$old_group_app[0]])
{
$apps_after[$old_group_app[0]] = $old_app_groups[$old_group_app[0]];
}
}
}
}
$apps->account_type = 'u';
$apps->account_id = $userData['account_id'];
$apps->account_apps = Array(Array());
if ($userData['account_permissions'])
{
@reset($userData['account_permissions']);
while ($app = each($userData['account_permissions']))
{
if ($app[1])
{
$apps->add($app[0]);
if (!$apps_after[$app[0]])
{
$apps_after[] = $app[0];
}
}
}
}
$apps->save_repository();
$GLOBALS['phpgw']->acl->add_repository('preferences','changepassword',$userData['account_id'],1);
// Assign user to groups
if ($userData['account_groups'])
{
$c_acct_groups = count($userData['account_groups']);
for ($i=0;$i<$c_acct_groups;$i++)
{
$GLOBALS['phpgw']->acl->add_repository('phpgw_group',$userData['account_groups'][$i],$userData['account_id'],1);
}
}
if ($apps_after)
{
$GLOBALS['pref'] = CreateObject('phpgwapi.preferences',$userData['account_id']);
$GLOBALS['phpgw']->common->hook_single('add_def_pref','admin');
while ($apps = each($apps_after))
{
if (strcasecmp ($apps[0], 'admin') != 0)
{
$GLOBALS['phpgw']->common->hook_single('add_def_pref', $apps[1]);
}
}
$GLOBALS['pref']->save_repository(False);
}
$apps->account_apps = Array(Array());
$apps_after = Array(Array());
$GLOBALS['phpgw']->db->unlock();
/*
// start inlcuding other admin tools
while($app = each($apps_after))
{
$GLOBALS['phpgw']->common->hook_single('add_user_data', $value);
}
*/
Header('Location: ' . $GLOBALS['phpgw']->link('/index.php',
Array(
'menuaction' => 'admin.uiaccounts.list_users',
'cd' => $cd
)
)
);
$GLOBALS['phpgw']->common->phpgw_exit();
}
else
{
$ui = createobject('admin.uiaccounts');
$ui->create_edit_user($userData['account_id'],$userData,$errors);
}
}
else
{
Header('Location: '.$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiaccounts.list_users'));
$GLOBALS['phpgw']->common->phpgw_exit();
}
}
function edit_user()
{
if ($GLOBALS['HTTP_POST_VARS']['submit'])
{
$userData = array(
'account_lid' => $GLOBALS['HTTP_POST_VARS']['account_lid'],
'firstname' => $GLOBALS['HTTP_POST_VARS']['account_firstname'],
'lastname' => $GLOBALS['HTTP_POST_VARS']['account_lastname'],
'account_passwd' => $GLOBALS['HTTP_POST_VARS']['account_passwd'],
'status' => $GLOBALS['HTTP_POST_VARS']['account_status'],
'old_loginid' => ($GLOBALS['HTTP_GET_VARS']['old_loginid']?rawurldecode($GLOBALS['HTTP_GET_VARS']['old_loginid']):''),
'account_id' => ($GLOBALS['HTTP_GET_VARS']['account_id']?$GLOBALS['HTTP_GET_VARS']['account_id']:0),
'account_passwd_2' => $GLOBALS['HTTP_POST_VARS']['account_passwd_2'],
'account_groups' => $GLOBALS['HTTP_POST_VARS']['account_groups'],
'account_permissions' => $GLOBALS['HTTP_POST_VARS']['account_permissions'],
'homedirectory' => $GLOBALS['HTTP_POST_VARS']['homedirectory'],
'loginshell' => $GLOBALS['HTTP_POST_VARS']['loginshell'],
'account_expires_month' => $GLOBALS['HTTP_POST_VARS']['account_expires_month'],
'account_expires_day' => $GLOBALS['HTTP_POST_VARS']['account_expires_day'],
'account_expires_year' => $GLOBALS['HTTP_POST_VARS']['account_expires_year']
/* 'file_space' => $GLOBALS['HTTP_POST_VARS']['account_file_space_number'] . "-" . $GLOBALS['HTTP_POST_VARS']['account_file_space_type'] */
);
if (!$errors = $this->validate_user($userData))
{
$this->save_user($userData);
// check if would create a menu
// if we do, we can't return to the users list, because
// there are also some other plugins
$menuClass = CreateObject('admin.uimenuclass');
if (!$menuClass->createHTMLCode('edit_user'))
{
Header('Location: ' . $GLOBALS['phpgw']->link('/index.php',
Array(
'menuaction' => 'admin.uiaccounts.list_users',
'cd' => $cd
)
)
);
$GLOBALS['phpgw']->common->phpgw_exit();
}
else
{
$linkdata = Array(
'menuaction' => 'admin.uiaccounts.edit_user',
'cd' => $cd,
'account_id' => $GLOBALS['HTTP_GET_VARS']['account_id']
);
Header('Location: ' . $GLOBALS['phpgw']->link('/index.php', $linkdata));
$GLOBALS['phpgw']->common->phpgw_exit();
}
}
else
{
$ui = createobject('admin.uiaccounts');
$ui->create_edit_user($userData['account_id'],$userData,$errors);
}
}
}
/* checks if the userdata are valid
returns FALSE if the data are correct
otherwise the error array
*/
function validate_user(&$_userData)
{
$totalerrors = 0;
if ($GLOBALS['phpgw_info']['server']['account_repository'] == 'ldap' && ! $allow_long_loginids)
{
if (strlen($_userData['account_lid']) > 8)
{
$error[$totalerrors] = lang('The loginid can not be more then 8 characters');
$totalerrors++;
}
}
if (!$_userData['account_lid'])
{
$error[$totalerrors] = lang('You must enter a loginid');
$totalerrors++;
}
if ($_userData['old_loginid'] != $_userData['account_lid'])
{
if ($GLOBALS['phpgw']->accounts->exists($_userData['account_lid']))
{
$error[$totalerrors] = lang('That loginid has already been taken');
$totalerrors++;
}
}
if ($_userData['account_passwd'] || $_userData['account_passwd_2'])
{
if ($_userData['account_passwd'] != $_userData['account_passwd_2'])
{
$error[$totalerrors] = lang('The two passwords are not the same');
$totalerrors++;
}
}
if (!count($_userData['account_permissions']) && !count($_userData['account_groups']))
{
$error[$totalerrors] = lang('You must add at least 1 permission or group to this account');
$totalerrors++;
}
if ($_userData['account_expires_month'] || $_userData['account_expires_day'] || $_userData['account_expires_year'])
{
if (! checkdate($_userData['account_expires_month'],$_userData['account_expires_day'],$_userData['account_expires_year']))
{
$error[$totalerrors] = lang('You have entered an invalid expiration date');
$totalerrors++;
}
else
{
$_userData['expires'] = mktime(2,0,0,$_userData['account_expires_month'],$_userData['account_expires_day'],$_userData['account_expires_year']);
$_userData['account_expires'] = $_userData['expires'];
}
}
else
{
$_userData['expires'] = -1;
$_userData['account_expires'] = $_userData['expires'];
}
/*
$check_account_file_space = explode ('-', $_userData['file_space']);
if (preg_match ("/\D/", $check_account_file_space[0]))
{
$error[$totalerrors] = lang ('File space must be an integer');
$totalerrors++;
}
*/
if ($totalerrors == 0)
{
return FALSE;
}
else
{
return $error;
}
}
/* stores the userdata */
function save_user($_userData)
{
$account = CreateObject('phpgwapi.accounts',$_userData['account_id']);
$account->update_data($_userData);
$account->save_repository();
if ($_userData['account_passwd'])
{
$auth = CreateObject('phpgwapi.auth');
$auth->change_password($old_passwd, $_userData['account_passwd'], $_userData['account_id']);
}
$apps = CreateObject('phpgwapi.applications',array(intval($_userData['account_id']),'u'));
$apps->account_id = $_userData['account_id'];
if ($_userData['account_permissions'])
{
while($app = each($_userData['account_permissions']))
{
if($app[1])
{
$apps->add($app[0]);
}
}
}
$apps->save_repository();
$account = CreateObject('phpgwapi.accounts',$_userData['account_id']);
$allGroups = $account->get_list('groups');
if ($_userData['account_groups']) {
reset($_userData['account_groups']);
while (list($key,$value) = each($_userData['account_groups'])) {
$newGroups[$value] = $value;
}
}
$acl = CreateObject('phpgwapi.acl',$_userData['account_id']);
reset($allGroups);
while (list($key,$groupData) = each($allGroups))
{
/* print "$key,". $groupData['account_id'] ."<br>";*/
/* print "$key,". $_userData['account_groups'][1] ."<br>"; */
if ($newGroups[$groupData['account_id']])
{
$acl->add_repository('phpgw_group',$groupData['account_id'],$_userData['account_id'],1);
}
else
{
$acl->delete_repository('phpgw_group',$groupData['account_id'],$_userData['account_id']);
}
}
$GLOBALS['phpgw']->session->delete_cache(intval($_userData['account_id']));
}
}
?>

View File

@ -0,0 +1,33 @@
<?php
/**************************************************************************\
* phpGroupWare - account administration *
* http://www.phpgroupware.org *
* -------------------------------------------- *
* 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. *
\**************************************************************************/
class soaccounts
{
function soaccounts()
{
}
function account_total($query)
{
if ($query)
{
$querymethod = " AND (account_firstname LIKE '%$query%' OR account_lastname LIKE "
. "'%$query%' OR account_lid LIKE '%$query%') ";
}
$GLOBALS['phpgw']->db->query("SELECT COUNT(*) FROM phpgw_accounts WHERE account_type='u'".$querymethod,__LINE__,__FILE__);
$GLOBALS['phpgw']->db->next_record();
return $GLOBALS['phpgw']->db->f(0);
}
}
?>

View File

@ -0,0 +1,585 @@
<?php
/**************************************************************************\
* phpGroupWare - account administration *
* http://www.phpgroupware.org *
* -------------------------------------------- *
* 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. *
\**************************************************************************/
class uiaccounts
{
var $public_functions = array(
'list_users' => True,
'add_user' => True,
'delete_user' => True,
'edit_user' => True,
'view_user' => True
);
var $bo;
var $nextmatchs;
function uiaccounts()
{
$this->bo = createobject('admin.boaccounts');
$this->nextmatchs = createobject('phpgwapi.nextmatchs');
}
function row_action($action,$type,$account_id)
{
return '<a href="'.$GLOBALS['phpgw']->link('/index.php',Array(
'menuaction' => 'admin.uiaccounts.'.$action.'_'.$type,
'account_id' => $account_id
)).'"> '.lang($action).' </a>';
}
function list_users($param_cd='')
{
if(!$param_cd)
{
$cd = $param_cd;
}
unset($GLOBALS['phpgw_info']['flags']['noheader']);
unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
$GLOBALS['phpgw']->common->phpgw_header();
$p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
$p->set_file(
Array(
'accounts' => 'accounts.tpl'
)
);
$p->set_block('accounts','list','list');
$p->set_block('accounts','row','row');
$p->set_block('accounts','row_empty','row_empty');
$total = $this->bo->account_total($query);
$url = $GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiaccounts.list_users');
$var = Array(
'bg_color' => $GLOBALS['phpgw_info']['theme']['bg_color'],
'th_bg' => $GLOBALS['phpgw_info']['theme']['th_bg'],
'left_next_matchs' => $this->nextmatchs->left($url,$start,$total),
'lang_user_accounts' => lang('user accounts'),
'right_next_matchs' => $this->nextmatchs->right($url,$start,$total),
'lang_loginid' => $this->nextmatchs->show_sort_order($sort,'account_lid',$order,$url,lang('LoginID')),
'lang_lastname' => $this->nextmatchs->show_sort_order($sort,'account_lastname',$order,$url,lang('last name')),
'lang_firstname' => $this->nextmatchs->show_sort_order($sort,'account_firstname',$order,$url,lang('first name')),
'lang_edit' => lang('edit'),
'lang_delete' => lang('delete'),
'lang_view' => lang('view'),
'actionurl' => $GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiaccounts.add_user'),
'accounts_url' => $url,
'lang_add' => lang('add'),
'lang_search' => lang('search')
);
$p->set_var($var);
$account_info = $GLOBALS['phpgw']->accounts->get_list('accounts',$start,$sort,$order,$query);
if (! count($account_info))
{
$p->set_var('message',lang('No matchs found'));
$p->parse('rows','row_empty',True);
}
else
{
while (list($null,$account) = each($account_info))
{
$this->nextmatchs->template_alternate_row_color($p);
$var = Array(
'row_loginid' => $account['account_lid'],
'row_firstname' => (!$account['account_firstname']?'&nbsp':$account['account_firstname']),
'row_lastname' => (!$account['account_lastname']?'&nbsp':$account['account_lastname']),
'row_edit' => $this->row_action('edit','user',$account['account_id']),
'row_delete' => ($GLOBALS['phpgw_info']['user']['userid'] != $account['account_lid']?$this->row_action('delete','user',$account['account_id']):'&nbsp'),
'row_view' => $this->row_action('view','user',$account['account_id'])
);
$p->set_var($var);
$p->parse('rows','row',True);
}
} // End else
$p->pparse('out','list');
}
function add_user()
{
$this->create_edit_user(0);
}
function delete_user()
{
if($GLOBALS['phpgw_info']['user']['account_id'] == $GLOBALS['HTTP_GET_VARS']['account_id'])
{
Header('Location: '.$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiaccounts.list_users'));
$GLOBALS['phpgw']->common->phpgw_exit();
}
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' => $GLOBALS['HTTP_GET_VARS']['account_id']
);
// the account can have special chars/white spaces, if it is a ldap dn
$account_id = rawurlencode($GLOBALS['HTTP_GET_VARS']['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 .= '<option value='.$users[$i]['account_id'].'>'.$GLOBALS['phpgw']->common->display_fullname($users[$i]['account_lid'],$users[$i]['account_firstname'],$users[$i]['account_lastname']).'</option>'."\n";
}
$var['lang_new_owner'] = lang('Who would you like to transfer ALL records owned by the deleted user to?');
$var['new_owner_select'] = '<select name="new_owner" size="5">'."\n".'<option value=0 selected>'.lang('Delete All Records').'</option>'."\n".$str.'</select>'."\n";
$var['cancel'] = lang('cancel');
$var['delete'] = lang('delete');
$t->set_var($var);
$t->pparse('out','form');
}
function edit_user($cd='',$account_id='')
{
$cdid = $cd;
settype($cd,'integer');
$cd = ($GLOBALS['HTTP_GET_VARS']['cd']?$GLOBALS['HTTP_GET_VARS']['cd']:$cdid);
$accountid = $account_id;
settype($account_id,'integer');
$account_id = ($GLOBALS['HTTP_GET_VARS']['account_id']?$GLOBALS['HTTP_GET_VARS']['account_id']:$accountid);
// todo
// not needed if i use the same file for new users too
if (!$account_id)
{
Header('Location: ' . $GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiaccounts.list_users'));
}
else
{
$this->create_edit_user($account_id);
}
}
function view_user()
{
if (!$GLOBALS['HTTP_GET_VARS']['account_id'])
{
Header('Location: ' . $phpgw->link('/index.php','menuaction=admin.uiaccounts.list_users'));
}
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_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_password' => lang('Password'),
'lang_reenter_password' => lang('Re-Enter Password'),
'lang_lastname' => lang('Last Name'),
'lang_groups' => lang('Groups'),
'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',$GLOBALS['HTTP_GET_VARS']['account_id']);
$userData = $account->read_repository();
$var['account_lid'] = $userData['account_lid'];
$var['account_firstname'] = $userData['firstname'];
$var['account_lastname'] = $userData['lastname'];
if ($userData['status'])
{
$var['account_status'] = lang('Enabled');
}
else
{
$var['account_status'] = '<b>' . lang('Disabled') . '</b>';
}
// 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(intval($GLOBALS['HTTP_GET_VARS']['account_id']));
if (gettype($usergroups) != 'array')
{
$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);
while ($application = each($availableApps))
{
if ($application[1]['enabled'] && $application[1]['status'] != 2)
{
$perm_display[$i]['appName'] = $application[0];
$perm_display[$i]['translatedName'] = $application[1]['title'];
$i++;
}
}
// create apps output
$apps = CreateObject('phpgwapi.applications',intval($GLOBALS['HTTP_GET_VARS']['account_id']));
$db_perms = $apps->read_account_specific();
@reset($db_perms);
for ($i=0;$i<=count($perm_display);$i++)
{
if ($perm_display[$i]['translatedName'])
{
$part1 = sprintf("<td>%s</td><td>%s</td>",lang($perm_display[$i]['translatedName']),($_userData['account_permissions'][$perm_display[$i]['appName']] || $db_perms[$perm_display[$i]['appName']]?'&nbsp;&nbsp;X':'&nbsp'));
}
$i++;
if ($perm_display[$i]['translatedName'])
{
$part2 = sprintf("<td>%s</td><td>%s</td>",lang($perm_display[$i]['translatedName']),($_userData['account_permissions'][$perm_display[$i]['appName']] || $db_perms[$perm_display[$i]['appName']]?'&nbsp;&nbsp;X':'&nbsp'));
}
else
{
$part2 = '<td colspan="2">&nbsp;</td>';
}
$appRightsOutput .= sprintf("<tr bgcolor=\"%s\">$part1$part2</tr>\n",$GLOBALS['phpgw_info']['theme']['row_on']);
}
$var['permissions_list'] = $appRightsOutput;
// create the menu on the left, if needed
$menuClass = CreateObject('admin.uimenuclass');
$var['rows'] = $menuClass->createHTMLCode('view_user');
$t->set_var($var);
$t->pfp('out','form');
}
function create_edit_user($_account_id,$_userData='',$_errors='')
{
$sbox = createobject('phpgwapi.sbox');
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_unknowns('remove');
if ($GLOBALS['phpgw_info']['server']['ldap_extra_attributes'] && ($GLOBALS['phpgw_info']['server']['account_repository'] == 'ldap'))
{
$t->set_file(array('account' => 'account_form_ldap.tpl'));
}
else
{
$t->set_file(array('account' => 'account_form.tpl'));
}
$t->set_block('account','form','form');
$t->set_block('account','form_passwordinfo','form_passwordinfo');
$t->set_block('account','form_buttons_','form_buttons_');
$t->set_block('account','link_row','link_row');
print_debug('Type : '.gettype($_userData).'<br>_userData(size) = "'.$_userData.'"('.strlen($_userData).')');
if (is_array($_userData))
{
$userData = Array();
$userData=$_userData;
@reset($userData['account_groups']);
while (list($key, $value) = @each($userData['account_groups']))
{
$userGroups[$key]['account_id'] = $value;
}
$account = CreateObject('phpgwapi.accounts');
$allGroups = $account->get_list('groups');
}
elseif(is_string($_userData) && $_userData=='')
{
if($_account_id)
{
$account = CreateObject('phpgwapi.accounts',$_account_id);
$userData = $account->read_repository();
$userGroups = $account->membership($_account_id);
}
else
{
$account = CreateObject('phpgwapi.accounts');
$userData = Array();
$userData['status'] = 'A';
$userGroups = Array();
}
$allGroups = $account->get_list('groups');
if ($userData['expires'] == -1)
{
$userData['account_expires_month'] = 0;
$userData['account_expires_day'] = 0;
$userData['account_expires_year'] = 0;
}
else
{
$userData['account_expires_month'] = date('m',$userData['expires']);
$userData['account_expires_day'] = date('d',$userData['expires']);
$userData['account_expires_year'] = date('Y',$userData['expires']);
}
}
$page_params['menuaction'] = 'admin.boaccounts.'.($_account_id?'edit':'add').'_user';
if($_account_id)
{
$page_params['account_id'] = $_account_id;
$page_params['old_loginid'] = rawurlencode($userData['account_lid']);
}
$var = Array(
'form_action' => $GLOBALS['phpgw']->link('/index.php',$page_params),
'error_messages' => (!$_errors?'':'<center>'.$GLOBALS['phpgw']->common->error_list($_errors).'</center>'),
'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' => ($_account_id?lang('Edit user account'):lang('Add new account')),
'lang_loginid' => lang('LoginID'),
'lang_account_active' => lang('Account active'),
'lang_password' => lang('Password'),
'lang_reenter_password' => lang('Re-Enter Password'),
'lang_lastname' => lang('Last Name'),
'lang_groups' => lang('Groups'),
'lang_expires' => lang('Expires'),
'lang_firstname' => lang('First Name'),
'lang_button' => ($_account_id?lang('Save'):lang('Add')),
/* 'lang_file_space' => lang('File Space') */
);
$t->set_var($var);
$t->parse('form_buttons','form_buttons_',True);
if ($GLOBALS['phpgw_info']['server']['ldap_extra_attributes']) {
$lang_homedir = lang('home directory');
$lang_shell = lang('login shell');
$homedirectory = '<input name="homedirectory" value="'
. ($_account_id?$userData['homedirectory']:$GLOBALS['phpgw_info']['server']['ldap_account_home'].SEP.$account_lid)
. '">';
$loginshell = '<input name="loginshell" value="'
. ($_account_id?$userData['loginshell']:$GLOBALS['phpgw_info']['server']['ldap_account_shell'])
. '">';
}
else
{
$lang_homedir = '';
$lang_shell = '';
$homedirectory = '';
$loginshell = '';
}
$_y = $sbox->getyears('account_expires_year',$userData['account_expires_year'],date('Y'),date('Y')+10);
$_m = $sbox->getmonthtext('account_expires_month',$userData['account_expires_month']);
$_d = $sbox->getdays('account_expires_day',$userData['account_expires_day']);
$account_file_space = '';
/*
if (!$userData['file_space'])
{
$userData['file_space'] = $GLOBALS['phpgw_info']['server']['vfs_default_account_size_number'] . "-" . $GLOBALS['phpgw_info']['server']['vfs_default_account_size_type'];
}
$file_space_array = explode ('-', $userData['file_space']);
$account_file_space_number = $file_space_array[0];
$account_file_space_type = $file_space_array[1];
$account_file_space_type_selected[$account_file_space_type] = ' selected';
$account_file_space = '<input type=text name="account_file_space_number" value="' . trim($account_file_space_number) . '" size="7">';
$account_file_space_select ='<select name="account_file_space_type">';
$account_file_space_types = array ('gb', 'mb', 'kb', 'b');
while (list ($num, $type) = each ($account_file_space_types))
{
$account_file_space_select .= '<option value="'.$type.'"' . $account_file_space_type_selected[$type] . '>' . strtoupper ($type) . '</option>';
}
$account_file_space_select .= '</select>';
$var = Array(
'lang_file_space' => 'File space',
'account_file_space' => $account_file_space,
'account_file_space_select' => $account_file_space_select
);
$t->set_var($var);
*/
$var = Array(
'input_expires' => $GLOBALS['phpgw']->common->dateformatorder($_y,$_m,$_d,True),
'account_lid' => '<input name="account_lid" value="' . $userData['account_lid'] . '">',
'lang_homedir' => $lang_homedir,
'lang_shell' => $lang_shell,
'homedirectory' => $homedirectory,
'loginshell' => $loginshell,
'account_status' => '<input type="checkbox" name="account_status" value="A"'.($userData['status']?' checked':'').'>',
'account_firstname' => '<input name="account_firstname" value="' . $userData['firstname'] . '">',
'account_lastname' => '<input name="account_lastname" value="' . $userData['lastname'] . '">',
'account_passwd' => $account_passwd,
'account_passwd_2' => $account_passwd_2,
'account_file_space' => $account_file_space
);
$t->set_var($var);
$t->parse('password_fields','form_passwordinfo',True);
// $allAccounts;
// $userGroups;
$groups_select = '';
reset($allGroups);
while (list($key,$value) = each($allGroups))
{
$groups_select .= '<option value="' . $value['account_id'] . '"';
for ($i=0; $i<count($userGroups); $i++)
{
/* print "Los1:".$userData["account_id"].$userGroups[$i]['account_id']." : ".$value['account_id']."<br>"; */
if ($userGroups[$i]['account_id'] == $value['account_id'])
{
$groups_select .= ' selected';
}
}
$groups_select .= '>' . $value['account_lid'] . '</option>'."\n";
}
/* create list of available apps */
$i = 0;
$apps = CreateObject('phpgwapi.applications',$_account_id);
$db_perms = $apps->read_account_specific();
@reset($GLOBALS['phpgw_info']['apps']);
$availableApps = $GLOBALS['phpgw_info']['apps'];
@asort($availableApps);
@reset($availableApps);
while (list($key,$application) = each($availableApps))
{
if ($application['enabled'] && $application['status'] != 3)
{
$perm_display[$i]['appName'] = $key;
$perm_display[$i]['translatedName'] = $application['title'];
$i++;
}
}
/* create apps output */
$appRightsOutput = '';
// @reset($perm_display);
for ($i=0;$i<count($perm_display);$i++)
{
if ($perm_display[$i]['translatedName'])
{
$part1 = sprintf('<td>%s</td><td><input type="checkbox" name="account_permissions[%s]" value="True"%s></td>',
lang($perm_display[$i]['translatedName']),
$perm_display[$i]['appName'],
($userData['account_permissions'][$perm_display[$i]['appName']] || $db_perms[$perm_display[$i]['appName']]?' checked':''));
}
$i++;
if ($perm_display[$i]['translatedName'])
{
$part2 = sprintf('<td>%s</td><td><input type="checkbox" name="account_permissions[%s]" value="True"%s></td>',
lang($perm_display[$i]['translatedName']),
$perm_display[$i]['appName'],
($userData['account_permissions'][$perm_display[$i]['appName']] || $db_perms[$perm_display[$i]['appName']]?' checked':''));
}
else
{
$part2 = '<td colspan="2">&nbsp;</td>';
}
$appRightsOutput .= sprintf('<tr bgcolor="%s">%s%s</tr>',$GLOBALS['phpgw_info']['theme']['row_on'], $part1, $part2);
}
$var = Array(
'groups_select' => '<select name="account_groups[]" multiple>'."\n".$groups_select.'</select>'."\n",
'permissions_list' => $appRightsOutput
);
$t->set_var($var);
// create the menu on the left, if needed
$menuClass = CreateObject('admin.uimenuclass');
$t->set_var('rows',$menuClass->createHTMLCode('edit_user'));
echo $t->fp('out','form');
}
}
?>

View File

@ -1,9 +1,8 @@
<?php
global $pref;
$pref->change("common","maxmatchs","15");
$pref->change("common","theme","default");
$pref->change("common","tz_offset","0");
$pref->change("common","dateformat","m/d/Y");
$pref->change("common","timeformat","12");
$pref->change("common","lang","en");
$GLOBALS['pref']->change('common','maxmatchs','15');
$GLOBALS['pref']->change('common','theme','default');
$GLOBALS['pref']->change('common','tz_offset',0);
$GLOBALS['pref']->change('common','dateformat','m/d/Y');
$GLOBALS['pref']->change('common','timeformat',12);
$GLOBALS['pref']->change('common','lang','en');
?>

View File

@ -14,8 +14,8 @@
$file = array(
'Site Configuration' => $phpgw->link('/admin/config.php','appname=admin'),
'Peer Servers' => $phpgw->link('/admin/servers.php'),
'User Accounts' => $phpgw->link('/admin/accounts.php'),
'User Groups' => $phpgw->link('/admin/groups.php'),
'User Accounts' => $phpgw->link('/index.php','menuaction=admin.uiaccounts.list_users'),
'User Groups' => $phpgw->link('/index.php','menuaction=admin.uiaccounts.list_groups'),
'Applications' => $phpgw->link('/admin/applications.php'),
'Global Categories' => $phpgw->link('/admin/categories.php'),
'Change Main Screen Message' => $phpgw->link('/admin/mainscreen_message.php'),
@ -27,4 +27,4 @@
//Do not modify below this line
display_section('admin','admin',$file);
?>
?>