Added moodle docs link to footer of the themes. The link is generated by the
[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");
13 require_once($CFG->libdir.'/questionlib.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);
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
516cf3eb 37 require_login($course->id, false);
38
39 if (!isteacheredit($course->id)) {
40 error("Only teachers authorized to edit the course '{$course->fullname}' can use this page!");
41 }
42
dc1f00de 43 $qcobject = new question_category_object();
516cf3eb 44 $qcobject->set_course($course);
45
46 //==========
47 // PAGE HEADER
48 //==========
49
e586cfb4 50 // TODO: generalise this to any activity
516cf3eb 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'), '',
e586cfb4 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>'.
516cf3eb 58 ' -> '.get_string('editcategories', 'quiz'),
59 "", "", true, $strupdatemodule);
60 $currenttab = 'edit';
61 $mode = 'categories';
e586cfb4 62 include($CFG->dirroot.'/mod/quiz/tabs.php');
516cf3eb 63 } else {
64 print_header_simple(get_string('editcategories', 'quiz'), '',
516cf3eb 65 '-> <a href="edit.php">'.get_string('editquestions', 'quiz').'</a>'.
66 ' -> '.get_string('editcategories', 'quiz'));
67 }
68
69 //==========
70 // ACTIONS
71 //==========
72
73 if (isset($_REQUEST['sesskey']) and confirm_sesskey()) { // sesskey must be ok
74 if (!empty($param->delete) and empty($param->cancel)) {
75 if (!empty($param->confirm)) {
76 /// 'confirm' is the category to move existing questions to
77 $qcobject->delete_category($param->delete, $param->confirm);
78 } else {
79 $qcobject->delete_category($param->delete);
80 }
81 } else if (!empty($param->moveup)) {
82 $qcobject->move_category_up_down('up', $param->moveup);
83 } else if (!empty($param->movedown)) {
84 $qcobject->move_category_up_down('down', $param->movedown);
85 } else if (!empty($param->hide)) {
86 $qcobject->publish_category(false, $param->hide);
87 } else if (!empty($param->move) and !empty($param->moveto)) {
88 $qcobject->move_category($param->move, $param->moveto);
89 } else if (!empty($param->publish)) {
90 $qcobject->publish_category(true, $param->publish);
91 } else if (!empty($param->addcategory)) {
92 $param->newparent = required_param('newparent',PARAM_INT);
93 $param->newcategory = required_param('newcategory',PARAM_ALPHANUM);
94 $param->newinfo = required_param('newinfo',PARAM_CLEAN);
95 $param->newpublish = required_param('newpublish',PARAM_INT);
96 $qcobject->add_category($param->newparent, $param->newcategory, $param->newinfo,
97 $param->newpublish, $course->id);
98 } else if (!empty($param->edit)) {
99 $qcobject->edit_single_category($param->edit, $param->page);
100 } else if (!empty($param->updateid)) {
101 $param->updateparent = required_param('updateparent',PARAM_INT);
102 $param->updatename = required_param('updatename',PARAM_ALPHANUM);
103 $param->updateinfo = required_param('updateinfo',PARAM_CLEAN);
104 $param->updatepublish = required_param('updatepublish',PARAM_INT);
105 $qcobject->update_category($param->updateid, $param->updateparent, $param->updatename,
106 $param->updateinfo, $param->updatepublish, $course->id);
107 }
108 }
109
110 //==========
111 // DISPLAY
112 //==========
113
114 // display the user interface
115 $qcobject->display_user_interface($param->page);
116
117 print_footer($course);
118
119
120
121
122?>