<?php 


if(isset($_POST['submit'])) {
	
	if(isset($_POST['re_password']) && strlen($_POST['re_password'])>0) {
		$re_password = trim($_POST['re_password']);
		if(isset($_POST['password']) && strlen($_POST['password'])>0) {
			if($re_password == $_POST['password']){
				//ok
			} else {
				$error = 'Password mis-match error!';
			}
		}
	} else {
		$error = 'Please re-enter Password';
	}
	
	if(isset($_POST['password']) && strlen($_POST['password'])>0) {
		$password = trim($_POST['password']);
		if(strlen($password)<5){
			$error = 'Password should contain a minimum of 5 chars.';
		}
	} else {
		$error = 'Please enter Password';
	}
	
	if(isset($_POST['cur_password']) && strlen($_POST['cur_password'])>0) {
		$cur_password = trim($_POST['cur_password']);
		$cur_passwordDb = md5($cur_password);
		$curAdminId = trim($_SESSION['adminId']);
		$chkRs = mysqli_query($con, "SELECT admin_id FROM tbl_admin WHERE ad_password = '".$cur_passwordDb."' AND admin_id = '".$curAdminId."'");
		if(mysqli_num_rows($chkRs)>0){
			//ok user exists
		} else {
			$error = 'Current password is not correct. Try again';
		}
	} else {
		$error = 'Please enter current Password';
	}
			

	if(empty($error)) {
		$password = md5($password);
		$update = mysqli_query($con, "UPDATE tbl_admin SET ad_password = '".$password."' WHERE admin_id = '".$_SESSION['adminId']."'");
		if($update){
			$success = 'Your password has been changed';
		}
		?><script language="javascript">
		//window.location='index.php?page=manage_admin';
		</script><?php
	}      
}



?>