public function create() { // Must be logged in if (!$this->valid_logged_in) { redirect('users/login'); } // Load libraries and helpers $this->load->library(array('form_validation', 'table')); $this->load->helper(array('date', 'form')); // If form validation fails, or is not run, load input form if ($this->form_validation->run('exercises_create') == FALSE) { $data['title'] = 'Create Exercise'; $data['content'] = 'exercises/create'; $data['javascript'] = array('jquery', 'exercises/create'); $this->load->view('master', $data); } else { $user = new User($this->user_id); // Grab post data $name = $this->input->post('name'); $description = $this->input->post('description'); $include_description = $this->input->post('include_description'); $types = $this->input->post('type'); $save_types = array('dist' => FALSE, 'time' => FALSE, 'laps' => FALSE, 'wght' => FALSE, 'reps' => FALSE, 'sets' => FALSE); foreach ($types as $type) { $save_types[$type] = TRUE; } $timestamp = date_timestamp(); // Create a new exercise $exercise = new Exercise(); $exercise->name = $name; if ($include_description) { $exercise->description = $description; } $exercise->distance = $save_types['dist']; $exercise->time = $save_types['time']; $exercise->weight = $save_types['wght']; $exercise->repetitions = $save_types['reps']; $exercise->sets = $save_types['sets']; $exercise->laps = $save_types['laps']; $exercise->last_log = $timestamp; $exercise->save($user); // TODO redirect somewhere smart redirect('exercises/view'); } }
public function log($exercise_id = null) { ////////////////////////////////////////////////// // Security // ////////////////////////////////////////////////// if (!$this->valid_logged_in) { redirect('users/login'); } $user = new User($this->user_id); $exercise = $user->exercise; $exercise->where('id', $exercise_id); $exercise->get(); if ($exercise->exists() == FALSE) { redirect('exercises/view'); } ////////////////////////////////////////////////// // End Security // ////////////////////////////////////////////////// $this->load->library('form_validation'); $this->load->helper(array('form', 'distance', 'time', 'date')); $user_exercises = array(); if ($this->form_validation->run('exercises_log') == FALSE) { $data['exercise'] = $exercise->getData(); $data['date'] = date("m/d/Y"); $data['user_exercises'] = $user_exercises; } else { ////////////////////////////////////////////////// // Get Data From Form // ////////////////////////////////////////////////// //$exercise_id = $this->input->post('exercise_id'); $date = $this->input->post('date'); $time_hours = $this->input->post('time_hours'); $time_minutes = $this->input->post('time_minutes'); $time_seconds = $this->input->post('time_seconds'); $distance = $this->input->post('distance'); $laps = $this->input->post('laps'); $wght = $this->input->post('wght'); $reps = $this->input->post('reps'); $sets = $this->input->post('sets'); ////////////////////////////////////////////////// // Convert Units // ////////////////////////////////////////////////// $time_output = time_seconds($time_hours, $time_minutes, $time_seconds); $meter_distance = distance_miles_to_meters($distance); $mysql_date = date_std_mysql($date); $timestamp = date_timestamp(); ////////////////////////////////////////////////// // Log Exercise // ////////////////////////////////////////////////// $user = new User($this->user_id); $exercise = $user->exercise; $exercise->where('id', $exercise_id); $exercise->get(); $log = new ExerciseLog(); $log->date = $mysql_date; $log->time = $time_output; $log->distance = $meter_distance; $log->laps = $laps; $log->weight = $wght; $log->repetitions = $reps; $log->sets = $sets; $log->save($exercise); $exercise->last_log = $timestamp; $exercise->save(); redirect("exercises/view_one/{$exercise->id}"); } $data['title'] = 'Log Exercise'; $data['content'] = 'exerciselogs/log'; $data['javascript'] = array('jquery', 'jquery-ui', 'date'); $data['css'] = array('calendar_widget/jquery-ui'); $this->load->view('master', $data); }