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

$suppliers = find_all('suppliers'); // Gantilah 'suppliers' dengan nama tabel Supplier Anda
?>

<?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-12">
        <div class="panel panel-default">
            <div class="panel-heading clearfix">
                <div class="pull-left">
                    <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#addVendorModal">Add New Vendor</button>
                </div>
            </div>
            <div class="panel-body">
                <!-- Tabel Vendor -->
                <div class="table-responsive">
                    <table class="table table-bordered">
                        <thead>
                            <tr>
                                <th class="text-center">#</th>
                                <th>Vendor Name</th>
                                <th>Contact Person</th>
                                <th>Email</th>
                                <th>Phone</th>
                                <th class="text-center">Actions</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php foreach ($suppliers as $supplier) : ?>
                                <tr>
                                    <td class="text-center"><?php echo count_id(); ?></td>
                                    <td><?php echo remove_junk($supplier['vendor_name']); ?></td>
                                    <td><?php echo remove_junk($supplier['contact_person']); ?></td>
                                    <td><?php echo remove_junk($supplier['email']); ?></td>
                                    <td><?php echo remove_junk($supplier['phone']); ?></td>
                                    <td class="text-center">
                                        <div class="btn-group">
                                            <a href="edit_vendor.php?id=<?php echo (int) $supplier['id']; ?>" class="btn btn-info btn-xs" title="Edit" data-toggle="tooltip">
                                                <span class="glyphicon glyphicon-edit"></span>
                                            </a>
                                            <a href="delete_vendor.php?id=<?php echo (int) $supplier['id']; ?>" class="btn btn-danger btn-xs" title="Delete" data-toggle="tooltip">
                                                <span class="glyphicon glyphicon-trash"></span>
                                            </a>
                                        </div>
                                    </td>
                                </tr>
                            <?php endforeach; ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- Add Vendor Modal -->
<div class="modal fade" id="addVendorModal" tabindex="-1" role="dialog" aria-labelledby="addVendorModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="addVendorModalLabel">Add New Vendor</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <form method="post" action="add_vendor.php">
                    <div class="form-group">
                        <label for="vendor_name">Vendor Name</label>
                        <input type="text" class="form-control" name="vendor_name" required>
                    </div>
                    <div class="form-group">
                        <label for="contact_person">Contact Person</label>
                        <input type="text" class="form-control" name="contact_person" required>
                    </div>
                    <div class="form-group">
                        <label for="email">Email</label>
                        <input type="email" class="form-control" name="email" required>
                    </div>
                    <div class="form-group">
                        <label for="phone">Phone</label>
                        <input type="text" class="form-control" name="phone" required>
                    </div>
                    <button type="submit" name="add_vendor" class="btn btn-primary">Add Vendor</button>
                </form>
            </div>
        </div>
    </div>
</div>
<!-- End of Add Vendor Modal -->

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