-
Notifications
You must be signed in to change notification settings - Fork 71
/
receive.php
114 lines (107 loc) · 4.94 KB
/
receive.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
<?php
use BikeShare\Rent\RentSystemInterface;
require_once 'vendor/autoload.php';
require_once "actions-sms.php";
log_sms($sms->getUUID(),$sms->getNumber(),$sms->getTime(),$sms->getMessage(),$sms->getIPAddress());
/**
* @var RentSystemInterface $rentSystem
*/
$rentSystem = $rentSystemFactory->getRentSystem('sms');
$args=preg_split("/\s+/",$sms->getProcessedMessage());//preg_split must be used instead of explode because of multiple spaces
if(!validateNumber($sms->getNumber()))
{
$logger->error("Invalid number", ["number" => $sms->getNumber(), 'sms' => $sms]);
####
#$smsSender->send($sms->getNumber(),_('Your number is not registered.'));
}
else
{
switch($args[0])
{
case "HELP":
help($sms->getNumber());
break;
case "CREDIT":
if ($creditSystem->isEnabled() == FALSE) {
unknownCommand($sms->getNumber(), $args[0]);
break;
}
credit($sms->getNumber());
break;
case "FREE":
freeBikes($sms->getNumber());
break;
case "RENT":
validateReceivedSMS($sms->getNumber(),count($args),2,_('with bike number:')." RENT 47");
$rentSystem->rentBike($sms->getNumber(), $args[1]);//intval
break;
case "RETURN":
validateReceivedSMS($sms->getNumber(),count($args),3,_('with bike number and stand name:')." RETURN 47 RACKO");
$rentSystem->returnBike($sms->getNumber(), $args[1], $args[2], trim(urldecode($sms->getMessage())));
break;
case "FORCERENT":
checkUserPrivileges($sms->getNumber());
validateReceivedSMS($sms->getNumber(),count($args),2,_('with bike number:')." FORCERENT 47");
$rentSystem->rentBike($sms->getNumber(), $args[1], true);
break;
case "FORCERETURN":
checkUserPrivileges($sms->getNumber());
validateReceivedSMS($sms->getNumber(),count($args),3,_('with bike number and stand name:')." FORCERETURN 47 RACKO");
$rentSystem->returnBike($sms->getNumber(), $args[1], $args[2], trim(urldecode($sms->getMessage())), TRUE);
break;
case "WHERE":
case "WHO":
validateReceivedSMS($sms->getNumber(),count($args),2,_('with bike number:')." WHERE 47");
where($sms->getNumber(),$args[1]);
break;
case "INFO":
validateReceivedSMS($sms->getNumber(),count($args),2,_('with stand name:')." INFO RACKO");
info($sms->getNumber(),$args[1]);
break;
case "NOTE":
validateReceivedSMS($sms->getNumber(),count($args),2,_('with bike number/stand name and problem description:')." NOTE 47 "._('Flat tire on front wheel'));
note($sms->getNumber(),$args[1],trim(urldecode($sms->getMessage())));
break;
case "TAG":
validateReceivedSMS($sms->getNumber(),count($args),2,_('with stand name and problem description:')." TAG MAINSQUARE "._('vandalism'));
tag($sms->getNumber(),$args[1],trim(urldecode($sms->getMessage())));
break;
case "DELNOTE":
validateReceivedSMS($sms->getNumber(),count($args),1,_('with bike number and optional pattern. All messages or notes matching pattern will be deleted:')." NOTE 47 wheel");
delnote($sms->getNumber(),$args[1],trim(urldecode($sms->getMessage())));
break;
case "UNTAG":
validateReceivedSMS($sms->getNumber(),count($args),1,_('with stand name and optional pattern. All notes matching pattern will be deleted for all bikes on that stand:')." UNTAG SAFKO1 pohoda");
untag($sms->getNumber(),$args[1],trim(urldecode($sms->getMessage())));
break;
case "LIST":
//checkUserPrivileges($sms->Number()); //allowed for all users as agreed
checkUserPrivileges($sms->getNumber());
validateReceivedSMS($sms->getNumber(),count($args),2,_('with stand name:')." LIST RACKO");
validateReceivedSMS($sms->getNumber(),count($args),2,"with stand name: LIST RACKO");
listBikes($sms->getNumber(),$args[1]);
break;
case "ADD":
checkUserPrivileges($sms->getNumber());
validateReceivedSMS($sms->getNumber(),count($args),3,_('with email, phone, fullname:')." ADD [email protected] 0901456789 Martin Luther King Jr.");
add($sms->getNumber(),$args[1],$args[2],trim(urldecode($sms->getMessage())));
break;
case "REVERT":
checkUserPrivileges($sms->getNumber());
validateReceivedSMS($sms->getNumber(),count($args),2,_('with bike number:')." REVERT 47");
revert($sms->getNumber(),$args[1]);
break;
// case "NEAR":
// case "BLIZKO":
// near($sms->Number(),$args[1]);
case "LAST":
checkUserPrivileges($sms->getNumber());
validateReceivedSMS($sms->getNumber(),count($args),2,_('with bike number:')." LAST 47");
last($sms->getNumber(),$args[1]);
break;
default:
unknownCommand($sms->getNumber(),$args[0]);
}
}
$db->commit();
$sms->respond();