Esempio n. 1
0
function includeAllData($pack)
{
    extract($pack);
    $element2query = $element2query == '' ? $s3ql['from'] : $element2query;
    #echo '<pre>';print_r($data);exit;
    $letter = letter($element2query);
    $element = $GLOBALS['s3codes'][$letter];
    if ($user_id != '1') {
        if (count($data) >= 4) {
            if (!ereg('^U|^G', $letter)) {
                $Z = compact('user_id', 'db', 'uidQuery', 'timer', 'WhereInfo', 'shared_with_query');
                $Z['toFind'] = $letter;
                $Z['shared_with_user'] = '******' . $user_id;
                $ids = permissionPropagation($Z);
            }
        }
    }
    if (ereg('^U|^G', $letter) && $WhereInfo) {
        $whereId = array_keys($WhereInfo);
        if (count($whereId) > 1) {
            $array = array();
            return $array;
        } else {
            $whereId = $whereId[0];
            #Tlist provides the list of resources that are shared with the uid of interest, including users & groups
            $Hlist = bottom_up_propagation_list($whereId, $db);
            $Tlist = user_included_bottom_up_propagation_list('U', $whereId, $user_id, $db);
            $resourceUsers = s3dbPercolate($Hlist, $Tlist, $letter);
            if ($_REQUEST['su3d']) {
            }
        }
    }
    ##Remove from data the uids that do not exist in ids
    $str = $GLOBALS['s3ids'][$GLOBALS['s3codes'][$letter]];
    $re_issued = array();
    if (is_array($data)) {
        foreach ($data as $ind => $array) {
            $uid = $letter . $array[$str];
            if ($uid != '') {
                if ($user_id != '1') {
                    if (is_array($ids)) {
                        if (!ereg('^U|^G', $letter)) {
                            if ($ids[$uid] != '') {
                                $array['acl'] = $ids[$uid];
                            } else {
                                $array = array();
                            }
                        } else {
                            if ($resourceUsers) {
                                if (in_array($uid, array_keys($resourceUsers))) {
                                    $array['permissionOnResource'] = $resourceUsers[$uid];
                                } else {
                                    $array = array();
                                }
                            }
                            #else {
                            #	 $array=array();
                            #}
                        }
                    } else {
                        $strictuid = 1;
                        $strictsharedwith = 1;
                        $shared_with = 'U' . $user_id;
                        $P = compact('uid', 'shared_with', 'user_id', 'db', 'strictuid', 'strictsharedwith', 'stream', 'timer');
                        if (!ereg('^U|^G', $letter)) {
                            $array['acl'] = permission4Resource($P);
                            $array['permission_level'] = $array['acl'];
                            $permission2user = permissionModelComp($array['permission_level']);
                            $isOwner = $array['created_by'] == $user_id;
                            $array['view'] = allowed($permission2user, 0, $isOwner);
                            $array['change'] = allowed($permission2user, 1, $isOwner);
                            $array['propagate'] = allowed($permission2user, 2, $isOwner);
                            #create the element "delete", in case it is eventually created...For now it is the same as change
                            $array['delete'] = $array['change'];
                            $array['add_data'] = $array['propagate'];
                            $array['delete_data'] = $array['add_data'];
                        } else {
                            if ($resourceUsers) {
                                if (in_array($uid, array_keys($resourceUsers))) {
                                    $array['permissionOnResource'] = $resourceUsers[$uid];
                                } else {
                                    $array = array();
                                }
                            }
                            #else {
                            #	 $array=array();
                            #}
                        }
                    }
                } else {
                    $array['acl'] = 'yyy';
                    if (ereg('^U|^G', $letter) && $resourceUsers) {
                        if ($resourceUsers) {
                            if (in_array($uid, array_keys($resourceUsers))) {
                                $array['permissionOnResource'] = $resourceUsers[$uid];
                            } else {
                                $array = array();
                            }
                        }
                        #else {
                        #	 $array=array();
                        #}
                    }
                }
            }
            if (!empty($array)) {
                $re_issued[$uid] = $array;
                $element_info = $re_issued[$uid];
                $info = $WhereInfo;
                $C = compact('letter', 'info', 'elements', 'element_info', 'user_id', 'db', 'key', 'timer', 'model');
                $element_info = include_all($C);
                $element_info['uri'] = S3DB_URI_BASE . '/' . $letter . $array[$str];
                #$element_info['uri'] = str_replace('central', 'TCGA', S3DB_URI_BASE.'/'.$letter.$array[$str]);
                $pack['uid'] = $uid;
                $pack['info'] = $element_info;
                $element_info = filterDataForQuery($pack);
                if ($timer) {
                    $timer->setMarker('Filter Data For The Query');
                }
                $re_issued[$uid] = $element_info;
            }
        }
    }
    $data = array_values(array_filter($re_issued));
    return $data;
}
Esempio n. 2
0
function s3dbPercolate($Tlist, $X, $toFind, $result = array(), $u = 1, $state = 3, $model = 'nsy', $timer = array())
{
    ##OLD OLD
    #Percolate performs the same function as calc, except that it does it with the transverse matrix. That way, all the children's pl may be calculated at once
    global $timer;
    ##Start by reading Tlist from file
    if (is_file($Tlist)) {
        $T = unserialize(file_get_contents($Tlist));
        unlink($Tlist);
        $Tlist = $T;
    }
    if (is_array($X)) {
        foreach ($X as $a => $b) {
            #recover the ids that are to be matched at the end
            if (ereg('^' . $toFind, $a, $m)) {
                if ($result[$a]) {
                    $result[$a] = s3dbMerge(array($result[$a], $b), $state, $model);
                } else {
                    $result[$a] = $b;
                }
            }
        }
    }
    #to save time, assign local permissions when they exist
    if (is_array($Tlist)) {
        foreach ($Tlist as $parent => $children) {
            #migrate permission from $parent to $children
            if ($timer) {
                $timer->setMarker('Propagationg permisions for ' . $parent);
            }
            if ($X[$parent]) {
                $s = s3dbMigrate($X[$parent]);
                list($x_self, $x_next) = $s;
                if (is_array($children)) {
                    $hasChild++;
                    foreach ($children as $child) {
                        #$b are the X that propagate towards $a
                        if ($x_next) {
                            //let's merge this child with existing results
                            if (!$X1[$child]) {
                                //child might have 2 parents in the same iteration (for example, one collection shared by 2 P
                                $X1[$child] = $x_next;
                            } else {
                                $X1[$child] = s3dbMerge(array($X1[$child], $x_next), $state, $model);
                            }
                        }
                    }
                }
            }
        }
    }
    if ($hasChild != 0 && $u <= 10 && is_array($X1)) {
        $u++;
        ##Now put Tlist back in a file so that it saves CPU
        $T = $GLOBALS['s3db_info']['server']['db']['uploads_folder'] . $GLOBALS['s3db_info']['server']['db']['uploads_file'] . '/Hlist' . random_string(10);
        if (!@file_put_contents($T, serialize($Tlist))) {
            $T = $Tlist;
        }
        if ($timer) {
            $timer->setMarker('Going to iteration ' . $u);
        }
        $result = s3dbPercolate($T, $X1, $toFind, $result, $u, $state, $model, $timer);
    }
    return $result;
}