<?php
include $_SERVER['DOCUMENT_ROOT'] . '/classes/autoload.php';
// var_dump($_POST);


$user_type_name = $_POST['name'];
$admin_access = isset($_POST['admin_access']) ? 1 : 2;
$app_access_array = $_POST['app_access'];
// echo "USER TYPE: " . $user_type_name . "<br>";
// echo "ADMIN ACCESS: " . $admin_access . "<br>";
// echo "ACCESS TO : <br>";
$user_type_id = $db->query("user_types", "INSERT INTO `user_types`(`name`,`user_id_added`,`admin_access`) VALUES ('$user_type_name','" . $_SESSION['user_id'] . "','$admin_access')");
foreach ($app_access_array as $app_access) {
    // echo "UNDER $app_access USER TYPE CAN: <br>";
    $db->query("user_type_app_access", "INSERT INTO `user_type_app_access`(`user_type_id`, `file_name`) VALUES ('$user_type_id','$app_access')");
    // if (isset($_POST[$app_access . '_add_access']) && $_POST[$app_access . '_add_access'] == 'on') {
    //     $add_access = 1;
    //     echo "ADD<br>";
    // }
    // if (isset($_POST[$app_access . '_edit_access']) && $_POST[$app_access . '_edit_access'] == 'on') {
    //     $edit_access = 1;
    //     echo "EDIT<br>";
    // }
    // if (isset($_POST[$app_access . '_view_access'])) {
    //     echo "COLUMNS<br>";
    //     foreach ($_POST[$app_access . '_view_access'] as $view_access) {
    //         echo $view_access;
    //     }
    // }
}



header("location: home.php");