<?php
$page_title = 'Input Volume Data';
require_once('includes/load.php');
page_require_level(2);

include_once('layouts/header.php');

// Handle form submission for adding volume data
if (isset($_POST['add_volume'])) {
    $volume = $db->escape($_POST['volume']);
    $isi_pcs = (int)$_POST['isi_pcs'];

    // Validate inputs
    if (empty($volume) || $isi_pcs <= 0) {
        $session->msg('d', 'Volume and isi_pcs are required and must be valid.');
    } else {
        $sql = "INSERT INTO volume (volume, isi_pcs) VALUES ('{$volume}', '{$isi_pcs}')";
        if ($db->query($sql)) {
            $session->msg('s', 'Volume data added successfully.');
        } else {
            $session->msg('d', 'Failed to add volume data.');
        }
    }
}
?>

<div class="row">
    <div class="col-md-12">
        <?php echo display_msg($msg); ?>
    </div>
</div>

<div class="row">
    <div class="col-md-6">
        <div class="panel panel-default">
            <div class="panel-heading">
                <strong>
                    <span class="glyphicon glyphicon-plus"></span>
                    <span>Add Volume Data</span>
                </strong>
            </div>
            <div class="panel-body">
                <form method="POST" action="volume_data.php">
                    <div class="form-group">
                        <label for="volume">Volume (e.g., 10.50):</label>
                        <input type="text" name="volume" class="form-control" required>
                    </div>
                    <div class="form-group">
                        <label for="isi_pcs">Isi PCS:</label>
                        <input type="number" name="isi_pcs" class="form-control" required>
                    </div>
                    <button type="submit" name="add_volume" class="btn btn-primary">Add Volume</button>
                </form>
            </div>
        </div>
    </div>
</div>

<?php include_once('layouts/footer.php'); ?>
