2006-02-24 10:21:40 +00:00
|
|
|
<?php // $Id$
|
|
|
|
/**
|
2006-10-17 21:45:19 +00:00
|
|
|
* Allows a teacher to create, edit and delete categories
|
|
|
|
*
|
|
|
|
* @author Martin Dougiamas and many others.
|
|
|
|
* {@link http://moodle.org}
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
2007-03-19 17:22:46 +00:00
|
|
|
* @package questionbank
|
2006-10-17 21:45:19 +00:00
|
|
|
*/
|
2006-02-24 10:21:40 +00:00
|
|
|
|
2006-02-24 10:35:28 +00:00
|
|
|
require_once("../config.php");
|
2007-08-09 21:51:09 +00:00
|
|
|
require_once($CFG->dirroot."/question/editlib.php");
|
|
|
|
require_once($CFG->dirroot."/question/category_class.php");
|
2006-02-24 10:21:40 +00:00
|
|
|
|
2007-05-03 10:10:01 +00:00
|
|
|
|
|
|
|
|
2007-08-09 21:51:09 +00:00
|
|
|
list($thispageurl, $contexts, $cmid, $cm, $module, $pagevars) = question_edit_setup('categories');
|
2007-05-03 10:10:01 +00:00
|
|
|
|
|
|
|
// get values from form for actions on this page
|
2006-02-24 10:21:40 +00:00
|
|
|
$param = new stdClass();
|
2007-04-19 08:57:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
$param->moveup = optional_param('moveup', 0, PARAM_INT);
|
|
|
|
$param->movedown = optional_param('movedown', 0, PARAM_INT);
|
2007-08-09 21:51:09 +00:00
|
|
|
$param->moveupcontext = optional_param('moveupcontext', 0, PARAM_INT);
|
|
|
|
$param->movedowncontext = optional_param('movedowncontext', 0, PARAM_INT);
|
|
|
|
$param->tocontext = optional_param('tocontext', 0, PARAM_INT);
|
2007-04-19 08:57:54 +00:00
|
|
|
$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);
|
|
|
|
|
2007-08-09 21:51:09 +00:00
|
|
|
$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'));
|
2006-02-24 10:21:40 +00:00
|
|
|
|
2007-05-03 10:10:01 +00:00
|
|
|
$streditingcategories = get_string('editcategories', 'quiz');
|
2007-08-09 21:51:09 +00:00
|
|
|
if ($param->left || $param->right || $param->moveup || $param->movedown|| $param->moveupcontext || $param->movedowncontext){
|
|
|
|
confirm_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 = count_records("question", "category", $param->delete))){
|
|
|
|
if (!$category = get_record("question_categories", "id", $param->delete)) { // security
|
2008-05-21 07:53:23 +00:00
|
|
|
print_error('nocate', 'question', $thispageurl->out(), $param->delete);
|
2007-08-09 21:51:09 +00:00
|
|
|
}
|
|
|
|
$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->out());
|
|
|
|
} elseif ($formdata = $qcobject->moveform->get_data()) {
|
|
|
|
/// 'confirm' is the category to move existing questions to
|
2008-04-17 15:59:49 +00:00
|
|
|
list($tocategoryid, $tocontextid) = explode(',', $formdata->category);
|
|
|
|
$qcobject->move_questions_and_delete_category($formdata->delete, $tocategoryid);
|
|
|
|
$thispageurl->remove_params('cat');
|
2008-04-22 14:06:58 +00:00
|
|
|
$thispageurl->remove_params('category'); // TODO check in fix for bug 5353
|
2007-08-09 21:51:09 +00:00
|
|
|
redirect($thispageurl->out());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$questionstomove = 0;
|
|
|
|
}
|
|
|
|
if ($qcobject->catform->is_cancelled()){
|
|
|
|
redirect($thispageurl->out());
|
|
|
|
}elseif ($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->out());
|
|
|
|
} elseif ((!empty($param->delete) and (!$questionstomove) and confirm_sesskey())) {
|
|
|
|
$qcobject->delete_category($param->delete);//delete the category now no questions to move
|
|
|
|
}
|
2007-08-15 11:36:01 +00:00
|
|
|
$navlinks = array();
|
2007-08-09 21:51:09 +00:00
|
|
|
if ($cm!==null) {
|
2007-04-19 08:57:54 +00:00
|
|
|
// Page header
|
2007-08-09 21:51:09 +00:00
|
|
|
$strupdatemodule = has_capability('moodle/course:manageactivities', $contexts->lowest())
|
|
|
|
? update_module_button($cm->id, $COURSE->id, get_string('modulename', $cm->modname))
|
2006-02-24 10:21:40 +00:00
|
|
|
: "";
|
2007-08-09 21:51:09 +00:00
|
|
|
$navlinks[] = array('name' => get_string('modulenameplural', $cm->modname),
|
2007-08-13 13:19:42 +00:00
|
|
|
'link' => "$CFG->wwwroot/mod/{$cm->modname}/index.php?id=$COURSE->id",
|
2007-05-03 10:10:01 +00:00
|
|
|
'type' => 'activity');
|
2007-08-09 21:51:09 +00:00
|
|
|
$navlinks[] = array('name' => format_string($module->name),
|
2007-08-15 11:36:01 +00:00
|
|
|
'link' => "$CFG->wwwroot/mod/{$cm->modname}/view.php?id={$cm->id}",
|
2007-05-03 10:10:01 +00:00
|
|
|
'type' => 'title');
|
2007-08-09 21:51:09 +00:00
|
|
|
} else {
|
|
|
|
// Print basic page layout.
|
|
|
|
$strupdatemodule = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$param->edit){
|
2007-07-05 04:40:48 +00:00
|
|
|
$navlinks[] = array('name' => $streditingcategories, 'link' => '', 'type' => 'title');
|
2007-08-09 21:51:09 +00:00
|
|
|
} else {
|
|
|
|
$navlinks[] = array('name' => $streditingcategories, 'link' => $thispageurl->out(), 'type' => 'title');
|
|
|
|
$navlinks[] = array('name' => get_string('editingcategory', 'question'), 'link' => '', 'type' => 'title');
|
|
|
|
}
|
2007-05-03 10:10:01 +00:00
|
|
|
|
2007-08-09 21:51:09 +00:00
|
|
|
$navigation = build_navigation($navlinks);
|
|
|
|
print_header_simple($streditingcategories, '', $navigation, "", "", true, $strupdatemodule);
|
2007-05-03 10:10:01 +00:00
|
|
|
|
2007-08-09 21:51:09 +00:00
|
|
|
// print tabs
|
|
|
|
if ($cm!==null) {
|
2006-02-24 10:21:40 +00:00
|
|
|
$currenttab = 'edit';
|
|
|
|
$mode = 'categories';
|
2007-05-03 10:10:01 +00:00
|
|
|
${$cm->modname} = $module;
|
|
|
|
include($CFG->dirroot."/mod/{$cm->modname}/tabs.php");
|
2006-02-24 10:21:40 +00:00
|
|
|
} else {
|
2006-03-01 08:43:41 +00:00
|
|
|
$currenttab = 'categories';
|
2007-08-09 21:51:09 +00:00
|
|
|
$context = $contexts->lowest();
|
2006-03-01 08:43:41 +00:00
|
|
|
include('tabs.php');
|
2006-02-24 10:21:40 +00:00
|
|
|
}
|
|
|
|
|
2007-08-09 21:51:09 +00:00
|
|
|
// 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();
|
2006-02-24 10:21:40 +00:00
|
|
|
}
|
2007-08-09 21:51:09 +00:00
|
|
|
print_footer($COURSE);
|
2006-02-24 10:21:40 +00:00
|
|
|
?>
|