Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.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
  19   * redirected to question.php
  20   *
  21   * @package    moodlecore
  22   * @subpackage questionbank
  23   * @copyright  2009 Tim Hunt
  24   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  25   */
  26  
  27  
  28  require_once(__DIR__ . '/../config.php');
  29  require_once (__DIR__ . '/editlib.php');
  30  
  31  // Read URL parameters.
  32  $categoryid = required_param('category', PARAM_INT);
  33  $cmid = optional_param('cmid', 0, PARAM_INT);
  34  $courseid = optional_param('courseid', 0, PARAM_INT);
  35  $returnurl = optional_param('returnurl', 0, PARAM_LOCALURL);
  36  $appendqnumstring = optional_param('appendqnumstring', '', PARAM_ALPHA);
  37  $validationerror = optional_param('validationerror', false, PARAM_BOOL);
  38  
  39  // Place to accumulate hidden params for the form we will print.
  40  $hiddenparams = array('category' => $categoryid);
  41  
  42  // Validate params.
  43  if (!$category = $DB->get_record('question_categories', array('id' => $categoryid))) {
  44      print_error('categorydoesnotexist', 'question', $returnurl);
  45  }
  46  
  47  if ($cmid) {
  48      list($module, $cm) = get_module_from_cmid($cmid);
  49      require_login($cm->course, false, $cm);
  50      $thiscontext = context_module::instance($cmid);
  51      $hiddenparams['cmid'] = $cmid;
  52  } else if ($courseid) {
  53      require_login($courseid, false);
  54      $thiscontext = context_course::instance($courseid);
  55      $module = null;
  56      $cm = null;
  57      $hiddenparams['courseid'] = $courseid;
  58  } else {
  59      print_error('missingcourseorcmid', 'question');
  60  }
  61  
  62  // Check permissions.
  63  $categorycontext = context::instance_by_id($category->contextid);
  64  require_capability('moodle/question:add', $categorycontext);
  65  
  66  // Ensure other optional params get passed on to question.php.
  67  if (!empty($returnurl)) {
  68      $hiddenparams['returnurl'] = $returnurl;
  69  }
  70  if (!empty($appendqnumstring)) {
  71      $hiddenparams['appendqnumstring'] = $appendqnumstring;
  72  }
  73  
  74  $PAGE->set_url('/question/addquestion.php', $hiddenparams);
  75  if ($cmid) {
  76      $questionbankurl = new moodle_url('/question/edit.php', array('cmid' => $cmid));
  77  } else {
  78      $questionbankurl = new moodle_url('/question/edit.php', array('courseid' => $courseid));
  79  }
  80  navigation_node::override_active_url($questionbankurl);
  81  
  82  $chooseqtype = get_string('chooseqtypetoadd', 'question');
  83  $PAGE->set_heading($COURSE->fullname);
  84  $PAGE->navbar->add($chooseqtype);
  85  $PAGE->set_title($chooseqtype);
  86  
  87  // Display a form to choose the question type.
  88  echo $OUTPUT->header();
  89  echo $OUTPUT->notification(get_string('youmustselectaqtype', 'question'));
  90  echo $OUTPUT->box_start('generalbox boxwidthnormal boxaligncenter', 'chooseqtypebox');
  91  echo print_choose_qtype_to_add_form($hiddenparams, null, false);
  92  echo $OUTPUT->box_end();
  93  echo $OUTPUT->footer();