<?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");

/// Color Grids    Base1 Base2     Decimal for Amounts

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

if($mainaction=='edit'){

	$query_edit="select Unit_Code, ifnull(Synchronized,0) from unit where Unit_Code='".$Unit_Code."'";
	$resultedit=mysql_query($query_edit,$connection) or die(mysql_error());
	$row_edit=mysql_fetch_row($resultedit);
	$Unit_Code		 = $row_edit[0];
	$txtSynchronized = $row_edit[1];
	$Old_Unit        = $Unit_Code;	
}

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

if($mainaction=='')
	$mainaction='insert';
	
print <<<HERE
<html>
<head>
<LINK REL=StyleSheet HREF="style.css" TYPE="text/css" MEDIA=screen>
<SCRIPT type="text/javascript" src="shortcut.js"></script>
<script type="text/javascript" language="javascript">

function SaveChanges(){
	x=document.itemunit;
		
	if(x.Unit_Code.value==''){
		alert('Code is Mandatory');
		x.Unit_Code.focus();
	}
	
	else{
		x.action="Form_ItemUnit_Actions.php";
		x.submit();
	}
}

function Edit_Record(unitcode){
	x=document.itemunit;
	x.Unit_Code.value=unitcode;
	x.mainaction.value='edit';
	//x.action="Form_ItemUnit_Actions.php";
	x.submit();
}

function confirm_delete(unitcode) {

	x=document.itemunit;
	if (confirm ( "Are you sure you want to Delete this Record ?")) {
		x.mainaction.value='delete';
		x.action="Form_ItemUnit_Actions.php?Unit_Code="+unitcode;
		x.submit();
	}
}

function setSync(){
	if(document.getElementById("txtSynchronized").checked)
		document.getElementById("txtSynchronized").value=1;
	else
		document.getElementById("txtSynchronized").value=0;
}	
</script>
<link rel="stylesheet" href="default.css" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<style type="text/css">

body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 11px;
}

.style11 {color: #999999; font-weight: bold; font-size:11}
.style12 {color: #000000; font-weight: bold; font-size:11}
.selectstyle {font-size: 11px; font-family:arial,verdana,geneva; color:#000000; width=52px}
.selectstyle1 {font-size: 11px; font-family:arial,verdana,geneva; color:#000000; width=35px}
</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>

<title>Items Units</title>
</head>
<body>
<form name='itemunit' method='post' enctype='multipart/form-data'>
<input type='hidden' name='mainaction' value='$mainaction'>
<input type='hidden' name='Old_Unit' value='$Old_Unit'>
<input type='hidden' name='message' value='$message'>

HERE;


echo "<table  border=0 >
	<col width='250'>
	<col width='250'>";
	
echo '<tr><th height="20"  bgcolor="#F7F7F7" colspan="2" align="left" valign="top"><span class="style3">Item Units</span></th></tr>';
echo "<tr bgcolor='#F7F7F7'><td height='20' colspan='2' align='center'><font size='1' color='#FF0000' face='Verdana'><b>$message</b></font></td></tr>";

echo"<tr><td colspan=2 valign='top'>";
echo "<table  border=0>
		<col width=25>
		<col width=25>
		<col width=120>
		<col width=100>
		<col width=30>";
		
echo"<tr   bgcolor='#F7F7F7' height='25'><td></td><td></td><td><span class='style11'>Unit Code</span></td><td><span class='style11'>Synchronized</span></td><td></td></tr>";
echo"<tr   bgcolor='#F7F7F7' height='25'><td></td><td></td>
					<td align='center'><span class='style11'><input type='text' name='Unit_Code' value='$Unit_Code' style='width:120px;' ></span></td>
					<td align='center'><span class='style11'><input type='checkbox' name='txtSynchronized' id='txtSynchronized' onclick=\"setSync();\" value='$txtSynchronized' ".($txtSynchronized==1?'checked':'')." ></span></td>
					<td><img src='img/confirm-1.png' width='20' height='20' onmouseover=\"style.cursor='pointer'\" onclick='SaveChanges();' style='vertical-align: bottom; cursor: pointer;' title='Save' /></tr>";
echo"<tr  height='25'><td colspan='5'></td></tr>";
$query_values="select Unit_Code, if(ifnull(Synchronized,0) = 1, '&#10004;', '&#10006') from unit order by Unit_Code";
$resultvalues=mysql_query($query_values,$connection) or die(mysql_error());
while($row_value=mysql_fetch_row($resultvalues)){
	if($i%2==0)
		$Color="style='background-color:".$grid_color1."'";
	else			
		$Color="style='background-color:".$grid_color2."'";	
	echo'<tr '.$Color.'>';

print<<<HERE
	<td align=center width='3%'><img border='0' src='img/edit.png' width='15' height='15' title='Edit Detail' onmouseover="this.style.cursor='pointer'" onclick="Edit_Record('$row_value[0]')" $ModMode ></td>
	<td align=center width='3%'><img border='0' src='img/delete.png' width='15' height='15' title='Delete Detail' onmouseover="this.style.cursor='pointer'" OnClick="confirm_delete('$row_value[0]')" $DelMode></td>

HERE;

	echo"<td align='center'>$row_value[0]</td><td align='center'>$row_value[1]</td></tr>";
	$i=$i+1;
}

echo"</table>";
echo"</td></tr>";
echo"</table>";
echo"</body></html>";
?>
