diff --git a/server/php/EnvayaSMS.php b/server/php/EnvayaSMS.php
index 5e7366e..301d484 100755
--- a/server/php/EnvayaSMS.php
+++ b/server/php/EnvayaSMS.php
@@ -11,6 +11,7 @@ class EnvayaSMS
const ACTION_INCOMING = 'incoming';
const ACTION_OUTGOING = 'outgoing';
const ACTION_SEND_STATUS = 'send_status';
+ const ACTION_TEST = 'test';
const STATUS_QUEUED = 'queued';
const STATUS_FAILED = 'failed';
@@ -39,13 +40,22 @@ class EnvayaSMS
static::$request = new EnvayaSMS_Request();
}
return static::$request;
- }
+ }
}
class EnvayaSMS_Request
{
private $request_action;
+ public $version;
+ public $phone_number;
+
+ function __construct()
+ {
+ $this->version = $_POST['version'];
+ $this->phone_number = $_POST['phone_number'];
+ }
+
function get_action()
{
if (!$this->request_action)
@@ -65,15 +75,12 @@ class EnvayaSMS_Request
return new EnvayaSMS_Action_Outgoing($this);
case EnvayaSMS::ACTION_SEND_STATUS:
return new EnvayaSMS_Action_SendStatus($this);
+ case EnvayaSMS::ACTION_TEST:
+ return new EnvayaSMS_Action_Test($this);
default:
return new EnvayaSMS_Action($this);
}
- }
-
- function get_phone_number()
- {
- return @$_POST['phone_number'];
- }
+ }
function is_validated($correct_password)
{
@@ -108,11 +115,26 @@ class EnvayaSMS_Request
return base64_encode(sha1($input, true));
}
+
+ static function get_messages_xml($messages)
+ {
+ ob_start();
+ echo "\n";
+ echo "";
+ foreach ($messages as $message)
+ {
+ $id = isset($message->id) ? " id='".EnvayaSMS::escape($message->id)."'" : "";
+ $to = isset($message->to) ? " to='".EnvayaSMS::escape($message->to)."'" : "";
+ echo "".EnvayaSMS::escape($message->message)."";
+ }
+ echo "";
+ return ob_get_clean();
+ }
}
class EnvayaSMS_OutgoingMessage
{
- public $id = ''; // ID generated by server
+ public $id; // ID generated by server
public $to; // destination phone number
public $message; // content of SMS message
}
@@ -128,15 +150,6 @@ class EnvayaSMS_Action
}
}
-class EnvayaSMS_Action_Test extends EnvayaSMS_Action
-{
- function __construct($request)
- {
- parent::__construct($request);
- $this->type = EnvayaSMS::ACTION_TEST;
- }
-}
-
class EnvayaSMS_MMS_Part
{
public $form_name; // name of form field with MMS part content
@@ -185,20 +198,12 @@ class EnvayaSMS_Action_Incoming extends EnvayaSMS_Action
$this->mms_parts[] = new EnvayaSMS_MMS_Part($mms_part);
}
}
- }
+ }
function get_response_xml($messages)
{
- ob_start();
- echo "\n";
- echo "";
- foreach ($messages as $message)
- {
- echo "".EnvayaSMS::escape($message->message)."";
- }
- echo "";
- return ob_get_clean();
- }
+ return $this->request->get_messages_xml($messages);
+ }
}
class EnvayaSMS_Action_Outgoing extends EnvayaSMS_Action
@@ -207,20 +212,20 @@ class EnvayaSMS_Action_Outgoing extends EnvayaSMS_Action
{
parent::__construct($request);
$this->type = EnvayaSMS::ACTION_OUTGOING;
- }
+ }
function get_response_xml($messages)
{
- ob_start();
- echo "\n";
- echo "";
- foreach ($messages as $message)
- {
- echo "".
- EnvayaSMS::escape($message->message)."";
- }
- echo "";
- return ob_get_clean();
+ return $this->request->get_messages_xml($messages);
+ }
+}
+
+class EnvayaSMS_Action_Test extends EnvayaSMS_Action
+{
+ function __construct($request)
+ {
+ parent::__construct($request);
+ $this->type = EnvayaSMS::ACTION_TEST;
}
}
diff --git a/server/php/example/www/index.php b/server/php/example/www/index.php
index a2cb0ff..ff3c80c 100755
--- a/server/php/example/www/index.php
+++ b/server/php/example/www/index.php
@@ -10,7 +10,7 @@ ini_set('display_errors','0');
$request = EnvayaSMS::get_request();
-$phone_number = $request->get_phone_number();
+$phone_number = $request->phone_number;
$password = @$PASSWORDS[$phone_number];
@@ -79,7 +79,9 @@ switch ($action->type)
echo "invalid id";
}
return;
-
+ case EnvayaSMS::ACTION_TEST:
+ echo "OK";
+ return;
default:
header("HTTP/1.1 404 Not Found");
echo "Invalid action";