Location: PHPKode > projects > eCanteen > ecanteen/user/admincalendar-sdates5.php
<? 
session_start(); 
if ($_SESSION['userlevel']>=3)
{
//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/>.
//*******************************************************
//*     ASP 101 Sample Code - http://www.php101.com/    *
//*                                                     *
//*   This code is made available as a service to our   *
//*      visitors and is provided strictly for the      *
//*               purpose of illustration.              *
//*                                                     *
//*      http://www.php101.com/samples/license.php      *
//*                                                     *
//* Please direct all inquiries to hide@address.com *
//*******************************************************
//PrintOrderMenuLink($dateD,$minorID,$BreakID,$Break,$minorName)
//{
//print "<a href=\"QuikMenu.php?date=".$dateD."&minor=".$minorID."&BreakID=".$BreakID."&Break=".$break."&minorname=".$minorName."\">".$break." Order </a><BR/>";
//}

//CustID,TransactionID,BreakID,dDate,Itemstr,BreakName,MinorName

$file_name="admincalendar-sdates5.php";
//HTML print functions
function PrintDelModButtons($minorID,$TransactionID,$BreakID,$dateD,$ItemStr,$BreakShortName,$minorName)
{

          print "<button id=\"DelClick-".$TransactionID."\" name=\"delorders\" alt=\"Delete Order\" onclick=\"DelOrders(".$minorID.",".$TransactionID.",".$BreakID.",'".$dateD."','".$ItemStr."',1,'".$BreakShortName."','".$minorName."')\">".$BreakShortName."-</button>";
                              print "<button id=\"DelClick-".$TransactionID."\" name=\"delorders\" alt=\"Delete Order\" onclick=\"DelOrders(".$minorID.",".$TransactionID.",".$BreakID.",'".$dateD."','".$ItemStr."',2,'".$BreakShortName."','".$minorName."')\">".$BreakShortName."*</button>";
}

function PrintBreakOrderSelect($itemstr)
{
				print "<select name=\"test\" size=\"3\" style=\"width:130\" >";
        $CostTotal=0;
       	$OrderArray=explode("*",$itemstr);
        for ($x=0; $x<=count($OrderArray)-1; $x=$x+1)
        {
          $LineArray=explode("/",$OrderArray[$x]);
          print "<option value=".$LineArray[1].">".$LineArray[0]."</option>";

        }
        print "</select><br/>";

}






//End HTML printing functions



function GetDaysInMonth($iMonth,$iYear)
{
  $function_ret = date('t',mktime(0,0,0,$iMonth,1,$iYear)); // This is to calculate number of days in a month
  return $function_ret;
} 

function leftcheckyear($iMonth,$iYear)

{
if ($iMonth=="1")
{
	$function_ret = intval($iYear-1);
}else{ 
  $function_ret = $iYear;  
}
return $function_ret;
}

function rightcheckyear($iMonth,$iYear)

{
if ($iMonth=="12")
{
	$function_ret = intval($iYear+1);
}else{ 
  $function_ret = $iYear;  
}
return $function_ret;
}

function SubtractOneMonth($iMonth,$iYear)
{
     $function_ret = date('n', mktime(0,0,0,($iMonth-1),28,$iYear));
  if ($function_ret<10)
		 {
		   $function_ret="0".$function_ret;
		 }
  
  return $function_ret;
} 

function GetWeekdayMonthStartsOn($iMonth,$iYear)
{

    $function_ret= date('w',mktime(0,0,0,$iMonth,1,$iYear)); // This will calculate the week day of the first day of the month
  
  return $function_ret;
} 

function AddOneMonth($iMonth,$iYear)
{
   $function_ret = date('n', mktime(0,0,0,($iMonth+1),28,$iYear));         // NEXT month of year (1-12)
   if ($function_ret<10)
		 {
		   $function_ret="0".$function_ret;
		 }
  
  return $function_ret;
} 

// ***End Function Declaration***




// Get selected date.  There are two ways to do this.
// First check if we were passed a full date in RQS("date").
// If so use it, if not look for seperate variables, putting them togeter into a date.
// Lastly check if the date is valid...if not use today

$iMonth=date('n',time());
$iDay=date('d',time());
$iYear=date('Y',time());

 if($_GET['date'] != "")
 {
    list($iYear,$iMonth,$iDay)=explode("-",$_GET["date"]);
    if (checkdate($iMonth,$iDay,$iYear))
    {
        //not much
    }else{
		        
    }           
 }elseif ($_GET["day"] != ""){
     $iMonth=$_GET["month"];        
     $iDay=$_GET["day"];  
     $iYear=$_GET["year"];    
 }else{
         
 }    

 
  
//Now we've got the date.  Now get Days in the choosen month and the day of the week it starts on.
$iDIM=GetDaysInMonth($iMonth,$iYear);
$iDOW=GetWeekdayMonthStartsOn($iMonth,$iYear)+1;
$datestr=$iYear."-".$iMonth."-".$iDay;
$FromDateStr=$iYear."-".$iMonth."-01";
$ToDateStr=$iYear."-".$iMonth."-".$iDIM;


?>
<script language="javascript" type="text/javascript">

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 DelOrders(CustID,TransactionID,BreakID,dDate,Itemstr,elSource,BreakName,MinorName)
{
//window.alert('DelOrders.php?CustID='+CustID+'&BreakID='+BreakID+'&dDate='+dDate+'&TransactionID='+TransactionID);
if (1==2){
	window.alert("Issues cannot be transferred within Projects!")
}else{
//window.alert(ToSel.options[ToSel.selectedIndex].value);

var decision=confirm(TransactionID+" - delete this Order?");


//window.alert(answer);
if (decision==true)
{
	disableAllFormControls()
	document.getElementById('DelClick-'+TransactionID).disabled=true;
	window.open('DelOrders.php?CustID='+CustID+'&BreakID='+BreakID+'&dDate='+dDate+'&TransactionID='+TransactionID+'&elSource='+elSource+'&Itemstr='+Itemstr+'&MinorName='+MinorName+'&BreakName='+BreakName);
	//,'CP','width=1,height=1,menubar=no');
    if (elSource==1)
    {        	
	    //window.location.href = unescape(window.location.href);
	}else{
	    			//window.location.href='QuikMenu.php?date='+dDate+'&minor='+CustID+'&BreakID='+BreakID+'&Itemstr='+Itemstr+'&Break='+BreakName+'&minorname='+MinorName
	}
	//var xtest=displayIncidents(SCHEDID,0);
	//,'CP','width=1,height=1,menubar=no'
}else{
}

}
}

</script>
<?

include("../include/constants.php");     mysql_free_result($res);
	session_start();

$objConnection1  = mysql_connect(DB_SERVER, DB_USER, DB_PASS);
  mysql_select_db(DB_NAME);

$sqlstmt="SELECT break.`BreakShortName`, break.`SortOrder`, Count(transactions.`TransactionID`) AS `CountOfTransactionID`, transactions.`TargetDate`, Sum(transactions.`WithdrawalAmount`) AS `SumOfWithdrawalAmount`, break.`BreakID`, break.`Break`, break.`~SiteID$`, transactions.`TransactionNumber`, IsNull(`PrintDate`) AS `Printed` FROM transactions RIGHT JOIN break ON transactions.`BreakID` = break.`BreakID` GROUP BY break.`BreakShortName`, break.`SortOrder`, transactions.`TargetDate`, break.`BreakID`, break.`Break`, break.`~SiteID$`, transactions.`TransactionNumber`, IsNull(`PrintDate`) HAVING (((transactions.`TargetDate`)>='".$FromDateStr."' And (transactions.`TargetDate`)<='".$ToDateStr."') AND ((break.`~SiteID$`)=".$_SESSION['SiteID'].")) ORDER BY break.`SortOrder`;";
//echo $sqlstmt   ;
//break;

$objRecordset1=mysql_query($sqlstmt);

$objRecordset1num=mysql_numrows($objRecordset1);
echo mysql_error();  
//echo $objRecordset1num."<br>";

$sqlstmt="SELECT break.`BreakID`,break.`Break`,break.`BreakShortName`,break.`SortOrder`,break.`OrderCloseTime`,break.`Minutes`,break.`~SiteID$` FROM break WHERE (((break.`SortOrder`)>0) AND ((break.`~SiteID$`)=".$_SESSION['SiteID'].")) ORDER BY break.`SortOrder`;";

//echo $sqlstmt;

$SiteBreaks=mysql_query($sqlstmt);

$SiteBreaksnum=mysql_numrows($SiteBreaks);

$query="SELECT specialdate.`SpecialDateID`,specialdate.`SpecialDateDescr`,specialdate.`SpecialDateFrom`,specialdate.`SpecialDateTo`,specialdate.`Active_L2`,specialdate.`~SiteID$` FROM specialdate WHERE (((specialdate.`SpecialDateFrom`)>='".$FromDateStr."' And (specialdate.`SpecialDateFrom`)<='".$ToDateStr."') AND ((specialdate.`~SiteID$`)=".$_SESSION['SiteID'].")) OR (((specialdate.`SpecialDateTo`)>='".$FromDateStr."' And (specialdate.`SpecialDateTo`)<='".$ToDateStr."') AND ((specialdate.`~SiteID$`)=".$_SESSION['SiteID'].")) ORDER BY specialdate.`SpecialDateDescr`;";
$result=mysql_query($query);

$num=mysql_numrows($result);




?>
<!-- Outer Table is simply to get the pretty border-->


<TABLE BORDER=10  width="98%" height="85%" CELLSPACING=0 CELLPADDING=0>
		<TR>
			<TD>
				<TABLE width="100%" height="100%" BORDER=1 CELLSPACING=0 CELLPADDING=1 BGCOLOR=#99CCFF>
	<TR>
		<TD BGCOLOR=#000099 ALIGN="center" COLSPAN=7>
			<TABLE WIDTH=100% BORDER=0 CELLSPACING=0 CELLPADDING=0>
				<TR>
					<TD ALIGN="right"><A HREF=<? echo $file_name?>?date=<? echo leftcheckyear($iMonth,$iYear) ."-".SubtractOneMonth($iMonth,$iYear)."-".$iDay."&minor=".$_GET["minor"]."&minorname=".$_GET["minorname"];?>><FONT COLOR=#FFFF00 SIZE="-1">&lt;&lt;</FONT></A></TD>
					<TD ALIGN="center"><FONT COLOR=#FFFF00><B><? echo date('F',mktime(0,0,0,$iMonth,1,$iYear))." ".$iYear;?></B></FONT><button id="Return2Cal" onclick="window.location.href='../index.php';return true;" style="width: 190px">Return to Main Menu</button></TD>
					<TD ALIGN="left"><A HREF=<? echo $file_name?>?date=<? echo rightcheckyear($iMonth,$iYear) ."-".AddOneMonth($iMonth,$iYear)."-".$iDay."&minor=".$_GET["minor"]."&minorname=".$_GET["minorname"];?>><FONT COLOR=#FFFF00 SIZE="-1">&gt;&gt;</FONT></A></TD>
				</TR>
			</TABLE>
		</TD>
	</TR>
	<TR>
		<TD ALIGN="center" BGCOLOR=#0000CC><FONT COLOR=#FFFF00><B>Sun</B></FONT><BR><IMG SRC="./images/spacer.gif" WIDTH=60 HEIGHT=1 BORDER=0></TD>
		<TD ALIGN="center" BGCOLOR=#0000CC><FONT COLOR=#FFFF00><B>Mon</B></FONT><BR><IMG SRC="./images/spacer.gif" WIDTH=60 HEIGHT=1 BORDER=0></TD>
		<TD ALIGN="center" BGCOLOR=#0000CC><FONT COLOR=#FFFF00><B>Tue</B></FONT><BR><IMG SRC="./images/spacer.gif" WIDTH=60 HEIGHT=1 BORDER=0></TD>
		<TD ALIGN="center" BGCOLOR=#0000CC><FONT COLOR=#FFFF00><B>Wed</B></FONT><BR><IMG SRC="./images/spacer.gif" WIDTH=60 HEIGHT=1 BORDER=0></TD>
		<TD ALIGN="center" BGCOLOR=#0000CC><FONT COLOR=#FFFF00><B>Thu</B></FONT><BR><IMG SRC="./images/spacer.gif" WIDTH=60 HEIGHT=1 BORDER=0></TD>
		<TD ALIGN="center" BGCOLOR=#0000CC><FONT COLOR=#FFFF00><B>Fri</B></FONT><BR><IMG SRC="./images/spacer.gif" WIDTH=60 HEIGHT=1 BORDER=0></TD>
		<TD ALIGN="center" BGCOLOR=#0000CC><FONT COLOR=#FFFF00><B>Sat</B></FONT><BR><IMG SRC="./images/spacer.gif" WIDTH=60 HEIGHT=1 BORDER=0></TD>
	</TR>
<?
// Write spacer cells at beginning of first row if month doesn't start on a Sunday.
if ($iDOW!=1)
{

  print "\t"."<TR>"."\r\n";
  $iPosition=1;
  while($iPosition<$iDOW)
  {

    print "\t"."\t"."<TD>&nbsp;</TD>"."\r\n";
    $iPosition=$iPosition+1;
  } 
} 


// Write days of month in proper day slots
$iCurrent=1;
$iPosition=$iDOW;

while($iCurrent<=$iDIM)


	{
	$ArrayiCurrent=$iCurrent;
	if ($iMonth<10 && strlen($iMonth)==1 )
		{
			$iMonth="0".$iMonth;
		}
	if ($iCurrent<10 && strlen($iCurrent)==1)
		{
			$iCurrent="0".$iCurrent;
		}


// If we're at the beginning of a row then write TR
  if ($iPosition==1)
  {

    print "\t"."<TR>"."\r\n";
  } 


// If the day we're writing is the selected day then highlight it somehow.
  $SpecialDateStr="";
  $DateActive=true;
	$i=0;
	$thisdate=$iYear."-".$iMonth."-".$iCurrent;
	while ($i < $num) {
		$Active_L2=mysql_result($result,$i,"Active_L2");
		$SpecialDateFrom=mysql_result($result,$i,"SpecialDateFrom");
		$SpecialDateTo=mysql_result($result,$i,"SpecialDateTo");
		$SpecialDateDescr=mysql_result($result,$i,"SpecialDateDescr");
		list($Fromdate,$FromTime)=explode(" ",$SpecialDateFrom);
		list($Todate,$ToTime)=explode(" ",$SpecialDateTo);
		if ($thisdate>=$Fromdate && $thisdate<=$Todate)
    {
        $SpecialDateStr=$SpecialDateStr."<br>".$SpecialDateDescr;
        $DateActive=$Active_L2;
    } 
		$i++;
	}
	//if Sunday or Saturday or inactive day for canteen, then print day only $iPosition==7 || $iPosition==1 || 
	if ($DateActive==false)
  {
  	if ($iCurrent==$iDay)
 		 {
   		 print "\t"."\t"."<TD align=\"center\" valign=\"top\" BGCOLOR=#00FFFF width=\"4%\"  height=\"15%\"><FONT SIZE=\"-1\"><B>".$iCurrent."</B></FONT><br>".$SpecialDateStr."</td>"."\r\n";
 		 }
  	  else
 		 {
      //$iMonth,$iYear
				print "\t"."\t"."<TD align=\"center\" valign=\"top\" width=\"4%\"  height=\"15%\"><A HREF=\"./".$file_name."?date=".$iYear ."-".$iMonth."-".$iCurrent."&minor=".$_GET["minor"]."&minorname=".$_GET["minorname"]."\"><FONT SIZE=\"-1\">".$iCurrent."</FONT></A><br>".$SpecialDateStr."</td>";
    
  		} 
			
	}else{
		if ($iCurrent==$iDay)
  		{
   		 print "\t"."\t"."<TD align=\"center\" valign=\"top\" BGCOLOR=#00FFFF width=\"4%\"  height=\"15%\"><FONT SIZE=\"-1\"><B>".$iCurrent."</B></FONT><br>";

  		}
   		else
  		{
      //$iMonth,$iYear
				print "\t"."\t"."<TD align=\"center\" valign=\"top\" width=\"4%\"  height=\"15%\"><A HREF=\"./".$file_name."?date=".$iYear ."-".$iMonth."-".$iCurrent."&minor=".$_GET["minor"]."&minorname=".$_GET["minorname"]."\"><FONT SIZE=\"-1\">".$iCurrent."</FONT></A><br>";
    
  		}
			
			//admin start
			print "<table>";
    $i=0;
		
		while ($i < $SiteBreaksnum) 
    {

 
			$h=0;
      if ($objRecordset1num>0)
      {

        $StartLabel="testx";
				
        while($h < $objRecordset1num)
        {
					list($Targetdate,$TargetTime)=explode(" ",mysql_result($objRecordset1,$h,"TargetDate"));
					//echo $Targetdate."=".$thisdate."<br>";
					
          if ($StartLabel!=mysql_result($SiteBreaks,$i,"Break"))
          {

            if ($StartLabel!="testx")
            {
              print "</tr>";
            } 
            print "<tr><td>";
            print "<a href=\"collatepage.php?date1=".$thisdate."&date2=".$thisdate."&BreakID=".mysql_result($SiteBreaks,$i,"BreakID")."&Break=".mysql_result($SiteBreaks,$i,"Break")."\" target=\"blank\">".mysql_result($SiteBreaks,$i,"Break")."</a>&nbsp";
						if ($iPosition==7)//Collate Week
						
		        {
						  $lastseven = date('Y-m-d', mktime(0, 0, 0, $iMonth  , $iCurrent-6, $iYear));
							
              if ($lastseven<10)
	            {
		            $lastseven="0".$lastseven;
		          }
						  
			        print "<a href=\"collatepage.php?date1=".$lastseven."&date2=".$thisdate."&BreakID=".mysql_result($SiteBreaks,$i,"BreakID")."&Break=".mysql_result($SiteBreaks,$i,"Break")."\" target=\"blank\">W-".mysql_result($SiteBreaks,$i,"Break")."</a>&nbsp";
			      }


            print "</td>";
//Response.Write "<br/>"&objRecordset1.fields("Break")&"&nbsp"
            $StartLabel=mysql_result($SiteBreaks,$i,"Break");
          } 
//$objRecordset1
					if ($Targetdate==$thisdate)
					{
					//echo "target=".$Targetdate;
					//break;
          if (mysql_result($objRecordset1,$h,"TransactionNumber")==1 && mysql_result($objRecordset1,$h,"Printed")==0 && mysql_result($objRecordset1,$h,"BreakID")==mysql_result($SiteBreaks,$i,"BreakID"))
          {
            print "<td><a href=\"csvfile2.php?date=".$thisdate."&BreakID=".mysql_result($SiteBreaks,$i,"BreakID")."&Break=".mysql_result($SiteBreaks,$i,"Break")."&tn=1&printed=0\" target=\"Main\"><font color=\"green\"  >".mysql_result($objRecordset1,$h,"CountOfTransactionID")."P</font></a>&nbsp</td>";

          } 

          if (mysql_result($objRecordset1,$h,"TransactionNumber")==1 && mysql_result($objRecordset1,$h,"Printed")==1  && mysql_result($objRecordset1,$h,"BreakID")==mysql_result($SiteBreaks,$i,"BreakID"))
          {
					  print "<td><a href=\"csvfile2.php?date=".$thisdate."&BreakID=".mysql_result($SiteBreaks,$i,"BreakID")."&Break=".mysql_result($SiteBreaks,$i,"Break")."&tn=1&printed=1\" target=\"Main\"><font color=\"red\"  >".mysql_result($objRecordset1,$h,"CountOfTransactionID")."N</font></a>&nbsp</td>";

            
          } 

          if (mysql_result($objRecordset1,$h,"TransactionNumber")==0 && mysql_result($objRecordset1,$h,"Printed")==0 && mysql_result($objRecordset1,$h,"BreakID")==mysql_result($SiteBreaks,$i,"BreakID"))
          {

            print "<td><a href=\"PrintCancelledPage.php?date=".$thisdate."&BreakID=".mysql_result($SiteBreaks,$i,"BreakID")."&Break=".mysql_result($SiteBreaks,$i,"Break")."&tn=0&printed=0\" target=\"Main\"><font color=\"black\"  >".mysql_result($objRecordset1,$h,"CountOfTransactionID")."C</font></a>&nbsp</td>";
          } 
				}
        $h++;  

       } 


      }
        else
      {


      } 

      $i++;

//Response.Write "<BR/>"
//iCurrent >= Day(dDate) or Month(dDate) > month(now())
    } 
    print "</table>";

    $WeekTotal=$WeekTotal+$CostTotal;
				
				print $SpecialDateStr."</td>"."\r\n";

	}
// If we're at the endof a row then write /TR
  if ($iPosition==7)
  {

    print "\t"."</TR>"."\r\n";
    $iPosition=0;
  } 


// Increment variables
  $iCurrent=$iCurrent+1;
  $iPosition=$iPosition+1;
} 

// Write spacer cells at end of last row if month doesn't end on a Saturday.
if ($iPosition!=1)
{

  while($iPosition<=7)
  {

    print "\t"."\t"."<TD>&nbsp;</TD>"."\r\n";
    $iPosition=$iPosition+1;
  } 
  print "\t"."</TR>"."\r\n";
} 

mysql_close();?>
</TABLE>
</TD>
</TR>
</TABLE>

<BR>

<table border=0 cellspacing=0 cellpadding=0>
		<tr>
			<td align="center">
				<form action=<? echo $file_name;?> method="get" id="usercalendar">
				<input type="hidden" name="minor" value="<? echo $_GET["minor"];?>" />
					<table border="1" cellpadding="0" cellspacing="2" width="188">
						<tr>
<td>
<select name="month">
<? 

$c_month[1]="January";
$c_month[2]="February";
$c_month[3]="March";
$c_month[4]="April";
$c_month[5]="May";
$c_month[6]="June";
$c_month[7]="July";
$c_month[8]="August";
$c_month[9]="September";
$c_month[10]="October";
$c_month[11]="November";
$c_month[12]="December";

for ($zz=1; $zz<=12; $zz=$zz+1)
{
?>
<option value=<?   echo $zz;?><?   if (strftime("%m",time())==$zz)
  {
    print " selected";
  } ?>><?   echo $c_month[$zz];?></option><? 

}
//zz
?>
</select></td>
<td><select name="day">
<? 
for ($c_day=1; $c_day<=31; $c_day=$c_day+1)
{
?>
<option value=<?   echo $c_day;?><?   if ($Day[time()]==$c_day)
  {
    print " selected";
  } ?>><?   echo $c_day;?></option><? 

}
//c_day
?>
</select></td>
<td><select name="year">
<? 
for ($c_year=strftime("%Y",time())-2; $c_year<=strftime("%Y",time())+2; $c_year=$c_year+1)
{
?>
<option value=<?   echo $c_year;?><?   if (strftime("%Y",time())==$c_year)
  {
    print " selected";
  } ?>><?   echo $c_year;?></option><? 

}
//c_year

?>
								</select></td>
							<td><input type="submit" value="Goto Date"></td>
						</tr>
						
						
					</table>
				</form>
			</td>
		</tr>
	</table>
	<?}?>


Return current item: eCanteen