Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/question/addquestion.php
Go to the documentation of this file.
00001 <?php
00002 // This file is part of Moodle - http://moodle.org/
00003 //
00004 // Moodle is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // Moodle is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00016 
00028 require_once(dirname(__FILE__) . '/../config.php');
00029 require_once(dirname(__FILE__) . '/editlib.php');
00030 
00031 // Read URL parameters.
00032 $categoryid = required_param('category', PARAM_INT);
00033 $cmid = optional_param('cmid', 0, PARAM_INT);
00034 $courseid = optional_param('courseid', 0, PARAM_INT);
00035 $returnurl = optional_param('returnurl', 0, PARAM_LOCALURL);
00036 $appendqnumstring = optional_param('appendqnumstring', '', PARAM_ALPHA);
00037 $validationerror = optional_param('validationerror', false, PARAM_BOOL);
00038 
00039 // Place to accumulate hidden params for the form we will print.
00040 $hiddenparams = array('category' => $categoryid);
00041 
00042 // Validate params.
00043 if (!$category = $DB->get_record('question_categories', array('id' => $categoryid))) {
00044     print_error('categorydoesnotexist', 'question', $returnurl);
00045 }
00046 
00047 if ($cmid) {
00048     list($module, $cm) = get_module_from_cmid($cmid);
00049     require_login($cm->course, false, $cm);
00050     $thiscontext = get_context_instance(CONTEXT_MODULE, $cmid);
00051     $hiddenparams['cmid'] = $cmid;
00052 } else if ($courseid) {
00053     require_login($courseid, false);
00054     $thiscontext = get_context_instance(CONTEXT_COURSE, $courseid);
00055     $module = null;
00056     $cm = null;
00057     $hiddenparams['courseid'] = $courseid;
00058 } else {
00059     print_error('missingcourseorcmid', 'question');
00060 }
00061 
00062 // Check permissions.
00063 $categorycontext = get_context_instance_by_id($category->contextid);
00064 require_capability('moodle/question:add', $categorycontext);
00065 
00066 // Ensure other optional params get passed on to question.php.
00067 if (!empty($returnurl)) {
00068     $hiddenparams['returnurl'] = $returnurl;
00069 }
00070 if (!empty($appendqnumstring)) {
00071     $hiddenparams['appendqnumstring'] = $appendqnumstring;
00072 }
00073 
00074 $PAGE->set_url('/question/addquestion.php', $hiddenparams);
00075 
00076 $chooseqtype = get_string('chooseqtypetoadd', 'question');
00077 $PAGE->set_heading($COURSE->fullname);
00078 if ($cm !== null) {
00079     // Nasty hack, but we don't want this link if returnurl returns to view.php
00080     if (stripos($returnurl, "/mod/{$cm->modname}/view.php")!== 0) {
00081         $PAGE->navbar->add(get_string('editinga', 'moodle', get_string('modulename', $cm->modname)),$returnurl);
00082     }
00083     $PAGE->navbar->add($chooseqtype);
00084     $PAGE->set_title($chooseqtype);
00085     echo $OUTPUT->header();
00086 } else {
00087     $PAGE->navbar->add(get_string('questionbank', 'question'),$returnurl);
00088     $PAGE->navbar->add($chooseqtype);
00089     $PAGE->set_title($chooseqtype);
00090     echo $OUTPUT->header();
00091 }
00092 
00093 // Display a form to choose the question type.
00094 echo $OUTPUT->notification(get_string('youmustselectaqtype', 'question'));
00095 echo $OUTPUT->box_start('generalbox boxwidthnormal boxaligncenter', 'chooseqtypebox');
00096 print_choose_qtype_to_add_form($hiddenparams);
00097 echo $OUTPUT->box_end();
00098 
00099 echo $OUTPUT->footer();
00100 
 All Data Structures Namespaces Files Functions Variables Enumerations