Fixed registering new form definition
[moodle.git] / grade / grading / manage.php
CommitLineData
6832a102
DM
1<?php
2
3// This file is part of Moodle - http://moodle.org/
4//
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17
18/**
19 * @package core
20 * @subpackage grading
21 * @copyright 2011 David Mudrak <david@moodle.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
25require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
26require_once($CFG->dirroot.'/grade/grading/lib.php');
27
28$areaid = optional_param('areaid', null, PARAM_INT);
29$contextid = optional_param('contextid', null, PARAM_INT);
30$component = optional_param('component', null, PARAM_COMPONENT);
31$area = optional_param('area', null, PARAM_AREA);
32$returnurl = optional_param('returnurl', null, PARAM_LOCALURL);
33$activemethod = optional_param('activemethod', null, PARAM_PLUGIN);
34
35if (!is_null($areaid)) {
36 // get manager by id
37 $manager = get_grading_manager($areaid);
38} else {
39 // get manager by context and component
98a73bb7 40 if (is_null($contextid) or is_null($component) or is_null($area)) {
6832a102
DM
41 throw new coding_exception('The caller script must identify the gradable area.');
42 }
43 $context = get_context_instance_by_id($contextid, MUST_EXIST);
44 $manager = get_grading_manager($context, $component, $area);
45}
46
98a73bb7
DM
47// currently active method
48$method = $manager->get_active_method();
49
6832a102
DM
50list($context, $course, $cm) = get_context_info_array($manager->get_context()->id);
51
52if (is_null($returnurl)) {
53 $returnurl = new moodle_url('/course/view.php', array('id' => $course->id));
54} else {
55 $returnurl = new moodle_url($returnurl);
56}
57
58require_login($course, true, $cm);
59require_capability('moodle/grade:managegradingforms', $context);
60
98a73bb7 61$PAGE->set_url($manager->get_management_url($returnurl));
6832a102
DM
62navigation_node::override_active_url($manager->get_management_url());
63$PAGE->set_title(get_string('gradingmanagement', 'core_grading'));
64$PAGE->set_heading(get_string('gradingmanagement', 'core_grading'));
65$output = $PAGE->get_renderer('core_grading');
66
6832a102
DM
67// process the eventual change of the active grading method
68if (!empty($activemethod)) {
69 require_sesskey();
70 if ($activemethod == 'none') {
71 // here we expect that noone would actually want to call their plugin as 'none'
72 $activemethod = null;
73 }
74 $manager->set_active_method($activemethod);
75 redirect($PAGE->url);
76}
77
78echo $output->header();
79echo $output->heading(get_string('gradingmanagementtitle', 'core_grading', array(
80 'component' => $manager->get_component_title(), 'area' => $manager->get_area_title())));
81
82// display the active grading method information and selector
83echo $output->management_method_selector($manager, $PAGE->url);
84
85// get the currently active method's controller
6832a102
DM
86if (!empty($method)) {
87 $controller = $manager->get_controller($method);
88 // display relevant actions
89 echo $output->container_start('actions');
90 if ($controller->is_form_defined()) {
91 echo $output->management_action_icon($controller->get_editor_url($returnurl),
92 get_string('manageactionedit', 'core_grading'), 'b/document-properties');
93 echo $output->management_action_icon($PAGE->url,
94 get_string('manageactiondelete', 'core_grading'), 'b/edit-delete');
95 } else {
96 echo $output->management_action_icon($controller->get_editor_url($returnurl),
97 get_string('manageactionnew', 'core_grading'), 'b/document-new');
98 echo $output->management_action_icon($PAGE->url,
99 get_string('manageactionclone', 'core_grading'), 'b/edit-copy');
100 }
101 echo $output->container_end();
102
103 // display the grading form preview
104 if ($controller->is_form_defined()) {
105 echo $output->box($controller->render_preview($PAGE), 'preview');
106 }
107}
108
109
110echo $output->footer();