3 * Allows a teacher to create, edit and delete categories
5 * @author Martin Dougiamas and many others.
6 * {@link http://moodle.org}
7 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
8 * @package questionbank
11 require_once("../config.php");
12 require_once("editlib.php");
13 require_once("category_class.php");
17 list($thispageurl, $courseid, $cmid, $cm, $module, $pagevars) = question_edit_setup();
20 // get values from form for actions on this page
21 $param = new stdClass();
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
);
39 if (! $course = get_record("course", "id", $courseid)) {
40 error("Course ID is incorrect");
43 $context = get_context_instance(CONTEXT_COURSE
, $courseid);
45 require_capability('moodle/question:managecategory', $context);
47 $qcobject = new question_category_object($pagevars['cpage'], $thispageurl);
49 $streditingcategories = get_string('editcategories', 'quiz');
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.
52 } else if ($cm!==null) {
54 $strupdatemodule = has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE
, $course->id
))
55 ?
update_module_button($cm->id
, $course->id
, get_string('modulename', $cm->modname
))
58 $navlinks[] = array('name' => get_string('modulenameplural', $cm->modname
),
59 'link' => "$CFG->wwwroot/mod/{$cm->modname}/index.php?id=$course->id",
60 'type' => 'activity');
61 $navlinks[] = array('name' => format_string($module->name
),
62 'link' => "$CFG->wwwroot/mod/{$cm->modname}/view.php?cmid={$cm->id}",
64 $navlinks[] = array('name' => $streditingcategories, 'link' => '', 'type' => 'title');
65 $navigation = build_navigation($navlinks);
66 print_header_simple($streditingcategories, '', $navigation, "", "", true, $strupdatemodule);
71 $
{$cm->modname
} = $module;
72 include($CFG->dirroot
."/mod/{$cm->modname}/tabs.php");
74 // Print basic page layout.
76 $navlinks[] = array('name' => $streditingcategories, 'link' => '', 'type' => 'title');
77 $navigation = build_navigation($navlinks);
79 print_header_simple($streditingcategories, '', $navigation);
82 $currenttab = 'categories';
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
);
93 $qcobject->delete_category($param->delete
);
95 } else if (!empty($param->hide
)) {
96 $qcobject->publish_category(false, $param->hide
);
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
);
101 $param->newcategory
= required_param('newcategory',PARAM_NOTAGS
);
102 $param->newinfo
= required_param('newinfo',PARAM_NOTAGS
);
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
)) {
107 $qcobject->edit_single_category($param->edit
, $pagevars['cpage']);
108 } else if (!empty($param->updateid
)) {
109 $param->updateparent
= required_param('updateparent',PARAM_INT
);
110 $param->updatename
= required_param('updatename',PARAM_NOTAGS
);
111 $param->updateinfo
= required_param('updateinfo',PARAM_NOTAGS
);
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
);
118 // display the user interface
119 $qcobject->display_user_interface();
121 print_footer($course);