<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1>
        <center>User Management</center>
        
      </h1>
	  	  
    </section>
    
    <section class="content">
    <div style="text-align:right;">
    <a href="<?php echo base_url() ?>userListing" class="btn btn-info" value="Back"/>Back</a>
	</div>
	<br/>
        <div class="row">
            <!-- left column -->
            <div class="col-md-12">
              <!-- general form elements -->
                
                
                
                <div class="box box-primary">
                    <div class="box-header">
                        <center><h3 class="box-title">Siddharth Industries - Add New User</h3></center>
                    </div><!-- /.box-header -->
                    <!-- form start -->
                    
                    <form role="form" id="addUser" action="<?php echo base_url() ?>addNewUser" method="post" role="form">
                        <div class="box-body">
                            <div class="row">
							<div class="col-md-3">                                
                                    <div class="form-group">
                                        <label for="fname">Emp ID</label>
                                         <select class="form-control required select"  id="EmpList" name="EmpList">
                                            <option value="0">Select Emp ID</option>
											
											<?php
                                            if(!empty($EmpList))
                                            {
                                                foreach ($EmpList as $EID)
                                                {
                                                   												
													$EmpID = $EID->EmpID;
                                                  													
													if ($_POST['EmpList'] == $EmpID) 
													{

												echo "<option value=\"".$EmpID."\" selected=\"selected\">".$EmpID.' -  '. $EID->FirstName."</option>"; 
													}
													else 
													{
													echo "<option value=\"".$EmpID."\">".$EmpID.' -  '. $EID->FirstName ."</option>";       
													}
                                                }
                                            }
                                            ?>
											</select>
                                    </div>
                                    
                                </div>
                                <div class="col-md-3">                                
                                    <div class="form-group">
                                        <label for="fname">First Name</label>
                                        <input type="text" class="form-control required" readonly id="FirstName" name="FirstName" maxlength="128">
                                    </div>
                                    
                                </div>
								<div class="col-md-3">                                
                                    <div class="form-group">
                                        <label for="fname">Last Name</label>
                                        <input type="text" class="form-control required" readonly id="LastName" name="LastName" maxlength="128">
                                    </div>
                                    
                                </div>
								 <div class="col-md-3">
                                    <div class="form-group">
                                        <label for="email">Designation</label>
                                        <input type="text" class="form-control required "  readonly id="Designation"  name="Designation" maxlength="128">
                                    </div>
                                </div>
								 </div>
								
								 <div class="row">
                               
								<div class="col-md-3">
                                    <div class="form-group">
                                        <label for="mobile">Department</label>
                                        <input type="text" class="form-control required " readonly id="Department" name="Department" minlength="10"maxlength="10">
                                    </div>
                                </div>
								 <div class="col-md-3">
                                    <div class="form-group">
                                        <label for="email">Email address</label>
                                        <input type="text" class="form-control required " readonly id="MailID"  name="MailID" maxlength="128">
                                    </div>
                                </div>
								<div class="col-md-3">
                                    <div class="form-group">
                                        <label for="mobile">Contact Number</label>
                                        <input type="text" class="form-control required digits" readonly id="ContactNo" name="ContactNo" minlength="10"maxlength="10">
                                    </div>
                                </div>
								
								 
								 </div>
								<div class="row">
                               
								
                            </div>
							
                            <div class="row">
							 <div class="col-md-3">
                                    <div class="form-group">
                                        <label for="role">Role</label>
                                        <select class="form-control required" id="role" name="role">
                                            <option value="0">Select Role</option>
                                            <?php
                                            if(!empty($roles))
                                            {
                                                foreach ($roles as $rl)
                                                {
                                                    ?>
                                                    <option value="<?php echo $rl->roleId ?>"><?php echo $rl->role ?></option>
                                                    <?php
                                                }
                                            }
                                            ?>
                                        </select>
                                    </div>
                                </div>    
                                <div class="col-md-3">
                                    <div class="form-group">
                                        <label for="password">Password</label>
                                        <input type="password" class="form-control required" id="password" required  name="password" maxlength="10">
                                    </div>
                                </div>
                                <div class="col-md-3">
                                    <div class="form-group">
                                        <label for="cpassword">Confirm Password</label>
                                        <input type="password" class="form-control required equalTo"  required id="cpassword" name="cpassword" maxlength="10">
                                    </div>
                                </div>
                            </div>
                           
                        </div><!-- /.box-body -->
    
                        <div class="box-footer" style="text-align:right">
                            <input type="submit" class="btn btn-info" value="Submit" />
                            <input type="reset" class="btn btn-info" value="Cancel" />
                        </div>
                    </form>
                </div>
            </div>
            <div class="col-md-4">
                <?php
                    $this->load->helper('form');
                    $error = $this->session->flashdata('error');
                    if($error)
                    {
                ?>
                <div class="alert alert-danger alert-dismissable">
                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                    <?php echo $this->session->flashdata('error'); ?>                    
                </div>
                <?php } ?>
                <?php  
                    $success = $this->session->flashdata('success');
                    if($success)
                    {
                ?>
                <div class="alert alert-success alert-dismissable">
                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                    <?php echo $this->session->flashdata('success'); ?>
                </div>
                <?php } ?>
                
                <div class="row">
                    <div class="col-md-12">
                        <?php echo validation_errors('<div class="alert alert-danger alert-dismissable">', ' <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button></div>'); ?>
                    </div>
                </div>
            </div>
        </div>    
    </section>
    
</div>
<script src="<?php echo base_url(); ?>assets/js/addUser.js" type="text/javascript"></script>

<script>
$('#EmpList').select2();
$('#EmpList').change(function() {
    
 var id = $('#EmpList').val();
 
 var y = <?php echo json_encode($EmpList, JSON_PRETTY_PRINT) ?>;

	
		
		if(id != "0")
		{
		
				
		$.each(y, function(idx, obj) {
			if(obj.EmpID === id)
			{		     
				$("#FirstName").val(obj.FirstName);
				$("#LastName").val(obj.LastName);
	     
				$("#Designation").val(obj.Designation);
				$("#Department").val(obj.DepartmentName);	
                $("#MailID").val(obj.EmailId);
				$("#ContactNo").val(obj.ContactNumber);					
			}
			
		});
		}
else
{
				alert('Please select Employee Details');
				$("#FirstName").val('');
				$("#LastName").val('');
	     
				$("#Designation").val('');
				$("#Department").val('');	
                $("#MailID").val('');
				$("#ContactNo").val('');
                return false;				
}	
  
});
</script>