-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathedit.php
98 lines (83 loc) · 3.45 KB
/
edit.php
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
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Management of the exports.
*
* @package tool_enrolexport
* @copyright 2018 Stephen Bourget
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require(__DIR__ . '/../../../config.php');
require_once('edit_form.php');
$id = optional_param('id', 0, PARAM_INT); // 0 means create new entry.
require_login();
$context = context_system::instance();
if (!has_capability('tool/enrolexport:manageexports', $context)) {
print_error('accessdenied', 'tool_enrolexport');
}
$PAGE->set_context($context);
$returnurl = new moodle_url("/$CFG->admin/tool/enrolexport/configure.php", array());
$PAGE->set_url(new moodle_url("/$CFG->admin/tool/enrolexport/edit.php", array()));
$PAGE->set_pagelayout('standard');
if ($id > 0) {
// Updating an existing record.
$strtitle = get_string('editexport', 'tool_enrolexport');
$mform = new export_edit_form($PAGE->url, false, $id);
$record = $DB->get_record('tool_enrolexport', array('id' => $id), '*', MUST_EXIST);
$record->courses = explode(",", $record->courses);
$mform->set_data($record);
} else {
// Adding a new record.
$strtitle = get_string('addexport', 'tool_enrolexport');
$mform = new export_edit_form($PAGE->url, true, $id);
$record = new stdClass;
$record->id = 0;
$mform->set_data($record);
}
if ($mform->is_cancelled()) {
redirect($returnurl);
} else if ($data = $mform->get_data()) {
if ($data->id == 0) {
$data->courses = implode(",", $data->courses);
$id = $DB->insert_record('tool_enrolexport', $data);
// Trigger event about adding the export.
$params = array('context' => $context, 'objectid' => $id);
$event = \tool_enrolexport\event\export_added::create($params);
$event->add_record_snapshot('tool_enrolexport', $data);
$event->trigger();
} else if (isset($data->id) && (int)$data->id > 0) {
$data->courses = implode(",", $data->courses);
$id = $DB->update_record('tool_enrolexport', $data);
// Trigger event about updating the export.
$params = array('context' => $context, 'objectid' => $data->id);
$event = \tool_enrolexport\event\export_updated::create($params);
$event->add_record_snapshot('tool_enrolexport', $data);
$event->trigger();
}
redirect($returnurl);
} else {
$strmanageexports = get_string('manageexports', 'tool_enrolexport');
$PAGE->navbar->add(get_string('pluginname', 'tool_enrolexport'), $returnurl);
$PAGE->navbar->add($strmanageexports);
$PAGE->set_title($strmanageexports);
$PAGE->set_heading(format_string($strmanageexports));
$PAGE->set_title($strtitle);
$PAGE->set_heading($strtitle);
echo $OUTPUT->header();
echo $OUTPUT->heading($strtitle, 2);
$mform->display();
echo $OUTPUT->footer();
}