-
Notifications
You must be signed in to change notification settings - Fork 0
/
phpjs.php
executable file
·272 lines (236 loc) · 10 KB
/
phpjs.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
<?php session_start();
require_once("sitelib.php");
// Default response
$response = array('ok' => false, 'msg' => "Invalid Javascript Request");
$javascriptReqType = $_POST['action'];
if(isset($javascriptReqType))
{
if($javascriptReqType == "login" || $javascriptReqType == "registerUser")
{
$username = $_POST['username'];
$password = $_POST['password'];
if($javascriptReqType == "registerUser")
{
// Register your user here :
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$passcode = $_POST['passcode'];
$expectedPasscode = "qreventgroup";
// Purposely change this such that user will login after registering
if ($passcode == $expectedPasscode) {
openDatabase();
// Check if username already exists
$query = "SELECT * FROM admins WHERE email='" . $username . "';";
$result = getQueryCount($query);
$status = false;
$msg = "A user already exists with that email ID";
if (0 == $result) {
$query = sprintf("INSERT INTO admins VALUES(NULL, '%s', '%s', '%s', '%s');",
$fname, $lname, $password, $username);
$result = mysql_query($query);
$status = true;
$msg = "OK";
// Change the request to "login" such that user can be logged in below.
$javascriptReqType = "login";
$response['d1'] = $result;
}
closeDatabase();
$response = array('ok' => $status, 'msg' => $msg);
}
else {
$response = array('ok' => false, 'msg' => "Invalid passcode");
}
}
if($javascriptReqType == "login")
{
$loginOk = false;
if($username != "" && $password != "") {
$query = "SELECT * FROM admins WHERE email='" . $username . "';";
openDatabase();
$result = mysql_query($query);
$result = mysql_fetch_assoc($result);
closeDatabase();
$loginOk = ($result['password'] == $password);
}
if(!$loginOk) {
$response = array('ok' => false, 'msg' => "Login Failed.");
}
else
{
session_start();
$_SESSION['isValid'] = true;
$_SESSION['sess_username'] = $username;
$response = array('ok' => true, 'msg' => "OK",
'navBarData' => getNavBar(),
'sideBarData' => getSideBar()
);
}
}
}
// Next requests until isUserLoggedIn() are permitted without user registration
else if($javascriptReqType == "Registered")
{
$response = array('ok' => true, 'msg' => "OK");
$event_id = $_POST['event_id'];
openDatabase();
$result = mysql_query("SELECT sjsu_id, first_name, last_name, event_name,
qr_code, is_checked_in From ".DB_SCHEMA.".qr_codes Where event_id = " . $event_id .";");
$result_array = array();
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$result_array[] = $row;
}
$response['registered'] = $result_array;
$response['event_id'] = $event_id;
closeDatabase();
}
else if($javascriptReqType == "getSampleNames")
{
$response = array('ok' => true, 'msg' => "OK");
$response['sample_names'] = array(
0=> array(
'name' => 'Arturo Montoya',
'email' => '[email protected]',
'role' => 'Android App & Web Developer',
),
1=> array(
'name' => 'Darryl DelaCruz',
'email' => '[email protected]',
'role' => 'Android App & Web Developer',
'link' => '<a href="http://www.linkedin.com/in/darrylndelacruz">
<img
src="https://static.licdn.com/scds/common/u/img/webpromo/btn_viewmy_160x33.png"
width="160" height="33" border="0" alt="View Darryl DelaCruz\'s profile on LinkedIn">
</a>'
),
2=> array(
'name' => 'Phuoc Tran',
'email' => '[email protected]',
'role' => 'Android App & Web Developer',
'link' => '<a href="http://www.linkedin.com/in/phuoctran">
<img src="https://static.licdn.com/scds/common/u/img/webpromo/btn_viewmy_160x33.png" width="160" height="33" border="0" alt="View Phuoc Trans profile on LinkedIn">
</a>',
),
3=> array(
'name' => 'Erik Montoya',
'email' => '[email protected]',
'role' => 'Android App & Web Developer',
)
);
}
// Rest of the request require user being logged in, so reject everything if user is not logged in
else if (!isUserLoggedIn())
{
$response = array('ok' => false, 'msg' => "Invalid session, please login again");
}
else if($javascriptReqType == "logout")
{
$response = array('ok' => true, 'msg' => "OK");
$_SESSION['isValid'] = false;
session_destroy();
}
/* User creating an event with list of attendees */
else if($javascriptReqType == "createAdminEvent")
{
$name = $_POST['name'];
$time = $_POST['time'];
$info = $_POST['info'];
$file = $_POST['file'];
$inviteList = $_POST['list'];
$response = createNewEvent($name, $time, $inviteList, $info);
$event_id = mysql_insert_id();
//include ("commitAttendees.php");
//commitAttendees($event_id, $file);
/* TODO - Remove csvParseLegacy, merge code, Fix $event_id so that it accurately passes the correct ID */
}
else if($javascriptReqType == "createAdminMultiEvent")
{
$name = $_POST['name'];
$info = $_POST['info'];
$eventids = $_POST['eventids'];
$response = createNewMultiEvent($name, $info, $eventids);
$multi_event_id = mysql_insert_id();
//include ("commitAttendees.php");
//commitAttendees($event_id, $file);
/* TODO - Remove csvParseLegacy, merge code, Fix $event_id so that it accurately passes the correct ID */
}
/* Users retrieving a list of their events */
else if($javascriptReqType == "getAdminEvents")
{
$response = getAdminEvents();
}
else if($javascriptReqType == "getAdminMulitEvents")
{
$response = getAdminMultiEvents();
}
else if($javascriptReqType == "getAdminInfo")
{
$response = getAdminInfo();
}
/* User deleting a created event */
else if($javascriptReqType == "deleteAdminEvent")
{
$id = $_POST['eventId'];
$response = deleteAdminEvent($id);
}
/* User retrieving list of attendees of an event */
else if($javascriptReqType == "getEventAttendeeList")
{
$id = $_POST['eventId'];
$response = getEventAttendeeList($id);
}
/* Check-in or Check-out an attendee
* This is the API for an admin that has already logged in.
*/
else if($javascriptReqType == "checkinCheckoutAttendee")
{
$userId = $_POST['userId'];
$eventId = $_POST['eventId'];
$checkedIn = $_POST['checkedIn'];
$response = checkinCheckoutAttendee($userId, $eventId, $checkedIn);
}
/* Get the last X number of checkins */
else if($javascriptReqType == "getLastCheckinList")
{
$minutes = $_POST['minutes'];
$eventId = $_POST['eventId'];
$response = getLastCheckinList($minutes, $eventId);
}
/* User retrieving values for attendees per hour of an event */
else if($javascriptReqType == "getEventAttendeeCount")
{
$id = $_POST['eventId'];
//$time = "2013-11-25 03:08:53";//$_POST['time']; // Would like to start from initial event time
$response = getEventAttendeeCount($id);
}
else if($javascriptReqType == "createQRcode")
{
$image_filename = "images/" . md5(date('DdMYHis')) . ".png";
$response = array('ok' => true, 'msg' => "OK");
$comment = $_POST['comment'];
include "phpqrcode/qrlib.php";
QRcode::png($comment, $image_filename); //, $errorCorrectionLevel, $matrixPointSize, 2); ^M
$response['filename'] = $image_filename;
}
/* User retrieving list of attendees of an event */
else if($javascriptReqType == "getEventAttendeeListOrientation")
{
$id = $_POST['eventId'];
$response = getEventAttendeeListOrientation($id);
}
/* User retrieving values for attendees per hour of an event */
else if($javascriptReqType == "getEventAttendeeCountOrientation")
{
$id = $_POST['eventId'];
$time = "2013-11-25 03:08:53";//$_POST['time']; // Would like to start from initial event time
$response = getEventAttendeeCountOrientation($id);
}
else if($javascriptReqType == "getMailLog")
{
$stuff = file_get_contents('mail.log');
$response = array('ok' => true, 'msg' => "OK");
$response["filecontent"] = $stuff;
}
} // isset()
echo json_encode($response);
exit;
?>