Пример #1
0
 /**
  * Tests Alert_Model->validate()
  *
  * @test
  * @dataProvider providerValidate
  * @param array $data Input data to be validated
  * @param boolean $save Toggles the saving of the alert data 
  */
 public function testValidate($data, $save)
 {
     // Create instance for the Alert_Model class
     $model = new Alert_Model();
     // Check if the validation	succeeded
     $this->assertEquals(TRUE, $model->validate($data, $save));
 }
Пример #2
0
 /**
  * Tests where no subscriber email address or phone no. has been specified
  * 
  * @dataProvider providerValidateSubscriber
  */
 public function test_validate_no_subscriber($data)
 {
     // Create an instance for the Alert_Model class
     $alert = new Alert_Model();
     //Check if validation succeeded
     $this->assertFalse($alert->validate($data), 'Neither Alert Email address or Alert Mobile phone number has been specified');
 }
Пример #3
0
 /**
  * This handles sms alerts subscription via phone
  *
  * @param string $message_from Subscriber MSISDN (mobile phone number)
  * @param string $message_description Message content
  * @return bool
  */
 public static function mobile_alerts_register($message_from, $message_description)
 {
     // Preliminary validation
     if (empty($message_from) or empty($message_description)) {
         // Log the error
         Kohana::log('info', 'Insufficient data to proceed with subscription via mobile phone');
         // Return
         return FALSE;
     }
     //Get the message details (location, category, distance)
     $message_details = explode(" ", $message_description);
     $message = $message_details[1] . "," . Kohana::config('settings.default_country');
     $geocoder = map::geocode($message);
     // Generate alert code
     $alert_code = text::random('distinct', 8);
     // POST variable with items to save
     $post = array('alert_type' => self::MOBILE_ALERT, 'alert_mobile' => $message_from, 'alert_code' => $alert_code, 'alert_lon' => $geocoder['lon'], 'alert_lat' => $geocoder['lat'], 'alert_radius' => '20', 'alert_confirmed' => '1');
     // Create ORM object for the alert and validate
     $alert_orm = new Alert_Model();
     if ($alert_orm->validate($post)) {
         return self::_send_mobile_alert($post, $alert_orm);
     }
     return FALSE;
 }
Пример #4
0
 /**
  * Unsubscribes alertee using alertee's confirmation code
  *
  * @param string $code
  */
 public function unsubscribe($code = NULL)
 {
     $this->template->content = new View('alerts_unsubscribe');
     $this->template->header->this_page = 'alerts';
     $this->template->content->unsubscribed = FALSE;
     // XXX Might need to validate $code as well
     if ($code != NULL) {
         Alert_Model::unsubscribe($code);
         $this->template->content->unsubscribed = TRUE;
     }
     // Rebuild Header Block
     $this->template->header->header_block = $this->themes->header_block();
 }
Пример #5
0
 /**
  * Lists all alerts in the system
  * @return void
  */
 public function index()
 {
     $this->template->content = new View('admin/manage/alerts/main');
     $this->template->content->title = Kohana::lang('ui_admin.alerts');
     // Is this an SMS or Email Filter?
     if (!empty($_GET['type'])) {
         $type = $_GET['type'];
         if ($type == '1') {
             // SMS
             $filter = 'alert_type=1';
         } elseif ($type == '2') {
             // EMAIL
             $filter = 'alert_type=2';
         } else {
             // ALL
             $filter = '1=1';
         }
     } else {
         $type = "0";
         $filter = '1=1';
     }
     // Are we using an Alert Keyword?
     if (isset($_GET['ak']) and !empty($_GET['ak'])) {
         $table_prefix = Kohana::config('database.default.table_prefix');
         //	Brute force input sanitization
         // Phase 1 - Strip the search string of all non-word characters
         $keyword = $_GET['ak'];
         $keyword_raw = preg_replace('#/\\w+/#', '', $keyword);
         // Strip any HTML tags that may have been missed in Phase 1
         $keyword_raw = strip_tags($keyword_raw);
         // Phase 3 - Invoke Kohana's XSS cleaning mechanism just incase an outlier wasn't caught
         // in the first 2 steps
         $keyword_raw = $this->input->xss_clean($keyword_raw);
         $keyword_raw = $this->db->escape_str($keyword_raw);
         $filter .= " AND " . $table_prefix . "alert_recipient LIKE '%" . $keyword_raw . "%'";
     } else {
         $keyword = '';
     }
     // setup and initialize form field names
     $form = array('action' => '');
     //	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;
     $form_action = "";
     if ($_POST) {
         $post = Validation::factory($_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('action', 'required', 'alpha', 'length[1,1]');
         if ($post->action == 'd') {
             $post->add_rules('alert_id.*', 'required', 'numeric');
         }
         if ($post->validate()) {
             // Delete Alert
             if ($post->action == 'd') {
                 foreach ($post->alert_id as $item) {
                     $update = new Alert_Model($item);
                     if ($update->loaded) {
                         $update->delete();
                     }
                 }
                 $form_saved = TRUE;
                 $form_action = strtoupper(Kohana::lang('ui_admin.deleted'));
             }
         } else {
             $errors = arr::overwrite($errors, $post->errors('alerts'));
             $form_error = TRUE;
         }
     }
     // Pagination
     $pagination = new Pagination(array('query_string' => 'page', 'items_per_page' => $this->items_per_page, 'total_items' => ORM::factory('alert')->where($filter)->count_all()));
     $alerts = ORM::factory('alert')->where($filter)->find_all($this->items_per_page, $pagination->sql_offset);
     $this->template->content->form = $form;
     $this->template->content->errors = $errors;
     $this->template->content->form_error = $form_error;
     $this->template->content->form_saved = $form_saved;
     $this->template->content->form_action = $form_action;
     $this->template->content->pagination = $pagination;
     $this->template->content->total_items = $pagination->total_items;
     $this->template->content->alerts = $alerts;
     $this->template->content->type = $type;
     $this->template->content->keyword = $keyword;
     // Javascript Header
     $this->themes->js = new View('admin/manage/alerts/alerts_js');
 }
Пример #6
0
 /**
  * Tests Alert_Model->alert_code_exist() where the alert_code is
  * non-existent
  *
  * @test
  * @dataProvider providerValidateAlertCode
  * @param array $data Input data to be validated
  */
 public function test_alert_code_non_exists($data)
 {
     // Create instance for the Alert_Model class
     $model = new Alert_Model();
     // Check if the alert code exists
     $this->assertEquals(FALSE, $model->alert_code_exists($data), 'Alert Code does not exist');
 }