File: category.php

package info (click to toggle)
moodle 1.6.3-2%2Betch3
  • links: PTS
  • area: main
  • in suites: etch
  • size: 37,172 kB
  • ctags: 51,688
  • sloc: php: 231,916; sql: 5,631; xml: 2,688; sh: 1,185; perl: 638; makefile: 48; pascal: 36
file content (124 lines) | stat: -rw-r--r-- 5,278 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php // $Id: category.php,v 1.8.2.1 2006/07/06 10:07:02 tjhunt Exp $
/**
* Allows a teacher to create, edit and delete categories
*
* @version $Id: category.php,v 1.8.2.1 2006/07/06 10:07:02 tjhunt Exp $
* @author Martin Dougiamas and many others.
*         {@link http://moodle.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package question
*/

    require_once("../config.php");
    require_once("editlib.php");
    require_once("category_class.php");

    // get values from form
    $param = new stdClass();
    $id = required_param('id',PARAM_INT);   // course id
    $param->moveup = optional_param('moveup',0,PARAM_INT);
    $param->movedown = optional_param('movedown',0,PARAM_INT);
    $param->hide = optional_param('hide',0,PARAM_INT);
    $param->delete = optional_param('delete',0,PARAM_INT);
    $param->confirm = optional_param('confirm',0,PARAM_INT);
    $param->cancel = optional_param('cancel','',PARAM_ALPHA);
    $param->move = optional_param('move',0,PARAM_INT);
    $param->moveto = optional_param('moveto',0,PARAM_INT);
    $param->publish = optional_param('publish',0,PARAM_INT);
    $param->addcategory = optional_param('addcategory','',PARAM_NOTAGS);
    $param->edit = optional_param('edit',0,PARAM_INT);
    $param->updateid = optional_param('updateid',0,PARAM_INT);
    $param->page = optional_param('page',1,PARAM_INT);

    if (! $course = get_record("course", "id", $id)) {
        error("Course ID is incorrect");
    }

    require_login($course->id, false);

    if (!isteacheredit($course->id)) {
        error("Only teachers authorized to edit the course '{$course->fullname}' can use this page!");
    }

    $qcobject = new question_category_object();
    $qcobject->set_course($course);

    //==========
    // PAGE HEADER
    //==========

    // TODO: generalise this to any activity
    if (isset($SESSION->modform->instance) and $quiz = get_record('quiz', 'id', $SESSION->modform->instance)) {
        $strupdatemodule = isteacheredit($course->id)
            ? update_module_button($SESSION->modform->cmid, $course->id, get_string('modulename', 'quiz'))
            : "";
        print_header_simple(get_string('editcategories', 'quiz'), '',
                 "<a href=\"$CFG->wwwroot/mod/quiz/index.php?id=$course->id\">".get_string('modulenameplural', 'quiz').'</a>'.
                 " -> <a href=\"$CFG->wwwroot/mod/quiz/view.php?q=$quiz->id\">".format_string($quiz->name).'</a>'.
                 ' -> '.get_string('editcategories', 'quiz'),
                 "", "", true, $strupdatemodule);
        $currenttab = 'edit';
        $mode = 'categories';
        include($CFG->dirroot.'/mod/quiz/tabs.php');
    } else {
        print_header_simple(get_string('editcategories', 'quiz'), '', get_string('editcategories', 'quiz'));

        // print tabs
        $currenttab = 'categories';
        include('tabs.php');
    }

    //==========
    // ACTIONS
    //==========

    if (isset($_REQUEST['sesskey']) and confirm_sesskey()) { // sesskey must be ok
        if (!empty($param->delete) and empty($param->cancel)) {
            if (!empty($param->confirm)) {
                /// 'confirm' is the category to move existing questions to
                $qcobject->delete_category($param->delete, $param->confirm);
            } else {
                $qcobject->delete_category($param->delete);
            }
        } else if (!empty($param->moveup)) {
            $qcobject->move_category_up_down('up', $param->moveup);
        } else if (!empty($param->movedown)) {
            $qcobject->move_category_up_down('down', $param->movedown);
        } else if (!empty($param->hide)) {
            $qcobject->publish_category(false, $param->hide);
        } else if (!empty($param->move)) {
            $qcobject->move_category($param->move, $param->moveto);
        } else if (!empty($param->publish)) {
            $qcobject->publish_category(true, $param->publish);
        } else if (!empty($param->addcategory)) {
            $param->newparent   = required_param('newparent',PARAM_INT);
            $param->newcategory = required_param('newcategory',PARAM_NOTAGS);
            $param->newinfo     = required_param('newinfo',PARAM_NOTAGS);
            $param->newpublish  = required_param('newpublish',PARAM_INT);
            $qcobject->add_category($param->newparent, $param->newcategory, $param->newinfo,
                $param->newpublish, $course->id);
        } else if (!empty($param->edit)) {
            $qcobject->edit_single_category($param->edit, $param->page);
        } else if (!empty($param->updateid)) {
            $param->updateparent  = required_param('updateparent',PARAM_INT);
            $param->updatename    = required_param('updatename',PARAM_NOTAGS);
            $param->updateinfo    = required_param('updateinfo',PARAM_NOTAGS);
            $param->updatepublish = required_param('updatepublish',PARAM_INT);
            $qcobject->update_category($param->updateid, $param->updateparent, $param->updatename,
                $param->updateinfo, $param->updatepublish, $course->id);
        }
    }

    //==========
    // DISPLAY
    //==========

    // display the user interface
    $qcobject->display_user_interface($param->page);

    print_footer($course);




?>