<?php
include("class_countrymaster.php");
$table="psm_psb_project";
$id=$_REQUEST['id'];
$pid=$_REQUEST['pid'];
$targeturl="index.php?route=PMS/Transcations/psb_creation_project".$rurl;
if($_REQUEST['client']==1)
{
	$dataArray['pbse_description']='NewClient';
	$dataArray['posted_date']=date('Y-m-d');
	
	$s->RecordInsert($table, $dataArray);
	$s->pageLocation("index.php?route=PMS/Transcations/psb_creation_project".$rurl);
}

if($_REQUEST['subchild']==1)
{
	$dataArray['pbse_description']='NewClient';
	$dataArray['parent_id']=$_REQUEST['pid'];
	$dataArray['posted_date']=date('Y-m-d');
	$s->RecordInsert($table, $dataArray);
	$s->pageLocation("index.php?route=PMS/Transcations/psb_creation_project".$rurl);
}
if($_REQUEST['del']==1)
{
		$condition="id='".$_REQUEST['pid']."'";
		$s->DeleteRecord($table,  $condition);
 	$s->pageLocation("index.php?route=PMS/Transcations/psb_creation_project".$rurl);
}

function get_children($parent, $level = 1)
{
global $db;$rurl="modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid'];

 	$query = DB_query('SELECT * FROM psm_psb_project WHERE parent_id = '.$parent, $db);
if(DB_num_rows($query) > 0)
{	 
	 		echo '<ul>';
			while($row =DB_fetch_array($query))
			 {
 			echo '<li><a href="index.php?route=PMS/Transcations/psb_creation_project&'.$rurl."&id=".$row['id']."&pid=".$row['parent_id'].'">'.$row['pbse_description'].'</a></li>';
 			get_children($row['id'], $level+1);
			}
			echo '</ul>';
		}
 	
}
if($_REQUEST['pid']!='' && $_REQUEST['id']!='' )
{
  $query = DB_query("SELECT * FROM psm_psb_project  where id='".$_REQUEST['id']."'  and parent_id='".$_REQUEST['pid']."' ",$db);
 $row =DB_fetch_array($query); 
		$project=$row['project'] ;
		 $parent_id=$row['pid'] ;
		 $pbse_description=$row['pbse_description'] ;
		 $pbse_shortcode=$row['pbse_shortcode'] ;
		 $pbse_code=$row['pbse_code'] ;
		 $pbse_order=$row['pbse_order'] ;
		 $seqno=$row['seqno'] ;
  		
	    
 }


if($_REQUEST['pid']!='' && $_REQUEST['SaveData'] )
{
		$Mstdata['project']=$_REQUEST['project'] ;
		 $Mstdata['parent_id']=$_REQUEST['pid'] ;
		 $Mstdata['pbse_description']=$_REQUEST['pbse_description'] ;
		 $Mstdata['pbse_shortcode']=$_REQUEST['pbse_shortcode'] ;
		 $Mstdata['pbse_code']=$_REQUEST['pbse_code'] ;
		 $Mstdata['pbse_order']=$_REQUEST['pbse_order'] ;
		 $Mstdata['seqno']=$_REQUEST['seqno'] ;
  		 $Mstdata['posted_date']=date('Y-m-d');
	    $cond="id='".$id."'";
		 $r= $s->RecordEdit($table, $Mstdata,$cond);
			//$lstid= DB_Last_Insert_ID($db,'boq_entry', $id);
 }
?>
<script language="javascript" type="text/javascript">
function expend()
{

document.getElementById('spanid').style.visibility = 'hidden'; 

 }
</script>
<link href="css/tender_project.css" rel="stylesheet" type="text/css" />

<div class="tender_main_page">
<h1>PBS Creation For Project</h1>
<!-- Body Content Start -->
<div id="body_content">
 <form method=""  action=""> 
 <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><img src="images/max_(c).png" border="0" usemap="#Map" /></td>
    <td><input type="button" value="Expand" class="search" onclick="expend()" /></td>
  </tr>
 
</table>
  </div>  <!--left table 1 close -->
  
  <div style="border:#93959c solid 1px; width:260px; overflow:auto; height:300px; margin-top:10px;">
  <?php 
  $query = DB_query('SELECT * FROM psm_psb_project  where parent_id=0',$db);
 #for avoiding some errors
if(DB_num_rows($query) > 0)
{
 	#start the list
	
	while($row =DB_fetch_array($query)) {
	echo '<ul >';
		#print the item, you can also make links out of these
		echo '<li><a href="'.$targeturl."&id=".$row['id']."&pid=".$row['parent_id'].'">'.$row['pbse_description'].'</a></li>';
		echo '<span style="display:block" id="spanid">'.get_children($row['id']).'</span>';
		echo '</ul>';
	}
	#end the list
	
}	
#some message if the database is empty
else echo 'No Items';
  ?>
  </div>
    </div><!-- Close Left Part -->
  
  
  </form> 
  
  
  
  <div class="right_part" >
  
<!-- Right Table 1 start -->	
<form action="" method="post">
<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 echo $country=$county->project($project); ?>
		</td>
  </tr>
  <tr class="row1">
    <td class="tabledata">PBS Description <span style="color:#FF0000;">*</span></td>
    <td><input type="text" class="input_border" style="width:350px;" name="pbse_description" id="pbse_description" value="<?php  echo $pbse_description;?>">
		</td>
  </tr>
  <tr class="row1">
    <td class="tabledata">PBSE Short Name <span style="color:#FF0000;">*</span></td>
    <td><input type="text" class="input_border" style="width:350px;" name="pbse_shortcode" id="pbse_shortcode" value="<?php  echo $pbse_shortcode;?>"></td>
  </tr>
  
   <tr class="row1">
    <td class="tabledata">PBSE Code <span style="color:#FF0000;">*</span></td>
    <td><input type="text" class="input_border" style="width:350px;" name="pbse_code" id="pbse_code" value="<?php  echo $pbse_code;?>"></td>
  </tr>
  
  <tr class="row1">
    <td class="tabledata">Display Order <span style="color:#FF0000;">*</span></td>
    <td>
	<input type="text" class="input_border" style="width:350px;" name="pbse_order" id="pbse_order" value="<?php  echo $pbse_order;?>">
	
	</td>
  </tr>
  
     <tr class="row1">
    <td class="tabledata">Sequence No <span style="color:#FF0000;">*</span></td>
    <td><input type="text" class="input_border" style="width:350px;" name="seqno" id="seqno" value="<?php  echo $seqno;?>"></td>
  </tr>

  
  
  
</table><div class="button_nav">
	<input type="submit" value="Save & Continue"  name="SaveData" class="submit_button"  onclick="return validate_project()"/>&nbsp;&nbsp;&nbsp;&nbsp;
	<input type="button" value="Save & Finish" class="submit_button" />&nbsp;&nbsp;&nbsp;&nbsp;
	<input type="button" value="Close" class="submit_button" />


</div>

 </div>
  
  </form>
  <!-- Right Table 2 Close -->
  
  
  </div><!-- Close Right Part -->
  
  
  <div class="cl"></div>
</div>
<!-- Body Content Close -->

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

</div>

<map name="Map" id="Map">
<area shape="rect" coords="1,0,24,22" href="index.php?route=PMS/Transcations/psb_creation_project<?php echo $rurl;?>&client=1" title="Child" /><area shape="rect" coords="26,1,48,20" href="index.php?route=PMS/Transcations/psb_creation_project<?php echo $rurl;?>&subchild=1&pid=<?php echo $_REQUEST['id'];?>" title="Sub Child"  /><area shape="rect" coords="51,2,72,20" href="index.php?route=PMS/Transcations/psb_creation_project<?php echo $rurl;?>&del=1&pid=<?php echo $_REQUEST['id'];?>" title="Delete"  />
</map>
<script type="text/javascript" language="javascript">
function validate_project()
{
	var project=document.getElementById("project").value;
	//alert(project);
	if(project=='000')
	{
		alert("Please Select The Project First");
		return false;
	}
	var pbs_desc=document.getElementById("pbse_description").value;
	if(pbs_desc=='')
	{
		alert("Please Enter The PBS Description");
		return false;
	}
	var Pbs_shortname=document.getElementById("pbse_shortcode").value;
	if(Pbs_shortname=='')
	{
		alert("Please Enter The PBS Short Name");
		return false;
	}
	var pbse_code=document.getElementById("pbse_code").value;
	if(pbse_code=='')
	{
		alert("Please Enter The PBSE Code");
		return false;
	}
	var pbse_order=document.getElementById("pbse_order").value;
	if(pbse_order=='')
	{
		alert("Please Enter The Display Order");
		return false;
		
	}
	var seq=document.getElementById("seqno").value;
	if(seq=='')
	{
		alert("Please Enter The Sequence No.");
		return false;
	}
	
}
</script>