public function block()
 {
     $content = new View('blocks/media_block');
     // Get Reports
     // XXX: Might need to replace magic no. 8 with a constant
     $content->total_items = ORM::factory('incident')->where('incident_active', '1')->limit('8')->count_all();
     $incidents = ORM::factory('incident')->where('incident_active', '1')->limit('10')->orderby('incident_date', 'desc')->find_all();
     $incident_video = array();
     $incident_photo = array();
     foreach ($incidents as $incident) {
         $incident_video[$incident->id] = array();
         $incident_photo[$incident->id] = array();
         foreach ($incident->media as $media) {
             // We only care about videos and photos
             if ($media->media_type == 2) {
                 $incident_video[$incident->id][] = array('link' => $media->media_link, 'thumb' => $media->media_thumb);
             } elseif ($media->media_type == 1) {
                 $incident_photo[$incident->id][] = array('large' => url::convert_uploaded_to_abs($media->media_link), 'thumb' => url::convert_uploaded_to_abs($media->media_thumb));
             }
         }
     }
     // Video & photo links
     $content->incident_videos = $incident_video;
     $content->incident_photos = $incident_photo;
     $content->incidents = $incidents;
     // Create object of the video embed class
     $content->video_embed = new VideoEmbed();
     echo $content;
 }
Beispiel #2
0
 /**
  * Returns an array of badges for a specific user
  * @return array
  */
 public static function users_badges($user_id)
 {
     // Get assigned badge ids
     $assigned_badges = ORM::factory('badge_user')->where(array('user_id' => $user_id))->find_all();
     $assigned = array();
     foreach ($assigned_badges as $assigned_badge) {
         $assigned[] = $assigned_badge->badge_id;
     }
     $arr = array();
     if (count($assigned) > 0) {
         // Get badges with those ids
         $badges = ORM::factory('badge')->in('id', $assigned)->find_all();
         foreach ($badges as $badge) {
             $arr[$badge->id] = array('id' => $badge->id, 'name' => $badge->name, 'description' => $badge->description, 'img' => url::convert_uploaded_to_abs($badge->media->media_link), 'img_m' => url::convert_uploaded_to_abs($badge->media->media_medium), 'img_t' => url::convert_uploaded_to_abs($badge->media->media_thumb));
         }
     }
     return $arr;
 }
Beispiel #3
0
 /**
  * Generate GEOJSON from incidents
  * 
  * @param ORM_Iterator|Database_Result|array $incidents collection of incidents
  * @param int $category_id
  * @param string $color
  * @param string $icon
  * @return array $json_features geojson features array
  **/
 protected function markers_geojson($incidents, $category_id, $color, $icon, $include_geometries = TRUE)
 {
     $json_features = array();
     // Extra params for markers only
     // Get the incidentid (to be added as first marker)
     $first_incident_id = (isset($_GET['i']) and intval($_GET['i']) > 0) ? intval($_GET['i']) : 0;
     $media_type = (isset($_GET['m']) and intval($_GET['m']) > 0) ? intval($_GET['m']) : 0;
     foreach ($incidents as $marker) {
         // Handle both reports::fetch_incidents() response and actual ORM objects
         $marker->id = isset($marker->incident_id) ? $marker->incident_id : $marker->id;
         if (isset($marker->latitude) and isset($marker->longitude)) {
             $latitude = $marker->latitude;
             $longitude = $marker->longitude;
         } elseif (isset($marker->location) and isset($marker->location->latitude) and isset($marker->location->longitude)) {
             $latitude = $marker->location->latitude;
             $longitude = $marker->location->longitude;
         } else {
             // No location - skip this report
             continue;
         }
         // Get thumbnail
         $thumb = "";
         $media = ORM::factory('incident', $marker->id)->media;
         if ($media->count()) {
             foreach ($media as $photo) {
                 if ($photo->media_thumb) {
                     // Get the first thumb
                     $thumb = url::convert_uploaded_to_abs($photo->media_thumb);
                     break;
                 }
             }
         }
         // Get URL from object, fallback to Incident_Model::get() if object doesn't have url or url()
         if (method_exists($marker, 'url')) {
             $link = $marker->url();
         } elseif (isset($marker->url)) {
             $link = $marker->url;
         } else {
             $link = Incident_Model::get_url($marker);
         }
         $item_name = $this->get_title($marker->incident_title, $link);
         $json_item = array();
         $json_item['type'] = 'Feature';
         $json_item['properties'] = array('id' => $marker->id, 'name' => $item_name, 'link' => $link, 'category' => array($category_id), 'color' => $color, 'icon' => $icon, 'thumb' => $thumb, 'timestamp' => strtotime($marker->incident_date), 'count' => 1, 'class' => get_class($marker), 'title' => $marker->incident_title);
         $json_item['geometry'] = array('type' => 'Point', 'coordinates' => array($longitude, $latitude));
         if ($marker->id == $first_incident_id) {
             array_unshift($json_features, $json_item);
         } else {
             array_push($json_features, $json_item);
         }
         // Get Incident Geometries
         if ($include_geometries) {
             $geometry = $this->get_geometry($marker->id, $marker->incident_title, $marker->incident_date, $link);
             if (count($geometry)) {
                 foreach ($geometry as $g) {
                     array_push($json_features, $g);
                 }
             }
         }
     }
     Event::run('ushahidi_filter.json_index_features', $json_features);
     return $json_features;
 }
Beispiel #4
0
</span>
			<?php 
Event::run('ushahidi_action.report_meta_after_time', $incident_id);
?>
		</p>

		<div class="report-category-list">
		<p>
			<?php 
foreach ($incident_category as $category) {
    // don't show hidden categoies
    if ($category->category->category_visible == 0) {
        continue;
    }
    if ($category->category->category_image_thumb) {
        $style = "background:transparent url(" . url::convert_uploaded_to_abs($category->category->category_image_thumb) . ") 0 0 no-repeat";
    } else {
        $style = "background-color:#" . $category->category->category_color;
    }
    ?>
					<a href="<?php 
    echo url::site() . "reports/?c=" . $category->category->id;
    ?>
" title="<?php 
    echo Category_Lang_Model::category_description($category->category_id);
    ?>
">
						<span class="r_cat-box" style="<?php 
    echo $style;
    ?>
">&nbsp;</span>
Beispiel #5
0
 public function index()
 {
     $this->template->header->this_page = 'home';
     $this->template->content = new View('main/layout');
     // Cacheable Main Controller
     $this->is_cachable = TRUE;
     // Map and Slider Blocks
     $div_map = new View('main/map');
     $div_timeline = new View('main/timeline');
     // Filter::map_main - Modify Main Map Block
     Event::run('ushahidi_filter.map_main', $div_map);
     // Filter::map_timeline - Modify Main Map Block
     Event::run('ushahidi_filter.map_timeline', $div_timeline);
     $this->template->content->div_map = $div_map;
     $this->template->content->div_timeline = $div_timeline;
     // Check if there is a site message
     $this->template->content->site_message = '';
     $site_message = trim(Kohana::config('settings.site_message'));
     if ($site_message != '') {
         // Send the site message to both the header and the main content body
         //   so a theme can utilize it in either spot.
         $this->template->content->site_message = $site_message;
         $this->template->header->site_message = $site_message;
     }
     // Get locale
     $l = Kohana::config('locale.language.0');
     // Get all active top level categories
     $parent_categories = array();
     $all_parents = ORM::factory('category')->where('category_visible', '1')->where('parent_id', '0')->find_all();
     foreach ($all_parents as $category) {
         // Get The Children
         $children = array();
         foreach ($category->children as $child) {
             $child_visible = $child->category_visible;
             if ($child_visible) {
                 // Check for localization of child category
                 $display_title = Category_Lang_Model::category_title($child->id, $l);
                 $ca_img = $child->category_image != NULL ? url::convert_uploaded_to_abs($child->category_image) : NULL;
                 $children[$child->id] = array($display_title, $child->category_color, $ca_img);
             }
         }
         // Check for localization of parent category
         $display_title = Category_Lang_Model::category_title($category->id, $l);
         // Put it all together
         $ca_img = $category->category_image != NULL ? url::convert_uploaded_to_abs($category->category_image) : NULL;
         $parent_categories[$category->id] = array($display_title, $category->category_color, $ca_img, $children);
     }
     $this->template->content->categories = $parent_categories;
     // Get all active Layers (KMZ/KML)
     $layers = array();
     $config_layers = Kohana::config('map.layers');
     // use config/map layers if set
     if ($config_layers == $layers) {
         foreach (ORM::factory('layer')->where('layer_visible', 1)->find_all() as $layer) {
             $layers[$layer->id] = array($layer->layer_name, $layer->layer_color, $layer->layer_url, $layer->layer_file);
         }
     } else {
         $layers = $config_layers;
     }
     $this->template->content->layers = $layers;
     // Get Default Color
     $this->template->content->default_map_all = Kohana::config('settings.default_map_all');
     // Get default icon
     $this->template->content->default_map_all_icon = '';
     if (Kohana::config('settings.default_map_all_icon_id')) {
         $icon_object = ORM::factory('media')->find(Kohana::config('settings.default_map_all_icon_id'));
         $this->template->content->default_map_all_icon = Kohana::config('upload.relative_directory') . "/" . $icon_object->media_medium;
     }
     // Get Twitter Hashtags
     $this->template->content->twitter_hashtag_array = array_filter(array_map('trim', explode(',', Kohana::config('settings.twitter_hashtags'))));
     // Get Report-To-Email
     $this->template->content->report_email = Kohana::config('settings.site_email');
     // Get SMS Numbers
     $phone_array = array();
     $sms_no1 = Kohana::config('settings.sms_no1');
     $sms_no2 = Kohana::config('settings.sms_no2');
     $sms_no3 = Kohana::config('settings.sms_no3');
     if (!empty($sms_no1)) {
         $phone_array[] = $sms_no1;
     }
     if (!empty($sms_no2)) {
         $phone_array[] = $sms_no2;
     }
     if (!empty($sms_no3)) {
         $phone_array[] = $sms_no3;
     }
     $this->template->content->phone_array = $phone_array;
     // Get external apps
     $external_apps = array();
     // Catch errors, in case we have an old db
     try {
         $external_apps = ORM::factory('externalapp')->find_all();
     } catch (Exception $e) {
     }
     $this->template->content->external_apps = $external_apps;
     // Get The START, END and Incident Dates
     $startDate = "";
     $endDate = "";
     $display_startDate = 0;
     $display_endDate = 0;
     $db = new Database();
     // Next, Get the Range of Years
     $query = $db->query('SELECT DATE_FORMAT(incident_date, \'%Y-%c\') AS dates ' . 'FROM ' . $this->table_prefix . 'incident ' . 'WHERE incident_active = 1 ' . 'GROUP BY DATE_FORMAT(incident_date, \'%Y-%c\') ' . 'ORDER BY incident_date');
     $first_year = date('Y');
     $last_year = date('Y');
     $first_month = 1;
     $last_month = 12;
     $i = 0;
     foreach ($query as $data) {
         $date = explode('-', $data->dates);
         $year = $date[0];
         $month = $date[1];
         // Set first year
         if ($i == 0) {
             $first_year = $year;
             $first_month = $month;
         }
         // Set last dates
         $last_year = $year;
         $last_month = $month;
         $i++;
     }
     $show_year = $first_year;
     $selected_start_flag = TRUE;
     while ($show_year <= $last_year) {
         $startDate .= "<optgroup label=\"" . $show_year . "\">";
         $s_m = 1;
         if ($show_year == $first_year) {
             // If we are showing the first year, the starting month may not be January
             $s_m = $first_month;
         }
         $l_m = 12;
         if ($show_year == $last_year) {
             // If we are showing the last year, the ending month may not be December
             $l_m = $last_month;
         }
         for ($i = $s_m; $i <= $l_m; $i++) {
             if ($i < 10) {
                 // All months need to be two digits
                 $i = "0" . $i;
             }
             $startDate .= "<option value=\"" . strtotime($show_year . "-" . $i . "-01") . "\"";
             if ($selected_start_flag == TRUE) {
                 $display_startDate = strtotime($show_year . "-" . $i . "-01");
                 $startDate .= " selected=\"selected\" ";
                 $selected_start_flag = FALSE;
             }
             $startDate .= ">" . date('M', mktime(0, 0, 0, $i, 1)) . " " . $show_year . "</option>";
         }
         $startDate .= "</optgroup>";
         $endDate .= "<optgroup label=\"" . $show_year . "\">";
         for ($i = $s_m; $i <= $l_m; $i++) {
             if ($i < 10) {
                 // All months need to be two digits
                 $i = "0" . $i;
             }
             $endDate .= "<option value=\"" . strtotime($show_year . "-" . $i . "-" . date('t', mktime(0, 0, 0, $i, 1)) . " 23:59:59") . "\"";
             if ($i == $l_m and $show_year == $last_year) {
                 $display_endDate = strtotime($show_year . "-" . $i . "-" . date('t', mktime(0, 0, 0, $i, 1)) . " 23:59:59");
                 $endDate .= " selected=\"selected\" ";
             }
             $endDate .= ">" . date('M', mktime(0, 0, 0, $i, 1)) . " " . $show_year . "</option>";
         }
         $endDate .= "</optgroup>";
         // Show next year
         $show_year++;
     }
     Event::run('ushahidi_filter.active_startDate', $display_startDate);
     Event::run('ushahidi_filter.active_endDate', $display_endDate);
     Event::run('ushahidi_filter.startDate', $startDate);
     Event::run('ushahidi_filter.endDate', $endDate);
     $this->template->content->div_timeline->startDate = $startDate;
     $this->template->content->div_timeline->endDate = $endDate;
     // Javascript Header
     $this->themes->map_enabled = TRUE;
     $this->themes->slider_enabled = TRUE;
     if (Kohana::config('settings.enable_timeline')) {
         $this->themes->timeline_enabled = TRUE;
     }
     // Map Settings
     $marker_radius = Kohana::config('map.marker_radius');
     $marker_opacity = Kohana::config('map.marker_opacity');
     $marker_stroke_width = Kohana::config('map.marker_stroke_width');
     $marker_stroke_opacity = Kohana::config('map.marker_stroke_opacity');
     $this->themes->js = new View('main/main_js');
     $this->themes->js->marker_radius = ($marker_radius >= 1 and $marker_radius <= 10) ? $marker_radius : 5;
     $this->themes->js->marker_opacity = ($marker_opacity >= 1 and $marker_opacity <= 10) ? $marker_opacity * 0.1 : 0.9;
     $this->themes->js->marker_stroke_width = ($marker_stroke_width >= 1 and $marker_stroke_width <= 5) ? $marker_stroke_width : 2;
     $this->themes->js->marker_stroke_opacity = ($marker_stroke_opacity >= 1 and $marker_stroke_opacity <= 10) ? $marker_stroke_opacity * 0.1 : 0.9;
     $this->themes->js->active_startDate = $display_startDate;
     $this->themes->js->active_endDate = $display_endDate;
     $this->themes->js->blocks_per_row = Kohana::config('settings.blocks_per_row');
 }
Beispiel #6
0
 public function index()
 {
     $this->template->header->this_page = 'home';
     $this->template->content = new View('main');
     // Cacheable Main Controller
     $this->is_cachable = TRUE;
     // Map and Slider Blocks
     $div_map = new View('main_map');
     $div_timeline = new View('main_timeline');
     // Filter::map_main - Modify Main Map Block
     Event::run('ushahidi_filter.map_main', $div_map);
     // Filter::map_timeline - Modify Main Map Block
     Event::run('ushahidi_filter.map_timeline', $div_timeline);
     $this->template->content->div_map = $div_map;
     $this->template->content->div_timeline = $div_timeline;
     // Check if there is a site message
     $this->template->content->site_message = '';
     $site_message = trim(Kohana::config('settings.site_message'));
     if ($site_message != '') {
         $this->template->content->site_message = $site_message;
     }
     // Get locale
     $l = Kohana::config('locale.language.0');
     // Get all active top level categories
     $parent_categories = array();
     foreach (ORM::factory('category')->where('category_visible', '1')->where('parent_id', '0')->orderby('category_position', 'asc')->find_all() as $category) {
         // Get The Children
         $children = array();
         foreach ($category->orderby('category_position', 'asc')->children as $child) {
             $child_visible = $child->category_visible;
             if ($child_visible) {
                 // Check for localization of child category
                 $display_title = Category_Lang_Model::category_title($child->id, $l);
                 $ca_img = $child->category_image != NULL ? url::convert_uploaded_to_abs($child->category_image) : NULL;
                 $children[$child->id] = array($display_title, $child->category_color, $ca_img);
                 if ($child->category_trusted) {
                     // Get Trusted Category Count
                     $trusted = $this->get_trusted_category_count($child->id);
                     if (!$trusted->count_all()) {
                         unset($children[$child->id]);
                     }
                 }
             }
         }
         // Check for localization of parent category
         $display_title = Category_Lang_Model::category_title($category->id, $l);
         // Put it all together
         $ca_img = $category->category_image != NULL ? url::convert_uploaded_to_abs($category->category_image) : NULL;
         $parent_categories[$category->id] = array($display_title, $category->category_color, $ca_img, $children);
         if ($category->category_trusted) {
             // Get Trusted Category Count
             $trusted = $this->get_trusted_category_count($category->id);
             if (!$trusted->count_all()) {
                 unset($parent_categories[$category->id]);
             }
         }
     }
     $this->template->content->categories = $parent_categories;
     // Get all active Layers (KMZ/KML)
     $layers = array();
     $config_layers = Kohana::config('map.layers');
     // use config/map layers if set
     if ($config_layers == $layers) {
         foreach (ORM::factory('layer')->where('layer_visible', 1)->find_all() as $layer) {
             $layers[$layer->id] = array($layer->layer_name, $layer->layer_color, $layer->layer_url, $layer->layer_file);
         }
     } else {
         $layers = $config_layers;
     }
     $this->template->content->layers = $layers;
     // Get all active Shares
     $shares = array();
     foreach (ORM::factory('sharing')->where('sharing_active', 1)->find_all() as $share) {
         $shares[$share->id] = array($share->sharing_name, $share->sharing_color);
     }
     $this->template->content->shares = $shares;
     // Get Default Color
     $this->template->content->default_map_all = Kohana::config('settings.default_map_all');
     // Get Twitter Hashtags
     $this->template->content->twitter_hashtag_array = array_filter(array_map('trim', explode(',', Kohana::config('settings.twitter_hashtags'))));
     // Get Report-To-Email
     $this->template->content->report_email = Kohana::config('settings.site_email');
     // Get SMS Numbers
     $phone_array = array();
     $sms_no1 = Kohana::config('settings.sms_no1');
     $sms_no2 = Kohana::config('settings.sms_no2');
     $sms_no3 = Kohana::config('settings.sms_no3');
     if (!empty($sms_no1)) {
         $phone_array[] = $sms_no1;
     }
     if (!empty($sms_no2)) {
         $phone_array[] = $sms_no2;
     }
     if (!empty($sms_no3)) {
         $phone_array[] = $sms_no3;
     }
     $this->template->content->phone_array = $phone_array;
     // Get The START, END and Incident Dates
     $startDate = "";
     $endDate = "";
     $display_startDate = 0;
     $display_endDate = 0;
     $db = new Database();
     // Next, Get the Range of Years
     $query = $db->query('SELECT DATE_FORMAT(incident_date, \'%Y-%c\') AS dates FROM ' . $this->table_prefix . 'incident WHERE incident_active = 1 GROUP BY DATE_FORMAT(incident_date, \'%Y-%c\') ORDER BY incident_date');
     $first_year = date('Y');
     $last_year = date('Y');
     $first_month = 1;
     $last_month = 12;
     $i = 0;
     foreach ($query as $data) {
         $date = explode('-', $data->dates);
         $year = $date[0];
         $month = $date[1];
         // Set first year
         if ($i == 0) {
             $first_year = $year;
             $first_month = $month;
         }
         // Set last dates
         $last_year = $year;
         $last_month = $month;
         $i++;
     }
     $show_year = $first_year;
     $selected_start_flag = TRUE;
     while ($show_year <= $last_year) {
         $startDate .= "<optgroup label=\"" . $show_year . "\">";
         $s_m = 1;
         if ($show_year == $first_year) {
             // If we are showing the first year, the starting month may not be January
             $s_m = $first_month;
         }
         $l_m = 12;
         if ($show_year == $last_year) {
             // If we are showing the last year, the ending month may not be December
             $l_m = $last_month;
         }
         for ($i = $s_m; $i <= $l_m; $i++) {
             if ($i < 10) {
                 // All months need to be two digits
                 $i = "0" . $i;
             }
             $startDate .= "<option value=\"" . strtotime($show_year . "-" . $i . "-01") . "\"";
             if ($selected_start_flag == TRUE) {
                 $display_startDate = strtotime($show_year . "-" . $i . "-01");
                 $startDate .= " selected=\"selected\" ";
                 $selected_start_flag = FALSE;
             }
             $startDate .= ">" . date('M', mktime(0, 0, 0, $i, 1)) . " " . $show_year . "</option>";
         }
         $startDate .= "</optgroup>";
         $endDate .= "<optgroup label=\"" . $show_year . "\">";
         for ($i = $s_m; $i <= $l_m; $i++) {
             if ($i < 10) {
                 // All months need to be two digits
                 $i = "0" . $i;
             }
             $endDate .= "<option value=\"" . strtotime($show_year . "-" . $i . "-" . date('t', mktime(0, 0, 0, $i, 1)) . " 23:59:59") . "\"";
             if ($i == $l_m and $show_year == $last_year) {
                 $display_endDate = strtotime($show_year . "-" . $i . "-" . date('t', mktime(0, 0, 0, $i, 1)) . " 23:59:59");
                 $endDate .= " selected=\"selected\" ";
             }
             $endDate .= ">" . date('M', mktime(0, 0, 0, $i, 1)) . " " . $show_year . "</option>";
         }
         $endDate .= "</optgroup>";
         // Show next year
         $show_year++;
     }
     Event::run('ushahidi_filter.active_startDate', $display_startDate);
     Event::run('ushahidi_filter.active_endDate', $display_endDate);
     Event::run('ushahidi_filter.startDate', $startDate);
     Event::run('ushahidi_filter.endDate', $endDate);
     $this->template->content->div_timeline->startDate = $startDate;
     $this->template->content->div_timeline->endDate = $endDate;
     // Javascript Header
     $this->themes->map_enabled = TRUE;
     $this->themes->main_page = TRUE;
     // Map Settings
     $clustering = Kohana::config('settings.allow_clustering');
     $marker_radius = Kohana::config('map.marker_radius');
     $marker_opacity = Kohana::config('map.marker_opacity');
     $marker_stroke_width = Kohana::config('map.marker_stroke_width');
     $marker_stroke_opacity = Kohana::config('map.marker_stroke_opacity');
     // pdestefanis - allows to restrict the number of zoomlevels available
     $numZoomLevels = Kohana::config('map.numZoomLevels');
     $minZoomLevel = Kohana::config('map.minZoomLevel');
     $maxZoomLevel = Kohana::config('map.maxZoomLevel');
     // pdestefanis - allows to limit the extents of the map
     $lonFrom = Kohana::config('map.lonFrom');
     $latFrom = Kohana::config('map.latFrom');
     $lonTo = Kohana::config('map.lonTo');
     $latTo = Kohana::config('map.latTo');
     $this->themes->js = new View('main_js');
     $this->themes->js->json_url = $clustering == 1 ? "json/cluster" : "json";
     $this->themes->js->marker_radius = $marker_radius >= 1 && $marker_radius <= 10 ? $marker_radius : 5;
     $this->themes->js->marker_opacity = $marker_opacity >= 1 && $marker_opacity <= 10 ? $marker_opacity * 0.1 : 0.9;
     $this->themes->js->marker_stroke_width = $marker_stroke_width >= 1 && $marker_stroke_width <= 5 ? $marker_stroke_width : 2;
     $this->themes->js->marker_stroke_opacity = $marker_stroke_opacity >= 1 && $marker_stroke_opacity <= 10 ? $marker_stroke_opacity * 0.1 : 0.9;
     // pdestefanis - allows to restrict the number of zoomlevels available
     $this->themes->js->numZoomLevels = $numZoomLevels;
     $this->themes->js->minZoomLevel = $minZoomLevel;
     $this->themes->js->maxZoomLevel = $maxZoomLevel;
     // pdestefanis - allows to limit the extents of the map
     $this->themes->js->lonFrom = $lonFrom;
     $this->themes->js->latFrom = $latFrom;
     $this->themes->js->lonTo = $lonTo;
     $this->themes->js->latTo = $latTo;
     $this->themes->js->default_map = Kohana::config('settings.default_map');
     $this->themes->js->default_zoom = Kohana::config('settings.default_zoom');
     $this->themes->js->latitude = Kohana::config('settings.default_lat');
     $this->themes->js->longitude = Kohana::config('settings.default_lon');
     $this->themes->js->default_map_all = Kohana::config('settings.default_map_all');
     $this->themes->js->active_startDate = $display_startDate;
     $this->themes->js->active_endDate = $display_endDate;
     $this->themes->js->blocks_per_row = Kohana::config('settings.blocks_per_row');
     //$myPacker = new javascriptpacker($js , 'Normal', false, false);
     //$js = $myPacker->pack();
     // Rebuild Header Block
     $this->template->header->header_block = $this->themes->header_block();
 }
 /**
  * Generic function to get reports by given set of parameters
  *
  * @param string $where SQL where clause
  * @return string XML or JSON string
  */
 public function _get_incidents($where = array())
 {
     // STEP 1.
     // Get the incidents
     $items = Incident_Model::get_incidents($where, $this->list_limit, $this->order_field, $this->sort);
     //No record found.
     if ($items->count() == 0) {
         return $this->response(4, $this->error_messages);
     }
     // Records found - proceed
     // Set the no. of records returned
     $this->record_count = $items->count();
     // Will hold the XML/JSON string to return
     $ret_json_or_xml = '';
     $json_reports = array();
     $json_report_media = array();
     $json_report_categories = array();
     $json_incident_media = array();
     $upload_path = str_replace("media/uploads/", "", Kohana::config('upload.relative_directory') . "/");
     //XML elements
     $xml = new XmlWriter();
     $xml->openMemory();
     $xml->startDocument('1.0', 'UTF-8');
     $xml->startElement('response');
     $xml->startElement('payload');
     $xml->writeElement('domain', $this->domain);
     $xml->startElement('incidents');
     // Records found, proceed
     // Store the incident ids
     $incidents_ids = array();
     $custom_field_items = array();
     foreach ($items as $item) {
         $incident_ids[] = $item->incident_id;
         $thiscustomfields = customforms::get_custom_form_fields($item->incident_id, null, false, "view");
         if (!empty($thiscustomfields)) {
             $custom_field_items[$item->incident_id] = $thiscustomfields;
         }
     }
     //
     // STEP 2.
     // Fetch the incident categories
     //
     // Execute the query
     $incident_categories = ORM::factory('category')->select('category.*, incident_category.incident_id')->join('incident_category', 'category.id', 'incident_category.category_id')->in('incident_category.incident_id', $incident_ids)->find_all();
     // To hold the incident category items
     $category_items = array();
     // Fetch items into array
     foreach ($incident_categories as $incident_category) {
         $category_items[$incident_category->incident_id][] = $incident_category->as_array();
     }
     // Free temporary variables from memory
     unset($incident_categories);
     //
     // STEP 3.
     // Fetch the media associated with all the incidents
     //
     $media_items_result = ORM::factory('media')->in('incident_id', $incident_ids)->find_all();
     // To store the fetched media items
     $media_items = array();
     // Fetch items into array
     foreach ($media_items_result as $media_item) {
         $media_item_array = $media_item->as_array();
         if ($media_item->media_type == 1 and !empty($media_item->media_thumb)) {
             $media_item_array["media_thumb_url"] = url::convert_uploaded_to_abs($media_item->media_thumb);
             $media_item_array["media_link_url"] = url::convert_uploaded_to_abs($media_item->media_link);
         }
         $media_items[$media_item->incident_id][] = $media_item_array;
     }
     // Free temporary variables
     unset($media_items_result, $media_item_array);
     //
     // STEP 4.
     // Fetch the comments associated with the incidents
     //
     if ($this->comments) {
         // Execute the query
         $incident_comments = ORM::factory('comment')->in('incident_id', $incident_ids)->where('comment_spam', 0)->find_all();
         // To hold the incident category items
         $comment_items = array();
         // Fetch items into array
         foreach ($incident_comments as $incident_comment) {
             $comment_items[$incident_comment->incident_id][] = $incident_comment->as_array();
         }
         // Free temporary variables from memory
         unset($incident_comments);
     }
     //
     // STEP 5.
     // Return XML
     //
     foreach ($items as $item) {
         // Build xml file
         $xml->startElement('incident');
         $xml->writeElement('id', $item->incident_id);
         $xml->writeElement('title', $item->incident_title);
         $xml->writeElement('description', $item->incident_description);
         $xml->writeElement('date', $item->incident_date);
         $xml->writeElement('mode', $item->incident_mode);
         $xml->writeElement('active', $item->incident_active);
         $xml->writeElement('verified', $item->incident_verified);
         $xml->startElement('location');
         $xml->writeElement('id', $item->location_id);
         $xml->writeElement('name', $item->location_name);
         $xml->writeElement('latitude', $item->latitude);
         $xml->writeElement('longitude', $item->longitude);
         $xml->endElement();
         $xml->startElement('categories');
         $json_report_categories[$item->incident_id] = array();
         // Check if the incident id exists
         if (isset($category_items[$item->incident_id])) {
             foreach ($category_items[$item->incident_id] as $category_item) {
                 if ($this->response_type == 'json' or $this->response_type == 'jsonp') {
                     $json_report_categories[$item->incident_id][] = array("category" => array("id" => $category_item['id'], "title" => $category_item['category_title']));
                 } else {
                     $xml->startElement('category');
                     $xml->writeElement('id', $category_item['id']);
                     $xml->writeElement('title', $category_item['category_title']);
                     $xml->endElement();
                 }
             }
         }
         // End categories
         $xml->endElement();
         $xml->startElement('comments');
         $json_report_comments[$item->incident_id] = array();
         // Check if the incident id exists
         if (isset($comment_items[$item->incident_id])) {
             foreach ($comment_items[$item->incident_id] as $comment_item) {
                 if ($this->response_type == 'json' or $this->response_type == 'jsonp') {
                     $json_report_comments[$item->incident_id][] = array("comment" => $comment_item);
                 } else {
                     $xml->startElement('comment');
                     $xml->writeElement('id', $comment_item['id']);
                     $xml->writeElement('comment_author', $comment_item['comment_author']);
                     $xml->writeElement('comment_email', $comment_item['comment_email']);
                     $xml->writeElement('comment_description', $comment_item['comment_description']);
                     $xml->writeElement('comment_date', $comment_item['comment_date']);
                     $xml->endElement();
                 }
             }
         }
         // End comments
         $xml->endElement();
         $json_report_media[$item->incident_id] = array();
         if (count($media_items) > 0) {
             if (isset($media_items[$item->incident_id]) and count($media_items[$item->incident_id]) > 0) {
                 $xml->startElement('mediaItems');
                 foreach ($media_items[$item->incident_id] as $media_item) {
                     if ($this->response_type == 'json' or $this->response_type == 'jsonp') {
                         $json_media_array = array("id" => $media_item['id'], "type" => $media_item['media_type'], "link" => $media_item['media_link'], "thumb" => $media_item['media_thumb']);
                         // If we are look at certain types of media, add some fields
                         if ($media_item['media_type'] == 1 and isset($media_item['media_thumb_url'])) {
                             // Give a full absolute URL to the image
                             $json_media_array["thumb_url"] = $media_item['media_thumb_url'];
                             $json_media_array["link_url"] = $media_item['media_link_url'];
                         }
                         $json_report_media[$item->incident_id][] = $json_media_array;
                     } else {
                         $xml->startElement('media');
                         if ($media_item['id'] != "") {
                             $xml->writeElement('id', $media_item['id']);
                         }
                         if ($media_item['media_title'] != "") {
                             $xml->writeElement('title', $media_item['media_title']);
                         }
                         if ($media_item['media_type'] != "") {
                             $xml->writeElement('type', $media_item['media_type']);
                         }
                         if ($media_item['media_link'] != "") {
                             $xml->writeElement('link', $upload_path . $media_item['media_link']);
                         }
                         if ($media_item['media_thumb'] != "") {
                             $xml->writeElement('thumb', $upload_path . $media_item['media_thumb']);
                         }
                         if ($media_item['media_type'] == 1 and isset($media_item['media_thumb_url'])) {
                             $xml->writeElement('thumb_url', $media_item['media_thumb_url']);
                             $xml->writeElement('link_url', $media_item['media_link_url']);
                         }
                         $xml->endElement();
                     }
                 }
                 $xml->endElement();
                 // Media
             }
         }
         if (count($custom_field_items) > 0 and $this->response_type != 'json' and $this->response_type != 'jsonp') {
             if (isset($custom_field_items[$item->incident_id]) and count($custom_field_items[$item->incident_id]) > 0) {
                 $xml->startElement('customFields');
                 foreach ($custom_field_items[$item->incident_id] as $field_item) {
                     $xml->startElement('field');
                     foreach ($field_item as $fname => $fval) {
                         $xml->writeElement($fname, $fval);
                     }
                     $xml->endElement();
                     // field
                 }
                 $xml->endElement();
                 // customFields
             }
         }
         $xml->endElement();
         // End incident
         // Check for response type
         if ($this->response_type == 'json' or $this->response_type == 'jsonp') {
             $json_reports[] = array("incident" => array("incidentid" => $item->incident_id, "incidenttitle" => $item->incident_title, "incidentdescription" => $item->incident_description, "incidentdate" => $item->incident_date, "incidentmode" => $item->incident_mode, "incidentactive" => $item->incident_active, "incidentverified" => $item->incident_verified, "locationid" => $item->location_id, "locationname" => $item->location_name, "locationlatitude" => $item->latitude, "locationlongitude" => $item->longitude), "categories" => $json_report_categories[$item->incident_id], "media" => $json_report_media[$item->incident_id], "comments" => $json_report_comments[$item->incident_id], "customfields" => isset($custom_field_items[$item->incident_id]) ? $custom_field_items[$item->incident_id] : array());
         }
     }
     // Create the JSON array
     $data = array("payload" => array("domain" => $this->domain, "incidents" => $json_reports), "error" => $this->api_service->get_error_msg(0));
     if ($this->response_type == 'json' or $this->response_type == 'jsonp') {
         return $this->array_as_json($data);
     } else {
         $xml->endElement();
         //end incidents
         $xml->endElement();
         // end payload
         $xml->startElement('error');
         $xml->writeElement('code', 0);
         $xml->writeElement('message', 'No Error');
         $xml->endElement();
         //end error
         $xml->endElement();
         // end response
         return $xml->outputMemory(true);
     }
 }
Beispiel #8
0
        $category_image = $category_info[2] != NULL ? url::convert_uploaded_to_abs($category_info[2]) : NULL;
        $category_description = html::escape(Category_Lang_Model::category_description($category));
        $color_css = 'class="category-icon swatch" style="background-color:#' . $category_color . '"';
        if ($category_info[2] != NULL) {
            $category_image = html::image(array('src' => $category_image));
            $color_css = 'class="category-icon"';
        }
        echo '<li>' . '<a href="#" id="cat_' . $category . '" title="' . $category_description . '">' . '<span ' . $color_css . '>' . $category_image . '</span>' . '<span class="category-title">' . $category_title . '</span>' . '</a>';
        // Get Children
        echo '<div class="hide" id="child_' . $category . '">';
        if (sizeof($category_info[3]) != 0) {
            echo '<ul>';
            foreach ($category_info[3] as $child => $child_info) {
                $child_title = html::escape($child_info[0]);
                $child_color = $child_info[1];
                $child_image = $child_info[2] != NULL ? url::convert_uploaded_to_abs($child_info[2]) : NULL;
                $child_description = html::escape(Category_Lang_Model::category_description($child));
                $color_css = 'class="category-icon swatch" style="background-color:#' . $child_color . '"';
                if ($child_info[2] != NULL) {
                    $child_image = html::image(array('src' => $child_image));
                    $color_css = 'class="category-icon"';
                }
                echo '<li>' . '<a href="#" id="cat_' . $child . '" title="' . $child_description . '">' . '<span ' . $color_css . '>' . $child_image . '</span>' . '<span class="category-title">' . $child_title . '</span>' . '</a>' . '</li>';
            }
            echo '</ul>';
        }
        echo '</div></li>';
    }
    ?>
			</ul>
			<?php 
    ?>
			<div><?php 
    echo Kohana::lang('ui_main.no_reports');
    ?>
</div>
			<?php 
}
$i = 0;
foreach ($incidents as $incident) {
    $incident_id = $incident->id;
    $incident_title = text::limit_chars($incident->incident_title, 40, '...', True);
    $incident_date = $incident->incident_date;
    $incident_date = date('j M Y', strtotime($incident->incident_date));
    $incident_category = $incident->category->current() ? $incident->category->current()->category_title : '';
    if (isset($incident->media_thumb)) {
        $incident_video = url::convert_uploaded_to_abs($incident->media_thumb);
        ?>
		<div class="report <?php 
        echo "col-" . $i % 5;
        ?>
">
			<a href="<?php 
        echo url::site() . 'reports/view/' . $incident_id;
        ?>
"> 
			<div class="report-image"><img src="<?php 
        echo $incident_video;
        ?>
" width="160" /></div>
			<div  class="report-date"><?php 
        echo $incident_date;
 /**
  * Generate GEOJSON from incidents
  * 
  * @param ORM_Iterator|Database_Result|array $incidents collection of incidents
  * @param int $category_id
  * @param string $color
  * @param string $icon
  * @return array $json_features geojson features array
  **/
 protected function markers_geojson($incidents, $category_id, $color, $icon, $include_geometries = TRUE)
 {
     $json_features = array();
     // Extra params for markers only
     // Get the incidentid (to be added as first marker)
     $first_incident_id = (isset($_GET['i']) and intval($_GET['i']) > 0) ? intval($_GET['i']) : 0;
     $media_type = (isset($_GET['m']) and intval($_GET['m']) > 0) ? intval($_GET['m']) : 0;
     $incident_model = new Incident_Model();
     $all_categories = $incident_model::get_active_categories();
     foreach ($incidents as $marker) {
         // Handle both reports::fetch_incidents() response and actual ORM objects
         $marker->id = isset($marker->incident_id) ? $marker->incident_id : $marker->id;
         if (isset($marker->latitude) and isset($marker->longitude)) {
             $latitude = $marker->latitude;
             $longitude = $marker->longitude;
         } elseif (isset($marker->location) and isset($marker->location->latitude) and isset($marker->location->longitude)) {
             $latitude = $marker->location->latitude;
             $longitude = $marker->location->longitude;
         } else {
             // No location - skip this report
             continue;
         }
         // Get thumbnail
         $thumb = "";
         $media = ORM::factory('incident', $marker->id)->media;
         //Invisible Cities customisation
         //Requires to uncluster markers and present them in their category color
         // get category for incident, we only visualise the first category present in the incident - gotcha but ok
         $incident_category_result = ORM::factory('incident_category')->where(array('incident_id' => $marker->id))->find();
         if (array_key_exists($incident_category_result->category_id, $all_categories)) {
             //get category details
             $category_details = $all_categories[$incident_category_result->category_id];
             //get the color
             $color = $category_details[1];
         }
         //code for debugging
         // $categories = array();
         // foreach ($incident_categories_result as $category) {
         // 	// $category_details = ORM::factory('category', $category->category_id);
         // 	$category_details = $all_categories[$category->category_id];
         // 	$color = $category_details[1];
         // 	array_push($categories, array(
         // 		'category_id' => $category->category_id,
         // 		'color' => $category_details[1]
         // 		));
         // }
         if ($media->count()) {
             foreach ($media as $photo) {
                 if ($photo->media_thumb) {
                     // Get the first thumb
                     $thumb = url::convert_uploaded_to_abs($photo->media_thumb);
                     break;
                 }
             }
         }
         // Get URL from object, fallback to Incident_Model::get() if object doesn't have url or url()
         if (method_exists($marker, 'url')) {
             $link = $marker->url();
         } elseif (isset($marker->url)) {
             $link = $marker->url;
         } else {
             $link = Incident_Model::get_url($marker);
         }
         $item_name = $this->get_title($marker->incident_title, $link);
         $json_item = array();
         $json_item['type'] = 'Feature';
         $json_item['properties'] = array('id' => $marker->id, 'name' => $item_name, 'link' => $link, 'category' => array($category_id), 'color' => $color, 'icon' => $icon, 'thumb' => $thumb, 'timestamp' => strtotime($marker->incident_date), 'count' => 1, 'class' => get_class($marker), 'title' => $marker->incident_title);
         $json_item['geometry'] = array('type' => 'Point', 'coordinates' => array((double) $longitude, (double) $latitude));
         if ($marker->id == $first_incident_id) {
             array_unshift($json_features, $json_item);
         } else {
             array_push($json_features, $json_item);
         }
         // Get Incident Geometries
         if ($include_geometries) {
             $geometry = $this->get_geometry($marker->id, $marker->incident_title, $marker->incident_date, $link);
             if (count($geometry)) {
                 foreach ($geometry as $g) {
                     array_push($json_features, $g);
                 }
             }
         }
     }
     Event::run('ushahidi_filter.json_index_features', $json_features);
     return $json_features;
 }
Beispiel #11
0
 /**
  * Site Settings
  */
 function site()
 {
     $this->template->content = new View('admin/site');
     $this->template->content->title = Kohana::lang('ui_admin.settings');
     $this->template->js = new View('admin/site_js');
     // setup and initialize form field names
     $form = array('site_name' => '', 'site_tagline' => '', 'banner_image' => '', 'delete_banner_image' => '', 'site_email' => '', 'alerts_email' => '', 'site_language' => '', 'site_timezone' => '', 'site_message' => '', 'site_copyright_statement' => '', 'site_submit_report_message' => '', 'site_contact_page' => '', 'items_per_page' => '', 'items_per_page_admin' => '', 'blocks_per_row' => '', 'allow_alerts' => '', 'allow_reports' => '', 'allow_comments' => '', 'allow_feed' => '', 'allow_stat_sharing' => '', 'allow_clustering' => '', 'cache_pages' => '', 'cache_pages_lifetime' => '', 'private_deployment' => '', 'checkins' => '', 'default_map_all' => '', 'google_analytics' => '', 'twitter_hashtags' => '', 'api_akismet' => '');
     //	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;
     // Retrieve Current Settings
     $settings = ORM::factory('settings', 1);
     // check, has the form been submitted, if so, setup validation
     if ($_POST) {
         //print_r($_POST);exit;
         // Instantiate Validation, use $post, so we don't overwrite $_POST
         // fields with our own things
         $post = new Validation($_POST);
         // Add some filters
         $post->pre_filter('trim', TRUE);
         // Add some rules, the input field, followed by a list of checks, carried out in order
         $post->add_rules('site_name', 'required', 'length[3,250]');
         $post->add_rules('site_tagline', 'length[3,250]');
         $post->add_rules('site_email', 'email', 'length[4,100]');
         //$post->add_rules('alerts_email','required', 'email', 'length[4,100]');
         //$post->add_rules('site_message', 'standard_text');
         $post->add_rules('site_copyright_statement', 'length[4,600]');
         $post->add_rules('site_language', 'required', 'length[5, 5]');
         //$post->add_rules('site_timezone','required', 'between[10,50]');
         $post->add_rules('site_contact_page', 'required', 'between[0,1]');
         $post->add_rules('items_per_page', 'required', 'between[10,50]');
         $post->add_rules('items_per_page_admin', 'required', 'between[10,50]');
         $post->add_rules('blocks_per_row', 'required', 'numeric');
         $post->add_rules('allow_alerts', 'required', 'between[0,1]');
         $post->add_rules('allow_reports', 'required', 'between[0,1]');
         $post->add_rules('allow_comments', 'required', 'between[0,2]');
         $post->add_rules('allow_feed', 'required', 'between[0,1]');
         $post->add_rules('allow_stat_sharing', 'required', 'between[0,1]');
         $post->add_rules('allow_clustering', 'required', 'between[0,1]');
         $post->add_rules('cache_pages', 'required', 'between[0,1]');
         $post->add_rules('cache_pages_lifetime', 'required', 'in_array[300,600,900,1800]');
         $post->add_rules('private_deployment', 'required', 'between[0,1]');
         $post->add_rules('checkins', 'required', 'between[0,1]');
         $post->add_rules('default_map_all', 'required', 'alpha_numeric', 'length[6,6]');
         $post->add_rules('google_analytics', 'length[0,20]');
         $post->add_rules('twitter_hashtags', 'length[0,500]');
         $post->add_rules('api_akismet', 'length[0,100]', 'alpha_numeric');
         // Add rules for file upload
         $files = Validation::factory($_FILES);
         $files->add_rules('banner_image', 'upload::valid', 'upload::type[gif,jpg,png]', 'upload::size[250K]');
         // Test to see if things passed the rule checks
         if ($post->validate() and $files->validate()) {
             // Yes! everything is valid
             $settings = new Settings_Model(1);
             $settings->site_name = $post->site_name;
             $settings->site_tagline = $post->site_tagline;
             $settings->site_email = $post->site_email;
             $settings->alerts_email = $post->alerts_email;
             $settings->site_message = $post->site_message;
             $settings->site_copyright_statement = $post->site_copyright_statement;
             $settings->site_submit_report_message = $post->site_submit_report_message;
             $settings->site_language = $post->site_language;
             $settings->site_timezone = $post->site_timezone;
             if ($settings->site_timezone == "0") {
                 // "0" is the "Server Timezone" setting and it needs to be null in the db
                 $settings->site_timezone = NULL;
             }
             $settings->site_contact_page = $post->site_contact_page;
             $settings->items_per_page = $post->items_per_page;
             $settings->items_per_page_admin = $post->items_per_page_admin;
             $settings->blocks_per_row = $post->blocks_per_row;
             $settings->allow_alerts = $post->allow_alerts;
             $settings->allow_reports = $post->allow_reports;
             $settings->allow_comments = $post->allow_comments;
             $settings->allow_feed = $post->allow_feed;
             $settings->allow_stat_sharing = $post->allow_stat_sharing;
             $settings->allow_clustering = $post->allow_clustering;
             $settings->cache_pages = $post->cache_pages;
             $settings->cache_pages_lifetime = $post->cache_pages_lifetime;
             $settings->private_deployment = $post->private_deployment;
             $settings->checkins = $post->checkins;
             $settings->default_map_all = $post->default_map_all;
             $settings->google_analytics = $post->google_analytics;
             $settings->twitter_hashtags = $post->twitter_hashtags;
             $settings->api_akismet = $post->api_akismet;
             $settings->date_modify = date("Y-m-d H:i:s", time());
             $settings->save();
             // Deal with banner image now
             // Check if deleting or updating a new image (or doing nothing)
             if (isset($post->delete_banner_image) and $post->delete_banner_image == 1) {
                 // Delete old badge image
                 ORM::factory('media')->delete($settings->site_banner_id);
                 // Remove from DB table
                 $settings = new Settings_Model(1);
                 $settings->site_banner_id = NULL;
                 $settings->save();
             } else {
                 // We aren't deleting, so try to upload if we are uploading an image
                 $filename = upload::save('banner_image');
                 if ($filename) {
                     $new_filename = "banner_" . time();
                     $file_type = strrev(substr(strrev($filename), 0, 4));
                     // Large size
                     $l_name = $new_filename . $file_type;
                     Image::factory($filename)->save(Kohana::config('upload.directory', TRUE) . $l_name);
                     // Medium size
                     $m_name = $new_filename . "_m" . $file_type;
                     Image::factory($filename)->resize(80, 80, Image::HEIGHT)->save(Kohana::config('upload.directory', TRUE) . $m_name);
                     // Thumbnail
                     $t_name = $new_filename . "_t" . $file_type;
                     Image::factory($filename)->resize(60, 60, Image::HEIGHT)->save(Kohana::config('upload.directory', TRUE) . $t_name);
                     // Name the files for the DB
                     $media_link = $l_name;
                     $media_medium = $m_name;
                     $media_thumb = $t_name;
                     // Okay, now we have these three different files on the server, now check to see
                     //   if we should be dropping them on the CDN
                     if (Kohana::config("cdn.cdn_store_dynamic_content")) {
                         $media_link = cdn::upload($media_link);
                         $media_medium = cdn::upload($media_medium);
                         $media_thumb = cdn::upload($media_thumb);
                         // We no longer need the files we created on the server. Remove them.
                         $local_directory = rtrim(Kohana::config('upload.directory', TRUE), '/') . '/';
                         unlink($local_directory . $l_name);
                         unlink($local_directory . $m_name);
                         unlink($local_directory . $t_name);
                     }
                     // Remove the temporary file
                     unlink($filename);
                     // Save banner image in the media table
                     $media = new Media_Model();
                     $media->media_type = 1;
                     // Image
                     $media->media_link = $media_link;
                     $media->media_medium = $media_medium;
                     $media->media_thumb = $media_thumb;
                     $media->media_date = date("Y-m-d H:i:s", time());
                     $media->save();
                     // Save new banner image in settings
                     $settings = new Settings_Model(1);
                     $settings->site_banner_id = $media->id;
                     $settings->save();
                 }
             }
             // Delete Settings Cache
             $this->cache->delete('settings');
             $this->cache->delete_tag('settings');
             // Everything is A-Okay!
             $form_saved = TRUE;
             // Action::site_settings_modified - Site settings have changed
             Event::run('ushahidi_action.site_settings_modified');
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
         } else {
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // populate the error fields, if any
             if (is_array($files->errors()) and count($files->errors()) > 0) {
                 // Error with file upload
                 $errors = arr::overwrite($errors, $files->errors('settings'));
             } else {
                 // Error with other form filed
                 $errors = arr::overwrite($errors, $post->errors('settings'));
             }
             $form_error = TRUE;
         }
     } else {
         $form = array('site_name' => $settings->site_name, 'site_tagline' => $settings->site_tagline, 'site_banner_id' => $settings->site_banner_id, 'site_email' => $settings->site_email, 'alerts_email' => $settings->alerts_email, 'site_message' => $settings->site_message, 'site_copyright_statement' => $settings->site_copyright_statement, 'site_submit_report_message' => $settings->site_submit_report_message, 'site_language' => $settings->site_language, 'site_timezone' => $settings->site_timezone, 'site_contact_page' => $settings->site_contact_page, 'items_per_page' => $settings->items_per_page, 'items_per_page_admin' => $settings->items_per_page_admin, 'blocks_per_row' => $settings->blocks_per_row, 'allow_alerts' => $settings->allow_alerts, 'allow_reports' => $settings->allow_reports, 'allow_comments' => $settings->allow_comments, 'allow_feed' => $settings->allow_feed, 'allow_stat_sharing' => $settings->allow_stat_sharing, 'allow_clustering' => $settings->allow_clustering, 'cache_pages' => $settings->cache_pages, 'cache_pages_lifetime' => $settings->cache_pages_lifetime, 'private_deployment' => $settings->private_deployment, 'checkins' => $settings->checkins, 'default_map_all' => $settings->default_map_all, 'google_analytics' => $settings->google_analytics, 'twitter_hashtags' => $settings->twitter_hashtags, 'api_akismet' => $settings->api_akismet);
     }
     // Get banner image
     if ($settings->site_banner_id != NULL) {
         $banner = ORM::factory('media')->find($settings->site_banner_id);
         $this->template->content->banner = url::convert_uploaded_to_abs($banner->media_link);
         $this->template->content->banner_m = url::convert_uploaded_to_abs($banner->media_medium);
         $this->template->content->banner_t = url::convert_uploaded_to_abs($banner->media_thumb);
     } else {
         $this->template->content->banner = NULL;
         $this->template->content->banner_m = NULL;
         $this->template->content->banner_t = NULL;
     }
     $this->template->colorpicker_enabled = TRUE;
     $this->template->content->form = $form;
     $this->template->content->errors = $errors;
     $this->template->content->form_error = $form_error;
     $this->template->content->form_saved = $form_saved;
     $this->template->content->items_per_page_array = array('10' => '10 Items', '20' => '20 Items', '30' => '30 Items', '50' => '50 Items');
     $blocks_per_row_array = array();
     for ($i = 1; $i <= 21; $i++) {
         $blocks_per_row_array[$i] = $i;
     }
     $this->template->content->blocks_per_row_array = $blocks_per_row_array;
     $this->template->content->yesno_array = array('1' => strtoupper(Kohana::lang('ui_main.yes')), '0' => strtoupper(Kohana::lang('ui_main.no')));
     $this->template->content->comments_array = array('1' => strtoupper(Kohana::lang('ui_main.yes') . " - " . Kohana::lang('ui_admin.approve_auto')), '2' => strtoupper(Kohana::lang('ui_main.yes') . " - " . Kohana::lang('ui_admin.approve_manual')), '0' => strtoupper(Kohana::lang('ui_main.no')));
     $this->template->content->cache_pages_lifetime_array = array('300' => '5 ' . Kohana::lang('ui_admin.minutes'), '600' => '10 ' . Kohana::lang('ui_admin.minutes'), '900' => '15 ' . Kohana::lang('ui_admin.minutes'), '1800' => '30 ' . Kohana::lang('ui_admin.minutes'));
     //Generate all timezones
     $site_timezone_array = array();
     $site_timezone_array[0] = Kohana::lang('ui_admin.server_time');
     foreach (timezone_identifiers_list() as $timezone) {
         $site_timezone_array[$timezone] = $timezone;
     }
     $this->template->content->site_timezone_array = $site_timezone_array;
     // Generate Available Locales
     $locales = locale::get_i18n();
     $this->template->content->locales_array = $locales;
     $this->cache->set('locales', $locales, array('locales'), 604800);
 }
 private function add_data_to_category($category_array)
 {
     if ($category_array['parent_id']) {
         $category_array['parent_id'] = array($category_array['parent_id'] => array('api_url' => url::site(rest_controller::$api_base_url . '/categories/' . $category_array['parent_id'])));
     }
     $category_array['api_url'] = url::site(rest_controller::$api_base_url . '/categories/' . $category_array['id']);
     $category_array['category_image'] = $category_array['category_image'] ? url::convert_uploaded_to_abs($category_array['category_image']) : $category_array['category_image'];
     $category_array['category_image_thumb'] = $category_array['category_image_thumb'] ? url::convert_uploaded_to_abs($category_array['category_image_thumb']) : $category_array['category_image_thumb'];
     // No date attached to categories so always now
     $category_array['updated_at'] = date_create()->format(DateTime::W3C);
     return $category_array;
 }
 public function gather_checkins($id, $user_id, $mobileid, $mapdata)
 {
     $data = array();
     if ($mobileid != '') {
         $find_user = ORM::factory('user_devices')->find($mobileid);
         $user_id = $find_user->user_id;
     }
     if ($user_id == '') {
         $where_user_id = array('checkin.user_id !=' => '-1');
     } else {
         $where_user_id = array('checkin.user_id' => $user_id);
     }
     if ($id == '') {
         $where_id = array('checkin.id !=' => '-1');
     } else {
         $where_id = array('checkin.id' => $id);
     }
     $orderby = 'checkin.id';
     if (isset($this->request['orderby'])) {
         $orderby = $this->request['orderby'];
     }
     $sort = 'ASC';
     if (isset($this->request['sort'])) {
         $sort = $this->request['sort'];
     }
     $since_id = 0;
     if (isset($this->request['sinceid'])) {
         $since_id = $this->request['sinceid'];
     }
     //echo $this->request['sqllimit'];
     $limit = 20;
     if (isset($this->request['sqllimit'])) {
         $limit = $this->request['sqllimit'];
     }
     $offset = 0;
     if (isset($this->request['sqloffset'])) {
         $offset = $this->request['sqloffset'];
     }
     $checkins = ORM::factory('checkin')->select('DISTINCT checkin.*')->where($where_id)->where($where_user_id)->where('checkin.id >=', $since_id)->with('user')->with('location')->orderby($orderby, $sort)->find_all($limit, $offset);
     $seen_latest_ci = array();
     $users_names = array();
     $i = 0;
     foreach ($checkins as $checkin) {
         $data["checkins"][$i] = array("id" => $checkin->id, "user" => array("id" => $checkin->user_id, "username" => $checkin->user->username, "name" => $checkin->user->name, "color" => $checkin->user->color), "loc" => $checkin->location_id, "msg" => $checkin->checkin_description, "date" => $checkin->checkin_date, "lat" => $checkin->location->latitude, "lon" => $checkin->location->longitude);
         $j = 0;
         foreach ($checkin->media as $media) {
             $data["checkins"][$i]['media'][(int) $j] = array("id" => $media->id, "type" => $media->media_type, "link" => url::convert_uploaded_to_abs($media->media_link), "medium" => url::convert_uploaded_to_abs($media->media_medium), "thumb" => url::convert_uploaded_to_abs($media->media_thumb));
             $j++;
         }
         $j = 0;
         foreach ($checkin->comment as $comment) {
             if ($comment->user_id != 0) {
                 $author = $comment->user->name;
                 $email = $comment->user->email;
                 $username = $comment->user->username;
             } else {
                 $author = $comment->comment_author;
                 $email = $comment->comment_email;
                 $username = '';
             }
             $data["checkins"][$i]['comments'][(int) $j] = array("id" => $comment->id, "user_id" => $comment->user_id, "author" => $author, "email" => $email, "username" => $username, "description" => $comment->comment_description, "date" => $comment->comment_date);
             $j++;
         }
         // If we are displaying some extra map data...
         if ($mapdata != '') {
             if (!isset($seen_latest_ci[$checkin->user_id])) {
                 $opacity = 1;
             } else {
                 $opacity = 0.5;
             }
             $seen_latest_ci[$checkin->user_id] = $checkin->user_id;
             $data["checkins"][$i]['opacity'] = $opacity;
         }
         $i++;
     }
     // foreach ($users_names as $user_data)
     // {
     // 	$data["users"][] = $user_data;
     // }
     return $data;
 }
    // Why they feel this way and how they would change it are custom form fields
    $why_feel = '';
    $change_place = '';
    $custom_data = customforms::get_custom_form_fields($incident_id);
    foreach ($custom_data as $custom) {
        switch ($custom['field_id']) {
            case '1':
                $why_feel = text::limit_chars(html::strip_tags($custom['field_response']), 100, '...', True);
            case '2':
                $change_place = text::limit_chars(html::strip_tags($custom['field_response']), 100, '...', True);
        }
    }
    $incident_image = false;
    foreach ($incident->media as $media) {
        if ($media->media_type == 1) {
            $incident_image = url::convert_uploaded_to_abs($media->media_thumb);
        }
    }
    ?>
		<tr>
			<td><a href="<?php 
    echo url::site() . 'reports/view/' . $incident_id;
    ?>
"> <?php 
    echo $incident_title;
    ?>
</a></td>
			<td><?php 
    echo html::escape($how_feel);
    ?>
</td>
Beispiel #15
0
 /**
  * Traverses an array containing category data and returns a tree view
  *
  * @param array $category_data
  * @return string
  */
 private static function _generate_treeview_html($category_data)
 {
     // To hold the treeview HTMl
     $tree_html = "";
     foreach ($category_data as $id => $category) {
         // Determine the category class
         $category_class = $category['parent_id'] > 0 ? " class=\"report-listing-category-child\"" : "";
         $category_image = $category['category_image_thumb'] ? html::image(array('src' => url::convert_uploaded_to_abs($category['category_image_thumb']), 'style' => 'float:left;padding-right:5px;')) : NULL;
         $tree_html .= "<li" . $category_class . ">" . "<a href=\"#\" class=\"cat_selected\" id=\"filter_link_cat_" . $id . "\" title=\"{$category['category_description']}\">" . "<span class=\"item-swatch\" style=\"background-color: #" . $category['category_color'] . "\">{$category_image}</span>" . "<span class=\"item-title\">" . html::strip_tags($category['category_title']) . "</span>" . "<span class=\"item-count\">" . $category['report_count'] . "</span>" . "</a></li>";
         $tree_html .= self::_generate_treeview_html($category['children']);
     }
     // Return
     return $tree_html;
 }
Beispiel #16
0
 /**
  * Generate JSON in CLUSTER mode
  */
 public function cluster()
 {
     // Database
     $db = new Database();
     $json = '';
     $json_item = array();
     $json_features = array();
     $geometry_array = array();
     $color = Kohana::config('settings.default_map_all');
     $icon = "";
     if (Kohana::config('settings.default_map_all_icon_id')) {
         $icon_object = ORM::factory('media')->find(Kohana::config('settings.default_map_all_icon_id'));
         $icon = url::convert_uploaded_to_abs($icon_object->media_medium);
     }
     // Get Zoom Level
     $zoomLevel = (isset($_GET['z']) and !empty($_GET['z'])) ? (int) $_GET['z'] : 8;
     //$distance = 60;
     $distance = (10000000 >> $zoomLevel) / 100000;
     // Fetch the incidents using the specified parameters
     $incidents = reports::fetch_incidents();
     // Category ID
     $category_id = (isset($_GET['c']) and intval($_GET['c']) > 0) ? intval($_GET['c']) : 0;
     // Start date
     $start_date = (isset($_GET['s']) and intval($_GET['s']) > 0) ? intval($_GET['s']) : NULL;
     // End date
     $end_date = (isset($_GET['e']) and intval($_GET['e']) > 0) ? intval($_GET['e']) : NULL;
     if (Category_Model::is_valid_category($category_id)) {
         // Get the color & icon
         $cat = ORM::factory('category', $category_id);
         $color = $cat->category_color;
         if ($cat->category_image) {
             $icon = url::convert_uploaded_to_abs($cat->category_image);
         }
     }
     // Create markers by marrying the locations and incidents
     $markers = array();
     foreach ($incidents as $incident) {
         $markers[] = array('id' => $incident->incident_id, 'incident_title' => $incident->incident_title, 'latitude' => $incident->latitude, 'longitude' => $incident->longitude, 'thumb' => '');
     }
     $clusters = array();
     // Clustered
     $singles = array();
     // Non Clustered
     // Loop until all markers have been compared
     while (count($markers)) {
         $marker = array_pop($markers);
         $cluster = array();
         // Compare marker against all remaining markers.
         foreach ($markers as $key => $target) {
             // This function returns the distance between two markers, at a defined zoom level.
             // $pixels = $this->_pixelDistance($marker['latitude'], $marker['longitude'],
             // $target['latitude'], $target['longitude'], $zoomLevel);
             $pixels = abs($marker['longitude'] - $target['longitude']) + abs($marker['latitude'] - $target['latitude']);
             // If two markers are closer than defined distance, remove compareMarker from array and add to cluster.
             if ($pixels < $distance) {
                 unset($markers[$key]);
                 $target['distance'] = $pixels;
                 $cluster[] = $target;
             }
         }
         // If a marker was added to cluster, also add the marker we were comparing to.
         if (count($cluster) > 0) {
             $cluster[] = $marker;
             $clusters[] = $cluster;
         } else {
             $singles[] = $marker;
         }
     }
     // Create Json
     foreach ($clusters as $cluster) {
         // Calculate cluster center
         $bounds = $this->calculate_center($cluster);
         $cluster_center = array_values($bounds['center']);
         $southwest = $bounds['sw']['longitude'] . ',' . $bounds['sw']['latitude'];
         $northeast = $bounds['ne']['longitude'] . ',' . $bounds['ne']['latitude'];
         // Number of Items in Cluster
         $cluster_count = count($cluster);
         // Get the time filter
         $time_filter = (!empty($start_date) and !empty($end_date)) ? "&s=" . $start_date . "&e=" . $end_date : "";
         // Build out the JSON string
         $link = url::base() . "reports/index/?c=" . $category_id . "&sw=" . $southwest . "&ne=" . $northeast . $time_filter;
         $item_name = $this->get_title(Kohana::lang('ui_main.reports_count', $cluster_count), $link);
         $json_item = array();
         $json_item['type'] = 'Feature';
         $json_item['properties'] = array('name' => $item_name, 'link' => $link, 'category' => array($category_id), 'color' => $color, 'icon' => $icon, 'thumb' => '', 'timestamp' => 0, 'count' => $cluster_count);
         $json_item['geometry'] = array('type' => 'Point', 'coordinates' => $cluster_center);
         array_push($json_features, $json_item);
     }
     foreach ($singles as $single) {
         $link = url::base() . "reports/view/" . $single['id'];
         $item_name = $this->get_title($single['incident_title'], $link);
         $json_item = array();
         $json_item['type'] = 'Feature';
         $json_item['properties'] = array('name' => $item_name, 'link' => $link, 'category' => array($category_id), 'color' => $color, 'icon' => $icon, 'thumb' => '', 'timestamp' => 0, 'count' => 1);
         $json_item['geometry'] = array('type' => 'Point', 'coordinates' => array($single['longitude'], $single['latitude']));
         array_push($json_features, $json_item);
     }
     //
     // E.Kala July 27, 2011
     // @todo Parking this geometry business for review
     //
     // if (count($geometry_array))
     // {
     // 	$json = implode(",", $geometry_array).",".$json;
     // }
     Event::run('ushahidi_filter.json_cluster_features', $json_features);
     $json = json_encode(array("type" => "FeatureCollection", "features" => $json_features));
     header('Content-type: application/json; charset=utf-8');
     echo $json;
 }
Beispiel #17
0
												</div>
												<?php 
    }
    ?>
												
											</td>
										</tr>
										<?php 
    // Get All Category Children
    foreach ($category->children as $child) {
        $category_id = $child->id;
        $parent_id = $child->parent_id;
        $category_title = Category_Lang_Model::category_title($category_id);
        $category_description = substr(Category_Lang_Model::category_description($category_id), 0, 150);
        $category_color = $child->category_color;
        $category_image = $child->category_image != NULL ? url::convert_uploaded_to_abs($child->category_image) : NULL;
        $category_visible = $child->category_visible;
        $fillFields = array();
        $fillFields['category_id'] = $child->id;
        $fillFields['parent_id'] = $child->parent_id;
        $fillFields['category_title'] = $child->category_title;
        $fillFields['category_description'] = $child->category_description;
        $fillFields['category_color'] = $child->category_color;
        $fillFields['category_image'] = $child->category_image;
        $fillFields['locale'] = $category->locale;
        $fillFields['category_langs'] = array();
        foreach ($child->category_lang as $category_lang) {
            $fillFields['category_langs'][$category_lang->locale] = array('category_title' => $category_lang->category_title, 'category_description' => $category_lang->category_description);
        }
        ?>
											<tr id="<?php 
Beispiel #18
0
 /**
  * Map Settings
  */
 function index($saved = false)
 {
     // Display all maps
     $this->template->api_url = Kohana::config('settings.api_url_all');
     // Current Default Country
     $current_country = Kohana::config('settings.default_country');
     $this->template->content = new View('admin/settings');
     $this->template->content->title = Kohana::lang('ui_admin.settings');
     // setup and initialize form field names
     $form = array('default_map' => '', 'api_google' => '', 'api_live' => '', 'default_country' => '', 'multi_country' => '', 'default_lat' => '', 'default_lon' => '', 'default_zoom' => '', 'default_map_all' => '', 'allow_clustering' => '', 'default_map_all_icon' => '', 'delete_default_map_all_icon' => '');
     //	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 = $saved == 'saved';
     // 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)->pre_filter('trim', TRUE)->add_rules('default_country', 'required', 'numeric', 'length[1,4]')->add_rules('multi_country', 'numeric', 'length[1,1]')->add_rules('default_map', 'required', 'length[0,100]')->add_rules('default_zoom', 'required', 'between[0,21]')->add_rules('default_lat', 'required', 'between[-85,85]')->add_rules('default_lon', 'required', 'between[-180,180]')->add_rules('allow_clustering', 'required', 'between[0,1]')->add_rules('default_map_all', 'required', 'alpha_numeric', 'length[6,6]')->add_rules('api_google', 'length[0,200]')->add_rules('api_live', 'length[0,200]');
         // Add rules for file upload
         $files = Validation::factory($_FILES);
         $files->add_rules('default_map_all_icon', 'upload::valid', 'upload::type[gif,jpg,png]', 'upload::size[250K]');
         // Test to see if things passed the rule checks
         if ($post->validate() and $files->validate(FALSE)) {
             // Yes! everything is valid
             $settings = new Settings_Model(1);
             $settings->default_country = $post->default_country;
             $settings->multi_country = $post->multi_country;
             $settings->default_map = $post->default_map;
             $settings->api_google = $post->api_google;
             // E.Kala 20th April 2012
             // Gangsta workaround prevent resetting og Bing Maps API Key
             // Soon to be addressed conclusively
             if (isset($post['api_live']) and !empty($post['api_live'])) {
                 $settings->api_live = $post->api_live;
             }
             $settings->default_zoom = $post->default_zoom;
             $settings->default_lat = $post->default_lat;
             $settings->default_lon = $post->default_lon;
             $settings->allow_clustering = $post->allow_clustering;
             $settings->default_map_all = $post->default_map_all;
             $settings->date_modify = date("Y-m-d H:i:s", time());
             $settings->save();
             // Deal with default category icon now
             // Check if deleting or updating a new image (or doing nothing)
             if (isset($post->delete_default_map_all_icon) and $post->delete_default_map_all_icon == 1) {
                 // Delete old badge image
                 ORM::factory('media')->delete($settings->default_map_all_icon_id);
                 // Remove from DB table
                 $settings = new Settings_Model(1);
                 $settings->default_map_all_icon_id = NULL;
                 $settings->save();
             } else {
                 // We aren't deleting, so try to upload if we are uploading an image
                 $filename = upload::save('default_map_all_icon');
                 if ($filename) {
                     $new_filename = "default_map_all_" . time();
                     $file_type = strrev(substr(strrev($filename), 0, 4));
                     // Large size
                     $l_name = $new_filename . $file_type;
                     Image::factory($filename)->save(Kohana::config('upload.directory', TRUE) . $l_name);
                     // Medium size
                     $m_name = $new_filename . "_m" . $file_type;
                     Image::factory($filename)->resize(32, 32, Image::HEIGHT)->save(Kohana::config('upload.directory', TRUE) . $m_name);
                     // Thumbnail
                     $t_name = $new_filename . "_t" . $file_type;
                     Image::factory($filename)->resize(16, 16, Image::HEIGHT)->save(Kohana::config('upload.directory', TRUE) . $t_name);
                     // Name the files for the DB
                     $media_link = $l_name;
                     $media_medium = $m_name;
                     $media_thumb = $t_name;
                     // Okay, now we have these three different files on the server, now check to see
                     //   if we should be dropping them on the CDN
                     if (Kohana::config("cdn.cdn_store_dynamic_content")) {
                         $media_link = cdn::upload($media_link);
                         $media_medium = cdn::upload($media_medium);
                         $media_thumb = cdn::upload($media_thumb);
                         // We no longer need the files we created on the server. Remove them.
                         $local_directory = rtrim(Kohana::config('upload.directory', TRUE), '/') . '/';
                         unlink($local_directory . $l_name);
                         unlink($local_directory . $m_name);
                         unlink($local_directory . $t_name);
                     }
                     // Remove the temporary file
                     unlink($filename);
                     // Save image in the media table
                     $media = new Media_Model();
                     $media->media_type = 1;
                     // Image
                     $media->media_link = $media_link;
                     $media->media_medium = $media_medium;
                     $media->media_thumb = $media_thumb;
                     $media->media_date = date("Y-m-d H:i:s", time());
                     $media->save();
                     // Save new image in settings
                     $settings = new Settings_Model(1);
                     $settings->default_map_all_icon_id = $media->id;
                     $settings->save();
                 }
             }
             // Delete Settings Cache
             $this->cache->delete('settings');
             $this->cache->delete_tag('settings');
             // Everything is A-Okay!
             $form_saved = TRUE;
             // Action::map_settings_modified - Map settings have changed
             Event::run('ushahidi_action.map_settings_modified');
             // Redirect to reload everything over again
             url::redirect('admin/settings/index/saved');
         } else {
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // populate the error fields, if any
             $errors = arr::overwrite($errors, $post->errors('settings'));
             $form_error = TRUE;
         }
     } else {
         // Retrieve Current Settings
         $settings = ORM::factory('settings', 1);
         $form = array('default_map' => $settings->default_map, 'api_google' => $settings->api_google, 'api_live' => $settings->api_live, 'default_country' => $settings->default_country, 'multi_country' => $settings->multi_country, 'default_lat' => $settings->default_lat, 'default_lon' => $settings->default_lon, 'default_zoom' => $settings->default_zoom, 'allow_clustering' => $settings->allow_clustering, 'default_map_all' => $settings->default_map_all, 'default_map_all_icon_id' => $settings->default_map_all_icon_id);
     }
     // Get default category image
     $settings = ORM::factory('settings', 1);
     if ($settings->default_map_all_icon_id != NULL) {
         $icon = ORM::factory('media')->find($settings->default_map_all_icon_id);
         $this->template->content->default_map_all_icon = url::convert_uploaded_to_abs($icon->media_link);
         $this->template->content->default_map_all_icon_m = url::convert_uploaded_to_abs($icon->media_medium);
         $this->template->content->default_map_all_icon_t = url::convert_uploaded_to_abs($icon->media_thumb);
     } else {
         $this->template->content->default_map_all_icon = NULL;
         $this->template->content->default_map_all_icon_m = NULL;
         $this->template->content->default_map_all_icon_t = NULL;
     }
     $this->template->content->form = $form;
     $this->template->content->errors = $errors;
     $this->template->content->form_error = $form_error;
     $this->template->content->form_saved = $form_saved;
     // 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, 30) . "...";
         }
         $countries[$country->id] = $this_country;
     }
     $this->template->content->countries = $countries;
     // Zoom Array for Slider
     $default_zoom_array = array();
     for ($i = Kohana::config('map.minZoomLevel'); $i < Kohana::config('map.minZoomLevel') + Kohana::config('map.numZoomLevels'); $i++) {
         $default_zoom_array[$i] = $i;
     }
     $this->template->content->default_zoom_array = $default_zoom_array;
     // Get Map API Providers
     $layers = map::base();
     $map_array = array();
     foreach ($layers as $layer) {
         $map_array[$layer->name] = $layer->title;
     }
     $this->template->content->map_array = $map_array;
     $this->template->content->yesno_array = array('1' => strtoupper(Kohana::lang('ui_main.yes')), '0' => strtoupper(Kohana::lang('ui_main.no')));
     // Javascript Header
     $this->template->map_enabled = TRUE;
     $this->template->colorpicker_enabled = TRUE;
     $this->template->js = new View('admin/settings_js');
     $this->template->js->default_map = $form['default_map'];
     $this->template->js->default_zoom = $form['default_zoom'];
     $this->template->js->default_lat = $form['default_lat'];
     $this->template->js->default_lon = $form['default_lon'];
     $this->template->js->all_maps_json = $this->_generate_settings_map_js();
 }
 /**
  * Displays a report.
  * @param boolean $id If id is supplied, a report with that id will be
  * retrieved.
  */
 public function view($id = FALSE)
 {
     $this->template->header->this_page = 'reports';
     $this->template->content = new View('reports/detail');
     // Load Akismet API Key (Spam Blocker)
     $api_akismet = Kohana::config('settings.api_akismet');
     // Sanitize the report id before proceeding
     $id = intval($id);
     if ($id > 0) {
         $incident = ORM::factory('sharing_incident')->where('id', $id)->where('incident_active', 1)->find();
         // Not Found
         if (!$incident->loaded) {
             url::redirect('reports/');
         }
         // Comment Post?
         // Setup and initialize form field names
         $form = array('comment_author' => '', 'comment_description' => '', 'comment_email' => '', 'comment_ip' => '', 'captcha' => '');
         $captcha = Captcha::factory();
         $errors = $form;
         $form_error = FALSE;
         // Check, has the form been submitted, if so, setup validation
         if ($_POST and Kohana::config('settings.allow_comments')) {
             // 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
             if (!$this->user) {
                 $post->add_rules('comment_author', 'required', 'length[3,100]');
                 $post->add_rules('comment_email', 'required', 'email', 'length[4,100]');
             }
             $post->add_rules('comment_description', 'required');
             $post->add_rules('captcha', 'required', 'Captcha::valid');
             // Test to see if things passed the rule checks
             if ($post->validate()) {
                 // Yes! everything is valid
                 if ($api_akismet != "") {
                     // Run Akismet Spam Checker
                     $akismet = new Akismet();
                     // Comment data
                     $comment = array('website' => "", 'body' => $post->comment_description, 'user_ip' => $_SERVER['REMOTE_ADDR']);
                     if ($this->user) {
                         $comment['author'] = $this->user->name;
                         $comment['email'] = $this->user->email;
                     } else {
                         $comment['author'] = $post->comment_author;
                         $comment['email'] = $post->comment_email;
                     }
                     $config = array('blog_url' => url::site(), 'api_key' => $api_akismet, 'comment' => $comment);
                     $akismet->init($config);
                     if ($akismet->errors_exist()) {
                         if ($akismet->is_error('AKISMET_INVALID_KEY')) {
                             // throw new Kohana_Exception('akismet.api_key');
                         } elseif ($akismet->is_error('AKISMET_RESPONSE_FAILED')) {
                             // throw new Kohana_Exception('akismet.server_failed');
                         } elseif ($akismet->is_error('AKISMET_SERVER_NOT_FOUND')) {
                             // throw new Kohana_Exception('akismet.server_not_found');
                         }
                         $comment_spam = 0;
                     } else {
                         $comment_spam = $akismet->is_spam() ? 1 : 0;
                     }
                 } else {
                     // No API Key!!
                     $comment_spam = 0;
                 }
                 $comment = new Comment_Model();
                 $comment->incident_id = 0;
                 if ($this->user) {
                     $comment->user_id = $this->user->id;
                     $comment->comment_author = $this->user->name;
                     $comment->comment_email = $this->user->email;
                 } else {
                     $comment->comment_author = strip_tags($post->comment_author);
                     $comment->comment_email = strip_tags($post->comment_email);
                 }
                 $comment->comment_description = strip_tags($post->comment_description);
                 $comment->comment_ip = $_SERVER['REMOTE_ADDR'];
                 $comment->comment_date = date("Y-m-d H:i:s", time());
                 // Activate comment for now
                 if ($comment_spam == 1) {
                     $comment->comment_spam = 1;
                     $comment->comment_active = 0;
                 } else {
                     $comment->comment_spam = 0;
                     $comment->comment_active = Kohana::config('settings.allow_comments') == 1 ? 1 : 0;
                 }
                 $comment->save();
                 // link comment to sharing_incident
                 $incident_comment = ORM::factory('sharing_incident_comment');
                 $incident_comment->comment_id = $comment->id;
                 $incident_comment->sharing_incident_id = $incident->id;
                 $incident_comment->save();
                 // Event::comment_add - Added a New Comment
                 Event::run('ushahidi_action.comment_add', $comment);
                 // Notify Admin Of New Comment
                 $send = notifications::notify_admins("[" . Kohana::config('settings.site_name') . "] " . Kohana::lang('notifications.admin_new_comment.subject'), Kohana::lang('notifications.admin_new_comment.message') . "\n\n'" . utf8::strtoupper($incident->incident_title) . "'" . "\n" . url::base() . 'reports/sharing/view/' . $id);
                 // Redirect
                 url::redirect('reports/sharing/view/' . $id);
             } else {
                 // No! We have validation errors, we need to show the form again, with the errors
                 // Repopulate the form fields
                 $form = arr::overwrite($form, $post->as_array());
                 // Populate the error fields, if any
                 $errors = arr::overwrite($errors, $post->errors('comments'));
                 $form_error = TRUE;
             }
         }
         // Filters
         $incident_title = $incident->incident_title;
         $incident_description = $incident->incident_description;
         Event::run('ushahidi_filter.report_title', $incident_title);
         Event::run('ushahidi_filter.report_description', $incident_description);
         $this->template->header->page_title .= $incident_title . Kohana::config('settings.title_delimiter');
         // Add Features
         // hardcode geometries to empty
         $this->template->content->features_count = 0;
         $this->template->content->features = array();
         $this->template->content->incident_id = $incident->id;
         $this->template->content->incident_title = $incident_title;
         $this->template->content->incident_description = $incident_description;
         $this->template->content->incident_location = $incident->location->location_name;
         $this->template->content->incident_latitude = $incident->location->latitude;
         $this->template->content->incident_longitude = $incident->location->longitude;
         $this->template->content->incident_date = date('M j Y', strtotime($incident->incident_date));
         $this->template->content->incident_time = date('H:i', strtotime($incident->incident_date));
         $this->template->content->incident_category = ORM::factory('sharing_incident_category')->where('sharing_incident_id', $incident->id)->find_all();
         // Incident rating
         $rating = ORM::factory('rating')->join('incident', 'incident.id', 'rating.incident_id', 'INNER')->where('rating.incident_id', $incident->id)->find();
         $this->template->content->incident_rating = $rating->rating == '' ? 0 : $rating->rating;
         // Retrieve Media
         $incident_news = array();
         $incident_video = array();
         $incident_photo = array();
         foreach ($incident->media as $media) {
             if ($media->media_type == 4) {
                 $incident_news[] = $media->media_link;
             } elseif ($media->media_type == 2) {
                 $incident_video[] = $media->media_link;
             } elseif ($media->media_type == 1) {
                 $incident_photo[] = array('large' => url::convert_uploaded_to_abs($media->media_link), 'thumb' => url::convert_uploaded_to_abs($media->media_thumb));
             }
         }
         $this->template->content->incident_verified = $incident->incident_verified;
         // Retrieve Comments (Additional Information)
         $this->template->content->comments = "";
         if (Kohana::config('settings.allow_comments')) {
             $this->template->content->comments = new View('reports/comments');
             $incident_comments = array();
             if ($id) {
                 $incident_comments = Sharing_Incident_Model::get_comments($id);
             }
             $this->template->content->comments->incident_comments = $incident_comments;
         }
     } else {
         url::redirect('reports');
     }
     // Add extra info to meta
     Event::add('ushahidi_action.report_display_media', array($this, 'report_display_media'));
     // Add Neighbors
     $this->template->content->incident_neighbors = Sharing_Incident_Model::get_neighbouring_incidents($id, TRUE, 0, 5);
     // News Source links
     $this->template->content->incident_news = $incident_news;
     // Video links
     $this->template->content->incident_videos = $incident_video;
     // Images
     $this->template->content->incident_photos = $incident_photo;
     // Create object of the video embed class
     $video_embed = new VideoEmbed();
     $this->template->content->videos_embed = $video_embed;
     // Javascript Header
     $this->themes->map_enabled = TRUE;
     $this->themes->photoslider_enabled = TRUE;
     $this->themes->videoslider_enabled = TRUE;
     $this->themes->js = new View('reports/view_js');
     $this->themes->js->incident_id = $incident->id;
     $this->themes->js->incident_json_url = 'json/share/single/' . $incident->id;
     $this->themes->js->default_map = Kohana::config('settings.default_map');
     $this->themes->js->default_zoom = Kohana::config('settings.default_zoom');
     $this->themes->js->latitude = $incident->location->latitude;
     $this->themes->js->longitude = $incident->location->longitude;
     $this->themes->js->incident_zoom = null;
     //$incident->incident_zoom;
     $this->themes->js->incident_photos = $incident_photo;
     // Initialize custom field array
     $this->template->content->custom_forms = new View('reports/detail_custom_forms');
     $form_field_names = customforms::get_custom_form_fields($id, 1, FALSE, "view");
     $this->template->content->custom_forms->form_field_names = $form_field_names;
     // Are we allowed to submit comments?
     $this->template->content->comments_form = "";
     if (Kohana::config('settings.allow_comments')) {
         $this->template->content->comments_form = new View('reports/comments_form');
         $this->template->content->comments_form->user = $this->user;
         $this->template->content->comments_form->form = $form;
         $this->template->content->comments_form->form_field_names = $form_field_names;
         $this->template->content->comments_form->captcha = $captcha;
         $this->template->content->comments_form->errors = $errors;
         $this->template->content->comments_form->form_error = $form_error;
     }
     // If the Admin is Logged in - Allow for an edit link
     $this->template->content->logged_in = $this->logged_in;
     // Rebuild Header Block
     $this->template->header->header_block = $this->themes->header_block();
     $this->template->footer->footer_block = $this->themes->footer_block();
 }
Beispiel #20
0
Event::run('ushahidi_action.report_form_admin_after_video_link', $id);
?>

							<!-- Photo Fields -->
							<div class="row link-row">
								<h4><?php 
echo Kohana::lang('ui_main.reports_photos');
?>
</h4>
								<?php 
if ($incident_media) {
    // Retrieve Media
    foreach ($incident_media as $photo) {
        if ($photo->media_type == 1) {
            $thumb = url::convert_uploaded_to_abs($photo->media_thumb);
            $large_photo = url::convert_uploaded_to_abs($photo->media_link);
            ?>
                        						<div class="report_thumbs" id="photo_<?php 
            echo $photo->id;
            ?>
">
	                        						<a class="photothumb" rel="lightbox-group1" href="<?php 
            echo $large_photo;
            ?>
">
	                        						<img src="<?php 
            echo $thumb;
            ?>
" />
	                        						</a>
													&nbsp;&nbsp;
Beispiel #21
0
    $incident_verified = $incident->incident_verified;
    if ($incident_verified) {
        $incident_verified = '<span class="r_verified">' . Kohana::lang('ui_main.verified') . '</span>';
        $incident_verified_class = "verified";
    } else {
        $incident_verified = '<span class="r_unverified">' . Kohana::lang('ui_main.unverified') . '</span>';
        $incident_verified_class = "unverified";
    }
    $comment_count = $incident->comment->count();
    $incident_thumb = url::file_loc('img') . "media/img/report-thumb-default.jpg";
    $media = $incident->media;
    if ($media->count()) {
        foreach ($media as $photo) {
            if ($photo->media_thumb) {
                // Get the first thumb
                $incident_thumb = url::convert_uploaded_to_abs($photo->media_thumb);
                break;
            }
        }
    }
    ?>
				<div id="<?php 
    echo $incident_id;
    ?>
" class="rb_report <?php 
    echo $incident_verified_class;
    ?>
">
					<div class="r_media">
						<p class="r_photo" style="text-align:center;"> <a href="<?php 
    echo url::site();
 private function add_data_to_incident($incident_array, $incident)
 {
     /*static $incident_type;
     		if (!$incident_type)
     		{
     			$incident_type = ORM::factory('service')->select_list('id','service_name');
     		}
     		
     		if ($incident_array['incident_id'])
     		{
     			$incident_array['incident_id'] = array($incident_array['incident_id'] => array(
     				'api_url' => url::site(rest_controller::$api_base_url.'/incidents/'.$incident_array['incident_id']),
     				'url' => url::site('/reports/view/'.$incident_array['incident_id'])
     			));
     		}*/
     // Add categories
     $incident_array['category'] = array();
     foreach ($incident->category as $category) {
         // Only include visible categories unless we're an admin
         if ($this->admin or $category->category_visible) {
             $category_data = $category->as_array();
             $category_data['category_image'] = $category_data['category_image'] ? url::convert_uploaded_to_abs($category_data['category_image']) : $category_data['category_image'];
             $category_data['category_image_thumb'] = $category_data['category_image_thumb'] ? url::convert_uploaded_to_abs($category_data['category_image_thumb']) : $category_data['category_image_thumb'];
             $category_data['api_url'] = url::site(rest_controller::$api_base_url . '/categories/' . $category_data['id']);
             $incident_array['category'][] = $category_data;
         }
     }
     // Add location
     // @todo filter on location_visible
     $incident_array['location'] = $incident->location->as_array();
     // format date in ISO standard
     $incident_array['location']['location_date'] = $incident_array['location']['location_date'] != null ? date('c', strtotime($incident_array['location']['location_date'])) : null;
     // Add incident_person
     if ($this->admin) {
         $incident_array['incident_person'] = $incident->incident_person->as_array();
         //@todo sanitize
         // format date in ISO standard
         $incident_array['incident_person']['person_date'] = $incident_array['incident_person']['person_date'] != null ? date('c', strtotime($incident_array['incident_person']['person_date'])) : null;
     } else {
         // @todo check what should be public
         $incident_array['incident_person'] = array('id' => $incident->incident_person->id, 'person_first' => $incident->incident_person->person_first, 'person_last' => $incident->incident_person->person_last);
     }
     // Add user?
     if ($this->admin) {
         $incident_array['user'] = $incident->user->as_array();
         //@todo sanitize
         unset($incident_array['user']['password']);
         unset($incident_array['user']['code']);
         // format date in ISO standard
         $incident_array['user']['updated'] = $incident_array['user']['updated'] != null ? date('c', strtotime($incident_array['user']['updated'])) : null;
     } else {
         // @todo check what should be public
         $incident_array['user'] = array('id' => $incident->user->id, 'name' => $incident->user->name, 'username' => $incident->user->username);
     }
     // Add media?
     $incident_array['media'] = array();
     foreach ($incident->media as $media) {
         // Only include visible categories unless we're an admin
         if ($this->admin or $media->media_active) {
             $media_data = $media->as_array();
             if ($media->media_link and !valid::url($media->media_link)) {
                 $media_data['media_link'] = url::convert_uploaded_to_abs($media_data['media_link']);
                 $media_data['media_medium'] = url::convert_uploaded_to_abs($media_data['media_medium']);
                 $media_data['media_thumb'] = url::convert_uploaded_to_abs($media_data['media_thumb']);
             }
             // format date in ISO standard
             $media_data['media_date'] = $media_data['media_date'] != null ? date('c', strtotime($media_data['media_date'])) : null;
             $incident_array['media'][] = $media_data;
         }
     }
     // Initialize custom field array - only supporting default form
     $incident_array['custom_field'] = customforms::get_custom_form_fields($incident_array['id'], 1, true);
     $incident_array['api_url'] = url::site(rest_controller::$api_base_url . '/incidents/' . $incident_array['id']);
     $incident_array['updated_at'] = $incident->incident_datemodify == null ? $incident->incident_dateadd : $incident->incident_datemodify;
     $incident_array['updated_at'] = date_create($incident_array['updated_at'])->format(DateTime::W3C);
     // format all dates in ISO standard
     $incident_array['incident_datemodify'] = $incident->incident_datemodify != null ? date_create($incident_array['incident_datemodify'])->format(DateTime::W3C) : null;
     $incident_array['incident_dateadd'] = $incident->incident_dateadd != null ? date_create($incident_array['incident_dateadd'])->format(DateTime::W3C) : null;
     $incident_array['incident_date'] = $incident->incident_date != null ? date_create($incident_array['incident_date'])->format(DateTime::W3C) : null;
     return $incident_array;
 }