change to print_paging_bar function to optionally support the use of a moodle_url...
[moodle.git] / question / category.php
1 <?php // $Id$
2 /**
3  * Allows a teacher to create, edit and delete categories
4  *
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
9  */
11     require_once("../config.php");
12     require_once("editlib.php");
13     require_once("category_class.php");
15     // get values from form
16     $param = new stdClass();
18     $id = required_param('courseid', PARAM_INT);   // course id
19     $param->page = optional_param('page', 1, PARAM_INT);
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);
36     if (! $course = get_record("course", "id", $id)) {
37         error("Course ID is incorrect");
38     }
40     $context = get_context_instance(CONTEXT_COURSE, $id);
42     require_login($course->id, false);
43     require_capability('moodle/question:managecategory', $context);
45     $qcobject = new question_category_object($param->page);
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
52         $strupdatemodule = has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $course->id))
53             ? update_module_button($SESSION->modform->cmid, $course->id, get_string('modulename', 'quiz'))
54             : "";
55         print_header_simple(get_string('editcategories', 'quiz'), '',
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>'.
58                  ' -> '.get_string('editcategories', 'quiz'),
59                  "", "", true, $strupdatemodule);
60         $currenttab = 'edit';
61         $mode = 'categories';
62         include($CFG->dirroot.'/mod/quiz/tabs.php');
63     } else {
64         print_header_simple(get_string('editcategories', 'quiz'), '', get_string('editcategories', 'quiz'));
66         // print tabs
67         $currenttab = 'categories';
68         include('tabs.php');
69     }
71     // Process actions.
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             }
80         } else if (!empty($param->hide)) {
81             $qcobject->publish_category(false, $param->hide);
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);
86             $param->newcategory = required_param('newcategory',PARAM_NOTAGS);
87             $param->newinfo     = required_param('newinfo',PARAM_NOTAGS);
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);
95             $param->updatename    = required_param('updatename',PARAM_NOTAGS);
96             $param->updateinfo    = required_param('updateinfo',PARAM_NOTAGS);
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     }
103     // display the user interface
104     $qcobject->display_user_interface();
106     print_footer($course);
107 ?>