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 }
<?php //start session session_start(); //load all includes include 'core/init.php'; //start a database $db = new Database(); /* * Handle session privacy checking user_agent */ $redirect_url = BASE_URL . "login.php"; session_user_agent_h($redirect_url, "userAgent"); //end if //make sure user is logged in check_if_logged_in_h(); /* * Handle data for list item from the ajax javascript request */ //the user_id is set in the php Database library under "check_user_loggin function" $current_user = $_SESSION['user_id']; $time_frame = $_POST['time_frame']; //if valid timeframe then return data if ($time_frame == 1 || $time_frame == 2 || $time_frame == 3) { //sanitize the returned html to escape characters. $sanitized_html = sanitize_object_h($db->get_list_items($time_frame, $current_user)); echo json_encode($sanitized_html); } else { echo "not a valid timeframe"; } //end if