<?php
if (file_exists('/config.php')) {
    require_once('/config.php');
}
if (file_exists('../../../' . $_REQUEST['tenant'] . '/config.php')) {
    require_once('../../../' . $_REQUEST['tenant'] . '/config.php');
}

require('../../includes/master/form_functions.php');
$stmt = $GLOBALS['con']->prepare("SELECT * FROM `itemdetails` WHERE `itemnumber`=?") or die(mysqli_error($GLOBALS['con']));
$stmt->bind_param('i', $_REQUEST['itemnumber']);
$stmt->execute();
$rc = $stmt->get_result();
$stmt->close();
$cd = mysqli_fetch_array($rc); ?>
<form id="itemEditForm">
    <div class="row mb-2">
        <div class="bg-white rounded">
            <table class="table table-striped table-sm table-hover w-100 rounded">
                <tr>
                    <th><strong>Description</strong></th>
                    <td><input type="text" class="form-control" name="desc" value="<?= $cd['desc'] ?>" readonly></td>
                    <th><strong>Date of Manufacture</strong></th>
                    <td><input type="text" class="form-control" name="dateofmanf" value="<?php if ($cd['dateofmanf'] == "") {
                                                                                                echo "Not Known";
                                                                                            } else {
                                                                                                echo $cd['dateofmanf'];
                                                                                            } ?>"></td>
                </tr>
                <tr>
                    <th><strong>Plant Number</strong></th>
                    <td><input type="text" class="form-control" name="plantnumber" value="<?= $cd['plantnumber'] ?>">
                    </td>
                    <th><strong>Model</strong></th>
                    <td><input type="text" class="form-control" name="model" value="<?= $cd['model'] ?>"></td>
                </tr>
                <tr>
                    <th><strong>Serial</strong></th>
                    <td><input type="text" class="form-control" name="serialnumber" value="<?= $cd['serialnumber'] ?>">
                    </td>
                    <th><strong>Location</strong></th>
                    <td><?= getSites2($cd['clientnumber'], $cd['locnumber']) ?></td>
                </tr>
                <tr>
                    <th><strong>Manufacturer</strong></th>
                    <td><input type="text" class="form-control" name="manf" value="<?= $cd['manf'] ?>"></td>
                    <th><strong>Location on site</strong></th>
                    <td><input type="text" class="form-control" name="subloc" value="<?= $cd['subloc'] ?>"></td>
                </tr>
                <tr>
                    <th><strong>SWL</strong></th>
                    <td><input type="text" class="form-control" name="swl" value="<?= $cd['swl'] ?>"></td>
                    <th></th>
                    <td></td>
                </tr>
            </table>
        </div>
    </div>
    <div class="row mt-2">
        <div class="text-center mt-3">
            <button type="submit" class="btn btn-info btn-sm me-4">Save Changes</button>
            <button type="button" onclick="cancelEdit()" class="btn btn-danger btn-sm">Cancel</button>
        </div>
    </div>
    <input type="hidden" name="FUNCTION" id="FUNCTION" value="update_item_details" />
    <input type="hidden" name="itemnumber" id="itemnumber" value="<?= $_REQUEST['itemnumber'] ?>" />
    <input type="hidden" name="tenant" id="tenant" value="<?= TENANT_URL ?>" />
</form>