Example #1
0
function URIinfo($uid, $user_id, $key, $db, $timer = array())
{
    $uid_info = uid($uid);
    $element = $GLOBALS['s3codes'][substr($uid, 0, 1)];
    $local_info = s3info($element, ereg_replace('^' . letter($uid), '', $uid), $db);
    #echo $uid.'<pre>';print_r($local_info);exit;
    if (is_array($local_info) && !empty($local_info)) {
        $uid_info['Did'] = $GLOBALS['Did'];
        $uid_info['uid'] = $uid;
        $element_info = $local_info;
        $letter = strtoupper(substr($element, 0, 1));
        $info = include_all(compact('elements', 'letter', 'element_info', 'user_id', 'db', 'key', 'timer'));
        $info['remote_uri'] = 0;
        #echo '<pre>';print_r($info);exit;
    }
    if ($uid_info['Did'] == $GLOBALS['Did'] || $uid_info['Did'] == S3DB_URI_BASE) {
        if (is_array($local_info) && !empty($local_info)) {
            $uid = str_replace(S3DB_URI_BASE . '/', '', $uid_info['uid']);
            $uid_info['Did'] = $GLOBALS['Did'];
            $uid_info['uid'] = $uid;
            $element_info = s3info($element, ereg_replace('^' . letter($uid), '', $uid), $db);
            $letter = strtoupper(substr($element, 0, 1));
            $info = include_all(compact('elements', 'letter', 'element_info', 'user_id', 'db', 'key'));
            $info['remote_uri'] = 0;
        } else {
            $info = false;
        }
        #echo 'loca'.$uid;exit;
        #$info = URI($uid_info['uid'], $user_id, $db);
        #$info['remote_uri']=0;
    } else {
        #echo 'ola'.$uid;exit;
        $key = $key != '' ? $key : get_user_key($user_id, $db);
        #echo $user_id;exit;
        $info = remoteURI($letter . $uid_info['uid'], $key, $user_id, $db);
        #echo '<pre>';print_r($info);exit;
        $info['remote_uri'] = 1;
        if (!is_array($info) || empty($info)) {
            $info = URI($uid, $user_id, $db);
        }
        if (!is_array($info)) {
            $info = false;
        }
    }
    #echo '<pre>';print_r($info);exit;
    return $info;
}
Example #2
0
function retrieveUIDInfoOLD($Z)
{
    extract($Z);
    #echo '<pre>';print_r($db);
    if ($s3ql['where'][$id] != '') {
        $element_name = $s3element;
        $id_name = $id;
        $letterSub = strtoupper(substr($id_name, 0, 1));
        $core = $GLOBALS['s3codes'][$letterSub];
        #is this remote?
        $uid_info = uid($letterSub . $s3ql['where'][$id_name]);
        $islocal = isLocal($letterSub . $s3ql['where'][$id_name], $db);
        $uid = $letter . $s3ql['where'][$id_name];
        #try regular URI (internal)
        if ($islocal) {
            $id = strtoupper(substr($element_name, 0, 1)) . $s3ql['where'][$id_name];
            $localuid = $letterSub . $s3ql['where'][$id_name];
            $element_info = URI($localuid, $user_id, $db);
            if ($element_info['acl'] == '') {
                $element_info['acl'] = permission4Resource(array('shared_with' => 'U' . $user_id, 'uid' => $id, 'db' => $db, 'user_id' => $user_id, 'strictuid' => 1, 'strictsharedwith' => 1));
            }
            if ($id_name == $element . "_id") {
                if (!is_array($element_info)) {
                    if ($uid_info['uid'] != '') {
                        $forbidden = array('#', ':', '/');
                        $test_str = str_split($uid_info['uid']);
                        foreach ($forbidden as $f) {
                            if (array_search($f, $test_str)) {
                                return formatReturn($GLOBALS['error_codes']['wrong_inputs'], 'Please do not use any of the following character when specifying IDs: ' . array_reduce($forbidden, "comma_split"), $s3ql['format'], '');
                            }
                        }
                    }
                    $element_info = array('to_create' => '1');
                } else {
                    #echo '<pre>';print_r($element_info);
                    $element_info['to_create'] = '0';
                    #only valid when resource being inserted in another resource.
                }
            }
        } else {
            #This UID can only be remote if it has a Did or URL attached. Does it?
            ereg('^D|http|(s3db:|ldap:|ftp:|smtp:){0,1}(.*):(.*)', $uid_info['uid'], $try);
            if (!$try) {
                #uh ho, it's not local nor remote, this might be a uid that someone is trying to create;
                #So let's check whether there is data to create it. Diff must be empty because it's the result of the difference between what is needed and what is provided.
                if (empty($diff) && $id_name == $GLOBALS['COREids'][$s3ql['insert']]) {
                    $element_info = array('to_create' => 1);
                    return $element_info;
                } else {
                    #Problem - id cannot be found and cannot be created :-(
                    $element_info = array();
                    return $element_info;
                }
            }
            #interpreting user input: if this is uid beloing to the object being inserted and there are literal values, assume the provided ID is a literal and is meant to create "de novo"
            $diff = array_diff(array_keys($s3ql['where']), array($GLOBALS['COREids'][$s3element]));
            if ($id_name == $GLOBALS['COREids'][$s3ql['insert']] && !empty($diff) && !ereg('^(U|G|P)$', $letter)) {
                #$element_info['to_create']='1';
                $element_info = URIinfo($letter . $s3ql['where'][$id_name], $user_id, $key, $db);
                $element_info['is_remote'] = '1';
            } else {
                #when inserting a remote user, project or group - when + ids. if this is user, most liel remoteURI will return no permission on the remote deployment
                if (ereg('^(U|G|P)$', $letter)) {
                    if (count($input_ids) > 1) {
                        $element_info = URI($s3ql['where'][$id_name], $user_id, $db);
                    } elseif (ereg('^P$', $letter)) {
                        #$element_info = URI($s3ql['where'][$id_name], $s3ql['key'], $user_id, $db);
                        $element_info = URIinfo($letter . $s3ql['where'][$id_name], $user_id, $key, $db);
                        if (is_array($element_info)) {
                            $element_info['is_remote'] = '1';
                        } else {
                            #Id does not exist. Will assume the goal is to create a new.
                            $element_info = array('to_create' => '1');
                            $diff = array_diff(array_keys($s3ql['where']), $GLOBALS['COREids'], array('permission_level'));
                        }
                    } else {
                        $element_info = array('is_remote' => '1', 'account_id' => $s3ql['where'][$id_name]);
                    }
                } else {
                    #check if is remote only if no other parameters are provided.
                    $diff = array_diff(array_keys($s3ql['where']), $GLOBALS['COREids'], array('permission_level'));
                    if (!empty($diff) && $id_name == $GLOBALS['COREids'][$s3ql['insert']]) {
                        $element_info = array('to_create' => 1);
                    } else {
                        $element_info = remoteURI($s3ql['where'][$id_name], $s3ql['key'], $user_id, $db);
                        if (is_array($element_info)) {
                            $element_info['is_remote'] = '1';
                        }
                    }
                }
            }
        }
        return $element_info;
    }
}
Example #3
0
function retrieveUIDInfo($s3element, $id, $scoreTable, $s3ql, $letter, $input_ids, $user_id, $db)
{
    #echo '<pre>';print_r($db);
    if ($s3ql['where'][$id] != '') {
        $element_name = $s3element;
        $id_name = $id;
        $letterSub = strtoupper(substr($id_name, 0, 1));
        $core = $GLOBALS['s3codes'][$letterSub];
        #is this remote?
        $uid_info = uid($letterSub . $s3ql['where'][$id_name]);
        $islocal = isLocal($letterSub . $s3ql['where'][$id_name], $db);
        #echo '<pre>';print_r($uid_info);
        #try regular URI (internal)
        if ($islocal) {
            $id = strtoupper(substr($element_name, 0, 1)) . $s3ql['where'][$id_name];
            $localuid = $letterSub . $s3ql['where'][$id_name];
            $element_info = URI($localuid, $user_id, $db);
            if ($element_info['acl'] == '') {
                $element_info['acl'] = permissionOnResource(array('shared_with' => 'U' . $user_id, 'uid' => $id, 'db' => $db, 'user_id' => $user_id, 'strictuid' => 1, 'strictsharedwith' => 1));
            }
            if ($id_name == $element . "_id") {
                if (!is_array($element_info)) {
                    if ($uid_info['uid'] != '') {
                        $forbidden = array('#', ':', '/');
                        $test_str = str_split($uid_info['uid']);
                        foreach ($forbidden as $f) {
                            if (array_search($f, $test_str)) {
                                if ($s3ql['format'] == '') {
                                    return '<TABLE><TR><TD>error_code</TD><TD>message</TD></TR><TR><TD>' . ereg_replace('[^(0-9)]', '', $GLOBALS['messages']['wrong_inputs']) . '</TD><TD>Please do not use any of the following character when specifying IDs: ' . array_reduce($forbidden, "comma_split") . '</TD></TR></TABLE>';
                                } else {
                                    return $GLOBALS['messages']['wrong_inputs'] . '<message>Please do not use any of the following character when specifying IDs: ' . array_reduce($forbidden, "comma_split") . '</message>';
                                }
                            }
                        }
                    }
                    $element_info = array('to_create' => '1');
                } else {
                    #echo '<pre>';print_r($element_info);
                    $element_info['to_create'] = '0';
                    #only valid when resource being inserted in another resource.
                }
            }
        } else {
            #interpreting user input: if this is uid beloing to the object being inserted and there are literal values, assume the provided ID is a literal and is meant to create "de novo"
            $diff = array_diff(array_keys($s3ql['where']), array($GLOBALS['COREids'][$s3element]));
            if ($id_name == $GLOBALS['COREids'][$s3ql['insert']] && !empty($diff) && !ereg('^(U|G|P)$', $letter)) {
                $element_info['to_create'] = '1';
            } else {
                #when inserting a remote user, project or group - when + ids. if this is user, most liel remoteURI will return no permission on the remote deployment
                if (ereg('^(U|G|P)$', $letter)) {
                    if (count($input_ids) > 1) {
                        $element_info = URI($s3ql['where'][$id_name], $user_id, $db);
                    } elseif (ereg('^P$', $letter)) {
                        $element_info = URI($s3ql['where'][$id_name], $s3ql['key'], $user_id, $db);
                        if (is_array($element_info)) {
                            $element_info['is_remote'] = '1';
                        } else {
                            #Id does not exist. Will assume the goal is to create a new.
                            $element_info = array('to_create' => '1');
                            $diff = array_diff(array_keys($s3ql['where']), $GLOBALS['COREids'], array('permission_level'));
                        }
                    } else {
                        $element_info = array('is_remote' => '1', 'account_id' => $s3ql['where'][$id_name]);
                    }
                } else {
                    #check if is remote only if no other parameters are provided.
                    $diff = array_diff(array_keys($s3ql['where']), $GLOBALS['COREids'], array('permission_level'));
                    if (!empty($diff) && $id_name == $GLOBALS['COREids'][$s3ql['insert']]) {
                        $element_info = array('to_create' => 1);
                    } else {
                        $element_info = remoteURI($s3ql['where'][$id_name], $s3ql['key'], $user_id, $db);
                        if (is_array($element_info)) {
                            $element_info['is_remote'] = '1';
                        }
                    }
                }
            }
        }
        return $element_info;
    }
}
Example #4
0
function object4objectID($S)
{
    extract($S);
    #$S must contain subject_id and db
    $sql = "select subject from s3db_rule where subject_id = '" . $object_id . "' and verb ='has UID' and object='UID'";
    $db->query($sql, __LINE__, __FILE__);
    if ($db->next_record()) {
        return $db->f('subject');
    } else {
        $data = remoteURI($object_id, $key, $user_id, $db);
        if ($data['entity']) {
            return $data['entity'];
        } else {
            return False;
        }
    }
}