User
<?php
$page_title = 'Input Productivity Data';
require_once('includes/load.php');
page_require_level(3);

include_once('layouts/header.php');



// Inisialisasi variabel tanggal
$date = date('Y-m-d');
$success_message = '';

// Periksa apakah formulir telah disubmit
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Tangkap data dari formulir
    $date = $_POST["date"];
    
    // Periksa form mana yang diisi oleh pengguna
    for ($i = 1; $i <= 5; $i++) {
        $work_time = $_POST["work_time_" . $i];
        $name = $_POST["name_" . $i];
        $color = $_POST["color_" . $i];
        $quantity = $_POST["quantity_" . $i];
        $work_center = $_POST["work_center_" . $i];
        
        // Validasi data formulir (lakukan validasi sesuai kebutuhan)
        if (!empty($work_time) && is_numeric($quantity) && !empty($name) && !empty($color) && !empty($work_center)) {
            // Sisipkan logika penyimpanan data ke dalam tabel "productivity" di sini
            // Gantilah perintah SQL berikut dengan perintah yang sesuai dengan database Anda
            $sql = "INSERT INTO productivity (date, work_time, name, color, quantity, work_center) VALUES ('$date', '$work_time', '$name', '$color', '$quantity', '$work_center')";


            if ($db->query($sql)) {
                $success_message = 'Data berhasil disimpan!';
            }
        }
    }
}



?>


<!-- Tombol Export CSV dengan pop-up -->
<a href="export_productivity.php" class="btn btn-primary" onclick="return confirm('Apakah Anda yakin ingin mengekspor data ke CSV?')">Export to CSV</a>

<form action="import_productivity.php" method="post" enctype="multipart/form-data">
    <input type="file" name="csv_file" id="csv_file" required>
    <input type="submit" value="Import CSV" name="import_button">
</form>

<h1>Productivity Input</h1>

<?php if (!empty($success_message)): ?>
<div class="alert alert-success">
    <?php echo $success_message; ?>
</div>
<?php endif; ?>

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <div class="form-group">
        <label for="date">Date:</label>
        <input type="date" name="date" id="date" value="<?php echo $date; ?>" required>
    </div>
    
    <?php for ($i = 1; $i <= 5; $i++): ?>
        <div class="form-group">
            <label for="work_time_<?php echo $i; ?>">Work Time (hours):</label>
            <input type="text" name="work_time_<?php echo $i; ?>">
            
            <label for="name_<?php echo $i; ?>">Name of Task:</label>
            <input type="text" name="name_<?php echo $i; ?>">
            
            <label for="color_<?php echo $i; ?>">Color:</label>
            <input type="text" name="color_<?php echo $i; ?>">

            
            <label for="quantity_<?php echo $i; ?>">Quantity:</label>
            <input type="text" name="quantity_<?php echo $i; ?>">
            
            <label for="work_center_<?php echo $i; ?>">Work Center:</label>
            <input type="text" name="work_center_<?php echo $i; ?>">
        </div>
    <?php endfor; ?>
    
    <input type="submit" value="Submit">
</form>

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