<script language="javascript" type="text/javascript">
function checkAll(menu) {
	var chk_sub = document.getElementsByName('chk_sub[]');
	if(menu.checked == true) {
		for(var i=0;i<chk_sub.length;i++) {
			if(chk_sub[i].id.substring(0,chk_sub[i].id.indexOf('_')) == menu.name){chk_sub[i].checked = true;}
		}
	} else {
		for(var i=0;i<chk_sub.length;i++) {
			if(chk_sub[i].id.substring(0,chk_sub[i].id.indexOf('_')) == menu.name){chk_sub[i].checked = false;}
		}	
	}
}
function unChkParent(elem){
	document.getElementsByName(elem.id.substring(0,elem.id.indexOf('_')))[0].checked = false;
}
</script>
<div class="page-content-wrapper">
                <div class="page-content">
                    <div class="page-bar">
                        <div class="page-title-breadcrumb">
                            <div class=" pull-left">
                                <div class="page-title">Admin Users</div>
                            </div>
                            <ol class="breadcrumb page-breadcrumb pull-right">
                                <li><i class="fa fa-home"></i>&nbsp;<a class="parent-item" href="index.html">Home</a>&nbsp;<i class="fa fa-angle-right"></i>
                                </li>
                                <li><a class="parent-item" href="">Manage Admin</a>&nbsp;<i class="fa fa-angle-right"></i></li><li class="active">Permission</li>
                            </ol>
                        </div>
                    </div>
<div class="row">
                        <div class="col-md-12 col-sm-12">
                            <div class="card card-box">
                                <div class="card-head">
                                    <header>Page Permission : <?php echo $resAccess1['ad_username']; ?></header>                                    
                                </div>
                                <div class="card-body" id="bar-parent1">
                                	<?php if(isset($error) && $error!='') { ?> 
                                	<div class="alert alert-danger"><?php echo $error; ?></div>
                                	<?php } else if(isset($success) && $success!=''){ ?>                                		
                                		<div class="alert alert-success"><?php echo $success; ?></div>
                                	<?php } else if(isset($_REQUEST['success'])){ ?>                                		
                                		<div class="alert alert-success"><?php echo $_REQUEST['success']; ?></div>
                                	<?php } ?>
                                                                      
						            
						            <form action="" method="post" name="form1" class="form label-inline">
						            	<div style="max-width:450px;margin-left:auto;margin-right:auto;" class="form-body"> 							              		
						            		<?php 
												$execMainMenu = mysqli_query($con, "SELECT DISTINCT(parent) AS parent FROM tbl_access_control WHERE menustatus ='Active' ORDER BY menu_order");
												while($resMainMenu = mysqli_fetch_assoc($execMainMenu)) {	?>							                
							                	<div class="form-group row">
	                                                <label class="control-label col-md-6"><b><?php echo $resMainMenu['parent']; ?></b></label>	                                                
	                                            </div>							                
							                <?php
												$execSubMenu = mysqli_query($con, "SELECT * FROM  tbl_access_control WHERE parent='".$resMainMenu['parent']."' AND  menustatus ='Active' ORDER BY menu_order");
												while($resSubMenu = mysqli_fetch_assoc($execSubMenu)) { ?>													
		                                            <div style="margin-left:30px;" class="checkbox checkbox-aqua">	                                                    
	                                                    <input type="checkbox" name="chk_sub[]"  id="<?php echo $resMainMenu['parent'].'_'.$resSubMenu['id']; ?>" value="<?php echo $resSubMenu['id']; ?>" onclick="unChkParent(this)" <?php if(in_array($resSubMenu['id'],$accessArray1)){echo ' checked="checked" ';} ?> />
	                                                    <label for="<?php echo $resMainMenu['parent'].'_'.$resSubMenu['id']; ?>">
	                                                        <?php echo $resSubMenu['menu']; ?>
	                                                    </label>
	                                                </div>							                
							                <?php
												}
											}
										    ?>
										    <div style="margin-top: 20px;" class="offset-md-3 col-md-9">	                                            	
	                                           <button type="submit" name="Submit" class="btn btn-info">Submit</button>	                                            		                                          	
	                                        </div>
										</div>    										
						            </form>
      
                                </div>
                            </div>
                        </div>
                    </div>
	</div>
</div>
