 




    <div class="row">
        <div class="box col-md-12">
            <div class="box-inner">
                <div class="box-header well" data-original-title="">
                    <h2><i class="glyphicon glyphicon-ban-circle"></i> Privilages</h2>

                    <div class="box-icon">
                        <a href="#" class="btn btn-setting btn-round btn-default"><i
                                class="glyphicon glyphicon-cog"></i></a>
                        <a href="#" class="btn btn-minimize btn-round btn-default"><i
                                class="glyphicon glyphicon-chevron-up"></i></a>
                        <a href="#" class="btn btn-close btn-round btn-default"><i
                                class="glyphicon glyphicon-remove"></i></a>
                    </div>
                </div>
                <div class="box-content">

<?php   if(isset($_REQUEST['opt']) && $_REQUEST['opt']!=''){
	
	
	
	 $select_section=mysqli_query($connect,"select * from priv_section");
	
	while($ro_section=mysqli_fetch_array($select_section)){ 
	//echo($ro_section["p_s_name"]." - ".$_REQUEST['secid_'.$ro_section["p_s_name"]]."<br>");
	
	 $select_priv=mysqli_query($connect,"select * from users_priv
	  where `u_p_sectionid`='".$_REQUEST['secid_'.$ro_section["p_s_name"]]."'
	 and `u_p_roleid`='".$_REQUEST['role']."'");
	
	
	
	if(mysqli_num_rows($select_priv)==0){
		$update="insert into";
		$updateWhere="";
		}else{
			$update="update ";
		$updateWhere="  where `u_p_sectionid`='".$_REQUEST['secid_'.$ro_section["p_s_name"]]."'
	 and `u_p_roleid`='".$_REQUEST['role']."'";
			}
			
	if($_REQUEST['secid_'.$ro_section["p_s_name"]]!=''){
	$insert=mysqli_query($connect,$update." users_priv set 
	`u_p_roleid`='".$_REQUEST['role']."',
	 `u_p_view`='".$_REQUEST['view_'.$ro_section["p_s_name"]]."',
	   `u_p_up`='".$_REQUEST['up_'.$ro_section["p_s_name"]]."',
	   `u_p_del`='".$_REQUEST['del_'.$ro_section["p_s_name"]]."',
	    `u_p_add`='".$_REQUEST['add_'.$ro_section["p_s_name"]]."',
		 
		  `u_p_sectionid`='".$_REQUEST['secid_'.$ro_section["p_s_name"]]."' ".$updateWhere
		  
		  );
	 
	 
	 
	 
	 
	 
	}
	//echo($updateWhere);
	
	}
	
	
}?>

<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<table width="500" border="0" align="center" cellpadding="0" cellspacing="0" class="table table-striped table-bordered bootstrap-datatable datatable responsive showtable" >
  <tr>
    <td>Role</td>
    <td>Add priv</td>
  </tr>
  
 <?php   $select_role=mysqli_query($connect,"select * from roles");
	
	while($ro_role=mysqli_fetch_array($select_role)){ 
	?>
  <tr>
    <td><?php echo($ro_role["roles_name"]); ?></td>
    <td><a href="index.php?page=privilages&role=<?php echo($ro_role["roles_id"]); ?>">Add Priv</a></td>
  </tr>
  <?php  }?>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>

<?php  if(isset($_REQUEST['role']) && $_REQUEST['role']!=''){ ?>
<form name="form1" method="post" action="">
<input type="hidden" name="role" value="<?php  echo($_REQUEST['role']); ?>">
<input type="hidden" name="opt" value="1">
  <table width="500" border="0" align="center" cellpadding="0" cellspacing="0" class="table table-striped table-bordered bootstrap-datatable datatable responsive showtable">
    <tr>
      <td>Section</td>
      <td>View</td>
      <td>Add</td>
      <td>Update</td>
      <td>delete</td>
      <!--<td>View All</td>-->
    </tr>
  
    
    <?php  
	
	
	 $select_section=mysqli_query($connect,"select * from priv_section");
	
	while($ro_section=mysqli_fetch_array($select_section)){ 
	
	
	
	 $select_priv=mysqli_query($connect,"select * from users_priv
	  where `u_p_sectionid`='".$ro_section["p_s_id"]."'
	 and `u_p_roleid`='".$_REQUEST['role']."'");
	 
	$rowSecPriv=mysqli_fetch_array($select_priv);
	?>
      <tr>
      <td><?php echo($ro_section["p_s_name"]); ?></td>
      <td><input type="hidden" name="secid_<?php echo($ro_section["p_s_name"]); ?>" id="secid_<?php echo($ro_section["p_s_name"]); ?>" value="<?php echo($ro_section["p_s_id"]); ?>" >
      
      <input type="checkbox" name="view_<?php echo($ro_section["p_s_name"]); ?>" id="view_<?php echo($ro_section["p_s_name"]); ?>" value="1" <?php    if($rowSecPriv['u_p_view']==1){ ?> checked="checked"<?php } ?>></td>
      <td><input type="checkbox" name="add_<?php echo($ro_section["p_s_name"]); ?>" id="add_<?php echo($ro_section["p_s_name"]); ?>" value="1"  <?php    if($rowSecPriv['u_p_add']==1){ ?> checked="checked"<?php } ?>></td>
      <td><input type="checkbox" name="up_<?php echo($ro_section["p_s_name"]); ?>" id="up_<?php echo($ro_section["p_s_name"]); ?>" value="1"  <?php    if($rowSecPriv['u_p_up']==1){ ?> checked="checked"<?php } ?>></td>
      <td><input type="checkbox" name="del_<?php echo($ro_section["p_s_name"]); ?>" id="del_<?php echo($ro_section["p_s_name"]); ?>" value="1"  <?php    if($rowSecPriv['u_p_del']==1){ ?> checked="checked"<?php } ?>></td>
  
    </tr>
    <?php  } ?>
    
    
    
   
    <tr>
      <td colspan="6" align="center"><input type="submit" name="button" id="button" value="Submit"></td>
    </tr>
  </table>
</form>
<p>&nbsp;</p>
<?php  } ?>


 </div>
            </div>
        </div>
        <!--/span-->
    </div><!--/row-->