change to print_paging_bar function to optionally support the use of a moodle_url...
[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
15 // get values from form
16 $param = new stdClass();
dac786f3 17
71e0eda8 18 $id = required_param('courseid', PARAM_INT); // course id
dac786f3 19 $param->page = optional_param('page', 1, PARAM_INT);
20
21 $param->moveup = optional_param('moveup', 0, PARAM_INT);
22 $param->movedown = optional_param('movedown', 0, PARAM_INT);
23 $param->left = optional_param('left', 0, PARAM_INT);
24 $param->right = optional_param('right', 0, PARAM_INT);
25 $param->hide = optional_param('hide', 0, PARAM_INT);
26 $param->delete = optional_param('delete', 0, PARAM_INT);
27 $param->confirm = optional_param('confirm', 0, PARAM_INT);
28 $param->cancel = optional_param('cancel', '', PARAM_ALPHA);
29 $param->move = optional_param('move', 0, PARAM_INT);
30 $param->moveto = optional_param('moveto', 0, PARAM_INT);
31 $param->publish = optional_param('publish', 0, PARAM_INT);
32 $param->addcategory = optional_param('addcategory', '', PARAM_NOTAGS);
33 $param->edit = optional_param('edit', 0, PARAM_INT);
34 $param->updateid = optional_param('updateid', 0, PARAM_INT);
516cf3eb 35
36 if (! $course = get_record("course", "id", $id)) {
37 error("Course ID is incorrect");
38 }
dac786f3 39
3765fd53 40 $context = get_context_instance(CONTEXT_COURSE, $id);
dac786f3 41
516cf3eb 42 require_login($course->id, false);
3765fd53 43 require_capability('moodle/question:managecategory', $context);
516cf3eb 44
dac786f3 45 $qcobject = new question_category_object($param->page);
516cf3eb 46
dac786f3 47 if ($qcobject->editlist->process_actions($param->left, $param->right, $param->moveup, $param->movedown)) {
48 //processing of these actions is handled in the method and page redirects.
49 } else if (isset($SESSION->modform->instance) and $quiz = get_record('quiz', 'id', $SESSION->modform->instance)) {
50 // Page header
51 // TODO: generalise this to any activity
17d6a25e 52 $strupdatemodule = has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $course->id))
516cf3eb 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 {
2662cf46 64 print_header_simple(get_string('editcategories', 'quiz'), '', get_string('editcategories', 'quiz'));
567709c4 65
66 // print tabs
67 $currenttab = 'categories';
68 include('tabs.php');
516cf3eb 69 }
70
bc649d80 71 // Process actions.
516cf3eb 72 if (isset($_REQUEST['sesskey']) and confirm_sesskey()) { // sesskey must be ok
73 if (!empty($param->delete) and empty($param->cancel)) {
74 if (!empty($param->confirm)) {
75 /// 'confirm' is the category to move existing questions to
76 $qcobject->delete_category($param->delete, $param->confirm);
77 } else {
78 $qcobject->delete_category($param->delete);
79 }
516cf3eb 80 } else if (!empty($param->hide)) {
81 $qcobject->publish_category(false, $param->hide);
516cf3eb 82 } else if (!empty($param->publish)) {
83 $qcobject->publish_category(true, $param->publish);
84 } else if (!empty($param->addcategory)) {
85 $param->newparent = required_param('newparent',PARAM_INT);
a60a7b0d 86 $param->newcategory = required_param('newcategory',PARAM_NOTAGS);
87 $param->newinfo = required_param('newinfo',PARAM_NOTAGS);
516cf3eb 88 $param->newpublish = required_param('newpublish',PARAM_INT);
89 $qcobject->add_category($param->newparent, $param->newcategory, $param->newinfo,
90 $param->newpublish, $course->id);
91 } else if (!empty($param->edit)) {
92 $qcobject->edit_single_category($param->edit, $param->page);
93 } else if (!empty($param->updateid)) {
94 $param->updateparent = required_param('updateparent',PARAM_INT);
a60a7b0d 95 $param->updatename = required_param('updatename',PARAM_NOTAGS);
96 $param->updateinfo = required_param('updateinfo',PARAM_NOTAGS);
516cf3eb 97 $param->updatepublish = required_param('updatepublish',PARAM_INT);
98 $qcobject->update_category($param->updateid, $param->updateparent, $param->updatename,
99 $param->updateinfo, $param->updatepublish, $course->id);
100 }
101 }
102
516cf3eb 103 // display the user interface
dac786f3 104 $qcobject->display_user_interface();
516cf3eb 105
106 print_footer($course);
516cf3eb 107?>