-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubmitanswer.php
More file actions
280 lines (208 loc) · 8.21 KB
/
Copy pathsubmitanswer.php
File metadata and controls
280 lines (208 loc) · 8.21 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
<?php include "inc/header.php"; ?>
<link rel="stylesheet" href="css/login.css">
<style>
label {
cursor: pointer;
/* Style as you please, it will become the visible UI component. */
}
#upload-photo ,#savebtn{
opacity: 0;
position: absolute;
z-index: -1;
}
</style>
<?php
$db = new Database();
$format = new Format();
$add = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
//!isset($_SESSION['name'],$_SESSION['login']) ||
if (!(isset($_SESSION['name'], $_SESSION['login']) || isset($_SESSION['ins_name'], $_SESSION['ins_login']))) {
header("location: login.php?reurl=".$add);
}
if(isset($_SESSION['name'], $_SESSION['login']))
{
$username = $_SESSION['name'];
$userlogin = $_SESSION['login'];
}
elseif(isset($_SESSION['ins_name'], $_SESSION['ins_login']))
{
$username = $_SESSION['ins_name'];
$userlogin = $_SESSION['ins_login'];
}
//Get data
$cat = $format->Stext($_REQUEST['CategoryID']);
$link = $format->Stext($_REQUEST['LinkID']);
//If available link and ccat
if($cat == null)
{
header("location: index.php");
}
elseif($cat == null)
{
header("location: index.php");
}
elseif($link == null)
{
header("location: index.php");
}
elseif($link == null)
{
header("location: index.php");
}
//End that link and cat avality
$query = "SELECT * FROM post where category ='$cat' AND problem ='$link'";
$GetData = $db->select($query)->fetch_assoc();
// </>
//Sensitive Data
$querys = "SELECT * FROM register WHERE user_login = '$userlogin'";
$GetDatas = $db->select($querys)->fetch_assoc();
// </>
$email = $format->Stext($GetDatas['user_email']);
$userid = $format->Stext($GetDatas['id']);
$username = $format->Stext($GetDatas['user_name']);
$userimage = $format->Stext($GetDatas['user_image']);
$userloginss = $format->Stext($GetDatas['user_login']);
$userUniqueID = $format->Stext($GetDatas['user_id']);
$usertype = 'user';
$userip = $_SERVER['REMOTE_ADDR'];
if(isset($_POST['submit']))
{
$ans = $format->Stext($_POST['ans']);
$queryCheck = "SELECT * FROM post where category = '$cat' AND problem = '$link'";
$GetDataCheck = $db->select($queryCheck)->fetch_assoc();
if(!($GetDataCheck['post_ans'] == $ans))
{
echo "<script type='text/javascript'>";
echo "$(document).ready(function(){";
echo "$('#notToast').toast('show')";
echo "});";
echo "</script>";
//insert data to submitted
$querySubmitted = "INSERT INTO submitted(user_unique_id, user_ans, user_email, ip, ans_cat, ans_linkid)
VALUES('$userUniqueID', '$ans', '$email', '$userip','$cat','$link')";
$readpostSubmit = $db->insert($querySubmitted);
//End submitted data
}
else if($GetDataCheck['post_ans'] == $ans){
$querypost = "INSERT INTO answere(user_unique_id,user_ans,user_email,user_id,user_name,user_image,user_login,user_type,ipadd,ans_cat,ans_linkid)
VALUES('$userUniqueID','$ans','$email',$userid,'$username','$userimage','$userloginss','$usertype','$userip','$cat','$link')";
$readpost = $db->insert($querypost);
echo "<script type='text/javascript'>";
echo "$(document).ready(function(){";
echo "$('#toast').toast('show')";
echo "});";
echo "</script>";
//insert data to submitted table
$querypost = "INSERT INTO submitted(user_unique_id, user_ans, user_email, ip, ans_cat, ans_linkid)
VALUES('$userUniqueID', '$ans', '$email', '$userip','$cat','$link')";
$readpost = $db->insert($querypost);
//End submitted data
//Insert points to leaderboard
$checkUserExist = $db->select("SELECT * FROM leaderboard WHERE user_email ='$email'");
if($checkUserExist){
$UserExistRow = $checkUserExist->fetch_assoc();
if(mysqli_num_rows($checkUserExist) > 0){
if($cat == "Daily Math Challenge"){
$points = $UserExistRow['points'] + 2;
}elseif ($cat == "Weekly Math Challenge") {
$points = $UserExistRow['points'] + 5;
}
$incPoint = $db->update("UPDATE leaderboard SET points = '$points' WHERE user_email ='$email'");
}
} else{
if($cat == "Daily Math Challenge"){
$points = 2;
}elseif ($cat == "Weekly Math Challenge") {
$points = 5;
}
$incPoint = $db->insert("INSERT INTO leaderboard(user_email, user_id, points)
VALUES('$email', '$userUniqueID', '$points') ");
}
//End Insert points to leaderboard
}
}
?>
<?php include "inc/sidebar.php"; ?>
<div class="col-xs-12 col-md-10 container-fluid bg-dark text-white rounded" style="padding-top:70px;padding-bottom:70px">
<h2>Answere Submission</h2>
<h2><?php echo $GetData['post_title']?></h2>
<p><?php echo $GetData['category']?> - <?php echo Format::formatDate($GetData['post_date']);?></p>
<p>Posted By - <?php echo $GetData['post_author'];?></p>
<hr>
<p class="text-secondary">
<?php echo $username;?>, welcome to Math Contest! Submit your numeric-only answer below (no brackets, commas, parentheses, spaces) — round to 2 (two) decimal places. If your answer is 0 (zero), enter 0</p>
<form action="" method="post" enctype="multipart/form-data">
<div class="form-group">
<div class="card text-primary">
<div class="card-body">
<p><?php echo $GetData['post_content']?></p>
</div>
</div>
</div>
<div class="form-group">
<p><img class="left-block float-right img-thumbnail" style="max-width: 50%;height: 30rem;" src="<?php echo $GetData['post_image']?>" alt=""></p><br>
</div>
<?php
$bool;
$queryGetTemp = "SELECT * FROM post where category = '$cat' AND problem = '$link'";
$GetDataGetTemp = $db->select($queryGetTemp)->fetch_assoc();
$queryGetUserAns = "SELECT * FROM answere where user_email='$userlogin' AND ans_cat = '$cat' AND ans_linkid = '$link'";
$GetDataGetUserAns = $db->select($queryGetUserAns);
if($GetDataGetUserAns){
while ($getAns = $GetDataGetUserAns->fetch_assoc()) {
if($getAns['user_ans'] == $GetDataGetTemp['post_ans'])
{
$bool = true;
}else {
$bool = false;
}
}
if($bool == true){
echo "<a class='text-danger alert alert-primary'>You have answered already</a>";
}
elseif($bool == false){
?>
Answere :
<div class="m-input-group">
<input name="ans" autocomplete="off" class="m-form-control" style="width:50%;" type="text">
<label>Enter your answere</label>
</div>
<input id="myBtn" type="submit" name="submit" value="Submit Answere" class="m-btn waves-effect">
<?php
}
}else{
?>
Answere :
<div class="m-input-group">
<input name="ans" autocomplete="off" class="m-form-control" style="width:50%;" type="text">
<label>Enter your answere</label>
</div>
<input id="myBtn" type="submit" name="submit" value="Submit Answere" class="m-btn waves-effect">
<?php } ?>
</form>
<!--Tooltip -->
<div id="toast" class="toast" data-autohide="false">
<div class="toast-header">
<strong class="mr-auto text-success">Answere Submitted successfully</strong>
<button type="button" class="ml-2 mb-1 close" data-dismiss="toast">×</button>
</div>
</div>
<!--End Tooltip -->
<!--Tooltip -->
<div id="notToast" class="toast" data-autohide="false">
<div class="toast-header">
<strong class="mr-auto text-danger">Answere not Submitted</strong>
<button type="button" class="ml-2 mb-1 close" data-dismiss="toast">×</button>
</div>
</div>
<!--End Tooltip -->
<p class="text-dark">
<ul>Example:
<li>-1234.56 is a valid answer</li>
<li>-1,234.56 & -1 234,56 are not valid answers</li>
</ul>
</p>
</div>
</div>
</div>
<?php include "inc/footer.php"; ?>