1: <?php
2:
3: class Aspsms_demo extends CI_Controller
4: {
5: 6: 7: 8:
9: var $aspsms;
10:
11: public function __construct() {
12: parent::__construct();
13:
14: $this->load->helper(array('url','form'));
15:
16: $this->load->library('aspsms');
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37: }
38:
39:
40: public function index()
41: {
42: $this->load->view('aspsms_demo/main');
43: }
44:
45:
46: public function check_balance()
47: {
48: try {
49: $balance = $this->aspsms->getCreditBalance();
50: }
51: catch(\tschiemer\Aspsms\ServiceException $e) {
52: show_error('ASPSMS send error: '. $e->getMessage());
53: }
54:
55: if ( !is_float($balance))
56: {
57: $statusCode = $this->aspsms->getLastStatusCode();
58: $statusDescription = $this->aspsms->getStatusDescription($statusCode);
59: show_error('Unexpected server response status '.$statusCode. ': '.$statusDescription);
60: }
61:
62: $this->load->view('aspsms_demo/success',array(
63: 'redirect' => 0,
64: 'messages' => array("You have {$balance} credits left.")
65: ));
66: }
67:
68:
69: public function send_text()
70: {
71: $recipient = $this->input->post('recipient');
72: $text = $this->input->post('text');
73:
74: $originator = $this->input->post('originator');
75: if ( ! empty($originator))
76: {
77: $this->aspsms->setOriginator($originator);
78: }
79:
80: try {
81: $success = $this->aspsms->sendText($recipient, $text);
82: }
83: catch(\tschiemer\Aspsms\ServiceException $e) {
84: show_error('ASPSMS send error: '. $e->getMessage());
85: }
86:
87: if ( ! $success)
88: {
89: $statusCode = $this->aspsms->getLastStatusCode();
90: $statusDescription = $this->aspsms->getStatusDescription($statusCode);
91: show_error('Unexpected server response status '.$statusCode. ': '.$statusDescription);
92: }
93:
94: $this->load->view('aspsms_demo/success',array(
95: 'redirect' => 3,
96: 'messages' => array("Message to recipient(s) {$recipient} submitted to ASPSMS server.")
97: ));
98: }
99:
100:
101: public function send_two_trackables()
102: {
103: $trackingnr = $this->input->post('trackingnr');
104: $recipient = $this->input->post('recipient');
105: $text = $this->input->post('text');
106:
107: try {
108: $success = $this->aspsms->sendText(array_combine($trackingnr, $recipient), $text);
109: }
110: catch(\tschiemer\Aspsms\ServiceException $e) {
111: show_error('ASPSMS send error: '. $e->getMessage());
112: }
113:
114: if ( ! $success)
115: {
116: $statusCode = $this->aspsms->getLastStatusCode();
117: $statusDescription = $this->aspsms->getStatusDescription($statusCode);
118: show_error('Unexpected server response status '.$statusCode. ': '.$statusDescription);
119: }
120:
121: $this->load->view('aspsms_demo/success',array(
122: 'redirect' => 3,
123: 'messages' => array("Messages with tracking numbers " . implode(',',$trackingnr) . " submitted to ASPSMS server.")
124: ));
125: }
126:
127:
128: public function track()
129: {
130: $this->lang->load('aspsms','english');
131: $this->load->helper('language');
132:
133: $trackingnr = $this->input->get('trackingnr');
134:
135: try {
136: $status = $this->aspsms->getDeliveryStatus($trackingnr);
137: }
138: catch(\tschiemer\Aspsms\ServiceException $e){
139: show_error('ASPSMS query failed: '.$e->getMessage());
140: }
141:
142: if (!is_array($status))
143: {
144: show_error('Unexpected server response');
145: }
146:
147:
148: $vars['status'] = $status;
149: $vars['trackingnr'] = $trackingnr;
150:
151: $this->load->view('aspsms_demo/track',$vars);
152: }
153:
154:
155: public function check_originator()
156: {
157: $originator = $this->input->post('originator');
158:
159: try {
160: $success = $this->aspsms->checkOriginator($originator);
161: }
162: catch(\tschiemer\Aspsms\ServiceException $e){
163: show_error('ASPSMS query failed: '.$e->getMessage());
164: }
165:
166: if ($success === NULL)
167: {
168: $statusCode = $this->aspsms->getLastStatusCode();
169: $statusDescription = $this->aspsms->getStatusDescription($statusCode);
170: show_error('Unexpected server response status '.$statusCode. ': '.$statusDescription);
171: }
172:
173: $message = $success ? "Originator `{$originator}` is valid for use." : "Originator `{$originator}` is NOT valid for use.";
174:
175: $this->load->view('aspsms_demo/success',array(
176: 'redirect' => 5,
177: 'messages' => array($message)
178: ));
179: }
180:
181:
182: public function request_originator_unlock()
183: {
184: $originator = $this->input->post('originator');
185:
186: try {
187: $success = $this->aspsms->requestOriginatorUnlockCode($originator);
188: }
189: catch(\tschiemer\Aspsms\ServiceException $e){
190: show_error('ASPSMS query failed: '.$e->getMessage());
191: }
192:
193: if ( ! $success and $this->aspsms->getLastStatusCode() == 31)
194: {
195: $this->load->view('aspsms_demo/success',array(
196: 'redirect' => 3,
197: 'messages' => array("Originator unlock request for `{$originator}`failed, as originator is already authorized.")
198: ));
199: }
200: elseif ( ! $success)
201: {
202: $statusCode = $this->aspsms->getLastStatusCode();
203: $statusDescription = $this->aspsms->getStatusDescription($statusCode);
204: show_error('Originator not valid or could not be verified due to '.$statusCode. ': '.$statusDescription);
205: }
206: else
207: {
208: $this->load->view('aspsms_demo/success',array(
209: 'redirect' => 3,
210: 'messages' => array("Originator unlock request sent for `{$originator}`. {$originator} should shortly receive an unlock code.")
211: ));
212: }
213: }
214:
215:
216: public function unlock_originator()
217: {
218: $code = $this->input->post('code');
219: $originator = $this->input->post('originator');
220:
221: try {
222: $success = $this->aspsms->unlockOriginator($code,$originator);
223: }
224: catch(\tschiemer\Aspsms\ServiceException $e){
225: show_error('ASPSMS query failed: '.$e->getMessage());
226: }
227:
228: if ( ! $success)
229: {
230: $statusCode = $this->aspsms->getLastStatusCode();
231: $statusDescription = $this->aspsms->getStatusDescription($statusCode);
232: show_error('Originator could not be unlocked or some other error occured: '.$statusCode. ' '.$statusDescription);
233: }
234:
235: $this->load->view('aspsms_demo/success',array(
236: 'redirect' => 3,
237: 'messages' => array("Originator `{$originator}` is unlocked and ready for use.")
238: ));
239: }
240:
241:
242: public function send_token()
243: {
244: $phoneNr = $this->input->post('recipient');
245: $reference = $this->input->post('reference');
246: $message = $this->input->post('message');
247: $mask = $this->input->post('mask');
248: $minutes = $this->input->post('minutes');
249: $case_sensitive = (bool)$this->input->post('case_sensitive');
250:
251: try {
252: $success = $this->aspsms->sendGeneratedToken($phoneNr, $reference, $message, $mask, $minutes, $case_sensitive);
253: }
254: catch (\tschiemer\Aspsms\ServiceException $e){
255: show_error('ASPSMS query failed: '.$e->getMessage());
256: }
257:
258: if ( ! $success)
259: {
260: $statusCode = $this->aspsms->getLastStatusCode();
261: $statusDescription = $this->aspsms->getStatusDescription($statusCode);
262: show_error('Unexpected server response status '.$statusCode. ': '.$statusDescription);
263: }
264:
265: $this->load->view('aspsms_demo/success',array(
266: 'redirect' => 3,
267: 'messages' => array("Token presumably sent to `{$phoneNr}`. Owner should shortly receive a token code.")
268: ));
269: }
270:
271: public function validate_token()
272: {
273: $phoneNr = $this->input->post('recipient');
274: $reference = $this->input->post('reference');
275: $token = $this->input->post('token');
276:
277: try {
278: $valid = $this->aspsms->validateToken($phoneNr, $reference, $token);
279: }
280: catch(\tschiemer\Aspsms\ServiceException $e){
281: show_error('ASPSMS query failed: '.$e->getMessage());
282: }
283:
284: if ( ! $valid)
285: {
286: $statusCode = $this->aspsms->getLastStatusCode();
287: $statusDescription = $this->aspsms->getStatusDescription($statusCode);
288: show_error('Token invalid or unexpected server response status '.$statusCode. ': '.$statusDescription);
289: }
290:
291: $this->load->view('aspsms_demo/success',array(
292: 'redirect' => 3,
293: 'messages' => array("Token received by `{$phoneNr}` is valid.")
294: ));
295: }
296:
297:
298: public function send_wap()
299: {
300: $recipient = $this->input->post('recipient');
301: $url = $this->input->post('url');
302: $description = $this->input->post('description');
303:
304: try {
305: $success = $this->aspsms->sendWapPush($recipient, $url, $description);
306: }
307: catch(\tschiemer\Aspsms\ServiceException $e) {
308: show_error('ASPSMS send error: '. $e->getMessage());
309: }
310:
311: if ( ! $success)
312: {
313: $statusCode = $this->aspsms->getLastStatusCode();
314: $statusDescription = $this->aspsms->getStatusDescription($statusCode);
315: show_error('Unexpected server response status '.$statusCode. ': '.$statusDescription);
316: }
317:
318: $this->load->view('aspsms_demo/success',array(
319: 'redirect' => 3,
320: 'messages' => array("WAP for recipient {$recipient} submitted to ASPSMS server.")
321: ));
322: }
323:
324:
325: public function send_vcard()
326: {
327: $recipient = $this->input->post('recipient');
328: $name = $this->input->post('vcard_name');
329: $phone = $this->input->post('vcard_phone');
330:
331: try {
332: $success = $this->aspsms->sendVCard($recipient, $name, $phone);
333: }
334: catch(\tschiemer\Aspsms\ServiceException $e) {
335: show_error('ASPSMS send error: '. $e->getMessage());
336: }
337:
338: if ( ! $success)
339: {
340: $statusCode = $this->aspsms->getLastStatusCode();
341: $statusDescription = $this->aspsms->getStatusDescription($statusCode);
342: show_error('Unexpected server response status '.$statusCode. ': '.$statusDescription);
343: }
344:
345: $this->load->view('aspsms_demo/success',array(
346: 'redirect' => 3,
347: 'messages' => array("VCard for recipient {$recipient} submitted to ASPSMS server.")
348: ));
349: }
350:
351: }