/** * Saves an incident * * @param Validation $post Validation object with the data to be saved * @param Incident_Model $incident Incident_Model instance to be modified * @param Location_Model $location_model Location to be attached to the incident * @param int $id ID no. of the report * */ public static function save_report($post, $incident, $location_id) { // Exception handling if (!$post instanceof Validation_Core and !$incident instanceof Incident_Model) { // Throw exception throw new Kohana_Exception('Invalid parameter types'); } // Verify that the location id exists if (!Location_Model::is_valid_location($location_id)) { throw new Kohana_Exception(sprintf('Invalid location id specified: ', $location_id)); } // Is this new or edit? if ($incident->loaded) { // Edit $incident->incident_datemodify = date("Y-m-d H:i:s", time()); } else { // New $incident->incident_dateadd = date("Y-m-d H:i:s", time()); } $incident->location_id = $location_id; //$incident->locale = $post->locale; if (isset($post->form_id)) { $incident->form_id = $post->form_id; } // Check if the user id has been specified if (isset($_SESSION['auth_user'])) { $incident->user_id = $_SESSION['auth_user']->id; } $incident->incident_title = $post->incident_title; $incident->incident_description = $post->incident_description; $incident_date = explode("/", $post->incident_date); // Where the $_POST['date'] is a value posted by form in mm/dd/yyyy format $incident_date = $incident_date[2] . "-" . $incident_date[0] . "-" . $incident_date[1]; $incident_time = $post->incident_hour . ":" . $post->incident_minute . ":00 " . $post->incident_ampm; $incident->incident_date = date("Y-m-d H:i:s", strtotime($incident_date . " " . $incident_time)); // Is this an Email, SMS, Twitter submitted report? if (!empty($post->service_id)) { // SMS if ($post->service_id == 1) { $incident->incident_mode = 2; } elseif ($post->service_id == 2) { $incident->incident_mode = 3; } elseif ($post->service_id == 3) { $incident->incident_mode = 4; } else { // Default to Web Form $incident->incident_mode = 1; } } // Approval Status if (isset($post->incident_active)) { $incident->incident_active = $post->incident_active; } // Verification status if (isset($post->incident_verified)) { $incident->incident_verified = $post->incident_verified; } // Incident zoom if (!empty($post->incident_zoom)) { $incident->incident_zoom = intval($post->incident_zoom); } // Tag this as a report that needs to be sent out as an alert if ($incident->incident_active == 1 and $incident->incident_alert_status != 2) { // 2 = report that has had an alert sent $incident->incident_alert_status = '1'; } // Remove alert if report is unactivated and alert hasn't yet been sent if ($incident->incident_active == 0 and $incident->incident_alert_status == 1) { $incident->incident_alert_status = '0'; } // Save the incident $incident->save(); }