<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Routing</title>
</head>
<body>
<?php session_start(); 
      echo "From Distance  Test Page";
      echo "<br/>";
	  echo "<br/>";
      /*info from the from*/
	  $passengers = $_POST["passengers"] ;
	  //$temp = is_int( $_POST["passengers"] );
	  
	  if ($passengers == '0')
	  {
	      echo "Passengers entry is not a valid number. Please change the input.<br>";
		  return;
	  }
	  echo $passengers . " Passenger(s)<br>";
	  
  
	  /*Check if the Dist is not NULL*/
	  if(!empty($_POST["dist"]))
	  {
	   					
						$dist = $_POST["dist"];
						if($_POST["distradio"]=='m')
						{
						  	echo round($dist) . " Miles<br>";
						   $dist = $dist * 1.61 ;
						  
						}
						else 
						{
						   echo round($dist) . " Kilometer<br>";
						}
						if ($dist == '0')
	  					{
						     echo "Distance entry is not a valid number. Please change the input.<br>";
							 return;
						}
					
						$total = emissiondist( $dist );
						echo round($total) . " kilograms<br>";
						$cton = round($total/1000,1);
						echo $cton . " tonne<br>";
						echo "<hr>";
						echo "Total : <br>";
						echo "$ ". ( $passengers * $cton * 20 ). " <br>";
		}
		echo '<hr>';
		echo '<h3> Save to Database :</h3>';
		//save the inputs in sessions so we can access them in the confirmation page, add a name form hear before sending us to
		//the next page.
        $_SESSION['emission'] = $cton;
        $_SESSION['distance'] = $dist ; 
		$_SESSION['cost'] =  $passengers * $cton * 16 ;
        echo '<form action="confirm.php?'. SID .'" method="post" target="_self">';
		echo '<label> Transaction ID: <br />';
		echo '<input name="transaction" type="text" />';
		echo '</label><br/>';
		echo '<label> Agent Code: <br />';
		echo '<input name="agent" type="text" />';
		echo '</label><br/>';
		echo '<label> Enter Traveler Name(optional): <br />';
		echo '<input name="name" type="text" />';
		echo '</label><br/>';
        echo '<input name="confirm" type="submit" value="Confirm" />';
		echo '</form>';
 ?>
 <br/>
<a href="index.php" title="New" accesskey="n" target="_self">New calculation</a>

<?php

//return emission in kgr
function emissiondist($dist) { 
  $metric = 2;
  //freight allocation
  $freight = 0.10;
  if($dist < 500)
  {
      $haul = 0.15; 
  }
   if($dist < 1600 && $dist > 500)
  {
      $haul = 0.11;
  }
   if($dist > 1600)
  {
      $haul = 0.11;
  }
   
   $temission = $dist * $haul;
   //echo $temission."<br>";
   $falloc = $temission * $freight;
   //echo $falloc."<br>";
   $emission = ($temission - $falloc)*$metric;   
   return $emission;
}


?>
 
</body>
</html>
