Commit 5222d3cb authored by Richard Mansfield's avatar Richard Mansfield

Set authinstance on edit user account page

parent acf7993e
......@@ -27,7 +27,7 @@
define('INTERNAL', 1);
define('ADMIN', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
define('TITLE', get_string('edituseraccount', 'admin'));
define('TITLE', get_string('accountsettings', 'admin'));
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'admin');
require_once('pieforms/pieform.php');
......@@ -124,6 +124,23 @@ $elements['quota'] = array(
'defaultvalue' => $user->quota / 1048576,
'rules' => array('integer' => true),
);
$authinstances = auth_get_auth_instances();
if (count($authinstances) > 1) {
$options = array();
foreach ($authinstances as $authinstance) {
$options[$authinstance->id] = $authinstance->displayname. ': '.$authinstance->instancename;
}
$elements['authinstance'] = array(
'type' => 'select',
'title' => get_string('authenticatedby', 'admin'),
'options' => $options,
'defaultvalue' => $user->authinstance
);
}
$elements['submit'] = array(
'type' => 'submit',
'value' => get_string('savechanges','admin'),
......@@ -150,6 +167,9 @@ function edituser_submit(Pieform $form, $values) {
$user->staff = (int) ($values['staff'] == 'on');
$user->admin = (int) ($values['admin'] == 'on');
$user->quota = $values['quota'] * 1048576;
if (isset($values['authinstance'])) {
$user->authinstance = $values['authinstance'];
}
update_record('usr', $user);
......
......@@ -68,44 +68,6 @@ $ALLOWEDKEYS = array(
'authinstance'
);
/**
* TODO: do we want to keep this function? Then it should be in auth/lib.php
* Given an institution, returns the authentication methods used by it, sorted
* by priority.
*
* @param string $institution Name of the institution
* @return array Array of auth instance records
*/
function auth_get_auth_instances() {
static $cache = array();
if (count($cache) > 0) {
return $cache;
}
$sql ='
SELECT DISTINCT
i.id,
inst.name,
inst.displayname,
i.instancename
FROM
{institution} inst,
{auth_instance} i
WHERE
i.institution = inst.name
ORDER BY
inst.displayname,
i.instancename';
$cache = get_records_sql_array($sql, array());
if (empty($cache)) {
return array();
}
return $cache;
}
$authinstances = auth_get_auth_instances();
if (count($authinstances) > 1) {
......
......@@ -389,6 +389,46 @@ function auth_setup () {
}
}
/**
*
* Returns all auth instances
*
* @return array Array of auth instance records
*/
function auth_get_auth_instances() {
static $cache = array();
if (count($cache) > 0) {
return $cache;
}
$sql ='
SELECT DISTINCT
i.id,
inst.name,
inst.displayname,
i.instancename
FROM
{institution} inst,
{auth_instance} i
WHERE
i.institution = inst.name
ORDER BY
inst.displayname,
i.instancename';
$cache = get_records_sql_array($sql, array());
if (empty($cache)) {
return array();
}
return $cache;
}
/**
* Given an institution, returns the authentication methods used by it, sorted
* by priority.
......
......@@ -241,6 +241,7 @@ $string['usersuspended'] = 'User suspended';
$string['userunsuspended'] = 'User unsuspended';
// User account settings
$string['accountsettings'] = 'Account settings';
$string['siteaccountsettings'] = 'Site account settings';
$string['resetpassword'] = 'Reset password';
$string['forcepasswordchange'] = 'Force password change on next login';
......@@ -275,6 +276,7 @@ $string['registrationallowed'] = 'Registration allowed?';
$string['registrationalloweddescription'] = 'Whether users can register for the system with this institution';
$string['defaultmembershipperiod'] = 'Default membership period';
$string['defaultmembershipperioddescription'] = 'How long new members remain associated with the institution';
$string['authenticatedby'] = 'Authentication Method';
// general stuff
......
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