Пример #1
0
/** guifi_zone_load(): Load the zone from the guifi database.
 */
function guifi_zone_load($node)
{
    guifi_log(GUIFILOG_TRACE, 'function guifi_zone_load()', $node);
    if (is_object($node)) {
        $k = $node->nid;
        if ($node->type != 'guifi_zone') {
            return FALSE;
        }
    } else {
        if (is_numeric($node)) {
            $k = $node;
        }
    }
    $loaded = db_fetch_object(db_query("\n    SELECT * FROM {guifi_zone} WHERE id = '%d'", $k));
    if ($loaded->nick == '' or $loaded->nick == NULL) {
        $loaded->nick = guifi_abbreviate($loaded->title);
    }
    // if zone map not set, take from parents
    if ($loaded->minx == 0 and $loaded->miny == 0 and $loaded->maxx == 0 and $loaded->maxy == 0) {
        $coords = guifi_zone_get_coords($loaded->master);
        $loaded->minx = $coords['minx'];
        $loaded->miny = $coords['miny'];
        $loaded->maxx = $coords['maxx'];
        $loaded->maxy = $coords['maxy'];
    }
    $loaded->maintainers = guifi_maintainers_load($loaded->id, 'zone');
    guifi_log(GUIFILOG_TRACE, 'function guifi_zone_load()', $loaded->maintainers);
    // if notification is NULL, take from the user who created the zone
    if (empty($loaded->notification)) {
        $u = user_load($node->uid);
        $loaded->notification = $u->mail;
    }
    if ($loaded->id != NULL) {
        return $loaded;
    }
    return FALSE;
}
function guifi_maintainers_parents($zid, $ret = 'maintainer')
{
    guifi_log(GUIFILOG_TRACE, 'function guifi_maintainers(parent maintainers)', $pmaintainers);
    $m = array();
    $parent = $zid;
    while ($parent > 0 and empty($m)) {
        $result = db_query('
      SELECT z.master master
      FROM {guifi_zone} z
      WHERE z.id = %d', $parent);
        $row = db_fetch_object($result);
        $parent = $row->master;
        if ($parent) {
            $m = guifi_maintainers_load($parent, 'zone', $ret);
        }
    }
    guifi_log(GUIFILOG_TRACE, 'function guifi_maintainers(loaded parent maintainers)', $m);
    return $m;
}
Пример #3
0
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;
}
Пример #4
0
/** 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;
}