Commit ec8805ab authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Create admin user account editing page

parent 16154f09
......@@ -27,7 +27,7 @@
define('INTERNAL', 1);
define('ADMIN', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
define('TITLE', get_string('suspenduser', 'admin'));
define('TITLE', get_string('edituseraccount', 'admin'));
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'admin');
require_once('pieforms/pieform.php');
......@@ -38,8 +38,12 @@ if (!$user = get_record('usr', 'id', $id)) {
throw new UserNotFoundException("User not found");
}
$f = pieform(array(
if (empty($user->suspendedcusr)) {
$suspendform = pieform(array(
'name' => 'suspend',
'plugintype' => 'core',
'pluginname' => 'admin',
'elements' => array(
'id' => array(
'type' => 'hidden',
......@@ -50,26 +54,115 @@ $f = pieform(array(
'title' => get_string('reason'),
),
'submit' => array(
'type' => 'submitcancel',
'value' => array(get_string('suspenduser','admin'), get_string('cancel')),
'type' => 'submit',
'value' => get_string('suspenduser','admin'),
),
)
));
));
} else {
$suspendform = pieform(array(
'name' => 'unsuspend',
'plugintype' => 'core',
'pluginname' => 'admin',
'elements' => array(
'id' => array(
'type' => 'hidden',
'value' => $id,
),
'submit' => array(
'type' => 'submit',
'value' => get_string('unsuspenduser','admin'),
),
)
));
}
function suspend_submit(Pieform $form, $values) {
global $SESSION;
suspend_user($values['id'], $values['reason']);
$SESSION->add_ok_msg(get_string('usersuspended', 'admin'));
redirect('/user/view.php?id=' . $values['id']);
redirect('/admin/users/edit.php?id=' . $values['id']);
}
function suspend_cancel_submit() {
redirect('/admin/users/search.php');
function unsuspend_submit(Pieform $form, $values) {
global $SESSION;
unsuspend_user($values['id']);
$SESSION->add_ok_msg(get_string('userunsuspended', 'admin'));
redirect('/admin/users/edit.php?id=' . $values['id']);
}
// Site-wide account settings
$elements['id'] = array(
'type' => 'hidden',
'rules' => array('integer' => true),
'value' => $id,
);
$elements['password'] = array(
'type' => 'text',
'title' => get_string('resetpassword','admin'),
);
$elements['passwordchange'] = array(
'type' => 'checkbox',
'title' => get_string('forcepasswordchange','admin'),
'defaultvalue' => $user->passwordchange,
);
$elements['staff'] = array(
'type' => 'checkbox',
'title' => get_string('sitestaff','admin'),
'defaultvalue' => $user->staff,
);
$elements['admin'] = array(
'type' => 'checkbox',
'title' => get_string('siteadmin','admin'),
'defaultvalue' => $user->admin,
);
$elements['quota'] = array(
'type' => 'text',
'title' => get_string('filequota','admin'),
'defaultvalue' => $user->quota / 1048576,
'rules' => array('integer' => true),
);
$elements['submit'] = array(
'type' => 'submit',
'value' => get_string('savechanges','admin'),
);
$mainform = pieform(array(
'name' => 'edituser',
'renderer' => 'table',
'plugintype' => 'core',
'pluginname' => 'admin',
'elements' => $elements,
));
function edituser_submit(Pieform $form, $values) {
if (!$user = get_record('usr', 'id', $values['id'])) {
return false;
}
if (isset($values['password']) && $values['password'] !== '') {
$user->password = $values['password'];
}
$user->passwordchange = (int) ($values['passwordchange'] == 'on');
$user->staff = (int) ($values['staff'] == 'on');
$user->admin = (int) ($values['admin'] == 'on');
$user->quota = $values['quota'] * 1048576;
update_record('usr', $user);
redirect('/admin/users/edit.php?id='.$user->id);
}
$smarty = smarty();
$smarty->assign('user', $user);
$smarty->assign('form', $f);
$smarty->display('admin/users/suspend.tpl');
$smarty->assign('suspendform', $suspendform);
$smarty->assign('mainform', $mainform);
$smarty->display('admin/users/edit.tpl');
?>
......@@ -6,7 +6,6 @@ function UserSearch() {
self.rewriteQueryButton();
self.rewritePaging();
self.rewriteSorting();
self.rewriteSuspendLinks();
self.params = {};
}
......@@ -110,13 +109,6 @@ function UserSearch() {
$('results').innerHTML = data.data;
self.rewritePaging();
self.rewriteSorting();
self.rewriteSuspendLinks();
});
}
this.rewriteSuspendLinks = function() {
forEach(getElementsByTagAndClassName('a', 'suspend-user-link', 'searchresults'), function(i) {
connect(i, 'onclick', suspendDisplay);
});
}
......@@ -124,46 +116,3 @@ function UserSearch() {
}
userSearch = new UserSearch();
function suspendDisplay(e) {
e.stop();
ref = this.parentNode.parentNode; // get the TR
var reason = INPUT({'type': 'text'});
var cancelButton = BUTTON({'type': 'button'}, get_string('cancel'));
var saveButton = BUTTON({'type': 'button'}, get_string('suspenduser'));
insertSiblingNodesAfter(ref, TR(null, TD({'colSpan': 6},
get_string('suspensionreason') + ': ',
reason,
cancelButton,
saveButton
)));
reason.focus();
connect(reason, 'onkeypress', function (k) {
if (k.key().code == 13) {
self.suspendSave(reason);
}
if (k.key().code == 27) {
suspendCancel(reason);
}
});
connect(cancelButton, 'onclick', partial(suspendCancel, reason));
var id = getNodeAttribute(this, 'href').replace(/.*\?id=(\d+).*/, '$1');
connect(saveButton, 'onclick', partial(suspendSave, id, reason));
}
function suspendSave(id, reason) {
var susReason = reason.value;
sendjsonrequest('search.json.php', {'action': 'suspend', 'reason': susReason, 'id': id}, 'GET');
removeElement(reason.parentNode.parentNode);
}
function suspendCancel(reason) {
removeElement(reason.parentNode.parentNode);
}
......@@ -238,6 +238,20 @@ $string['usersdeletedsuccessfully'] = 'Users deleted successfully';
$string['usersunsuspendedsuccessfully'] = 'Users unsuspended successfully';
$string['suspendingadmin'] = 'Suspending Admin';
$string['usersuspended'] = 'User suspended';
$string['userunsuspended'] = 'User unsuspended';
// User account settings
$string['siteaccountsettings'] = 'Site account settings';
$string['resetpassword'] = 'Reset password';
$string['forcepasswordchange'] = 'Force password change on next login';
$string['sitestaff'] = 'Site staff';
$string['siteadmin'] = 'Site administrator';
$string['suspended'] = 'Suspended';
$string['suspendedreason'] = 'Reason for suspension';
$string['suspendedreasondescription'] = 'The explanation you enter here will be displayed to the user when they try to login';
$string['unsuspenduser'] = 'Unsuspend User';
$string['thisuserissuspended'] = 'This user has been suspended';
$string['filequota'] = 'File quota (MB)';
// Institutions
$string['admininstitutions'] = 'Admininster Institutions';
......
......@@ -175,8 +175,6 @@ function build_admin_user_search_results($search, $offset, $limit, $sortby, $sor
'email' => array('name' => get_string('email')),
'institution' => array('name' => get_string('institution'),
'template' => file_get_contents($templatedir . 'institution.tpl')),
'suspend' => array('name' => '',
'template' => file_get_contents($templatedir . 'suspendlink.tpl'))
);
$smarty = smarty_core();
......
{include file="header.tpl"}
{include file="columnfullstart.tpl"}
<h2><a href="{$WWWROOT}user/view.php?id={$user->id}">{$user->firstname} {$user->lastname} ({$user->username})</a></h2>
{if empty($user->suspendedcusr)}
<h3>{str tag="suspenduser" section="admin"}</h3>
{else}
<h4>{str tag="thisuserissuspended" section="admin"}</h4>
<div><strong>{str tag="suspendedreason" section="admin"}:</strong></div>
<div>{$user->suspendedreason}</div>
{/if}
{$suspendform}
<h3>{str tag="siteaccountsettings" section="admin"}</h3>
{$mainform}
{include file="columnfullend.tpl"}
{include file="footer.tpl"}
<a href="{$WWWROOT}user/view.php?id={$r.id}">{$r.username}</a>
\ No newline at end of file
<a href="{$WWWROOT}/admin/users/edit.php?id={$r.id}">{$r.username}</a>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment