Automatic installer.php lang files by installer_builder (20060913)
[moodle.git] / question / category.php
blobc0ef9ef01a051f660c07263003ec871e9b50ccf0
1 <?php // $Id$
2 /**
3 * Allows a teacher to create, edit and delete categories
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
9 * @package question
12 require_once("../config.php");
13 require_once("editlib.php");
14 require_once("category_class.php");
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);
28 $param->addcategory = optional_param('addcategory','',PARAM_NOTAGS);
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);
33 if (! $course = get_record("course", "id", $id)) {
34 error("Course ID is incorrect");
37 require_login($course->id, false);
39 if (!isteacheredit($course->id)) {
40 error("Only teachers authorized to edit the course '{$course->fullname}' can use this page!");
43 $qcobject = new question_category_object();
44 $qcobject->set_course($course);
46 //==========
47 // PAGE HEADER
48 //==========
50 // TODO: generalise this to any activity
51 if (isset($SESSION->modform->instance) and $quiz = get_record('quiz', 'id', $SESSION->modform->instance)) {
52 $strupdatemodule = isteacheredit($course->id)
53 ? update_module_button($SESSION->modform->cmid, $course->id, get_string('modulename', 'quiz'))
54 : "";
55 print_header_simple(get_string('editcategories', 'quiz'), '',
56 "<a href=\"$CFG->wwwroot/mod/quiz/index.php?id=$course->id\">".get_string('modulenameplural', 'quiz').'</a>'.
57 " -> <a href=\"$CFG->wwwroot/mod/quiz/view.php?q=$quiz->id\">".format_string($quiz->name).'</a>'.
58 ' -> '.get_string('editcategories', 'quiz'),
59 "", "", true, $strupdatemodule);
60 $currenttab = 'edit';
61 $mode = 'categories';
62 include($CFG->dirroot.'/mod/quiz/tabs.php');
63 } else {
64 print_header_simple(get_string('editcategories', 'quiz'), '', get_string('editcategories', 'quiz'));
66 // print tabs
67 $currenttab = 'categories';
68 include('tabs.php');
71 //==========
72 // ACTIONS
73 //==========
75 if (isset($_REQUEST['sesskey']) and confirm_sesskey()) { // sesskey must be ok
76 if (!empty($param->delete) and empty($param->cancel)) {
77 if (!empty($param->confirm)) {
78 /// 'confirm' is the category to move existing questions to
79 $qcobject->delete_category($param->delete, $param->confirm);
80 } else {
81 $qcobject->delete_category($param->delete);
83 } else if (!empty($param->moveup)) {
84 $qcobject->move_category_up_down('up', $param->moveup);
85 } else if (!empty($param->movedown)) {
86 $qcobject->move_category_up_down('down', $param->movedown);
87 } else if (!empty($param->hide)) {
88 $qcobject->publish_category(false, $param->hide);
89 } else if (!empty($param->move)) {
90 $qcobject->move_category($param->move, $param->moveto);
91 } else if (!empty($param->publish)) {
92 $qcobject->publish_category(true, $param->publish);
93 } else if (!empty($param->addcategory)) {
94 $param->newparent = required_param('newparent',PARAM_INT);
95 $param->newcategory = required_param('newcategory',PARAM_NOTAGS);
96 $param->newinfo = required_param('newinfo',PARAM_NOTAGS);
97 $param->newpublish = required_param('newpublish',PARAM_INT);
98 $qcobject->add_category($param->newparent, $param->newcategory, $param->newinfo,
99 $param->newpublish, $course->id);
100 } else if (!empty($param->edit)) {
101 $qcobject->edit_single_category($param->edit, $param->page);
102 } else if (!empty($param->updateid)) {
103 $param->updateparent = required_param('updateparent',PARAM_INT);
104 $param->updatename = required_param('updatename',PARAM_NOTAGS);
105 $param->updateinfo = required_param('updateinfo',PARAM_NOTAGS);
106 $param->updatepublish = required_param('updatepublish',PARAM_INT);
107 $qcobject->update_category($param->updateid, $param->updateparent, $param->updatename,
108 $param->updateinfo, $param->updatepublish, $course->id);
112 //==========
113 // DISPLAY
114 //==========
116 // display the user interface
117 $qcobject->display_user_interface($param->page);
119 print_footer($course);