-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontest.php
More file actions
370 lines (342 loc) · 13 KB
/
contest.php
File metadata and controls
370 lines (342 loc) · 13 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
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
<?require_once("./include/db_info.inc.php");
if(isset($OJ_LANG)){
require_once("./lang/$OJ_LANG.php");
}
?>
<?require_once("./include/my_func.inc.php")?>
<?require_once("./include/const.inc.php")?>
<?
if (isset($_GET['cid'])){
$cid=intval($_GET['cid']);
// print $cid;
require_once("contest-header.php");
// check contest valid
$sql="SELECT * FROM `contest` WHERE `contest_id`='$cid' AND `defunct`='N' ";
$result=mysql_query($sql);
$rows_cnt=mysql_num_rows($result);
echo "<center>";
if ($rows_cnt==0){
mysql_free_result($result);
echo "<h2>No Such Contest!</h2>";
require_once("oj-footer.php");
exit(0);
}else{
$row=mysql_fetch_object($result);
$now=time();
if (! ((isset($_SESSION['administrator']) || isset($_SESSION['contest_creator']))) ) {
if (! isIpInSubnets($_SERVER['REMOTE_ADDR'], json_decode($row->allow_ips, true) )) {
require_once("contest-header.php");
echo "<center><h1>Not Invited!</h1></center>";
require_once("oj-footer.php");
exit(0);
}
}
$start_time=strtotime($row->start_time);
$end_time=strtotime($row->end_time);
$description=$row->description;
echo "<title>Contest - $row->title</title>";
echo "<h3>Contest - $row->title</h3>
<p>$description</p>
Start Time: <font color=#993399>$row->start_time</font> ";
echo "End Time: <font color=#993399>$row->end_time</font><br>";
echo "Current Time: <font color=#993399><span id=nowdate >".date("Y-m-d H:i:s")."</span></font> Status:";
if ($now>$end_time) echo "<font color=red>Ended</font>";
else if ($now<$start_time) echo "<font color=red>Not Started</font>";
else echo "<font color=red>Running</font>";
if ($row->private=='0') echo " <font color=blue>Public</font>";
else if($row->private=='1') echo " <font color=red>Private</font>";
else echo " <font color=purple>Register Private</font>";
$sql1="select user_id from privilege where rightstr='m$cid'";
$result1=mysql_query($sql1) or die(mysql_error());
$row1=mysql_fetch_object($result1);
echo " Manager: $row1->user_id";
if (!isset($_SESSION['administrator']) && $now<$start_time){
echo "</center>";
require_once("oj-footer.php");
exit(0);
}
}
if (!$contest_ok){
echo "<br><h1>Not Invited!</h1>";
require_once("oj-footer.php");
exit(1);
}
//$sql="SELECT count(`num`) FROM `contest_problem` WHERE `contest_id`='$cid'";
//$result=mysql_query($sql);
//$row=mysql_fetch_array($result);
$sql="SELECT count(`num`) FROM `contest_problem` WHERE `contest_id`='$cid'";
$result=mysql_query($sql);
$row=mysql_fetch_array($result);
$pid_cnt=intval($row[0]);
mysql_free_result($result);
$start_timeC=strftime("%Y-%m-%d %X",($start_time));
$end_timeC=strftime("%Y-%m-%d %X",($end_time));
if(!isset($OJ_RANK_LOCK_PERCENT)) $OJ_RANK_LOCK_PERCENT=0;
$lock_time=$end_time-($end_time-$start_time)*$OJ_RANK_LOCK_PERCENT;
$lock_timeC=strftime("%Y-%m-%d %X",($lock_time));
if($end_time>time())
{
if (isset($_SESSION['administrator'])||isset($_SESSION['contest_creator']))
$timetoend=$end_timeC;
else
$timetoend=$lock_timeC;
}else
$timetoend=$end_timeC;
$sql="SELECT `result`,`num`,`language` FROM `solution` WHERE `contest_id`='$cid' and num>=0 and in_date>'$start_timeC' and in_date<'$timetoend'";
$result=mysql_query($sql);
$R=array();
while ($row=mysql_fetch_object($result)){
$res=intval($row->result)-4;
if ($res<0) $res=8;
$num=intval($row->num);
$lag=intval($row->language);
if(!isset($R[$num][$res]))
$R[$num][$res]=1;
else
$R[$num][$res]++;
if(!isset($R[$num][$lag+10]))
$R[$num][$lag+10]=1;
else
$R[$num][$lag+10]++;
if(!isset($R[$pid_cnt][$res]))
$R[$pid_cnt][$res]=1;
else
$R[$pid_cnt][$res]++;
if(!isset($R[$pid_cnt][$lag+10]))
$R[$pid_cnt][$lag+10]=1;
else
$R[$pid_cnt][$lag+10]++;
if(!isset($R[$num][8]))
$R[$num][8]=1;
else
$R[$num][8]++;
if(!isset($R[$pid_cnt][8]))
$R[$pid_cnt][8]=1;
else
$R[$pid_cnt][8]++;
}
mysql_free_result($result);
if (isset($_SESSION['administrator'])||isset($_SESSION['contest_creator'])){
$sql="SELECT `problem`.`title` as `title`,`problem`.`problem_id` as `pid`
FROM `contest_problem`,`problem`
WHERE `contest_problem`.`problem_id`=`problem`.`problem_id`
AND `contest_problem`.`contest_id`='$cid' ORDER BY `contest_problem`.`num`";
}
else
{
$sql="SELECT `problem`.`title` as `title`,`problem`.`problem_id` as `pid` FROM `contest_problem`,`problem`
WHERE `contest_problem`.`problem_id`=`problem`.`problem_id` AND `problem`.`defunct`='N'
AND `contest_problem`.`contest_id`='$cid' ORDER BY `contest_problem`.`num`";
}
// echo $cid;
// echo "<br>";
// echo $sql;
// echo "<br>";
$result=mysql_query($sql);
$end_flag=false;
$sql1="SELECT `private` FROM `contest` WHERE `contest_id`='$cid' AND `end_time`<NOW()";
$result1=mysql_query($sql1);
$rows_cnt1=mysql_num_rows($result1);
if ($rows_cnt1==1){
$end_flag=true;
}
$cnt=0;
echo "<table width=60% ><tr class=toprow><td width=5><td width=30%><b>Problem ID</b><td width=35%><b>Title</b><td width=30%><center><b>Ratio(AC/Submit)</b></center></tr>";
while ($row=mysql_fetch_object($result)){
if ($cnt&1) echo "<tr class=oddrow>";
else echo "<tr class=evenrow>";
echo "<td>";
if (isset($_SESSION['user_id'])) echo check_ac($cid,$cnt);
if(!$end_flag){
echo "<td>Problem $PID[$cnt]
<td><a href='problem.php?cid=$cid&pid=$cnt'>$row->title</a>
";}
else
{
echo "<td>Problem $PID[$cnt]
<td><a href='problem.php?id=$row->pid'>$row->title</a>
";}
echo "<td><center>";
if($R[$cnt][8]=="")
echo "0.00%";
else
echo sprintf( "%.02lf%%",100*$R[$cnt][0]/$R[$cnt][8]);
echo "(";
if($R[$cnt][0]=="")
echo "0";
else
echo $R[$cnt][0];
echo "/";
if($R[$cnt][8]=="")
echo "0";
else
echo $R[$cnt][8];
echo ")";
$cnt++;
}
echo "</tr></table><br>";
mysql_free_result($result);
echo "[<a href='status.php?cid=$cid'>Status</a>]";
echo "[<a href='contestrank.php?cid=$cid'>Standing</a>]";
echo "[<a href='conteststatistics.php?cid=$cid'>Statistics</a>]";
echo "</center>";
}else{
require_once("oj-header.php");
?>
<title>Contest List</title>
<?
$sz=30;
$sql="SELECT * FROM `contest` WHERE `defunct`='N'";
if (isset($_GET['page']))
$page=strval(intval($_GET['page']));
else $page=0;
$start=$page*$sz;
if(isset($_GET['search'])){
$search=trim(mysql_real_escape_string($_GET['search']));
if($search!='')
$sql=$sql." and title like '%$search%' ORDER BY `contest_id` DESC ";
}else
//$sql=$sql." ORDER BY `contest_id` DESC limit $start,$sz";
$sql=$sql." ORDER BY `start_time` DESC,`contest_id` DESC limit $start,$sz";
$result=mysql_query($sql);
$rows_cnt = mysql_num_rows($result);
$color=false;
echo "<center><h2>Contest List</h2><form>ServerTime:<span id=nowdate></span> <td>   <input type='text' name='search'><input type='submit' value='$MSG_SEARCH'</td></form> ";
echo "<table width=85%><tr class=toprow align=center>
<td width=5%>ID
<td width=55%>Contest Name
<td width=18%>Start time
<td width=8%>Status
<td width=30%>Type
</tr>";
while ($row=mysql_fetch_object($result)){
if ($color) echo "<tr align=center class=oddrow>";
else echo "<tr align=center class=evenrow>";
echo "<td>$row->contest_id</td>";
echo "<td><div style=\"float:left;\"><a href='contest.php?cid=$row->contest_id'>$row->title</a></div>";
$start_time=strtotime($row->start_time);
$end_time=strtotime($row->end_time);
$reg_start_time=strtotime($row->reg_start_time);
$reg_end_time=strtotime($row->reg_end_time);
$now=time();
//0 public 1 private 2 register
if($row->private=='2'){
if (($now>=$reg_start_time)&& ($now<=$reg_end_time))
{
$query_cnt=0;
if(isset($_SESSION['user_id']))
{
$user_id=$_SESSION['user_id'];
$sql2="SELECT * FROM `contestreg` WHERE `contestreg`.`user_id`='".$user_id."' AND `contestreg`.`contest_id`='$row->contest_id'";
$result2=mysql_query($sql2);
if($result2)
$query_cnt=mysql_num_rows($result2);
else
$query_cnt=0;
if($query_cnt>0)
$row2=mysql_fetch_array($result2);
mysql_free_result($result2);
}
//do not register
if((!isset($_SESSION['user_id']))||($query_cnt==0)){
echo "<div style=\"float:right;text-align:right;font-size:90%\">
<a href='cstregisterpage.php?cid=$row->contest_id' title='Register\nStart time:$row->reg_start_time\nEnd time:$row->reg_end_time'>
<font color=white style='background-color:rgb(15,209,22)'><u><strong>$MSG_CSTREGISTER >></strong></u></font></a> </div>";
}
else{
if($row2['ispending']!=1)
echo "<div style=\"float:right;text-align:right;font-size:90%\">
<a href='updateregisterpage.php?cid=$row->contest_id' title='Register\nStart time:$row->reg_start_time\nEnd time:$row->reg_end_time'>
<font color=white style='background-color:rgb(15,209,22)'><u><strong>$MSG_MODIFYREGISTER</strong></u></font></a> </div>";
else
echo "<div style=\"float:right;text-align:right;font-size:90%\">
<a href='contestrank.php?cid=$row->contest_id'>
<span style='color:blue'><u>Standings</u></span></a> <div>";
}
}
else{
echo "<div style=\"float:right;text-align:right;font-size:90%\">
<a href='contestrank.php?cid=$row->contest_id'>
<span style='color:blue'><u>Standings</u></span></a> <div>";
}
}
else{
echo "<div style=\"float:right;text-align:right;font-size:90%\">
<a href='contestrank.php?cid=$row->contest_id'>
<span style='color:blue'><u>Standings</u></span></a> <div>";
}
echo "<td>$row->start_time";
// past
if ($now>$end_time) echo "<td><font color=green>Ended</font>";
// pending
else if ($now<$start_time) echo "<td><font color=blue>Pending</font>";
// running
else echo "<td><font color=red> Running </font>";
$private=intval($row->private);
if ($private==0) echo "<td><font color=blue>Public</font>";
else if($private==1) echo "<td><font color=red>Private</font>";
else {
if ($now>$reg_end_time) echo "<td><font color=gray title='Registration\nStart time:$row->reg_start_time\nEnd time:$row->reg_end_time'>Registration Ended</font>";
else if ($now<$reg_start_time) echo "<td><font color=blue title='Registration\nStart time:$row->reg_start_time\nEnd time:$row->reg_end_time'>Registration Pending</font>";
else echo "<td><font color=red title='Registration\nStart time:$row->reg_start_time\nEnd time:$row->reg_end_time'>Registering</font>";
//echo "<br><font size=1px>Start:$row->reg_start_time";
//echo "<br>End:$row->reg_end_time";
$tmpsql="SELECT count(`user_id`) FROM `contestreg` WHERE `contestreg`.`contest_id`='$row->contest_id'";
$tmpresult=mysql_query($tmpsql);
$tmprow=mysql_fetch_array($tmpresult);
$cntpeople=intval($tmprow[0]);
mysql_free_result($tmpresult);
echo "<td><a href='showallregister.php?cid=$row->contest_id'><img src='./image/user.png'>x$cntpeople";
}
echo "</tr>";
$color=!$color;
}
echo "</table></center>";
mysql_free_result($result);
if (!isset($_GET['search'])){
echo "<center><a href='contest.php'>[Top]</a>";
if($page>0){
$page--;
echo " <a href='contest.php?page=$page'>[Previous]</a>";
$page++;
}
else
{
echo " <a href='contest.php'>[Previous]</a>";
}
if($rows_cnt==$sz){
$page++;
echo " <a href='contest.php?page=$page'>[Next]</a>";
$page--;
}
else
echo " <a href='contest.php?page=$page'>[Next]</a>";
echo "</center>";
}
?>
<?
}
require_once("oj-footer.php");
?>
<script>
var diff=new Date("<?=date("Y/m/d H:i:s")?>").getTime()-new Date().getTime();
//alert(diff);
function clock()
{
var x,h,m,s,n,xingqi,y,mon,d;
var x = new Date(new Date().getTime()+diff);
y = x.getYear()+1900;
if (y>3000) y-=1900;
mon = x.getMonth()+1;
d = x.getDate();
xingqi = x.getDay();
h=x.getHours();
m=x.getMinutes();
s=x.getSeconds();
n=y+"-"+mon+"-"+d+" "+(h>=10?h:"0"+h)+":"+(m>=10?m:"0"+m)+":"+(s>=10?s:"0"+s);
//alert(n);
document.getElementById('nowdate').innerHTML=n;
setTimeout("clock()",1000);
}
clock();
</script>