/
list_submissions.php
143 lines (120 loc) · 4.55 KB
/
list_submissions.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
<?php
require('../../include/mellivora.inc.php');
enforce_authentication(CONFIG_UC_MODERATOR);
head('Submissions');
menu_management();
if (!isset($_GET['all'])) {
$_GET['all'] = 0;
}
if ($_GET['all']) {
section_head('All submissions');
} else {
section_head('Submissions in need of marking', '<a href="list_submissions?all=1">List all submissions</a>', false);
}
$num_subs = db_query_fetch_one('
SELECT
COUNT(*) AS num
FROM submissions AS s
LEFT JOIN challenges AS c ON c.id = s.challenge
'.($_GET['all'] ? '' : 'WHERE c.automark = 0 AND s.marked = 0').'
');
$from = get_pager_from($_GET);
$results_per_page = 1000;
if(verifySA())
$submissions = db_query_fetch_all('
SELECT
s.id,
u.id AS user_id,
u.team_name,
s.added,
s.correct,
s.flag,
c.id AS challenge_id,
c.title AS challenge_title
FROM submissions AS s
LEFT JOIN users AS u on s.user_id = u.id
LEFT JOIN challenges AS c ON c.id = s.challenge
'.($_GET['all'] ? '' : 'WHERE c.automark = 0 AND s.marked = 0').'
ORDER BY s.added DESC
LIMIT '.$from.', '.$results_per_page);
else
$submissions = db_query_fetch_all('
SELECT
s.id,
u.id AS user_id,
u.team_name,
s.added,
s.correct,
s.flag,
c.id AS challenge_id,
c.title AS challenge_title
FROM submissions AS s
LEFT JOIN users AS u on s.user_id = u.id
LEFT JOIN challenges AS c ON c.id = s.challenge
'.($_GET['all'] ? '' : 'WHERE c.automark = 0 AND s.marked = 0').'
WHERE s.instanceID = \''.$_SESSION["IID"].'\'
ORDER BY s.added DESC
LIMIT '.$from.', '.$results_per_page);
pager(CONFIG_SITE_ADMIN_URL.'list_submissions/?'.(isset($_GET['all']) ? 'all='.$_GET['all'] : ''), count($submissions), $results_per_page, $from);
echo '
<table style="width:100%; table-layout:fixed;" id="files" class="table table-striped table-hover" >
<thead>
<tr>
<th style="white-space:nowrap;">Challenge</th>
<th style="white-space:nowrap;">Team name</th>
<th style="white-space:nowrap;">Added</th>
<th style="white-space:nowrap;">Flag</th>
<th style="white-space:nowrap;">Correct</th>
<th style="white-space:nowrap;">Manage</th>
</tr>
</thead>
<tbody>
';
foreach($submissions as $submission) {
echo '
<tr>
<td><a href="../challenge.php?id=',htmlspecialchars($submission['challenge_id']),'">',htmlspecialchars($submission['challenge_title']),'</a></td>
<td><a href="/user.php?id=',htmlspecialchars($submission['user_id']),'">',htmlspecialchars($submission['team_name']),'</a></td>
<td>',date_time ($submission['added']),'</td>
<td style="word-break: break-all;">',htmlspecialchars($submission['flag']),'</td>
<td>
',($submission['correct'] ?
'<img src="'.CONFIG_SITE_URL.'img/accept.png" alt="Correct!" title="Correct!" />' :
'<img src="'.CONFIG_SITE_URL.'img/stop.png" alt="Wrong!" title="Wrong!" />'),'
</td>
<td>
<form method="post" action="actions/list_submissions" class="discreet-inline">';
form_xsrf_token();
echo '
<input type="hidden" name="action" value="',($submission['correct'] ? 'mark_incorrect' : 'mark_correct'),'" />
<input type="hidden" name="id" value="',htmlspecialchars($submission['id']),'" />
<button type="submit" class="btn btn-sm btn-',($submission['correct'] ? 'warning' : 'success'),'">Mark ',($submission['correct'] ? 'incorrect' : 'correct'),'</button>
</form>
<form method="post" action="actions/list_submissions" class="discreet-inline">';
form_xsrf_token();
echo '
<input type="hidden" name="action" value="delete" />
<input type="hidden" name="id" value="',htmlspecialchars($submission['id']),'" />
<button type="submit" class="btn btn-sm btn-danger">Delete</button>
</form>
</td>
</tr>
';
}
echo '
</tbody>
</table>
';
foot();
echo'
<!-- DataTables CSS -->
<link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.9/css/jquery.dataTables.css">
<!-- jQuery -->
<script type="text/javascript" charset="utf8" src="//code.jquery.com/jquery-1.10.2.min.js"></script>
<!-- DataTables -->
<script type="text/javascript" charset="utf8" src="//cdn.datatables.net/1.10.9/js/jquery.dataTables.js"></script>
';
echo '<script>
$( document ).ready(function() {
$("#files").DataTable();
});</script>';