1 |
38716
|
eri.katsar
|
<!DOCTYPE html
|
2 |
|
|
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
3 |
|
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
4 |
|
|
<html>
|
5 |
|
|
<?php
|
6 |
|
|
require_once('controller.php');
|
7 |
|
|
$controller = new Controller(false);
|
8 |
|
|
|
9 |
|
|
if(isset($_GET['com'])) {
|
10 |
|
|
if($_GET['com'] == "query") {
|
11 |
|
|
$selectedData = json_encode($_GET['data']);
|
12 |
|
|
|
13 |
|
|
|
14 |
|
|
//make the query
|
15 |
|
|
if(!isset($_GET['persistent'])){
|
16 |
|
|
|
17 |
|
|
$persistent="true";
|
18 |
|
|
}
|
19 |
|
|
else
|
20 |
|
|
{
|
21 |
|
|
$persistent="false";
|
22 |
|
|
}
|
23 |
|
|
$resp = $controller->makeQuery('table',$persistent);
|
24 |
|
|
}
|
25 |
|
|
else{
|
26 |
|
|
echo "unknown command code";
|
27 |
|
|
}
|
28 |
|
|
}
|
29 |
|
|
else {
|
30 |
|
|
//oops error
|
31 |
|
|
echo "no command given";
|
32 |
|
|
}
|
33 |
|
|
|
34 |
|
|
?>
|
35 |
|
|
<head>
|
36 |
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
37 |
|
|
<title>google table</title>
|
38 |
|
|
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
|
39 |
|
|
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
|
40 |
|
|
|
41 |
|
|
<link type="text/css" href="js/googlecharts.css" rel="stylesheet" />
|
42 |
|
|
|
43 |
|
|
<script type='text/javascript' src='//www.google.com/jsapi'></script>
|
44 |
|
|
<script type='text/javascript'>
|
45 |
|
|
|
46 |
|
|
function isNumber (o) {
|
47 |
|
|
return ! isNaN (o-0) && o !== null && o !== "" && o !== false;
|
48 |
|
|
}
|
49 |
|
|
|
50 |
|
|
var chart;
|
51 |
|
|
var tableData;
|
52 |
|
|
var selectedData;
|
53 |
|
|
var headers;
|
54 |
|
|
|
55 |
|
|
var wflag = <?php
|
56 |
|
|
if(isset($_GET['w']) && $_GET['w']!='' && $_GET['w'][strlen($_GET['w'])-1] == '%'){
|
57 |
|
|
echo "true";
|
58 |
|
|
}
|
59 |
|
|
else{
|
60 |
|
|
echo "false";
|
61 |
|
|
}
|
62 |
|
|
?>
|
63 |
|
|
|
64 |
|
|
var mywidth = <?php if(isset($_GET['w']) && $_GET['w']!=''){
|
65 |
|
|
if($_GET['w'][strlen($_GET['w'])-1] == '%'){
|
66 |
|
|
echo substr($_GET['w'],0,strlen($_GET['w'])-1);
|
67 |
|
|
|
68 |
|
|
}
|
69 |
|
|
else{
|
70 |
|
|
if($_GET['w'][strlen($_GET['w'])-1] == 'x'){
|
71 |
|
|
echo substr($_GET['w'],0,strlen($_GET['w'])-2);
|
72 |
|
|
}
|
73 |
|
|
else
|
74 |
|
|
echo $_GET['w'];
|
75 |
|
|
}
|
76 |
|
|
}
|
77 |
|
|
else echo '556'; ?>;
|
78 |
|
|
|
79 |
|
|
var hflag = <?php
|
80 |
|
|
if(isset($_GET['h']) && $_GET['h']!='' && $_GET['h'][strlen($_GET['h'])-1] == '%'){
|
81 |
|
|
echo "true";
|
82 |
|
|
}
|
83 |
|
|
else{
|
84 |
|
|
echo "false";
|
85 |
|
|
}
|
86 |
|
|
?>
|
87 |
|
|
|
88 |
|
|
|
89 |
|
|
var myheight = <?php if(isset($_GET['h']) && $_GET['h']!=''){
|
90 |
|
|
if($_GET['h'][strlen($_GET['h'])-1] == '%'){
|
91 |
|
|
echo substr($_GET['h'],0,strlen($_GET['h'])-1);
|
92 |
|
|
|
93 |
|
|
}
|
94 |
|
|
else{
|
95 |
|
|
if($_GET['w'][strlen($_GET['h'])-1] == 'x'){
|
96 |
|
|
echo substr($_GET['h'],0,strlen($_GET['h'])-2);
|
97 |
|
|
}
|
98 |
|
|
else
|
99 |
|
|
echo $_GET['h'];
|
100 |
|
|
}
|
101 |
|
|
}
|
102 |
|
|
else echo '347'; ?>;
|
103 |
|
|
|
104 |
|
|
if(wflag)
|
105 |
|
|
mywidth = mywidth * window.innerWidth / 100;
|
106 |
|
|
if(hflag)
|
107 |
|
|
myheight = myheight * window.innerHeight / 100;
|
108 |
|
|
|
109 |
|
|
tableData = <?php echo $resp ?>;
|
110 |
|
|
|
111 |
|
|
/*tableData['data'].sort(function(a,b) {
|
112 |
|
|
return parseInt(b[1],10)-parseInt(a[1],10);
|
113 |
|
|
});*/
|
114 |
|
|
|
115 |
|
|
selectedData = $.parseJSON(<?php echo $selectedData;?>);
|
116 |
|
|
|
117 |
|
|
google.load('visualization', '1', {packages:['table']});
|
118 |
|
|
google.setOnLoadCallback(draw);
|
119 |
|
|
|
120 |
|
|
function draw() {
|
121 |
|
|
drawTable();
|
122 |
|
|
drawToolbar();
|
123 |
|
|
credits();
|
124 |
|
|
document.getElementById("credits").style.width = (mywidth/2)+"px";
|
125 |
|
|
}
|
126 |
|
|
|
127 |
|
|
function drawTable(){
|
128 |
|
|
$('h1').html(selectedData['title']);
|
129 |
|
|
$('h2').html(selectedData['subtitle']);
|
130 |
|
|
|
131 |
|
|
var data = new google.visualization.DataTable();
|
132 |
|
|
var xtype;
|
133 |
|
|
if(isNumber(tableData['data'][0][0])){
|
134 |
|
|
xtype = "number";
|
135 |
|
|
}
|
136 |
|
|
else{
|
137 |
|
|
xtype = "string";
|
138 |
|
|
}
|
139 |
|
|
|
140 |
|
|
|
141 |
|
|
if(selectedData['xaxistitle'] && selectedData['xaxistitle']!=''){
|
142 |
|
|
data.addColumn(xtype, selectedData['xaxistitle']);
|
143 |
|
|
}
|
144 |
|
|
else{
|
145 |
|
|
var fld = selectedData['xaxis']['name'].split('-');
|
146 |
|
|
if(selectedData['xaxis']['agg']!='')
|
147 |
|
|
data.addColumn(xtype, selectedData['xaxis']['agg']+" of "+fld[fld.length-1]);
|
148 |
|
|
else
|
149 |
|
|
data.addColumn(xtype, fld[fld.length-1]);
|
150 |
|
|
}
|
151 |
|
|
for(var i=0;i<selectedData['fields'].length;i++){
|
152 |
|
|
var ftype = '';
|
153 |
|
|
if(isNumber(tableData['data'][0][i+1]))
|
154 |
|
|
ftype= 'number';
|
155 |
|
|
else
|
156 |
|
|
ftype = 'string';
|
157 |
|
|
|
158 |
|
|
if(selectedData['fieldsheaders'] && selectedData['fieldsheaders'][i] && selectedData['fieldsheaders'][i]!=''){
|
159 |
|
|
data.addColumn(ftype, selectedData['fieldsheaders'][i]);
|
160 |
|
|
}
|
161 |
|
|
else{
|
162 |
|
|
fld = selectedData['fields'][i]['fld'].split('-');
|
163 |
|
|
if(selectedData['fields'][i]['agg']!='')
|
164 |
|
|
data.addColumn(ftype, selectedData['fields'][i]['agg']+" of "+fld[fld.length-1]);
|
165 |
|
|
else
|
166 |
|
|
data.addColumn(ftype, fld[fld.length-1]);
|
167 |
|
|
}
|
168 |
|
|
}
|
169 |
|
|
if(selectedData['group'] != '' && selectedData['group'] != 'no'){
|
170 |
|
|
fld = selectedData['group'].split('-');
|
171 |
|
|
data.addColumn('string', fld[fld.length-1]);
|
172 |
|
|
}
|
173 |
|
|
else if(selectedData['color'] != '' && selectedData['color'] != 'no'){
|
174 |
|
|
fld = selectedData['color'].split('-');
|
175 |
|
|
data.addColumn('string', fld[fld.length-1]);
|
176 |
|
|
}
|
177 |
|
|
|
178 |
|
|
var rows = new Array();
|
179 |
|
|
for(var i in tableData['data']){
|
180 |
|
|
if(xtype=="string" && isNumber(tableData['data'][i][0]))
|
181 |
|
|
continue;
|
182 |
|
|
var row = new Array();
|
183 |
|
|
var len=tableData['data'][i].length;
|
184 |
|
|
|
185 |
|
|
for(var j=0;j<len;j++){
|
186 |
|
|
row.push(tableData['data'][i][j]);
|
187 |
|
|
}
|
188 |
|
|
rows.push(row);
|
189 |
|
|
}
|
190 |
|
|
data.addRows(rows);
|
191 |
|
|
//data.setProperty(0,0,'style','max-width:200px');
|
192 |
|
|
var table = new google.visualization.Table(document.getElementById('table_div'));
|
193 |
|
|
table.draw(data, {showRowNumber: true,page:"enable",pageSize:30});
|
194 |
|
|
}
|
195 |
|
|
|
196 |
|
|
function drawToolbar() {
|
197 |
|
|
|
198 |
|
|
var components = [
|
199 |
|
|
{type: 'html', datasource: 'datasource.php?com=query&data='+<?php echo $selectedData;?>},
|
200 |
|
|
{type: 'csv', datasource: 'datasource.php?com=query&data='+<?php echo $selectedData;?>},
|
201 |
|
|
{type: 'htmlcode', datasource: '<?php echo $stats_server ?>/datasource.php?com=query&data='+<?php echo $selectedData;?>,
|
202 |
|
|
style: 'width: 800px; height: 700px; border: 3px solid purple;'}
|
203 |
|
|
];
|
204 |
|
|
//TODO hide toolbar!!!
|
205 |
|
|
// var container = document.getElementById('toolbar');
|
206 |
|
|
// google.visualization.drawToolbar(container, components);
|
207 |
|
|
};
|
208 |
|
|
|
209 |
|
|
function credits(){
|
210 |
|
|
var today = new Date();
|
211 |
|
|
var dd = today.getDate();
|
212 |
|
|
var mm = today.getMonth()+1; //January is 0!
|
213 |
|
|
var yyyy = today.getFullYear();
|
214 |
|
|
|
215 |
|
|
var cr = document.getElementById("credits");
|
216 |
|
|
cr.innerHTML = "from OpenAIRE via Google Charts (date: " + dd + "/" + mm + "/" + yyyy +")";
|
217 |
|
|
}
|
218 |
|
|
|
219 |
|
|
</script>
|
220 |
|
|
</head>
|
221 |
|
|
|
222 |
|
|
<body>
|
223 |
|
|
<h1 id='title'></h1>
|
224 |
|
|
<h2 id='subtitle'></h2>
|
225 |
|
|
|
226 |
|
|
<div id='table_div' style="margin:auto;width:80%;height:95%"></div>
|
227 |
|
|
<div id="toolbar-outer" style="width:85%;"><div id='toolbar' style="margin:auto;width:218px;padding-top:40px;"></div></div>
|
228 |
|
|
<div id="credits"></div>
|
229 |
|
|
</body>
|
230 |
|
|
</html>
|