-
Notifications
You must be signed in to change notification settings - Fork 3
/
adminsettings.php
executable file
·167 lines (151 loc) · 7.1 KB
/
adminsettings.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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<?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/>.
/**
* Settings for the evasys_sync block
*
* @package block_evasys_sync
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(__DIR__ . '/../../config.php');
require_once($CFG->libdir . '/adminlib.php');
require_once($CFG->dirroot . '/course/lib.php');
$delid = optional_param('d', 0, PARAM_INT);
$confirm = optional_param('c', 0, PARAM_INT);
require_login();
// Set the URL that should be used to return to this page.
$PAGE->set_url('/blocks/evasys_sync/adminsettings');
if (has_capability('moodle/site:config', context_system::instance())) {
admin_externalpage_setup('block_evasys_sync');
$evasysroleid = $DB->get_record('role', ['shortname' => 'evasysmanager'])->id;
if (!empty($delid) && !empty($confirm)) {
// Course category user is deleted.
$persistent = new \block_evasys_sync\evasys_category($delid);
if ($evasysroleid) {
role_unassign($evasysroleid, $persistent->get('userid'), context_coursecat::instance($persistent->get('course_category'))->id);
}
$persistent->delete();
redirect($PAGE->url);
exit();
}
$mform = new block_evasys_sync\admin_form();
if (!empty($delid)) {
// Deletion has to be confirmed.
// Print a confirmation message.
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('settings', 'block_evasys_sync'));
echo $OUTPUT->confirm(get_string("delete_confirm", 'block_evasys_sync'),
"adminsettings.php?d=$delid&c=$delid",
'adminsettings.php');
echo $OUTPUT->footer();
exit();
} else if ($data = $mform->get_data()) {
// Form is submitted.
// Added course category.
if (isset($data->addcatbutton)) {
// Insert new record.
$record = new stdClass();
$record->userid = $data->evasys_cc_user;
$record->course_category = $data->evasys_cc_select;
if (isset($data->evasys_cc_mode) && $data->evasys_cc_mode == 1) {
$record->category_mode = 1;
} else {
$record->category_mode = 0;
}
$record->mode_flags = 0;
$persistent = new \block_evasys_sync\evasys_category(0, $record);
$persistent->create();
if ($evasysroleid) {
role_assign($evasysroleid, $record->userid, context_coursecat::instance($record->course_category));
}
\block_evasys_sync\evalcat_manager::get_instance()->purge();
redirect($PAGE->url);
exit();
} else if (isset($data->submitbutton)) {
if (isset($data->evasys_wsdl_url)) {
set_config('evasys_wsdl_url', $data->evasys_wsdl_url, 'block_evasys_sync');
}
if (isset($data->evasys_soap_url)) {
set_config('evasys_soap_url', $data->evasys_soap_url, 'block_evasys_sync');
}
if (isset($data->evasys_username)) {
set_config('evasys_username', $data->evasys_username, 'block_evasys_sync');
}
if (isset($data->evasys_password)) {
set_config('evasys_password', $data->evasys_password, 'block_evasys_sync');
}
if (isset($data->default_evasys_moodleuser)) {
set_config('default_evasys_moodleuser', $data->default_evasys_moodleuser, 'block_evasys_sync');
}
// Checkboxes will only get submitted if they're checked...
if (isset($data->default_evasys_mode)) {
set_config('default_evasys_mode', $data->default_evasys_mode, 'block_evasys_sync');
} else {
set_config('default_evasys_mode', 0, 'block_evasys_sync');
}
if (isset($data->default_his_connection)) {
set_config('default_his_connection', $data->default_his_connection, 'block_evasys_sync');
} else {
set_config('default_his_connection', 0, 'block_evasys_sync');
}
$records = \block_evasys_sync\evasys_category::get_records();
foreach ($records as $allocation) {
$newvalue = 'category_' . $allocation->get('id');
$oldvalue = $allocation->get('userid');
$newvaluemodename = 'category_mode_' . $allocation->get('id');
// Checkboxex only get submitted if they're checked.
if (isset($data->$newvaluemodename) && $data->$newvaluemodename) {
$newvaluemode = 1; // Category uses automated mode.
} else {
$newvaluemode = 0; // Category uses manual mode.
}
try {
$oldvaluemode = $allocation->get('category_mode');
} catch (coding_exception $e) {
$oldvaluemode = $newvaluemode + 1; // Make the below if statement execute.
}
// Update db entry.
if ($data->$newvalue != $oldvalue or
$newvaluemode != $oldvaluemode) {
if ($evasysroleid && $data->$newvalue != $oldvalue) {
role_unassign($evasysroleid, $oldvalue, context_coursecat::instance($allocation->get('course_category'))->id);
}
$allocation->set('userid', $data->$newvalue);
$allocation->set('category_mode', $newvaluemode);
$allocation->update();
}
if ($evasysroleid) {
role_assign($evasysroleid, $data->$newvalue, context_coursecat::instance($allocation->get('course_category')));
}
}
}
\block_evasys_sync\evalcat_manager::get_instance()->purge();
}
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('settings', 'block_evasys_sync'));
// Load existing setttings.
if (empty($entry->id)) {
$entry = new stdClass;
$entry->id = 0;
}
$entry->evasys_username = get_config('block_evasys_sync', 'evasys_username');
$entry->evasys_password = get_config('block_evasys_sync', 'evasys_password');
$entry->evasys_soap_url = get_config('block_evasys_sync', 'evasys_soap_url');
$entry->evasys_wsdl_url = get_config('block_evasys_sync', 'evasys_wsdl_url');
$entry->default_evasys_moodleuser = get_config('block_evasys_sync', 'default_evasys_moodleuser');
$mform->set_data($entry);
$mform->display();
echo $OUTPUT->footer();
}