include("include.php");
include("datefunctions.php");
$pageName= "reports.php";
if ( !$userLoggedIn )
{
header( "location: login.php?from=new");
exit;
}
else
{
$cUserInfo = GetUserInfo( $userLoggedIn );
$usUserName = $userLoggedIn;
}
$formatChecked[individual] = "CHECKED";
$noReport = 1;
if ( count($HTTP_POST_VARS) > 0 )
{
$shared = "";
if ( $shareWorkout == "T" )
$shared = "T";
else
$shared = "F";
switch( $submit )
{
case "Show Workouts":
// Check Date Range validity
$dateError = CheckDateRange( $starDate, $endDate );
if ( !$dateError )
{
$sql = "
SELECT
woId,
woDate,
woTime,
woDistance,
woType,
woComments
FROM
workouts
WHERE
usUserName = '$usUserName'
";
if ( $woType != "All" )
$sql .= "AND woType = '$woType' ";
if (!empty($startDate) && !empty($endDate) )
$sql .= " and to_days(woDate) BETWEEN to_days('$startDate') and to_days('$endDate')";
$sql .= " ORDER BY woDate";
// echo("$sql");
$noReport = 0;
$formatChecked[$reportFormat] = "checked";
}
break;
case "addnote":
$sql = "
INSERT INTO
notes ( noteText, notePageName, usUserName )
VALUES
( '$newNote', '$pageName', '$usUserName' )
";
break;
case "addworkout":
$newWoTime = $newWoTimeHours*60 + $newWoTimeMin;
$sql = "
INSERT INTO
workouts ( woDate, woType, woDistance, woTime, woComments, usUserName, woShared )
VALUES
('$newWoDate', '$newWoType', '$newWoDistance', '$newWoTime', '$newWoComments', '$usUserName', '$shared' )
";
break;
default:
break;
}
// echo("sql - $sql
");
if ( !($result = mysql_query($sql,$conn)) ) DBErr($sql, $conn);
}
// get current date
if ( !$woDate )
$today = date("Y-m-d");
else
$today = $woDate;
if ( $startDate == "" ) $startDate = $today;
if ( $endDate == "" ) $endDate = $today;
?>
InnerAthlete™ - Free Training Log and Fitness Portal: running, cycling, triathlons, adventure racing.
|
| Run Reports |
|
if ( !$noReport )
{
echo("");
switch ( $reportFormat )
{
case weeksummary;
case monthsummary;
case yearsummary;
ShowSummaryItemReport( $sql, $reportFormat );
break;
case individual;
ShowIndividualItemReport( $sql );
break;
case calender;
ShowCalenderItemReport( $sql, $endDate );
break;
}
}
?>
| Copyright©
1999-2007 InnerAthlete™ All rights reserved.
|
|
|
|
/*
*/
function ShowIndividualItemReport( $sql )
{
global $conn;
echo("
| |
Date |
Type |
Distance |
Time |
Comments |
Modify Workout |
");
if ( !($result = mysql_query($sql,$conn)) ) DBErr($sql, $conn);
$count = 0;
while( list( $woId, $woDate, $woTime, $woDistance, $woType, $woComments ) = mysql_fetch_row($result) )
{
$sums[$woType][timeSum] += $woTime;
$sums[$woType][distanceSum] += $woDistance;
$sums[$woType][wocount]++;
$timeStr = GetTimeString( $woTime );
if ( $count%2 )
$bgc = "#DDDDDD";
else
$bgc = "#FFFFFF";
echo("
| |
$woDate |
$woType |
$woDistance |
$timeStr |
$woComments |
Modify |
");
$count++;
}
echo("
| |
Wo Type |
Total Time |
Ave. Time |
Total Distance |
Ave. Distance |
|
");
$count=0;
while( list( $woType, $sumInfo ) = each( $sums ) )
{
$aveTime = $sumInfo[timeSum]/$sumInfo[wocount];
$aveTime = GetTimeString( $aveTime );
$aveDistance = $sumInfo[distanceSum]/$sumInfo[wocount];
$aveDistance = round( $aveDistance, 2 );
$timeStr = GetTimeString($sumInfo[timeSum]);
if ( $count%2 )
$bgc = "#DDDDDD";
else
$bgc = "#FFFFFF";
echo("
| |
$woType |
$timeStr |
$aveTime |
$sumInfo[distanceSum] |
$aveDistance |
|
");
$count++;
}
} // ShowIndividualItemReport
/*
*/
function ShowSummaryItemReport( $sql, $timePeriod )
{
global $conn, $startDate, $endDate;
if ( !($result = mysql_query($sql,$conn)) ) DBErr($sql, $conn);
$count = 0;
while( list( $woId, $woDate, $woTime, $woDistance, $woType, $woComments ) = mysql_fetch_row($result) )
{
//echo("dates: $dateIndex, $woDate, $timePeriod
" );
$dateIndex = GetIndex( $woDate, $timePeriod );
$sums[$dateIndex][$woType][timeSum] += $woTime;
$sums[$dateIndex][$woType][distanceSum] += $woDistance;
$sums[$dateIndex][$woType][wocount]++;
}
// echo("| $timePeriod Summary |
");
echo("
| |
Dates |
Wo Type |
Total Time |
Ave Time |
Total Dist. |
Ave. Dist. |
");
$count=0;
while( list( $dateIndex, $daySumInfo ) = each( $sums ) )
{
$periodTotalTime = 0;
$periodTotalDistance = 0;
while( list( $woType, $sumInfo ) = each( $daySumInfo ) )
{
if ( $sumInfo[wocount] )
{
$aveTime = round( $sumInfo[timeSum]/$sumInfo[wocount], 2 );
$aveTime = GetTimeString( $aveTime );
}
$timeStr = GetTimeString( $sumInfo[timeSum] );
if ( $sumInfo[wocount] )
$aveDistance = round( $sumInfo[distanceSum]/$sumInfo[wocount], 2 );
if ( $count%2 )
$bgc = "#DDDDDD";
else
$bgc = "#FFFFFF";
echo("
| |
$dateIndex |
$woType |
$timeStr |
$aveTime |
$sumInfo[distanceSum] |
$aveDistance |
");
$count++;
$totals[$woType][time1] += $sumInfo[timeSum];
$totals[$woType][distance] += $sumInfo[distanceSum];
$totalTime += $sumInfo[timeSum];
$totalDistance += $sumInfo[distanceSum];
$periodTotalTime += $sumInfo[timeSum];
$periodTotalDistance += $sumInfo[distanceSum];
}
$timeStr = GetTimeString( $periodTotalTime );
echo("
| |
$dateIndex |
|
Total Time |
$timeStr |
Total Dist: |
$periodTotalDistance |
");
}
echo("
| |
Totals |
");
echo("
| |
Totals by Type |
Workout Type |
Time |
Distance |
");
while( list( $woType, $sum ) = each( $totals ) )
{
$timeStr = GetTimeString($sum[time1]);
echo("
| |
|
$woType |
$timeStr |
$sum[distance] |
");
}
$timeStr = GetTimeString( $totalTime );
echo("
| |
TOTALS: |
$timeStr |
$totalDistance |
");
} // ShowSummaryItemReport
/*
*/
function ShowCalenderItemReport( $sql, $endDate )
{
global $conn;
if ( !$endDate )
$endDate = $today = date("Y-m-d");
$dateArray = explode( "-", $endDate );
$reportYear = intval( $dateArray[0] );
$reportMonth = intval( $dateArray[1] );
if ( !($result = mysql_query($sql,$conn)) ) DBErr($sql, $conn);
while( list( $sql, $woDate, $woTime, $woDistance, $woType, $woComments ) = mysql_fetch_row($result) )
{
//echo("endDate - $endDate
");
$dateArray = explode( "-", $woDate );
$year = intval( $dateArray[0] );
$month = intval( $dateArray[1] );
$day = intval( $dateArray[2] );
if ( $reportYear != $year || $reportMonth != $month )
continue;
$distStr = "";
$timeStr = "";
if ( $woDistance != 0 )
{
$distStr = " dist:" . $woDistance;
$timeStr = ",";
}
if ( $woTime != 0)
$timeStr .= " " . $woTime . " mins";
$dayItemList[$day] .= $woType . $distStr . $timeStr . " " . $woComments . "
";
}
// Won't give them the option to page through months yet.
// ShowMonthYearSelection( "showbymonth.php" );
ShowCalendarMonth( $dayItemList, $reportMonth, $reportYear );
}
/*
From the given date and time period creates an array ready index.
E.G. For a year, returns the year of the date, for month returns
month and year, for week returns date1-date2.
*/
function GetIndex( $woDate, $timePeriod )
{
global $conn;
$dateArray = explode( "-", $woDate );
$year = intval( $dateArray[0] );
$month = intval( $dateArray[1] );
$day = intval( $dateArray[2] );
switch ( $timePeriod )
{
case weeksummary;
//fetch the first day of the week and the last.
$firstday = mktime(0,0,0,$month,$day,$year);
// Get day of week by number.
$day_of_week = date(w,$firstday);
$firstday = mktime(0,0,0,$month,$day-$day_of_week,$year);
$lastday = $day-$day_of_week+6;
$lastday = mktime(0,0,0,$month,$lastday,$year);
$firstDate = date("Y-m-d",$firstday);
$lastDate = date("Y-m-d",$lastday);
$dateIndex = $firstDate . " - " . $lastDate;
break;
case monthsummary;
// Extracts the month and year.
$month_text = mktime(0,0,0,$month,1,$year);
$month_text = date(F,$month_text);
$dateIndex = $month_text . ", " . $year;
break;
case yearsummary;
// Extracts the year.
$dateIndex = $year;
break;
}
return $dateIndex;
}
function ShowWorkOutWeek()
{
$today = date("Y-m-d");
$datesInWeek = GetWeekRange( $today, $startDate, $endDate );
$weekDateRange = "$startDate - $endDate";
echo("
|
Workouts Completed this week: $weekDateRange
|
");
// ShowWorkouts( $startDate, $endDate, FALSE );
ShowWorkoutsWeekView( $startDate, $endDate, FALSE, $datesInWeek );
// ShowWorkouts( "2002-03-03", "2002-03-09", FALSE );
echo ("
| |
|
Scheduled Workouts for $weekDateRange Edit Program
|
");
// ShowWorkouts( $startDate, $endDate, TRUE );
ShowWorkoutsWeekView( $startDate, $endDate, TRUE, $datesInWeek );
echo("
");
}
function ShowWorkouts( $startDate, $endDate, $scheduled )
{
global $conn, $usUserName;
if ( $scheduled )
{
$startDate = date("Y-m-d");
$fromTable = "scheduledworkouts";
}
else
$fromTable = "workouts";
$sql = "
SELECT woId, woDate, woTime, woDistance, woType, woComments
FROM $fromTable
WHERE usUserName = '$usUserName'
and to_days(woDate) BETWEEN to_days('$startDate') and to_days('$endDate')
ORDER BY woDate";
// echo("sql - $sql
");
if ( !($result = mysql_query($sql,$conn)) ) DBErr($sql, $conn);
$count = 0;
$totalTime = 0;
while( list( $woId, $woDate, $woTime, $woDistance, $woType, $woComments ) = mysql_fetch_row($result) )
{
$timeStr = GetTimeString( $woTime );
if ( $woComments == "" )
$woComments = " ";
echo("
| $woDate |
$woType |
$woDistance |
$timeStr |
$woComments |
Modify |
");
$count++;
$totalTime += $woTime;
}
$timeStr = GetTimeString( $totalTime );
echo("
| Total Number |
$count |
Total Time |
$timeStr |
|
|
");
} // ShowWorkouts()
function ShowWorkoutsWeekView( $startDate, $endDate, $scheduled, $datesInWeek )
{
global $conn, $usUserName;
if ( $scheduled )
{
$startDate = date("Y-m-d");
$fromTable = "scheduledworkouts";
$noneMess = "None Scheduled";
}
else
{
$fromTable = "workouts";
$noneMess = "None Completed....slacker";
}
$sql = "
SELECT woId, woDate, woTime, woDistance, woType, woComments
FROM $fromTable
WHERE usUserName = '$usUserName'
and to_days(woDate) BETWEEN to_days('$startDate') and to_days('$endDate')
ORDER BY woType, woDate";
// echo("sql - $sql
");
if ( !($result = mysql_query($sql,$conn)) ) DBErr($sql, $conn);
$count = 0;
$totalTime = 0;
while( list( $woId, $woDate, $woTime, $woDistance, $woType, $woComments ) = mysql_fetch_row($result) )
{
$woWeekInfo[$woType][$woDate][woTime] = $woTime;
$woWeekInfo[$woType][$woDate][woDist] = $woDistance;
$woWeekInfo[$woType][woTotalTime] += $woTime;
$woWeekInfo[$woType][woTotalDist] += $woDistance;
$woWeekInfo[$woType][$woDate][woComments] = $woComments;
$woWeekInfo[$woType][$woDate][woId] = $woId;
$count++;
$totalTime += $woTime;
}
if ( $count > 0 )
{
echo("| Type |
Sun. $datesInWeek[0] |
Mon. $datesInWeek[1] |
Tues. $datesInWeek[2] |
Wed. $datesInWeek[3] |
Thur. $datesInWeek[4] |
Fri. $datesInWeek[5] |
Sat. $datesInWeek[6] |
Totals |
");
}
else
echo("| $noneMess | ");
// var_dump( $woWeekInfo);
if ( is_array( $woWeekInfo ) )
{
while (list( $woType, $woDayInfo ) = each( $woWeekInfo ) )
{
echo("$woType | ");
for ( $i = 0; $i < 7; $i++ )
{
$theDate = $datesInWeek[$i];
$woTime = $woDayInfo[$theDate][woTime];
$woDistance = $woDayInfo[$theDate][woDistance];
// echo("WO - $theDate, $woTime, $woDistance, $woId
");
$woId = $woDayInfo[$theDate][woId];
if ( $woId > 0 )
echo("Time: $woTime Min. Dist.: $woDistance
edit | ");
else
echo(" | ");
}
$woTotalTime = $woDayInfo[woTotalTime];
$woTotalDist = $woDayInfo[woTotalDist];
echo("Time: $woTotalTime Min. Dist.: $woTotalDist |
");
}
}
$timeStr = GetTimeString( $totalTime );
echo("
| |
Total Number |
$count |
Total Time |
$timeStr |
");
} // ShowWorkoutsWeekView()
?>