<?php

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


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

set_time_limit(0);


$connection = mysql_connect($config['dbServer'],$config['dbUser_log'],$config['dbPass_log']) or die("Could not connect to DB");
 mysql_select_db($config['dbName_log'],$connection) or die("Could not find DB");


$PForm 		= $_GET["PForm"]; if ($PForm == ""){$PForm = $_POST["PForm"];}   
$PRetId 	= $_GET["PRetId"]; if ($PRetId == ""){$PRetId = $_POST["PRetId"];}   
$mainaction = $_GET["mainaction"]; if ($mainaction == ""){$mainaction = $_POST["mainaction"];}   
$actionmode = $_GET["actionmode"]; if ($actionmode == ""){$actionmode = $_POST["actionmode"];}   
$message 	= $_GET["message"]; if ($message == ""){$message = $_POST["message"];}   

$txtSupervisor = $_POST["txtSupervisor"]; if ($txtSupervisor == ""){$txtSupervisor = $_GET["txtSupervisor"];}   
$txtPassword   = $_POST["txtPassword"]; if ($txtPassword == ""){$txtPassword = $_GET["txtPassword"];}   
 
 
print <<<HERE
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" href="default.css" type="text/css" />
<script type="text/javascript" language="javascript">

function LoadForm() 
{
	x=document.password;
	x.txtPassword.focus();
}

function CloseForm() {
	self.close();
}


function SubmitRecord() {
	x = document.password;
	
	   
	x.action = 'Form_RetailDiscount_PasswordAdmin.php?act=SelectUser';
    x.submit();
}


function Passkd(e)
{ 
	x=document.password;
    var intKey = (window.Event) ? e.which : e.keyCode;
	
		
    if (intKey == 13) { //enter key
        x.btnOk.click();
		return false;
    }
	
	
    return true;
}

function kd(e)
{ 
	x=document.password;
	if (!e) { var e = window.event;}
    var intKey = (window.Event) ? e.which : e.keyCode;
	
	 
	// Block browser short cuts     
	//F1, F3, F4  key
	if (intKey == 112 || intKey == 114 || intKey == 115 ) {
		if(e.preventDefault) // non-IE browsers         
			e.preventDefault();     
		else  // IE Only  
		{
			e.keyCode=0;  
			e.returnValue = false; 
			
		}	
	}

	
    if (intKey == 113) { //F2 key
		x.btnOk.click();
		return false;
	}
	else if (intKey == 27) { //ESC key
		x.btnClose.click();
		return false;
	}
	
	
    return true;
}

</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Add Discount</title>


<script type="text/javascript" src="dropdown.js"></script>
<link rel="stylesheet" href="default.css" type="text/css" />
<link rel="stylesheet" href="short.css" type="text/css" />
<link rel="stylesheet" href="dropdown.css" type="text/css" />
<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;
}
.style11 {color: #999999; font-weight: bold; }
.style12 {
	font-size: 12px;
	color: #999999;
	font-weight: bold;
	font-family: "Times New Roman", Times, serif;
}
.style15 {color: #5151FF; font-size: 10px;}
.style16 {
	font-size: 16px;
	color: #FF0000;
	font-weight: bold;
	font-family: "Times New Roman", Times, serif;
}
.style17 {font-size: 9px}
.style25 {color: #999999; font-weight: bold; font-size: 10px; }
.style26 {color: #FF0000}
.style27 {color: #999999 ;font-size: 10px;}
.style28 {color: #FFFFFF ;font-size: 10px;}

</style>

<link type="text/css" rel="stylesheet" href="dhtmlgoodies_calendar.css?random=20051112" media="screen"></LINK>
<SCRIPT type="text/javascript" src="dhtmlgoodies_calendar.js?random=20060118"></script>

</head>
<body onLoad='LoadForm();' onkeydown='return kd(event);'>
<form name='password' method='post'>
<input type='hidden' name='mainaction' value='$mainaction'>
<input type='hidden' name='actionmode' value='$actionmode'>
<input type='hidden' name='message' value='$message'>
<input type='hidden' name='PRetId' value='$PRetId'>
<input type='hidden' name='PForm' value='$PForm'>
		
HERE;
	

if ($act == 'SelectUser'){

	if ($config['EncryptPassMod'] == 1)
		$sub_query="select encryptpassword('$txtPassword') as pass";
	else
		$sub_query="select '$txtPassword' as pass";
	
	$sub_result    = selectData($connection, $sub_query);	
		
	//echo "<BR>".
	$sub_query1 = " Select Users.user_account ".
				  "	From users inner join login on login.user_account = users.user_account  ".
	              " Where Users.User_Password = '".$sub_result[0]."' ".
				  " And ifNull(login.FC_CashRegisterDisc,0) = 1 ".
				  " And Upper(login.Login_Schema) = Upper('".$_SESSION['dbName']."')  ".
				  " Limit 1 ";
				 
	//echo $sub_query1;
	$sub_result1    = selectData($connection, $sub_query1);
	$txtSupervisor = $sub_result1[0];
	
	if (empty($sub_result1[0])) {
		$message = 'Incorrect password or user has no discount access.';
	} else {
		$_SESSION['discount_userX'] = "$txtSupervisor";
		 
		echo"<script type='text/javascript' language='javascript'>  
			opener.document.retaildt.txtRetDtDiscount.readOnly = false;
			window.opener.location.reload();
			self.close();</script>";
	}
}



$style= "style=' width:70px; height:22px; background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'";

	  
echo"   <tr><td valign='top'>
        <table border='0' cellpadding='1' style='table-layout:fixed' align='center' valign='top' >
          <col width=100>
		  <col width=245>
		   <tr bgcolor='#F7F7F7' height='20'>	
			 <td colspan='2' align='center'><font size='1' color='#FF0000' face='Verdana'><b>".$message."</b></font></td></tr>

			
		  <tr bgcolor='#F7F7F7' height='30'>
             <td valign='center' align='left' ><span class='style12'>Supervisor</span></td> 
			 <td align='left' ><input type='text' name='txtSupervisor' value='$txtSupervisor' maxlength='20' style='background-color: #000000; color:#00FF00; text-align:left; font-size:16px; font-weight:bold; width:195px; height:27px;' readonly ></td>
		  </tr>	

		  
		  <tr bgcolor='#F7F7F7' height='30'>
             <td valign='center' align='left' ><span class='style12'>Password</span></td> 
			 <td align='left'><input type='password' name='txtPassword' value='$txtPassword' maxlength='20' onkeydown='return Passkd(event);' style='text-align:left; font-size:16px; font-weight:bold; width:195px; height:27px;' ></td>
		  </tr>	 	
			 
		  <tr bgcolor='#F7F7F7' height='30'>
		     <td colspan='2' align='center' bgcolor=#D8D8D8>
			    <input type='button' id='btnOk' name='btnOk'  value='F2:Ok'  onclick='SubmitRecord();' $style title='Ok'>
				<input type='button' id='btnClose' name='btnClose'  value='Esc:Close'  onclick='CloseForm();' $style title='Close'>
			 </td>
			 
		  </tr>
        </table>";

	

print <<<HERE
</form>
</body>

HERE;

?>