<link href="css/tender_project.css" rel="stylesheet" type="text/css" />
<?php
if($_REQUEST['act']=='del' & !empty($_REQUEST['id']))
{
$delete="delete  from sub_block_master where id='".$_REQUEST['id']."'";
$deleted=DB_query($delete,$db);
echo "<script>location.href='index.php?route=SubContractors/Masters/block_master&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."&deleted=1'</script>";
}
 
if($_REQUEST['act']=='edit' && !empty($_REQUEST['id']))
{
$temp="select * from sub_block_master where id='".$_REQUEST['id']."'";
$temps=DB_query($temp,$db);
$myname=DB_fetch_array($temps);
$prjct_name=$myname['prjct_name'];
$block_name=$myname['block_name'];
$short_name=$myname['short_name'];
}
else 
{
	$prjct_name=$_REQUEST['prjct_name'];
	$block_name=$_REQUEST['block_name'];
	$short_name=$_REQUEST['short_name'];
}

if($_REQUEST['save']!='' && $_REQUEST['act']=='edit')
{
	$update="update sub_block_master set prjct_name='".$_REQUEST['prjct_name']."', block_name='".$_REQUEST['block_name']."', short_name='".$_REQUEST['short_name']."' where id='".$_REQUEST['id']."' ";
$updated=DB_query($update,$db);
echo "<script>location.href='index.php?route=SubContractors/Masters/block_master&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."&edited=1'</script>";
}

if($_REQUEST['save']!='' && $_REQUEST['act']=='')
{
$prjct_name=$_REQUEST['prjct_name'];
$block_name=$_REQUEST['block_name'];
$short_name=$_REQUEST['short_name'];
$q1="insert into sub_block_master set prjct_name='".$prjct_name."',
										 block_name='".$block_name."',
    									   short_name='".$short_name."'";  
$res=DB_query($q1,$db);

}?>

<div class="tender_main_page">
<h1>BLOCK MASTER</h1>
<?php if($_REQUEST['edited']=='1'){prnMsg( _(' Record Updated successfully!'),'success');}
if($_REQUEST['deleted']=='1'){prnMsg( _(' Record deleted successfully!'),'success');}?>
<form method="post">
<table width="100%" border="1" cellspacing="0" cellpadding="3">
  <tr>
    <td class="tabledata">Project Name</td>
	<td>
    <select name="prjct_name" id="projct_name"  style="width:200px;">
    <option value="0">---Select---</option>
<?php 
$site="select loccode,locationname from locations";
$result=DB_query($site,$db);		
while($mrow=DB_fetch_array($result))
{?>
		<option value="<?php echo $mrow['loccode']?>" <?php if(isset($prjct_name)){if($mrow['loccode']==$prjct_name){echo "selected";}}?>><?php echo $mrow['locationname']?></option>
	<?php } ?>
</select> 
</td>
  </tr>
  <tr>
    <td class="tabledata">Block Name</td>
    <td><input type="text" name="block_name" style="width:200px;" value="<?php echo $block_name?>"/></td>
  </tr>
  <tr>
    <td class="tabledata">Short Name</td>
    <td><input type="text" name="short_name" style="width:200px;" value="<?php echo $short_name?>"/></td>
  </tr>
</table>
<p style="text-align:left"><input type="submit" name="save" value="save"/></p>
</form>
<table width="100%" border="1" cellspacing="0" cellpadding="3">
  <tr>
    <td class="tabledata">Project</td>
    <td class="tabledata">Block</td>
    <td class="tabledata">Short Name</td>
    <td class="tabledata" colspan="2">Actions</td>
  </tr>
<?php 
$quer="select * from sub_block_master"; 
$results=DB_query($quer,$db);
while($myrow=DB_fetch_array($results))
{	
?>
<tr bgcolor="#FFFFFF" onMouseOver="this.style.backgroundColor='#fffeb3'; this.style.color='#00f';" onMouseOut="this.style.backgroundColor='#FFF'; this.style.color='#000000';" >
    <td><?php 
	$var="select * from locations where loccode='".$myrow['prjct_name']."'"; 
	$vars=DB_query($var,$db);$myvar=DB_fetch_array($vars); 
	echo $myvar['locationname'];  
	?></td>
    <td><?php echo $myrow['block_name'];?></td> 
    <td><?php echo $myrow['short_name'];?></td>
	<td><a href="index.php?route=SubContractors/Masters/block_master&act=edit&id=<?php echo $myrow['id'];?>&modid=<?php echo $_REQUEST['modid']?>&frmid=<?php echo $_REQUEST['frmid'] ?>"><img src="images/icon_edit.gif"/></a></td>
	<td>
	<a href="index.php?route=SubContractors/Masters/block_master&act=del&id=<?php echo $myrow['id'];?>&modid=<?php $_REQUEST['modid']?>&frmid=<?php $_REQUEST['frmid'] ?>" onclick="return confirm('Are you sure you want to delete?')"><img src="images/Icon_Delete3.gif" /></a></td>
  </tr><?php }?>
</table>
</div>