1 |
37810
|
eri.katsar
|
<?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 |
|
|
|
26 |
|
|
if(isset($_GET['com'])) {
|
27 |
|
|
//analoga me to command kalei tin katallili synanrtisi
|
28 |
|
|
if($_GET['com'] == "query") {
|
29 |
|
|
$selectedData = json_decode($_GET['data'],true);
|
30 |
|
|
|
31 |
|
|
//make the query
|
32 |
|
|
if(!isset($_GET['persistent'])){
|
33 |
|
|
$persistent="true";
|
34 |
|
|
}
|
35 |
|
|
else
|
36 |
|
|
{
|
37 |
|
|
$persistent="false";
|
38 |
|
|
}
|
39 |
|
|
|
40 |
|
|
|
41 |
|
|
|
42 |
|
|
$resp = $controller->makeQuery('table',$persistent);
|
43 |
|
|
$resp = json_decode($resp,true);
|
44 |
|
|
//make the header row
|
45 |
|
|
$header = array();
|
46 |
|
|
if($selectedData['xaxistitle'] && $selectedData['xaxistitle'] !='')
|
47 |
|
|
$header[] = $selectedData['xaxistitle'];
|
48 |
|
|
else{
|
49 |
|
|
$temp = explode("-",$selectedData['xaxis']['name']);
|
50 |
|
|
$header[] = $temp[count($temp)-1];
|
51 |
|
|
}
|
52 |
|
|
|
53 |
|
|
for($i=0;$i<count($selectedData['fields']);$i++){
|
54 |
|
|
if(isset($selectedData['fieldsheaders']) && isset($selectedData['fieldsheaders'][$i]) && $selectedData['fieldsheaders'][$i]!=''){
|
55 |
|
|
$header[] = $selectedData['fieldsheaders'][$i];
|
56 |
|
|
}
|
57 |
|
|
else{
|
58 |
|
|
$temp = explode("-",$selectedData['fields'][$i]['fld']);
|
59 |
|
|
if($selectedData['fields'][$i]['agg'] != '')
|
60 |
|
|
$header[] = $selectedData['fields'][$i]['agg']." of ".$temp[count($temp)-1];
|
61 |
|
|
else
|
62 |
|
|
$header[] = $temp[count($temp)-1];
|
63 |
|
|
}
|
64 |
|
|
}
|
65 |
|
|
if($selectedData['group']!='' && $selectedData['group'] !='no'){
|
66 |
|
|
$temp = explode("-",$selectedData['group']);
|
67 |
|
|
$header[] = $temp[count($temp)-1];
|
68 |
|
|
}
|
69 |
|
|
|
70 |
|
|
for($i=0;$i<count($header);$i++){
|
71 |
|
|
//print_r($resp['data'][0][$i]);
|
72 |
|
|
if(is_numeric($resp['data'][0][$i]))
|
73 |
|
|
$header[$i] .= " as number";
|
74 |
|
|
}
|
75 |
|
|
|
76 |
|
|
$tempdata = array();
|
77 |
|
|
$tempdata[] = implode(",",$header);
|
78 |
|
|
for($l=1;$l<count($resp['data']);$l++){
|
79 |
|
|
$tempdata[] = implode(",",$resp['data'][$l]);
|
80 |
|
|
}
|
81 |
|
|
$data = implode("\n",$tempdata);
|
82 |
|
|
//echo $data;
|
83 |
|
|
/*$file = '../data/data.csv';
|
84 |
|
|
$data = file_get_contents($file);
|
85 |
|
|
if ($file === FALSE) {
|
86 |
|
|
die("Couldnt read `$file'");
|
87 |
|
|
}*/
|
88 |
|
|
|
89 |
|
|
|
90 |
|
|
$vt = new csv_vistable($tqx, $tq, $tqrt,$tz,$locale,$extra);
|
91 |
|
|
|
92 |
|
|
$vt->setup_table($data);
|
93 |
|
|
|
94 |
|
|
$result = $vt->execute();
|
95 |
|
|
|
96 |
|
|
echo $result;
|
97 |
|
|
}
|
98 |
|
|
else{
|
99 |
|
|
die("unknown command code");
|
100 |
|
|
}
|
101 |
|
|
}
|
102 |
|
|
else {
|
103 |
|
|
//oops error
|
104 |
|
|
die("no command given");
|
105 |
|
|
}
|
106 |
|
|
//#ob_end_flush();
|
107 |
|
|
?>
|