Updated to have all posts and gets go to the ui class. Bo class functions now take direct arguments and respond with true, false, or array of errors (for now).

This commit is contained in:
Miles Lott 2007-03-09 12:07:15 +00:00
parent c973715bc4
commit d274143269
3 changed files with 494 additions and 493 deletions

View File

@ -20,8 +20,7 @@
'delete_group' => True,
'delete_user' => True,
'edit_group' => True,
'edit_user' => True,
'set_group_managers' => True
'edit_user' => True
);
var $xml_functions = array();
@ -36,83 +35,21 @@
function boaccounts()
{
$this->so =& CreateObject('admin.soaccounts');
if (get_magic_quotes_gpc()) // deal with magic_quotes_gpc On
{
$_POST = $this->array_stripslashes($_POST);
}
}
/**
* applies stripslashes recursivly on each element of an array
*
* @param array &$var
* @return array
*/
function array_stripslashes($var)
function delete_group($account_id='')
{
if (!is_array($var))
if(!$account_id || $GLOBALS['egw']->acl->check('group_access',32,'admin'))
{
return stripslashes($var);
}
foreach($var as $key => $val)
{
$var[$key] = is_array($val) ? $this->array_stripslashes($val) : stripslashes($val);
}
return $var;
}
function DONTlist_methods($_type='xmlrpc')
{
/*
This handles introspection or discovery by the logged in client,
in which case the input might be an array. The server always calls
this function to fill the server dispatch map using a string.
*/
if (is_array($_type))
{
$_type = $_type['type'] ? $_type['type'] : $_type[0];
}
switch($_type)
{
case 'xmlrpc':
$xml_functions = array(
'rpc_add_user' => array(
'function' => 'rpc_add_user',
'signature' => array(array(xmlrpcStruct,xmlrpcStruct)),
'docstring' => lang('Add a new account.')
),
'list_methods' => array(
'function' => 'list_methods',
'signature' => array(array(xmlrpcStruct,xmlrpcString)),
'docstring' => lang('Read this list of methods.')
)
);
return $xml_functions;
break;
case 'soap':
return $this->soap_functions;
break;
default:
return array();
break;
}
}
function delete_group()
{
if (!@isset($_POST['account_id']) || !@$_POST['account_id'] || $GLOBALS['egw']->acl->check('group_access',32,'admin'))
{
ExecMethod('admin.uiaccounts.list_groups');
return False;
}
$account_id = (int)$_POST['account_id'];
$account_id = (int)$account_id;
// delete all acl (and memberships) of group
$GLOBALS['egw']->acl->delete_account($account_id);
if (! @rmdir($GLOBALS['egw_info']['server']['files_dir'].SEP.'groups'.SEP.$GLOBALS['egw']->accounts->id2name($account_id)))
if(!@rmdir($GLOBALS['egw_info']['server']['files_dir'].SEP.'groups'.SEP.$GLOBALS['egw']->accounts->id2name($account_id)))
{
$cd = 38;
}
@ -123,30 +60,26 @@
$GLOBALS['egw']->accounts->delete($account_id);
Header('Location: '.$GLOBALS['egw']->link('/index.php','menuaction=admin.uiaccounts.list_groups'));
$GLOBALS['egw']->common->egw_exit();
return True;
}
function delete_user()
function delete_user($account_id='',$new_owner='')
{
if (isset($_POST['cancel']) || $GLOBALS['egw']->acl->check('account_access',32,'admin'))
if(!$account_id || $GLOBALS['egw']->acl->check('account_access',32,'admin'))
{
ExecMethod('admin.uiaccounts.list_users');
return False;
}
elseif($_POST['delete_account'])
{
$accountid = $_POST['account_id'];
settype($account_id,'integer');
$accountid = (int)$account_id;
$account_id = get_account_id($accountid);
// make this information also in hook available
// make this information also available in the hook
$lid = $GLOBALS['egw']->accounts->id2name($account_id);
$GLOBALS['hook_values'] = array(
'account_id' => $account_id,
'account_lid' => $lid,
'new_owner' => (int)$_POST['new_owner'],
'location' => 'deleteaccount',
'new_owner' => (int)$new_owner,
'location' => 'deleteaccount'
);
// first all other apps, then preferences and admin
foreach(array_merge(array_diff(array_keys($GLOBALS['egw_info']['apps']),array('preferences','admin')),array('preferences','admin')) as $app)
@ -156,7 +89,7 @@
$basedir = $GLOBALS['egw_info']['server']['files_dir'] . SEP . 'users' . SEP;
if (! @rmdir($basedir . $lid))
if(!@rmdir($basedir . $lid))
{
$cd = 34;
}
@ -165,39 +98,21 @@
$cd = 29;
}
ExecMethod('admin.uiaccounts.list_users');
return False;
}
return True;
}
function add_group()
function add_group($group_info)
{
if ($GLOBALS['egw']->acl->check('group_access',4,'admin'))
if($GLOBALS['egw']->acl->check('group_access',4,'admin'))
{
ExecMethod('admin.uiaccounts.list_groups');
return False;
}
$group_permissions = ($_POST['account_apps']?$_POST['account_apps']:Array());
$account_apps = Array();
@reset($group_permissions);
while(list($key,$value) = each($group_permissions))
$errors = $this->validate_group($group_info);
if(count($errors))
{
if($value)
{
$account_apps[$key] = True;
return $errors;
}
}
@reset($account_apps);
$group_info = Array(
'account_id' => ($_POST['account_id']?(int)$_POST['account_id']:0),
'account_name' => ($_POST['account_name']?$_POST['account_name']:''),
'account_user' => $_POST['account_user'],
'account_apps' => $account_apps
);
$this->validate_group($group_info);
$group =& CreateObject('phpgwapi.accounts',$group_info['account_id'],'g');
$group->acct_type = 'g';
@ -210,11 +125,13 @@
'account_status' => 'A',
'account_expires' => -1,
// 'account_file_space' => $account_file_space_number . "-" . $account_file_space_type,
'account_email' => $_POST['account_email'],
'account_email' => $group_info['account_email'],
'account_members' => $group_info['account_user']
);
$group_info['account_id'] = $group->create($account_info);
// do the following only if we got an id - the create succided
if ($group_info['account_id'])
// do the following only if we got an id - the create succeeded
if($group_info['account_id'])
{
$group->set_members($group_info['account_user'],$group_info['account_id']);
@ -231,21 +148,20 @@
$basedir = $GLOBALS['egw_info']['server']['files_dir'] . SEP . 'groups' . SEP;
$cd = 31;
umask(000);
if (! @mkdir ($basedir . $group_info['account_name'], 0707))
if(!@mkdir($basedir . $group_info['account_name'], 0707))
{
$cd = 37;
}
return True;
}
ExecMethod('admin.uiaccounts.list_groups');
return False;
}
function add_user()
function add_user($userData)
{
if ($GLOBALS['egw']->acl->check('account_access',4,'admin'))
if($GLOBALS['egw']->acl->check('account_access',4,'admin'))
{
ExecMethod('admin.uiaccounts.list_users');
return False;
}
@ -254,35 +170,10 @@
{
$accountPrefix = $GLOBALS['egw_info']['server']['account_prefix'];
}
if ($_POST['submit'])
if($accountPrefix)
{
if (!($email = $_POST['account_email']))
{
$email = $GLOBALS['egw']->common->email_address($_POST['account_firstname'],$_POST['account_lastname'],$_POST['account_lid']);
$userData['account_lid'] = $accountPrefix . $userData['account_lid'];
}
$userData = array(
'account_type' => 'u',
'account_lid' => $accountPrefix.$_POST['account_lid'],
'account_firstname' => $_POST['account_firstname'],
'account_lastname' => $_POST['account_lastname'],
'account_passwd' => $_POST['account_passwd'],
'status' => ($_POST['account_status'] ? 'A' : ''),
'account_status' => ($_POST['account_status'] ? 'A' : ''),
'old_loginid' => ($_GET['old_loginid']?rawurldecode($_GET['old_loginid']):''),
'account_id' => ($_GET['account_id']?$_GET['account_id']:0),
'account_primary_group' => $_POST['account_primary_group'],
'account_passwd_2' => $_POST['account_passwd_2'],
'account_groups' => $_POST['account_groups'],
'anonymous' => $_POST['anonymous'],
'changepassword' => $_POST['changepassword'],
'account_permissions' => $_POST['account_permissions'],
'homedirectory' => $_POST['homedirectory'],
'loginshell' => $_POST['loginshell'],
'account_expires_never' => $_POST['never_expires'],
'account_email' => $email,
/* 'file_space' => $_POST['account_file_space_number'] . "-" . $_POST['account_file_space_type'] */
);
// add the primary group, to the users other groups, if not already added
if(is_array($userData['account_groups']))
@ -297,18 +188,11 @@
$userData['account_groups'] = array((int)$userData['account_primary_group']);
}
// when does the account expire
if ($_POST['expires'] !== '' && !$_POST['never_expires'])
{
$jscal =& CreateObject('phpgwapi.jscalendar',False);
$userData += $jscal->input2date($_POST['expires'],False,'account_expires_day','account_expires_month','account_expires_year');
}
// do we have all needed data??
if (!($errors = $this->validate_user($userData)) &&
if(!($errors = $this->validate_user($userData)) &&
($userData['account_id'] = $account_id = $this->so->add_user($userData))) // no error in the creation
{
if ($userData['anonymous'])
if($userData['anonymous'])
{
$GLOBALS['egw']->acl->add_repository('phpgwapi','anonymous',$account_id,1);
}
@ -322,49 +206,27 @@
'location' => 'addaccount'
),False,True); // called for every app now, not only enabled ones
ExecMethod('admin.uiaccounts.list_users');
return False;
return True;
}
else
{
$ui =& CreateObject('admin.uiaccounts');
$ui->create_edit_user($userData['account_id'],$userData,$errors);
return $errors;
}
}
else
{
ExecMethod('admin.uiaccounts.list_users');
return False;
}
}
function edit_group()
{
if ($GLOBALS['egw']->acl->check('group_access',16,'admin'))
{
ExecMethod('admin.uiaccounts.list_groups');
return False;
}
$group_permissions = ($_POST['account_apps']?$_POST['account_apps']:Array());
$account_apps = Array();
@reset($group_permissions);
while(list($key,$value) = each($group_permissions))
function edit_group($group_info)
{
if($value)
if($GLOBALS['egw']->acl->check('group_access',16,'admin'))
{
$account_apps[$key] = True;
return False;
}
}
@reset($account_apps);
$group_info = Array(
'account_id' => ($_POST['account_id']?(int)$_POST['account_id']:0),
'account_name' => ($_POST['account_name']?$_POST['account_name']:''),
'account_user' => $_POST['account_user'],
'account_apps' => $account_apps,
);
$this->validate_group($group_info);
$errors = $this->validate_group($group_info);
if(count($errors))
{
return $errors;
}
$group =& CreateObject('phpgwapi.accounts',$group_info['account_id'],'g');
$old_group_info = $group->read_repository();
@ -395,7 +257,7 @@
$group->data['firstname'] = $group_info['account_name'];
$basedir = $GLOBALS['egw_info']['server']['files_dir'] . SEP . 'groups' . SEP;
if (! @rename($basedir . $old_group_info['account_lid'], $basedir . $group_info['account_name']))
if(!@rename($basedir . $old_group_info['account_lid'], $basedir . $group_info['account_name']))
{
$cd = 39;
}
@ -413,7 +275,7 @@
// This is down here so we are sure to catch the acl changes
// for LDAP to update the memberuid attribute
$group->data['account_email'] = $_POST['account_email'];
$group->data['account_email'] = $group_info['account_email'];
$group->save_repository();
$GLOBALS['hook_values'] = $group_info;
@ -421,15 +283,13 @@
'location' => 'editgroup'
),False,True); // called for every app now, not only enabled ones)
ExecMethod('admin.uiaccounts.list_groups');
return False;
return True;
}
function edit_user()
function edit_user($userData)
{
if ($GLOBALS['egw']->acl->check('account_access',16,'admin'))
if($GLOBALS['egw']->acl->check('account_access',16,'admin'))
{
ExecMethod('admin.uiaccounts.list_users');
return False;
}
@ -439,42 +299,12 @@
$accountPrefix = $GLOBALS['egw_info']['server']['account_prefix'];
}
if ($_POST['submit'])
$errors = $this->validate_user($userData);
if(@is_array($errors))
{
if (!($email = $_POST['account_email']))
{
$email = $GLOBALS['egw']->common->email_address($_POST['account_firstname'],$_POST['account_lastname'],$_POST['account_lid']);
return $errors;
}
$userData = array(
'account_lid' => $accountPrefix.$_POST['account_lid'],
'account_firstname' => $_POST['account_firstname'],
'account_lastname' => $_POST['account_lastname'],
'account_passwd' => $_POST['account_passwd'],
'account_status' => ($_POST['account_status'] ? 'A' : ''),
'old_loginid' => ($_GET['old_loginid']?rawurldecode($_GET['old_loginid']):''),
'account_id' => ($_GET['account_id']?$_GET['account_id']:0),
'account_passwd_2' => $_POST['account_passwd_2'],
'account_groups' => $_POST['account_groups'],
'account_primary_group' => $_POST['account_primary_group'],
'anonymous' => $_POST['anonymous'],
'changepassword' => $_POST['changepassword'],
'account_permissions' => $_POST['account_permissions'],
'homedirectory' => $_POST['homedirectory'],
'loginshell' => $_POST['loginshell'],
'account_expires_never' => $_POST['never_expires'],
'account_email' => $email,
/* 'file_space' => $_POST['account_file_space_number'] . "-" . $_POST['account_file_space_type'] */
);
if ($userData['account_primary_group'] && (!isset($userData['account_groups']) || !in_array($userData['account_primary_group'],$userData['account_groups'])))
{
$userData['account_groups'][] = (int)$userData['account_primary_group'];
}
if ($_POST['expires'] !== '' && !$_POST['never_expires'])
{
$jscal =& CreateObject('phpgwapi.jscalendar',False);
$userData += $jscal->input2date($_POST['expires'],False,'account_expires_day','account_expires_month','account_expires_year');
}
if (!($errors = $this->validate_user($userData)))
else
{
$this->save_user($userData);
$GLOBALS['hook_values'] = $userData;
@ -482,67 +312,9 @@
'location' => 'editaccount'
),False,True); // called for every app now, not only enabled ones)
// check if would create a menu
// if we do, we can't return to the users list, because
// there are also some other plugins
if (!ExecMethod('admin.uimenuclass.createHTMLCode','edit_user'))
{
if ($userData['account_id'] == $GLOBALS['egw_info']['user']['account_id'])
{
$GLOBALS['egw']->redirect_link('/index.php',array( // without redirect changes happen only in the next page-view!
'menuaction' => 'admin.uiaccounts.list_users',
));
return True;
}
ExecMethod('admin.uiaccounts.list_users');
return False;
}
else
{
if ($userData['account_id'] == $GLOBALS['egw_info']['user']['account_id'])
{
$GLOBALS['egw']->redirect_link('/index.php',array( // without redirect changes happen only in the next page-view!
'menuaction' => 'admin.uiaccounts.edit_user',
'account_id' => $_GET['account_id'],
));
}
ExecMethod('admin.uiaccounts.edit_user',$_GET['account_id']);
return False;
}
}
else
{
$ui =& CreateObject('admin.uiaccounts');
$ui->create_edit_user($userData['account_id'],$userData,$errors);
}
}
}
function set_group_managers()
{
if($GLOBALS['egw']->acl->check('group_access',16,'admin') || $_POST['cancel'])
{
$GLOBALS['egw']->redirect($GLOBALS['egw']->link('/index.php','menuaction=admin.uiaccounts.list_groups'));
$GLOBALS['egw']->common->egw_exit();
}
elseif($_POST['submit'])
{
$acl =& CreateObject('phpgwapi.acl',(int)$_POST['account_id']);
$users = $GLOBALS['egw']->accounts->member($_POST['account_id']);
@reset($users);
while($managers && list($key,$user) = each($users))
{
$acl->add_repository('phpgw_group',(int)$_POST['account_id'],$user['account_id'],1);
}
$managers = $_POST['managers'];
@reset($managers);
while($managers && list($key,$manager) = each($managers))
{
$acl->add_repository('phpgw_group',(int)$_POST['account_id'],$manager,(1 + EGW_ACL_GROUP_MANAGERS));
}
}
$GLOBALS['egw']->redirect($GLOBALS['egw']->link('/index.php','menuaction=admin.uiaccounts.list_groups'));
$GLOBALS['egw']->common->egw_exit();
return True;
}
function validate_group($group_info)
@ -556,26 +328,29 @@
{
$errors[] = lang('You must enter a group name.');
}
/* For LDAP */
if(!$group_info['account_user'])
{
$errors[] = lang('You must select at least one group member.');
}
if($group_info['account_name'] != $group->id2name($group_info['account_id']))
{
if ($group->exists($group_info['account_name']))
if($group->exists($group_info['account_name']))
{
$errors[] = lang('Sorry, that group name has already been taken.');
}
}
/*
if (preg_match ("/\D/", $account_file_space_number))
if(preg_match("/\D/", $account_file_space_number))
{
$errors[] = lang ('File space must be an integer');
$errors[] = lang('File space must be an integer');
}
*/
if(count($errors))
{
$ui =& CreateObject('admin.uiaccounts');
$ui->create_edit_group($group_info,$errors);
$GLOBALS['egw']->common->egw_exit();
return $errors;
}
}
@ -587,14 +362,14 @@
{
$totalerrors = 0;
if ($GLOBALS['egw_info']['server']['account_repository'] == 'ldap' &&
if($GLOBALS['egw_info']['server']['account_repository'] == 'ldap' &&
(!$_userData['account_lastname'] && !$_userData['lastname']))
{
$error[$totalerrors] = lang('You must enter a lastname');
$totalerrors++;
}
if (!$_userData['account_lid'])
if(!$_userData['account_lid'])
{
$error[$totalerrors] = lang('You must enter a loginid');
$totalerrors++;
@ -606,11 +381,11 @@
$totalerrors++;
}
if ($_userData['old_loginid'] != $_userData['account_lid'])
if($_userData['old_loginid'] != $_userData['account_lid'])
{
if ($GLOBALS['egw']->accounts->exists($_userData['account_lid']))
if($GLOBALS['egw']->accounts->exists($_userData['account_lid']))
{
if ($GLOBALS['egw']->accounts->exists($_userData['account_lid']) && $GLOBALS['egw']->accounts->get_type($_userData['account_lid'])=='g')
if($GLOBALS['egw']->accounts->exists($_userData['account_lid']) && $GLOBALS['egw']->accounts->get_type($_userData['account_lid'])=='g')
{
$error[$totalerrors] = lang('There already is a group with this name. Userid\'s can not have the same name as a groupid');
}
@ -622,22 +397,22 @@
}
}
if ($_userData['account_passwd'] || $_userData['account_passwd_2'])
if($_userData['account_passwd'] || $_userData['account_passwd_2'])
{
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']))
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'] || $_userData['account_expires_never'])
if($_userData['account_expires_month'] || $_userData['account_expires_day'] || $_userData['account_expires_year'] || $_userData['account_expires_never'])
{
if($_userData['account_expires_never'])
{
@ -646,7 +421,7 @@
}
else
{
if (! checkdate($_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++;
@ -665,17 +440,17 @@
}
/*
$check_account_file_space = explode ('-', $_userData['file_space']);
if (preg_match ("/\D/", $check_account_file_space[0]))
$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');
$error[$totalerrors] = lang('File space must be an integer');
$totalerrors++;
}
*/
if ($totalerrors == 0)
if($totalerrors == 0)
{
return FALSE;
return False;
}
else
{
@ -692,7 +467,7 @@
$account->set_memberships($_userData['account_groups'],$_userData['account_id']);
if ($_userData['account_passwd'])
if($_userData['account_passwd'])
{
$auth =& CreateObject('phpgwapi.auth');
$auth->change_password($old_passwd, $_userData['account_passwd'], $_userData['account_id']);
@ -706,7 +481,7 @@
}
$apps =& CreateObject('phpgwapi.applications',(int)$_userData['account_id']);
if ($_userData['account_permissions'])
if($_userData['account_permissions'])
{
foreach($_userData['account_permissions'] as $app => $enabled)
{
@ -719,7 +494,7 @@
$apps->save_repository();
$acl =& CreateObject('phpgwapi.acl',$_userData['account_id']);
if ($_userData['anonymous'])
if($_userData['anonymous'])
{
$acl->add_repository('phpgwapi','anonymous',$_userData['account_id'],1);
}
@ -727,7 +502,7 @@
{
$acl->delete_repository('phpgwapi','anonymous',$_userData['account_id']);
}
if (!$_userData['changepassword'])
if(!$_userData['changepassword'])
{
$GLOBALS['egw']->acl->add_repository('preferences','nopasswordchange',$_userData['account_id'],1);
}
@ -750,7 +525,7 @@
$group_user = $temp_user;
}
$account_user = Array();
while (list($key,$user) = each($group_user))
while(list($key,$user) = each($group_user))
{
$account_user[$user] = ' selected';
}
@ -777,7 +552,7 @@
{
exit;
if (!$errors = $this->validate_user($data))
if(!$errors = $this->validate_user($data))
{
$result = $this->so->add_user($data);
}

View File

@ -1,5 +1,5 @@
<?php
/**************************************************************************\
/***************************************************************************\
* eGroupWare - account administration *
* http://www.egroupware.org *
* -------------------------------------------- *
@ -34,7 +34,7 @@
$apps =& CreateObject('phpgwapi.applications',$userData['account_id']);
$apps->read_installed_apps();
/* dont think this is still used -- RalfBecker 2006-06-03
/* dont think this is still used -- RalfBecker 2006-06-03
// Read Group Apps
if ($userData['account_groups'])
{
@ -54,7 +54,7 @@
}
}
}
*/
*/
$apps->account_type = 'u';
$apps->account_id = $userData['account_id'];
$apps->data = Array(Array());
@ -67,12 +67,12 @@
if ($turned_on)
{
$apps->add($app);
/* dont think this is still used -- RalfBecker 2006-06-03
/* dont think this is still used -- RalfBecker 2006-06-03
if (!$apps_after[$app])
{
$apps_after[] = $app;
}
*/
*/
}
}
}
@ -84,7 +84,7 @@
}
$apps->account_apps = array(array());
// $apps_after = array(array());
// $apps_after = array(array());
return $userData['account_id'];
}

View File

@ -13,8 +13,7 @@
class uiaccounts
{
//(regis) maybe some of them should be deleted?
var $public_functions = array
(
var $public_functions = array(
'list_groups' => True,
'list_users' => True,
'add_group' => True,
@ -27,7 +26,7 @@
'view_user' => True,
'edit_group_hook' => True,
'edit_view_user_hook' => True,
'group_manager' => True,
'group_manager' => True
);
var $bo;
@ -48,7 +47,7 @@
'inv' => True,
'phpbrain' => True,
'projectmanager' => True,
'timesheet' => true,
'timesheet' => True
);
function uiaccounts()
@ -56,6 +55,11 @@
$this->bo =& CreateObject('admin.boaccounts');
$this->nextmatchs =& CreateObject('phpgwapi.nextmatchs');
@set_time_limit(300);
/* Moved from bo class */
if (get_magic_quotes_gpc()) // deal with magic_quotes_gpc On
{
$_POST = $this->array_stripslashes($_POST);
}
}
function row_action($action,$type,$account_id)
@ -72,7 +76,7 @@
'all' => 'all fields',
'lid' => 'LoginID',
'start' => 'start with',
'exact' => 'exact',
'exact' => 'exact'
);
if ($GLOBALS['egw']->acl->check('group_access',1,'admin'))
@ -145,7 +149,7 @@
'start' => $start,
'sort' => $sort,
'order' => $order,
'query_type' => $_REQUEST['query_type'],
'query_type' => $_REQUEST['query_type']
);
//_debug_array($search_param);
if (!$GLOBALS['egw']->acl->check('account_access',2,'admin'))
@ -223,13 +227,12 @@
}
$p->fp('rows','row',True);
}
}
$link_data += array(
'order' => $order,
'sort' => $sort,
'sort' => $sort
);
$p->set_var(array(
'query' => $GLOBALS['egw']->html->htmlspecialchars($GLOBALS['query']),
@ -497,6 +500,36 @@
return False;
}
if($_POST['edit'])
{
$group_permissions = ($_POST['account_apps']?$_POST['account_apps']:Array());
$account_apps = Array();
foreach($group_permissions as $key => $value)
{
if($value)
{
$account_apps[$key] = True;
}
}
@reset($account_apps);
$group_info = Array(
'account_id' => ($_POST['account_id']?(int)$_POST['account_id']:0),
'account_name' => ($_POST['account_name']?$_POST['account_name']:''),
'account_user' => $_POST['account_user'],
'account_apps' => $account_apps,
'account_email' => $_POST['account_email']
);
$errors = $this->bo->add_group($group_info);
if(is_array($errors))
{
$this->create_edit_group($group_info,$errors);
$GLOBALS['egw']->common->egw_exit();
}
$GLOBALS['egw']->redirect($GLOBALS['egw']->link('/index.php','menuaction=admin.uiaccounts.list_groups'));
}
else
{
$group_info = Array(
'account_id' => $_GET['account_id'],
'account_name' => '',
@ -505,6 +538,7 @@
);
$this->create_edit_group($group_info);
}
}
function add_user()
{
@ -512,6 +546,51 @@
{
$this->list_users();
}
if($_POST['submit'])
{
if(!($email = $_POST['account_email']))
{
$email = $GLOBALS['egw']->common->email_address($_POST['account_firstname'],$_POST['account_lastname'],$_POST['account_lid']);
}
$userData = array(
'account_type' => 'u',
'account_lid' => $accountPrefix . $_POST['account_lid'],
'account_firstname' => $_POST['account_firstname'],
'account_lastname' => $_POST['account_lastname'],
'account_passwd' => $_POST['account_passwd'],
'status' => ($_POST['account_status'] ? 'A' : ''),
'account_status' => ($_POST['account_status'] ? 'A' : ''),
'old_loginid' => ($_GET['old_loginid']?rawurldecode($_GET['old_loginid']):''),
'account_id' => ($_GET['account_id']?$_GET['account_id']:0),
'account_primary_group' => $_POST['account_primary_group'],
'account_passwd_2' => $_POST['account_passwd_2'],
'account_groups' => $_POST['account_groups'],
'anonymous' => $_POST['anonymous'],
'changepassword' => $_POST['changepassword'],
'account_permissions' => $_POST['account_permissions'],
'homedirectory' => $_POST['homedirectory'],
'loginshell' => $_POST['loginshell'],
'account_expires_never' => $_POST['never_expires'],
'account_email' => $email
/* 'file_space' => $_POST['account_file_space_number'] . "-" . $_POST['account_file_space_type'] */
);
/* when does the account expire */
if ($_POST['expires'] !== '' && !$_POST['never_expires'])
{
$jscal =& CreateObject('phpgwapi.jscalendar',False);
$userData += $jscal->input2date($_POST['expires'],False,'account_expires_day','account_expires_month','account_expires_year');
}
$errors = $this->bo->add_user($userData);
if(is_array($errors))
{
$this->create_edit_user($userData,$errors);
$GLOBALS['egw']->common->egw_exit();
}
$GLOBALS['egw']->redirect($GLOBALS['egw']->link('/index.php','menuaction=admin.uiaccounts.list_users'));
}
else
{
$this->create_edit_user(0);
@ -524,10 +603,9 @@
{
if ($_POST['yes'])
{
$this->bo->delete_group();
$this->bo->delete_group($_POST['account_id']);
}
$this->list_groups();
return False;
$GLOBALS['egw']->redirect($GLOBALS['egw']->link('/index.php','menuaction=admin.uiaccounts.list_groups'));
}
unset($GLOBALS['egw_info']['flags']['noheader']);
@ -603,8 +681,12 @@
{
if ($GLOBALS['egw']->acl->check('account_access',32,'admin') || $GLOBALS['egw_info']['user']['account_id'] == $_GET['account_id'])
{
$this->list_users();
return False;
$GLOBALS['egw']->redirect($GLOBALS['egw']->link('/index.php','menuaction=admin.uiaccounts.list_users'));
}
if($_POST['delete_account'])
{
$this->bo->delete_user($_POST['account_id'],$_POST['new_owner']);
$GLOBALS['egw']->redirect($GLOBALS['egw']->link('/index.php','menuaction=admin.uiaccounts.list_users'));
}
unset($GLOBALS['egw_info']['flags']['noheader']);
@ -623,7 +705,7 @@
)
);
$var = Array(
'form_action' => $GLOBALS['egw']->link('/index.php','menuaction=admin.boaccounts.delete_user'),
'form_action' => $GLOBALS['egw']->link('/index.php','menuaction=admin.uiaccounts.delete_user'),
'account_id' => $_GET['account_id']
);
@ -660,18 +742,45 @@
'extradata' => 'menuaction=admin.uiaclmanager.list_apps'
);
}
}
function edit_group($cd='',$account_id='')
{
if ($GLOBALS['egw']->acl->check('group_access',16,'admin'))
{
$this->list_groups();
return False;
$GLOBALS['egw']->redirect($GLOBALS['egw']->link('/index.php','menuaction=admin.uiaccounts.list_groups'));
}
if($_POST['edit'])
{
$group_permissions = ($_POST['account_apps']?$_POST['account_apps']:Array());
$account_apps = Array();
foreach($group_permissions as $key => $value)
{
if($value)
{
$account_apps[$key] = True;
}
}
@reset($account_apps);
$group_info = Array(
'account_id' => ($_POST['account_id']?(int)$_POST['account_id']:0),
'account_name' => ($_POST['account_name']?$_POST['account_name']:''),
'account_user' => $_POST['account_user'],
'account_apps' => $account_apps,
'account_email' => $_POST['account_email']
);
$errors = $this->bo->edit_group($group_info);
if(is_array($errors))
{
$this->create_edit_group($group_info,$errors);
$GLOBALS['egw']->common->egw_exit();
}
$GLOBALS['egw']->redirect($GLOBALS['egw']->link('/index.php','menuaction=admin.uiaccounts.list_groups'));
}
else
{
$cdid = $cd;
settype($cd,'integer');
$cd = ($_GET['cd']?$_GET['cd']:(int)$cdid);
@ -698,6 +807,7 @@
$this->create_edit_group($group_info);
}
}
}
function edit_view_user_hook()
{
@ -734,18 +844,87 @@
}
*/
//NDEE
}
function edit_user($cd='',$account_id='')
{
if ($GLOBALS['egw']->acl->check('account_access',16,'admin'))
if($GLOBALS['egw']->acl->check('account_access',16,'admin'))
{
$this->list_users();
return False;
}
if($_POST['submit'])
{
if(!($email = $_POST['account_email']))
{
$email = $GLOBALS['egw']->common->email_address($_POST['account_firstname'],$_POST['account_lastname'],$_POST['account_lid']);
}
$userData = array(
'account_lid' => $accountPrefix.$_POST['account_lid'],
'account_firstname' => $_POST['account_firstname'],
'account_lastname' => $_POST['account_lastname'],
'account_passwd' => $_POST['account_passwd'],
'account_status' => ($_POST['account_status'] ? 'A' : ''),
'old_loginid' => ($_GET['old_loginid']?rawurldecode($_GET['old_loginid']):''),
'account_id' => ($_GET['account_id']?$_GET['account_id']:0),
'account_passwd_2' => $_POST['account_passwd_2'],
'account_groups' => $_POST['account_groups'],
'account_primary_group' => $_POST['account_primary_group'],
'anonymous' => $_POST['anonymous'],
'changepassword' => $_POST['changepassword'],
'account_permissions' => $_POST['account_permissions'],
'homedirectory' => $_POST['homedirectory'],
'loginshell' => $_POST['loginshell'],
'account_expires_never' => $_POST['never_expires'],
'account_email' => $email,
/* 'file_space' => $_POST['account_file_space_number'] . "-" . $_POST['account_file_space_type'] */
);
if($userData['account_primary_group'] && (!isset($userData['account_groups']) || !in_array($userData['account_primary_group'],$userData['account_groups'])))
{
$userData['account_groups'][] = (int)$userData['account_primary_group'];
}
if($_POST['expires'] !== '' && !$_POST['never_expires'])
{
$jscal =& CreateObject('phpgwapi.jscalendar',False);
$userData += $jscal->input2date($_POST['expires'],False,'account_expires_day','account_expires_month','account_expires_year');
}
$errors = $this->bo->add_user($userData);
if(!@is_array($errors))
{
// check if would create a menu
// if we do, we can't return to the users list, because
// there are also some other plugins
if(!ExecMethod('admin.uimenuclass.createHTMLCode','edit_user'))
{
if($userData['account_id'] == $GLOBALS['egw_info']['user']['account_id'])
{
$GLOBALS['egw']->redirect_link('/index.php',array( // without redirect changes happen only in the next page-view!
'menuaction' => 'admin.uiaccounts.list_users'
));
}
// ExecMethod('admin.uiaccounts.list_users');
//return False;
}
else
{
if($userData['account_id'] == $GLOBALS['egw_info']['user']['account_id'])
{
$GLOBALS['egw']->redirect_link('/index.php',array( // without redirect changes happen only in the next page-view!
'menuaction' => 'admin.uiaccounts.edit_user',
'account_id' => $_GET['account_id']
));
}
}
// $GLOBALS['egw']->redirect($GLOBALS['egw']->link('/index.php','menuaction=admin.uiaccounts.list_users'));
}
else
{
$this->create_edit_user($userData['account_id'],$userData,$errors);
}
}
else
{
$cdid = $cd;
settype($cd,'integer');
$cd = ($_GET['cd']?$_GET['cd']:(int)$cdid);
@ -756,7 +935,7 @@
// todo
// not needed if i use the same file for new users too
if (! $account_id)
if(!$account_id)
{
$this->list_users();
return False;
@ -766,6 +945,7 @@
$this->create_edit_user($account_id);
}
}
}
function view_user()
{
@ -995,7 +1175,7 @@
$p->set_var('accounts',$GLOBALS['egw']->uiaccountsel->selection('account_user[]','admin_uiaccounts_user',$group_info['account_user'],'accounts',min(3+count($group_info['account_user']),10),false,'style="width: 300px;"'));
$var = Array(
'form_action' => $GLOBALS['egw']->link('/index.php','menuaction=admin.boaccounts.'.($group_info['account_id']?'edit':'add').'_group'),
'form_action' => $GLOBALS['egw']->link('/index.php','menuaction=admin.uiaccounts.'.($group_info['account_id']?'edit':'add').'_group'),
'hidden_vars' => '<input type="hidden" name="account_id" value="' . $group_info['account_id'] . '">',
'lang_group_name' => lang('group name'),
'group_name_value' => $group_info['account_name'],
@ -1081,7 +1261,6 @@
$p->set_var('select','');
$p->set_var('popwin','');
$p->pfp('out','edit');
}
function create_edit_user($_account_id,$_userData='',$_errors='')
@ -1159,7 +1338,7 @@
}
$allGroups = $account->get_list('groups');
}
$page_params['menuaction'] = 'admin.boaccounts.'.($_account_id?'edit':'add').'_user';
$page_params['menuaction'] = 'admin.uiaccounts.'.($_account_id?'edit':'add').'_user';
if($_account_id)
{
$page_params['account_id'] = $_account_id;
@ -1192,7 +1371,8 @@
$t->set_var($var);
$t->parse('form_buttons','form_buttons_',True);
if ($GLOBALS['egw_info']['server']['ldap_extra_attributes']) {
if ($GLOBALS['egw_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['egw_info']['server']['ldap_account_home'].$account_lid).'">';
@ -1260,7 +1440,7 @@
'account_passwd' => $userData['account_passwd'],
'account_passwd_2' => $userData['account_passwd_2'],
'account_file_space' => $account_file_space,
'account_id' => (int) $userData['account_id'],
'account_id' => (int) $userData['account_id']
);
if($userData['expires'] == -1)
@ -1350,8 +1530,7 @@
=> '<select
name="account_primary_group">'."\n".$primary_group_select.'</
select>'."\n",
'permissions_list'
=> $appRightsOutput,
'permissions_list' => $appRightsOutput,
'lang_app' => lang('application'),
'lang_acl' => lang('enabled').' / '.lang('ACL'),
);
@ -1440,7 +1619,7 @@
$var['lang_group'] = lang('Group');
$var['group_name'] = $group_info['account_name'];
$var['tr_color1'] = $GLOBALS['egw_info']['user']['theme']['row_on'];
$var['form_action'] = $GLOBALS['egw']->link('/index.php','menuaction=admin.boaccounts.set_group_managers');
$var['form_action'] = $GLOBALS['egw']->link('/index.php','menuaction=admin.uiaccounts.set_group_managers');
$var['hidden'] = '<input type="hidden" name="account_id" value="'.$group_info['account_id'].'">';
$var['lang_select_managers'] = lang('Select Group Managers');
$var['group_members'] = '<select name="managers[]" size="'.(count($account_list)<5?count($account_list):5).'" multiple>'.$user_list.'</select>';
@ -1453,5 +1632,52 @@
$t->pfp('out','form');
}
function set_group_managers()
{
if($GLOBALS['egw']->acl->check('group_access',16,'admin') || $_POST['cancel'])
{
$GLOBALS['egw']->redirect($GLOBALS['egw']->link('/index.php','menuaction=admin.uiaccounts.list_groups'));
$GLOBALS['egw']->common->egw_exit();
}
elseif($_POST['submit'])
{
$acl =& CreateObject('phpgwapi.acl',(int)$_POST['account_id']);
$users = $GLOBALS['egw']->accounts->member($_POST['account_id']);
@reset($users);
while($managers && list($key,$user) = each($users))
{
$acl->add_repository('phpgw_group',(int)$_POST['account_id'],$user['account_id'],1);
}
$managers = $_POST['managers'];
@reset($managers);
while($managers && list($key,$manager) = each($managers))
{
$acl->add_repository('phpgw_group',(int)$_POST['account_id'],$manager,(1 + EGW_ACL_GROUP_MANAGERS));
}
}
$GLOBALS['egw']->redirect($GLOBALS['egw']->link('/index.php','menuaction=admin.uiaccounts.list_groups'));
$GLOBALS['egw']->common->egw_exit();
}
/**
* applies stripslashes recursively on each element of an array
*
* @param array &$var
* @return array
*/
function array_stripslashes($var)
{
if(!is_array($var))
{
return stripslashes($var);
}
foreach($var as $key => $val)
{
$var[$key] = is_array($val) ? $this->array_stripslashes($val) : stripslashes($val);
}
return $var;
}
}
?>