<link href="<?php echo ASSETS_URL;?>bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<link href="<?php echo ASSETS_URL;?>plugins/datatables/dataTables.bootstrap.css" rel="stylesheet" type="text/css" />
<script src="<?php echo ASSETS_URL;?>plugins/jQuery/jQuery-2.1.4.min.js"></script>
<script src="<?php echo ASSETS_URL;?>bootstrap/js/bootstrap.min.js"></script>
<script src="<?php echo ASSETS_URL;?>plugins/datatables/jquery.dataTables.js"></script>
<script src="<?php echo ASSETS_URL;?>plugins/datatables/dataTables.bootstrap.min.js"></script>

                <div class="row">
                  <div class="col-lg-12">
                      <section class="panel">
                          <header class="panel-heading">
                              ROLE MODULE ACCESS <?php echo $role['f_role_code'];?>
                          </header>

                            <div class="panel-body">
                                  <div class="form">
<form class="form-validate form-horizontal" name="frmrole" id="frmrole" method="post" > 
<?php 
$attributes = array('class' => 'form-validate form-horizontal', 'name' => 'frmrole', 'id' => 'frmrole');
//echo form_open('role_module/fnRole_moduleCreate/'.$role_id,$attributes);
?>                                          
				  <div class="form-group">
					<table class="table table-striped table-bordered scrollme" >
					   <thead>
						  <tr>
							 <th id="t_header" width="10px"> No</th>
							 <th id="t_header" >MODULE NAME</th>                               
							 <th id="t_header" >DESCRIPTION</th> 
							 <th id="t_header" >VIEW<br/><input type="checkbox" name="viewall" id="viewall"/></th>         
							 <th id="t_header" >ADD<br/><input type="checkbox" name="addall" id="addall"/></th>         
							 <th id="t_header" >EDIT<br/><input type="checkbox" name="editall" id="editall"/></th>
							 <th id="t_header" >DELETE<br/><input type="checkbox" name="deleall" id="deleall"/></th>
							 <th id="t_header" >EXPORT<br/><input type="checkbox" name="expall" id="expall"/></th>
							 <th id="t_header" >IMPORT<br/><input type="checkbox" name="impall" id="impall"/></th>
							 <th id="t_header" >VALID<br/><input type="checkbox" name="valall" id="valall"/></th>

						  </tr>
						  </thead>
						  <tbody>
   <?php
  // echo print_r($vResult)."<br/>";
		$i=1;
		foreach($vResult as $vRows):
				 echo "<tr>";
				 echo "<td align='center'>$i</td>
						<td>$vRows[f_mod_name]<br/>class : $vRows[f_mod_class]</td>                               
						<td>$vRows[f_mod_desc]</td>                               
				 ";
				if($vRows[f_mod_class] != '') {
					$selview =  ($vRows['f_mod_id'].'_1' === $vRows['view'].'_1') ? true  : false;
				} else {
					$selview =  true;
				}
				$vwc = array('name'=>'view[]','value'=> $vRows['f_mod_id'].'_1','checked'=> $selview,"class" => "view_".$vRows['f_mod_id'],"onClick"=> "cView('view_".$vRows['f_mod_id']."')");
				echo "<td>".form_checkbox($vwc)."</td>";

			if($vRows[f_mod_class] != '')
			{					
				$seladd =  ($vRows['f_mod_id'].'_1' === $vRows['f_mod_id']."_".$vRows['add']) ? true  : false;
				$addc = array('name'=>'add[]','value'=> $vRows['f_mod_id'].'_1','checked'=> $seladd,"class" => "add_".$vRows['f_mod_id']);
				echo "<td>".form_checkbox($addc)."</td>";		
	
				$seledit =  ($vRows['f_mod_id'].'_1' === $vRows['f_mod_id']."_".$vRows['edit']) ? true  : false;
				$editc = array('name'=>'edit[]','value'=> $vRows['f_mod_id'].'_1','checked'=> $seledit,"class" => "edit_".$vRows['f_mod_id']);
				echo "<td>".form_checkbox($editc)."</td>";		
	
				$seldel =  ($vRows['f_mod_id'].'_1' === $vRows['f_mod_id']."_".$vRows['delete']) ? true  : false;
				$delc = array('name'=>'delete[]','value'=> $vRows['f_mod_id'].'_1','checked'=> $seldel,"class" => "del_".$vRows['f_mod_id']);
				echo "<td>".form_checkbox($delc)."</td>";		
	
				$selexp =  ($vRows['f_mod_id'].'_1' === $vRows['f_mod_id']."_".$vRows['export']) ? true  : false;
				$expc = array('name'=>'export[]','value'=> $vRows['f_mod_id'].'_1','checked'=> $selexp,"class" => "exp_".$vRows['f_mod_id']);
				echo "<td>".form_checkbox($expc)."</td>";		
	
				$selimp =  ($vRows['f_mod_id'].'_1' === $vRows['f_mod_id']."_".$vRows['import']) ? true  : false;
				$impc = array('name'=>'import[]','value'=> $vRows['f_mod_id'].'_1','checked'=> $selimp,"class" => "imp_".$vRows['f_mod_id']);
				echo "<td>".form_checkbox($impc)."</td>";		
	
				$selvalid =  ($vRows['f_mod_id'].'_1' === $vRows['f_mod_id']."_".$vRows['valid']) ? true  : false;
				$valc = array('name'=>'validasi[]','value'=> $vRows['f_mod_id'].'_1','checked'=> $selvalid,"class" => "val_".$vRows['f_mod_id']);
				echo "<td>".form_checkbox($valc)."</td>";
			}
			else
			{
				echo "<td></td><td></td><td></td><td></td><td></td><td></td>";
			}
	
				echo "</tr>";
			$i++;
		endforeach;
	?>                                 
                                               </tbody>
                                            </table>   
                                </div>
                                          
                                  </div>
                            </div>
                            <div class="panel-footer" align="center">
							  <a id=btn_save class="btn btn-primary" href="javascript:void(0)"  onclick="fnSaveData()">Save</a><?php echo nbs(10);?>
							  <a class="btn btn-default" onClick="fnCancel();" >Cancel</a>								
                            </div>
						</form>

                      </section>
                  </div>
                </div>  
<script type="text/javascript">
$(document).ready(function(){
    $('.scrollme').dataTable({
        "scrollX":        true,
        "scrollY":        "350px",
        "scrollCollapse": true,
        "paging":         false,
		"ordering": false,
        "info":     false, 
        "bFilter": false,       		
		});
	// cek all view		
	$('#viewall').click(function(event) {   
	    if(this.checked) {	$(':checkbox[name="view[]"]').each(function() {	this.checked = true;	});    }
	    else    {	$(':checkbox[name="view[]"]').each(function() {	this.checked = false; });	}
	});		
	// cek all add		
	$('#addall').click(function(event) {   
	    if(this.checked) {	$(':checkbox[name="add[]"]').each(function() {	this.checked = true;	});    }
	    else    {   $(':checkbox[name="add[]"]').each(function() {	this.checked = false; });	}
	});		
	// cek all edit
	$('#editall').click(function(event) {   
	    if(this.checked) {  $(':checkbox[name="edit[]"]').each(function() { this.checked = true; });    }
	    else    {   $(':checkbox[name="edit[]"]').each(function() { this.checked = false; });	}
	});		
	// cek all delete
	$('#deleall').click(function(event) {   
	    if(this.checked) {  $(':checkbox[name="delete[]"]').each(function() { this.checked = true; });    }
	    else    {   $(':checkbox[name="delete[]"]').each(function() { this.checked = false; });	}
	});		
	// cek all export
	$('#expall').click(function(event) {   
	    if(this.checked) {  $(':checkbox[name="export[]"]').each(function() { this.checked = true; });    }
	    else    {   $(':checkbox[name="export[]"]').each(function() { this.checked = false; });	}
	});		
	// cek all import
	$('#impall').click(function(event) {   
	    if(this.checked) {  $(':checkbox[name="import[]"]').each(function() { this.checked = true; });    }
	    else    {   $(':checkbox[name="import[]"]').each(function() { this.checked = false; });	}
	});		
	// cek all valid
	$('#valall').click(function(event) {   
	    if(this.checked) {  $(':checkbox[name="validasi[]"]').each(function() { this.checked = true; });    }
	    else    {   $(':checkbox[name="validasi[]"]').each(function() { this.checked = false; });	}
	});		

});
    
function cView(clas)
{
	var cV = $('.'+clas).prop("checked");
	var sV = clas.split('_');
	if(cV)
	{
		$('.add_'+sV[1]).prop("checked",true);
		$('.edit_'+sV[1]).prop("checked",true);
		$('.del_'+sV[1]).prop("checked",true);
		$('.exp_'+sV[1]).prop("checked",true);
		$('.imp_'+sV[1]).prop("checked",true);
		$('.val_'+sV[1]).prop("checked",true);
        
	}
	else
	{
		$('.add_'+sV[1]).prop("checked",false);		
		$('.edit_'+sV[1]).prop("checked",false);
		$('.del_'+sV[1]).prop("checked",false);
		$('.exp_'+sV[1]).prop("checked",false);
		$('.imp_'+sV[1]).prop("checked",false);
		$('.val_'+sV[1]).prop("checked",false);
        
	}
}
function fnSaveData() {
        $.ajax({
            type: 'POST',
            url : '<?php  echo site_url('role_module/fnRole_moduleCreate/'.$role_id);?>',
            dataType: 'json',
//            data: formdata,
            data: $("#frmrole").serialize(),
            success: function(data) {
                
                if(data.hasil == "ok") {
					alert('Sukses Simpan');
	                parent.$.fancybox.close();
				}
				else
				{
					alert('Gagal Simpan');
				}
            }
        });		
}

function fnCancel()
{
	parent.$.fancybox.close();
}
</script>
