Example #1
0
function tmp()
{
    global $wpdb;
    $query = "SELECT * FROM wp_flmain";
    $results = $wpdb->get_results($query, ARRAY_A);
    foreach ($results as $row) {
        $update = "UPDATE wp_flmain SET seconds=" . convert_time_seconds($row["duration"]) . " WHERE user_id=" . $row["user_id"] . " AND sbr_type='" . $row["sbr_type"] . "' AND plan_type='" . $row["plan_type"] . "' AND workout_date='" . $row["workout_date"] . "'";
        $wpdb->query($update);
    }
}
Example #2
0
// for the element arrays defaults are as follows:
// 0 = swim
// 1 = bike
// 2 = run
// 3 = strength
//
// example:
//	$workout_date[0] = workoutdate for swim
//	$workout_date[1] = workoutdate for bike
//	$workout_date[2] = workoutdate for run
//	$workout_date[3] = workoutdate for strength
// Get the data entered and validate it.
$workout_date = array($_POST["s_workoutdate"], $_POST["b_workoutdate"], $_POST["r_workoutdate"], $_POST["s_workoutdate"]);
$workout_time = array($_POST["s_workouttime"], $_POST["b_workouttime"], $_POST["r_workouttime"], $_POST["str_workouttime"]);
$duration = array($_POST["s_duration"], $_POST["b_duration"], $_POST["r_duration"], $_POST["str_duration"]);
$seconds = array(convert_time_seconds($duration[0]), convert_time_seconds($duration[1]), convert_time_seconds($duration[2]), convert_time_seconds($duration[3]));
$distance = array($_POST["s_distance"], $_POST["b_distance"], $_POST["r_distance"], 0);
$notes = array($_POST["s_notes"], $_POST["b_notes"], $_POST["r_notes"], $_POST["str_notes"]);
$min_hr = array($_POST["s_min_hr"], $_POST["b_min_hr"], $_POST["r_min_hr"], 0);
$avg_hr = array($_POST["s_avg_hr"], $_POST["b_avg_hr"], $_POST["r_avg_hr"], 0);
$max_hr = array($_POST["s_max_hr"], $_POST["b_max_hr"], $_POST["r_max_hr"], 0);
$avg_rpms = $_POST["avg_rpms"];
$calsburned = array($_POST["s_calsburned"], $_POST["b_calsburned"], $_POST["r_calsburned"], 0);
$updatingswim = $_POST["updatingswim"];
$updatingbike = $_POST["updatingbike"];
$updatingrun = $_POST["updatingrun"];
$updatingblognotes = $_POST["updatingblognotes"];
$blog_notes = $_POST["blog_notes"];
for ($i = 0; $i < 3; $i++) {
    // Validate data.
    if (!validate_date($workout_date[$i])) {
Example #3
0
<?php

require 'fitlogfunc.php';
// Get time, distance and activity
$strtime = strval($_GET['time']);
$distance = floatval($_GET['distance']);
$activity = strval($_GET['activity']);
// convert the parsed time into seconds and put that into the $time variable
$time = convert_time_seconds($strtime);
switch ($activity) {
    case "swim":
        $pace = swimpace($time, $distance);
        break;
    case "bike":
        $pace = bikepace($time, $distance);
        break;
    case "run":
        $pace = runpace($time, $distance);
        break;
    default:
        $pace = 0;
        break;
}
echo $pace;
Example #4
0
function saveday($userID, $connection, $xml_data)
{
    $recordSaved = 0;
    $xmldoc = simplexml_load_string($xml_data);
    /* First we need the start time and duration of the workout and convert duration to 
       seconds, and get the date of the workout. */
    $startTime = $xmldoc->starttime;
    $duration = $xmldoc->duration;
    $seconds = convert_time_seconds($xmldoc->duration);
    $date = $xmldoc->date;
    $type = $xmldoc->type;
    $notes = $xmldoc->notes;
    $strId = $xmldoc->strid;
    /* Check to see if we are going to update a current record or creating a new one */
    if (!strcmp($strId, "0")) {
        /* Now create the initial record in flstrength table */
        $query = "INSERT INTO flstrength (exercises_id, plan_type, workout_date, time_of_day, duration, notes, seconds, user_id) VALUES ( NULL, '{$type}', '{$date}', '{$startTime}', '{$duration}', '{$notes}', {$seconds}, {$userID} )";
        $result = @mysql_query($query, $connection);
    } else {
        /* Delete all the records in the flexercises table to be replaced with the current data set. */
        $query = "DELETE FROM fl_exercises WHERE exercises_id={$strID} AND user_id={$userID}";
        $result = @mysql_query($query, $connection);
        /* Update the current record then in the flstrength table */
        $query = "UPDATE flstrength SET duration='" . $duration . "', seconds={$seconds}, notes='" . $notes . "' WHERE exercises_id={$strId} AND user_id={$userID}";
        $result = @mysql_query($query, $connection);
    }
    if (!result) {
        $msg = "<saveDay>" . "<error>" . "Unable to create record in flstrength!" . "</error>" . "</saveDay>";
        return $msg;
    } else {
        /* Get the id for the just created strength record. */
        $query = "SELECT exercises_id FROM flstrength WHERE user_id={$userID} ORDER BY exercises_id DESC";
        $result = @mysql_query($query, $connection);
        $row = mysql_fetch_array($result);
        $exercisesID = $row["exercises_id"];
        foreach ($xmldoc->row as $row) {
            $catexercisePair = explode(":", $row->exercise_desc);
            $setNum = $row->set;
            if (strcmp($row->reps, "")) {
                $reps = $row->reps;
            } else {
                $reps = 0;
            }
            if (strcmp($row->weight, "")) {
                $weight = $row->weight;
            } else {
                $weight = 0;
            }
            // Fetch the exercise Id from the flexercise_type table.
            $query = "SELECT exercise_type_id FROM flexercise_type WHERE user_id={$userID} AND category='" . $catexercisePair[0] . "' AND exercise='" . $catexercisePair[1] . "'";
            $result = @mysql_query($query, $connection);
            $rows = mysql_fetch_array($result);
            $exerciseID = $rows['exercise_type_id'];
            // Save the current row into the flexercises table
            $query = "INSERT INTO flexercises (exercises_id, exercise_type_id, set_number, reps, weight) VALUES ({$exercisesID}, {$exerciseID}, {$setNum}, {$reps}, {$weight})";
            $result = @mysql_query($query, $connection);
            if (!result) {
                $error = true;
            } else {
                $error = false;
                $recordsSaved++;
            }
        }
        if (!$error) {
            $msg = "<saveTemplate>" . "<recordssaved>" . $recordsSaved . "</recordssaved>" . "</saveTemplate>";
        } else {
            $msg = "<saveDay>" . "<error>" . "There was an error saving your workout" . "</error>" . "</saveDay>";
        }
    }
    return $msg;
}
Example #5
0
function create_history($connection, $template)
{
    $userid = getUserID($connection);
    $yearmoday = explode("-", $_SESSION["nav_month"]);
    // See if the users is trying to display a month other than the current month.
    if ($yearmoday != NULL) {
        $display_mo = new Date();
        $display_mo->setDayMonthYear($yearmoday[2], $yearmoday[1], $yearmoday[0]);
    } else {
        $display_mo = new Date();
    }
    $LastDay = $display_mo->getYear() . "-" . $display_mo->getMonth() . "-" . $display_mo->GetDaysInMonth();
    $FirstDay = $display_mo->format("%Y") . "-" . $display_mo->format("%m") . "-" . "1";
    $sbr_type = array("s", "b", "r");
    $total_duration = array(0, 0, 0);
    $total_distance = array(0, 0, 0);
    $total_calories = array(0, 0, 0);
    $i = 0;
    while ($i < 3) {
        $query = "SELECT * FROM flmain WHERE user_id={$userid} AND workout_date>='" . $FirstDay . "' AND workout_date<='" . $LastDay . "' AND sbr_type='" . $sbr_type[$i] . "' ORDER BY workout_date ASC";
        $result = @mysql_query($query, $connection);
        if (mysql_num_rows($result) > 0) {
            //set the correct template block
            selectActivityBlock($i, $template);
            //Get the first row of data and compare it to the day of the month to see if we have any
            //data to display on the current day.
            $row = mysql_fetch_array($result);
            //Out put each day of the displayed month. If we have data for that day
            //then put it into the grid also.
            $currentDay = new Date();
            $nextMonth = new Date();
            $currentDay->setDayMonthYear(1, $display_mo->getMonth(), $display_mo->getYear());
            //Move the display_mo to the first day of the next month.
            $nextMonth->setDayMonthYear($display_mo->GetDaysInMonth(), $display_mo->getMonth(), $display_mo->getYear());
            $nextMonth->addDays(1);
            while ($currentDay->before($nextMonth)) {
                // select the correct activity block.
                selectActivityBlock($i, $template);
                $template->setVariable("UPDATE", $currentDay->format("%Y-%m-%d"));
                $template->setVariable("DATE", $currentDay->format("%b %e, %Y"));
                //Check to see if the current day matches the current row, if so then output it.
                if (!strcmp($currentDay->format("%Y-%m-%d"), $row["workout_date"])) {
                    outputCurrentDay($template, $row, $i);
                    //Add up the duration, distance and calories
                    $total_dur[$i] = $total_dur[$i] + convert_time_seconds($row["duration"]);
                    $total_dist[$i] = $total_dist[$i] + $row["distance"];
                    $total_cal[$i] = $total_cal[$i] + $row["cals_burned"];
                    $row = mysql_fetch_array($result);
                }
                $template->parseCurrentBlock();
                $currentDay->addDays(1);
            }
            outputTotals($template, $total_dur[$i], $total_dist[$i], $total_cal[$i], $i);
        } else {
            $currentDay = new Date();
            $nextMonth = new Date();
            $currentDay->setDayMonthYear(1, $display_mo->getMonth(), $display_mo->getYear());
            //Move the display_mo to the first day of the next month.
            $nextMonth->setDayMonthYear($display_mo->GetDaysInMonth(), $display_mo->getMonth(), $display_mo->getYear());
            $nextMonth->addDays(1);
            while ($currentDay->before($nextMonth)) {
                // set the correct activity block.
                selectActivityBlock($i, $template);
                $template->setVariable("UPDATE", $currentDay->format("%Y-%m-%d"));
                $template->setVariable("DATE", $currentDay->format("%b %e, %Y"));
                $template->parseCurrentBlock();
                $currentDay->addDays(1);
            }
        }
        $i = $i + 1;
    }
}