Location: PHPKode > projects > Polaring > view/month.php
<?php
// vim: sw=4:ts=4
/**
* @version 00.04.09
* @package polaring
* @license This component in released under the GNU/GPL License
*
* File: view/month.php
* Role: Shows information about a single month
*
**/

function visaMonthen($year, $month) {
  $phpindex = "polaring.php?section=polar";

  $fullMonth = mktime(8,0,0,$month,1,$year); 

  $workout = give::yearMonthWorkouts(
      $_SESSION['workouts'], $year, $month);
  ksort($workout);

  visa::backLink($_REQUEST);

  $mKey = substr($year, 2, 2).$month;
  $monthTotal = $_SESSION['monthData'][$mKey];

  echo "<h2>".ucfirst(strftime("%B %Y", $fullMonth))."</h2>\n";


  ///////////////////////////////////////////////////
  // Create table and titles for trainings per month
  ///////////////////////////////////////////////////
  echo " <table border=\"0\">\n" .
    "  <thead>\n" .
    "    <tr class=\"headline\">\n" .
    "      <td class=\"headline floorframe\" width=\"8%\">".
    strings::expression("polar", "date").
    "</td>\n";
  $headlinesMonth = array(
	  strings::expression("polar", "time"));
  if ( $monthTotal['distance'] != 0 ) {
      $headlinesMonth[] = strings::expression(
	  "polar", "distance");
  }
  if ( $monthTotal['hrAvg'] != 0 ) {
      $headlinesMonth[] = strings::expression("polar", "hrAvgMax");
  }
  if ( $monthTotal['speedAvg'] != 0 ) {
      $headlinesMonth[] = strings::expression(
	  "polar", "speedAvg");
  }
  if ( $monthTotal['ascent'] != 0 ) {
      $headlinesMonth[] = strings::expression(
	  "polar", "ascent");
  }
  if ( $monthTotal['energy'] != 0 ) {
      $headlinesMonth[] = strings::expression(
	  "polar", "energy");
  }
  if ( $monthTotal['tempAvg'] != 0 ) {
	  $headlinesMonth[] = strings::expression("polar", "temperatureAvgMax");
  }

  foreach ($headlinesMonth as $headline) {
      echo "      <td class=\"headline right floorframe\" width=".
	  "\"5%\">".$headline."</td>\n";
  }
  echo "    </tr>\n" .
    "  </thead>\n" .
    "  <tbody>";

  ///////////////////////////////////////////////////
  // Echo exercises for month
  ///////////////////////////////////////////////////

  $i=0;
  foreach($workout as $w) {
      $dateStartTime = $w["dateStartTime"];
      $i++;

      if ($i%2 == 0) {
	  echo "    <tr class=\"grey\">\n";
      } else {
	  echo "    <tr>\n";
      }
      
      $datum = ucfirst(strftime("%a %d %b %R", $dateStartTime));
      $dateLink = date("YmdHi", $dateStartTime);

      echo "      <td width=\"10%\"><a href=\"".$phpindex.
	  "&amp;mission=day&amp;dateTime=".$dateLink."\">".
	  $datum."</a></td>\n".
	  "      <td class=\"right\" width=\"7%\">".
	  $w['duration']."</td>\n";

      if ( $monthTotal['distance'] != 0 ) {
	      echo "      <td class=\"right\" width=\"4%\">";
	if ( $w['distance'] != 0 ) {
		echo $w['distance']." ".$w['unitDistance'];
	}
	      echo "</td>\n";
      }
      if ( $monthTotal['hrAvg'] != 0 ) {
	  echo "      <td class=\"right\" width=\"10%\">";
	  if ( $w['hrAvg'] != 0 ) {
	      echo round($w['hrAvg'], 0)."/".$w['hrMax']." ".$w['unitHr'];
	  }
	  echo "</td>\n";
      }
      if ( $monthTotal['speedAvg'] != 0 ) {
	      echo "      <td class=\"right\" width=\"8%\">";
	if ( $w['speedAvg'] != 0 ) {
		echo give::speedUnited($w['speedAvg'])." ".
			$_SESSION['unitSpeed'];
	}
	      echo "</td>\n";
      }
      if ( $monthTotal['ascent'] != 0 ) {
	      echo "      <td class=\"right\" width=\"4%\">";
	if ( $w['ascent'] != 0 ) {
		echo round($w['ascent'], 1)." ".$w['unitAltitude'];
	}
	      echo "</td>\n";
      }
      if ( $monthTotal['energy'] != 0 ) {
	      echo "      <td class=\"right\" width=\"7%\">";
	if ( $w['energy'] != 0 ) {
		echo $w['energy']." ".$w['unitEnergy'];
	}
	      echo "</td>\n";
      }
      if ( $monthTotal['tempAvg'] != 0 ) {
	      echo "      <td class=\"right\" width=\"9%\">";
	if ( $w['temperatureAvg'] != 0 ) {
	    echo $w['temperatureAvg']."/".$w['temperatureMax'].
		" ".$w['unitTemperature'];
	}
	      echo "</td>\n";
      }
      echo "    </tr>\n";
  } // End of exercises for month


  ///////////////////////////////////////////////////
  // Echo summarization of this months exercises
  ///////////////////////////////////////////////////

  echo "    <tr>\n".
    "      <td class=\" right takram\">".$monthTotal['amount'].
    " ".strings::expression("polar", "amountOfExercises").": ".
    "</td>\n".
    "      <td class=\"takram right\">".
    $monthTotal['time']."</td>\n";
  if ( $monthTotal['distance'] != 0 ) {
      echo "      <td class=\"takram right\">".
	  $monthTotal['distance']." km</td>\n";
  }
  if ( $monthTotal['hrAvg'] != 0 ) {
      echo "      <td class=\"takram right\">".
	  $monthTotal['hrAvg']."/".
	  $monthTotal['hrMax']." bpm</td>\n";
  }
  if ( $monthTotal['speedAvg'] != 0 ) {
      echo "      <td class=\"takram right\">".
		  give::speedUnited($monthTotal['speedAvg'])." ".
		  $_SESSION['unitSpeed']."</td>\n";
  }
  if ( $monthTotal['ascent'] != 0 ) {
      echo "      <td class=\"takram right\">".
	  round($monthTotal['ascent'], 1)." m</td>\n";
  }
  if ( $monthTotal['energy'] != 0 ) {
      echo "      <td class=\"takram right\">".
	  $monthTotal['energy']." KCal</td>\n";
  }
  if ( $monthTotal['tempAvg'] != 0 ) {
      echo "      <td class=\"takram right\">".
	  $monthTotal['tempAvg']."/".$monthTotal['tempMax'].
	  " &deg;C</td>\n";
  }

  echo "    </tr>\n";
  echo "  </tbody>\n" .
    " </table>\n\n";


  ///////////////////////////////////////////////////
  // Show graphs
  // Available graphs: monthDistanceTime, monthKCal, monthTime
  ///////////////////////////////////////////////////

  if ( $monthTotal['amount'] > 1 ) {
	  // If there's only one exercise, there's no use in
	  // showing graphs of it.

	  echo "<br /><hr />\n";
	  echo "<h2>".strings::expression("polar", "graphs").
	      "</h2>\n";

	  echo "<table 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;

	  // distance and time
	  if ( $monthTotal['distance'] > 0 ) {
	      visa::graphLinkSmall("monthDistanceTime", 
		  strings::expression("polar", "distance_and_time"),
		  "300", "125");
	      visa::graphLinkSmall("monthAvgMaxSpeed",
		  strings::expression("polar", "speed"),
		  "300", "100");
	  } else {
	      visa::graphLinkSmall("monthTime",
		  strings::expression("polar", "time"),
		  "300", "125");
	  }
	  // kcal/energy
	  if ( $monthTotal['energy'] > 0 ) {
	      visa::graphLinkSmall("monthKCal",
		  strings::expression("polar", "energySpendage"),
		  "300", "100");
	  }

	  echo "  </tbody>\n</table>\n";
  } // end graphs
 

  visa::backLink($_REQUEST);
 
  return(true);
}

?>
Return current item: Polaring