<?php 

function change_password_cb() {
	global $post_meta;
	$args = ['label' => '', 'id' => 'password', 'placeholder' => 'New Password', 'required' => 'required', 'type' => 'password'];
	$password_rules = get_option("password_rules");
	if($password_rules) {
		if(in_array("numeric", $password_rules)) {
			$args['data-numeric'] = true;
		}
		if(in_array("lowercase", $password_rules)) {
			$args['data-lower-case'] = true;
		}
		if(in_array("uppercase", $password_rules)) {
			$args['data-upper-case'] = true;
		}
		if(in_array("specialchar", $password_rules)) {
			$args['data-special-char'] = true;
		}
	}
	if($option = get_option("min_password_length")) {
		$args['data-password-len'] = $option;
	}
	?>
	<div class="row">
		<div class="col-md-8">
			<div class="panel panel-custom bg-white">
			    <div class="panel-heading">
			        <h1>Change Password</h1>
			    </div>
		        <div class="panel-body instruction">
		        	<form method="post" id="form" action="contents/plugins/password_api/ajax.php">
		        		<?php 
		        		input(['label' => '', 'id' => 'current_password', 'placeholder' => 'Old Password', 'type' => 'password']);
			            input($args);
			            input(['label' => '', 'id' => 'c_password', 'placeholder' => 'Repeat Password', 'required' => 'required', 'type' => 'password']);
			            alert(); submit_btn('change_password', 'Submit', 'submit');
		        		 ?>
		        	</form>
				</div>
			</div>
		</div>
		<div class="col-md-4">
			<?php do_action("right_column"); ?>
		</div>
	</div>
		
	<?php
	$post_meta['plugin_name'] = password_api::$plugin_name;
	add_page_javascript('app/assets/js/page-scripts/koweb.js');
	add_page_javascript('app/assets/js/page-scripts/submit.js');
}

function change_password2_cb() {
	$session = Session::getInstance();
	global $post_meta;
	if(!isset($_GET['authe']))
		return_method();

	$authe = $_GET['authe'];
	$user = new user;
	$umeta = $user->get_user_meta($session->id);
	if($authe === $umeta['authe'] && $umeta['authe'] != '') :
		$args = ['label' => 'New Password', 'id' => 'password', 'required' => 'required', 'type' => 'password'];
		$password_rules = get_option("password_rules");
		if($password_rules) {
			if(in_array("numeric", $password_rules)) {
				$args['data-numeric'] = true;
			}
			if(in_array("lowercase", $password_rules)) {
				$args['data-lower-case'] = true;
			}
			if(in_array("uppercase", $password_rules)) {
				$args['data-upper-case'] = true;
			}
			if(in_array("specialchar", $password_rules)) {
				$args['data-special-char'] = true;
			}
		}
		if($option = get_option("min_password_length")) {
			$args['data-password-len'] = $option;
		}
		?>
		<div class="row">
			<div class="col-md-4">
				<form id="form" method="post" action="contents/plugins/password_api/ajax.php">
					<?php 
						input($args);
						input(['label' => 'Retype Password', 'id' => 'retype_password', 'type' => 'password', 'required' => 'required']);
						alert();
						submit_btn('change_password2', 'Save');
					 ?>
				</form>
			</div>
		</div>
		<?php
	else:
		echo '<script>window.location = "logout.php"; </script>';
	endif;
	add_page_javascript('app/assets/js/page-scripts/submit.js');
}

function change_user_password_cb() {
	if(!isset($_GET['id'])) return_method();
	global $post_meta;
	$args = ['label' => 'New Password', 'id' => 'password', 'required' => 'required', 'type' => 'password'];
	$password_rules = get_option("password_rules");
	if($password_rules) {
		if(in_array("numeric", $password_rules)) {
			$args['data-numeric'] = true;
		}
		if(in_array("lowercase", $password_rules)) {
			$args['data-lower-case'] = true;
		}
		if(in_array("uppercase", $password_rules)) {
			$args['data-upper-case'] = true;
		}
		if(in_array("specialchar", $password_rules)) {
			$args['data-special-char'] = true;
		}
	}
	if($option = get_option("min_password_length")) {
		$args['data-password-len'] = $option;
	}
	?>
	<div class="col-md-4">
		<form id="form" method="post" action="contents/plugins/password_api/ajax.php">
			<input type="hidden" name="user_id" id="user_id" value="<?php echo $_GET['id'] ?>">
			<?php 
				input($args);
				input(['label' => 'Retype Password', 'id' => 'retype_password', 'type' => 'password', 'required' => 'required']);
				submit_btn('change_user_password', 'Save');
			 ?>
		</form>
	</div>

	<?php
	add_page_javascript('app/assets/js/page-scripts/submit.js');
}