-
Notifications
You must be signed in to change notification settings - Fork 3
/
settings.php
170 lines (132 loc) · 6.17 KB
/
settings.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
168
169
170
<?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/>.
/**
* plagiarism.php - allows the admin to configure plagiarism stuff
*
* @package plagiarism_tomagrade
* @copyright 2021 Tomax ltd <[email protected]>
* @copyright based on 2010 Dan Marsden http://danmarsden.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(dirname(dirname(__FILE__)) . '/../config.php');
require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->libdir.'/plagiarismlib.php');
require_once($CFG->dirroot.'/plagiarism/tomagrade/lib.php');
require_once($CFG->dirroot.'/plagiarism/tomagrade/plagiarism_form.php');
require_login();
admin_externalpage_setup('plagiarismtomagrade');
if ($CFG->version < 2011120100) {
$context = get_context_instance(CONTEXT_SYSTEM);
} else {
$context = context_system::instance();
}
require_capability('moodle/site:config', $context, $USER->id, true, "nopermissions");
$mform = new plagiarism_setup_form();
$plagiarismsettings = (array)get_config('plagiarism_tomagrade');
if ($mform->is_cancelled()) {
redirect(new moodle_url('/plagiarism/tomagrade/settings.php'));
}
echo $OUTPUT->header();
if (($data = $mform->get_data()) && confirm_sesskey()) {
if (!isset($data->tomagrade_use)) {
$data->tomagrade_use = 0;
}
set_config('enabled', $data->tomagrade_use, 'plagiarism_tomagrade');
if (isset($data->tomagrade_log)) {
set_config('tomagrade_log', $data->tomagrade_log, 'plagiarism_tomagrade');
} else {
set_config('tomagrade_log', false, 'plagiarism_tomagrade');
}
$tomagradeuserrolestodisplayrelatedassign = "";
$tomagradeuserrolestodisplayrelatedassignisfirst = true;
$tomagradeuserrolespermissiongradedexam = "";
$tomagradeuserrolespermissiongradedexamisfirst = true;
foreach ($data as $field => $value) {
if (isset($plagiarismsettings->$field) && $plagiarismsettings->$field == $value) {
// Local property copy is equal to submitted property!
continue; // Setting unchanged!
}
if (strpos($field, 'role_') !== false) {
$roleid = str_replace("role_", "", $field);
if (is_numeric($roleid) == false) {
continue;
}
if ($tomagradeuserrolestodisplayrelatedassignisfirst) {
$tomagradeuserrolestodisplayrelatedassign = $roleid;
$tomagradeuserrolestodisplayrelatedassignisfirst = false;
} else {
$tomagradeuserrolestodisplayrelatedassign = $tomagradeuserrolestodisplayrelatedassign . ",". $roleid;
}
continue;
}
if (strpos($field, 'rolePermissionGradedExam_') !== false) {
$roleid = str_replace("rolePermissionGradedExam_", "", $field);
if (is_numeric($roleid) == false) {
continue;
}
if ($tomagradeuserrolespermissiongradedexamisfirst) {
$tomagradeuserrolespermissiongradedexam = $roleid;
$tomagradeuserrolespermissiongradedexamisfirst = false;
} else {
$tomagradeuserrolespermissiongradedexam = $tomagradeuserrolespermissiongradedexam . ",". $roleid;
}
continue;
}
// Save the setting!
set_config($field, $value, 'plagiarism_tomagrade');
if (strpos($field, 'tomagrade') === 0) {
if ($tiiconfigfield = $DB->get_record('config_plugins', array('name' => $field, 'plugin' => 'plagiarism'))) {
$tiiconfigfield->value = $value;
if (! $DB->update_record('config_plugins', $tiiconfigfield)) {
error("errorupdating");
}
} else {
$tiiconfigfield = new stdClass();
$tiiconfigfield->value = $value;
$tiiconfigfield->plugin = 'plagiarism';
$tiiconfigfield->name = $field;
if (! $DB->insert_record('config_plugins', $tiiconfigfield)) {
error("errorinserting");
}
}
}
}
$plagiarismsettings['tomagrade_userRolesToDisplayRelatedAssign'] = $tomagradeuserrolestodisplayrelatedassign;
set_config('tomagrade_userRolesToDisplayRelatedAssign', $tomagradeuserrolestodisplayrelatedassign, 'plagiarism_tomagrade');
$plagiarismsettings['tomagrade_userRolesPermissionGradedExam'] = $tomagradeuserrolespermissiongradedexam;
set_config('tomagrade_userRolesPermissionGradedExam', $tomagradeuserrolespermissiongradedexam, 'plagiarism_tomagrade');
echo $OUTPUT->notification(get_string('savedconfigsuccess', 'plagiarism_tomagrade'), 'notifysuccess');
}
$settingskeys = array_keys($plagiarismsettings);
$rolesarrrelateduser = array();
$rolesarrpermissiongradedexam = array();
if (in_array('tomagrade_userRolesToDisplayRelatedAssign', $settingskeys)) {
$rolesarrrelateduser = explode(",", $plagiarismsettings['tomagrade_userRolesToDisplayRelatedAssign']);
}
if (in_array('tomagrade_userRolesPermissionGradedExam', $settingskeys)) {
$rolesarrpermissiongradedexam = explode(",", $plagiarismsettings['tomagrade_userRolesPermissionGradedExam']);
}
foreach ($rolesarrrelateduser as $role) {
$plagiarismsettings["role_".$role] = true;
}
foreach ($rolesarrpermissiongradedexam as $role) {
$plagiarismsettings["rolePermissionGradedExam_".$role] = true;
}
$mform->set_data($plagiarismsettings);
echo $OUTPUT->box_start('generalbox boxaligncenter', 'intro');
$mform->display();
echo $OUTPUT->box_end();
echo $OUTPUT->footer();