From 2ca3911d56b0339930297fb31cbe3a928cedbca6 Mon Sep 17 00:00:00 2001 From: FrancescoUK Date: Thu, 23 Jun 2016 09:05:30 +0100 Subject: [PATCH] No autoload and refactoring of SMS lib and Message Controller to be consistent with the rest of libraries (#693) --- application/config/autoload.php | 2 +- application/controllers/Messages.php | 27 +++++++------------ application/libraries/Barcode_lib.php | 3 ++- application/libraries/Item_lib.php | 2 +- application/libraries/Receiving_lib.php | 4 ++- application/libraries/Sale_lib.php | 4 ++- .../libraries/{Sms.php => Sms_lib.php} | 21 +++++++++++---- 7 files changed, 35 insertions(+), 28 deletions(-) rename application/libraries/{Sms.php => Sms_lib.php} (68%) diff --git a/application/config/autoload.php b/application/config/autoload.php index 1da59fcb7..114114780 100644 --- a/application/config/autoload.php +++ b/application/config/autoload.php @@ -58,7 +58,7 @@ $autoload['packages'] = array(); | | $autoload['libraries'] = array('user_agent' => 'ua'); */ -$autoload['libraries'] = array('database', 'form_validation', 'session', 'user_agent', 'pagination', 'sms'); +$autoload['libraries'] = array('database', 'form_validation', 'session', 'user_agent', 'pagination'); /* | ------------------------------------------------------------------- diff --git a/application/controllers/Messages.php b/application/controllers/Messages.php index e24414c98..077181745 100644 --- a/application/controllers/Messages.php +++ b/application/controllers/Messages.php @@ -7,6 +7,8 @@ class Messages extends Secure_Controller public function __construct() { parent::__construct('messages'); + + $this->load->library('sms_lib'); } public function index() @@ -28,15 +30,10 @@ class Messages extends Secure_Controller public function send() { - $username = $this->config->item('msg_uid'); - $password = $this->config->item('msg_pwd'); - $phone = $this->input->post('phone'); - $message = $this->input->post('message'); - $originator = $this->config->item('msg_src'); + $phone = $this->input->post('phone'); + $message = $this->input->post('message'); - $response = $this->sms->sendSMS($username, $password, $phone, $message, $originator); - - $phone = $this->xss_clean($phone); + $response = $this->sms_lib->sendSMS($phone, $message); if($response) { @@ -50,20 +47,14 @@ class Messages extends Secure_Controller public function send_form($person_id = -1) { - $username = $this->config->item('msg_uid'); - $password = $this->config->item('msg_pwd'); - $phone = $this->input->post('phone'); - $message = $this->input->post('message'); - $originator = $this->config->item('msg_src'); + $phone = $this->input->post('phone'); + $message = $this->input->post('message'); - $response = $this->sms->sendSMS($username, $password, $phone, $message, $originator); - - $phone = $this->xss_clean($phone); - $person_id = $this->xss_clean($person_id); + $response = $this->sms_lib->sendSMS($phone, $message); if($response) { - echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('messages_successfully_sent') . ' ' . $phone, 'person_id' => $person_id)); + echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('messages_successfully_sent') . ' ' . $phone, 'person_id' => $this->xss_clean($person_id))); } else { diff --git a/application/libraries/Barcode_lib.php b/application/libraries/Barcode_lib.php index cc8a23b1a..6e3169b28 100644 --- a/application/libraries/Barcode_lib.php +++ b/application/libraries/Barcode_lib.php @@ -1,4 +1,4 @@ - \ No newline at end of file diff --git a/application/libraries/Item_lib.php b/application/libraries/Item_lib.php index bce8f1fbe..01afc8550 100644 --- a/application/libraries/Item_lib.php +++ b/application/libraries/Item_lib.php @@ -1,4 +1,4 @@ - diff --git a/application/libraries/Sale_lib.php b/application/libraries/Sale_lib.php index b3677c8a5..e2fe04371 100644 --- a/application/libraries/Sale_lib.php +++ b/application/libraries/Sale_lib.php @@ -1,4 +1,5 @@ - diff --git a/application/libraries/Sms.php b/application/libraries/Sms_lib.php similarity index 68% rename from application/libraries/Sms.php rename to application/libraries/Sms_lib.php index aa43dc144..b4e3c7c99 100644 --- a/application/libraries/Sms.php +++ b/application/libraries/Sms_lib.php @@ -1,17 +1,28 @@ -CI =& get_instance(); + } + /* * SMS send function - * Example of use: $response = sendSMS('myUsername', 'myPassword', '4477777777', 'My test message', 'My company'); + * Example of use: $response = sendSMS('4477777777', 'My test message'); */ - function sendSMS($username, $password, $phone, $message, $originator) + public function sendSMS($phone, $message) { + $username = $this->CI->config->item('msg_uid'); + $password = $this->CI->config->item('msg_pwd'); + $originator = $this->CI->config->item('msg_src'); + $response = FALSE; // if any of the parameters is empty return with a FALSE - if( empty($username) || empty($password) || empty($phone) || empty($message) || empty($originator) ) + if(empty($username) || empty($password) || empty($phone) || empty($message) || empty($originator)) { //echo $username . ' ' . $password . ' ' . $phone . ' ' . $message . ' ' . $originator; }