<?php 
//****************************SAVE THE DATA START HERE************************************
if($_REQUEST['save_finish'])
{
	$groupid=implode(",",$_REQUEST['pbs_group']);
	$date=date('Y-m-d');
	$data['estimation_name']=$_REQUEST['estimation_name'];
	$data['pbse_code']=$_REQUEST['pbse_code'];
	$data['group_id']=$groupid;
	$data['project']=$_REQUEST['project'];
	$data['block']=$_REQUEST['block'];
	$data['act_material']=$_REQUEST['act_material'];
	$data['qty']=$_REQUEST['qty'];
	$data['rate']=$_REQUEST['rate'];
	$data['amt']=$_REQUEST['amt'];
	$data['posted_date']=$date;
	$insert=$s->RecordInsert('psm_estimation_type', $data);
	$s->pageLocation("index.php?route=PMS/Transcations/estimation_type_view".$rurl);
}


//****************************SAVE THE DATA END HERE************************************


//****************************FETCH THE DATA FOR EDITING START HERE**********************

if($_REQUEST['action']=='Edit' && $_REQUEST['id']!='')
{
	$condition="id='".$_REQUEST['id']."'";
	$Fetchdata=$s->GetRecordById('psm_estimation_type',$condition);
	$FetchdataRow=DB_fetch_array($Fetchdata);
}


//****************************FETCH THE DATA FOR EDITING END HERE**********************


//****************************EDIT THE DATA START HERE************************************

if($_REQUEST['Update_finish'] && $_REQUEST['action']=='Edit')
{
	$groupid1=implode(",",$_REQUEST['pbs_group']);
	$date1=date('Y-m-d');
	$dataArray['estimation_name']=$_REQUEST['estimation_name'];
	$dataArray['pbse_code']=$_REQUEST['pbse_code'];
	$dataArray['group_id']=$groupid1;
	$dataArray['project']=$_REQUEST['project'];
	$dataArray['block']=$_REQUEST['block'];
	$dataArray['act_material']=$_REQUEST['act_material'];
	$dataArray['qty']=$_REQUEST['qty'];
	$dataArray['rate']=$_REQUEST['rate'];
	$dataArray['amt']=$_REQUEST['amt'];
	$dataArray['posted_date']=$date1;
	$cond="id='".$_REQUEST['id']."'";
	//print_r();
	$s->RecordEdit('psm_estimation_type', $dataArray, $cond);
	$s->pageLocation("index.php?route=PMS/Transcations/estimation_type_view".$rurl);
}

//****************************EDIT THE DATA END HERE************************************

?>

<link href="css/tender_project.css" rel="stylesheet" type="text/css" />
<form method="post">
<div class="tender_main_page">
<h1>Estimation Type</h1>
<!-- Body Content Start -->
<div id="body_content">
  <div class="left_part">
  <!--left table 1 start --><div>
  
  	<table width="100%" border="0" cellspacing="0" cellpadding="0" style="border-width: 0 0 0 0px;">
  <tr>
  <td>
  <?php 
$sql=DB_query("SELECT id,estimation_name FROM  mst_estimation where 1=1",$db);	
	echo "<select  class='input_border' style='width:200px;' name='estimation_name'  >";					
	echo "<option value='000'> -- Select Block -- </option>";
	while($row=DB_fetch_array($sql))
	{
		$p='';
		if($row['id']==$FetchdataRow['estimation_name'])
		$p='selected';
		echo "<option value='".$row['id']."' $p >".$row['estimation_name']."</option>";
	}
   echo "</select>";
?>
  </td>
    <td><!--<input type="button" value="Expand" class="search" />--></td>
  </tr>
  <tr>
    <td style="width:100px;">
	<?php $grp=DB_query("select * from psm_psb_project where parent_id='0'",$db); ?>
	<select name="pbse_code" id="pbse_code" style="width:200px;" onchange="ShowDiv(this.value,'hid_group','psm_pbs_group.php')">
	<option value="0">Select Group</option>
	<?php while($grpRow=DB_fetch_array($grp)) { 
	
	$sel='';
	if($FetchdataRow['pbse_code']==$grpRow['id'])
	$sel='selected';
	?>
	<option value="<?php echo $grpRow['id']; ?>"<?php echo $sel; ?>><?php echo $grpRow['pbse_description']; ?></option>
	<?php } ?>
	</select>
	<!--<input class="input_border" value="PBSE Code" style="width:133px; padding-left:5px;" />&nbsp;<input type="button" value="Search" class="search" />-->
	
	
	</td>
	<td>&nbsp;</td>
  </tr>
</table>
  </div>  <!--left table 1 close -->
  
  <div id="hid_group" style="border:#93959c solid 1px; width:260px; overflow:auto; height:300px; margin-top:10px;">
 <?php 
 if($_REQUEST['action']!=''){
 $sql=DB_query("SELECT * from psm_psb_project where parent_id!='0'",$db); ?> 
<select style="width:260px;height:280px;margin-top:10px;"multiple="multiple"  class="input_border" name="pbs_group[]">					
	<option value="000"> -- Select Block -- </option>
	<?php 
	$k=0;
	while($row=DB_fetch_array($sql))
	{
	
	
	 $x=explode(',',$FetchdataRow['group_id']);
	print_r($x);
	 $p='';
	for($i=0;$i<count($x);$i++)
	{		
		if($row['id']==$x[$i])
		$p='selected';		
	}
		 ?>
		<option value="<?php echo $row['id'] ?>" <?php echo $p; ?>><?php echo $row['pbse_description']; ?></option>
	<?php   } ?>
  </select>
  <?php  } ?>
  </div>
    </div><!-- Close Left Part -->
  
  
  
  
  
  
  <div class="right_part">
  
<!-- Right Table 1 start --><div>
	
<table width="100%" border="0" cellspacing="0" cellpadding="3">
  <tr class="row1">
    <td class="tabledata">Project <span style="color:#FF0000;">*</span></td>
    <td> 
		  <?Php $sql_state=DB_query("SELECT loccode,locationname FROM  locations ",$db);	?>
 <select class="input_border" style="width:350px;"   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']==$FetchdataRow['project'])
					   $p='selected';
					   echo "<option value='".$row_branch['loccode']."' $p >".$row_branch['locationname']."</option>";
					}
				 
					?>
 
  </select></td>
  </tr>
  <tr class="row1">
    <td class="tabledata">Block <span style="color:#FF0000;">*</span></td>
    <td><div id='hid_blockdiv'> 
<?php 
//echo "SELECT id,block_name FROM  sub_block_master where prjct_name='".$project."' ";
$sql=DB_query("SELECT id,block_name FROM  sub_block_master",$db);	
	echo "<select  class='input_border' style='width:350px;' name='block'  >";					
	echo "<option value='000'> -- Select Block -- </option>";
	while($row=DB_fetch_array($sql))
	{
		$pe='';
		if($row['id']==$FetchdataRow['block'])
		$pe='selected';
		echo "<option value='".$row['id']."' $pe >".$row['block_name']."</option>";
	}
   echo "</select>";
?>
</div></td>
  </tr>
  <tr class="row1">
    <td class="tabledata">Activity / Material Name <span style="color:#FF0000;">*</span></td>
    <td><input type="text" name="act_material" value="<?php echo $FetchdataRow['act_material']; ?>" class="input_border" style="width:350px;" /></td>
  </tr>
  <tr class="row1">
    <td colspan="2">
	
		<table width="100%" border="0" cellspacing="0" cellpadding="3">
  <tr>
    <td class="tabledata">Quantity</td>
	<td><input type="text" name="qty" id="qty" value="<?php echo $FetchdataRow['qty']; ?>" class="input_border" style="width:100px;" /></td>
    <td class="tabledata">Rate</td>
    <td><input type="text" name="rate" id="rate" value="<?php echo $FetchdataRow['rate']; ?>" class="input_border" style="width:100px;" /></td>
    <td class="tabledata">Ammout</td>
    <td><input type="text" name="amt" id="amt" value="<?php echo $FetchdataRow['amt']; ?>" class="input_border" style="width:100px;" onfocus="calculate()" /></td>
    <td><!--<input type="button" value="Apply" class="search" />--></td>
  </tr>
</table>
	</td>
  </tr>
  
  
  
  
  
</table>
	
	
	
</div><!-- Right Table 2 Close -->
  
  
  
  
  
  </div><!-- Close Right Part -->
  
  
  <div class="cl"></div>
</div>
<!-- Body Content Close -->

<div style="height:30px;"></div>

<div class="button_nav">
	<input type="submit" name="<?php if($_REQUEST['action']=='Edit'){echo 'Update_finish';}else{echo 'save_finish'; } ?>" value="<?php if($_REQUEST['action']=='Edit'){echo 'Update & finish';}else{echo 'Save & finish'; } ?>" class="submit_button" />&nbsp;&nbsp;&nbsp;&nbsp;
	<input type="button" value="Save & Continue" class="submit_button" />&nbsp;&nbsp;&nbsp;&nbsp;
	<input type="button" value="Close" class="submit_button" />


</div>
</div>
</form>
<script type="text/javascript" language="javascript">
function calculate()
{
var a=document.getElementById("qty").value;
var b=document.getElementById("rate").value;
var c=a*b;
document.getElementById("amt").value=c;
}
</script>