Project

General

Profile

1
<?php
2

    
3
//#ob_start("ob_gzhandler");
4

    
5
require_once('controller.php');
6
require_once("./js/gdatasource/vistable.php");
7

    
8
$tqx = isset($_GET['tqx']) ? $_GET['tqx'] : "";
9
$tq = isset($_GET['tq']) ? $_GET['tq'] : "";
10
$tqrt = isset($_GET['tqrt']) ? $_GET['tqrt'] : "";
11
$tz = isset($_GET['tz']) ? $_GET['tz'] : "PDT";
12
$locale = isset($_SERVER["HTTP_ACCEPT_LANGUAGE"]) ? $_SERVER["HTTP_ACCEPT_LANGUAGE"] : "en_US";
13

    
14
if (isset($_GET['locale'])) {
15
    $locale = $_GET['locale'];
16
}
17

    
18
$extra = array();
19
if (isset($_GET['debug']) && $_GET['debug']) {
20
    header('Content-type: text/plain; charset="UTF-8"');
21
    $extra['debug'] = 1;
22
}
23

    
24
$controller = new Controller(false);
25
$persistent="true";
26

    
27
if(isset($_GET['com'])) {
28
	//analoga me to command kalei tin katallili synanrtisi
29
	if($_GET['com'] == "query") {
30
		$selectedData = json_decode($_GET['data'],true);
31

    
32
if(!isset($_GET['persistent']))
33
{ $persistent="true";
34
}else{$persistent="false";}
35

    
36

    
37
		$resp = $controller->makeQuery('table',$persistent);
38
		$resp = json_decode($resp,true);
39
		//make the header row
40
		$header = array();
41
		if($selectedData['xaxistitle'] && $selectedData['xaxistitle'] !='')
42
			$header[] = $selectedData['xaxistitle'];
43
		else{
44
			$temp = explode("-",$selectedData['xaxis']['name']);
45
			$header[] = $temp[count($temp)-1];
46
		}
47

    
48
		for($i=0;$i<count($selectedData['fields']);$i++){
49
			if(isset($selectedData['fieldsheaders']) && isset($selectedData['fieldsheaders'][$i]) && $selectedData['fieldsheaders'][$i]!=''){
50
				$header[] = $selectedData['fieldsheaders'][$i];
51
			}
52
			else{
53
				$temp = explode("-",$selectedData['fields'][$i]['fld']);
54
				if($selectedData['fields'][$i]['agg'] != '')
55
					$header[] = $selectedData['fields'][$i]['agg']." of ".$temp[count($temp)-1];
56
				else
57
					$header[] = $temp[count($temp)-1];
58
			}
59
		}
60
		if($selectedData['group']!='' && $selectedData['group'] !='no'){
61
			$temp = explode("-",$selectedData['group']);
62
			$header[] = $temp[count($temp)-1];
63
		}
64

    
65
		for($i=0;$i<count($header);$i++){
66
			//print_r($resp['data'][0][$i]);
67
			if(is_numeric($resp['data'][0][$i]))
68
				$header[$i] .= " as number";
69
		}
70

    
71
		$tempdata = array();
72
		$tempdata[] = implode(",",$header);
73
		for($l=1;$l<count($resp['data']);$l++){
74
			$tempdata[] = implode(",",$resp['data'][$l]);
75
		}
76
		$data = implode("\n",$tempdata);
77
		//echo $data;
78
		/*$file = '../data/data.csv';
79
		$data = file_get_contents($file);
80
		if ($file === FALSE) {
81
			die("Couldnt read `$file'");
82
		}*/
83

    
84

    
85
		$vt = new csv_vistable($tqx, $tq, $tqrt,$tz,$locale,$extra);
86

    
87
		$vt->setup_table($data);
88

    
89
		$result = $vt->execute();
90

    
91
		echo $result;
92
	}
93
	else{
94
		die("unknown command code");
95
	}
96
}
97
else {
98
	//oops error
99
	die("no command given");
100
}
101
//#ob_end_flush();
102
?>
(8-8/28)