From: vinkmar Date: Mon, 21 Aug 2006 04:06:58 +0000 (+0000) Subject: fixed tabs, fixed potential notices for undefined variables, added structure that... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=6fcbab99ef1aeb2845aa9da7d42ee1b114e4f04e;p=moodle.git 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 --- diff --git a/admin/adminlib.php b/admin/adminlib.php index 85b7423ebc..45a63d41d0 100644 --- a/admin/adminlib.php +++ b/admin/adminlib.php @@ -14,9 +14,9 @@ include_once($CFG->dirroot . '/backup/lib.php'); // admin_category or an admin_externalpage) is searchable class part_of_admin_tree { - function &locate($name) { trigger_error('Admin class does not implement method locate()', E_USER_WARNING); return; } - function check_access() { trigger_error('Admin class does not implement method check_access()', E_USER_WARNING); return; } - function path($name, $path = array()) { trigger_error('Admin class does not implement method path()', E_USER_WARNING); return; } + function &locate($name) { trigger_error('Admin class does not implement method locate()', E_USER_WARNING); return; } + function check_access() { trigger_error('Admin class does not implement method check_access()', E_USER_WARNING); return; } + function path($name, $path = array()) { trigger_error('Admin class does not implement method path()', E_USER_WARNING); return; } } @@ -26,7 +26,7 @@ class part_of_admin_tree { class parentable_part_of_admin_tree extends part_of_admin_tree { function add($destinationname, &$something) { trigger_error('Admin class does not implement method add()', E_USER_WARNING); return; } - + } //--------------------------------------------------------------------------------------------------- @@ -38,53 +38,53 @@ class parentable_part_of_admin_tree extends part_of_admin_tree { class admin_category extends parentable_part_of_admin_tree { var $children; - var $name; - var $visiblename; - - function admin_category($name, $visiblename) { - $this->children = array(); - $this->name = $name; - $this->visiblename = $visiblename; - } - - function path($name, $path = array()) { - - $path[count($path)] = $this->name; - - if ($this->name == $name) { - return $path; - } - - foreach($this->children as $child) { - if ($return = $child->path($name, $path)) { - return $return; - } - } - - return NULL; - - } + var $name; + var $visiblename; + + function admin_category($name, $visiblename) { + $this->children = array(); + $this->name = $name; + $this->visiblename = $visiblename; + } + + function path($name, $path = array()) { + + $path[count($path)] = $this->name; + + if ($this->name == $name) { + return $path; + } + + foreach($this->children as $child) { + if ($return = $child->path($name, $path)) { + return $return; + } + } + + return NULL; + + } function &locate($name) { - - if ($this->name == $name) { - return $this; - } - - foreach($this->children as $child) { - if ($return =& $child->locate($name)) { - return $return; - } - } - $return = NULL; - return $return; - } + + if ($this->name == $name) { + return $this; + } + + foreach($this->children as $child) { + if ($return =& $child->locate($name)) { + return $return; + } + } + $return = NULL; + return $return; + } function add($destinationname, &$something, $precedence = '') { - - if (!is_a($something, 'part_of_admin_tree')) { - return false; - } + + if (!is_a($something, 'part_of_admin_tree')) { + return false; + } if ($destinationname == $this->name) { if ($precedence === '') { @@ -95,37 +95,37 @@ class admin_category extends parentable_part_of_admin_tree { } $this->children[$precedence] = $something; } - return true; - } - - unset($entries); + return true; + } + + unset($entries); $entries = array_keys($this->children); - - foreach($entries as $entry) { - $child =& $this->children[$entry]; - if (is_a($child, 'parentable_part_of_admin_tree')) { - if ($child->add($destinationname, $something, $precedence)) { - return true; - } - } - } - - return false; - - } - - function check_access() { - - $return = false; - foreach ($this->children as $child) { - $return = $return || $child->check_access(); - } - - return $return; - - } - + + foreach($entries as $entry) { + $child =& $this->children[$entry]; + if (is_a($child, 'parentable_part_of_admin_tree')) { + if ($child->add($destinationname, $something, $precedence)) { + return true; + } + } + } + + return false; + + } + + function check_access() { + + $return = false; + foreach ($this->children as $child) { + $return = $return || $child->check_access(); + } + + return $return; + + } + } // this is the class we use to add an external page to the admin hierarchy. on the @@ -148,24 +148,24 @@ class admin_externalpage extends part_of_admin_tree { $this->role = $role; } - function path($name, $path = array()) { - if ($name == $this->name) { - array_push($path, $this->name); - return $path; - } else { - return NULL; - } - } - - function &locate($name) { + function path($name, $path = array()) { + if ($name == $this->name) { + array_push($path, $this->name); + return $path; + } else { + return NULL; + } + } + + function &locate($name) { $return = ($this->name == $name ? $this : NULL); - return $return; - } + return $return; + } - function check_access() { - $context = get_context_instance(CONTEXT_SYSTEM, SITEID); + function check_access() { + $context = get_context_instance(CONTEXT_SYSTEM, SITEID); return has_capability($this->role, $context); - } + } } @@ -175,67 +175,66 @@ class admin_externalpage extends part_of_admin_tree { class admin_settingpage extends part_of_admin_tree { var $name; - var $visiblename; - var $settings; - var $role; - - function path($name, $path = array()) { - if ($name == $this->name) { - array_push($path, $this->name); - return $path; - } else { - return NULL; - } - } - - function &locate($name) { + var $visiblename; + var $settings; + var $role; + + function path($name, $path = array()) { + if ($name == $this->name) { + array_push($path, $this->name); + return $path; + } else { + return NULL; + } + } + + function &locate($name) { $return = ($this->name == $name ? $this : NULL); - return $return; - } - - function admin_settingpage($name, $visiblename, $role = 'moodle/legacy:admin') { - global $CFG; - $this->settings = new stdClass(); - $this->name = $name; - $this->visiblename = $visiblename; - $this->role = $role; - } - - function add(&$setting) { - if (is_a($setting, 'admin_setting')) { - $temp = $setting->name; - $this->settings->$temp =& $setting; - return true; - } - return false; - } - - function check_access() { - $context = get_context_instance(CONTEXT_SYSTEM, SITEID); + return $return; + } + + function admin_settingpage($name, $visiblename, $role = 'moodle/legacy:admin') { + global $CFG; + $this->settings = new stdClass(); + $this->name = $name; + $this->visiblename = $visiblename; + $this->role = $role; + } + + function add(&$setting) { + if (is_a($setting, 'admin_setting')) { + $this->settings->{$setting->name} =& $setting; + return true; + } + return false; + } + + function check_access() { + $context = get_context_instance(CONTEXT_SYSTEM, SITEID); return has_capability($this->role, $context); - } - - function output_html() { - $return = '' . "\n"; - foreach($this->settings as $setting) { - $return .= $setting->output_html(); - } - $return .= '
'; - return $return; - } + } + + function output_html() { + $return = '' . "\n"; + foreach($this->settings as $setting) { + $return .= $setting->output_html(); + } + $return .= '
'; + return $return; + } // return '' (empty string) for successful write, otherwise return language-specific error function write_settings($data) { - $return = ''; - foreach($this->settings as $setting) { - if (isset($data['s_' . $setting->name])) { + $return = ''; + foreach($this->settings as $setting) { + if (isset($data['s_' . $setting->name])) { $return .= $setting->write_setting($data['s_' . $setting->name]); } else { $return .= $setting->write_setting(''); } - } - return $return; - } + } + return $return; + } } @@ -244,28 +243,28 @@ class admin_settingpage extends part_of_admin_tree { class admin_setting { var $name; - var $visiblename; - var $description; - var $data; + var $visiblename; + var $description; + var $data; function admin_setting($name, $visiblename, $description) { - $this->name = $name; - $this->visiblename = $visiblename; - $this->description = $description; - } - - function get_setting() { - return; // has to be overridden - } - - function write_setting($data) { - return; // has to be overridden - } - - function output_html() { + $this->name = $name; + $this->visiblename = $visiblename; + $this->description = $description; + } + + function get_setting() { + return NULL; // has to be overridden + } + + function write_setting($data) { + return; // has to be overridden + } + + function output_html() { return; // has to be overridden - } - + } + } @@ -279,15 +278,14 @@ 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 - } - - function write_setting($data) { - $data = clean_param($data, $this->paramtype); - return (set_config($this->name,$data) ? '' : get_string('errorsetting', 'admin') . $this->visiblename . '
'); - } + global $CFG; + return (isset($CFG->{$this->name}) ? $CFG->{$this->name} : NULL); + } + + function write_setting($data) { + $data = clean_param($data, $this->paramtype); + return (set_config($this->name,$data) ? '' : get_string('errorsetting', 'admin') . $this->visiblename . '
'); + } function output_html() { return '' . $this->visiblename . '' . @@ -304,18 +302,17 @@ 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 - } - - function write_setting($data) { - if ($data == '1') { - return (set_config($this->name,1) ? '' : get_string('errorsetting', 'admin') . $this->visiblename . '
'); - } else { - return (set_config($this->name,0) ? '' : get_string('errorsetting', 'admin') . $this->visiblename . '
'); - } - } + global $CFG; + return (isset($CFG->{$this->name}) ? $CFG->{$this->name} : NULL); + } + + function write_setting($data) { + if ($data == '1') { + return (set_config($this->name,1) ? '' : get_string('errorsetting', 'admin') . $this->visiblename . '
'); + } else { + return (set_config($this->name,0) ? '' : get_string('errorsetting', 'admin') . $this->visiblename . '
'); + } + } function output_html() { return '' . $this->visiblename . '' . @@ -328,35 +325,34 @@ class admin_setting_configcheckbox extends admin_setting { class admin_setting_configselect extends admin_setting { var $choices; - + function admin_setting_configselect($name, $visiblename, $description, $choices) { - $this->choices = $choices; - parent::admin_setting($name, $visiblename, $description); - } + $this->choices = $choices; + parent::admin_setting($name, $visiblename, $description); + } function get_setting() { - global $CFG; - $temp = $this->name; - return $CFG->$temp; - } - - function write_setting($data) { + global $CFG; + return (isset($CFG->{$this->name}) ? $CFG->{$this->name} : NULL); + } + + function write_setting($data) { // check that what we got was in the original choices - if (! in_array($data, array_keys($this->choices))) { - return 'Error setting ' . $this->visiblename . '
'; - } - - return (set_config($this->name, $data) ? '' : get_string('errorsetting', 'admin') . $this->visiblename . '
'); - } - - function output_html() { - $return = '' . $this->visiblename . ''; foreach ($this->choices as $key => $value) { - $return .= ''; - } - $return .= ' ' . $this->description . ''; - return $return; - } + $return .= ''; + } + $return .= ' ' . $this->description . ''; + return $return; + } } @@ -365,51 +361,52 @@ class admin_setting_configselect extends admin_setting { class admin_setting_configtime extends admin_setting { var $name2; - var $choices; - var $choices2; + var $choices; + var $choices2; function admin_setting_configtime($hoursname, $minutesname, $visiblename, $description) { - $this->name2 = $minutesname; - $this->choices = array(); - for ($i = 0; $i < 24; $i++) { - $this->choices[$i] = $i; - } - $this->choices2 = array(); - for ($i = 0; $i < 60; $i += 5) { - $this->choices2[$i] = $i; - } - parent::admin_setting($hoursname, $visiblename, $description); - } + $this->name2 = $minutesname; + $this->choices = array(); + for ($i = 0; $i < 24; $i++) { + $this->choices[$i] = $i; + } + $this->choices2 = array(); + for ($i = 0; $i < 60; $i += 5) { + $this->choices2[$i] = $i; + } + parent::admin_setting($hoursname, $visiblename, $description); + } 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)); - } - - function write_setting($data) { + global $CFG; + return (isset($CFG->{$this->name}) && isset($CFG->{$this->name2}) ? array($CFG->{$this->name}, $CFG->{$this->name2}) : NULL); + } + + function write_setting($data) { // check that what we got was in the original choices - if (!(in_array($data['h'], array_keys($this->choices)) && in_array($data['m'], array_keys($this->choices2)))) { - return get_string('errorsetting', 'admin') . $this->visiblename . '
'; - } - - return (set_config($this->name, $data['h']) && set_config($this->name2, $data['m']) ? '' : get_string('errorsetting', 'admin') . $this->visiblename . '
'); - } - - function output_html() { - $setvalue = $this->get_setting(); - $return = '' . $this->visiblename . ''; foreach ($this->choices as $key => $value) { - $return .= ''; - } - $return .= '       ' . $this->description . ''; - return $return; - } + $return .= ''; + } + $return .= ' ' . $this->description . ''; + return $return; + } } @@ -420,46 +417,49 @@ class admin_setting_configmultiselect extends admin_setting_configselect { } function get_setting() { - global $CFG; - $temp = $this->name; - return explode(',', $CFG->$temp); - } - - function write_setting($data) { - foreach ($data as $datum) { - if (! in_array($datum, array_keys($this->choices))) { - return get_string('errorsetting', 'admin') . $this->visiblename . '
'; - } - } - - return (set_config($this->name, implode(',',$data)) ? '' : get_string('errorsetting', 'admin') . $this->visiblename . '
'); - } - - function output_html() { - $return = '' . $this->visiblename . ''; foreach ($this->choices as $key => $value) { - $return .= ''; - } - $return .= ' ' . $this->description . ''; - return $return; + $return .= ''; + } + $return .= ' ' . $this->description . ''; + return $return; } } class admin_setting_special_adminseesall extends admin_setting_configcheckbox { - function admin_setting_special_adminseesall() { - $name = 'calendar_adminseesall'; - $visiblename = get_string('adminseesall', 'admin'); - $description = get_string('helpadminseesall', 'admin'); - parent::admin_setting($name, $visiblename, $description); - } + function admin_setting_special_adminseesall() { + $name = 'calendar_adminseesall'; + $visiblename = get_string('adminseesall', 'admin'); + $description = get_string('helpadminseesall', 'admin'); + parent::admin_setting($name, $visiblename, $description); + } function write_setting($data) { - global $SESSION; + global $SESSION; unset($SESSION->cal_courses_shown); - parent::write_setting($data); - } + parent::write_setting($data); + } } class admin_setting_sitesetselect extends admin_setting_configselect { @@ -468,89 +468,95 @@ class admin_setting_sitesetselect extends admin_setting_configselect { function admin_setting_sitesetselect($name, $visiblename, $description, $choices) { - $site = get_site(); - $this->id = $site->id; - parent::admin_setting_configselect($name, $visiblename, $description, $choices); - - } - - function get_setting() { - $site = get_site(); - $temp = $this->name; - return $site->$temp; - } - - function write_setting($data) { - if (!in_array($data, array_keys($this->choices))) { + $site = get_site(); + $this->id = $site->id; + parent::admin_setting_configselect($name, $visiblename, $description, $choices); + + } + + function get_setting() { + $site = get_site(); + return (isset($site->{$this->name}) ? $site->{$this->name} : NULL); + } + + function write_setting($data) { + if (!in_array($data, array_keys($this->choices))) { return get_string('errorsetting', 'admin') . $this->visiblename . '
'; - } - $record = new stdClass(); - $record->id = $this->id; - $temp = $this->name; - $record->$temp = $data; - $record->timemodified = time(); - return (update_record('course', $record) ? '' : get_string('errorsetting', 'admin') . $this->visiblename . '
'); - } - + } + $record = new stdClass(); + $record->id = $this->id; + $temp = $this->name; + $record->$temp = $data; + $record->timemodified = time(); + return (update_record('course', $record) ? '' : get_string('errorsetting', 'admin') . $this->visiblename . '
'); + } + } class admin_setting_special_frontpage extends admin_setting_configselect { function admin_setting_special_frontpage($loggedin = false) { - global $CFG; - require_once($CFG->dirroot . '/course/lib.php'); - $name = 'frontpage' . ($loggedin ? 'loggedin' : ''); - $visiblename = get_string('frontpage' . ($loggedin ? 'loggedin' : ''),'admin'); - $description = get_string('configfrontpage' . ($loggedin ? 'loggedin' : ''),'admin'); - $choices = array(FRONTPAGENEWS => get_string('frontpagenews'), + global $CFG; + require_once($CFG->dirroot . '/course/lib.php'); + $name = 'frontpage' . ($loggedin ? 'loggedin' : ''); + $visiblename = get_string('frontpage' . ($loggedin ? 'loggedin' : ''),'admin'); + $description = get_string('configfrontpage' . ($loggedin ? 'loggedin' : ''),'admin'); + $choices = array(FRONTPAGENEWS => get_string('frontpagenews'), FRONTPAGECOURSELIST => get_string('frontpagecourselist'), FRONTPAGECATEGORYNAMES => get_string('frontpagecategorynames'), FRONTPAGECATEGORYCOMBO => get_string('frontpagecategorycombo'), - '' => get_string('none')); - if (count_records("course") > FRONTPAGECOURSELIMIT) { - unset($choices[FRONTPAGECOURSELIST]); - } - parent::admin_setting_configselect($name, $visiblename, $description, $choices); - } - + '' => get_string('none')); + if (count_records("course") > FRONTPAGECOURSELIMIT) { + unset($choices[FRONTPAGECOURSELIST]); + } + parent::admin_setting_configselect($name, $visiblename, $description, $choices); + } + function get_setting() { - global $CFG; - $temp = $this->name; - return (explode(',', $CFG->$temp)); - } - - function write_setting($data) { - if (empty($data)) { - $data = array(); - } - foreach($data as $datum) { - if (! in_array($datum, array_keys($this->choices))) { - return get_string('errorsetting', 'admin') . $this->visiblename . '
'; - } - } - return (set_config($this->name, implode(',', $data)) ? '' : get_string('errorsetting', 'admin') . $this->visiblename . '
'); - } - - function output_html() { - - $currentsetting = $this->get_setting(); - $return = '' . $this->visiblename . ''; - for ($i = 0; $i < count($this->choices) - 1; $i++) { - $return .=''; foreach ($this->choices as $key => $value) { $return .= ''; - } - $return .= ''; - if ($i !== count($this->choices) - 2) { - $return .= '  ' . get_string('then') . '  '; - } - } - $return .= ' ' . $this->description . ''; - return $return; - - - } + } + $return .= ''; + if ($i !== count($this->choices) - 2) { + $return .= '  ' . get_string('then') . '  '; + } + } + $return .= ' ' . $this->description . ''; + return $return; + + + } } class admin_setting_sitesetcheckbox extends admin_setting_configcheckbox { @@ -559,27 +565,26 @@ class admin_setting_sitesetcheckbox extends admin_setting_configcheckbox { function admin_setting_sitesetcheckbox($name, $visiblename, $description) { - $site = get_site(); - $this->id = $site->id; - parent::admin_setting_configcheckbox($name, $visiblename, $description); - - } - - function get_setting() { - $site = get_site(); - $temp = $this->name; - return ($site->$temp == '1' ? 1 : 0); - } - - function write_setting($data) { - $record = new stdClass(); - $record->id = $this->id; - $temp = $this->name; - $record->$temp = ($data == '1' ? 1 : 0); - $record->timemodified = time(); - return (update_record('course', $record) ? '' : get_string('errorsetting', 'admin') . $this->visiblename . '
'); - } - + $site = get_site(); + $this->id = $site->id; + parent::admin_setting_configcheckbox($name, $visiblename, $description); + + } + + function get_setting() { + $site = get_site(); + return (isset($site->{$this->name}) ? $site->{$this->name} : NULL); + } + + function write_setting($data) { + $record = new stdClass(); + $record->id = $this->id; + $temp = $this->name; + $record->$temp = ($data == '1' ? 1 : 0); + $record->timemodified = time(); + return (update_record('course', $record) ? '' : get_string('errorsetting', 'admin') . $this->visiblename . '
'); + } + } class admin_setting_sitesettext extends admin_setting_configtext { @@ -588,83 +593,81 @@ class admin_setting_sitesettext extends admin_setting_configtext { function admin_setting_sitesettext($name, $visiblename, $description, $paramtype) { - $site = get_site(); - $this->id = $site->id; - parent::admin_setting_configtext($name, $visiblename, $description, $paramtype); - - } - - function get_setting() { - $site = get_site(); - $temp = $this->name; - return $site->$temp; - } - - function write_setting($data) { - $record = new stdClass(); - $record->id = $this->id; - $temp = $this->name; - $record->$temp = $data; - $record->timemodified = time(); - return (update_record('course', $record) ? '' : get_string('errorsetting', 'admin') . $this->visiblename . '
'); - } - + $site = get_site(); + $this->id = $site->id; + parent::admin_setting_configtext($name, $visiblename, $description, $paramtype); + + } + + function get_setting() { + $site = get_site(); + return (isset($site->{$this->name}) ? $site->{$this->name} : NULL); + } + + function write_setting($data) { + $record = new stdClass(); + $record->id = $this->id; + $temp = $this->name; + $record->$temp = $data; + $record->timemodified = time(); + return (update_record('course', $record) ? '' : get_string('errorsetting', 'admin') . $this->visiblename . '
'); + } + } class admin_setting_special_frontpagedesc extends admin_setting { var $id; - - function admin_setting_special_frontpagedesc() { - $site = get_site(); - $this->id = $site->id; - $name = 'summary'; - $visiblename = get_string('frontpagedescription'); - $description = get_string('frontpagedescriptionhelp'); - parent::admin_setting($name, $visiblename, $description); - } + + function admin_setting_special_frontpagedesc() { + $site = get_site(); + $this->id = $site->id; + $name = 'summary'; + $visiblename = get_string('frontpagedescription'); + $description = get_string('frontpagedescriptionhelp'); + parent::admin_setting($name, $visiblename, $description); + } function output_html() { - - $usehtmleditor = can_use_html_editor(); - + + $usehtmleditor = can_use_html_editor(); + $return = '' . $this->visiblename . '' . - ''; - - ob_start(); // double-check the number of columns below... might overrun some screen resolutions - print_textarea($usehtmleditor, 20, 40, 0, 0, 's_' . $this->name, $this->get_setting()); - - if ($usehtmleditor) { - use_html_editor(); - } - $return .= ob_get_contents(); - ob_end_clean(); - $return .= ' ' . $this->description . ''; - return $return; - - } - - function get_setting() { - - $site = get_site(); - $temp = $this->name; - return ($site->$temp); - - } - - function write_setting($data) { - - $data = addslashes(clean_param($data, PARAM_CLEANHTML)); - - $record = new stdClass(); - $record->id = $this->id; - $temp = $this->name; - $record->$temp = $data; - $record->timemodified = time(); - - return(update_record('course', $record) ? '' : get_string('errorsetting', 'admin') . $this->visiblename . '
'); - - } + ''; + + ob_start(); // double-check the number of columns below... might overrun some screen resolutions + print_textarea($usehtmleditor, 20, 40, 0, 0, 's_' . $this->name, $this->get_setting()); + + if ($usehtmleditor) { + use_html_editor(); + } + $return .= ob_get_contents(); + ob_end_clean(); + $return .= ' ' . $this->description . ''; + return $return; + + } + + function get_setting() { + + $site = get_site(); + return (isset($site->{$this->name}) ? $site->{$this->name} : NULL); + + } + + function write_setting($data) { + + $data = addslashes(clean_param($data, PARAM_CLEANHTML)); + + $record = new stdClass(); + $record->id = $this->id; + $temp = $this->name; + $record->$temp = $data; + $record->timemodified = time(); + + return(update_record('course', $record) ? '' : get_string('errorsetting', 'admin') . $this->visiblename . '
'); + + } } @@ -674,84 +677,92 @@ class admin_setting_special_editorfontlist extends admin_setting { var $items; function admin_setting_special_editorfontlist() { - global $CFG; - $name = 'editorfontlist'; - $visiblename = get_string('editorfontlist', 'admin'); - $description = get_string('configeditorfontlist', 'admin'); - $items = explode(';', $CFG->editorfontlist); - $this->items = array(); - foreach ($items as $item) { - $item = explode(':', $item); - $this->items[$item[0]] = $item[1]; - } - parent::admin_setting($name, $visiblename, $description); - } - - function get_setting() { - return $this->items; - } - - function write_setting($data) { - - // there miiight be an easier way to do this :) - - $keys = array(); - $values = array(); - - foreach ($data as $key => $value) { - if (substr($key,0,1) == 'k') { - $keys[substr($key,1)] = $value; - } elseif (substr($key,0,1) == 'v') { - $values[substr($key,1)] = $value; - } - } - - $result = ''; - for ($i = 0; $i < count($keys); $i++) { - if (($keys[$i] !== '') && ($values[$i] !== '')) { - $result .= clean_param($keys[$i],PARAM_NOTAGS) . ':' . clean_param($values[$i], PARAM_NOTAGS) . ';'; - } - } - - $result = substr($result, 0, -1); // trim the last semicolon - - return (set_config($this->name, $result) ? '' : get_string('errorsetting', 'admin') . $this->visiblename . '
'); - } - - function output_html() { + global $CFG; + $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); + } + + function get_setting() { + return $this->items; + } + + function write_setting($data) { + + // there miiight be an easier way to do this :) + + $keys = array(); + $values = array(); + + foreach ($data as $key => $value) { + if (substr($key,0,1) == 'k') { + $keys[substr($key,1)] = $value; + } elseif (substr($key,0,1) == 'v') { + $values[substr($key,1)] = $value; + } + } + + $result = ''; + for ($i = 0; $i < count($keys); $i++) { + if (($keys[$i] !== '') && ($values[$i] !== '')) { + $result .= clean_param($keys[$i],PARAM_NOTAGS) . ':' . clean_param($values[$i], PARAM_NOTAGS) . ';'; + } + } + + $result = substr($result, 0, -1); // trim the last semicolon + + return (set_config($this->name, $result) ? '' : get_string('errorsetting', 'admin') . $this->visiblename . '
'); + } + + function output_html() { $return = '' . $this->visiblename . ''; - $count = 0; - foreach ($this->items as $key => $value) { - $return .= ''; - $return .= '  '; + $count = 0; + $currentsetting = $this->items; + if (!is_array($currentsetting)) { + $currentsetting = NULL; + } + foreach ($currentsetting as $key => $value) { + $return .= ''; + $return .= '  '; $return .= '
'; - $count++; - } - $return .= ''; - $return .= '  '; + $count++; + } + $return .= ''; + $return .= '  '; $return .= '
'; - $return .= ''; - $return .= '  '; + $return .= ''; + $return .= '  '; $return .= ''; - $return .= ' ' . $this->description . ''; + $return .= ' ' . $this->description . ''; return $return; - } - + } + } class admin_setting_special_editordictionary extends admin_setting_configselect { function admin_setting_special_editordictionary() { - $name = 'editordictionary'; - $visiblename = get_string('editordictionary','admin'); - $description = get_string('configeditordictionary', 'admin'); - $choices = $this->editor_get_dictionaries(); - if (! is_array($choices)) { - $choices = array(''); - } - - parent::admin_setting_configselect($name, $visiblename, $description, $choices); - } + $name = 'editordictionary'; + $visiblename = get_string('editordictionary','admin'); + $description = get_string('configeditordictionary', 'admin'); + $choices = $this->editor_get_dictionaries(); + if (! is_array($choices)) { + $choices = array(''); + } + + parent::admin_setting_configselect($name, $visiblename, $description, $choices); + } // function borrowed from the old moodle/admin/editor.php, slightly modified function editor_get_dictionaries () { @@ -815,110 +826,112 @@ class admin_setting_special_editordictionary extends admin_setting_configselect class admin_setting_special_editorhidebuttons extends admin_setting { var $name; - var $visiblename; - var $description; - var $items; + var $visiblename; + var $description; + var $items; function admin_setting_special_editorhidebuttons() { - $this->name = 'editorhidebuttons'; - $this->visiblename = get_string('editorhidebuttons', 'admin'); - $this->description = get_string('confeditorhidebuttons', 'admin'); + $this->name = 'editorhidebuttons'; + $this->visiblename = get_string('editorhidebuttons', 'admin'); + $this->description = get_string('confeditorhidebuttons', 'admin'); // weird array... buttonname => buttonimage (assume proper path appended). if you leave buttomimage blank, text will be printed instead - $this->items = array('fontname' => '', - 'fontsize' => '', - 'formatblock' => '', - 'bold' => 'ed_format_bold.gif', - 'italic' => 'ed_format_italic.gif', - 'underline' => 'ed_format_underline.gif', - 'strikethrough' => 'ed_format_strike.gif', - 'subscript' => 'ed_format_sub.gif', - 'superscript' => 'ed_format_sup.gif', - 'copy' => 'ed_copy.gif', - 'cut' => 'ed_cut.gif', - 'paste' => 'ed_paste.gif', - 'clean' => 'ed_wordclean.gif', - 'undo' => 'ed_undo.gif', - 'redo' => 'ed_redo.gif', - 'justifyleft' => 'ed_align_left.gif', - 'justifycenter' => 'ed_align_center.gif', - 'justifyright' => 'ed_align_right.gif', - 'justifyfull' => 'ed_align_justify.gif', - 'lefttoright' => 'ed_left_to_right.gif', - 'righttoleft' => 'ed_right_to_left.gif', - 'insertorderedlist' => 'ed_list_num.gif', - 'insertunorderedlist' => 'ed_list_bullet.gif', - 'outdent' => 'ed_indent_less.gif', - 'indent' => 'ed_indent_more.gif', - 'forecolor' => 'ed_color_fg.gif', - 'hilitecolor' => 'ed_color_bg.gif', - 'inserthorizontalrule' => 'ed_hr.gif', - 'createanchor' => 'ed_anchor.gif', - 'createlink' => 'ed_link.gif', - 'unlink' => 'ed_unlink.gif', - 'insertimage' => 'ed_image.gif', - 'inserttable' => 'insert_table.gif', - 'insertsmile' => 'em.icon.smile.gif', - 'insertchar' => 'icon_ins_char.gif', - 'spellcheck' => 'spell-check.gif', - 'htmlmode' => 'ed_html.gif', - 'popupeditor' => 'fullscreen_maximize.gif', - 'search_replace' => 'ed_replace.gif'); - } + $this->items = array('fontname' => '', + 'fontsize' => '', + 'formatblock' => '', + 'bold' => 'ed_format_bold.gif', + 'italic' => 'ed_format_italic.gif', + 'underline' => 'ed_format_underline.gif', + 'strikethrough' => 'ed_format_strike.gif', + 'subscript' => 'ed_format_sub.gif', + 'superscript' => 'ed_format_sup.gif', + 'copy' => 'ed_copy.gif', + 'cut' => 'ed_cut.gif', + 'paste' => 'ed_paste.gif', + 'clean' => 'ed_wordclean.gif', + 'undo' => 'ed_undo.gif', + 'redo' => 'ed_redo.gif', + 'justifyleft' => 'ed_align_left.gif', + 'justifycenter' => 'ed_align_center.gif', + 'justifyright' => 'ed_align_right.gif', + 'justifyfull' => 'ed_align_justify.gif', + 'lefttoright' => 'ed_left_to_right.gif', + 'righttoleft' => 'ed_right_to_left.gif', + 'insertorderedlist' => 'ed_list_num.gif', + 'insertunorderedlist' => 'ed_list_bullet.gif', + 'outdent' => 'ed_indent_less.gif', + 'indent' => 'ed_indent_more.gif', + 'forecolor' => 'ed_color_fg.gif', + 'hilitecolor' => 'ed_color_bg.gif', + 'inserthorizontalrule' => 'ed_hr.gif', + 'createanchor' => 'ed_anchor.gif', + 'createlink' => 'ed_link.gif', + 'unlink' => 'ed_unlink.gif', + 'insertimage' => 'ed_image.gif', + 'inserttable' => 'insert_table.gif', + 'insertsmile' => 'em.icon.smile.gif', + 'insertchar' => 'icon_ins_char.gif', + 'spellcheck' => 'spell-check.gif', + 'htmlmode' => 'ed_html.gif', + 'popupeditor' => 'fullscreen_maximize.gif', + 'search_replace' => 'ed_replace.gif'); + } function get_setting() { - global $CFG; - $temp = $this->name; - return explode(' ', $CFG->$temp); - } + global $CFG; + return (isset($CFG->{$this->name}) ? explode(' ', $CFG->{$this->name}) : NULL); + } function write_setting($data) { - $result = array(); - if (empty($data)) { $data = array(); } + $result = array(); + if (empty($data)) { $data = array(); } foreach ($data as $key => $value) { - if (!in_array($key, array_keys($this->items))) { - return get_string('errorsetting', 'admin') . $this->visiblename . '
'; - } - if ($value == '1') { - $result[] = $key; - } - } - return (set_config($this->name, implode(' ',$result)) ? '' : get_string('errorsetting', 'admin') . $this->visiblename . '
'); - } + if (!in_array($key, array_keys($this->items))) { + return get_string('errorsetting', 'admin') . $this->visiblename . '
'; + } + if ($value == '1') { + $result[] = $key; + } + } + return (set_config($this->name, implode(' ',$result)) ? '' : get_string('errorsetting', 'admin') . $this->visiblename . '
'); + } function output_html() { - - global $CFG; - - // checkboxes with input name="$this->name[$key]" value="1" - // we do 15 fields per column - - $currentsetting = $this->get_setting(); - - $return = '' . $this->visiblename . ''; - - $return .= ''; - $return .= '
'; - - $count = 0; - - foreach($this->items as $key => $value) { - if ($count % 15 == 0) { - $return .= ''; - } - - $return .= ($value == '' ? get_string($key,'editor') : '' . get_string($key,'editor') . '') . ' '; - $return .= '       '; - $count++; - if ($count % 15 != 0) { - $return .= '

'; - } - } - - $return .= '
'; - $return .= ' ' . $this->description . ''; - - return $return; - } + + global $CFG; + + // checkboxes with input name="$this->name[$key]" value="1" + // we do 15 fields per column + + $currentsetting = $this->get_setting(); + if (!is_array($currentsetting)) { + $currentsetting = array(); + } + + $return = '' . $this->visiblename . ''; + + $return .= ''; + $return .= '
'; + + $count = 0; + + foreach($this->items as $key => $value) { + if ($count % 15 == 0) { + $return .= ''; + } + + $return .= ($value == '' ? get_string($key,'editor') : '' . get_string($key,'editor') . '') . ' '; + $return .= '       '; + $count++; + if ($count % 15 != 0) { + $return .= '

'; + } + } + + $return .= '
'; + $return .= ' ' . $this->description . ''; + + return $return; + } } @@ -929,18 +942,17 @@ 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 - } - - function write_setting($data) { + $backup_config = backup_get_config(); + return (isset($backup_config->{$this->name}) ? $backup_config->{$this->name} : NULL); + } + + function write_setting($data) { // check that what we got was in the original choices - if (! in_array($data, array_keys($this->choices))) { - return get_string('errorsetting', 'admin') . $this->visiblename . '
'; - } - - return (backup_set_config($this->name, $data) ? '' : get_string('errorsetting', 'admin') . $this->visiblename . '
'); + if (! in_array($data, array_keys($this->choices))) { + return get_string('errorsetting', 'admin') . $this->visiblename . '
'; + } + + return (backup_set_config($this->name, $data) ? '' : get_string('errorsetting', 'admin') . $this->visiblename . '
'); } } @@ -948,27 +960,26 @@ class admin_setting_backupselect extends admin_setting_configselect { class admin_setting_special_backupsaveto extends admin_setting_configtext { function admin_setting_special_backupsaveto() { - $name = 'backup_sche_destination'; - $visiblename = get_string('saveto'); - $description = get_string('backupsavetohelp'); - parent::admin_setting_configtext($name, $visiblename, $description, PARAM_PATH); - } - - 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 - } - - function write_setting($data) { + $name = 'backup_sche_destination'; + $visiblename = get_string('saveto'); + $description = get_string('backupsavetohelp'); + parent::admin_setting_configtext($name, $visiblename, $description, PARAM_PATH); + } + + function get_setting() { + $backup_config = backup_get_config(); + return (isset($backup_config->{$this->name}) ? $backup_config->{$this->name} : NULL); + } + + function write_setting($data) { $data = clean_param($data, PARAM_PATH); - if (!empty($data) and (substr($data,-1) == '/' or substr($data,-1) == '\\')) { + if (!empty($data) and (substr($data,-1) == '/' or substr($data,-1) == '\\')) { return get_string('pathslasherror') . '
'; } else if (!empty($data) and !is_dir($data)) { - return get_string('pathnotexists') . '
'; + return get_string('pathnotexists') . '
'; } - return (backup_set_config($this->name, $data) ? '' : get_string('errorsetting', 'admin') . $this->visiblename . '
'); - } + return (backup_set_config($this->name, $data) ? '' : get_string('errorsetting', 'admin') . $this->visiblename . '
'); + } } @@ -979,114 +990,115 @@ class admin_setting_backupcheckbox extends admin_setting_configcheckbox { } function write_setting($data) { - if ($data == '1') { - return (backup_set_config($this->name, 1) ? '' : get_string('errorsetting', 'admin') . $this->visiblename . '
'); - } else { - return (backup_set_config($this->name, 0) ? '' : get_string('errorsetting', 'admin') . $this->visiblename . '
'); - } - } - - 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 - } + if ($data == '1') { + return (backup_set_config($this->name, 1) ? '' : get_string('errorsetting', 'admin') . $this->visiblename . '
'); + } else { + return (backup_set_config($this->name, 0) ? '' : get_string('errorsetting', 'admin') . $this->visiblename . '
'); + } + } + + function get_setting() { + $backup_config = backup_get_config(); + return (isset($backup_config->{$this->name}) ? $backup_config->{$this->name} : NULL); + } } class admin_setting_special_backuptime extends admin_setting_configtime { function admin_setting_special_backuptime() { - $name = 'backup_sche_hour'; - $name2 = 'backup_sche_minute'; - $visiblename = get_string('executeat'); - $description = get_string('backupexecuteathelp'); + $name = 'backup_sche_hour'; + $name2 = 'backup_sche_minute'; + $visiblename = get_string('executeat'); + $description = get_string('backupexecuteathelp'); parent::admin_setting_configtime($name, $name2, $visiblename, $description); } - - 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 - } - - function write_setting($data) { + + function get_setting() { + $backup_config = backup_get_config(); + 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) { // check that what we got was in the original choices - if (!(in_array($data['h'], array_keys($this->choices)) && in_array($data['m'], array_keys($this->choices2)))) { - return get_string('errorsetting', 'admin') . $this->visiblename . '
'; - } - - return (backup_set_config($this->name, $data['h']) && backup_set_config($this->name2, $data['m']) ? '' : get_string('errorsetting', 'admin') . $this->visiblename . '
'); - } - + if (!(in_array($data['h'], array_keys($this->choices)) && in_array($data['m'], array_keys($this->choices2)))) { + return get_string('errorsetting', 'admin') . $this->visiblename . '
'; + } + + return (backup_set_config($this->name, $data['h']) && backup_set_config($this->name2, $data['m']) ? '' : get_string('errorsetting', 'admin') . $this->visiblename . '
'); + } + } class admin_setting_special_backupdays extends admin_setting { function admin_setting_special_backupdays() { - $name = 'backup_sche_weekdays'; - $visiblename = get_string('schedule'); - $description = get_string('backupschedulehelp'); - parent::admin_setting($name, $visiblename, $description); - } - - function get_setting() { - $backup_config = backup_get_config(); - $temp = $this->name; - return (isset($backup_config->$temp) ? $backup_config->$temp : '0000000'); - } - - function output_html() { - + $name = 'backup_sche_weekdays'; + $visiblename = get_string('schedule'); + $description = get_string('backupschedulehelp'); + parent::admin_setting($name, $visiblename, $description); + } + + function get_setting() { + $backup_config = backup_get_config(); + return (isset($backup_config->{$this->name}) ? $backup_config->{$this->name} : NULL); + } + + function output_html() { + + $currentsetting = $this->get_setting(); + if ($currentsetting === NULL) { + $currentsetting = '0000000'; + } + return '' . $this->visiblename . '' . - '' . - '' . - '' . - '' . - '' . - '' . - '' . - '' . - '
  ' . get_string('sunday', 'calendar') . '  
  ' . - get_string('monday', 'calendar') . '  
  ' . get_string('tuesday', 'calendar') . '  
  ' . - get_string('wednesday', 'calendar') . '  
  ' . get_string('thursday', 'calendar') . '  
  ' . - get_string('friday', 'calendar') . '  
  ' . get_string('saturday', 'calendar') . '  
get_setting(),0,1) == '1' ? 'checked="checked"' : '') . ' />
get_setting(),1,1) == '1' ? 'checked="checked"' : '') . ' />
get_setting(),2,1) == '1' ? 'checked="checked"' : '') . ' />
get_setting(),3,1) == '1' ? 'checked="checked"' : '') . ' />
get_setting(),4,1) == '1' ? 'checked="checked"' : '') . ' />
get_setting(),5,1) == '1' ? 'checked="checked"' : '') . ' />
get_setting(),6,1) == '1' ? 'checked="checked"' : '') . ' />
' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '
  ' . get_string('sunday', 'calendar') . '  
  ' . + get_string('monday', 'calendar') . '  
  ' . get_string('tuesday', 'calendar') . '  
  ' . + get_string('wednesday', 'calendar') . '  
  ' . get_string('thursday', 'calendar') . '  
  ' . + get_string('friday', 'calendar') . '  
  ' . get_string('saturday', 'calendar') . '  
' . ' ' . $this->description . ''; - - } - - // we're using the array trick (see http://ca.php.net/manual/en/faq.html.php#faq.html.arrays) to get the data passed to use without having to modify - // admin_settingpage (note that admin_settingpage only calls write_setting with the data that matches $this->name... so if we have multiple form fields, - // they MUST go into an array named $this->name, or else we won't receive them here - function write_setting($data) { - $week = 'umtwrfs'; - $result = array(0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0); - foreach($data as $key => $value) { - if ($value == '1') { - $result[strpos($week, $key)] = 1; - } - } - return (backup_set_config($this->name, implode('',$result)) ? '' : get_string('errorsetting', 'admin') . $this->visiblename . '
'); - } + + } + + // we're using the array trick (see http://ca.php.net/manual/en/faq.html.php#faq.html.arrays) to get the data passed to use without having to modify + // admin_settingpage (note that admin_settingpage only calls write_setting with the data that matches $this->name... so if we have multiple form fields, + // they MUST go into an array named $this->name, or else we won't receive them here + function write_setting($data) { + $week = 'umtwrfs'; + $result = array(0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0); + foreach($data as $key => $value) { + if ($value == '1') { + $result[strpos($week, $key)] = 1; + } + } + return (backup_set_config($this->name, implode('',$result)) ? '' : get_string('errorsetting', 'admin') . $this->visiblename . '
'); + } } class admin_setting_special_debug extends admin_setting_configcheckbox { function admin_setting_special_debug() { - $name = 'debug'; - $visiblename = get_string('debug', 'admin'); - $description = get_string('configdebug', 'admin'); - parent::admin_setting_configcheckbox($name, $visiblename, $description); - } - - function write_setting($data) { - if ($data == '1') { - return (set_config($this->name,15) ? '' : get_string('errorsetting', 'admin') . $this->visiblename . '
'); - } else { - return (set_config($this->name,7) ? '' : get_string('errorsetting', 'admin') . $this->visiblename . '
'); - } - } + $name = 'debug'; + $visiblename = get_string('debug', 'admin'); + $description = get_string('configdebug', 'admin'); + parent::admin_setting_configcheckbox($name, $visiblename, $description); + } + + function write_setting($data) { + if ($data == '1') { + return (set_config($this->name,15) ? '' : get_string('errorsetting', 'admin') . $this->visiblename . '
'); + } else { + return (set_config($this->name,7) ? '' : get_string('errorsetting', 'admin') . $this->visiblename . '
'); + } + } function output_html() { return '' . $this->visiblename . '' . @@ -1108,42 +1120,47 @@ class admin_setting_special_calendar_weekend extends admin_setting { function get_setting() { global $CFG; - $temp = $this->name; - $setting = intval($CFG->$temp); - return array('u' => $setting & 1, 'm' => $setting & 2, 't' => $setting & 4, 'w' => $setting & 8, 'r' => $setting & 16, 'f' => $setting & 32, 's' => $setting & 64); + 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) { - $week = 'umtwrfs'; - $result = array(0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0); - foreach($data as $key => $value) { - if ($value == '1') { - $result[strpos($week, $key)] = 1; - } - } - return (set_config($this->name, bindec(implode('',$result))) ? '' : get_string('errorsetting', 'admin') . $this->visiblename . '
'); - } + function write_setting($data) { + $week = 'umtwrfs'; + $result = array(0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0); + foreach($data as $key => $value) { + if ($value == '1') { + $result[strpos($week, $key)] = 1; + } + } + return (set_config($this->name, bindec(implode('',$result))) ? '' : get_string('errorsetting', 'admin') . $this->visiblename . '
'); + } - function output_html() { + 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 '' . $this->visiblename . '' . - '' . - '' . - '' . - '' . - '' . - '' . - '' . - '' . - '
  ' . get_string('sunday', 'calendar') . '  
  ' . - get_string('monday', 'calendar') . '  
  ' . get_string('tuesday', 'calendar') . '  
  ' . - get_string('wednesday', 'calendar') . '  
  ' . get_string('thursday', 'calendar') . '  
  ' . - get_string('friday', 'calendar') . '  
  ' . get_string('saturday', 'calendar') . '  
' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '
  ' . get_string('sunday', 'calendar') . '  
  ' . + get_string('monday', 'calendar') . '  
  ' . get_string('tuesday', 'calendar') . '  
  ' . + get_string('wednesday', 'calendar') . '  
  ' . get_string('thursday', 'calendar') . '  
  ' . + get_string('friday', 'calendar') . '  
  ' . get_string('saturday', 'calendar') . '  
' . ' ' . $this->description . ''; - - } + + } } @@ -1151,19 +1168,19 @@ class admin_setting_special_calendar_weekend extends admin_setting { class admin_setting_special_perfdebug extends admin_setting_configcheckbox { function admin_setting_special_perfdebug() { - $name = 'perfdebug'; - $visiblename = get_string('perfdebug', 'admin'); - $description = get_string('configperfdebug', 'admin'); - parent::admin_setting_configcheckbox($name, $visiblename, $description); - } - - function write_setting($data) { - if ($data == '1') { - return (set_config($this->name,15) ? '' : get_string('errorsetting', 'admin') . $this->visiblename . '
'); - } else { - return (set_config($this->name,7) ? '' : get_string('errorsetting', 'admin') . $this->visiblename . '
'); - } - } + $name = 'perfdebug'; + $visiblename = get_string('perfdebug', 'admin'); + $description = get_string('configperfdebug', 'admin'); + parent::admin_setting_configcheckbox($name, $visiblename, $description); + } + + function write_setting($data) { + if ($data == '1') { + return (set_config($this->name,15) ? '' : get_string('errorsetting', 'admin') . $this->visiblename . '
'); + } else { + return (set_config($this->name,7) ? '' : get_string('errorsetting', 'admin') . $this->visiblename . '
'); + } + } function output_html() { return '' . $this->visiblename . '' . @@ -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); @@ -1210,13 +1223,13 @@ function admin_externalpage_setup($section) { if (!is_a($root, 'admin_externalpage')) { error(get_string('sectionerror','admin')); - die; + die; } // this eliminates our need to authenticate on the actual pages if (!($root->check_access())) { error(get_string('accessdenied', 'admin')); - die; + die; } $adminediting = optional_param('adminedit', -1, PARAM_BOOL); diff --git a/admin/index.php b/admin/index.php index 55c6783a2c..77accff9ef 100644 --- a/admin/index.php +++ b/admin/index.php @@ -559,4 +559,4 @@ admin_externalpage_print_footer(); -?> +?> \ No newline at end of file diff --git a/admin/pagelib.php b/admin/pagelib.php index a7b0689e7c..2eef6fc227 100644 --- a/admin/pagelib.php +++ b/admin/pagelib.php @@ -9,10 +9,10 @@ page_map_class(PAGE_ADMIN, 'page_admin'); class page_admin extends page_base { var $section; - var $pathtosection; + var $pathtosection; var $visiblepathtosection; - function init_full() { + function init_full($section) { global $CFG, $ADMIN; if($this->full_init_done) { @@ -20,19 +20,19 @@ class page_admin extends page_base { } // fetch the path parameter - $this->section = optional_param("section","",PARAM_PATH); + $this->section = $section; $this->visiblepathtosection = array(); - - // this part is (potentially) processor-intensive... there's gotta be a better way - // of handling this - if ($this->pathtosection = $ADMIN->path($this->section)) { - foreach($this->pathtosection as $element) { - if ($pointer = $ADMIN->locate($element)) { - array_push($this->visiblepathtosection, $pointer->visiblename); - } - } - } + + // this part is (potentially) processor-intensive... there's gotta be a better way + // of handling this + if ($this->pathtosection = $ADMIN->path($this->section)) { + foreach($this->pathtosection as $element) { + if ($pointer = $ADMIN->locate($element)) { + array_push($this->visiblepathtosection, $pointer->visiblename); + } + } + } // all done $this->full_init_done = true; @@ -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 = '
'. ''. @@ -97,7 +96,7 @@ class page_admin extends page_base { } else { $buttons = ' '; } - + print_header("$SITE->shortname: " . implode(": ",$this->visiblepathtosection), $SITE->fullname, implode(" -> ",$this->visiblepathtosection),'', '', true, $buttons, ''); } diff --git a/admin/settings.php b/admin/settings.php index d1bdb2b227..617fa12a5c 100644 --- a/admin/settings.php +++ b/admin/settings.php @@ -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); @@ -42,12 +44,12 @@ $root = $ADMIN->locate($PAGE->section); if (!is_a($root, 'admin_settingpage')) { error(get_string('sectionerror', 'admin')); - die; + die; } if (!($root->check_access())) { error(get_string('accessdenied', 'admin')); - die; + die; } // WRITING SUBMITTED DATA (IF ANY) ------------------------------------------------------------------------------- @@ -56,14 +58,14 @@ if ($data = data_submitted()) { if (confirm_sesskey()) { $errors = $root->write_settings((array)$data); if (empty($errors)) { - redirect("$CFG->wwwroot/admin/settings.php?section=" . $PAGE->section, get_string('changessaved'),1); - } else { - error(get_string('errorwithsettings', 'admin') . '
' . $errors); - } - } else { - error(get_string('confirmsesskeybad', 'error')); - die; - } + redirect("$CFG->wwwroot/admin/settings.php?section=" . $PAGE->section, get_string('changessaved'),1); + } else { + error(get_string('errorwithsettings', 'admin') . '
' . $errors); + } + } else { + error(get_string('confirmsesskeybad', 'error')); + die; + } } // ---------------------------------------------------------------------------------------------------------------