0 ) { $datesInWeek = GetWeekRange( $startDate, $startDate, $endDate ); $sql = " DELETE FROM scheduledworkouts WHERE usUserName = '$usUserName' AND to_days(woDate) BETWEEN to_days('$startDate') and to_days('$endDate') "; // echo("sql - $sql
"); // if ( !($result = mysql_query($sql,$conn)) ) DBErr($sql, $conn); } if ( count($HTTP_POST_VARS) > 0 ) { switch( $submit ) { case "Show Template": $showTemplate=TRUE; break; case "Hide Template": $showTemplate=FALSE; break; case "Add Workout": $templateExists = TRUE; $newTwoTime = $newTwoTimeHours*60 + $newTwoTimeMin; $sql = " INSERT INTO templateworkouts ( twoDay, twoType, twoDistance, twoTime, twoComments, usUserName ) VALUES ('$newTwoDay', '$newTwoType', '$newTwoDistance', '$newTwoTime', '$newTwoComments', '$usUserName' ) "; // echo("sql - $sql
"); // if ( !($result = mysql_query($sql,$conn)) ) DBErr($sql, $conn); break; case "Create Program": if ( $tpName == "" ) $errMess = "You must enter a program name"; else { $sql = " INSERT INTO trainingprogram ( tpName, usUserName, tpGoal, tpGoalDate, tpTimeGoal ) VALUES ( '$tpName', '$usUserName', '$tpGoal', '$tpGoalDate', '$tpTimeGoal') "; // if ( !($result = mysql_query($sql,$conn)) ) DBErr($sql, $conn); $programExists = TRUE; } break; case "Create Schedule": if ( $tpGoalDate != "" ) { // need to validate date. // Fetch the first day of this week $day = date(j) - date(w); $month = date(n); $year = date(Y); $firstday = mktime(0,0,0,$month,$day,$year); $theDate = explode( "-", $tpGoalDate ); $lastday = mktime(0,0,0,$theDate[1],$theDate[2],$theDate[0]); $day = date(j,$lastday) - date(w,$lastday) + 7; $month = date(n,$lastday); $year = date(Y,$lastday); $lastday = mktime(0,0,0,$month,$day,$year); $timeDiff = $lastday - $firstday; $weeksBetween = $timeDiff/(60*60*24*7); } else $weeksBetween = $numberOfWeeks; $day = date(j) - date(w); $month = date(n); $year = date(Y); $firstDay = mktime(0,0,0,$month,$day,$year); $firstDay = date("Y-m-d", $firstDay); $weeksBetween = round( $weeksBetween ); CreateTrainingProgramWeeks( $weeksBetween, $firstDay ); $hasScheduledWorkouts = TRUE; break; case "Save Changes": if ( $tpName == "" ) $errMess = "You must enter a program name"; else { $sql = " UPDATE trainingprogram SET tpName = '$tpName', tpGoal = '$tpGoal', tpGoalDate = '$tpGoalDate', tpTimeGoal = '$tpTimeGoal' WHERE usUserName = '$usUserName' "; // if ( !($result = mysql_query($sql,$conn)) ) DBErr($sql, $conn); } break; case "Add Week": $day = date(j) - date(w); $month = date(n); $year = date(Y); $firstDay = mktime(0,0,0,$month,$day,$year); $firstDay = date("Y-m-d", $firstDay); CreateTrainingProgramWeeks( 1, $weekStartDate ); break; case "Delete Program": if ( $usUserName != "" AND $tpName != "" ) { $sql = " DELETE FROM trainingprogram WHERE usUserName = '$usUserName' AND tpName = '$tpName' "; // echo("sql - $sql
"); // if ( !($result = mysql_query($sql,$conn)) ) DBErr($sql, $conn); $today = date("Y-m-d"); $sql = " DELETE FROM scheduledworkouts WHERE usUserName = '$usUserName' "; // echo("sql - $sql
"); // if ( !($result = mysql_query($sql,$conn)) ) DBErr($sql, $conn); $sql = " DELETE FROM templateworkouts WHERE usUserName = '$usUserName' "; // if ( !($result = mysql_query($sql,$conn)) ) DBErr($sql, $conn); $programExists = FALSE; $templateExists = FALSE; $hasScheduledWorkouts = FALSE; $showTemplate = FALSE; $tpName = FALSE; $tpGoal = FALSE; $tpGoalDate = FALSE; $tpTimeGoal = FALSE; } break; case "addworkout": $newWoTime = $newWoTimeHours*60 + $newWoTimeMin; $sql = " INSERT INTO workouts ( woDate, woType, woDistance, woTime, woComments, usUserName, woScheduled ) VALUES ('$newWoDate', '$newWoType', '$newWoDistance', '$newWoTime', '$newWoComments', '$usUserName', 'T' ) "; if ( !($result = mysql_query($sql,$conn)) ) DBErr($sql, $conn); break; default: break; } } else { $cTP = new CTrainingProgram( $usUserName ); $showTemplate = TRUE; if ( $cTP->tpName != "" ) { $programExists = TRUE; $tpName = $cTP->tpName; $tpGoal = $cTP->tpGoal; $tpGoalDate = $cTP->tpGoalDate; $tpTimeGoalHours = $cTP->tpTimeGoalHours; $tpTimeGoalMinutes = $cTP->tpTimeGoalMinutes; $template = $cTP->template; $hasScheduledWorkouts = CheckForScheduledWorkouts(); if ( $hasScheduledWorkouts ) $showTemplate = FALSE; } else $programExists = FALSE; } if ( $programExists ) { FetchTemplateWorkouts( $template, $count ); if ( $count > 0 ) $templateExists = TRUE; else $templateExists = FALSE; } else $templateExists = FALSE; ?> InnerAthlete™ - Free Training Log and Fitness Portal: running, cycling, triathlons, adventure racing.
Your Ad Here
HOME My IA Tools Articles Find Trainer/Coach Events About  
Create/Edit Training Program

Add new workout
Date: " SIZE=12>   Type: Distance:
Time: Hrs. min: Comments:
$errMess
"); ?>
Creating a training program  
"); } else echo(" "); echo(" "); if ( $programExists ) { if ( $showTemplate ) { echo(""); if ( $templateExists && !$hasScheduledWorkouts ) { echo(" "); } } else { echo(" "); } if ( $hasScheduledWorkouts ) { echo(" "); } } if ( $hasScheduledWorkouts ) { echo(" "); } ?>
Program Name: Race or Overall Goal: Race or Goal Date:  
Sub-Goals:
Sub-Goal #1:
Sub-Goal #2:
Sub-Goal #3:
Objective #1:
Objective #2:
Objective #3:
Objective #4:
Objective #5:
Race or Leg Type #1: Race or Leg Distance #1 Race or Leg Time #1
Race or Leg Type #2: Race or Leg Distance #2 Race or Leg Time #2
Race or Leg Type #3: Race or Leg Distance #3 Race or Leg Time #3
Goal or Race Notes:
   
"); ShowTemplateForm(); ShowTemplateWorkOutWeek( $template, $count ); echo("
Click here to automatically generate your workout schdule based on you template.
Click here to see and edit your training template
"); ShowScheduledWorkouts($tpName, $tpGoalDate); echo("
Home |  Help |  Contact Us |  Site Map |  Coach Benson
Copyright© 1999-2007 InnerAthlete™ All rights reserved. 
 
"); global $conn, $usUserName, $tpName; if ($numberofWeeks > 52 || $numberofWeeks <= 0 ) $numberofWeeks = 52; $sql = " SELECT twoDay, twoTime, twoDistance, twoType, twoComments FROM templateworkouts WHERE usUserName = '$usUserName' ORDER BY twoType, twoDay "; // if ( !($result = mysql_query($sql,$conn)) ) DBErr($sql, $conn); $dateOffset = 0; while( list( $twoDay, $twoTime, $twoDistance, $twoType, $twoComments ) = mysql_fetch_row($result) ) { // what about multiple workouts of the same type on the same day? $workouts[$twoDay][$twoType][dist] = $twoDistance; $workouts[$twoDay][$twoType][time] = $twoTime; $workouts[$twoDay][$twoType][comments] = $twoComments; //echo("$twoDay, $twoTime, $twoDistance, $twoType
"); } for ( $i = 0; $i < $numberofWeeks; $i++ ) CreateWorkOutWeek( $workouts, $i, $programStartDate ); } function CreateWorkOutWeek( $workouts, $weekNumber, $startDate ) { global $conn, $usUserName; while( list( $twoDay, $workoutsByDay ) = each($workouts) ) { while( list( $twoType, $workoutsByDayType ) = each($workoutsByDay) ) { $twoDistance = $workouts[$twoDay][$twoType][dist]; $twoTime = $workouts[$twoDay][$twoType][time]; $twoComments = $workouts[$twoDay][$twoType][comments]; $theDate = explode( "-", $startDate ); // week (dayinweek) for date of current workout. $theDay = mktime(0,0,0,$theDate[1],$theDate[2]+$twoDay+$weekNumber*7,$theDate[0]); $newWoDate = date("Y-m-d", $theDay); // echo("$newWoDate, $twoDay, $twoTime, $twoDistance, $twoType
"); $sql = " REPLACE INTO scheduledworkouts ( woDate, woType, woDistance, woTime, woComments, usUserName ) VALUES ('$newWoDate', '$twoType', '$twoDistance', '$twoTime', '$twoComments', '$usUserName' ) "; // echo("sql - $sql
"); // if ( !($result = mysql_query($sql,$conn)) ) DBErr($sql, $conn); } } } function GetWeekList( $tpName, $lastDay ) { global $conn, $usUserName; // Fetch the first day of this week $day = date(j) - date(w); $month = date(n); $year = date(Y); $firstday = mktime(0,0,0,$month,$day,$year); $theDate = explode( "-", $lastDay ); $lastDay = mktime(0,0,0,$theDate[1],$theDate[2],$theDate[0]); $endday = date(j,$lastDay) - date(w,$lastDay) + 7; $endmonth = date(n,$lastDay); $endyear = date(Y,$lastDay); $lastDay = mktime(0,0,0,$endmonth,$endday,$endyear); $timeDiff = $lastDay - $firstday; $weeksBetween = $timeDiff/(60*60*24*7); $firstday = date("Y-m-d", $firstday); $offset = 0; for ( $i = 0; $i < $weeksBetween; $i++ ) { $sql = " SELECT woDate, woTime, woDistance, woType FROM scheduledworkouts WHERE usUserName = '$usUserName' and to_days(woDate) BETWEEN to_days('$firstday')+$offset and to_days('$firstday')+$offset+7 "; //echo("sql - $sql
"); // if ( !($result = mysql_query($sql,$conn)) ) DBErr($sql, $conn); $count = 0; $totalTime = 0; $firstDayOfWeek = mktime(0,0,0,$month,$day+$offset,$year); $firstDayOfWeek = date( "Y-m-d", $firstDayOfWeek); while( list( $woDate, $woTime, $woDistance, $woType ) = mysql_fetch_row($result) ) { // echo(" HERE! - $woTime, $woDistance, $woType
"); $trainingWeeks[$firstDayOfWeek][woCount]++; $trainingWeeks[$firstDayOfWeek][woTime]+= $woTime; $trainingWeeks[$firstDayOfWeek][woDistance]+= $woDistance; } $offset += 7; } return( $trainingWeeks ); } function ShowTemplateForm() { global $hasScheduledWorkouts; echo(" "); if ( $hasScheduledWorkouts ) { echo(" "); } else { echo(" "); } } class CTrainingProgram { var $usUserName; var $tpName = ""; var $tpGoal; var $tpGoalDate; var $tpTimeGoalHours; var $tpTimeGoalMinutes; var $template = FALSE; function CTrainingProgram( $usUserName ) { global $conn; // Load all training program info. $sql = " SELECT tpName, tpGoal, tpGoalDate, tpTimeGoal FROM trainingprogram WHERE usUserName = '$usUserName' "; // if ( !($result = mysql_query($sql,$conn)) ) DBErr($sql, $conn); if ( list( $this->tpName, $this->tpGoal, $this->tpGoalDate, $tpTimeGoal ) = mysql_fetch_row( $result ) ) { $this->tpTimeGoalHours = (int)floor( $tpTimeGoal/60 ); $this->tpTimeGoalMinutes .= $tpTimeGoal%60; } } // CTrainingProgram() } function CheckForScheduledWorkouts() { global $conn, $usUserName; $sql = " SELECT woId FROM scheduledworkouts WHERE usUserName = '$usUserName' "; //echo("sql - $sql
"); // if ( !($result = mysql_query($sql,$conn)) ) DBErr($sql, $conn); if ( mysql_num_rows($result) > 0 ) return TRUE; else return FALSE; } function ShowScheduledWorkouts($tpName, $tpGoalDate) { echo("
Training Template
Click here to hide your training template
Day:  Type: Distance:
Time: Hrs. min: Comments:
Click here to add a workout (from the above fields) to your workout template (shown below).
Click here to add a workout (from the above fields) to your workout template (shown below).
"); $weekList = GetWeekList( $tpName, $tpGoalDate ); if ( is_array( $weekList ) ) { while ( list( $firstDayOfWeek, $weekInfo ) = each( $weekList ) ) { echo(" "); } } echo("
Week Start Date Total Workouts Total Time Total Distance    
$firstDayOfWeek $weekInfo[woCount] $weekInfo[woTime] $weekInfo[woDistance] Edit Week Delete Week
"); } function FetchTemplateWorkouts( &$template, &$count ) { global $conn, $usUserName; $sql = " SELECT twoId, twoDay, twoTime, twoDistance, twoType, twoComments FROM templateworkouts WHERE usUserName = '$usUserName' ORDER BY twoType, twoDay "; //echo("sql - $sql
"); // if ( !($result = mysql_query($sql,$conn)) ) DBErr($sql, $conn); $count = 0; $totalTime = 0; $hasTemplate = FALSE; while( list( $twoId, $twoDay, $twoTime, $twoDistance, $twoType, $twoComments ) = mysql_fetch_row($result) ) { $hasTemplate = TRUE; //"date, time, type - $twoDay, $twoTime, $twoType, $twoDistance
"); $template[$twoType][$twoDay][twoTime] = $twoTime; $template[$twoType][$twoDay][twoDist] = $twoDistance; $template[$twoType][twoTotalTime] += $twoTime; $template[$twoType][twoTotalDist] += $twoDistance; $template[$twoType][$twoDay][twoComments] = $twoComments; $template[$twoType][$twoDay][twoId] = $twoId; $count++; $totalTime += $twoTime; } } function ShowTemplateWorkOutWeek( $template, $count ) { echo(" "); if ( $count > 0 ) { while (list( $twoType, $twoDayInfo ) = each( $template ) ) { echo(""); for ( $i = 1; $i < 8; $i++ ) { $twoTime = $twoDayInfo[$i][twoTime]; $twoDistance = $twoDayInfo[$i][twoDist]; $twoId = $twoDayInfo[$i][twoId]; if ( $twoId > 0 ) echo(""); else echo(""); } $twoTotalTime = $twoDayInfo[twoTotalTime]; $totalTime += $twoTotalTime; $twoTotalDist = $twoDayInfo[twoTotalDist]; echo(""); } } $timeStr = GetTimeString( $totalTime ); if ( $count == "" ) $count = 0; echo(" "); echo("
Type Sun. Mon. Tues. Wed. Thur. Fri. Sat. Totals
$twoTypeTime: $twoTime Min.
Dist.: $twoDistance
edit
 Time:$twoTotalTime
Dist.:$twoTotalDist
  Total Number $count Total Time $timeStr
"); } // ShowTemplateWorkOutWeek() ?>