Commit 90764906 authored by Donal McMullan's avatar Donal McMullan
Browse files

Better support for creating new institutions and their auth instances

parent 9f037a5c
...@@ -91,13 +91,14 @@ if ($institution || $add) { ...@@ -91,13 +91,14 @@ if ($institution || $add) {
exit; exit;
} }
$instancearray = array();
$instancestring = '';
$c = count($authinstances);
if (!$add) { if (!$add) {
$data = get_record('institution', 'name', $institution); $data = get_record('institution', 'name', $institution);
$lockedprofilefields = (array) get_column('institution_locked_profile_field', 'profilefield', 'name', $institution); $lockedprofilefields = (array) get_column('institution_locked_profile_field', 'profilefield', 'name', $institution);
$c = count($authinstances);
$instancestring = '';
$instancearray = array();
// TODO: Find a better way to work around Smarty's minimal looping logic // TODO: Find a better way to work around Smarty's minimal looping logic
foreach($authinstances as $key => $val) { foreach($authinstances as $key => $val) {
$authinstances[$key]->index = $key; $authinstances[$key]->index = $key;
...@@ -116,6 +117,8 @@ if ($institution || $add) { ...@@ -116,6 +117,8 @@ if ($institution || $add) {
$data->defaultaccountinactivewarn = 604800; // 1 week $data->defaultaccountinactivewarn = 604800; // 1 week
$lockedprofilefields = array(); $lockedprofilefields = array();
$smarty->assign('add', true); $smarty->assign('add', true);
$authtypes = auth_get_available_auth_types();
} }
safe_require('artefact', 'internal'); safe_require('artefact', 'internal');
...@@ -276,7 +279,7 @@ function institution_submit(Pieform $form, $values) { ...@@ -276,7 +279,7 @@ function institution_submit(Pieform $form, $values) {
if ($add) { if ($add) {
insert_record('institution', $newinstitution); insert_record('institution', $newinstitution);
} }
else { else {
$where = new StdClass; $where = new StdClass;
$where->name = $institution; $where->name = $institution;
update_record('institution', $newinstitution, $where); update_record('institution', $newinstitution, $where);
...@@ -293,9 +296,17 @@ function institution_submit(Pieform $form, $values) { ...@@ -293,9 +296,17 @@ function institution_submit(Pieform $form, $values) {
} }
db_commit(); db_commit();
$message = ($add) ? 'institutionaddedsuccessfully' : 'institutionupdatedsuccessfully'; if ($add) {
$message = 'institutionaddedsuccessfully';
$nexturl = '/admin/users/institutions.php?i='.urlencode($institution);
}
else {
$message = 'institutionupdatedsuccessfully';
$nexturl = '/admin/users/institutions.php';
}
$SESSION->add_ok_msg(get_string($message, 'admin')); $SESSION->add_ok_msg(get_string($message, 'admin'));
redirect('/admin/users/institutions.php'); redirect($nexturl);
} }
function institution_cancel_submit() { function institution_cancel_submit() {
......
...@@ -387,10 +387,14 @@ function auth_setup () { ...@@ -387,10 +387,14 @@ function auth_setup () {
* @param string $institution Name of the institution * @param string $institution Name of the institution
* @return array Array of auth instance records * @return array Array of auth instance records
*/ */
function auth_get_auth_instances_for_institution($institution) { function auth_get_auth_instances_for_institution($institution=null) {
global $CFG; global $CFG;
static $cache = array(); static $cache = array();
if(null == $institution) {
return array();
}
if (!isset($cache[$institution])) { if (!isset($cache[$institution])) {
// Get auth instances in order of priority // Get auth instances in order of priority
// DO NOT CHANGE THE SORT ORDER OF THIS RESULT SET // DO NOT CHANGE THE SORT ORDER OF THIS RESULT SET
...@@ -499,9 +503,9 @@ function auth_get_auth_instances_for_username($institution, $username) { ...@@ -499,9 +503,9 @@ function auth_get_auth_instances_for_username($institution, $username) {
* @param string $institution Name of the institution * @param string $institution Name of the institution
* @return array Array of auth instance records * @return array Array of auth instance records
*/ */
function auth_get_available_auth_types($institution) { function auth_get_available_auth_types($institution=null) {
global $CFG; global $CFG;
if (!is_string($institution) || strlen($institution) > 255) { if (!is_null($institution) && (!is_string($institution) || strlen($institution) > 255)) {
return array(); return array();
} }
...@@ -524,7 +528,11 @@ function auth_get_available_auth_types($institution) { ...@@ -524,7 +528,11 @@ function auth_get_available_auth_types($institution) {
ORDER BY ORDER BY
a.name'; a.name';
$result = get_records_sql_array($sql, array()); if (is_null($institution)) {
$result = get_records_array('auth_installed', '','','name','name, requires_config');
} else {
$result = get_records_sql_array($sql, array());
}
if (empty($result)) { if (empty($result)) {
return array(); return array();
......
...@@ -242,7 +242,7 @@ $string['defaultaccountlifetime'] = 'Default account lifetime'; ...@@ -242,7 +242,7 @@ $string['defaultaccountlifetime'] = 'Default account lifetime';
$string['defaultaccountlifetimedescription'] = 'How long newly created user accounts will be usable for before they expire'; $string['defaultaccountlifetimedescription'] = 'How long newly created user accounts will be usable for before they expire';
$string['deleteinstitution'] = 'Delete Institution'; $string['deleteinstitution'] = 'Delete Institution';
$string['deleteinstitutionconfirm'] = 'Are you really sure you wish to delete this institution?'; $string['deleteinstitutionconfirm'] = 'Are you really sure you wish to delete this institution?';
$string['institutionaddedsuccessfully'] = 'Institution added successfully'; $string['institutionaddedsuccessfully'] = 'Institution added successfully. Please configure an authentication plugin for this institution.';
$string['institutiondeletedsuccessfully'] = 'Institution deleted successfully'; $string['institutiondeletedsuccessfully'] = 'Institution deleted successfully';
$string['institutionname'] = 'Institution name'; $string['institutionname'] = 'Institution name';
$string['institutiondisplayname'] = 'Institution display name'; $string['institutiondisplayname'] = 'Institution display name';
......
...@@ -63,7 +63,11 @@ ...@@ -63,7 +63,11 @@
<KEYS> <KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" /> <KEY NAME="primary" TYPE="primary" FIELDS="id" />
<KEY NAME="authnamefk" TYPE="foreign" FIELDS="authname" REFTABLE="auth_installed" REFFIELDS="name" /> <KEY NAME="authnamefk" TYPE="foreign" FIELDS="authname" REFTABLE="auth_installed" REFFIELDS="name" />
<!-- The following foreign-key constraint can't be implemented, as we currently have to be able to create
the auth instance before we create the institution record. This workflow is probably bogus and should
be changed once we're able to do multi-page/tabbed forms.
<KEY NAME="institutionfk" TYPE="foreign" FIELDS="institution" REFTABLE="institution" REFFIELDS="name" /> <KEY NAME="institutionfk" TYPE="foreign" FIELDS="institution" REFTABLE="institution" REFFIELDS="name" />
-->
</KEYS> </KEYS>
</TABLE> </TABLE>
<TABLE NAME="institution_locked_profile_field"> <TABLE NAME="institution_locked_profile_field">
......
...@@ -107,6 +107,11 @@ ...@@ -107,6 +107,11 @@
function addinstance() { function addinstance() {
var selectedPlugin = document.getElementById('dummySelect').value; var selectedPlugin = document.getElementById('dummySelect').value;
var institution = '{{$institution}}';
if (institution.length == 0) {
alert('Please save the institution details before configuring authentication plugins.');
return false;
}
if (requiresConfig(selectedPlugin) == 1) { if (requiresConfig(selectedPlugin) == 1) {
window.open('addauthority.php?add=1&i={{$institution}}&p=' + selectedPlugin, 'addinstance', 'height=520,width=550,screenx=250,screenY=200,scrollbars=1'); window.open('addauthority.php?add=1&i={{$institution}}&p=' + selectedPlugin, 'addinstance', 'height=520,width=550,screenx=250,screenY=200,scrollbars=1');
...@@ -179,7 +184,7 @@ section name=mysec loop=$instancelist ...@@ -179,7 +184,7 @@ section name=mysec loop=$instancelist
/section /section
}}</div> }}</div>
<br> <br>
<select name="dummy" id="dummySelect"> <select name="dummy" id="dummySelect" {{if $institution eq ''}}disabled{{/if}}>
{{section name=mysec2 loop=$authtypes}} {{section name=mysec2 loop=$authtypes}}
<option>{{$authtypes[mysec2]->name}}</option> <option>{{$authtypes[mysec2]->name}}</option>
{{/section}} {{/section}}
......
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