Location: PHPKode > projects > eCanteen > ecanteen/user/quikmenu.php
<?
//Copyright David Byrne 2007

//This file is part of eCanteen.

//    eCanteen is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.

//    eCanteen is distributed in the hope that it will be useful
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.

//    You should have received a copy of the GNU General Public License
//    along with eCanteen.  If not, see <http://www.gnu.org/licenses/>.
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en-au" xmlns="http://www.w3.org/1999/xhtml">
<head>

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

<script type="text/javascript">


function dateaddtest()

{

var today=new Date();

for (i=0;i<=9;i++)
{
today.setDate(today.getDate()+7);
window.alert(today);
}

}


var NS4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) < 5);

var d = new Date();

function RunningTotal(Credit)
{
var MinorOrderSel=document.getElementById('MinorOrder');
var RunningTotalDisplay=document.getElementById('RunningTotalDisplay');
//var CreditDisplay=document.getElementById('credit');
var RunningPrice=0;
for (var i=0; i<MinorOrderSel.length; i++) 
	{
	     //window.alert (MinorOrderSel.options[i].value)
		//if (MinorOrderSel.options[i].selected && MinorOrderSel.options[i].value>0) 
		//{
		
		var tempStr=MinorOrderSel.options[i].text;
		//window.alert(tempStr.length);
		RunningPrice=RunningPrice+parseFloat(tempStr.substring(tempStr.indexOf("$")+1));
		
		//}
	}
	
	
	
	//CreditDisplay.value=CreditDisplay.value-RunningPrice;
	if (RunningPrice > Credit)
	{
	    
	    //window.alert("OverLimit")
	}else{
	    RunningTotalDisplay.value=formatCurrency(RunningPrice);
	}
	return RunningPrice;
}


function RepeatOrders(CustID,BreakID,dDate,minorname,DaysGap,ExcludedDays)
{

//window.alert(CustID+' '+BreakID+' '+dDate+' '+MinorName+' '+DaysGap);

ExcludedDaysArray=ExcludedDays.split(",");

document.getElementById('PlaceOrdersClick').disabled=true;
document.getElementById('RepeatOrdersWeekly').disabled=true;
document.getElementById('RepeatOrdersDaily').disabled=true;




var RunningTotalDisplay=document.getElementById('RunningTotalDisplay');
var CreditDisplay=document.getElementById('credit');
var StartCredit=document.getElementById('StartCredit');

var MinorOrderSel=document.getElementById('MinorOrder');
if (1==2){
	window.alert("ghgjhgjh")
}else{
//window.alert(ToSel.options[ToSel.selectedIndex].value);

var answer = 'Y'//prompt ("Transfer Selected entries to ?\nType 'Y' to proceed...","N");
//window.alert(answer);


if (parseFloat(RunningTotalDisplay.value.substring(RunningTotalDisplay.value.indexOf("$")+1))<=StartCredit.value)
{
	var IncidentsXferStr="";
	//window.alert(fromSel.length);
	for (var i=0; i<MinorOrderSel.length; i++) 
	{
		
		IncidentsXferStr=IncidentsXferStr+MinorOrderSel.options[i].value+'*';
		
	}
	
	OrderArray=IncidentsXferStr.split("*");
	var OrderStr="";
	for (i in OrderArray)
	{
	//window.alert(OrderArray[i]);
	var Quant=0;
	var ItemX=OrderArray[i]; 
	if (parseInt(OrderArray[i])!=0)
	{
	    for (j in OrderArray)

	    {
               
	        if(parseInt(ItemX)==parseInt(OrderArray[j]))
	        {
	          	 
	          Quant=Quant+1;
	         // window.alert(Quant);
	          OrderArray[j]='0';
	        }
	    }
	    if (Quant!=0)
	    {
	    OrderStr=OrderStr+ItemX+'/'+Quant+'*'
	    }
	}    
	
	}
	
	//CustID,BreakID,dDate
	//window.alert ("This is the initial order:"+dDate);
	//var msgvar='test';
	returnValue=window.open('processorder.php?TargetVals='+OrderStr+'&CustID='+CustID+'&minorname='+minorname+'&BreakID='+BreakID+'&dDate='+dDate+'&Repeat=1')//,'CP','width=1,height=1,menubar=no');

    	
    var totalTab=(parseFloat(RunningTotalDisplay.value.substring(RunningTotalDisplay.value.indexOf("$")+1))-StartCredit.value);
    var orderCost=parseFloat(RunningTotalDisplay.value.substring(RunningTotalDisplay.value.indexOf("$")+1));
    var totalTab=parseFloat(totalTab)-parseFloat(orderCost);
    if (parseFloat(totalTab)<=parseFloat(orderCost))
	{
	    var DayName=['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
	    var MonthName=["January", "February", "March", "April", "May", "June","July","August", "September", "October", "November", "December"];
			
	    dDateStr=dDate.replace(/-/g,'/');
	    var totalTab=totalTab*-1;
	    var totalTab=parseFloat(totalTab)-parseFloat(orderCost);
        for (i=0;i<=10000;i++)
        {
       //window.alert(dDateStr);
       var startDate=new Date(dDateStr);
       startDate.setDate(startDate.getDate()+DaysGap);
			 
       var theyear=startDate.getFullYear();
       var thedaynum=startDate.getDay();
       var themonth=startDate.getMonth()+1;
       var thetoday=startDate.getDate();
			 //myString.indexOf("com")
       
       var answer = prompt (formatCurrency(totalTab)+" left. Type 'Y' to repeat order for "+DayName[thedaynum] + "/" + thetoday + "/" + MonthName[startDate.getMonth()]+".\nType 'N' to skip this date. Click Cancel to cancel process.. ","Y");
       if (thetoday<10)
			 {
			 		thetoday="0"+thetoday;
			 }
			 if (themonth<10)
			 {
			 		themonth="0"+themonth;
			 }
			 
       var paradDateStr=theyear + "-" + themonth + "-" + thetoday;
			 var dDateStr=theyear + "/" + themonth + "/" + thetoday;
        
        if (answer=='Y')
          {
            
            returnValue=window.open('processorder.php?TargetVals='+OrderStr+'&CustID='+CustID+'&minorname='+minorname+'&BreakID='+BreakID+'&dDate='+paradDateStr+'&Repeat=1')//,'CP','width=1,height=1,menubar=no');
            
            var totalTab=parseFloat(totalTab)-parseFloat(orderCost);
          }  
        if (answer=='C') {i=100000}
        if (answer==null) {i=100000}
        }
    }

}else{
window.alert("Overlimit - transaction cancelled");
}

}
}


function disableAllFormControls() {
 for (var i=0; i<document.forms.length; i++) {
  for (var j=0; j<document.forms[i].elements.length; j++) {
    document.forms[i].elements[j].disabled=true;
  }
 }
}


function PlaceOrders(CustID,BreakID,dDate,minorname)
{

disableAllFormControls();
var RunningTotalDisplay=document.getElementById('RunningTotalDisplay');
var CreditDisplay=document.getElementById('credit');
var StartCredit=document.getElementById('StartCredit');

var MinorOrderSel=document.getElementById('MinorOrder');
if (1==2){
	window.alert("Issues cannot be transferred within Projects!")
}else{
//window.alert(ToSel.options[ToSel.selectedIndex].value);

var answer = 'Y'//prompt ("Transfer Selected entries to ?\nType 'Y' to proceed...","N");
//window.alert(answer);


if (parseFloat(RunningTotalDisplay.value.substring(RunningTotalDisplay.value.indexOf("$")+1))<=StartCredit.value)
{
	var IncidentsXferStr="";
	//window.alert(fromSel.length);
	for (var i=0; i<MinorOrderSel.length; i++) 
	{
		
		IncidentsXferStr=IncidentsXferStr+MinorOrderSel.options[i].value+'*';
		
	}
	//window.alert(IncidentsXferStr);
	OrderArray=IncidentsXferStr.split("*");
	var OrderStr="";
	for (i in OrderArray)
	{
	//window.alert(OrderArray[i]);
	var Quant=0;
	var ItemX=OrderArray[i]; 
	if (parseInt(OrderArray[i])!=0)
	{
	    for (j in OrderArray)

	    {
               
	        if(parseInt(ItemX)==parseInt(OrderArray[j]))
	        {
	          	 
	          Quant=Quant+1;
	         // window.alert(Quant);
	          OrderArray[j]='0';
	        }
	    }
	    if (Quant!=0)
	    {
	    OrderStr=OrderStr+ItemX+'/'+Quant+'*'
	    }
	}    
	
	}
	
	//CustID,BreakID,dDate
	//window.alert (OrderStr);
	var processWindow=window.open('processorder.php?TargetVals='+OrderStr+'&CustID='+CustID+'&minorname='+minorname+'&BreakID='+BreakID+'&dDate='+dDate+'&Repeat=0')//,'CP','width=1,height=1,menubar=no');



	//window.open('usercalendar-sdates.asp?minor='+CustID+'&date='+dDate+'&minorname=minor');
	//var xtest=displayIncidents(SCHEDID,0);
	//,'CP','width=1,height=1,menubar=no'
	
}else{
window.alert("Overlimit - transaction cancelled");
}

}
}


function FromTo(Credit)
{
var MenuSel=document.getElementById('MenuList');
var MinorOrderSel=document.getElementById('MinorOrder');

var RunningTotalDisplay=document.getElementById('RunningTotalDisplay');
var CreditDisplay=document.getElementById('credit');

if (1 == 2){
	window.alert("Issues cannot be transferred within Projects!")
}else{
//window.alert(ToSel.options[ToSel.selectedIndex].value);

//window.alert(document.VerP.Fromselect.length);
var answer = 'Y';
//window.alert(answer);
if (answer=='Y')
{
	
	//window.alert(fromSel.length);
	var RunningPrice=0;
	for (var i=0; i<MenuSel.length; i++) 
	{
		if (MenuSel.options[i].selected)
		{
		    	var newOpt = new Option(MenuSel.options[i].text, MenuSel.options[i].value);
	            var selLength = MinorOrderSel.length;
	            MinorOrderSel.options[selLength] = newOpt;
	            var tempStr=MenuSel.options[i].text;
		//window.alert(tempStr.length);
		RunningPrice=RunningPrice+parseFloat(tempStr.substring(tempStr.indexOf("$")+1));
		}
	}
}else{
window.alert("Transfer cancelled");
}
}
//RunningTotalDisplay.value=RunningPrice;
var TallyTotal=RunningTotal(Credit);
if (TallyTotal<=Credit)
{
    //tempStr.substring(tempStr.indexOf("$")+1)
    var tempCreditDisplay=Credit-TallyTotal;
    CreditDisplay.value=formatCurrency(tempCreditDisplay);
}else{
    var RunningPrice=0;
    var delFlag=false;
    for (var i=0; i<MinorOrderSel.length; i++) 
    {
	    
	    if (delFlag)
	    {
		    MinorOrderSel.remove(i);
	    }else{
		    var tempStr=MinorOrderSel.options[i].text;
		    //window.alert(tempStr.length);
		    RunningPrice=RunningPrice+parseFloat(tempStr.substring(tempStr.indexOf("$")+1));
		if (RunningPrice>Credit)
	    {
		    delFlag=true;
		    var tempStr=MinorOrderSel.options[i].text;
		   
		    var tempCreditDisplay=Credit-(RunningPrice-parseFloat(tempStr.substring(tempStr.indexOf("$")+1)));
            CreditDisplay.value=formatCurrency(tempCreditDisplay);     
		    
	    }
		    
	    }
	    
	    
    }
    MinorOrderSel.remove(MinorOrderSel.length - 1);

    window.alert("OverLimit")
}

}



function formatCurrency(num) {

//window.alert (num);
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '$' + num + '.' + cents);
}


function removeOptionSelected()
{

  var elSel = document.getElementById('MinorOrder');
  var RunningTotalDisplay=document.getElementById('RunningTotalDisplay');
  var CreditDisplay=document.getElementById('credit');
	credit=parseFloat(CreditDisplay.value.substring(CreditDisplay.value.indexOf("$")+1));
	
  var i;
  var RunningPrice=0;
	//window.alert(credit);
  for (i = elSel.length - 1; i>=0; i--) {
    if (elSel.options[i].selected) {
		    //window.alert(elSel.options[i].text);
        var tempStr=elSel.options[i].text;
				RunningPrice=RunningPrice+parseFloat(tempStr.substring(tempStr.indexOf("$")+1));
      	elSel.remove(i);
    }
  }
  //RunningTotalDisplay.value=RunningTotalDisplay.value-RunningPrice;
	//parseFloat(CreditDisplay.value.substring(CreditDisplay.value.indexOf("$")+1))
	
  if (RunningPrice>0){
		var tempCreditDisplay=credit+RunningPrice;
		
		CreditDisplay.value=formatCurrency(tempCreditDisplay);
		//window.alert(Credit);
		RunningTotal(credit);
}
}


</script>
</head>
<? 

// $objConnection1 is of type "ADODB.Connection"
// $MenuList is of type "ADODB.Recordset"
include("../include/constants.php");     
mysql_free_result($res);
session_start();
//echo "session=".$_SESSION['SiteID$']."<br>";
$objConnection1=mysql_connect(DB_SERVER, DB_USER, DB_PASS);
  mysql_select_db(DB_NAME);

$sqlstmt="SELECT minorcustomer.`CustomerID`, minorcustomer.`MajorCustomerExtract$` FROM minorcustomer WHERE (((minorcustomer.`CustomerID`)=".$_GET["minor"]."));";

$CheckMajor=mysql_query($sqlstmt);

echo mysql_result($CheckMajor,0,"MajorCustomerExtract$")."<br/>";
echo (mysql_result($CheckMajor,0,"MajorCustomerExtract$")==$_SESSION['CustomerID'])."<br/>";


if (mysql_result($CheckMajor,0,"MajorCustomerExtract$")==$_SESSION['CustomerID'])
{

$sqlstmt="SELECT menuitem.`MenuItemID`, break.`Break`, itemtype.`ItemType`, itemtype.`OrderSunsetDays`, menuitem.`Item`, menuitem.`Break$`,break.`SortOrder`, menuitem.`Cost`, menuitem.`FromDate`, menuitem.`ToDate` FROM (itemtype INNER JOIN menuitem ON itemtype.`ItemTypeID` = menuitem.`ItemType$`) INNER JOIN Break ON menuitem.`Break$`=break.`BreakID` WHERE (((menuitem.`Break$`)=".$_GET["BreakID"]." Or (break.`SortOrder`)=0) AND ((menuitem.`FromDate`)<='".$_GET["date"]."') AND ((menuitem.`ToDate`)>='".$_GET["date"]."') AND ((menuitem.`~SiteID$`)=".$_SESSION['SiteID'].")) ORDER BY break.`Break`, itemtype.`ItemType`, menuitem.`Item`;";
//echo $sqlstmt;


$objRecordset1=mysql_query($sqlstmt);

$objRecordset1num=mysql_numrows($objRecordset1);
;
//echo mysql_error();
//**************checking if redo of original order adding items to order
$PreTotal="0.00";
//response.Write Request.QueryString("ItemStr")

if (strlen($_GET["ItemStr"])>0)
{
	
  $ItemArray=explode("*",$_GET["ItemStr"]);
	
  $z=0;
  for ($x=0; $x<=count($ItemArray)-1; $x=$x+1)
  {
    $ItemDetails=explode("/",$ItemArray[$x]);
    $i=0;
    while($i < $objRecordset1num)
    {
			$MenuItemID=mysql_result($objRecordset1,$i,"MenuItemID");
			$ItemType=mysql_result($objRecordset1,$i,"ItemType");
			$Item=mysql_result($objRecordset1,$i,"Item");
			$cost=mysql_result($objRecordset1,$i,"cost");
      if ($MenuItemID==$ItemDetails[1])
      {
				$bracketx=strpos($ItemDetails[0],"(");
				$quantx=substr($ItemDetails[0],$bracketx+1,1);
				//print "=".$quantx."<BR>";
        for ($y=0; $y<=$quantx-1; $y=$y+1)
        {
          $ReDoList[$z][0]=$MenuItemID;
          $ReDoList[$z][1]=$ItemType;
          $ReDoList[$z][2]=$Item;
          $ReDoList[$z][3]=$cost;
          $PreTotal=$PreTotal+$cost;
          $z++;

        }


      } 

      $i++;

    } 

  }

  
} 


//***********************



$x=0;
?>
<body >


<? 
if ($objRecordset1num>0)
{
?>
<center>
<img src="../backgrounds/papertop.jpg" alt="papertop" width="100%">
  <table width="50%" border="0">
    <tr> 
      <td colspan="4">
          Select Items from Menu and click --&gt;&gt; to add item to order.
          
          Use &lt;&lt;-- to remove item
          from order.<br />
          (Use Control-click and/or Shift/Click
 to select multiple items from the menu)</td>
    </tr>
      <tr>
          <td style="width: 612px" valign="top">
           <?   echo $_GET["Break"];?> Menu for <?   echo $_GET["date"];?><br />
          </td>
          <td style="width: 397px">
          <?   echo $_GET["minorname"];?>
          </td>
          <td valign="top" style="width: 251px; text-align: right;">
            Credit:<br /><input id="StartCredit" type="hidden" value="<?   echo $_SESSION['credit']-$PreTotal;?>" />
						
						
          Order Total:
           </td>
          <td style="width: 2px" valign="top">
          <input id="credit" type="text" size="10" value="<? $StartTotal=$_SESSION['credit']-$PreTotal;echo "$".$StartTotal;?>" readonly="readOnly" /><br />
           <input id="RunningTotalDisplay" type="text" size="10" readonly="readOnly" value="<?echo "$".$PreTotal;?>"  /></td>
      </tr>
    <tr> 
      <td style="width: 612px" valign="top"><div align="center">
			
          
          <select name="MenuList" size="20" id="MenuList" multiple>
            <? 
  $i=0;
	$itemchk="checker";
    while($i < $objRecordset1num)
  {
			$OrderSunsetDays=mysql_result($objRecordset1,$i,"OrderSunsetDays");
			
			$MenuItemID=mysql_result($objRecordset1,$i,"MenuItemID");
			$ItemType=mysql_result($objRecordset1,$i,"ItemType");
			$Item=mysql_result($objRecordset1,$i,"Item");
			$cost=mysql_result($objRecordset1,$i,"cost");
			if ($itemchk!=$ItemType)
			{
				if ($itemchk!="checker")
				{
				
				  print "</optgroup>";
				
				}
			  
				print "<optgroup label=\"".$ItemType."\">";
				$itemchk=$ItemType;
			}
//if now-date > sunset then print option
		if (datediff('d', date("Y-m-d"), $_GET["date"], false)>=$OrderSunsetDays)
   // if (1>0)
    {


?>
            <option value=<?       echo $MenuItemID;?>><?       echo $Item;?>=<?       echo "$".$cost;?> </option>
            <? 
    } 

   
$i++;

  } 
?>
          </select><br />
          &nbsp;&nbsp;<br />
          &nbsp;</div></td>
        <td style="width: 397px" align="center">
          <button id="menuSelect" name="menuSelect" onclick="FromTo(<?   echo $_SESSION['credit'];?>)" style="width: 60px">
              --&gt;&gt;</button>
            <br /> Move selections to Order.<br />
          <button id="removeOptionS" name="removeOptionS" onclick="removeOptionSelected()" style="width: 60px">
              &lt;&lt;--</button>&nbsp;<br />
            Remove selections from Order.<br />
            <br />
         
          
          <button id="PlaceOrdersClick" name="menuSelect" onclick="PlaceOrders(<?   echo $_GET["minor"];?>,<?   echo $_GET["BreakID"];?>,'<?   echo $_GET["date"];?>','<?   echo $_GET["minorname"];?>')" style="width: 190px">Place Order</button><br />
            Complete the order.<br />
           <button id="Return2Cal" onclick="window.location.href = 'usercalendar-sdates3.php?minor=<?   echo $_GET["minor"];?>&date=<?   echo $_GET["date"];?>&minorname=<?   echo $_GET["minorname"];?>';return true;" style="width: 190px">Return to Calendar</button><br />
            <br />
            
         <button id="RepeatOrdersWeekly" name="RepeatOrdersWeekly" onclick="RepeatOrders(<?   echo $_GET["minor"];?>,<?   echo $_GET["BreakID"];?>,'<?   echo $_GET["date"];?>','<?   echo $_GET["minorname"];?>',7,'<?   echo $_COOKIE["nondaysString"];?>')" style="width: 190px">
             Repeat Order Weekly</button><br />
            Complete the order and repeat it on a weekly basis.<br />
             
             <button id="RepeatOrdersDaily" name="RepeatOrdersDaily" onclick="RepeatOrders(<?   echo $_GET["minor"];?>,<?   echo $_GET["BreakID"];?>,'<?   echo $_GET["date"];?>','<?   echo $_GET["minorname"];?>',1,'<?   echo $_COOKIE["nondaysString"];?>')" style="width: 190px">
             Repeat Order Daily</button><br /> Complete the order and repeat it on a daily basis.<br />
            

        </td>
        <td valign="top" style="width: 251px" colspan="2">
        <?   if (strlen($_GET["ItemStr"])>0)
  {
}

   
//for x=0 to ubound(ItemArray)-1

//response.Write ItemArray(x)&"<br/>"

//ItemDetails=split(ItemArray(x),"*")


//response.Write ItemDetails(0)&"="&ItemDetails(1)&"<br/>"



//next 
 

//if len(Request.QueryString("ItemStr"))> 0 then
//ReDoList(y,3)

// for x = 0 to z-1

//  response.write ReDoList(x,0)&","&ReDoList(x,1)&","&ReDoList(x,2)&","&ReDoList(x,3)&"<BR/>"


//  next 

//end if

//response.end

?>
        
          <select name="MinorOrder" size="20" id="MinorOrder" multiple style="width:250" onchange="RunningTotal(<?   echo $_SESSION['credit'];?>)">
            <? 

//do while not MinorOrder.eof
  if (strlen($_GET["ItemStr"])>0)
  {

//ReDoList(y,3)

    for ($x=0; $x<=$z-1; $x=$x+1)
    {

?>
    <option value="<?       echo $ReDoList[$x][0];?>"><?       echo $ReDoList[$x][1];?>,<?       echo $ReDoList[$x][2];?>=<?       echo "$".$ReDoList[$x][3];?></option>
    <? 


    }


  } 


//MinorOrder.movenext

//loop
?>
          </select>
         
          
          
        </td>
    </tr>
  </table>
  
  </center>
 
	

<? 
}
}
  else
{

?>
<h1>No items available</h1><br/>
<button id="Return2Cal" onclick="window.location.href = 'usercalendar-sdates3.php?minor=<?   echo $_GET["minor"];?>&date=<?   echo $_GET["date"];?>&minorname=<?   echo $_GET["minorname"];?>';return true;" style="width: 190px">Return to Calendar</button><br />


<? }
function datediff($interval, $datefrom, $dateto, $using_timestamps = false) {
/*
$interval can be:
yyyy - Number of full years
q - Number of full quarters
m - Number of full months
y - Difference between day numbers
(eg 1st Jan 2004 is "1", the first day. 2nd Feb 2003 is "33". The datediff is "-32".)
d - Number of full days
w - Number of full weekdays
ww - Number of full weeks
h - Number of full hours
n - Number of full minutes
s - Number of full seconds (default)
*/

if (!$using_timestamps) {
$datefrom = strtotime($datefrom, 0);
$dateto = strtotime($dateto, 0);
}
$difference = $dateto - $datefrom; // Difference in seconds

switch($interval) {

case 'yyyy': // Number of full years

$years_difference = floor($difference / 31536000);
if (mktime(date("H", $datefrom), date("i", $datefrom), date("s", $datefrom), date("n", $datefrom), date("j", $datefrom), date("Y", $datefrom)+$years_difference) > $dateto) {
$years_difference--;
}
if (mktime(date("H", $dateto), date("i", $dateto), date("s", $dateto), date("n", $dateto), date("j", $dateto), date("Y", $dateto)-($years_difference+1)) > $datefrom) {
$years_difference++;
}
$datediff = $years_difference;
break;

case "q": // Number of full quarters

$quarters_difference = floor($difference / 8035200);
while (mktime(date("H", $datefrom), date("i", $datefrom), date("s", $datefrom), date("n", $datefrom)+($quarters_difference*3), date("j", $dateto), date("Y", $datefrom)) < $dateto) {
$months_difference++;
}
$quarters_difference--;
$datediff = $quarters_difference;
break;

case "m": // Number of full months

$months_difference = floor($difference / 2678400);
while (mktime(date("H", $datefrom), date("i", $datefrom), date("s", $datefrom), date("n", $datefrom)+($months_difference), date("j", $dateto), date("Y", $datefrom)) < $dateto) {
$months_difference++;
}
$months_difference--;
$datediff = $months_difference;
break;

case 'y': // Difference between day numbers

$datediff = date("z", $dateto) - date("z", $datefrom);
break;

case "d": // Number of full days

$datediff = floor($difference / 86400);
break;

case "w": // Number of full weekdays

$days_difference = floor($difference / 86400);
$weeks_difference = floor($days_difference / 7); // Complete weeks
$first_day = date("w", $datefrom);
$days_remainder = floor($days_difference % 7);
$odd_days = $first_day + $days_remainder; // Do we have a Saturday or Sunday in the remainder?
if ($odd_days > 7) { // Sunday
$days_remainder--;
}
if ($odd_days > 6) { // Saturday
$days_remainder--;
}
$datediff = ($weeks_difference * 5) + $days_remainder;
break;

case "ww": // Number of full weeks

$datediff = floor($difference / 604800);
break;

case "h": // Number of full hours

$datediff = floor($difference / 3600);
break;

case "n": // Number of full minutes

$datediff = floor($difference / 60);
break;

default: // Number of full seconds (default)

$datediff = $difference;
break;
}

return $datediff;

}

?>




</body>
</html>

Return current item: eCanteen