-
Notifications
You must be signed in to change notification settings - Fork 0
/
function.php
224 lines (166 loc) · 6.6 KB
/
function.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
<?php
function getAllUsers() {
$result = mysql_query("select * FROM traffictable");
return $result;
}
function myfunction() {
echo "hai";
}
//Storing new user and returns user details
function storeUser($Email, $Password, $Name,$Age,$Contact,$City,$State,$sex,$GcmId,$profile_pic) {
// insert user into database
$result = mysql_query("INSERT INTO logintable(Email, Password, Name,Age,Contact,City,State,sex,GcmId,profile_pic) VALUES('$Email', '$Password', '$Name','$Age','$Contact','$City','$State','$sex','$GcmId','$profile_pic')");
// check for successful store
if ($result) {
// get user details
$id = mysql_insert_id(); // last inserted id
$result = mysql_query("SELECT * FROM logintable WHERE Email = '$Email'") or die(mysql_error());
// return user details
if (mysql_num_rows($result) > 0) {
return mysql_fetch_array($result);
} else {
return false;
}
} else {
return false;
}
}
function storeFacebookUser($Email, $Password, $Name,$Age,$Contact,$City,$State,$sex,$GcmId,$profile_pic) {
// insert user into database
$result = mysql_query("INSERT INTO logintable(Email, Password, Name,Age,Contact,City,State,sex,GcmId,profile_pic,Type) VALUES('$Email', '$Password', '$Name','$Age','$Contact','$City','$State','$sex','$GcmId','$profile_pic','FACEBOOK')");
// check for successful store
if ($result) {
// get user details
$id = mysql_insert_id(); // last inserted id
$result = mysql_query("SELECT * FROM logintable WHERE Email = '$Email'") or die(mysql_error());
// return user details
if (mysql_num_rows($result) > 0) {
return mysql_fetch_array($result);
} else {
return false;
}
} else {
return false;
}
}
function isUserExisted($Email) {
$result = mysql_query("SELECT email from logintable WHERE Email = '$Email'");
$NumOfRows = mysql_num_rows($result);
if ($NumOfRows > 0) {
// user existed
return true;
} else {
// user not existed
return false;
}
}
function getUserDetail($Email) {
$result = mysql_query("SELECT * from logintable WHERE Email = '$Email'");
$NumOfRows = mysql_num_rows($result);
if ($NumOfRows <= 0) {
echo "null";
return;
}
$rows = array();
while($r = mysql_fetch_assoc($result))
$rows[] = $r;
echo json_encode($rows);
}
function login($LoginEmail,$LoginPassword) {
$result = mysql_query("SELECT * from logintable WHERE Email = '$LoginEmail' and Password ='$LoginPassword'" );
$NumOfRows = mysql_num_rows($result);
if ($NumOfRows <= 0) {
echo "failed";
return;
}
$rows = array();
while($r = mysql_fetch_assoc($result))
$rows[] = $r;
echo json_encode($rows);
}
function storeComplaint( $Priority, $myLocation, $User,$message,$Category,$filename) {
if($Category=="traffictable")
$value="traffic";
else
if($Category=="policetable")
$value="police";
else
if($Category=="mescomtable")
$value="mescom";
else
if($Category=="mnpotable")
$value="mnpo";
// insert user into database
$result = mysql_query("INSERT INTO ".$Category."(Priority, myLocation, userId,message,image) VALUES('$Priority', '$myLocation', '$User','$message','$filename')");
// check for successful store
if ($result) {
// get user details
$id = mysql_insert_id(); // last inserted id
$result = mysql_query("SELECT * FROM ".$Category." WHERE image = '$filename'") or die(mysql_error());
// return user details
if (mysql_num_rows($result) > 0) {
$GcmIdresult=mysql_query("SELECT * FROM logintable WHERE Email = '$User'") or die(mysql_error());
while ($row = mysql_fetch_assoc($GcmIdresult))
{
$gcmRegID=$row['GcmId'];
}
$registatoin_ids = array($gcmRegID);
$completeId="complete registred ID ".$value."_".$id;
$message = array("message" => $completeId);
$push_notif_result = send_push_notification($registatoin_ids, $message);
return mysql_fetch_array($result);
} else {
return false;
}
} else {
return false;
}
}
function updateProfilePic( $User,$filename) {
// insert user into database
$result = mysql_query("UPDATE `logintable` SET `profile_pic`='$filename' WHERE Email='$User'");
// check for successful store
if ($result) {
return true;
} else {
return false;
}
}
function sendNotification( $id,$User,$Category){
}
function send_push_notification($registatoin_ids, $message) {
// Set POST variables
$url = 'https://android.googleapis.com/gcm/send';
$fields = array(
'registration_ids' => $registatoin_ids,
'data' => $message,
);
$headers = array(
'Authorization: key=' . GOOGLE_API_KEY,
'Content-Type: application/json'
);
//print_r($headers);
// Open connection
$ch = curl_init();
// Set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Disabling SSL Certificate support temporarly
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
// Execute post
$result = curl_exec($ch);
if ($result === FALSE) {
die('Curl failed: ' . curl_error($ch));
}
// Close connection
curl_close($ch);
echo $result;
}
function updateUser($Email, $Password, $Name,$Age,$Contact,$City,$State,$sex,$GcmId,$profile_pic) {
$result = mysql_query("UPDATE logintable SET Name='$Name',Name='$Name',Age='$Age',Contact='$Contact',
State='$State',sex='$sex',GcmId='$GcmId',profile_pic='$profile_pic' WHERE Email='$Email'");
}
?>