<?php
include_once("../../../../lib/konfig.php");
include_once("../../../../lib/function.php");
session_start();

$edidbrg = $_POST['edidbrg'];
$edkodebrg = $_POST['edkodebrg'];
$eddeskripsibrg = $_POST['eddeskripsibrg'];
$edunit1brg = $_POST['edunit1brg'];
$edunit2brg = $_POST['edunit2brg'];
$edratio2brg = $_POST['edratio2brg'];
$edunit3brg = $_POST['edunit3brg'];
$edratio3brg = $_POST['edratio3brg'];
$edlokasibrg = $_POST['edlokasibrg'];

$MySQLi = new MySQLi($strDBHostName, $strDBUsername, $strDBPassword, $strDBName);

$query = "SELECT * FROM item WHERE stsAktif>0 AND ID='" . $edidbrg . "';";

$result = $MySQLi->query($query);
if ($result->num_rows == 1) {
    $query = "UPDATE item 
				SET strKdItem='" . $edkodebrg . "', 
					strDeskripsi='" . trim(str_replace("'", "`", str_replace('"', '`', $eddeskripsibrg))) . "', 
					strUnit='" . trim(str_replace("'", "`", str_replace('"', '`', $edunit1brg))) . "', 
                    strUnit2='" . trim(str_replace("'", "`", str_replace('"', '`', $edunit2brg))) . "', 
                    iRatio2=" . $edratio2brg . ", 
                    strUnit2='" . trim(str_replace("'", "`", str_replace('"', '`', $edunit3brg))) . "', 
                    iRatio3=" . $edratio3brg . ", 
                    strItemLoc='" . trim(str_replace("'", "`", str_replace('"', '`', $edlokasibrg))) . "', 
					usrUpdate='" . $_SESSION['strEmail'] . "', 
					dtUpdate=NOW() 
				WHERE ID='" . $edidbrg . "'
				";
    $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 : " . $edidbrg . "', 
						dtCreate=NOW(), 
						usrCreate='" . $_SESSION['strEmail'] . "' 
					";
        $MySQLi->query($query);
    }
}

if ($MySQLi->affected_rows == 1) {
    echo "1";
} else {
    echo "0";
}
