Automatic installer.php lang files by installer_builder (20070224)
[moodle.git] / question / category.php
blob8b75156d5b36a2d8d3904bded0b366118c2c5b9f
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
10 *//** */
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 // Page header
47 // TODO: generalise this to any activity
48 if (isset($SESSION->modform->instance) and $quiz = get_record('quiz', 'id', $SESSION->modform->instance)) {
49 $strupdatemodule = isteacheredit($course->id)
50 ? update_module_button($SESSION->modform->cmid, $course->id, get_string('modulename', 'quiz'))
51 : "";
52 print_header_simple(get_string('editcategories', 'quiz'), '',
53 "<a href=\"$CFG->wwwroot/mod/quiz/index.php?id=$course->id\">".get_string('modulenameplural', 'quiz').'</a>'.
54 " -> <a href=\"$CFG->wwwroot/mod/quiz/view.php?q=$quiz->id\">".format_string($quiz->name).'</a>'.
55 ' -> '.get_string('editcategories', 'quiz'),
56 "", "", true, $strupdatemodule);
57 $currenttab = 'edit';
58 $mode = 'categories';
59 include($CFG->dirroot.'/mod/quiz/tabs.php');
60 } else {
61 print_header_simple(get_string('editcategories', 'quiz'), '', get_string('editcategories', 'quiz'));
63 // print tabs
64 $currenttab = 'categories';
65 include('tabs.php');
68 // Process actions.
69 if (isset($_REQUEST['sesskey']) and confirm_sesskey()) { // sesskey must be ok
70 if (!empty($param->delete) and empty($param->cancel)) {
71 if (!empty($param->confirm)) {
72 /// 'confirm' is the category to move existing questions to
73 $qcobject->delete_category($param->delete, $param->confirm);
74 } else {
75 $qcobject->delete_category($param->delete);
77 } else if (!empty($param->moveup)) {
78 $qcobject->move_category_up_down('up', $param->moveup);
79 } else if (!empty($param->movedown)) {
80 $qcobject->move_category_up_down('down', $param->movedown);
81 } else if (!empty($param->hide)) {
82 $qcobject->publish_category(false, $param->hide);
83 } else if (!empty($param->move)) {
84 $qcobject->move_category($param->move, $param->moveto);
85 } else if (!empty($param->publish)) {
86 $qcobject->publish_category(true, $param->publish);
87 } else if (!empty($param->addcategory)) {
88 $param->newparent = required_param('newparent',PARAM_INT);
89 $param->newcategory = required_param('newcategory',PARAM_NOTAGS);
90 $param->newinfo = required_param('newinfo',PARAM_NOTAGS);
91 $param->newpublish = required_param('newpublish',PARAM_INT);
92 $qcobject->add_category($param->newparent, $param->newcategory, $param->newinfo,
93 $param->newpublish, $course->id);
94 } else if (!empty($param->edit)) {
95 $qcobject->edit_single_category($param->edit, $param->page);
96 } else if (!empty($param->updateid)) {
97 $param->updateparent = required_param('updateparent',PARAM_INT);
98 $param->updatename = required_param('updatename',PARAM_NOTAGS);
99 $param->updateinfo = required_param('updateinfo',PARAM_NOTAGS);
100 $param->updatepublish = required_param('updatepublish',PARAM_INT);
101 $qcobject->update_category($param->updateid, $param->updateparent, $param->updatename,
102 $param->updateinfo, $param->updatepublish, $course->id);
106 // display the user interface
107 $qcobject->display_user_interface($param->page);
109 print_footer($course);