當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Incident_Model::save方法代碼示例

本文整理匯總了PHP中Incident_Model::save方法的典型用法代碼示例。如果您正苦於以下問題:PHP Incident_Model::save方法的具體用法?PHP Incident_Model::save怎麽用?PHP Incident_Model::save使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Incident_Model的用法示例。


在下文中一共展示了Incident_Model::save方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: add_reports

 /**
  * Adds reports in JSON format to the database
  * @param string $data - CF JSON results
  */
 private function add_reports($data)
 {
     $reports = json_decode($data, false);
     foreach ($reports as $report) {
         //Save the Report location
         $location = new Location_Model();
         $location->longitude = $report->{'longitude'};
         $location->latitude = $report->{'latitude'};
         $location->location_name = $report->{'location_city'};
         $location->save();
         // Save CF result as Report
         $incident = new Incident_Model();
         $incident->location_id = $location->id;
         // $incident->id = $report->{'id'};
         $incident->incident_title = date("Y-m-d H:i:s", time());
         $incident->incident_description = $report->{'sms_text'};
         $incident->incident_date = date("Y-m-d H:i:s", time());
         $incident->incident_dateadd = date("Y-m-d H:i:s", time());
         $incident->incident_active = 1;
         $incident->incident_verified = 1;
         $incident->save();
         // Save Incident Category
         $categories = explode(",", $report->{'categories'});
         foreach ($categories as $category) {
             $report_category_id = ORM::factory("category")->where("category_title", $category)->find();
             if ($report_category_id->loaded) {
                 $incident_category = new Incident_Category_Model();
                 $incident_category->incident_id = $incident->id;
                 $incident_category->category_id = $report_category_id->id;
                 $incident_category->save();
             }
         }
     }
 }
開發者ID:rrbaker,項目名稱:ushahidicrowdflower,代碼行數:38,代碼來源:s_crowdflower.php

示例2: index

 function index()
 {
     $source = 'http://legacy.ushahidi.com/export_data.asp';
     ORM::factory('Location')->delete_all();
     ORM::factory('Incident')->delete_all();
     ORM::factory('Media')->delete_all();
     ORM::factory('Incident_Person')->delete_all();
     ORM::factory('Incident_Category')->delete_all();
     ORM::factory('Comment')->delete_all();
     ORM::factory('Rating')->delete_all();
     // load as string
     $xmlstr = file_get_contents($source);
     $incidents = new SimpleXMLElement($xmlstr);
     foreach ($incidents as $post) {
         // STEP 1: SAVE LOCATION
         $location = new Location_Model();
         $location->location_name = (string) $post->location_name;
         $location->latitude = (string) $post->latitude;
         $location->longitude = (string) $post->longitude;
         $location->country_id = 115;
         $location->location_date = date("Y-m-d H:i:s", time());
         $location->save();
         // STEP 2: SAVE INCIDENT
         $incident = new Incident_Model();
         $incident->location_id = $location->id;
         $incident->user_id = 0;
         $incident->incident_title = (string) $post->incident_title;
         $incident->incident_description = (string) $post->incident_description;
         $incident->incident_date = (string) $post->incident_date;
         $incident->incident_active = (string) $post->active;
         $incident->incident_verified = (string) $post->verified;
         $incident->incident_dateadd = date("Y-m-d H:i:s", time());
         $incident->save();
         // STEP 3: SAVE CATEGORIES
         $incident_category = split(",", (string) $post->incident_category);
         foreach ($incident_category as $item) {
             if ($item != "") {
                 $incident_category = new Incident_Category_Model();
                 $incident_category->incident_id = $incident->id;
                 $incident_category->category_id = $item;
                 $incident_category->save();
             }
         }
         // STEP 4: SAVE MEDIA
         // a. News
         $news = new Media_Model();
         $news->location_id = $location->id;
         $news->incident_id = $incident->id;
         $news->media_type = 4;
         // News
         $news->media_link = (string) $post->news;
         $news->media_date = date("Y-m-d H:i:s", time());
         $news->save();
         // b. Video
         $video = new Media_Model();
         $video->location_id = $location->id;
         $video->incident_id = $incident->id;
         $video->media_type = 2;
         // Video
         $video->media_link = (string) $post->video;
         $video->media_date = date("Y-m-d H:i:s", time());
         $video->save();
         // STEP 5: SAVE PERSONAL INFORMATION
         $person = new Incident_Person_Model();
         $person->location_id = $location->id;
         $person->incident_id = $incident->id;
         $person->person_first = (string) $post->person_first;
         $person->person_phone = (string) $post->person_phone;
         $person->person_email = (string) $post->person_email;
         $person->person_ip = (string) $post->person_ip;
         $person->person_date = date("Y-m-d H:i:s", time());
         $person->save();
     }
     echo "******************************************<BR>";
     echo "******************************************<BR>";
     echo "**** IMPORT COMPLETE!!!<BR>";
     echo "******************************************<BR>";
     echo "******************************************<BR>";
 }
開發者ID:emoksha,項目名稱:freefairelections,代碼行數:79,代碼來源:import.php

示例3: submit

 /**
  * Submits a new report.
  */
 public function submit()
 {
     $this->template->header->this_page = 'reports_submit';
     $this->template->content = new View('reports_submit');
     // setup and initialize form field names
     $form = array('incident_title' => '', 'incident_description' => '', 'incident_date' => '', 'incident_hour' => '', 'incident_minute' => '', 'incident_ampm' => '', 'latitude' => '', 'longitude' => '', 'location_name' => '', 'country_id' => '', 'incident_category' => array(), 'incident_news' => array(), 'incident_video' => array(), 'incident_photo' => array(), 'person_first' => '', 'person_last' => '', 'person_email' => '');
     //copy the form as errors, so the errors will be stored with keys corresponding to the form field names
     $errors = $form;
     $form_error = FALSE;
     // Initialize Default Values
     $form['incident_date'] = date("m/d/Y", time());
     $form['incident_hour'] = "12";
     $form['incident_minute'] = "00";
     $form['incident_ampm'] = "pm";
     // 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 = Validation::factory(array_merge($_POST, $_FILES));
         //  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('incident_title', 'required', 'length[3,200]');
         $post->add_rules('incident_description', 'required');
         $post->add_rules('incident_date', 'required', 'date_mmddyyyy');
         $post->add_rules('incident_hour', 'required', 'between[1,12]');
         $post->add_rules('incident_minute', 'required', 'between[0,59]');
         if ($_POST['incident_ampm'] != "am" && $_POST['incident_ampm'] != "pm") {
             $post->add_error('incident_ampm', 'values');
         }
         // Validate for maximum and minimum latitude values
         $post->add_rules('latitude', 'required', 'between[-90,90]');
         $post->add_rules('longitude', 'required', 'between[-180,180]');
         $post->add_rules('location_name', 'required', 'length[3,200]');
         //XXX: Hack to validate for no checkboxes checked
         if (!isset($_POST['incident_category'])) {
             $post->incident_category = "";
             $post->add_error('incident_category', 'required');
         } else {
             $post->add_rules('incident_category.*', 'required', 'numeric');
         }
         // Validate only the fields that are filled in
         if (!empty($_POST['incident_news'])) {
             foreach ($_POST['incident_news'] as $key => $url) {
                 if (!empty($url) and !(bool) filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED)) {
                     $post->add_error('incident_news', 'url');
                 }
             }
         }
         // Validate only the fields that are filled in
         if (!empty($_POST['incident_video'])) {
             foreach ($_POST['incident_video'] as $key => $url) {
                 if (!empty($url) and !(bool) filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED)) {
                     $post->add_error('incident_video', 'url');
                 }
             }
         }
         // Validate photo uploads
         $post->add_rules('incident_photo', 'upload::valid', 'upload::type[gif,jpg,png]', 'upload::size[2M]');
         // Validate Personal Information
         if (!empty($_POST['person_first'])) {
             $post->add_rules('person_first', 'length[3,100]');
         }
         if (!empty($_POST['person_last'])) {
             $post->add_rules('person_last', 'length[3,100]');
         }
         if (!empty($_POST['person_email'])) {
             $post->add_rules('person_email', 'email', 'length[3,100]');
         }
         // Test to see if things passed the rule checks
         if ($post->validate()) {
             // STEP 1: SAVE LOCATION
             $location = new Location_Model();
             $location->location_name = $post->location_name;
             $location->latitude = $post->latitude;
             $location->longitude = $post->longitude;
             $location->location_date = date("Y-m-d H:i:s", time());
             $location->save();
             // STEP 2: SAVE INCIDENT
             $incident = new Incident_Model();
             $incident->location_id = $location->id;
             $incident->user_id = 0;
             $incident->incident_title = $post->incident_title;
             $incident->incident_description = $post->incident_description;
             $incident_date = explode("/", $post->incident_date);
             // 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 = $incident_date . " " . $incident_time;
             $incident->incident_dateadd = date("Y-m-d H:i:s", time());
             $incident->save();
             // STEP 3: SAVE CATEGORIES
             foreach ($post->incident_category as $item) {
                 $incident_category = new Incident_Category_Model();
                 $incident_category->incident_id = $incident->id;
                 $incident_category->category_id = $item;
                 $incident_category->save();
             }
//.........這裏部分代碼省略.........
開發者ID:kiirti,項目名稱:Ushahidi_MHI,代碼行數:101,代碼來源:reports.php

示例4: add_hash_tweets

 /**
  * Adds hash tweets in JSON format to the database and saves the sender as a new
  * Reporter if they don't already exist
  * @param string $data - Twitter JSON results
  */
 private function add_hash_tweets($data)
 {
     if ($this->_lock()) {
         return false;
     }
     $services = new Service_Model();
     $service = $services->where('service_name', 'Twitter')->find();
     if (!$service) {
         $this->_unlock();
         return false;
     }
     $tweets = json_decode($data, false);
     if (!$tweets) {
         $this->_unlock();
         return false;
     }
     if (isset($tweets->{'error'})) {
         $this->_unlock();
         return false;
     }
     $tweet_results = $tweets->{'results'};
     foreach ($tweet_results as $tweet) {
         $reporter = ORM::factory('reporter')->where('service_id', $service->id)->where('service_account', $tweet->{'from_user'})->find();
         if (!$reporter->loaded) {
             // get default reporter level (Untrusted)
             $level = ORM::factory('level')->where('level_weight', 0)->find();
             $reporter->service_id = $service->id;
             $reporter->level_id = $level->id;
             $reporter->service_account = $tweet->{'from_user'};
             $reporter->reporter_first = null;
             $reporter->reporter_last = null;
             $reporter->reporter_email = null;
             $reporter->reporter_phone = null;
             $reporter->reporter_ip = null;
             $reporter->reporter_date = date('Y-m-d');
             $reporter->save();
         }
         if ($reporter->level_id > 1 && count(ORM::factory("message")->where("service_messageid = '" . $tweet->{'id_str'} . "'")->find_all()) == 0) {
             // Grab geo data if it exists from the tweet
             $tweet_lat = null;
             $tweet_lon = null;
             if ($tweet->{'geo'} != null) {
                 $tweet_lat = $tweet->{'geo'}->coordinates[0];
                 $tweet_lon = $tweet->{'geo'}->coordinates[1];
             }
             // Save Tweet as Message
             $message = new Message_Model();
             $message->parent_id = 0;
             $message->incident_id = 0;
             $message->user_id = 0;
             $message->reporter_id = $reporter->id;
             $message->message_from = $tweet->{'from_user'};
             $message->message_to = null;
             $message->message = $tweet->{'text'};
             $message->message_type = 1;
             // Inbox
             $tweet_date = date("Y-m-d H:i:s", strtotime($tweet->{'created_at'}));
             $message->message_date = $tweet_date;
             $message->service_messageid = $tweet->{'id_str'};
             $message->latitude = $tweet_lat;
             $message->longitude = $tweet_lon;
             $message->save();
             // Action::message_twitter_add - Twitter Message Received!
             Event::run('ushahidi_action.message_twitter_add', $message);
             // Auto-Create A Report if Reporter is Trusted
             $reporter_weight = $reporter->level->level_weight;
             $reporter_location = $reporter->location;
             if ($reporter_weight > 0 and $reporter_location) {
                 $incident_title = text::limit_chars($message->message, 50, "...", false);
                 // Create Incident
                 $incident = new Incident_Model();
                 $incident->location_id = $reporter_location->id;
                 $incident->incident_title = $incident_title;
                 $incident->incident_description = $message->message;
                 $incident->incident_date = $tweet_date;
                 $incident->incident_dateadd = date("Y-m-d H:i:s", time());
                 $incident->incident_active = 1;
                 if ($reporter_weight == 2) {
                     $incident->incident_verified = 1;
                 }
                 $incident->save();
                 // Update Message with Incident ID
                 $message->incident_id = $incident->id;
                 $message->save();
                 // Save Incident Category
                 $trusted_categories = ORM::factory("category")->where("category_trusted", 1)->find();
                 if ($trusted_categories->loaded) {
                     $incident_category = new Incident_Category_Model();
                     $incident_category->incident_id = $incident->id;
                     $incident_category->category_id = $trusted_categories->id;
                     $incident_category->save();
                 }
             }
         }
     }
//.........這裏部分代碼省略.........
開發者ID:nemmy,項目名稱:Ushahidi_Web,代碼行數:101,代碼來源:s_twitter.php

示例5: edit

 /**
  * Edit a report
  * @param bool|int $id The id no. of the report
  * @param bool|string $saved
  */
 function edit($id = false, $saved = false)
 {
     $this->template->content = new View('admin/reports_edit');
     $this->template->content->title = Kohana::lang('ui_admin.create_report');
     // setup and initialize form field names
     $form = array('location_id' => '', 'form_id' => '', 'locale' => '', 'incident_title' => '', 'incident_description' => '', 'incident_date' => '', 'incident_hour' => '', 'incident_minute' => '', 'incident_ampm' => '', 'latitude' => '', 'longitude' => '', 'location_name' => '', 'country_id' => '', 'incident_category' => array(), 'incident_news' => array(), 'incident_video' => array(), 'incident_photo' => array(), 'person_first' => '', 'person_last' => '', 'person_email' => '', 'custom_field' => array(), 'incident_active' => '', 'incident_verified' => '', 'incident_source' => '', 'incident_information' => '');
     //  copy the form as errors, so the errors will be stored with keys corresponding to the form field names
     $errors = $form;
     $form_error = FALSE;
     if ($saved == 'saved') {
         $form_saved = TRUE;
     } else {
         $form_saved = FALSE;
     }
     // Initialize Default Values
     $form['locale'] = Kohana::config('locale.language');
     //$form['latitude'] = Kohana::config('settings.default_lat');
     //$form['longitude'] = Kohana::config('settings.default_lon');
     $form['country_id'] = Kohana::config('settings.default_country');
     $form['incident_date'] = date("m/d/Y", time());
     $form['incident_hour'] = date('g');
     $form['incident_minute'] = date('i');
     $form['incident_ampm'] = date('a');
     // initialize custom field array
     $form['custom_field'] = $this->_get_custom_form_fields($id, '', true);
     // Locale (Language) Array
     $this->template->content->locale_array = Kohana::config('locale.all_languages');
     // Create Categories
     $this->template->content->categories = $this->_get_categories();
     $this->template->content->new_categories_form = $this->_new_categories_form_arr();
     // Time formatting
     $this->template->content->hour_array = $this->_hour_array();
     $this->template->content->minute_array = $this->_minute_array();
     $this->template->content->ampm_array = $this->_ampm_array();
     // Get Countries
     $countries = array();
     foreach (ORM::factory('country')->orderby('country')->find_all() as $country) {
         // Create a list of all categories
         $this_country = $country->country;
         if (strlen($this_country) > 35) {
             $this_country = substr($this_country, 0, 35) . "...";
         }
         $countries[$country->id] = $this_country;
     }
     $this->template->content->countries = $countries;
     //GET custom forms
     $forms = array();
     foreach (ORM::factory('form')->find_all() as $custom_forms) {
         $forms[$custom_forms->id] = $custom_forms->form_title;
     }
     $this->template->content->forms = $forms;
     // Retrieve thumbnail photos (if edit);
     //XXX: fix _get_thumbnails
     $this->template->content->incident = $this->_get_thumbnails($id);
     // Are we creating this report from SMS/Email/Twitter?
     // If so retrieve message
     if (isset($_GET['mid']) && !empty($_GET['mid'])) {
         $message_id = $_GET['mid'];
         $service_id = "";
         $message = ORM::factory('message', $message_id);
         if ($message->loaded == true && $message->message_type == 1) {
             $service_id = $message->reporter->service_id;
             // Has a report already been created for this Message?
             if ($message->incident_id != 0) {
                 // Redirect to report
                 url::redirect('admin/reports/edit/' . $message->incident_id);
             }
             $this->template->content->show_messages = true;
             $incident_description = $message->message;
             if (!empty($message->message_detail)) {
                 $incident_description .= "\n\n~~~~~~~~~~~~~~~~~~~~~~~~~\n\n" . $message->message_detail;
             }
             $form['incident_description'] = $incident_description;
             $form['incident_date'] = date('m/d/Y', strtotime($message->message_date));
             $form['incident_hour'] = date('h', strtotime($message->message_date));
             $form['incident_minute'] = date('i', strtotime($message->message_date));
             $form['incident_ampm'] = date('a', strtotime($message->message_date));
             $form['person_first'] = $message->reporter->reporter_first;
             $form['person_last'] = $message->reporter->reporter_last;
             // Retrieve Last 5 Messages From this account
             $this->template->content->all_messages = ORM::factory('message')->where('reporter_id', $message->reporter_id)->orderby('message_date', 'desc')->limit(5)->find_all();
         } else {
             $message_id = "";
             $this->template->content->show_messages = false;
         }
     } else {
         $this->template->content->show_messages = false;
     }
     // Are we creating this report from a Newsfeed?
     if (isset($_GET['fid']) && !empty($_GET['fid'])) {
         $feed_item_id = $_GET['fid'];
         $feed_item = ORM::factory('feed_item', $feed_item_id);
         if ($feed_item->loaded == true) {
             // Has a report already been created for this Feed item?
             if ($feed_item->incident_id != 0) {
//.........這裏部分代碼省略.........
開發者ID:Nyamai,項目名稱:Ushahidi_Web,代碼行數:101,代碼來源:reports.php

示例6: array

 /**
  * the actual reporting - ***must find a cleaner way to do this than duplicating code verbatim - modify report***
  */
 function _submit()
 {
     // setup and initialize form field names
     $form = array('incident_title' => '', 'incident_description' => '', 'incident_date' => '', 'incident_hour' => '', 'incident_minute' => '', 'incident_ampm' => '', 'latitude' => '', 'longitude' => '', 'location_name' => '', 'country_id' => '', 'incident_category' => array(), 'incident_news' => array(), 'incident_video' => array(), 'incident_photo' => array(), 'person_first' => '', 'person_last' => '', 'person_email' => '');
     //	copy the form as errors, so the errors will be stored with keys corresponding to the form field names
     $this->messages = $form;
     // 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 = Validation::factory(array_merge($_POST, $_FILES));
         //  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('incident_title', 'required', 'length[3,200]');
         $post->add_rules('incident_description', 'required');
         $post->add_rules('incident_date', 'required', 'date_mmddyyyy');
         $post->add_rules('incident_hour', 'required', 'between[1,12]');
         //$post->add_rules('incident_minute','required','between[0,59]');
         if ($this->_verifyArrayIndex($_POST, 'incident_ampm')) {
             if ($_POST['incident_ampm'] != "am" && $_POST['incident_ampm'] != "pm") {
                 $post->add_error('incident_ampm', 'values');
             }
         }
         $post->add_rules('latitude', 'required', 'between[-90,90]');
         // Validate for maximum and minimum latitude values
         $post->add_rules('longitude', 'required', 'between[-180,180]');
         // Validate for maximum and minimum longitude values
         $post->add_rules('location_name', 'required', 'length[3,200]');
         $post->add_rules('incident_category', 'required', 'length[3,100]');
         // Validate Personal Information
         if (!empty($post->person_first)) {
             $post->add_rules('person_first', 'length[3,100]');
         }
         if (!empty($post->person_last)) {
             $post->add_rules('person_last', 'length[3,100]');
         }
         if (!empty($post->person_email)) {
             $post->add_rules('person_email', 'email', 'length[3,100]');
         }
         // Test to see if things passed the rule checks
         if ($post->validate()) {
             // SAVE LOCATION (***IF IT DOES NOT EXIST***)
             $location = new Location_Model();
             $location->location_name = $post->location_name;
             $location->latitude = $post->latitude;
             $location->longitude = $post->longitude;
             $location->location_date = date("Y-m-d H:i:s", time());
             $location->save();
             // SAVE INCIDENT
             $incident = new Incident_Model();
             $incident->location_id = $location->id;
             $incident->user_id = 0;
             $incident->incident_title = $post->incident_title;
             $incident->incident_description = $post->incident_description;
             $incident_date = split("/", $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 = $incident_date . " " . $incident_time;
             $incident->incident_dateadd = date("Y-m-d H:i:s", time());
             $incident->save();
             // SAVE CATEGORIES
             //check if data is array or a serialized data.
             if (is_array($post->incident_category)) {
                 $categories = $post->incident_category;
             } else {
                 $categories = unserialize($post->incident_category);
             }
             if (!empty($categories) && is_array($categories)) {
                 foreach ($categories as $item) {
                     $incident_category = new Incident_Category_Model();
                     $incident_category->incident_id = $incident->id;
                     $incident_category->category_id = $item;
                     $incident_category->save();
                 }
             }
             // STEP 4: SAVE MEDIA
             // a. News
             if (!empty($post->incident_news) && is_array($post->incident_news)) {
                 foreach ($post->incident_news as $item) {
                     if (!empty($item)) {
                         $news = new Media_Model();
                         $news->location_id = $location->id;
                         $news->incident_id = $incident->id;
                         $news->media_type = 4;
                         // News
                         $news->media_link = $item;
                         $news->media_date = date("Y-m-d H:i:s", time());
                         $news->save();
                     }
                 }
             }
             // b. Video
             if (!empty($post->incident_video) && is_array($post->incident_video)) {
                 foreach ($post->incident_video as $item) {
                     if (!empty($item)) {
                         $video = new Media_Model();
//.........這裏部分代碼省略.........
開發者ID:rabble,項目名稱:Ushahidi_Web,代碼行數:101,代碼來源:api.php

示例7: add_hash_tweets

 /**
  * Adds hash tweets in JSON format to the database and saves the sender as a new
  * Reporter if they don't already exist
  * @param string $data - Twitter JSON results
  */
 private function add_hash_tweets($data)
 {
     $services = new Service_Model();
     $service = $services->where('service_name', 'Twitter')->find();
     if (!$service) {
         return;
     }
     // HACK: Make twitter IDs be strings so 32bit php doesn't choke on them - Nigel McNie
     $data = preg_replace('/"id":(\\d+)/', '"id":"$1"', $data);
     $tweets = json_decode($data, false);
     if (!$tweets) {
         return;
     }
     if (isset($tweets->{'error'})) {
         return;
     }
     $tweet_results = $tweets->{'results'};
     foreach ($tweet_results as $tweet) {
         // Skip over duplicate tweets
         $tweet_hash = $this->tweet_hash($tweet->text);
         if ($this->is_tweet_registered($tweet_hash)) {
             continue;
         }
         $reporter = ORM::factory('reporter')->where('service_id', $service->id)->where('service_account', $tweet->{'from_user'})->find();
         if (!$reporter->loaded) {
             // get default reporter level (Untrusted)
             $level = ORM::factory('level')->where('level_weight', 0)->find();
             $reporter->service_id = $service->id;
             $reporter->level_id = $level->id;
             $reporter->service_userid = null;
             $reporter->service_account = $tweet->{'from_user'};
             $reporter->reporter_first = null;
             $reporter->reporter_last = null;
             $reporter->reporter_email = null;
             $reporter->reporter_phone = null;
             $reporter->reporter_ip = null;
             $reporter->reporter_date = date('Y-m-d');
             $reporter->save();
         }
         if ($reporter->level_id > 1 && count(ORM::factory('message')->where('service_messageid', $tweet->{'id'})->find_all()) == 0) {
             // Save Tweet as Message
             $message = new Message_Model();
             $message->parent_id = 0;
             $message->incident_id = 0;
             $message->user_id = 0;
             $message->reporter_id = $reporter->id;
             $message->message_from = $tweet->{'from_user'};
             $message->message_to = null;
             $message->message = $tweet->{'text'};
             $message->message_type = 1;
             // Inbox
             $tweet_date = date("Y-m-d H:i:s", strtotime($tweet->{'created_at'}));
             $message->message_date = $tweet_date;
             $message->service_messageid = $tweet->{'id'};
             $message->save();
             // Mark this tweet as received for the duplicate checker
             $this->register_tweet($message->id, $tweet_hash);
             // Action::message_twitter_add - Twitter Message Received!
             Event::run('ushahidi_action.message_twitter_add', $message);
         }
         // Auto-Create A Report if Reporter is Trusted
         $reporter_weight = $reporter->level->level_weight;
         $reporter_location = $reporter->location;
         if ($reporter_weight > 0 and $reporter_location) {
             $incident_title = text::limit_chars($message->message, 50, "...", false);
             // Create Incident
             $incident = new Incident_Model();
             $incident->location_id = $reporter_location->id;
             $incident->incident_title = $incident_title;
             $incident->incident_description = $message->message;
             $incident->incident_date = $tweet_date;
             $incident->incident_dateadd = date("Y-m-d H:i:s", time());
             $incident->incident_active = 1;
             if ($reporter_weight == 2) {
                 $incident->incident_verified = 1;
             }
             $incident->save();
             // Update Message with Incident ID
             $message->incident_id = $incident->id;
             $message->save();
             // Save Incident Category
             $trusted_categories = ORM::factory("category")->where("category_trusted", 1)->find();
             if ($trusted_categories->loaded) {
                 $incident_category = new Incident_Category_Model();
                 $incident_category->incident_id = $incident->id;
                 $incident_category->category_id = $trusted_categories->id;
                 $incident_category->save();
             }
         }
     }
 }
開發者ID:redspider,項目名稱:Ushahidi_Web,代碼行數:96,代碼來源:s_twitter.php

示例8: save_report

 /**
  * 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();
 }
開發者ID:rabbit09,項目名稱:Taarifa_Web,代碼行數:82,代碼來源:reports.php

示例9: importreport

 /**
  * Function to import a report form a row in the CSV file
  * @param array $row
  * @return bool
  */
 function importreport($row)
 {
     // If the date is not in proper date format
     if (!strtotime($row['INCIDENT DATE'])) {
         $this->errors[] = 'Could not parse incident date "' . htmlspecialchars($row['INCIDENT DATE']) . '" on line ' . ($this->rownumber + 1);
     }
     // If a value of Yes or No is NOT set for approval status for the imported row
     if (isset($row["APPROVED"]) and !in_array($row["APPROVED"], array('NO', 'YES'))) {
         $this->errors[] = 'APPROVED must be either YES or NO on line ' . ($this->rownumber + 1);
     }
     // If a value of Yes or No is NOT set for verified status for the imported row
     if (isset($row["VERIFIED"]) and !in_array($row["VERIFIED"], array('NO', 'YES'))) {
         $this->errors[] = 'VERIFIED must be either YES or NO on line ' . ($this->rownumber + 1);
     }
     if (count($this->errors)) {
         return false;
     }
     // STEP 1: SAVE LOCATION
     if (isset($row['LOCATION'])) {
         $location = new Location_Model();
         $location->location_name = isset($row['LOCATION']) ? $row['LOCATION'] : '';
         $location->latitude = isset($row['LATITUDE']) ? $row['LATITUDE'] : '';
         $location->longitude = isset($row['LONGITUDE']) ? $row['LONGITUDE'] : '';
         $location->location_date = $this->time;
         $location->save();
         $this->locations_added[] = $location->id;
     }
     // STEP 2: SAVE INCIDENT
     $incident = new Incident_Model();
     $incident->location_id = isset($row['LOCATION']) ? $location->id : 0;
     $incident->user_id = 0;
     $incident->incident_title = $row['INCIDENT TITLE'];
     $incident->incident_description = isset($row['DESCRIPTION']) ? $row['DESCRIPTION'] : '';
     $incident->incident_date = date("Y-m-d H:i:s", strtotime($row['INCIDENT DATE']));
     $incident->incident_dateadd = $this->time;
     $incident->incident_active = (isset($row['APPROVED']) and $row['APPROVED'] == 'YES') ? 1 : 0;
     $incident->incident_verified = (isset($row['VERIFIED']) and $row['VERIFIED'] == 'YES') ? 1 : 0;
     $incident->save();
     $this->incidents_added[] = $incident->id;
     // STEP 3: SAVE CATEGORIES
     // If CATEGORIES column exists
     if (isset($row['CATEGORY'])) {
         $categorynames = explode(',', trim($row['CATEGORY']));
         // Add categories to incident
         foreach ($categorynames as $categoryname) {
             // There seems to be an uppercase convention for categories... Don't know why
             $categoryname = strtoupper(trim($categoryname));
             // Empty categoryname not allowed
             if ($categoryname != '') {
                 if (!isset($this->category_ids[$categoryname])) {
                     $this->notices[] = 'There exists no category "' . htmlspecialchars($categoryname) . '" in database yet.' . ' Added to database.';
                     $category = new Category_Model();
                     $category->category_title = $categoryname;
                     // We'll just use black for now. Maybe something random?
                     $category->category_color = '000000';
                     // because all current categories are of type '5'
                     $category->category_type = 5;
                     $category->category_visible = 1;
                     $category->category_description = $categoryname;
                     $category->save();
                     $this->categories_added[] = $category->id;
                     // Now category_id is known: This time, and for the rest of the import.
                     $this->category_ids[$categoryname] = $category->id;
                 }
                 $incident_category = new Incident_Category_Model();
                 $incident_category->incident_id = $incident->id;
                 $incident_category->category_id = $this->category_ids[$categoryname];
                 $incident_category->save();
                 $this->incident_categories_added[] = $incident_category->id;
             }
         }
     }
     return true;
 }
開發者ID:kjgarza,項目名稱:ushahidi,代碼行數:79,代碼來源:ReportsImporter.php

示例10: array

 /**
  * the actual reporting - ***must find a cleaner way to do this than duplicating code verbatim - modify report***
  */
 function _submit()
 {
     // setup and initialize form field names
     $form = array('incident_title' => '', 'incident_description' => '', 'incident_date' => '', 'incident_hour' => '', 'incident_minute' => '', 'incident_ampm' => '', 'latitude' => '', 'longitude' => '', 'location_name' => '', 'country_id' => '', 'incident_category' => '', 'incident_news' => array(), 'incident_video' => array(), 'incident_photo' => array(), 'person_first' => '', 'person_last' => '', 'person_email' => '');
     //copy the form as errors, so the errors will be stored with keys corresponding to the form field names
     $this->messages = $form;
     // 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 = Validation::factory(array_merge($_POST, $_FILES));
         //  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('incident_title', 'required', 'length[3,200]');
         $post->add_rules('incident_description', 'required');
         $post->add_rules('incident_date', 'required', 'date_mmddyyyy');
         $post->add_rules('incident_hour', 'required', 'between[0,23]');
         //$post->add_rules('incident_minute','required','between[0,59]');
         if ($this->_verifyArrayIndex($_POST, 'incident_ampm')) {
             if ($_POST['incident_ampm'] != "am" && $_POST['incident_ampm'] != "pm") {
                 $post->add_error('incident_ampm', 'values');
             }
         }
         $post->add_rules('latitude', 'required', 'between[-90,90]');
         // Validate for maximum and minimum latitude values
         $post->add_rules('longitude', 'required', 'between[-180,180]');
         // Validate for maximum and minimum longitude values
         $post->add_rules('location_name', 'required', 'length[3,200]');
         $post->add_rules('incident_category', 'required', 'length[1,100]');
         // Validate Personal Information
         if (!empty($post->person_first)) {
             $post->add_rules('person_first', 'length[3,100]');
         }
         if (!empty($post->person_last)) {
             $post->add_rules('person_last', 'length[3,100]');
         }
         if (!empty($post->person_email)) {
             $post->add_rules('person_email', 'email', 'length[3,100]');
         }
         // Test to see if things passed the rule checks
         if ($post->validate()) {
             // SAVE LOCATION (***IF IT DOES NOT EXIST***)
             $location = new Location_Model();
             $location->location_name = $post->location_name;
             $location->latitude = $post->latitude;
             $location->longitude = $post->longitude;
             $location->location_date = date("Y-m-d H:i:s", time());
             $location->save();
             // SAVE INCIDENT
             $incident = new Incident_Model();
             $incident->location_id = $location->id;
             $incident->user_id = 0;
             $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 = $incident_date . " " . $incident_time;
             $incident->incident_dateadd = date("Y-m-d H:i:s", time());
             $incident->save();
             // SAVE CATEGORIES
             //check if data is csv or a single value.
             $pos = strpos($post->incident_category, ",");
             if ($pos === false) {
                 //for backward compactibility. will drop support for it in the future.
                 if (@unserialize($post->incident_category)) {
                     $categories = unserialize($post->incident_category);
                 } else {
                     $categories = array($post->incident_category);
                 }
             } else {
                 $categories = explode(",", $post->incident_category);
             }
             if (!empty($categories) && is_array($categories)) {
                 foreach ($categories as $item) {
                     $incident_category = new Incident_Category_Model();
                     $incident_category->incident_id = $incident->id;
                     $incident_category->category_id = $item;
                     $incident_category->save();
                 }
             }
             // STEP 4: SAVE MEDIA
             // a. News
             if (!empty($post->incident_news) && is_array($post->incident_news)) {
                 foreach ($post->incident_news as $item) {
                     if (!empty($item)) {
                         $news = new Media_Model();
                         $news->location_id = $location->id;
                         $news->incident_id = $incident->id;
                         $news->media_type = 4;
                         // News
                         $news->media_link = $item;
                         $news->media_date = date("Y-m-d H:i:s", time());
//.........這裏部分代碼省略.........
開發者ID:nebogeo,項目名稱:borrowed-scenery,代碼行數:101,代碼來源:api.php

示例11: index

 public function index()
 {
     $apiurl = "http://tasukeai.heroku.com/all.xml";
     #$apiurl = "http://localhost/message.xml";
     $messages = simplexml_load_file($apiurl);
     foreach ($messages as $message) {
         $title = "";
         $lat = "";
         $active = 1;
         $long = "";
         $matches = array();
         if (strcmp($message->title["nil"], "true") != 0) {
             $title = (string) $message->title;
         } else {
             if (preg_match("/\\s*\\[ボランティア名稱\\]\\s*\n([^\n]+)\n/", $message->body, $matches)) {
                 $title = $matches[1];
             } else {
                 if (preg_match("/\\s*\\[主催\\]\\s*([^\n]+)\n/", $message->body, $matches)) {
                     $title = $matches[1];
                 } else {
                     if (preg_match("/\\s*\\[タイトル\\]\\s*([^\n]+)\n/", $message->body, $matches)) {
                         $title = $matches[1];
                     } else {
                         $title = "無題";
                         $active = 0;
                     }
                 }
             }
         }
         if (strcmp($message->latitude["nil"], "true") != 0 && strcmp($message->longitude["nil"], "true") != 0) {
             $lat = (double) $message->latitude;
             $long = (double) $message->longitude;
         } else {
             if (preg_match("/\\s*\\[緯度経度\\]\\s*\n([^,]+),([^\n]+)/", $message->body, $matches)) {
                 $lat = $matches[1];
                 $long = $matches[2];
             }
         }
         $link = $this->input->xss_clean($message->link);
         $where_string = "media_link = '" . $link . "'";
         $db = new Database();
         $count = $db->count_records('media', $where_string);
         if ($count > 0) {
             if (strcmp($message->{"valid-f"}, "false") == 0) {
                 $search_query = "SELECT incident_id FROM media" . " WHERE (" . $where_string . ")";
                 $query = $db->query($search_query);
                 ORM::factory('Incident')->where('id', $query[0]->incident_id)->delete_all();
                 ORM::factory('Media')->where('incident_id', $query[0]->incident_id)->delete_all();
             }
             continue;
         }
         if (strcmp($message->{"valid-f"}, "true") != 0) {
             continue;
         }
         $incident = new Incident_Model();
         // STEP 1: SAVE LOCATION
         if (isset($lat) && isset($long)) {
             $location = new Location_Model("");
             $location->location_name = (string) $message->address;
             $location->latitude = $lat;
             $location->longitude = $long;
             $location->location_date = date("Y-m-d H:i:s", time());
             $location->save();
             $incident->location_id = $location->id;
         }
         $incident->incident_title = $title;
         $incident->incident_description = (string) $message->body;
         $incident->incident_date = date("Y-m-d H:i:s", strtotime($message->{"created-at"}));
         $incident->incident_dateadd = date("Y-m-d H:i:s", time());
         $incident->incident_mode = 1;
         $incident->incident_active = $active;
         $incident->incident_verified = 1;
         $incident->incident_source = 3;
         $incident->incident_information = 1;
         //Save
         $incident->save();
         $news = new Media_Model();
         $news->incident_id = $incident->id;
         if (isset($location)) {
             $news->location_id = $location->id;
         }
         $news->media_type = 4;
         // News
         $news->media_link = $link;
         $news->media_date = date("Y-m-d H:i:s", strtotime($message->{"created-at"}));
         $news->save();
         $incident_category = new Incident_Category_Model();
         $incident_category->incident_id = $incident->id;
         if (strcmp($message->target, "2") == 0) {
             $incident_category->category_id = 9;
             //救援物資
         } else {
             $incident_category->category_id = 13;
             //求む
         }
         $incident_category->save();
     }
     $this->template->content = new View('tasukeaiimport/main');
 }
開發者ID:nastasio,項目名稱:Ushahidi_Web,代碼行數:99,代碼來源:tasukeaiimport.php

示例12: index

 /**
  * Lists the reports.
  * @param int $page
  */
 public function index($page = 1)
 {
     // If user doesn't have access, redirect to dashboard
     if (!admin::permissions($this->user, "reports_view")) {
         url::redirect(url::site() . 'admin/dashboard');
     }
     $this->template->content = new View('admin/reports');
     $this->template->content->title = Kohana::lang('ui_admin.reports');
     if (!empty($_GET['status'])) {
         $status = $_GET['status'];
         if (strtolower($status) == 'a') {
             $filter = 'incident_active = 0';
         } elseif (strtolower($status) == 'v') {
             $filter = 'incident_verified = 0';
         } else {
             $status = "0";
             $filter = '1=1';
         }
     } else {
         $status = "0";
         $filter = "1=1";
     }
     // Get Search Keywords (If Any)
     if (isset($_GET['k'])) {
         //	Brute force input sanitization
         // Phase 1 - Strip the search string of all non-word characters
         $keyword_raw = preg_replace('/[^\\w+]\\w*/', '', $_GET['k']);
         // 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);
         $filter .= " AND (" . $this->_get_searchstring($keyword_raw) . ")";
     } else {
         $keyword_raw = "";
     }
     // Check, has the form been submitted?
     $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]');
         $post->add_rules('incident_id.*', 'required', 'numeric');
         if ($post->validate()) {
             // Approve Action
             if ($post->action == 'a') {
                 foreach ($post->incident_id as $item) {
                     $update = new Incident_Model($item);
                     if ($update->loaded == TRUE) {
                         $update->incident_active = $update->incident_active == 0 ? '1' : '0';
                         // Tag this as a report that needs to be sent out as an alert
                         if ($update->incident_alert_status != '2') {
                             // 2 = report that has had an alert sent
                             $update->incident_alert_status = '1';
                         }
                         $update->save();
                         $verify = new Verify_Model();
                         $verify->incident_id = $item;
                         $verify->verified_status = '1';
                         // Record 'Verified By' Action
                         $verify->user_id = $_SESSION['auth_user']->id;
                         $verify->verified_date = date("Y-m-d H:i:s", time());
                         $verify->save();
                         // Action::report_approve - Approve a Report
                         Event::run('ushahidi_action.report_approve', $update);
                     }
                 }
                 $form_action = strtoupper(Kohana::lang('ui_admin.approved'));
             } elseif ($post->action == 'u') {
                 foreach ($post->incident_id as $item) {
                     $update = new Incident_Model($item);
                     if ($update->loaded == true) {
                         $update->incident_active = '0';
                         // If Alert hasn't been sent yet, disable it
                         if ($update->incident_alert_status == '1') {
                             $update->incident_alert_status = '0';
                         }
                         $update->save();
                         $verify = new Verify_Model();
                         $verify->incident_id = $item;
                         $verify->verified_status = '0';
                         // Record 'Verified By' Action
                         $verify->user_id = $_SESSION['auth_user']->id;
                         $verify->verified_date = date("Y-m-d H:i:s", time());
                         $verify->save();
                         // Action::report_unapprove - Unapprove a Report
                         Event::run('ushahidi_action.report_unapprove', $update);
                     }
                 }
                 $form_action = strtoupper(Kohana::lang('ui_admin.unapproved'));
             } elseif ($post->action == 'v') {
                 foreach ($post->incident_id as $item) {
//.........這裏部分代碼省略.........
開發者ID:kjgarza,項目名稱:thrasos,代碼行數:101,代碼來源:reports.php

示例13: edit

 /**
  * Edit a report
  * @param bool|int $id The id no. of the report
  * @param bool|string $saved
  */
 function edit($id = false, $saved = false)
 {
     $this->template->content = new View('admin/reports_edit');
     $this->template->content->title = 'Create A Report';
     // setup and initialize form field names
     $form = array('location_id' => '', 'locale' => '', 'incident_title' => '', 'incident_description' => '', 'incident_date' => '', 'incident_hour' => '', 'incident_minute' => '', 'incident_ampm' => '', 'latitude' => '', 'longitude' => '', 'location_name' => '', 'country_id' => '', 'incident_category' => array(), 'incident_news' => array(), 'incident_video' => array(), 'incident_photo' => array(), 'person_first' => '', 'person_last' => '', 'person_email' => '');
     //  copy the form as errors, so the errors will be stored with keys corresponding to the form field names
     $errors = $form;
     $form_error = FALSE;
     if ($saved == 'saved') {
         $form_saved = TRUE;
     } else {
         $form_saved = FALSE;
     }
     // Locale (Language) Array
     $this->template->content->locale_array = Kohana::config('locale.all_languages');
     // Create Categories
     $this->template->content->categories = $this->_get_categories();
     $this->template->content->new_categories_form = $this->_new_categories_form_arr();
     // Time formatting
     $this->template->content->hour_array = $this->_hour_array();
     $this->template->content->minute_array = $this->_minute_array();
     $this->template->content->ampm_array = $this->_ampm_array();
     // Get Countries
     $countries = array();
     foreach (ORM::factory('country')->orderby('country')->find_all() as $country) {
         // Create a list of all categories
         $this_country = $country->country;
         if (strlen($this_country) > 35) {
             $this_country = substr($this_country, 0, 35) . "...";
         }
         $countries[$country->id] = $this_country;
     }
     $this->template->content->countries = $countries;
     // Retrieve thumbnail photos (if edit);
     //XXX: fix _get_thumbnails
     $this->template->content->incident = $this->_get_thumbnails($id);
     // Are we creating this report from an SMS or Twitter Message?
     // If so retrieve message
     if (isset($_GET['mid']) && !empty($_GET['mid']) || isset($_GET['tid']) && !empty($_GET['tid'])) {
         // Check what kind of message this is
         if (isset($_GET['mid'])) {
             //Then it's an SMS message
             $messageType = 'sms';
             $mobile_id = $_GET['mid'];
             $dbtable = 'message';
             $col_prefix = 'message';
             $incident_title = 'Mobile Report';
         } elseif (isset($_GET['tid'])) {
             //Then it's a Twitter message
             $messageType = 'twitter';
             $mobile_id = $_GET['tid'];
             $dbtable = 'twitter';
             $col_prefix = 'tweet';
             $incident_title = 'Twitter Report';
         }
         $message = ORM::factory($dbtable, $mobile_id)->where($col_prefix . '_type', '1');
         if ($message->loaded == true) {
             // Has a report already been created for this SMS?
             if ($message->incident_id != 0) {
                 // Redirect to report
                 url::redirect('admin/reports/edit/' . $message->incident_id);
             }
             if ($messageType == 'sms') {
                 $this->template->content->message = $message->message;
                 $this->template->content->message_from = $message->message_from;
                 $this->template->content->show_messages = true;
                 $form['incident_title'] = $incident_title;
                 $form['incident_description'] = $message->message;
                 $from_search = $this->template->content->message_from;
             } elseif ($messageType == 'twitter') {
                 $this->template->content->message = $message->tweet;
                 $this->template->content->message_from = $message->tweet_from;
                 $this->template->content->show_messages = true;
                 $form['incident_title'] = $incident_title;
                 $form['incident_description'] = $message->tweet;
                 $from_search = $this->template->content->tweet_from;
             }
             // Retrieve Last 5 Messages From this Number
             $this->template->content->allmessages = ORM::factory($dbtable)->where($col_prefix . '_from', $from_search)->where($col_prefix . '_type', '1')->orderby($col_prefix . '_date', 'desc')->limit(5)->find_all();
         } else {
             $mobile_id = "";
             $this->template->content->show_messages = false;
         }
     } else {
         $this->template->content->show_messages = 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 = Validation::factory(array_merge($_POST, $_FILES));
         //  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('locale', 'required', 'alpha_dash', 'length[5]');
//.........這裏部分代碼省略.........
開發者ID:emoksha,項目名稱:freefairelections,代碼行數:101,代碼來源:reports.php

示例14: import_reports

 /**
  * Import Reports via XML
  * @param DOMNodeList Object $report
  * @return bool
  */
 public function import_reports($reports)
 {
     /* Import individual reports */
     foreach ($reports->getElementsByTagName('report') as $report) {
         $this->totalreports++;
         // Get Report id
         $report_id = $report->getAttribute('id');
         // Check if this incident already exists in the db
         if (isset($report_id) and isset($this->incident_ids[$report_id])) {
             $this->notices[] = Kohana::lang('import.incident_exists') . $report_id;
         } else {
             /* Step 1: Location information */
             $locations = $report->getElementsByTagName('location');
             // If location information has been provided
             if ($locations->length > 0) {
                 $report_location = $locations->item(0);
                 // Location Name
                 $location_name = xml::get_node_text($report_location, 'name');
                 // Longitude
                 $longitude = xml::get_node_text($report_location, 'longitude');
                 // Latitude
                 $latitude = xml::get_node_text($report_location, 'latitude');
                 if ($location_name) {
                     // For geocoding purposes
                     $location_geocoded = map::geocode($location_name);
                     // Save the location
                     $new_location = new Location_Model();
                     $new_location->location_name = $location_name ? $location_name : NULL;
                     $new_location->location_date = $this->time;
                     // If longitude/latitude values are present
                     if ($latitude and $longitude) {
                         $new_location->latitude = $latitude ? $latitude : 0;
                         $new_location->longitude = $longitude ? $longitude : 0;
                     } else {
                         // Get geocoded lat/lon values
                         $new_location->latitude = $location_geocoded ? $location_geocoded['latitude'] : $latitude;
                         $new_location->longitude = $location_geocoded ? $location_geocoded['longitude'] : $longitude;
                     }
                     $new_location->country_id = $location_geocoded ? $location_geocoded['country_id'] : 0;
                     $new_location->save();
                     // Add this location to array of imported locations
                     $this->locations_added[] = $new_location->id;
                 }
             }
             /* Step 2: Save Report */
             // Report Title
             $report_title = xml::get_node_text($report, 'title');
             // Report Date
             $report_date = xml::get_node_text($report, 'date');
             // Missing report title or report date?
             if (!$report_title or !$report_date) {
                 $this->errors[] = Kohana::lang('import.xml.incident_title_date') . $this->totalreports;
             }
             // If report date is not in the required format
             if (!strtotime($report_date)) {
                 $this->errors[] = Kohana::lang('import.incident_date') . $this->totalreports . ': ' . html::escape($report_date);
             } else {
                 // Approval status?
                 $approved = $report->getAttribute('approved');
                 $report_approved = (isset($approved) and in_array($approved, $this->allowable)) ? $approved : 0;
                 // Verified Status?
                 $verified = $report->getAttribute('verified');
                 $report_verified = (isset($verified) and in_array($verified, $this->allowable)) ? $verified : 0;
                 // Report mode?
                 $allowed_modes = array(1, 2, 3, 4);
                 $mode = $report->getAttribute('mode');
                 $report_mode = (isset($mode) and in_array($mode, $allowed_modes)) ? $mode : 1;
                 // Report Form
                 $report_form = xml::get_node_text($report, 'form_name', FALSE);
                 if ($report_form) {
                     if (!isset($this->existing_forms[utf8::strtoupper($report_form)])) {
                         $this->notices[] = Kohana::lang('import.xml.no_form_exists') . $this->totalreports . ': "' . $report_form . '"';
                     }
                     $form_id = isset($this->existing_forms[utf8::strtoupper($report_form)]) ? $this->existing_forms[utf8::strtoupper($report_form)] : 1;
                 }
                 // Report Date added
                 $dateadd = xml::get_node_text($report, 'dateadd');
                 // Report Description
                 $report_description = xml::get_node_text($report, 'description');
                 $new_report = new Incident_Model();
                 $new_report->location_id = isset($new_location) ? $new_location->id : 0;
                 $new_report->user_id = 0;
                 $new_report->incident_title = $report_title;
                 $new_report->incident_description = $report_description ? $report_description : '';
                 $new_report->incident_date = date("Y-m-d H:i:s", strtotime($report_date));
                 $new_report->incident_dateadd = ($dateadd and strtotime($dateadd)) ? $dateadd : $this->time;
                 $new_report->incident_active = $report_approved;
                 $new_report->incident_verified = $report_verified;
                 $new_report->incident_mode = $report_mode;
                 $new_report->form_id = isset($form_id) ? $form_id : 1;
                 $new_report->save();
                 // Increment imported rows counter
                 $this->importedreports++;
                 // Add this report to array of reports added during import
                 $this->incidents_added[] = $new_report->id;
//.........這裏部分代碼省略.........
開發者ID:Dirichi,項目名稱:Ushahidi_Web,代碼行數:101,代碼來源:XMLImporter.php

示例15: submit

 /**
  * Submits a new report.
  */
 public function submit($id = false, $saved = false)
 {
     // First, are we allowed to submit new reports?
     if (!Kohana::config('settings.allow_reports')) {
         url::redirect(url::site() . 'main');
     }
     $this->template->header->this_page = 'reports_submit';
     $this->template->content = new View('reports_submit');
     // setup and initialize form field names
     $form = array('incident_title' => '', 'incident_description' => '', 'incident_date' => '', 'incident_hour' => '', 'incident_minute' => '', 'incident_ampm' => '', 'latitude' => '', 'longitude' => '', 'location_name' => '', 'country_id' => '', 'incident_category' => array(), 'incident_news' => array(), 'incident_video' => array(), 'incident_photo' => array(), 'person_first' => '', 'person_last' => '', 'person_email' => '', 'form_id' => '', 'custom_field' => array());
     //	copy the form as errors, so the errors will be stored with keys corresponding to the form field names
     $errors = $form;
     $form_error = FALSE;
     if ($saved == 'saved') {
         $form_saved = TRUE;
     } else {
         $form_saved = FALSE;
     }
     // Initialize Default Values
     $form['incident_date'] = date("m/d/Y", time());
     $form['incident_hour'] = "12";
     $form['incident_minute'] = "00";
     $form['incident_ampm'] = "pm";
     // initialize custom field array
     $form['custom_field'] = $this->_get_custom_form_fields($id, '', true);
     //GET custom forms
     $forms = array();
     foreach (ORM::factory('form')->find_all() as $custom_forms) {
         $forms[$custom_forms->id] = $custom_forms->form_title;
     }
     $this->template->content->forms = $forms;
     // 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 = Validation::factory(array_merge($_POST, $_FILES));
         //	 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('incident_title', 'required', 'length[3,200]');
         $post->add_rules('incident_description', 'required');
         $post->add_rules('incident_date', 'required', 'date_mmddyyyy');
         $post->add_rules('incident_hour', 'required', 'between[1,12]');
         $post->add_rules('incident_minute', 'required', 'between[0,59]');
         if ($_POST['incident_ampm'] != "am" and $_POST['incident_ampm'] != "pm") {
             $post->add_error('incident_ampm', 'values');
         }
         // Validate for maximum and minimum latitude values
         $post->add_rules('latitude', 'required', 'between[-90,90]');
         $post->add_rules('longitude', 'required', 'between[-180,180]');
         $post->add_rules('location_name', 'required', 'length[3,200]');
         //XXX: Hack to validate for no checkboxes checked
         if (!isset($_POST['incident_category'])) {
             $post->incident_category = "";
             $post->add_error('incident_category', 'required');
         } else {
             $post->add_rules('incident_category.*', 'required', 'numeric');
         }
         // Validate only the fields that are filled in
         if (!empty($_POST['incident_news'])) {
             foreach ($_POST['incident_news'] as $key => $url) {
                 if (!empty($url) and !(bool) filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED)) {
                     $post->add_error('incident_news', 'url');
                 }
             }
         }
         // Validate only the fields that are filled in
         if (!empty($_POST['incident_video'])) {
             foreach ($_POST['incident_video'] as $key => $url) {
                 if (!empty($url) and !(bool) filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED)) {
                     $post->add_error('incident_video', 'url');
                 }
             }
         }
         // Validate photo uploads
         $post->add_rules('incident_photo', 'upload::valid', 'upload::type[gif,jpg,png]', 'upload::size[2M]');
         // Validate Personal Information
         if (!empty($_POST['person_first'])) {
             $post->add_rules('person_first', 'length[3,100]');
         }
         if (!empty($_POST['person_last'])) {
             $post->add_rules('person_last', 'length[3,100]');
         }
         if (!empty($_POST['person_email'])) {
             $post->add_rules('person_email', 'email', 'length[3,100]');
         }
         // Test to see if things passed the rule checks
         if ($post->validate()) {
             // STEP 1: SAVE LOCATION
             $location = new Location_Model();
             $location->location_name = $post->location_name;
             $location->latitude = $post->latitude;
             $location->longitude = $post->longitude;
             $location->location_date = date("Y-m-d H:i:s", time());
             $location->save();
             // STEP 2: SAVE INCIDENT
             $incident = new Incident_Model();
             $incident->location_id = $location->id;
//.........這裏部分代碼省略.........
開發者ID:nebogeo,項目名稱:borrowed-scenery,代碼行數:101,代碼來源:reports.php


注:本文中的Incident_Model::save方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。