<?php
$this->load->view ( $left );
$this->load->view ( $header );
?>
<style type="text/css">
    .ibox-content {
        border-style : none;
    }

    .hr-line-dashed {
        margin: 5px 0;
    }
</style>
<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-sm-4">
        <h2>Site Setings</h2>
    </div>
</div>
<div class="wrapper wrapper-content">
    <div class="row text-center animated fadeInRightBig">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
                <form method="post" class="form-horizontal">
                    <div class="ibox-content">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">Current Password</label>
                            <div class="col-sm-10">
                                <input type="text" name="cur-pwd" id="cur-pwd" class="form-control" placeholder="Current Password" value="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">New Password</label>
                            <div class="col-sm-10">
                                <input type="text" name="new-pwd" id="new-pwd" class="form-control" placeholder="New Password" value="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">Re-enter Password</label>
                            <div class="col-sm-10">
                                <input type="text" name="conf-pwd" id="conf-pwd" class="form-control" placeholder="Re-enter Password" value="">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="ibox">
                    <div class="ibox-content">
                        <div class="row">
                            <div class="col-lg-6 pull-right">
                                <div class="form-group">
                                    <div class="col-sm-12 col-sm-offset-2">
                                        <button class="btn btn-primary save_setings" type="button"><span class="m-l-xs">Save Settings</span></button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<?php $this->load->view($footer); ?>
<script type="text/javascript">
    $(document).ready(function(){
        $('.save_setings').on('click',function(){
            if ($('#cur-pwd').val() == '') {
                $('#cur-pwd').parent().parent().addClass('has-error');
                return false;
            } else {
                $('#cur-pwd').parent().parent().removeClass('has-error');
            }

            if ($('#new-pwd').val() == '') {
                $('#new-pwd').parent().parent().addClass('has-error');
                return false;
            } else {
                $('#new-pwd').parent().parent().removeClass('has-error');
            }

            if ($('#conf-pwd').val() == '') {
                $('#conf-pwd').parent().parent().addClass('has-error');
                return false;
            } else {
                $('#conf-pwd').parent().parent().removeClass('has-error');
            }
            var curpwd = $('#cur-pwd').val();
            var newpwd = $('#new-pwd').val();
            var confpwd = $('#conf-pwd').val();
            if (newpwd == confpwd) {
                $.ajax({
                    url: '<?php echo site_url('setings/update_password');?>',
                    type: "POST",
                    data:{
                        'curpwd'   : curpwd,
                        'newpwd'   : newpwd
                    },
                    success: function(data){ 
                        window.location.href = '<?php echo site_url("setings/changepassword");?>';
                    }
                });
            } else {
                $('#new-pwd').parent().parent().addClass('has-error');
                $('#conf-pwd').parent().parent().addClass('has-error');
                return false;
            }
        });
    });
</script>