Output was missing utf8 meta tag.
[moodle-linuxchix.git] / question / category.php
blobde930d203540b676fef193fd399c70a1d764d7f9
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 $context = get_context_instance(CONTEXT_COURSE, $id);
39 require_login($course->id, false);
40 require_capability('moodle/question:managecategory', $context);
42 $qcobject = new question_category_object();
43 $qcobject->set_course($course);
45 // Page header
46 // TODO: generalise this to any activity
47 if (isset($SESSION->modform->instance) and $quiz = get_record('quiz', 'id', $SESSION->modform->instance)) {
48 $strupdatemodule = has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $course->id))
49 ? update_module_button($SESSION->modform->cmid, $course->id, get_string('modulename', 'quiz'))
50 : "";
51 print_header_simple(get_string('editcategories', 'quiz'), '',
52 "<a href=\"$CFG->wwwroot/mod/quiz/index.php?id=$course->id\">".get_string('modulenameplural', 'quiz').'</a>'.
53 " -> <a href=\"$CFG->wwwroot/mod/quiz/view.php?q=$quiz->id\">".format_string($quiz->name).'</a>'.
54 ' -> '.get_string('editcategories', 'quiz'),
55 "", "", true, $strupdatemodule);
56 $currenttab = 'edit';
57 $mode = 'categories';
58 include($CFG->dirroot.'/mod/quiz/tabs.php');
59 } else {
60 print_header_simple(get_string('editcategories', 'quiz'), '', get_string('editcategories', 'quiz'));
62 // print tabs
63 $currenttab = 'categories';
64 include('tabs.php');
67 // Process actions.
68 if (isset($_REQUEST['sesskey']) and confirm_sesskey()) { // sesskey must be ok
69 if (!empty($param->delete) and empty($param->cancel)) {
70 if (!empty($param->confirm)) {
71 /// 'confirm' is the category to move existing questions to
72 $qcobject->delete_category($param->delete, $param->confirm);
73 } else {
74 $qcobject->delete_category($param->delete);
76 } else if (!empty($param->moveup)) {
77 $qcobject->move_category_up_down('up', $param->moveup);
78 } else if (!empty($param->movedown)) {
79 $qcobject->move_category_up_down('down', $param->movedown);
80 } else if (!empty($param->hide)) {
81 $qcobject->publish_category(false, $param->hide);
82 } else if (!empty($param->move)) {
83 $qcobject->move_category($param->move, $param->moveto);
84 } else if (!empty($param->publish)) {
85 $qcobject->publish_category(true, $param->publish);
86 } else if (!empty($param->addcategory)) {
87 $param->newparent = required_param('newparent',PARAM_INT);
88 $param->newcategory = required_param('newcategory',PARAM_NOTAGS);
89 $param->newinfo = required_param('newinfo',PARAM_NOTAGS);
90 $param->newpublish = required_param('newpublish',PARAM_INT);
91 $qcobject->add_category($param->newparent, $param->newcategory, $param->newinfo,
92 $param->newpublish, $course->id);
93 } else if (!empty($param->edit)) {
94 $qcobject->edit_single_category($param->edit, $param->page);
95 } else if (!empty($param->updateid)) {
96 $param->updateparent = required_param('updateparent',PARAM_INT);
97 $param->updatename = required_param('updatename',PARAM_NOTAGS);
98 $param->updateinfo = required_param('updateinfo',PARAM_NOTAGS);
99 $param->updatepublish = required_param('updatepublish',PARAM_INT);
100 $qcobject->update_category($param->updateid, $param->updateparent, $param->updatename,
101 $param->updateinfo, $param->updatepublish, $course->id);
105 // display the user interface
106 $qcobject->display_user_interface($param->page);
108 print_footer($course);