Project

General

Profile

1
<!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
		$resp = $controller->makeQuery('table');
13
	}
14
	else{
15
		echo "unknown command code";
16
	}
17
}
18
else {
19
	//oops error
20
	echo "no command given";
21
}
22

    
23
?>
24
  <head>
25
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
26
	<title>google table</title>
27
	<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
28
	<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
29

    
30
	<link type="text/css" href="js/googlecharts.css" rel="stylesheet" />
31

    
32
	<script type='text/javascript' src='//www.google.com/jsapi'></script>
33
	<script type='text/javascript'>
34

    
35
	function isNumber (o) {
36
		return ! isNaN (o-0) && o !== null && o !== "" && o !== false;
37
	}
38

    
39
	var chart;
40
	var tableData;
41
	var selectedData;
42
	var headers;
43

    
44
 	var wflag = <?php
45
                if(isset($_GET['w']) && $_GET['w']!='' && $_GET['w'][strlen($_GET['w'])-1] == '%'){
46
                        echo "true";
47
                }
48
                else{
49
                        echo "false";
50
                }
51
                ?>
52

    
53
        var mywidth =  <?php if(isset($_GET['w']) && $_GET['w']!=''){
54
                        if($_GET['w'][strlen($_GET['w'])-1] == '%'){
55
                                echo substr($_GET['w'],0,strlen($_GET['w'])-1);
56

    
57
                        }
58
                        else{
59
                                if($_GET['w'][strlen($_GET['w'])-1] == 'x'){
60
                                        echo substr($_GET['w'],0,strlen($_GET['w'])-2);
61
                                }
62
                                else
63
                                        echo $_GET['w'];
64
                        }
65
                }
66
                else echo '556'; ?>;
67

    
68
        var hflag = <?php
69
                if(isset($_GET['h']) && $_GET['h']!='' && $_GET['h'][strlen($_GET['h'])-1] == '%'){
70
                        echo "true";
71
                }
72
                else{
73
                        echo "false";
74
                }
75
                ?>
76

    
77

    
78
	 var myheight =  <?php if(isset($_GET['h']) && $_GET['h']!=''){
79
                        if($_GET['h'][strlen($_GET['h'])-1] == '%'){
80
                                echo substr($_GET['h'],0,strlen($_GET['h'])-1);
81

    
82
                        }
83
                        else{
84
                                if($_GET['w'][strlen($_GET['h'])-1] == 'x'){
85
                                        echo substr($_GET['h'],0,strlen($_GET['h'])-2);
86
                                }
87
                                else
88
                                        echo $_GET['h'];
89
                        }
90
                }
91
                else echo '347'; ?>;
92

    
93
        if(wflag)
94
                mywidth = mywidth * window.innerWidth / 100;
95
        if(hflag)
96
                myheight = myheight * window.innerHeight / 100;
97

    
98
	tableData = <?php echo $resp ?>;
99

    
100
	/*tableData['data'].sort(function(a,b) {
101
		return parseInt(b[1],10)-parseInt(a[1],10);
102
	});*/
103

    
104
	selectedData = $.parseJSON(<?php echo $selectedData;?>);
105

    
106
		google.load('visualization', '1', {packages:['table']});
107
		google.setOnLoadCallback(draw);
108

    
109
		function draw() {
110
			drawTable();
111
			drawToolbar();
112
			credits();
113
	        document.getElementById("credits").style.width = (mywidth/2)+"px";
114
		}
115

    
116
		function drawTable(){
117
			$('h1').html(selectedData['title']);
118
			$('h2').html(selectedData['subtitle']);
119

    
120
			var data = new google.visualization.DataTable();
121
			var xtype;
122
			if(isNumber(tableData['data'][0][0])){
123
				xtype = "number";
124
			}
125
			else{
126
				xtype = "string";
127
			}
128

    
129

    
130
			if(selectedData['xaxistitle'] && selectedData['xaxistitle']!=''){
131
					data.addColumn(xtype, selectedData['xaxistitle']);
132
			}
133
			else{
134
				var fld = selectedData['xaxis']['name'].split('-');
135
				if(selectedData['xaxis']['agg']!='')
136
					data.addColumn(xtype, selectedData['xaxis']['agg']+" of "+fld[fld.length-1]);
137
				else
138
					data.addColumn(xtype, fld[fld.length-1]);
139
			}
140
			for(var i=0;i<selectedData['fields'].length;i++){
141
				var ftype = '';
142
				if(isNumber(tableData['data'][0][i+1]))
143
					ftype= 'number';
144
				else
145
					ftype = 'string';
146

    
147
				if(selectedData['fieldsheaders'] && selectedData['fieldsheaders'][i] && selectedData['fieldsheaders'][i]!=''){
148
						data.addColumn(ftype, selectedData['fieldsheaders'][i]);
149
				}
150
				else{
151
					fld = selectedData['fields'][i]['fld'].split('-');
152
					if(selectedData['fields'][i]['agg']!='')
153
						data.addColumn(ftype, selectedData['fields'][i]['agg']+" of "+fld[fld.length-1]);
154
					else
155
						data.addColumn(ftype, fld[fld.length-1]);
156
				}
157
			}
158
			if(selectedData['group'] != '' && selectedData['group'] != 'no'){
159
				fld = selectedData['group'].split('-');
160
				data.addColumn('string', fld[fld.length-1]);
161
			}
162
			else if(selectedData['color'] != '' && selectedData['color'] != 'no'){
163
				fld = selectedData['color'].split('-');
164
				data.addColumn('string', fld[fld.length-1]);
165
			}
166

    
167
			var rows = new Array();
168
			for(var i in tableData['data']){
169
				if(xtype=="string" && isNumber(tableData['data'][i][0]))
170
                                                continue;
171
				var row = new Array();
172
				var len=tableData['data'][i].length;
173

    
174
				for(var j=0;j<len;j++){
175
					row.push(tableData['data'][i][j]);
176
				}
177
				rows.push(row);
178
			}
179
			data.addRows(rows);
180
			//data.setProperty(0,0,'style','max-width:200px');
181
			var table = new google.visualization.Table(document.getElementById('table_div'));
182
			table.draw(data, {showRowNumber: true,page:"enable",pageSize:30});
183
		}
184

    
185
		function drawToolbar() {
186
			var components = [
187
				{type: 'html', datasource: 'datasource.php?com=query&data='+<?php echo $selectedData;?>},
188
				{type: 'csv', datasource: 'datasource.php?com=query&data='+<?php echo $selectedData;?>},
189
				{type: 'htmlcode', datasource: '<?php echo $stats_server ?>/datasource.php?com=query&data='+<?php echo $selectedData;?>,
190
				style: 'width: 800px; height: 700px; border: 3px solid purple;'}
191
			];
192

    
193
			var container = document.getElementById('toolbar');
194
			google.visualization.drawToolbar(container, components);
195
		};
196

    
197
        function credits(){
198
                var today = new Date();
199
                var dd = today.getDate();
200
                var mm = today.getMonth()+1; //January is 0!
201
                var yyyy = today.getFullYear();
202

    
203
                var cr = document.getElementById("credits");
204
                cr.innerHTML = "from OpenAIRE via Google Charts (date: " + dd + "/" + mm + "/" + yyyy +")";
205
        }
206

    
207
	</script>
208
  </head>
209

    
210
  <body>
211
  <h1 id='title'></h1>
212
  <h2 id='subtitle'></h2>
213

    
214
	<div id='table_div' style="margin:auto;width:80%;height:95%"></div>
215
	<div id="toolbar-outer" style="width:85%;"><div id='toolbar' style="margin:auto;width:218px;padding-top:40px;"></div></div>
216
  	<div id="credits"></div>
217
 </body>
218
</html>
(9-9/29)