<?php
    include("../include/session.php");
    if(!$session->isAdmin() && !$session->isRadstoneReceptionUser()){
        header("Location: ../main.php");
    }
    else {
    	include("../productionHeader.php");
//        include("../include/db.php");
        
		require_once('classes/tc_calendar.php');
		$d = date("d");
		$m = date("m");
		$y = date("Y");
		$currentmonth = date("F");
		$lastmonthtemp = $m-1;
		$lastmonth  = date("F", mktime(0, 0, 0, date("m")-1, date("d"),   date("Y")) );
				
		$today=date('Y-m-d'); 
		$yesterday = date('Y-m-d', mktime(0, 0, 0, date("m") , date("d") - 1, date("Y"))); 
		$yesterday1 = date('Y-m-d', mktime(0, 0, 0, date("m") , date("d") - 2, date("Y")));
		
		$numdays = cal_days_in_month(CAL_GREGORIAN, $m, $y) ; 
		$numdays2 = cal_days_in_month(CAL_GREGORIAN, $m-1, $y) ; 
        		
		$CurrentMonthStart = date('Y-m-d', mktime(0, 0, 0, date("m") , 1, date("Y"))); 
		$CurrentMonthEnd = date('Y-m-d', mktime(0, 0, 0, date("m") , $numdays, date("Y"))); 
		$LastMonthStart = date('Y-m-d', mktime(0, 0, 0, date("m")-1 , 1, date("Y"))); 
		$LastMonthEnd = date('Y-m-d', mktime(0, 0, 0, date("m")-1 , $numdays2, date("Y"))); 

		
		$start = isset($_REQUEST["date1"]) ? $_REQUEST["date1"] : "";
        $end = isset($_REQUEST["date2"]) ? $_REQUEST["date2"] : "";
        
//		$start = mysql_real_escape_string($_POST['startDate']);
//		$end = mysql_real_escape_string($_POST['endDate']);
		$q = "SELECT * FROM nam_production WHERE date >= '$start' AND date <= '$end' ORDER BY date DESC";
		$resultLate = execsql($q);
		$num = mysql_num_rows($resultLate);
		$i = 0;
		$start = strtotime($start);
		$end = strtotime($end);
		
		
		$start1=date("Y-m-d", $start); 
		$end1=date("Y-m-d", $end);
		
		
	$q = "SELECT recipieId, recipieName FROM nam_recipie";
	$resultPro = execsql($q);
	$numPro = mysql_num_rows($resultPro);
	$j = 0;
	$proArray = array();
	while($j < $numPro){
		$proArray[mysql_result($resultPro, $j, "recipieId")] = mysql_result($resultPro, $j, "recipieName");
		$j++;
	}
?>	
<link
	href="calendar.css" rel="stylesheet" type="text/css" />
<script
	language="javascript" src="../include/calendar.js"></script>
<div class="headerbox">Heating Hours</div>
<div class="menubox">
<div align="right">
      <form action="depByDates.php" method="post" >
        <div align="right">from:
          <?php
		$myCalendar = new tc_calendar("date1", true);
		$myCalendar->setIcon("../img/iconCalendar.gif");
		$myCalendar->setDate($d, $m, $y);
		$myCalendar->setPath("./");
		$myCalendar->setYearInterval(2000, 2030);
	 // $myCalendar->dateAllow('2008-05-13', '2010-03-01', false);
		//$myCalendar->setHeight(350);
		//$myCalendar->autoSubmit(true, "form1");
		$myCalendar->writeScript();?>
          <br />
          to:&nbsp;&nbsp;&nbsp;&nbsp;
            <?php
		$myCalendar = new tc_calendar("date2", true);
		$myCalendar->setIcon("../img/iconCalendar.gif");
		$myCalendar->setDate($d, $m, $y);
		$myCalendar->setPath("./");
		$myCalendar->setYearInterval(1970, 2030);
		//$myCalendar->dateAllow('2009-02-20', "", false);
		$myCalendar->writeScript();
			
		?>
          <br />
          <input name="submitok"  type="image" src="../../Images/go_btn.png" align="right" width="40" height="25" />
          <br />
          <a href="heatingByDates.php?<?php echo "date1=$today&date2=$today"; ?>"><img src="../../Images/today_btn.png" width="75" height="25" /></a><a href="heatingByDates.php?<?php echo "date1=$yesterday&date2=$yesterday"; ?>"><img src="../../Images/today1_btn.png" width="75" height="25" /></a><a href="heatingByDates.php?<?php echo "date1=$yesterday1&date2=$yesterday1"; ?>"><img src="../../Images/today2_btn.png" width="75" height="25" /></a></div>
      </form>
  </div>
	   <div align="right"><a href="heatingByDates.php?<?php echo "date1=$CurrentMonthStart&date2=$CurrentMonthEnd"; ?>"><img src="../../Images/this_month_btn.png" alt="." width="75" height="25" /></a><a href="heatingByDates.php?<?php echo "date1=$LastMonthStart&date2=$LastMonthEnd"; ?>"><img src="../../Images/last_month_btn.png" alt="." width="75" height="25" /></a><img src="../../Images/print_btn.png" alt="." width="75" height="25" class="style1" onclick="JavaScript:printPreviewDiv('top-bar');"/><br />
  </div>
</div>
<div class="subheaderbox">  <?php 
	  if ($start1==$today) {echo "for Today<br>(". $today.")";}
	        else { 
	           if ($start1==$yesterday) {echo "for Yesterday<br>(". $yesterday.")";}
			       else { 
				   if($start1==$yesterday1) {echo "for Day before Yesterday<br>(". $yesterday1 . ")";}
	                  else {
					  if ($start1==$CurrentMonthStart){echo "for this month:  ". $currentmonth."  ".$y.".";}
					    else
						{ if ($start1==$LastMonthStart){echo "for last month:  ". $lastmonth."  ".$y.".";}
						   else
					        { echo "from <br>". $start1." to ". $end1;}
					        }
							}
					 
}			}?></div>
<br /><br /><br /><br /><br /><br />
<table id="test1" cellpadding="0" cellspacing="0" border="0" class="rowstyle-alt colstyle-alt no-arrow">
    <thead>
      <tr>
        <th class="sortable-date-ymd">Date</th>
        <th class="sortable-numeric">Recipie Id</th>
        <th class="sortable-numeric">Heating Hours</th>
        <th class="sortable-numeric">Cost for Heating (P)</th>
      </tr>
    </thead>
    <tbody>
<?php
    $i = 0;
    $qD = "SELECT Diesel FROM nam_perwetprice LIMIT 1";
    $rD = execsql($qD);
    $diesel = mysql_result($rD, 0, "Diesel");
//    echo $diesel;
    while($i < $num){
       $b2 = mysql_result($resultLate, $i, "date");
       $b3 = mysql_result($resultLate, $i, "heatingHours");
       $b7 = mysql_result($resultLate, $i, "recipieId");
		$tCost += $b3 * $diesel;
		$tHeating += $b3;

?>

        <tr class="alt">
        <td><?php echo $b2?></td>
        <td><?php echo $b7?></td>
        <td align="right"><?php echo $b3?></td>
        <td align="right">
        	<?php 
        		$b4 = $b3 * $diesel;
        		echo number_format($b4,2);
        	?>
        </td>
     
        </tr> 
<?php
    $i++;
    }
?>
<tr><td></td><td></td><td align="right"><b><?php echo $tHeating?></b></td><td align="right"><b><?php echo $tCost?></b></td></tr>
</tbody>
</table>

<?php
	include("../footer.php");
    }
    ?>