<?php
// File: api/log_activity.php
require_once '../config/database.php';

header('Content-Type: application/json');

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

if (!$data) {
    echo json_encode(['success' => false, 'message' => 'No data received']);
    exit;
}

// Log to file
$log_file = '../logs/activity.log';
$log_dir = dirname($log_file);

if (!is_dir($log_dir)) {
    mkdir($log_dir, 0755, true);
}

$log_message = date('Y-m-d H:i:s') . " - " . json_encode($data) . PHP_EOL;
file_put_contents($log_file, $log_message, FILE_APPEND);

echo json_encode(['success' => true]);
?>