<?php
session_start();
$_SESSION['stsSimpan'] = "";
include_once("../../../../lib/konfig.php");
include_once("../../../../lib/function.php");
if (isset($_POST['simpan']) && isset($_POST['strSandiBaru']) && isset($_POST['strSandiKonfirmasi'])) {
	$MySQLi = new MySQLi($strDBHostName, $strDBUsername, $strDBPassword, $strDBName);
	$query = "SELECT * 
			FROM employee
			WHERE stsAktif=1 AND 
				  Email='" . $_SESSION['strEmail'] . "' AND 
				  strPassword='" . passwd($_POST['strSandiLama']) . "'
			";
	$result = $MySQLi->query($query);
	$strPassword = passwd($_POST['strSandiBaru']);
	if ($result->num_rows == 1 && $_POST['strSandiBaru'] === $_POST['strSandiKonfirmasi']) {
		$query = "UPDATE employee 
				SET strPassword='" . $strPassword . "', 
					usrUpdate='" . $_SESSION['strEmail'] . "', 
					dtUpdate=NOW() 
				WHERE Email='" . $_SESSION['strEmail'] . "'
				";
		$MySQLi->query($query);
		if ($MySQLi->affected_rows == 1) {
			$strBuffer = str_replace("'", "`", str_replace('"', '`', $query));
			$query = "INSERT INTO tpc_log 
					SET strPCHostname='" . gethostbyaddr(getIPv4()) . "', 
						strIPv4='" . getIPv4() . "', 
						strPort='" . $_SERVER['REMOTE_PORT'] . "', 
						strTable='employee', 
						strQuery='" . $strBuffer . "', 
						strKeterangan='" . $_SESSION['strEmail'] . " mengubah mengubah password nya sendiri', 
						dtCreate=NOW(), 
						usrCreate='" . $_SESSION['strEmail'] . "' 
					";
			$MySQLi->query($query);
			$_SESSION['stsSimpan'] = "Password Berhasil diubah";
		}
	} else $_SESSION['stsSimpan'] = "Password Gagal diubah";
} else $_SESSION['stsSimpan'] = "Password Gagal diubah";
//header("location:http://".$strNmDomain."/home/index.php?menu=ubah-sandi");
alertpopup($_SESSION['stsSimpan'], "", "../../?menu=ubah-sandi");
