Fixed up debugging() function so it's more useful.
[moodle.git] / question / category.php
CommitLineData
516cf3eb 1<?php // $Id$
2/**
3* Allows a teacher to create, edit and delete categories
4*
5* @version $Id$
6* @author Martin Dougiamas and many others.
7* {@link http://moodle.org}
8* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
e586cfb4 9* @package question
516cf3eb 10*/
11
e586cfb4 12 require_once("../config.php");
4fbfd971 13 require_once("editlib.php");
516cf3eb 14 require_once("category_class.php");
15
16 // get values from form
17 $param = new stdClass();
18 $id = required_param('id',PARAM_INT); // course id
19 $param->moveup = optional_param('moveup',0,PARAM_INT);
20 $param->movedown = optional_param('movedown',0,PARAM_INT);
21 $param->hide = optional_param('hide',0,PARAM_INT);
22 $param->delete = optional_param('delete',0,PARAM_INT);
23 $param->confirm = optional_param('confirm',0,PARAM_INT);
24 $param->cancel = optional_param('cancel','',PARAM_ALPHA);
25 $param->move = optional_param('move',0,PARAM_INT);
26 $param->moveto = optional_param('moveto',0,PARAM_INT);
27 $param->publish = optional_param('publish',0,PARAM_INT);
2c49e710 28 $param->addcategory = optional_param('addcategory','',PARAM_NOTAGS);
516cf3eb 29 $param->edit = optional_param('edit',0,PARAM_INT);
30 $param->updateid = optional_param('updateid',0,PARAM_INT);
31 $param->page = optional_param('page',1,PARAM_INT);
32
33 if (! $course = get_record("course", "id", $id)) {
34 error("Course ID is incorrect");
35 }
3765fd53 36
37 $context = get_context_instance(CONTEXT_COURSE, $id);
38
516cf3eb 39 require_login($course->id, false);
3765fd53 40 require_capability('moodle/question:managecategory', $context);
516cf3eb 41
dc1f00de 42 $qcobject = new question_category_object();
516cf3eb 43 $qcobject->set_course($course);
44
45 //==========
46 // PAGE HEADER
47 //==========
48
e586cfb4 49 // TODO: generalise this to any activity
516cf3eb 50 if (isset($SESSION->modform->instance) and $quiz = get_record('quiz', 'id', $SESSION->modform->instance)) {
51 $strupdatemodule = isteacheredit($course->id)
52 ? update_module_button($SESSION->modform->cmid, $course->id, get_string('modulename', 'quiz'))
53 : "";
54 print_header_simple(get_string('editcategories', 'quiz'), '',
e586cfb4 55 "<a href=\"$CFG->wwwroot/mod/quiz/index.php?id=$course->id\">".get_string('modulenameplural', 'quiz').'</a>'.
56 " -> <a href=\"$CFG->wwwroot/mod/quiz/view.php?q=$quiz->id\">".format_string($quiz->name).'</a>'.
516cf3eb 57 ' -> '.get_string('editcategories', 'quiz'),
58 "", "", true, $strupdatemodule);
59 $currenttab = 'edit';
60 $mode = 'categories';
e586cfb4 61 include($CFG->dirroot.'/mod/quiz/tabs.php');
516cf3eb 62 } else {
2662cf46 63 print_header_simple(get_string('editcategories', 'quiz'), '', get_string('editcategories', 'quiz'));
567709c4 64
65 // print tabs
66 $currenttab = 'categories';
67 include('tabs.php');
516cf3eb 68 }
69
70 //==========
71 // ACTIONS
72 //==========
73
74 if (isset($_REQUEST['sesskey']) and confirm_sesskey()) { // sesskey must be ok
75 if (!empty($param->delete) and empty($param->cancel)) {
76 if (!empty($param->confirm)) {
77 /// 'confirm' is the category to move existing questions to
78 $qcobject->delete_category($param->delete, $param->confirm);
79 } else {
80 $qcobject->delete_category($param->delete);
81 }
82 } else if (!empty($param->moveup)) {
83 $qcobject->move_category_up_down('up', $param->moveup);
84 } else if (!empty($param->movedown)) {
85 $qcobject->move_category_up_down('down', $param->movedown);
86 } else if (!empty($param->hide)) {
87 $qcobject->publish_category(false, $param->hide);
68d07f8b 88 } else if (!empty($param->move)) {
516cf3eb 89 $qcobject->move_category($param->move, $param->moveto);
90 } else if (!empty($param->publish)) {
91 $qcobject->publish_category(true, $param->publish);
92 } else if (!empty($param->addcategory)) {
93 $param->newparent = required_param('newparent',PARAM_INT);
a60a7b0d 94 $param->newcategory = required_param('newcategory',PARAM_NOTAGS);
95 $param->newinfo = required_param('newinfo',PARAM_NOTAGS);
516cf3eb 96 $param->newpublish = required_param('newpublish',PARAM_INT);
97 $qcobject->add_category($param->newparent, $param->newcategory, $param->newinfo,
98 $param->newpublish, $course->id);
99 } else if (!empty($param->edit)) {
100 $qcobject->edit_single_category($param->edit, $param->page);
101 } else if (!empty($param->updateid)) {
102 $param->updateparent = required_param('updateparent',PARAM_INT);
a60a7b0d 103 $param->updatename = required_param('updatename',PARAM_NOTAGS);
104 $param->updateinfo = required_param('updateinfo',PARAM_NOTAGS);
516cf3eb 105 $param->updatepublish = required_param('updatepublish',PARAM_INT);
106 $qcobject->update_category($param->updateid, $param->updateparent, $param->updatename,
107 $param->updateinfo, $param->updatepublish, $course->id);
108 }
109 }
110
111 //==========
112 // DISPLAY
113 //==========
114
115 // display the user interface
116 $qcobject->display_user_interface($param->page);
117
118 print_footer($course);
119
120
121
122
123?>