<?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']; 
	 
	 
	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);	
 			if(DB_num_rows($rsCate)>0)
			{
				while($rowCate = DB_fetch_array($rsCate))
				{
				$px='';
 //if($rowCate['parentid']==$PcateID)
 //$px="selected"; ?>
 
 <option value="<?php echo $rowCate['id'];?>" <?php echo $px ?>><?php echo $dashVal;?>
 <?php echo "-".$rowCate['deptname'];?> </option>
  					
				 
 				 
				
					 
					<?php 
					  CategoryShow($companyid,$rowCate['id'], $dashVal);
				}
			}
		} 
		
	 
		
		$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')
{ 
  ?>	
  
  <table width="100%" border="0">
  <tr>
		<th><strong>Dealer</strong></th>
		<td colspan="2"> 		
		<select name="dealer" id='dealer'  style="width:100%" onchange="showbranch(this.value)">
           <option value="0">Select</option>
 		<?php //CompanyId='".$_SESSION['ACGCompanyId']."'
		  $query=DB_query("select * from dbl_dealer where company='".$q."'",$db);
		  while($row=DB_fetch_array($query))
		  {
 		  	$p='';
			if($row['id']==$dealer)
			{
			   $p="selected";
			}
 		 ?>
		<option value="<?php echo $row['id'] ?>" <?php echo $p; ?>><?php echo $row['dealer_name'] ?></option>
		<?php } ?>
		</select>		 </td>
		</tr>
  <tr>
	<th width="50%"><strong>Heirarchy</strong></th>
	<td>
	
			<div style="overflow:auto; height:150px; width:100%; border:1px solid; background-color:#FFFFFF" >
            <select name="heirarchy" id="heirarchy"  multiple="multiple" style="height:200px; width:100%">
 			<?php 
			$dashVal = "&nbsp;&nbsp;&nbsp;";
			
			 $query_comprole=DB_query("select * from deptmaster_hierarchy where parentid=0 and companyid='".$q."'",$db);
 			  while($row_comprole=DB_fetch_array($query_comprole))
			  {			  
			  ?>
		<option value="<?php echo $row_comprole['id']; ?>" selected="selected"><?php echo $row_comprole['deptname']; ?></option>
  			<?php  CategoryShow($row_comprole['CompanyId'], $row_comprole['id'], $dashVal);	  }	 ?>
	     </select>
		
		</div></td></tr>   
        <tr>
		<th width="50%"><strong>Roles <br /></strong></th>
		<td colspan="2" width="50%"> 
		<?php 
		$pcode= $rolepid;
		function CategoryShow1($pcode, $PcateID, $dashVal)
		{
			global $db;
			$dashVal = $dashVal . "&nbsp;&nbsp;&nbsp;&nbsp;";
			$sqlCate = "select * from securityroles  where  rolepid  = '".$PcateID."'";
			$rsCate  = DB_query($sqlCate,$db);	
			 
			if(DB_num_rows($rsCate)>0)
			{
				while($rowCate = DB_fetch_array($rsCate))
				{
					$sqlCateSel = "select * from securityroles where rolepid =".$rowCate['rolepid']." ";
					$rsCateSel	= DB_query($sqlCateSel,$db);
					$px='';
					 if($rowCate['secroleid']==$pcode)
					 $px="selected";
			?>
					<option value="<?php echo $rowCate['secroleid'];?>" <?php echo $px ?>><?php echo $dashVal;?>
					 <?php echo $rowCate['role_name'];?> </option>
		   <?php			
					   CategoryShow1( $pcode,$rowCate['secroleid'], $dashVal);
				}
			}
		} 
		
		$dashVal = "&nbsp;&nbsp;&nbsp;";
		$query=DB_query("select * from securityroles where rolepid=0 and companyid ='".$q."'",$db);
		?>
		   <strong>(Select only one Role)</strong>
		   <div id='txtCompanyRole'>
		 <select name="rolepid" multiple="multiple" style="height:200px; width:100%">
            <?php
		if(DB_num_rows($query)>0){
		 
		  while($row=DB_fetch_array($query))
		  {		  
		  	$p='';
			if($row['secroleid']==$rolepid)
			{
			   $p="selected";
			}
		 ?>
            <option value="<?php echo $row['secroleid'] ?>" <?php echo $p; ?> ><?php echo $row['role_name'] ?></option>
            <?php 
		   CategoryShow1($rolepid, $row['secroleid'], $dashVal);
		}} ?>
          </select>
		</div></td></tr>  
    
  
  
  
  
  
</table>

  	
		 
<?php  } ?>