Search moodle.org's
Developer Documentation

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.
  • /admin/ -> category.php (source)

    Differences Between: [Versions 310 and 34] [Versions 310 and 35] [Versions 310 and 36] [Versions 310 and 37] [Versions 34 and 310] [Versions 35 and 310] [Versions 36 and 310] [Versions 37 and 310]

       1  <?php
       2  // This file is part of Moodle - http://moodle.org/
       3  //
       4  // Moodle is free software: you can redistribute it and/or modify
       5  // it under the terms of the GNU General Public License as published by
       6  // the Free Software Foundation, either version 3 of the License, or
       7  // (at your option) any later version.
       8  //
       9  // Moodle is distributed in the hope that it will be useful,
      10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
      11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      12  // GNU General Public License for more details.
      13  //
      14  // You should have received a copy of the GNU General Public License
      15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
      16  
      17  /**
      18   * This file is used to display a categories sub categories, external pages, and settings.
      19   *
      20   * @since      Moodle 2.3
      21   * @package    admin
      22   * @copyright  2011 Sam Hemelryk
      23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
      24   */
      25  
      26  require_once('../config.php');
      27  require_once($CFG->libdir.'/adminlib.php');
      28  
      29  $category = required_param('category', PARAM_SAFEDIR);
      30  $return = optional_param('return','', PARAM_ALPHA);
      31  $adminediting = optional_param('adminedit', -1, PARAM_BOOL);
      32  
      33  require_login(0, false);
      34  $PAGE->set_context(context_system::instance());
      35  $PAGE->set_url('/admin/category.php', array('category' => $category));
      36  $PAGE->set_pagetype('admin-setting-' . $category);
      37  $PAGE->set_pagelayout('admin');
      38  $PAGE->navigation->clear_cache();
      39  
      40  $adminroot = admin_get_root(); // need all settings
      41  $settingspage = $adminroot->locate($category, true);
      42  
      43  if (empty($settingspage) or !($settingspage instanceof admin_category)) {
      44      print_error('categoryerror', 'admin', "$CFG->wwwroot/$CFG->admin/");
      45  }
      46  
      47  if (!($settingspage->check_access())) {
      48      print_error('accessdenied', 'admin');
      49  }
      50  
      51  
      52  $statusmsg = '';
      53  $errormsg  = '';
      54  
      55  if ($data = data_submitted() and confirm_sesskey()) {
      56      $count = admin_write_settings($data);
      57      if (empty($adminroot->errors)) {
      58          // No errors. Did we change any setting?  If so, then indicate success.
      59          if ($count) {
      60              $statusmsg = get_string('changessaved');
      61          } else {
      62              switch ($return) {
      63                  case 'site': redirect("$CFG->wwwroot/");
      64                  case 'admin': redirect("$CFG->wwwroot/$CFG->admin/");
      65              }
      66          }
      67      } else {
      68          $errormsg = get_string('errorwithsettings', 'admin');
      69          $firsterror = reset($adminroot->errors);
      70      }
      71      $settingspage = $adminroot->locate($category, true);
      72  }
      73  
      74  if ($PAGE->user_allowed_editing() && $adminediting != -1) {
      75      $USER->editing = $adminediting;
      76  }
      77  $buttons = null;
      78  if ($PAGE->user_allowed_editing()) {
      79      $url = clone($PAGE->url);
      80      if ($PAGE->user_is_editing()) {
      81          $caption = get_string('blockseditoff');
      82          $url->param('adminedit', 'off');
      83      } else {
      84          $caption = get_string('blocksediton');
      85          $url->param('adminedit', 'on');
      86      }
      87      $buttons = $OUTPUT->single_button($url, $caption, 'get');
      88  }
      89  
      90  $savebutton = false;
      91  $outputhtml = '';
      92  foreach ($settingspage->children as $childpage) {
      93      if ($childpage->is_hidden() || !$childpage->check_access()) {
      94          continue;
      95      }
      96      if ($childpage instanceof admin_externalpage) {
      97          $outputhtml .= $OUTPUT->heading(html_writer::link($childpage->url, $childpage->visiblename), 3);
      98      } else if ($childpage instanceof admin_settingpage) {
      99          $outputhtml .= $OUTPUT->heading(html_writer::link(new moodle_url('/'.$CFG->admin.'/settings.php', array('section' => $childpage->name)), $childpage->visiblename), 3);
     100          // If its a settings page and has settings lets display them.
     101          if (!empty($childpage->settings)) {
     102              $outputhtml .= html_writer::start_tag('fieldset', array('class' => 'adminsettings'));
     103              foreach ($childpage->settings as $setting) {
     104                  if (empty($setting->nosave)) {
     105                      $savebutton = true;
     106                  }
     107                  $fullname = $setting->get_full_name();
     108                  if (array_key_exists($fullname, $adminroot->errors)) {
     109                      $data = $adminroot->errors[$fullname]->data;
     110                  } else {
     111                      $data = $setting->get_setting();
     112                  }
     113                  $outputhtml .= html_writer::tag('div', '<!-- -->', array('class' => 'clearer'));
     114                  $outputhtml .= $setting->output_html($data);
     115              }
     116              $outputhtml .= html_writer::end_tag('fieldset');
     117          }
     118      } else if ($childpage instanceof admin_category) {
     119          $outputhtml .= $OUTPUT->heading(html_writer::link(new moodle_url('/'.$CFG->admin.'/category.php', array('category' => $childpage->name)), get_string('admincategory', 'admin', $childpage->visiblename)), 3);
     120      }
     121  }
     122  if ($savebutton) {
     123      $outputhtml .= html_writer::start_tag('div', array('class' => 'form-buttons'));
     124      $outputhtml .= html_writer::empty_tag('input', array('class' => 'btn btn-primary form-submit', 'type' => 'submit', 'value' => get_string('savechanges','admin')));
     125      $outputhtml .= html_writer::end_tag('div');
     126  }
     127  
     128  $visiblepathtosection = array_reverse($settingspage->visiblepath);
     129  $PAGE->set_title("$SITE->shortname: " . implode(": ",$visiblepathtosection));
     130  $PAGE->set_heading($SITE->fullname);
     131  if ($buttons) {
     132      $PAGE->set_button($buttons);
     133  }
     134  
     135  echo $OUTPUT->header();
     136  
     137  if ($errormsg !== '') {
     138      echo $OUTPUT->notification($errormsg);
     139  } else if ($statusmsg !== '') {
     140      echo $OUTPUT->notification($statusmsg, 'notifysuccess');
     141  }
     142  
     143  $path = array_reverse($settingspage->visiblepath);
     144  if (is_array($path)) {
     145      $visiblename = join(' / ', $path);
     146  } else {
     147      $visiblename = $path;
     148  }
     149  echo $OUTPUT->heading(get_string('admincategory', 'admin', $visiblename), 2);
     150  
     151  echo html_writer::start_tag('form', array('action' => '', 'method' => 'post', 'id' => 'adminsettings'));
     152  echo html_writer::start_tag('div');
     153  echo html_writer::input_hidden_params(new moodle_url($PAGE->url, array('sesskey' => sesskey(), 'return' => $return)));
     154  echo html_writer::end_tag('div');
     155  echo html_writer::start_tag('fieldset');
     156  echo html_writer::tag('div', '<!-- -->', array('class' => 'clearer'));
     157  echo $outputhtml;
     158  echo html_writer::end_tag('fieldset');
     159  echo html_writer::end_tag('form');
     160  
     161  echo $OUTPUT->footer();