This repository has been archived by the owner on Jun 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
urkund_debug.php
221 lines (198 loc) · 10.2 KB
/
urkund_debug.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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<?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/>.
/**
* urkund_defaults.php - Displays default values to use inside assignments for URKUND
*
* @package plagiarism_urkund
* @author Dan Marsden <[email protected]>
* @copyright 2021 Catalyst IT
* @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.'/tablelib.php');
require_once($CFG->dirroot.'/plagiarism/urkund/lib.php');
$id = optional_param('id', 0, PARAM_INT);
$resetuser = optional_param('reset', 0, PARAM_INT);
$delete = optional_param('delete', 0, PARAM_INT);
$resubmitallfiltered = optional_param('resubmitallfiltered', '', PARAM_TEXT);
$confirm = optional_param('confirm', 0, PARAM_INT);
$deleteselected = optional_param('deleteselectedfiles', 0, PARAM_TEXT);
$deleteallfiltered = optional_param('deleteallfiltered', 0, PARAM_TEXT);
$fileids = optional_param('fileids', '', PARAM_TEXT);
require_login();
$url = new moodle_url('/plagiarism/urkund/urkund_debug.php');
admin_externalpage_setup('plagiarismurkund', '', array(), $url);
$context = context_system::instance();
$exportfilename = 'UrkundDebugOutput.csv';
$limit = 50;
$filters = array('realname' => 0, 'timesubmitted' => 0, 'statuscode' => 0, 'errorcode' => 0, 'course' => 0);
$ufiltering = new \plagiarism_urkund\output\filtering($filters, $PAGE->url);
list($ufextrasql, $ufparams) = $ufiltering->get_sql_filter();
$plagiarismsettings = plagiarism_plugin_urkund::get_settings();
if (!empty($deleteselected)) {
if (empty($fileids)) {
$fileids = array();
// First time form submit - get list of ids from checkboxes or from single delete action.
if (!empty($delete)) {
// This is a single delete action.
$fileids[] = $delete;
} else {
// Get list of ids from checkboxes.
$post = data_submitted();
foreach ($post as $k => $v) {
if (preg_match('/^item(\d+)$/', $k, $m)) {
$fileids[] = $m[1];
}
}
}
// Display confirmation box.
$params = array('deleteselectedfiles' => 1, 'confirm' => 1, 'fileids' => implode(',', $fileids));
$deleteurl = new moodle_url($PAGE->url, $params);
$numfiles = count($fileids);
echo $OUTPUT->header();
echo $OUTPUT->confirm(get_string('areyousurebulk', 'plagiarism_urkund', $numfiles),
$deleteurl, $CFG->wwwroot . '/plagiarism/urkund/urkund_debug.php');
echo $OUTPUT->footer();
exit;
} else if ($confirm && confirm_sesskey()) {
$count = 0;
$fileids = explode(',', $fileids);
foreach ($fileids as $id) {
$DB->delete_records('plagiarism_urkund_files', array('id' => $id));
$count++;
}
\core\notification::success(get_string('recordsdeleted', 'plagiarism_urkund', $count));
}
} else if (!empty($deleteallfiltered) || !empty($resubmitallfiltered)) {
$sqlfrom = "FROM {plagiarism_urkund_files} t, {user} u, {modules} m, {course_modules} cm, {course} c
WHERE m.id = cm.module AND cm.id = t.cm AND t.userid = u.id AND c.id = cm.course
AND t.statuscode <> 'Analyzed' AND $ufextrasql";
$numfiles = $DB->count_records_sql("SELECT count(t.id) $sqlfrom", $ufparams);
if (!$confirm) {
$params = array('deleteallfiltered' => $deleteallfiltered,
'resubmitallfiltered' => $resubmitallfiltered, 'confirm' => 1);
$deleteurl = new moodle_url($PAGE->url, $params);
$areyousure = !empty($deleteallfiltered) ? 'areyousurefiltereddelete' : 'areyousurefilteredresubmit';
echo $OUTPUT->header();
echo $OUTPUT->confirm(get_string($areyousure, 'plagiarism_urkund', $numfiles),
$deleteurl, $CFG->wwwroot . '/plagiarism/urkund/urkund_debug.php');
echo $OUTPUT->footer();
exit;
} else if ($confirm && confirm_sesskey()) {
if (!empty($deleteallfiltered)) {
$sql = "DELETE FROM {plagiarism_urkund_files}
WHERE id IN (SELECT t.id $sqlfrom)";
$DB->execute($sql, $ufparams);
\core\notification::success(get_string('recordsdeleted', 'plagiarism_urkund', $numfiles));
} else {
// Deal with any 202 files first.
// Reset their attempt value.
$pfiles = $DB->get_records_sql("SELECT t.* $sqlfrom AND t.statuscode = '202'", $ufparams);
foreach ($pfiles as $plagiarismfile) {
$file = urkund_get_score($plagiarismsettings, $plagiarismfile, true);
// Reset attempts as this was a manual check.
$file->attempt = $file->attempt - 1;
$DB->update_record('plagiarism_urkund_files', $file);
if ($file->statuscode == URKUND_STATUSCODE_ACCEPTED) {
$response = get_string('scorenotavailableyet', 'plagiarism_urkund');
} else if ($file->statuscode == URKUND_STATUSCODE_PROCESSED ||
$file->statuscode == 'Analyzed') {
$response = get_string('scoreavailable', 'plagiarism_urkund');
} else {
$response = get_string('unknownwarninggetscore', 'plagiarism_urkund');
if (debugging()) {
echo plagiarism_urkund_pretty_print($file);
}
}
}
// Now deal with the other files.
$pfiles = $DB->get_records_sql("SELECT t.* $sqlfrom AND t.statuscode <> '202'", $ufparams);
foreach ($pfiles as $plagiarismfile) {
urkund_reset_file($plagiarismfile, $plagiarismsettings);
}
\core\notification::success(get_string('filesresubmitted', 'plagiarism_urkund', $numfiles));
}
}
}
plagiarism_urkund_checkcronhealth();
if ($resetuser == 1 && $id && confirm_sesskey()) {
if (urkund_reset_file($id, $plagiarismsettings)) {
\core\notification::success(get_string('fileresubmitted', 'plagiarism_urkund'));
}
} else if ($resetuser == 2 && $id && confirm_sesskey()) {
$plagiarismfile = $DB->get_record('plagiarism_urkund_files', array('id' => $id), '*', MUST_EXIST);
$file = urkund_get_score(plagiarism_plugin_urkund::get_settings(), $plagiarismfile, true);
// Reset attempts as this was a manual check.
$file->attempt = $file->attempt - 1;
$DB->update_record('plagiarism_urkund_files', $file);
if ($file->statuscode == URKUND_STATUSCODE_ACCEPTED) {
\core\notification::warning(get_string('scorenotavailableyet', 'plagiarism_urkund'));
} else if ($file->statuscode == URKUND_STATUSCODE_PROCESSED || $file->statuscode == 'Analyzed') {
\core\notification::success(get_string('scoreavailable', 'plagiarism_urkund'));
} else {
\core\notification::error(get_string('unknownwarninggetscore', 'plagiarism_urkund'));
echo plagiarism_urkund_pretty_print($file);
}
}
if (!empty($delete) && confirm_sesskey()) {
$DB->delete_records('plagiarism_urkund_files', array('id' => $id));
\core\notification::success(get_string('filedeleted', 'plagiarism_urkund'));
}
$table = new \plagiarism_urkund\output\debug_table('debugtable');
$userfields = get_all_user_name_fields(true, 'u');
$sqlfields = "t.*, ".$userfields.", m.name as moduletype, ".
"cm.course as courseid, cm.instance as cminstance, c.fullname, c.shortname";
$sqlfrom = "{plagiarism_urkund_files} t, {user} u, {modules} m, {course_modules} cm, {course} c ";
$sqlwhere = "m.id = cm.module AND cm.id = t.cm AND t.userid = u.id AND c.id = cm.course AND t.statuscode <> 'Analyzed'";
if (!empty($ufextrasql)) {
$sqlwhere .= " and ".$ufextrasql;
}
$table->set_sql($sqlfields, $sqlfrom, $sqlwhere, $ufparams);
if (!$table->is_downloading()) {
echo $OUTPUT->header();
$currenttab = 'urkunddebug';
require_once('urkund_tabs.php');
echo $OUTPUT->heading(get_string('urkundfiles', 'plagiarism_urkund'));
echo $OUTPUT->box(get_string('explainerrors', 'plagiarism_urkund'));
$ufiltering->display_add();
$ufiltering->display_active();
echo '<form action="urkund_debug.php" method="post" id="debugform">';
echo html_writer::start_div();
echo html_writer::tag('input', '', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey()));
echo html_writer::tag('input', '', array('type' => 'hidden', 'name' => 'returnto', 'value' => s($PAGE->url->out(false))));
}
$table->out($limit, false);
if (!$table->is_downloading()) {
echo html_writer::tag('input', "", array('name' => 'deleteselectedfiles', 'type' => 'submit',
'id' => 'deleteallselected', 'class' => 'btn btn-secondary',
'value' => get_string('deleteselectedfiles', 'plagiarism_urkund')));
if (!empty($ufextrasql)) {
// If a filter is in use, show a button to delete all that use this filter.
echo html_writer::span(' ');
echo html_writer::tag('input', "", array('name' => 'deleteallfiltered', 'type' => 'submit',
'id' => 'deleteallfiltered', 'class' => 'btn btn-secondary',
'value' => get_string('deleteallfiltered', 'plagiarism_urkund')));
echo html_writer::span(' ');
echo html_writer::tag('input', "", array('name' => 'resubmitallfiltered', 'type' => 'submit',
'id' => 'resubmitallfiltered', 'class' => 'btn btn-secondary',
'value' => get_string('resubmitallfiltered', 'plagiarism_urkund')));
}
echo html_writer::end_tag('form');
echo html_writer::end_div();
echo html_writer::empty_tag('hr');
echo $OUTPUT->footer();
}