[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/admin/ -> settings.php (source)

   1  <?php
   2  
   3  require_once('../config.php');
   4  require_once($CFG->libdir.'/adminlib.php');
   5  
   6  $section = required_param('section', PARAM_SAFEDIR);
   7  $return = optional_param('return','', PARAM_ALPHA);
   8  $adminediting = optional_param('adminedit', -1, PARAM_BOOL);
   9  
  10  /// no guest autologin
  11  require_login(0, false);
  12  $PAGE->set_context(context_system::instance());
  13  $PAGE->set_url('/admin/settings.php', array('section' => $section));
  14  $PAGE->set_pagetype('admin-setting-' . $section);
  15  $PAGE->set_pagelayout('admin');
  16  $PAGE->navigation->clear_cache();
  17  navigation_node::require_admin_tree();
  18  
  19  $adminroot = admin_get_root(); // need all settings
  20  $settingspage = $adminroot->locate($section, true);
  21  
  22  if (empty($settingspage) or !($settingspage instanceof admin_settingpage)) {
  23      if (moodle_needs_upgrading()) {
  24          redirect(new moodle_url('/admin/index.php'));
  25      } else {
  26          print_error('sectionerror', 'admin', "$CFG->wwwroot/$CFG->admin/");
  27      }
  28      die;
  29  }
  30  
  31  if (!($settingspage->check_access())) {
  32      print_error('accessdenied', 'admin');
  33      die;
  34  }
  35  
  36  /// WRITING SUBMITTED DATA (IF ANY) -------------------------------------------------------------------------------
  37  
  38  $statusmsg = '';
  39  $errormsg  = '';
  40  
  41  if ($data = data_submitted() and confirm_sesskey()) {
  42      if (admin_write_settings($data)) {
  43          redirect($PAGE->url, get_string('changessaved'), null, \core\output\notification::NOTIFY_SUCCESS);
  44      }
  45  
  46      if (empty($adminroot->errors)) {
  47          switch ($return) {
  48              case 'site': redirect("$CFG->wwwroot/");
  49              case 'admin': redirect("$CFG->wwwroot/$CFG->admin/");
  50          }
  51          redirect($PAGE->url);
  52      } else {
  53          $errormsg = get_string('errorwithsettings', 'admin');
  54          $firsterror = reset($adminroot->errors);
  55      }
  56      $settingspage = $adminroot->locate($section, true);
  57  }
  58  
  59  if ($PAGE->user_allowed_editing() && $adminediting != -1) {
  60      $USER->editing = $adminediting;
  61  }
  62  
  63  /// print header stuff ------------------------------------------------------------
  64  if (empty($SITE->fullname)) {
  65      $PAGE->set_title($settingspage->visiblename);
  66      $PAGE->set_heading($settingspage->visiblename);
  67  
  68      echo $OUTPUT->header();
  69      echo $OUTPUT->box(get_string('configintrosite', 'admin'));
  70  
  71      if ($errormsg !== '') {
  72          echo $OUTPUT->notification($errormsg);
  73  
  74      } else if ($statusmsg !== '') {
  75          echo $OUTPUT->notification($statusmsg, 'notifysuccess');
  76      }
  77  
  78      // ---------------------------------------------------------------------------------------------------------------
  79  
  80      echo '<form action="' . $PAGE->url . '" method="post" id="adminsettings">';
  81      echo '<div class="settingsform clearfix">';
  82      echo html_writer::input_hidden_params($PAGE->url);
  83      echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
  84      echo '<input type="hidden" name="return" value="'.$return.'" />';
  85      // HACK to prevent browsers from automatically inserting the user's password into the wrong fields.
  86      echo prevent_form_autofill_password();
  87  
  88      echo $settingspage->output_html();
  89  
  90      echo '<div class="form-buttons"><input class="form-submit" type="submit" value="'.get_string('savechanges','admin').'" /></div>';
  91  
  92      echo '</div>';
  93      echo '</form>';
  94  
  95  } else {
  96      if ($PAGE->user_allowed_editing()) {
  97          $url = clone($PAGE->url);
  98          if ($PAGE->user_is_editing()) {
  99              $caption = get_string('blockseditoff');
 100              $url->param('adminedit', 'off');
 101          } else {
 102              $caption = get_string('blocksediton');
 103              $url->param('adminedit', 'on');
 104          }
 105          $buttons = $OUTPUT->single_button($url, $caption, 'get');
 106          $PAGE->set_button($buttons);
 107      }
 108  
 109      $visiblepathtosection = array_reverse($settingspage->visiblepath);
 110  
 111      $PAGE->set_title("$SITE->shortname: " . implode(": ",$visiblepathtosection));
 112      $PAGE->set_heading($SITE->fullname);
 113      echo $OUTPUT->header();
 114  
 115      if ($errormsg !== '') {
 116          echo $OUTPUT->notification($errormsg);
 117  
 118      } else if ($statusmsg !== '') {
 119          echo $OUTPUT->notification($statusmsg, 'notifysuccess');
 120      }
 121  
 122      // ---------------------------------------------------------------------------------------------------------------
 123  
 124      echo '<form action="' . $PAGE->url . '" method="post" id="adminsettings">';
 125      echo '<div class="settingsform clearfix">';
 126      echo html_writer::input_hidden_params($PAGE->url);
 127      echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
 128      echo '<input type="hidden" name="return" value="'.$return.'" />';
 129      // HACK to prevent browsers from automatically inserting the user's password into the wrong fields.
 130      echo prevent_form_autofill_password();
 131      echo $OUTPUT->heading($settingspage->visiblename);
 132  
 133      echo $settingspage->output_html();
 134  
 135      if ($settingspage->show_save()) {
 136          echo '<div class="form-buttons"><input class="form-submit" type="submit" value="'.get_string('savechanges','admin').'" /></div>';
 137      }
 138  
 139      echo '</div>';
 140      echo '</form>';
 141  }
 142  
 143  $PAGE->requires->yui_module('moodle-core-formchangechecker',
 144          'M.core_formchangechecker.init',
 145          array(array(
 146              'formid' => 'adminsettings'
 147          ))
 148  );
 149  $PAGE->requires->string_for_js('changesmadereallygoaway', 'moodle');
 150  
 151  echo $OUTPUT->footer();


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1