示例#1
0
 public function edit()
 {
     if (!$this->valid_logged_in) {
         redirect('users/login');
     }
     $this->load->library(array('form_validation', 'table'));
     $this->load->helper(array('date', 'form'));
     if ($this->form_validation->run('profiles_edit') == FALSE) {
         // Get current user
         $user = new User($this->user_id);
         // Get existing profile
         $profile = $user->profile;
         $profile->get();
         // Pack existing profile info for content
         if ($this->input->post()) {
             $data['profile'] = array('gender' => set_value('gender'), 'date_of_birth' => set_value('date_of_birth'), 'phone' => set_value('phone'), 'phone_ext' => set_value('phone_ext'), 'address_street_1' => set_value('street_1'), 'address_street_2' => set_value('street_2'), 'address_city' => set_value('city'), 'address_state' => set_value('state'), 'address_zip' => set_value('zip'), 'about' => set_value('about'));
         } else {
             $data['profile'] = array('gender' => $profile->gender, 'date_of_birth' => date_mysql_std($profile->date_of_birth), 'phone' => $profile->phone, 'phone_ext' => $profile->phone_ext, 'address_street_1' => $profile->address_street_1, 'address_street_2' => $profile->address_street_2, 'address_city' => $profile->address_city, 'address_state' => $profile->address_state_province, 'address_zip' => $profile->address_zip, 'about' => $profile->about);
         }
         // Pack user information for content
         $data['user'] = array('firstname' => $user->firstname, 'middlename' => $user->middlename, 'lastname' => $user->lastname, 'email' => $user->email);
         $data['title'] = 'Edit Profile';
         $data['content'] = 'profiles/edit';
         $data['javascript'] = array('jquery', 'jquery-ui', 'date');
         $data['css'] = array('calendar_widget/jquery-ui');
         $this->load->view('master', $data);
     } else {
         // Grab input
         $gender = $this->input->post('gender');
         $date_of_birth = date_std_mysql($this->input->post('date_of_birth'));
         $phone = $this->input->post('phone');
         $phone_ext = $this->input->post('phone_ext');
         $address_street_1 = $this->input->post('street_1');
         $address_street_2 = $this->input->post('street_2');
         $address_city = $this->input->post('city');
         $address_state = $this->input->post('state');
         $address_zip = $this->input->post('zip');
         $about = $this->input->post('about');
         // Get Current User
         $user = new User($this->user_id);
         // Get Existing Profile
         $profile = $user->profile;
         $profile->get();
         // If no existing profile
         if (!$profile->exists()) {
             $profile = new Profile();
         }
         // Save Profile
         $profile->gender = $gender;
         $profile->date_of_birth = $date_of_birth;
         $profile->phone = $phone;
         $profile->phone_ext = $phone_ext;
         $profile->address_street_1 = $address_street_1;
         $profile->address_street_2 = $address_street_2;
         $profile->address_city = $address_city;
         $profile->address_state_province = $address_state;
         $profile->address_zip = $address_zip;
         $profile->about = $about;
         $profile->save($user);
         redirect('profiles');
     }
 }
示例#2
0
 public function modify($log_id = null)
 {
     //////////////////////////////////////////////////
     // Security                                     //
     //////////////////////////////////////////////////
     // Must be logged in
     if (!$this->valid_logged_in) {
         redirect('users/login');
     }
     // Must have log_id in url
     if (!$log_id) {
         redirect('exercises/view');
     }
     $log = new ExerciseLog($log_id);
     // Log must exist
     if (!$log->exists()) {
         redirect('exercises/view');
     }
     // Exercise from log
     $exercise = $log->exercise;
     $exercise->get();
     // User from exercise
     $user = $exercise->user;
     $user->get();
     // User id from exercise must match logged in user
     if ($user->id != $this->user_id) {
         redirect('exercises/view');
     }
     //////////////////////////////////////////////////
     // End Security                                 //
     //////////////////////////////////////////////////
     $this->load->helper(array('date', 'distance', 'form', 'time'));
     $this->load->library('form_validation');
     if ($this->form_validation->run('exercises_modify_log') == FALSE) {
         $data['exercise'] = $exercise->getData();
         $data['log'] = array('id' => $log->id, 'date' => date_mysql_std($log->date), 'time' => time_seconds_to_units($log->time), 'distance' => distance_meters_to_miles($log->distance), 'laps' => $log->laps, 'wght' => $log->weight, 'reps' => $log->repetitions, 'sets' => $log->sets);
         $data['content'] = 'exerciselogs/modify';
         $data['javascript'] = array('jquery', 'jquery-ui', 'date');
         $data['css'] = array('calendar_widget/jquery-ui');
         $this->load->view('master', $data);
     } else {
         $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');
         $log->distance = distance_miles_to_meters($distance);
         $log->time = time_seconds($time_hours, $time_minutes, $time_seconds);
         $log->date = date_std_mysql($date);
         $log->laps = $laps;
         $log->weight = $wght;
         $log->repetitions = $reps;
         $log->sets = $sets;
         $log->save();
         redirect('exercises/view');
     }
 }