-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcus.setEntry.smartToll.php
167 lines (140 loc) · 4.74 KB
/
cus.setEntry.smartToll.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
<?php
/**
Page Info
Requires : DatabaseConnect.smartToll
@author : Sudipta Saha
@since : 23rd Jan, 2018
This page is used to update the current status of an user and set the entry information.
*/
/*
1= Invalid data or empty data
2= Improper email id and password
3= Failed DatabaseConnectivity, try again.
4= Duplicate username, rejected.
5= MYSQL error
6= no such user
7= not enough balance
*/
/*
* The status codes for tour:
* 0 - Default tour status value.
* 1 - Travelling.
* 2 - Completed.
*/
require("phpMQTT.php");
$curpage=$_SERVER['SCRIPT_NAME'];
$db_tablename='tourDetails';
$errorCode;
$successvalue;
$minbal=5;
$tourid;
if(isset($_POST['username']) && isset($_POST['station_from']) && isset($_POST['gate']) ){
if(!empty($_POST['username']) && !empty($_POST['station_from']) && !empty($_POST['status']) && !empty($_POST['gate'])){
require 'DatabaseConnect.smartToll.php';
$username=$_POST['username'];
$station_from=$_POST['station_from'];
$status=$_POST['status'];
$gate=$_POST['gate'];
if(makeConnection()){
//Get bank information
$query="SELECT money FROM `bankaccount`WHERE username=\"".mysqli_real_escape_string($db_con,$username)."\"";
if(!@$db_result=mysqli_query($db_con,$query)){
$successvalue='false';
$errorCode='5';
}
else{
if(mysqli_num_rows($db_result)==0){
$successvalue='false';
$errorCode='6';
}
else{
$row=mysqli_fetch_assoc($db_result);
$money=floatval($row['money']);
//Get id of the associated user.
if($money>=$minbal){
$query="SELECT id FROM `cusrecord` WHERE username=\"".mysqli_real_escape_string($db_con,$username)."\"";
if(!@$db_result=mysqli_query($db_con,$query)){
$successvalue='false';
$errorCode='5';
}
else{
if(mysqli_num_rows($db_result)==0){
$successvalue='false';
$errorCode='6';
}
else{
$row=mysqli_fetch_assoc($db_result);
$userid=$row['id'];
//Making a unique tourid
$query="SELECT COUNT(*) FROM `tourdetails` WHERE userid=$userid";
if(!@$db_result=mysqli_query($db_con,$query)){
$successvalue='false';
$errorCode='5';
}
else{
$row=mysqli_fetch_assoc($db_result);
$curmax=$row['COUNT(*)'];
$curmax=$curmax+1;
$tourid=$userid."_".$curmax;
//Setting new tour
$query= "INSERT INTO `$db_tablename` (`tourid`,`userid`, `station_from`, `status`) VALUES (\"$tourid\", $userid, '".mysqli_real_escape_string($db_con,$station_from)."', '".mysqli_real_escape_string($db_con,$status)."')";
//echo $query;
if($db_result=mysqli_query($db_con,$query)){
$successvalue='true';
$errorCode='null';
//Use details of your MQTT client
/*$server = "..."; // change if necessary
$port = ...; // change if necessary
$username = "..."; // set your username
$password = "..."; // set your password
*/
$client_id = "phpMQTT-publisher"; // make sure this is unique for connecting to sever - you could use uniqid()
$mqtt = new phpMQTT($server, $port, $client_id);
if ($mqtt->connect(true, NULL, $username, $password)) {
$info['gate']=$gate;
$info['station']=$station_from;
$info=json_encode($info);
//Publish information on the channel of the associated gate that needs to be opened
$mqtt->publish("smartToll", $info , 0);
$mqtt->close();
} else {
echo "Time out!\n";
}
}
else{
$successvalue='false';
$errorCode='5';
}
}
//
}
}
}
else{
$successvalue='false';
$errorCode='7';
}
}
}
mysqli_close($db_con);
}
else{
$successvalue='false';
$errorCode='3';
}
}
else{
$successvalue='false';
$errorCode='1';
}
}
else{
$successvalue='false';
$errorCode='1';
}
if(!empty($successvalue)){
$result= array('success' => $successvalue, 'errorCode' => (string)$errorCode, 'tourid' => $tourid);
$result=json_encode($result);
echo $result;
}
?>