MDL-10838 Applied standard table classes and scopes to tr, th and tds of the grader...
[moodle.git] / question / category.php
CommitLineData
516cf3eb 1<?php // $Id$
2/**
bc649d80 3 * Allows a teacher to create, edit and delete categories
4 *
bc649d80 5 * @author Martin Dougiamas and many others.
6 * {@link http://moodle.org}
7 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
4323d029 8 * @package questionbank
bc649d80 9 */
516cf3eb 10
e586cfb4 11 require_once("../config.php");
271e6dec 12 require_once($CFG->dirroot."/question/editlib.php");
13 require_once($CFG->dirroot."/question/category_class.php");
516cf3eb 14
b72ff476 15
16
271e6dec 17 list($thispageurl, $contexts, $cmid, $cm, $module, $pagevars) = question_edit_setup('categories');
b72ff476 18
19 // get values from form for actions on this page
516cf3eb 20 $param = new stdClass();
dac786f3 21
dac786f3 22
23 $param->moveup = optional_param('moveup', 0, PARAM_INT);
24 $param->movedown = optional_param('movedown', 0, PARAM_INT);
271e6dec 25 $param->moveupcontext = optional_param('moveupcontext', 0, PARAM_INT);
26 $param->movedowncontext = optional_param('movedowncontext', 0, PARAM_INT);
27 $param->tocontext = optional_param('tocontext', 0, PARAM_INT);
dac786f3 28 $param->left = optional_param('left', 0, PARAM_INT);
29 $param->right = optional_param('right', 0, PARAM_INT);
dac786f3 30 $param->delete = optional_param('delete', 0, PARAM_INT);
31 $param->confirm = optional_param('confirm', 0, PARAM_INT);
32 $param->cancel = optional_param('cancel', '', PARAM_ALPHA);
33 $param->move = optional_param('move', 0, PARAM_INT);
34 $param->moveto = optional_param('moveto', 0, PARAM_INT);
dac786f3 35 $param->edit = optional_param('edit', 0, PARAM_INT);
dac786f3 36
271e6dec 37 $qcobject = new question_category_object($pagevars['cpage'], $thispageurl, $contexts->having_one_edit_tab_cap('categories'), $param->edit, $pagevars['cat'], $param->delete,
38 $contexts->having_cap('moodle/question:add'));
516cf3eb 39
b72ff476 40 $streditingcategories = get_string('editcategories', 'quiz');
271e6dec 41 if ($param->left || $param->right || $param->moveup || $param->movedown|| $param->moveupcontext || $param->movedowncontext){
42 confirm_sesskey();
43 foreach ($qcobject->editlists as $list){
44 //processing of these actions is handled in the method where appropriate and page redirects.
45 $list->process_actions($param->left, $param->right, $param->moveup, $param->movedown,
46 $param->moveupcontext, $param->movedowncontext, $param->tocontext);
47 }
48 }
49 if ($param->delete && ($questionstomove = count_records("question", "category", $param->delete))){
50 if (!$category = get_record("question_categories", "id", $param->delete)) { // security
51 error("No such category {$param->delete}!", $thispageurl->out());
52 }
53 $categorycontext = get_context_instance_by_id($category->contextid);
54 $qcobject->moveform = new question_move_form($thispageurl,
55 array('contexts'=>array($categorycontext), 'currentcat'=>$param->delete));
56 if ($qcobject->moveform->is_cancelled()){
57 redirect($thispageurl->out());
58 } elseif ($formdata = $qcobject->moveform->get_data()) {
59 /// 'confirm' is the category to move existing questions to
60 $qcobject->move_questions_and_delete_category($formdata->delete, $formdata->category);
61 redirect($thispageurl->out());
62 }
63 } else {
64 $questionstomove = 0;
65 }
66 if ($qcobject->catform->is_cancelled()){
67 redirect($thispageurl->out());
68 }elseif ($catformdata = $qcobject->catform->get_data()) {
69 if (!$catformdata->id) {//new category
70 $qcobject->add_category($catformdata->parent, $catformdata->name, $catformdata->info);
71 } else {
72 $qcobject->update_category($catformdata->id, $catformdata->parent, $catformdata->name, $catformdata->info);
73 }
74 redirect($thispageurl->out());
75 } elseif ((!empty($param->delete) and (!$questionstomove) and confirm_sesskey())) {
76 $qcobject->delete_category($param->delete);//delete the category now no questions to move
77 }
78 $crumbs = array();
79 if ($cm!==null) {
dac786f3 80 // Page header
271e6dec 81 $strupdatemodule = has_capability('moodle/course:manageactivities', $contexts->lowest())
82 ? update_module_button($cm->id, $COURSE->id, get_string('modulename', $cm->modname))
516cf3eb 83 : "";
3b27b0fe 84 $navlinks = array();
271e6dec 85 $navlinks[] = array('name' => get_string('modulenameplural', $cm->modname),
7cb30aca 86 'link' => "$CFG->wwwroot/mod/{$cm->modname}/index.php?id=$COURSE->id",
b72ff476 87 'type' => 'activity');
271e6dec 88 $navlinks[] = array('name' => format_string($module->name),
b72ff476 89 'link' => "$CFG->wwwroot/mod/{$cm->modname}/view.php?cmid={$cm->id}",
90 'type' => 'title');
271e6dec 91 } else {
92 // Print basic page layout.
93 $strupdatemodule = '';
94 $navlinks = array();
95 }
96
97 if (!$param->edit){
3b27b0fe 98 $navlinks[] = array('name' => $streditingcategories, 'link' => '', 'type' => 'title');
271e6dec 99 } else {
100 $navlinks[] = array('name' => $streditingcategories, 'link' => $thispageurl->out(), 'type' => 'title');
101 $navlinks[] = array('name' => get_string('editingcategory', 'question'), 'link' => '', 'type' => 'title');
102 }
b72ff476 103
271e6dec 104 $navigation = build_navigation($navlinks);
105 print_header_simple($streditingcategories, '', $navigation, "", "", true, $strupdatemodule);
b72ff476 106
271e6dec 107 // print tabs
108 if ($cm!==null) {
516cf3eb 109 $currenttab = 'edit';
110 $mode = 'categories';
b72ff476 111 ${$cm->modname} = $module;
112 include($CFG->dirroot."/mod/{$cm->modname}/tabs.php");
516cf3eb 113 } else {
567709c4 114 $currenttab = 'categories';
271e6dec 115 $context = $contexts->lowest();
567709c4 116 include('tabs.php');
516cf3eb 117 }
118
271e6dec 119 // display UI
120 if (!empty($param->edit)) {
121 $qcobject->edit_single_category($param->edit);
122 } else if ($questionstomove){
123 $qcobject->display_move_form($questionstomove, $category);
124 } else {
125 // display the user interface
126 $qcobject->display_user_interface();
516cf3eb 127 }
271e6dec 128 print_footer($COURSE);
516cf3eb 129?>