forked from keithloughnane/TaxiServer
/
server.php
666 lines (551 loc) · 20.3 KB
/
server.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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
<?php
/*
Taxa server to be used with Taxa iPhone App.
Copyright 2011 <name>
V1 Writen by Keith Loughnane (loughnanedevelopment@gmail.com)
*/
//Only use echo of device data
//Use debugMsg for debuging
//TODO Time
require_once ("gps_class.php");
$AproachDist = 5; //KM
$ArriveDist = 0.5; //KM
$timeoutTime = (5*60); //Seconds
$id = $_GET['id'];
$url = $_SERVER[SCRIPT_NAME]."?".$_SERVER[QUERY_STRING];
$debug = false;
//Setup MySQL connection
$conn = mysql_connect("mysql9.unoeuro.com","needataxino_com","opjunk64");
mysql_select_db("needataxinow_com_db",$conn);
//See if there is anything to be done, most timeouts for inactive devices
//Uncomment to reset
/*
$sqlStmnt = "delete from messages";
$result = mysql_query($sqlStmnt,$conn);
$sqlStmnt1 = "delete from devices";
$result = mysql_query($sqlStmnt1,$conn);
$sqlStmnt2 = "delete from pickupCalc";
$result = mysql_query($sqlStmnt2,$conn);
$sqlStmnt3 = "delete from pickups";
$result = mysql_query($sqlStmnt3,$conn);
*/
debugMsg("BEGINING INTERACTION URL=" . $url);
//housekeeping();
if(isset($_GET['msgtype']))
{
$messageType = $_GET['msgtype'];
// Figure out which message was recieved and hand off
switch ($messageType)
{
/*case "debug":
{
debugMsg( "*********************************************************************************************************************");
//----------Debug Mode---------------------------
$id = -1;
header( 'refresh: 5; url='.$url );
//recievedGetMessages(-1);
$debug = true;
}
break;*/
case "setPosition":
{
//preg_replace('/[^a-zA-Z0-9\ .-]/','',$var) ;
//-----------Device Setting Possition-----------------
echo("setPosition in switch");
$id = mysql_real_escape_string($_GET['id']);
$llong = mysql_real_escape_string( $_GET['llong']);
//$llat = $_GET['llat'];
$llat = mysql_real_escape_string($_GET['llat']);
recievedSetPosition($id, $llong, $llat);
}
break;
case "requestPickup":
{
//----------Device/Customer Requesting Pickup--------
$id = mysql_real_escape_string( $_GET['id']);
$llong = mysql_real_escape_string( $_GET['llong']);
$llat = mysql_real_escape_string( $_GET['llat']);
recievedRequestPickup($id, $llong, $llat);
}
break;
case "acceptPickup":
{
//----------Device/Taxi Accepting Pickup Request-------
$id = mysql_real_escape_string($_GET['id']);
$pickupid = mysql_real_escape_string($_GET['pickupid']);
recievedAcceptPickup($id, $pickupid);
}
break;
case "refusePickup":
{
//----------Device/Taxi Refusing Pickup Request--------
$id = mysql_real_escape_string($_GET['id']);
$pickupid = mysql_real_escape_string($_GET['pickupid']);
recievedRefusePickup($id, $pickupid);
}
break;
case "activate":
{
//----------Device is checking to keep active-----------
$id = mysql_real_escape_string($_GET['id']);
$mode = mysql_real_escape_string($_GET['mode']);
debugMsg("Activate ID=" . $id . "Mode = " . $mode);
recievedActivate($id,$mode);
}
break;
case "deActivate":
{
//----------Device is deactivating (like logoff)-----------
$id = mysql_real_escape_string($_GET['id']);
recievedDeactivate($id);
}
break;
case "getMessages":
{
//---Getting Messages, All responses from server come through this---
$id = mysql_real_escape_string($_GET['id']);
recievedGetMessages($id);
}
break;
default:
echo "Request not understood";
break;
}
}
else //If no message was recieved they probably aren't using the app
{
echo "TaxAppV0.1<br>Please use the app.";
}
function recievedGetMessages($fromDeviceID) //GetMessages is the servers way of talking TO the device
{
debugMsg("RCV GetMessages id=".$fromDeviceID);
global $conn;
//Update
$sqlStmnt = "select * from messages where receiverID = " .$fromDeviceID. " and status = 0";
//debugMsg($sqlStmnt);
$result = mysql_query($sqlStmnt,$conn);
$numRows = mysql_num_rows($result);
//echo $numRows;
echo "MSGSTART\n";
while($newArray = mySql_fetch_array($result))
{
$txt = $newArray['msgText'];
echo $txt."\n";
}
echo "MSGEND\n";
//temp removed for iPhone testing, put back when done
//Mark message as Delivered
if( $_GET['msgtype'] != "debug")
{
$sqlStmnt1 = "update messages set status = 1, delivered ='". "2001-01-01 13:00:30" ."' where receiverID = " .$fromDeviceID . " and status = 0";
$result = mysql_query($sqlStmnt1,$conn);
}
}
function registerDevice()
{
//Todo
}
function recievedSetPosition($fromDeviceID, $llong, $llat) //Device is updating it's position with server
{
$time = time();
$stime = date("Y-m-d H:i:s") ;
debugMsg($stime);
global $conn;
debugMsg("RCV SetPosition id=".$fromDeviceID." llong=".$llong." llat=".$llat);
$sqlStmnt = "update devices set llong = " . $llong . ", llat = " . $llat . " , lastActive = " . " '" . $stime . "' " . " where deviceId = " . $fromDeviceID;
debugMsg("about to update position");
echo $sqlStmnt;
debugMsg($sqlStmnt);
$result = mysql_query($sqlStmnt,$conn);
debugMsg($result);
updateDistances($fromDeviceID); //Used for updating ongoing pickups.
}
function recievedActivate($fromDeviceID,$mode) //This updates the active time so it doesn't timeout
{
global $conn;
debugMsg("RCV Activate id=".$fromDeviceID);
$time = time();
$stime = date("Y-m-d H:i:s") ;
//If Device isn't registered it must be
$sqlStmnt = "select deviceId from devices where deviceId =" . $fromDeviceID . " and master = " . $mode;
$result = mysql_query($sqlStmnt,$conn);
$numRows = mysql_num_rows($result);
if($numRows < 1)
{
debugMsg("numRows<1/Device not registered Registering");
$sqlStmnt0 = "delete from devices where deviceId = " . $fromDeviceID;
//$sqlStmnt = "insert into devices ( deviceId, lastActive, active ) values (" . $fromDeviceID . ", " . $stime . ", true";
$result0 = mysql_query($sqlStmnt0,$conn);
//Remove device (in case of swithing mode)
//Not registered register it
debugMsg($sqlStmnt0);
$sqlStmnt1 = "insert into devices ( deviceId, lastActive, master , active,available ) values (" . $fromDeviceID . ", '" . $stime . "' , " . $mode . ", 1 , 1)";
$result1 = mysql_query($sqlStmnt1,$conn);
$numRows1 = mysql_num_rows($result1);
debugMsg($sqlStmnt1);
}
else
{
debugMsg("device already rgistered, checking in");
global $conn;
$sqlStmnt = "update devices set lastActive ='". $stime ."', active = ". true;
$result = mysql_query($sqlStmnt,$conn);
}
}
/*------------------------------------
When the server recieves a pickup request it calls
recievedRequestPickup();
This in turn calls
calcDistances();
Which creates a list of available Taxis and distances then recievedRequestPickup calls
findCab()
To select the nearest cab, on refusal it is called again and agin going through the list of cabs until
pickupAccepted()
is called accepting the pickup or
completeRefusal()
is reached meaning there are no more taxis left on the list.
------------------------------------*/
function recievedRequestPickup($fromDeviceID, $llong, $llat) //Device is asking for a Taxi pickup
{
$time = time();
$stime = date("Y-M-d H:i:s") ;
debugMsg("RCV RequestPickup id=".$fromDeviceID." llong=".$llong." llat".$llat);
global $conn;
$sqlStmnt = "SELECT MAX(pickupId) FROM pickups";
$result = mysql_query($sqlStmnt,$conn);
$numRows = mysql_num_rows($result);
debugMsg("num of rows: ".$numRows);
$newArray = mySql_fetch_array($result);
$sqlStmnt = "insert into pickups (pickupId, taxiID, clientID, llong, llat ,StartTime ,status)
values (".($newArray[0]+1) .",-1,".$fromDeviceID.",".$llong.",".$llat.", '" . $stime . "' ,0);";
calcDistances($llat,$llong,($newArray[0]+1));
debugMsg($sqlStmnt);
$result = mysql_query($sqlStmnt,$conn);
findCab(($newArray[0]+1));
}
function calcDistances($llat,$llong,$pickupID) //This Method is used to create a list of taxis with distances to the apropriate cab can be called
{
debugMsg("--Creating Distance Calculations");
global $conn;
$sqlStmnt = "select deviceId, llong, llat from devices where master = true and active = true and available = true";
debugMsg($sqlStmnt);
$result = mysql_query($sqlStmnt,$conn);
$numRows = mysql_num_rows($result);
debugMsg("num of rows: ".$numRows);
while($newArray = mySql_fetch_array($result))
{
$distance = new calcMiles ($llat, $llong, $newArray['llat'], $newArray['llong'], "kilometer");
$numericalDistance = $distance->lastResult;
debugMsg("----From Lat:".$llat." long:".$llong." PickupID:".$pickupID."To Lat:".$newArray['llat']." Long:".$newArray['llong']." Id".$newArray['deviceId']." ->".$numericalDistance."KM");
$sqlStmnt1 = "SELECT MAX(calcId) FROM pickupCalc";
debugMsg("----" . $sqlStmnt1);
$result1 = mysql_query($sqlStmnt1,$conn);
$numRows1 = mysql_num_rows($result1);
debugMsg("----" . "num of rows: ".$numRows1);
$newArray1 = mySql_fetch_array($result1);
debugMsg(gettype($pickupID));
$DpickupID = $pickupID;
//not working
$sqlStmnt2 = "insert into pickupCalc ( calcId, pickupId, taxiDeviceId, distance) values (" . ($newArray1[0]+1) . "," . $DpickupID . "," . $newArray['deviceId'] .",". $numericalDistance .")";
//$sqlStmnt2 = "insert into pickupCalc (calcId, pickupId, taxiDeviceId, distance) values (5,20,66,15642.051111166)";
//STatment works when entered manualy
debugMsg( $sqlStmnt2);
mysql_error(mysql_query($sqlStmnt2,$conn));
//debugMsg($result2);
}
}
function findCab($pickupId) // This Method Finds the nearest Cab for the Client
{
global $conn;
debugMsg("--FindCab For Pickup " . $pickupId);
$sqlStmnt1 = "SELECT MIN(distance) FROM pickupCalc where pickupId = ".$pickupId;
$result1 = mysql_query($sqlStmnt1,$conn);
debugMsg("--" . $sqlStmnt1);
debugMsg("FIND CAB HAS " . mysql_num_rows($result1) . " CABS AVAILABLE");
$newArray1 = mySql_fetch_array($result1);
debugMsg((Double) $newArray1[0]);
if ((Double)$newArray1[0] == 0.0)
{
debugMsg("--No Taxis available");
sendPickupTotalRefused($pickupId,"No Taxis Available");
return;
}
$sqlStmnt = "select taxiDeviceId from pickupCalc where pickupId = ".$pickupId ." and distance = ". $newArray1[0];
$result = mysql_query($sqlStmnt,$conn);
debugMsg($sqlStmnt);
$newArray = mySql_fetch_array($result);
debugMsg($newArray['taxiDeviceId']);
$sqlStmnt2 = "SELECT llong, llat from pickups where pickupId = " . $pickupId;
debugMsg($sqlStmnt2);
$result2 = mysql_query($sqlStmnt2,$conn);
$newArray2 = mySql_fetch_array($result2);
debugMsg($newArray2['llong'].$newArray2['llat']);
sendRequestPickup($newArray['taxiDeviceId'],$newArray2['llong'],$newArray2['llat'],$pickupId);
}
function sendRequestPickup($toDeviceID,$llong,$llat,$pickupID) //Send a pickup request to Taxi
{
//debugMsg("Testing debug");
debugMsg($toDeviceID . "PICKREQ:".$pickupID.":".$llong.":".$llat);
createMessage($toDeviceID,"PICKREQ:".$pickupID.":".$llong.":".$llat);
}
function sendPickupAccepted($toDeviceID, $pickupID) //Taxi Accepts a pickup request
{
//debugMsg("Testing debug");
createMessage($toDeviceID,"PICKACC:".$pickupID);
clearPickupCalc($pickupID);
}
function sendPickupTotalRefused($pickupID,$msg) //Find Cab has reached end of Taxi list, none at all available
{
debugMsg("Pickup Complete Refusal");
global $conn;
//Get Client ID to notify them
$sqlStmnt1 = "select clientID from pickups where pickupId = " . $pickupID;
debugMsg($sqlStmnt1);
$result1 = mysql_query($sqlStmnt1,$conn);
$newArray1 = mySql_fetch_array($result1);
debugMsg($newArray1['clientID']);
//Notify them
createMessage($newArray1['clientID'],"PICKFAIL:".$pickupID.":".$msg);
//Set pickup status to fail
$sqlStmnt2 = "update pickups set status = -2 where pickupId = " . $pickupID;
debugMsg($sqlStmnt2);
$result2 = mysql_query($sqlStmnt2,$conn);
//Dump rough work
//clearPickupCalc($pickupID);
}
function sendPickupCaneled($toDeviceID1,$toDeviceID2, $pickupID)//Pickup has been canceled by someone
{
debugMsg("--Sending pickup canceled");
createMessage($toDeviceID1,"PICKCAN:".$pickupID);
createMessage($toDeviceID2,"PICKCAN:".$pickupID);
//Set pickup status to cancle
$sqlStmnt2 = "update pickups set status = -2 where pickupId = " . $pickupID;
debugMsg($sqlStmnt2);
$result2 = mysql_query($sqlStmnt2,$conn);
clearPickupCalc($pickupID);
}
function sendPickupNear($toDeviceID1,$toDeviceID2, $pickupID)
{
debugMsg("--TAXI NEAR");
createMessage($toDeviceID1,"PICKNEAR:".$pickupID);
createMessage($toDeviceID2,"PICKNEAR:".$pickupID);
}
function sendPickupArrived($toDeviceID1,$toDeviceID2, $pickupID) //The Taxi has Arrived
{
debugMsg("--TAXI ARRIVED");
createMessage($toDeviceID1,"PICKARR:".$pickupID);
createMessage($toDeviceID2,"PICKARR:".$pickupID);
//Set pickup status to Comple
$sqlStmnt2 = "update pickups set status = -2 where pickupId = " . $pickupID; //TO DO change to status comple and time
debugMsg($sqlStmnt2);
$result2 = mysql_query($sqlStmnt2,$conn);
clearPickupCalc($pickupID);
}
function recievedAcceptPickup($fromDeviceID, $pickupID)
{
$time = time();
$stime = date("Y-M-d H:i:s") ;
//Done for now, Not Tested
//Todo fix datetime
debugMsg("RCV AcceptPickup id=".$fromDeviceID." pickupId=".$pickupID);
global $conn;
//Update Pickups
$sqlStmnt = "update pickups set taxiID = ". $fromDeviceID .", status = ". 1 .", StartTime = '". $stime ."' where pickupId = ".$pickupID;
//Get Client ID to notify them
$sqlStmnt1 = "select clientID from pickups where pickupId = " . $pickupID;
debugMsg($sqlStmnt1);
$result1 = mysql_query($sqlStmnt1,$conn);
$newArray1 = mySql_fetch_array($result1);
debugMsg($newArray1['clientID']);
//Notify them
createMessage($newArray1['clientID'],"PICKACC:".$pickupID);
//Drop roughwork
clearPickupCalc($pickupID);
$result = mysql_query($sqlStmnt,$conn);
}
function recievedRefusePickup($fromDeviceID, $pickupID)
{
debugMsg("RCV RefusePickup id=".$fromDeviceID." pickupId=".$pickupID);
global $conn;
//Update
$sqlStmnt = "delete from pickupCalc where taxiDeviceId = " . $fromDeviceID . " and pickupId = ".$pickupID;
debugMsg($sqlStmnt);
$result = mysql_query($sqlStmnt,$conn);
findCab($pickupID);
}
function recievedDeactivate($fromDeviceID)
{
$time = time();
$stime = date("Y-M-d H:i:s") ;
debugMsg("RCV Deactivate id=".$fromDeviceID);
global $conn;
//Update
$sqlStmnt = "update devices set lastActive = '". $stime ."', active = ". false;
$result = mysql_query($sqlStmnt,$conn);
}
function createMessage($toID,$msg)
{
$time = time();
$stime = date("Y-M-d H:i:s") ;
//Todo unique ID
//debugMsg("RCV GetMessages id=".$toID . "MSG>>" . $msg);
global $conn;
//Update
$sqlStmnt = "insert into messages (messageID,receiverID,msgText,status,created) values(" . 1 . "," . $toID . ",'".$msg."'," . 0 . ",'". $stime ."')";
$result = mysql_query($sqlStmnt,$conn);
//debugMsg($result);
//$numRows = mysql_num_rows($result);
}
function housekeeping()
{
debugMsg("Starting Housekeeping"); //TODO
//It is important for efficency that this not run too often
//There for we need a way to chack last time this ran
//Investigate system variables
//if lastTimoutCheck > x
// {
doTimeOuts();
// }
}
function doTimeOuts()
{
global $conn;
$time = time();
$time->modify("-" . $timeoutTime . "minutes");
//TIMEDIFF('2009:01:08 00:00:00', '2008:01:01 00:00:00.000001');
$stime = date("Y-M-d H:i:s") ;
$sqlStmnt = "update devices set active = false where lastActive < '" . $stime . "'";
$result = mysql_query($sqlStmnt,$conn);
//Pickup Requests
//select calcId, pickupId from calcTable where offerd < now()-PIKREQtimoutTime();
//remove from calcTable where calcID = calcID[i];
//findCab(pickupID);
//Active Timeouts
//select deviceId where lastActive < now() - DEVACTtimeoutTime();
//update active = false where deviceId = deviceId[i];
}
function clearPickupCalc($pickupID)
{
//Done not tested
debugMsg("Clearing pickup table for pickup:" . $pickupID);
//Used after pickupRequest has been resloved or refused completly to remove calc entries
global $conn;
$sqlStmnt = "delete from pickupCalc where pickupId = " . $pickupID;
$result = mysql_query($sqlStmnt,$conn);
debugMsg($result);
}
function updateDistances($taxiID)
{
//TODO Clean up this message
//Updates Distances For Working Pickups
//Only updates if Device is a taxi (both client and taxi would be redundant and the taxi is the one moving)
//Only updates if the Device is on a pickup. Otherwise there is nothing to calc and so a waste of resources.
debugMsg("Updatinging distances");
global $conn;
//Update
$sqlStmnt = "select pickupId,clientID from pickups where taxiID = " .$taxiID. " and status = 1";
debugMsg($sqlStmnt);
$result = mysql_query($sqlStmnt,$conn);
$numRows = mysql_num_rows($result);
debugMsg("Returned >>" . $numRows);
debugMsg("--CalcDistances Retreved");
debugMsg("--in loop");
while($newArray = mySql_fetch_array($result))
{
$txt = $newArray['pickupId<br>'];
debugMsg("--" . $txt."<< pickupid" );
$clientID = $newArray['clientID'];
$pickUpUD = $newArray['pickupId'];
$txt = $newArray['clientID'];
debugMsg("--" . $txt . "<< clientID\n<br>");
//Get both Locations
//Taxi
$sqlStmnt1 = "select llong , llat from devices where deviceId = " . $taxiID;
debugMsg("--" . $sqlStmnt1);
$result1 = mysql_query($sqlStmnt1,$conn);
$numRows1 = mysql_num_rows($result1);
debugMsg("--" . "S1 Returned " . $numRows1 . "<br>");
// echo $numRows1;
$newArray2 = mySql_fetch_array($result1);
$txt = $newArray2['llong'];
$TLong = $newArray2['llong'];
debugMsg("--" . $txt."<< tllong\n<br>");
//echo $newArray2[1];
$txt2 = $newArray2['llat'];
$TLat = $newArray2['llat'];
debugMsg("--" . $txt2 . "<< Tllat\n<br>");
//Customer
$sqlStmnt3 = "select llong, llat from devices where deviceId = " . $clientID;
debugMsg("--" . $sqlStmnt3);
$result2 = mysql_query($sqlStmnt3,$conn);
$numRows2 = mysql_num_rows($result2);
$newArray3 = mySql_fetch_array($result2);
$txt = $newArray3['llong'];
$CLong = $newArray3['llong'];
debugMsg("--" . $txt."<< Cllon\n<br>");
$txt = $newArray3['llat'];
$CLat = $newArray3['llat'];
debugMsg("--" . $txt . "<< Cllat\n<br>");
debugMsg("--" . "PreDistCalcTest " . $CLong . "," . $CLat . "," . $TLong . "," . $TLat);
$distance = new calcMiles ($CLat, $CLong, $TLat, $TLong, "kilometer");
$distance = new calcMiles ($CLat, $CLong, $TLat, $TLong, "kilometer");
$numericalDistance = $distance->lastResult;
debugMsg("--" . "newDistance " . $numericalDistance);
// Test for about to arrive
$AproachDist = 5; //KM
$ArriveDist = 0.5; //KM
debugMsg("AproachDist" . $AproachDist . "ArriveDist" . $ArriveDist);
if($numericalDistance< $ArriveDist)
{
debugMsg("Inside arrivet");
hasArrived($pickUpId, $taxiID ,$clientID);
}
else if($numericalDistance < $AproachDist )
{
debugMsg("Inside 5 Min warnign");
fiveMinWarning($pickUpId, $clientID);
}
}
// echo "MSGEND\n";
//Write app first
// select taxiID, clientID llong llat from pickups where status = 0;
//loop through
//select llong llat from devices where id = taxiID
//distance = get distance()
//if distance < neerenough
//hasArrived()
//id distance < 5minDist
//fiveMinWarning
//echo "yep";
}
function hasArrived($pickup,$taxi,$client)
{
debugMsg("HAS ARIVED");
//TODO Pickup update, cleanup
$time = time();
$stime = date("Y-M-d H:i:s") ;
$sqlStmnt3 = "update pickups set status = 1 completedTime = " . $stime . " where pickupId = " . $pickupId;
debugMsg($sqlStmnt3);
//$result2 = mysql_query($sqlStmnt3,$conn);
createMessage($client,"PICKARR" . $pickup);
createMessage($taxi,"PICKARR" . $pickup);
//Write app first
//notify client
//update pickups as success
}
function fiveMinWarning($pickup,$client)
{
createMessage($client,"PICKNEAR" . $pickup);
}
function debugMsg($msg)
{
global $debug;
if($debug == false)
{
$time = time();
global $id;
createMessage(-1, date("Y-M-d_H:i:s") . "[" . $id . "]". " >> " . $msg . "<br>");
}
}
?>
<END>