-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathplagiarism_copyleaks_settings.php
193 lines (164 loc) · 7.24 KB
/
plagiarism_copyleaks_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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<?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/>.
/**
* Copyleaks settings page
* @package plagiarism_copyleaks
* @author Bayan Abuawad <[email protected]>
* @copyright 2021 Copyleaks
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require(dirname(dirname(__FILE__)) . '/../config.php');
require_once($CFG->dirroot . '/plagiarism/copyleaks/classes/plagiarism_copyleaks_comms.class.php');
require_once($CFG->dirroot . '/plagiarism/copyleaks/classes/plagiarism_copyleaks_pluginconfig.class.php');
require_once($CFG->dirroot . '/plagiarism/copyleaks/classes/plagiarism_copyleaks_assignmodule.class.php');
require_once($CFG->dirroot . '/plagiarism/copyleaks/classes/plagiarism_copyleaks_utils.class.php');
// Get url params.
$cmid = optional_param('cmid', null, PARAM_INT);
$courseid = optional_param('courseid', null, PARAM_INT);
$modulename = optional_param('modulename', null, PARAM_TEXT);
$isnewmodulesettings = optional_param('isnewactivity', false, PARAM_TEXT);
$isadminview = false;
if (!isset($cmid) || !isset($modulename)) {
$isadminview = true;
}
if ($isadminview) {
require_once($CFG->libdir . '/adminlib.php');
// Request login.
require_login();
admin_externalpage_setup('plagiarismcopyleaks');
$context = context_system::instance();
require_capability('moodle/site:config', $context, $USER->id, true, "nopermissions");
// Setup page meta data for admin.
$PAGE->set_url('/moodle/plagiarism/copyleaks/plagiarism_copyleaks_settings.php');
} else {
// Get instance modules.
$cm = null;
if (!$isnewmodulesettings) {
$cm = get_coursemodule_from_id('', $cmid);
$PAGE->set_cm($cm);
}
if (!isset($courseid)) {
$courseid = $cm->course;
}
$course = $DB->get_record('course', ['id' => $courseid], '*', MUST_EXIST);
// Request login.
require_login($course, true, $cm);
// Setup page meta data.
$context = context_course::instance($courseid);
$PAGE->set_course($course);
$PAGE->set_pagelayout('incourse');
$PAGE->add_body_class('cl-settings-page');
$roles = get_user_roles($context, $USER->id);
foreach ($roles as $role) {
if ($role->shortname == 'student') {
echo html_writer::div(get_string('clnopageaccess', 'plagiarism_copyleaks'), null, ['style' => $errormessagestyle]);
return;
}
}
$PAGE->set_url('/moodle/plagiarism/copyleaks/plagiarism_copyleaks_settings.php', [
'courseid' => $courseid,
'cmid' => $cmid,
'modulename' => $modulename,
]);
}
global $USER;
$userid = $USER->id;
$isinstructor = plagiarism_copyleaks_assignmodule::is_instructor($context);
// Check if copyleaks plugin is disabled.
$clmoduleenabled = true;
if (isset($cm)) {
$clmoduleenabled = plagiarism_copyleaks_pluginconfig::is_plugin_configured('mod_' . $cm->modname);
}
$errormessagestyle = 'color:red; display:flex; width:100%; justify-content:center;';
if (!$isnewmodulesettings && !$isadminview && !$clmoduleenabled) {
echo html_writer::div(get_string('cldisabledformodule', 'plagiarism_copyleaks'), null, ['style' => $errormessagestyle]);
} else {
// Incase students not allowed to see the plagiairsm score.
if (!$isinstructor) {
echo html_writer::div(get_string('clnopageaccess', 'plagiarism_copyleaks'), null, ['style' => $errormessagestyle]);
} else {
// Proceed to displaying the settings.
if ($isinstructor) {
// Get admin config.
$config = plagiarism_copyleaks_pluginconfig::admin_config();
// Add Page style via javascript.
echo html_writer::script(
"var css = document.createElement('style'); " .
"css.type = 'text/css'; " .
"styles = ' body.cl-settings-page footer { display:none; }'; " .
"styles += 'body.cl-settings-page .m-t-2 { display:none; }'; " .
"styles += ' body.cl-settings-page #page-wrapper::after { min-height:unset; }'; " .
"if (css.styleSheet) " .
"css.styleSheet.cssText = styles; " .
"else " .
"css.appendChild(document.createTextNode(styles)); " .
"document.getElementsByTagName('head')[0].appendChild(css); "
);
$cl = new plagiarism_copyleaks_comms();
$breadcrumbs = [];
$role = 0;
$accesstoken = "";
if (!$isadminview) {
$breadcrumbs = plagiarism_copyleaks_utils::set_copyleaks_page_navbar_breadcrumbs(
$isnewmodulesettings ? 'new' : $cm,
$course
);
$role = 2;
$accesstoken = $cl->request_access_for_settings(
$role,
$breadcrumbs,
$isnewmodulesettings ? 'new' : $cm->modname,
$isnewmodulesettings ? '' : $cm->name,
$cmid
);
} else {
$role = 1;
$breadcrumbs = plagiarism_copyleaks_utils::set_copyleaks_page_navbar_breadcrumbs(null, null);
$accesstoken = $cl->request_access_for_settings($role, $breadcrumbs, $modulename, null, $cmid);
}
$lang = plagiarism_copyleaks_utils::get_lang();
$actionurl = "$config->plagiarism_copyleaks_apiurl/api/moodle/$config->plagiarism_copyleaks_key/settings";
if (isset($cmid)) {
$actionurl = $actionurl . "/$cmid";
}
echo html_writer::tag(
'iframe',
null,
[
'title' => 'Copyleaks Settings',
'srcdoc' =>
"<form target='_self'" .
"method='POST'" .
"style='display: none;'" .
"action='$actionurl' >" .
"<input name='token' value='$accesstoken'>" .
"<input name='lang' value='$lang'>" .
"<input name='accessRole' value='$role'>" .
"</form>" .
"<script type='text/javascript'>" .
"window.document.forms[0].submit();" .
"</script>",
'style' => 'width: 100%; height: 100%; margin: 0px; padding: 0px; border: none;',
]
);
} else {
echo html_writer::div(get_string('clnopageaccess', 'plagiarism_copyleaks'), null, ['style' => $errormessagestyle]);
}
}
}
echo html_writer::script(
"window.document.body.style.margin=0;"
);