<?php
require_once 'config.php';
checkLogin();

if ($_POST) {
    $schedule = [
        'consolation' => $_POST['consolation_time'],
        'starter' => $_POST['starter_time'],
        'third' => $_POST['third_time'],
        'second' => $_POST['second_time'],
        'first' => $_POST['first_time']
    ];
    
    $db->query("UPDATE lottery_results SET
        generate_time_consolation = '{$schedule['consolation']}',
        generate_time_starter = '{$schedule['starter']}',
        generate_time_3rd = '{$schedule['third']}',
        generate_time_2nd = '{$schedule['second']}',
        generate_time_1st = '{$schedule['first']}'
        WHERE draw_date = CURDATE()");
    
    $_SESSION['success'] = "Schedule updated!";
    header("Location: update_schedule.php");
    exit;
}

// Ambil jadwal terbaru
$current_schedule = $db->query("SELECT * FROM lottery_results 
                              WHERE draw_date = CURDATE() LIMIT 1")->fetch();
?>

<form method="post">
    Consolation Time: <input type="time" name="consolation_time" step="1" 
                           value="<?= $current_schedule['generate_time_consolation'] ?>"><br>
    Starter Time: <input type="time" name="starter_time" step="1"
                       value="<?= $current_schedule['generate_time_starter'] ?>"><br>
    <!-- Tambahkan input untuk prize lainnya -->
    <button type="submit">Update Schedule</button>
</form>