<?php
require_once __DIR__ . '/security.php';

$tenant = enrep_tenant_segment();
if ($tenant !== '' && file_exists('../../' . $tenant . '/config.php')) {
    require_once('../../' . $tenant . '/config.php');
}
if (file_exists('/config.php')) {
    require_once('/config.php');
}

if (!isset($GLOBALS['con']) || !($GLOBALS['con'] instanceof mysqli)) {
    enrep_fail(400, 'Tenant config not found');
}
enrep_require_user();

$item = enrep_request_int('item');
$notes = enrep_request_string('notes', '', 65000);

if ($item < 1) {
    enrep_fail(400, 'Invalid item');
}

$stmt = $GLOBALS['con']->prepare("UPDATE `itemdetails` SET `itemnotes`=? WHERE `itemnumber`=?") or die(mysqli_error($GLOBALS['con']));
$stmt->bind_param('si', $notes, $item);
$stmt->execute();
$stmt->close();

echo 'success';
