<?php
// log-download.php - ذخیره لاگ دانلودها
session_start();

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

if ($data) {
    $log = [
        'timestamp' => $data['timestamp'] ?? date('Y-m-d H:i:s'),
        'action' => $data['action'] ?? 'unknown',
        'user' => $data['user'] ?? 'unknown',
        'ip' => $_SERVER['REMOTE_ADDR'],
        'user_agent' => $_SERVER['HTTP_USER_AGENT']
    ];
    
    file_put_contents('logs/downloads.log', json_encode($log) . PHP_EOL, FILE_APPEND);
    
    echo json_encode(['status' => 'success']);
} else {
    echo json_encode(['status' => 'error', 'message' => 'No data received']);
}
?>