      <!--Select2 css-->
    <link href="<?php echo base_url();?>assets/css/select2.min.css" rel="stylesheet" />
        <!-- page content -->
        <div class="right_col" role="main">
          <div class="">
            <div class="page-title">
                <div class="title_left">
                </div>
            </div>
            <div class="clearfix"></div>

            <div class="row">
              <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                  <div class="x_title">
                    <h2>Add Teacher</h2>
                    <ul class="nav navbar-right panel_toolbox">
                      <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a></li>
                    </ul>
                    <div class="clearfix"></div>
                  </div>
                  <div class="x_content">

                    <form class="form-horizontal form-label-left" id="routePermit" action="<?php echo $base_url;?>teacher/save" method="post" enctype="multipart/form-data">

                     <?php if($this->user_model->is_super()){ ?>
             <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Branch <span class="text-danger">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <select id="branch" class="form-control col-md-7 col-xs-12" name="branch" required="required">
                            <option value=''>Select Branch</option>
                      <?php
                            foreach ($branch as $value) {?>
                            <option value="<?php echo $value['id']; ?>"><?php echo $value['name']?></option>

                      <?php } ?>
                          </select>
                        </div>
                      </div>
                      <?php  }else{$branch=$this->user_model->getbranch();?>
                          <input id="branch" name="branch" type="hidden" value="<?= $branch ?>">
                      <?php  } ?>
                       <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Department
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <select id="dpt" class="form-control col-md-7 col-xs-12" name="dpt">
                              <option value="">Select Department</option>
                             <?php
                                  foreach ($department as $key => $value) {
                                    echo "<option value= $value[id]>$value[name]</option>";
                                  }
                               ?>
                          </select>
                        </div>
                      </div>
                      <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">First Name <span class="text-danger">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <input id="firstname" class="form-control col-md-7 col-xs-12 abc"   name="firstname" placeholder="First Name"  type="text" required="required"  >
                        </div>
                      </div>
                      
                      <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Last Name <span class="text-danger">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <input id="lastname" class="form-control col-md-7 col-xs-12 abc"   name="lastname" placeholder="Last Name" required="required"   type="text" >
                        </div>
                      </div>
                      
                       <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">User Name <span class="text-danger">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <input id="u_name" class="form-control col-md-7 col-xs-12"  name="u_name" placeholder="User Name" required="required" type="text" >
                        </div>
                         <p id="status"></p>
                      </div>
                      
                       <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Password <span class="text-danger">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <input id="u_pass" class="form-control col-md-7 col-xs-12"  name="u_pass" placeholder="Password" type="password" >
                        </div>
                      </div>
                      
                       <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Email<span class="text-danger">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <input id="u_mail" class="form-control col-md-7 col-xs-12"  name="u_mail" placeholder="User Email"  type="email" >
                        </div>
                      </div>
                      
                      <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Incharge
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <select id="incharge" class="form-control col-md-7 col-xs-12" name="incharge">
                              <option value="">Select Class</option>
                             <?php
                                  foreach ($class  as $key => $value) {
                                    echo "<option value= $value[class_id]>$value[class_name]</option>";
                                  }
                               ?>
                          </select>
                        </div>
                      </div>
             
                      <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Picture <span class="text-danger">
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
	                    <?php
	                        $pic = array(
	                        'name' => 'img',
	                        'id' => 'pic', 
	                        'class'=> 'form-control col-md-7 col-xs-12',
	                        );

	                        echo form_upload($pic);  
	                    ?>
                      </div>
                      </div> 		                                 
                      <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="cnic">ID No <span class="text-danger">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <input type="text" id="cnic" name="cnic"  class="form-control col-md-7 col-xs-12" aria-describedby="name-format" placeholder="ID" pattern="\d{5}\d{3}" title="12345123 (8 numbers)">
                        </div>
                      </div>
                      <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="contact">Contact No <span class="text-danger">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <input type="text" id="contact" name="contact" maxlength="13" class="form-control col-md-7 col-xs-12 " placeholder="+254XXXXXXXXX" pattern="[\+]\d{3}\d{3}\d{6}" title='Phone Number (Format: +2543027566364'>
                        </div>
                      </div>
                      <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="b_head">Basic Salary<span class="text-danger">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <input id="salery" class="form-control col-md-7 col-xs-12 num" name="salery" placeholder="Salary" min=0  type="number">
                        </div>
                      </div>
                       <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="b_head">Security<span class="text-danger">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <input id="security" class="form-control col-md-7 col-xs-12 num" min=0 max="100000" name="security" placeholder="Security"  type="number">
                        </div>
                      </div>
                      <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="b_h_contact">Designation <span class="text-danger">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <input type="text" id="designation" name="designation"   title="Only alphatatic character" class="form-control col-md-7 col-xs-12 abc" placeholder="Designation">
                        </div>
                      </div>

                        <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="b_h_contact">Qualification<span class="text-danger">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <input type="text" id="qualification" name="qualification"  data-validate-minmax="10,100" class="form-control col-md-7 col-xs-12 abc1" placeholder="Qualification">
                        </div>
                      </div>

                      <div class="item form-group">
                        <label for="password" class="control-label col-md-3">Specialization<span class="text-danger">*</span></label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <input id="specialization" type="text" name="specialization" placeholder="Specialization" class="form-control col-md-7 col-xs-12 abc1"   title="only Alphatic character">
                        </div>
                      </div>
                      <div class="item form-group">
                        <label for="password" class="control-label col-md-3">Seniority Level<span class="text-danger">*</span></label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <input id="sen_lev" type="number" name="sen_lev" placeholder="Seniority Level" min=0 class="form-control col-md-7 col-xs-12  num" >
                        </div>
                      </div>
                      <div class="item form-group">
                        <label for="password" class="control-label col-md-3">Date of Birth<span class="text-danger">*</span></label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <input id="dob" type="text" name="dob"  placeholder="Date of Birth" class="form-control col-md-7 col-xs-12 datepicker">
                        </div>
                      </div>
                      <div class="item form-group">
                        <label for="password" class="control-label col-md-3">Date of Joining<span class="text-danger">*</span></label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <input id="doj" type="text" name="doj" placeholder="Date of joining"  class="form-control col-md-7 col-xs-12 datepicker"  />
                        </div>
                      </div>
                      <div class="item form-group">
                        <label for="password" class="control-label col-md-3">Address<span class="text-danger">*</span></label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <textarea id="address"  name="address" placeholder="Address" class="form-control col-md-7 col-xs-12" ></textarea>
                        </div>
                      </div>
                      <div class="item form-group">
                        <label for="password" class="control-label col-md-3">Bank Name</label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <input id="bank" type="text" name="bank" placeholder="Bank Name" class="form-control col-md-7 col-xs-12 abc1" >
                        </div>
                      </div>
                      <div class="item form-group">
                        <label for="account" class="control-label col-md-3"> Account Number</label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <input id="account" type="text" name="account" onkeypress="return ((event.charCode > 47 && event.charCode < 58) || event.charCode == 45  );" placeholder="999-9999999999999-99" class="form-control col-md-7 col-xs-12" >
                        </div>
                      </div>
                      


                    
                      <div class="form-group">
                        <div class="col-md-6 col-md-offset-3">
                          <button id="send" type="submit" class="btn btn-success pull-right">Save</button>
                        </div>
                      </div>
                    </form>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <!-- /page content -->

        <!-- footer content -->
        
        <!-- /footer content -->
      </div>
    </div>

    <!-- jQuery -->
    <script src="<?php echo base_url(); ?>assets/vendors/jquery/dist/jquery.min.js"></script>
     <script src="<?php echo base_url(); ?>assets/select/js/select2.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/js/datepicker/daterangepicker.js"></script>
 
<!-- Jquery UI-daterangepicker -->
    
<script src="<?php echo base_url(); ?>assets/vendors/datepicker/jquery-ui.min.js"></script>

    
    <!-- Form Validator -->
<script type="text/javascript" src="<?php echo base_url(); ?>assets/js/bootstrapValidator.js"></script>
<!-- Form Validator-->
 
    
  <script>
    $('#dpt').select2({
        allowClear:true
    });
    $('#incharge').select2({
        allowClear:true
    });
</script>
 
<script type="text/javascript">
    $(document).ready(function() {
        
    $("#u_name").keyup(function(){
      var name = $(this).val();
      $.get("<?php echo $base_url; ?>Teacher/admin_name/"+name,{},function(ret){
            if(ret==1)
            {
                 $("#status").text("Username already exist.");
                 $("#send").attr("disabled", "disabled");
            }else
            {
                 $("#status").text("");
                 $("#send").removeAttr("disabled");
            }
          });
    });


        $('#routePermit')
            .on('init.form.bv', function(e, data) {
                //console.log(data);
            })
            .bootstrapValidator({
                message: 'This value is not valid',
                feedbackIcons: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                fields: {
                    firstname: {
                        trigger:'blur',
                        validators: {
                            notEmpty: {
                                message: 'The firstname is required'
                            }
                        }
                    },
                     designation: {
                        trigger:'blur',
                        validators: {
                            Empty: {
                                message: 'The designation is required'
                            }
                        }
                    },
                    qualification: {
                        trigger:'blur',
                        validators: {
                            Empty: {
                                message: 'The qualification is required'
                            }
                        }
                    },
                    specialization: {
                        trigger:'blur',
                        validators: {
                            Empty: {
                                message: 'The specialization is required'
                            }
                        }
                    },
                    address: {
                        trigger:'blur',
                        validators: {
                            Empty: {
                                message: 'The address is required'
                            }
                        }
                    },
                     security: {
                        trigger:'blur',
                        validators: {
                            Empty: {
                                message: 'The security is required'
                            }
                        }
                    },
                      
                     password: {
                        trigger:'blur',
                        validators: {
                            Empty: {
                                message: 'The password is required'
                            }
                        }
                    },
                     lastname: {
                        trigger:'blur',
                        validators: {
                            Empty: {
                                message: 'The lastname is required'
                            }
                        }
                    },
                    salery: {
                        message: 'The salary is not valid',
                         trigger:'blur',
                        validators: 

                        {
                            Empty: {
                                message: 'The salary is required'
                            },
                         //      regexp: {
                         //    regexp: /^[0-9]{10}$/,
                         //     message: 'Plz Enter 10 Digit Number'
                         // },
                       
                            
                        }
                    },

                
                contact: {
                                    validators: {
                                        Empty: {
                                            message: 'The contact is required and cannot be empty'
                                        },
                                        
                                    }
                                },

                    'phone[]': {
                      
                    trigger:'blur',
                validators: {
                    
                         stringLength: {
                            min: 12,
                            max: 12,
                            message: 'The phone number must be  +254XXXXXXXX'
                        }
                    
                                  // callback: {
                    //     callback: function(value, validator, $field) {
                    //         var $phone          = validator.getFieldElements('phone[]'),
                    //             numphone        = $phone.length,
                    //             notEmptyCount    = 0,
                    //             obj              = {},
                    //             duplicateRemoved = [];

                    //         for (var i = 0; i < numphone; i++) {
                    //             var v = $phone.eq(i).val();
                    //             if (v !== '') {
                    //                 obj[v] = 0;
                    //                 notEmptyCount++;
                    //             }
                    //         }

                    //         for (i in obj) {
                    //             duplicateRemoved.push(obj[i]);
                    //         }

                    //         if (duplicateRemoved.length === 0) {
                    //             return {
                    //                 valid: false,
                    //                 message: 'Phone Number is required'
                    //             };
                    //         } else if (duplicateRemoved.length !== notEmptyCount) {
                    //             return {
                    //                 valid: false,
                    //                 message: 'The phone no must be unique, cannot duplicate'
                    //             };
                    //         }

                    //         validator.updateStatus('phone[]', validator.STATUS_VALID, 'callback');
                    //         return true;
                    //     }
                   
                       
                //  },
                   // remote: {
                    //     url: 'existphonecustomer',
                    //     // Send { email: 'its value', username: 'its value' } to the back-end
                    //     data: function(validator, $field, value) {
                    //         var phone=validator.getFieldElements('phone[]').val();
                    //         console.log(phone);
                    //         return {
                    //             phone: phone
                    //         };
                    //     },
                    //     message: 'This phone number is already exist',
                    //     type: 'POST'
                    // }
                }
            },

                     cnic: {
                    trigger:'blur',
                validators: {
                     Empty: {
                             message: 'The id is required'
                         },
                         stringLength: {
                            min: 8,
                            max: 8,
                            message: 'The id must be 8 digit'
                        },
                    
                }
            },

                    email: {
                                    validators: {
                                        Empty: {
                                            message: 'The email address is required and cannot be empty'
                                        },
                                        emailAddress: {
                                            message: 'The email address is not valid'
                                        }
                                    }
                                },
            
            
        

                    address: {
                         trigger:'blur',
                        validators: {
                            Empty: {
                                message: 'The address is required'
                            }
                        }
                    },

                    contactname: {
                         trigger:'blur',
                        validators: {
                            Empty: {
                                message: 'The Contact Person Name is required'
                            }
                        }
                    },
                    


                   
                }
            });
    });
    
 
    
$("#zzz").click(function(){
   $('#routePermit').bootstrapValidator("resetForm",true);    
});


$(".num").on("keypress", function (e) {
          
            var evt = (e) ? e : window.event;
            var charCode = (evt.keyCode) ? evt.keyCode : evt.which;
            if (charCode > 31 && (charCode < 48 || charCode > 57)) {
                return false;
            }
            return true;
        });
</script>
<script>
    
     
// $(document).ready(function(){
  
//           $('.DMY').daterangepicker({
    
//   		format: 'DD-MM-YYYY',
     
//   		singleDatePicker: true,
     
//   		showDropdowns: true
    
// 	});
//         // $("#myModal").modal({
  
//           // backdrop: 'static',
         
//   // keyboard: false
//     // });
//         });

 $( function() {
 
   $( ".datepicker" ).datepicker({
	 dateFormat: 'd-m-yy' 
	}).val();
  
	} );
  
</script>
