<?php
include("lib/config.php");

$groupID = isset($_GET["gid"])?$_GET["gid"]:'';
?>

<div class="box-content">
  <form method="post" name="frmGroups" id="frmGroups">
    <input type="hidden" name="action" value="modulesAccess">
    <input type="hidden" name="group_id" value="<?php echo(isset($groupID))?$groupID:'';?>">
   
    <div>
    <table class="table table-striped table-bordered dataTable no-footer">
        <thead>
          <tr>
            <th>Sr#</th>
            <th>Module</th>
            <th>Access</th>
          </tr>
        </thead>
        <tbody>
			  <?php 
                $counter_modules = 0;
                $selQry_mod = "SELECT * FROM ".TBL_MODULES." WHERE status='1' ORDER BY id";
                $modInfo =  $con->getMultiRow($selQry_mod, __FILE__,__LINE__);
                $totMods = count($modInfo);	
                    for($m=0;$m<$totMods;$m++)
                    {
						$counter_modules++;
						//----------------------------------------
						$selQry_mod_per = "SELECT * FROM ".TBL_GROUPS_PERMISSIONS." WHERE group_id='".$groupID."' and module_id='".$modInfo[$m]['id']."' LIMIT 1";
                		$modPerInfo =  $con->getSingleRow($selQry_mod_per, __FILE__,__LINE__);
						$totModsPer = count($modPerInfo);
						//----------------------------------------
               ?>
      		  <tr>
                <td><?php echo $counter_modules;?>.</td>
                <td><?php echo $modInfo[$m]['module_name'];?></td>
                <td><input type="checkbox" name="modules[]" id="module_<?php echo $modInfo[$m]['id'];?>" value="<?php echo $modInfo[$m]['id'];?>" <?php if($totModsPer>0){?>checked="checked"<?php }?> /></td>
              </tr>
      		  <?php }?>
        </tbody>
      </table>
    </div>    
    <div style="margin-top:30px; text-align:right;">
      <button data-loading-text="Saving..." type="submit" class="btn btn-success"> <i class="fa fa-floppy-o"></i> Assign</button>
      <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
    </div>
  </form>
</div>
<script>
$(document).ready(function(e){
    $("#frmGroups").on('submit', function(e){
	    
		e.preventDefault();
		
        $.ajax({
            type: 'POST',
            url: 'groups-config.php',
            data: new FormData(this),
			
            //data: userData,
            contentType: false,
            cache: false,
            processData:false,
			dataType: 'JSON',
            beforeSend: function(){
                //$('.submitBtn').attr("disabled","disabled");
                //$('#fupForm').css("opacity",".5");
            },
            success: function(msg){			
                //$('.statusMsg').html('');
				
                if(msg[0].message == 'ok'){
				
                    $('#frmGroups')[0].reset();
					
					//$('.statusMMsg').html('<span style="font-size:18px;color:#34A853">Product(s) added successfully.</span>');
					$('#myModal').modal('hide');
					
					//getUsers(); 
					
					Lobibox.notify('success', {
						title: 'Success',
						msg: 'Record added successfully.'
					});					
                }
				else
				{   
					//$('.statusMMsg').html('<span style="font-size:18px;color:#EA4335">Some problem occurred, please try again.</span>');
					$('#myModal').modal('hide');
					
					Lobibox.notify('error', {
						title: 'Error',
						msg: 'Some problem occurred, please try again.'
					});
                }
            }
        });
    });
	
});
</script>