Commit d3603157 authored by Tim Hunt's avatar Tim Hunt
Browse files

MDL-20636 Add @package and GPL boiler-plate to files in /question.

parent 0ff4bd08
<?php
///////////////////////////////////////////////////////////////////////////
// //
// NOTICE OF COPYRIGHT //
// //
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// http://moodle.org //
// //
// Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation; either version 2 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details: //
// //
// http://www.gnu.org/copyleft/gpl.html //
// //
///////////////////////////////////////////////////////////////////////////
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Shows a screen where the user can choose a question type, before being
* redirected to question.php
*
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package questionbank
*//** */
* @package moodlecore
* @subpackage questionbank
* @copyright 2009 Tim Hunt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(dirname(__FILE__) . '/../config.php');
require_once(dirname(__FILE__) . '/editlib.php');
......
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Allows a teacher to create, edit and delete categories
* This script allows a teacher to create, edit and delete question categories.
*
* @author Martin Dougiamas and many others.
* {@link http://moodle.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package questionbank
* @package moodlecore
* @subpackage questionbank
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once("../config.php");
require_once($CFG->dirroot."/question/editlib.php");
require_once($CFG->dirroot."/question/category_class.php");
list($thispageurl, $contexts, $cmid, $cm, $module, $pagevars) =
question_edit_setup('categories', '/question/category.php');
require_once("../config.php");
require_once($CFG->dirroot."/question/editlib.php");
require_once($CFG->dirroot."/question/category_class.php");
list($thispageurl, $contexts, $cmid, $cm, $module, $pagevars) =
question_edit_setup('categories', '/question/category.php');
// get values from form for actions on this page
$param = new stdClass();
$param->moveup = optional_param('moveup', 0, PARAM_INT);
$param->movedown = optional_param('movedown', 0, PARAM_INT);
$param->moveupcontext = optional_param('moveupcontext', 0, PARAM_INT);
$param->movedowncontext = optional_param('movedowncontext', 0, PARAM_INT);
$param->tocontext = optional_param('tocontext', 0, PARAM_INT);
$param->left = optional_param('left', 0, PARAM_INT);
$param->right = optional_param('right', 0, PARAM_INT);
$param->delete = optional_param('delete', 0, PARAM_INT);
$param->confirm = optional_param('confirm', 0, PARAM_INT);
$param->cancel = optional_param('cancel', '', PARAM_ALPHA);
$param->move = optional_param('move', 0, PARAM_INT);
$param->moveto = optional_param('moveto', 0, PARAM_INT);
$param->edit = optional_param('edit', 0, PARAM_INT);
// get values from form for actions on this page
$param = new stdClass();
$param->moveup = optional_param('moveup', 0, PARAM_INT);
$param->movedown = optional_param('movedown', 0, PARAM_INT);
$param->moveupcontext = optional_param('moveupcontext', 0, PARAM_INT);
$param->movedowncontext = optional_param('movedowncontext', 0, PARAM_INT);
$param->tocontext = optional_param('tocontext', 0, PARAM_INT);
$param->left = optional_param('left', 0, PARAM_INT);
$param->right = optional_param('right', 0, PARAM_INT);
$param->delete = optional_param('delete', 0, PARAM_INT);
$param->confirm = optional_param('confirm', 0, PARAM_INT);
$param->cancel = optional_param('cancel', '', PARAM_ALPHA);
$param->move = optional_param('move', 0, PARAM_INT);
$param->moveto = optional_param('moveto', 0, PARAM_INT);
$param->edit = optional_param('edit', 0, PARAM_INT);
$url = new moodle_url($thispageurl);
foreach ((array)$param as $key=>$value) {
if (($key !== 'cancel' && $value !== 0) || ($key === 'cancel' && $value !== '')) {
$url->param($key, $value);
}
$url = new moodle_url($thispageurl);
foreach ((array)$param as $key=>$value) {
if (($key !== 'cancel' && $value !== 0) || ($key === 'cancel' && $value !== '')) {
$url->param($key, $value);
}
$PAGE->set_url($url);
$PAGE->set_pagelayout('standard');
}
$PAGE->set_url($url);
$PAGE->set_pagelayout('standard');
$qcobject = new question_category_object($pagevars['cpage'], $thispageurl, $contexts->having_one_edit_tab_cap('categories'), $param->edit, $pagevars['cat'], $param->delete,
$contexts->having_cap('moodle/question:add'));
$qcobject = new question_category_object($pagevars['cpage'], $thispageurl, $contexts->having_one_edit_tab_cap('categories'), $param->edit, $pagevars['cat'], $param->delete,
$contexts->having_cap('moodle/question:add'));
$streditingcategories = get_string('editcategories', 'quiz');
if ($param->left || $param->right || $param->moveup || $param->movedown|| $param->moveupcontext || $param->movedowncontext){
require_sesskey();
foreach ($qcobject->editlists as $list){
//processing of these actions is handled in the method where appropriate and page redirects.
$list->process_actions($param->left, $param->right, $param->moveup, $param->movedown,
$param->moveupcontext, $param->movedowncontext, $param->tocontext);
}
$streditingcategories = get_string('editcategories', 'quiz');
if ($param->left || $param->right || $param->moveup || $param->movedown|| $param->moveupcontext || $param->movedowncontext){
require_sesskey();
foreach ($qcobject->editlists as $list){
//processing of these actions is handled in the method where appropriate and page redirects.
$list->process_actions($param->left, $param->right, $param->moveup, $param->movedown,
$param->moveupcontext, $param->movedowncontext, $param->tocontext);
}
if ($param->delete && ($questionstomove = $DB->count_records("question", array("category" => $param->delete)))){
if (!$category = $DB->get_record("question_categories", array("id" => $param->delete))) { // security
print_error('nocate', 'question', $thispageurl->out(), $param->delete);
}
$categorycontext = get_context_instance_by_id($category->contextid);
$qcobject->moveform = new question_move_form($thispageurl,
array('contexts'=>array($categorycontext), 'currentcat'=>$param->delete));
if ($qcobject->moveform->is_cancelled()){
redirect($thispageurl);
} elseif ($formdata = $qcobject->moveform->get_data()) {
/// 'confirm' is the category to move existing questions to
list($tocategoryid, $tocontextid) = explode(',', $formdata->category);
$qcobject->move_questions_and_delete_category($formdata->delete, $tocategoryid);
$thispageurl->remove_params('cat', 'category');
redirect($thispageurl);
}
} else {
$questionstomove = 0;
}
if ($param->delete && ($questionstomove = $DB->count_records("question", array("category" => $param->delete)))){
if (!$category = $DB->get_record("question_categories", array("id" => $param->delete))) { // security
print_error('nocate', 'question', $thispageurl->out(), $param->delete);
}
if ($qcobject->catform->is_cancelled()) {
redirect($thispageurl);
} else if ($catformdata = $qcobject->catform->get_data()) {
if (!$catformdata->id) {//new category
$qcobject->add_category($catformdata->parent, $catformdata->name, $catformdata->info);
} else {
$qcobject->update_category($catformdata->id, $catformdata->parent, $catformdata->name, $catformdata->info);
}
$categorycontext = get_context_instance_by_id($category->contextid);
$qcobject->moveform = new question_move_form($thispageurl,
array('contexts'=>array($categorycontext), 'currentcat'=>$param->delete));
if ($qcobject->moveform->is_cancelled()){
redirect($thispageurl);
} else if ((!empty($param->delete) and (!$questionstomove) and confirm_sesskey())) {
$qcobject->delete_category($param->delete);//delete the category now no questions to move
} elseif ($formdata = $qcobject->moveform->get_data()) {
/// 'confirm' is the category to move existing questions to
list($tocategoryid, $tocontextid) = explode(',', $formdata->category);
$qcobject->move_questions_and_delete_category($formdata->delete, $tocategoryid);
$thispageurl->remove_params('cat', 'category');
redirect($thispageurl);
}
if ($param->edit){
$PAGE->navbar->add(get_string('editingcategory', 'question'));
} else {
$questionstomove = 0;
}
if ($qcobject->catform->is_cancelled()) {
redirect($thispageurl);
} else if ($catformdata = $qcobject->catform->get_data()) {
if (!$catformdata->id) {//new category
$qcobject->add_category($catformdata->parent, $catformdata->name, $catformdata->info);
} else {
$qcobject->update_category($catformdata->id, $catformdata->parent, $catformdata->name, $catformdata->info);
}
redirect($thispageurl);
} else if ((!empty($param->delete) and (!$questionstomove) and confirm_sesskey())) {
$qcobject->delete_category($param->delete);//delete the category now no questions to move
$thispageurl->remove_params('cat', 'category');
redirect($thispageurl);
}
$PAGE->set_title($streditingcategories);
$PAGE->set_heading($COURSE->fullname);
echo $OUTPUT->header();
if ($param->edit){
$PAGE->navbar->add(get_string('editingcategory', 'question'));
}
// display UI
if (!empty($param->edit)) {
$qcobject->edit_single_category($param->edit);
} else if ($questionstomove){
$qcobject->display_move_form($questionstomove, $category);
} else {
// display the user interface
$qcobject->display_user_interface();
}
echo $OUTPUT->footer();
$PAGE->set_title($streditingcategories);
$PAGE->set_heading($COURSE->fullname);
echo $OUTPUT->header();
// display UI
if (!empty($param->edit)) {
$qcobject->edit_single_category($param->edit);
} else if ($questionstomove){
$qcobject->display_move_form($questionstomove, $category);
} else {
// display the user interface
$qcobject->display_user_interface();
}
echo $OUTPUT->footer();
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* A class for representing question categories.
*
* @package moodlecore
* @subpackage questionbank
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Class representing question categories
*
* @author Martin Dougiamas and many others. {@link http://moodle.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package questionbank
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
// number of categories to display on page
define("QUESTION_PAGE_LENGTH", 25);
define('QUESTION_PAGE_LENGTH', 25);
require_once($CFG->libdir . '/listlib.php');
require_once($CFG->dirroot . '/question/category_form.php');
......
<?php
///////////////////////////////////////////////////////////////////////////
// //
// NOTICE OF COPYRIGHT //
// //
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// http://moodle.org //
// //
// Copyright (C) 1999 onwards Martin Dougiamas and others //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation; either version 2 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details: //
// //
// http://www.gnu.org/copyleft/gpl.html //
// //
///////////////////////////////////////////////////////////////////////////
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Page to edit the question bank
*
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package questionbank
* @package moodlecore
* @subpackage questionbank
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once("../config.php");
require_once("editlib.php");
$url = new moodle_url('/question/edit.php');
if (($lastchanged = optional_param('lastchanged', 0, PARAM_INT)) !== 0) {
$url->param('lastchanged', $lastchanged);
}
if (($category = optional_param('category', 0, PARAM_TEXT)) !== 0) {
$url->param('category', $category);
}
if (($qpage = optional_param('qpage', 0, PARAM_INT)) !== 0) {
$url->param('qpage', $qpage);
}
if (($cat = optional_param('cat', 0, PARAM_TEXT)) !== 0) {
$url->param('cat', $cat);
}
if (($courseid = optional_param('courseid', 0, PARAM_INT)) !== 0) {
$url->param('courseid', $courseid);
}
if (($returnurl = optional_param('returnurl', 0, PARAM_INT)) !== 0) {
$url->param('returnurl', $returnurl);
}
if (($cmid = optional_param('cmid', 0, PARAM_INT)) !== 0) {
$url->param('cmid', $cmid);
}
$PAGE->set_url($url);
$PAGE->set_pagelayout('standard');
require_once(dirname(__FILE__) . '/../config.php');
require_once($CFG->dirroot . '/question/editlib.php');
list($thispageurl, $contexts, $cmid, $cm, $module, $pagevars) =
question_edit_setup('questions', '/question/edit.php');
$questionbank = new question_bank_view($contexts, $thispageurl, $COURSE, $cm);
$questionbank->process_actions();
$url = new moodle_url('/question/edit.php');
if (($lastchanged = optional_param('lastchanged', 0, PARAM_INT)) !== 0) {
$url->param('lastchanged', $lastchanged);
}
if (($category = optional_param('category', 0, PARAM_TEXT)) !== 0) {
$url->param('category', $category);
}
if (($qpage = optional_param('qpage', 0, PARAM_INT)) !== 0) {
$url->param('qpage', $qpage);
}
if (($cat = optional_param('cat', 0, PARAM_TEXT)) !== 0) {
$url->param('cat', $cat);
}
if (($courseid = optional_param('courseid', 0, PARAM_INT)) !== 0) {
$url->param('courseid', $courseid);
}
if (($returnurl = optional_param('returnurl', 0, PARAM_INT)) !== 0) {
$url->param('returnurl', $returnurl);
}
if (($cmid = optional_param('cmid', 0, PARAM_INT)) !== 0) {
$url->param('cmid', $cmid);
}
$PAGE->set_url($url);
$PAGE->set_pagelayout('standard');
// TODO log this page view.
list($thispageurl, $contexts, $cmid, $cm, $module, $pagevars) =
question_edit_setup('questions', '/question/edit.php');
$questionbank = new question_bank_view($contexts, $thispageurl, $COURSE, $cm);
$questionbank->process_actions();
$context = $contexts->lowest();
$streditingquestions = get_string('editquestions', "quiz");
$PAGE->set_title($streditingquestions);
$PAGE->set_heading($COURSE->fullname);
echo $OUTPUT->header();
// TODO log this page view.
echo '<div class="questionbankwindow boxwidthwide boxaligncenter">';
$questionbank->display('questions', $pagevars['qpage'],
$pagevars['qperpage'], $pagevars['qsortorder'], $pagevars['qsortorderdecoded'],
$pagevars['cat'], $pagevars['recurse'], $pagevars['showhidden'], $pagevars['showquestiontext']);
echo "</div>\n";
$context = $contexts->lowest();
$streditingquestions = get_string('editquestions', "quiz");
$PAGE->set_title($streditingquestions);
$PAGE->set_heading($COURSE->fullname);
echo $OUTPUT->header();
echo $OUTPUT->footer();
echo '<div class="questionbankwindow boxwidthwide boxaligncenter">';
$questionbank->display('questions', $pagevars['qpage'],
$pagevars['qperpage'], $pagevars['qsortorder'], $pagevars['qsortorderdecoded'],
$pagevars['cat'], $pagevars['recurse'], $pagevars['showhidden'], $pagevars['showquestiontext']);
echo "</div>\n";
echo $OUTPUT->footer();
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Export quiz questions into the given category
* Script for importing questions into the question bank.
*
* @author Martin Dougiamas, Howard Miller, and many others.
* {@link http://moodle.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package questionbank
* @subpackage importexport
* @package moodlecore
* @subpackage questionbank
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once("../config.php");
require_once("editlib.php");
require_once("export_form.php");
$PAGE->set_pagelayout('standard');
require_once(dirname(__FILE__) . '/../config.php');
require_once($CFG->dirroot . '/question/editlib.php');
require_once($CFG->dirroot . '/question/export_form.php');
list($thispageurl, $contexts, $cmid, $cm, $module, $pagevars) =
question_edit_setup('export', '/question/export.php');
$PAGE->set_pagelayout('standard');
// get display strings
$strexportquestions = get_string('exportquestions', 'question');
list($thispageurl, $contexts, $cmid, $cm, $module, $pagevars) =
question_edit_setup('export', '/question/export.php');
// make sure we are using the user's most recent category choice
if (empty($categoryid)) {
$categoryid = $pagevars['cat'];
}
// get display strings
$strexportquestions = get_string('exportquestions', 'question');
list($catid, $catcontext) = explode(',', $pagevars['cat']);
if (!$category = $DB->get_record("question_categories", array("id" => $catid, 'contextid' => $catcontext))) {
print_error('nocategory','quiz');
}
// make sure we are using the user's most recent category choice
if (empty($categoryid)) {
$categoryid = $pagevars['cat'];
}
list($catid, $catcontext) = explode(',', $pagevars['cat']);
if (!$category = $DB->get_record("question_categories", array("id" => $catid, 'contextid' => $catcontext))) {
print_error('nocategory','quiz');
}
/// Header
$PAGE->set_url($thispageurl->out());
$PAGE->set_title($strexportquestions);
$PAGE->set_heading($COURSE->fullname);
echo $OUTPUT->header();
$export_form = new question_export_form($thispageurl, array('contexts'=>$contexts->having_one_edit_tab_cap('export'), 'defaultcategory'=>$pagevars['cat']));
/// Header
$PAGE->set_url($thispageurl->out());
$PAGE->set_title($strexportquestions);
$PAGE->set_heading($COURSE->fullname);
echo $OUTPUT->header();
$export_form = new question_export_form($thispageurl, array('contexts'=>$contexts->having_one_edit_tab_cap('export'), 'defaultcategory'=>$pagevars['cat']));
if ($from_form = $export_form->get_data()) {
$thiscontext = $contexts->lowest();
if (!is_readable("format/$from_form->format/format.php")) {
print_error('unknowformat', '', '', $from_form->format);
}
$withcategories = 'nocategories';
if (!empty($from_form->cattofile)) {
$withcategories = 'withcategories';
}
$withcontexts = 'nocontexts';
if (!empty($from_form->contexttofile)) {
$withcontexts = 'withcontexts';
}
$classname = 'qformat_' . $from_form->format;
$qformat = new $classname();
$filename = question_default_export_filename($COURSE, $category) .
$qformat->export_file_extension();
$export_url = question_make_export_url($thiscontext->id, $category->id,
$from_form->format, $withcategories, $withcontexts, $filename);
echo $OUTPUT->box_start();
echo get_string('yourfileshoulddownload', 'question', $export_url->out());
echo $OUTPUT->box_end();
$PAGE->requires->js_function_call('document.location.replace', array($export_url->out()), false, 1);
echo $OUTPUT->continue_button(new moodle_url('edit.php', $thispageurl->params()));
echo $OUTPUT->footer();
exit;
if ($from_form = $export_form->get_data()) {
$thiscontext = $contexts->lowest();
if (!is_readable("format/$from_form->format/format.php")) {
print_error('unknowformat', '', '', $from_form->format);
}
$withcategories = 'nocategories';
if (!empty($from_form->cattofile)) {
$withcategories = 'withcategories';
}
$withcontexts = 'nocontexts';
if (!empty($from_form->contexttofile)) {
$withcontexts = 'withcontexts';
}
$classname = 'qformat_' . $from_form->format;
$qformat = new $classname();
$filename = question_default_export_filename($COURSE, $category) .
$qformat->export_file_extension();
$export_url = question_make_export_url($thiscontext->id, $category->id,
$from_form->format, $withcategories, $withcontexts, $filename);
/// Display export form
echo $OUTPUT->heading_with_help($strexportquestions, 'exportquestions', 'question');
echo $OUTPUT->box_start();
echo get_string('yourfileshoulddownload', 'question', $export_url->out());
echo $OUTPUT->box_end();
$export_form->display();
$PAGE->requires->js_function_call('document.location.replace', array($export_url->out()), false, 1);
echo $OUTPUT->continue_button(new moodle_url('edit.php', $thispageurl->params()));
echo $OUTPUT->footer();