forked from jmcgettrick/moodle-mod_turnitintool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilestable.php
175 lines (159 loc) · 7.25 KB
/
filestable.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
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
require_once(__DIR__.'/../../config.php');
require_once($CFG->dirroot.'/course/lib.php');
require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->libdir.'/tablelib.php');
require_once(__DIR__."/lib.php");
if (!is_callable('groups_get_activity_group')) {
$adminroot = admin_get_root();
admin_externalpage_setup('managemodules',$adminroot);
} else {
admin_externalpage_setup('managemodules');
}
$param_module = optional_param('module', null, PARAM_INT); // module
$param_displaystart = optional_param('iDisplayStart', null, PARAM_INT); // displaystart
$param_displaylength = optional_param('iDisplayLength', null, PARAM_INT); // displaylength
$aColumns = array( 'tu.name', 'cs.shortname', 'cs.fullname', 'sb.submission_filename', 'us.firstname', 'us.lastname', 'us.email', 'fl.filename', 'sb.submission_objectid' );
$sQuery = 'SELECT
fl.id AS id,
cm.id AS cmid,
tu.id AS activityid,
tu.name AS activity,
sb.submission_unanon AS unanon,
us.firstname AS firstname,
us.lastname AS lastname,
us.email AS email,
us.id AS userid,
fl.mimetype AS mimetype,
fl.filesize AS filesize,
fl.timecreated AS created,
fl.pathnamehash AS hash,
fl.filename AS rawfilename,
cs.fullname AS coursetitle,
cs.shortname AS courseshort,
cs.id AS course,
sb.submission_filename AS filename,
sb.submission_objectid AS objectid
FROM '.$CFG->prefix.'files fl
LEFT JOIN
'.$CFG->prefix.'turnitintool_submissions sb ON fl.itemid = sb.id
LEFT JOIN
'.$CFG->prefix.'user us ON fl.userid = us.id
LEFT JOIN
'.$CFG->prefix.'course_modules cm ON fl.contextid = cm.id AND cm.module = '.$param_module.'
LEFT JOIN
'.$CFG->prefix.'turnitintool tu ON cm.instance = tu.id
LEFT JOIN
'.$CFG->prefix.'course cs ON tu.course = cs.id
WHERE
fl.component = \'mod_turnitintool\' AND fl.filesize != 0';
$sCountQuery = 'SELECT
fl.id AS id
FROM
'.$CFG->prefix.'files fl
LEFT JOIN
'.$CFG->prefix.'turnitintool_submissions sb ON fl.itemid = sb.id
WHERE
fl.component = "mod_turnitintool" AND fl.filesize != 0';
$param_sortcol[0] = optional_param('iSortCol_0', null, PARAM_INT); // sortcol
$param_sortingcols = optional_param('iSortingCols', 0, PARAM_INT); // sortingcols
$sOrder = "";
if ( !is_null( $param_sortcol[0] ) ) {
$sOrder = " ORDER BY ";
$startOrder = $sOrder;
for ( $i=0; $i < intval( $param_sortingcols ); $i++ ) {
$param_sortcol[$i] = optional_param('iSortCol_'.$i, null, PARAM_INT); // sortcol
$param_sortable[$i] = optional_param('bSortable_'.$param_sortcol[$i], null, PARAM_TEXT); // sortable
$param_sortdir[$i] = optional_param('sSortDir_'.$i, null, PARAM_TEXT); // sortdir
if ( $param_sortable[$i] == "true" ) {
$sOrder .= $aColumns[ $param_sortcol[$i] ] . " " . $param_sortdir[$i] . ", ";
}
}
$sOrder = substr_replace( $sOrder, "", -2 );
if ( $sOrder == $startOrder ) $sOrder = "";
}
$sOrder .= ",tu.id asc ";
$param_search = optional_param('sSearch', null, PARAM_TEXT); // sortingcols
$start = true;
$sWhere = ' AND ( ';
$nobracket = false;
for ( $i=0; $i < count($aColumns); $i++ ) {
$param_searchable[$i] = optional_param('bSearchable_'.$i, null, PARAM_TEXT);
$param_search_n[$i] = optional_param('sSearch_'.$i, null, PARAM_TEXT);
if ( !is_null($param_searchable[$i]) && $param_searchable[$i] == "true" && ( $param_search != '' OR $param_search_n[$i] != '' ) ) {
if ( !$start ) $sWhere .= " OR ";
if ( $aColumns[$i] == 'sb.submission_objectid' AND $param_search_n[$i] == '##deletable##' ) {
$sWhere = ( $sWhere == ' AND ( ' ) ? '' : substr_replace( $sWhere, "", -3 ) . ' )';
$sWhere .= " AND ( sb.submission_objectid IS NOT NULL OR sb.submission_filename IS NULL )";
$nobracket = true;
} else if ( $aColumns[$i] != ' ' ) {
$sWhere .= "CAST(" . $aColumns[$i] . " AS CHAR) LIKE '%" . $param_search . "%'";
$start = false;
}
}
}
if ( $sWhere != ' AND ( ' AND !$nobracket ) {
$sWhere .= " ) ";
} else if ( $nobracket ) {
$sWhere .= " ";
} else {
$sWhere = "";
}
$sLimit = "";
if ( !is_null( $param_displaystart ) && $param_displaylength != '-1' ) {
$limitfrom = $param_displaystart;
$limitnum = $param_displaylength;
} else {
$limitfrom = ( isset($DB) AND is_callable(array($DB,'get_records_sql')) ) ? 0 : '';
$limitnum = ( isset($DB) AND is_callable(array($DB,'get_records_sql')) ) ? 0 : '';
}
$sQuery .= $sWhere;
$cResult = ( isset($DB) AND is_callable(array($DB,'get_records_sql')) ) ? $DB->get_records_sql( $sQuery, array() ) : get_records_sql( $sQuery );
$iTotal = count( $cResult );
$sQuery .= $sOrder . $sLimit;
$rResult = ( isset($DB) AND is_callable(array($DB,'get_records_sql')) )
? $DB->get_records_sql( $sQuery, array(), $limitfrom, $limitnum )
: get_records_sql( $sQuery, $limitfrom, $limitnum );
$iFilteredTotal = $iTotal; //count( $rResult );
$param_echo = optional_param('sEcho', 0, PARAM_INT); // echo
$output = array(
"sEcho" => $param_echo,
"iTotalRecords" => $iTotal,
"iTotalDisplayRecords" => $iFilteredTotal,
"aaData" => array()
);
foreach ( $rResult as $result ) {
// 'cs.fullname', 'tu.name', 'fl.filename', 'us.firstname', 'us.lastname', 'us.email', 'fl.timecreated'
if ( !empty( $param_search ) AND !is_null( $result->unanon ) AND !$result->unanon ) {
$output['iTotalDisplayRecords'] = $output['iTotalDisplayRecords'] - 1;
continue; // If these are search results and this is anonymised skip it
}
$row = array();
if ( is_null( $result->filename ) OR is_null( $result->activityid ) ) {
$row[] = '<i><b>'.get_string('assigngeterror','turnitintool').'</b></i>';
} else {
$row[] = '<a href="'.$CFG->wwwroot.'/mod/turnitintool/view.php?id='.$result->cmid.'&do=allsubmissions">' . $result->coursetitle . ' (' . $result->courseshort . ') - ' . $result->activity . '</a>';
}
$row[] = $result->courseshort;
$row[] = $result->coursetitle;
$row[] = '<a href="'.$CFG->wwwroot.'/mod/turnitintool/extras.php?do=files&fileid='.$result->id.'&filehash='.$result->hash.'" class="fileicon">'
. ( is_null( $result->filename ) ? $result->rawfilename : $result->filename ) . '</a>';
$row[] = ' ';
$row[] = ( !is_null( $result->unanon ) AND !$result->unanon ) ? get_string( 'anonenabled', 'turnitintool' ) : '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$result->userid.'">'
.$result->lastname . ', ' . $result->firstname . '</a> (' . $result->email . ')';
$row[] = ' ';
$row[] = userdate( $result->created );
$fnd = array("\n","\r");
$rep = array('\n','\r');
$row[] = ( !is_null( $result->objectid ) OR is_null( $result->filename ) ) ? '<a href="'.$CFG->wwwroot.'/mod/turnitintool/extras.php?do=files&fileid='
.$result->id.'&filehash='.$result->hash.'&filerem=true" '
.' onclick="return confirm(\''.str_replace($fnd, $rep, get_string('filedeleteconfirm','turnitintool')).'\')">'
.'<img src="pix/delete.png" class="tiiicons" alt="'.get_string('delete','turnitintool').'" /></a>' : '';
$output['aaData'][] = $row;
}
$output['query']=$sQuery;
echo json_encode( $output );