Ejemplo n.º 1
0
        if ($s3qlout != '' && $s3qlout[1] != '0') {
            echo formatReturn($s3qlout[1], $s3qlout[2]);
            exit;
        } else {
            $data[0] = $element_info;
        }
        $data[0]['uid'] = $GLOBALS['Did'] . ($letter != 'U' ? '|U' . $user_id : '') . '|' . $letter . $ID;
        $data[0]['uri'] = S3DB_URI_BASE . '/' . $uid;
        $data[0] = array_filter(array_diff_key($data[0], array('project_folder' => '', 'account_pwd' => '', 'status' => '', 'view' => '', 'change' => '', 'add_data' => '', 'delete' => '')));
        if ($letter == 'U' && ($user_id != 1 && $user_id != $element_info['created_by'] && $user_id != $element_info['account_id'])) {
            $data[0]['email'] = "";
            $data[0]['account_email'] = "";
        }
    }
}
if (!is_array($data[0])) {
    echo formatReturn($GLOBALS['error_codes'][$something_does_not_exist], "uid " . $uid . " does not exist", $s3ql['format'], '');
    exit;
}
$cols = columnsToDisplay($letter);
if ($complete) {
    if ($data[0]['links']) {
        foreach ($data[0]['links'] as $newCol => $moreData) {
            $data[0][$newCol] = $moreData;
            array_push($cols, $newCol);
        }
    }
}
$z = compact('data', 'cols', 'format', 'letter');
echo outputFormat($z);
exit;
Ejemplo n.º 2
0
function completeDisplay($pack)
{
    global $timer;
    #$pack = compact('t', 'data', 'format')
    extract($pack);
    $data = $s3qlOut == '' ? $data : $s3qlOut;
    $Outputs = columnsToDisplay($letter, $returnFields = array(), $data);
    ##Disctionary output
    if ($complete) {
        #Find what other cols should be in the output based on dictionary
        $linkCols = array();
        foreach ($data as $d => $data_info) {
            if ($data[$d]['links'] != "") {
                foreach ($data[$d]['links'] as $lName => $lVal) {
                    $data[$d][$lName] = $lVal;
                    if (!in_array($lName, $Outputs)) {
                        array_push($Outputs, $lName);
                    }
                }
            }
        }
    }
    $cols = $Outputs;
    #map some cols
    if ($data['class_id'] != '') {
        $data['resource_class_id'] = $data['class_id'];
    }
    if ($s3ql['from'] == 'users' && $s3ql['where']['project_id'] != '') {
        $s3ql['from'] = 'project_acl';
        #$cols = array_merge($cols, array('permissionOnResource'));
        foreach ($data as $out => $val) {
            $data[$out]['project_id'] = $data[$out]['acl_project_id'];
            $data[$out]['user_id'] = $data[$out]['acl_account'];
            $data[$out]['permission_level'] = $data[$out]['acl_rights'];
        }
    }
    if (is_array($data)) {
        $data = array_map('ValuesToFileLinks', $data);
        #on statements, return links each time there is a file
    }
    if (is_array($cols)) {
        if ($user_id != '1') {
            $cols = array_diff($cols, array('session_id', 'account_type', 'account_status', 'iid', 'project_status'));
        }
        $cols = array_diff($cols, array('account_pwd'));
    }
    #if(ereg('html|tab', $format) ||  $format=='')
    if (!ereg('json|php|xml|rdf|n3|sif|turtle', $format)) {
        if ($format == 'html.pretty') {
            $format = 'html';
            echo '<script type="text/javascript">
				<!--
				function paintRows(){
				lines = document.getElementsByTagName(\'tr\');
				for (i=0; i<lines.length; i=i+2) {lines[i].style.backgroundColor = \'#BBFFFF\'}
				for (i=1; i<lines.length; i=i+2) 
				{lines[i].style.backgroundColor = \'lightyellow\'};
				}
				//-->
				</script>';
            echo '<body onload = paintRows()>';
        } elseif (ereg('html.(.*)', $format, $css)) {
            $format = 'html';
            $style = @stream_get_contents(@fopen($css[1], 'r'));
            echo '<style type="text/css">';
            echo $style;
            echo '</style>';
        }
        $format = get_parser_characters($format);
        #Fetch the cols of what is to be returned
        if ($s3ql['select'] != '') {
            $P['out'] = urldecode($s3ql['select']);
            $P['SQLfun'] = ereg_replace("\\(.*\\)", "", $P['out']);
            if ($P['out'] == $P['SQLfun']) {
                $P['SQLfun'] = '';
            }
        }
        #After the query, resume the cols that are supposed to be displayed. Remove the sensitivy cols that should not be displayed
        if ($P['out'] != '' && $P['out'] != '*') {
            if ($P['SQLfun'] == 'distinct') {
                $P['out'] = str_replace(array($P['SQLfun'], "(", ")"), "", $P['out']);
            }
            $cols = array_map('trimmit', explode(',', $P['out']));
        }
        #echo '<pre>';print_r($cols);exit;
        $c = 0;
        foreach ($cols as $i => $name) {
            $pCol = $name;
            #if($c==count($cols)-1)
            if ($c < count($cols) - 1) {
                $header .= trim($pCol) . $format['middle'];
            } else {
                $header .= trim($pCol);
            }
            $c++;
        }
        $x = array('data' => $data, 'format' => $format, 'header' => $header, 'columns' => $cols);
        return display($x);
        #exit;
    } else {
        #filter data by selected
        if ($s3ql['select'] != '*') {
            $s3ql_out = ereg_replace(' ', '', $s3ql['select']);
            #take out all the spaces
            $selectFields = explode(',', $s3ql_out);
        }
        #clean up the non display field first
        if (is_array($data)) {
            foreach ($data as $kd => $value) {
                if (!empty($selectFields[0])) {
                    foreach ($selectFields as $colname) {
                        $data2display[$kd][$colname] = $value[$colname];
                    }
                } else {
                    //echo '<pre>';print_r($value);
                    foreach ($cols as $colname) {
                        #if($value[$colname]!='')
                        $data2display[$kd][$colname] = $value[$colname];
                    }
                }
            }
        }
        #if dictionary is requested, get the namespaces
        if ($complete) {
            $s3qlN = compact('user_id', 'db');
            $s3qlN['from'] = 'namespaces';
            $formatN = 'array';
            $namespaces = query_user_dictionaries($s3qlN, $db, $user_id, $formatN);
            if ($timer) {
                $timer->setMarker('Namespaces retrieved');
            }
        }
        $data = is_array($data2display) ? $data2display : $data;
        if ($_REQUEST['out'] == 'header' || $format == 'json' && $_SERVER['HTTPS']) {
            header("Pragma: public");
            header("Expires: 0");
            // set expiration time
            header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
            header("Content-Type: application/force-download");
            header("Content-Type: application/octet-stream");
            header("Content-Type: application/download");
            #header("Content-Type: ".$ext."");
            // use the Content-Disposition header to supply a recommended filename and
            // force the browser to display the save dialog.
            header("Content-Disposition: attachment; filename=s3db." . $format . "");
            header("Content-Transfer-Encoding: binary");
        }
        if ($format == 'json') {
            $callback = $_REQUEST['jsonp'] == '' ? $_REQUEST['callback'] == '' ? 's3db_json' : $_REQUEST['callback'] : $_REQUEST['jsonp'];
            $onLoad = $_REQUEST['onload'] == '' ? '' : '; ' . stripslashes($_REQUEST['onload']) . (ereg('\\(.*\\)', $_REQUEST['onload']) ? '' : '()');
            $jsonpp = $_REQUEST['jsonpp'] == '' ? '' : ', "' . $_REQUEST['jsonpp'] . '"';
            return $callback . '(' . json_encode($data) . $jsonpp . ')' . $onLoad;
            exit;
        } elseif ($format == 'php') {
            return serialize($data);
            #echo '$data = ';
            #print_r($data);
            exit;
        } elseif ($format == 'xml') {
            $xmlData = xml_encode($data, $letter, $root, $namespaces);
            return $xmlData;
            exit;
        } elseif (ereg('rdf-json|rdf|n3|turtle', $format)) {
            if (!in_array(S3DB_SERVER_ROOT . '/rdfheader.inc.php', get_included_files())) {
                include_once S3DB_SERVER_ROOT . '/rdfheader.inc.php';
            }
            return rdf_encode($data, $letter, $format, $db, $namespaces);
            exit;
        } elseif ($format == 'sif') {
            return tab_encode($data, $returnFields);
            exit;
        }
    }
    if (is_array($s3qlOut) && !empty($s3qlOut)) {
        #this menas data was removed
        return formatReturn($GLOBALS['error_codes']['no_permission_message'], "User does not have permission to access resource(s)", $s3ql['format']);
    }
}