edihistory -- revisions and cleanup of 277 claim status functions
[openemr.git] / modules / sms_email_reminder / sms_tmb4.php
blobf5a1ed36bc2c009dba1db6b3908c7cf4d2802919
1 <?php
2 ////////////////////////////////////////////////////////////////////
3 // Class: TM4B SMS Api
4 // Usage:
5 // <code>
6 // require_once("sms_tm4b.php");
7 // $sms = new sms( "user", "pass" );
8 // $sms->send("123456789","sender","message");
9 // </code>
10 //
11 // Package: sms_tm4b
12 // Created by: Avasiloaei Dorin
13 // Modified by: Larry Lart
14 ////////////////////////////////////////////////////////////////////
15 class sms
17 // init vars
18 var $username = "";
19 var $password = "";
21 function sms( $strUser, $strPass )
23 $this->username = $strUser;
24 $this->password = $strPass;
27 /**
28 * Send sms method
29 * @access public
30 * @return string response
33 function send($phoneNo, $sender, $message)
35 /* Prepare the server request */
36 $request = "";
37 $request .= "username=".urlencode($this->username);
38 $request .= "&password=".urlencode($this->password);
39 $request .= "&revision=2.0";
40 $request .= "&type=broadcast";
41 $request .= "&msg=".urlencode($message);
42 $request .= "&to=".urlencode($phoneNo);
44 // larry :: default if not defined - TODO replace
45 if( !$sender )
46 $request .= "&from=BosmanGGZ";
47 else
48 $request .= "&from=".urlencode($sender);
50 $request .= "&route=GD02";
52 /**
53 * Send the request to the server
54 * @TODO make sure the request was sent
57 $response = $this->_send($request);
58 // larry :: debug
59 echo "DEBUG :SMS ENGINE: sms sent with code =".$response." for req= ".$request."\n";
61 /**
62 * Return the server response
63 * @TODO parse the server response
66 return $response;
69 /**
70 * Send sms method
71 * @access private
72 * @return string response
74 function _send($request)
76 if(extension_loaded('curl'))
78 /**
79 * cURL extension is installed
80 * call the method that sends the sms through cURL
81 */
83 $response = $this->_send_curl($request);
85 elseif(!extension_loaded('sockets'))
87 /**
88 * Sockets extension is installed
89 * call the method that sends the sms through sockets
92 $response = $this->_send_sock($request);
94 else
96 /**
97 * The required extensions are not installed
98 * call the method that sends the sms using file_get_contents
101 $response = file_get_contents("https://www.tm4b.com/client/api/http.php?".$request);
104 /* Return the server response */
105 return $response;
109 * Send SMS through cURL
110 * @access private
111 * @return string response
114 function _send_curl($request)
116 /* Initiate a cURL session */
117 $ch = curl_init();
119 /* Set cURL variables */
120 curl_setopt($ch, CURLOPT_URL, "https://www.tm4b.com/client/api/http.php");
121 curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
122 curl_setopt($ch, CURLOPT_POST, 1);
123 curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
124 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
126 /* Send the request through cURL */
127 $response = curl_exec($ch);
129 /* End the cURL session */
130 curl_close($ch);
132 /* Return the server response */
133 return $response;
137 * Send SMS using the sockets extension
138 * @access private
139 * @return string response
141 function _send_sock($request)
143 /* Prepare the HTTP headers */
144 $http_header = "POST /client/api/http.php HTTP/1.1\r\n";
145 $http_header .= "Host: tm4b.com\r\n";
146 $http_header .= "User-Agent: HTTP/1.1\r\n";
147 $http_header .= "Content-Type: application/x-www-form-urlencoded\r\n";
148 $http_header .= "Content-Length: ".strlen($request)."\r\n";
149 $http_header .= "Connection: close\r\n\r\n";
150 $http_header .= $request."\r\n";
152 /* Set the host that we are connecting to and the port number */
153 $host = "ssl://tm4b.com";
154 $port = 443;
156 /* Connect to the TM4B server */
157 $out = @fsockopen($host, $port, $errno, $errstr);
159 /* Make sure that the connection succeded */
160 if($out)
162 /* Send the request */
163 fputs($out, $http_header);
165 /* Get the response */
166 while(!feof($out)) $result[] = fgets($out);
168 /* Terminate the connection */
169 fclose($out);
171 /* Get the response from the returned string */
172 $response = $result[9];