This repository has been archived by the owner on Jun 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
turnitin_errors.php
186 lines (169 loc) · 8.38 KB
/
turnitin_errors.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
<?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/>.
/**
* turnitin_errors.php - Displays Turnitin files with a current error state.
*
* @package plagiarism_turnitin
* @author Dan Marsden <dan@danmarsden.com>
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.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/turnitin/lib.php');
require_once('turnitin_form.php');
require_once($CFG->dirroot.'/mod/assign/locallib.php');
require_once($CFG->dirroot.'/mod/assign/submission/file/locallib.php');
require_login();
admin_externalpage_setup('plagiarismturnitin');
$id = optional_param('id', 0, PARAM_INT);
$resetuser = optional_param('reset', 0, PARAM_INT);
$delete = optional_param('delete', 0, PARAM_INT);
$page = optional_param('page', 0, PARAM_INT);
$sort = optional_param('sort', '', PARAM_ALPHA);
$dir = optional_param('dir', '', PARAM_ALPHA);
$limit = 20;
$baseurl = new moodle_url('turnitin_errors.php', array('page' => $page, 'sort' => $sort));
echo $OUTPUT->header();
$currenttab='turnitinerrors';
require_once('turnitin_tabs.php');
echo $OUTPUT->box(get_string('tiiexplainerrors', 'plagiarism_turnitin'));
$sqlallfiles = "SELECT t.*, u.firstname, u.lastname, m.name as moduletype, ".
"cm.course as courseid, cm.instance as cminstance FROM ".
"{plagiarism_turnitin_files} t, {user} u, {modules} m, {course_modules} cm ".
"WHERE m.id=cm.module AND cm.id=t.cm AND t.userid=u.id ".
"AND t.statuscode <>'success' AND t.statuscode <>'pending' AND t.statuscode <> '51'";
$sqlcount = "SELECT COUNT(id) FROM {plagiarism_turnitin_files} WHERE statuscode <>'success' AND statuscode <>'pending' AND statuscode <> '51'";
if ($resetuser==1 && $id) {
$sqlid = "SELECT t.*, u.firstname, u.lastname, u.id as userid, m.name as moduletype, cm.course as courseid, cm.instance as cminstance
FROM {plagiarism_turnitin_files} t, {user} u, {modules} m, {course_modules} cm
WHERE m.id=cm.module AND cm.id=t.cm AND t.userid=u.id AND t.id = ?";
$tfile = $DB->get_record_sql($sqlid, array('id'=>$id));
$tfile->statuscode = 'pending';
$modulecontext = context_module::instance($tfile->cm);
if ($tfile->moduletype == 'assignment' or $tfile->moduletype == 'assign') {
$fs = get_file_storage();
if ($tfile->moduletype =='assignment') {
$submission = $DB->get_record('assignment_submissions', array('assignment'=>$tfile->cminstance, 'userid'=>$tfile->userid));
$files = $fs->get_area_files($modulecontext->id, 'mod_assignment', 'submission', $submission->id);
} else if ($tfile->moduletype =='assign') {
$submission = $DB->get_record('assign_submission', array('assignment'=>$tfile->cminstance, 'userid'=>$tfile->userid));
$files = $fs->get_area_files($modulecontext->id, 'assignsubmission_file', ASSIGNSUBMISSION_FILE_FILEAREA, $submission->id, "id", false);
}
if (!empty($files)) {
$eventdata = new stdClass();
$eventdata->modulename = $tfile->moduletype;
$eventdata->cmid = $tfile->cm;
$eventdata->courseid = $tfile->courseid;
$eventdata->userid = $tfile->userid;
$eventdata->pathnamehashes = array_keys($files);
events_trigger('assessable_file_uploaded', $eventdata);
//now reset status so that it disapears from error page
if ($DB->update_record('plagiarism_turnitin_files', $tfile)) {
notify(get_string('fileresubmitted', 'plagiarism_turnitin'));
}
} else {
notify("could not find any files for this submission");
}
} else {
notify("resubmit function for ".$tfile->moduletype. " not complete yet");
}
//TODO: trigger event for this file
} else if ($resetuser==2) {
$tiifiles = get_records_sql($sqlallfiles);
foreach ($tiifiles as $tiifile) {
$tiifile->statuscode = 'pending';
//TODO: trigger event for this file
// if ($DB->update_record('plagiarism_turnitin_files', $tiifile)) {
// notify(get_string('fileresubmitted','plagiarism_turnitin'));
//}
}
}
if (!empty($delete)) {
$DB->delete_records('plagiarism_turnitin_files', array('id'=>$id));
notify(get_string('filedeleted', 'plagiarism_turnitin'));
}
//now do sorting if specified
$orderby = '';
if (!empty($sort)) {
if ($sort=="name") {
$orderby = " ORDER BY u.firstname, u.lastname";
} else if ($sort=="module") {
$orderby = " ORDER BY cm.id";
} else if ($sort=="status") {
$orderby = " ORDER BY t.statuscode";
} else if ($sort=="id") {
$orderby = " ORDER BY t.id";
}
if (!empty($orderby) && ($dir=='asc' || $dir=='desc')) {
$orderby .= " ".$dir;
}
}
$count = $DB->count_records_sql($sqlcount);
$turnitin_files = $DB->get_records_sql($sqlallfiles.$orderby, null, $page*$limit, $limit);
$table = new html_table();
$columns = array('id', 'name', 'module', 'file', 'status');
foreach ($columns as $column) {
$strtitle = get_string($column, 'plagiarism_turnitin');
if ($column=='file') {
$table->head[] = $strtitle;
} else {
if ($sort != $column) {
$columnicon = '';
$columndir = 'asc';
} else {
$columndir = $dir == 'asc' ? 'desc' : 'asc';
$columnicon = ' <img src="'.$OUTPUT->pix_url('t/'.($dir == 'asc' ? 'down' : 'up' )).'f" alt="" />';
}
$table->head[] = '<a href="turnitin_errors.php?sort='.$column.'&dir='.$columndir.'">'.$strtitle.'</a>'.$columnicon;
}
$table->align[] = 'left';
}
$table->head[] = '';
$table->width = "95%";
$fs = get_file_storage();
foreach ($turnitin_files as $tf) {
$modulecontext = context_module::instance($tf->cm);
$coursemodule = get_coursemodule_from_id($tf->moduletype, $tf->cm);
$file = $fs->get_file_by_hash($tf->identifier);
if ($file && ($tf->moduletype == 'assignment' || $tf->moduletype == 'assign')) {
if ($tf->moduletype == 'assignment') {
$fileurl = file_encode_url("$CFG->wwwroot/pluginfile.php", '/'.$modulecontext->id.'/mod_assignment/submission/'.$file->get_itemid(). $file->get_filepath().$file->get_filename(), true);
} else if ($tf->moduletype == 'assign') {
$fileurl = file_encode_url("$CFG->wwwroot/pluginfile.php", '/'.$modulecontext->id.'/assignsubmission_file/'.ASSIGNSUBMISSION_FILE_FILEAREA.'/'.$file->get_itemid(). $file->get_filepath().$file->get_filename(), true);
}
$filelink = html_writer::link($fileurl, shorten_text($file->get_filename(), 40, true), array('title'=>$file->get_filename()));
} else {
$filelink = $tf->identifier;
}
$user = "<a href='".$CFG->wwwroot."/user/profile.php?id=".$tf->userid."'>".fullname($tf)."</a>";
$reset = '<a href="turnitin_errors.php?reset=1&id='.$tf->id.'">'.get_string('resubmit', 'plagiarism_turnitin').'</a> | '.
'<a href="turnitin_errors.php?delete=1&id='.$tf->id.'">'.get_string('delete').'</a>';
$cmurl = new moodle_url($CFG->wwwroot.'/mod/'.$tf->moduletype.'/view.php', array('id'=>$tf->cm));
$cmlink = html_writer::link($cmurl, shorten_text($coursemodule->name, 40, true), array('title'=>$coursemodule->name));
$table->data[] = array ($tf->id,
$user,
$cmlink,
$filelink,
$tf->statuscode,
$reset);
}
if (!empty($table)) {
echo html_writer::table($table);
echo $OUTPUT->paging_bar($count, $page, $limit, $baseurl);
}
echo $OUTPUT->footer();