<?php
// Include file untuk memuat file yang diperlukan
require_once('includes/load.php');
page_require_level(3); // Memastikan level akses sesuai

// Proses form saat disubmit
if (isset($_POST['add_std_time'])) {
    $part_number  = remove_junk($db->escape($_POST['part_number']));
    $time_filling = remove_junk($db->escape($_POST['time_filling']));
    $time_label   = remove_junk($db->escape($_POST['time_label']));
    $time_seal    = remove_junk($db->escape($_POST['time_seal']));
    $time_packing = remove_junk($db->escape($_POST['time_packing']));
    $time_shrink  = remove_junk($db->escape($_POST['time_shrink']));
    $description  = remove_junk($db->escape($_POST['description']));

    if(empty($errors)){
        $sql  = "INSERT INTO std_time (part_number, time_filling, time_label, time_seal, time_packing, time_shrink, description) ";
        $sql .= "VALUES ('{$part_number}', '{$time_filling}', '{$time_label}', '{$time_seal}', '{$time_packing}', '{$time_shrink}', '{$description}')";
        if($db->query($sql)){
            $session->msg('s',"Data std_time berhasil ditambahkan.");
            redirect('add_std_time.php', false);
        } else {
            $session->msg('d','Maaf, gagal menambahkan data!');
            redirect('add_std_time.php', false);
        }
    } else{
        $session->msg("d", $errors);
        redirect('add_std_time.php',false);
    }
}
?>

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

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

<div class="row">
    <div class="col-md-9">
        <div class="panel panel-default">
            <div class="panel-heading">
                <strong>
                    <span class="glyphicon glyphicon-th"></span>
                    <span>Tambah Data Std Time</span>
                </strong>
            </div>
            <div class="panel-body">
                <form method="post" action="add_std_time.php" class="clearfix">
                    <div class="form-group">
                        <label for="part_number" class="control-label">Part Number</label>
                        <input type="text" class="form-control" name="part_number" placeholder="Product Code" required>
                    </div>
                    <div class="form-group">
                        <label for="time_filling" class="control-label">Time Filling</label>
                        <input type="number" step="0.01" class="form-control" name="time_filling" placeholder="Time Filling" required>
                    </div>
                    <div class="form-group">
                        <label for="time_label" class="control-label">Time Label</label>
                        <input type="number" step="0.01" class="form-control" name="time_label" placeholder="Time Label" required>
                    </div>
                    <div class="form-group">
                        <label for="time_seal" class="control-label">Time Seal</label>
                        <input type="number" step="0.01" class="form-control" name="time_seal" placeholder="Time Seal" required>
                    </div>
                    <div class="form-group">
                        <label for="time_packing" class="control-label">Time Packing</label>
                        <input type="number" step="0.01" class="form-control" name="time_packing" placeholder="Time Packing" required>
                    </div>
                    <div class="form-group">
                        <label for="time_shrink" class="control-label">Time Shrink</label>
                        <input type="number" step="0.01" class="form-control" name="time_shrink" placeholder="Time Shrink" required>
                    </div>
                    <div class="form-group">
                        <label for="description" class="control-label">Deskripsi</label>
                        <textarea class="form-control" name="description" placeholder="Deskripsi" rows="4"></textarea>
                    </div>
                    <div class="form-group clearfix">
                        <button type="submit" name="add_std_time" class="btn btn-primary">Tambah</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

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