<?php
$PageSecurity = 11;
//echo $_SERVER['QUERY_STRING'];exit;
include('includes/SQL_CommonFunctions.inc');
include('includes/function_lib.php');
include('includes/session.inc');
?>

<?php 
		   $data1='';
		   	$q=$_GET['type'];
		 	$sql="select * from deptmaster  Where CompanyId ='".$q."'";
 			$result = DB_query($sql,$db);
 			while($myrow=DB_Fetch_array($result))
			{
			$data1.="<option value=".$myrow['id'].">".$myrow['deptname']."</option>";
			}
			
			$data2='';
			
			
			
			$pcode= $MainGroupId;
 	function CategoryShow($pcode, $PcateID, $dashVal)
	{
	    global $db;
		$dashVal = $dashVal . "-";
	    $sqlCate = "select * from deptmaster_hierarchy  where  parentid = '".$PcateID."'";
 		$rsCate  = DB_query($sqlCate,$db);	
 		if(DB_num_rows($rsCate)>0)
		{
			while($rowCate = DB_fetch_array($rsCate))
			{
				$sqlCateSel = "select * from deptmaster_hierarchy where id  =".$rowCate['id']." ";
				$rsCateSel	= DB_query($sqlCateSel,$db);
				$px='';
				 if($rowCate['id']==$pcode)
				 $px="selected";
 		
 				$data2.="<option value=".$rowCate['id']." ".$px.">".$dashVal.$rowCate['deptname']." </option>";
	   
				   CategoryShow($pcode,$rowCate['id'], $dashVal);
			}
		}
	} 
	$pcode=$_POST['parentid']  ;
   
   $data2.="<select name='parentid' id='parentid'>	  
  <option value='000'>----</option>";
  
	$dashVal = "&nbsp;&nbsp;&nbsp;";
	echo $sqlCate = "select * from  deptmaster_hierarchy  where    parentid   = 0 and CompanyId='".$q."'";
	$rsCate  = DB_query($sqlCate,$db);
	if(DB_num_rows($rsCate)>0)
	{
		while($rowCate =DB_fetch_array($rsCate))
		{
 				$sqlCateSel = "select * from deptmaster_hierarchy where parentid   =".$rowCate['id']." ";
				$rsCateSel	= DB_query($sqlCateSel,$db);
				$px='';
				 if($rowCate['id']==$pcode)
				 $px="selected";
			//echo $dashVal;	
		 
		$data2.="<option value=".$rowCate['id']."".$px.">".$rowCate['deptname']."</option>";
 				
			 CategoryShow($pcode, $rowCate['id'], $dashVal);
		}
	}
	
	echo $data=$data1."__".$data2;
	
	
?></select>
		 	 
			 
 