<?php

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


include("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");
//amin nabil spanish
/*
mysql_query("SET NAMES 'utf8'"); 
mysql_query('SET CHARACTER SET utf8'); 		
mysql_set_charset('utf8', $connection);
*/
if(!isset($actionmode))
$actionmode='';


$querysetup="select DecimalBase, DecimalBase1, DecimalBase2, base1, base2, grid_color1, grid_color2,maxperpage from setup";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}


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" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
		<meta name="viewport" content="width=device-width, initial-scale=1.0"> 
<LINK REL="stylesheet" TYPE="text/css" MEDIA="all" HREF="css/tabs.css">

<link rel="stylesheet" type="text/css" media="all" href="css-v2/style.css">
<script type="text/javascript" src="js/grid/jquery-1.9.1.js"></script>
<link type="text/css" href="js/calendar/jquery.datepick.css" rel="stylesheet">
<script type="text/javascript" src="js/calendar/jquery.datepick.js"></script>
<script type="text/javascript" language="javascript">

function SearchForUser(){
	var x = document.lockper;
	x.action='Form_LockedPeriod.php?startrange=0';
	x.submit();
}

function submitenter(myfield,e){
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   	document.lockper.action='Form_LockedPeriod.php?startrange=0';
	document.lockper.submit();
  
   return false;
   }
else
   return true;
}

function ClearKeyword(){
	var x = document.lockper;
	x.txtKeyword.value='';
	x.submit();
}


function SetNextPage(startrange,perpage){
	document.lockper.action='Form_LockedPeriod.php?PRef=&startrange='+startrange+'&perpage='+perpage;
	document.lockper.submit();
}

function SetPrvPage(startrange,perpage){
	document.lockper.action='Form_LockedPeriod.php?PRef=&startrange='+startrange+'&perpage='+perpage;
	document.lockper.submit();
}

function set_limit(){

	perpage=document.lockper.perpage.value;
	document.lockper.action='Form_LockedPeriod.php?perpage='+perpage+'&startrange=0';
	document.lockper.submit();
}

function changePeriod(stat){
	var x = document.lockper;
	var mode = stat;
	x.action="Form_LockedPeriod_Actions.php?mode="+mode;
	x.submit();
}

function checkPer(indx){
	var txt = 'txtlockperiod'+indx;
	if(document.getElementById(txt).checked)
		document.getElementById(txt).value=1;
	else document.getElementById(txt).value=0;
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Locekd Period</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;
}

.style12 {
	font-size: 9px;
	color: #999999;
	font-weight: bold;
}
.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 >
<form name='lockper' method='post' onKeyPress="return submitenter(this,event)">
<input type='hidden' name='actionmode' value='$actionmode'>
<input type=hidden name='message' value='$message'>
HERE;

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

echo"<table cellpadding='0' cellspacing='0' border='0'  align='center' class='layout-width'>";
include_once("header.php");
echo" <tr><td  valign='top'>";

include_once("sidemenu.php");
echo"  </td></tr>";


echo" <tr style='height:26px;'>
		<td  valign='top' id='content-top'>
			<table border='0' cellpadding='0' cellspacing='0' style='table-layout:fixed; height:26px;' class='layout-width'>
			<tr style='height:26px;'>
				<td style='width:38px; height:26px;'>&nbsp;</td>
				<td valign='middle' style='width:300px; height:26px;'><span class='title' style='text-transform: uppercase'>Locked Period</span></td>
				<td class='message' valign='middle' style='height:26px;'>".htmlspecialchars($message, ENT_QUOTES)."</td>
			</tr></table>
		</td>
	  </tr>";

echo"<tr>
		<td  height='34'  valign='top' id='content-top2'>
			<table border='0' cellpadding='0' cellspacing='0' class='layout-width' width='1100px'>
				<col width='450'>
				<col width='120'>
				<col width='150'>
				<col width='250'>
				<col width='200'>
				<col width='200'>
				<tr>
					<td valign='middle' height='34' style='padding-left:40px'>";
	echo"				<button type='button' idbtnLockbtnClear' name='btnLock' onclick='changePeriod(1); return false;' title='Lock'><span><span>Lock</span></span></button>";
	echo"				<button type='button' id='btnUnlock' name='btnUnlock' onclick='changePeriod(0); return false;' title='Unlock' ><span><span>Unlock</span></span></button>";					
					
						$querysearch="select Usercode,Username, ifnull(AllowLockedPeriod,0), date_format(LockedPeriod,'%d-%m-%Y'),companyname from ".$_SESSION['dbLabel'].".listuserdir where   upper(concat(CompanyName,'_',Diryear)) = Upper('".$_SESSION['dbName']."') and ifnull(Usercode,'') != '' ";
						//	$querysearch=$querysearch." and (Usercode like"."('%".$txtKeyword."%') or Username like"."('%".$txtKeyword."%')) ";
							
							$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());
							$totalrows = mysql_num_rows($resultsearch);
							
							if ($startrange=='')
								$startrange = 0;
							if ($perpage=='')
								$perpage = 20;
							
						//	$querysearch = $querysearch." limit ".$startrange.",".$perpage;
//						echo$querysearch;
							
echo"					<td align='center'>";
/*						$diff= $startrange - $perpage;
						
						if (($diff) >= 0 ){
							$prvstartrange = $startrange - $perpage;
							echo"<img src='img/arrowleft.png' title='Previous' onMouseOver=\"style.cursor='hand'\"  onclick=SetPrvPage('".$prvstartrange."','".$perpage."')>";
						}
						else
							echo "&nbsp;";*/
						
						echo"</td><td  align='center'>";
						
						
/*						if ($startrange <= $totalrows){
							$startrange = $startrange + $perpage;
							if  ($startrange <= $totalrows)
								echo"<img src='img/arrowright.png' title='Next' onMouseOver=\"style.cursor='hand'\" onclick=SetNextPage('".$startrange."','".$perpage."')>";
						} else
							echo "&nbsp;";
*/						
echo"				</td>
					
					<td align='left' width='263px'> ";
/*echo"					<input type='text' name='txtKeyword' value='$txtKeyword' style='width:115px;' onKeyPress='return submitenter(this,event)'>
						<button type='button' id='btnSearch' name='btnSearch' onclick='SearchForUser(); return false;' title='Search User'><span><span>Find</span></span></button>
						<button type='button' id='btnClear' name='btnClear' onclick='ClearKeyword(); return false;' title='Clear Keyword'><span><span>Clear</span></span></button>";*/
echo"				</td>
					
					<td colspan=2 align='left'>";
/*echo"				<span class='style1'><b>".$ResultsPage1."</b></span>
						<span class='style1'><select name='perpage' id='perpage' value='$perpage' onchange=set_limit();>";
	 
						if ($startrange=='')
							$startrange = 0;
						if ($perpage=='')
							$perpage = 20;
						//row limit loop
						foreach ($config['trowlimit'] as $value) {
							echo "<option value='$value' ";
									if($value==$perpage) echo "selected";
										echo " >$value</option>";
						}
			*/
echo"  				 </td>
				</tr>
			</table>
		</td>
	</tr>";

echo"	<tr>
		<td id='content-body'>";		
echo"			<table border='0'  align='center' valign='top' width=1100px class='tablecontent'>";
echo"   			<tr bgcolor='#F7F7F7'>";
echo"   				<td valign='top'>
							<table style='table-layout:fixed' align='left' valign='top' width='1100px' border=0>
								<col width=25>
								<col width=150>
								<col width=200>
								<col width=100>
								<col width=100>";
echo "<tr><td  colspan='3'><span class='style1'>Locked Date </span><input type='text' name='txtlockdate' id='txtlockdate' value='$txtlockdate' maxlength='10' style='width:90px;text-align:center;' >
 <A HREF='#' onClick=\"displayCalendar(document.lockper.txtlockdate,'dd/mm/yyyy',this);  return false;\" NAME='anchor1' ID='anchor1'><img src='./img/cal.gif' border=0 align=center></A></tr>";	

echo "<tr height='20px'><td></td></tr>";
echo "<tr height='20px' style='background-color:rgba(169, 169, 169, 0.52);'><td></td><td align='center'><b>User Account</b></td><td align='center'><b>User Name</b></td>
		<td align='center'><b>Company Name</b></td><td align='center'><b>Status</b></td><td align='center'><b>Locked Date</b></td></tr>"; 
$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());
$ct=0;
while($row = mysql_fetch_row($resultsearch)){
	$ct+=1;
	$stylefont='style15';
	if($ct%2==0)
		$Color="style='background-color:".$grid_color1."'";
	else			
		$Color="style='background-color:".$grid_color2."'";	
	$txtlockperiod = 'txtlockperiod'.$row[0];		
	echo "<tr $Color><td align='center'><input type='checkbox' name='$txtlockperiod' id='$txtlockperiod' value='1' onclick=\"checkPer('$row[0]');\" checked></td><td><span class='style15'>$row[0]</span></td>
		<td><span class='style15'>$row[1]</span></td><td><span class='style15'>$row[4]</span></td><td><span class='style15'>".($row[2]==1?'Locked':'')."</span></td>
		<td><span class='style15'>$row[3]</span></td></tr>"; 
}
echo "</table></td></tr></table></td></tr>";		  
 echo" <tr height='30'><td align='center' id='content-bottom' ></td></tr>";
include("footer.php");	
print <<< HERE
			</td>
		</tr>
	</table>
HERE;



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

HERE;

?>
