-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpast_score.php
More file actions
160 lines (143 loc) · 5.41 KB
/
past_score.php
File metadata and controls
160 lines (143 loc) · 5.41 KB
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
<?php
session_start() ;
require_once('includes/lib.inc.php');
//ini_set("display_errors", "Off"); // 顯示錯誤是否打開( On=開, Off=關 )
//error_reporting(E_ALL & ~E_NOTICE);
if (!isset($_SESSION['account'])){
header ("Location:index.php") ;
} else {
?>
<div class="hero-unit upload_section">
<p>PD Problems</p>
<table class="table table-hover">
<thead>
<tr>
<th>Problem</th>
<th>Status</th>
<th>Run time</th>
<th>Submission date</th>
<th>Score</th>
</tr>
</thead>
<tbody>
<?php
$acc = mysql_real_escape_string($_SESSION['account']);
//查詢使用者s_id
$query_id = "SELECT s_id FROM student WHERE account = '".$acc."'";
$id = mysql_query($query_id);
$fetch_id = mysql_fetch_row($id);
$year = 13;
$gonext = True;
while ($gonext) {
$query_ID = "SELECT past_id FROM past_hw WHERE past_id LIKE 'PD".(string)$year."%'";
$ID = mysql_query($query_ID);
$num = mysql_num_rows($ID);
$fetch_ID = mysql_fetch_row($ID);
$problem_set = "'".$fetch_ID[0]."'";
while ($fetch_ID = mysql_fetch_row($ID)){
$problem_set = $problem_set.",'".$fetch_ID[0]."'";
}
//查詢使用者每個題目最新上傳的狀態和成績
$query_score = "SELECT past_id, status, exec_time, time, score FROM past_score WHERE time IN (SELECT MAX(time) FROM past_score WHERE s_id = ".$fetch_id[0]." AND past_id IN (".$problem_set.") GROUP BY past_id) ORDER BY past_id ";
$score = mysql_query($query_score);
$fetch_score = NULL;
//將結果顯示在畫面
if ($num){
$fetch_score = mysql_fetch_row($score);
} else {
$gonext = False;
}
$ID = mysql_query($query_ID);
for ($i = 1; $i <= $num; $i++){
$fetch_ID = mysql_fetch_row($ID);
if ( $fetch_score != NULL and $fetch_ID[0] == $fetch_score[0]){
//如果該題有上傳紀錄 顯示最新一次上傳成績與狀態
if ($fetch_score[1] == 'Accepted'){
?><tr class="accept"><?php
} else if ($fetch_score[1] == 'Compilation error' or $fetch_score[1] == 'Runtime error'){
?><tr class="error"><?php
} else if ($fetch_score[1] == 'Time limit exceed'){
?><tr class="time_exceed"><?php
} else if ($fetch_score[1] == 'Wrong answer'){
?><tr class="wrong_answer"><?php
} else if ($fetch_score[1] == 'System upload error'){
?><tr class="upload_error"><?php
} ?>
<td><?php echo $fetch_score[0];?></td>
<td><?php echo $fetch_score[1];?></td>
<td><?php echo $fetch_score[2].'s';?></td>
<td><?php echo $fetch_score[3];?></td>
<td><?php echo $fetch_score[4];?></td>
</tr><?php
$fetch_score = mysql_fetch_row($score);
} else {
//如果該題沒有上傳紀錄 顯示No submit
?><tr>
<td><?php echo $fetch_ID[0];?></td>
<td><?php echo "No submit"; ?></td>
<td><?php echo "";?></td>
<td><?php echo "";?></td>
<td><?php echo "";?></td>
</tr><?php
}
}
$query_ID = "SELECT past_id FROM past_hw WHERE past_id LIKE 'EX".(string)$year."%'";
$ID = mysql_query($query_ID);
$num = mysql_num_rows($ID);
$fetch_ID = mysql_fetch_row($ID);
$problem_set = "'".$fetch_ID[0]."'";
while ($fetch_ID = mysql_fetch_row($ID)){
$problem_set = $problem_set.",'".$fetch_ID[0]."'";
}
//查詢使用者每個題目最新上傳的狀態和成績
$query_score = "SELECT past_id, status, exec_time, time, score FROM past_score WHERE time IN (SELECT MAX(time) FROM past_score WHERE s_id = ".$fetch_id[0]." AND past_id IN (".$problem_set.") GROUP BY past_id) ORDER BY past_id ";
$score = mysql_query($query_score);
$fetch_score = NULL;
//將結果顯示在畫面
if ($num){
$fetch_score = mysql_fetch_row($score);
} else {
$gonext = False;
}
$ID = mysql_query($query_ID);
for ($i = 1; $i <= $num; $i++){
$fetch_ID = mysql_fetch_row($ID);
if ( $fetch_score != NULL and $fetch_ID[0] == $fetch_score[0]){
//如果該題有上傳紀錄 顯示最新一次上傳成績與狀態
if ($fetch_score[1] == 'Accepted'){
?><tr class="accept"><?php
} else if ($fetch_score[1] == 'Compilation error' or $fetch_score[1] == 'Runtime error'){
?><tr class="error"><?php
} else if ($fetch_score[1] == 'Time limit exceed'){
?><tr class="time_exceed"><?php
} else if ($fetch_score[1] == 'Wrong answer'){
?><tr class="wrong_answer"><?php
} else if ($fetch_score[1] == 'System upload error'){
?><tr class="upload_error"><?php
} ?>
<td><?php echo $fetch_score[0];?></td>
<td><?php echo $fetch_score[1];?></td>
<td><?php echo $fetch_score[2].'s';?></td>
<td><?php echo $fetch_score[3];?></td>
<td><?php echo $fetch_score[4];?></td>
</tr><?php
$fetch_score = mysql_fetch_row($score);
} else {
//如果該題沒有上傳紀錄 顯示No submit
?><tr>
<td><?php echo $fetch_ID[0];?></td>
<td><?php echo "No submit"; ?></td>
<td><?php echo "";?></td>
<td><?php echo "";?></td>
<td><?php echo "";?></td>
</tr><?php
}
}
$year++;
}?>
</tbody>
</table>
</div>
<?php
}
?>