<?php
require_once(__DIR__ . '/../config/settings.php');

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $name = $_POST['name'] ?? '';
    $url = $_POST['url'] ?? '';

    if (!empty($name) && !empty($url)) {
        try {
            $dsn = "dblib:host={$db_settings['host']};dbname={$db_settings['name']}";
            $pdo = new PDO($dsn, $db_settings['user'], $db_settings['pass']);
            
            $stmt = $pdo->prepare("INSERT INTO Web_Downloads (name, url) VALUES (?, ?)");
            $stmt->execute([$name, $url]);
            echo json_encode(['status' => 'success']);
        } catch (Exception $e) {
            echo json_encode(['status' => 'error']);
        }
    }
}