function guifi_device_access($op, $id)
{
    global $user;
    guifi_log(GUIFILOG_TRACE, 'function guifi_device_access()', $id);
    guifi_log(GUIFILOG_FULL, 'user='******'view') {
        return true;
    }
    if (is_array($id)) {
        $device = $id;
    } else {
        $device = guifi_device_load($id);
    }
    $node = node_load(array('nid' => $device['nid']));
    switch ($op) {
        case 'create':
            return user_access("create guifi nodes");
        case 'update':
        case 'delete':
            if (user_access('administer guifi networks') || user_access('administer guifi zones') || $device['user_created'] == $user->uid || in_array($user->uid, guifi_maintainers_load($device['id'], 'device', 'uid')) || in_array($user->uid, guifi_funders_load($device['id'], 'device', 'uid'))) {
                return TRUE;
            } else {
                //      	guifi_log(GUIFILOG_BASIC,'guifi_device_access(update)',$device);
                if (empty($device['maintainers']) and guifi_node_access($op, $node)) {
                    return TRUE;
                }
                if (empty($device['funders']) and guifi_node_access($op, $node)) {
                    return TRUE;
                }
            }
    }
    return FALSE;
}
/** guifi_node_load(): load and constructs node array from the database
**/
function guifi_node_load($node)
{
    if (is_object($node)) {
        $k = $node->nid;
    } else {
        $k = $node;
    }
    $node = db_fetch_object(db_query("SELECT * FROM {guifi_location} WHERE id = '%d'", $k));
    $node->maintainers = guifi_maintainers_load($node->id, 'location');
    $node->funders = guifi_funders_load($node->id, 'location');
    if (!$node->id == NULL) {
        return $node;
    }
    return FALSE;
}