<?php

function access($access, $u_id = null, $exit = false) {

    $db = new db;

    if ($u_id == null) {
        global $user;
    } else {
        $user = get_user($u_id);
    }

    if (!isset($user['group_access']) || $user['group_access'] == null) {
        if ($exit !== false) {
            header("Location: $exit");
            exit;
        } else {
            return false;
        }
    }
    $query = $db->super_query("SELECT COUNT(*) as count FROM `user_group_access` WHERE `id_group` = '$user[group_access]' AND `id_access` = '" . $db->safesql($access) . "'");

    if ($exit !== false) {
        if ($query['count'] == 0) {
            header("Location: $exit");
            exit;
        }
    } else {
        return ($query['count'] == 1 ? true : false);
    }
    unset($query);
}
