MDL-9376, disallow student to see the other users posts in max editing time, credits...
[moodle.git] / question / addquestion.php
blob01325dd13a9ceb1f37aa9395b7d36746b7686e24
1 <?php
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 ///////////////////////////////////////////////////////////////////////////
26 /**
27 * Shows a screen where the user can choose a question type, before being
28 * redirected to question.php
30 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
31 * @package questionbank
32 *//** */
34 require_once(dirname(__FILE__) . '/../config.php');
35 require_once(dirname(__FILE__) . '/editlib.php');
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);
43 $validationerror = optional_param('validationerror', false, PARAM_BOOL);
45 // Place to accumulate hidden params for the form we will print.
46 $hiddenparams = array('category' => $categoryid);
48 // Validate params.
49 if (!$category = $DB->get_record('question_categories', array('id' => $categoryid))) {
50 print_error('categorydoesnotexist', 'question', $returnurl);
53 if ($cmid) {
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');
68 // Check permissions.
69 $categorycontext = get_context_instance_by_id($category->contextid);
70 require_capability('moodle/question:add', $categorycontext);
72 // Ensure other optional params get passed on to question.php.
73 if (!empty($returnurl)) {
74 $hiddenparams['returnurl'] = $returnurl;
76 if (!empty($appendqnumstring)) {
77 $hiddenparams['appendqnumstring'] = $appendqnumstring;
80 $PAGE->set_url('/question/addquestion.php', $hiddenparams);
82 $chooseqtype = get_string('chooseqtypetoadd', 'question');
83 $PAGE->set_heading($COURSE->fullname);
84 if ($cm !== null) {
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) {
87 $PAGE->navbar->add(get_string('editinga', 'moodle', get_string('modulename', $cm->modname)),$returnurl);
89 $PAGE->navbar->add($chooseqtype);
90 $PAGE->set_title($chooseqtype);
91 echo $OUTPUT->header();
92 } else {
93 $PAGE->navbar->add(get_string('questionbank', 'question'),$returnurl);
94 $PAGE->navbar->add($chooseqtype);
95 $PAGE->set_title($chooseqtype);
96 echo $OUTPUT->header();
99 // Display a form to choose the question type.
100 echo $OUTPUT->notification(get_string('youmustselectaqtype', 'question'));
101 echo $OUTPUT->box_start('generalbox boxwidthnormal boxaligncenter', 'chooseqtypebox');
102 print_choose_qtype_to_add_form($hiddenparams);
103 echo $OUTPUT->box_end();
105 echo $OUTPUT->footer();