Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 401 and 402] [Versions 401 and 403]

   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   * Reset course indentation
  19   *
  20   * @copyright 2023 Amaia Anabitarte <amaia@moodle.com>
  21   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22   */
  23  
  24  require_once('../../config.php');
  25  
  26  require_admin();
  27  
  28  $format = required_param('format', PARAM_PLUGIN);
  29  $confirm = optional_param('confirm', false, PARAM_BOOL);
  30  $backurl = new moodle_url('/admin/settings.php', ['section' => 'formatsetting'.$format]);
  31  
  32  $PAGE->set_url('/admin/course/resetindentation.php', ['format' => $format]);
  33  $PAGE->set_context(context_system::instance());
  34  
  35  if ($confirm) {
  36      require_sesskey();
  37      $courses = $DB->get_records('course', ['format' => $format], 'id', 'id');
  38      if (!empty($courses)) {
  39          $courseids = array_keys($courses);
  40          list($courseinsql, $courseparams) = $DB->get_in_or_equal($courseids, SQL_PARAMS_NAMED, 'course');
  41          $DB->set_field_select('course_modules', 'indent', '0', "course $courseinsql AND indent <> 0", $courseparams);
  42          rebuild_course_cache(0, true);
  43      }
  44      redirect(
  45          $backurl,
  46          get_string('resetindentationsuccess', 'admin'),
  47          null,
  48          \core\output\notification::NOTIFY_SUCCESS
  49      );
  50  }
  51  
  52  $strtitle = get_string('resetindentation', 'admin');
  53  
  54  $PAGE->set_title($strtitle);
  55  $PAGE->set_heading($strtitle);
  56  
  57  navigation_node::override_active_url(new moodle_url(
  58      '/admin/course/resetindentation.php',
  59      ['action' => 'confirm', 'format' => $format]
  60  ));
  61  
  62  echo $OUTPUT->header();
  63  
  64  $displayoptions = ['confirmtitle' => get_string('resetindentation_title', 'admin')];
  65  $confirmbutton = new single_button(
  66      new moodle_url('/admin/course/resetindentation.php', ['confirm' => 1, 'format' => $format, 'sesskey' => sesskey()]),
  67      get_string('resetindentation', 'admin'),
  68      'post'
  69  );
  70  $cancelbutton = new single_button($backurl, get_string('cancel'));
  71  echo $OUTPUT->confirm(
  72      get_string('resetindentation_help', 'admin', ['format' => get_string('pluginname', 'format_'.$format)]),
  73      $confirmbutton,
  74      $cancelbutton,
  75      $displayoptions
  76  );
  77  
  78  echo $OUTPUT->footer();