]> git.mjollnir.org Git - moodle.git/commitdiff
Admin page cleanup (Google soc 2006)
authorvinkmar <vinkmar>
Fri, 18 Aug 2006 07:25:17 +0000 (07:25 +0000)
committervinkmar <vinkmar>
Fri, 18 Aug 2006 07:25:17 +0000 (07:25 +0000)
21 files changed:
admin/adminlib.php [new file with mode: 0644]
admin/auth.php
admin/block.php
admin/blocks.php
admin/enrol.php
admin/enrol_config.php
admin/environment.php
admin/filter.php
admin/filters.php
admin/index.php
admin/lang.php
admin/langdoc.php
admin/langimport.php
admin/maintenance.php
admin/module.php
admin/modules.php
admin/pagelib.php [new file with mode: 0644]
admin/roles/manage.php
admin/settings.php [new file with mode: 0644]
admin/timezoneimport.php
admin/user.php

diff --git a/admin/adminlib.php b/admin/adminlib.php
new file mode 100644 (file)
index 0000000..0468411
--- /dev/null
@@ -0,0 +1,1243 @@
+<?php // $Id$
+
+//---------------------------------------------------------------------------------------------------
+// Miscellaneous Header Stuff
+//---------------------------------------------------------------------------------------------------
+
+include_once($CFG->dirroot . '/backup/lib.php');
+
+//---------------------------------------------------------------------------------------------------
+// Interfaces
+//---------------------------------------------------------------------------------------------------
+
+// part_of_admin_tree indicates that a node (whether it be an admin_settingpage or an
+// admin_category or an admin_externalpage) is searchable
+interface part_of_admin_tree {
+
+       function &locate($name);
+       function check_access();        
+       function path($name, $path = array());
+
+}
+
+// parentable_part_of_admin_tree indicates that a node can have children in the hierarchy. only
+// admin_category implements this interface (yes, yes, theoretically admin_setting* is a child of
+// admin_settingpage, but you can't navigate admin_setting*s through the hierarchy)
+interface parentable_part_of_admin_tree {
+
+    function add($destinationname, &$something);
+       
+}
+
+//---------------------------------------------------------------------------------------------------
+// Classes
+//---------------------------------------------------------------------------------------------------
+
+// admin categories don't handle much... they can't be printed to the screen (except as a hierarchy), and when we
+// check_access() to a category, we're actually just checking if any of its children are accessible
+class admin_category implements part_of_admin_tree, 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;
+       
+       }
+
+    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;
+       }
+
+    function add($destinationname, &$something, $precedence = '') {
+       
+           if (!($something instanceof part_of_admin_tree)) {
+                   return false;
+               }
+
+        if ($destinationname == $this->name) {
+            if ($precedence === '') {
+                $this->children[] = $something;
+            } else {
+                if (isset($this->children[$precedence])) { // this should never, ever be triggered in a release version of moodle.
+                    echo ('<font style="color: red;">There is a precedence conflict in the category ' . $this->name . '. The object named ' . $something->name . ' is overwriting the object named ' . $this->children[$precedence]->name . '.</font><br />');
+                }
+                $this->children[$precedence] = $something;
+            }
+                       return true;
+               }
+               
+               foreach($this->children as $child) {
+                       if ($child instanceof 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
+// external page (if you'd like), do the following for a consistent look & feel:
+//  -require_once admin/adminlib.php
+//  -start the page with a call to admin_externalpage_setup($name)
+//  -use admin_externalpage_print_header() to print the header & blocks
+//  -use admin_externalpage_print_footer() to print the footer
+class admin_externalpage implements part_of_admin_tree {
+
+    var $name;
+    var $visiblename;
+    var $url;
+    var $role;
+    
+    function admin_externalpage($name, $visiblename, $url, $role = 'moodle/legacy:admin') {
+        $this->name = $name;
+        $this->visiblename = $visiblename;
+        $this->url = $url;
+        $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) {
+        $return = ($this->name == $name ? $this : NULL);
+           return $return;
+       }
+    
+       function check_access() {
+           $context = get_context_instance(CONTEXT_SYSTEM, SITEID); 
+        return has_capability($this->role, $context);
+       }
+
+}
+
+// authentication happens at this level
+// an admin_settingpage is a LEAF of the admin_tree, it can't have children. it only contains
+// an array of admin_settings that can be printed out onto a webpage
+class admin_settingpage implements 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) {
+        $return = ($this->name == $name ? $this : NULL);
+           return $return;
+       }
+       
+       function admin_settingpage($name, $visiblename, $role = 'moodle/legacy:admin') {
+           $this->settings = new stdClass();
+               $this->name = $name;
+               $this->visiblename = $visiblename;
+               $this->role = $role;
+       }
+       
+       function add(&$setting) {
+           if ($setting instanceof admin_setting) {
+                   $temp = $setting->name;
+           $this->settings->$temp =& $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 = '<table class="generaltable" width="100%" border="0" align="center" cellpadding="5" cellspacing="1">' . "\n";
+           foreach($this->settings as $setting) {
+                 $return .= $setting->output_html();
+               }
+               $return .= '</table>';
+               return $return;
+       }
+
+    // return '' (empty string) for successful write, otherwise return language-specific error
+    function write_settings($data) {
+           $return = '';
+               foreach($this->settings as $setting) {
+                   $return .= $setting->write_setting($data['s_' . $setting->name]);
+               }
+               return $return;
+       }
+
+}
+
+
+// read & write happens at this level; no authentication
+class admin_setting {
+
+    var $name;
+       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() {
+        return; // has to be overridden
+       }
+               
+}
+
+
+class admin_setting_configtext extends admin_setting {
+
+    var $paramtype;
+
+    function admin_setting_configtext($name, $visiblename, $description, $paramtype = 'PARAM_RAW') {
+        $this->paramtype = $paramtype;
+        parent::admin_setting($name, $visiblename, $description);
+    }
+
+    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) ? '' : 'Error setting ' . $this->visiblename . '<br />');
+       }
+
+    function output_html() {
+        return '<tr><td width="100" align="right" valign="top">' . $this->visiblename . '</td>' .
+            '<td align="left"><input type="text" size="50" name="s_'. $this->name .'" value="'. $this->get_setting() .'" /></td></tr>' .
+            '<tr><td>&nbsp;</td><td align="left">' . $this->description . '</td></tr>';
+    }
+
+}
+
+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) ? '' : 'Error setting ' . $this->visiblename . '<br />');
+               } else {
+           return (set_config($this->name,0) ? '' : 'Error setting ' . $this->visiblename . '<br />');
+               }
+       }
+
+    function output_html() {
+        return '<tr><td width="100" align="right" valign="top">' . $this->visiblename . '</td>' .
+            '<td align="left"><input type="checkbox" size="50" name="s_'. $this->name .'" value="1" ' . ($this->get_setting() == true ? 'checked="checked"' : '') . ' /></td></tr>' .
+            '<tr><td>&nbsp;</td><td align="left">' . $this->description . '</td></tr>';
+    }
+
+}
+
+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);
+       }
+
+    function get_setting() {
+           global $CFG;
+        $temp = $this->name;
+           return $CFG->$temp;
+       }
+       
+       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 . '<br />';
+            }
+                
+                return (set_config($this->name, $data) ? '' : 'Error setting ' . $this->visiblename . '<br />');
+    }
+       
+       function output_html() {
+           $return = '<tr><td width="100" align="right" valign="top">' . $this->visiblename . '</td><td align="left"><select name="s_' . $this->name .'">';
+        foreach ($this->choices as $key => $value) {
+                   $return .= '<option value="' . $key . '"' . ($key == $this->get_setting() ? ' selected="selected"' : '') . '>' . $value . '</option>';
+               }
+               $return .= '</select></td></tr><tr><td>&nbsp;</td><td align="left">' . $this->description . '</td></tr>';
+           return $return;
+       }
+
+}
+
+// this is a liiitle bit messy. we're using two selects, but we're returning them as an array named after $name (so we only use $name2
+// internally for the setting)
+class admin_setting_configtime extends admin_setting {
+
+    var $name2;
+       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);
+       }
+
+    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) {
+         // 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 'Error setting ' . $this->visiblename . '<br />';
+            }
+                
+                return (set_config($this->name, $data['h']) && set_config($this->name2, $data['m']) ? '' : 'Error setting ' . $this->visiblename . '<br />');
+    }
+       
+       function output_html() {
+           $setvalue = $this->get_setting();
+           $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>';
+               }
+               $return .= '</select>&nbsp;&nbsp;&nbsp;<select name="s_' . $this->name . '[m]">';
+        foreach ($this->choices2 as $key => $value) {
+                   $return .= '<option value="' . $key . '"' . ($key == $setvalue[1] ? ' selected="selected"' : '') . '>' . $value . '</option>';
+               }               
+               $return .= '</select></td></tr><tr><td>&nbsp;</td><td align="left">' . $this->description . '</td></tr>';
+           return $return;
+       }
+
+}
+
+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 'Error setting ' . $this->visiblename . '<br />';
+                       }
+               }
+               
+               return (set_config($this->name, implode(',',$data)) ? '' : 'Error setting ' . $this->visiblename . '<br />');
+       }
+       
+       function output_html() {
+           $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 .= '</select></td></tr><tr><td>&nbsp;</td><td align="left">' . $this->description . '</td></tr>';
+           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_configcheckbox($name, $visiblename, $description);
+       }
+
+    function write_setting($data) {
+           global $SESSION;
+        unset($SESSION->cal_courses_shown);
+               parent::write_setting($data);
+       }
+}
+
+class admin_setting_sitesetselect extends admin_setting_configselect {
+
+    var $id;
+
+    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))) {
+            return 'Error setting ' . $this->visiblename . '<br />';
+               }
+           $record = new stdClass();
+               $record->id = $this->id;
+               $temp = $this->name;
+               $record->$temp = $data;
+               $record->timemodified = time();
+           return (update_record('course', $record) ? '' : 'Error setting ' . $this->visiblename . '<br />');
+       }
+       
+}
+
+
+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'),
+                         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);
+       }
+       
+    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 'Error setting ' . $this->visiblename . '<br />';
+                       }
+               }
+               return (set_config($this->name, implode(',', $data)) ? '' : 'Error setting ' . $this->visiblename . '<br />');
+       }
+       
+       function output_html() {
+           
+               $currentsetting = $this->get_setting();
+           $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 .'[]">';             
+            foreach ($this->choices as $key => $value) {
+                   $return .= '<option value="' . $key . '"' . ($key == $currentsetting[$i] ? ' selected="selected"' : '') . '>' . $value . '</option>';
+               }
+               $return .= '</select>';
+                       if ($i !== count($this->choices) - 2) {
+                         $return .= '&nbsp;&nbsp;' . get_string('then') . '&nbsp;&nbsp;';
+                       }
+               }
+               $return .= '</td></tr><tr><td>&nbsp;</td><td align="left">' . $this->description . '</td></tr>';
+           return $return;     
+       
+       
+       }
+}
+
+class admin_setting_sitesetcheckbox extends admin_setting_configcheckbox {
+
+    var $id;
+
+    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) ? '' : 'Error setting ' . $this->visiblename . '<br />');
+       }
+       
+}
+
+class admin_setting_sitesettext extends admin_setting_configtext {
+
+    var $id;
+
+    function admin_setting_sitesettext($name, $visiblename, $description) {
+
+       $site = get_site();     
+       $this->id = $site->id;
+       parent::admin_setting_configtext($name, $visiblename, $description);
+       
+       }
+       
+       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) ? '' : 'Error setting ' . $this->visiblename . '<br />');
+       }
+       
+}
+
+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 output_html() {
+       
+               $usehtmleditor = can_use_html_editor();
+       
+        $return = '<tr><td width="100" align="right" valign="top">' . $this->visiblename . '</td>' .
+                          '<td>';
+                                  
+               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 .= '</td></tr><tr><td>&nbsp;</td><td>' . $this->description . '</td></tr>';
+           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) ? '' : 'Error setting ' . $this->visiblename . '<br />');
+       
+       }
+
+}
+
+
+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 .= $keys[$i] . ':' . $values[$i] . ';';
+                       }
+               }
+               
+               $result = substr($result, 0, -1); // trim the last semicolon
+               
+               return (set_config($this->name, $result) ? '' : 'Error setting ' . $this->visiblename . '<br />');
+       }
+    
+       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) {
+                   $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 />';
+                   $count++;
+               }
+           $return .= '<input type="text" name="s_editorfontlist[k' . $count . ']" value="" size="20" />';
+               $return .= '&nbsp;&nbsp;';
+        $return .= '<input type="text" name="s_editorfontlist[v' . $count . ']" value="" size="40" /><br />';
+           $return .= '<input type="text" name="s_editorfontlist[k' . ($count + 1) . ']" value="" size="20" />';
+               $return .= '&nbsp;&nbsp;';
+        $return .= '<input type="text" name="s_editorfontlist[v' . ($count + 1) . ']" value="" size="40" />';
+               $return .= '</td></tr><tr><td>&nbsp;</td><td align="left">' . $this->description . '</td></tr>';        
+        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);
+       }
+
+    // function borrowed from the old moodle/admin/editor.php, slightly modified
+    function editor_get_dictionaries () {
+    /// Get all installed dictionaries in the system
+
+        global $CFG;
+    
+//        error_reporting(E_ALL); // for debug, final version shouldn't have this...
+        clearstatcache();
+
+        // If aspellpath isn't set don't even bother ;-)
+        if (empty($CFG->aspellpath)) {
+            return 'Empty aspell path!';
+        }
+
+        // Do we have access to popen function?
+        if (!function_exists('popen')) {
+            return 'Popen function disabled!';
+        }
+    
+        $cmd          = $CFG->aspellpath;
+        $output       = '';
+        $dictionaries = array();
+        $dicts        = array();
+
+        if(!($handle = @popen(escapeshellarg($cmd) .' dump dicts', 'r'))) {
+            return 'Couldn\'t create handle!';
+        }
+
+        while(!feof($handle)) {
+            $output .= fread($handle, 1024);
+        }
+        @pclose($handle);
+
+        $dictionaries = explode(chr(10), $output);
+
+        // Get rid of possible empty values
+        if (is_array($dictionaries)) {
+
+            $cnt = count($dictionaries);
+
+            for ($i = 0; $i < $cnt; $i++) {
+                if (!empty($dictionaries[$i])) {
+                    $dicts[] = $dictionaries[$i];
+                }
+            }
+        }
+
+        if (count($dicts) >= 1) {
+            return $dicts;
+        }
+
+        return 'Error! Check your aspell installation!';
+    }
+
+    
+
+}
+
+
+class admin_setting_special_editorhidebuttons extends admin_setting {
+
+    var $name;
+       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');
+        // 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');
+       }
+
+    function get_setting() {
+           global $CFG;
+           $temp = $this->name;
+           return explode(' ', $CFG->$temp);
+       }
+
+    function write_setting($data) {
+           $result = array();
+               if (empty($data)) { $data = array(); }
+        foreach ($data as $key => $value) {
+                   if (!in_array($key, array_keys($this->items))) {
+                       return 'Error setting ' . $this->visiblename . '<br />';
+                       }
+                       if ($value == '1') {
+                           $result[] = $key;
+                       }
+               }
+               return (set_config($this->name, implode(' ',$result)) ? '' : 'Error setting ' . $this->visiblename . '<br />');
+       }
+
+    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 = '<tr><td width="100" align="right" valign="top">' . $this->visiblename . '</td><td align="left">';
+               
+               $return .= '<table><tr><td valign="top" align="right">';
+               
+               $count = 0;
+               
+               foreach($this->items as $key => $value) {
+                   if ($count % 15 == 0) {
+                           $return .= '</div></td><td valign="top" align="right">';
+                       }
+                       
+                       $return .= ($value == '' ? get_string($key,'editor') : '<img width="18" height="18" src="' . $CFG->wwwroot . '/lib/editor/htmlarea/images/' . $value . '" alt="' . get_string($key,'editor') . '" title="' . get_string($key,'editor') . '" />') . '&nbsp;';
+                       $return .= '<input type="checkbox" value="1" name="s_' . $this->name . '[' . $key . ']"' . (in_array($key,$currentsetting) ? ' checked="checked"' : '') . ' />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
+                       $count++;
+                       if ($count % 15 != 0) {
+                           $return .= '<br /><br />';
+                       }
+               }
+               
+               $return .= '</td></tr>';        
+               $return .= '</table>';
+               $return .= '</td></tr><tr><td>&nbsp;</td><td align="left">' . $this->description . '</td></tr>';
+
+           return $return;
+       }
+
+}
+
+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) {
+         // check that what we got was in the original choices
+                if (! in_array($data, array_keys($this->choices))) {
+                    return 'Error setting ' . $this->visiblename . '<br />';
+            }
+                
+                return (backup_set_config($this->name, $data) ? '' : 'Error setting ' . $this->visiblename . '<br />');
+    }
+
+}
+
+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);
+       }
+       
+       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) {
+        $data = clean_param($data, PARAM_PATH);
+       if (!empty($data) and (substr($data,-1) == '/' or substr($data,-1) == '\\')) {
+            return get_string('pathslasherror') . '<br />';
+        } else if (!empty($data) and !is_dir($data)) {
+                   return get_string('pathnotexists') . '<br />';
+        }
+               return (backup_set_config($this->name, $data) ? '' : 'Error setting ' . $this->visiblename . '<br />');
+       }
+
+}
+
+class admin_setting_backupcheckbox extends admin_setting_configcheckbox {
+
+    function write_setting($data) {
+           if ($data == '1') {
+                   return (backup_set_config($this->name, 1) ? '' : 'Error setting ' . $this->visiblename . '<br />');
+               } else {
+                   return (backup_set_config($this->name, 0) ? '' : 'Error setting ' . $this->visiblename . '<br />');
+               }
+       }
+       
+       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
+       }
+
+}
+
+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');
+        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) {
+         // 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 'Error setting ' . $this->visiblename . '<br />';
+            }
+                
+                return (backup_set_config($this->name, $data['h']) && backup_set_config($this->name2, $data['m']) ? '' : 'Error setting ' . $this->visiblename . '<br />');    
+       }
+       
+}
+
+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() {
+           
+        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>' . 
+               '</tr></table>' .                                                                                               
+        '</td></tr><tr><td>&nbsp;</td><td align="left">' . $this->description . '</td></tr>';
+       
+       }
+       
+       // 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)) ? '' : 'Error setting ' . $this->visiblename . '<br />');
+       }
+}
+
+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) ? '' : 'Error setting ' . $this->visiblename . '<br />');
+               } else {
+           return (set_config($this->name,7) ? '' : 'Error setting ' . $this->visiblename . '<br />');
+               }
+       }
+
+    function output_html() {
+        return '<tr><td width="100" align="right" valign="top">' . $this->visiblename . '</td>' .
+            '<td align="left"><input type="checkbox" size="50" name="s_'. $this->name .'" value="1" ' . ($this->get_setting() == 15 ? 'checked="checked"' : '') . ' /></td></tr>' .
+            '<tr><td>&nbsp;</td><td align="left">' . $this->description . '</td></tr>';
+    }
+
+}
+
+
+class admin_setting_special_calendar_weekend extends admin_setting {
+
+    function admin_setting_special_calendar_weekend() {
+        $name = 'calendar_weekend';
+        $visiblename = get_string('calendar_weekend', 'admin');
+        $description = get_string('helpweekenddays', 'admin');
+        parent::admin_setting($name, $visiblename, $description);
+    }
+
+    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);
+    }
+    
+       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))) ? '' : 'Error setting ' . $this->visiblename . '<br />');
+       }
+    
+       function output_html() {
+
+        $result = $this->get_setting();
+           
+        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>' . 
+               '</tr></table>' .                                                                                               
+        '</td></tr><tr><td>&nbsp;</td><td align="left">' . $this->description . '</td></tr>';
+       
+       }
+
+}
+
+
+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) ? '' : 'Error setting ' . $this->visiblename . '<br />');
+               } else {
+           return (set_config($this->name,7) ? '' : 'Error setting ' . $this->visiblename . '<br />');
+               }
+       }
+
+    function output_html() {
+        return '<tr><td width="100" align="right" valign="top">' . $this->visiblename . '</td>' .
+            '<td align="left"><input type="checkbox" size="50" name="s_'. $this->name .'" value="1" ' . ($this->get_setting() == 15 ? 'checked="checked"' : '') . ' /></td></tr>' .
+            '<tr><td>&nbsp;</td><td align="left">' . $this->description . '</td></tr>';
+    }
+
+}
+
+// Code for a function that helps externalpages print proper headers and footers
+// N.B.: THIS FUNCTION HANDLES AUTHENTICATION
+function admin_externalpage_setup($section) {
+
+    global $CFG, $ADMIN, $PAGE, $_GET, $root;
+    
+    require_once($CFG->libdir . '/blocklib.php');
+    require_once($CFG->dirroot . '/admin/pagelib.php');
+    
+    // we really shouldn't do this... but it works. and it's so elegantly simple.
+    // oh well :)
+    $_GET['section'] = $section;
+    
+    define('TEMPORARY_ADMIN_PAGE_ID',26);
+
+    define('BLOCK_L_MIN_WIDTH',160);
+    define('BLOCK_L_MAX_WIDTH',210);
+
+    $pagetype = PAGE_ADMIN;                 // erm... someone should check this. does
+    $pageclass = 'page_admin';              // any of it duplicate the code I have in 
+    page_map_class($pagetype, $pageclass);  // admin/pagelib.php?
+
+    $PAGE = page_create_object($pagetype,TEMPORARY_ADMIN_PAGE_ID);
+
+    $PAGE->init_full();
+
+    $root = $ADMIN->locate($PAGE->section);
+
+    if ($site = get_site()) {
+        require_login();
+    } else {
+        redirect($CFG->wwwroot . '/admin/index.php');
+        die;
+    }
+
+    if (!($root instanceof admin_externalpage)) {
+        error('Section does not exist, is invalid, or should not be accessed via this URL.');
+       die;
+    }
+
+    // this eliminates our need to authenticate on the actual pages
+    if (!($root->check_access())) {
+        error('Access denied.');
+       die;
+    }
+    
+}
+
+function admin_externalpage_print_header() {
+
+    global $CFG, $ADMIN, $PAGE, $_GET, $root;
+    
+    $pageblocks = blocks_setup($PAGE);
+
+    $preferred_width_left = bounded_number(BLOCK_L_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]), BLOCK_L_MAX_WIDTH);
+
+    $PAGE->print_header();
+    echo '<table id="layout-table"><tr>';
+    echo '<td style="width: ' . $preferred_width_left . 'px;" id="left-column">';
+    blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
+    echo '</td>';
+    echo '<td id="middle-column" width="*">';
+
+}
+
+function admin_externalpage_print_footer() {
+
+    echo '</td></tr></table>';
+    print_footer();
+    
+}
+
+
+
+// Code to build admin-tree ----------------------------------------------------------------------------
+
+// hrm... gotta put this somewhere more systematic
+$site = get_site();
+
+// start the admin tree!
+$ADMIN = new admin_category('root','Administration');
+
+// we process this file first to get categories up and running
+include_once($CFG->dirroot . '/admin/settings/first.php');
+
+// now we process all other files in admin/settings to build the
+// admin tree
+foreach (glob($CFG->dirroot . '/admin/settings/*.php') as $file) {
+    if ($file != $CFG->dirroot . '/admin/settings/first.php') {
+        include_once($file);
+    }
+}
+
+?>
\ No newline at end of file
index 80af18c75efe57d579d059b860b9592af8dfb7df..9362c7bae42577b00fffb779b1aadf7345cb25bc 100644 (file)
@@ -3,21 +3,12 @@
 
     require_once('../config.php');
 
-    $auth = optional_param('auth', '', PARAM_SAFEDIR);
+    require_once($CFG->dirroot . '/admin/adminlib.php');
 
-    require_login();
+    admin_externalpage_setup('userauthentication');
 
-    if (!$site = get_site()) {
-        redirect("index.php");
-    }
+    $auth = optional_param('auth', '', PARAM_SAFEDIR);
 
-    if (!isadmin()) {
-        error("Only the admin can use this page");
-    }
-
-    if (!confirm_sesskey()) {
-        error(get_string('confirmsesskeybad', 'error'));
-    }
 
     $focus = '';
 
 
     if ($config = data_submitted()) {
 
+        if (!confirm_sesskey()) {
+            error(get_string('confirmsesskeybad', 'error'));
+        }
+
         $config = (array)$config;
 
         // extract and sanitize the auth key explicitly
     $strsettings = get_string("settings");
     $strusers = get_string("users");
 
-    print_header("$site->shortname: $strauthenticationoptions", "$site->fullname",
-                  "<a href=\"index.php\">$stradministration</a> -> <a href=\"users.php\">$strusers</a> -> $strauthenticationoptions", "$focus");
+    admin_externalpage_print_header();
 
     echo "<center><b>";
     echo "<form target=\"{$CFG->framename}\" name=\"authmenu\" method=\"post\" action=\"auth.php\">";
     echo "<input type=\"hidden\" name=\"sesskey\" value=\"".$USER->sesskey."\" />";
     print_string("chooseauthmethod","auth");
+    
+    echo '&nbsp;&nbsp;';
 
     choose_from_menu ($options, "auth", $auth, "","document.location='auth.php?sesskey=$USER->sesskey&auth='+document.authmenu.auth.options[document.authmenu.auth.selectedIndex].value", "");
 
-    echo "</b></center>";
+    echo "</b></center><br />";
 
     print_simple_box_start("center", "100%");
     print_heading($options[$auth]);
 
     print_simple_box_end();
 
-    print_footer();
+    admin_externalpage_print_footer();
     exit;
 
 /// Functions /////////////////////////////////////////////////////////////////
index 522da78fb9591e36ed24afc8b1bf491b3df74f03..8ea52e08344a09fef2e5e953042134f0c122b683 100644 (file)
@@ -3,17 +3,10 @@
 // block.php - allows admin to edit all local configuration variables for a block
 
     require_once('../config.php');
+    require_once($CFG->dirroot . '/admin/adminlib.php');
+    admin_externalpage_setup('blockmanagement');
     require_once($CFG->libdir.'/blocklib.php');
 
-    require_login();
-
-    if (!isadmin()) {
-        error('Only an admin can use this page');
-    }
-    if (!$site = get_site()) {
-        error("Site isn't defined!");
-    }
-
     $blockid = required_param('block', PARAM_INT);
    
     if(($blockrecord = blocks_get_record($blockid)) === false) {
     // of the page. It is also used to generate the link to the Moodle Docs for this view.
     $CFG->pagepath = 'block/' . $block->name() . '/config';
     
-    print_header($site->shortname.': '.$strblockname.": $strconfiguration", $site->fullname,
-                  "<a href=\"index.php\">$stradmin</a> -> ".
-                  "<a href=\"configure.php\">$strconfiguration</a> -> ".
-                  "<a href=\"blocks.php\">$strmanageblocks</a> -> ".$strblockname);
+
+    admin_externalpage_print_header();
 
     print_heading($strblockname);
 
@@ -80,6 +71,6 @@
     echo '</p>';
     $block->config_print();
     echo '</form>';
-    print_footer();
+    admin_externalpage_print_footer();
 
 ?>
index 895fb111d2c5ab61218587d6840da35fbaa40a8c..f6e4ebfb3b919a7239d21200f763e5b2f4aa30d9 100644 (file)
@@ -3,6 +3,8 @@
     // Allows the admin to configure blocks (hide/show, delete and configure)
 
     require_once('../config.php');
+    require_once($CFG->dirroot . '/admin/adminlib.php');
+    admin_externalpage_setup('blockmanagement');
     require_once($CFG->libdir.'/blocklib.php');
     require_once($CFG->libdir.'/tablelib.php');
 
     $delete   = optional_param('delete', 0, PARAM_INT);
     $multiple = optional_param('multiple', 0, PARAM_INT);
 
-    require_login();
-
-    if (!isadmin()) {
-        error("Only administrators can use this page!");
-    }
-
-    if (!$site = get_site()) {
-        error("Site isn't defined!");
-    }
-
 
 /// Print headings
 
@@ -37,9 +29,7 @@
     $strname = get_string('name');
     $strmultiple = get_string('blockmultiple', 'admin');
 
-    print_header("$site->shortname: $strmanageblocks", "$site->fullname",
-                 "<a href=\"index.php\">$stradministration</a> -> ".
-                 "<a href=\"configure.php\">$strconfiguration</a> -> $strmanageblocks");
+    admin_externalpage_print_header();
 
     print_heading($strmanageblocks);
 
@@ -85,7 +75,7 @@
             notice_yesno(get_string('blockdeleteconfirm', '', $strblockname),
                          'blocks.php?delete='.$block->id.'&amp;confirm=1&amp;sesskey='.$USER->sesskey,
                          'blocks.php');
-            print_footer();
+            admin_externalpage_print_footer();
             exit;
 
         } else {
         $table->print_html();
     }
 
-    print_footer();
+    admin_externalpage_print_footer();
 
 ?>
index 61c9ed3423e6cd8ea41fdf45bed0a16dfc926453..1661bb728105509aaebfc2e37a2485ebb5d3c4f3 100644 (file)
@@ -3,29 +3,23 @@
        //             Yes, enrol is correct English spelling.
 
     require_once('../config.php');
+    require_once($CFG->dirroot . '/admin/adminlib.php');
 
     $enrol = optional_param('enrol', $CFG->enrol, PARAM_SAFEDIR);
     $CFG->pagepath = 'enrol';
     
-    require_login();
+    admin_externalpage_setup('enrolment');
 
-    if (!$site = get_site()) {
-        redirect("index.php");
-    }
-
-    if (!isadmin()) {
-        error("Only the admin can use this page");
-    }
 
-    if (!confirm_sesskey()) {
-        error(get_string('confirmsesskeybad', 'error'));
-    }
 
     require_once("$CFG->dirroot/enrol/enrol.class.php");   /// Open the factory class
 
 /// Save settings
 
     if ($frm = data_submitted()) {
+        if (!confirm_sesskey()) {
+            error(get_string('confirmsesskeybad', 'error'));
+        }    
         if (empty($frm->enable)) {
             $frm->enable = array();
         }
         $frm->enable = array_merge(array('manual'), $frm->enable); // make sure manual plugin is called first
         set_config('enrol_plugins_enabled', implode(',', $frm->enable));
         set_config('enrol', $frm->default);
-        redirect("enrol.php?sesskey=$USER->sesskey", get_string("changessaved"), 1);
+        redirect("enrol.php", get_string("changessaved"), 1);
     }
 
 /// Print the form
 
     $str = get_strings(array('enrolmentplugins', 'users', 'administration', 'settings', 'edit'));
 
-    print_header("$site->shortname: $str->enrolmentplugins", "$site->fullname",
-                  "<a href=\"index.php\">$str->administration</a> -> 
-                   <a href=\"users.php\">$str->users</a> -> $str->enrolmentplugins");
+    admin_externalpage_print_header();
 
     $modules = get_list_of_plugins("enrol");
     $options = array();
@@ -97,7 +89,7 @@
             $default = '';
         }
         $table->data[$name] = array($name, $enable, $default,
-                                '<a href="enrol_config.php?sesskey='.$USER->sesskey.'&amp;enrol='.$module.'">'.$str->edit.'</a>');
+                                '<a href="enrol_config.php?enrol='.$module.'">'.$str->edit.'</a>');
     }
     asort($table->data);
 
     echo "<center><input type=\"submit\" value=\"".get_string("savechanges")."\"></center>\n";
     echo "</form>";
 
-    print_footer();
+    admin_externalpage_print_footer();
 
 ?>
\ No newline at end of file
index f78a915e5760b44d5e6bbc1dc203177cebb5956a..1bbc993910c45a95e8294e9166660c5868dd4fc8 100644 (file)
@@ -3,23 +3,13 @@
        //                    Yes, enrol is correct English spelling.
 
     require_once("../config.php");
+    require_once($CFG->dirroot . '/admin/adminlib.php');
+    
+    admin_externalpage_setup('enrolment');
 
     $enrol = required_param('enrol', PARAM_ALPHA);
     $CFG->pagepath = 'enrol/' . $enrol;
-    
-    require_login();
-
-    if (!$site = get_site()) {
-        redirect("index.php");
-    }
 
-    if (!isadmin()) {
-        error("Only the admin can use this page");
-    }
-
-    if (!confirm_sesskey()) {
-        error(get_string('confirmsesskeybad', 'error'));
-    }
 
     require_once("$CFG->dirroot/enrol/enrol.class.php");   /// Open the factory class
 
@@ -28,6 +18,9 @@
 /// If data submitted, then process and store.
 
     if ($frm = data_submitted()) {
+        if (!confirm_sesskey()) {
+            error(get_string('confirmsesskeybad', 'error'));
+        }    
         if ($enrolment->process_config($frm)) {
             redirect("enrol.php?sesskey=$USER->sesskey", get_string("changessaved"), 1);
         }
@@ -40,6 +33,7 @@
     /// get language strings
     $str = get_strings(array('enrolmentplugins', 'configuration', 'users', 'administration'));
 
+    unset($options);
 
     $modules = get_list_of_plugins("enrol");
     foreach ($modules as $module) {
     }
     asort($options);
 
-    print_header("$site->shortname: $str->enrolmentplugins", "$site->fullname",
-                  "<a href=\"index.php\">$str->administration</a> -> 
-                   <a href=\"users.php\">$str->users</a> -> 
-                   <a href=\"enrol.php?sesskey=$USER->sesskey\">$str->enrolmentplugins</a> -> 
-                   $str->configuration");
+    admin_externalpage_print_header();
 
     echo "<form target=\"{$CFG->framename}\" name=\"enrolmenu\" method=\"post\" action=\"enrol_config.php\">";
     echo "<input type=\"hidden\" name=\"sesskey\" value=\"".$USER->sesskey."\">";
@@ -61,7 +51,7 @@
 /// Choose an enrolment method
     echo get_string('chooseenrolmethod').': ';
     choose_from_menu ($options, "enrol", $enrol, "",
-                      "document.location='enrol_config.php?sesskey=$USER->sesskey&enrol='+document.enrolmenu.enrol.options[document.enrolmenu.enrol.selectedIndex].value", "");
+                      "document.location='enrol_config.php?enrol='+document.enrolmenu.enrol.options[document.enrolmenu.enrol.selectedIndex].value", "");
 
     echo "</b></p></div>";
     
@@ -82,7 +72,7 @@
 
     print_simple_box_end();
 
-    print_footer();
+    admin_externalpage_print_footer();
 
     exit;
 ?>
index 8b59eb8981d5a9923d705e89dd51e74f34afe905..175ca0f3fe9104b0ab8c10d8d38f72e4dab8798a 100644 (file)
 // from moodle.org be able to check more and more versions.
 
     require_once('../config.php');
+    require_once($CFG->dirroot . '/admin/adminlib.php');
     require_once($CFG->libdir.'/environmentlib.php');
     require_once($CFG->libdir.'/componentlib.class.php');
 
+    admin_externalpage_setup('environment');
 
 /// Parameters
     $action  = optional_param('action', '', PARAM_ACTION);
     $version = optional_param('version', '', PARAM_FILE); //
 
-/// Security checks
-    require_login();
-
-    if (!isadmin()) {
-        error('You need to be admin to use this page');
-    }
-
-    if (!$site = get_site()) {
-        error("Site isn't defined!");
-    }
 
 /// Get some strings
     $stradmin = get_string('administration');
@@ -60,9 +52,7 @@
     $strmisc = get_string('miscellaneous');
 
 /// Print the header stuff
-    print_header("$SITE->shortname: $strenvironment", $SITE->fullname,
-                 "<a href=\"index.php\">$stradmin</a> -> <a href=\"misc.php\">$strmisc</a> -> "
-                 .$strenvironment);
+    admin_externalpage_print_header();
 
 /// Print the component download link
     echo '<div class="reportlink"><a href="environment.php?action=updatecomponent&amp;sesskey='.$USER->sesskey.'">'.$strupdate.'</a></div>';
     echo '</div>';
 
 /// Print footer
-    print_footer();
+    admin_externalpage_print_footer();
 ?>
index 4b571fb6ed8efe764d9e3b2475aa0c6b8056160e..56b7d1cb8b684b04d3675aebf5edd9bdcc0cd4ed 100644 (file)
@@ -3,16 +3,10 @@
     // Edit text filter settings
 
     require_once('../config.php');
+    require_once($CFG->dirroot . '/admin/adminlib.php');
     require_once($CFG->libdir.'/tablelib.php');
 
-    // check for allowed access
-    require_login();
-    if (!isadmin()) {
-        error( 'Only administrators can use the filters administration page' );
-    }
-    if (!$site = get_site()) {
-        error( 'Site is not defined in filters administration page' );
-    }
+    admin_externalpage_setup('filtermanagement');
 
     // get parameters
     $param = new Object;
     //==============================
     
     $filtername = ucfirst($filtername);
-    print_header( "$site->shortname: $txt->managefilters", "$site->fullname",
-        "<a href=\"index.php\">$txt->administration</a> -> <a href=\"configure.php\">$txt->configuration</a> " .
-        "-> <a href=\"filters.php\">$txt->managefilters</a> -> $filtername" );
-
-    print_heading( $txt->managefilters );
+    admin_externalpage_print_header();
+    print_heading( $filtername );
 
     print_simple_box("<center>".get_string("configwarning", "admin")."</center>", "center", "50%");
     echo "<br />";
 
     print_simple_box_end();
 
-    print_footer();
+    admin_externalpage_print_footer();
 ?>
index 8fde4e0c3d04e0a7d67fb2df991418813a44cd99..5490e84d177b4228b0c4fbe6ffe3d634c4abd016 100644 (file)
@@ -3,20 +3,13 @@
     // Edit list of available text filters
 
     require_once('../config.php');
+    require_once($CFG->dirroot . '/admin/adminlib.php');
     require_once($CFG->libdir.'/tablelib.php');
 
     // defines
     define('FILTER_TABLE','filter_administration_table');
 
-    // check for allowed access
-    require_login();
-
-    if (!isadmin()) {
-        error('Only administrators can use the filters administration page');
-    }
-    if (!$site = get_site()) {
-        error('Site is not defined in filters administration page');
-    }
+    admin_externalpage_setup('filtermanagement');
 
     // get values from page
     $params = new object();
     // Display logic
     //==============================
 
-    print_header("$site->shortname: $txt->managefilters", "$site->fullname",
-        "<a href=\"index.php\">$txt->administration</a> -> <a href=\"configure.php\">$txt->configuration</a> " .
-        "-> $txt->managefilters");
+    admin_externalpage_print_header();
 
     print_heading_with_help($txt->managefilters, 'filters');
 
     // print the table of all the filters
     $table->print_html();
 
-    // print the table for the cache controls
-    print_heading($txt->cachecontrols);
-    print_simple_box_start('center');
-    ?>
-
-    <form name="options" id="options" method="post" action="<?php echo $url; ?>" >
-        <input type="hidden" name="sesskey" value="<?php echo sesskey(); ?>" />
-        <input type="hidden" name="action" value="config" />
-        <table cellpadding="20">
-            <tr valign="top">
-                <td nowrap="nowrap" align="right"><?php echo $txt->cachetext; ?></td>
-                <td><?php choose_from_menu($options, "cachetext", $CFG->cachetext, "", "", ""); ?></td>
-                <td><?php echo $txt->configcachetext; ?></td>
-            </tr>
-            <tr valign="top">
-                <td nowrap="nowrap" align="right"><?php echo $txt->filteruploadedfiles; ?></td>
-                <td><?php choose_from_menu(array($txt->none,$txt->allfiles,$txt->htmlfilesonly),
-                    "filteruploadedfiles", $CFG->filteruploadedfiles,"","",""); ?></td>
-                <td><?php echo $txt->configfilteruploadedfiles; ?></td>
-            </tr>
-            <tr valign="top">
-                <td nowrap="nowrap" align="right"><?php echo $txt->filtermatchoneperpage; ?></td>
-                <td><?php choose_from_menu(array($txt->no,$txt->yes), "filtermatchoneperpage", $CFG->filtermatchoneperpage,"","",""); ?></td>
-                <td><?php echo $txt->configfiltermatchoneperpage; ?></td>
-        <tr valign="top">
-        <td nowrap="nowrap" align="right"><?php echo $txt->filtermatchonepertext; ?></td>
-        <td><?php choose_from_menu(array($txt->no,$txt->yes), "filtermatchonepertext", $CFG->filtermatchonepertext,"","",""); ?></td>
-        <td><?php echo $txt->configfiltermatchonepertext; ?></td>
-        </tr>
-            </tr>
-            <tr valign="top">
-                <td nowrap="nowrap" align="right"><?php echo $txt->filterall; ?></td>
-                <td><?php choose_from_menu(array($txt->no,$txt->yes), "filterall", $CFG->filterall,"","",""); ?></td>
-                <td><?php echo $txt->configfilterall; ?></td>
-            </tr>
-            <tr valign="top">
-                <td>&nbsp;</td>
-                <td><input type="submit" value="<?php print_string('savechanges'); ?>" /></td>
-                <td>&nbsp;</td>
-            </tr>
-        </table>
-    </form>
-
-    <?php
-    print_simple_box_end();
+    // cache control table has been removed
 
-    print_footer();
+    admin_externalpage_print_footer();
 
 ?>
index b5f0a4ae906e550fa67f8ab0b60aad281a5b47bf..c1712e11195d5b48938fb54bcb66df75ea0da385 100644 (file)
 
 /// At this point everything is set up and the user is an admin, so print menu
 
-    $stradministration = get_string("administration");
-    print_header("$site->shortname: $stradministration","$site->fullname", "$stradministration");
-    print_simple_box_start('center', '100%', '', 20);
-    print_heading($stradministration);
-
+#    $stradministration = get_string("administration");
+#    print_header("$site->shortname: $stradministration","$site->fullname", "$stradministration");
+#    print_simple_box_start('center', '100%', '', 20);
+#    print_heading($stradministration);
+
+    require_once($CFG->dirroot . '/admin/adminlib.php');
+    admin_externalpage_setup('adminnotifications');
+    admin_externalpage_print_header();
+    echo 'Umm... any notifications should show up here... I hope :)<br /><br />';
+    echo 'Also, I\'m including the old admin menu on this page incase I forgot any links in the new admin structure. It should be removed after. <br /><br />';
 /// Deprecated database! Warning!!
     if (!empty($CFG->migrated_to_new_db)) {
         print_simple_box_start('center','60%');
         print_simple_box_end();
     }
 
+// keeping this old menu here for a little while /*
     $table->tablealign = "center";
     $table->align = array ("right", "left");
     $table->wrap = array ("nowrap", "nowrap");
 
     $table->data[] = array('<strong><a href="configure.php">'.get_string('configuration').'</a></strong>', $configdata);
 
-
     $userdata =  '<div class="adminlink"><a href="auth.php?sesskey='.$USER->sesskey.'">'.get_string("authentication").
                  '</a> - <span class="explanation">'.get_string('adminhelpauthentication').'</span></div>';
     $userdata .= '<div class="adminlink"><a href="user.php">'.get_string('edituser').
 
 
     $table->data[] = array('<strong><a href="courses.php">'.get_string('courses').'</a></strong>', $coursedata);
-    
+  
     $miscdata = '<div class="adminlink"><a href="../files/index.php?id='.$site->id.'">'.get_string('sitefiles').
                  '</a> - <span class="explanation">'.get_string('adminhelpsitefiles').'</span></div>';
     $miscdata .= '<div class="adminlink"><a href="stickyblocks.php">'.get_string('stickyblocks','admin').
 /// The eventual official versions may not look like this
     if (isset($CFG->portfolio) && file_exists("$CFG->dirroot/$CFG->portfolio")) {
                 $table->data[] = array("<strong><a href=\"../portfolio/\">".get_string('portfolio','portfolio').'</a></
-trong>',
+strong>',
                             '<div class="explanation">'.get_string('adminhelpportfolio','portfolio').'</div>');
     }
 
     if (isset($CFG->repo) && file_exists("$CFG->dirroot/$CFG->repo")) {
             $table->data[] = array("<strong><a href=\"../repository/?repoid=1&action=list\">".get_string('repository','
-epository').'</a></strong>',
+repository').'</a></strong>',
                             '<div class="explanation">'.get_string('adminhelprepository','repository').'</div>');
     }
 
@@ -505,6 +510,8 @@ epository').'</a></strong>',
 
     print_table($table);
 
+// old stuff ends here  */
+
     //////////////////////////////////////////////////////////////////////////////////////////////////
     ////  IT IS ILLEGAL AND A VIOLATION OF THE GPL TO REMOVE OR MODIFY THE COPYRIGHT NOTICE BELOW ////
     $copyrighttext = '<a href="http://moodle.org/">Moodle</a> '.
@@ -533,6 +540,6 @@ epository').'</a></strong>',
     }
 
 
-    print_footer($site);
+    admin_externalpage_print_footer();
 
 ?>
index aeb1e786e10f4492ddfad0e23868cf98c41172cb..cc418e2e6d5095c1ff54e029d40f7f240d56e075 100644 (file)
@@ -33,6 +33,8 @@
     */
 
     require_once('../config.php');
+    require_once($CFG->dirroot . '/admin/adminlib.php');
+    admin_externalpage_setup('langedit');    
 
     define('LANG_SUBMIT_REPEAT', 1);            // repeat displaying submit button?
     define('LANG_SUBMIT_REPEAT_EVERY', 20);     // if so, after how many lines?
         $SESSION->langtranslateintolocal = $uselocal;
     }
 
-    require_login();
-
-    if (!isadmin()) {
-        error("You need to be admin to edit this page");
-    }     
-
-    if (! $site = get_site()) {
-        error("Site not defined!");
-    }
-
     $stradministration = get_string("administration");
     $strconfiguration = get_string("configuration");
     $strlanguage = get_string("language");
     }
 
 
-    print_header("$site->shortname: $title", "$site->fullname",
-                 "<a href=\"index.php\">$stradministration</a> -> ".
-                 "<a href=\"configure.php\">$strconfiguration</a> -> $navigation",
-                 '', '', true, $button);
+    admin_externalpage_print_header();
 
     if (!$mode) {
         print_simple_box_start('center','80%');
-        echo '<table summary="" align="center" width="100%"><tr><td width="50%" align="center">';
-        print_string('managelang','admin');
-        echo '</td><td align="center" width="50%">';
+        echo '<div align="center">';
         print_string('editlang','admin');
-        echo '</td></tr><tr><td>';
-        print_string('lang16notify','admin');
-        echo '<p /><a href="langimport.php">'.get_string('langimport','admin').'</a>';
-        echo '</td><td>';
+        echo '<br />';
         $currlang = current_language();
         $langs = get_list_of_languages();
-        echo "<table summary=\"\" align=\"center\"><tr><td align=\"right\">";
         echo "<b>$strcurrentlanguage:</b>";
-        echo "</td><td>";
+        echo '<br />';
         echo popup_form ("$CFG->wwwroot/$CFG->admin/lang.php?lang=", $langs, "chooselang", $currlang, "", "", "", true);
-        echo '</td></tr><tr><td colspan="2">';
         $options["lang"] = $currentlang;
-        //print_single_button("http://moodle.org/download/lang/", $options, get_string("latestlanguagepack"));
-        echo "</td></tr></table>";
         print_heading("<a href=\"lang.php?mode=missing\">$strmissingstrings</a>");
         print_heading("<a href=\"lang.php?mode=compare\">$streditstrings</a>");
         print_heading("<a href=\"langdoc.php\">$stredithelpdocs</a>");
-        echo '</td></tr></table>';
+        echo '</div>';
         print_simple_box_end();
-        print_footer();
+        admin_externalpage_print_footer();
         exit;
     }
 
         }
     }
 
-    print_footer();
+    admin_externalpage_print_footer();
 
 //////////////////////////////////////////////////////////////////////
 
index 7530a9822af77b5f68ed7cda82805542a6fb425d..920a73534bf95217f2ba9c3745144520d039ea46 100755 (executable)
@@ -10,6 +10,8 @@
  *             for intensive testing of this my first contribution
  */
     require_once('../config.php');
+    require_once($CFG->dirroot . '/admin/adminlib.php');
+    admin_externalpage_setup('langedit');
 
     //
     // Some local configuration
 
     $currentfile = optional_param('currentfile', 'docs/README.txt', PARAM_PATH); 
 
-    require_login();
-
-    if (!isadmin()) {
-        error("You need to be admin to edit this page");
-    }     
-
-    if (! $site = get_site()) {
-        error("Site not defined!");
-    }
-
     $stradministration = get_string("administration");
     $strconfiguration = get_string("configuration");
     $strlanguage = get_string("language");
     $strthislanguage = get_string("thislanguage");
     $stredithelpdocs = get_string('edithelpdocs', 'admin');
 
-    print_header("$site->shortname: $stredithelpdocs: $currentfile", "$site->fullname",
-                 "<a href=\"index.php\">$stradministration</a> -> ".
-                 "<a href=\"configure.php\">$strconfiguration</a> -> 
-                  <a href=\"lang.php\">$strlanguage</a> -> $stredithelpdocs",
-                 'choosefile.popup', '', true);
+    admin_externalpage_print_header();
 
     $currentlang = current_language();
     $langdir = "$CFG->dataroot/lang/$currentlang";
@@ -207,7 +195,7 @@ $langdir/$currentfile")."</font></p>";
         error_reporting($CFG->debug);
     }
 
-    print_footer();
+    admin_externalpage_print_footer();
 
 //////////////////////////////////////////////////////////////////////
 
index 4ff88921939a4eee2cfeed9b3d17fc5eb736bf60..b019a6072ba40ac51d4507b5cbebdd42947f64ea 100755 (executable)
@@ -5,6 +5,8 @@
 ///This helps to avoid confusion.
 
     require_once('../config.php');
+    require_once($CFG->dirroot . '/admin/adminlib.php');
+    admin_externalpage_setup('langimport');
 
     $mode          = optional_param('mode', 0, PARAM_INT);     //phase
     $pack          = optional_param('pack', '', PARAM_FILE);   //pack to install
     define('CHANGE_SITE_LANG', 3);
     define('DELETION_OF_SELECTED_LANG', 4);
     define('UPDATE_ALL_LANG', 5);
-
-    require_login();
-
-    if (!isadmin()) {
-        error('You must be an admin');
-    }
-    
-    if (!$site = get_site()) {
-        error("Site not defined!");
-    }
     
     $strlang = get_string('langimport','admin');
     
     $strlanguage = get_string("language");
     $strthislanguage = get_string("thislanguage");
     $title = $strlang;
+        
+    admin_externalpage_print_header();
     
-    print_header("$site->shortname: $title", "$site->fullname",
-                 "<a href=\"index.php\">$stradministration</a> -> ".
-                 "<a href=\"configure.php\">$strconfiguration</a> -> ".
-                 "<a href=\"lang.php\">$strlanguage</a> -> $strlang",
-                 '', '', true, '');
-    
-    print_heading('');
 
     switch ($mode){
     
             echo '<p />';
             
             /// Display option to change site language
+ /// Erm... this doesn't seem to work. Plus it's redundant. -vinkmar
             
-            print_string('changesitelang','admin');
-            $sitelanguage = get_record('config','name','lang');
-            echo '<form name="changelangform" action="langimport.php?mode=3" method="POST">';
-            echo '<select name="sitelangconfig">';
-            
-            foreach ($installedlangs as $clang =>$ilang) {
-                if ($clang == $sitelanguage->value){
-                    echo '<option value="'.$clang.'" selected="selected">'.$ilang.'</option>';
-                } else {
-                    echo '<option value="'.$clang.'">'.$ilang.'</option>';
-                }
-            }
-            echo '</select>';
-            echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
-            echo '<input type="submit" value="'.get_string('change','admin').'" />';
-            echo '</form>';
+//            print_string('changesitelang','admin');
+//            $sitelanguage = get_record('config','name','lang');
+//            echo '<form name="changelangform" action="langimport.php?mode=3" method="POST">';
+//            echo '<select name="sitelangconfig">';
+//            
+//            foreach ($installedlangs as $clang =>$ilang) {
+//                if ($clang == $sitelanguage->value){
+//                    echo '<option value="'.$clang.'" selected="selected">'.$ilang.'</option>';
+//                } else {
+//                    echo '<option value="'.$clang.'">'.$ilang.'</option>';
+//                }
+//            }
+//            echo '</select>';
+//            echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
+//            echo '<input type="submit" value="'.get_string('change','admin').'" />';
+//            echo '</form>';
 
             /// display to be installed langs here
 
 
     }    //close of main switch
 
-    print_footer();
+    admin_externalpage_print_footer();
     
     /* returns a list of available language packs from a
      * local copy shipped with standard moodle distro
index 2be4eb1ea0d7e4dc52cab039c890cd4791bef2e2..da8e96764f85d2dad69ff76c479bb65a4f1d286a 100644 (file)
@@ -2,14 +2,11 @@
       // Enables/disables maintenance mode
 
     require('../config.php');
+    require_once($CFG->dirroot . '/admin/adminlib.php');
 
     $action = optional_param('action', '', PARAM_ALPHA);
 
-    require_login();
-
-    if (!isadmin()) {
-        error('You need to be admin to use this page');
-    }
+    admin_externalpage_setup('maintenancemode');
 
     //Check folder exists
     if (! make_upload_directory(SITEID)) {   // Site folder
         if (confirm_sesskey()) {
             if ($form->action == "disable") {
                 unlink($filename);
-                redirect('index.php', get_string('sitemaintenanceoff','admin'));
+                redirect('maintenance.php', get_string('sitemaintenanceoff','admin'));
             } else {
                 $file = fopen($filename, 'w');
                 fwrite($file, stripslashes($form->text));
                 fclose($file);
-                redirect('index.php', get_string('sitemaintenanceon', 'admin'));
+                redirect('maintenance.php', get_string('sitemaintenanceon', 'admin'));
             }
         }
     }
 
 /// Print the header stuff
 
-    $strmaintenance = get_string('sitemaintenancemode', 'admin');
-    $stradmin = get_string('administration');
-    $strconfiguration = get_string('configuration');
-
-    print_header("$SITE->shortname: $strmaintenance", $SITE->fullname,
-                  "<a href=\"index.php\">$stradmin</a> -> ".
-                  "<a href=\"configure.php\">$strconfiguration</a> -> $strmaintenance");
-
-    print_heading($strmaintenance);
+    admin_externalpage_print_header();
 
 /// Print the appropriate form
 
@@ -74,5 +63,5 @@
         }
     }
 
-    print_footer();
+    admin_externalpage_print_footer();
 ?>
index e1e8be547578e4ad8edf527f065046b45504b30b..b2e60b37c1da8d55846ec3eba1693822944dc5d6 100644 (file)
@@ -2,16 +2,8 @@
        // module.php - allows admin to edit all local configuration variables for a module
 
     require_once('../config.php');
-
-    require_login();
-
-    if (!isadmin()) {
-        error("Only an admin can use this page");
-    }
-
-    if (!$site = get_site()) {
-        error("Site isn't defined!");
-    }
+    require_once($CFG->dirroot . '/admin/adminlib.php');
+    admin_externalpage_setup('modulemanagement');
 
 /// If data submitted, then process and store.
 
     // of the page. It is also used to generate the link to the Moodle Docs for this view.
     $CFG->pagepath = 'mod/' . $module . '/config';
     
-    print_header("$site->shortname: $strmodulename: $strconfiguration", $site->fullname,
-                  "<a href=\"index.php\">$stradmin</a> -> ".
-                  "<a href=\"configure.php\">$strconfiguration</a> -> ".
-                  "<a href=\"modules.php\">$strmanagemodules</a> -> $strmodulename");
+    admin_externalpage_print_header();
 
     print_heading($strmodulename);
 
@@ -75,6 +64,6 @@
     include("$CFG->dirroot/mod/$module/config.html");
     print_simple_box_end();
 
-    print_footer();
+    admin_externalpage_print_footer();
 
 ?>
index 25d9492a0947aaa6bd4b8ee4d2ce9aac881ca802..3070028d423b9efb5c10d552fa7f55b1c6b9e18b 100644 (file)
@@ -2,6 +2,8 @@
       // Allows the admin to manage activity modules
 
     require_once('../config.php');
+    require_once($CFG->dirroot . '/admin/adminlib.php');
+    admin_externalpage_setup('modulemanagement');
     require_once('../course/lib.php');
 
     $show    = optional_param('show', '', PARAM_SAFEDIR);
@@ -9,16 +11,6 @@
     $delete  = optional_param('delete', '', PARAM_SAFEDIR);
     $confirm = optional_param('confirm', '', PARAM_BOOL);
 
-    require_login();
-
-    if (!isadmin()) {
-        error("Only administrators can use this page!");
-    }
-
-    if (!$site = get_site()) {
-        error("Site isn't defined!");
-    }
-
 
 /// Print headings
 
     $stractivities = get_string("activities");
     $stractivitymodule = get_string("activitymodule");
 
-    print_header("$site->shortname: $strmanagemodules", "$site->fullname", 
-                 "<a href=\"index.php\">$stradministration</a> -> ".
-                 "<a href=\"configure.php\">$strconfiguration</a> -> $strmanagemodules");
+//    print_header("$site->shortname: $strmanagemodules", "$site->fullname", 
+//                 "<a href=\"index.php\">$stradministration</a> -> ".
+//                 "<a href=\"configure.php\">$strconfiguration</a> -> $strmanagemodules");
+
+    admin_externalpage_print_header();
 
     print_heading($strmanagemodules);
    
@@ -72,7 +66,7 @@
             notice_yesno(get_string("moduledeleteconfirm", "", $strmodulename), 
                          "modules.php?delete=$delete&amp;confirm=1&amp;sesskey=$USER->sesskey", 
                          "modules.php");
-            print_footer();
+            admin_externalpage_print_footer();
             exit;
 
         } else {  // Delete everything!!
 
     echo "<br /><br />";
 
-    print_footer();
+    admin_externalpage_print_footer();
 
 ?>
diff --git a/admin/pagelib.php b/admin/pagelib.php
new file mode 100644 (file)
index 0000000..01d95af
--- /dev/null
@@ -0,0 +1,114 @@
+<?php // $Id$
+
+// Places where there's a multilingual issue (i.e. a string is hardcoded when it should be
+// fetched from current lang) are marked with  /*ML*/
+
+// Two Big Issues
+//  -What do I use as the pageid? Is 1 okay for index.php given that no other pages
+//   in Moodle use this pagelib?
+//  -How do I handle user_is_editing()? I'm sure what I have below isn't... well... "proper".
+
+require_once($CFG->libdir.'/pagelib.php');
+
+define('PAGE_ADMIN', 'admin-index');
+
+page_map_class(PAGE_ADMIN, 'page_admin');
+
+// $DEFINEDPAGES = array(PAGE_CHAT_VIEW);  -- is anything like this needed?
+
+class page_admin extends page_base {
+
+    var $section;
+       var $pathtosection;
+    var $visiblepathtosection;
+
+    function init_full() { 
+        global $CFG, $ADMIN;
+
+        if($this->full_init_done) {
+            return;
+        }
+
+        // fetch the path parameter
+        $this->section = optional_param("section","",PARAM_PATH);
+
+        $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);
+                               }
+                       }
+               }
+
+        // all done
+        $this->full_init_done = true;
+    }
+
+    function blocks_get_default() {
+        return 'admin_2';
+    }
+
+    // seems reasonable that the only people that can edit blocks on the admin pages
+    // are the admins... but maybe we want a role for this?
+    function user_allowed_editing() { 
+        return isadmin();
+    }
+
+    // has to be fixed. i know there's a "proper" way to do this
+    function user_is_editing() { 
+        global $USER;
+        return (($_GET["edit"] == 'on') && isadmin());
+    }
+
+    function url_get_path() {  // erm.... this has to be based on the current location, right?
+        global $CFG;
+        return $CFG->wwwroot .'/admin/settings.php';
+    }
+
+    function url_get_parameters() {  // only handles parameters relevant to the admin pagetype
+        $this->init_full();
+        return array('section' => $this->section);
+    }
+
+    function blocks_get_positions() { 
+        return array(BLOCK_POS_LEFT);
+    }
+
+    function blocks_default_position() { 
+        return BLOCK_POS_LEFT;
+    }
+
+    // does anything need to be done here?
+    function init_quick($data) {
+        parent::init_quick($data);
+    }
+
+    function print_header() {
+        global $USER, $CFG, $SITE;
+
+        $this->init_full();
+
+        // 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="settings.php">'.
+                       '<input type="hidden" name="edit" value="'.($this->user_is_editing()?'off':'on').'" />'.
+                       '<input type="hidden" name="section" value="'.$this->section.'" />'.
+                       '<input type="submit" value="'.get_string($this->user_is_editing()?'blockseditoff':'blocksediton').'" /></form></td>' . 
+                       '</tr></table>';
+        } else {
+            $buttons = '&nbsp;';
+        }
+               
+/*ML*/  print_header("$SITE->shortname: " . implode(": ",$this->visiblepathtosection), $SITE->fullname, implode(" -> ",$this->visiblepathtosection),'', '', true, $buttons, '');
+    }
+
+    function get_type() {
+        return PAGE_ADMIN;
+    }
+}
+
+?>
index 552c9baa7301f36d043623f3ffe83111aa88da14..c184cb1221886f54a1ef3e0322d5193a6a6b692e 100755 (executable)
@@ -3,7 +3,9 @@
 //testing
     require_once('../../config.php');
 
-    require_login();
+    require_once($CFG->dirroot . '/admin/adminlib.php');
+    admin_externalpage_setup('manageroles');
+//    require_login();
 
     $roleid      = optional_param('roleid', 0, PARAM_INT); // if set, we are editing a role
     $action      = optional_param('action', '', PARAM_ALPHA);
 
     $sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
     
-    if (!isadmin()) {
-        error('Only admins can access this page');
-    }
+//    if (!isadmin()) {
+//        error('Only admins can access this page');
+//    }
 
-    if (!$site = get_site()) {
-        redirect('index.php');
-    }
+//    if (!$site = get_site()) {
+//        redirect('index.php');
+//    }
     
     $stradministration = get_string('administration');
     $strmanageroles = get_string('manageroles');
         $editingstr ='';  
     }
     
-    print_header("$site->shortname: $strmanageroles", 
-                 "$site->fullname", 
-                 "<a href=\"../index.php\">$stradministration</a> -> <a href=\"manage.php\">$strmanageroles</a>
-                 $editingstr
-                 ");
+    admin_externalpage_print_header();
+//    print_header("$site->shortname: $strmanageroles", 
+//                 "$site->fullname", 
+//                 "<a href=\"../index.php\">$stradministration</a> -> <a href=\"manage.php\">$strmanageroles</a>
+//                 $editingstr
+//                 ");
 
     // form processing, editing a role, adding a role or deleting a role
     if ($action && confirm_sesskey()) {
                       echo ('<input type="hidden" name="confirm" value="1">');
                       echo ('are you sure?');
                       echo ('<input type="submit" value="yes">');
-                      print_footer($course);
+                      admin_externalpage_print_footer();
+//                      print_footer($course);
                       exit;
                       
                       // prints confirmation form
     }
 
     use_html_editor("description");
-    print_footer($course);
+    admin_externalpage_print_footer();
+//    print_footer($course);
 ?>
diff --git a/admin/settings.php b/admin/settings.php
new file mode 100644 (file)
index 0000000..284afde
--- /dev/null
@@ -0,0 +1,90 @@
+<?php // $Id$
+
+require_once('../config.php');
+require_once($CFG->dirroot . '/admin/adminlib.php');
+
+// for external pages, most of this code is duplicated in the admin_externalpage_print_header()
+// and admin_externalpage_print_footer() functions... just include adminlib.php!
+//
+// lines marked //d at the end are handled (for other pages) by admin_externalpage_print_header()
+// and admin_externalpage_print_footer()
+require_once($CFG->libdir . '/blocklib.php'); //d
+require_once($CFG->dirroot . '/admin/pagelib.php'); //d
+
+if ($site = get_site()) { //d
+    require_login(); //d
+} //d
+
+// Question: what pageid should be used for this?
+
+define('TEMPORARY_ADMIN_PAGE_ID',26); //d
+
+define('BLOCK_L_MIN_WIDTH',160); //d
+define('BLOCK_L_MAX_WIDTH',210); //d
+
+$pagetype = PAGE_ADMIN; //d
+$pageclass = 'page_admin'; //d
+page_map_class($pagetype, $pageclass); //d
+
+$PAGE = page_create_object($pagetype,TEMPORARY_ADMIN_PAGE_ID); //d
+
+$PAGE->init_full(); //d
+
+unset($root); //d
+
+$root = $ADMIN->locate($PAGE->section); //d
+
+if (!($root instanceof admin_settingpage)) { //d
+    error('Section does not exist, is invalid, or should not be accessed via this URL.'); //d
+       die; //d
+} //d
+
+if (!($root->check_access())) { //d
+    error('Access denied.'); //d
+       die; //d
+} //d
+
+// WRITING SUBMITTED DATA (IF ANY) -------------------------------------------------------------------------------
+
+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('The following errors occurred when trying to save settings: <br />' . $errors);
+       }
+       } else {
+           error(get_string('confirmsesskeybad', 'error'));
+               die;
+       }
+}
+
+// ---------------------------------------------------------------------------------------------------------------
+
+$pageblocks = blocks_setup($PAGE);
+
+$preferred_width_left = bounded_number(BLOCK_L_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]), BLOCK_L_MAX_WIDTH);
+
+// print header stuff
+$PAGE->print_header();
+echo '<table id="layout-table"><tr>';
+echo '<td style="width: ' . $preferred_width_left . 'px;" id="left-column">';
+blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
+echo '</td>';
+echo '<td id="middle-column" width="*">';
+echo '<form action="settings.php" method="post" name="mainform">';
+echo '<input type="hidden" name="section" value="' . $PAGE->section . '" />';
+echo '<input type="hidden" name="sesskey" value="' . $USER->sesskey . '" />';
+print_simple_box_start('','100%','',5,'generalbox','');
+
+echo $root->output_html();
+
+echo '<center><input type="submit" value="Save Changes" /></center>';
+echo '</form>';
+print_simple_box_end();
+echo '</td></tr></table>'; //d
+
+print_footer(); //d
+
+?>
\ No newline at end of file
index 29473c38a63a4075595d7a24a597cce906d87108..308c0fab79d92fa83803740ff70a3f6a9b7663f7 100644 (file)
@@ -1,22 +1,16 @@
 <?php // $Id$
 
     // Automatic update of Timezones from a new source
-
+    
     require_once('../config.php');
+    require_once($CFG->dirroot .'/admin/adminlib.php');
     require_once($CFG->libdir.'/filelib.php');
     require_once($CFG->libdir.'/olson.php');
 
-    $ok = optional_param('ok', 0, PARAM_BOOL);
-
-    require_login();
+    admin_externalpage_setup('timezoneimport');
 
-    if (!isadmin()) {
-        error('Only administrators can use this page!');
-    }
+    $ok = optional_param('ok', 0, PARAM_BOOL);
 
-    if (!$site = get_site()) {
-        error('Site isn\'t defined!');
-    }
 
 /// Print headings
 
     $strcalendarsettings = get_string('calendarsettings', 'admin');
     $strimporttimezones = get_string('importtimezones', 'admin');
 
-    print_header("$site->shortname: $strcalendarsettings", "$site->fullname",
-                 "<a href=\"index.php\">$stradministration</a> -> ".
-                 "<a href=\"configure.php\">$strconfiguration</a> -> ".
-                 "<a href=\"calendar.php\">$strcalendarsettings</a> -> $strimporttimezones");
+    admin_externalpage_print_header();
 
     print_heading($strimporttimezones);
 
@@ -42,9 +33,9 @@
 
         $message = get_string("configintrotimezones", 'admin', $message);
 
-        notice_yesno($message, 'timezoneimport.php?ok=1&sesskey='.sesskey(), 'calendar.php');
+        notice_yesno($message, 'timezoneimport.php?ok=1&sesskey='.sesskey(), 'index.php');
 
-        print_footer();
+        admin_externalpage_print_footer();
         exit;
     }
 
         $a->source  = $importdone;
         print_heading(get_string('importtimezonescount', 'admin', $a), '', 3);
 
-        print_continue('calendar.php');
+        print_continue('index.php');
 
         $timezonelist = array();
         foreach ($timezones as $timezone) {
 
     } else {
         print_heading(get_string('importtimezonesfailed', 'admin'), '', 3);
-        print_continue('calendar.php');
+        print_continue('index.php');
     }
 
-    print_footer();
+    admin_externalpage_print_footer();
 
 ?>
index 0714fdec8feab1e35a681cf6e012149b8e47141b..32f03bde6aea6ebfcdc936d8feba9b5d8e68877b 100644 (file)
@@ -1,6 +1,11 @@
 <?php // $Id$
 
-    require_once('../config.php');
+require_once('../config.php');
+require_once($CFG->dirroot . '/admin/adminlib.php');
+
+admin_externalpage_setup('editusers');
+admin_externalpage_print_header();
+
 
     $newuser      = optional_param('newuser', 0, PARAM_BOOL);
     $delete       = optional_param('delete', 0, PARAM_INT);
     
     if ($newuser && confirm_sesskey()) {                 // Create a new user
         
-        if (!has_capability('moodle/user:create', $context)) {
+        if (!has_capability('moodle/user:create', $context->id)) {
             error('You do not have the required permission to create new users.');
         }
         
 
     } else {                        // List all users for editing
         
-        if (!has_capability('moodle/user:update', $context)) {
+        if (!has_capability('moodle/user:update', $context->id)) {
             error('You do not have the required permission to edit users.');
         }
         
         $strsearch = get_string("search");
         $strshowallusers = get_string("showallusers");
 
-        if ($firstinitial or $lastinitial or $search or $page) {
-            print_header("$site->shortname: $stredituser", $site->fullname,
-                         "<a href=\"index.php\">$stradministration</a> -> ".
-                         "<a href=\"users.php\">$strusers</a> -> ".
-                         "<a href=\"user.php\">$stredituser</a>");
-        } else {
-            print_header("$site->shortname: $stredituser", $site->fullname,
-                         "<a href=\"index.php\">$stradministration</a> -> ".
-                         "<a href=\"users.php\">$strusers</a> -> $stredituser");
-        }
 
         if ($confirmuser and confirm_sesskey()) {
             if (!$user = get_record("user", "id", "$confirmuser")) {
 
         } else if ($delete and confirm_sesskey()) {              // Delete a selected user, after confirmation
             
-            if (!has_capability('moodle/user:delete', $context)) {
+            if (!has_capability('moodle/user:delete', $context->id)) {
                 error('You do not have the required permission to delete a user.');
             }
             
                 if ($user->id == $USER->id or $user->username == "changeme") {
                     $deletebutton = "";
                 } else {
-                      if (has_capability('moodle/user:delete', $context)) {
+                      if (has_capability('moodle/user:delete', $context->id)) {
                         $deletebutton = "<a href=\"user.php?delete=$user->id&amp;sesskey=$USER->sesskey\">$strdelete</a>";                    } else {
                         $deletebutton ="";      
                     }
                 }
                 $fullname = fullname($user, true);
                 
-                if (has_capability('moodle/user:edit', $context)) {
+                if (has_capability('moodle/user:edit', $context->id)) {
                 
                     $table->data[] = array ("<a href=\"../user/view.php?id=$user->id&amp;course=$site->id\">$fullname</a>",
                                         "$user->email",
         echo "</form>";
         echo "</td></tr></table>";
         
-        if (has_capability('moodle/user:create', $context)) {
+        if (has_capability('moodle/user:create', $context->id)) {
             print_heading("<a href=\"user.php?newuser=true&amp;sesskey=$USER->sesskey\">".get_string("addnewuser")."</a>");    
         }
         if (!empty($table)) {
             print_paging_bar($usercount, $page, $perpage,
                              "user.php?sort=$sort&amp;dir=$dir&amp;perpage=$perpage".
                              "&amp;firstinitial=$firstinitial&amp;lastinitial=$lastinitial&amp;search=".urlencode(stripslashes($search))."&amp;");
-            if (has_capability('moodle/user:create', $context)) {                
+            if (has_capability('moodle/user:create', $context->id)) {                
                 print_heading("<a href=\"user.php?newuser=true&amp;sesskey=$USER->sesskey\">".get_string("addnewuser")."</a>");
             }
         }
 
 
-        print_footer();
+    admin_externalpage_print_footer();
     }
 
-?>
+?>
\ No newline at end of file