<?php
session_start();
include_once("../../../../lib/konfig.php");
include_once("../../../../lib/function.php");
if (isset($_POST['simpan'])) {
	$MySQLi = new MySQLi($strDBHostName, $strDBUsername, $strDBPassword, $strDBName);
	$query = "SELECT * 
			FROM item
			WHERE stsAktif>0 AND 
				  ID='" . $_POST['ID'] . "'
			";
	$result = $MySQLi->query($query);
	if ($result->num_rows == 1) {
		$query = "UPDATE item 
				SET strKdItem='" . $_POST['strKdItem'] . "', 
					strDeskripsi='" . trim(str_replace("'", "`", str_replace('"', '`', $_POST['strDeskripsi']))) . "', 
					strUnit='" . trim(str_replace("'", "`", str_replace('"', '`', $_POST['strUnit']))) . "', 
					usrUpdate='" . $_SESSION['strEmail'] . "', 
					dtUpdate=NOW() 
				WHERE ID='" . $_POST['ID'] . "'
				";
		$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='item', 
						strQuery='" . $strBuffer . "', 
						strKeterangan='" . $_SESSION['strEmail'] . " mengubah barang dengan no ID : " . $_POST['ID'] . "', 
						dtCreate=NOW(), 
						usrCreate='" . $_SESSION['strEmail'] . "' 
					";
			$MySQLi->query($query);
		}
	}
}
header("location:http://" . $strNmDomain . "/home/index.php?menu=master-barang");
// echo '<script type="text/javascript">';
// echo 'alert(\'Data Master User berhasil disimpan \');';
// echo 'location.href = \'index.php?menu=master-barang\';';
// echo '</script>';	
