<?php

$db = new SQLite3('./.db_ads.db');
if (!$db) {
    die("Database connection error.");
}

$query = "SELECT * FROM adsstatus";
$result = $db->query($query);

if ($result) {
    $myadsstatus = null;

    while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
        $myadsstatus = $row['adstype'];
    }

    // Finalizamos y cerramos antes de redirigir
    $result->finalize();
    $db->close();

    switch ($myadsstatus) {
        case 'Autoads':
            header("Location: main_movies.php");
            break;
        case 'ads1':
            header("Location: adsv1.php");
            break;
        case 'ads2':
            header("Location: adsv2.php");
            break;
        case 'ads3':
            header("Location: adsv3.php");
            break;
        case 'ads4':
            header("Location: adsv4.php");
            break;
        case 'ads5':
            header("Location: adsv5.php");
            break;
        case 'ads6':
            header("Location: adsv6.php");
            break;
        case 'ads7':
            header("Location: adsv7.php");
            break;
        case 'ads8':
            header("Location: adsv8.php");
            break;
        default:
            header("Location: menads.php"); // O alguna página por defecto
            break;
    }
    exit();

} else {
    echo "Error fetching records: " . $db->lastErrorMsg();
    $db->close();
}
?>

