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.
   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   * Shows a screen where the user can choose a question type, before being redirected to question.php
  19   *
  20   * @package    qbank_editquestion
  21   * @copyright  2009 Tim Hunt
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  require_once(__DIR__ . '/../../../config.php');
  26  require_once (__DIR__ . '/../../editlib.php');
  27  
  28  use qbank_editquestion\editquestion_helper;
  29  
  30  // Read URL parameters.
  31  $categoryid = required_param('category', PARAM_INT);
  32  $cmid = optional_param('cmid', 0, PARAM_INT);
  33  $courseid = optional_param('courseid', 0, PARAM_INT);
  34  $returnurl = optional_param('returnurl', 0, PARAM_LOCALURL);
  35  $appendqnumstring = optional_param('appendqnumstring', '', PARAM_ALPHA);
  36  $validationerror = optional_param('validationerror', false, PARAM_BOOL);
  37  
  38  \core_question\local\bank\helper::require_plugin_enabled('qbank_editquestion');
  39  
  40  // Place to accumulate hidden params for the form we will print.
  41  $hiddenparams = array('category' => $categoryid);
  42  
  43  // Validate params.
  44  if (!$category = $DB->get_record('question_categories', array('id' => $categoryid))) {
  45      throw new moodle_exception('categorydoesnotexist', 'question', $returnurl);
  46  }
  47  
  48  if ($cmid) {
  49      list($module, $cm) = get_module_from_cmid($cmid);
  50      require_login($cm->course, false, $cm);
  51      $thiscontext = context_module::instance($cmid);
  52      $hiddenparams['cmid'] = $cmid;
  53  } else if ($courseid) {
  54      require_login($courseid, false);
  55      $thiscontext = context_course::instance($courseid);
  56      $module = null;
  57      $cm = null;
  58      $hiddenparams['courseid'] = $courseid;
  59  } else {
  60      throw new moodle_exception('missingcourseorcmid', 'question');
  61  }
  62  
  63  // Check permissions.
  64  $categorycontext = context::instance_by_id($category->contextid);
  65  require_capability('moodle/question:add', $categorycontext);
  66  
  67  // Ensure other optional params get passed on to question.php.
  68  if (!empty($returnurl)) {
  69      $hiddenparams['returnurl'] = $returnurl;
  70  }
  71  if (!empty($appendqnumstring)) {
  72      $hiddenparams['appendqnumstring'] = $appendqnumstring;
  73  }
  74  
  75  $PAGE->set_url('/question/bank/editquestion/addquestion.php', $hiddenparams);
  76  if ($cmid) {
  77      $questionbankurl = new moodle_url('/question/edit.php', array('cmid' => $cmid));
  78  } else {
  79      $questionbankurl = new moodle_url('/question/edit.php', array('courseid' => $courseid));
  80  }
  81  navigation_node::override_active_url($questionbankurl);
  82  
  83  $chooseqtype = get_string('chooseqtypetoadd', 'question');
  84  $PAGE->set_heading($COURSE->fullname);
  85  $PAGE->navbar->add($chooseqtype);
  86  $PAGE->set_title($chooseqtype);
  87  
  88  // Display a form to choose the question type.
  89  echo $OUTPUT->header();
  90  echo $OUTPUT->notification(get_string('youmustselectaqtype', 'question'));
  91  echo $OUTPUT->box_start('generalbox boxwidthnormal boxaligncenter', 'chooseqtypebox');
  92  echo editquestion_helper::print_choose_qtype_to_add_form($hiddenparams, null, false);
  93  echo $OUTPUT->box_end();
  94  echo $OUTPUT->footer();