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