]> git.mjollnir.org Git - moodle.git/commitdiff
admin tree: MDL-10047 and MDL-13104 weird things happen when you turn editing on...
authortjhunt <tjhunt>
Thu, 11 Dec 2008 09:21:41 +0000 (09:21 +0000)
committertjhunt <tjhunt>
Thu, 11 Dec 2008 09:21:41 +0000 (09:21 +0000)
That was becuase not enough information was being passed in for the blocks editing controls to construct the right URL to reload the page.

It is also now possible for admin external pages to add some UI next to the turn blocks editing on/off button. For example, when you are editing the list of course catgories, the turn editing off button is now in the right place.

admin/pagelib.php
admin/report/unittest/index.php
admin/roles/allowassign.php
admin/roles/allowoverride.php
admin/roles/assign.php
admin/roles/check.php
admin/roles/define.php
admin/roles/override.php
course/category.php
course/index.php
lib/adminlib.php

index 971ae09d3d31bcc7f5c32c436430f01b5b8ffb2a..1dee158b54cc35247e1874393a4d399cdcf49a84 100644 (file)
@@ -20,8 +20,11 @@ page_map_class(PAGE_ADMIN, 'page_admin');
 
 class page_admin extends page_base {
 
-    var $section;
+    var $section = '';
     var $visiblepathtosection;
+    var $extraurlparams = array();
+    var $extrabutton = '';
+    var $url = '';
 
     // hack alert!
     // this function works around the inability to store the section name
@@ -62,6 +65,9 @@ class page_admin extends page_base {
 
     function url_get_path() {
         global $CFG;
+        if (!empty($this->url)) {
+            return $this->url;
+        }
 
         $adminroot =& admin_get_root(false, false); //settings not required - only pages
 
@@ -73,8 +79,29 @@ class page_admin extends page_base {
         }
     }
 
+    /**
+     * Use this to pass extra HTML that is added after the turn blocks editing on/off button.
+     *
+     * @param string $extrabutton HTML code.
+     */
+    function set_extra_button($extrabutton) {
+        $this->extrabutton = $extrabutton;
+    }
+
+    /**
+     * Use this to pass extra URL parameters that, for example, the blocks editing controls need to reload the current page accurately.
+     *
+     * @param array $extraurlparams paramname => value array.
+     */
+    function set_extra_url_params($extraurlparams, $actualurl = '') {
+        $this->extraurlparams = $extraurlparams;
+        if (!empty($actualurl)) {
+            $this->url = $actualurl;
+        }
+    }
+
     function url_get_parameters() {  // only handles parameters relevant to the admin pagetype
-        return array('section' => (isset($this->section) ? $this->section : ''));
+        return array_merge($this->extraurlparams, array('section' => $this->section));
     }
 
     function blocks_get_positions() {
@@ -107,13 +134,19 @@ class page_admin extends page_base {
 
         // The search page currently doesn't handle block editing
         if ($this->section != 'search' and $this->user_allowed_editing()) {
-            $buttons = '<div><form '.$CFG->frametarget.' method="get" action="' . $this->url_get_path() . '">'.
-                '<div><input type="hidden" name="adminedit" 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').'" /></div></form></div>';
+            $options = $this->url_get_parameters();
+            if ($this->user_is_editing()) {
+                $caption = get_string('blockseditoff');
+                $options['adminedit'] = 'off';
+            } else {
+                $caption = get_string('blocksediton');
+                $options['adminedit'] = 'on';
+            }
+            $buttons = print_single_button($this->url_get_path(), $options, $caption, 'get', '', true);
         } else {
             $buttons = '&nbsp;';
         }
+        $buttons .= $this->extrabutton;
 
         $navlinks = array();
         foreach ($this->visiblepathtosection as $element) {
index 47a350f900f041705f5bd859ed6d33307643b38b..53560ad65c4f03ab19cc6932d4a80df25425055b 100644 (file)
@@ -29,7 +29,8 @@ $continuesetuptesttables = optional_param('continuesetuptesttables', false, PARA
 $droptesttables = optional_param('droptesttables', false, PARAM_BOOL);
 $testtablesok = optional_param('testtablesok', false, PARAM_BOOL);
 
-admin_externalpage_setup('reportsimpletest');
+admin_externalpage_setup('reportsimpletest', '', array('showpasses' => $showpasses,
+        'showsearch' => $showsearch, 'thorough' => $thorough));
 admin_externalpage_print_header();
 
 $langfile = 'simpletest';
index d0ced251dc4d8f920373ed510b70eb1c2ffdb635..81e6f83357da0871c99039705c6cec3883a9ee45 100755 (executable)
@@ -76,7 +76,7 @@
     }
 
 /// Display the editing form.
-    admin_externalpage_setup('defineroles');
+    admin_externalpage_setup('defineroles', '', array(), $CFG->wwwroot . '/' . $CFG->admin . '/roles/allowassign.php');
     admin_externalpage_print_header();
 
     $currenttab='allowassign';
index 25272d650eb853840abc0313846149c0d2b7b578..1d1dd2fb39534b4fee87792b7c8bfebe7b752d90 100755 (executable)
@@ -74,7 +74,7 @@
     }
 
 /// Display the editing form.
-    admin_externalpage_setup('defineroles');
+    admin_externalpage_setup('defineroles', '', array(), $CFG->wwwroot . '/' . $CFG->admin . '/roles/allowoverride.php');
     admin_externalpage_print_header();
 
     $currenttab='allowoverride';
index 0b82a78090968ea13640c3d6ed092a1a1df2d0b0..b7ada55b3daa937fbfb30198559b64d1565a1aa7 100755 (executable)
         include_once($CFG->dirroot.'/user/tabs.php');
 
     } else if ($context->contextlevel == CONTEXT_SYSTEM) {
-        admin_externalpage_setup('assignroles');
+        admin_externalpage_setup('assignroles', '', array('contextid' => $contextid, 'roleid' => $roleid));
         admin_externalpage_print_header();
 
     } else if ($isfrontpage) {
-        admin_externalpage_setup('frontpageroles');
+        admin_externalpage_setup('frontpageroles', '', array('contextid' => $contextid, 'roleid' => $roleid));
         admin_externalpage_print_header();
         $currenttab = 'assign';
         include_once('tabs.php');
index 2589a91a1abfe2bb8e3f40ba40a44b5ce2f568ad..abd55d844749dd81649bea731c4cc3803cbebc96 100755 (executable)
         include_once($CFG->dirroot.'/user/tabs.php');
 
     } else if ($context->contextlevel == CONTEXT_SYSTEM) {
-        admin_externalpage_setup('checkpermissions');
+        admin_externalpage_setup('checkpermissions', '', array('contextid' => $contextid));
         admin_externalpage_print_header();
 
     } else if ($context->contextlevel == CONTEXT_COURSE and $context->instanceid == SITEID) {
-        admin_externalpage_setup('frontpageroles');
+        admin_externalpage_setup('frontpageroles', '', array('contextid' => $contextid), $CFG->wwwroot . '/' . $CFG->admin . '/roles/check.php');
         admin_externalpage_print_header();
         $currenttab = 'check';
         include_once('tabs.php');
index 78be6bd9b09717738831c87ab3315438795b0e44..7981b5f6d7d50da0ae13a0725c81f837c9b25326 100755 (executable)
@@ -65,7 +65,7 @@
     $systemcontext = get_context_instance(CONTEXT_SYSTEM);
     require_login();
     require_capability('moodle/role:manage', $systemcontext);
-    admin_externalpage_setup('defineroles');
+    admin_externalpage_setup('defineroles', '', array($action, $roleid), $defineurl);
 
 /// Handle the cancel button.
     if (optional_param('cancel', false, PARAM_BOOL)) {
index b6cdc99429f507f179ed5fee7a9c59023ffb5f74..d85cb30556f1488170634cc36656252302c8367b 100755 (executable)
         include_once($CFG->dirroot.'/user/tabs.php');
     } else if ($context->contextlevel==CONTEXT_COURSE and $context->instanceid == SITEID) {
         require_once($CFG->libdir.'/adminlib.php');
-        admin_externalpage_setup('frontpageroles');
+        admin_externalpage_setup('frontpageroles', '', array('contextid' => $contextid, 'roleid' => $roleid), $CFG->wwwroot . '/' . $CFG->admin . '/roles/override.php');
         admin_externalpage_print_header();
         $currenttab = 'override';
         include_once('tabs.php');
index cfc5ae860a485abbaa66c1fac9fe163bb514906f..7473e75af597d835d9e668ea892b407f1312b133 100644 (file)
         // Integrate into the admin tree only if the user can edit categories at the top level,
         // otherwise the admin block does not appear to this user, and you get an error.
         require_once($CFG->libdir.'/adminlib.php');
-        admin_externalpage_setup('coursemgmt');
+        admin_externalpage_setup('coursemgmt', $navbaritem, array('id' => $id,
+                'page' => $page, 'perpage' => $perpage), $CFG->wwwroot . '/course/category.php');
         admin_externalpage_print_header();
     } else {
         print_header("$site->shortname: $category->name", "$site->fullname: $strcourses", $navigation, '', '', true, $navbaritem);
     }
 
-/// Print button to turn editing off
-    if ($editingon) {
-        echo '<div class="categoryediting button">'.update_category_button($category->id).'</div>';
-    }
-
 /// Print link to roles
     if (has_capability('moodle/role:assign', $context)) {
         echo '<div class="rolelink"><a href="'.$CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?contextid='.
index 0c239ba5ebbdf42a0f4156e5061ac692a921abbf..f711fa85eb3e9680cc5dd1e3ed5fdec1e5b34189 100644 (file)
     }
 
     print_course_request_buttons($systemcontext);
-    // admin page does not allow custom buttons in the navigation bar
-    echo '<div class="singlebutton">';
-    echo update_category_button();
-    echo '</div></div>';
 
     admin_externalpage_print_footer();
 
@@ -369,7 +365,7 @@ function print_category_edit_header() {
     global $SITE;
 
     require_once($CFG->libdir.'/adminlib.php');
-    admin_externalpage_setup('coursemgmt');
+    admin_externalpage_setup('coursemgmt', update_category_button());
     admin_externalpage_print_header();
 }
 ?>
index 3b56e1d28e1b006e840fc39172d5932dbfd376fc..724b81e38f2eb51e77055cc391104dfc7445f482 100644 (file)
@@ -2122,6 +2122,9 @@ class admin_externalpage extends part_of_admin_tree {
      * @param string $visiblename The displayed name for this external page. Usually obtained through get_string().
      * @param string $url The external URL that we should link to when someone requests this external page.
      * @param mixed $req_capability The role capability/permission a user must have to access this external page. Defaults to 'moodle/site:config'.
+     * @param boolean $hidden Is this external page hidden in admin tree block? Default false.
+     * @param context $context The context the page relates to. Not sure what happens
+     *      if you specify something other than system or front page. Defaults to system.
      */
     function admin_externalpage($name, $visiblename, $url, $req_capability='moodle/site:config', $hidden=false, $context=NULL) {
         $this->name        = $name;
@@ -2132,7 +2135,7 @@ class admin_externalpage extends part_of_admin_tree {
         } else {
             $this->req_capability = array($req_capability);
         }
-        $this->hidden  = $hidden;
+        $this->hidden = $hidden;
         $this->context = $context;
     }
 
@@ -5169,8 +5172,13 @@ class admin_setting_manageportfolio extends admin_setting {
  * checks specified in page definition.
  * This function must be called on each admin page before other code.
  * @param string $section name of page
+ * @param string $extrabutton extra HTML that is added after the blocks editing on/off button.
+ * @param string $extraurlparams an array paramname => paramvalue, or parameters that need to be
+ *      added to the turn blocks editing on/off form, so this page reloads correctly.
+ * @param string $actualurl if the actual page being viewed is not the normal one for this
+ *      page (e.g. admin/roles/allowassin.php, instead of admin/roles/manage.php, you can pass the alternate URL here.
  */
-function admin_externalpage_setup($section) {
+function admin_externalpage_setup($section, $extrabutton='', $extraurlparams=array(), $actualurl='') {
 
     global $CFG, $PAGE, $USER;
     require_once($CFG->libdir.'/blocklib.php');
@@ -5200,6 +5208,8 @@ function admin_externalpage_setup($section) {
     page_map_class(PAGE_ADMIN, 'page_admin');
     $PAGE = page_create_object(PAGE_ADMIN, 0); // there must be any constant id number
     $PAGE->init_extra($section); // hack alert!
+    $PAGE->set_extra_button($extrabutton);
+    $PAGE->set_extra_url_params($extraurlparams, $actualurl);
 
     $adminediting = optional_param('adminedit', -1, PARAM_BOOL);