<?php
include("system/functions.php");
include("system/environment.php");
?>
<html>
<?php
include("system/head.php");
?>
<body>
<div class="logo"><a href="http://run.sourceforge.net/index.php?run=08"><img src="system/imgs/runsmall.png" border="0"></a></div>
<div class="navigation">
<script language="javascript" type="text/javascript">
function editWindow(url) {
link = window.open(url,'edit','location=no,toolbar=no,scrollbars=no,width=370,height=630');
}
function logrunWindow(url) {
link = window.open(url,'logarun','toolbar=no,location=no,scrollbars=no,width=370,height=630');
}
function paceWindow(url) {
link = window.open(url,'pace','toolbar=no,location=no,scrollbars=yes,width=440,height=680');
}
function shoesWindow(url) {
link = window.open(url,'shoes','toolbar=no,location=no,scrollbars=yes,width=520,height=630');
}
function settingsWindow(url) {
link = window.open(url,'settings','toolbar=no,location=no,scrollbars=yes,width=340,height=660');
}
function detailsWindow(url) {
link = window.open(url,'details','toolbar=no,location=no,scrollbars=no,width=370,height=630');
}
</script>
<a href="javascript:logrunWindow('logrun.php')" title="Log a Run: Alt+L" accesskey="l" class="url"><u>L</u>og a Run</a> |
<a href="javascript:paceWindow('pace.php')" title="Pace Calculator: Alt+P" accesskey="p" class="url"><u>P</u>ace Calculator</a> |
<a href="javascript:shoesWindow('shoes.php?active=1')" title="Shoe Management: Alt+S" accesskey="s" class="url"><u>S</u>hoe Management</a> |
<a href="javascript:settingsWindow('runnersettings.php')" title="Settings: Alt+O" accesskey="o" class="url">Settings</a> |
<a href="<?php $_SERVER['PHP_SELF'] ?>" title="Refresh: Alt+R" accesskey="R" class="url"><u>R</u>efresh</a> |
<a href="index.php?logout=1" title="Logout User: Alt+Q" accesskey="q" class="url">Logout</a>
</div>
<div class="content">
<table cellpadding="5" cellspacing="0" border="0">
<tr>
<td class="user" colspan="3">Runner: <?php echo $user?></td>
<td class="right" colspan="12">
<?php //echo $_SERVER['REQUEST_URI']?>
<!-- begin form for selecting criteria for data to be displayed: month, year, shoes !-->
<form class="log" method="get" action="<?php echo $_SERVER['PHP_SELF'] ?>">
Display data for month <select class="log" name="month">
<option value="<?php echo $_GET['month']?>"><?php if ($_GET['month'] == '' || $_GET['month'] == 'All') { echo 'All'; } else { echo date("F", mktime(0, 0, 0, $_GET['month'], 1, $_GET['year'])); }?></option>
<option value="All">All</option>
<?php
generateMonths();
?>
</select>
year <select class="log" name="year">
<option value="<?php echo $_GET['year']?>"><?php echo $_GET['year']?></option>
<option value="All">All</option>
<?php
//this part is used to put in the "year" dropdown menu only years since runner started using Run
$yearquery = mysql_query("select distinct year(Date) from $user");
while($year = mysql_fetch_array($yearquery)) {
printf("<option value=\"%s\">%s</option>\n", $year["year(Date)"], $year["year(Date)"]);
}
?>
</select>
shoes <select class="log" name="shoes">
<option value="<?php echo $_GET['shoes']?>"><?php echo $_GET['shoes']?></option>
<option value="All">All</option>
<!-- active shoes dropdown menu delimiter !-->
<option disabled></option>
<option disabled>--Active Shoes--</option>
<?php
//get active shoes from the Shoes table and list them in the last part of the shoe dropdown menu
$getactiveshoes = mysql_query("select distinct ShoeName from $mysqltableshoes where ((RunnerID='$user') and (ShoeRetired!='Y')) order by ShoeName");
while($activeshoes = mysql_fetch_array($getactiveshoes)) {
printf("<option value=\"%s\">%s</option>", $activeshoes["ShoeName"], $activeshoes["ShoeName"]);
}
?>
<!-- retired shoes dropdown menu delimiter !-->
<option disabled></option>
<option disabled>--Retired Shoes--</option>
<?php
//get retired shoes from the Shoes table and list them in the last part of the shoe dropdown menu
$getretiredshoes = mysql_query("select distinct ShoeName from $mysqltableshoes where ((RunnerID='$user') and (ShoeRetired!='N')) order by ShoeName");
while($retiredshoes = mysql_fetch_array($getretiredshoes)) {
printf("<option value=\"%s\">%s</option>", $retiredshoes["ShoeName"], $retiredshoes["ShoeName"]);
}
?>
</select>
<input class="log" type="submit" name="submit" accesskey="d" value="Display">
</form>
<!-- end form for selecting criteria for data to be displayed: month, year, shoes !-->
</td>
</tr>
<tr><td class="user" colspan="4">
<?php
//if no value is passed for which month to display, show the current month and year, else display what is requested
//if all months are selected and specific year, show "Data for whole year <year>"
//if all months and years are selected, show "All data"
//if specific month is selected and all years, show "All <month>'s"
//$dateDetail variable determines the amount of date details displayed in the table: 1 shows day of week, day of month, 2 shows day of week, month, day of month, 3 shows day of week, month, day of month, year
if (is_numeric($_GET['month']) && is_numeric($_GET['year']) && $_GET['shoes'] == 'All') {
echo date("F", mktime(0, 0, 0, $_GET['month'], 1, $_GET['year'])) . " " . $_GET['year'];
$dateDetail = 1;
} elseif (is_numeric($_GET['month']) && is_numeric($_GET['year'])) {
echo date("F", mktime(0, 0, 0, $_GET['month'], 1, $_GET['year'])) . " " . $_GET['year'] . " in " . $_GET['shoes'];
$dateDetail = 1;
} elseif ($_GET['month'] == 'All' && is_numeric($_GET['year']) && $_GET['shoes'] == 'All') {
echo "Data for whole year " . $_GET['year'];
$dateDetail = 2;
} elseif ($_GET['month'] == 'All' && is_numeric($_GET['year'])) {
echo "Data for whole year " . $_GET['year'] . " in " . $_GET['shoes'];
$dateDetail = 2;
} elseif ($_GET['month'] == 'All' && $_GET['year'] == 'All' && $_GET['shoes'] == 'All') {
echo "All data";
$dateDetail = 3;
} elseif ($_GET['month'] == 'All' && $_GET['year']) {
echo "All data for " . $_GET['shoes'];
$dateDetail = 3;
} elseif (is_numeric($_GET['month']) && $_GET['year'] == 'All' && $_GET['shoes'] == 'All') {
echo $_GET['year'] . " " . date("F", mktime(0, 0, 0, $_GET['month'], 1, 0, 0)) . "'s";
$dateDetail = 3;
} elseif (is_numeric($_GET['month']) && $_GET['year'] == 'All') {
echo $_GET['year'] . " " . date("F", mktime(0, 0, 0, $_GET['month'], 1, 0, 0)) . "'s in " . $_GET['shoes'];
$dateDetail = 3;
}
?>
</td>
<td colspan="11" class="right">
<?php
//previous/next links and when what is shown
//if month and year is selected, show buttons "Previous month" and "Next month"
//if only year is selected (and "All" is selected for month), show buttons "Previous year" and "Next year"
$month = $_GET['month'];
$year = $_GET['year'];
$shoes = $_GET['shoes'];
if (is_numeric($month) && is_numeric($year)) {
if ($month - 1 == 0) {
$monthPrev = 12;
$yearPrev = $year - 1;
} else {
//add 0 if month is a single digit - this prevents mysql queries that return wrong results
if (strlen($month - 1) == 1) {
$monthPrev = str_pad($month - 1, 2, "0", STR_PAD_LEFT);
} else {
$monthPrev = $month - 1;
}
$yearPrev = $year;
}
if ($month + 1 == 13) {
$monthNext = "01";
$yearNext = $year + 1;
} else {
//add 0 if month is a single digit - this prevents mysql queries that return wrong results
if (strlen($month + 1) == 1) {
$monthNext = str_pad($month + 1, 2, "0", STR_PAD_LEFT);
} else {
$monthNext = $month + 1;
}
$yearNext = $year;
}
printf('<a href="?month=%s&year=%s&shoes=%s">Previous month</a>', $monthPrev, $yearPrev, $shoes);
echo " - ";
printf('<a href="?month=%s&year=%s&shoes=%s">Next month</a>', $monthNext, $yearNext, $shoes);
} elseif ($month == "All" && is_numeric($year)) {
printf('<a href="?month=%s&year=%s&shoes=%s">Previous year</a>', $month, $year-1, $shoes);
echo " - ";
printf('<a href="?month=%s&year=%s&shoes=%s">Next year</a>', $month, $year+1, $shoes);
}
?>
</td>
</tr>
<tr>
<?php
//if first digit of $viewMode (system/environment.php) is 1, show summary in main display. if it is 0, show full data in main display.
if (substr($viewMode, 0, 1) == "1") {
?>
<th class="display">Day</th>
<th class="display">Run Type</th>
<th class="display">Time</th>
<th class="display">Distance</th>
<th class="display">AHR</th>
<th class="display">Terrain</th>
<th class="display">Feeling</th>
<th class="display">Notes</th>
<th class="display"></th>
<?php
} elseif (substr($viewMode, 0, 1) == "0") {
?>
<th class="display">Day</th>
<th class="display">Time of Day</th>
<th class="display">Time</th>
<th class="display">Distance</th>
<th class="display">Run Type</th>
<th class="display">Surface</th>
<th class="display">Terrain</th>
<th class="display">Weather</th>
<th class="display">Temp.</th>
<th class="display">AHR</th>
<th class="display">Weight</th>
<th class="display">Shoes</th>
<th class="display">Feeling</th>
<th class="display">Notes</th>
<th class="display"></th>
<?php
}
?>
</tr>
<tr><td height="10px"></td></tr>
<?php
//display data for the selected month/year tool
if($user !== 0) {
//the following three if statements make sure user gets data only for current month/year for all shoes by default
$month = $_GET['month'];
$year = $_GET['year'];
$shoes = $_GET['shoes'];
if ($year == "All") {
$year = null;
}
if ($month == "All") {
$month = null;
}
if ($shoes == "All") {
$shoes = null;
}
$select = mysql_query("select * from $mysqlTableRunningLogs where ((RunnerID='$user') and (Date like '$year%') and (Date like '%-%$month%-%') and (Shoes like '%$shoes%')) order by Date");
$numRows = mysql_num_rows($select);
if ($numRows == 0) {
echo "<tr><td colspan=\"5\" class=\"left\">There are not data for the selected criteria.</td></tr>";
} else {
while($connect = mysql_fetch_assoc($select)) {
//if notes are longer than 100 characters, trunctuate and add elipsis
if (strlen($connect['Notes']) > 100) {
$connect['Notes'] = substr($connect['Notes'], 0, 100) . "...";
}
//separate date into year, month, day
$dateexplode = explode ("-", $connect['Date']);
//set $date to the level of date detail displayed. this correlates to the running log data selection criteria
if ($dateDetail == 1) {
$date = date("l, jS", mktime(0, 0, 0, $dateexplode['1'], $dateexplode['2'], $dateexplode['0']));
} elseif ($dateDetail == 2) {
$date = date("D., M. jS", mktime(0, 0, 0, $dateexplode['1'], $dateexplode['2'], $dateexplode['0']));
} elseif ($dateDetail == 3) {
$date = date("D., M. jS, Y", mktime(0, 0, 0, $dateexplode['1'], $dateexplode['2'], $dateexplode['0']));
}
//if row is even, use different tr style
//first pass $numRows to oddEven function which finds out whether the passed number is odd or even, and then subtract 1 from $numRows to get 1 less than $numRows was in previous turn
$row = oddEven($numRows);
$numRows--;
if (substr($viewMode, 0, 1) == "1") {
printf("
<tr class=\"display%s\">
<td class=\"left\">%s</td>
<td class=\"left\">%s</td>
<td class=\"left\">%s</td>
<td class=\"right\">%s %s</td>
<td class=\"right\">%s bpm</td>
<td class=\"left\">%s</td>
<td class=\"left\">%s</td>
<td class=\"left\" width=\"200px\">%s</td>
<td class=\"left\"><a href=\"?month=%s&year=%s&shoes=%s&rundetails=1&ID=%s\" class=\"url\">Show Details</a><br><a href=\"javascript:editWindow('edit.php?ID=%s')\" class=\"url\">Edit Entry</a></td>
</tr>\n",
$row, $date, $connect["RunType"], $connect["Time"], stripslashes($connect["Distance"]), $connect["DistanceUnit"], stripslashes($connect["AHR"]), $connect["Terrain"], $connect["Feeling"], stripslashes(nl2br(htmlentities($connect['Notes']))), ($month == '') ? $month = 'All' : $month, ($year == '') ? $year = 'All' : $year, ($shoes == '') ? $shoes = 'All' : $shoes, $connect['ID'], $connect["ID"]);
} elseif (substr($viewMode, 0, 1) == "0") {
printf("
<tr class=\"display%s\">
<td class=\"left\">%s</td>
<td class=\"left\">%s</td>
<td class=\"left\">%s</td>
<td class=\"right\">%s %s</td>
<td class=\"left\">%s</td>
<td class=\"left\">%s</td>
<td class=\"left\">%s</td>
<td class=\"left\">%s</td>
<td class=\"right\">%s °%s</td>
<td class=\"right\">%s bpm</td>
<td class=\"right\">%s %s</td>
<td class=\"left\">%s</td>
<td class=\"left\">%s</td>
<td class=\"left\" width=\"200px\">%s</td>
<td class=\"left\"><a href=\"javascript:detailsWindow('details.php?ID=%s')\" class=\"url\">Show Details</a><br><a href=\"javascript:editWindow('edit.php?ID=%s')\" class=\"url\">Edit Entry</a></td>
</tr>\n",
$row, $date, $connect["TimeOfDay"], $connect["Time"], stripslashes($connect["Distance"]), $connect["DistanceUnit"], $connect["RunType"], $connect["Surface"], $connect["Terrain"], $connect["Weather"], stripslashes($connect["Temperature"]), $connect["TemperatureUnit"], stripslashes($connect["AHR"]), stripslashes($connect["Weight"]), $connect["WeightUnit"], $connect["Shoes"], $connect["Feeling"], stripslashes(nl2br(htmlentities($connect["Notes"]))), $connect["ID"], $connect["ID"]);
}
}
}
if ($year == "All") {
$year = null;
}
if ($month == "All") {
$month = null;
}
if ($shoes == "All") {
$shoes = null;
}
//assign distance measurement unit from $units['0'] to $distUnit
$distUnit = $units['0'];
//get the total distance for runs in kilometers
$distanceTotalKm = mysql_result(mysql_query("select sum(Distance) from $mysqlTableRunningLogs where RunnerID='$user' and Date like '$year%' and Date like '%-%$month%-%' and Shoes like '%$shoes%' and DistanceUnit='km'"), 0);
//get the total distance for runs in miles
$distanceTotalMi = mysql_result(mysql_query("select sum(Distance) from $mysqlTableRunningLogs where RunnerID='$user' and Date like '$year%' and Date like '%-%$month%-%' and Shoes like '%$shoes%' and DistanceUnit='mi'"), 0);
//if distance unit in runner's settings is 'km', convert all mile entries to kilometers and add the two values. round the result to two decimal values.
//if distance unit in runner's settings is 'mi', convert all kilometer entries to miles and add the two values. round the result to two decimal values.
if ($distUnit == 'km') {
$distanceMiToKm = $distanceTotalMi * 1.609344;
$distanceTotal = round(($distanceTotalKm + $distanceMiToKm), 2);
} elseif ($distUnit == 'mi') {
$distanceKmToMi = $distanceTotalKm * 0.621371192;
$distanceTotal = round(($distanceTotalMi + $distanceKmToMi), 2);
}
//get the average per run distance
$numberRuns = mysql_result(mysql_query("select count(Distance) from $mysqlTableRunningLogs where ((RunnerID='$user') and (Date like '$year%') and (Date like '%-%$month%-%') and (Shoes like '%$shoes%'))"), 0);
$distanceAvg = round(($distanceTotal / $numberRuns), 2);
//get the total time
$timeTotal = mysql_result(mysql_query("select sec_to_time(sum(time_to_sec(Time))) from $mysqlTableRunningLogs where ((RunnerID='$user') and (Date like '$year%') and (Date like '%-%$month%-%') and (Shoes like '%$shoes%'))"), 0);
//get the average per run time
$timeAvg = mysql_result(mysql_query("select sec_to_time(avg(time_to_sec(Time))) from $mysqlTableRunningLogs where ((RunnerID='$user') and (Date like '$year%') and (Date like '%-%$month%-%') and (Shoes like '%$shoes%'))"), 0);
//display the totals result
//spacer
echo "<tr><td height=\"10px\"></td></tr>";
//if totals are 0, display 0
printf("<tr><td class=\"right\" colspan=\"2\"><b>Total:</b></td><td class=\"right\">%s</td><td class=\"right\">%s %s</td></tr>\n", $timeTotal, ($distanceTotal == 0) ? $distanceTotal = 0 : $distanceTotal, $distUnit);
//display the averages result
//if averages are 0, display 0
printf("<tr><td class=\"right\" colspan=\"2\"><b>Average:</b></td><td class=\"right\">%s</td><td class=\"right\">%s %s</td></tr>\n", $timeAvg, ($distanceAvg == 0) ? $distanceAvg = 0 : $distanceAvg, $distUnit);
}
?>
</table>
</div>
<div class="details">
<?php
if ($_GET['rundetails'] == 1) {
$select = mysql_query("select * from $mysqlTableRunningLogs where ID='".$_GET['ID']."'");
$details = mysql_fetch_assoc($select);
printf("
<table border=\"0\">
<tr><td class=\"left\"colspan=\"2\"><p class=\"header\">Details for the selected run</td></tr>
<tr><td height=\"10px\"></td></tr>
<tr><td class=\"details\">Date:</td><td class=\"left\">%s</td></tr>
<tr><td class=\"details\">Time of Day:</td><td class=\"left\">%s</td></tr>
<tr><td class=\"details\">Time:</td><td class=\"left\">%s</td></tr>
<tr><td class=\"details\">Distance:</td><td class=\"left\">%s %s</td></tr>
<tr><td class=\"details\">Run Type:</td><td class=\"left\">%s</td></tr>
<tr><td class=\"details\">Surface:</td><td class=\"left\">%s</td></tr>
<tr><td class=\"details\">Terrain:</td><td class=\"left\">%s</td></tr>
<tr><td class=\"details\">Weather:</td><td class=\"left\">%s</td></tr>
<tr><td class=\"details\">Temperature:</td><td class=\"left\">%s °%s</td></tr>
<tr><td class=\"details\">Average HR:</td><td class=\"left\">%s bpm</td></tr>
<tr><td class=\"details\">Weight:</td><td class=\"left\">%s %s</td></tr>
<tr><td class=\"details\">Shoes:</td><td class=\"left\">%s</td></tr>
<tr><td class=\"details\">Feeling:</td><td class=\"left\">%s</td></tr>
<tr><td class=\"details\">Notes:</td><td class=\"left\" width=\"200px\">%s</td></tr>
<tr><td height=\"10px\"></td></tr>
<tr><td colspan=\"2\" class=\"right\"><a href=\"javascript:editWindow('edit.php?ID=%s')\" class=\"url\">Edit Entry</a></td></tr>
</table>\n",
datum($details["Date"]), $details["TimeOfDay"], $details["Time"], stripslashes($details["Distance"]), $details["DistanceUnit"], $details["RunType"], $details["Surface"], $details["Terrain"], $details["Weather"], stripslashes($details["Temperature"]), $details["TemperatureUnit"], stripslashes($details["AHR"]), stripslashes($details["Weight"]), $details["WeightUnit"], $details["Shoes"], $details["Feeling"], stripslashes(nl2br(htmlentities($details["Notes"]))), $details["ID"]);
}
?>
</div>
</body>
</html>