Example #1
0
 public static function boot()
 {
     parent::boot();
     static::created(function ($notification) {
         switch ($notification->type) {
             case 'new_prospect':
                 $prospect = Prospect::find($notification->type_id);
                 $user = User::find($notification->user_id);
                 Clickatell::send("Nuevo Interesado en " . $prospect->type . " - Nombre: " . $prospect->name . " Email: " . $prospect->email . " Tel.: " . $prospect->phone, $user->phone);
                 $data = ['name' => $prospect->name, 'email' => $prospect->email, 'phone' => $prospect->phone];
                 Mail::queue('emails.notify.new-prospect', $data, function ($message) use($user) {
                     $message->from('*****@*****.**', 'MLMfunnel');
                     $message->to($user->email, $user->full_name)->subject('Nuevo prospecto! - MLMfunnel');
                 });
                 break;
         }
     });
 }
 public function message($message)
 {
     self::$message = $message;
     return $this;
 }
Example #3
0
 /**
  * Retrieves Clickatell Balance using Clickatell Library
  */
 function smsbalance()
 {
     $this->template = "";
     $this->auto_render = FALSE;
     $settings = new Settings_Model(1);
     if ($settings->loaded == true) {
         $clickatell_api = $settings->clickatell_api;
         $clickatell_username = $settings->clickatell_username;
         $clickatell_password = $settings->clickatell_password;
         $mysms = new Clickatell();
         $mysms->api_id = $clickatell_api;
         $mysms->user = $clickatell_username;
         $mysms->password = $clickatell_password;
         $mysms->use_ssl = false;
         $mysms->sms();
         // echo $mysms->session;
         echo $mysms->getbalance();
     }
 }
Example #4
0
 public function index()
 {
     $config = kohana::config('alerts');
     $settings = kohana::config('settings');
     $site_name = $settings['site_name'];
     $unsubscribe_message = Kohana::lang('alerts.unsubscribe') . url::site() . 'alerts/unsubscribe/';
     $settings = NULL;
     $sms_from = NULL;
     $clickatell = NULL;
     $db = new Database();
     $incidents = $db->query("SELECT incident.id, incident_title, \n\t\t\t\t\t\t\t\t incident_description, incident_verified, \n\t\t\t\t\t\t\t\t location.latitude, location.longitude, alert_sent.incident_id\n\t\t\t\t\t\t\t\t FROM incident INNER JOIN location ON incident.location_id = location.id\n\t\t\t\t\t\t\t\t LEFT OUTER JOIN alert_sent ON incident.id = alert_sent.incident_id");
     foreach ($incidents as $incident) {
         if ($incident->incident_id != NULL) {
             continue;
         }
         $verified = (int) $incident->incident_verified;
         if ($verified) {
             $latitude = (double) $incident->latitude;
             $longitude = (double) $incident->longitude;
             $proximity = new Proximity($latitude, $longitude);
             $alertees = $this->_get_alertees($proximity);
             foreach ($alertees as $alertee) {
                 $alert_type = (int) $alertee->alert_type;
                 if ($alert_type == 1) {
                     if ($settings == null) {
                         $settings = ORM::factory('settings', 1);
                         if ($settings->loaded == true) {
                             // Get SMS Numbers
                             if (!empty($settings->sms_no3)) {
                                 $sms_from = $settings->sms_no3;
                             } elseif (!empty($settings->sms_no2)) {
                                 $sms_from = $settings->sms_no2;
                             } elseif (!empty($settings->sms_no1)) {
                                 $sms_from = $settings->sms_no1;
                             } else {
                                 $sms_from = "000";
                             }
                             // User needs to set up an SMS number
                         }
                         $clickatell = new Clickatell();
                         $clickatell->api_id = $settings->clickatell_api;
                         $clickatell->user = $settings->clickatell_username;
                         $clickatell->password = $settings->clickatell_password;
                         $clickatell->use_ssl = false;
                         $clickatell->sms();
                     }
                     $message = $incident->incident_description;
                     if ($clickatell->send($alertee->alert_recipient, $sms_from, $message) == "OK") {
                         $alert = ORM::factory('alert_sent');
                         $alert->alert_id = $alertee->id;
                         $alert->incident_id = $incident->id;
                         $alert->alert_date = date("Y-m-d H:i:s");
                         $alert->save();
                     }
                 } elseif ($alert_type == 2) {
                     $to = $alertee->alert_recipient;
                     $from = $config['alerts_email'];
                     $subject = "[{$site_name}] " . $incident->incident_title;
                     $message = $incident->incident_description . "<p>" . $unsubscribe_message . $alertee->alert_code . "</p>";
                     if (email::send($to, $from, $subject, $message, TRUE) == 1) {
                         $alert = ORM::factory('alert_sent');
                         $alert->alert_id = $alertee->id;
                         $alert->incident_id = $incident->id;
                         $alert->alert_date = date("Y-m-d H:i:s");
                         $alert->save();
                     }
                 }
             }
         }
     }
 }
Example #5
0
 private function _send_mobile_alert($alert_mobile, $alert_lon, $alert_lat, $alert_radius)
 {
     // For Mobile Alerts, Confirmation Code
     // Should be 6 distinct characters
     $alert_code = text::random('distinct', 8);
     $settings = ORM::factory('settings', 1);
     if (!$settings->loaded) {
         return FALSE;
     }
     // Get SMS Numbers
     if (!empty($settings->sms_no3)) {
         $sms_from = $settings->sms_no3;
     } elseif (!empty($settings->sms_no2)) {
         $sms_from = $settings->sms_no2;
     } elseif (!empty($settings->sms_no1)) {
         $sms_from = $settings->sms_no1;
     } else {
         $sms_from = "000";
         // User needs to set up an SMS number
     }
     $sms = new Clickatell();
     $sms->api_id = $settings->clickatell_api;
     $sms->user = $settings->clickatell_username;
     $sms->password = $settings->clickatell_password;
     $sms->use_ssl = false;
     $sms->sms();
     $message = "Your alerts confirmation code\n\t\t\t\tis: " . $alert_code . " This code is NOT case sensitive";
     if ($sms->send($alert_mobile, $sms_from, $message) == "OK") {
         $alert = ORM::factory('alert');
         $alert->alert_type = self::MOBILE_ALERT;
         $alert->alert_recipient = $alert_mobile;
         $alert->alert_code = $alert_code;
         $alert->alert_lon = $alert_lon;
         $alert->alert_lat = $alert_lat;
         $alert->alert_radius = $alert_radius;
         $alert->save();
         return TRUE;
     }
     return FALSE;
 }
Example #6
0
 public function index()
 {
     $db = new Database();
     $incidents = $db->query("SELECT distinct incident.id, incident_title, incident_verified, location.latitude, location.longitude \n\t\t\t\t\t\t\t\t\tFROM location, incident, alert_sent \n\t\t\t\t\t\t\t\t\tWHERE incident.location_id = location.id AND incident.id != alert_sent.incident_id");
     $settings = null;
     $sms_from = null;
     $clickatell = null;
     foreach ($incidents as $incident) {
         $verified = (int) $incident->incident_verified;
         if ($verified) {
             $latitude = (double) $incident->latitude;
             $longitude = (double) $incident->longitude;
             $proximity = new Proximity($latitude, $longitude);
             $alertees = $this->_get_alertees($proximity);
             foreach ($alertees as $alertee) {
                 $alert_type = (int) $alertee->alert_type;
                 if ($alert_type == 1) {
                     if ($settings == null) {
                         $settings = ORM::factory('settings', 1);
                         if ($settings->loaded == true) {
                             // Get SMS Numbers
                             if (!empty($settings->sms_no3)) {
                                 $sms_from = $settings->sms_no3;
                             } elseif (!empty($settings->sms_no2)) {
                                 $sms_from = $settings->sms_no2;
                             } elseif (!empty($settings->sms_no1)) {
                                 $sms_from = $settings->sms_no1;
                             } else {
                                 $sms_from = "000";
                             }
                             // User needs to set up an SMS number
                         }
                         $clickatell = new Clickatell();
                         $clickatell->api_id = $settings->clickatell_api;
                         $clickatell->user = $settings->clickatell_username;
                         $clickatell->password = $settings->clickatell_password;
                         $clickatell->use_ssl = false;
                         $clickatell->sms();
                     }
                     //XXX: Fix the outgoing message!
                     $message = $incident->incident_title . " occured near you!";
                     echo "{$message}<br/>";
                     if ($clickatell->send($alertee->alert_alert_recipient, $sms_from, $message) == "OK") {
                         $alert = ORM::factory('alert_sent');
                         $alert->alert_id = $alertee->id;
                         $alert->incident_id = $incident->id;
                         $alert->alert_date = date("Y-m-d H:i:s");
                         $alert->save();
                     }
                 } elseif ($alert_type == 2) {
                     //XXX: Setup correct 'from' address and message
                     $to = $alertee->alert_recipient;
                     $from = '*****@*****.**';
                     $subject = 'Ushahidi alert!';
                     $message = $incident->incident_title . " occured near you!";
                     if (email::send($to, $from, $subject, $message, TRUE) == 1) {
                         $alert = ORM::factory('alert_sent');
                         $alert->alert_id = $alertee->id;
                         $alert->incident_id = $incident->id;
                         $alert->alert_date = date("Y-m-d H:i:s");
                         $alert->save();
                     }
                 }
             }
         }
     }
 }
Example #7
0
 /**
  * Send A New Message Using Clickatell Library
  */
 function send()
 {
     $this->template = "";
     $this->auto_render = FALSE;
     // setup and initialize form field names
     $form = array('to_id' => '', 'message' => '');
     //  Copy the form as errors, so the errors will be stored with keys
     //  corresponding to the form field names
     $errors = $form;
     $form_error = FALSE;
     // check, has the form been submitted, if so, setup validation
     if ($_POST) {
         // Instantiate Validation, use $post, so we don't overwrite $_POST
         // fields with our own things
         $post = new Validation($_POST);
         // Add some filters
         $post->pre_filter('trim', TRUE);
         // Add some rules, the input field, followed by a list of checks, carried out in order
         $post->add_rules('to_id', 'required', 'numeric');
         $post->add_rules('message', 'required', 'length[1,160]');
         // Test to see if things passed the rule checks
         if ($post->validate()) {
             // Yes! everything is valid
             $reply_to = ORM::factory('message', $post->to_id);
             if ($reply_to->loaded == true) {
                 // Yes! Replyto Exists
                 // This is the message we're replying to
                 $sms_to = intval($reply_to->message_from);
                 // Load Users Settings
                 $settings = new Settings_Model(1);
                 if ($settings->loaded == true) {
                     // Get SMS Numbers
                     if (!empty($settings->sms_no3)) {
                         $sms_from = $settings->sms_no3;
                     } elseif (!empty($settings->sms_no2)) {
                         $sms_from = $settings->sms_no2;
                     } elseif (!empty($settings->sms_no1)) {
                         $sms_from = $settings->sms_no1;
                     } else {
                         $sms_from = "000";
                         // User needs to set up an SMS number
                     }
                     // Create Clickatell Object
                     $mysms = new Clickatell();
                     $mysms->api_id = $settings->clickatell_api;
                     $mysms->user = $settings->clickatell_username;
                     $mysms->password = $settings->clickatell_password;
                     $mysms->use_ssl = false;
                     $mysms->sms();
                     $send_me = $mysms->send($sms_to, $sms_from, $post->message);
                     // Message Went Through??
                     if ($send_me == "OK") {
                         $newmessage = ORM::factory('message');
                         $newmessage->parent_id = $post->to_id;
                         // The parent message
                         $newmessage->message_from = $sms_from;
                         $newmessage->message_to = $sms_to;
                         $newmessage->message = $post->message;
                         $newmessage->message_type = 2;
                         // This is an outgoing message
                         $newmessage->reporter_id = $reply_to->reporter_id;
                         $newmessage->message_date = date("Y-m-d H:i:s", time());
                         $newmessage->save();
                         echo json_encode(array("status" => "sent", "message" => Kohana::lang('ui_admin.message_sent')));
                     } else {
                         echo json_encode(array("status" => "error", "message" => Kohana::lang('ui_admin.error') . " - " . $send_me));
                     }
                 } else {
                     echo json_encode(array("status" => "error", "message" => Kohana::lang('ui_admin.error') . Kohana::lang('ui_admin.check_sms_settings')));
                 }
             } else {
                 echo json_encode(array("status" => "error", "message" => Kohana::lang('ui_admin.error') . Kohana::lang('ui_admin.check_number')));
             }
         } else {
             // populate the error fields, if any
             $errors = arr::overwrite($errors, $post->errors('messages'));
             echo json_encode(array("status" => "error", "message" => Kohana::lang('ui_admin.error') . Kohana::lang('ui_admin.check_message_valid')));
         }
     }
 }
Example #8
0
 public function index()
 {
     // Create new session
     $this->session->create();
     $this->template->header->this_page = 'alerts';
     $this->template->content = new View('alerts');
     // Display news feeds?
     $this->template->content->allow_feed = Kohana::config('settings.allow_feed');
     // Retrieve default country, latitude, longitude
     $default_country = Kohana::config('settings.default_country');
     // Retrieve Country Cities
     $this->template->content->cities = $this->_get_cities($default_country);
     // setup and initialize form field names
     $form = array('alert_mobile' => '', 'alert_mobile_yes' => '', 'alert_email' => '', 'alert_email_yes' => '', 'alert_lat' => '', 'alert_lon' => '');
     // copy the form as errors, so the errors will be stored with keys
     // corresponding to the form field names
     $errors = $form;
     $form_error = FALSE;
     $form_saved = FALSE;
     // check, has the form been submitted, if so, setup validation
     if ($_POST) {
         // Instantiate Validation, use $post, so we don't overwrite $_POST fields with our own things
         $post = new Validation($_POST);
         //  Add some filters
         $post->pre_filter('trim', TRUE);
         // Add some rules, the input field, followed by a list of checks, carried out in order
         if (!empty($_POST['alert_mobile']) || isset($_POST['alert_mobile_yes'])) {
             $post->add_rules('alert_mobile', 'required', 'numeric', 'length[6,20]');
         }
         if (!empty($_POST['alert_email']) || isset($_POST['alert_email_yes'])) {
             $post->add_rules('alert_email', 'required', 'email', 'length[3,64]');
         }
         if (empty($_POST['alert_email']) && empty($_POST['alert_mobile'])) {
             $post->add_error('alert_mobile', 'one_required');
             $post->add_error('alert_email', 'one_required');
         }
         $post->add_rules('alert_lat', 'required', 'between[-90,90]');
         // Validate for maximum and minimum latitude values
         $post->add_rules('alert_lon', 'required', 'between[-180,180]');
         // Validate for maximum and minimum longitude values
         // Add a callback, to validate the mobile phone/email (See the methods below)
         $post->add_callbacks('alert_mobile', array($this, 'mobile_check'));
         $post->add_callbacks('alert_email', array($this, 'email_check'));
         // Test to see if things passed the rule checks
         if ($post->validate()) {
             // Yes! everything is valid
             // Save alert and send out confirmation code
             $email_confirmation_saved = FALSE;
             $sms_confirmation_saved = FALSE;
             if (!empty($post->alert_mobile)) {
                 $alert_code = $this->_mk_code();
                 $settings = ORM::factory('settings', 1);
                 if ($settings->loaded == true) {
                     // Get SMS Numbers
                     if (!empty($settings->sms_no3)) {
                         $sms_from = $settings->sms_no3;
                     } elseif (!empty($settings->sms_no2)) {
                         $sms_from = $settings->sms_no2;
                     } elseif (!empty($settings->sms_no1)) {
                         $sms_from = $settings->sms_no1;
                     } else {
                         $sms_from = "000";
                         // User needs to set up an SMS number
                     }
                     $sms = new Clickatell();
                     $sms->api_id = $settings->clickatell_api;
                     $sms->user = $settings->clickatell_username;
                     $sms->password = $settings->clickatell_password;
                     $sms->use_ssl = false;
                     $sms->sms();
                     $message = "Your alerts confirmation code\n\t\t\t\t\t\t\t\tis: " . $alert_code . " This code is NOT case sensitive";
                     if ($sms->send($post->alert_mobile, $sms_from, $message) == "OK") {
                         $alert = ORM::factory('alert');
                         $alert->alert_type = self::MOBILE_ALERT;
                         $alert->alert_recipient = $post->alert_mobile;
                         $alert->alert_code = $alert_code;
                         $alert->alert_lon = $post->alert_lon;
                         $alert->alert_lat = $post->alert_lat;
                         $alert->save();
                         if ($alert->saved == TRUE) {
                             $sms_confirmation_saved = TRUE;
                         }
                     }
                 }
             }
             if (!empty($post->alert_email)) {
                 $alert_code = $this->_mk_code();
                 //Send verification email
                 $config = kohana::config('alerts');
                 $settings = kohana::config('settings');
                 $to = $post->alert_email;
                 $from = $config['alerts_email'];
                 $subject = $settings['site_name'] . ' alerts - verification';
                 $message = 'Please follow ' . url::base() . 'alerts/verify/' . $alert_code . ' to confirm your alert request';
                 if (email::send($to, $from, $subject, $message, TRUE) == 1) {
                     $alert = ORM::factory('alert');
                     $alert->alert_type = self::EMAIL_ALERT;
                     $alert->alert_recipient = $post->alert_email;
                     $alert->alert_code = $alert_code;
                     $alert->alert_lon = $post->alert_lon;
                     $alert->alert_lat = $post->alert_lat;
                     $alert->save();
                     if ($alert->saved == TRUE) {
                         $email_confirmation_saved = TRUE;
                     }
                 }
             }
             $this->session->set('alert_mobile', $post->alert_mobile);
             $this->session->set('alert_email', $post->alert_email);
             $this->session->set('sms_confirmation_saved', $sms_confirmation_saved);
             $this->session->set('email_confirmation_saved', $email_confirmation_saved);
             url::redirect('alerts/confirm');
         } else {
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // populate the error fields, if any
             $errors = arr::overwrite($errors, $post->errors('alerts'));
             $form_error = TRUE;
         }
     } else {
         $form['alert_lat'] = Kohana::config('settings.default_lat');
         $form['alert_lon'] = Kohana::config('settings.default_lon');
     }
     $this->template->content->form = $form;
     $this->template->content->errors = $errors;
     $this->template->content->form_error = $form_error;
     $this->template->content->form_saved = $form_saved;
     // Javascript Header
     $this->template->header->map_enabled = TRUE;
     $this->template->header->js = new View('alerts_js');
     $this->template->header->js->default_map = Kohana::config('settings.default_map');
     $this->template->header->js->default_zoom = Kohana::config('settings.default_zoom');
     $this->template->header->js->latitude = $form['alert_lat'];
     $this->template->header->js->longitude = $form['alert_lon'];
 }
Example #9
0
    public function index()
    {
        $settings = ORM::factory('settings')->find(1);
        $site_name = $settings->site_name;
        $alerts_email = $settings->alerts_email;
        $unsubscribe_message = Kohana::lang('alerts.unsubscribe') . url::site() . 'alerts/unsubscribe/';
        $sms_from = NULL;
        $clickatell = NULL;
        $miles = FALSE;
        // Change to True to calculate distances in Miles
        $max_recipients = 20;
        // Limit each script execution to 50 recipients
        if ($settings->email_smtp == 1) {
            Kohana::config_set('email.driver', 'smtp');
            Kohana::config_set('email.options', array('hostname' => $settings->alerts_host, 'port' => $settings->alerts_port, 'username' => $settings->alerts_username, 'password' => $settings->alerts_password));
        }
        $db = new Database();
        /* Find All Alerts with the following parameters
        		- incident_active = 1 -- An approved incident
        		- incident_alert_status = 1 -- Incident has been tagged for sending
        		
        		Incident Alert Statuses
        		  - 0, Incident has not been tagged for sending. Ensures old incidents are not sent out as alerts
        		  - 1, Incident has been tagged for sending by updating it with 'approved' or 'verified'
        		  - 2, Incident has been tagged as sent. No need to resend again
        		*/
        // 1 - Retrieve All the Incidents that haven't been sent (Process only 1 per script execution)
        $incidents = $db->query("\n\t\t\t\t\t\t\t\t SELECT incident.id, incident_title, \n\t\t\t\t\t\t\t\t incident_description, incident_verified, \n\t\t\t\t\t\t\t\t location.latitude, location.longitude\n\t\t\t\t\t\t\t\t FROM incident\n\t\t\t\t\t\t\t\t INNER JOIN location on location.id = incident.location_id\n\t\t\t\t\t\t\t\t WHERE incident.incident_active=1 AND incident.incident_alert_status = 1 LIMIT 1\n\t\t\t\t\t\t\t\t");
        foreach ($incidents as $incident) {
            $latitude = (double) $incident->latitude;
            $longitude = (double) $incident->longitude;
            // 2 - Retrieve All Qualifying Alertees Based on Distance and Make sure they haven't received this alert,
            // 	   Return Alertees if they haven't requested a Category OR Return Alertees if they specifically asked
            // 	   for this incident region and specific category.
            $distance_type = $miles ? "" : " * 1.609344";
            $alertees = $db->query('
									SELECT DISTINCT alert.*, ((ACOS(SIN(' . $latitude . ' * PI() / 180) * 
									SIN(`alert`.`alert_lat` * PI() / 180) + COS(' . $latitude . ' * PI() / 180) * 
									COS(`alert`.`alert_lat` * PI() / 180) * COS((' . $longitude . ' - `alert`.`alert_lon`)
									 * PI() / 180)) * 180 / PI()) * 60 * 1.1515 ' . $distance_type . ') AS distance
									FROM alert 
									WHERE  alert.alert_confirmed = 1
									HAVING distance <= alert_radius
									');
            $i = 0;
            foreach ($alertees as $alertee) {
                // 3 - Has this incident alert been sent to this alertee?
                $alert_sent = ORM::factory('alert_sent')->where('alert_id', $alertee->id)->where('incident_id', $incident->id)->find();
                $requested_category = true;
                $alert_categories = ORM::factory('alert_category')->select("alert_category.category_id")->where('alert_id', $alertee->id)->find_all();
                // The Alertee requested specific categories for the incident.
                // Make sure the categories are part of this incident.
                $requested_category = alert::requested_category($alert_categories, $incident->id);
                // Alert has not been sent and the alertee requested the incident with the category
                if ($alert_sent->loaded == FALSE && $requested_category) {
                    // 4 - Get Alert Type. 1=SMS, 2=EMAIL
                    $alert_type = (int) $alertee->alert_type;
                    if ($alert_type == 1) {
                        // Save this first
                        $alert = ORM::factory('alert_sent');
                        $alert->alert_id = $alertee->id;
                        $alert->incident_id = $incident->id;
                        $alert->alert_date = date("Y-m-d H:i:s");
                        $alert->save();
                        // Get SMS Numbers
                        if (!empty($settings->sms_no3)) {
                            $sms_from = $settings->sms_no3;
                        } elseif (!empty($settings->sms_no2)) {
                            $sms_from = $settings->sms_no2;
                        } elseif (!empty($settings->sms_no1)) {
                            $sms_from = $settings->sms_no1;
                        } else {
                            $sms_from = "000";
                        }
                        // Admin needs to set up an SMS number
                        $clickatell = new Clickatell();
                        $clickatell->api_id = $settings->clickatell_api;
                        $clickatell->user = $settings->clickatell_username;
                        $clickatell->password = $settings->clickatell_password;
                        $clickatell->use_ssl = false;
                        $clickatell->sms();
                        $message = text::limit_chars($incident->incident_description, 150, "...");
                        //++ We won't verify for now if sms was sent
                        // Leaves too much room for duplicates to be sent out
                        $clickatell->send($alertee->alert_recipient, $sms_from, $message);
                    } elseif ($alert_type == 2) {
                        // Save this first
                        $alert = ORM::factory('alert_sent');
                        $alert->alert_id = $alertee->id;
                        $alert->incident_id = $incident->id;
                        $alert->alert_date = date("Y-m-d H:i:s");
                        $alert->save();
                        //for some reason, mail function complains about bad parameters
                        // in the function so i'm disallowing these characters in the
                        // subject field to allow the mail function to work.
                        $disallowed_chars = array("(", ")", "[", "]", "-");
                        $to = $alertee->alert_recipient;
                        $from = $alerts_email;
                        $subject = trim(str_replace($disallowed_chars, "", $site_name) . ": " . str_replace($disallowed_chars, "", $incident->incident_title));
                        $message = $incident->incident_description . "<p>" . url::base() . "reports/view/" . $incident->id . "</p>" . "<p>" . $unsubscribe_message . "?c=" . $alertee->alert_code . "</p>";
                        //++ We won't verify for now if email was sent
                        // Leaves too much room for duplicates to be sent out
                        email::send($to, $from, $subject, $message, TRUE);
                    }
                    sleep(1);
                    $i++;
                }
                if ($i == $max_recipients) {
                    exit;
                }
            }
            // End For Each Loop
            // Update Incident - All Alerts Have Been Sent!
            $update_incident = ORM::factory('incident', $incident->id);
            if ($update_incident->loaded) {
                $update_incident->incident_alert_status = 2;
                $update_incident->save();
            }
        }
    }
Example #10
0
 public function index()
 {
     $db = new Database();
     $incidents = $db->query("SELECT incident.id, incident_title,\n\t\t\t\t\t\t\t\t incident_description,\n\t\t\t\t\t\t\t     incident_verified, location.latitude, \n\t\t\t\t\t\t\t\t location.longitude FROM incident INNER JOIN location \n\t\t\t\t\t\t\t\t ON incident.location_id = location.id");
     $alerts_sent = $db->query("SELECT incident_id FROM alert_sent");
     $alerts_sent_ids = array();
     foreach ($alerts_sent as $alert_sent) {
         array_push($alerts_sent_ids, $alert_sent->incident_id);
     }
     $config = kohana::config('alerts');
     $settings = null;
     $sms_from = null;
     $clickatell = null;
     foreach ($incidents as $incident) {
         if (in_array($incident->id, $alerts_sent_ids)) {
             continue;
         }
         $verified = (int) $incident->incident_verified;
         if ($verified) {
             $latitude = (double) $incident->latitude;
             $longitude = (double) $incident->longitude;
             $proximity = new Proximity($latitude, $longitude);
             $alertees = $this->_get_alertees($proximity);
             foreach ($alertees as $alertee) {
                 $alert_type = (int) $alertee->alert_type;
                 if ($alert_type == 1) {
                     if ($settings == null) {
                         $settings = ORM::factory('settings', 1);
                         if ($settings->loaded == true) {
                             // Get SMS Numbers
                             if (!empty($settings->sms_no3)) {
                                 $sms_from = $settings->sms_no3;
                             } elseif (!empty($settings->sms_no2)) {
                                 $sms_from = $settings->sms_no2;
                             } elseif (!empty($settings->sms_no1)) {
                                 $sms_from = $settings->sms_no1;
                             } else {
                                 $sms_from = "000";
                             }
                             // User needs to set up an SMS number
                         }
                         $clickatell = new Clickatell();
                         $clickatell->api_id = $settings->clickatell_api;
                         $clickatell->user = $settings->clickatell_username;
                         $clickatell->password = $settings->clickatell_password;
                         $clickatell->use_ssl = false;
                         $clickatell->sms();
                     }
                     //XXX: Fix the outgoing message!
                     $message = $incident->incident_description;
                     if ($clickatell->send($alertee->alert_recipient, $sms_from, $message) == "OK") {
                         $alert = ORM::factory('alert_sent');
                         $alert->alert_id = $alertee->id;
                         $alert->incident_id = $incident->id;
                         $alert->alert_date = date("Y-m-d H:i:s");
                         $alert->save();
                     }
                 } elseif ($alert_type == 2) {
                     //XXX: Setup correct 'from' address and message
                     $to = $alertee->alert_recipient;
                     $from = $config['alerts_email'];
                     $subject = $incident->incident_title;
                     $message = $incident->incident_description;
                     if (email::send($to, $from, $subject, $message, TRUE) == 1) {
                         $alert = ORM::factory('alert_sent');
                         $alert->alert_id = $alertee->id;
                         $alert->incident_id = $incident->id;
                         $alert->alert_date = date("Y-m-d H:i:s");
                         $alert->save();
                     }
                 }
             }
         }
     }
 }
 public function index()
 {
     $settings = kohana::config('settings');
     $site_name = $settings['site_name'];
     $alerts_email = $settings['alerts_email'];
     $unsubscribe_message = Kohana::lang('alerts.unsubscribe') . url::site() . 'alerts/unsubscribe/';
     $database_settings = kohana::config('database');
     //around line 33
     $this->table_prefix = $database_settings['default']['table_prefix'];
     //around line 34
     $settings = NULL;
     $sms_from = NULL;
     $clickatell = NULL;
     $db = new Database();
     /* Find All Alerts with the following parameters
     		- incident_active = 1 -- An approved incident
     		- incident_alert_status = 1 -- Incident has been tagged for sending
     		
     		Incident Alert Statuses
     		  - 0, Incident has not been tagged for sending. Ensures old incidents are not sent out as alerts
     		  - 1, Incident has been tagged for sending by updating it with 'approved' or 'verified'
     		  - 2, Incident has been tagged as sent. No need to resend again
     		*/
     $incidents = $db->query("SELECT i.id, incident_title, \n\t\t\t\t\t\t\t\t incident_description, incident_verified, \n\t\t\t\t\t\t\t\t l.latitude, l.longitude, a.alert_id, a.incident_id\n\t\t\t\t\t\t\t\t FROM " . $this->table_prefix . "incident AS i INNER JOIN " . $this->table_prefix . "location AS l ON i.location_id = l.id\n\t\t\t\t\t\t\t\t LEFT OUTER JOIN " . $this->table_prefix . "alert_sent AS a ON i.id = a.incident_id WHERE\n\t\t\t\t\t\t\t\t i.incident_active=1 AND i.incident_archived = 0 AND i.incident_alert_status = 1 ");
     foreach ($incidents as $incident) {
         $latitude = (double) $incident->latitude;
         $longitude = (double) $incident->longitude;
         // Get all alertees
         $alertees = ORM::factory('alert')->where('alert_confirmed', '1')->find_all();
         foreach ($alertees as $alertee) {
             // Has this alert been sent to this alertee?
             if ($alertee->id == $incident->alert_id) {
                 continue;
             }
             $alert_radius = (int) $alertee->alert_radius;
             $alert_type = (int) $alertee->alert_type;
             $latitude2 = (double) $alertee->alert_lat;
             $longitude2 = (double) $alertee->alert_lon;
             $distance = (string) new Distance($latitude, $longitude, $latitude2, $longitude2);
             // If the calculated distance between the incident and the alert fits...
             if ($distance <= $alert_radius) {
                 if ($alert_type == 1) {
                     if ($settings == null) {
                         $settings = ORM::factory('settings', 1);
                         if ($settings->loaded == true) {
                             // Get SMS Numbers
                             if (!empty($settings->sms_no3)) {
                                 $sms_from = $settings->sms_no3;
                             } elseif (!empty($settings->sms_no2)) {
                                 $sms_from = $settings->sms_no2;
                             } elseif (!empty($settings->sms_no1)) {
                                 $sms_from = $settings->sms_no1;
                             } else {
                                 $sms_from = "000";
                             }
                             // Admin needs to set up an SMS number
                         }
                         $clickatell = new Clickatell();
                         $clickatell->api_id = $settings->clickatell_api;
                         $clickatell->user = $settings->clickatell_username;
                         $clickatell->password = $settings->clickatell_password;
                         $clickatell->use_ssl = false;
                         $clickatell->sms();
                     }
                     $message = $incident->incident_description;
                     // If Clickatell Is Set Up
                     if ($clickatell->send($alertee->alert_recipient, $sms_from, $message) == "OK") {
                         $alert = ORM::factory('alert_sent');
                         $alert->alert_id = $alertee->id;
                         $alert->incident_id = $incident->id;
                         $alert->alert_date = date("Y-m-d H:i:s");
                         $alert->save();
                     }
                 } elseif ($alert_type == 2) {
                     $to = $alertee->alert_recipient;
                     $from = $alerts_email;
                     $subject = "[{$site_name}] " . $incident->incident_title;
                     $message = $incident->incident_description . "<p>" . $unsubscribe_message . $alertee->alert_code . "</p>";
                     if (email::send($to, $from, $subject, $message, TRUE) == 1) {
                         $alert = ORM::factory('alert_sent');
                         $alert->alert_id = $alertee->id;
                         $alert->incident_id = $incident->id;
                         $alert->alert_date = date("Y-m-d H:i:s");
                         $alert->save();
                     }
                 }
             }
         }
         // End For Each Loop
         // Update Incident - All Alerts Have Been Sent!
         $update_incident = ORM::factory('incident', $incident->id);
         if ($update_incident->loaded) {
             $update_incident->incident_alert_status = 2;
             $update_incident->save();
         }
     }
 }
Example #12
0
 public function ProcessSMS()
 {
     require_once "Twilio.php";
     $sms_sender_id = Yii::app()->functions->getOptionAdmin('sms_sender_id');
     $sms_account_id = Yii::app()->functions->getOptionAdmin('sms_account_id');
     $sms_token = Yii::app()->functions->getOptionAdmin('sms_token');
     $nexmo_sender_id = Yii::app()->functions->getOptionAdmin('nexmo_sender_id');
     $nexmo_key = Yii::app()->functions->getOptionAdmin('nexmo_key');
     $nexmo_secret = Yii::app()->functions->getOptionAdmin('nexmo_secret');
     $nexmo_use_curl = Yii::app()->functions->getOptionAdmin('nexmo_use_curl');
     $sms_provider = Yii::app()->functions->getOptionAdmin('sms_provider');
     $clickatel_user = Yii::app()->functions->getOptionAdmin('clickatel_user');
     $clickatel_password = Yii::app()->functions->getOptionAdmin('clickatel_password');
     $clickatel_api_id = Yii::app()->functions->getOptionAdmin('clickatel_api_id');
     $clickatel_use_curl = Yii::app()->functions->getOptionAdmin('clickatel_use_curl');
     $nexmo_use_unicode = Yii::app()->functions->getOptionAdmin('nexmo_use_unicode');
     $clickatel_use_unicode = Yii::app()->functions->getOptionAdmin('clickatel_use_unicode');
     $clickatel_sender = Yii::app()->functions->getOptionAdmin('clickatel_sender');
     $privatesms_username = Yii::app()->functions->getOptionAdmin('privatesms_username');
     $privatesms_password = Yii::app()->functions->getOptionAdmin('privatesms_password');
     $privatesms_sender = Yii::app()->functions->getOptionAdmin('privatesms_sender');
     /*dump($sms_sender_id);
     		dump($sms_account_id);
     		dump($sms_token);*/
     $db_ext = new DbExt();
     $stmt = "\n\t\tSELECT * FROM\n\t\t{{sms_broadcast_details}}\n\t\tWHERE\n\t\tstatus IN ('pending')\n\t\tORDER BY id ASC\n\t\tLIMIT 0,50\n\t\t";
     if ($res = $db_ext->rst($stmt)) {
         foreach ($res as $val) {
             dump($val);
             //$available_credit=Yii::app()->functions->getMerchantSMSCredit(Yii::app()->functions->getMerchantID());
             $available_credit = Yii::app()->functions->getMerchantSMSCredit($val['merchant_id']);
             dump($available_credit);
             if ($available_credit >= 1) {
                 //if ( !empty($sms_sender_id) && !empty($sms_account_id) && !empty($sms_token)){
                 $raw = '';
                 $msg = '';
                 if ($sms_provider == "nexmo") {
                     $Nexmo = new Nexmo();
                     $Nexmo->key = $nexmo_key;
                     $Nexmo->secret = $nexmo_secret;
                     $Nexmo->sender = $nexmo_sender_id;
                     $Nexmo->to = $val['contact_phone'];
                     $Nexmo->message = $val['sms_message'];
                     $Nexmo->is_curl = $nexmo_use_curl;
                     if ($nexmo_use_unicode == 1) {
                         $Nexmo->unicode = true;
                     }
                     try {
                         $raw = $resp = $Nexmo->sendSMS();
                         $msg = "process";
                     } catch (Exception $e) {
                         $msg = $e->getMessage();
                     }
                 } elseif ($sms_provider == "clickatell") {
                     $Clickatell = new Clickatell();
                     $Clickatell->user = $clickatel_user;
                     $Clickatell->password = $clickatel_password;
                     $Clickatell->api_id = $clickatel_api_id;
                     $Clickatell->is_curl = $clickatel_use_curl;
                     $Clickatell->to = $val['contact_phone'];
                     $Clickatell->message = $val['sms_message'];
                     if ($clickatel_use_unicode == 1) {
                         $Clickatell->unicode = true;
                     }
                     $Clickatell->sender = $clickatel_sender;
                     try {
                         $raw = $resp = $Clickatell->sendSMS();
                         $msg = "process";
                     } catch (Exception $e) {
                         $msg = $e->getMessage();
                     }
                 } elseif ($sms_provider == "private") {
                     $obj = new Sender("103.16.101.52", "80", $privatesms_username, $privatesms_password, $privatesms_sender, $val['sms_message'], $val['contact_phone'], "0", "1");
                     $resp = $obj->Submit();
                     if (preg_match("/1701/i", $resp)) {
                         $raw = $resp;
                         $msg = "process";
                     } else {
                         $errors['1702'] = "Invalid URL Error, This means that one of the parameters was not\n\t\t\tprovided or left blank";
                         $errors['1703'] = "Invalid value in username or password field";
                         $errors['1704'] = 'Invalid value in "type" field';
                         $errors['1705'] = "Invalid Message";
                         $errors['1706'] = "Invalid Destination";
                         $errors['1707'] = "Invalid Source (Sender)";
                         $errors['1708'] = 'Invalid value for "dlr" field';
                         $errors['1709'] = "User validation failed";
                         $errors['1710'] = "Internal Error";
                         $errors['1025'] = "Insufficient Credit";
                         $resp_temp = explode("|", $resp);
                         if (is_array($resp_temp) && count($resp_temp) >= 1) {
                             $code_error = $resp_temp[0];
                         } else {
                             $code_error = $resp;
                         }
                         $raw = $resp;
                         if (array_key_exists($code_error, $errors)) {
                             $msg = $errors[$code_error];
                         } else {
                             $msg = "Undefined response from api.";
                         }
                     }
                 } else {
                     $twilio = new Twilio();
                     $twilio->_debug = false;
                     $twilio->sid = $sms_account_id;
                     $twilio->auth = $sms_token;
                     $twilio->data['From'] = $sms_sender_id;
                     $twilio->data['To'] = $val['contact_phone'];
                     $twilio->data['Body'] = $val['sms_message'];
                     if ($resp = $twilio->sendSMS()) {
                         $raw = $twilio->getSuccessXML();
                         $msg = "process";
                     } else {
                         $msg = $twilio->getError();
                     }
                 }
                 //} else $msg=Yii::t("default","Admin SMS Settings Invalid");
             } else {
                 $msg = Yii::t("default", "No SMS Credit");
             }
             $params = array('status' => $msg, 'gateway_response' => $raw, 'date_executed' => date('c'), 'gateway' => $sms_provider);
             $db_ext->updateData("{{sms_broadcast_details}}", $params, 'id', $val['id']);
         }
     } else {
         echo "<p>No records to process</p>";
     }
 }
Example #13
0
        $inst = $instruction[0];
    }
    $specinst = "Special instruction by customer:" . $inst;
}
if ($restuarant_id == '61111') {
    echo "hells kitchen";
    $to = 'Djamel Omari';
    $to_email = '*****@*****.**';
    $text_msg = 'Hells kitchen:It looks like ' . $fname . '(phone:' . $phone . ') has booked a table for ' . $people_count . ' on ' . $date . ' at ' . $time . "." . $specinst;
} else {
    echo "west village";
    $to = 'Philippe Thienard';
    $to_email = '*****@*****.**';
    $text_msg = 'West Village:It looks like ' . $fname . '(phone:' . $phone . ')  has booked a table for ' . $people_count . ' on ' . $date . ' at ' . $time . "." . $specinst;
}
$mm = substr($date, 0, 2);
$dd = substr($date, 3, 2);
$yy = substr($date, 6, 4);
$format_date = $yy . '-' . $mm . '-' . $dd;
echo $date . "\n";
echo $format_date . "\n";
$InsQuery = "Insert into Booking_details (fname, lname, phone, email, instruction, reservation_id, receipt_no, people_count, time,date,restuarant_id,flag_reminder)VALUES ('{$fname}', '{$lname}', '{$phone}', '{$emailid}', '{$inst}', '{$reservation_id}', '{$receipt_no}', '{$people_count}', '{$time}','{$format_date}','{$restuarant_id}','0') ";
mysql_query($InsQuery);
send_mail($fname, $people_count, $date, $time, $receipt_no, $to, $to_email, $phone, $emailid, $specinst);
$obj = new Clickatell();
$obj->sendSms("16465957373", $text_msg);
?>



Example #14
0
$date = date("h:i");
$specinst = "";
if ($result && mysql_num_rows($result) > 0) {
    while ($row = mysql_fetch_array($result)) {
        $varTime = $row["time"];
        $varHour = substr($varTime, 0, 2);
        $varMin = substr($varTime, 3, 2);
        if ($varHour < 12) {
            $varHour = $varHour + 12;
        }
        $varRowTime = $varHour . ":" . $varMin;
        $time_diff = get_timedifference($time1, $varRowTime);
        echo $row["id"] . "time diff is" . $time_diff . "\n";
        if ($time_diff <= 40) {
            echo "reminder sent" . $row["id"] . "\n";
            $obj = new Clickatell();
            $phone_number_temp = $row["phone"];
            $phone_number = preg_replace("/[^0-9]/", "", $phone_number_temp);
            if (strlen($phone_number) == 10) {
                $phone_number = "1" . $phone_number;
            } else {
                $phone_number = $phone_number;
            }
            $obj->sendSms($phone_number, $text_msg);
            send_reminder($row["fname"], $row["email"]);
            $sql = "UPDATE Booking_details SET flag_reminder ='1' WHERE id='" . $row['id'] . "'";
            mysql_query($sql) or die("I cannot run , reason : " . mysql_error());
        }
    }
} else {
    echo "inside else";
Example #15
0
    public function index()
    {
        $config = kohana::config('alerts');
        $settings = kohana::config('settings');
        $site_name = $settings['site_name'];
        $unsubscribe_message = Kohana::lang('alerts.unsubscribe') . url::site() . 'alerts/unsubscribe/';
        $settings = NULL;
        $sms_from = NULL;
        $clickatell = NULL;
        $miles = FALSE;
        // Change to True to calculate distances in Miles
        $max_recipients = 20;
        // Limit each script execution to 50 recipients
        $db = new Database();
        $incidents = $db->query("SELECT incident.id, incident_title, \n\t\t\t\t\t\t\t\t incident_description, incident_verified, \n\t\t\t\t\t\t\t\t location.latitude, location.longitude, alert_sent.incident_id\n\t\t\t\t\t\t\t\t FROM incident INNER JOIN location ON incident.location_id = location.id\n\t\t\t\t\t\t\t\t LEFT OUTER JOIN alert_sent ON incident.id = alert_sent.incident_id");
        foreach ($incidents as $incident) {
            $latitude = (double) $incident->latitude;
            $longitude = (double) $incident->longitude;
            // 2 - Retrieve All Qualifying Alertees Based on Distance and Make sure they haven't received this alert
            $distance_type = $miles ? "" : " * 1.609344";
            $alertees = $db->query('SELECT DISTINCT alert.*, ((ACOS(SIN(' . $latitude . ' * PI() / 180) * 
									SIN(`alert`.`alert_lat` * PI() / 180) + COS(' . $latitude . ' * PI() / 180) * 
									COS(`alert`.`alert_lat` * PI() / 180) * COS((' . $longitude . ' - `alert`.`alert_lon`)
									 * PI() / 180)) * 180 / PI()) * 60 * 1.1515 ' . $distance_type . ') AS distance
									FROM alert WHERE alert.alert_confirmed = 1 
									HAVING distance <= alert_radius ');
            if ($incident->incident_id != NULL) {
                continue;
            }
            $verified = (int) $incident->incident_verified;
            if ($verified) {
                $latitude = (double) $incident->latitude;
                $longitude = (double) $incident->longitude;
                $proximity = new Proximity($latitude, $longitude);
                $alertees = $this->_get_alertees($proximity);
                foreach ($alertees as $alertee) {
                    $alert_type = (int) $alertee->alert_type;
                    if ($alert_type == 1) {
                        if ($settings == null) {
                            $settings = ORM::factory('settings', 1);
                            if ($settings->loaded == true) {
                                // Get SMS Numbers
                                if (!empty($settings->sms_no3)) {
                                    $sms_from = $settings->sms_no3;
                                } elseif (!empty($settings->sms_no2)) {
                                    $sms_from = $settings->sms_no2;
                                } elseif (!empty($settings->sms_no1)) {
                                    $sms_from = $settings->sms_no1;
                                } else {
                                    $sms_from = "000";
                                }
                                // User needs to set up an SMS number
                            }
                            $clickatell = new Clickatell();
                            $clickatell->api_id = $settings->clickatell_api;
                            $clickatell->user = $settings->clickatell_username;
                            $clickatell->password = $settings->clickatell_password;
                            $clickatell->use_ssl = false;
                            $clickatell->sms();
                        }
                        $message = $incident->incident_description;
                        if ($clickatell->send($alertee->alert_recipient, $sms_from, $message) == "OK") {
                            $alert = ORM::factory('alert_sent');
                            $alert->alert_id = $alertee->id;
                            $alert->incident_id = $incident->id;
                            $alert->alert_date = date("Y-m-d H:i:s");
                            $alert->save();
                        }
                    } elseif ($alert_type == 2) {
                        $disallowed_chars = array("(", ")", "[", "]");
                        $to = $alertee->alert_recipient;
                        $from = $config['alerts_email'];
                        $subject = trim(str_replace($disallowed_chars, "", $site_name) . ": " . str_replace($disallowed_chars, "", $incident->incident_title));
                        $message = $incident->incident_description . "<p>" . url::base() . "reports/view/" . $incident->id . "</p>" . "<p>" . $unsubscribe_message . $alertee->alert_code . "</p>";
                        if (email::send($to, $from, $subject, $message, TRUE) == 1) {
                            $alert = ORM::factory('alert_sent');
                            $alert->alert_id = $alertee->id;
                            $alert->incident_id = $incident->id;
                            $alert->alert_date = date("Y-m-d H:i:s");
                            $alert->save();
                        }
                    }
                }
            }
        }
    }
Example #16
-1
 public function sendSMS($to = '', $message = '')
 {
     $to = trim($to);
     $message = trim($message);
     $msg = '';
     $raw = '';
     $sms_provider = Yii::app()->functions->getOptionAdmin('sms_provider');
     //if ($sms_provider=="nexmo"){
     $sms_provider = strtolower($sms_provider);
     //dump($sms_provider);
     switch ($sms_provider) {
         case "clickatell":
             $Clickatell = new Clickatell();
             $Clickatell->user = Yii::app()->functions->getOptionAdmin('clickatel_user');
             $Clickatell->password = Yii::app()->functions->getOptionAdmin('clickatel_password');
             $Clickatell->api_id = Yii::app()->functions->getOptionAdmin('clickatel_api_id');
             $Clickatell->is_curl = Yii::app()->functions->getOptionAdmin('clickatel_use_curl');
             $Clickatell->to = $to;
             $Clickatell->message = $message;
             $clickatel_use_unicode = Yii::app()->functions->getOptionAdmin('clickatel_use_unicode');
             if ($clickatel_use_unicode == 1) {
                 $Clickatell->unicode = true;
             }
             $clickatel_sender = Yii::app()->functions->getOptionAdmin('clickatel_sender');
             $Clickatell->sender = $clickatel_sender;
             try {
                 $raw = $Clickatell->sendSMS();
                 $msg = "process";
             } catch (Exception $e) {
                 $msg = $e->getMessage();
                 $raw = $e->getMessage();
             }
             break;
         case "nexmo":
             $nexmo_sender_id = Yii::app()->functions->getOptionAdmin('nexmo_sender_id');
             $nexmo_key = Yii::app()->functions->getOptionAdmin('nexmo_key');
             $nexmo_secret = Yii::app()->functions->getOptionAdmin('nexmo_secret');
             $nexmo_use_curl = Yii::app()->functions->getOptionAdmin('nexmo_use_curl');
             $Nexmo = new Nexmo();
             $Nexmo->key = $nexmo_key;
             $Nexmo->secret = $nexmo_secret;
             $Nexmo->sender = $nexmo_sender_id;
             $Nexmo->to = $to;
             $Nexmo->message = $message;
             $Nexmo->is_curl = $nexmo_use_curl;
             $nexmo_use_unicode = Yii::app()->functions->getOptionAdmin('nexmo_use_unicode');
             if ($nexmo_use_unicode == 1) {
                 $Nexmo->unicode = true;
             }
             try {
                 $raw = $Nexmo->sendSMS();
                 $msg = "process";
             } catch (Exception $e) {
                 $msg = $e->getMessage();
             }
             break;
         case "private":
             $privatesms_username = Yii::app()->functions->getOptionAdmin('privatesms_username');
             $privatesms_password = Yii::app()->functions->getOptionAdmin('privatesms_password');
             $privatesms_sender = Yii::app()->functions->getOptionAdmin('privatesms_sender');
             /*dump($privatesms_username);
             	 dump($privatesms_password);
             	 dump($privatesms_sender);*/
             $obj = new Sender("103.16.101.52", "80", $privatesms_username, $privatesms_password, $privatesms_sender, $message, $to, "0", "1");
             $resp = $obj->Submit();
             if (preg_match("/1701/i", $resp)) {
                 $raw = $resp;
                 $msg = "process";
             } else {
                 $errors['1702'] = "Invalid URL Error, This means that one of the parameters was not\r\n\t\t\tprovided or left blank";
                 $errors['1703'] = "Invalid value in username or password field";
                 $errors['1704'] = 'Invalid value in "type" field';
                 $errors['1705'] = "Invalid Message";
                 $errors['1706'] = "Invalid Destination";
                 $errors['1707'] = "Invalid Source (Sender)";
                 $errors['1708'] = 'Invalid value for "dlr" field';
                 $errors['1709'] = "User validation failed";
                 $errors['1710'] = "Internal Error";
                 $errors['1025'] = "Insufficient Credit";
                 $resp_temp = explode("|", $resp);
                 if (is_array($resp_temp) && count($resp_temp) >= 1) {
                     $code_error = $resp_temp[0];
                 } else {
                     $code_error = $resp;
                 }
                 if (array_key_exists($code_error, $errors)) {
                     $msg = $errors[$code_error];
                 } else {
                     $msg = "Undefined response from api.";
                 }
             }
             break;
         case "bhashsms":
             $bhashsms_user = Yii::app()->functions->getOptionAdmin('bhashsms_user');
             $bhashsms_pass = Yii::app()->functions->getOptionAdmin('bhashsms_pass');
             $bhashsms_senderid = Yii::app()->functions->getOptionAdmin('bhashsms_senderid');
             $bhashsms_smstype = Yii::app()->functions->getOptionAdmin('bhashsms_smstype');
             $bhashsms_priority = Yii::app()->functions->getOptionAdmin('bhashsms_priority');
             $bhashsms_use_curl = Yii::app()->functions->getOptionAdmin('bhashsms_use_curl');
             $Bhashsms = new Bhashsms();
             $Bhashsms->user = $bhashsms_user;
             $Bhashsms->password = $bhashsms_pass;
             $Bhashsms->sender = $bhashsms_senderid;
             $Bhashsms->sms_type = $bhashsms_smstype;
             $Bhashsms->priority = $bhashsms_priority;
             $Bhashsms->to = $to;
             $Bhashsms->message = $message;
             $Bhashsms->is_curl = $bhashsms_use_curl == 1 ? true : false;
             try {
                 $raw = $Bhashsms->sendSMS();
                 $msg = "process";
             } catch (Exception $e) {
                 $msg = $e->getMessage();
             }
             break;
         default:
             require_once "Twilio.php";
             $sms_sender_id = Yii::app()->functions->getOptionAdmin('sms_sender_id');
             $sms_account_id = Yii::app()->functions->getOptionAdmin('sms_account_id');
             $sms_token = Yii::app()->functions->getOptionAdmin('sms_token');
             $twilio = new Twilio();
             $twilio->_debug = false;
             $twilio->sid = $sms_account_id;
             $twilio->auth = $sms_token;
             $twilio->data['From'] = $sms_sender_id;
             $twilio->data['To'] = $to;
             $twilio->data['Body'] = $message;
             if ($resp = $twilio->sendSMS()) {
                 $raw = $twilio->getSuccessXML();
                 $msg = "process";
             } else {
                 $msg = $twilio->getError();
             }
             break;
     }
     return array('msg' => $msg, 'raw' => $raw, 'sms_provider' => $sms_provider);
 }