Location: PHPKode > projects > eCanteen > ecanteen/user/csvfile2.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/>.
?>
<?	session_start();

if ($_SESSION['userlevel']>=3)
{
include("../include/constants.php");     mysql_free_result($res);


  $objConnection1=mysql_connect(DB_SERVER, DB_USER, DB_PASS);
  mysql_select_db(DB_NAME);
list($Nowdate,$NowTime)=explode(" ",date("Y-m-d"));
// $objConnection1 is of type "ADODB.Connection"
// $MenuList is of type "ADODB.Recordset"

$sqlstmt="SELECT class.`Class`, minorcustomer.`Class$`, minorcustomer.`LastName`, minorcustomer.`FirstName`, break.`BreakID`, break.`Break`, break.`~SiteID$`, customersandorders.`OrderDate`, itemtype.`ItemType`, menuitem.`Item`, menuitem.`Cost`, customersandorders.`Quantity`, customersandorders.`Active_L2`, transactions.`TransactionNumber`, IsNull(`PrintDate`) AS Printed, transactions.`TransactionID` FROM ((class INNER JOIN minorcustomer ON class.`ClassID` = minorcustomer.`Class$`) INNER JOIN ((itemtype INNER JOIN menuitem ON itemtype.`ItemTypeID` = menuitem.`ItemType$`) INNER JOIN (customersandorders INNER JOIN break ON customersandorders.`Break$` = break.`BreakID`) ON menuitem.`MenuItemID` = customersandorders.`MenuItem$`) ON minorcustomer.`CustomerID` = customersandorders.`MinorCustomerC$`) INNER JOIN transactions ON (customersandorders.`MinorCustomerC$` = transactions.`MinorAccountID`) AND (customersandorders.`Break$` = transactions.`BreakID`) AND (customersandorders.`OrderDate` = transactions.`TargetDate`) WHERE (((break.`BreakID`)=".$_GET["BreakID"].") AND ((customersandorders.`OrderDate`)='".$_GET["date"]."') AND ((transactions.`TransactionNumber`)=1) AND ((break.`~SiteID$`)=".$_SESSION["SiteID"].") AND ((IsNull(`PrintDate`))=".$_GET["printed"].")) ORDER BY class.`Class`, transactions.`TransactionID`, itemtype.`ItemType`, menuitem.`Item`;";



//
//echo $sqlstmt;
//break;
//echo "<br>";
//response.Write "<br/>"

$SearchList=mysql_query($sqlstmt);

$SearchListnum=mysql_numrows($SearchList);


$sqlstmt="UPDATE transactions INNER JOIN majorcustomer ON transactions.`MajorAccountID` = majorcustomer.`CustomerID` SET transactions.`PrintDate` = '".$Nowdate."' WHERE (((transactions.`TargetDate`)='".$_GET["date"]."') AND ((transactions.`BreakID`)=".$_GET["BreakID"].") AND ((majorcustomer.`~SiteID$`)=".$_SESSION['SiteID'].") AND ((transactions.`TransactionNumber`)=1));";

//echo $SearchListnum;
mysql_query(($sqlstmt),$objConnection1);
$StName=-120;
$i=0;
$orderStr="Class,FirstName,lastname,TransactionID,Break,Date,Item 1,Item 2,Item 3,Item 4,Item 5,Item 6,Item 7,Item 8,Item 9,Item 10, Total".PHP_EOL;
while($i<$SearchListnum)
{
	list($Orderdate,$OrderTime)=explode(" ",mysql_result($SearchList,$i,"OrderDate"));
  if ($StName!=mysql_result($SearchList,$i,"TransactionID"))
  {
    if ($StName!=-120)
    {
		  $c=0;
			while($c<$linescount-1)
			{
			  $orderStr=$orderStr.",";
				$c++;
			}
		  $orderStr=$orderStr.",".$TotalCost.PHP_EOL;
		}
    $linescount=10;
    $TotalCost=0;
    $orderStr=$orderStr.mysql_result($SearchList,$i,"Class").",".mysql_result($SearchList,$i,"FirstName").", ".mysql_result($SearchList,$i,"lastname").",".mysql_result($SearchList,$i,"TransactionID").",".mysql_result($SearchList,$i,"Break").",".$Orderdate.",";


    $StName=mysql_result($SearchList,$i,"TransactionID");
    }    
	     $orderStr=$orderStr.mysql_result($SearchList,$i,"Item")." ";
	     $orderStr=$orderStr."$".mysql_result($SearchList,$i,"Cost")." ";
			 $orderStr=$orderStr.mysql_result($SearchList,$i,"Quantity")." ";  
			 $orderStr=$orderStr."$".mysql_result($SearchList,$i,"Cost")*mysql_result($SearchList,$i,"Quantity").",";
       $TotalCost=$TotalCost+mysql_result($SearchList,$i,"Cost")*mysql_result($SearchList,$i,"Quantity");
       $i++;
$linescount=$linescount-1;

 

}

//echo $linescount;
$c=0;
while($c<$linescount-1)
			{
			  $orderStr=$orderStr.",";
				$c++;
			}
			
		  $orderStr=$orderStr.",".$TotalCost.PHP_EOL;
			$filename=$Orderdate."-".mysql_result($SearchList,0,"Break")."-Site".$_SESSION["SiteID"].".csv";
			
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"".$filename."\"");
echo $orderStr;
}
?>
Return current item: eCanteen