question category is not remembered correctly by import and export pages, fixing...
[moodle.git] / question / category.php
CommitLineData
516cf3eb 1<?php // $Id$
2/**
3* Allows a teacher to create, edit and delete categories
4*
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
e586cfb4 9* @package question
516cf3eb 10*/
11
e586cfb4 12 require_once("../config.php");
13 require_once($CFG->libdir.'/questionlib.php');
516cf3eb 14 require_once("category_class.php");
15
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);
2c49e710 28 $param->addcategory = optional_param('addcategory','',PARAM_NOTAGS);
516cf3eb 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);
32
33 if (! $course = get_record("course", "id", $id)) {
34 error("Course ID is incorrect");
35 }
36
516cf3eb 37 require_login($course->id, false);
38
39 if (!isteacheredit($course->id)) {
40 error("Only teachers authorized to edit the course '{$course->fullname}' can use this page!");
41 }
42
dc1f00de 43 $qcobject = new question_category_object();
516cf3eb 44 $qcobject->set_course($course);
45
46 //==========
47 // PAGE HEADER
48 //==========
49
e586cfb4 50 // TODO: generalise this to any activity
516cf3eb 51 if (isset($SESSION->modform->instance) and $quiz = get_record('quiz', 'id', $SESSION->modform->instance)) {
52 $strupdatemodule = isteacheredit($course->id)
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
71 //==========
72 // ACTIONS
73 //==========
74
75 if (isset($_REQUEST['sesskey']) and confirm_sesskey()) { // sesskey must be ok
76 if (!empty($param->delete) and empty($param->cancel)) {
77 if (!empty($param->confirm)) {
78 /// 'confirm' is the category to move existing questions to
79 $qcobject->delete_category($param->delete, $param->confirm);
80 } else {
81 $qcobject->delete_category($param->delete);
82 }
83 } else if (!empty($param->moveup)) {
84 $qcobject->move_category_up_down('up', $param->moveup);
85 } else if (!empty($param->movedown)) {
86 $qcobject->move_category_up_down('down', $param->movedown);
87 } else if (!empty($param->hide)) {
88 $qcobject->publish_category(false, $param->hide);
89 } else if (!empty($param->move) and !empty($param->moveto)) {
90 $qcobject->move_category($param->move, $param->moveto);
91 } else if (!empty($param->publish)) {
92 $qcobject->publish_category(true, $param->publish);
93 } else if (!empty($param->addcategory)) {
94 $param->newparent = required_param('newparent',PARAM_INT);
95 $param->newcategory = required_param('newcategory',PARAM_ALPHANUM);
96 $param->newinfo = required_param('newinfo',PARAM_CLEAN);
97 $param->newpublish = required_param('newpublish',PARAM_INT);
98 $qcobject->add_category($param->newparent, $param->newcategory, $param->newinfo,
99 $param->newpublish, $course->id);
100 } else if (!empty($param->edit)) {
101 $qcobject->edit_single_category($param->edit, $param->page);
102 } else if (!empty($param->updateid)) {
103 $param->updateparent = required_param('updateparent',PARAM_INT);
104 $param->updatename = required_param('updatename',PARAM_ALPHANUM);
105 $param->updateinfo = required_param('updateinfo',PARAM_CLEAN);
106 $param->updatepublish = required_param('updatepublish',PARAM_INT);
107 $qcobject->update_category($param->updateid, $param->updateparent, $param->updatename,
108 $param->updateinfo, $param->updatepublish, $course->id);
109 }
110 }
111
112 //==========
113 // DISPLAY
114 //==========
115
116 // display the user interface
117 $qcobject->display_user_interface($param->page);
118
119 print_footer($course);
120
121
122
123
124?>