<?php

session_start();
if($_SESSION['dbName']==""){
header("location:../index.php");
}


include("config.inc.php");
include("Functions_Sales.php");

$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass']) or die("Could not connect to DB");
mysql_select_db($_SESSION['dbName'],$connection) or die("Could not find DB");

$actionmode = $_POST["actionmode"]; if ($actionmode == ""){$actionmode = $_GET["actionmode"];}   
$message 	= $_POST["message"]; if ($message == ""){$message = $_GET["message"];}   
$frm	   	= $_POST['frm']; if ($frm == ""){$frm = $_GET["frm"];}
$item 	   	= $_POST['item'];if ($item == ""){$item = $_GET["item"];}
$startrange = $_POST['startrange'];if ($startrange == ""){$startrange = $_GET["startrange"];}
$PTabIndex  = $_POST['PTabIndex'];if ($PTabIndex == ""){$PTabIndex = $_GET["PTabIndex"];}


$perpage   		= $_POST["perpage"]; if ($perpage == ""){$perpage = $_GET["perpage"];}
$p_name    		= $_POST["p_name"]; if ($p_name == ""){$p_name = $_GET["p_name"];}
$p_cashregister = $_POST["p_cashregister"]; if ($p_cashregister == ""){$p_cashregister = $_GET["p_cashregister"];}
$p_subgroup  	= $_POST["p_subgroup"]; if ($p_subgroup == ""){$p_subgroup = $_GET["p_subgroup"];}
$p_category  	= $_POST["p_category"]; if ($p_category == ""){$p_category = $_GET["p_category"];}

$Reason_Id  	= $_POST["Reason_Id"]; if ($Reason_Id == ""){$Reason_Id = $_GET["Reason_Id"];}
$Reason_Remark 	= $_POST["Reason_Remark"]; if ($Reason_Remark == ""){$Reason_Remark = $_GET["Reason_Remark"];}

$Payment_Id  		 = $_POST["Payment_Id"]; if ($Payment_Id == ""){$Payment_Id = $_GET["Payment_Id"];}
$Payment_Account 	 = $_POST["Payment_Account"]; if ($Payment_Account == ""){$Payment_Account = $_GET["Payment_Account"];}
$Payment_Description = $_POST["Payment_Description"]; if ($Payment_Description == ""){$Payment_Description = $_GET["Payment_Description"];}


$User_Account  = $_POST["User_Account"]; if ($User_Account == ""){$User_Account = $_GET["User_Account"];}
$User_Name 	   = $_POST["User_Name"]; if ($User_Name == ""){$User_Name = $_GET["User_Name"];}
$User_Password = $_POST["User_Password"]; if ($User_Password == ""){$User_Password = $_GET["User_Password"];}

$CashRegister_Name = $_GET["CashRegister_Name"]; if ($CashRegister_Name == ""){$CashRegister_Name = $_POST["CashRegister_Name"];} 

//Read From Setup Table							
$querysetup= " Select DecimalBase, DecimalBase1, DecimalBase2, Base1, Base2, grid_color1, grid_color2, ifNull(ShowSlipNumber,0) As ShowSlipNumber, ".
             " Setup_VatNo, Date_Format(Setup_VatStartDate,'%d/%m/%Y') As Setup_VatStartDate, ifNull(Setup_VatPercentage,0) As Setup_VatPercentage, Company_Name As CompanyName, ".
			 " CashReg_DispLedMsg, ifNull(CashReg_Weight,0) As CashReg_Weight, CashReg_StartBarcode, CashReg_EndBarcode, CashReg_StartQty, CashReg_EndQty, ".
			 " ifNull(CashReg_Price,0) As CashReg_Price, CashReg_StartPrice, CashReg_EndPrice, ifNull(CashReg_RoundDivisor,1) As CashReg_RoundDivisor, ".
			 " ifNull(CashReg_ColorTheme,'default') as CashReg_ColorTheme, CashReg_BgColorOffer, CashReg_BgColorQty, CashReg_BgColorOrderQty, Company_memo as CompanyMemo, ".
			 " CashReg_BgColorZeroPrice, CashReg_BgColorZeroQty, CashReg_BgColorHasDiscount, ifNull(CashReg_ApplyColorOffer,0) As CashReg_ApplyColorOffer, ".
			 " ifNull(CashReg_ApplyColorQty,0) As CashReg_ApplyColorQty, ifNull(CashReg_ApplyColorOrderQty,0) As CashReg_ApplyColorOrderQty, ifNull(CashReg_ApplyColorZeroPrice,0) As CashReg_ApplyColorZeroPrice,  ".
			 " ifNull(CashReg_ApplyColorZeroQty,0) As CashReg_ApplyColorZeroQty, ifNull(CashReg_ApplyColorHasDiscount,0) As CashReg_ApplyColorHasDiscount  ".
			 " From Setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}

//Read From Module Table
$querymodule=" Select ifNull(Module_PostRetailOneToOne,0) As Module_PostRetailOneToOne, ifNull(Module_PostingByCashRegister,0) As Module_PostingByCashRegister, ".
             " ifNull(Module_CashRegItemQtyInCode,0) As Module_CashRegItemQtyInCode, ifNull(Module_CashRegItemSeperate,0) As Module_CashRegItemSeperate, ".
			 " ifNull(Module_CashRegisterBase2,0) As Module_CashRegisterBase2, ifNull(Module_PriceOffer,0) As Module_PriceOffer ".
			 " From Module";
$resultmodule=mysql_query($querymodule,$connection) or die(mysql_error());
while($rowmodule=mysql_fetch_array($resultmodule)){
	extract($rowmodule);
}

if (empty($CashRegister_Name) && !isset($CashRegister_Name)) {
	$queryCashRegisterDft=" Select CashRegister_Name From CashRegister Order By CashRegister_Name Limit 1 ";
	$resultCashRegisterDft = selectData($connection, $queryCashRegisterDft);
	
	$CashRegister_Name = $resultCashRegisterDft[0];
}

//Read From CashRegister Table
$queryCashRegister=" Select CashRegister_Name, Currency_Code, CostCenter_Code, Project_Code, Warehouse_Code, Client_Account, Sales_Account, Cash_Account, ".
				   " Check_Account, Tips_Account, Coupon_Account, ifNull(CashRegister_Drawer,0) As CashRegister_Drawer, CashRegister_DrawerCOM,  ".
                   " ifNull(CashRegister_DisplayLed,0) As CashRegister_DisplayLed, CashRegister_DispCOM, ifNull(CashRegister_LedDescLength,0) As CashRegister_LedDescLength, ".
				   " ifNull(CashRegister_BarCode,0) As CashRegister_BarCode, ifNull(CashRegister_PrintBarcode,0) As CashRegister_PrintBarcode, ".
				   " ifNull(CashRegister_SerialNo,0) As CashRegister_SerialNo, ifNull(CashRegister_RestSerialNo,0) As CashRegister_RestSerialNo, ".
				   " ifNull(CashRegister_Discount,0) As CashRegister_Discount, ifNull(CashRegister_SlipPrinter,0) As CashRegister_SlipPrinter, ".
				   " ifNull(CashRegister_Printer,0) As CashRegister_Printer, ifNull(CashRegisterTTC,0) As CashRegisterTTC, ".
				   " ifNull(CashRegister_Credit,0) As CashRegister_Credit, ifNull(CashRegister_Check,0) As CashRegister_Check, ".
				   " ifNull(CashReg_Vendor,0) As CashReg_Vendor, ifNull(CashReg_ForcingVendor,0) As CashReg_ForcingVendor, ".
				   " ifNull(Module_CashRegisterTable,0) As Module_CashRegisterTable, ifNull(Module_CashregisterStandardview,0) As Module_CashregisterStandardview, ".
				   " ifNull(Module_CashRegisterFastItem,0) As Module_CashRegisterFastItem, ifNull(Module_RestaurantDelivery,0) As Module_RestaurantDelivery, ".
				   " ifNull(Module_CashRegAutoItemsList,0) As Module_CashRegAutoItemsList, ifNull(CashRegister_ShowTaxNonTax,0) As CashRegister_ShowTaxNonTax, ".
				   " ifNull(CashRegister_AutoPost,0) As CashRegister_AutoPost, ifNull(CashRegister_SlipKitchen,0) As CashRegister_SlipKitchen, ".
				   " ifNull(CashRegister_SlipCopy, 1) As CashRegister_SlipCopy, CashRegister_DrawerPrinter, ifNull(CashRegister_AutoClosePrint,0) as CashRegister_AutoClosePrint ".
				   " ,ifNull(cashregister_logout,0) As cashregister_logout, ifNull(cashregister_retailtype,0) As cashregister_retailtype".
				   " From CashRegister ".
				   " Where CashRegister_Name = '".$CashRegister_Name."' ";

$resultCashRegister=mysql_query($queryCashRegister,$connection) or die(mysql_error());
while($rowCashRegister=mysql_fetch_array($resultCashRegister)){
	extract($rowCashRegister);
}

$querycurrency="select Currency_code from currency order by currency_code";
$resultcurrency=mysql_query($querycurrency,$connection) or die(mysql_error());
$resultcurrency1=mysql_query($querycurrency,$connection) or die(mysql_error());
$resultcurrency2=mysql_query($querycurrency,$connection) or die(mysql_error());

print <<<HERE
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<link rel="stylesheet" type="text/css" media="all" href="css/style.css">
<script type="text/javascript" src="js/grid/jquery-1.9.1.js"></script>
<link type="text/css" href="js/calendar/jquery.datetimepicker.css" rel="stylesheet">
<script type="text/javascript" src="js/calendar/jquery.datetimepicker.js"></script>
<script type="text/javascript" src="js/jscolor/jscolor.js"></script>
<script type="text/javascript" src="tabsClass/tabber.js"></script>
<link rel="stylesheet" href="tabsClass/tabber.css" type="text/css" />

<script type="text/javascript">

/* Optional: Temporarily hide the "tabber" class so it does not "flash"
   on the page as plain HTML. After tabber runs, the class is changed
   to "tabberlive" and it will appear.
*/

var tabberOptions = {

  /* Optional: instead of letting tabber run during the onload event,
     we'll start it up manually. This can be useful because the onload
     even runs after all the images have finished loading, and we can
     run tabber at the bottom of our page to start it up faster. See the
     bottom of this page for more info. Note: this variable must be set
     BEFORE you include tabber.js.
  */
  'manualStartup':true,

  /* Optional: code to run after each tabber object has initialized */


  /* Optional: code to run when the user clicks a tab. If this
     function returns boolean false then the tab will not be changed
     (the click is canceled). If you do not return a value or return
     something that is not boolean false, */

  'onClick': function(argsObj) {

    var t = argsObj.tabber; /* Tabber object */
    var id = t.id; /* ID of the main tabber DIV */
    var i = argsObj.index; /* Which tab was clicked (0 is the first tab) */
    var e = argsObj.event; /* Event object */
	
	if (id == 'tab1') document.getElementById('PTabIndex').value = i;
  },

  /* Optional: set an ID for each tab navigation link */
  'addLinkId': true

};

</script>

<script type="text/javascript" language="javascript">
	$(document).on('click', '#txtDateFrom', function() {
			$('#txtDateFrom').datetimepicker({
				timepicker:false,
				formatDate:'Y/m/d',
				scrollMonth:false
			});
		});
</script>
		
<script type="text/javascript" language="javascript">
$(document).ready(function(){
	$( document ).on( "click", ".addTableWrapper article strong", function() {
  $(this).toggleClass('selectedTable');
});
});	

function AddAllTables(){
var userName = document.getElementById('userName').value;
var mode = 'Add';

$('#availableTables strong').each(function(){
		var tableValue = $(this).html();
		var tableValue1 = $(this).attr('id');
		$('#assignedTables').append('<strong>'+tableValue+'</strong>');
		$(this).remove();
		var dataString ='tableName=' + tableValue1+'&mode=' + mode+ '&userName=' + userName;
							// AJAX code to submit form.
							$.ajax({
									type: "POST",
									url: "Form_Assign_table_Action.php",
									data: dataString,
									cache: false,
									success: function(html) {
											//alert(html);
										    
									}
								});

});	
setTimeout(function(){ location.reload(); }, 1000);
}

function AddSelectedTables(){
var userName = document.getElementById('userName').value;
var mode = 'Add';

$('#availableTables strong').each(function(){
	if($(this).hasClass('selectedTable')){
		var tableValue = $(this).html();
		var tableValue1 = $(this).attr('id');
		$('#assignedTables').append('<strong id='+tableValue+'>'+tableValue+'</strong>');
		$(this).remove();
		var dataString ='tableName=' + tableValue1+'&mode=' + mode+ '&userName=' + userName;
							// AJAX code to submit form.
							$.ajax({
									type: "POST",
									url: "Form_Assign_table_Action.php",
									data: dataString,
									cache: false,
									success: function(html) {
											//alert(html);
										    
									}
								});
	}
});	
setTimeout(function(){ location.reload(); }, 1000);
}

function RemoveSelectedTables(){
var userName = document.getElementById('userName').value;
var mode = 'Remove';

$('#assignedTables strong').each(function(){
	if($(this).hasClass('selectedTable')){
		var tableValue = $(this).html();
		var tableValue1 = $(this).attr('id');
		$('#availableTables').append('<strong id='+tableValue+'>'+tableValue+'</strong>');
		$(this).remove();
		var dataString ='tableName=' + tableValue1+'&mode=' + mode+ '&userName=' + userName;
							// AJAX code to submit form.
							$.ajax({
									type: "POST",
									url: "Form_Assign_table_Action.php",
									data: dataString,
									cache: false,
									success: function(html) {
											//alert(html);
										    
									}
								});
	}
});	
setTimeout(function(){ location.reload(); }, 1000);
}

function RemoveAllTables(){
var userName = document.getElementById('userName').value;
var mode = 'Remove';

$('#assignedTables strong').each(function(){
		var tableValue = $(this).html();
		var tableValue1 = $(this).attr('id');
		$('#availableTables').append('<strong>'+tableValue+'</strong>');
		$(this).remove();
		var dataString ='tableName=' + tableValue1+'&mode=' + mode+ '&userName=' + userName;
							// AJAX code to submit form.
							$.ajax({
									type: "POST",
									url: "Form_Assign_table_Action.php",
									data: dataString,
									cache: false,
									success: function(html) {
											//alert(html);
										    
									}
								});
	
});	
setTimeout(function(){ location.reload(); }, 1000);
}

</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>CashRegister Setup</title>
<style type="text/css">

body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 11px;
}
body {
	margin-top: 2px;
	margin-left: 1px;
}
a:link {
	text-decoration: none;
	color: #0000FF;
}
a:visited {
	text-decoration: none;
	color: #0000FF;
}
a:hover {
	text-decoration: none;
	color: #0000FF;
}
a:active {
	text-decoration: none;
	color: #0000FF;
}
.style39 {color:#FF0000; font-weight:bold; font-size:16px; padding:2px;}
.style38 {color:#0026FF; font-weight:bold; font-size:14px; padding:2px;}

div#mainDiv, div#imgDiv {
	font-size: 12px; 
    font-weight:bold; 
	color: #FF0000 ;
	text-align: center; 
	margin-top:10px;
	display:none;
}
 button {
  padding: 0 0 0 0;
  margin: 0 3px 0 3px;
  border: none;
  cursor: pointer;
  text-decoration: none;
  outline: none;
  white-space: nowrap;
  overflow: visible;
  height: 22px; 
  font-family: 11px Arial, sans-serif;
  font-size: 13px;
  color: #000000;
  background: none;
  font-weight: bold;

}

* html .clearfix {
	height: 1%;
	overflow: visible;
}
* + html .clearfix {
	min-height: 1%;
}
.clearfix:after {
	clear: both;
	content: ".";
	display: block;
	height: 0;
	visibility: hidden;
	font-size: 0;
}

.addTableWrapper{
	margin-top:40px;
}

.addTableWrapper article{
	border:1px solid #000;
	width:40%;
	height:200px;
}

.addTableWrapper article:first-child{
	float:left;
}

.addTableWrapper article:last-child{
	float:right;
}

.addTableWrapper article aside{
	overflow:auto;
	height:173px;
}

.addTableWrapper section{
	float:left;
	width:15%;
	margin-left:2.5%;
	padding-top: 50px;
}

.addTableWrapper article b{
	display:block;
	border-bottom:1px solid #000;
	padding:5px;
}

.addTableWrapper article strong{
	line-height: 25px;
	display:block;
	padding:0 10px;
	font-size:12px;
	cursor:pointer;
}

.addTableWrapper article strong:nth-child(2n){
	background-color:#f6f6f6;
	
}

.addTableWrapper section span{
	cursor:pointer;
}

.title2 {
    color: #000;
    font-family: Verdana,Geneva,sans-serif;
    font-size: 14px;
    font-weight: bold;
    text-align: left;
}

.addTableWrapper article strong.selectedTable{
	background-color:#1e87a5;
	color:#fff;
}

</style>

</head>
<body>
<form name='form1' method='post' enctype="multipart/form-data">
<input type='hidden' name='actionmode' value='$actionmode'>
<input type='hidden' name='message' value='$message'>
<input type='hidden' name='PTabIndex' id='PTabIndex' value='$PTabIndex'>

<input type='hidden' name='p_id' id='p_id'  value='$p_id' >
<input type='hidden' name='item' id='item' value='$item' />
<input type='hidden' name='frm' id='frm' value='$frm' />
<input type='hidden' name='startrange' value='$startrange'>
HERE;
	

echo"<table cellpadding='0' cellspacing='0' border='0'  align='center' style='table-layout:fixed' width='700px;'>";
echo"<tr>
		<td id='search-top1' style='height:34px; width:31px;'>&nbsp;</td>
	  	<td id='search-top2' style='height:34px; width:638px' align='center' valign='middle'>$message</td>
		<td id='search-top3' style='height:34px; width:31px;'>&nbsp;</td>
	</tr>";

	  
echo"<tr><td id='search-content1' style='width:31px;'>&nbsp;</td>
		 <td id='search-content2' >"; 

echo "<br><span class='title2'>CASH REGISTER: <input id='userName' value='$UserName' type='text' style='border:0; background:none;' readonly disabled> 
		
	</span>";

$query =	" Select ProjectDt.Projectdt_id as ProjectDt_Id, ProjectDt.Projectdt_name, ProjectDt.Projectdt_numberofseats,ProjectDt.Project_id".
			" From ProjectDt ".
			" Inner Join Project on ProjectDt.Project_ID = Project.Project_ID And Project_name = 'Table'".
			" Left Join ". $config['dbName_log'].".loginstk on projectDt.projectdt_ID=loginstk.projectdt_id and user_account = '$UserName' ".
			" Where loginstk.projectDt_id is Null ";
//echo $query;
	
$result=mysql_query($query,$connection) or die(mysql_error());

$queryAssigned =	" Select loginstk.projectDt_id, ProjectDt.Projectdt_name ".
					" From ". $config['dbName_log'].".loginstk ".
					" inner join ProjectDt on ProjectDt.Projectdt_id = loginstk.projectdt_id ".
					" Where loginstk.user_account ='$UserName'".
					" Order By loginstk.projectDt_id";
//echo $queryAssigned;
	
$resultAssigned=mysql_query($queryAssigned,$connection) or die(mysql_error());


	
echo"<br><div class='addTableWrapper clearfix'>
		<article><b>Assigned Table</b>
			<aside id='assignedTables'>";
			while($rows=mysql_fetch_row($resultAssigned)){
				echo "<strong id='".$rows[0]."'>".$rows[1]."</strong>";
			}
echo"		</aside>
		</article>
	
		<section>
			<span onClick='AddAllTables();'>Add All</span><br>
			<span onClick='AddSelectedTables();'>Add</span><br><br><br><br>
			<span onClick='RemoveSelectedTables();'>Remove</span><br>
			<span onClick='RemoveAllTables();'>Remove All</span>
		</section>
		
		<article>
			<b>Available Table</b><aside id='availableTables'>";
			while($rows=mysql_fetch_row($result)){
				echo "<strong id='".$rows[0]."'>".$rows[1]."</strong>";
			}
			
echo"   </aside></article>";
echo"	</div>";

echo " <div style='margin-top:20px;'>
		<!--<input id='close' type='button' title='Close' onclick=''  name='close' value='Close'>-->
		<a href='Form_RetailSetup.php'>Close</a>
		</div>";

echo "</td><td id='search-content3' style='width:31px;'>&nbsp;</td></tr>";			 
echo"<tr >
		<td id='search-bottom1' style='height:34px; width:31px;'>&nbsp;</td>
		<td id='search-bottom2' style='height:34px; width:638px;' valign='top'></td>
		<td id='search-bottom3' style='height:34px; width:31px;' valign='top'></td>";
echo"</tr>";	


echo"<script type=\"text/javascript\" language=\"javascript\">";
echo"	tabberAutomatic(tabberOptions);";
echo"   vTabIndex = document.getElementById('PTabIndex').value; ";
echo"	if (document.getElementById('tab1')) document.getElementById('tab1').tabber.tabShow(vTabIndex); ";
echo"</script>";

function fbegin()
{
	mysql_query("START TRANSACTION");
}
function fcommit(){
	mysql_query("COMMIT");
}
function frollback()
{
	mysql_query("ROLLBACK");
}
echo "
</form>
</body>

";

?>