当前位置: 首页>>代码示例>>PHP>>正文


PHP Location_Model::save方法代码示例

本文整理汇总了PHP中Location_Model::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Location_Model::save方法的具体用法?PHP Location_Model::save怎么用?PHP Location_Model::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Location_Model的用法示例。


在下文中一共展示了Location_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: importreport

 function importreport($row)
 {
     if (!strtotime($row['PROFILE DATE'])) {
         $this->errors[] = 'Could not parse profile date "' . htmlspecialchars($row['PROFILE DATE']) . '" on line ' . ($this->rownumber + 1);
     }
     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 (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['PROFILE TITLE'];
     $incident->incident_description = isset($row['DESCRIPTION']) ? $row['DESCRIPTION'] : '';
     $incident->incident_date = date("Y-m-d H:i:s", strtotime($row['PROFILE 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 (isset($row['CATEGORY'])) {
         $categorynames = explode(',', trim($row['CATEGORY']));
         foreach ($categorynames as $categoryname) {
             $categoryname = strtoupper(trim($categoryname));
             // There seems to be an uppercase convention for categories... Don't know why.
             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;
                     $category->category_color = '000000';
                     // We'll just use black for now. Maybe something random?
                     $category->category_type = 5;
                     // because all current categories are of type '5'
                     $category->category_visible = 1;
                     $category->category_description = $categoryname;
                     $category->save();
                     $this->categories_added[] = $category->id;
                     $this->category_ids[$categoryname] = $category->id;
                     // Now category_id is known: This time, and for the rest of the import.
                 }
                 $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;
             }
             // empty categoryname not allowed
         }
         // add categories to incident
     }
     // if CATEGORIES column exists
     //SAVE Custom fields
     $custom_form_fields = $this->_get_custom_form_fields($incident->id, 1, false);
     foreach ($custom_form_fields as $custom_form_field) {
         $field_name = $custom_form_field['field_name'];
         $field_name = strtoupper($field_name);
         if (isset($row[$field_name])) {
             $form_response = new Form_Response_Model();
             $form_response->form_field_id = $custom_form_field['field_id'];
             $form_response->incident_id = $incident->id;
             $form_response->form_response = $row[$field_name];
             //  $form_response->save();
         }
     }
     return true;
 }
开发者ID:ushahidi,项目名称:Ushahidi_Kanco,代码行数:84,代码来源:ReportsImporter.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: index

 public function index($service_id = 1)
 {
     $this->template->content = new View('admin/reporters');
     $this->template->content->title = Kohana::lang('ui_admin.reporters');
     $filter = "1=1";
     $search_type = "";
     $keyword = "";
     // Get Search Type (If Any)
     if ($service_id) {
         $search_type = $service_id;
         $filter .= " AND (service_id='" . $service_id . "')";
     } else {
         $search_type = "0";
     }
     // Get Search Keywords (If Any)
     if (isset($_GET['k']) and !empty($_GET['k'])) {
         $keyword = $_GET['k'];
         $filter .= " AND (service_account LIKE'%" . $_GET['k'] . "%')";
     }
     // setup and initialize form field names
     $form = array('reporter_id' => '', 'level_id' => '', 'service_name' => '', 'service_account' => '', 'location_id' => '', 'location_name' => '', 'latitude' => '', 'longitude' => '');
     //  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 = "";
     // 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($_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('reporter_id.*', 'required', 'numeric');
         if ($post->action == 'l') {
             $post->add_rules('level_id', 'required', 'numeric');
         } elseif ($post->action == 'a') {
             $post->add_rules('level_id', 'required', 'numeric');
             // If any location data is provided, require all location parameters
             if ($post->latitude or $post->longitude or $post->location_name) {
                 $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]');
             }
         }
         // Test to see if things passed the rule checks
         if ($post->validate()) {
             if ($post->action == 'd') {
                 foreach ($post->reporter_id as $item) {
                     // Delete Reporters Messages
                     ORM::factory('message')->where('reporter_id', $item)->delete_all();
                     // Delete Reporter
                     $reporter = ORM::factory('reporter')->find($item);
                     $reporter->delete($item);
                 }
                 $form_saved = TRUE;
                 $form_action = strtoupper(Kohana::lang('ui_admin.deleted'));
             } elseif ($post->action == 'l') {
                 foreach ($post->reporter_id as $item) {
                     // Update Reporter Level
                     $reporter = ORM::factory('reporter')->find($item);
                     if ($reporter->loaded) {
                         $reporter->level_id = $post->level_id;
                         $reporter->save();
                     }
                 }
                 $form_saved = TRUE;
                 $form_action = strtoupper(Kohana::lang('ui_admin.modified'));
             } else {
                 if ($post->action == 'a') {
                     foreach ($post->reporter_id as $item) {
                         $reporter = ORM::factory('reporter')->find($item);
                         // SAVE Reporter only if loaded
                         if ($reporter->loaded) {
                             $reporter->level_id = $post->level_id;
                             // SAVE Location if available
                             if ($post->latitude and $post->longitude) {
                                 $location = new Location_Model($post->location_id);
                                 $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();
                                 $reporter->location_id = $location->id;
                             }
                             $reporter->save();
                             $form_saved = TRUE;
                             $form_action = strtoupper(Kohana::lang('ui_admin.modified'));
                         }
                     }
                 }
             }
         } else {
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // populate the error fields, if any
             $errors = arr::overwrite($errors, $post->errors('reporters'));
//.........这里部分代码省略.........
开发者ID:mewsop,项目名称:Ushahidi_Web,代码行数:101,代码来源:reporters.php

示例5: importreport

 function importreport($row, $group)
 {
     if (!strtotime($row['INCIDENT DATE'])) {
         $this->errors[] = 'Could not parse incident date "' . htmlspecialchars($row['INCIDENT DATE']) . '" on line ' . ($this->rownumber + 1);
     }
     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 (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 2.5: SAVE THE GROUP ASSOCIATION
     $group_incident = ORM::factory("simplegroups_groups_incident");
     $group_incident->incident_id = $incident->id;
     $group_incident->simplegroups_groups_id = $group->id;
     $group_incident->save();
     // STEP 3: SAVE CATEGORIES
     if (isset($row['CATEGORY'])) {
         $categorynames = explode(',', trim($row['CATEGORY']));
         foreach ($categorynames as $categoryname) {
             $categoryname = strtoupper(trim($categoryname));
             // There seems to be an uppercase convention for categories... Don't know why.
             if ($categoryname != '') {
                 if (!isset($this->category_ids[$categoryname])) {
                     $this->notices[] = 'There exists no category "' . htmlspecialchars($categoryname) . '" in database yet. This category was skipped.';
                     continue;
                     /*
                     $this->notices[] = 'There exists no category "'.htmlspecialchars($categoryname).'" in database yet. Added to database.';
                     $category = new Category_Model;
                     $category->category_title = $categoryname;
                     $category->category_color = '000000'; // We'll just use black for now. Maybe something random?
                     $category->category_type = 5; // because all current categories are of type '5'
                     $category->category_visible = 1;
                     $category->category_description = $categoryname;
                     $category->save();
                     $this->categories_added[] = $category->id;
                     $this->category_ids[$categoryname] = $category->id; // Now category_id is known: This time, and for the rest of the import.
                     */
                 }
                 $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;
             }
             // empty categoryname not allowed
         }
         // add categories to incident
     }
     // if CATEGORIES column exists
     // STEP 4: SAVE GROUP CATEGORIES
     if (isset($row['GROUP CATEGORY'])) {
         $categorynames = explode(',', trim($row['GROUP CATEGORY']));
         foreach ($categorynames as $categoryname) {
             $categoryname = strtoupper(trim($categoryname));
             // There seems to be an uppercase convention for categories... Don't know why.
             if ($categoryname != '') {
                 if (!isset($this->group_category_ids[$categoryname])) {
                     $this->notices[] = 'There exists no category "' . htmlspecialchars($categoryname) . '" in the group categories yet. Added to database.';
                     $category = ORM::factory("simplegroups_category");
                     $category->category_title = $categoryname;
                     $category->category_color = '000000';
                     // We'll just use black for now. Maybe something random?
                     $category->category_type = 5;
                     // because all current categories are of type '5'
                     $category->category_visible = 1;
                     $category->category_description = $categoryname;
                     $category->simplegroups_groups_id = $group->id;
                     $category->applies_to_report = 1;
                     $category->save();
                     $this->categories_added[] = $category->id;
                     $this->group_category_ids[$categoryname] = $category->id;
                     // Now category_id is known: This time, and for the rest of the import.
                 }
                 $incident_category = ORM::factory("simplegroups_incident_category");
//.........这里部分代码省略.........
开发者ID:rabbit09,项目名称:Taarifa_Web,代码行数:101,代码来源:SimpleGroupsReportsImporter.php

示例6: index

 /**
  * parse feed and send feed items to database
  */
 public function index()
 {
     // Max number of feeds to keep
     $max_feeds = 100;
     // Today's Date
     $today = strtotime('now');
     // Get All Feeds From DB
     $feeds = ORM::factory('feed')->find_all();
     foreach ($feeds as $feed) {
         $last_update = $feed->feed_update;
         // Parse Feed URL using Feed Helper
         $feed_data = feed::simplepie($feed->feed_url);
         foreach ($feed_data->get_items(0, 50) as $feed_data_item) {
             $title = $feed_data_item->get_title();
             $link = $feed_data_item->get_link();
             $description = $feed_data_item->get_description();
             $date = $feed_data_item->get_date();
             $latitude = $feed_data_item->get_latitude();
             $longitude = $feed_data_item->get_longitude();
             $categories = $feed_data_item->get_categories();
             // HT: new code
             $category_ids = new stdClass();
             // HT: new code
             // Make Sure Title is Set (Atleast)
             if (isset($title) && !empty($title)) {
                 // We need to check for duplicates!!!
                 // Maybe combination of Title + Date? (Kinda Heavy on the Server :-( )
                 $dupe_count = ORM::factory('feed_item')->where('item_title', $title)->where('item_date', date("Y-m-d H:i:s", strtotime($date)))->count_all();
                 if ($dupe_count == 0) {
                     // Does this feed have a location??
                     $location_id = 0;
                     // STEP 1: SAVE LOCATION
                     if ($latitude and $longitude) {
                         $location = new Location_Model();
                         $location->location_name = "Unknown";
                         $location->latitude = $latitude;
                         $location->longitude = $longitude;
                         $location->location_date = date("Y-m-d H:i:s", time());
                         $location->save();
                         $location_id = $location->id;
                     }
                     $newitem = new Feed_Item_Model();
                     $newitem->feed_id = $feed->id;
                     $newitem->location_id = $location_id;
                     $newitem->item_title = $title;
                     if (isset($description) and !empty($description)) {
                         $newitem->item_description = $description;
                     }
                     if (isset($link) and !empty($link)) {
                         $newitem->item_link = $link;
                     }
                     if (isset($date) and !empty($date)) {
                         $newitem->item_date = date("Y-m-d H:i:s", strtotime($date));
                     } else {
                         $newitem->item_date = date("Y-m-d H:i:s", time());
                     }
                     // HT: new code
                     if (!empty($categories)) {
                         foreach ($categories as $category) {
                             $categoryData = ORM::factory('category')->where('category_title', $category->term)->find();
                             if ($categoryData->loaded == TRUE) {
                                 $category_ids->feed_item_category[$categoryData->id] = $categoryData->id;
                             } elseif (Kohana::config('settings.allow_feed_category')) {
                                 $newcategory = new Category_Model();
                                 $newcategory->category_title = $category->term;
                                 $newcategory->parent_id = 0;
                                 $newcategory->category_description = $category->term;
                                 $newcategory->category_color = '000000';
                                 $newcategory->category_visible = 0;
                                 $newcategory->save();
                                 $category_ids->feed_item_category[$newcategory->id] = $newcategory->id;
                             }
                         }
                     }
                     // HT: End of new code
                     $newitem->save();
                     // HT: New code
                     if (!empty($category_ids->feed_item_category)) {
                         feed::save_category($category_ids, $newitem);
                     }
                     // HT: End of New code
                     // Action::feed_item_add - Feed Item Received!
                     Event::run('ushahidi_action.feed_item_add', $newitem);
                 }
             }
         }
         // Get Feed Item Count
         $feed_count = ORM::factory('feed_item')->where('feed_id', $feed->id)->count_all();
         if ($feed_count > $max_feeds) {
             // Excess Feeds
             $feed_excess = $feed_count - $max_feeds;
         }
         // Set feed update date
         $feed->feed_update = strtotime('now');
         $feed->save();
     }
 }
开发者ID:Dirichi,项目名称:Ushahidi_Web,代码行数:100,代码来源:s_feeds.php

示例7: submit

	public function submit($saved = false)
	{
		// Cacheable Controller
		$this->is_cachable = FALSE;

		$this->template->header->show_map = TRUE;
		$this->template->content  = new View('keitai/reports_submit');

		// First, are we allowed to submit new reports?
		if ( ! Kohana::config('settings.allow_reports'))
		{
			url::redirect(url::site().'main');
		}

		// setup and initialize form field names
		$form = array
		(
			'incident_title' => '',
			'incident_description' => '',
			'incident_month' => '',
			'incident_day' => '',
			'incident_year' => '',
			'incident_hour' => '',
			'incident_minute' => '',
			'incident_ampm' => '',
			'latitude' => '',
			'longitude' => '',
			'location_name' => '',
			'country_id' => '',
			'incident_category' => 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_month'] = date('m');
		$form['incident_day'] = date('d');
		$form['incident_year'] = date('Y');
		$form['incident_hour'] = date('h');
		$form['incident_minute'] = date('i');
		$form['incident_ampm'] = date('a');
		// 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_month', 'required', 'numeric', 'between[1,12]');
			$post->add_rules('incident_day', 'required', 'numeric', 'between[1,31]');
			$post->add_rules('incident_year', 'required', 'numeric', 'length[4,4]');

			if ( ! checkdate($_POST['incident_month'], $_POST['incident_day'], $_POST['incident_year']) )
			{
				$post->add_error('incident_date','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', 'between[-90,90]');
			$post->add_rules('longitude', '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 = "";
//.........这里部分代码省略.........
开发者ID:rindou240,项目名称:Ushahidi_Web,代码行数:101,代码来源:reports.php

示例8: register_checkin

 /**
  * This function performs the actual checkin and will register a new user
  *   if the user doesn't exist. Also, if the name and email is passed with
  *   the checkin, the user will be updated.
  *
  *   mobileid, lat and lon are the only required fields.
  *
  * Handles the API task parameters
  */
 public function register_checkin($mobileid, $lat, $lon, $message = FALSE, $firstname = FALSE, $lastname = FALSE, $email = FALSE, $color = FALSE)
 {
     // Check if this device has been registered yet
     if (!User_Devices_Model::device_registered($mobileid)) {
         // Device has not been registered yet. Register it!
         // TODO: Formalize the user creation process. For now we are creating
         //       a new user for every new device but eventually, we need
         //       to be able to have multiple devices for each user
         if ($firstname and $lastname) {
             $user_name = $firstname . ' ' . $lastname;
         } else {
             $user_name = '';
         }
         if ($email) {
             $user_email = $email;
         } else {
             $user_email = $this->getRandomString();
         }
         if ($color) {
             $user_color = $color;
         } else {
             $user_color = $this->random_color();
         }
         // Check if email exists
         $query = 'SELECT id FROM ' . $this->table_prefix . 'users WHERE `email` = \'' . $user_email . '\' LIMIT 1;';
         $usercheck = $this->db->query($query);
         if (isset($usercheck[0]->id)) {
             $user_id = $usercheck[0]->id;
         } else {
             // Create a new user
             $user = ORM::factory('user');
             $user->name = $user_name;
             $user->email = $user_email;
             $user->username = $this->getRandomString();
             $user->password = 'checkinuserpw';
             $user->color = $user_color;
             $user->add(ORM::factory('role', 'login'));
             $user_id = $user->save();
         }
         //   TODO: When we have user registration down, we need to pass a user id here
         //         so we can assign it to a specific user
         User_Devices_Model::register_device($mobileid, $user_id);
     }
     // Now we have a fully registered device so lets update our user if we need to
     if ($firstname and $lastname and $email) {
         $user_id = User_Devices_Model::device_owner($mobileid);
         $user_name = $firstname . ' ' . $lastname;
         $user_email = $email;
         $user = ORM::factory('user', $user_id);
         $user->name = $user_name;
         $user->email = $user_email;
         if ($color) {
             $user->color = $color;
         }
         $user_id = $user->save();
         $user_id = $user_id->id;
     }
     // Get our user id if it hasn't already been set by one of the processes above
     if (!isset($user_id)) {
         $user_id = User_Devices_Model::device_owner($mobileid);
     }
     // Whew, now that all that is out of the way, do the flippin checkin!
     // FIRST, save the location
     $location = new Location_Model();
     $location->location_name = $lat . ',' . $lon;
     $location->latitude = $lat;
     $location->longitude = $lon;
     $location->location_date = date("Y-m-d H:i:s", time());
     $location_id = $location->save();
     // SECOND, save the checkin
     if (!$message) {
         $message = '';
     }
     $checkin = ORM::factory('checkin');
     $checkin->user_id = $user_id;
     $checkin->location_id = $location_id;
     $checkin->checkin_description = $message;
     $checkin->checkin_date = date("Y-m-d H:i:s", time());
     $checkin_id = $checkin->save();
     // THIRD, save the photo, if there is a photo
     if (isset($_FILES['photo'])) {
         $filename = upload::save('photo');
         $new_filename = 'ci_' . $user_id . '_' . time() . '_' . $this->getRandomString(4);
         $file_type = strrev(substr(strrev($filename), 0, 4));
         // IMAGE SIZES: 800X600, 400X300, 89X59
         // Large size
         Image::factory($filename)->resize(800, 600, Image::AUTO)->save(Kohana::config('upload.directory', TRUE) . $new_filename . $file_type);
         // Medium size
         Image::factory($filename)->resize(400, 300, Image::HEIGHT)->save(Kohana::config('upload.directory', TRUE) . $new_filename . "_m" . $file_type);
         // Thumbnail
         Image::factory($filename)->resize(89, 59, Image::HEIGHT)->save(Kohana::config('upload.directory', TRUE) . $new_filename . "_t" . $file_type);
//.........这里部分代码省略.........
开发者ID:huslage,项目名称:Ushahidi_Web,代码行数:101,代码来源:MY_Checkin_Api_Object.php

示例9: 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

示例10: 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

示例11: 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

示例12: 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

示例13: isset

 /**
  * Function to import a report form a row in the CSV file
  * @param array $row
  * @return bool
  */
 function import_report($row)
 {
     // If the date is not in proper date format
     if (!strtotime($row['INCIDENT DATE'])) {
         $this->errors[] = Kohana::lang('import.incident_date') . ($this->rownumber + 1) . ': ' . $row['INCIDENT DATE'];
     }
     // If a value of Yes or No is NOT set for approval status for the imported row
     if (isset($row["APPROVED"]) and !in_array(utf8::strtoupper($row["APPROVED"]), array('NO', 'YES'))) {
         $this->errors[] = Kohana::lang('import.csv.approved') . ($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(utf8::strtoupper($row["VERIFIED"]), array('NO', 'YES'))) {
         $this->errors[] = Kohana::lang('import.csv.verified') . ($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'] : '';
         // For Geocoding purposes
         $location_geocoded = map::geocode($location->location_name);
         // If we have LATITUDE and LONGITUDE use those
         if (isset($row['LATITUDE']) and isset($row['LONGITUDE'])) {
             $location->latitude = isset($row['LATITUDE']) ? $row['LATITUDE'] : 0;
             $location->longitude = isset($row['LONGITUDE']) ? $row['LONGITUDE'] : 0;
         } else {
             $location->latitude = $location_geocoded ? $location_geocoded['latitude'] : 0;
             $location->longitude = $location_geocoded ? $location_geocoded['longitude'] : 0;
         }
         $location->country_id = $location_geocoded ? $location_geocoded['country_id'] : 0;
         $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->form_id = (isset($row['FORM #']) and Form_Model::is_valid_form($row['FORM #'])) ? $row['FORM #'] : 1;
     $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 utf8::strtoupper($row['APPROVED']) == 'YES') ? 1 : 0;
     $incident->incident_verified = (isset($row['VERIFIED']) and utf8::strtoupper($row['VERIFIED']) == 'YES') ? 1 : 0;
     $incident->save();
     $this->incidents_added[] = $incident->id;
     // STEP 3: Save Personal Information
     if (isset($row['FIRST NAME']) or isset($row['LAST NAME']) or isset($row['EMAIL'])) {
         $person = new Incident_Person_Model();
         $person->incident_id = $incident->id;
         $person->person_first = isset($row['FIRST NAME']) ? $row['FIRST NAME'] : '';
         $person->person_last = isset($row['LAST NAME']) ? $row['LAST NAME'] : '';
         $person->person_email = (isset($row['EMAIL']) and valid::email($row['EMAIL'])) ? $row['EMAIL'] : '';
         $person->person_date = date("Y-m-d H:i:s", time());
         // Make sure that you're not importing an empty record i.e at least one field has been recorded
         // If all fields are empty i.e you have an empty record, don't save
         if (!empty($person->person_first) or !empty($person->person_last) or !empty($person->person_email)) {
             $person->save();
             // Add to array of incident persons added
             $this->incident_persons_added[] = $person->id;
         }
     }
     // STEP 4: SAVE CATEGORIES
     // If CATEGORY column exists
     if (isset($row['CATEGORY'])) {
         $categorynames = explode(',', trim($row['CATEGORY']));
         // Trim whitespace from array values
         $categorynames = array_map('trim', $categorynames);
         // Get rid of duplicate category entries in a row
         $categories = array_unique(array_map('strtolower', $categorynames));
         // Add categories to incident
         foreach ($categories as $categoryname) {
             // Convert the first string character of the category name to Uppercase
             $categoryname = utf8::ucfirst($categoryname);
             // For purposes of adding an entry into the incident_category table
             $incident_category = new Incident_Category_Model();
             $incident_category->incident_id = $incident->id;
             // If category name exists, add entry in incident_category table
             if ($categoryname != '') {
                 // Check if the category exists (made sure to convert to uppercase for comparison)
                 if (!isset($this->existing_categories[utf8::strtoupper($categoryname)])) {
                     $this->notices[] = Kohana::lang('import.new_category') . $categoryname;
                     $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_visible = 1;
                     $category->category_description = $categoryname;
                     $category->category_position = count($this->existing_categories);
                     $category->save();
                     $this->categories_added[] = $category->id;
//.........这里部分代码省略.........
开发者ID:rjmackay,项目名称:Ushahidi_Web,代码行数:101,代码来源:CSVImporter.php

示例14: save_location

 /**
  * Function to save report location
  * 
  * @param Validation $post
  * @param Location_Model $location Instance of the location model
  */
 public static function save_location($post, $location)
 {
     $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();
 }
开发者ID:huslage,项目名称:Ushahidi_Web,代码行数:14,代码来源:reports.php

示例15: index

 public function index()
 {
     $birth = 1263427200;
     // 2010-01-14 - We'll move in 3 hour increments from here
     $cache = Cache::instance();
     $last_message_date = $cache->get('georss_parser');
     if ($last_message_date == NULL) {
         $last_message_date = $birth;
         $cache->set('georss_parser', $birth, array('georss'), 0);
     }
     //echo $last_message_date;
     $settings = ORM::factory('settings', 1);
     $sms_rss = $settings->georss_feed . "&only_phone=1&limit=50," . $this->items;
     //."&uptots=".$last_message_date;
     $curl_handle = curl_init();
     curl_setopt($curl_handle, CURLOPT_URL, $sms_rss);
     curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
     // Timeout
     curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
     // Set curl to store data in variable instead of print
     $buffer = curl_exec($curl_handle);
     curl_close($curl_handle);
     // Parse Feed URL using SimplePIE
     $feed_data = $this->_simplepie($buffer);
     if (count($feed_data->get_items(0, $this->items)) == 0) {
         $cache->set('georss_parser', $last_message_date + 3600, array('georss'), 0);
         //exit;
     }
     // Cycle through feed data
     $i = 0;
     foreach ($feed_data->get_items(0, $this->items) as $feed_data_item) {
         $service_messageid = $feed_data_item->get_item_tags('http://www.w3.org/2005/Atom', 'id');
         $service_messageid = str_replace("http://4636.ushahidi.com/person.php?id=", "", trim($service_messageid[0]['data']));
         $date = $feed_data_item->get_item_tags('http://www.w3.org/2005/Atom', 'updated');
         $date = date("Y-m-d H:i:s", strtotime(trim($date[0]['data'])));
         $phone = $feed_data_item->get_item_tags('http://www.w3.org/2005/Atom', 'phone');
         $phone = intval($phone[0]['data']);
         $category = $feed_data_item->get_item_tags('http://www.w3.org/2005/Atom', 'categorization');
         $category = trim($category[0]['data']);
         $message_sms = $feed_data_item->get_item_tags('http://www.w3.org/2005/Atom', 'sms');
         $message_sms = trim($message_sms[0]['data']);
         $message_notes = $feed_data_item->get_item_tags('http://www.w3.org/2005/Atom', 'notes');
         $message_notes = trim($message_notes[0]['data']);
         $message_detail = $message_notes . "\n~~~~~~~~~~~~~~~~~\n";
         $message_detail .= "Category: " . $category;
         $latitude = $feed_data_item->get_latitude();
         $longitude = $feed_data_item->get_longitude();
         $location_name = $feed_data_item->get_item_tags('http://www.w3.org/2005/Atom', 'city');
         $location_name = trim($location_name[0]['data']);
         // Okay now we have everything we need
         // Step 1. Does this message have a phone number?
         if ($phone) {
             // Step 2. Has this particular message been saved before??
             $exists = ORM::factory('message')->where('service_messageid', $service_messageid)->where('message_from', $phone)->find();
             if (!$exists->loaded) {
                 $parent_id = 0;
                 // Step 3. Make sure this phone number is not in our database
                 $reporter = ORM::factory('reporter')->where('service_id', 1)->where('service_account', $phone)->find();
                 if (!$reporter->loaded) {
                     $reporter->service_id = 1;
                     // 1 - SMS (See Service Table)
                     $reporter->level_id = 3;
                     // 3 - Untrusted (See Level Table)
                     $reporter->service_account = $phone;
                     $reporter->reporter_date = $date;
                     $reporter->save();
                 } else {
                     // Find previous message and use it as parent
                     $parent = ORM::factory('message')->where('reporter_id', $reporter->id)->where('message_type', '1')->where('parent_id', '0')->where('message_trash', '0')->orderby('message_date', 'desc')->find();
                     if ($parent->loaded) {
                         $parent_id = $parent->id;
                         $parent->message_reply = 1;
                         $parent->save($parent->id);
                     }
                 }
                 // Step 4. If this message has a location, save it!
                 $location_id = 0;
                 if ($latitude && $longitude) {
                     $location = ORM::factory('location')->where('latitude', $latitude)->where('longitude', $longitude)->find();
                     if (!$location->loaded) {
                         $location = new Location_Model();
                         if ($location_name) {
                             $location->location_name = $location_name;
                         } else {
                             $location->location_name = "Unknown";
                         }
                         $location->latitude = $latitude;
                         $location->longitude = $longitude;
                         $location->location_date = date("Y-m-d H:i:s", time());
                         $location->save();
                         $location_id = $location->id;
                     }
                 }
                 // Save Message
                 $message = new Message_Model();
                 $message->parent_id = $parent_id;
                 $message->incident_id = 0;
                 $message->location_id = $location_id;
                 $message->user_id = 0;
                 $message->reporter_id = $reporter->id;
//.........这里部分代码省略.........
开发者ID:surflightroy,项目名称:Ushahidi_Web,代码行数:101,代码来源:georss.php


注:本文中的Location_Model::save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。