Commit 2e0819ce authored by Nigel McNie's avatar Nigel McNie
Browse files

(#2212) Major cleanup of user edit screen.

It now is ordered a bit more sensibly. Improved help and description
text on the page. Added a button to allow admins to delete users.
Improved the suspension/unsuspension process.
parent 1bf46226
......@@ -42,63 +42,6 @@ if (!$USER->is_admin_for_user($user)) {
redirect(get_config('wwwroot').'user/view.php?id='.$id);
}
$suspended = $user->get('suspendedcusr');
if (empty($suspended)) {
$suspendform = pieform(array(
'name' => 'edituser_suspend',
'plugintype' => 'core',
'pluginname' => 'admin',
'elements' => array(
'id' => array(
'type' => 'hidden',
'value' => $id,
),
'reason' => array(
'type' => 'textarea',
'rows' => 5,
'cols' => 60,
'title' => get_string('reason'),
'description' => get_string('suspendedreasondescription', 'admin'),
),
'submit' => array(
'type' => 'submit',
'value' => get_string('suspenduser','admin'),
),
)
));
} else {
$suspendform = pieform(array(
'name' => 'edituser_unsuspend',
'plugintype' => 'core',
'pluginname' => 'admin',
'elements' => array(
'id' => array(
'type' => 'hidden',
'value' => $id,
),
'submit' => array(
'type' => 'submit',
'value' => get_string('unsuspenduser','admin'),
),
)
));
$suspender = display_name(get_record('usr', 'id', $suspended));
}
function edituser_suspend_submit(Pieform $form, $values) {
global $SESSION;
suspend_user($values['id'], $values['reason']);
$SESSION->add_ok_msg(get_string('usersuspended', 'admin'));
redirect('/admin/users/edit.php?id=' . $values['id']);
}
function edituser_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
$currentdate = getdate();
......@@ -123,14 +66,14 @@ if ($USER->get('admin')) {
$elements['staff'] = array(
'type' => 'checkbox',
'title' => get_string('sitestaff','admin'),
//'description' => get_string('sitestaffdescription','admin'),
'defaultvalue' => $user->staff,
'help' => true,
);
$elements['admin'] = array(
'type' => 'checkbox',
'title' => get_string('siteadmin','admin'),
//'description' => get_string('siteadmindescription','admin'),
'defaultvalue' => $user->admin,
'help' => true,
);
}
$elements['expiry'] = array(
......@@ -153,10 +96,18 @@ $authinstances = auth_get_auth_instances();
if (count($authinstances) > 1) {
$options = array();
// NOTE: This is a little broken at the moment. The "username in the remote
// system" setting is only actively used by the XMLRPC authentication
// plugin, and thus only makes sense when the user is authenticating in
// this manner.
//
// We hope to one day make it possible for users to get into accounts via
// multiple methods, at which time we can tie the username-in-remote-system
// setting to the XMLRPC plugin only, making the UI a bit more consistent
$external = false;
foreach ($authinstances as $authinstance) {
if ($USER->can_edit_institution($authinstance->name)) {
$options[$authinstance->id] = $authinstance->displayname. ': '.$authinstance->instancename;
$options[$authinstance->id] = $authinstance->instancename . ' (' . $authinstance->displayname . ')';
if ($authinstance->authname != 'internal') {
$external = true;
}
......@@ -167,9 +118,10 @@ if (count($authinstances) > 1) {
$elements['authinstance'] = array(
'type' => 'select',
'title' => get_string('authenticatedby', 'admin'),
//'description' => get_string('authenticatedbydescription', 'admin'),
'description' => get_string('authenticatedbydescription', 'admin'),
'options' => $options,
'defaultvalue' => $user->authinstance,
'help' => true,
);
if ($external) {
$un = get_field('auth_remote_user', 'remoteusername', 'authinstance', $user->authinstance, 'localusr', $user->id);
......@@ -258,8 +210,96 @@ function edituser_site_submit(Pieform $form, $values) {
}
// Institution settings form
// Suspension/deletion controls
$suspended = $user->get('suspendedcusr');
if (empty($suspended)) {
$suspendform = pieform(array(
'name' => 'edituser_suspend',
'plugintype' => 'core',
'pluginname' => 'admin',
'elements' => array(
'id' => array(
'type' => 'hidden',
'value' => $id,
),
'reason' => array(
'type' => 'textarea',
'rows' => 5,
'cols' => 60,
'title' => get_string('reason'),
'description' => get_string('suspendedreasondescription', 'admin'),
),
'submit' => array(
'type' => 'submit',
'value' => get_string('suspenduser','admin'),
),
)
));
}
else {
$suspendformdef = array(
'name' => 'edituser_unsuspend',
'plugintype' => 'core',
'pluginname' => 'admin',
'renderer' => 'oneline',
'elements' => array(
'id' => array(
'type' => 'hidden',
'value' => $id,
),
'submit' => array(
'type' => 'submit',
'value' => get_string('unsuspenduser','admin'),
),
)
);
// Create two forms for unsuspension - one in the suspend message and the
// other where the 'suspend' button normally goes. This keeps the HTML IDs
// unique
$suspendform = pieform($suspendformdef);
$suspendformdef['name'] = 'edituser_suspend2';
$suspendformdef['validatecallback'] = 'edituser_unsuspend_validate';
$suspendformdef['successcallback'] = 'edituser_unsuspend_submit';
$suspendform2 = pieform($suspendformdef);
$suspender = display_name(get_record('usr', 'id', $suspended));
}
function edituser_suspend_submit(Pieform $form, $values) {
global $SESSION;
suspend_user($values['id'], $values['reason']);
$SESSION->add_ok_msg(get_string('usersuspended', 'admin'));
redirect('/admin/users/edit.php?id=' . $values['id']);
}
function edituser_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']);
}
$deleteform = pieform(array(
'name' => 'edituser_delete',
'plugintype' => 'core',
'pluginname' => 'admin',
'renderer' => 'oneline',
'elements' => array(
'id' => array(
'type' => 'hidden',
'value' => $id,
),
'submit' => array(
'type' => 'submit',
'value' => get_string('deleteuser', 'admin'),
'confirm' => get_string('confirmdeleteuser', 'admin'),
),
),
));
// Institution settings form
$elements = array(
'id' => array(
'type' => 'hidden',
......@@ -302,13 +342,13 @@ foreach ($user->get('institutions') as $i) {
'type' => 'submit',
'value' => get_string('update'),
),
$i->institution.'_remove' => array(
'type' => 'submit',
'value' => get_string('removeuserfrominstitution', 'admin'),
'confirm' => get_string('confirmremoveuserfrominstitution', 'admin'),
),
),
);
$elements[$i->institution.'_remove'] = array(
'type' => 'submit',
'value' => get_string('remove'),
'confirm' => get_string('confirmremoveuserfrominstitution', 'admin'),
);
}
// Only site admins can add institutions; institutional admins must invite
......@@ -321,14 +361,18 @@ if ($USER->get('admin')
}
}
if (!empty($options)) {
$elements['addinstitutionheader'] = array(
'type' => 'markup',
'value' => '<tr><td colspan="2"><h4>' . get_string('addusertoinstitution', 'admin') . '</h4></td></tr>',
);
$elements['addinstitution'] = array(
'type' => 'select',
'title' => get_string('addinstitution', 'admin'),
'title' => get_string('institution'),
'options' => $options,
);
$elements['add'] = array(
'type' => 'submit',
'value' => get_string('addinstitution','admin'),
'value' => get_string('addusertoinstitution', 'admin'),
);
}
}
......@@ -427,6 +471,10 @@ if ($suspended) {
$smarty->assign('suspendedby', get_string('suspendedby', 'admin', $suspender));
}
$smarty->assign('suspendform', $suspendform);
if (isset($suspendform2)) {
$smarty->assign('suspendform2', $suspendform2);
}
$smarty->assign('deleteform', $deleteform);
$smarty->assign('siteform', $siteform);
$smarty->assign('institutions', count($allinstitutions) > 1);
$smarty->assign('institutionform', $institutionform);
......
......@@ -296,10 +296,8 @@ $string['resetpassworddescription'] = 'If you enter text here, it will replace t
$string['forcepasswordchange'] = 'Force password change on next login';
$string['forcepasswordchangedescription'] = 'The user will be directed to a change password page the next time they login.';
$string['sitestaff'] = 'Site Staff';
$string['sitestaffdescription'] = 'If checked, the user can create controlled Communities, receive and release submitted views and access key user profile information.';
$string['siteadmins'] = 'Site Admins';
$string['siteadmin'] = 'Site administrator';
$string['siteadmindescription'] = 'Site administrators can to do anything and go anywhere on the site';
$string['siteadmin'] = 'Site Administrator';
$string['accountexpiry'] = 'Account expires';
$string['accountexpirydescription'] = 'Date on which the user\'s login is automatically disabled.';
$string['suspended'] = 'Suspended';
......@@ -308,8 +306,12 @@ $string['suspendedreasondescription'] = 'The text that will be displayed to the
$string['unsuspenduser'] = 'Unsuspend User';
$string['thisuserissuspended'] = 'This user has been suspended';
$string['suspendedby'] = 'This user has been suspended by %s';
$string['deleteuser'] = 'Delete User';
$string['confirmdeleteuser'] = 'Are you sure you want to delete this user?';
$string['filequota'] = 'File quota (MB)';
$string['filequotadescription'] = 'Total storage available in the user\'s files area.';
$string['addusertoinstitution'] = 'Add User to Institution';
$string['removeuserfrominstitution'] = 'Remove user from this institution';
$string['confirmremoveuserfrominstitution'] = 'Are you sure you want to remove the user from this institution?';
// Add User
......@@ -349,9 +351,9 @@ $string['registrationalloweddescription2'] = 'Whether users can register for you
$string['defaultmembershipperiod'] = 'Default membership period';
$string['defaultmembershipperioddescription'] = 'How long new members remain associated with the institution';
$string['authenticatedby'] = 'Authentication Method';
$string['authenticatedbydescription'] = '';
$string['authenticatedbydescription'] = 'How this user authenticates to Mahara';
$string['remoteusername'] = 'Username for external authentication';
$string['remoteusernamedescription'] = 'If this user is authenticated by an external method and you would like to associate them with a different identity on a remote database, enter their remote username here.';
$string['remoteusernamedescription'] = 'The username that this user has in the remote system';
$string['institutionsettings'] = 'Institution Settings';
$string['changeinstitution'] = 'Change Institution';
$string['institutionstaff'] = 'Institution Staff';
......
......@@ -519,9 +519,10 @@ $string['virusrepeatsubject'] = 'Warning: %s is a repeat virus uploader.';
$string['virusrepeatmessage'] = 'The user %s has uploaded multiple files which have been scanned by a virus checker and found to be infected.';
$string['youraccounthasbeensuspended'] = 'Your account has been suspended';
$string['youraccounthasbeensuspendedtext'] = 'Your account has been suspended'; // @todo: more info?
$string['youraccounthasbeensuspendedtext2'] = 'Your account at %s has been suspended by %s.'; // @todo: more info?
$string['youraccounthasbeensuspendedreasontext'] = "Your account at %s has been suspended by %s. Reason:\n\n%s";
$string['youraccounthasbeenunsuspended'] = 'Your account has been unsuspended';
$string['youraccounthasbeenunsuspendedtext'] = 'Your account has been unsuspended'; // @todo: more info?
$string['youraccounthasbeenunsuspendedtext2'] = 'Your account at %s has been unsuspended. You may once again log in and use the site.'; // can't provide a login link because we don't know how they log in - it might be by xmlrpc
// size of stuff
$string['sizemb'] = 'MB';
......
......@@ -1474,6 +1474,11 @@ function xmldb_core_upgrade($oldversion=0) {
ensure_record_exists('event_type', $event, $event);
}
if ($oldversion < 2008110400) {
// Correct capitalisation of internal authinstance for 'no institution', only if it hasn't changed previously
execute_sql("UPDATE {auth_instance} SET instancename = 'Internal' WHERE institution = 'mahara' AND authname = 'internal' AND instancename = 'internal'");
}
return $status;
}
......
......@@ -560,7 +560,7 @@ function core_install_lastcoredata_defaults() {
insert_record('institution', $institution);
$auth_instance = new StdClass;
$auth_instance->instancename = 'internal';
$auth_instance->instancename = 'Internal';
$auth_instance->priority='1';
$auth_instance->institution = 'mahara';
$auth_instance->authname = 'internal';
......
......@@ -640,7 +640,14 @@ function suspend_user($suspendeduserid, $reason, $suspendinguserid=null) {
$message = new StdClass;
$message->users = array($suspendeduserid);
$message->subject = get_string_from_language($lang, 'youraccounthasbeensuspended');
$message->message = get_string_from_language($lang, 'youraccounthasbeensuspendedtext');
if ($reason == '') {
$message->message = get_string_from_language($lang, 'youraccounthasbeensuspendedtext2', 'mahara',
get_config('sitename'), display_name($suspendinguserid, $suspendeduserid));
}
else {
$message->message = get_string_from_language($lang, 'youraccounthasbeensuspendedreasontext', 'mahara',
get_config('sitename'), display_name($suspendinguserid, $suspendeduserid), $reason);
}
require_once('activity.php');
activity_occurred('maharamessage', $message);
......@@ -664,7 +671,7 @@ function unsuspend_user($userid) {
$message = new StdClass;
$message->users = array($userid);
$message->subject = get_string_from_language($lang, 'youraccounthasbeenunsuspended');
$message->message = get_string_from_language($lang, 'youraccounthasbeenunsuspendedtext');
$message->message = get_string_from_language($lang, 'youraccounthasbeenunsuspendedtext2', 'mahara', get_config('sitename'));
require_once('activity.php');
activity_occurred('maharamessage', $message);
......
......@@ -2707,6 +2707,32 @@ table#initials .initial-letters {
padding: 0;
}
/* MANAGE USERS > EDIT USER */
#edituser hr {
height: 1px;
border: 1px solid #aaa;
border-width: 1px 0 0 0;
}
#edituser .message h4 {
margin: 0;
}
#edituser .message div#suspendreason {
text-align: left;
width: 50%;
margin: 0 auto;
}
#edituser table#suspenddelete {
width: 90%;
margin: 0 auto;
}
#edituser table#suspenddelete td#delete {
width: 50%;
text-align: center;
}
#edituser table#suspenddelete h4 {
margin-top: 0;
}
/* MANAGE USERS > SUSPENDED USERS */
#suspendedlist {
......
{include file="header.tpl"}
{include file="columnfullstart.tpl"}
<div id="edituser">
<div id="edituser" style="position: relative;">
<div style="position: absolute; top: 0; right: 0;"><a href="{$WWWROOT}user/view.php?id={$user->id}"><img src="{$WWWROOT}thumb.php?type=profileiconbyid&amp;maxwidth=100&amp;maxheight=100&amp;id={$user->profileicon}" alt=""></a></div>
<h2><a href="{$WWWROOT}user/view.php?id={$user->id}">{$user->firstname} {$user->lastname} ({$user->username})</a></h2>
{if !empty($loginas)}
<div><a href="{$WWWROOT}admin/users/changeuser.php?id={$user->id}">{$loginas}</a></div>
{/if}
{if !$suspended}
<h3>{str tag="suspenduser" section="admin"}</h3>
{else}
{if $suspended}
<div class="message">
<h4>{$suspendedby|escape}</h4>
{if $user->suspendedreason}
<div><strong>{str tag="suspendedreason" section="admin"}:</strong></div>
<div>{$user->suspendedreason}</div>
<div id="suspendreason">
<h5>{str tag="suspendedreason" section="admin"}:</h5>
{$user->suspendedreason|format_whitespace}
</div>
{/if}
<div class="center">{$suspendform2}</div>
</div>
{/if}
{$suspendform}
<h3>{str tag="siteaccountsettings" section="admin"}</h3>
<p>Here you can view and set details for this user account. Below, you can also <a href="#suspend">suspend or delete this account</a>, or change settings for this user in the <a href="#institutions">institutions they are in</a>.</p>
{$siteform}
<!--<h3>{str tag="suspenduser" section="admin"}</h3>-->
<hr>
<h3 id="suspend">Suspend/Delete User</h3>
<p>Here you may suspend or entirely delete a user account. Suspended users are unable to log in until their account is unsuspended. Please note that while a suspension can be undone, deletion <strong>cannot</strong> be undone.</p>
<table id="suspenddelete">
<tr>
<td>
<h4>Suspend User</h4>
{$suspendform}
</td>
<td id="delete">
<h4>Delete User</h4>
<p>Please note that this operation <strong>cannot be undone</strong>.</p>
{$deleteform}
</td>
</tr>
</table>
{if ($institutions)}
<h3>{str tag="institutionsettings" section="admin"}</h3>
<hr>
<h3 id="institutions">{str tag="institutionsettings" section="admin"}</h3>
<p>Here you can change settings regarding this user's membership with institutions in the system.</p>
{$institutionform}
{/if}
</div>
......
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