<?php
session_start();

include('contract/config.inc.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");

//Read From CashRegister Table
$queryCashRegister=" Select ifNull(CashRegister_DisplayLed,0) As CashRegister_DisplayLed, ifNull(CashRegister_DispCOM,0) As CashRegister_DispCOM, ".
				   " ifNull(CashRegister_LedDescLength,0) As CashRegister_LedDescLength ".
				   " From CashRegister ".
				   " Where CashRegister_Name = '".$_SESSION['cashregister']."' ";
$resultCashRegister=mysql_query($queryCashRegister,$connection) or die(mysql_error());
while($rowCashRegister=mysql_fetch_array($resultCashRegister)){
	extract($rowCashRegister);
}

//Read From Setup Table							
$querysetup= " select Company_Name As CompanyName, ifNull(CashReg_DispLedMsg, 'Welcome !') As CashReg_DispLedMsg from setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}

//Display Led Section
$com = 0;
if ($CashRegister_DisplayLed == 1) {
	$com = $CashRegister_DispCOM;
	if (empty($com)) $com = 0;
		
	$fp = fopen ("com".$com.":9600,n,8,1,DS", "wb+");
	//$string='Welcome  !      '; //simulating device
	$string=str_pad($CashReg_DispLedMsg,$CashRegister_LedDescLength,"&nbsp;",STR_PAD_RIGHT); 
	$string=$string.substr($CompanyName,0,$CashRegister_LedDescLength); //simulating device	
	fputs ($fp, $string );          
	fclose ($fp);
}	
			
session_unset();
session_destroy();

session_unregister("username");
session_unregister("useraccount");
session_unregister("dbLabel");
session_unregister("dbName");
session_unregister("defaultdb");
session_unregister("cashregister");

header("location:cashregister_index.php");
?>
