Project

General

Profile

« Previous | Next » 

Revision 37264

Added by Eri Katsari about 9 years ago

Added Persistent flag for queries; added cache clean up after migrate

View differences:

choromap.php
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
	//oops error
11
	echo "no command given";
12
	return;
13
}
14

  
15
if($_GET['com'] != "query") {
16
	echo "unknown command code";
17
	return;
18
}
19
$selectedData = json_encode($_GET['data']);
20
// the response of the db
21
$resp = $controller->makeQuery('table');
22

  
23
// the selected data
24
$myData = json_decode($_GET['data']);
25
// the filters to include
26
$myfilters = $myData->incfilters;
27
// if all posible values are included, get them from the db
28
for($i=0;$i<count($myfilters);$i++){
29
	if(isset($myfilters[$i]->values) && $myfilters[$i]->values=='all'){
30
		$temp = $controller->getFilterData($myData->table,$myfilters[$i]->name);
31
		$myfilters[$i]->values = $temp['data'];
32
	}
33
}
34

  
35
?>
36
  <head>
37
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
38
	<title>choromap</title>
39
	<!-- Include JQuery Core-->
40
	<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
41
	<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
42
	<!-- Include styles -->
43
	<!-- <link href="//code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css" rel="stylesheet"> -->
44
	<!-- <link href="./js/jquery/css/start/jquery-ui-1.8.20.custom.css" type="text/css">  -->
45
	<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css" />
46

  
47
	<link type="text/css" href="./js/googlecharts.css" rel="stylesheet" />
48
	<link rel="stylesheet" href="./js/filters.css" />
49

  
50

  
51

  
52
	<!-- Google charts api -->
53
	<script type='text/javascript' src='//www.google.com/jsapi'></script>
54

  
55
<script type='text/javascript'>
56
	var chart;
57
	var tableData;
58
	var selectedData;
59
	var filterData;
60
	var myFilter;
61
	var rows = null;
62

  
63
	//the width is set to percentage
64
	var wflag = <?php if(isset($_GET['w']) && $_GET['w']!='' && $_GET['w'][strlen($_GET['w'])-1] == '%'){echo "true";}
65
                	else{echo "false";}?>
66

  
67
	var mywidth =  <?php if(isset($_GET['w']) && $_GET['w']!=''){ 
68
		                if($_GET['w'][strlen($_GET['w'])-1] == '%'){
69
		                        echo substr($_GET['w'],0,strlen($_GET['w'])-1);
70
		 		}else{
71
		                        if($_GET['w'][strlen($_GET['w'])-1] == 'x'){
72
		                                echo substr($_GET['w'],0,strlen($_GET['w'])-2);
73
		                        }else
74
				               echo $_GET['w'];
75
		                }
76
                	     }else echo '556'; ?>;
77
	//the height is set to percentage
78
	var hflag = <?php if(isset($_GET['h']) && $_GET['h']!='' && $_GET['h'][strlen($_GET['h'])-1] == '%'){echo "true";}
79
                	else{echo "false";}?>
80

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

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

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

  
96
	tableData = <?php echo $resp ?>;
97

  
98
	selectedData = $.parseJSON(<?php echo $selectedData;?>);
99

  
100
	google.load('visualization', '1', {'packages': ['geomap']});
101
    google.setOnLoadCallback(draw);
102

  
103
	function draw() {
104
		drawRegionsMap();
105
		drawToolbar();
106
		credits();
107
		filterData = <?php echo json_encode($myfilters);?>;
108
		renderfilters();
109
		controlsforfilters();
110

  
111
		document.getElementById("chart_div").style.width = mywidth+"px";
112
	        document.getElementById("chart_div").style.height = myheight+"px";
113
		document.getElementById("toolbar").style.width = (mywidth/2)+"px";
114
		document.getElementById("credits").style.width = (mywidth/2)+"px";
115
	}
116

  
117
	function drawRegionsMap() {
118
		$('h1').html(selectedData['title']);
119
		$('h2').html(selectedData['subtitle']);
120
		//var rows = new Array();
121
		var headerrow = new Array();
122

  
123
		var tlen = tableData['data'].length;
124
		if(tlen > 0){
125
			rows = new Array();
126
			if(selectedData['xaxistitle'] && selectedData['xaxistitle']!=''){
127
				headerrow.push(selectedData['xaxistitle']);
128
			}
129
			else{
130
				var fld = selectedData['xaxis']['name'].split('-');
131
				if(selectedData['xaxis']['agg']!='')
132
					headerrow.push(selectedData['xaxis']['agg']+" of "+fld[fld.length-1]);
133
				else
134
					headerrow.push(fld[fld.length-1]);
135
			}
136
			for(var i in selectedData['fields']){
137
				if(selectedData['fieldsheaders'] && selectedData['fieldsheaders'][i] && selectedData['fieldsheaders'][i]!=''){
138
					headerrow.push(selectedData['fieldsheaders'][i]);
139
				}
140
				else{
141
					fld = selectedData['fields'][i]['fld'].split('-');
142
					if(selectedData['fields'][i]['agg']!='')
143
						headerrow.push(selectedData['fields'][i]['agg']+" of "+fld[fld.length-1]);
144
					else
145
						headerrow.push(fld[fld.length-1]);
146
				}
147
			}
148
			//headerrow.push({type: 'string', role: 'tooltip'});
149
			rows.push(headerrow);
150
			for(var i=0;i<tlen;i++){
151
				if(tableData['data'][i][0] != "UNKNOWN"){
152
					var row = new Array();
153
					for(var j in tableData['data'][i]){
154
						row.push(tableData['data'][i][j]);
155
					}
156
					rows.push(row);
157
				}
158
			}
159
			//alert(JSON.stringify(rows));
160
		}
161
		else{
162
			for(var i=1;i<rows.length;i++){
163
				for(var j=1;j<rows[i].length;j++){
164
					rows[i][j]=0;
165
				}
166
			}
167
		}
168
		var data = google.visualization.arrayToDataTable(rows);
169

  
170
        	var options = {
171
			displayMode: 'auto',
172
			region: '150',
173
			//width: mywidth,
174
			//heigth: myheight,
175
			colors: [0xCED8F6,0x282F93]
176
		};
177
	$("#chart_div").empty();
178
        var chart = new google.visualization.GeoMap(document.getElementById('chart_div'));
179
        chart.draw(data, options);
180
    };
181

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

  
190
		var container = document.getElementById('toolbar');
191
		google.visualization.drawToolbar(container, components);
192
	}
193

  
194
	function numberWithCommas(num){
195
		if(typeof num == "string")
196
			var array = num;
197
		else
198
			var array = num.toString().split('');
199
		var index = -3;
200
		var len = array.length;
201
		while(len + index > 0){
202
			array.splice(index, 0 , ',');
203
			index -= 4;
204
		}
205
		return array.join('');
206
	}
207

  
208

  
209
	function isNumber (o) {
210
		return ! isNaN (o-0) && o !== null && o !== "" && o !== false;
211
	}
212

  
213
	function credits(){
214
		var today = new Date();
215
		var dd = today.getDate();
216
		var mm = today.getMonth()+1; //January is 0!
217
		var yyyy = today.getFullYear();
218

  
219
		var cr = document.getElementById("credits");
220
		cr.innerHTML = "from OpenAIRE via Google Charts (date: " + dd + "/" + mm + "/" + yyyy +")";
221
	}
222

  
223

  
224
function renderfilters(){
225
	if(filterData!=null){
226
		var container = document.getElementById("filters");
227

  
228
		var len = filterData.length
229
		for(var i=0;i<len;i++){
230
			//checkboxes
231
			if(filterData[i].values != undefined){
232
				var str = "<div class='filter'><div class='filterHeader'><p>"+filterData[i].showname+"</p><input type='hidden' value='"+filterData[i].name+"' class='filtername'/></div><a class='all' href='#'>select all</a><a class='none' href='#' style='display:none;float:right'>clear</a><div class='filterForm'><div class='formContainer'><form id='"+filterData[i].name+"' class='filterform'>";
233
				for(var v=0;v<filterData[i].values.length;v++){
234
					str+="<input type='checkbox' value='"+filterData[i].values[v]+"' name='form"+filterData[i].name+"'>"+filterData[i].values[v]+"<br>";
235
				}
236
				str +=	"</form></div></div></div>";
237
				$(container).append(str);
238
			}
239
			//slider <------ NOT WORKING YET
240
			else{
241
				var str = "<div class='filter'><div class='filterHeader'><p>"+filterData[i].showname+"</p><input type='hidden' value='"+filterData[i].name+"' class='filtername'/></div>";
242
				str += "<div class='filter-slider'><div class='slider-container'><div id='slider"+filterData[i].name+"' class='ui-slider ui-slider-horizontal ui-widget ui-widget-content ui-corner-all' aria-disabled='false'></div></div>";
243

  
244
				str += "<span class='price-tip slider-user-min'><span id='userMin"+filterData[i].name+"'>"+filterData[i]['min']+"</span></span>";
245
				str += "<span class='price-tip slider-user-max'><span id='userMax"+filterData[i].name+"'>"+filterData[i]['max']+"</span></span>";
246
				str += "<span class='min' style='display:none'><span id='productMin"+filterData[i].name+"'>"+filterData[i]['min']+"</span></span>";
247
				str += "<span class='max' style='display:none'><span id='productMax"+filterData[i].name+"'>"+filterData[i]['max']+"</span></span>";
248
				str += "</div></div>";
249
				$(container).append(str);
250
				myFilter = filterData[i];
251
				$(function(){
252
					$("#slider"+myFilter.name).slider({
253
						step: 1,
254
						range: true,
255
						min: parseInt(myFilter['min']),
256
						max: parseInt(myFilter['max']),
257
						values: [parseInt(myFilter['min']), parseInt(myFilter['max'])],
258
						slide: function(event, ui){
259
							$(this).parent().parent().find('.slider-user-min').find('span').html(ui.values[0]);
260
							$(this).parent().parent().find('.slider-user-max').find('span').html(ui.values[1]);
261
							slidermove(myFilter.name,ui.values[0],ui.values[1]);
262
						}
263
					});
264
				});
265
			}
266
		}
267
	}
268
}
269

  
270
function slidermove(field,min,max){
271
	var myfilters = selectedData['filters'];
272
	var len = myfilters.length;
273
	for(var i=0;i<len;i++){
274
		if(myfilters[i]['name'] == field){
275
			myfilters[i]['min'] = min;
276
			myfilters[i]['max'] = max;
277
			break;
278
		}
279
	}
280

  
281

  
282
	//ajax call to get the new data
283
	$.ajax({
284
	   type: "GET",
285
	   url: "ajaxRouter9.php",
286
	   data: "com=query&type=table&data="+encodeURIComponent(JSON.stringify(selectedData)),
287
	   success: function(resp){
288
		 // we have the response
289
		chartDataFromServer = JSON.parse(resp);
290
		tableData = JSON.parse(resp);
291
		drawRegionsMap();
292
		drawToolbar();
293
		credits();
294
		},
295
	   error: function(e){
296
		 alert('Error:' + e);
297
	   }
298
	});
299
}
300

  
301
function controlsforfilters(){
302
	$("a.all").live("click",function(){
303
		$(this).siblings('.filterForm').find('input').attr("checked","checked");
304
		newValues($(this).siblings('.filterForm').find('input')[0]);
305
		return false;
306
	});
307

  
308
	$("a.none").live("click",function(){
309
                $(this).siblings('.filterForm').find('input').removeAttr("checked");
310
		newValues($(this).siblings('.filterForm').find('input')[0]);		
311
		return false;
312
        });
313

  
314
	$(".formContainer input").live("click",function(){
315
		newValues(this);
316
	});
317
}
318

  
319
function newValues(obj){
320
	var field = $(obj).parent().attr('id');
321
	var myfilters = selectedData['filters'];
322
	var thisfilter;
323
	for(var i=0;i<selectedData['incfilters'].length;i++){
324
		if(selectedData['incfilters'][i]['name'] == field){
325
			thisfilter = selectedData['incfilters'][i];
326
			break;
327
		}
328
	}
329

  
330
	//change the url params
331
	//if is it checked
332
	if($(obj).is(":checked")){
333
		$("a.none").show();
334
		var flag = false;
335
		var i;
336
		for(i=0;i<myfilters.length;i++){
337
			if(myfilters[i]['name'] == field){
338
				flag=true;
339
				break;
340
			}
341
		}
342
		//if there is already such a filter delete all values and insert all the checked
343
		if(flag){
344
			myfilters[i].values = new Array();
345
			$(obj).parent().find("input:checked").each(function(){
346
				myfilters[i].values.push($(this).val());
347
			});
348
			//myfilters[i].values.push($(obj).val());
349
		}
350
		//if there is no such filter
351
		else{
352
			//create one
353
			var newfilter = new Object();
354
			newfilter.name = field;
355
			newfilter.values = new Array();
356
			newfilter.values[0] = $(obj).val();
357
			myfilters.push(newfilter);
358
		}
359
	}
360
	//if it was unchecked
361
	else{
362
		if($(obj).parent().find("input:checked").length == 0)
363
			$("a.none").hide();
364

  
365
		//there should be already such a filter
366
		var flag = false;
367
                var i;
368
                for(i=0;i<myfilters.length;i++){
369
                        if(myfilters[i]['name'] == field){
370
                                flag=true;
371
                                break;
372
                        }
373
                }
374
		//remove the value
375
		var j;
376
		for(j=0;j<myfilters[i].values.length;j++){
377
			if(myfilters[i].values[j] == $(obj).val()){
378
				myfilters[i].values.splice(j,1);
379
				break;
380
			}
381
		}
382
		//if no more values, add the values in the incfilter list and if it is all remove the filter
383
		if(myfilters[i].values.length == 0){
384
			if(thisfilter.values[0]=="all")
385
				myfilters.splice(i,1);
386
			else
387
				myfilters[i].values = thisfilter.values;
388
		}
389
	}
390
	//ajax call to get the new data
391
	$.ajax({
392
	   type: "GET",
393
	   url: "ajaxRouter9.php",
394
	   data: "com=query&type=table&data="+encodeURIComponent(JSON.stringify(selectedData)),  
395
	   success: function(resp){
396
		 // we have the response
397
		chartDataFromServer = JSON.parse(resp);
398
		tableData = JSON.parse(resp);
399
		drawRegionsMap();
400
		drawToolbar();
401
		credits();
402
		},
403
	   error: function(e){
404
		 alert('Error: ' + e);
405
	   }
406
	});
407

  
408
}
409

  
410

  
411

  
412
	</script>
413
  </head>
414
  <body>
415
	<h1 id='title'></h1>
416
	<h2 id='subtitle'></h2>
417
	<div id="chart_div" style="margin:auto;"></div>
418
	<div id='toolbar' style="margin:auto;padding-top:40px"></div>
419
	<div id="credits" style=""></div>
420
	<div id="filters"></div>
421
  </body>
422
</html>
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
	//oops error
11
	echo "no command given";
12
	return;
13
}
14

  
15
if($_GET['com'] != "query") {
16
	echo "unknown command code";
17
	return;
18
}
19
$selectedData = json_encode($_GET['data']);
20
// the response of the db
21

  
22
//make the query
23
if(!isset($_GET['persistent'])){
24
     $persistent="true";
25
}
26
else
27
{
28
$persistent="false";
29
}
30
$resp = $controller->makeQuery('table',$persistent);
31

  
32
// the selected data
33
$myData = json_decode($_GET['data']);
34
// the filters to include
35
$myfilters = $myData->incfilters;
36
// if all posible values are included, get them from the db
37
for($i=0;$i<count($myfilters);$i++){
38
	if(isset($myfilters[$i]->values) && $myfilters[$i]->values=='all'){
39
		$temp = $controller->getFilterData($myData->table,$myfilters[$i]->name);
40
		$myfilters[$i]->values = $temp['data'];
41
	}
42
}
43

  
44
?>
45
  <head>
46
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
47
	<title>choromap</title>
48
	<!-- Include JQuery Core-->
49
	<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
50
	<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
51
	<!-- Include styles -->
52
	<!-- <link href="//code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css" rel="stylesheet"> -->
53
	<!-- <link href="./js/jquery/css/start/jquery-ui-1.8.20.custom.css" type="text/css">  -->
54
	<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css" />
55

  
56
	<link type="text/css" href="./js/googlecharts.css" rel="stylesheet" />
57
	<link rel="stylesheet" href="./js/filters.css" />
58

  
59

  
60

  
61
	<!-- Google charts api -->
62
	<script type='text/javascript' src='//www.google.com/jsapi'></script>
63

  
64
<script type='text/javascript'>
65
	var chart;
66
	var tableData;
67
	var selectedData;
68
	var filterData;
69
	var myFilter;
70
	var rows = null;
71

  
72
	//the width is set to percentage
73
	var wflag = <?php if(isset($_GET['w']) && $_GET['w']!='' && $_GET['w'][strlen($_GET['w'])-1] == '%'){echo "true";}
74
                	else{echo "false";}?>
75

  
76
	var mywidth =  <?php if(isset($_GET['w']) && $_GET['w']!=''){ 
77
		                if($_GET['w'][strlen($_GET['w'])-1] == '%'){
78
		                        echo substr($_GET['w'],0,strlen($_GET['w'])-1);
79
		 		}else{
80
		                        if($_GET['w'][strlen($_GET['w'])-1] == 'x'){
81
		                                echo substr($_GET['w'],0,strlen($_GET['w'])-2);
82
		                        }else
83
				               echo $_GET['w'];
84
		                }
85
                	     }else echo '556'; ?>;
86
	//the height is set to percentage
87
	var hflag = <?php if(isset($_GET['h']) && $_GET['h']!='' && $_GET['h'][strlen($_GET['h'])-1] == '%'){echo "true";}
88
                	else{echo "false";}?>
89

  
90
	var myheight =  <?php if(isset($_GET['h']) && $_GET['h']!=''){
91
		                if($_GET['h'][strlen($_GET['h'])-1] == '%'){
92
		                        echo substr($_GET['h'],0,strlen($_GET['h'])-1);
93

  
94
		                }else{ 
95
		                        if($_GET['w'][strlen($_GET['h'])-1] == 'x'){
96
		                                echo substr($_GET['h'],0,strlen($_GET['h'])-2);
97
		                        }else
98
		                                echo $_GET['h'];
99
		                }
100
                	     }else echo '347'; ?>;
101

  
102
	if(wflag) mywidth = mywidth * window.innerWidth / 100;
103
	if(hflag) myheight = myheight * window.innerHeight / 100;
104

  
105
	tableData = <?php echo $resp ?>;
106

  
107
	selectedData = $.parseJSON(<?php echo $selectedData;?>);
108

  
109
	google.load('visualization', '1', {'packages': ['geomap']});
110
    google.setOnLoadCallback(draw);
111

  
112
	function draw() {
113
		drawRegionsMap();
114
		drawToolbar();
115
		credits();
116
		filterData = <?php echo json_encode($myfilters);?>;
117
		renderfilters();
118
		controlsforfilters();
119

  
120
		document.getElementById("chart_div").style.width = mywidth+"px";
121
	        document.getElementById("chart_div").style.height = myheight+"px";
122
		document.getElementById("toolbar").style.width = (mywidth/2)+"px";
123
		document.getElementById("credits").style.width = (mywidth/2)+"px";
124
	}
125

  
126
	function drawRegionsMap() {
127
		$('h1').html(selectedData['title']);
128
		$('h2').html(selectedData['subtitle']);
129
		//var rows = new Array();
130
		var headerrow = new Array();
131

  
132
		var tlen = tableData['data'].length;
133
		if(tlen > 0){
134
			rows = new Array();
135
			if(selectedData['xaxistitle'] && selectedData['xaxistitle']!=''){
136
				headerrow.push(selectedData['xaxistitle']);
137
			}
138
			else{
139
				var fld = selectedData['xaxis']['name'].split('-');
140
				if(selectedData['xaxis']['agg']!='')
141
					headerrow.push(selectedData['xaxis']['agg']+" of "+fld[fld.length-1]);
142
				else
143
					headerrow.push(fld[fld.length-1]);
144
			}
145
			for(var i in selectedData['fields']){
146
				if(selectedData['fieldsheaders'] && selectedData['fieldsheaders'][i] && selectedData['fieldsheaders'][i]!=''){
147
					headerrow.push(selectedData['fieldsheaders'][i]);
148
				}
149
				else{
150
					fld = selectedData['fields'][i]['fld'].split('-');
151
					if(selectedData['fields'][i]['agg']!='')
152
						headerrow.push(selectedData['fields'][i]['agg']+" of "+fld[fld.length-1]);
153
					else
154
						headerrow.push(fld[fld.length-1]);
155
				}
156
			}
157
			//headerrow.push({type: 'string', role: 'tooltip'});
158
			rows.push(headerrow);
159
			for(var i=0;i<tlen;i++){
160
				if(tableData['data'][i][0] != "UNKNOWN"){
161
					var row = new Array();
162
					for(var j in tableData['data'][i]){
163
						row.push(tableData['data'][i][j]);
164
					}
165
					rows.push(row);
166
				}
167
			}
168
			//alert(JSON.stringify(rows));
169
		}
170
		else{
171
			for(var i=1;i<rows.length;i++){
172
				for(var j=1;j<rows[i].length;j++){
173
					rows[i][j]=0;
174
				}
175
			}
176
		}
177
		var data = google.visualization.arrayToDataTable(rows);
178

  
179
        	var options = {
180
			displayMode: 'auto',
181
			region: '150',
182
			//width: mywidth,
183
			//heigth: myheight,
184
			colors: [0xCED8F6,0x282F93]
185
		};
186
	$("#chart_div").empty();
187
        var chart = new google.visualization.GeoMap(document.getElementById('chart_div'));
188
        chart.draw(data, options);
189
    };
190

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

  
199
		var container = document.getElementById('toolbar');
200
		google.visualization.drawToolbar(container, components);
201
	}
202

  
203
	function numberWithCommas(num){
204
		if(typeof num == "string")
205
			var array = num;
206
		else
207
			var array = num.toString().split('');
208
		var index = -3;
209
		var len = array.length;
210
		while(len + index > 0){
211
			array.splice(index, 0 , ',');
212
			index -= 4;
213
		}
214
		return array.join('');
215
	}
216

  
217

  
218
	function isNumber (o) {
219
		return ! isNaN (o-0) && o !== null && o !== "" && o !== false;
220
	}
221

  
222
	function credits(){
223
		var today = new Date();
224
		var dd = today.getDate();
225
		var mm = today.getMonth()+1; //January is 0!
226
		var yyyy = today.getFullYear();
227

  
228
		var cr = document.getElementById("credits");
229
		cr.innerHTML = "from OpenAIRE via Google Charts (date: " + dd + "/" + mm + "/" + yyyy +")";
230
	}
231

  
232

  
233
function renderfilters(){
234
	if(filterData!=null){
235
		var container = document.getElementById("filters");
236

  
237
		var len = filterData.length
238
		for(var i=0;i<len;i++){
239
			//checkboxes
240
			if(filterData[i].values != undefined){
241
				var str = "<div class='filter'><div class='filterHeader'><p>"+filterData[i].showname+"</p><input type='hidden' value='"+filterData[i].name+"' class='filtername'/></div><a class='all' href='#'>select all</a><a class='none' href='#' style='display:none;float:right'>clear</a><div class='filterForm'><div class='formContainer'><form id='"+filterData[i].name+"' class='filterform'>";
242
				for(var v=0;v<filterData[i].values.length;v++){
243
					str+="<input type='checkbox' value='"+filterData[i].values[v]+"' name='form"+filterData[i].name+"'>"+filterData[i].values[v]+"<br>";
244
				}
245
				str +=	"</form></div></div></div>";
246
				$(container).append(str);
247
			}
248
			//slider <------ NOT WORKING YET
249
			else{
250
				var str = "<div class='filter'><div class='filterHeader'><p>"+filterData[i].showname+"</p><input type='hidden' value='"+filterData[i].name+"' class='filtername'/></div>";
251
				str += "<div class='filter-slider'><div class='slider-container'><div id='slider"+filterData[i].name+"' class='ui-slider ui-slider-horizontal ui-widget ui-widget-content ui-corner-all' aria-disabled='false'></div></div>";
252

  
253
				str += "<span class='price-tip slider-user-min'><span id='userMin"+filterData[i].name+"'>"+filterData[i]['min']+"</span></span>";
254
				str += "<span class='price-tip slider-user-max'><span id='userMax"+filterData[i].name+"'>"+filterData[i]['max']+"</span></span>";
255
				str += "<span class='min' style='display:none'><span id='productMin"+filterData[i].name+"'>"+filterData[i]['min']+"</span></span>";
256
				str += "<span class='max' style='display:none'><span id='productMax"+filterData[i].name+"'>"+filterData[i]['max']+"</span></span>";
257
				str += "</div></div>";
258
				$(container).append(str);
259
				myFilter = filterData[i];
260
				$(function(){
261
					$("#slider"+myFilter.name).slider({
262
						step: 1,
263
						range: true,
264
						min: parseInt(myFilter['min']),
265
						max: parseInt(myFilter['max']),
266
						values: [parseInt(myFilter['min']), parseInt(myFilter['max'])],
267
						slide: function(event, ui){
268
							$(this).parent().parent().find('.slider-user-min').find('span').html(ui.values[0]);
269
							$(this).parent().parent().find('.slider-user-max').find('span').html(ui.values[1]);
270
							slidermove(myFilter.name,ui.values[0],ui.values[1]);
271
						}
272
					});
273
				});
274
			}
275
		}
276
	}
277
}
278

  
279
function slidermove(field,min,max){
280
	var myfilters = selectedData['filters'];
281
	var len = myfilters.length;
282
	for(var i=0;i<len;i++){
283
		if(myfilters[i]['name'] == field){
284
			myfilters[i]['min'] = min;
285
			myfilters[i]['max'] = max;
286
			break;
287
		}
288
	}
289

  
290

  
291
	//ajax call to get the new data
292
	$.ajax({
293
	   type: "GET",
294
	   url: "ajaxRouter9.php",
295
	   data: "com=query&type=table&data="+encodeURIComponent(JSON.stringify(selectedData)),
296
	   success: function(resp){
297
		 // we have the response
298
		chartDataFromServer = JSON.parse(resp);
299
		tableData = JSON.parse(resp);
300
		drawRegionsMap();
301
		drawToolbar();
302
		credits();
303
		},
304
	   error: function(e){
305
		 alert('Error:' + e);
306
	   }
307
	});
308
}
309

  
310
function controlsforfilters(){
311
	$("a.all").live("click",function(){
312
		$(this).siblings('.filterForm').find('input').attr("checked","checked");
313
		newValues($(this).siblings('.filterForm').find('input')[0]);
314
		return false;
315
	});
316

  
317
	$("a.none").live("click",function(){
318
                $(this).siblings('.filterForm').find('input').removeAttr("checked");
319
		newValues($(this).siblings('.filterForm').find('input')[0]);		
320
		return false;
321
        });
322

  
323
	$(".formContainer input").live("click",function(){
324
		newValues(this);
325
	});
326
}
327

  
328
function newValues(obj){
329
	var field = $(obj).parent().attr('id');
330
	var myfilters = selectedData['filters'];
331
	var thisfilter;
332
	for(var i=0;i<selectedData['incfilters'].length;i++){
333
		if(selectedData['incfilters'][i]['name'] == field){
334
			thisfilter = selectedData['incfilters'][i];
335
			break;
336
		}
337
	}
338

  
339
	//change the url params
340
	//if is it checked
341
	if($(obj).is(":checked")){
342
		$("a.none").show();
343
		var flag = false;
344
		var i;
345
		for(i=0;i<myfilters.length;i++){
346
			if(myfilters[i]['name'] == field){
347
				flag=true;
348
				break;
349
			}
350
		}
351
		//if there is already such a filter delete all values and insert all the checked
352
		if(flag){
353
			myfilters[i].values = new Array();
354
			$(obj).parent().find("input:checked").each(function(){
355
				myfilters[i].values.push($(this).val());
356
			});
357
			//myfilters[i].values.push($(obj).val());
358
		}
359
		//if there is no such filter
360
		else{
361
			//create one
362
			var newfilter = new Object();
363
			newfilter.name = field;
364
			newfilter.values = new Array();
365
			newfilter.values[0] = $(obj).val();
366
			myfilters.push(newfilter);
367
		}
368
	}
369
	//if it was unchecked
370
	else{
371
		if($(obj).parent().find("input:checked").length == 0)
372
			$("a.none").hide();
373

  
374
		//there should be already such a filter
375
		var flag = false;
376
                var i;
377
                for(i=0;i<myfilters.length;i++){
378
                        if(myfilters[i]['name'] == field){
379
                                flag=true;
380
                                break;
381
                        }
382
                }
383
		//remove the value
384
		var j;
385
		for(j=0;j<myfilters[i].values.length;j++){
386
			if(myfilters[i].values[j] == $(obj).val()){
387
				myfilters[i].values.splice(j,1);
388
				break;
389
			}
390
		}
391
		//if no more values, add the values in the incfilter list and if it is all remove the filter
392
		if(myfilters[i].values.length == 0){
393
			if(thisfilter.values[0]=="all")
394
				myfilters.splice(i,1);
395
			else
396
				myfilters[i].values = thisfilter.values;
397
		}
398
	}
399
	//ajax call to get the new data
400
	$.ajax({
401
	   type: "GET",
402
	   url: "ajaxRouter9.php",
403
	   data: "com=query&type=table&data="+encodeURIComponent(JSON.stringify(selectedData)),  
404
	   success: function(resp){
405
		 // we have the response
406
		chartDataFromServer = JSON.parse(resp);
407
		tableData = JSON.parse(resp);
408
		drawRegionsMap();
409
		drawToolbar();
410
		credits();
411
		},
412
	   error: function(e){
413
		 alert('Error: ' + e);
414
	   }
415
	});
416

  
417
}
418

  
419

  
420

  
421
	</script>
422
  </head>
423
  <body>
424
	<h1 id='title'></h1>
425
	<h2 id='subtitle'></h2>
426
	<div id="chart_div" style="margin:auto;"></div>
427
	<div id='toolbar' style="margin:auto;padding-top:40px"></div>
428
	<div id="credits" style=""></div>
429
	<div id="filters"></div>
430
  </body>
431
</html>

Also available in: Unified diff