MDL-20636 Review option defaults in the admin settings.
[moodle.git] / question / addquestion.php
CommitLineData
aeb15530 1<?php
cd120b23 2
3///////////////////////////////////////////////////////////////////////////
4// //
5// NOTICE OF COPYRIGHT //
6// //
7// Moodle - Modular Object-Oriented Dynamic Learning Environment //
8// http://moodle.org //
9// //
10// Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
11// //
12// This program is free software; you can redistribute it and/or modify //
13// it under the terms of the GNU General Public License as published by //
14// the Free Software Foundation; either version 2 of the License, or //
15// (at your option) any later version. //
16// //
17// This program is distributed in the hope that it will be useful, //
18// but WITHOUT ANY WARRANTY; without even the implied warranty of //
19// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
20// GNU General Public License for more details: //
21// //
22// http://www.gnu.org/copyleft/gpl.html //
23// //
24///////////////////////////////////////////////////////////////////////////
25
26/**
27 * Shows a screen where the user can choose a question type, before being
28 * redirected to question.php
29 *
30 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
31 * @package questionbank
32 *//** */
33
34require_once(dirname(__FILE__) . '/../config.php');
35require_once(dirname(__FILE__) . '/editlib.php');
36
37// Read URL parameters.
38$categoryid = required_param('category', PARAM_INT);
39$cmid = optional_param('cmid', 0, PARAM_INT);
40$courseid = optional_param('courseid', 0, PARAM_INT);
41$returnurl = optional_param('returnurl', 0, PARAM_LOCALURL);
42$appendqnumstring = optional_param('appendqnumstring', '', PARAM_ALPHA);
a27aa5c6 43$validationerror = optional_param('validationerror', false, PARAM_BOOL);
cd120b23 44
45// Place to accumulate hidden params for the form we will print.
46$hiddenparams = array('category' => $categoryid);
47
48// Validate params.
49if (!$category = $DB->get_record('question_categories', array('id' => $categoryid))) {
50 print_error('categorydoesnotexist', 'question', $returnurl);
51}
52
babcc520 53if ($cmid) {
cd120b23 54 list($module, $cm) = get_module_from_cmid($cmid);
55 require_login($cm->course, false, $cm);
56 $thiscontext = get_context_instance(CONTEXT_MODULE, $cmid);
57 $hiddenparams['cmid'] = $cmid;
58} else if ($courseid) {
59 require_login($courseid, false);
60 $thiscontext = get_context_instance(CONTEXT_COURSE, $courseid);
61 $module = null;
62 $cm = null;
63 $hiddenparams['courseid'] = $courseid;
64} else {
65 print_error('missingcourseorcmid', 'question');
66}
67
68// Check permissions.
69$categorycontext = get_context_instance_by_id($category->contextid);
70require_capability('moodle/question:add', $categorycontext);
71
72// Ensure other optional params get passed on to question.php.
73if (!empty($returnurl)) {
74 $hiddenparams['returnurl'] = $returnurl;
75}
76if (!empty($appendqnumstring)) {
77 $hiddenparams['appendqnumstring'] = $appendqnumstring;
78}
79
a6855934 80$PAGE->set_url('/question/addquestion.php', $hiddenparams);
5c0daafc 81
cd120b23 82$chooseqtype = get_string('chooseqtypetoadd', 'question');
0f56fde2 83$PAGE->set_heading($COURSE->fullname);
cd120b23 84if ($cm !== null) {
fb6dcdab
TH
85 // Nasty hack, but we don't want this link if returnurl returns to view.php
86 if (stripos($returnurl, "/mod/{$cm->modname}/view.php")!== 0) {
d412354c 87 $PAGE->navbar->add(get_string('editinga', 'moodle', get_string('modulename', $cm->modname)),$returnurl);
cd120b23 88 }
d412354c 89 $PAGE->navbar->add($chooseqtype);
0f56fde2 90 $PAGE->set_title($chooseqtype);
d412354c 91 echo $OUTPUT->header();
cd120b23 92} else {
5c0daafc 93 $PAGE->navbar->add(get_string('questionbank', 'question'),$returnurl);
d412354c 94 $PAGE->navbar->add($chooseqtype);
0f56fde2 95 $PAGE->set_title($chooseqtype);
d412354c 96 echo $OUTPUT->header();
cd120b23 97}
98
99// Display a form to choose the question type.
a27aa5c6 100echo $OUTPUT->notification(get_string('youmustselectaqtype', 'question'));
beb677cd 101echo $OUTPUT->box_start('generalbox boxwidthnormal boxaligncenter', 'chooseqtypebox');
cd120b23 102print_choose_qtype_to_add_form($hiddenparams);
beb677cd 103echo $OUTPUT->box_end();
cd120b23 104
9b59580b 105echo $OUTPUT->footer();
aeb15530 106