<?php
/**
 * Dashboard - Doctor Password
 */

defined( 'ABSPATH' ) || exit;

global $doctor, $wp;

$nonce = isset( $_POST['docpro_pw_nonce_val'] ) ? sanitize_text_field( $_POST['docpro_pw_nonce_val'] ) : '';

if ( wp_verify_nonce( $nonce, 'docpro_pw_nonce' ) ) {

	$old_password     = isset( $_POST['old_password'] ) ? sanitize_text_field( $_POST['old_password'] ) : '';
	$new_password     = isset( $_POST['new_password'] ) ? sanitize_text_field( $_POST['new_password'] ) : '';
	$confirm_password = isset( $_POST['confirm_password'] ) ? sanitize_text_field( $_POST['confirm_password'] ) : '';
	$current_url      = isset( $_POST['current_url'] ) ? sanitize_text_field( $_POST['current_url'] ) : '';

	if ( wp_check_password( $old_password, $doctor->user_pass, $doctor->ID ) && $new_password == $confirm_password ) {
		wp_set_password( $new_password, $doctor->ID );

		wp_safe_redirect( $current_url );
		exit();
	}
}


?>

<div class="add-listing change-password">
    <form action="<?php echo esc_url( site_url( $wp->request ) ); ?>" method="post">
        <div class="single-box">
            <div class="title-box">
                <h3><?php esc_html_e( 'Change Password', 'docpro' ); ?></h3>
            </div>
            <div class="inner-box">
                <div class="row clearfix">
                    <div class="col-lg-6 col-md-12 col-sm-12 form-group">
                        <label><?php esc_html_e( 'Old Password', 'docpro' ); ?></label>
                        <input type="password" name="old_password" required="">
                    </div>
                    <div class="col-lg-6 col-md-12 col-sm-12 form-group"></div>
                    <div class="col-lg-6 col-md-12 col-sm-12 form-group">
                        <label><?php esc_html_e( 'New Password', 'docpro' ); ?></label>
                        <input type="password" name="new_password" required="">
                    </div>
                    <div class="col-lg-6 col-md-12 col-sm-12 form-group"></div>
                    <div class="col-lg-6 col-md-12 col-sm-12 form-group">
                        <label><?php esc_html_e( 'Confirm Password', 'docpro' ); ?></label>
                        <input type="password" name="confirm_password" required="">
                    </div>
                    <div class="col-lg-6 col-md-12 col-sm-12 form-group"></div>
                </div>
            </div>
        </div>
        <div class="btn-box">
			<?php wp_nonce_field( 'docpro_pw_nonce', 'docpro_pw_nonce_val' ); ?>
            <input type="hidden" name="current_url" value="<?php echo esc_url( site_url( $wp->request ) ); ?>">
            <button type="submit" class="theme-btn-one"><?php esc_html_e( 'Save Change', 'docpro' ); ?><i class="icon-Arrow-Right"></i></button>
            <button type="reset" class="cancel-btn"><?php esc_html_e( 'Cancel', 'docpro' ); ?></button>
        </div>
    </form>
</div>