function index() { $this->template->content = new View('members/dashboard'); $this->template->content->title = Kohana::lang('ui_admin.dashboard'); $this->template->this_page = 'dashboard'; // User $this->template->content->user = $this->user; // User Reputation Score $this->template->content->reputation = reputation::calculate($this->user->id); // Get Badges $this->template->content->badges = Badge_Model::users_badges($this->user->id); // Retrieve Dashboard Counts... // Total Reports $this->template->content->reports_total = ORM::factory('incident')->where("user_id", $this->user->id)->count_all(); // Total Unapproved Reports $this->template->content->reports_unapproved = ORM::factory('incident')->where('incident_active', '0')->where("user_id", $this->user->id)->count_all(); // Total Checkins $this->template->content->checkins = ORM::factory('checkin')->where("user_id", $this->user->id)->count_all(); // Total Alerts $this->template->content->alerts = ORM::factory('alert')->where("user_id", $this->user->id)->count_all(); // Total Votes $this->template->content->votes = ORM::factory('rating')->where("user_id", $this->user->id)->count_all(); // Total Votes Positive $this->template->content->votes_up = ORM::factory('rating')->where("user_id", $this->user->id)->where("rating", "1")->count_all(); // Total Votes Negative $this->template->content->votes_down = ORM::factory('rating')->where("user_id", $this->user->id)->where("rating", "-1")->count_all(); // Get reports for display $this->template->content->incidents = ORM::factory('incident')->where("user_id", $this->user->id)->limit(5)->orderby('incident_dateadd', 'desc')->find_all(); // To support the "welcome" or "not enough info on user" form if ($this->user->public_profile == 1) { $this->template->content->profile_public = TRUE; $this->template->content->profile_private = FALSE; } else { $this->template->content->profile_public = FALSE; $this->template->content->profile_private = TRUE; } $this->template->content->hidden_welcome_fields = array('email' => $this->user->email, 'notify' => $this->user->notify, 'color' => $this->user->color, 'password' => '', 'needinfo' => 0); /* // Javascript Header $this->template->flot_enabled = TRUE; $this->template->js = new View('admin/dashboard_js'); // Graph $this->template->js->all_graphs = Incident_Model::get_incidents_by_interval('ALL',NULL,NULL,'all'); $this->template->js->current_date = date('Y') . '/' . date('m') . '/01'; */ // Javascript Header $this->template->protochart_enabled = TRUE; $this->template->js = new View('admin/stats_js'); $this->template->content->failure = ''; // Build dashboard chart // Set the date range (how many days in the past from today?) // Default to one year if invalid or not set $range = (isset($_GET['range']) and preg_match('/^\\d+$/', $_GET['range']) > 0) ? (int) $_GET['range'] : 365; // Phase 3 - Invoke Kohana's XSS cleaning mechanism just incase an outlier wasn't caught $range = $this->input->xss_clean($range); $incident_data = Incident_Model::get_number_reports_by_date($range, $this->user->id); $data = array('Reports' => $incident_data); $options = array('xaxis' => array('mode' => '"time"')); $this->template->content->report_chart = protochart::chart('report_chart', $data, $options, array('Reports' => 'CC0000'), 410, 310); }
/** * Displays a profile page for a user */ public function user() { // Cacheable Controller $this->is_cachable = TRUE; $this->template->header->this_page = 'profile'; // Check if we are looking for a user. Argument must be set to continue. if (!isset(Router::$arguments[0])) { url::redirect('profile'); } $username = Router::$arguments[0]; // We won't allow profiles to be public if the username is an email address if (valid::email($username)) { url::redirect('profile'); } $user = User_Model::get_user_by_username($username); // We only want to show public profiles here if ($user->public_profile == 1) { $this->template->content = new View('profile/user'); $this->template->content->user = $user; // User Reputation Score $this->template->content->reputation = reputation::calculate($user->id); // All users reports $this->template->content->reports = ORM::factory('incident')->where(array('user_id' => $user->id, 'incident_active' => 1))->with('incident:location')->find_all(); // Get Badges $this->template->content->badges = Badge_Model::users_badges($user->id); // Logged in user id (false if not logged in) $logged_in_id = FALSE; if (isset(Auth::instance()->get_user()->id)) { $logged_in_id = Auth::instance()->get_user()->id; } $this->template->content->logged_in_id = $logged_in_id; // Is this the logged in user? $logged_in_user = FALSE; if ($logged_in_id == $user->id) { $logged_in_user = TRUE; } $this->template->content->logged_in_user = $logged_in_user; } else { // this is a private profile so get out of here url::redirect('profile'); } $this->template->header->page_title .= $user->name . Kohana::config('settings.title_delimiter'); $this->template->header->header_block = $this->themes->header_block(); $this->template->footer->footer_block = $this->themes->footer_block(); }
function index() { $this->template->content = new View('admin/badges'); $this->template->content->title = Kohana::lang('ui_main.badges'); // setup and initialize form field names $form = array('id' => '', 'name' => '', 'description' => ''); // copy the form as errors, so the errors will be stored with keys corresponding to the form field names $errors = $form; $form_error = FALSE; $form_saved = FALSE; $form_action = ""; if ($_POST) { $post = Validation::factory($_POST); // Add some filters $post->pre_filter('trim', TRUE); // Add some rules, the input field, followed by a list of checks, carried out in order $post->add_rules('action', 'required', 'alpha', 'length[1,1]'); $post->add_rules('name', 'standard_text', 'length[1,250]'); $post->add_rules('description', 'standard_text'); $post->add_rules('image', 'upload::valid', 'upload::type[gif,jpg,png]', 'upload::size[100K]'); if ($post->validate()) { // ADD if ($post->action == 'a') { // Step 1. Save badge name and description $badge = new Badge_Model(); $badge->name = $post->name; $badge->description = $post->description; $badge->save(); // Step 2. Save badge image $filename = upload::save('image'); if ($filename) { $new_filename = "badge_" . $badge->id . "_" . 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")) { $cdn = new cdn(); $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 . $new_filename . $file_type); unlink($local_directory . $new_filename . '_m' . $file_type); unlink($local_directory . $new_filename . '_t' . $file_type); } // Remove the temporary file unlink($filename); // Delete old badge image ORM::factory('media')->where(array('badge_id' => $badge->id))->delete_all(); // Save new badge image $media = new Media_Model(); $media->badge_id = $badge->id; $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(); } } // ASSIGN USER if ($post->action == 'b') { $badge_user = new Badge_User_Model(); $badge_user->badge_id = $post->badge_id; $badge_user->user_id = $post->assign_user; $badge_user->save(); } // REVOKE USER if ($post->action == 'r') { ORM::factory('badge_user')->where(array('badge_id' => (int) $post->badge_id, 'user_id' => (int) $post->revoke_user))->delete_all(); } elseif ($post->action == 'd') { // Remove from badge table ORM::factory('badge')->delete((int) $post->badge_id); // Remove from media ORM::factory('media')->where(array('badge_id' => (int) $post->badge_id))->delete_all(); // Remove from assignment ORM::factory('badge_user')->where(array('badge_id' => (int) $post->badge_id))->delete_all(); } } else { $errors = arr::overwrite($errors, $post->errors('badges')); $form_error = 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->form_action = $form_action; // Get badges $this->template->content->badges = Badge_Model::badges(); $this->template->content->total_items = count($this->template->content->badges); // Get all users for dropdowns $users_result = ORM::factory('user')->orderby('name', 'asc')->find_all(); $users = array(); foreach ($users_result as $user) { $users[$user->id] = $user->username; } $this->template->content->users = $users; // Javascript Header $this->template->js = new View('admin/badges_js'); }
function index() { $this->template->content = new View('admin/manage/actions/main'); $this->template->content->title = Kohana::lang('ui_admin.actions'); $this->template->map_enabled = TRUE; $this->template->treeview_enabled = TRUE; $this->template->js = new View('admin/manage/actions/actions_js'); $this->template->js->default_map = Kohana::config('settings.default_map'); $this->template->js->default_zoom = Kohana::config('settings.default_zoom'); $this->template->js->latitude = Kohana::config('settings.default_lat'); $this->template->js->longitude = Kohana::config('settings.default_lon'); // TODO: Figure out what to do with this $this->template->js->incident_zoom = array(); $this->template->js->geometries = array(); $trigger_options = $this->_trigger_options(); $response_options = $this->_response_options(); $trigger_advanced_options = $this->_trigger_advanced_options(); $advanced_option_areas = $this->_advanced_option_areas(); $response_advanced_options = $this->_response_advanced_options(); $response_advanced_option_areas = $this->_response_advanced_option_areas(); $trigger_allowed_responses = $this->_trigger_allowed_responses(); // Setup and initialize form field names $form = array('geometry' => '', 'action_trigger' => '', 'action_user' => '', 'action_location_specific' => '', 'action_keywords' => '', 'action_category' => array(), 'action_on_specific_count' => '', 'action_on_specific_count_collective' => '', 'action_days_of_the_week' => array(), 'action_specific_days' => array(), 'action_between_times_hour_1' => '', 'action_between_times_hour_2' => '', 'action_between_times_minute_1' => '', 'action_between_times_minute_2' => '', 'action_response' => '', 'action_email_send_address' => '', 'action_email_send_address_specific' => '', 'action_email_subject' => '', 'action_email_body' => '', 'action_add_category' => array(), 'action_verify' => '', 'action_badge' => ''); // Process form submission if ($_POST) { $post = Validation::factory($_POST); // Trim all of the fields to get rid of errant spaces $post->pre_filter('trim', TRUE); $expected_qualifier_fields = $trigger_advanced_options[$post['action_trigger']]; $expected_response_fields = $response_advanced_options[$post['action_response']]; $expected_fileds = array_merge($expected_qualifier_fields, $expected_response_fields); // Since our form is dynamic, we need to set validation dynamically foreach ($expected_fileds as $field) { $this->_form_field_rules($field, $post); } if ($post->validate()) { $qualifiers = array(); foreach ($expected_qualifier_fields as $field) { $form_field = 'action_' . $field; // 1. Standard field population if (isset($post->{$form_field})) { $qualifiers[$field] = $post->{$form_field}; } // 2. Check additional field population // Populate additional geometry field if ($field == 'location' && $post->{$form_field} == 'specific') { // Add geometry if this is a specific location $qualifiers['geometry'] = $post->geometry; } // Populate additional specific count collective boolean if ($field == 'on_specific_count') { // Grab if we are counting everyone or just the individual users themselves $qualifiers['on_specific_count_collective'] = $post->action_on_specific_count_collective; } // Change the specific_days field to an array of timestamps if ($field == 'specific_days') { // Grab if we are counting everyone or just the individual users themselves $qualifiers['specific_days'] = explode(',', $qualifiers['specific_days']); foreach ($qualifiers['specific_days'] as $key => $specific_day) { $qualifiers['specific_days'][$key] = strtotime($specific_day); } if ($qualifiers['specific_days'][0] == false) { // Just get rid of it if we aren't using it unset($qualifiers['specific_days']); } } // Grab dropdowns for between_times if ($field == 'between_times') { // Do everything for between times here if ($post->action_between_times_hour_1 != 0 or $post->action_between_times_minute_1 != 0 or $post->action_between_times_hour_2 != 0 or $post->action_between_times_minute_2 != 0) { // We aren't all zeroed out so the user is not ignoring between_times. Now we need // to calculate seconds into the day for each and put the lower count in the first // variable and the higher in the second so the check in the hook doesn't have to // do so much work. Also, set between_times to true so the hook knows to check it. $qualifiers['between_times'] = 1; $time1 = (int) $post->action_between_times_hour_1 * 3600 + (int) $post->action_between_times_minute_1 * 60; $time2 = (int) $post->action_between_times_hour_2 * 3600 + (int) $post->action_between_times_minute_2 * 60; if ($time1 < $time2) { $qualifiers['between_times_1'] = $time1; $qualifiers['between_times_2'] = $time2; } else { $qualifiers['between_times_1'] = $time2; $qualifiers['between_times_2'] = $time1; } } else { // Between_times is being ignored, set it that way here $qualifiers['between_times'] = 0; } } } $qualifiers = serialize($qualifiers); $response_vars = array(); foreach ($expected_response_fields as $field) { $form_field = 'action_' . $field; if (isset($post->{$form_field})) { $r_var = $post->{$form_field}; if ($field == 'email_send_address' and $post->{$form_field} == '1') { // Then set as the specific email address so we know where to send it $r_var = $post->action_email_send_address_specific; } // This is the array we're building to pass on the data we need // to perform the response when qualifiers are all passed $response_vars[$field] = $r_var; } } $response_vars = serialize($response_vars); $action = ORM::factory('actions'); $action->action = $post->action_trigger; $action->qualifiers = $qualifiers; $action->response = $post->action_response; $action->response_vars = $response_vars; $action->active = 1; $action->save(); } else { // TODO: Proper Validation $errors = $post->errors(); foreach ($errors as $key => $val) { echo $key . ' failed rule ' . $val . '<br />'; } } } // Copy the form as errors, so the errors will be stored with keys corresponding to the form field names $errors = $form; $form_error = FALSE; $form_saved = FALSE; $form_action = ""; $sharing_id = ""; // Defined actions by the user that already exist in the system $this->template->content->actions = $this->_get_actions(); $this->template->content->total_items = $this->template->content->actions->count(); $this->template->content->trigger_options = $trigger_options; $this->template->content->response_options = $response_options; $this->template->content->trigger_advanced_options = $trigger_advanced_options; $this->template->content->advanced_option_areas = $advanced_option_areas; $this->template->content->response_advanced_options = $response_advanced_options; $this->template->content->response_advanced_option_areas = $response_advanced_option_areas; $this->template->content->trigger_allowed_responses = $trigger_allowed_responses; // Build user options list $this->template->content->user_options = $this->_user_options(); // Grab categories for category advanced options $this->template->content->categories = Category_Model::get_categories(0, FALSE, FALSE); // Grab badges for dropdown $this->template->content->badges = Badge_Model::badge_names(); // Timezone $this->template->content->site_timezone = Kohana::config('settings.site_timezone'); // Days of the week $this->template->content->days = array('mon' => Kohana::lang('datetime.monday.full'), 'tue' => Kohana::lang('datetime.tuesday.full'), 'wed' => Kohana::lang('datetime.wednesday.full'), 'thu' => Kohana::lang('datetime.thursday.full'), 'fri' => Kohana::lang('datetime.friday.full'), 'sat' => Kohana::lang('datetime.saturday.full'), 'sun' => Kohana::lang('datetime.sunday.full')); $this->template->content->form = $form; $this->template->content->form_error = $form_error; $this->template->content->form_saved = $form_saved; $this->template->content->form_action = $form_action; $this->template->content->errors = $errors; // Enable date picker $this->template->datepicker_enabled = TRUE; }