Updated questionlib to work with the new location of the question scripts
[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
9* @package quiz
10*/
11
12 require_once("../../config.php");
13 require_once("locallib.php");
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);
28 $param->addcategory = optional_param('addcategory','',PARAM_ALPHA);
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 }
36
37 if (isset($_REQUEST['backtoquiz'])) {
38 redirect("edit.php");
39 }
40
41 require_login($course->id, false);
42
43 if (!isteacheredit($course->id)) {
44 error("Only teachers authorized to edit the course '{$course->fullname}' can use this page!");
45 }
46
47 $qcobject = new quiz_category_object();
48 $qcobject->set_course($course);
49
50 //==========
51 // PAGE HEADER
52 //==========
53
54 if (isset($SESSION->modform->instance) and $quiz = get_record('quiz', 'id', $SESSION->modform->instance)) {
55 $strupdatemodule = isteacheredit($course->id)
56 ? update_module_button($SESSION->modform->cmid, $course->id, get_string('modulename', 'quiz'))
57 : "";
58 print_header_simple(get_string('editcategories', 'quiz'), '',
59 "<a href=\"index.php?id=$course->id\">".get_string('modulenameplural', 'quiz').'</a>'.
60 " -> <a href=\"view.php?q=$quiz->id\">".format_string($quiz->name).'</a>'.
61 ' -> '.get_string('editcategories', 'quiz'),
62 "", "", true, $strupdatemodule);
63 $currenttab = 'edit';
64 $mode = 'categories';
65 include('tabs.php');
66 } else {
67 print_header_simple(get_string('editcategories', 'quiz'), '',
68 "<a href=\"index.php?id=$course->id\">".get_string('modulenameplural', 'quiz').'</a>'.
69 '-> <a href="edit.php">'.get_string('editquestions', 'quiz').'</a>'.
70 ' -> '.get_string('editcategories', 'quiz'));
71 }
72
73 //==========
74 // ACTIONS
75 //==========
76
77 if (isset($_REQUEST['sesskey']) and confirm_sesskey()) { // sesskey must be ok
78 if (!empty($param->delete) and empty($param->cancel)) {
79 if (!empty($param->confirm)) {
80 /// 'confirm' is the category to move existing questions to
81 $qcobject->delete_category($param->delete, $param->confirm);
82 } else {
83 $qcobject->delete_category($param->delete);
84 }
85 } else if (!empty($param->moveup)) {
86 $qcobject->move_category_up_down('up', $param->moveup);
87 } else if (!empty($param->movedown)) {
88 $qcobject->move_category_up_down('down', $param->movedown);
89 } else if (!empty($param->hide)) {
90 $qcobject->publish_category(false, $param->hide);
91 } else if (!empty($param->move) and !empty($param->moveto)) {
92 $qcobject->move_category($param->move, $param->moveto);
93 } else if (!empty($param->publish)) {
94 $qcobject->publish_category(true, $param->publish);
95 } else if (!empty($param->addcategory)) {
96 $param->newparent = required_param('newparent',PARAM_INT);
97 $param->newcategory = required_param('newcategory',PARAM_ALPHANUM);
98 $param->newinfo = required_param('newinfo',PARAM_CLEAN);
99 $param->newpublish = required_param('newpublish',PARAM_INT);
100 $qcobject->add_category($param->newparent, $param->newcategory, $param->newinfo,
101 $param->newpublish, $course->id);
102 } else if (!empty($param->edit)) {
103 $qcobject->edit_single_category($param->edit, $param->page);
104 } else if (!empty($param->updateid)) {
105 $param->updateparent = required_param('updateparent',PARAM_INT);
106 $param->updatename = required_param('updatename',PARAM_ALPHANUM);
107 $param->updateinfo = required_param('updateinfo',PARAM_CLEAN);
108 $param->updatepublish = required_param('updatepublish',PARAM_INT);
109 $qcobject->update_category($param->updateid, $param->updateparent, $param->updatename,
110 $param->updateinfo, $param->updatepublish, $course->id);
111 }
112 }
113
114 //==========
115 // DISPLAY
116 //==========
117
118 // display the user interface
119 $qcobject->display_user_interface($param->page);
120
121 print_footer($course);
122
123
124
125
126?>