<?php session_start();  ?>
<!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>
<title>CoolDrivePass : Emissions Calculator</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script type="text/JavaScript">
</script>

</head>

<?php
/* Connection to MySQL Database*/
	  $host="server358.mysite4now.com";
      $user="cooladmin";
      $password="chillme";
	  $database="emissions";
	  //Connection
	  $cxn = mysqli_connect($host,$user,$password,$database);
	  $car_id = $_POST['modelsubcat'];
	 
	  $car_query="SELECT CAR_YEAR,MODEL,CONSUMPTION,EMISSION
				  FROM car_emissions
				  WHERE CAR_ID =".$car_id."";

	  $car_result = mysqli_query($cxn,$car_query);
	  $result = mysqli_fetch_array($car_result);
	  $year = $result['CAR_YEAR'];
	  $make_type = $result['MAKE_TYPE'];
	  $consumption = $result['CONSUMPTION'];
	  $emission = $result['EMISSION'];
	  $totalcons = $consumption * $_POST['kmselect'] / 100 ;
	  $totalemit = $emission * $_POST['kmselect'];
	  $annualoffset = $totalemit * 0.02;
	  $yearnum = $_POST['xyears'];
	  $totaloffset = $annualoffset * $yearnum;
	  $averageannual = 0.2843 * 20000;
	
	?>


<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<p align="center">

</p>
<div align="center">
 
 <table id="Table_02" width="674" border="0" cellpadding="0" cellspacing="0">
    
      <td align="right" valign="top"><div align="right" class="fixtable" >
        <table width="99%" border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td width="64%" align="left" valign="bottom" bgcolor="#FFFFFF">
			  
				<p><strong>Vehicle Report:</strong></p>
				
		

			  </td>
			  
            </tr>
            <tr valign="bottom">
              <td colspan="2" align="left" valign="top">
		      
		  </td>
			    
            </tr>
            <tr valign="bottom">
              <td colspan="3" align="left"><br>
         
		 
		<p>	  
		 
		Your car consumes <strong>
		<?php echo number_format($consumption, 2, '.', ''); ?>
		liters</strong> of gas per 100km,		
		which equals <strong>
        <?php echo number_format($totalcons, 2, '.', ''); ?>
		liters</strong> of gas per year.
		<br>
		Your annual emissions are: <strong>
		<?php echo number_format($totalemit, 2, '.', ''); ?>
		KG</strong> of CO2 per year.
		<br>
		Your annual offset cost is : <strong> $
		<?php echo number_format($annualoffset, 2, '.', ''); ?>
		</strong>
		<br>
		Your total offset costs for <strong>
		<?php echo number_format($yearnum, 0, '.', ''); ?>
		</strong> year(s) is: <strong> $
		<?php echo number_format($totaloffset, 2, '.', ''); ?>
		</strong>
		<br>
		
		<form name="my_lv" method="post" action="https://www.paypal.com/cgi-bin/webscr">
			<input type="hidden" name="cmd" value="_xclick"/>
			<input type="hidden" name="business" value="offsetters@gmail.com"/>
			<input type="hidden" name="item_name" value="Cooldrivepass CO2 Offset"/>
			<input type="hidden" name="currency_code" value="CAD"/>
			<input type="hidden" name="amount" value="<?php echo number_format($totaloffset, 2, '.', ''); ?>"/>
			<input type="submit" name="OffsetBttn" value="Offset Your Emissions Now">
		</form>

  </p>
</td>
            </tr>
          </table>
      </div></td>
    </tr>
  </table>
 
</div>
</body>
</html>