<?php
// vim: sw=4:ts=4
/**
* @version 00.04.09
* @package polaring
* @license This component in released under the GNU/GPL License
*
* Fil: view/months.php
* Roll: Visar information om months
*
**/
function visaMonths($yearShow) {
$phpindex = "polaring.php?section=polar";
initWorkouts();
// Calculate total for months
$yearMonth = give::yearsMonths($_SESSION['workouts']);
$monthData = $_SESSION['monthData'];
$monthsTotal = give::monthsTotal($monthData);
$yearsTotal = give::yearsTotal($monthData);
echo "<table class=\"mitt months\" width=\"100%\" ".
"border=\"0\" >\n" .
" <thead>\n" .
" <tr>\n" .
" <td class=\"headline floorframe\" >".
strings::expression("polar", "year_month").
"</td>\n" .
" <td class=\"headline right floorframe\" >".
strings::expression("polar", "amOfEx").
"</td>\n" .
" <td class=\"headline right floorframe\" >".
strings::expression("polar", "timeAvgTot").
"</td>\n";
if ( $monthsTotal['distance'] != 0 ) {
echo " <td class=\"headline right floorframe\" >".
strings::expression("polar", "distanceAvgTot")."</td>\n";
}
if ( $monthsTotal['speedAvg'] != 0 ) {
echo " <td class=\"headline right floorframe\" >".
strings::expression("polar", "speedAvg")."</td>\n";
}
if ( $monthsTotal['ascent'] != 0 ) {
echo " <td class=\"headline right floorframe\" >".
strings::expression("polar", "ascentAvgTot")."</td>\n";
}
if ( $monthsTotal['energy'] != 0 ) {
echo " <td class=\"headline right floorframe\" >".
strings::expression("polar", "kcalAvgTot")."</td>\n";
}
echo " </tr>\n" .
" </thead>\n" .
" <tbody>\n";
$j = 0; # Labels every other row class=grey
$yearsTotShow = array();
$years = array();
foreach($yearMonth as $key) {
$year = substr($key, 0, 2);
if ( !in_array($year, $years) ) { $years[] = $year; }
$month = substr($key, 2, 2);
if ( !isset($yearShow) ) {
$yearShow = $year;
}
if ( $year == $yearShow) {
$wDate = mktime(0, 0, 0, substr($key,2,2), 1,
substr($key,0,2));
$year = date("Y",$wDate);
$month = date("m",$wDate);
$linkname = strftime("%Y %B", $wDate);
$j++;
if ($j%2 == 0) {
echo " <tr>\n ";
} else {
echo " <tr class=\"grey\">\n";
}
echo " <td><a href=\"".$phpindex.
"&mission=monthen&year=".$year."&month=".
$month."\" >".$linkname."</a></td>\n".
" <td width=\"5%\" class=\"right\" >"
.$monthData[$key]['amount']." ".
strings::expression("common", "amountAbbrev").
"</td>\n".
" <td class=\"right\" >"
.$monthData[$key]['avgTime'].
" / ".$monthData[$key]['time']."</td>\n";
if ( $monthsTotal['distance'] != 0 ) {
echo " <td class=\"right\" >";
if ( $monthData[$key]['distance'] != 0 ) {
echo $monthData[$key]['avgDistance']." / ".
$monthData[$key]['distance']." km";
}
echo "</td>\n";
}
if ( $monthsTotal['speedAvg'] != 0 ) {
echo " <td class=\"right\" >";
if ( $monthData[$key]['speedAvg'] != 0 ) {
echo give::speedUnited($monthData[$key]['speedAvg'])." ".
$_SESSION['unitSpeed'];
}
echo "</td>\n";
}
if ( $monthsTotal['ascent'] != 0 ) {
echo " <td class=\"right\" >";
if ( $monthData[$key]['ascent'] != 0 ) {
echo round($monthData[$key]['avgAscent'], 0)." / ".
round($monthData[$key]['ascent'], 0)." m";
}
echo "</td>\n";
}
if ( $monthsTotal['energy'] != 0 ) {
echo " <td class=\"right\" >";
if ( $monthData[$key]['energy'] != 0 ) {
echo $monthData[$key]['avgEnergy']." / ".
$monthData[$key]['energy']." KCal";
}
echo "</td>\n";
}
echo " </tr>\n";
}
}
// YEAR TOTALS
if ( count($years) > 1 ) {
foreach($yearMonth as $key) {
$year = substr($key, 0, 2);
$month = substr($key, 2, 2);
if ( !isset($yearShow) ) {
$yearShow = $year;
}
# Sum year
if ( !in_array($year, $yearsTotShow) ) {
echo "<tr class=\"total\">\n";
$yearsTotShow[] = $year;
$linkYear = date("Y", mktime(0, 0, 0, 5, 5, $year, 1));
$yearShowLink = $year;
echo "<td><a href=\"".$phpindex.
"&mission=months&yearShow=".
$yearShowLink."\">".$linkYear.", ".
strings::expression("polar", "total").
"</a></td>\n<td class=\"right\">";
if ( $yearsTotal[$year]['amount'] ) {
echo $yearsTotal[$year]['amount']." ".
strings::expression("common", "amountAbbrev");
}
echo "</td><td class=\"right\">";
if ( $yearsTotal[$year]['time'] ) {
echo $yearsTotal[$year]['time'];
}
echo "</td>\n<td class=\"right\">";
if ( $yearsTotal[$year]['distance'] != 0 ) {
echo $yearsTotal[$year]['distance']." km";
}
echo "</td>\n<td class=\"right\">";
if ( $yearsTotal[$year]['speedAvg'] != 0 ) {
echo give::speedUnited($yearsTotal[$year]['speedAvg'])." ".
$_SESSION['unitSpeed'];
}
echo "</td>\n<td class=\"right\">";
if ( $yearsTotal[$year]['ascent'] != 0 ) {
echo $yearsTotal[$year]['ascent']." m";
}
echo "</td>\n<td class=\"right\">";
if ( $yearsTotal[$year]['energy'] != 0 ) {
echo $yearsTotal[$year]['energy']. "KCal";
}
echo "</td>\n";
echo "</tr>\n";
}
}
}
// GRAND TOTAL
echo " <tr>\n".
" <td class=\"right takram\"></td>\n".
" <td class=\"right takram\">".$monthsTotal['amount'].
" ".strings::expression("common", "amountAbbrev")."</td>\n".
" <td class=\"right takram\">".$monthsTotal['time'].
"</td>\n";
if ( $monthsTotal['distance'] != 0 ) {
echo " <td class=\"right takram\">"
.$monthsTotal['distance']." km</td>\n";
}
if ( $monthsTotal['speedAvg'] != 0 ) {
echo " <td class=\"right takram\">".
give::speedUnited($monthsTotal['speedAvg'])." ".
$_SESSION['unitSpeed']."</td>\n";
}
if ( $monthsTotal['ascent'] != 0 ) {
echo " <td class=\"right takram\">".
round($monthsTotal['ascent'], 0)." m</td>\n";
}
if ( $monthsTotal['energy'] != 0 ) {
echo " <td class=\"right takram\">".
$monthsTotal['energy']." KCal</td>\n";
}
echo " </tr>\n";
echo " </tbody>\n" .
"</table>\n";
echo "<br /><hr />\n";
/*******************************\
* GRAPHS
\*******************************/
if ( count($yearMonth) > 1 ) {
// If there's only one exercise, there's no use in
// showing graphs of it. (It would only produce errors.)
echo "<h2>".strings::expression("polar", "graphs").
"</h2>\n";
$_SESSION['monthData'] = $monthData;
echo "<table class=\"mitt months\" width=\"100%\" ".
"border=\"0\" >\n".
" <thead>\n";
if ( isset($_REQUEST['selGraph']) ) {
echo " <tr>\n <td colspan=\"2\" ".
"class=\"center\">";
visa::graphLinkMedium($_REQUEST['selGraph']);
echo "</td>\n </tr>\n";
}
echo " </thead>\n".
" <tfoot>\n".
" <tr>\n".
" <td colspan=\"2\" class=\"center\"><p>(".
strings::expression("polar", "ClickToEnlargeGraph").
")</p></td>\n".
" </tr>\n </tfoot>\n <tbody>\n";
$_SESSION['nGraphs'] = 0;
// Available months-graphs: monthsDistanceTime, monthsKCal
// distance and time
if ( $monthsTotal['distance'] != 0 ) {
visa::graphLinkSmall("monthsDistanceTime",
strings::expression("polar",
"distance_and_time"), "300", "125");
visa::graphLinkSmall("monthsAvgMaxMinDistance",
strings::expression("polar", "distance"),
"300", "125");
} else {
$i++;
visa::graphLinkSmall("monthsTime",
strings::expression("polar", "time"),
"300", "125");
}
$i++;
visa::graphLinkSmall("monthsAvgMaxMinTime",
strings::expression("polar", "time"), "300", "100");
if ( $monthsTotal['speedAvg'] != 0 ) {
$i++;
visa::graphLinkSmall("monthsAvgMaxSpeed",
strings::expression("polar", "speed").", ".
strings::expression("common", "average"),
"300", "100");
}
// kcal/energy
if ( $monthsTotal['energy'] != 0 ) {
$i++;
visa::graphLinkSmall("monthsKCal",
strings::expression("polar", "energySpendage"),
"300", "100");
}
echo " </tr>\n";
echo " </tbody>\n".
"</table>\n";
}
return;
}
?>