Пример #1
0
<?php

session_start();
include "Includes/databaseClassMySQLi.php";
include "Includes/commonFuncs.php";
if (isset($_POST["exercises"]) && isset($_POST["date"]) && isset($_SESSION["username"])) {
    $exercises = $_POST["exercises"];
    $date = $_POST["date"];
    $username = $_SESSION["username"];
    $db = new database();
    $db->pick_db("workoutlog");
    $userId = getUserIdFromUsername($username);
    if ($userId != null) {
        //Add workout to tbl_workoutlog_workout, get workoutId
        $stmt = $db->prepare("INSERT INTO tbl_workoutlog_workout (UserId, WorkoutDate) VALUES (?, STR_TO_DATE(?, '%Y-%m-%d'))");
        $stmt->bind_param('is', $userId, $date);
        $stmt->execute();
        if ($stmt->affected_rows == 1) {
            $stmt->free_result();
            $res = $db->send_sql("SELECT LAST_INSERT_ID() AS Id");
            if ($res->num_rows > 0) {
                $row = $res->fetch_assoc();
                $workoutId = $row['Id'];
                foreach ($exercises as $exercise) {
                    //Add each exercise to tbl_WorkoutLog_Exercise linking to the workoutId
                    $stmt = $db->prepare("SELECT ExerciseNameId FROM tbl_workoutlog_exercisename WHERE ExerciseName = ?");
                    $stmt->bind_param('s', $exercise['name']);
                    $stmt->execute();
                    $stmt->bind_result($exerciseNameId);
                    $stmt->fetch();
                    $stmt->free_result();
Пример #2
0
<?php

include "Includes/header.php";
?>

<?php 
include "Includes/class.FastTemplate.php";
$tpl = new FastTemplate("Templates");
$tpl->define(array("WorkoutHistoryPage" => "workoutHistory.html", "WorkoutTable" => "workoutTable.html", "WorkoutRow" => "workoutRow.html", "exerciseData" => "exerciseData.html"));
if (isset($_SESSION["username"])) {
    $allCategoriesDetails = json_decode(getAllCategoriesDetails(), TRUE);
    $db = new database();
    $db->pick_db("workoutlog");
    $userId = getUserIdFromUsername($_SESSION["username"]);
    $query = "SELECT WorkoutDate, WorkoutId FROM tbl_workoutlog_workout WHERE UserId = " . $userId . " ORDER BY WorkoutDate DESC";
    $res = $db->send_sql($query);
    $workouts = $res->fetch_all(MYSQLI_ASSOC);
    if (count($workouts) == 0) {
        $tpl->assign("WORKOUTTABLES", "<p>You haven't recorded any workouts yet!</p>");
    } else {
        foreach ($workouts as $workout) {
            $tpl->clear("EXERCISEROW");
            $query = "SELECT ExerciseId, ExerciseNameId FROM tbl_workoutlog_exercise WHERE WorkoutId = " . $workout['WorkoutId'];
            $res = $db->send_sql($query);
            $exercises = $res->fetch_all(MYSQLI_ASSOC);
            //Find maximum number of sets for any exercise
            $exerciseIds = "(";
            foreach ($exercises as $exercise) {
                $exerciseIds = $exerciseIds . $exercise['ExerciseId'] . ",";
            }
            $exerciseIds = substr($exerciseIds, 0, -1) . ")";