<style>
#def{
  display:none;
}
#hide_cls{
  display:none;
}


</style>  
<!-- page content -->
        <div class="right_col" role="main">
          <div class="">
            <div class="page-title">
              <div class="title_left">
                <h3></h3>
              </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>View Users</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>
                  <input id="add_cls" class="btn btn-success" value="Add User"  type="button">
                  
                  <div class="x_content">
                      <div id="def">
                          <!--$base_url;?>classes/save-->
                    <form class="form-horizontal form-label-left" id="routePermit" action="" method="post">

                        <input type="hidden" name="edit_id" id="edit_id">
                      <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12 " for="name">First Name <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <input id="fname" class="form-control col-md-7 col-xs-12 abc" name="fname" placeholder="First 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">Last Name <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <input id="lname" class="form-control col-md-7 col-xs-12 abc"  name="lname" 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="email">Email <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <input type="email" id="email" name="email" required="required"  class="form-control col-md-7 col-xs-12" pattern="^[\w-]+(\.[\w-]+)*@([a-z0-9-]+(\.[a-z0-9-]+)*?\.[a-z]{2,6}|(\d{1,3}\.){3}\d{1,3})(:\d{4})?$" placeholder="username@domain.com">
                        </div>
                      </div>
                      <div class="item form-group" id="msg" style="display:none;">
                           <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name"> 
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <input id="msgfield" style="background-color:#e86d6d; color:white;" class="form-control col-md-7 col-xs-12" value="Sorry! This Username already exists!"  name="msg" type="text" readonly>
                        </div>
                      </div>
                      <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Username <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <input id="username" class="form-control col-md-7 col-xs-12" onKeyup="myFunction()"  data-validate-length-range="6" data-validate-words="2" name="username" placeholder="Username" required="required" type="text">
                        </div>
                      </div>
                      <div class="item form-group" id="pass">
                        <label for="password" class="control-label col-md-3">Password <span class="required">*</span></label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <input id="password" type="password" name="password" data-toggle="password" data-validate-length="6,8" data-bv-identical="true"
                data-bv-identical-field="confirmPassword"
                data-bv-identical-message="The password and its confirm are not the same" class="form-control col-md-7 col-xs-12" maxlength="12" required="required" onkeyup='check();' />
                        </div>
                      </div>
                      <div class="item form-group" id="pass1">
                        <label for="password2" class="control-label col-md-3 col-sm-3 col-xs-12">Repeat Password <span class="required">*</span></label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <input id="password2" type="password" name="password2" data-bv-identical="true"
                data-bv-identical-field="password" data-bv-identical-message="The password and its confirm are not the same"  data-toggle="password" data-validate-linked="password" class="form-control col-md-7 col-xs-12"  required="required" onkeyup='check();' />
                        </div>
                        <span id='message'></span>
                      </div>
                      <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="number">Contact # <span></span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                     

<input id="number" name="contact" class="form-control  col-md-7 col-xs-12 phone" type="text" placeholder="+254XXXXXXXXX" pattern="[\+]\d{3}\d{4}\d{6}" title="Phone No. Format: +254XXXXXXXXX" maxlength="13">
                        </div>
                      </div>
                    
                      <div class="form-group">
                        <div class="col-md-6 col-md-offset-3">
                          <button id="new_type" type="button" disabled="disabled" value="Add" class="btn btn-success pull-left">Save</button><input id="hide_cls" class="btn btn-danger" value="Cancel"  type="button">
                        </div>
                      </div>
                    </form>
                    <hr>
                    
                      </div>
                     
                        
                      <table id="datatable-buttons" class="table table-striped table-bordered dt-responsive nowrap">
                      <thead>
                          <span id="success_msg"></span>
                        <tr>
                          <th>#</th>
                          <th>First Name</th>
                          <th>Last Name</th>
                          <th>Username</th>
                          <th>Email</th>
                          <th>Contact</th>
                          <th>Role</th>
                         <?php  if($this->user_model->is_super()){ ?>
                         
                          <th>Branch</th>
                          <?php } ?>
                          <th>Actions</th>
                        </tr>
                      </thead>


                      <tbody class="center">
                       
                      </tbody>
                      
                    </table>
                   
                  </div>
                </div>
              </div>

            </div>
          </div>
        </div>
        <!-- /page content -->

        <!-- footer content -->
        <footer>
          <div class="pull-right">
            Prudmac
          </div>
          <div class="clearfix"></div>
        </footer>
        
        
        <div id='ajaxload' style='position:fixed;top:0;left:0;bottom:0; width:100%;height:100%;z-index:1000;background:rgba(2,132,130,0.5);display:none;'>
            <i class='fa fa-spinner fa-spin fa-4x' style='position: relative;top: 50%;left: 50%;margin-top: -50px;margin-left: -50px;'></i>
        </div>
        <!-- /footer content -->
      </div>
    </div>
    
    

    <!-- jQuery -->
    <script src="<?php echo base_url(); ?>assets/vendors/jquery/dist/jquery.min.js"></script>
    <!-- Custom JS -->
    <script src="<?php echo base_url(); ?>assets/js/main.js"></script>
    <!-- Bootstrap -->
    <script src="<?php echo base_url(); ?>assets/vendors/bootstrap/dist/js/bootstrap.min.js"></script>
    <!-- FastClick -->
    <script src="<?php echo base_url(); ?>assets/vendors/fastclick/lib/fastclick.js"></script>
    <!-- NProgress -->
    <script src="<?php echo base_url(); ?>assets/vendors/nprogress/nprogress.js"></script>
    <!-- Chart.js -->
    <script src="<?php echo base_url(); ?>assets/vendors/Chart.js/dist/Chart.min.js"></script>
    <!-- gauge.js -->
    <script src="<?php echo base_url(); ?>assets/vendors/gauge.js/dist/gauge.min.js"></script>
    <!-- bootstrap-progressbar -->
    <script src="<?php echo base_url(); ?>assets/vendors/bootstrap-progressbar/bootstrap-progressbar.min.js"></script>
    <!-- iCheck -->
    <script src="<?php echo base_url(); ?>assets/vendors/iCheck/icheck.min.js"></script>
    <!-- Skycons -->
    <script src="<?php echo base_url(); ?>assets/vendors/skycons/skycons.js"></script>
    <!-- Flot -->
    <script src="<?php echo base_url(); ?>assets/vendors/Flot/jquery.flot.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/Flot/jquery.flot.pie.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/Flot/jquery.flot.time.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/Flot/jquery.flot.stack.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/Flot/jquery.flot.resize.js"></script>
    <!-- Flot plugins -->
    <script src="<?php echo base_url(); ?>assets/js/flot/jquery.flot.orderBars.js"></script>
    <script src="<?php echo base_url(); ?>assets/js/flot/date.js"></script>
    <script src="<?php echo base_url(); ?>assets/js/flot/jquery.flot.spline.js"></script>
    <script src="<?php echo base_url(); ?>assets/js/flot/curvedLines.js"></script>
    <!-- jVectorMap -->
    <script src="<?php echo base_url(); ?>assets/js/maps/jquery-jvectormap-2.0.3.min.js"></script>
    <!-- bootstrap-daterangepicker -->
    <script src="<?php echo base_url(); ?>assets/js/moment/moment.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/js/datepicker/daterangepicker.js"></script>

    <!-- Custom Theme Scripts -->
    <script src="<?php echo base_url(); ?>assets/build/js/custom.min.js"></script>

    <!-- Datatables -->
    <script src="<?php echo base_url(); ?>assets/vendors/datatables.net/js/jquery.dataTables.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/datatables.net-bs/js/dataTables.bootstrap.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/datatables.net-buttons/js/dataTables.buttons.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/datatables.net-buttons-bs/js/buttons.bootstrap.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/jszip/dist/jszip.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/pdfmake/build/pdfmake.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/pdfmake/build/vfs_fonts.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/datatables.net-buttons/js/buttons.flash.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/datatables.net-buttons/js/buttons.html5.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/datatables.net-buttons/js/buttons.print.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/datatables.net-fixedheader/js/dataTables.fixedHeader.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/datatables.net-keytable/js/dataTables.keyTable.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/datatables.net-responsive/js/dataTables.responsive.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/datatables.net-responsive-bs/js/responsive.bootstrap.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/datatables.net-scroller/js/datatables.scroller.min.js"></script>
    
    <script  src="<?php echo base_url(); ?>assets/js/notify.js"></script>
    
    <!-- Form Validator-->
     
     <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-show-password/1.0.3/bootstrap-show-password.min.js"></script>

    <script type="text/javascript" src="<?php echo base_url(); ?>assets/js/bootstrapValidator.js"></script>
<!-- Form Validator-->
  <link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/bootstrapValidator.css"/>


    <!-- Datatables -->
   
   <script>
  var check = function() {
  if (document.getElementById('password').value ==
    document.getElementById('password2').value) {
    document.getElementById('message').style.color = 'green';
    document.getElementById('message').innerHTML = 'Password Matched';
  } else {
    document.getElementById('message').style.color = 'red';
    document.getElementById('message').innerHTML = 'Password Not Matched';
  }
}
</script>
    
<script>

$(document).ready(function(){
         
            $(document).ajaxStart(function() {
                $('#ajaxload').show();
            });
            
        // $('#datatable-buttons').DataTable();
   $.ajax({
    url: '<?php echo base_url(); ?>admin/fetch_user/',data: {},
         success: function (result) {
            
      $(document).ajaxStop(function() {
           $('#ajaxload').hide();
      });
        
        
             console.log(result);
              $("#datatable-buttons").dataTable().fnDestroy();
               setTimeout(function(){
               
               $("tbody.center").html(result);
                $("#datatable-buttons").DataTable({
                dom: "lBfrtip",
              "bPaginate": true,
              "pageLength":35,
              "lengthMenu": [[35, 70, 100, -1], [35, 70, 100, "All"]],
               
             buttons: [
                 {
                  extend: "print",
                  className: "btn-sm",
                   exportOptions: {
                       <?php  if($this->user_model->is_super()){ ?>
                        columns: [0,1,2,3,4,5,6,7],
                       <?php }else{?>
                       columns: [0,1,2,3,4,5,6],
                       <?php }?>
                        modifier: {
                            selected: true
                        }
                    }
                },
                {
                  extend: "copy",
                  className: "btn-sm",
                  exportOptions: {
                       <?php  if($this->user_model->is_super()){ ?>
                        columns: [0,1,2,3,4,5,6,7],
                       <?php }else{?>
                       columns: [0,1,2,3,4,5,6],
                       <?php }?>
                        modifier: {
                            selected: true
                        }
                    }
                },
                {
                  extend: "csv",
                  className: "btn-sm",
                  exportOptions: {
                       <?php  if($this->user_model->is_super()){ ?>
                        columns: [0,1,2,3,4,5,6,7],
                       <?php }else{?>
                       columns: [0,1,2,3,4,5,6],
                       <?php }?>
                        modifier: {
                            selected: true
                        }
                    }
                },
                {
                  extend: "excel",
                  className: "btn-sm",
                  exportOptions: {
                       <?php  if($this->user_model->is_super()){ ?>
                        columns: [0,1,2,3,4,5,6,7],
                       <?php }else{?>
                       columns: [0,1,2,3,4,5,6],
                       <?php }?>
                        modifier: {
                            selected: true
                        }
                    }
                },
                {
                extend: 'pdfHtml5',
                className: "btn-sm",
                title: '',
                exportOptions: {
                       <?php  if($this->user_model->is_super()){ ?>
                        columns: [0,1,2,3,4,5,6,7],
                       <?php }else{?>
                       columns: [0,1,2,3,4,5,6],
                       <?php }?>
                        modifier: {
                            selected: true
                        }
                    }
                },
              ],
              responsive: true
            });
            },500);
           }
     });//end ajax for loading form


});
</script>
    
<script>
       $(document).ready(function() {
        $("#add_cls").click(function(event){
            $("h2").html("Add User");
         $('#def').show();
         $('#hide_cls').show();
         $('#add_cls').hide();
         $('#pass').show();
         $('#pass1').show();
         $('#pass').val("");
         $('#pass1').val("");
         $("#uper_clearfix").hide();
         
        });
        });
</script>
    
<script>
       $(document).ready(function() {
        $("#hide_cls").click(function(event){
            $("h2").html("View Users");
         $('#def').hide();
         $('#hide_cls').hide();
          $("#uper_clearfix").show();
         $('#add_cls').show();
         $("#fname").val("");
         $("#lname").val("");
         $("#email").val("");
         $("#username").val("");
         $("#password").val("");
         $("#password2").val("");
         $("#number").val("");
        });
        });
</script>
    
    
<script type="text/javascript">
    $(document).ready(function() {
        $('#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: {
                    password: {
                validators: {
                    identical: {
                        field: 'confirmPassword',
                        message: 'The password and its confirm are not the same'
                    }
                }
            },
            confirmPassword: {
                validators: {
                    identical: {
                        field: 'password',
                        message: 'The password and its confirm are not the same'
                    }
                }
            },
            lname: {
                        trigger:'change keyup',
                        validators: {
                             regexp: {
                                 regexp: /^[a-z\s]+$/i,
                                     message: 'The last name can consist of alphabetical characters and spaces only'
                              }
                        }
                    },
            username: {
                        trigger:'change keyup',
                        validators: {
                             regexp: {
                                 regexp: /^[a-z\s]+$/i,
                                     message: 'The full name can consist of alphabetical characters and spaces only'
                              }
                        }
                    },        
            fname: {
                        trigger:'change keyup',
                        validators: {
                            regexp: {
                                 regexp: /^[a-z\s]+$/i,
                                     message: 'The full name can consist of alphabetical characters and spaces only'
                              }
                        }
                    },
                    
            contact: {
                        validators: {
                                 
                                    }
                                },

                    'phone[]': {
                      
                    trigger:'blur',
                validators: {
                    
                         stringLength: {
                            min: 13,
                            max: 13,
                            message: 'The phone numbe   r must be mobile number'
                        }
                }
            },
                
                   
                }
            });
    });
    
$("#zzz").click(function(){
   $('#routePermit').bootstrapValidator("resetForm",true);    
});

</script>

<script>
   $(document).ready(function() { 
    $("#new_type").click(function(event){
  event.preventDefault();
   $('#def').hide();
 $('#hide_cls').hide();
 $('#add_cls').show();
 
  var value=$("#new_type").val();
  var fname=$("#fname").val();
  var lname=$("#lname").val();
  var email=$("#email").val();
  var username=$("#username").val();
  var password=$("#password").val();
  var password2=$("#password2").val();
  var number=$("#number").val();
  
  
if(fname=="" || lname=="" || email=="" || username=="" || password=="" || password2=="" || number=="")
  {
    $.notify("Please Fill The Fields..", "danger");
    $('#def').show();
 $('#hide_cls').show();
 $('#add_cls').hide();
    return false;
    
  }
 if(password == password2){
   var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
if(re.test(email))
{
if(value=="Add")
{
     
      $(document).ajaxStart(function() {
                $('#ajaxload').show();
            });
$.ajax({
    type:'POST',
 url:'<?php echo base_url();?>admin/saveUser',
 data:{fname:fname,lname:lname,email:email,username:username,password:password,password2:password2,number:number},
 
        success: function (result) {
             $(document).ajaxStop(function() {
                $('#ajaxload').hide();
            });
            
   $.notify("Successfully Added..", "success");


          /*  $("#success_msg").fadeIn().html("Successfully Added...");
             setTimeout(function(){
                $("#success_msg").fadeOut('slow');
            },5000);*/
           $("#datatable-buttons").dataTable().fnDestroy();
           setTimeout(function(){
               
        $("tbody.center").html(result);
            $('#datatable-buttons').DataTable({
              dom: "lBfrtip",
              "bPaginate": true,
              "pageLength":35,
              "lengthMenu": [[35, 70, 100, -1], [35, 70, 100, "All"]],
               
             buttons: [
                {
                  extend: "copy",
                  className: "btn-sm",
                  exportOptions: {
                       <?php  if($this->user_model->is_super()){ ?>
                        columns: [0,1,2,3,4,5,6,7],
                       <?php }else{?>
                       columns: [0,1,2,3,4,5,6],
                       <?php }?>
                        modifier: {
                            selected: true
                        }
                    }
                },
                {
                  extend: "csv",
                  className: "btn-sm",
                  exportOptions: {
                       <?php  if($this->user_model->is_super()){ ?>
                        columns: [0,1,2,3,4,5,6,7],
                       <?php }else{?>
                       columns: [0,1,2,3,4,5,6],
                       <?php }?>
                        modifier: {
                            selected: true
                        }
                    }
                },
                {
                  extend: "excel",
                  className: "btn-sm",
                  exportOptions: {
                       <?php  if($this->user_model->is_super()){ ?>
                        columns: [0,1,2,3,4,5,6,7],
                       <?php }else{?>
                       columns: [0,1,2,3,4,5,6],
                       <?php }?>
                        modifier: {
                            selected: true
                        }
                    }
                },
                {
                 extend: "pdfHtml5",
                  className: "btn-sm",
                  exportOptions: {
                       <?php  if($this->user_model->is_super()){ ?>
                        columns: [0,1,2,3,4,5,6,7],
                       <?php }else{?>
                       columns: [0,1,2,3,4,5,6],
                       <?php }?>
                        modifier: {
                            selected: true
                        }
                    }
          
                
                },
                {
                    extend: "print",
                    className: "btn-sm",
                   exportOptions: {
                       <?php  if($this->user_model->is_super()){ ?>
                        columns: [0,1,2,3,4,5,6,7],
                       <?php }else{?>
                       columns: [0,1,2,3,4,5,6],
                       <?php }?>
                        modifier: {
                            selected: true
                        }
                    }
                 
                },
              ],
              responsive: true
            });
            },500);
            
           
            
           }
    });
$("#new_type").val("Add");
 $("#fname").val("");
 $("#lname").val("");
 $("#email").val("");
 $("#username").val("");
 $("#password").val("");
 $("#password2").val("");
 $("#number").val("");
 $("#uper_clearfix").show();
}
else if(value=="Update")
{
  var value=$("#new_type").val();
  var id=$("#edit_id").val();
  var fname=$("#fname").val();
  var lname=$("#lname").val();
  var email=$("#email").val();
  var username=$("#username").val();
 /*var password=$("#password").val();
  var password2=$("#password2").val();*/
  var number=$("#number").val();

   $.ajax({
     type:'POST', 
    url:'<?php echo base_url()?>admin/up_user',
    data:{id:id,fname:fname,lname:lname,email:email,username:username,number:number},
    success: function (result) {
        $.notify("Successfully Updated..", "success");
           $("#datatable-buttons").dataTable().fnDestroy();
           setTimeout(function(){ 
                $("tbody.center").html(result);
            $('#datatable-buttons').DataTable({
               dom: "lBfrtip",
              "bPaginate": true,
              "pageLength":35,
              "lengthMenu": [[35, 70, 100, -1], [35, 70, 100, "All"]],
              buttons: [
                {
                  extend: "copy",
                  className: "btn-sm"
                },
                {
                  extend: "csv",
                  className: "btn-sm",
                   exportOptions: {
                       <?php  if($this->user_model->is_super()){ ?>
                        columns: [0,1,2,3,4,5,6,7],
                       <?php }else{?>
                       columns: [0,1,2,3,4,5,6],
                       <?php }?>
                        modifier: {
                            selected: true
                        }
                    }
                },
                {
                  extend: "excel",
                  className: "btn-sm",
                   exportOptions: {
                       <?php  if($this->user_model->is_super()){ ?>
                        columns: [0,1,2,3,4,5,6,7],
                       <?php }else{?>
                       columns: [0,1,2,3,4,5,6],
                       <?php }?>
                        modifier: {
                            selected: true
                        }
                    }
                },
                {
                  extend: "pdfHtml5",
                  className: "btn-sm",
                   exportOptions: {
                       <?php  if($this->user_model->is_super()){ ?>
                        columns: [0,1,2,3,4,5,6,7],
                       <?php }else{?>
                       columns: [0,1,2,3,4,5,6],
                       <?php }?>
                        modifier: {
                            selected: true
                        }
                    }
                },
                {
                  extend: "print",
                  className: "btn-sm",
                   exportOptions: {
                       <?php  if($this->user_model->is_super()){ ?>
                        columns: [0,1,2,3,4,5,6,7],
                       <?php }else{?>
                       columns: [0,1,2,3,4,5,6],
                       <?php }?>
                        modifier: {
                            selected: true
                        }
                    }
                },
              ],
              responsive: true
            });
            },500);
           }
  });
  $("#new_type").val("Add");
 $("#fname").val("");
 $("#lname").val("");
 $("#email").val("");
 $("#username").val("");
 $("#password").val("");
 $("#password2").val("");
 $("#number").val("");
 $("#uper_clearfix").show();
}
}
else
{
    $.notify("Please Fill The Correct Email Field..", "danger");
    $('#def').show();
 $('#hide_cls').show();
 $('#add_cls').hide();
    return false;    
}
}
else
{
   $.notify("Password Does Not Match..", "danger");
    $('#def').show();
 $('#hide_cls').show();
 $('#add_cls').hide();
    return false;      
}
});//end if for button type checking
});
</script>
<script>
function edit(id,event){
    $("h2").html("Update User");
     $("#msg").css("display", "none");
    document.getElementById("new_type").disabled = false;
    
  event.preventDefault();
  $.ajax({
     url: '<?php echo base_url(); ?>admin/get_record/'+id,
         success: function (result)
          { 
           //$(e.target).data('bootstrapValidator').getInvalidFields()
            var obj=JSON.parse(result);
            $("#edit_id").val(obj.id);
           $("#fname").val(obj.first_name);
            $("#lname").val(obj.last_name);
            $('#username').attr("data-id",obj.id);
            $("#username").val(obj.username);
            $("#email").val(obj.email);
            $("#number").val(obj.contact_no);
            $("#new_type").val("Update");
            $("#pass").hide();
            $("#pass1").hide();
             $('#def').show();
             $("#password").val(1);
             $("#password2").val(1);
           $('#hide_cls').show();
        $('#add_cls').hide();
        $("#uper_clearfix").hide();
         $('html, body').animate({
        scrollTop: $("#def").offset().top
    }, 2000);
            //$("tbody.center").html(result);
            }
      });
}
</script>   


<script>
function myFunction() {
     val=$('#username').val();
     id = $('#username').attr('data-id');
     if(id){
       $.ajax({
         url: '<?php echo base_url(); ?>admin/check_useredit/'+id+'/'+val,
        data: {},
        success: function (res) {
                            if(res == 1)
                            {
                             //alert("Already exists");
                             
                            $("#msg").css("display", "block");
                            document.getElementById("new_type").disabled = true;
                           
                            }
                             else{
                             //alert("You can add class");
                             $("#msg").css("display", "none");
                             document.getElementById("new_type").disabled = false;
                             }
                    },
                     error: function(){
                                        alert("failure");
                                    }
                });
    
     }else{
         $.ajax({
         url: '<?php echo base_url(); ?>admin/check_user/'+val,
        data: {},
        success: function (res) {
                            if(res == 1)
                            {
                             //alert("Already exists");
                             
                            $("#msg").css("display", "block");
                            document.getElementById("new_type").disabled = true;
                           
                            }
                             else{
                             //alert("You can add class");
                             $("#msg").css("display", "none");
                             document.getElementById("new_type").disabled = false;
                             }
                    },
                     error: function(){
                                        alert("failure");
                                    }
                });
    
     }
     //alert($val);
    
}
</script>



<script>

function delete_user(id,event){
   
  event.preventDefault();
  $.ajax({
     url: '<?php echo base_url(); ?>admin/delete_user/'+id,
         success: function (result) {
             console.log(result);
              $("#datatable-buttons").dataTable().fnDestroy();
               setTimeout(function(){
               
               $("tbody.center").html(result);
                $('#datatable-buttons').DataTable({
               dom: "lBfrtip",
              "bPaginate": true,
              "pageLength":35,
              "lengthMenu": [[35, 70, 100, -1], [35, 70, 100, "All"]],
              buttons: [
                {
                  extend: "copy",
                  className: "btn-sm",
                   exportOptions: {
                       <?php  if($this->user_model->is_super()){ ?>
                        columns: [0,1,2,3,4,5,6,7],
                       <?php }else{?>
                       columns: [0,1,2,3,4,5,6],
                       <?php }?>
                        modifier: {
                            selected: true
                        }
                    }
                },
                {
                  extend: "csv",
                  className: "btn-sm",
                   exportOptions: {
                       <?php  if($this->user_model->is_super()){ ?>
                        columns: [0,1,2,3,4,5,6,7],
                       <?php }else{?>
                       columns: [0,1,2,3,4,5,6],
                       <?php }?>
                        modifier: {
                            selected: true
                        }
                    }
                },
                {
                  extend: "excel",
                  className: "btn-sm",
                   exportOptions: {
                       <?php  if($this->user_model->is_super()){ ?>
                        columns: [0,1,2,3,4,5,6,7],
                       <?php }else{?>
                       columns: [0,1,2,3,4,5,6],
                       <?php }?>
                        modifier: {
                            selected: true
                        }
                    }
                },
                {
                  extend: "pdfHtml5",
                  className: "btn-sm",
                   exportOptions: {
                       <?php  if($this->user_model->is_super()){ ?>
                        columns: [0,1,2,3,4,5,6,7],
                       <?php }else{?>
                       columns: [0,1,2,3,4,5,6],
                       <?php }?>
                        modifier: {
                            selected: true
                        }
                    }
                },
                {
                  extend: "print",
                  className: "btn-sm",
                   exportOptions: {
                       <?php  if($this->user_model->is_super()){ ?>
                        columns: [0,1,2,3,4,5,6,7],
                       <?php }else{?>
                       columns: [0,1,2,3,4,5,6],
                       <?php }?>
                        modifier: {
                            selected: true
                        }
                    }
                },
              ],
              responsive: true
            });
            },500);
           }
      });
}
</script>   

    <script>
    $(document).on("keypress",".abc", function (event) {

            var englishAlphabetAndWhiteSpace = /[A-Za-z ]/g;


            var key = String.fromCharCode(event.which);


            if (event.keyCode == 8 || event.keyCode == 9 || event.keyCode == 37 || event.keyCode == 39 || englishAlphabetAndWhiteSpace.test(key)) {
                return true;
            }
            return false;
        });

         
        $(document).on("keypress",".abc1", function (event) {

            var englishAlphabetAndWhiteSpace = /[A-Za-z0-9|-]/g;


            var key = String.fromCharCode(event.which);


            if (event.keyCode == 8 || event.keyCode == 9 || event.keyCode == 32 || event.keyCode == 37 || event.keyCode == 39 || englishAlphabetAndWhiteSpace.test(key)) {
                return true;
            }


            return false;
        });
         //form only numbers
        $(".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>
   /* window.setTimeout(function() {
  $(".alert").fadeTo(500, 0).slideUp(500, function(){
      $(this).remove(); 
  });
  }, 2000);*/
</script>
    
  </body>
</html>