fixed tabs, fixed potential notices for undefined variables, added structure that will be used for detecting what variables to flag during installs & upgrades, removed all $_GET usage, switched 'admin' to $CFG->admin (for directory paths), and fixed blank line at end of index.php

This commit is contained in:
vinkmar 2006-08-21 04:06:58 +00:00
parent d37bac7e5d
commit 6fcbab99ef
4 changed files with 807 additions and 793 deletions

View file

@ -203,8 +203,7 @@ class admin_settingpage extends part_of_admin_tree {
function add(&$setting) {
if (is_a($setting, 'admin_setting')) {
$temp = $setting->name;
$this->settings->$temp =& $setting;
$this->settings->{$setting->name} =& $setting;
return true;
}
return false;
@ -255,7 +254,7 @@ class admin_setting {
}
function get_setting() {
return; // has to be overridden
return NULL; // has to be overridden
}
function write_setting($data) {
@ -280,8 +279,7 @@ class admin_setting_configtext extends admin_setting {
function get_setting() {
global $CFG;
$temp = $this->name; // there's gotta be a more elegant way
return $CFG->$temp; // of doing this
return (isset($CFG->{$this->name}) ? $CFG->{$this->name} : NULL);
}
function write_setting($data) {
@ -305,8 +303,7 @@ class admin_setting_configcheckbox extends admin_setting {
function get_setting() {
global $CFG;
$temp = $this->name; // there's gotta be a more elegant way
return $CFG->$temp; // of doing this
return (isset($CFG->{$this->name}) ? $CFG->{$this->name} : NULL);
}
function write_setting($data) {
@ -336,8 +333,7 @@ class admin_setting_configselect extends admin_setting {
function get_setting() {
global $CFG;
$temp = $this->name;
return $CFG->$temp;
return (isset($CFG->{$this->name}) ? $CFG->{$this->name} : NULL);
}
function write_setting($data) {
@ -383,9 +379,7 @@ class admin_setting_configtime extends admin_setting {
function get_setting() {
global $CFG;
$temp = $this->name;
$temp2 = $this->name2;
return array((empty($CFG->$temp) ? 0 : $CFG->$temp), (empty($CFG->$temp2) ? 0 : $CFG->$temp2));
return (isset($CFG->{$this->name}) && isset($CFG->{$this->name2}) ? array($CFG->{$this->name}, $CFG->{$this->name2}) : NULL);
}
function write_setting($data) {
@ -399,6 +393,9 @@ class admin_setting_configtime extends admin_setting {
function output_html() {
$setvalue = $this->get_setting();
if (!is_array($setvalue)) {
$setvalue = array(0,0);
}
$return = '<tr><td width="100" align="right" valign="top">' . $this->visiblename . '</td><td align="left"><select name="s_' . $this->name .'[h]">';
foreach ($this->choices as $key => $value) {
$return .= '<option value="' . $key . '"' . ($key == $setvalue[0] ? ' selected="selected"' : '') . '>' . $value . '</option>';
@ -421,8 +418,7 @@ class admin_setting_configmultiselect extends admin_setting_configselect {
function get_setting() {
global $CFG;
$temp = $this->name;
return explode(',', $CFG->$temp);
return (isset($CFG->{$this->name}) ? explode(',', $CFG->{$this->name}) : NULL);;
}
function write_setting($data) {
@ -436,9 +432,13 @@ class admin_setting_configmultiselect extends admin_setting_configselect {
}
function output_html() {
$currentsetting = $this->get_setting();
if (!is_array($currentsetting)) {
$currentsetting = array();
}
$return = '<tr><td width="100" align="right" valign="top">' . $this->visiblename . '</td><td align="left"><select name="s_' . $this->name .'[]" size="10" multiple="multiple">';
foreach ($this->choices as $key => $value) {
$return .= '<option value="' . $key . '"' . (in_array($key,$this->get_setting()) ? ' selected="selected"' : '') . '>' . $value . '</option>';
$return .= '<option value="' . $key . '"' . (in_array($key,$currentsetting) ? ' selected="selected"' : '') . '>' . $value . '</option>';
}
$return .= '</select></td></tr><tr><td>&nbsp;</td><td align="left">' . $this->description . '</td></tr>';
return $return;
@ -476,8 +476,7 @@ class admin_setting_sitesetselect extends admin_setting_configselect {
function get_setting() {
$site = get_site();
$temp = $this->name;
return $site->$temp;
return (isset($site->{$this->name}) ? $site->{$this->name} : NULL);
}
function write_setting($data) {
@ -516,8 +515,7 @@ class admin_setting_special_frontpage extends admin_setting_configselect {
function get_setting() {
global $CFG;
$temp = $this->name;
return (explode(',', $CFG->$temp));
return (isset($CFG->{$this->name}) ? explode(',', $CFG->{$this->name}) : NULL);
}
function write_setting($data) {
@ -535,6 +533,14 @@ class admin_setting_special_frontpage extends admin_setting_configselect {
function output_html() {
$currentsetting = $this->get_setting();
if (!is_array($currentsetting)) {
$currentsetting = array();
}
for ($i = 0; $i < count($this->choices) - 1; $i++) {
if (!isset($currentsetting[$i])) {
$currentsetting[$i] = 0;
}
}
$return = '<tr><td width="100" align="right" valign="top">' . $this->visiblename . '</td><td align="left">';
for ($i = 0; $i < count($this->choices) - 1; $i++) {
$return .='<select name="s_' . $this->name .'[]">';
@ -567,8 +573,7 @@ class admin_setting_sitesetcheckbox extends admin_setting_configcheckbox {
function get_setting() {
$site = get_site();
$temp = $this->name;
return ($site->$temp == '1' ? 1 : 0);
return (isset($site->{$this->name}) ? $site->{$this->name} : NULL);
}
function write_setting($data) {
@ -596,8 +601,7 @@ class admin_setting_sitesettext extends admin_setting_configtext {
function get_setting() {
$site = get_site();
$temp = $this->name;
return $site->$temp;
return (isset($site->{$this->name}) ? $site->{$this->name} : NULL);
}
function write_setting($data) {
@ -647,8 +651,7 @@ class admin_setting_special_frontpagedesc extends admin_setting {
function get_setting() {
$site = get_site();
$temp = $this->name;
return ($site->$temp);
return (isset($site->{$this->name}) ? $site->{$this->name} : NULL);
}
@ -678,12 +681,16 @@ class admin_setting_special_editorfontlist extends admin_setting {
$name = 'editorfontlist';
$visiblename = get_string('editorfontlist', 'admin');
$description = get_string('configeditorfontlist', 'admin');
if (isset($CFG->editorfontlist)) {
$items = explode(';', $CFG->editorfontlist);
$this->items = array();
foreach ($items as $item) {
$item = explode(':', $item);
$this->items[$item[0]] = $item[1];
}
} else {
$items = NULL;
}
parent::admin_setting($name, $visiblename, $description);
}
@ -721,7 +728,11 @@ class admin_setting_special_editorfontlist extends admin_setting {
function output_html() {
$return = '<tr><td width="100" align="right" valign="top">' . $this->visiblename . '</td><td align="left">';
$count = 0;
foreach ($this->items as $key => $value) {
$currentsetting = $this->items;
if (!is_array($currentsetting)) {
$currentsetting = NULL;
}
foreach ($currentsetting as $key => $value) {
$return .= '<input type="text" name="s_editorfontlist[k' . $count . ']" value="' . $key . '" size="20" />';
$return .= '&nbsp;&nbsp;';
$return .= '<input type="text" name="s_editorfontlist[v' . $count . ']" value="' . $value . '" size="40" /><br />';
@ -867,8 +878,7 @@ class admin_setting_special_editorhidebuttons extends admin_setting {
function get_setting() {
global $CFG;
$temp = $this->name;
return explode(' ', $CFG->$temp);
return (isset($CFG->{$this->name}) ? explode(' ', $CFG->{$this->name}) : NULL);
}
function write_setting($data) {
@ -893,6 +903,9 @@ class admin_setting_special_editorhidebuttons extends admin_setting {
// we do 15 fields per column
$currentsetting = $this->get_setting();
if (!is_array($currentsetting)) {
$currentsetting = array();
}
$return = '<tr><td width="100" align="right" valign="top">' . $this->visiblename . '</td><td align="left">';
@ -929,9 +942,8 @@ class admin_setting_backupselect extends admin_setting_configselect {
}
function get_setting() {
$backup_config = backup_get_config(); // we need this function from backup/lib.php ... but it causes conflicts. ideas?
$temp = $this->name;
return (isset($backup_config->$temp) ? $backup_config->$temp : 0); // we default to false/0 if the pair doesn't exist
$backup_config = backup_get_config();
return (isset($backup_config->{$this->name}) ? $backup_config->{$this->name} : NULL);
}
function write_setting($data) {
@ -956,8 +968,7 @@ class admin_setting_special_backupsaveto extends admin_setting_configtext {
function get_setting() {
$backup_config = backup_get_config();
$temp = $this->name;
return (isset($backup_config->$temp) ? $backup_config->$temp : ''); // we default to false/0 if the pair doesn't exist
return (isset($backup_config->{$this->name}) ? $backup_config->{$this->name} : NULL);
}
function write_setting($data) {
@ -988,8 +999,7 @@ class admin_setting_backupcheckbox extends admin_setting_configcheckbox {
function get_setting() {
$backup_config = backup_get_config();
$temp = $this->name;
return (isset($backup_config->$temp) ? $backup_config->$temp : 0); // we default to false if the pair doesn't exist
return (isset($backup_config->{$this->name}) ? $backup_config->{$this->name} : NULL);
}
}
@ -1006,9 +1016,7 @@ class admin_setting_special_backuptime extends admin_setting_configtime {
function get_setting() {
$backup_config = backup_get_config();
$temp = $this->name;
$temp2 = $this->name2;
return array(isset($backup_config->$temp) ? $backup_config->$temp : 0, isset($backup_config->$temp2) ? $backup_config->$temp2 : 0); // we default to 0:0 if the pair doesn't exist
return (isset($backup_config->{$this->name}) && isset($backup_config->{$this->name}) ? array($backup_config->{$this->name}, $backup_config->{$this->name2}) : NULL);
}
function write_setting($data) {
@ -1033,24 +1041,28 @@ class admin_setting_special_backupdays extends admin_setting {
function get_setting() {
$backup_config = backup_get_config();
$temp = $this->name;
return (isset($backup_config->$temp) ? $backup_config->$temp : '0000000');
return (isset($backup_config->{$this->name}) ? $backup_config->{$this->name} : NULL);
}
function output_html() {
$currentsetting = $this->get_setting();
if ($currentsetting === NULL) {
$currentsetting = '0000000';
}
return '<tr><td width="100" align="right" valign="top">' . $this->visiblename . '</td><td align="left">' .
'<table><tr><td><div align="center">&nbsp;&nbsp;' . get_string('sunday', 'calendar') . '&nbsp;&nbsp;</div></td><td><div align="center">&nbsp;&nbsp;' .
get_string('monday', 'calendar') . '&nbsp;&nbsp;</div></td><td><div align="center">&nbsp;&nbsp;' . get_string('tuesday', 'calendar') . '&nbsp;&nbsp;</div></td><td><div align="center">&nbsp;&nbsp;' .
get_string('wednesday', 'calendar') . '&nbsp;&nbsp;</div></td><td><div align="center">&nbsp;&nbsp;' . get_string('thursday', 'calendar') . '&nbsp;&nbsp;</div></td><td><div align="center">&nbsp;&nbsp;' .
get_string('friday', 'calendar') . '&nbsp;&nbsp;</div></td><td><div align="center">&nbsp;&nbsp;' . get_string('saturday', 'calendar') . '&nbsp;&nbsp;</div></td></tr><tr>' .
'<td><div align="center"><input type="checkbox" name="s_'. $this->name .'[u]" value="1" ' . (substr($this->get_setting(),0,1) == '1' ? 'checked="checked"' : '') . ' /></div></td>' .
'<td><div align="center"><input type="checkbox" name="s_'. $this->name .'[m]" value="1" ' . (substr($this->get_setting(),1,1) == '1' ? 'checked="checked"' : '') . ' /></div></td>' .
'<td><div align="center"><input type="checkbox" name="s_'. $this->name .'[t]" value="1" ' . (substr($this->get_setting(),2,1) == '1' ? 'checked="checked"' : '') . ' /></div></td>' .
'<td><div align="center"><input type="checkbox" name="s_'. $this->name .'[w]" value="1" ' . (substr($this->get_setting(),3,1) == '1' ? 'checked="checked"' : '') . ' /></div></td>' .
'<td><div align="center"><input type="checkbox" name="s_'. $this->name .'[r]" value="1" ' . (substr($this->get_setting(),4,1) == '1' ? 'checked="checked"' : '') . ' /></div></td>' .
'<td><div align="center"><input type="checkbox" name="s_'. $this->name .'[f]" value="1" ' . (substr($this->get_setting(),5,1) == '1' ? 'checked="checked"' : '') . ' /></div></td>' .
'<td><div align="center"><input type="checkbox" name="s_'. $this->name .'[s]" value="1" ' . (substr($this->get_setting(),6,1) == '1' ? 'checked="checked"' : '') . ' /></div></td>' .
'<td><div align="center"><input type="checkbox" name="s_'. $this->name .'[u]" value="1" ' . (substr($currentsetting,0,1) == '1' ? 'checked="checked"' : '') . ' /></div></td>' .
'<td><div align="center"><input type="checkbox" name="s_'. $this->name .'[m]" value="1" ' . (substr($currentsetting,1,1) == '1' ? 'checked="checked"' : '') . ' /></div></td>' .
'<td><div align="center"><input type="checkbox" name="s_'. $this->name .'[t]" value="1" ' . (substr($currentsetting,2,1) == '1' ? 'checked="checked"' : '') . ' /></div></td>' .
'<td><div align="center"><input type="checkbox" name="s_'. $this->name .'[w]" value="1" ' . (substr($currentsetting,3,1) == '1' ? 'checked="checked"' : '') . ' /></div></td>' .
'<td><div align="center"><input type="checkbox" name="s_'. $this->name .'[r]" value="1" ' . (substr($currentsetting,4,1) == '1' ? 'checked="checked"' : '') . ' /></div></td>' .
'<td><div align="center"><input type="checkbox" name="s_'. $this->name .'[f]" value="1" ' . (substr($currentsetting,5,1) == '1' ? 'checked="checked"' : '') . ' /></div></td>' .
'<td><div align="center"><input type="checkbox" name="s_'. $this->name .'[s]" value="1" ' . (substr($currentsetting,6,1) == '1' ? 'checked="checked"' : '') . ' /></div></td>' .
'</tr></table>' .
'</td></tr><tr><td>&nbsp;</td><td align="left">' . $this->description . '</td></tr>';
@ -1108,9 +1120,12 @@ class admin_setting_special_calendar_weekend extends admin_setting {
function get_setting() {
global $CFG;
$temp = $this->name;
$setting = intval($CFG->$temp);
if (isset($CFG->{$this->name})) {
$setting = intval($CFG->{$this->name});
return array('u' => $setting & 1, 'm' => $setting & 2, 't' => $setting & 4, 'w' => $setting & 8, 'r' => $setting & 16, 'f' => $setting & 32, 's' => $setting & 64);
} else {
return NULL;
}
}
function write_setting($data) {
@ -1126,20 +1141,22 @@ class admin_setting_special_calendar_weekend extends admin_setting {
function output_html() {
$result = $this->get_setting();
$currentsetting = $this->get_setting();
if (!is_array($currentsetting)) {
$currentsetting = array('u' => 0, 'm' => 0, 't' => 0, 'w' => 0, 'r' => 0, 'f' => 0, 's' => 0);
}
return '<tr><td width="100" align="right" valign="top">' . $this->visiblename . '</td><td align="left">' .
'<table><tr><td><div align="center">&nbsp;&nbsp;' . get_string('sunday', 'calendar') . '&nbsp;&nbsp;</div></td><td><div align="center">&nbsp;&nbsp;' .
get_string('monday', 'calendar') . '&nbsp;&nbsp;</div></td><td><div align="center">&nbsp;&nbsp;' . get_string('tuesday', 'calendar') . '&nbsp;&nbsp;</div></td><td><div align="center">&nbsp;&nbsp;' .
get_string('wednesday', 'calendar') . '&nbsp;&nbsp;</div></td><td><div align="center">&nbsp;&nbsp;' . get_string('thursday', 'calendar') . '&nbsp;&nbsp;</div></td><td><div align="center">&nbsp;&nbsp;' .
get_string('friday', 'calendar') . '&nbsp;&nbsp;</div></td><td><div align="center">&nbsp;&nbsp;' . get_string('saturday', 'calendar') . '&nbsp;&nbsp;</div></td></tr><tr>' .
'<td><div align="center"><input type="checkbox" name="s_'. $this->name .'[u]" value="1" ' . ($result['u'] ? 'checked="checked"' : '') . ' /></div></td>' .
'<td><div align="center"><input type="checkbox" name="s_'. $this->name .'[m]" value="1" ' . ($result['m'] ? 'checked="checked"' : '') . ' /></div></td>' .
'<td><div align="center"><input type="checkbox" name="s_'. $this->name .'[t]" value="1" ' . ($result['t'] ? 'checked="checked"' : '') . ' /></div></td>' .
'<td><div align="center"><input type="checkbox" name="s_'. $this->name .'[w]" value="1" ' . ($result['w'] ? 'checked="checked"' : '') . ' /></div></td>' .
'<td><div align="center"><input type="checkbox" name="s_'. $this->name .'[r]" value="1" ' . ($result['r'] ? 'checked="checked"' : '') . ' /></div></td>' .
'<td><div align="center"><input type="checkbox" name="s_'. $this->name .'[f]" value="1" ' . ($result['f'] ? 'checked="checked"' : '') . ' /></div></td>' .
'<td><div align="center"><input type="checkbox" name="s_'. $this->name .'[s]" value="1" ' . ($result['s'] ? 'checked="checked"' : '') . ' /></div></td>' .
'<td><div align="center"><input type="checkbox" name="s_'. $this->name .'[u]" value="1" ' . ($currentsetting['u'] ? 'checked="checked"' : '') . ' /></div></td>' .
'<td><div align="center"><input type="checkbox" name="s_'. $this->name .'[m]" value="1" ' . ($currentsetting['m'] ? 'checked="checked"' : '') . ' /></div></td>' .
'<td><div align="center"><input type="checkbox" name="s_'. $this->name .'[t]" value="1" ' . ($currentsetting['t'] ? 'checked="checked"' : '') . ' /></div></td>' .
'<td><div align="center"><input type="checkbox" name="s_'. $this->name .'[w]" value="1" ' . ($currentsetting['w'] ? 'checked="checked"' : '') . ' /></div></td>' .
'<td><div align="center"><input type="checkbox" name="s_'. $this->name .'[r]" value="1" ' . ($currentsetting['r'] ? 'checked="checked"' : '') . ' /></div></td>' .
'<td><div align="center"><input type="checkbox" name="s_'. $this->name .'[f]" value="1" ' . ($currentsetting['f'] ? 'checked="checked"' : '') . ' /></div></td>' .
'<td><div align="center"><input type="checkbox" name="s_'. $this->name .'[s]" value="1" ' . ($currentsetting['s'] ? 'checked="checked"' : '') . ' /></div></td>' .
'</tr></table>' .
'</td></tr><tr><td>&nbsp;</td><td align="left">' . $this->description . '</td></tr>';
@ -1177,14 +1194,10 @@ class admin_setting_special_perfdebug extends admin_setting_configcheckbox {
// N.B.: THIS FUNCTION HANDLES AUTHENTICATION
function admin_externalpage_setup($section) {
global $CFG, $ADMIN, $PAGE, $_GET, $USER;
global $CFG, $ADMIN, $PAGE, $USER;
require_once($CFG->libdir . '/blocklib.php');
require_once($CFG->dirroot . '/admin/pagelib.php');
// this needs to be changed.
$_GET['section'] = $section;
require_once($CFG->dirroot . '/' . $CFG->admin . '/pagelib.php');
define('TEMPORARY_ADMIN_PAGE_ID',26);
@ -1197,7 +1210,7 @@ function admin_externalpage_setup($section) {
$PAGE = page_create_object($pagetype,TEMPORARY_ADMIN_PAGE_ID);
$PAGE->init_full();
$PAGE->init_full($section);
$root = $ADMIN->locate($PAGE->section);

View file

@ -12,7 +12,7 @@ class page_admin extends page_base {
var $pathtosection;
var $visiblepathtosection;
function init_full() {
function init_full($section) {
global $CFG, $ADMIN;
if($this->full_init_done) {
@ -20,7 +20,7 @@ class page_admin extends page_base {
}
// fetch the path parameter
$this->section = optional_param("section","",PARAM_PATH);
$this->section = $section;
$this->visiblepathtosection = array();
@ -65,8 +65,7 @@ class page_admin extends page_base {
}
function url_get_parameters() { // only handles parameters relevant to the admin pagetype
$this->init_full();
return array('section' => $this->section);
return array('section' => (isset($this->section) ? $this->section : ''));
}
function blocks_get_positions() {
@ -82,12 +81,12 @@ class page_admin extends page_base {
parent::init_quick($data);
}
function print_header() {
function print_header($section = '') {
global $USER, $CFG, $SITE;
$this->init_full();
$this->init_full($section); // we're trusting that init_full() has already been called by now; it should have.
// if not, print_header() has to be called with a $section parameter
// should this rely on showblocksonmodpages in any way? after all, teachers aren't accessing this...
if ($this->user_allowed_editing()) {
$buttons = '<table><tr><td><form target="' . $CFG->framename . '" method="get" action="' . $this->url_get_path() . '">'.
'<input type="hidden" name="adminedit" value="'.($this->user_is_editing()?'off':'on').'" />'.

View file

@ -2,8 +2,8 @@
require_once('../config.php');
require_once($CFG->dirroot . '/' . $CFG->admin . '/adminlib.php');
require_once($CFG->libdir . '/blocklib.php'); //d
require_once($CFG->dirroot . '/' . $CFG->admin . '/pagelib.php'); //d
require_once($CFG->libdir . '/blocklib.php');
require_once($CFG->dirroot . '/' . $CFG->admin . '/pagelib.php');
if ($site = get_site()) {
require_login();
@ -20,7 +20,9 @@ page_map_class($pagetype, $pageclass);
$PAGE = page_create_object($pagetype,TEMPORARY_ADMIN_PAGE_ID);
$PAGE->init_full();
$section = optional_param('section', '', PARAM_ALPHAEXT);
$PAGE->init_full($section);
$adminediting = optional_param('adminedit', -1, PARAM_BOOL);