<?php
	include('common/header.php');
	// error_reporting(E_ALL);
  $value['user_type']="";
  $user_type_id="";
  $modules="";

	// print_r($user_type);
?>
<div id="messages" style="color: red;"><h5><?php echo $this->session->flashdata('message'); ?></h5></div>
<?php 
  if ($this->uri->segment(4)) {
   foreach ($user_type as  $value){
    $user_type_id=$value['user_type_id'];
    $mod= $value['module_ids'];   
    $modules= explode(',', $mod);
   }   
}
 ?>
	<div class="">
		<div class="col-xm-12">
			<div class="widget-box light-border">
				<!-- <div class="widget-header header-color-grey">
					<h4 class="smaller">
						User Type
					</h4>
				</div> -->
				<div class="widget-body">
					<div class="widget-main">
						<div class="row">
							<div class="col-sm-12">
								<form class="form-horizontal" role="form" method="post" onsubmit="return validateForm()" name="myForm" action="<?php echo base_url()?>index.php/<?php echo USER_TYPE;?>add_user_type">
                  <input type="hidden" value="<?php echo $user_type_id ?>" name="hidden">
								<div class="">
									<!-- PAGE CONTENT BEGINS -->
                    <div class="form-group">  
										<label class="col-sm-5 control-label" for="form-field-2" ><?php echo 'User Type';?><font style="color:red">*</font></label>
										 <div class="col-sm-7">
                               				 
                                			<input type="text" name="user_type" id="user_type" value="<?php echo $value['user_type']; ?>" placeholder="User Type" class="form-control" />
                                			

                               			<span id="user_type1" class="text-danger font-weight-bold"></span>       
                            		 </div>
									</div>

								     <!-- <div class="form-group"> --> 
										<label class="col-sm-5 control-label" for="form-field-2" ><?php echo 'Access Control';?><font style="color:red">*</font></label>
										<div class="col-sm-7">
											<table class="table table-bordered">
   											 <tbody>
     										  <tr>
     										  <?php  
                            foreach ($module as  $m) {
                              ?>
                              <?php
                              
                              if(in_array($m['module_id'], $modules)){?>
                                <td style="width: 21px;"><input name="form-field-checkbox[]" type="checkbox" id="mod" value="<?php echo $m['module_id']?>" checked/></td><?php  
                                 }else{?>
                                 <td style="width: 21px;"><input name="form-field-checkbox[]" type="checkbox" id="mod" value="<?php echo $m['module_id']?>"  /></td><?php } ?>
                                <td>
        									   	<?php
                                  if ($m['module_parent_id']==0) {    		
        									        echo "<b>".$m['module_name']."</b>"; 
        									        	}elseif($m['module_parent_id']==$m['module_id']){
                                    echo "".$m['module_name']."";
        									        }else{
        									        	echo "--".$m['module_name']."";
        									        }
        									        ?>
        									   </td>
      										  </tr>
      										<?php }?>
    										 </tbody>
  											</table>

                        	</div>	
																		
								</div>
								
							</div>
						</div>
					</div>	
				</div>
			</div>
		</div>
		<!-- /.col -->
	</div>
	<div class="clearfix form-actions">
		<div class="col-md-offset-5 col-md-5">
			
			<button class="btn btn-info" type="submit">
				Submit
			</button>
		</div>
	</div>
	</form>	
	<div class="space-4"></div>
		<!-- /.page-row -->
        <!-- /.page-content --> 
    </div>
    <!-- /.main-content --> 
	</div>
    <!-- /#ace-settings-container --> 
	</div>
	<!-- /.main-container-inner --> 	
<?php
	include('common/footer.php');
?>
<script>
function hide()
{
	document.getElementById("admin_type_code").style.display="none";
}
function show()
{
	document.getElementById("admin_type_code").style.display="";
}
</script>
<script>
  $("#user_management").change(function(){  //"select all" change 
    $(".um").prop('checked', $(this).prop("checked")); //change all ".checkbox" checked status
});
  $("#masters").change(function(){  //"select all" change 
    $(".m").prop('checked', $(this).prop("checked")); //change all ".checkbox" checked status
});
  $("#transactions").change(function(){  //"select all" change 
    $(".t").prop('checked', $(this).prop("checked")); //change all ".checkbox" checked status
});
  $("#reports").change(function(){  //"select all" change 
    $(".r").prop('checked', $(this).prop("checked")); //change all ".checkbox" checked status
});

function validateForm(){

      var user_type = document.getElementById('user_type').value;
      var mod = document.getElementById('mod').value;

      if(user_type == ""){
        document.getElementById('user_type1').innerHTML =" ** Please fill the User Type  field";
        return false;
      }
       if(!isNaN(user_type)){
        document.getElementById('user_type1').innerHTML =" ** User Type must be characters are allowed";
        return false;
      }
      if(mod == ""){
        alert('Please select any one from this checkboxes  field');
        document.getElementById('mod1').innerHTML =" ** Please select any one from this checkboxes  field";
        return false;
      }
      
    }


</script>

