<?php


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

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

//Connect to Database
$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");

$query1="select grid_color1, grid_color2, DecimalBase, DecimalBase1, DecimalBase2, base1, base2 from setup";
$result1=mysql_query($query1,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($result1)){
extract($rows);

}

$act = $_GET['act'];
$user = $_GET['user'];

if ($act == '' && $user == ''){
	//$UserPcName = strtoupper(gethostbyaddr($_SERVER['REMOTE_ADDR']));
	//$UserPcName = $_SERVER['REMOTE_ADDR'];
	$UserPcName = $config['POS'];
	
	$sub_query =  " Select Cash_Register ".
  	     " From ".$_SESSION['dbLabel'].".logindt ".
		 " Where User_Account = '".$_SESSION['useraccount']."' ";
	$sub_result = mysql_query($sub_query, $connection);
	$sub_rowcount = mysql_num_rows($sub_result);
				 
	if ($sub_rowcount > 1) {
		$sub_query = " Select CashRegister_Name ".
					 " From CashRegister ".
					 " Where Upper(CashRegister_PCName) = '".$UserPcName."'";
		$sub_result = selectData($connection, $sub_query); 
		$user = $sub_result[0];
		$act  = 'SelectUser';
	} else {
		$sub_row = mysql_fetch_row($sub_result);
		$user = $sub_row[0];
		$act  = 'SelectUser';
	}
	

}
	

if ($act == 'SelectUser' && $user != ''){
	
	//Adding CashRegsiter User To Session	
	//session_register("cashregister");
	//$cashregister = $user;	
	$_SESSION['cashregister'] = $user;
	 $_GET['MainMenu']=1;
	
	if ($_GET['MainMenu'] == 1) {
		echo'<script type="text/javascript" language="javascript">
				//var vHeight = screen.availHeight;
				//var vWidth  = screen.availWidth;
				
				open("Form_Retail.php", "_blank");
				self.close();
			 </script>';
	} else {
		echo'<script type="text/javascript" language="javascript">
				open("Form_Retail.php", "_self").close();
				
			 </script>';
	}

}

print <<< HERE
<html>
<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" language="javascript">

function ClearForm() {
  x = document.cashusers;

  //x.action = 'menu.php';
  //x.submit();
  self.close();
}


function SelectUser() {
	x = document.cashusers;
	
	for (var i=0; i < x.SelUser.length; i++)
	{
		if (x.SelUser[i].checked)
		{
			var vUser = x.SelUser[i].value;
		}
	}
	
	if (x.SelUser.length == undefined)
		var vUser = x.SelUser.value;
	
	
	x.action = 'Form_Retail_CashUsers.php?act=SelectUser&user='+vUser;
    x.submit();

}

function MouseOverColor(object)
{

	object.style.backgroundColor = '#E1EAFE';
}

function MouseOutColor(object, Color)
{

	object.style.backgroundColor = Color;
}

</script>
<title>Select Cash User </title>

<style type="text/css">
<!--
body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 14px;
}
a:link {
	text-decoration: none;
}
a:visited {
	text-decoration: none;
}
a:hover {
	text-decoration: none;
}
a:active {
	text-decoration: none;
}
.style1 {
	font-family: Arial;
	font-size: 12px;
	color: #4069A7;
	font-weight: bold;
}
.style2 {
	color: #FF0000;
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 10px;
}
.style3 {
	color: #4069A7;
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 10px;
}
.style8 {font-size: 11px; color: #999999; font-weight: bold; }
.style11 {font-size: 11px}
.style15 {
	font-size: 15px;
	color: #000000;
	font-weight: bold;
	font-family: "Times New Roman", Times, serif;
}
body {
	margin-top: 0px;
}
-->
</style>

</head>
<body >


	<form name='cashusers' method='post' action=''>
<table cellpadding='0' cellspacing='0' border='0'  align='left' style='table-layout:fixed' width='250px'>

HERE;

	//$UserPcName = strtoupper(gethostbyaddr($_SERVER['REMOTE_ADDR']));
	//$UserPcName = $_SERVER['REMOTE_ADDR'];
	$UserPcName = $config['POS'];
	
		
echo "<tr >
		<td id='search-top1' style='height:34px; width:31px;'>&nbsp;</td>
	  	<td id='search-top2' style='height:34px; width:250px;padding-top:8px;' align='center' valign='middle'>
			
			 <button type='button' id='btnSubmit' name='btnSubmit' onclick='SelectUser(); return false;' title='Ok'><span><span>Ok</span></span></button>
			 <button type='button' id='btnCancel' name='btnCancel' onclick='ClearForm(); return false;' title='Cancel'><span><span>Cancel</span></span></button>
			
		</td>
		<td id='search-top3' style='height:34px; width:31px;'>&nbsp;</td>
	</tr>

<tr><td id='search-content1' style='width:31px;'>&nbsp;</td>
		 <td id='search-content2' >
	 <table border='0' align='left' width='250px'  cellpadding='0' cellspacing='0'>
";
echo"
		<tr height='5'><td>&nbsp;</td></tr>
		<tr><td align='left'><div style='overflow-y:scroll;height:250px;width:240px;border:0px solid #000000;' ><table border='0' align='left' width='100%'  >";


$i = 0;
/*$query = " Select CashRegister_Name ".
  	     " From CashRegister ".
	     " Order By CashRegister_Name ";*/
$query = " Select Cash_Register ".
  	     " From ".$_SESSION['dbLabel'].".logindt ".
		 " Where User_Account = '".$_SESSION['useraccount']."' ".
	     " Order By Cash_Register ";		 
//echo $query; 
//exit;
//echo $connection;
$result=mysql_query($query,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($result)){
			    
	$ct+=1;
    $i = $i + 1;
	//if($ct%2==0)
		$Color="style='background-color:".$grid_color1."'";
	//else			
		//$Color="style='background-color:".$grid_color2."'";	
						
	
	$Selected = '';
	if ($i == 1) $Selected = ' checked ';
	
	echo "<tr ".$Color." height='20' onmouseover='MouseOverColor(this)' onmouseout='MouseOutColor(this, \"#F7F7F7\")'>";
	echo"   <td width='5%' align='center'><span class='style15'><input type='radio' name='SelUser' id='SelUser' value='".$rows[0]."'  $Selected/></span></td>";
	echo "	<td width='95%' align='left'><span class='style15'>".$rows[0]."</span></td>";		
	echo "</tr>";
						
					
								
}

	
print <<< HERE
		
		</table></div></td></tr>
	</table>
	<td id='search-content3' style='width:31px;'>&nbsp;</td></tr>
	<tr >
		<td id='search-bottom1' style='height:34px; width:31px;'>&nbsp;</td>
		<td id='search-bottom2' style='height:34px; width:1025px;' valign='top'>
		</td><td id='search-bottom3' style='height:34px; width:31px;'>&nbsp;</td></tr></table>
	</form>
</body>
</html>

HERE;

?>