<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<link href="../css/main.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" src="../jscript/gen_validatorv4.js"  type="text/javascript" xml:space="preserve"></script>
<script type="text/javascript">
<!--
function MM_callJS(jsStr) { //v2.0
  return eval(jsStr)
}
//-->
</script>

<?php
include('../include/session.php');
$access_id = $_GET['user_select'];
$set = $_GET['set'];
$message='';
$home_page='';

$table_name = $_SESSION['db_prefix']."_users";
$user_query = "SELECT username, home_page FROM $table_name WHERE access_id = '". $access_id."'";
$user_result = execsql($user_query);
$user_num = mysql_num_rows($user_result);
if ($user_num==1) {
$username = mysql_result($user_result, 0, "username");
$home_page = mysql_result($user_result, 0, "home_page");
}
else {
	$username="";
}



$table_name = $_SESSION['db_prefix']."_permissions";
$perm_list_query = "SELECT page_name FROM $table_name WHERE access_id = '". $access_id." ' ";
$perm_list_result = execsql($perm_list_query);
$perm_list_num = mysql_num_rows($perm_list_result);


$table_name = $_SESSION['db_prefix']."_users";
$select_query = "SELECT access_id, username FROM $table_name ";
	$arrId = array ();
	$arrName = array ();
	$select_result = execsql($select_query);
	$select_num = mysql_num_rows($select_result);
	$a = 0;
	while ($a < $select_num) {
		$arrId[$a] = mysql_result($select_result, $a, "access_id");
		$arrName[$a] = mysql_result($select_result, $a, "username");
		$a++;
	}
	
$table_name = $_SESSION['db_prefix']."_permissions";
$page_query = "SELECT access_id, page_name FROM $table_name WHERE access_id ='".$access_id."' AND page_name LIKE 'HR%' ORDER BY page_name ";
	$arrId1 = array ();
	$arrName1 = array ();
	$page_result = execsql($page_query);
	$page_num = mysql_num_rows($page_result);
	$b = 0;
	while ($b < $page_num) {
		$arrId1[$b] = mysql_result($page_result, $b, "page_name");
		$arrName1[$b] = mysql_result($page_result, $b, "page_name");
		$b++;
	}
	
$table_name = $_SESSION['db_prefix']."_permissions";
$page_query = "SELECT access_id, page_name FROM $table_name WHERE access_id ='".$access_id."' AND page_name LIKE 'Sales%' ORDER BY page_name ";
	$arrId2 = array ();
	$arrName2 = array ();
	$page_result = execsql($page_query);
	$page_num = mysql_num_rows($page_result);
	$b = 0;
	while ($b < $page_num) {
		$arrId2[$b] = mysql_result($page_result, $b, "page_name");
		$arrName2[$b] = mysql_result($page_result, $b, "page_name");
		$b++;
	}
	
$table_name = $_SESSION['db_prefix']."_permissions";
$page_query = "SELECT access_id, page_name FROM $table_name WHERE access_id ='".$access_id."' AND page_name LIKE 'Production%' ORDER BY page_name ";
	$arrId3 = array ();
	$arrName3 = array ();
	$page_result = execsql($page_query);
	$page_num = mysql_num_rows($page_result);
	$b = 0;
	while ($b < $page_num) {
		$arrId3[$b] = mysql_result($page_result, $b, "page_name");
		$arrName3[$b] = mysql_result($page_result, $b, "page_name");
		$b++;
	}

$table_name = $_SESSION['db_prefix']."_permissions";
$page_query = "SELECT access_id, page_name FROM $table_name WHERE access_id ='".$access_id."' AND page_name LIKE 'Installation%' ORDER BY page_name ";
	$arrId4 = array ();
	$arrName4 = array ();
	$page_result = execsql($page_query);
	$page_num = mysql_num_rows($page_result);
	$b = 0;
	while ($b < $page_num) {
		$arrId4[$b] = mysql_result($page_result, $b, "page_name");
		$arrName4[$b] = mysql_result($page_result, $b, "page_name");
		$b++;
	}	
	
$table_name = $_SESSION['db_prefix']."_permissions";
$page_query = "SELECT access_id, page_name FROM $table_name WHERE access_id ='".$access_id."' AND page_name LIKE 'Service%' ORDER BY page_name ";
	$arrId5 = array ();
	$arrName5 = array ();
	$page_result = execsql($page_query);
	$page_num = mysql_num_rows($page_result);
	$b = 0;
	while ($b < $page_num) {
		$arrId5[$b] = mysql_result($page_result, $b, "page_name");
		$arrName5[$b] = mysql_result($page_result, $b, "page_name");
		$b++;
	}
	
	
$table_name = $_SESSION['db_prefix']."_permissions";
$page_query = "SELECT access_id, page_name FROM $table_name WHERE access_id ='".$access_id."' AND page_name LIKE 'Stores%' ORDER BY page_name ";
	$arrId6 = array ();
	$arrName6 = array ();
	$page_result = execsql($page_query);
	$page_num = mysql_num_rows($page_result);
	$b = 0;
	while ($b < $page_num) {
		$arrId6[$b] = mysql_result($page_result, $b, "page_name");
		$arrName6[$b] = mysql_result($page_result, $b, "page_name");
		$b++;
	}
	
$table_name = $_SESSION['db_prefix']."_permissions";
$page_query = "SELECT access_id, page_name FROM $table_name WHERE access_id ='".$access_id."' AND page_name LIKE 'Transport%' ORDER BY page_name ";
	$arrId7 = array ();
	$arrName7 = array ();
	$page_result = execsql($page_query);
	$page_num = mysql_num_rows($page_result);
	$b = 0;
	while ($b < $page_num) {
		$arrId7[$b] = mysql_result($page_result, $b, "page_name");
		$arrName7[$b] = mysql_result($page_result, $b, "page_name");
		$b++;
	}
	

	
	
$table_name = $_SESSION['db_prefix']."_permissions";
$page_query = "SELECT access_id, page_name FROM $table_name WHERE access_id ='".$access_id."' AND page_name LIKE 'AD%' ORDER BY page_name ";
	$arrId8 = array ();
	$arrName8 = array ();
	$page_result = execsql($page_query);
	$page_num = mysql_num_rows($page_result);
	$b = 0;
	while ($b < $page_num) {
		$arrId8[$b] = mysql_result($page_result, $b, "page_name");
		$arrName8[$b] = mysql_result($page_result, $b, "page_name");
		$b++;
	}

?>
</head>

<body  onload="<?php if ($set==5) { ?> document.getElementById('hidden_frame').style.display = 'none'; <?php } else { ?> document.getElementById('hidden_frame').style.display = 'block'; <?php } ?>" >
<?php
include ("../navigation/header.php");
$page_name = "AD-user list";
include ("../navigation/access.php");


if ($permission_num==1) {
	include ("../navigation/admin_sidebar.php");
?>

<div class="main_frame" style="height:auto;">
<div class="page_head_frame">
        <table width="809" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="385"><label class="label_page_head">View User Permissions</label></td>
            <td align="right">&nbsp;</td>
          </tr>
        </table>
      </div>
        <br /><br /><br /><br /><br />
<div class="page_middle_frame">
<div class="page_inside_frame">
<form name="form1" id="form1" action="view_permissions.php" method="get"> <label class="std">Select a user to view and set permissions&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
    <select name="user_select" class="selectbox120" onchange="window.location.href= this.form.user_select.options[this.form.user_select.selectedIndex].value" >
      <option value=""></option>
      <?php
        	for ($i = 0; $i < count($arrId); $i++) {
    		echo "<option value=view_permissions.php?user_select=".$arrId[$i]."&set=0>".$arrName[$i]."</option>";
	}
?>
    </select>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</form>
<script language="JavaScript" type="text/javascript" xml:space="preserve">
  var frmvalidator  = new Validator("form1");
  frmvalidator.EnableMsgsTogether();
  frmvalidator.addValidation("user_select","req","Please select user.");
</script>
</div>
<br />
<br />

<div class="page_inside_frame">
        
            
            <div class="lay_out_frame_medium" style="width:200px;">
              <label class="std">Permissions for:&nbsp;&nbsp;&nbsp;<font size="3"><font size="3"><font size="3"><font size="3"><?php echo $username ?></font></font></font></font></label></div>              
        
 <div class="lay_out_frame_medium" style="width:200px;">Home page: <label class="std">
                  <?php if ($home_page=="production") { echo "Production." ;} ?>
                  <?php if ($home_page=="stores") { echo "Stores." ;} ?> 
                  <?php if ($home_page=="sales") { echo "Sales." ;}  ?>
                  <?php if ($home_page=="transport") { echo "Transport." ; } ?>
                  <?php if ($home_page=="admin") { echo "Admin." ; } ?>
                  </label>
                  
                  <br />
              
           
               
    </div>
 <div class="spacer_frame" style="height:10px;"></div>          

     <div class="lay_out_frame_medium">
               <b> HR<br />
               </b>
               <select name="permission_select1" class="selectbox160" size="10" >
                 <?php
        	for ($j = 0; $j < count($arrId1); $j++) {
    		echo "<option value=" . "\"" . $arrId1[$j] . "\"" . ">" . $arrName1[$j] . "</option>";
	}
?>
               </select>
               <br /> 
          
      </div>     
    <div class="lay_out_frame_medium">
               <b> Sales<br />
               </b>
               <select name="permission_select2" class="selectbox160" size="10" >
                 <?php
        	for ($j = 0; $j < count($arrId2); $j++) {
    		echo "<option value=" . "\"" . $arrId2[$j] . "\"" . ">" . $arrName2[$j] . "</option>";
	}
?>
               </select>
               <br /> 
          
      </div>     
   <div class="lay_out_frame_medium">
               <b> Production<br />
               </b>
               <select name="permission_select3" class="selectbox160" size="10" >
                 <?php
        	for ($j = 0; $j < count($arrId3); $j++) {
    		echo "<option value=" . "\"" . $arrId3[$j] . "\"" . ">" . $arrName3[$j] . "</option>";
	}
?>
               </select>
               <br /> 
          
      </div>     
   <div class="lay_out_frame_medium">
               <b> Installation<br />
               </b>
               <select name="permission_select4" class="selectbox160" size="10" >
                 <?php
        	for ($j = 0; $j < count($arrId4); $j++) {
    		echo "<option value=" . "\"" . $arrId4[$j] . "\"" . ">" . $arrName4[$j] . "</option>";
	}
?>
               </select>
               <br /> 
          
      </div>     
   <div class="lay_out_frame_medium">
               <b> Service<br />
               </b>
               <select name="permission_select5" class="selectbox160" size="10" >
                 <?php
        	for ($j = 0; $j < count($arrId5); $j++) {
    		echo "<option value=" . "\"" . $arrId5[$j] . "\"" . ">" . $arrName5[$j] . "</option>";
	}
?>
               </select>
               <br /> 
          
      </div>     
   <div class="lay_out_frame_medium">
               <b> Stores<br />
               </b>
               <select name="permission_select6" class="selectbox160" size="10" >
                 <?php
        	for ($j = 0; $j < count($arrId6); $j++) {
    		echo "<option value=" . "\"" . $arrId6[$j] . "\"" . ">" . $arrName6[$j] . "</option>";
	}
?>
               </select>
               <br /> 
          
      </div>     
   <div class="lay_out_frame_medium">
               <b> Transport<br />
               </b>
               <select name="permission_select7" class="selectbox160" size="10" >
                 <?php
        	for ($j = 0; $j < count($arrId7); $j++) {
    		echo "<option value=" . "\"" . $arrId7[$j] . "\"" . ">" . $arrName7[$j] . "</option>";
	}
?>
               </select>
               <br /> 
          
      </div>     
   <div class="lay_out_frame_medium">
               <b> Admin<br />
               </b>
               <select name="permission_select8" class="selectbox160" size="10" >
                  <?php
        	for ($j = 0; $j < count($arrId8); $j++) {
    		echo "<option value=" . "\"" . $arrId8[$j] . "\"" . ">" . $arrName8[$j] . "</option>";
	}
?>
            </select>
               <br /> 
          
      </div>     
          
              
</div>   
        

</div>
</div>



<?php include ('../navigation/side_bar.php'); ?>

<?php } else {
$_SESSION['denied_return'] = "admin_module/admin_main.php?period=day";		
include ("../navigation/hr_sidebar.php");?>
	<body onload="accessdenied(); return false">
	</body>
<?php }
?>
</body>
</html>