addquestion.php 3.3 KB

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