This repository has been archived by the owner on Jun 22, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend_sms.php
142 lines (141 loc) · 5.67 KB
/
send_sms.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
<?php
require_once './configuration.php';
require_once './Constants.php';
global $url,$actions,$user,$password;
$smsObj->url=$url;
$smsObj->user=$user;
$smsObj->password=$password;
$smsObj->from=trim($_REQUEST['fromTxtBox']);
$smsObj->to=trim($_REQUEST['toTxtBox']);
$smsObj->msg=urlencode(trim($_REQUEST['msgTxtArea']));
$smsObj->deliveryMonth=trim($_REQUEST['deliveryMonthDrpDown'])!=='-1'?trim($_REQUEST['deliveryMonthDrpDown']):'';
$smsObj->deliveryDay=trim($_REQUEST['deliveryDayDrpDown'])!=='-1'?trim($_REQUEST['deliveryDayDrpDown']):'';
$smsObj->deliveryHour=trim($_REQUEST['deliveryHourDrpDown'])!=='-1'?trim($_REQUEST['deliveryHourDrpDown']):'';
$smsObj->deliveryMin=trim($_REQUEST['deliveryMinDrpDown'])!=='-1'?trim($_REQUEST['deliveryMinDrpDown']):'';
if($smsObj->deliveryMonth!=='' and $smsObj->deliveryDay!==''){
if($smsObj->deliveryHour===''){
$smsObj->deliveryHour='00';
}
if($smsObj->deliveryMin===''){
$smsObj->deliveryMin='00';
}
}
$errorMsg=isFormValidated($smsObj);
if(strlen($errorMsg)===0){
$smsObj->deliveryTime=$smsObj->deliveryMonth?date('Y')."-$smsObj->deliveryMonth-$smsObj->deliveryDay $smsObj->deliveryHour:$smsObj->deliveryMin:00":'';
$smsObj->deliveryTime=$smsObj->deliveryTime?urlencode($smsObj->deliveryTime):'';
$sendSMSURL="$smsObj->url?action={$actions['sendsms']}&user=$smsObj->user&password=$smsObj->password&from=$smsObj->from&to=$smsObj->to&text=$smsObj->msg";
if($smsObj->deliveryTime){
$sendSMSURL.="&scheduledatetime=$smsObj->deliveryTime";
}
$response=file_get_contents($sendSMSURL);
$response=parseResponse($response);
if(is_array($response) and $response[0]==='success'){
$response=urlencode($response[1]);
header("location:./sms_status.php?response=$response");
die();
}
else if(is_array($response) and $response[0]==='failure'){
$response=urlencode($response[1]);
header("location:./sms_status.php?response=$response");
die();
}
if(is_array($response)){
$errorMsg=$response[1];
}
}
$errorMsg=urlencode($errorMsg);
header("location:./error_page.php?errorMsg=$errorMsg");
die();
function isFormValidated($smsObj){
$alphaNumericRE='/^[0-9a-zA-Z]+$/';//Alpha Numeric Regular Expression
$numericRE='/^[0-9]+$/';//Numeric Regular Expression
$errorMsg='';
$errorCount=1;
if(empty($smsObj->url) or $smsObj->url==='' or is_null($smsObj->url)){
$errorMsg.="$errorCount. SMS Global URL is missing. Kindly open configuration.php and edit the variable '$url'.<br>";
$errorCount++;
}
if(empty($smsObj->user) or $smsObj->user==='' or is_null($smsObj->user)){
$errorMsg.="$errorCount. Username used to send SMS is missing. Kindly open configuration.php and edit the variable '$user'.<br>";
$errorCount++;
}
if(empty($smsObj->password) or $smsObj->password==='' or is_null($smsObj->password)){
$errorMsg.="$errorCount. Password used to send SMS is missing. Kindly open configuration.php and edit the variable '$password'.<br>";
$errorCount++;
}
if(empty($smsObj->from) or $smsObj->from==='' or is_null($smsObj->from)){
$errorMsg.="$errorCount. From number is missing. Kindly provide From as a Alpha Numeric value.<br>";
$errorCount++;
}
if(preg_match($alphaNumericRE,$smsObj->from)===0){
$errorMsg.="$errorCount. From number must be Alpha Numeric. Kindly provide From as a Alpha Numeric value.<br>";
$errorCount++;
}
if(empty($smsObj->to) or $smsObj->to==='' or is_null($smsObj->to)){
$errorMsg.="$errorCount. To number is missing. Kindly provide To as a Numeric value.<br>";
$errorCount++;
}
if(preg_match($numericRE,$smsObj->to)===0){
$errorMsg.="$errorCount. To number must be Numeric. Kindly provide To as a Numeric value.<br>";
$errorCount++;
}
if(empty($smsObj->msg) or $smsObj->msg==='' or is_null($smsObj->msg)){
$errorMsg.="$errorCount. SMS Message is missing. Kindly provide Message.<br>";
$errorCount++;
}
if(strlen($smsObj->msg)>800){
$errorMsg.="$errorCount. SMS Message must be 800 Characters long. Kindly provide a Message contianing at most 800 Characters.<br>";
$errorCount++;
}
if($smsObj->deliveryMonth==='' and $smsObj->deliveryDay==='' and $smsObj->deliveryHour==='' and $smsObj->deliveryMin===''){
return $errorMsg;
}
if($smsObj->deliveryMonth===''){
$errorMsg.="$errorCount. SMS Delivery Month is missing. Kindly provide SMS Delivery Month.<br>";
$errorCount++;
}
if($smsObj->deliveryDay===''){
$errorMsg.="$errorCount. SMS Delivery Day is missing. Kindly provide SMS Delivery Day.<br>";
$errorCount++;
}
if($smsObj->deliveryHour===''){
$errorMsg.="$errorCount. SMS Delivery Hour is missing. Kindly provide SMS Delivery Hour.<br>";
$errorCount++;
}
if($smsObj->deliveryMin===''){
$errorMsg.="$errorCount. SMS Delivery Minutes is missing. Kindly provide SMS Delivery Minutes.<br>";
$errorCount++;
}
return $errorMsg;
}
function parseResponse($response){
global $smsErrorCodes;
if(preg_match('/^SMSGLOBAL DELAY MSGID:/',$response)===1){
$response=array(0=>'success',1=>$response);
}
else if(preg_match('/^OK: 0;/',$response)===1){
$pattern='/^OK: 0;/';
$response=trim(preg_replace($pattern,'',$response));
$response=array(0=>'success',1=>$response);
}
else if(preg_match('/^ERROR:/',$response)===1){
$pattern='/^ERROR:/';
$errorNo=extractErrorNumber($response);
if($errorNo and array_key_exists($errorNo,$smsErrorCodes)){
$response=$smsErrorCodes[$errorNo];
}else{
$response=trim(preg_replace($pattern,'',$response));
}
$response=array(0=>'failure',1=>$response);
}
else{
$response=array(0=>'failure',1=>$response);
}
return $response;
}
function extractErrorNumber($response){
$pattern='/[^0-9]/';
return preg_replace($pattern,'',$response);
}
?>