Commit 3f6fb17d authored by Nigel McNie's avatar Nigel McNie Committed by Nigel McNie
Browse files

- Implemented "deleting" of institutions

  - i18n for institutions
parent 2d967e15
...@@ -33,12 +33,52 @@ $smarty = smarty(); ...@@ -33,12 +33,52 @@ $smarty = smarty();
$institution = param_variable('i', ''); $institution = param_variable('i', '');
$add = param_boolean('add'); $add = param_boolean('add');
$edit = param_boolean('edit');
$delete = param_boolean('delete');
if ($institution || $add) { if ($institution || $add) {
if ($delete) {
function delete_cancel_submit() {
redirect(get_config('wwwroot') . 'admin/institutions.php');
}
function delete_submit($values) {
global $SESSION;
db_begin();
delete_records('institution_locked_profile_field', 'name', $values['i']);
delete_records('institution', 'name', $values['i']);
db_commit();
$SESSION->add_ok_msg(get_string('institutiondeletedsuccessfully', 'admin'));
redirect(get_config('wwwroot') . 'admin/institutions.php');
}
$form = array(
'name' => 'delete',
'elements' => array(
'i' => array(
'type' => 'hidden',
'value' => $institution
),
'delete' => array(
'type' => 'hidden',
'value' => 1
),
'submit' => array(
'type' => 'submitcancel',
'value' => array(get_string('yes'), get_string('no'))
)
)
);
$smarty->assign('delete_form', pieform($form));
$smarty->display('admin/institutions.tpl');
exit;
}
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);
} }
else { else {
$data = new StdClass; $data = new StdClass;
...@@ -52,76 +92,74 @@ if ($institution || $add) { ...@@ -52,76 +92,74 @@ if ($institution || $add) {
} }
safe_require('artefact', 'internal'); safe_require('artefact', 'internal');
$elements = array(); $elements = array(
'name' => array(
if ($add) {
$elements['name'] = array(
'type' => 'text', 'type' => 'text',
'title' => get_string('institutionname'), 'title' => get_string('institutionname', 'admin'),
'rules' => array( 'rules' => array(
'required' => true, 'required' => true,
'maxlength' => 255, 'maxlength' => 255,
'regex' => '/^[a-z]+$/' 'regex' => '/^[a-z]+$/'
),
'ignore' => !$add
),
'add' => array(
'type' => 'hidden',
'value' => true,
'ignore' => !$add
),
'i' => array(
'type' => 'hidden',
'value' => $institution,
'ignore' => $add
),
'displayname' => array(
'type' => 'text',
'title' => get_string('institutiondisplayname', 'admin'),
'defaultvalue' => $data->displayname,
'rules' => array(
'required' => true,
'maxlength' => 255
) )
); ),
$elements['add'] = array( 'authplugin' => array(
'type' => 'hidden', 'type' => 'select',
'value' => true 'title' => get_string('authplugin', 'admin'),
); 'options' => get_records_menu('auth_installed', '', '', 'name', 'name, name')
} ),
else { 'registerallowed' => array(
$elements['i'] = array( 'type' => 'checkbox',
'type' => 'hidden', 'title' => get_string('registrationallowed', 'admin'),
'value' => $institution 'description' => get_string('registrationalloweddescription', 'admin'),
); 'checked' => $data->registerallowed
} ),
'defaultaccountlifetime' => array(
$elements['displayname'] = array( 'type' => 'expiry',
'type' => 'text', 'title' => get_string('defaultaccountlifetime', 'admin'),
'title' => get_string('institutiondisplayname'), 'description' => get_string('defaultaccountlifetimedescription', 'admin'),
'defaultvalue' => $data->displayname, 'defaultvalue' => $data->defaultaccountlifetime
'rules' => array( ),
'required' => true, 'defaultaccountinactiveexpire' => array(
'maxlength' => 255 'type' => 'expiry',
'title' => get_string('defaultaccountinactiveexpire', 'admin'),
'description' => get_string('defaultaccountinactiveexpiredescription', 'admin'),
'defaultvalue' => $data->defaultaccountinactiveexpire
),
'defaultaccountinactivewarn' => array(
'type' => 'expiry',
'title' => get_string('defaultaccountinactivewarn', 'admin'),
'description' => get_string('defaultaccountinactivewarndescription', 'admin'),
'defaultvalue' => $data->defaultaccountinactivewarn
),
'lockedfields' => array(
'value' => '<tr><th colspan="2">Locked fields</th></tr>'
) )
);
$elements['authplugin'] = array(
'type' => 'select',
'title' => get_string('authplugin'),
'options' => get_records_menu('auth_installed', '', '', 'name', 'name, name')
);
$elements['registerallowed'] = array(
'type' => 'checkbox',
'title' => get_string('registrationallowed'),
'description' => get_string('registrationalloweddescription'),
'checked' => $data->registerallowed
);
$elements['defaultaccountlifetime'] = array(
'type' => 'expiry',
'title' => get_string('defaultaccountlifetime'),
'description' => get_string('defaultaccountlifetimedescription'),
'defaultvalue' => $data->defaultaccountlifetime
);
$elements['defaultaccountinactiveexpire'] = array(
'type' => 'expiry',
'title' => get_string('defaultaccountinactiveexpire'),
'description' => get_string('defaultaccountinactiveexpiredescription'),
'defaultvalue' => $data->defaultaccountinactiveexpire
);
$elements['defaultaccountinactivewarn'] = array(
'type' => 'expiry',
'title' => get_string('defaultaccountinactivewarn'),
'description' => get_string('defaultaccountinactivewarndescription'),
'defaultvalue' => $data->defaultaccountinactivewarn
);
$elements['lockedfields'] = array(
'value' => '<tr><th colspan="2">Locked fields</th></tr>'
); );
foreach (ArtefactTypeProfile::get_all_fields() as $field => $type) { foreach (ArtefactTypeProfile::get_all_fields() as $field => $type) {
$elements[$field] = array( $elements[$field] = array(
'type' => 'checkbox', 'type' => 'checkbox',
'title' => get_string($field), 'title' => get_string($field, 'artefact.internal'),
'checked' => in_array($field, $lockedprofilefields) 'checked' => in_array($field, $lockedprofilefields)
); );
} }
...@@ -138,7 +176,7 @@ if ($institution || $add) { ...@@ -138,7 +176,7 @@ if ($institution || $add) {
} }
else { else {
// Get a list of institutions // Get a list of institutions
$institutions = get_records_sql_array('SELECT i.name, i.displayname, i.authplugin, i.registerallowed, COUNT(u.*) $institutions = get_records_sql_array('SELECT i.name, i.displayname, i.authplugin, i.registerallowed, COUNT(u.*) AS hasmembers
FROM institution i FROM institution i
LEFT OUTER JOIN usr u ON (u.institution = i.name) LEFT OUTER JOIN usr u ON (u.institution = i.name)
GROUP BY 1, 2, 3, 4 GROUP BY 1, 2, 3, 4
...@@ -185,7 +223,8 @@ function institution_submit($values) { ...@@ -185,7 +223,8 @@ function institution_submit($values) {
} }
db_commit(); db_commit();
$SESSION->add_ok_msg(get_string('institutionupdatedsuccessfully')); $message = ($add) ? 'institutionaddedsuccessfully' : 'institutionupdatedsuccessfully';
$SESSION->add_ok_msg(get_string($message, 'admin'));
redirect(get_config('wwwroot') . 'admin/institutions.php'); redirect(get_config('wwwroot') . 'admin/institutions.php');
} }
......
...@@ -147,7 +147,21 @@ $string['adminnotifications'] = 'Admin Notifications'; ...@@ -147,7 +147,21 @@ $string['adminnotifications'] = 'Admin Notifications';
// Suspended Users // Suspended Users
$string['suspendedusers'] = 'Suspended Users'; $string['suspendedusers'] = 'Suspended Users';
// Authentication // Institutions
$string['authconfigoptionssaved'] = 'Auth configuration has been saved'; $string['addinstitution'] = 'Add Institution';
$string['authplugin'] = 'Authentication plugin';
$string['defaultaccountinactiveexpire'] = 'Default account expiry time';
$string['defaultaccountinactiveexpiredescription'] = 'How long a user account will remain active without the user logging in';
$string['defaultaccountinactivewarn'] = 'Default account expire warning time';
$string['defaultaccountinactivewarndescription'] = 'The time before user accounts are to expire at which a warning message will be sent to them';
$string['defaultaccountlifetime'] = 'Default account lifetime';
$string['defaultaccountlifetimedescription'] = 'How long accounts will last for by default';
$string['institutionaddedsuccessfully'] = 'Institution added successfully';
$string['institutiondeletedsuccessfully'] = 'Institution deleted successfully';
$string['institutionname'] = 'Institution name';
$string['institutiondisplayname'] = 'Institution display name';
$string['institutionupdatedsuccessfully'] = 'Institution updated successfully';
$string['registrationallowed'] = 'Registration allowed?';
$string['registrationalloweddescription'] = 'Whether users can register for the system with this institution';
?> ?>
...@@ -2,19 +2,24 @@ ...@@ -2,19 +2,24 @@
<h2>AdminInstitutions</h2> <h2>AdminInstitutions</h2>
{if $delete_form}
<h3>{str tag="deleteinstitution" section="admin"}</h3>
<p>{str tag="deleteinstitutionconfirm" section="admin"}</p>
{$delete_form}
{else}
{if $institution_form} {if $institution_form}
{if $add} {if $add}
<h3>Add Institution</h3> <h3>{str tag="addinstitution" section="admin"}</h3>
{/if} {/if}
{$institution_form} {$institution_form}
{else} {else}
<p>Here is a list of all installed institutions.</p>
<table> <table>
<tr> <tr>
<th>Institution</th> <th>{str tag="institution"}</th>
<th>Authentication Method</th> <th>{str tag="authplugin" section="admin"}</th>
<th>Registration Allowed?</th> <th>{str tag="registrationallowed" section="admin"}</th>
<th></th> <th></th>
</tr> </tr>
{foreach from=$institutions item=institution} {foreach from=$institutions item=institution}
...@@ -25,8 +30,8 @@ ...@@ -25,8 +30,8 @@
<td> <td>
<form action="" method="post"> <form action="" method="post">
<input type="hidden" name="i" value="{$institution->name}"> <input type="hidden" name="i" value="{$institution->name}">
<input type="submit" name="edit" value="Edit"> <input type="submit" name="edit" value="{str tag="edit"}">
{if $institution->candelete}<input type="submit" name="delete" value="Delete">{/if} {if !$institution->hasmembers && $institution->name != 'mahara'}<input type="submit" name="delete" value="{str tag="delete"}">{/if}
</form> </form>
</td> </td>
</tr> </tr>
...@@ -34,11 +39,12 @@ ...@@ -34,11 +39,12 @@
<tr> <tr>
<td colspan="4"> <td colspan="4">
<form action="" method="post"> <form action="" method="post">
<input type="submit" name="add" value="Add Institution"> <input type="submit" name="add" value="{str tag="addinstitution" section="admin"}">
</form> </form>
</td> </td>
</tr> </tr>
</table> </table>
{/if} {/if}
{/if}
{include file="footer.tpl"} {include file="footer.tpl"}
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