<link href="css/tender_project.css" rel="stylesheet" type="text/css" />
<div class="tender_main_page">
<h1><?php echo $page_title; ?></h1>
	 
<?php include("class_countrymaster.php");
 $targetpage="index.php?route=PMS/Maintenance/EstimationType".$rurl;
$table='mst_estimation';
$PageSecurity = 15;
$action=$_REQUEST['action'];
$daction=$_REQUEST['daction'];
$title = _('Estimation Type Master') ;
$status=true;
if($_REQUEST['Save'])
{
	if(empty($_REQUEST['estimation_name']))
	{
	   $msgErr[]='Please Enter Estimation Name';
	   $status=false;
	}
	
	if(empty($_REQUEST['estimation_code']))
	{
	   $msgErr[]='Please Enter Estimation Code';
	   $status=false;
	}
 }

//************************Delete*********************************************** 
if( $action=='del')
{
 		 $condition="id='".$_REQUEST['id']."'";
	     $s->DeleteRecord($table,$condition);
	     $s->pageLocation($targetpage.'daction=Deleted');
 }
 //************************Edit*********************************************** 
 if(!$_REQUEST['Save'] &&  $status && $action=='Edit')
{
	$condition="id='".$_REQUEST['id']."'";
	$allready=$s->GetRecord($table,  $condition);
	$Select=DB_query($allready,$db);
	$RData=DB_fetch_array($Select);		
	  $block=$RData['block'];
 	  $project=$RData['project'];
	 
	$estimation_name=$RData['estimation_name']; $estimation_code=$RData['estimation_code'];
	$estimation_code=$RData['estimation_code'];
			 
}
 //************************INSERT*********************************************** 
if($_REQUEST['Save'] &&  $status  )
{
	$data['project']=$_REQUEST['project'];
	$data['block']=$_REQUEST['block'];
	$data['estimation_name']=$_REQUEST['estimation_name'];
	 $data['estimation_code']=$_REQUEST['estimation_code'];	
	 
	$data['posted_date']=date('Y-m-d');
  	
	if($action=='Edit')
 	$row= $s->RecordEdit($table, $data,"id='".$_REQUEST['id']."'");
 	else
	$row= $s->RecordInsert($table, $data);
	 
	if(!$row) 
	{
	   die('Error'.DB_error());
	}
  $s->pageLocation($targetpage.'&daction=Inserted');
}?>
 <script type="text/javascript" language="javascript">
 
 	function getdate()
	{
	
 	  a=document.getElementById('estimation_name_').value;
 	 b=document.getElementById('estimation_code_').value;
 	 c=a*b;
 	  document.getElementById('amount_').value=c;
	
	}
 </script>
 
<form method="post" action="">
<table width="60%" border="1" cellspacing="0" cellpadding="3">
 
  <?php if(isset($daction))
  {?>
    <tr>
  
    <td colspan="2" ><div class="success">
	<?php 
 
	 echo "Record ".$daction." Successfully";
 
		 ?>
	</div></td>
  </tr>
  <?php }
  if(isset($msgErr)&&$msgErr!='' )
   {?>
    <tr>
  
    <td colspan="2" ><div class="error"><?php 
for($kp=0;$kp<count($msgErr);$kp++)
 {
		echo  $msgErr[$kp].'<br>';
 }
  ?></div></td>
  </tr>
    <?php }?>
<tr>
  <td class="tabledata">Project</td>
  <td>
  <?Php $sql_state=DB_query("SELECT loccode,locationname FROM  locations ",$db);	?>
 <select class='input_border' style='width:250px;' name='project' onchange="ShowDiv(this.value,'hid_blockdiv','estimation_block.php')">
 <option value='000'> -- Select Project -- </option>
 <?php 				 
					while($row_branch=DB_fetch_array($sql_state))
					{
					   $p='';
					   if($row_branch['loccode']==$project)
					   $p='selected';
					   echo "<option value='".$row_branch['loccode']."' $p >".$row_branch['locationname']."</option>";
					}
				 
					?>
 
  </select>   </td>
</tr>
<tr>
<td class="tabledata">Block Name</td>
<td> 
<div id='hid_blockdiv'> 
<?php 
$sql=DB_query("SELECT id,block_name FROM  sub_block_master where prjct_name='".$project."' ",$db);	
	echo "<select class='input_border' style='width:250px;' name='block'  >";					
	echo "<option value='000'> -- Select Block -- </option>";
	while($row=DB_fetch_array($sql))
	{
		$p='';
		if($row['id']==$block)
		$p='selected';
		echo "<option value='".$row['id']."' $p >".$row['block_name']."</option>";
	}
   echo "</select>";
?>
</div>
</td>
</tr> <tr>
  <td class="tabledata">Estimation Name</td>
  <td><input name="estimation_name" type="text" id="estimation_name_" value="<?php echo $estimation_name?>"  size="43" /></td>
</tr>

 <tr>
  <td class="tabledata">Estimation Code</td>
  <td><input name="estimation_code" type="text" id="estimation_code_" value="<?php echo $estimation_code?>"  size="43" /></td>
</tr>
</table>
  
<input type="submit" name="Save"  value="Save"  class="button" />
<input type="submit" name="cancel"  value="Cancel" /> 
</form>
<table width="100%" border="1" cellspacing="0" cellpadding="3">
<tr><td class="tabledata">Sno.</td>
 
<td class="tabledata"  >Project  </td>
 <td class="tabledata">Estimation Name</td>
 <td class="tabledata">Estimation Code</td>
<td class="tabledata">EDIT</td>
<td class="tabledata">DELETE</td>
</tr>
<?php $s=new db_query();
$SQL ="select * from mst_estimation";	
$result=DB_query($SQL,$db,$ErrMsg); 
while($resrow=DB_fetch_array($result)){
if($resrow['parentid']==0)
{
 $i=1;
 }
 ?>


<tr bgcolor="#FFFFFF" onMouseOver="this.style.backgroundColor='#fffeb3'; this.style.color='#00f';" onMouseOut="this.style.backgroundColor='#FFF'; this.style.color='#000000';" >
<td><?php echo $i++?></td>
 <td ><?php 
 //  $s->GetFieldValue($table,"id='".$resrow['parentid']."'" ,'block');
   echo $resrow['project']?></td>
    <td><?php  echo $resrow['estimation_name']?></td>
  <td><?php  echo $resrow['estimation_code']?></td>
 <td>
 <a href="index.php?route=PMS/Maintenance/EstimationType<?php echo $rurl;?>&action=Edit&id=<?php echo $resrow['id']?>" class="link">Edit</a></td>
<td>
 <a href="index.php?route=PMS/Maintenance/EstimationType<?php echo $rurl;?>&action=del&id=<?php echo $resrow['id']?>" onclick="return confirm('Are you sure you want to delete this record?')" class="link">Delete</a></td>
</tr>
<?php }?>
</table>
 </div>