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

    
123
			if(isNumber(tableData['data'][0][0])){
124
				xtype = "number";
125
			}
126
			else{
127
				xtype = "string";
128
			}
129

    
130

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

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

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

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

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

    
196
			var container = document.getElementById('toolbar');
197
			google.visualization.drawToolbar(container, components);
198
		};
199

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

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

    
210
	</script>
211
  </head>
212

    
213
  <body>
214
  <h1 id='title'></h1>
215
  <h2 id='subtitle'></h2>
216

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