Beispiel #1
0
function array2str($D)
{
    #$D = compact('data','format', 'select','returnFields', 'letter','cols', 'db')
    extract($D);
    $select = $s3ql['select'] != '' ? $s3ql['select'] : $select;
    if (!ereg('json|php|xml|rdf|n3|sif', $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 ($select != '') {
            $P['out'] = urldecode($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);
        $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'] != '*') {
            #$t=$GLOBALS['s3codes'][$letter];
            #$t=$GLOBALS['plurals'][$t];
            #$toreplace = array_keys($GLOBALS['s3map'][$t]);
            #$replacements = array_values($GLOBALS['s3map'][$t]);
            #$s3ql['select'] = str_replace($toreplace, $replacements, $s3ql['select']);
            $s3ql_out = ereg_replace(' ', '', $s3ql['select']);
            #take out all the spaces
            $selectFields = explode(',', $s3ql_out);
        }
        #clean up the non display field first
        #echo '<pre>';print_r($data);
        #echo '<pre>';print_r($selectFields);
        foreach ($data as $key => $value) {
            if (!empty($selectFields[0])) {
                foreach ($selectFields as $colname) {
                    $data2display[$key][$colname] = $value[$colname];
                }
            } else {
                //echo '<pre>';print_r($value);
                foreach ($cols as $colname) {
                    $data2display[$key][$colname] = $value[$colname];
                }
            }
        }
        $data = $data2display;
        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') {
            return 's3db_json(' . json_encode($data) . ')';
            exit;
        } elseif ($format == 'php') {
            return serialize($data);
            #echo '$data = ';
            #print_r($data);
            exit;
        } elseif ($format == 'xml') {
            #header("Content-type: application/xml");
            return xml_encode($data, $letter);
            exit;
        } elseif ($format == 'rdf' || $format == 'n3') {
            include 'rdfheader.inc.php';
            return rdf_encode($data, $letter, $format, $db);
            exit;
        } elseif ($format == 'sif') {
            return tab_encode($data, $returnFields);
            exit;
        }
    }
}
Beispiel #2
0
function render_datamatrix_values($vals)
{
    $action = $GLOBALS['webaction'];
    extract($vals);
    $color = $_REQUEST['color'];
    $format = $_REQUEST['format'];
    $parser = get_parser_characters($format);
    $rows = '';
    $items = $instances;
    //		if($_REQUEST['num_per_page']!='' && $_REQUEST['current_page']!='')
    //			{
    //			$start = (($_REQUEST['current_page']-1)*$_REQUEST['num_per_page']);
    //			$end=($_REQUEST['num_per_page']*$_REQUEST['current_page']);
    //			}
    //			else {
    //				$start = 0;
    //				$end= count($items);
    //		}
    #if(is_array($matched_resource))
    for ($i = $start; $i < $end; $i++) {
        $item_id = $items[$i]['item_id'];
        if (!is_array($items[$i]['stats'])) {
            $row = '';
            $s3ql = compact('db', 'user_id');
            $s3ql['select'] = '*';
            $s3ql['from'] = 'statements';
            $s3ql['where']['item_id'] = $item_id;
            $all_values = S3QLaction($s3ql);
        } else {
            $all_values = $items[$i]['stats'];
        }
        #echo '<pre>';print_r($all_values);exit;
        if (is_array($all_values) && !empty($all_values)) {
            #replace values with filelinks and find the notes for the buttons
            $all_values = include_button_notes($all_values, $project_id, $db);
            $all_values = Values2Links($all_values);
        }
        if (count($all_values) == '0') {
            if ($color == 'on') {
                if ($total % 2 == 0) {
                    $row = sprintf("%s\n", '		<tr bgcolor="AliceBlue">');
                } else {
                    $row = sprintf("%s\n", $parser['tr']);
                }
                #$all_values = include_button_notes($all_values, $project_id, $db);
                #In case color is on, it means we are trying to achieve one of the interactive, user-friendly interfaces. Therefore, resource should come in the format of a button. Need to be dealt with care in case
                $resource_id_button = '<input type="button" size="10" value="' . str_pad($item_id, 6, '0', STR_PAD_LEFT) . '" onClick="window.open(\'' . $action['item'] . '&item_id=' . $item_id . '\', \'_blank\', \'width=700, height=600, location=no, titlebar=no, scrollbars=yes, resizable=yes\')">';
            } else {
                $resource_id_button = $item_id;
            }
            $subrow = '';
            $subrow .= sprintf("%s", $parser['td'] . $resource_id_button . $parser['end_td']);
            $subrow .= sprintf("%s", $parser['td'] . $items[$i]['notes'] . $parser['end_td']);
            #Moving on to the data on the rules, since there are no values on this row, print only opening and ending the cell
            if (is_array($rules)) {
                foreach ($rules as $j => $value) {
                    $subrow .= sprintf("%s", $parser['td'] . $parser['end_td']);
                }
            }
            $subrow .= sprintf("%s", $parser['end_tr']);
            $row .= $subrow;
            $total += 1;
        } else {
            $n = get_max_num_values($all_values, $rules) == 0 ? 1 : get_max_num_values($all_values, $rules);
            #$n will determine the number of lines for this item
            $total = 0;
            $row = '';
            for ($m = 0; $m < $n; $m++) {
                //$row ='';
                if ($_REQUEST['color'] == 'on') {
                    #if($total%2==0)
                    #$row .=sprintf("%s\n", '<tr bgcolor="AliceBlue">');}
                    #else
                    #$row .=sprintf("%s\n", $parser['tr']);
                    $resource_id_button = '<input type="button" size="10" value="' . str_pad($item_id, 6, '0', STR_PAD_LEFT) . '" onClick="window.open(\'' . $action['item'] . '&item_id=' . $item_id . '\', \'_blank\', \'width=700, height=600, location=no, titlebar=no, scrollbars=yes, resizable=yes\')">';
                } else {
                    $resource_id_button = $item_id;
                }
                $row .= sprintf("%s", $parser['tr']);
                $subrow = '';
                $subrow .= sprintf("%s", $parser['td'] . $resource_id_button . $parser['end_td']);
                $subrow .= sprintf("%s", $parser['td'] . $items[$i]['notes'] . $parser['end_td']);
                #if($item_id=='3783'){ echo $row ;  exit;}
                //print_r($rules);
                if (is_array($rules)) {
                    foreach ($rules as $j => $value) {
                        $rule_id = $rules[$j]['rule_id'];
                        $values = get_value_by_rule($all_values, $rule_id);
                        if ($format == 'html' && $color == 'on') {
                            $value = viewStatementValue($values[$m]);
                        } else {
                            $value = $values[$m]['value'];
                        }
                        if ($value != '') {
                            $subrow .= sprintf("%s", $parser['td'] . $value . $parser['end_td']);
                        } else {
                            $subrow .= sprintf("%s", $parser['td'] . $parser['end_td']);
                        }
                    }
                }
                $subrow .= sprintf($parser['end_tr']);
                $row .= $subrow;
            }
            $rows .= $row;
        }
    }
    $rows .= sprintf($parser['end_table']);
    return $rows;
}