<?php
session_name('CAKEPHP'); session_start();
$PageSecurity = 11;
//echo $_SERVER['QUERY_STRING'];exit;
include('includes/SQL_CommonFunctions.inc');
include('includes/function_lib.php');
include('includes/Class_www_users.php');
include('includes/Class_Emp.php');
include('includes/session.inc');
$q=$_GET['q']; 
//$pcode= $rolepid;
	function CategoryShow($companyid, $PcateID,$dashVal)
	{
	global $db;
	$dashVal = $dashVal . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	$s=new db_query();
	$sqlCate = "select * from deptmaster_hierarchy  where  parentid  = '".$PcateID."' and companyid='".$companyid."'";
	$rsCate  = DB_query($sqlCate,$db);	
	$num=DB_num_rows($rsCate);
	if(DB_num_rows($rsCate)>0)
	{
	while($rowCate = DB_fetch_array($rsCate))
	{
	$px='';
 	$data5.="<option value='".$rowCate['id']."'>".$dashVal."-".$rowCate['deptname']."</option>";
	$data5.=CategoryShow($companyid,$rowCate['id'], $dashVal);	
	//CategoryShow($companyid,$rowCate['id'], $dashVal);
	}
	return  $data5;
	}
	} 
		
		$dashVal = "&nbsp;&nbsp;&nbsp;";
	?>

<?php if($_REQUEST['type']=='')
	  {
		 	$sql="Select prefix from locations Where loccode ='".$q."'";
 			$result = DB_query($sql,$db);
 			$myrow=DB_Fetch_array($result);
			
			$condition="1=1";	 
			$lastids=$s->GetLastRecord('invoice',  $condition,'invoice_id');
			$newid=$lastids+1;
?> <input type="text" name="invoice_code" id="invoice_code" value="<?php echo $_GET['q'];?>"  style="width:50px;" tabindex="2" readonly="true" size="5"/> - In - <input type="text" name="invoice_number"  id="invoice_number" size="5"   tabindex="7"  style="width:50px;" value="<?php echo  $newid; ?>">
<?php } 
if($_REQUEST['type']=='Companyusers')
{ 
	$data1=" ";
	$dashVal = "&nbsp;&nbsp;&nbsp;";
	$query_comprole=DB_query("select * from deptmaster_hierarchy where parentid=0 and companyid='".$q."'",$db);
	if(DB_num_rows($query_comprole)>0)
	{
		while($row_comprole=DB_fetch_array($query_comprole))
		{
			$data1.="<option value='".$row_comprole['id']."'>".$row_comprole['deptname']."</option>";
			$data1.=CategoryShow($row_comprole['CompanyId'], $row_comprole['id'],$dashVal);
		}
	}
	
	
	 
	
	
	
	$data2="";
	$ClientSQL=DB_query(" Select id , site,shift_for,shift_category  from shift_master where  CompanyId='".$q."' ",$db);		
	$data2.="<select name='emp_shift' style='width:200px;' >";
	$data2.="<option value='000'>--Select Shift--</option>";
	while($Row=DB_fetch_array($ClientSQL))
	{
	$p='';
	if($Row['id']==$seldata)
	$p='selected';
	$locname=DB_fetch_array(DB_query("Select locationname from locations where loccode='".$Row['site']."'",$db));
	
	$data2.="<option value='". $Row['id']."' $p >".$locname['locationname'].' - '.$Row['shift_for']."(".$Row['shift_category'].")"."</option>";
	}
	$data2.="</select>";
	
	
	
	
	$data3="";
	
	
	$data3.="<select name='department' id='department' onchange='GetDesginationUser(this.value)'  style='width:200px;'>";
	$data3.="<option value='000'>---Select---</option>";
	$qdepart=DB_query("select * from deptmaster where CompanyId='".$q."'",$db); 
	while($rsdepart=DB_fetch_array($qdepart)){
	$data3.="<option value='".$rsdepart['id']."' ".($department==$rsdepart['id']?'selected':'').">".$rsdepart['deptname']."</option>";
}
	$data3.="</select>";
	
	
	
	
	
		$data4="";
		$query=DB_query("select * from securityroles where rolepid=0 and companyid ='".$q."'",$db);
		$data4.="<strong>(Select only one Role)</strong>";
		$data4.="<select name='rolepid' id='rolepid' multiple='multiple' style='height:135px; width:200px;'>";
		if(DB_num_rows($query)>0){
		  while($row=DB_fetch_array($query))
		  {		  
		  	$p='';
			if($row['secroleid']==$rolepid)
			{
			   $p="selected";
			}
            $data4.="<option value='".$row['secroleid']."' ".$p.">".$row['role_name']."</option>";
		}} 
          $data4.="</select>";
		  
		  
		  
		$data5="";
		$c3=0;
		$query=DB_query("select * from locations where mst_companyid='".$q."'",$db);
		while($row=DB_Fetch_array($query))
		{
		$data5.="<input type='checkbox' name='mst_site[".$c3."]' id='mst_site_".$c3."' value='".$row['loccode']."' 
		onclick='getZones(this.value)'/>";
		$data5.=$row['loccode']." - ".$row['locationname'].'<br />';
		
		
		$c3++; } 
		$data5.="<input type='hidden' name='' id='cnt' value='".$c3."' />";
	
	
	
	
	echo $data=$data1."__".$data2."__".$data3."__".$data4."__".$data5;

} ?>