Location: PHPKode > projects > Run > Run-0.8.0.2/Run-0.8.0.2/pace.php
<?php
include("system/functions.php");
include("system/environment.php");
?>

<html>
<?php
include("system/head.php");
?>
<body>

<div class="logo"><img src="system/imgs/runsmall.png"></div>

<div class="navigation">
<a href="splits.php" title="Splits: Alt+S" accesskey="s" class="url"><u>S</u>plits Calculator</a>
</div>

<!-- calculate pace !-->
<div class="content">
<p class="header">Calculate Splits</p>

<table width="390px" border="0">
<tr><td class="descript" valign="top">Was my hill run really that fast? Enter your goal time for any distance and you'll get the per kilometer (or mile) pace to achieve your goal.</td></tr>
<tr><td height="15px"></td></tr>

<tr><td>
<table border="0">
<form method="post" action="<?php $_SERVER['PHP_SELF']?>">
<tr><td class="right">Time:</td>
<td class="left">
<input class="log" type="text" name="hrs" size="1" maxlength="2"> hrs</input>
<input class="log" type="text" name="mins" size="1" maxlength="2"> mins</input>
<input class="log" type="text" name="secs" size="1" maxlength="2"> secs</input>
</td></tr>
<tr><td class="right">Distance:</td>
<td class="left">
<input class="log" type="text" name="distance" size="3" maxlength="4"></input>
<select class="log" name="DistanceUnit">
<?php
//system/environment.php holds an if statement that chooses between either a preset value from the settings or from a value selected from the drop-down menu
distanceUnitsShort($distanceUnit);
?>
</select>
</td></tr>
<tr><td></td><td class="left"><input class="log" type="submit" name="submit" accesskey="p" value="Calculate Pace"></td></tr>
</form>
</table>

</td></tr>
<tr>
<td class="descript">

<?php
	//put variable values from the form into user-friendly names
$distance = $_POST["distance"];
$hrs = $_POST["hrs"];
$mins = $_POST["mins"];
$secs = $_POST["secs"];

	//the following three if statements assign value 0 to variables that were not filled out in the form
if($hrs == null) {
	$hrs = 0;
}
if($mins == null) {
	$mins = 0;
}
if($secs == null) {
	$secs = 0;
}
if($distance == null) {
	$distance = 0;
}
if($speed == null) {
	$speed = 0;
}

	//writes time and distance values that were filled out in the form
echo "<br>Time: $hrs hrs $mins mins $secs secs <br>Distance: $distance " . kmMi($distanceUnit) . "";

	//converts hours to seconds
$hrssecs = $hrs * 3600;
	//converts minutes to seconds
$minssecs = $mins * 60;
	//adds the hours-to-seconds minutes-to-seconds and seconds values and assigns the value to a new variable
$timesecs = $hrssecs + $minssecs + $secs;

	//calculates the pace in seconds
$pacesecs = $timesecs / $distance;
	//calculates the value for pace minutes - result is float
$paceminsfull = $pacesecs / 60;
	//picks up only integer part of the pace minutes, which is later displayed as pace minutes
$pacemins = intval($paceminsfull);
	//calculates the remainder of seconds from total amount of seconds - this value is later displayed as pace seconds
$pacesecsfull = $pacesecs % 60;

	//finally the pace per kilometer or mile is displayed in minutes and seconds for the provided time and distance
echo "<br>Pace: <span class=\"pace\">$pacemins mins $pacesecsfull secs per " . kmMi($distanceUnit) . "</span>";

	//calculates the speed in km/h or mi/h
$speed = ($distance / $timesecs) * 3600;
	//rounds speed value to two decimal digits
$speedround = round($speed, 2);
	//speed in km/h or mi/h is displayed
echo "<br>Speed: <span class=\"pace\">$speedround " . kmhMih($distanceUnit) . "</span>";
?>

</td>
</tr>
<!-- end of calculate pace !-->



<!-- spacer !-->
<tr><td height="30px"></td></tr>
</table>
<!-- end of spacer !-->



<!-- calculate goal time !-->
<p class="header">Goal Time</p>
<table width="390" border="0">
<tr><td class="descript" valign="top">You know how fast you can run but have no idea how long it will take you to cover your distance? Enter your per kilometer (or mile) pace and distance of your run to get your goal time.</td></tr>
<tr>
<td height="15px"></td></tr>

<tr><td>
<table border="0">
<form method="post" action="<?php $_SERVER['PHP_SELF']?>">
<tr><td class="right">Pace:</td>
<td class="left">
<input class="log" type="text" name="goalmins" size="1" maxlength="2"> mins</input>
<input class="log" type="text" name="goalsecs" size="1" maxlength="2"> secs per km/mi</input>
</td></tr>
<tr><td class="right">Distance:</td>
<td class="left"><input class="log" type="text" name="goaldistance" size="3" maxlength="4"></input>
<select class="log" name="DistanceUnit">
<?php
//system/environment.php holds an if statement that chooses between either a preset value from the settings or from a value selected from the drop-down menu
distanceUnitsShort($distanceUnit);
?>
</select>
</td></tr>
<tr><td></td><td><input class="log" type="submit" name="submit" accesskey="t" value="Calculate Time"></td></tr>
</form>
</table>

</td></tr>
<tr>
<td class="descript">

<?php
	//put variable values from the form into user-friendly names
$goaldistance = $_POST["goaldistance"];
$goalmins = $_POST["goalmins"];
$goalsecs = $_POST["goalsecs"];

	//the following three if statements assign value 0 to variables that were not filled out in the form
if($goaldistance == null) {
	$goaldistance = 0;
}
if($goalmins == null) {
	$goalmins = 00;
}
if($goalsecs == null) {
	$goalsecs = 00;
}

	//writes distance and pace values that were filled out in the form
echo "<br>Distance: $goaldistance " . kmMi($distanceUnit) . "<br>Pace: $goalmins mins $goalsecs secs per " . kmMi($distanceUnit) . "";

	//calculates the total time in seconds and multiplies the value with the provided distance
$goaltimesecsfull = (($goalmins * 60) + $goalsecs) * $goaldistance;
	//gets integer part from the calculated value - later displayed as hours
$goaltimehrs = intval($goaltimesecsfull / 3600);
	//gets integer part from the calculated value - later displayed as minutes
$goaltimemins = intval(($goaltimesecsfull % 3600) / 60);
	//gets integer part from the calculated value - later displayed as seconds
$goaltimesecs = intval(($goaltimesecsfull % 3600) % 60);

	//finally the goal time in hours, minutes and seconds is displayed for the provided distance and pace per kilometer or mile
echo "<br>Goal time: <span class=\"pace\">$goaltimehrs hrs $goaltimemins mins $goaltimesecs secs</span>";

	//calculates the speed in km/h or mi/h
$goalspeed = ($goaldistance / $goaltimesecsfull) * 3600;
	//rounds speed value to two decimal digits
$goalspeedround = round($goalspeed, 2);
	//speed in km/h or mi/h is displayed
echo "<br>Goal speed: <span class=\"pace\">$goalspeedround " . kmhMih($distanceUnit) . "</span>";
?>

</td>
</tr>

<!-- end of calculate goal time !-->

<tr>
<td align="right"><a href="javascript:window.close();" title="Close This Window: Alt+C" accesskey="c" class="url"><u>C</u>lose</a></td>
</tr>

</table>

</body>
</html>
Return current item: Run