<!-------------------------INCLUDE ROOT FILES---------------------START HERE--------------------------->
<?php session_name('CAKEPHP'); session_start();
$PageSecurity = 4;
$PageName = 'Add Items';
include('includes/DefinePOClass.php');
include('includes/session.inc');
include('includes/SQL_CommonFunctions.inc');
include('includes/DefineSuppTransClass.php');
include('includes/function_lib.php');
 //echo $_REQUEST['action'];
?>
<!-------------------------INCLUDE ROOT FILES---------------------START HERE--------------------------->
<link href="css/tender_project.css" rel="stylesheet" type="text/css" />
<script> 
 
function ExitWindow()
{
	opener.window.location="index.php?route=PMS/Transcations/boq_template_entry&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>";self.close();
}
</script>
<!--<link href="css/professional/default.css" rel="stylesheet" type="text/css" />-->

 <h1 align="center">Search BOQ </h1>
 <form action="" method="post" >
<table width="60%" align="center" border="0" cellpadding="3" cellspacing="0">
  <tr>
  <td class="tabledata">Search By Category</td>
  <td><select name="group_title " id="group_title "   >
  	<option value="">Select Group</option>
            <?php 
		 $store_sql ="SELECT * FROM master_boq where parentid=0";
		$store_result = DB_query($store_sql,$db);
		while($store_row = DB_fetch_array($store_result))
		{
			$p='';
			if($store_row['id'] == $_REQUEST['group_title '])	
			$p="selected";
		
		?>
            <option value="<?php echo $store_row['id']; ?>" <?php echo $p;?>><?php echo $store_row['group_title ']; ?></option>
            <?php } ?>
</select>  </td>
  </tr>
   <tr> <td colspan="2"><input name="Search" type="submit" value="Search"  /></td>
  </tr>
</table>
 </form>
<?php 
if($_REQUEST['Select'] != '')
{
//***************CREATE SESSION WHEN ACTION IS ADDNEW******START HERE*************************************s
$editarray=array();
if($_REQUEST['action']=='Addnew'){
	$item_array=$_REQUEST['row_id'];
	$_SESSION['ACGBOQ']=$item_array;
 	$itemlist=implode("#",$_SESSION['ACGBOQ']);
	$_SESSION['ACGBOQ']=$itemlist;
	}
	
//***************CREATE SESSION WHEN ACTION IS ADDNEW******END HERE****************************************
	
	
	
//***************CREATE SESSION WHEN ACTION IS EDIT*********START HERE*************************************
	if($_REQUEST['action']=='Edit')
	{
	//echo "Hello";
	$itemchek=DB_query("select boqid from boq_entry_details where pid='".$_REQUEST['id']."'",$db);
	while($itemchekRow=DB_fetch_array($itemchek))
	{
		$editarray[]=$itemchekRow['boqid'];
	}
	///echo "<pre>";
	///print_r($editarray);
	///print_r($_REQUEST['row_id']);
	if(array_intersect($editarray,$_REQUEST['row_id']))//*********CHECK FOR ITEM ALREADY EXIST*************/
	{ ?>
	<script type="text/javascript" language="javascript">
		alert("This Item Is Already Exist");
	</script>
<?php } else {
$item_array1=$_REQUEST['row_id'];
	$_SESSION['ACGBOQEDIT']=$item_array1;
 	$itemlist1=implode("#",$_SESSION['ACGBOQEDIT']);
$_SESSION['ACGBOQEDIT']=$itemlist1;
}

//***************CREATE SESSION WHEN ACTION IS EDIT***********END HERE*********************************************

}

//***********************************CANCEL SESSION*************START HERE******************************************

if($_REQUEST['Reset']!='')
{
	unset($_SESSION['ACGBOQ']);
 	unset($_SESSION['IntermediateList']);
}


//***********************************CANCEL SESSION*************END HERE********************************************
?>

<!-----------------------------REDIRECT ON boq_template_entry PAGE WHEN ACTION IS ADD NEW------START HERE---------------->
<?php if($_REQUEST['action']=='Addnew')  {?>
<script language="javascript">
opener.window.location="index.php?route=PMS/Transcations/boq_template_entry&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&action=<?php echo $_REQUEST['action']?>&storeses=1";self.close();
</script>

<!-----------------------------REDIRECT ON boq_template_entry PAGE WHEN ACTION IS ADD NEW------END HERE---------------->


<!-----------------------------REDIRECT ON boq_template_entry PAGE WHEN ACTION IS EDIT------START HERE---------------->

<?php } else if($_REQUEST['action']=='Edit') {?>


<script language="javascript">
opener.window.location="index.php?route=PMS/Transcations/boq_template_entry&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&action=<?php echo $_REQUEST['action']?>&id=<?php echo $_REQUEST['id']; ?>";self.close();
</script>

<!-----------------------------REDIRECT ON boq_template_entry PAGE WHEN ACTION IS EDIT------END HERE---------------->


<?php } ?>
<?php 
}
?>
<form name="form1" action="" method="post">
<table width="100%" border="0">
	<tr><td><input style="margin:0px 0px 10px 0px;" type="submit" name="Select" id="Select" value="Add To List">
	<input style="margin:0px 0px 10px 0px;" type="submit" name="Reset" id="Reset" value="Reset"></td>
		<td><div align="right"><input style="margin:0px 0px 10px 0px;" type="button" name="Exit" id="Exit" value="Exit" onclick="ExitWindow()" ></div>
		</td>
	</tr></table>
<?php
$i=0;
  	if($i%2==0)
	{$bg="#CCCCCC";}
	else
	$bg="#C8BECB";
//echo "Select * from master_boq where 1=1";
 	$sql=DB_query("Select * from master_boq where 1=1",$db); 	
	?>
	<div style="overflow: scroll; height: 300px" id="ItemListDiv">
<table width="100%" border="1" cellspacing="0" cellpadding="3" style="font-family:Arial, Helvetica, sans-serif; font-size:12px;">
	 <tr>
	<td class="tabledata">Select</td>
  	<td class="tabledata">BOQ Group.</td>
    <td class="tabledata">BOQ Code.</td>
	<td class="tabledata">BOQ Qty.</td>
    <td class="tabledata">BOQ Rate.</td>
    <td class="tabledata">BOQ Amt.</td>
    <td class="tabledata">Activity</td>
        </tr>
	<?php 
	if(isset($_SESSION['ACGBOQ']))
	{
		$y=explode("#",$_SESSION['ACGBOQ']);
	}
	if(DB_num_rows($sql)>0)
	{
		while($myrow=DB_fetch_array($sql))
	  	{ 	
	  		$parameter=$myrow['id'];
			$c='';
			for($x=0;$x<count($y);$x++)
			{
				if($parameter==$y[$x])
				$c="checked";
			}
  ?>
   <tr>
      <td style="width:120px;">
	 <?php  if($myrow['parentid']!=0){?>
	  <input type="checkbox" name="row_id[]" id="row_id_<?php echo $i;?>" value="<?php echo $parameter;?>"	<?php echo $c;?> />
	  <?php }?>
	  </td>	  
	   <td width="14%"><?php  
 if($myrow['parentid']==0)
	echo  $s->GetFieldValue('master_boq',"id='".$myrow['id']."'" ,'group_title');
	else
		echo  $s->GetFieldValue('master_boq',"id='".$myrow['parentid']."'" ,'group_title');
	?></td>
<?php  if($myrow['parentid']!=0) {?>	
<td style="width:450px;"><?php 
   echo $myrow['group_title']?>
   </td>
   
   <?php }?>
    <?php if($myrow['parentid']!=0) {?>
      <td style="width:120px;"><?php echo $myrow['rate'];?></td>
      <td style="width:120px;"><?php echo $myrow['qty'];?></td>
	  <td style="width:120px;"><?php echo $myrow['unit'];?></td>
	  <td style="width:120px;"><?php echo $myrow['amount'];?></td>
      <?php } ?>
    </tr>
<?php $i++;
		} 
}?>
<input type="hidden" name="row_sount" id="row_count" value="<?php echo $i;?>">
</table></div>
 </form>

