-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontestsubmit.php
executable file
·310 lines (192 loc) · 6.17 KB
/
contestsubmit.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
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
<?php
session_start();
date_default_timezone_set("Asia/Dhaka");
require_once "config.php";
$_SESSION['url'] = $_SERVER['REQUEST_URI'];
if (!isset($_SESSION['un'])) {
header("Location:login.php");
}
if (isset($_SESSION['un'])) {
$username = $_SESSION['un'];
}
$mysql = "SELECT status from user WHERE name='$username'";
$snd = mysqli_query($con, $mysql);
$arrow = mysqli_fetch_array($snd);
$st = $arrow['status'];
$c = 0;
$access = 0;
if (isset($_GET['id'])) {
$problemid = $_GET['id'];
$c = 1;
} else {
header("Location:contest.php");
}
$sql = "SELECT * FROM contestproblems WHERE pbid='$problemid' ";
$sq = mysqli_query($con, $sql);
$r1 = mysqli_fetch_array($sq);
$conid = $r1['id'];
$mycon = "SELECT * from contest WHERE id='$conid'";
$sendcon = mysqli_query($con, $mycon);
$rhis = mysqli_fetch_array($sendcon);
$owner = $rhis['owner'];
$passdb = $rhis['pass'];
if ($username == $owner) {
$access = 1;
} else if ($st == "Teacher" || $st == "Developer") {
$access = 1;
}
if ($passdb != NULL && $access == 0) {
if (!isset($_SESSION["con" . $conid])) {
header("Location:countdown.php?id=$conid");
}
}
//echo "<textarea style=\"display:none;\" name=\"in\"
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Submit</title>
<?php include 'linkers.php';?>
<script>
// Set the date we're counting down to
function call(d,val,st,xd){
//console.log(d);
//console.log(val);
//console.log(st);
var countDownDate = new Date(d).getTime();
var start =new Date(st).getTime();
var nowserver=xd;
//document.write(nowserver + "<br>");
nowserver= new Date(nowserver).getTime();
var nowclient = Math.floor(new Date().getTime());
var diff= nowserver-nowclient;
//console.log(start);
var result;
// Update the count down every 1 second
var x = setInterval(function() {
// Get todays date and time
var now = new Date().getTime();
now+=diff;
// Find the distance between now an the count down date
if(start>now)
{
var distance = start - now;
// Time calculations for days, hours, minutes and seconds
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
// Output the result in an contestproblems with id="demo"
var result=days + "d " + hours + "h "
+ minutes + "m " + seconds + "s ";
//console.log(result);
//document.getElementById(val).innerHTML = "Countdown : " + days + "d " + hours + "h " + minutes + "m " + seconds + "s ";
}
else if(countDownDate>=now)
{
var distance = countDownDate - now;
// Time calculations for days, hours, minutes and seconds
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
// Output the result in an contestproblems with id="demo"
var result=days + "d " + hours + "h "
+ minutes + "m " + seconds + "s ";
//console.log(result);
//document.getElementById(val).innerHTML = " Running.... : "+ days + "d " + hours + "h "
//+ minutes + "m " + seconds + "s ";
document.getElementById("show").style.display="block";
}
// If the count down is over, write some text
else if (now>countDownDate) {
clearInterval(x);
document.getElementById("fin").innerHTML = "Contest has Finished";
}
}, 1000);
return x;
}
</script>
</head>
<body>
<div class="main">
<?php require 'nav2.php';?>
<div class="row log">
<div class="col-sm-12">
<center><h3 >Submit Code</h3></center>
</div>
</div>
<br>
<br>
<div class="row ">
<div class="col-sm-2"></div>
<div class="col-sm-8">
<div class="form-group">
<form action="pcompile.php" name="f2" method="POST">
<label for="language">Choose Language</label>
<select class="form-control rb" name="language">
<option value="c">C</option>
<option value="cpp">C++</option>
<option value="cpp11">C++11</option>
<!-- <option value="java">Java</option> -->
<!--<option value="python2.7">Python2</option>
<option value="python3.2">Python2</option>-->
</select><br><br>
<?php
if ($c == 1) {
//echo "<input type=\"hidden\" name=\"pbn\" value=\"$problem\">";
echo "<input type=\"hidden\" name=\"id\" value=\"$problemid\">";
} else {
echo "<label for=\"pp\">Enter Problem ID</label><br>";
//echo "<input class=\"form-control\" type=\"text\" name=\"pbn\">";
echo "<input class=\"form-control\" type=\"text\" name=\"id\">";
}
?>
<label for="ta">Write Your Code</label>
<textarea class="form-control rb" name="src" rows="10" cols="50" required></textarea><br><br>
<input type="hidden" name='pbn' value="<?php echo $r1['pbname']; ?>">
<!--<input type="submit" class="btn btn-success" value="Submit"><br><br><br>-->
<?php
$conid = $r1['id'];
$q3 = "SELECT * FROM contest WHERE id='$conid'";
$sq3 = mysqli_query($con, $q3);
$i = 0;
while ($row = mysqli_fetch_array($sq3)) {
$current = date("Y-m-d H:i:s ");
$nv = $row['start_at'];
// $i++;
// $demo="demo"+"$i";
$en = $row['end_at'];
?>
<script type="text/javascript">
var end=<?php print json_encode($en);?>;
var val=<?php print json_encode($i);?>;
var nv=<?php print json_encode($nv);?>;
var cur=<?php print json_encode(date("Y-m-d H:i:s "));?>;
//console.log("Start" +nv);
call(end,val,nv,cur);
</script>
<?php
$diff = strtotime($nv) - strtotime($current);
$current = strtotime($current);
// echo "$current<br>";
//echo "$diff";
if ($diff > 0) {
header("Location:countdown.php?id=$conid");
}
echo ("<div id=\"show\" style=\"display:none;\"><input type=\"submit\" class=\"btn btn-success\" value=\"Submit\"></div><br><br><br>");
echo ("<div id=\"fin\"></div>");
}
?>
</form><br><br>
</div>
<div class="col-sm-4">
</div>
</div>
</div>
</div><br><br><br>
<?php require 'footer.php';?>
</body>
</html>