quiz editing / question bank: MDL-18355 Convert the add question drop-down to be...
[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     $navlinks = array();
82     if (stripos($returnurl, "$CFG->wwwroot/mod/{$cm->modname}/view.php")!== 0){
83         //don't need this link if returnurl returns to view.php
84         $navlinks[] = array('name' => get_string('editinga', 'moodle', get_string('modulename', $cm->modname)), 'link' => $returnurl, 'type' => 'title');
85     }
86     $navlinks[] = array('name' => $chooseqtype, 'link' => '', 'type' => 'title');
87     $navigation = build_navigation($navlinks, $cm);
88     print_header_simple($chooseqtype, '', $navigation, '', '', true, update_module_button($cm->id, $cm->course, get_string('modulename', $cm->modname)));
90 } else {
91     $navlinks = array();
92     $navlinks[] = array('name' => get_string('editquestions', 'question'), 'link' => $returnurl, 'type' => 'title');
93     $navlinks[] = array('name' => $chooseqtype, 'link' => '', 'type' => 'title');
94     $navigation = build_navigation($navlinks);
95     print_header_simple($chooseqtype, '', $navigation);
96 }
98 // Display a form to choose the question type.
99 print_box_start('generalbox boxwidthnormal boxaligncenter', 'chooseqtypebox');
100 print_choose_qtype_to_add_form($hiddenparams);
101 print_box_end();
103 print_footer($COURSE);
106 ?>