merging MOODLE_19_QUESTIONS with HEAD
[moodle.git] / question / category.php
CommitLineData
516cf3eb 1<?php // $Id$
2/**
bc649d80 3 * Allows a teacher to create, edit and delete categories
4 *
bc649d80 5 * @author Martin Dougiamas and many others.
6 * {@link http://moodle.org}
7 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
4323d029 8 * @package questionbank
bc649d80 9 */
516cf3eb 10
e586cfb4 11 require_once("../config.php");
4fbfd971 12 require_once("editlib.php");
516cf3eb 13 require_once("category_class.php");
14
b72ff476 15
16
17 list($thispageurl, $courseid, $cmid, $cm, $module, $pagevars) = question_edit_setup();
18
19
20 // get values from form for actions on this page
516cf3eb 21 $param = new stdClass();
dac786f3 22
dac786f3 23
24 $param->moveup = optional_param('moveup', 0, PARAM_INT);
25 $param->movedown = optional_param('movedown', 0, PARAM_INT);
26 $param->left = optional_param('left', 0, PARAM_INT);
27 $param->right = optional_param('right', 0, PARAM_INT);
28 $param->hide = optional_param('hide', 0, PARAM_INT);
29 $param->delete = optional_param('delete', 0, PARAM_INT);
30 $param->confirm = optional_param('confirm', 0, PARAM_INT);
31 $param->cancel = optional_param('cancel', '', PARAM_ALPHA);
32 $param->move = optional_param('move', 0, PARAM_INT);
33 $param->moveto = optional_param('moveto', 0, PARAM_INT);
34 $param->publish = optional_param('publish', 0, PARAM_INT);
35 $param->addcategory = optional_param('addcategory', '', PARAM_NOTAGS);
36 $param->edit = optional_param('edit', 0, PARAM_INT);
37 $param->updateid = optional_param('updateid', 0, PARAM_INT);
516cf3eb 38
b72ff476 39 if (! $course = get_record("course", "id", $courseid)) {
516cf3eb 40 error("Course ID is incorrect");
41 }
dac786f3 42
b72ff476 43 $context = get_context_instance(CONTEXT_COURSE, $courseid);
dac786f3 44
3765fd53 45 require_capability('moodle/question:managecategory', $context);
516cf3eb 46
986effb6 47 $qcobject = new question_category_object($pagevars['cpage'], $thispageurl);
516cf3eb 48
b72ff476 49 $streditingcategories = get_string('editcategories', 'quiz');
dac786f3 50 if ($qcobject->editlist->process_actions($param->left, $param->right, $param->moveup, $param->movedown)) {
51 //processing of these actions is handled in the method and page redirects.
b72ff476 52 } else if ($cm!==null) {
dac786f3 53 // Page header
17d6a25e 54 $strupdatemodule = has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $course->id))
b72ff476 55 ? update_module_button($cm->id, $course->id, get_string('modulename', $cm->modname))
516cf3eb 56 : "";
3b27b0fe 57 $navlinks = array();
58 $navlinks[] = array('name' => get_string('modulenameplural', $cm->modname),
b72ff476 59 'link' => "$CFG->wwwroot/mod/{$cm->modname}/index.php?id=$course->id",
60 'type' => 'activity');
3b27b0fe 61 $navlinks[] = array('name' => format_string($module->name),
b72ff476 62 'link' => "$CFG->wwwroot/mod/{$cm->modname}/view.php?cmid={$cm->id}",
63 'type' => 'title');
3b27b0fe 64 $navlinks[] = array('name' => $streditingcategories, 'link' => '', 'type' => 'title');
65 $navigation = build_navigation($navlinks);
b72ff476 66 print_header_simple($streditingcategories, '', $navigation, "", "", true, $strupdatemodule);
67
68
516cf3eb 69 $currenttab = 'edit';
70 $mode = 'categories';
b72ff476 71 ${$cm->modname} = $module;
72 include($CFG->dirroot."/mod/{$cm->modname}/tabs.php");
516cf3eb 73 } else {
b72ff476 74 // Print basic page layout.
3b27b0fe 75 $navlinks = array();
76 $navlinks[] = array('name' => $streditingcategories, 'link' => '', 'type' => 'title');
77 $navigation = build_navigation($navlinks);
b72ff476 78
79 print_header_simple($streditingcategories, '', $navigation);
567709c4 80
81 // print tabs
82 $currenttab = 'categories';
83 include('tabs.php');
516cf3eb 84 }
85
bc649d80 86 // Process actions.
516cf3eb 87 if (isset($_REQUEST['sesskey']) and confirm_sesskey()) { // sesskey must be ok
88 if (!empty($param->delete) and empty($param->cancel)) {
89 if (!empty($param->confirm)) {
90 /// 'confirm' is the category to move existing questions to
91 $qcobject->delete_category($param->delete, $param->confirm);
92 } else {
93 $qcobject->delete_category($param->delete);
94 }
516cf3eb 95 } else if (!empty($param->hide)) {
96 $qcobject->publish_category(false, $param->hide);
516cf3eb 97 } else if (!empty($param->publish)) {
98 $qcobject->publish_category(true, $param->publish);
99 } else if (!empty($param->addcategory)) {
100 $param->newparent = required_param('newparent',PARAM_INT);
a60a7b0d 101 $param->newcategory = required_param('newcategory',PARAM_NOTAGS);
102 $param->newinfo = required_param('newinfo',PARAM_NOTAGS);
516cf3eb 103 $param->newpublish = required_param('newpublish',PARAM_INT);
104 $qcobject->add_category($param->newparent, $param->newcategory, $param->newinfo,
105 $param->newpublish, $course->id);
106 } else if (!empty($param->edit)) {
986effb6 107 $qcobject->edit_single_category($param->edit, $pagevars['cpage']);
516cf3eb 108 } else if (!empty($param->updateid)) {
109 $param->updateparent = required_param('updateparent',PARAM_INT);
a60a7b0d 110 $param->updatename = required_param('updatename',PARAM_NOTAGS);
111 $param->updateinfo = required_param('updateinfo',PARAM_NOTAGS);
516cf3eb 112 $param->updatepublish = required_param('updatepublish',PARAM_INT);
113 $qcobject->update_category($param->updateid, $param->updateparent, $param->updatename,
114 $param->updateinfo, $param->updatepublish, $course->id);
115 }
116 }
117
516cf3eb 118 // display the user interface
dac786f3 119 $qcobject->display_user_interface();
516cf3eb 120
121 print_footer($course);
516cf3eb 122?>