<?php
session_name('CAKEPHP'); session_start();
include('exportconfig.php');
$Ticketsql = $_SESSION['Ticket'];
$TicketRes = mysqli_query($db, $Ticketsql);

class db_query
{
	function getField($table, $cond, $val, $field)
	{
		global $db;
		$sql = "select " . $field . " from " . $table . " where " . $cond . "='" . $val . "'";
		$res = mysqli_query($db, $sql);
		$row = mysqli_fetch_array($res);
		return ($row[$field]);
	}
}
$data = '';
$s = new db_query();
$data .= "<table>";
$data .= "<tr>";
$data .= "<td><center>Branch</center></td>";
$data .= "<td><center> Ticket No</center></td>";
$data .= "<td><center>Product Name</center></td>";
$data .= "</tr>";
$i = 0;
while ($TicketRow = mysqli_fetch_array($TicketRes)) {
	$data .= "<tr>";
	$data .= "<td><center>";
	$SiteName = $s->getField('locations', 'loccode', $TicketRow['branch'], 'locationname');
	$data .= $SiteName;
	$data .= "</center></td>";
	$data .= "<td><center>" . $TicketRow['ticket_number'] . "</center></td>";
	$data .= "<td><center>" . $TicketRow['product_name'] . "</center></td>";
	$data .= "</tr>";
	$i++;
}
$data .= "</table>";


$header = '';
header("Content-type: application/x-msdownload");
header("Content-Disposition: attachment; filename=TicketExp.xls");
header("Pragma: no-cache");
header("Expires: 0");
print "$header\n$data";
