<?php include("parent/callMe.php"); ?>
<?php  include("sessioncheck.php"); ?>
<?php
 
   $m->where("status", '0');
   $m->where("branch_id", $_SESSION['branch']);
   $m->where("user_id", $_REQUEST['id']);
   $m->orderBy("user_id", 'desc');
   $WorkAssignListings = $m->get("edu_user_config");

   $m->where("designation_id", $WorkAssignListings[0]['designation_id']);
   $designation=$m->get("eduportal_designation_config");


   $m->where("user_id", $_REQUEST['id']);
   $m->where("branch_id", $_SESSION['branch']);
   $privileges = $m->get("users_privilege_detail");
 
     ?>


<!DOCTYPE html>
<html lang="en">
  <head>
    
    <title>User Access | EduPortal</title>
    <?php include('RootMe/css_links.php');?>
 
<style>

.tdStyle{border-bottom:1px solid lightgray;}
.thStyle{background-color:#00AFEF;color:white;}

</style>  

<style>
      input.larger {
        width: 20px;
        height: 20px;
      }


@media only screen and (max-width: 768px) {

    /* For mobile phones: */

    .accessFontSize{
        font-size:  15px;
    }    

    .labelFontSize{
        font-size:  14px;
    } 

}


@media (min-width:801px)  { /* tablet, landscape iPad, lo-res laptops ands desktops */ 

    .accessFontSize{
        
        font-size:  22px;
       
    }

    .labelFontSize{
        font-size:  16px;
    }
      
}

</style>
  </head>
  <body class="nav-md">
    <div class="container body">
      <div class="main_container">
        <div class="col-md-3 left_col">
     
            <?php include('RootMe/sidebar.php');?>

              <?php include('RootMe/header.php');?>
     
        <!-- page content -->
          <div class="right_col" role="main" >

          <div class="" style="background-color: white;    padding: 2%">
           
  <section class="add_sub_agent" id="table_sub_agent">
  <div class="container">

 <div class="" style="margin-top:10px;">
 
    </div>

 <div>
  <h3> <?php echo $WorkAssignListings[0]['user_fname'].' '.$designation[0]['designation_name'] ?>
    
  </h3>
  
 </div>
 <br>


<div style="overflow-x:auto;">

<form action="<?php echo DOMAIN.AgentDirectory;?>parent/InsertMe1.php" method="post" enctype="multipart/form-data">

 <input type="hidden" name="action" value="UpdateUserAccess">

 <label class="container1">Check All<input  type="checkbox" class="checkAll"/><span class="checkmark"></span></label>
<input type="submit" class="btn btn-success pull-right" value="Save Access" />
<a href="user_access.php" class="btn btn-primary" style="float: right;">Back to users</a>
<table class="table table-striped table-bordered" style="width:100%;font-size: 16px; font-weight: bold;">
        <thead>
            <tr>

                <th style="text-align: center;" width="5%">S.No</th>
                <th width="15%">Modules</th>               
                <th width="70%">Pages Access</th>
                
            </tr>
        </thead>
        <tbody>

     <?php 
      

      $qr="SELECT * FROM eduportal_modules_detail as modu, eduportal_school_modules as schl WHERE modu.modules_id=schl.module_id and schl.branch_id='$branch' ORDER BY order_no ASC ";
        //echo $qr;
       $modules = $m->query($qr);

     $count=1;
      foreach($modules as $module)
      { 
        
      ?>
      <input type="hidden" name="user_id" value="<?php echo $WorkAssignListings[0]['user_id'];?>" />
      <input type="hidden" name="module[]" value="<?php echo $module['modules_id'];?>" />

  <tr>
        
     <td style="text-align: center;"> <?php echo $count; $count++; ?>  </td>
      
      <td> <?php echo $module['modules_name'];?> </td>
      
           <td> 
                 <?php 
    
                  $m->where("module_id", $module['modules_id']);
                  $user_pages = $m->get("eduportal_modules_pages_detail");

                  foreach($user_pages as $user_page) {

                  $m->where("user_id", $_REQUEST['id']);
                  $m->where ("branch_id", $_SESSION['branch']);
                  $m->where("page_id", $user_page['page_id']);
                  $access = $m->get("users_privilege_detail");

                    if(count($privileges)>0){

                    $m->where("user_id", $_REQUEST['id']);
                    $m->where("module_id", $module['modules_id']);
                    $m->where ("branch_id", $_SESSION['branch']);
                    $m->where("page_id", $user_page['page_id']);
                    $values = $m->get("users_privilege_detail");

                  } else {

                    $m->where("package_id", $brid[0]['package_id']);
                    $m->where("designation_id", $_REQUEST['desigID']);
                    $m->where("page_id", $user_page['page_id']);
                    $values = $m->get("eduportal_designation_access");

                  }


                    if(count($values)>0){
                      
                      ?>
                 <div class="col-md-12">

                  <div class="col-md-8 col-sm-12 col-xs-12" style="float: left;">

                  <label class="container1 accessFontSize">
                    <input type="checkbox" name="pages<?php echo $module['modules_id'];?>[]" checked value="<?php echo $user_page['page_id'];?>" />
                    <?php echo " ".$user_page['page_title']." ";?><span class="checkmark"></span>
                    
                  </label>
                  </div>

                  <div class="col-md-4 col-sm-12 col-xs-12" style="float: left;">

                  <?php if ($user_page['edit_access']!=NULL) { ?>
                    
                    <input type="checkbox" class="larger" id="edit" <?php if ($access[0]['edit_access']!=NULL) { echo "checked"; }?> name="edit<?php echo $user_page['page_id'];?>" value="edit">
                    <label for="edit" class="labelFontSize">&nbsp;&nbsp; Edit</label>

                  <?php } ?>
                  

                <?php if ($user_page['delete_access']!=NULL) { ?>

                &nbsp;&nbsp;<input type="checkbox" class="larger" id="delete" <?php if ($access[0]['delete_access']!=NULL) { echo "checked"; }?> name="delete<?php echo $user_page['page_id'];?>" value="delete">
                    <label for="delete" class="labelFontSize">&nbsp;&nbsp; Delete</label>

                <?php } ?>
                </div>

                </div>
                    <?php  }  else { ?>

                    <div class="col-md-12">

                    <div class="col-md-8 col-sm-12 col-xs-12" style="float: left;">

                    <label class="container1 accessFontSize">
                    <input type="checkbox" name="pages<?php echo $module['modules_id'];?>[]"  value="<?php echo $user_page['page_id'];?>" />
                    <?php echo " ".$user_page['page_title']." ";?><span class="checkmark"></span>
                    </label> 

                    </div>

                    <div class="col-md-4 col-sm-12 col-xs-12" style="float: left;">

                    <?php if ($user_page['edit_access']!=NULL) { ?>
                    
                    <input type="checkbox" class="larger" id="edit" name="edit<?php echo $user_page['page_id'];?>" value="edit">
                    <label for="edit" class="labelFontSize">&nbsp;&nbsp; Edit</label>

                  <?php } ?>
                  

                <?php if ($user_page['delete_access']!=NULL) { ?>

                &nbsp;&nbsp;<input type="checkbox" class="larger" id="delete" name="delete<?php echo $user_page['page_id'];?>" value="delete">
                    <label for="delete" class="labelFontSize">&nbsp;&nbsp; Delete</label>
                    
                <?php } ?>

                </div>
                </div>
                    <?php 
                      } // ending else
                      
                    }
                  ?> 
                      
                     
                    


         </td>          
  </tr>

              <?php
      } ?>
    
        </tbody>
        
    </table>

     

</form>

  </div>

    <br><br>


  </div>
  <div class="clearfix"></div>
</section>          
    

           
          </div>
        </div>

            </div>
          </div>
        </div>
        <!-- /page content -->
  

    
  <?php include('RootMe/js_linksscript.php');?>

  <script src="https://cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js"></script>
   <!-- jQuery -->
    <script src="js/ajax_functions.js"></script> 

 <script>

  $(".checkAll").change(function () {

      $("input:checkbox").prop('checked', $(this).prop("checked"));
  });


</script>

  </body>
</html>
