| 1441 |
ariadna |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* Site configuration settings for the gradepenalty_duedate plugin
|
|
|
19 |
*
|
|
|
20 |
* @package gradepenalty_duedate
|
|
|
21 |
* @copyright 2024 Catalyst IT Australia Pty Ltd
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
use core\output\notification;
|
|
|
26 |
use core\url;
|
|
|
27 |
use gradepenalty_duedate\output\edit_penalty_rule_action_bar;
|
|
|
28 |
use gradepenalty_duedate\output\form\edit_penalty_form;
|
|
|
29 |
use gradepenalty_duedate\output\view_penalty_rule_action_bar;
|
|
|
30 |
use gradepenalty_duedate\penalty_rule;
|
|
|
31 |
use gradepenalty_duedate\table\penalty_rule_table;
|
|
|
32 |
|
|
|
33 |
require_once(__DIR__ . '/../../../config.php');
|
|
|
34 |
require_once("$CFG->libdir/adminlib.php");
|
|
|
35 |
|
|
|
36 |
// Page parameters.
|
|
|
37 |
$contextid = optional_param('contextid', 1, PARAM_INT);
|
|
|
38 |
$returnurl = optional_param('returnurl', '', PARAM_LOCALURL);
|
|
|
39 |
$edit = optional_param('edit', 0, PARAM_INT);
|
|
|
40 |
$reset = optional_param('reset', 0, PARAM_INT);
|
|
|
41 |
$deleteeall = optional_param('deleteallrules', 0, PARAM_INT);
|
|
|
42 |
|
|
|
43 |
// Check login and permissions.
|
|
|
44 |
[$context, $course, $cm] = get_context_info_array($contextid);
|
|
|
45 |
if ($context->contextlevel == CONTEXT_SYSTEM) {
|
|
|
46 |
require_admin();
|
|
|
47 |
} else {
|
|
|
48 |
require_login($course, false, $cm);
|
|
|
49 |
require_capability('gradepenalty/duedate:manage', $context);
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
$PAGE->set_context($context);
|
|
|
53 |
$url = new url('/grade/penalty/duedate/manage_penalty_rule.php', ['contextid' => $contextid]);
|
|
|
54 |
$PAGE->set_url($url);
|
|
|
55 |
|
|
|
56 |
// Return to this page without edit mode.
|
|
|
57 |
if (!$returnurl) {
|
|
|
58 |
$returnurl = $url;
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
// Display page according to context.
|
|
|
62 |
if ($context->contextlevel == CONTEXT_COURSE) {
|
|
|
63 |
$course = get_course($context->instanceid);
|
|
|
64 |
$PAGE->set_heading($course->fullname);
|
|
|
65 |
} else if ($context->contextlevel == CONTEXT_MODULE) {
|
|
|
66 |
$PAGE->set_heading($PAGE->activityrecord->name);
|
|
|
67 |
} else {
|
|
|
68 |
$PAGE->set_heading(get_string('administrationsite'));
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
// Print the header and tabs.
|
|
|
72 |
$PAGE->set_cacheable(false);
|
|
|
73 |
if (!$edit) {
|
|
|
74 |
$title = get_string('duedaterule', 'gradepenalty_duedate');
|
|
|
75 |
} else {
|
|
|
76 |
$title = get_string('editduedaterule', 'gradepenalty_duedate');
|
|
|
77 |
// Add edit navigation node.
|
|
|
78 |
$PAGE->navbar->add(get_string('editduedaterule', 'gradepenalty_duedate'));
|
|
|
79 |
}
|
|
|
80 |
$PAGE->set_title($title);
|
|
|
81 |
$PAGE->set_pagelayout('admin');
|
|
|
82 |
$PAGE->activityheader->disable();
|
|
|
83 |
|
|
|
84 |
// If reset button is clicked, reset the penalty rules.
|
|
|
85 |
if ($reset || $deleteeall) {
|
|
|
86 |
// Show message for user confirmation.
|
|
|
87 |
$confirmurl = new url($url->out(), [
|
|
|
88 |
'contextid' => $contextid,
|
|
|
89 |
'resetconfirm' => 1,
|
|
|
90 |
]);
|
|
|
91 |
echo $OUTPUT->header();
|
|
|
92 |
echo $OUTPUT->confirm(get_string('resetconfirm', 'gradepenalty_duedate'), $confirmurl, $url);
|
|
|
93 |
echo $OUTPUT->footer();
|
|
|
94 |
die;
|
|
|
95 |
} else if (optional_param('resetconfirm', 0, PARAM_INT)) {
|
|
|
96 |
// Reset the penalty rules.
|
|
|
97 |
penalty_rule::reset_rules($contextid);
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
// Only initialize the form if we are in edit mode.
|
|
|
101 |
if ($edit) {
|
|
|
102 |
// Create a form to add / edit penalty rules.
|
|
|
103 |
$mform = new edit_penalty_form($url->out(), [
|
|
|
104 |
'contextid' => $contextid,
|
|
|
105 |
'edit' => $edit,
|
|
|
106 |
]);
|
|
|
107 |
|
|
|
108 |
if ($mform->is_cancelled()) {
|
|
|
109 |
redirect($returnurl);
|
|
|
110 |
} else if ($fromform = $mform->get_data()) {
|
|
|
111 |
// Save the form data.
|
|
|
112 |
$mform->save_data($fromform);
|
|
|
113 |
|
|
|
114 |
// Redirect to the same page.
|
|
|
115 |
redirect($url, get_string('changessaved'), 0, notification::NOTIFY_SUCCESS);
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
// Add javascript to handle the repeater.
|
|
|
119 |
$PAGE->requires->js_call_amd('gradepenalty_duedate/edit_penalty_form', 'init');
|
|
|
120 |
}
|
|
|
121 |
|
|
|
122 |
// Start output.
|
|
|
123 |
echo $OUTPUT->header();
|
|
|
124 |
|
|
|
125 |
if (!$edit) {
|
|
|
126 |
$actionbar = new view_penalty_rule_action_bar($context, $title, $url);
|
|
|
127 |
$renderer = $PAGE->get_renderer('core_grades');
|
|
|
128 |
echo $renderer->render_action_bar($actionbar);
|
|
|
129 |
|
|
|
130 |
// Display the penalty table.
|
|
|
131 |
echo $OUTPUT->heading(get_string('existingrule', 'gradepenalty_duedate'), 5);
|
|
|
132 |
$penaltytable = new penalty_rule_table('penalty_rule_table', $contextid);
|
|
|
133 |
$penaltytable->define_baseurl($url);
|
|
|
134 |
$penaltytable->out(30, true);
|
|
|
135 |
} else {
|
|
|
136 |
$actionbar = new edit_penalty_rule_action_bar($context, $title, $url);
|
|
|
137 |
$renderer = $PAGE->get_renderer('core_grades');
|
|
|
138 |
echo $renderer->render_action_bar($actionbar);
|
|
|
139 |
|
|
|
140 |
// Wrap the form in a container, so we can replace the form.
|
|
|
141 |
echo $OUTPUT->box_start('generalbox', 'penalty_rule_form_container');
|
|
|
142 |
// Display the form.
|
|
|
143 |
$mform->display();
|
|
|
144 |
// End of the box.
|
|
|
145 |
echo $OUTPUT->box_end();
|
|
|
146 |
}
|
|
|
147 |
|
|
|
148 |
// Footer.
|
|
|
149 |
echo $OUTPUT->footer();
|