Skip to content

Commit

Permalink
MDL-11561 admin tree improvements and bugfixing
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Dec 19, 2007
1 parent a5feb17 commit 220a90c
Show file tree
Hide file tree
Showing 110 changed files with 4,027 additions and 4,714 deletions.
239 changes: 8 additions & 231 deletions admin/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,67 +11,36 @@
require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->libdir.'/tablelib.php');

admin_externalpage_setup('userauthentication');
require_login();
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));

$returnurl = "$CFG->wwwroot/$CFG->admin/settings.php?section=manageauths";

$action = optional_param('action', '', PARAM_ACTION);
$auth = optional_param('auth', '', PARAM_SAFEDIR);

// get currently installed and enabled auth plugins
$authsavailable = get_list_of_plugins('auth');

//revert auth_plugins_enabled
if (isset($CFG->auth_plugins_enabled)) {
set_config('auth', $CFG->auth_plugins_enabled);
delete_records('config', 'name', 'auth_plugins_enabled');
unset($CFG->auth_plugins_enabled);
}

get_enabled_auth_plugins(true); // fix the list of enabled auths
if (empty($CFG->auth)) {
$authsenabled = array();
} else {
$authsenabled = explode(',', $CFG->auth);
}

if (!isset($CFG->registerauth)) {
set_config('registerauth', '');
}

if (!isset($CFG->auth_instructions)) {
set_config('auth_instructions', '');
}

if (!empty($auth) and !exists_auth_plugin($auth)) {
error(get_string('pluginnotinstalled', 'auth', $auth), $url);
}


////////////////////////////////////////////////////////////////////////////////
// process actions

$status = '';
if (!confirm_sesskey()) {
redirect($returnurl);
}

switch ($action) {

case 'save':
if (data_submitted() and confirm_sesskey()) {

// save settings
set_config('guestloginbutton', required_param('guestloginbutton', PARAM_BOOL));
set_config('alternateloginurl', stripslashes(trim(required_param('alternateloginurl', PARAM_RAW))));
set_config('forgottenpasswordurl', stripslashes(trim(required_param('forgottenpasswordurl', PARAM_RAW))));
set_config('registerauth', required_param('register', PARAM_SAFEDIR));
set_config('auth_instructions', stripslashes(trim(required_param('auth_instructions', PARAM_RAW))));

// enable registerauth in $CFG->auth if needed
if (!empty($CFG->registerauth) and !in_array($CFG->registerauth, $authsenabled)) {
$authsenabled[] = $CFG->registerauth;
set_config('auth', implode(',', $authsenabled));
}
$status = get_string('changessaved');
}
break;

case 'disable':
// remove from enabled list
$key = array_search($auth, $authsenabled);
Expand Down Expand Up @@ -128,198 +97,6 @@
break;
}

// display strings
$txt = get_strings(array('authenticationplugins', 'users', 'administration',
'settings', 'edit', 'name', 'enable', 'disable',
'up', 'down', 'none'));
$txt->updown = "$txt->up/$txt->down";

// construct the display array, with enabled auth plugins at the top, in order
$displayauths = array();
$registrationauths = array();
$registrationauths[''] = $txt->disable;
foreach ($authsenabled as $auth) {
$authplugin = get_auth_plugin($auth);
/// Get the auth title (from core or own auth lang files)
$authtitle = get_string("auth_{$auth}title", "auth");
if ($authtitle == "[[auth_{$auth}title]]") {
$authtitle = get_string("auth_{$auth}title", "auth_{$auth}");
}
/// Apply titles
$displayauths[$auth] = $authtitle;
if ($authplugin->can_signup()) {
$registrationauths[$auth] = $authtitle;
}
}

foreach ($authsavailable as $auth) {
if (array_key_exists($auth, $displayauths)) {
continue; //already in the list
}
$authplugin = get_auth_plugin($auth);
/// Get the auth title (from core or own auth lang files)
$authtitle = get_string("auth_{$auth}title", "auth");
if ($authtitle == "[[auth_{$auth}title]]") {
$authtitle = get_string("auth_{$auth}title", "auth_{$auth}");
}
/// Apply titles
$displayauths[$auth] = $authtitle;
if ($authplugin->can_signup()) {
$registrationauths[$auth] = $authtitle;
}
}

// build the display table
$table = new flexible_table('auth_admin_table');
$table->define_columns(array('name', 'enable', 'order', 'settings'));
$table->define_headers(array($txt->name, $txt->enable, $txt->updown, $txt->settings));
$table->define_baseurl("{$CFG->wwwroot}/{$CFG->admin}/auth.php");
$table->set_attribute('id', 'blocks');
$table->set_attribute('class', 'generaltable generalbox boxaligncenter boxwidthwide');
$table->setup();

//add always enabled plugins first
$displayname = "<span>".$displayauths['manual']."</span>";
$settings = "<a href=\"auth_config.php?sesskey={$USER->sesskey}&amp;auth=manual\">{$txt->settings}</a>";
$table->add_data(array($displayname, '', '', $settings));
$displayname = "<span>".$displayauths['nologin']."</span>";
$settings = "<a href=\"auth_config.php?sesskey={$USER->sesskey}&amp;auth=nologin\">{$txt->settings}</a>";
$table->add_data(array($displayname, '', '', $settings));


// iterate through auth plugins and add to the display table
$updowncount = 1;
$authcount = count($authsenabled);
$url = "auth.php?sesskey=" . sesskey();
foreach ($displayauths as $auth => $name) {
if ($auth == 'manual' or $auth == 'nologin') {
continue;
}
// hide/show link
if (in_array($auth, $authsenabled)) {
$hideshow = "<a href=\"$url&amp;action=disable&amp;auth=$auth\">";
$hideshow .= "<img src=\"{$CFG->pixpath}/i/hide.gif\" class=\"icon\" alt=\"disable\" /></a>";
// $hideshow = "<a href=\"$url&amp;action=disable&amp;auth=$auth\"><input type=\"checkbox\" checked /></a>";
$enabled = true;
$displayname = "<span>$name</span>";
}
else {
$hideshow = "<a href=\"$url&amp;action=enable&amp;auth=$auth\">";
$hideshow .= "<img src=\"{$CFG->pixpath}/i/show.gif\" class=\"icon\" alt=\"enable\" /></a>";
// $hideshow = "<a href=\"$url&amp;action=enable&amp;auth=$auth\"><input type=\"checkbox\" /></a>";
$enabled = false;
$displayname = "<span class=\"dimmed_text\">$name</span>";
}

// up/down link (only if auth is enabled)
$updown = '';
if ($enabled) {
if ($updowncount > 1) {
$updown .= "<a href=\"$url&amp;action=up&amp;auth=$auth\">";
$updown .= "<img src=\"{$CFG->pixpath}/t/up.gif\" alt=\"up\" /></a>&nbsp;";
}
else {
$updown .= "<img src=\"{$CFG->pixpath}/spacer.gif\" class=\"icon\" alt=\"\" />&nbsp;";
}
if ($updowncount < $authcount) {
$updown .= "<a href=\"$url&amp;action=down&amp;auth=$auth\">";
$updown .= "<img src=\"{$CFG->pixpath}/t/down.gif\" alt=\"down\" /></a>";
}
else {
$updown .= "<img src=\"{$CFG->pixpath}/spacer.gif\" class=\"icon\" alt=\"\" />";
}
++ $updowncount;
}

// settings link
$settings = "<a href=\"auth_config.php?sesskey={$USER->sesskey}&amp;auth=$auth\">{$txt->settings}</a>";

// add a row to the table
$table->add_data(array($displayname, $hideshow, $updown, $settings));
}

// output form
admin_externalpage_print_header();

//print stus messages
if ($status !== '') {
notify($status, 'notifysuccess');
}

print_simple_box(get_string('configauthenticationplugins', 'admin'), 'center', '700');

$table->print_html();

////////////////////////////////////////////////////////////////////////////////

$guestoptions = array();
$guestoptions[0] = get_string("hide");
$guestoptions[1] = get_string("show");

echo '<hr />';

echo '<form '.$CFG->frametarget.' id="adminsettings" method="post" action="auth.php">';
echo '<div class="settingsform clearfix">';
print_heading(get_string('auth_common_settings', 'auth'));
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
echo '<input type="hidden" name="action" value="save" />';
echo '<fieldset>';
##echo '<table cellspacing="0" cellpadding="5" border="0" style="margin-left:auto;margin-right:auto">';

// User self registration
echo '<div class="form-item" id="admin-register">';
echo '<label for = "menuregister">' . get_string("selfregistration", "auth");
echo '<span class="form-shortname">registerauth</span>';
echo '</label>';
choose_from_menu($registrationauths, "register", $CFG->registerauth, "");
echo '<div class="description">' . get_string("selfregistration_help", "auth") . '</div>';
echo '</div>';

// Login as guest button enabled
echo '<div class="form-item" id="admin-guestloginbutton">';
echo '<label for = "menuguestloginbutton">' . get_string("guestloginbutton", "auth");
echo '<span class="form-shortname">guestloginbutton</span>';
echo '</label>';
choose_from_menu($guestoptions, "guestloginbutton", $CFG->guestloginbutton, "");
echo '<div class="description">' . get_string("showguestlogin", "auth") . '</div>';
echo '</div>';

/// An alternate url for the login form. It means we can use login forms that are integrated
/// into non-moodle pages
echo '<div class="form-item" id="admin-alternateloginurl">';
echo '<label for = "alternateloginurl">' . get_string("alternateloginurl", "auth");
echo '<span class="form-shortname">alternateloginurl</span>';
echo '</label>';
echo '<input type="text" size="60" name="alternateloginurl" id="alternateloginurl" value="'.s($CFG->alternateloginurl)."\" />\n";
echo '<div class="description">' . get_string("alternatelogin", "auth", htmlspecialchars($CFG->wwwroot.'/login/index.php')) . '</div>';
echo '</div>';

/// An alternate url for lost passwords. It means we can use external lost password
/// recovery for all users. Effectively disables built-in processes!!!
echo '<div class="form-item" id="admin-forgottenpasswordurl">';
echo '<label for = "forgottenpasswordurl">' . get_string("forgottenpasswordurl", "auth");
echo '<span class="form-shortname">forgottenpasswordurl</span>';
echo '</label>';
echo '<input type="text" size="60" name="forgottenpasswordurl" id="forgottenpasswordurl" value="'.s($CFG->forgottenpasswordurl)."\" />\n";
echo '<div class="description">' . get_string("forgottenpassword", "auth" ) . '</div>';
echo '</div>';

/// Instructions about login/password
/// to be showed to users
echo '<div class="form-item" id="admin-auth_instructions">';
echo '<label for = "auth_instructions">' . get_string("instructions", "auth");
echo '<span class="form-shortname">auth_instructions</span>';
echo '</label>';
echo '<textarea cols="30" rows="4" name="auth_instructions" id="auth_instructions">'.s($CFG->auth_instructions)."</textarea>\n";
echo '<div class="description">' . get_string("authinstructions", "auth") . '</div>';
echo '</div>';

echo '</fieldset>';

////////////////////////////////////////////////////////////////////////////////
echo '<div class="form-buttons"><input class="form-submit" type="submit" value="'.get_string('savechanges', 'admin').'" /></div>';
echo '</div>';
echo '</form>';
admin_externalpage_print_footer();
redirect ($returnurl);

?>
15 changes: 7 additions & 8 deletions admin/auth_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@
require_once '../config.php';
require_once $CFG->libdir.'/adminlib.php';

admin_externalpage_setup('userauthentication');
$auth = required_param('auth', PARAM_SAFEDIR);

admin_externalpage_setup('authsetting'.$auth);

$authplugin = get_auth_plugin($auth);
$err = array();

// save configuration changes
if ($frm = data_submitted()) {

if (!confirm_sesskey()) {
error(get_string('confirmsesskeybad', 'error'));
}
$returnurl = "$CFG->wwwroot/$CFG->admin/settings.php?section=manageauths";

// save configuration changes
if ($frm = data_submitted() and confirm_sesskey()) {
$frm = stripslashes_recursive($frm);

$authplugin->validate_form($frm, $err);
Expand All @@ -37,7 +36,7 @@
}
}
}
redirect("auth.php");
redirect($returnurl);
exit;
}
} else {
Expand Down
13 changes: 4 additions & 9 deletions admin/block.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->libdir.'/blocklib.php');

admin_externalpage_setup('manageblocks');

$blockid = required_param('block', PARAM_INT);

if(($blockrecord = blocks_get_record($blockid)) === false) {
if(!$blockrecord = blocks_get_record($blockid)) {
error('This block does not exist');
}

admin_externalpage_setup('blocksetting'.$blockrecord->name);

$block = block_instance($blockrecord->name);
if($block === false) {
error('Problem in instantiating block object');
Expand Down Expand Up @@ -50,11 +50,6 @@
$strmanageblocks = get_string('manageblocks');
$strblockname = $block->get_title();

// $CFG->pagepath is used to generate the body and id attributes for the body tag
// of the page. It is also used to generate the link to the Moodle Docs for this view.
$CFG->pagepath = 'block/' . $block->name() . '/config';


admin_externalpage_print_header();

print_heading($strblockname);
Expand All @@ -70,6 +65,6 @@
echo '</p>';
$block->config_print();
echo '</form>';
admin_externalpage_print_footer();
print_footer();

?>
Loading

0 comments on commit 220a90c

Please sign in to comment.