<?php
$page_title = 'Add Vendor';
require_once('includes/load.php');
page_require_level(3); // Hanya akses untuk level pengguna tertentu (sesuaikan dengan level yang sesuai)

if (isset($_POST['add_vendor'])) {
    $vendor_name = remove_junk($db->escape($_POST['vendor_name']));
    $contact_person = remove_junk($db->escape($_POST['contact_person']));
    $email = remove_junk($db->escape($_POST['email']));
    $phone = remove_junk($db->escape($_POST['phone']));

    $query = "INSERT INTO suppliers (vendor_name, contact_person, email, phone) VALUES ('{$vendor_name}', '{$contact_person}', '{$email}', '{$phone}')";
 if ($db->query($query)) {
    $session->msg('s', "Vendor added successfully.");
    redirect('data_vendor.php');
} else {
    $session->msg('d', 'Error: ' . $db->get_last_error()); // Menampilkan pesan kesalahan
    redirect('data_vendor.php');
}

}
?>

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

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

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