quiz MDL-19813 Upgraded deprecated calls and called set_url with pre-generated var
[moodle.git] / question / addquestion.php
CommitLineData
cd120b23 1<?php // $Id$
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);
43
44// Place to accumulate hidden params for the form we will print.
45$hiddenparams = array('category' => $categoryid);
46
47// Validate params.
48if (!$category = $DB->get_record('question_categories', array('id' => $categoryid))) {
49 print_error('categorydoesnotexist', 'question', $returnurl);
50}
51
babcc520 52if ($cmid) {
cd120b23 53 list($module, $cm) = get_module_from_cmid($cmid);
54 require_login($cm->course, false, $cm);
55 $thiscontext = get_context_instance(CONTEXT_MODULE, $cmid);
56 $hiddenparams['cmid'] = $cmid;
57} else if ($courseid) {
58 require_login($courseid, false);
59 $thiscontext = get_context_instance(CONTEXT_COURSE, $courseid);
60 $module = null;
61 $cm = null;
62 $hiddenparams['courseid'] = $courseid;
63} else {
64 print_error('missingcourseorcmid', 'question');
65}
66
67// Check permissions.
68$categorycontext = get_context_instance_by_id($category->contextid);
69require_capability('moodle/question:add', $categorycontext);
70
71// Ensure other optional params get passed on to question.php.
72if (!empty($returnurl)) {
73 $hiddenparams['returnurl'] = $returnurl;
74}
75if (!empty($appendqnumstring)) {
76 $hiddenparams['appendqnumstring'] = $appendqnumstring;
77}
78
79$chooseqtype = get_string('chooseqtypetoadd', 'question');
80if ($cm !== null) {
babcc520 81 if (stripos($returnurl, "$CFG->wwwroot/mod/{$cm->modname}/view.php")!== 0) {
cd120b23 82 //don't need this link if returnurl returns to view.php
d412354c 83 $PAGE->navbar->add(get_string('editinga', 'moodle', get_string('modulename', $cm->modname)),$returnurl);
cd120b23 84 }
d412354c 85 $PAGE->navbar->add($chooseqtype);
86 $PAGE->set_title($chooseqtype);
1d58b567 87 $PAGE->set_button($OUTPUT->update_module_button($cm->id, $cm->modname));
d412354c 88 echo $OUTPUT->header();
cd120b23 89} else {
d412354c 90 $PAGE->navbar->add(get_string('editquestions', 'question'),$returnurl);
91 $PAGE->navbar->add($chooseqtype);
92 $PAGE->set_title($chooseqtype);
93 echo $OUTPUT->header();
cd120b23 94}
95
96// Display a form to choose the question type.
beb677cd 97echo $OUTPUT->box_start('generalbox boxwidthnormal boxaligncenter', 'chooseqtypebox');
cd120b23 98print_choose_qtype_to_add_form($hiddenparams);
beb677cd 99echo $OUTPUT->box_end();
cd120b23 100
9b59580b 101echo $OUTPUT->footer();
102?>