<?php include "common/user_log.php";

if(isset($_GET['gid'])) { 
	$gid = htmlspecialchars(strip_tags(trim($_GET['gid'])), ENT_QUOTES, 'UTF-8');

} else {
	$gid = '';
}

?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>NWP Engineering Department</title>
<!-- Tell the browser to be responsive to screen width -->
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<!-- Bootstrap 3.3.5 -->
<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
<!-- Font Awesome -->
<link rel="stylesheet" href="dist/css/font-awesome.min.css">
<!-- Ionicons -->
<link rel="stylesheet" href="dist/css/ionicons.min.css">
<!-- daterange picker -->
<link rel="stylesheet" href="plugins/daterangepicker/daterangepicker-bs3.css">
<!-- iCheck for checkboxes and radio inputs -->
<link rel="stylesheet" href="plugins/iCheck/all.css">
<!-- Bootstrap Color Picker -->
<link rel="stylesheet" href="plugins/colorpicker/bootstrap-colorpicker.min.css">
<!-- Bootstrap time Picker -->
<link rel="stylesheet" href="plugins/timepicker/bootstrap-timepicker.min.css">
<!-- Select2 -->
<link rel="stylesheet" href="plugins/select2/select2.min.css">
<!-- Theme style -->
<link rel="stylesheet" href="dist/css/AdminLTE.min.css">
<!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
<link rel="stylesheet" href="dist/css/skins/_all-skins.min.css">
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
  <header class="main-header"> 
    <!-- Logo --> 
    <a href="home.php" class="logo"> 
    <!-- mini logo for sidebar mini 50x50 pixels --> 
    <span class="logo-mini"><img src="img/logo.png" width="100"></span> 
    <!-- logo for regular state and mobile devices --> 
    <span class="logo-lg"><b><img src="img/logo.png" width="100"></b></span> </a> 
    <!-- Header Navbar: style can be found in header.less -->
    <nav class="navbar navbar-static-top" role="navigation"> 
      <!-- Sidebar toggle button--> 
      <a href="#" class="sidebar-toggle" data-toggle="offcanvas" role="button"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="logo-lg"> &nbsp;&nbsp;<font face="Lucida Sans Unicode, Lucida Grande, sans-serif">NWP Engineering Department</font></span> </a>
      <div class="navbar-custom-menu">
        <ul class="nav navbar-nav">
          
          <!-- User Account: style can be found in dropdown.less -->
          <li class="dropdown user user-menu"> <a href="#" class="dropdown-toggle" data-toggle="dropdown"> <img src="dist/img/user2-160x160.png" class="user-image" alt="User Image"> <span class="hidden-xs"><?php echo $name; ?></span> </a>
            <ul class="dropdown-menu">
              <!-- User image -->
              <li class="user-header"> <img src="dist/img/user2-160x160.png" class="img-circle" alt="User Image">
                <p> NWP Engineering Department <small></small> </p>
              </li>
              <!-- Menu Body --> 
              
              <!-- Menu Footer-->
              <li class="user-footer">
                <div class="pull-left"> </div>
                <div class="pull-right"> <a href="distroy.php" class="btn btn-default btn-flat">Sign out</a> </div>
              </li>
            </ul>
          </li>
          <!-- Control Sidebar Toggle Button -->
          <li> <a href="#" data-toggle="control-sidebar"><i class="fa fa-gears"></i></a> </li>
        </ul>
      </div>
    </nav>
  </header>
  <!-- Left side column. contains the logo and sidebar -->
  <aside class="main-sidebar"> 
    <!-- sidebar: style can be found in sidebar.less -->
    <section class="sidebar"> 
      <!-- Sidebar user panel -->
      <?php include "common/sidebar.php"; ?>
    </section>
    
    <!-- /.sidebar --> 
  </aside>
  
  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper"> 
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1> Assign Group Policy </h1>
      <ol class="breadcrumb">
        <li><a href="home.php"><i class="fa fa-home"></i> Home</a></li>
      </ol>
    </section>
    <script>
function addFunc(str) {
    if (str == "") {
        document.getElementById("txtHint").innerHTML = "";
        return;
    } else {
        if (window.XMLHttpRequest) {
            // code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        } else {
            // code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
            }
        };
        xmlhttp.open("GET","function/prof_priv_conn.php?gid=<?php echo $gid; ?>&flag=1&menu="+str,true);
        xmlhttp.send();
    }
}

function removeFunc(str) {
    if (str == "") {
        document.getElementById("txtHint").innerHTML = "";
        return;
    } else {
        if (window.XMLHttpRequest) {
            // code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        } else {
            // code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
            }
        };
        xmlhttp.open("GET","function/prof_priv_conn.php?gid=<?php echo $gid; ?>&flag=2&menu="+str,true);
        xmlhttp.send();
    }
}
</script> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> 
    
    <!-- Main content -->
    <section class="content"> 
      
      <!-- ************************************************* -->
      <form role="form" method="get" action="assign_profile_privileges.php">
        <div class="box box-info">
          <div class="box-body">
            <div class="form-group">
              <label>Select Group Profile:<font color="#FF0000"><strong>*</strong></font></label>
              <select class="form-control select2" name="gid" style="width: 100%;" required>
                <?php
				 $sql3 = "SELECT id, type FROM group_profile WHERE del=0 ORDER BY type ASC";
                 $result3 = mysqli_query($conn, $sql3);
				 echo "<option></option>"; 
				while ($row3 = mysqli_fetch_array($result3)){ ?>
					<option value="<?php echo $row3['id']; ?>" <?php if($row3['id'] == $gid) { echo 'selected'; } ?>><?php echo $row3['type']; ?></option>; 
				<?php } ?>
              </select>
            </div>
            <!-- /.box-body -->
            <div class="box-footer">
              <button type="submit" class="btn btn-primary">FILTER</button>
            </div>
          </div>
        </div>
		<input type="hidden" name="menu" value="<?php echo $menu; ?>">
		
      </form>
      <?php if(isset($_GET['gid'])) { 
	$gid = htmlspecialchars(strip_tags(trim($_GET['gid'])), ENT_QUOTES, 'UTF-8'); 
	$sqld = mysqli_fetch_assoc(mysqli_query($conn, "SELECT type FROM group_profile WHERE id='$gid'")); 
    
	$sql1 = mysqli_query($conn, "SELECT id, category FROM dashboard_category where del='0' order by order_id ASC");
	$xx = 0;
	while($row1 = mysqli_fetch_array($sql1)) {
		$xx++;
		$cat = $row1['id'];
	?>
      <div class="panel box box-primary">
        <div class="box-header with-border">
          <h4 class="box-title"> <a href="#collapse<?php echo $xx; ?>" data-parent="#accordion" data-toggle="collapse"><?php echo $row1['category']; ?></a> </h4>
        </div>
        <div id="collapse<?php echo $xx; ?>" class="panel-collapse collapse in">
          <div class="box-body">
            <div class="form-group"> 
              
              <!-- /.table -->
              <div class="box-body">
                <table class="table table-bordered">
                  <tr>
                    <th width="5%">ID</th>
                    <th width="25%">Name</th>
                    <th width="5%">Status</th>
                    <th width="10%">Add/Remove</th>
                  </tr>
                  <?php 
						$sql="SELECT * FROM menu_list WHERE cat_id='$cat' and del='0' order by order_id ASC";
						$result=mysqli_query($conn, $sql);
						
						$yy=0;
						while ($row = mysqli_fetch_array($result)){ $yy++;
						$mlist =  $row['id']; ?>
                  <tr>
                    <td><?php echo $yy; ?>.</td>
                    <td><?php echo $row['name']; ?></td>
                    <?php $sql2 = mysqli_query($conn, "SELECT * FROM user_privileges WHERE group_id='$gid' and menu_id='$mlist'"); ?>
                    <td><img src="img/w.png" width="20" id="img2<?php echo $mlist; ?>"> <img src="img/r.png" width="20" id="img1<?php echo $mlist; ?>"></td>
                    <td><button onClick="addFunc(<?php echo $mlist; ?>)" class="btn btn-sm btn-primary" id="add<?php echo $mlist; ?>" style="display:none"> <i class="fa fa-plus"></i> &nbsp;ADD&nbsp;</button>
                      <button onClick="removeFunc(<?php echo $mlist; ?>)" class="btn btn-sm btn-danger" id="remove<?php echo $mlist; ?>" style="display:none"> <i class="fa fa-trash-o"></i> &nbsp;REMOVE&nbsp;</button></td>
                    <script>
							<?php if(mysqli_num_rows($sql2) == 0) { ?>
								$("#img2<?php echo $mlist; ?>").show();
								$("#img1<?php echo $mlist; ?>").hide();
								$("#remove<?php echo $mlist; ?>").hide();
								$("#add<?php echo $mlist; ?>").show();
							
							<?php } else {?>
								$("#img1<?php echo $mlist; ?>").show();
								$("#img2<?php echo $mlist; ?>").hide();
								$("#remove<?php echo $mlist; ?>").show();
								$("#add<?php echo $mlist; ?>").hide();
							<?php } ?>
						</script> 
                    <script>
						$(document).ready(function(){
							$("#add<?php echo $mlist; ?>").click(function(){
								$("#img1<?php echo $mlist; ?>").show();
								$("#img2<?php echo $mlist; ?>").hide();
								$("#remove<?php echo $mlist; ?>").show();
								$("#add<?php echo $mlist; ?>").hide();
							});
							$("#remove<?php echo $mlist; ?>").click(function(){
								$("#img2<?php echo $mlist; ?>").show();
								$("#img1<?php echo $mlist; ?>").hide();
								$("#remove<?php echo $mlist; ?>").hide();
								$("#add<?php echo $mlist; ?>").show();
							});
						});
						</script> 
                  </tr>
                  <?php  }  ?>
                </table>
              </div>
              <?php // } ?>
            </div>
            <!-- /.End table --> 
            
          </div>
        </div>
      </div>
      <?php }} ?>
    </section>
    <!-- ************************************************* --> 
    
    <!-- /.col --> 
  </div>
  <!-- /.row --> 
</div>
<!-- /.box-body -->

<div class="row"> </div>
<!-- /.col (right) -->

</div>
<footer class="main-footer">
  <div class="pull-right hidden-xs"> </div>
  <strong>Copyright &copy; NWP Engineering Department ..</strong> All rights reserved. </footer>

<!-- Control Sidebar -->
<aside class="control-sidebar control-sidebar-dark"> 
  <!-- Create the tabs -->
  <ul class="nav nav-tabs nav-justified control-sidebar-tabs">
    <li><a href="#control-sidebar-home-tab" data-toggle="tab"><i class="fa fa-home"></i></a></li>
    <li><a href="#control-sidebar-settings-tab" data-toggle="tab"><i class="fa fa-gears"></i></a></li>
  </ul>
  <!-- Tab panes -->
  <div class="tab-content"> 
    <!-- Home tab content -->
    <div class="tab-pane" id="control-sidebar-home-tab"> </div>
    <!-- /.tab-pane --> 
    
  </div>
  <!-- /.tab-pane -->
  </div>
</aside>
<!-- /.control-sidebar --> 
<!-- Add the sidebar's background. This div must be placed
           immediately after the control sidebar -->
<div class="control-sidebar-bg"></div>
</div>
<!-- ./wrapper --> 

<!-- jQuery 2.1.4 --> 
<script src="plugins/jQuery/jQuery-2.1.4.min.js"></script> 
<!-- Bootstrap 3.3.5 --> 
<script src="bootstrap/js/bootstrap.min.js"></script> 
<!-- Select2 --> 
<script src="plugins/select2/select2.full.min.js"></script> 
<!-- DataTables --> 
<script src="plugins/datatables/jquery.dataTables.min.js"></script> 
<script src="plugins/datatables/dataTables.bootstrap.min.js"></script> 
<!-- InputMask --> 
<script src="plugins/input-mask/jquery.inputmask.js"></script> 
<script src="plugins/input-mask/jquery.inputmask.date.extensions.js"></script> 
<script src="plugins/input-mask/jquery.inputmask.extensions.js"></script> 
<!-- date-range-picker --> 
<script src="plugins/daterangepicker/moment.min.js"></script> 
<script src="plugins/daterangepicker/daterangepicker.js"></script> 
<!-- bootstrap color picker --> 
<script src="plugins/colorpicker/bootstrap-colorpicker.min.js"></script> 
<!-- bootstrap time picker --> 
<script src="plugins/timepicker/bootstrap-timepicker.min.js"></script> 
<!-- SlimScroll 1.3.0 --> 
<script src="plugins/slimScroll/jquery.slimscroll.min.js"></script> 
<!-- iCheck 1.0.1 --> 
<script src="plugins/iCheck/icheck.min.js"></script> 
<!-- FastClick --> 
<script src="plugins/fastclick/fastclick.min.js"></script> 
<!-- AdminLTE App --> 
<script src="dist/js/app.min.js"></script> 
<!-- AdminLTE for demo purposes --> 
<script src="dist/js/demo.js"></script> 
<!-- Page script --> 
<script>
      $(function () {
        //Initialize Select2 Elements
        $(".select2").select2();

        //Datemask dd/mm/yyyy
        $("#datemask").inputmask("dd/mm/yyyy", {"placeholder": "yyyy-mm-dd"});
        //Datemask2 mm/dd/yyyy
        $("#datemask2").inputmask("mm/dd/yyyy", {"placeholder": "yyyy-mm-dd"});
        //Money Euro
        $("[data-mask]").inputmask();

        //Date range picker
        $('#reservation').daterangepicker();
        //Date range picker with time picker
		   $('#reservationtime').daterangepicker({timePicker: false, timePickerIncrement: 30, format: 'YYYY-MM-DD'});
        //Date range as a button
        $('#daterange-btn').daterangepicker(
            {
              ranges: {
                'Today': [moment(), moment()],
                'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
                'Last 7 Days': [moment().subtract(6, 'days'), moment()],
                'Last 30 Days': [moment().subtract(29, 'days'), moment()],
                'This Month': [moment().startOf('month')],
                'Last Month': [moment().subtract(1, 'month').startOf('month')]
              },
              startDate: moment().subtract(29, 'days'),
           
            },
        function (start) {
          $('#reportrange span').html(start.format('MMMM D, YYYY'));
        }
        );

        //iCheck for checkbox and radio inputs
        $('input[type="checkbox"].minimal, input[type="radio"].minimal').iCheck({
          checkboxClass: 'icheckbox_minimal-blue',
          radioClass: 'iradio_minimal-blue'
        });
        //Red color scheme for iCheck
        $('input[type="checkbox"].minimal-red, input[type="radio"].minimal-red').iCheck({
          checkboxClass: 'icheckbox_minimal-red',
          radioClass: 'iradio_minimal-red'
        });
        //Flat red color scheme for iCheck
        $('input[type="checkbox"].flat-red, input[type="radio"].flat-red').iCheck({
          checkboxClass: 'icheckbox_flat-green',
          radioClass: 'iradio_flat-green'
        });

        
      });
    </script> 
<script>
      $(function () {
        $("#example1").DataTable();
        $('#example2').DataTable({
          "paging": true,
          "lengthChange": false,
          "searching": false,
          "ordering": true,
          "info": true,
          "autoWidth": false
        });
      });
    </script>
</body>
</html>
