<?php
// File: api/log_bel.php
header('Content-Type: application/json');
require_once '../config/database.php';

$data = json_decode(file_get_contents('php://input'), true);

if ($data) {
    $tanggal = date('Y-m-d');
    $jam = date('H:i:s');
    $kegiatan = $data['kegiatan'];
    $status = $data['status'];
    
    // Insert log ke tabel belloto_log
    $stmt = $conn->prepare("INSERT INTO belloto_log (tanggal, jam, kegiatan, status) VALUES (?, ?, ?, ?)");
    $stmt->bind_param("ssss", $tanggal, $jam, $kegiatan, $status);
    
    if ($stmt->execute()) {
        echo json_encode(['success' => true, 'id' => $conn->insert_id]);
    } else {
        echo json_encode(['success' => false, 'error' => $stmt->error]);
    }
    
    $stmt->close();
} else {
    echo json_encode(['success' => false, 'error' => 'No data received']);
}

$conn->close();
?>