question MDL-19820 Updated print_header and build_navigation to OUTPUT and PAGE equiv...
[moodle.git] / question / addquestion.php
1 <?php  // $Id$
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
29  *
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);
44 // Place to accumulate hidden params for the form we will print.
45 $hiddenparams = array('category' => $categoryid);
47 // Validate params.
48 if (!$category = $DB->get_record('question_categories', array('id' => $categoryid))) {
49     print_error('categorydoesnotexist', 'question', $returnurl);
50 }
52 if ($cmid) {
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 }
67 // Check permissions.
68 $categorycontext = get_context_instance_by_id($category->contextid);
69 require_capability('moodle/question:add', $categorycontext);
71 // Ensure other optional params get passed on to question.php.
72 if (!empty($returnurl)) {
73     $hiddenparams['returnurl'] = $returnurl;
74 }
75 if (!empty($appendqnumstring)) {
76     $hiddenparams['appendqnumstring'] = $appendqnumstring;
77 }
79 $chooseqtype = get_string('chooseqtypetoadd', 'question');
80 if ($cm !== null) {
81     if (stripos($returnurl, "$CFG->wwwroot/mod/{$cm->modname}/view.php")!== 0) {
82         //don't need this link if returnurl returns to view.php
83         $PAGE->navbar->add(get_string('editinga', 'moodle', get_string('modulename', $cm->modname)),$returnurl);
84     }
85     $PAGE->navbar->add($chooseqtype);
86     $PAGE->set_title($chooseqtype);
87     $PAGE->set_button(update_module_button($cm->id, $cm->course, get_string('modulename', $cm->modname)));
88     echo $OUTPUT->header();
89 } else {
90     $PAGE->navbar->add(get_string('editquestions', 'question'),$returnurl);
91     $PAGE->navbar->add($chooseqtype);
92     $PAGE->set_title($chooseqtype);
93     echo $OUTPUT->header();
94 }
96 // Display a form to choose the question type.
97 echo $OUTPUT->box_start('generalbox boxwidthnormal boxaligncenter', 'chooseqtypebox');
98 print_choose_qtype_to_add_form($hiddenparams);
99 echo $OUTPUT->box_end();
101 echo $OUTPUT->footer();
102 ?>