<?php

include '../helper_functions/data_request.php';

if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['hardwareType'])) {
    $hardwareType = $_POST['hardwareType'];

    // Redirect based on the selected hardware type
    switch ($hardwareType) {
        case 'smsio':
            header('Location: smsio/smsio.php');
            break;
        case 'type2':
            header('Location: type2.php');
            break;
        case 'type3':
            header('Location: type3.php');
            break;
        // Add more cases as needed
        default:
            header('Location: default.php');
            break;
    }
    exit();
}

if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['getHardware'])) {

    $currentHardware = fetchData('hardware_configs');

    echo json_encode($currentHardware);
    exit();
}

if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['hardware_name'])) {

    $hwName = $_POST['hardware_name'];
    $hwConfig = $_POST['hardware_config'];
    $hwTbl = "hardware_configs";
    $hwData = [
        'hardware' => $hwName,
        'base_config' => $hwConfig
    ];

    insertData($hwTbl, $hwData);

    header('Location: ../admin/admin_panel.php');
}

