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

$stmt = $GLOBALS['con']->prepare("SELECT * FROM `dd_plant` WHERE `id`='".$_REQUEST['id']."'")or die(mysqli_error($GLOBALS['con']));
$stmt->execute();$rslt=$stmt->get_result();
$d=mysqli_fetch_array($rslt);

?>
<form id="editForm">
    <div class="row">
        <div class="col-12 col-md-6 mb-2">
            <span>Code</span>
            <input type="text" class="form-control form-control-sm" aria-label="code" name="code" value="<?= $d['code']?>" />
        </div>
        <div class="col-12 col-md-6 mb-2">
            <span>Description</span>
            <input type="text" class="form-control form-control-sm" aria-label="formtype" name="desc" value="<?= $d['description']?>" />
        </div>
        <div class="col-12 col-md-6 mb-2">
            <span>Frequency</span>
            <input type="text" class="form-control form-control-sm" aria-label="frequency" name="freq" value="<?= $d['frequency']?>" />
        </div>
        <div class="col-12 col-md-6 mb-2">
            <span>Size</span>
            <input type="text" class="form-control form-control-sm" aria-label="size" name="size" value="<?= $d['size']?>" />
        </div>
        <div class="col-12 col-md-6 mb-2">
            <span>IU</span>
            <input type="text" class="form-control form-control-sm" aria-label="units" name="units" value="<?= $d['units']?>" />
        </div>
        <input type="hidden" name="id" value="<?= $d['id']?>">
        <input type="hidden" name="mode" value="plant">
        <input type="hidden" name="tenant" value="<?=TENANT_URL?>">
        <input type="hidden" name="FUNCTION" value="update">
    </div>
    <div class="row">
        <div class="co-12 text-center"><a href="javascript:void(0)" class="btn btn-success" onclick="updateEntry()">Update Entry</a></div>
    </div>
</form>
<script>
function updateEntry() {
    var dest = '<p>Sure you wish to update this entry?</p>'

    loadModalContent(dest, 'updateBox', 'modal-sm', 1070, 'false', 'Confirm Save', 'cancelConfirm', updateItemData)


}

function updateItemData() {

    event.preventDefault();
    $.ajax({
        url: ROOT_URL + '/includes/jump/jump_functions.php',
        type: 'POST',
        data: $('#editForm').serialize(),
        success: function(result) {
            if ($.trim(result) == "s") {
                showResponse('success', 'Your entry has been updated successfully');
                loadItems('plant', 'list', 'pl')
                killModal('updateBox')
                killModal('editBox')
            } else {
                showResponse('danger', 'There was a problem, please check your details and try again')
            }
        }
    });
}
</script>