
<main class="main-content bgc-grey-100">
          <div id="mainContent">
            <div class="row gap-20 masonry pos-r">
              <div class="masonry-sizer col-md-6"></div>
              <div class="masonry-item col-md-12" style="position: absolute; left: 0%; top: 832px;">
                <div class="bgc-white p-20 bd">
                  <h6 class="c-grey-900">Profile</h6>
                  <div class="mT-30">
                    <div class="alert alert-success LoginSuccMsg" style="display: none;">
                      <strong>Password successfully changed!</strong>
                    </div>
                     <div class="alert alert-danger LoginFailedMsg" style="display: none;">
                        <strong> New password and Confirm password aren't same!</strong>
                      </div>
                    <form class="form" id="ChangePass">
                      <div class="row">
                        <div class="col-md-12 mb-3"><label for="validationCustom01">Username</label><input type="text" class="form-control" value=" <?php echo $this->session->userdata('admin_user_id'); ?>" readonly></div>
                        <div class="col-md-12 mb-3"><label for="validationCustom01">Name</label><input type="text" class="form-control" value="<?php echo $this->session->userdata('admin_name'); ?>" required name="full_name"></div>
                        
                        <div class="col-md-4 mb-3"><label for="validationCustom02"> Old Password</label><input type="password" name="old" class="form-control" id="old" onchange="checkPass()" placeholder="Enter Old Password" required><div id="old_e"></div></div>
                        <div class="col-md-4 mb-3">
                          <label for="validationCustom03">New Password</label><input type="password" name="new" class="form-control" id="new" placeholder="Enter New Password" required="">
                        </div>
                        <div class="col-md-4 mb-3">
                          <label for="validationCustom04">Confirm New Password</label><input type="password" name="newC" class="form-control" id="newC" placeholder="Confirm New Password" required="">
                        </div>
                        
                        <!-- <div class="col-md-12">
                          <div class="form-group">
                            <div class="checkbox checkbox-circle checkbox-info peers ai-c"><input type="checkbox" id="inputCall2" name="inputCheckboxesCall" class="peer"><label for="inputCall2" class="peers peer-greed js-sb ai-c"><span class="peer peer-greed">Call John for Dinner</span></label></div>
                          </div>
                        </div> -->
                        
                      </div>
                      <button class="btn btn-primary" type="submit">Submit</button>
                    </form>
                  </div>
                </div>
              </div>
              
            </div>
          </div>
        </main>
<script src="https://code.jquery.com/jquery-1.9.1.js"></script>
<link rel="stylesheet" href="<?php echo base_url();?>css/site-demos.css">
<script src="<?php echo base_url();?>js/jquery.validate.min.js"></script>
<script src="<?php echo base_url();?>js/additional-methods.min.js"></script>
<script type="text/javascript">
function checkPass(){
  var old = $("#old").val();

  var url = "<?php echo base_url() ?>ChangePassword/check";

  $.ajax({

    url: url,
    method: "post",
    data:{
      old: old
    },

    success: function(res){

      if(res == 'false'){
        $("#old_e").html('<span style="color: red;margin: 0;">Password didn\'t match.</span>');
        $("#old_e").attr("class", "has-error");
        $("#old").attr("class", "form-control error");

      } else if(res == 'true'){
        $("#old_e").html('');
        $("#old_e").attr("class", "has-success");
        $("#old").attr("class", "form-control has-success")
      }
    }

  });

}
</script>
<script>
// just for the demos, avoids form submit
jQuery.validator.setDefaults({
success: "valid"
});
$( "#ChangePass" ).validate({
rules: {
}
});
</script>
<script>
$(document).ready(function(e){
    $("#ChangePass").on('submit', function(e){
        e.preventDefault();
        var formStatus = $('#ChangePass').validate().form();
        if(true == formStatus){
        $.ajax({
            type: 'POST',
            url: '<?php echo base_url(); ?>ChangePassword/update',
            data: new FormData(this),
            contentType: false,
            cache: false,
            processData:false,
            beforeSend: function(){
                $('.login_button').attr("disabled","disabled");
                $('#ChangePass').css("opacity",".5");
            },
            success: function(msg){
                if(msg=='failed'){
                  $(".LoginFailedMsg").show();
                  $('.LoginFailedMsg').delay(5000).hide(500);
                  $('#ChangePass').css("opacity","");
                  $(".login_button").removeAttr("disabled");
               }
               else{
                  $(".LoginSuccMsg").show();
                  $('.LoginSuccMsg').delay(3000).hide(300);
                  $('#ChangePass').css("opacity","");
                  $(".login_button").removeAttr("disabled");
                   setInterval(function(){ 
                  location.reload();
                  }, 3000);
               }
            }
        });
        }
    });
});
</script>