MDL-9147
[moodle-pu.git] / question / category.php
blob265972c4af0648ff2ce3f2ad6627ae85a1a98e3a
1 <?php // $Id$
2 /**
3 * Allows a teacher to create, edit and delete categories
5 * @author Martin Dougiamas and many others.
6 * {@link http://moodle.org}
7 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
8 * @package questionbank
9 */
11 require_once("../config.php");
12 require_once("editlib.php");
13 require_once("category_class.php");
15 // get values from form
16 $param = new stdClass();
17 $id = required_param('id',PARAM_INT); // course id
18 $param->moveup = optional_param('moveup',0,PARAM_INT);
19 $param->movedown = optional_param('movedown',0,PARAM_INT);
20 $param->hide = optional_param('hide',0,PARAM_INT);
21 $param->delete = optional_param('delete',0,PARAM_INT);
22 $param->confirm = optional_param('confirm',0,PARAM_INT);
23 $param->cancel = optional_param('cancel','',PARAM_ALPHA);
24 $param->move = optional_param('move',0,PARAM_INT);
25 $param->moveto = optional_param('moveto',0,PARAM_INT);
26 $param->publish = optional_param('publish',0,PARAM_INT);
27 $param->addcategory = optional_param('addcategory','',PARAM_NOTAGS);
28 $param->edit = optional_param('edit',0,PARAM_INT);
29 $param->updateid = optional_param('updateid',0,PARAM_INT);
30 $param->page = optional_param('page',1,PARAM_INT);
32 if (! $course = get_record("course", "id", $id)) {
33 error("Course ID is incorrect");
36 $context = get_context_instance(CONTEXT_COURSE, $id);
38 require_login($course->id, false);
39 require_capability('moodle/question:managecategory', $context);
41 $qcobject = new question_category_object();
42 $qcobject->set_course($course);
44 // Page header
45 // TODO: generalise this to any activity
46 if (isset($SESSION->modform->instance) and $quiz = get_record('quiz', 'id', $SESSION->modform->instance)) {
47 $strupdatemodule = has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $course->id))
48 ? update_module_button($SESSION->modform->cmid, $course->id, get_string('modulename', 'quiz'))
49 : "";
50 print_header_simple(get_string('editcategories', 'quiz'), '',
51 "<a href=\"$CFG->wwwroot/mod/quiz/index.php?id=$course->id\">".get_string('modulenameplural', 'quiz').'</a>'.
52 " -> <a href=\"$CFG->wwwroot/mod/quiz/view.php?q=$quiz->id\">".format_string($quiz->name).'</a>'.
53 ' -> '.get_string('editcategories', 'quiz'),
54 "", "", true, $strupdatemodule);
55 $currenttab = 'edit';
56 $mode = 'categories';
57 include($CFG->dirroot.'/mod/quiz/tabs.php');
58 } else {
59 print_header_simple(get_string('editcategories', 'quiz'), '', get_string('editcategories', 'quiz'));
61 // print tabs
62 $currenttab = 'categories';
63 include('tabs.php');
66 // Process actions.
67 if (isset($_REQUEST['sesskey']) and confirm_sesskey()) { // sesskey must be ok
68 if (!empty($param->delete) and empty($param->cancel)) {
69 if (!empty($param->confirm)) {
70 /// 'confirm' is the category to move existing questions to
71 $qcobject->delete_category($param->delete, $param->confirm);
72 } else {
73 $qcobject->delete_category($param->delete);
75 } else if (!empty($param->moveup)) {
76 $qcobject->move_category_up_down('up', $param->moveup);
77 } else if (!empty($param->movedown)) {
78 $qcobject->move_category_up_down('down', $param->movedown);
79 } else if (!empty($param->hide)) {
80 $qcobject->publish_category(false, $param->hide);
81 } else if (!empty($param->move)) {
82 $qcobject->move_category($param->move, $param->moveto);
83 } else if (!empty($param->publish)) {
84 $qcobject->publish_category(true, $param->publish);
85 } else if (!empty($param->addcategory)) {
86 $param->newparent = required_param('newparent',PARAM_INT);
87 $param->newcategory = required_param('newcategory',PARAM_NOTAGS);
88 $param->newinfo = required_param('newinfo',PARAM_NOTAGS);
89 $param->newpublish = required_param('newpublish',PARAM_INT);
90 $qcobject->add_category($param->newparent, $param->newcategory, $param->newinfo,
91 $param->newpublish, $course->id);
92 } else if (!empty($param->edit)) {
93 $qcobject->edit_single_category($param->edit, $param->page);
94 } else if (!empty($param->updateid)) {
95 $param->updateparent = required_param('updateparent',PARAM_INT);
96 $param->updatename = required_param('updatename',PARAM_NOTAGS);
97 $param->updateinfo = required_param('updateinfo',PARAM_NOTAGS);
98 $param->updatepublish = required_param('updatepublish',PARAM_INT);
99 $qcobject->update_category($param->updateid, $param->updateparent, $param->updatename,
100 $param->updateinfo, $param->updatepublish, $course->id);
104 // display the user interface
105 $qcobject->display_user_interface($param->page);
107 print_footer($course);