Example #1
0
 public function index()
 {
     $this->load->library('session');
     /*
      *make sure session is valid and check session user agent to help prevent session hijacking. 
      */
     $redirect_path = base_url() . "login";
     //check that user is logged in
     if ($_SESSION['loggedIn'] != true) {
         redirect($redirect_path);
     }
     //get user id from the session
     $userID = $_SESSION['userID'];
     //check session user agent
     $session_name = "userAgent";
     check_session_user_agent_h($redirect_path, $session_name);
     //if add an exercise has been submitted
     if (isset($_POST['add-exercise-submit'])) {
         if (!empty($_POST['name'])) {
             //get the post data from ajax request.
             $name = $_POST['name'];
             $description = $_POST['description'];
             $is_cardio = $_POST['is_cardio'];
             //add the exercise to the database
             $this->Database_model->add_exercise($userID, $name, $description, $is_cardio);
             echo "true";
         } else {
             echo "Fill out name";
         }
         //end if
     } else {
         echo "false";
     }
     //end if
 }
Example #2
0
 public function index()
 {
     $this->load->library('session');
     /*
      *make sure session is valid and check session user agent to help prevent session hijacking. 
      */
     $redirect_path = base_url() . "login";
     //check that user is logged in
     if ($_SESSION['loggedIn'] != true) {
         redirect($redirect_path);
     }
     //get user id from the session
     $userID = $_SESSION['userID'];
     //check session user agent
     $session_name = "userAgent";
     check_session_user_agent_h($redirect_path, $session_name);
     /*
      *	Destroy the session
      */
     $this->session->sess_destroy();
     /*
      *	Redirect the user to the login page
      */
     redirect(base_url() . "login");
 }
Example #3
0
 public function index()
 {
     $this->load->library('session');
     //custom javascript filename to include
     $data['javascript'] = 'start_workout.js';
     /*
      *make sure session is valid and check session user agent to help prevent session hijacking. 
      */
     $redirect_path = base_url() . "login";
     //check that user is logged in
     if (!isset($_SESSION['loggedIn'])) {
         redirect($redirect_path);
     }
     //get user id from the session
     $userID = $_SESSION['userID'];
     //check session user agent
     $session_name = "userAgent";
     check_session_user_agent_h($redirect_path, $session_name);
     /*
      *	get all user workouts and pass it to the view
      */
     $workouts = $this->Database_model->get_all_user_workouts_asc($userID);
     $data['workouts'] = $workouts;
     //this variable is created for the "main" file in view/layouts/main.  Main takes $main_content and uses it to load the view 'products.php'.
     $data['main_content'] = 'Start_workout';
     //load a view and pass it the data object to use in the view.  For instance, to use $data['name'] = "mike" in the view simply use "$name".
     $this->load->view('layouts/main', $data);
 }
Example #4
0
 public function index()
 {
     $this->load->library('session');
     /*
      *make sure session is valid and check session user agent to help prevent session hijacking. 
      */
     $redirect_path = base_url() . "login";
     //check that user is logged in
     if (!isset($_SESSION['loggedIn'])) {
         redirect($redirect_path);
     }
     //get user id from the session
     $userID = $_SESSION['userID'];
     //check session user agent
     $session_name = "userAgent";
     check_session_user_agent_h($redirect_path, $session_name);
     //get the current workoutlogID
     $global_workout_log_id = $_SESSION['workout_log_id'];
     /*
      *	Handle delete set functionality
      */
     //if the delete set form has been submitted
     if (isset($_POST['delete_exercise_submit'])) {
         //get posted variables
         $exerciseID = $_POST['exerciseID'];
         $setID = $_POST['setID'];
         //delete the set from the database.
         $this->Database_model->delete_set($userID, $setID);
         //return the sets to the javascript file
         $sets = previous_exercise_sets_h($userID, $exerciseID, $global_workout_log_id);
         $sanitized_html = sanitize_object_h($sets);
         //send the sanitized data.
         echo json_encode($sanitized_html);
     }
     //end if
     /*
      *	Take care of ajax post from javascript
      */
     //if the submit-set-btn was clicked and the form was submitted
     if (isset($_POST['weight']) && isset($_POST['reps'])) {
         //get all post data
         $weight = $_POST['weight'];
         $reps = $_POST['reps'];
         $rest = $_POST['rest'];
         $exerciseID = $_POST['exerciseID'];
         $workoutID = $_POST['workoutsID'];
         $difficulty = $_POST['difficulty'];
         $workout_log_id = $_POST['workout-log-id'];
         $this->Database_model->enter_set($userID, $workoutID, $workout_log_id, $exerciseID, $weight, $reps, $rest, $difficulty);
         //get the sets to return to the javascript file to be posted in the view
         $sets = previous_exercise_sets_h($userID, $exerciseID, $global_workout_log_id);
         $sanitized_html = sanitize_object_h($sets);
         //send the sanitized data.
         echo json_encode($sanitized_html);
     }
     //end if
 }
Example #5
0
 public function index()
 {
     //custom javascript filename to include
     $data['javascript'] = 'workout.js';
     $this->load->library('session');
     /*
      *make sure session is valid and check session user agent to help prevent session hijacking. 
      */
     $redirect_path = base_url() . "login";
     //check that user is logged in
     if (!isset($_SESSION['loggedIn'])) {
         redirect($redirect_path);
     }
     //get user id from the session
     $userID = $_SESSION['userID'];
     //check session user agent
     $session_name = "userAgent";
     check_session_user_agent_h($redirect_path, $session_name);
     /*
      * If a workout has been initiated, else redirect
      */
     if (isset($_POST['workoutID']) || isset($_SESSION['workoutID'])) {
         //if a new workout has been initiated - reset the workoutID variable and session variable.  Else set it equal to the session workout variable - this helps if a person accidentilly leaves the workout page....the workout is still accessable.
         if (isset($_POST['workoutID'])) {
             //brand new workout - get workoutID and set the session workout variable.
             $workoutID = $_POST['workoutID'];
             $_SESSION['workoutID'] = $workoutID;
             $this->Database_model->log_new_workout($userID, $workoutID);
             //get and set the workout_log id variable - used to access previous exercise sets
             $_SESSION['workout_log_id'] = $this->Database_model->get_latest_workout_log_id($userID);
         } else {
             $workoutID = $_SESSION['workoutID'];
         }
         //end if
         //send workout log id to the view.
         $data['workout_log_id'] = $_SESSION['workout_log_id'];
         //send the workout ID to the view
         $data['workoutID'] = $workoutID;
         /*
          *  Handle getting all the exercises for a workout
          */
         $exercisesForWorkout = $this->Database_model->get_all_exercises_for_workout($userID, $workoutID);
         $data['exercisesForWorkout'] = $exercisesForWorkout;
         //get all workout information and send it to the view
         $workoutDetails = $this->Database_model->get_workout_details($userID, $workoutID);
         $data['workoutDetails'] = $workoutDetails;
     } else {
         redirect(base_url() . "start_workout");
     }
     //end if
     $data['userID'] = $userID;
     //this variable is created for the "main" file in view/layouts/main.  Main takes $main_content and uses it to load the view 'products.php'.
     $data['main_content'] = 'Workout';
     //load a view and pass it the data object to use in the view.  For instance, to use $data['name'] = "mike" in the view simply use "$name".
     $this->load->view('layouts/main', $data);
 }
Example #6
0
 public function index()
 {
     //errors array
     $errors = array();
     $this->load->library('session');
     //custom javascript filename to include
     $data['javascript'] = 'exercises.js';
     /*
      *make sure session is valid and check session user agent to help prevent session hijacking. 
      */
     $redirect_path = base_url() . "login";
     //check that user is logged in
     if (!isset($_SESSION['loggedIn'])) {
         redirect($redirect_path);
     }
     //get user id from the session
     $userID = $_SESSION['userID'];
     //check session user agent
     $session_name = "userAgent";
     check_session_user_agent_h($redirect_path, $session_name);
     /*
      *	Add exercise functionality
      */
     //if user submitted to add an exerise
     if (isset($_POST['add-exercise-submit'])) {
         if (!empty($_POST['name'])) {
             //get the post data from ajax request.
             $name = $_POST['name'];
             $description = $_POST['description'];
             $is_cardio = $_POST['is_cardio'];
             //add the exercise to the database
             $this->Database_model->add_exercise($userID, $name, $description, $is_cardio);
         } else {
             $errors[] = "The name of your exercise is a required field.";
         }
         //end if
     }
     /*
      *	If user deletes an exercise in the modal popup
      */
     if (isset($_POST['delete_exercise_submit'])) {
         //get the id of the exercise to be deleted
         $exerciseToDeleteID = $_POST['exercise_id'];
         //delete the exercise in the database - changes it's deleted column to 1 and leaves the exercise for historical purposes.
         $this->Database_model->delete_exercise($userID, $exerciseToDeleteID);
     }
     //end if isset
     /*
      *	Get all user exercises and pass it to the view
      */
     $exercises = $this->Database_model->get_all_user_exercises($userID);
     $data['exercises'] = $exercises;
     $data['errors'] = $errors;
     //iterator - used for accordian in the view
     $data['iterator'] = 0;
     $data['userID'] = $userID;
     //this variable is created for the "main" file in view/layouts/main.  Main takes $main_content and uses it to load the view 'products.php'.
     $data['main_content'] = 'Exercises';
     //load a view and pass it the data object to use in the view.  For instance, to use $data['name'] = "mike" in the view simply use "$name".
     $this->load->view('layouts/main', $data);
 }
Example #7
0
 public function index()
 {
     //errors array
     $errors = array();
     $this->load->library('session');
     /*
      *make sure session is valid and check session user agent to help prevent session hijacking. 
      */
     $redirect_path = base_url() . "login";
     //check that user is logged in
     if (!isset($_SESSION['loggedIn'])) {
         redirect($redirect_path);
     }
     //get user id from the session
     $userID = $_SESSION['userID'];
     //check session user agent
     $session_name = "userAgent";
     check_session_user_agent_h($redirect_path, $session_name);
     //loads a unique javascript file in the footer for this particular page
     $data['javascript'] = 'workouts.js';
     /*
      *	Add workout 
      */
     //if user submitted to add a workout
     if (isset($_POST['add_workout_submit'])) {
         if (!empty($_POST['add_workout_name'])) {
             //get the post data
             $name = $_POST['add_workout_name'];
             $description = $_POST['add_workout_description'];
             //add the exercise to the database
             $this->Database_model->add_workout($userID, $name, $description);
         } else {
             $errors[] = "The name of your workout is a required field.  Please try again.";
         }
         //end if
     }
     //end if
     /*
      *	Handle delete workout functionality
      */
     //if the delete workout form has been submitted
     if (isset($_POST['delete-workout-submit'])) {
         //get the variables from the post
         $workout_id = $_POST['workout_id'];
         //set the deleted column of the workout to "1" - doesn't delete from database for historical data purposes
         $this->Database_model->delete_workout($userID, $workout_id);
     }
     //end if post
     /*
      *	Add existing exercise to workout functionality - modal popup
      */
     //if the user has submitted the form for existing exercise
     if (isset($_POST['add-existing-exercise'])) {
         //get the post variables
         $existingExerciseID = $_POST['add_existing_exercise_selection'];
         $existingExerciseWorkoutID = $_POST['existing-exercise-workoutID'];
         //update the database
         $this->Database_model->add_exercise_to_workout($userID, $existingExerciseID, $existingExerciseWorkoutID);
     }
     //end if
     //if the user has submitted the form for the new exercise portion
     if (isset($_POST['add_new_exercise_workout'])) {
         //get post variables
         $name = $_POST['name'];
         $description = $_POST['description'];
         $is_cardio = $_POST['is_cardio'];
         $workoutID = $_POST['workoutID'];
         //add the new exercise to the database
         $this->Database_model->add_exercise($userID, $name, $description, $is_cardio);
         //get the exericse id of that exercise
         $latestExerciseID = $this->Database_model->get_latest_exercise_id($userID);
         //add the new exercise to the workout
         $this->Database_model->add_exercise_to_workout($userID, $latestExerciseID, $workoutID);
     }
     //end if
     /*
      *	Delete exercise from a workout
      */
     if (isset($_POST['delete-exercise-from-workout'])) {
         //set the post variables
         $workout_exercisesID = $_POST['workout_exerciseID'];
         //delete the workout from the database
         $this->Database_model->delete_exercise_from_workout($userID, $workout_exercisesID);
     }
     //end if
     /*
      *	Get all workouts and send to the view
      */
     //get all the workouts from the model.
     $allWorkouts = $this->Database_model->get_all_user_workouts_asc($userID);
     //send them to the view.
     $data['allWorkouts'] = $allWorkouts;
     /*
      *	Load all exercises - the view passes a variable to the controller for the foreach loop of the exercises to obtain the current workout_id from the foreach loop.
      */
     //variable to store all the workout id's displayed in the view.
     $workoutIDs = array();
     //get the workouts for each
     $workoutExercises = array();
     $workoutExercisestest = array();
     //get all the workout id's for the different workouts to use in the view and add them to above array. Also get all of the exercises for each workout and put them into the workoutExercises array to use in the view.
     foreach ($allWorkouts as $workout) {
         $workoutIDs[] = $workout->id;
         $workoutExercises[] = $this->Database_model->get_all_exercises_for_workout($userID, $workout->id);
     }
     //end foreach
     /*
      * Get all user exercises for the add exercise to workout modal popup selection 
      */
     $allExercises = $this->Database_model->get_all_user_exercises($userID);
     //pass variables to the view.
     $data['workoutIDs'] = $workoutIDs;
     $data['workoutExercises'] = $workoutExercises;
     $data['userID'] = $userID;
     $data['allExercises'] = $allExercises;
     //an iterator for the accordian functionality
     $data['iterator'] = 1;
     //pass the errors to the view
     $data['errors'] = $errors;
     //this variable is created for the "main" file in view/layouts/main.  Main takes $main_content and uses it to load the view 'products.php'.
     $data['main_content'] = 'Workouts';
     //load a view and pass it the data object to use in the view.  For instance, to use $data['name'] = "mike" in the view simply use "$name".
     $this->load->view('layouts/main', $data);
 }