-
Notifications
You must be signed in to change notification settings - Fork 0
/
getanswer.php
129 lines (123 loc) · 3.68 KB
/
getanswer.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
<?php
session_start();
if(!isset($_SESSION['username']))
{
die();
}
require_once("dbconnection.php");
if($_GET['option'])
{
$option=mysqli_real_escape_string($con,($_GET['option']));
$sid=mysqli_real_escape_string($con,($_GET['id']));
$username=$_SESSION['username'];
$sql="select * from oe_mechatron_users where Username='$username'";
$result=mysqli_query($con,$sql);
$row=mysqli_fetch_array($result,MYSQL_ASSOC);
$qno=$row['QNo'];
$answered=$row['Answered'];
$sql="select * from oe_mechatron_questions where Id='$qno' and (O1='$option' OR O2='$option' OR O3='$option' OR O4='$option' OR O5='$option' OR O6='$option')";
$result=mysqli_query($con,$sql);
$count=mysqli_num_rows($result);
if($count==1 && $answered!=3)
{
$sql="select * from oe_mechatron_answers where O='$option'";
$result=mysqli_query($con,$sql) or die(mysqli_error());
$row=mysqli_fetch_array($result,MYSQL_ASSOC);
$status=$row['Status'];
$username=$_SESSION['username'];
if($status==1)
{
$sql2="select * from oe_mechatron_currentstate where SId='$sid' and Username='$username'";
$result2=mysqli_query($con,$sql2);
$count2=mysqli_num_rows($result2);
if($count2==0)
{
$sql="select * from oe_mechatron_users where Username='$username'";
$result=mysqli_query($con,$sql);
$row=mysqli_fetch_array($result,MYSQL_ASSOC);
$answered=$row['Answered'];
$answered++;
$sql="update oe_mechatron_users set Answered='$answered' where Username='$username'";
$result=mysqli_query($con,$sql);
$sql="select * from oe_mechatron_users where Username='$username'";
$result=mysqli_query($con,$sql);
$row=mysqli_fetch_array($result,MYSQL_ASSOC);
$opt=$row['Options'];
$opt=unserialize($opt);
$key=array_search($option, $opt);
if($key!==FALSE)
{
unset($opt[$key]);
$store=serialize($opt);
$sql="update oe_mechatron_users set Options='$store' where Username='$username'";
$result=mysqli_query($con,$sql);
$sql="select * from oe_mechatron_users where Username='$username'";
$result=mysqli_query($con,$sql);
$row=mysqli_fetch_array($result,MYSQL_ASSOC);
$sql1="insert into oe_mechatron_currentstate(Username,SId,Color,Flag) values('$username','$sid',1,0)";
$result1=mysqli_query($con,$sql1);
$data=array("status"=>"1",
"color"=>"rgb(46,254,46)");
echo json_encode($data);
}
}
else
{
$data=array("status"=>"reload");
}
}
else
{
$sql2="select * from oe_mechatron_currentstate where SId='$sid' and Username='$username'";
$result2=mysqli_query($con,$sql2);
$count2=mysqli_num_rows($result2);
if($count2==0)
{
$sql="select * from oe_mechatron_users where Username='$username'";
$result=mysqli_query($con,$sql);
$row=mysqli_fetch_array($result,MYSQL_ASSOC);
$answered=$row['Answered'];
$answered++;
$sql="update oe_mechatron_users set Answered='$answered' where Username='$username'";
$result=mysqli_query($con,$sql);
$sql="select * from oe_mechatron_users where Username='$username'";
$result=mysqli_query($con,$sql);
$row=mysqli_fetch_array($result,MYSQL_ASSOC);
$opt=$row['Options'];
$opt=unserialize($opt);
$key=array_search($option, $opt);
if($key!==FALSE)
{
unset($opt[$key]);
$store=serialize($opt);
$sql="update oe_mechatron_users set Options='$store' where Username='$username'";
$result=mysqli_query($con,$sql);
$sql="select * from oe_mechatron_users where Username='$username'";
$result=mysqli_query($con,$sql);
$row=mysqli_fetch_array($result,MYSQL_ASSOC);
$sql1="insert into oe_mechatron_currentstate(Username,SId,Color,Flag) values('$username','$sid',0,0)";
$result1=mysqli_query($con,$sql1);
$data=array("status"=>"1",
"color"=>"rgb(255,0,0)");
echo json_encode($data);
}
else
{
$data=array("status"=>"reload");
echo json_encode($data);
}
}
else
{
$data=array("status"=>"reload");
echo json_encode($data);
}
}
}
else
{
$data=array("status"=>"reload");
echo json_encode($data);
}
}
?>