Project

General

Profile

1
<?php
2
/*
3
Has a database object, a codifier object and a cache object ....
4
gets requests for data (from view), codifys them, checks if there are in the cache, if not gets them from db, if yes, gets them from cache
5
places restrictions on them and sends them to model
6
also sets up the view
7

    
8
*/
9
require_once("paths.php");
10
//setting up the logger
11
require_once('./js/log4php/Logger.php');
12
Logger::configure('./js/log4php/log4php.xml');
13
$logger = Logger::getLogger("controller");
14
require_once('MYDB.php');
15
//require_once('error_handler.php');
16
//require_once('help_functions.php');
17

    
18
class Controller {
19

    
20
	private $database;
21
	private $log;
22
	private $data = null;
23
	private $chart;
24
	private $chart2;
25
	private $colors = array();
26
	private $size = 30;
27
	//private $cache = null; //predis
28
	private $myqueries = null;
29

    
30
	function __construct($myflag = true){
31

    
32
		// this creates a logger named "Controller"
33
		$this->log = Logger::getLogger(__CLASS__);
34
		$this->database = new MYDB();
35
		
36
		if($myflag) {
37
			$this->database->loadSchema($GLOBALS['schema_file']);
38
		} else {
39
			$this->database->doConnect($GLOBALS['schema_file']);
40
		}
41

    
42
		$this->myqueries = array();
43
		$this->myqueries['mperf1'] = array();
44
		$this->myqueries['mperf1']['q'] = "select funding_lvl1, max(daysfromend) from result_projects, project where result_projects.project=project.id and funding_lvl0='FP7' group by funding_lvl1 order by funding_lvl1";	
45
		$this->myqueries['aperf1'] = array();
46
		$this->myqueries['aperf1']['q'] = "select funding_lvl1, avg(daysfromend) from result_projects, project where result_projects.project=project.id and funding_lvl0='FP7' and daysfromend>=0 group by funding_lvl1 order by funding_lvl1";	
47

    
48
		$this->myqueries['mperf2'] = array();
49
		$this->myqueries['mperf2']['q'] = "select funding_lvl2, max(daysfromend) from result_projects, project where result_projects.project=project.id and funding_lvl0='FP7' group by funding_lvl2 order by funding_lvl2";	
50
		$this->myqueries['aperf2'] = array();
51
		$this->myqueries['aperf2']['q'] = "select funding_lvl2, avg(daysfromend) from result_projects, project where result_projects.project=project.id and funding_lvl0='FP7'  and daysfromend>=0 group by funding_lvl2 order by funding_lvl2";	
52

    
53
		$this->myqueries['maperf1'] = array();
54
		$this->myqueries['maperf1']['q'] = "select funding_lvl1, max(daysfromend), avg(daysfromend) from result_projects, project where result_projects.project=project.id and funding_lvl0='FP7'  and daysfromend>=0 group by funding_lvl1 order by funding_lvl1";	
55

    
56
		$this->myqueries['maperf2'] = array();
57
		$this->myqueries['maperf2']['q'] = "select funding_lvl2, max(daysfromend), avg(daysfromend) from result_projects, project where result_projects.project=project.id and funding_lvl0='FP7'  and daysfromend>=0 group by funding_lvl2 order by funding_lvl2";	
58

    
59
                $this->myqueries['pubsperf1'] = array();
60
                $this->myqueries['pubsperf1']['q'] = "select extract(year from date(r.date)), count(distinct p.id) as field0, funding_lvl1 from result r join result_projects rp on r.id=rp.id join project p on rp.project=p.id where extract(year from date(r.date)) >= 2007 and date <> '' and funding_lvl0='FP7' and date(r.date) < now() group by funding_lvl1,  extract(year from date(r.date)) order by  extract(year from date(r.date)), funding_lvl1";
61

    
62
		$this->myqueries['pubsperf2'] = array();
63
		$this->myqueries['pubsperf2']['q'] = "select extract(year from date(r.date)), count(distinct r.id) as field0, funding_lvl2 from result r join result_projects rp on r.id=rp.id join project p on rp.project=p.id where extract(year from date(r.date)) >= 2007 and date <> '' and funding_lvl0='FP7' and funding_lvl2 <> '' and date(r.date) < now() group by funding_lvl2,  extract(year from date(r.date)) order by  extract(year from date(r.date)), funding_lvl2";
64

    
65
		$this->myqueries['pubsperf1_double'] = array();
66
		$this->myqueries['pubsperf1_double']['q'] = "select funding_lvl1, count(sq.id), sum((case when access_mode='Open Access' then 1 else 0 end)) as open from (select distinct r.id, access_mode, funding_lvl1 from result r join result_projects rp on r.id=rp.id join project p on rp.project=p.id where  funding_lvl0='FP7' and type='publication') as sq group by sq.funding_lvl1 order by funding_lvl1";
67

    
68
		$this->myqueries['pubsperf2_double'] = array();
69
		$this->myqueries['pubsperf2_double']['q'] = "select funding_lvl2, count(sq.id), sum((case when access_mode='Open Access' then 1 else 0 end)) as open from (select distinct r.id, access_mode, funding_lvl2 from result r join result_projects rp on r.id=rp.id join project p on rp.project=p.id where  funding_lvl0='FP7' and funding_lvl2 <> ''  and type='publication') as sq group by sq.funding_lvl2 order by funding_lvl2";
70

    
71
		$this->myqueries['pubsperf1_total'] = array();
72
		$this->myqueries['pubsperf1_total']['q'] = "select funding_lvl1, count(sq.id) from (select distinct r.id, access_mode, funding_lvl1 from result r join result_projects rp on r.id=rp.id join project p on rp.project=p.id where  funding_lvl0='FP7' and type='publication') as sq group by sq.funding_lvl1 order by funding_lvl1";
73

    
74
		$this->myqueries['pubsperf2_total'] = array();
75
		$this->myqueries['pubsperf2_total']['q'] = "select funding_lvl2, count(sq.id) from (select distinct r.id, access_mode, funding_lvl2 from result r join result_projects rp on r.id=rp.id join project p on rp.project=p.id where  funding_lvl0='FP7' and funding_lvl2 <> '' and type='publication') as sq group by sq.funding_lvl2 order by funding_lvl2";
76

    
77
		$this->myquerie['allproj'] = array();
78
		$this->myqueries['allproj']['q'] = "select acronym, startdate, enddate, funding_lvl1, funding_lvl2, numpubs, delayedpubs, case when daysforlastpub>0 then daysforlastpub else 0 end as days from project where funding_lvl0='FP7' and numpubs>0 and enddate!='' and cast(enddate as date) < CURRENT_DATE  order by days desc, funding_lvl1, funding_lvl2";
79

    
80
		$this->myqueries['erctime'] = array();
81
		$this->myqueries['erctime']['q'] = "select extract(year from date(r.date)), count(r.id)  from result r natural join result_projects rp join project p on rp.project=p.id where type='publication' and extract(year from date(r.date)) >= 2007 and date <> ''  and funding_lvl2='ERC' and date(r.date) < now() group by extract(year from date(r.date)) order by extract(year from date(r.date))";
82

    
83
		$this->myqueries['wttime'] = array();
84
		$this->myqueries['wttime']['q'] = "select extract(year from date(r.date)), count(r.id)  from result r natural join result_projects rp join project p on rp.project=p.id where type='publication' and extract(year from date(r.date)) >= 2007 and date <> ''  and funding_lvl0='WT' and date(r.date) < now() group by extract(year from date(r.date)) order by extract(year from date(r.date))";
85

    
86
		$this->myqueries['projpubs'] = array();
87
		$this->myqueries['projpubs']['q'] = "SELECT project.funding_lvl1 as xfield, count(distinct project.id) as field0 FROM project, project_results, result  WHERE project.project_results=project_results.id and project_results.result=result.id  and (project.funding_lvl0='FP7') and (project.haspubs='yes') and (result.type='publication')  GROUP BY project.funding_lvl1 ORDER BY project.funding_lvl1 LIMIT 30";
88

    
89
		$this->myqueries['projpubsf2'] = array();
90
		$this->myqueries['projpubsf2']['q'] = "SELECT project.funding_lvl2 as xfield, count(distinct project.id) as field0 FROM project, project_results, result  WHERE project.project_results=project_results.id and project_results.result=result.id  and (project.funding_lvl0='FP7') and (project.funding_lvl2 <> '' ) and (project.haspubs='yes') and (result.type='publication')  GROUP BY project.funding_lvl2 ORDER BY project.funding_lvl2 LIMIT 30";
91

    
92
		$this->myqueries['fp7pubsdtsrc']= array();
93
		$this->myqueries['fp7pubsdtsrc']['q'] = "select datasource.type, count(distinct result_projects.id) from result_projects, project, result_datasources, datasource, result where result.id=result_projects.id and result.type='publication' and result_projects.project=project.id and result_datasources.datasource=datasource.id and result_projects.id=result_datasources.id and funding_lvl0='FP7'group by datasource.type";
94

    
95
		$this->myqueries['egiTimeline']['q'] = "select r.year as xfield, count(r.id) as field0 from result r join result_concepts rc on rc.id=r.result_concepts join concept c on rc.concept=c.id join category cat on cat.id = c.category join context ctx on ctx.id = cat.context where  ctx.name='EGI' group by r.year order by r.year asc;";
96
		$this->myqueries['egiProjects']['q'] = "select c.name as xfield, count(distinct rc.id) as field0 from result_concepts rc join concept c on c.id=rc.concept join category cat on cat.id=c.category where cat.id='egi::projects' group by c.name order by c.name;";
97
		$this->myqueries['egiVO']['q'] = "select c.name as xfield, count(distinct rc.id) as field0 from result_concepts rc join concept c on c.id=rc.concept join category cat on cat.id=c.category where cat.id='egi::virtual' group by c.name order by c.name;";
98
		$this->myqueries['egiOA']['q'] = "select access_mode as xfield, count(distinct r.id) as field0 from result r join result_concepts rc on r.result_concepts=rc.id join concept c on c.id=rc.concept group by access_mode";
99

    
100
		$this->colors[0] = '#4572A7';
101
		$this->colors[1] = '#AA4643';
102
		$this->colors[2] = '#89A54E';
103

    
104
		$this->types[0] = 'column';
105
		$this->types[1] = 'spline';
106
		$this->types[2] = 'spline';
107

    
108
		/*set up*/
109
		$this->chart = array();
110
		$this->chart['chart'] = array();
111
		//$this->chart['exporting'] = array();
112
		$this->chart['title'] = array();
113
		$this->chart['xAxis'] = array();
114
		$this->chart['xAxis']['labels'] = array();
115
		$this->chart['xAxis']['title'] = array();
116
		$this->chart['xAxis']['categories'] = array();
117
		$this->chart['yAxis'] = array();
118
		$this->chart['tooltip'] = array();
119
		$this->chart['legend'] = array();
120
		$this->chart['series'] = array();
121
		/*more*/
122
		//$this->chart['exporting']['enabled'] = true;
123
		$this->chart['chart']['renderTo'] = 'chart';
124
		$this->chart['chart']['reflow'] = false;
125
		$this->chart['chart']['showAxes'] = true;
126
		$this->chart['chart']['zoomType'] = 'xy';
127
		//$this->chart['chart']['margin'] = 'auto';
128
		//$this->chart['chart']['marginRight'] = 70;
129
		//$this->chart['chart']['marginBottom'] = 70;
130
		//$this->chart['chart']['height'] = 450;
131
		//$this->chart['chart']['spacingBottom'] = 100;
132
		$this->chart['credits']['enabled'] = false;
133
		//$this->chart['credits']['text'] = "from OpenAIRE via HighCharts".date("d / m / Y");
134
		//$this->chart['credits']['href'] = "#";
135
		//$this->chart['credits']['position'] = array();
136
		//$this->chart['credits']['position']['y'] = -2;
137

    
138

    
139
		/*$this->chart['xAxis']['labels']['overflow'] = null;//'justify';
140
		$this->chart['xAxis']['labels']['style'] = array();
141
		$this->chart['xAxis']['labels']['style']['font-size'] = '10px';
142

    
143
		$this->chart['xAxis']['showEmpty'] = true;
144
		$this->chart['xAxis']['labels']['enabled'] = true;
145
		$this->chart['xAxis']['labels']['style'] = array();
146
		$this->chart['xAxis']['labels']['style']['font-size'] = '8px';
147
		//$this->chart['xAxis']['labels']['style']['margin-left'] = '10px';
148
		//$this->chart['xAxis']['labels']['style']['margin-right'] = '10px';*/
149
		$this->chart['xAxis']['startOnTick'] = true;
150
		$this->chart['xAxis']['endOnTick'] = true;
151
		$this->chart['xAxis']['showFirstLabel'] = true;
152
		$this->chart['xAxis']['showLastLabel'] = true;
153

    
154
		$this->chart['tooltip']['percentageDecimals'] = 1;
155
		$this->chart['tooltip']['valueDecimals'] = 1;
156
		$this->chart['legend']['layout'] = 'vertical';
157
		$this->chart['legend']['align'] = 'right';
158
		$this->chart['legend']['verticalAlign'] = 'top';
159
		$this->chart['legend']['floating'] = true;
160
		$this->chart['legend']['borderWidth'] = 0;
161
		$this->chart['legend']['x'] = -10;
162
		$this->chart['legend']['y'] = 50;
163
		$this->chart['legend']['padding'] = 3;
164
		$this->chart['legend']['itemMarginBottom'] = 5;
165

    
166
		//for scatter plots
167
		$this->chart['plotOptions'] = array();
168
		$this->chart['plotOptions']['series'] = array();
169
	        $this->chart['plotOptions']['series']['showCheckbox'] = true;
170
	        $this->chart['plotOptions']['series']['selected'] = true;
171
		$this->chart['plotOptions']['scatter'] = array();
172
		$this->chart['plotOptions']['scatter']['marker'] = array();
173
		$this->chart['plotOptions']['scatter']['marker']['radius'] = 5;
174
		$this->chart['plotOptions']['scatter']['marker']['states'] = array();
175
		$this->chart['plotOptions']['scatter']['marker']['states']['hover'] = array();
176
		$this->chart['plotOptions']['scatter']['marker']['states']['hover']['enabled'] = true;
177
		$this->chart['plotOptions']['scatter']['marker']['states']['hover']['lineColor'] = 'rgb(100,100,100)';
178
		$this->chart['plotOptions']['scatter']['states'] = array();
179
		$this->chart['plotOptions']['scatter']['states']['hover'] = array();
180
		$this->chart['plotOptions']['scatter']['states']['hover']['marker'] = array();
181
		$this->chart['plotOptions']['scatter']['states']['hover']['marker']['enabled'] = false;
182

    
183
		$this->chart['plotOptions']['area'] = array();
184
                $this->chart['plotOptions']['area']['stacking'] = null;
185

    
186
                $this->chart['plotOptions']['areaspline'] = array();
187
                $this->chart['plotOptions']['areaspline']['stacking'] = null;
188

    
189
		//for pie charts
190
		$this->chart['plotOptions']['pie'] = array();
191
		$this->chart['plotOptions']['pie']['allowPointSelect'] = true;
192
		//$this->chart['plotOptions']['pie']['size'] = '50%';
193
		$this->chart['plotOptions']['pie']['cursor'] = 'pointer';
194
		$this->chart['plotOptions']['pie']['showInLegend'] = true;
195
		$this->chart['plotOptions']['pie']['dataLabels'] = array();
196
		$this->chart['plotOptions']['pie']['dataLabels']['enabled'] = true;
197
		$this->chart['plotOptions']['pie']['dataLabels']['color'] = '#000000';
198
		$this->chart['plotOptions']['pie']['dataLabels']['connectorColor'] = '#000000';
199
		$this->chart['plotOptions']['pie']['dataLabels']['crop'] = false;
200
		$this->chart['plotOptions']['pie']['dataLabels']['distance'] = 10;
201
		//$this->chart['plotOptions']['pie']['dataLabels']['formatter'] = '';
202
		//for column
203
		$this->chart['plotOptions']['column'] = array();
204
		$this->chart['plotOptions']['column']['allowPointSelect'] = true;
205
		$this->chart['plotOptions']['column']['cursor'] = 'pointer';
206
		$this->chart['plotOptions']['column']['showInLegend'] = true;
207
		$this->chart['plotOptions']['column']['grouping'] = true;
208

    
209
		$this->chart['plotOptions']['area'] = array();
210
	}
211

    
212
	function makeQuery($viztype) {
213
		if(!isset($_GET['data'])){
214
			$this->log->info("data param not set: ". print_r($_GET,true));
215
			return 'empty';
216
		}
217
		else {
218
			$data = $_GET['data'];
219
			//$this->log->info("data param: ". $data. "end");
220
			$this->data = json_decode($data,true);//print_r($this->data);
221
			$this->log->debug("data param decoded: ". print_r($this->data,true));
222
			$cachedData = $this->data;
223
			//unset($cachedData['yaxisheaders']);
224
			//unset($cachedData['fieldsheaders']);
225
			unset($cachedData['title']);
226
			unset($cachedData['subtitle']);
227
			//unset($cachedData['xaxistitle']);
228
			unset($cachedData['theme']);
229
			unset($cachedData['xStyle']);
230
			$this->size = $this->data['size'];
231

    
232
		
233
			return $this->computeChartObject($viztype);
234
		}
235
	}
236

    
237
	function computeChartObject($viztype){
238
		//$this->log->info("DATA: ".print_r($this->data,true));
239
		if(!isset($this->data['query'])){
240
			$this->log->info("query not set");
241
			$this->queryResult = $this->database->getData($this->data);
242
		}
243
		else{
244
			$this->log->info("query set");
245
			$this->queryResult = array("type"=>"chart","data"=>$this->database->performQuery($this->myqueries[$this->data['query']]['q']));
246
		}
247

    
248
		$this->log->info("data from DB: ".print_r($this->queryResult,true));
249
		if($viztype=="chart"){
250
			if($this->queryResult['type'] == 'scatter'){
251
				$this->createScatterData();
252
			}
253
			else{
254
				$this->createChartData();
255
			}
256

    
257
			if(isset($this->data['in']) && count($this->data['in'])){
258
				$this->chart2 = $this->chart;
259
				for($w=0;$w<count($this->chart['series']);$w++){
260
					//$whichfield = $this->data['in'][$w]['f'];
261
					//$this->chart2 = $this->chart;
262
					$data = $this->chart2['series'][$w]['data'];
263
					for($i=1;$i<count($this->chart2['xAxis']['categories']);$i++){
264
						$data[$i] += $data[$i-1];
265
					}
266
					$this->chart2['series'][$w]['data'] = $data;
267
				}
268
				//return json_encode(array($this->chart,$this->chart2),JSON_NUMERIC_CHECK);
269
				return json_encode(array($this->chart,$this->chart2));
270
			}
271

    
272
			//return json_encode($this->chart,JSON_NUMERIC_CHECK);
273
			return json_encode($this->chart);
274
		}
275
		if($viztype=='table'){
276
			//return json_encode($this->queryResult,JSON_NUMERIC_CHECK);
277
			return json_encode($this->queryResult);
278
		}
279
	}
280

    
281
	function COM_getMeasMetadata(){
282
		if(!isset($_GET['table'])) {
283
			echo 'empty';
284
		}
285
		else{
286
			echo json_encode($this->database->getMeasMetadata($_GET['table']));
287
		}
288
	}
289

    
290
	function COM_defaultChart() {
291
		//get the default values for this table
292
		$temp = $this->database->getDefaultData($_GET['table']);
293
		if($temp == 'empty')
294
			echo json_encode("empty");
295
		else{
296
			$this->size = $temp['size'];
297
			//$this->queryResult = $temp['data'];
298
			$this->data = $temp['selectedData'];
299
			//echo json_encode($this->data,JSON_NUMERIC_CHECK);
300
			echo json_encode($this->data);
301
		}
302
		//$this->data['group'] = '';
303
		//$this->data['color'] = '';
304
		//print_r($this->queryResult);return;
305
		/*if($this->data['type'] == 'chart')
306
			$this->createChartData();
307
		else
308
			$this->createScatterData();
309
		$toreturn = array();
310
		$toreturn['chart'] = $this->chart;
311
		$toreturn['selectedData'] = $this->data;
312
		echo json_encode($toreturn,JSON_NUMERIC_CHECK);*/
313
	}
314

    
315
	function defaultChart() {
316
		//get the default values for this table
317
		$temp = $this->database->getDefaultData($_GET['table']);
318
		$this->queryResult = $temp['data'];
319
		$this->data = $temp['selectedData'];
320
		$this->data['group'] = '';
321
		$this->data['color'] = 'no';
322
		//print_r($this->queryResult);return;
323
		if($temp['type'] == 'chart')
324
			$this->createChartData($temp['type']);
325
		else
326
			$this->createScatterData('');
327
		//$this->chart['chart']['type'] = $temp['type'];
328
		//print_r($this->chart);return;
329
		//print_r($this->data);
330
		$toreturn = array();
331
		$toreturn['chart'] = $this->chart;
332
		$toreturn['selectedData'] = $this->data;
333
		//return json_encode($toreturn,JSON_NUMERIC_CHECK);
334
		return json_encode($toreturn);
335
	}
336

    
337
	function defaultChartSelections() {
338
		//get the default values for this table
339
		$temp = $this->database->getDefaultData($_GET['table']);
340
		$this->queryResult = $temp['data'];
341
		$this->data = $temp['selectedData'];
342

    
343
		//echo json_encode($this->data,JSON_NUMERIC_CHECK);
344
		echo json_encode($this->data);
345
	}
346

    
347
	function COM_getFilterData(){
348
		if(!isset($_GET['table']) || !isset($_GET['field'])) {
349
			echo 'empty';
350
		}
351
		else {
352
			echo $this->computeFilterObject($_GET['table'],$_GET['field'],true);
353
		}
354
	}
355

    
356
	function getFilterData($table, $field){
357
		return $this->computeFilterObject($table,$field,false);
358
	}
359

    
360
	function computeFilterObject($table, $field, $encode){
361
		$flds = explode("-",$field);
362
		if(count($flds)>1){
363
			$ctable = $flds[count($flds)-2];
364
			$field = $flds[count($flds)-1];
365
		}
366
		else {
367
			$ctable = $table;
368
			$field = $field;
369
		}
370
		//call mydb function
371
		if($encode)
372
			//return json_encode($this->database->getFilterData($ctable,$field),JSON_NUMERIC_CHECK);
373
			return json_encode($this->database->getFilterData($ctable,$field));
374
		else
375
			return $this->database->getFilterData($ctable,$field);
376
	}
377

    
378
	function COM_get_schema(){
379
		$facts = $this->database->getFacts();
380
		$dimensions = $this->database->getDimensions();
381
		$response = array();
382
		$menu = array();
383
		if($facts === null) {
384
			$this->log->error("there are no fact tables");
385
			echo "empty";
386
			return;
387
		}//print_r($facts);
388
		foreach($facts as $facttable){
389
			$newfact = array();
390
			$newfact['name'] = $facttable['name'];
391
			if(!isset($facttable['meas'][0]))
392
				$newfact['meas'][] = $facttable['meas'];
393
			else
394
				$newfact['meas'] = $facttable['meas'];
395
			$newfact['dim'] = array();
396
			//gia kathe dim theloume: name, type, data, kai attrib opou to attrib mporei na einai ki ayto dim
397
			//otan pigainoume se bathos stin ierarxia twn diastasewn kratame touw progonous kai an ftasoume se diastasi pou yparxei stous progonous tin agnooume
398
			foreach($facttable['dim'] as $curdim) {
399
				$newdim = array();
400
				$newdim['name'] = $curdim['name'];
401
				$newdim['type'] = $curdim['type'];
402
				//$newdim['data'] = $curdim['data'];//may not need it
403
				if(isset($curdim['view']))
404
					$newdim['view'] = $curdim['view'];
405
				if(isset($curdim['dimtable']))
406
					$newdim['dimtable'] = 'no';
407
				else{
408
					$newdim['dimtable'] = 'yes';
409
					$newdim['attrib'] = array();
410

    
411
					//need to find table $curdim['refer']['table'] from all the dimentions
412
					$tabledim = search($dimensions, 'name', $curdim['name']);
413
					//print_r($tabledim);
414
					for($i=0;$i<count($tabledim);$i++){
415
						if(isset($tabledim[$i]['type']) && $tabledim[$i]['type']=='dimension')
416
							break;
417
					}
418
					$newdim['attrib'] = $this->makeAttrList($tabledim[$i]['attrib'],$dimensions,array($curdim['name']),$facttable['name']);
419
				}
420
				//I am interested in all the attributes of this dimension
421
				array_push($newfact['dim'],$newdim);
422
			}
423
			array_push($menu,$newfact);
424
		}
425
		$response['name'] = $GLOBALS['db_name'];
426
		$response['schema'] = $menu;
427
		echo json_encode($response);
428
	}
429

    
430
	function makeAttrList($attrList, $dimensions, $ancestors,$facttable){
431
		$newList = array();
432
		if(is_array($attrList)) {
433
			foreach($attrList as $attr) {
434
				if($attr['name'] != 'id' && $attr['name']!=$facttable) {
435
					$newAttr = array();
436
					$newAttr['name'] = $attr['name'];
437
					if(isset($newAttr['view']))
438
						$newAttr['view'] = $attr['view'];
439
					$newAttr['type'] = $attr['type'];
440
					if(isset($attr['analysed']) && !in_array($attr['name'],$ancestors)){
441

    
442
						$finddim = search($dimensions, 'name', $attr['name']);
443
						$nextdim = search($finddim,'type','dimension');//print_r($nextdim);
444
						$newnewList = $this->makeAttrList($nextdim[0]['attrib'],$dimensions, array_merge($ancestors,array($attr['name'])),$facttable);
445
						$ancestors[] = $attr['name'];
446
						$newAttr['analysed'] = $attr['name'];
447
						$newAttr['attrib']= $newnewList;
448
					}
449
					else{
450
						$newAttr['attrib']= array();
451
					}
452
					array_push($newList,$newAttr);
453
				}
454
			}
455
		}
456
		return $newList;
457
	}
458

    
459

    
460
/*
461
type = color | group | ''
462
*/
463
	function createScatterData(){
464
		unset($this->chart['xAxis']['categories']);
465
		$this->chart['chart']['type'] = 'bubble';
466
		$xaxisindex = 0;
467
		$yaxisindex = 1;
468
		$left = 0;
469
		$right = 0;
470
		$fields = count($this->data['fields']);
471
		$dimindex = 1+$fields;
472
		if($this->data['group'] == '')
473
			$this->chart['xAxis']['title']['text'] = $this->data['xaxis']['name'];
474
		else
475
			$this->chart['xAxis']['title']['text'] = $this->data['xaxis']['agg'].'('.$this->data['xaxis']['name'].')';
476
		//arxikopoiisi
477
		//posoi yaxis??
478
		$this->chart['yAxis'] = array();
479
		$yaxis = $this->data['fields'][$fields-1]['yaxis'];
480
		$tempy = -1;
481
		for($f=0;$f<count($this->data['fields']);$f++){
482
			if($this->data['fields'][$f]['yaxis']!=$tempy+1){//new y
483
				$tempy++;
484
				$this->chart['yAxis'][$tempy] = array();
485
				$this->chart['yAxis'][$tempy]['labels'] = array();
486
				$this->chart['yAxis'][$tempy]['labels']['enabled'] = true;
487
				$this->chart['yAxis'][$tempy]['labels']['overflow'] = 'justify';
488
				//$this->chart['yAxis'][$tempy]['offset'] = 70;
489
				$this->chart['yAxis'][$tempy]['title'] = array();
490
				if($this->data['yaxisheaders'][$tempy] !=''){
491
					$this->chart['yAxis'][$tempy]['title']['text'] = $this->data['yaxisheaders'][$tempy];
492
				}
493
				else{
494
					if($this->data['fieldsheaders'][$f] !=''){
495
						$this->chart['yAxis'][$tempy]['title']['text'] = $this->data['fieldsheaders'][$f];
496
					}
497
					else{
498
						if($this->data['group'] == '')
499
							$this->chart['yAxis'][$tempy]['title']['text'] = $this->data['fields'][$f]['fld'];
500
						else
501
							$this->chart['yAxis'][$tempy]['title']['text'] = $this->data['fields'][$f]['agg'].'('.$this->data['fields'][$f]['fld'].')';
502
					}
503
				}
504
				if($right>=$left){
505
					$left++;
506
				}
507
				else{
508
					$right++;
509
					$this->chart['yAxis'][$tempy]['opposite'] = true;
510
				}
511
			}
512
			else if($this->data['yaxisheaders'][$tempy] == ""){//more in the name
513
				if($this->data['fieldsheaders'][$f] !=''){
514
					$this->chart['yAxis'][$tempy]['title']['text'] .= " / ".$this->data['fieldsheaders'][$f];
515
				}
516
				else{
517
					if($this->data['group'] == '')
518
						$this->chart['yAxis'][$tempy]['title']['text'] .= " / ".$this->data['fields'][$f]['fld'];
519
					else
520
						$this->chart['yAxis'][$tempy]['title']['text'] .= " / ".$this->data['fields'][$f]['agg'].'('.$this->data['fields'][$f]['fld'].')';
521
				}
522
			}
523
		}
524
		$this->chart['series'] = array();
525
		$this->chart['legend']['enabled'] = false;
526
		//an einai group exw ena series
527
		if(($this->data['group']  && $this->data['group'] != '') || $this->data['color'] == ''){//ena series kai diaforetiko onoma gia kathe data
528
			for($f=0;$f<$fields;$f++){
529
				$this->chart['series'][$f] = array();
530
				$this->chart['series'][$f]['data'] = array();
531
				if($this->data['fields'][$f]['yaxis']!=1)
532
					$this->chart['series'][$f]['yAxis'] = $this->data['fields'][$f]['yaxis']-1;
533
			}
534
			//for($line=0;$line<10;$line++){
535
			for($line=0;$line<count($this->queryResult['data']);$line++){
536
				for($f=0;$f<$fields;$f++){
537
					//insert a new data object to the only series
538
					$data = array();
539
					$data['x'] = $this->queryResult['data'][$line][$xaxisindex];
540
					$data['y'] = $this->queryResult['data'][$line][$yaxisindex+$f];
541
					if($this->data['group'] != ''){
542
						$data['name'] = $this->queryResult['data'][$line][$dimindex];
543
						if($this->data['fieldsheaders'][$f]=="")
544
							$this->chart['series'][$f]['name'] = $this->data['fields'][$f]['agg'].'('.$this->data['fields'][$f]['fld'].')';
545
						else
546
							$this->chart['series'][$f]['name'] = $this->data['fieldsheaders'][$f];
547
					}
548
					else{
549
						if($this->data['fieldsheaders'][$f]=="")
550
							$this->chart['series'][$f]['name'] = $this->data['fields'][$f]['fld'];
551
						else
552
							$this->chart['series'][$f]['name'] = $this->data['fieldsheaders'][$f];
553
					}
554
					$this->chart['series'][$f]['data'][] = $data;
555
				}
556
			}//print_r($this->chart['series']);
557
		}
558
		//an einai color exw ena series gia kathe timi tou dimindex
559
		else{
560
			$this->chart['legend']['enabled'] = true;
561
			$curseries = '';
562
			$seriescount = 0;
563
			//for($line=0;$line<10;$line++){
564
			for($line=0;$line<count($this->queryResult['data']);$line++){
565
				if($this->queryResult['data'][$line][$dimindex] != $curseries){
566
					$curseries = $this->queryResult['data'][$line][$dimindex];
567
					for($f=0;$f<$fields;$f++){
568
						$this->chart['series'][$seriescount+$f] = array();
569
						if($this->data['fieldsheaders'][$f]!='')
570
							$this->chart['series'][$seriescount+$f]['name'] = $this->data['fieldsheaders'][$f]." for ".$this->queryResult['data'][$line][$dimindex];
571
						else
572
							$this->chart['series'][$seriescount+$f]['name'] = $this->data['fields'][$f]['fld']." for ".$this->queryResult['data'][$line][$dimindex];
573
						$this->chart['series'][$seriescount+$f]['data'] = array();
574
					}
575
					$seriescount += $fields;
576
				}
577
				for($f=0;$f<$fields;$f++){
578
					$this->chart['series'][$seriescount-$fields+$f]['data'][] = array($this->queryResult['data'][$line][$xaxisindex],$this->queryResult['data'][$line][$yaxisindex+$f]);
579
				}
580
			}
581
		}
582

    
583
	}
584

    
585
	function createChartData(){
586
		$this->chart['xAxis']['categories'] = array();
587
		unset($this->chart['chart']['type']);
588
		$this->chart['series'] = array();
589
		$this->chart['yAxis'] = array();
590
		$xaxisindex = 0;
591
		$yaxisindex = 1;
592
		$left = 0;
593
		$right = 0;
594
		//print_r($this->queryResult['data']);
595
		$fields = count($this->data['fields']);
596
		$dimindex = 1+$fields;
597

    
598
		if($this->data['xaxistitle']!='')
599
			$this->chart['xAxis']['title']['text'] = $this->data['xaxistitle'];
600
		else{
601
			$xaxis = explode("-",$this->data['xaxis']['name']);
602
			$this->chart['xAxis']['title']['text'] = $xaxis[count($xaxis)-1];
603
		}
604
		$this->chart['legend']['enabled'] = true;
605
		//posoi yaxis??
606
		$yaxis = $this->data['fields'][$fields-1]['yaxis'];
607
		$tempy = -1;
608
		for($f=0;$f<count($this->data['fields']);$f++){
609
			if($this->data['fields'][$f]['yaxis']!=$tempy+1){//new y
610
				$tempy++;
611
				$this->chart['yAxis'][$tempy] = array();
612
				$this->chart['yAxis'][$tempy]['labels'] = array();
613
				$this->chart['yAxis'][$tempy]['labels']['enabled'] = true;
614
				$this->chart['yAxis'][$tempy]['labels']['overflow'] = 'justify';
615
				$this->chart['yAxis'][$tempy]['min'] = 0;
616
				//$this->chart['yAxis'][$tempy]['offset'] = 70;
617
				$this->chart['yAxis'][$tempy]['title'] = array();
618
				if($this->data['yaxisheaders'][$tempy]!=''){
619
					$this->chart['yAxis'][$tempy]['title']['text'] = $this->data['yaxisheaders'][$tempy];
620
					if($this->data['fieldsheaders'][$f] == '' && (($f<count($this->data['fields'])-1 && $this->data['fields'][$f]['yaxis']!=$this->data['fields'][$f+1]['yaxis']) || $f==count($this->data['fields'])-1)){//the fields name is not set and it is the only field in the axis
621
						$this->data['fieldsheaders'][$f] = $this->data['yaxisheaders'][$tempy];
622
					}
623
				}
624
				else{
625
					if($this->data['fieldsheaders'][$f] !=''){
626
						$this->chart['yAxis'][$tempy]['title']['text']  = $this->data['fieldsheaders'][$f];
627
					}
628
					else {
629
						$this->chart['yAxis'][$tempy]['title']['text'] = $this->data['fields'][$f]['agg'].'('.$this->data['fields'][$f]['fld'].')';
630
					}
631
				}
632
				if($right>=$left){
633
					$left++;
634
				}
635
				else{
636
					$right++;
637
					$this->chart['yAxis'][$tempy]['opposite'] = true;
638
				}
639
			}
640
			else if($this->data['yaxisheaders'][$tempy]==''){//more in the name
641
				if($this->data['fieldsheaders'][$f] !='')
642
					$this->chart['yAxis'][$tempy]['title']['text']  .= " / ".$this->data['fieldsheaders'][$f];
643
				else
644
					$this->chart['yAxis'][$tempy]['title']['text'] .= " / ".$this->data['fields'][$f]['agg'].'('.$this->data['fields'][$f]['fld'].')';
645
			}
646
		}
647

    
648
		if($this->data['group'] != ''){//periptwsi analyze
649
			$this->chartDataGroup();
650
		}
651
		else{//polloi yaxis xwris group
652
			$this->chartDataMultiY();
653
		}
654

    
655
		if(count($this->chart['xAxis']['categories']) > 30){
656
			$this->chart['xAxis']['labels']['formatter'] = 'trim';
657
			//$this->chart['xAxis']['labels']['rotation'] = 90;
658
		}//print_r($this->chart);
659
		else{
660
			$trimflag = false;
661
			for($i=0;$i<count($this->chart['xAxis']['categories']);$i++){
662
				if(is_string($this->chart['xAxis']['categories'][$i]) && strlen($this->chart['xAxis']['categories'][$i])>10){
663
					$trimflag = true;
664
					break;
665
				}
666
			}
667
			if($trimflag){
668
				$this->chart['xAxis']['labels']['formatter'] = 'cond-trim';
669
				//$this->chart['xAxis']['labels']['rotation'] = 90;
670
			}
671
		}
672
	}
673

    
674
	function chartDataGroup(){
675
		//ena series gia kathe field gia kathe timi tou groupdim
676
		//read data
677
		$res = $this->queryResult['data'];
678
		$seriesindex = array();
679
		$names = array();
680
		$name = '';
681
		$seriescount = 0;
682
		$curseries = '';
683
		$xaxisindex = 0;
684
		$yaxisindex = 1;
685
		$fields = count($this->data['fields']);
686
		$dimindex = 1+$fields;
687

    
688
		($this->size >= count($this->queryResult['data'])) ? $num=count($this->queryResult['data']) : $num=$this->size; 
689
		//$num = $this->size;
690
		$flag = true;
691
		for($line=0;$line<$num;$line++){
692
			//list with x axis categories
693
			if(!in_array($res[$line][$xaxisindex],$this->chart['xAxis']['categories'])){
694
				if(count($this->chart['xAxis']['categories'])<$num){
695
					$this->chart['xAxis']['categories'][] = $res[$line][$xaxisindex];
696
					$flag = true;
697
				}
698
				else{
699
					$flag = false;
700
				}
701
			}
702
			else{
703
				$flag = true;
704
			}
705
			if($flag){
706
				//insert new data in currentseries or make new one
707
				if($this->queryResult['data'][$line][$dimindex] != $curseries){
708
					$curseries = $this->queryResult['data'][$line][$dimindex];
709
					for($f=0;$f<$fields;$f++){
710
						if($this->data['fieldsheaders'][$f]!="")
711
							$names[$f] = $this->data['fieldsheaders'][$f] ." for ".$curseries;
712
						else
713
							$names[$f] = $curseries;
714
						if(!isset($seriesindex[$names[$f]])){
715
							$seriesindex[$names[$f]] = array();
716
							$seriesindex[$names[$f]]['name'] = $names[$f];
717
							if($this->data['fields'][$f]['type'] !='area')
718
								$seriesindex[$names[$f]]['type'] = $this->data['fields'][$f]['type'];
719
							else
720
								$this->chart->type='area';
721
							if($this->data['fields'][$f]['yaxis']>1){
722
								$seriesindex[$names[$f]]['yAxis'] = $this->data['fields'][$f]['yaxis']-1;
723
							}
724
							$seriesindex[$names[$f]]['data'] = array();
725
							if($curseries == "UNKNOWN")
726
								$seriesindex[$names[$f]]['visible'] = false;
727

    
728
							if(isset($this->data['fields'][$f]['c']) && $this->data['fields'][$f]['c'] == true)
729
								$seriesindex[$names[$f]]['c'] = true;
730
							else
731
								$seriesindex[$names[$f]]['c'] = false;
732
						}
733
					}
734
					$seriescount += $fields;
735
				}
736
				$index = array_search($this->queryResult['data'][$line][$xaxisindex],$this->chart['xAxis']['categories']);
737
				for($f=0;$f<$fields;$f++){
738
					if($this->data['fieldsheaders'][$f]!="")
739
						$name = $this->data['fieldsheaders'][$f] . " for ".$curseries;
740
					else
741
						$name = $this->data['fields'][$f]['agg'].'('.$this->data['fields'][$f]['fld'].") for ".$curseries;
742
					$lastindex = count($seriesindex[$name]['data']);
743
					for($t=$lastindex;$t<$index;$t++){
744
						$seriesindex[$name]['data'][$t] = 0;
745
					}
746
					$seriesindex[$name]['data'][$index] = $this->queryResult['data'][$line][$yaxisindex+$f];
747
				}
748
			}
749
		}
750
		foreach($seriesindex as $s){
751
			$this->chart['series'][] = $s;
752
		}
753
	}
754

    
755
	function chartDataMultiY(){
756
		$xaxisindex = 0;
757
		$yaxisindex = 1;
758
		//1 series gia kathe field
759
		for($i=0; $i<count($this->data['fields']);$i++){
760
			$this->chart['series'][] = array();
761
			if($this->data['fieldsheaders'][$i]!='')
762
				$this->chart['series'][$i]['name'] = $this->data['fieldsheaders'][$i];
763
			else
764
				$this->chart['series'][$i]['name'] = $this->data['fields'][$i]['agg'].'('.$this->data['fields'][$i]['fld'].')';
765
			if($this->data['fields'][$i]['type'] != 'area')
766
				$this->chart['series'][$i]['type'] = $this->data['fields'][$i]['type'];
767
			else
768
				$this->chart->type='area';
769
			//$this->chart['series'][$i]['yAxis'] = $this->data['fields'][$i]['yAxis'];
770

    
771
			if($this->data['fields'][$i]['yaxis']>1){
772
				$this->chart['series'][$i]['yAxis'] = $this->data['fields'][$i]['yaxis']-1;
773
			}
774
			$this->chart['series'][$i]['data'] = array();
775
		}
776
		//read data
777
		$res = $this->queryResult['data'];
778

    
779
		($this->size >= count($this->queryResult['data'])) ? $num=count($this->queryResult['data']) : $num=$this->size; 
780
		//$num = $this->size;
781
		$flag = true;
782
		for($line=0;$line<$num;$line++){
783
			//list with x axis categories
784
			if(!in_array($res[$line][$xaxisindex],$this->chart['xAxis']['categories'])){
785
				if(count($this->chart['xAxis']['categories'])<$num){
786
					$this->chart['xAxis']['categories'][] = $res[$line][$xaxisindex];
787
					$flag = true;
788
				}
789
				else{
790
					$flag = false;
791
				}
792
			}
793
			else{
794
				$flag = true;
795
			}
796
			//insert new data in each series
797
			if($flag){
798
				for($s=0;$s<count($this->data['fields']);$s++) {
799
					if($this->data['fields'][$s]['type'] == 'pie'){
800
						$this->chart['series'][$s]['data'][$line]['name'] = $res[$line][$xaxisindex];
801
						$this->chart['series'][$s]['data'][$line]['y'] = $res[$line][$s+$yaxisindex];
802
					}
803
					else {
804
						$this->chart['series'][$s]['data'][] = $res[$line][$s+$yaxisindex];
805
					}
806
				}
807
			}
808
		}
809

    
810
		if(count($this->data['fields']) == 1)
811
			$this->chart['legend']['enabled'] = false;
812
	}
813

    
814
	function COM_performQuery() {
815
	
816
		if(!isset($_GET['query']) || $_GET['query'] == ''){
817
			$this->log->error("no query string");
818
			return;
819
		}
820

    
821
		$query = urldecode($_GET['query']);
822

    
823
		$this->log->info("performing query: ".$query);
824
		$resp = json_encode($this->database->performQuery($query));
825
		//$this->log->info("response: ".$resp);
826
		echo $resp;
827
	}
828

    
829
	function sortSeries() {
830
		//exoume mia series gia kathe field
831
		//prepei na broume ayti ti series kai me basi ayti na kanoume sort kai oles tis alles kai ta categories tou xaxis
832
		$snum = 0;
833
		for($snum=0;$snum<$this->data['fields'];$snum++){
834
			if($this->data['fields'][$snum]['agg']."(".$this->data['fields'][$snum]['fld'].")" == $this->data['sort'])
835
				break;
836
		}
837
		//kanw sort ayto to series diatirontas ta kleidia opws einai kai meta kanw sort tis ypoloipes me basi ti seira kleidiwn aytinis
838
		if($this->data['order'] && $this->data['order'] == 'd'){
839
			arsort($this->chart['series'][$snum]['data']);
840
		}
841
		else{
842
			asort($this->chart['series'][$snum]['data']);
843
		}
844
		//ypoloipes
845
		//categories
846
		$tempordered = array() ;
847
		foreach (array_keys($this->chart['xAxis']['categories']) as $key) {
848
			$tempordered[$key] = $this->chart['xAxis']['categories'][$key] ;
849
		}
850
		$this->chart['xAxis']['categories'] = $tempordered;
851
		
852
		for($i=0;$i<$this->data['fields'];$i++){
853
			if($i!=$snum){
854
				unset($tempordered);
855
				$tempordered = array();
856
				$myarray = $this->chart['series'][$i]['data'];
857
				foreach (array_keys($myarray) as $key) {
858
					$tempordered[$key] = $myarray[$key] ;
859
				}
860
				$this->chart['series'][$i]['data'] = $tempordered;
861
			}
862
		}
863
	}
864

    
865

    
866
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
867
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
868
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
869
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
870
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
871
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
872

    
873
	function COM_makeQuery() {
874
		if(!isset($_GET['data'])){
875
			$this->log->info("data param not set: ". print_r($_GET,true));
876
			echo 'empty';
877
		}
878
		else {
879
			$viztype = $_GET['type'];
880
			$data = $_GET['data'];
881
			$this->data = json_decode($data,true);
882

    
883
			$cachedData = $this->data;
884
			unset($cachedData['yaxisheaders']);
885
			unset($cachedData['fieldsheaders']);
886
			unset($cachedData['title']);
887
			unset($cachedData['subtitle']);
888
			unset($cachedData['xaxistitle']);
889
			unset($cachedData['theme']);
890
			unset($cachedData['xStyle']);
891

    
892
			$this->size = $this->data['size'];
893

    
894
			echo $this->computeChartObject($viztype);
895
		}
896
	}
897

    
898
	function COM_read() {
899
		if(!isset($_GET['facttable']) || !isset($_GET['dimensions']) || !isset($_GET['measures'])) {
900
			echo "empty";
901
		}
902

    
903
		$dims = explode(';',$_GET['dimensions']);
904
		$meas = explode(';',$_GET['measures']);
905
		echo $this->readtest($dims, $meas, $_GET['facttable'],$_GET['aggregation']);
906
	
907
	}
908

    
909
	function COM_check_fact() {
910
		if(!isset($_GET['name'])) {
911
			echo "empty";
912
		}
913
		else{
914
			$res = $this->database->findTableType($_GET['name']);
915
			if($res == false) echo 'false';
916
			else echo $res;
917
		}
918
	}
919
	
920
	function COM_list_of_dim_names() {
921
		$res = $this->database->getAllDims();
922
		if($res != false)
923
			echo json_encode($res);
924
		else
925
			echo "false";
926
	}
927

    
928
	function COM_search_warehouse_by_dims() {
929
		if(!isset($_GET['dims'])) {
930
			echo 'empty';
931
		}
932
		else {
933
			$res = $this->database->searchWarehousebyDims(explode(';',$_GET['dims']));
934
			if($res == false) echo "false";
935
			else echo $res;	
936
		}
937
	}
938

    
939
	function COM_create_new_fact_table() {
940
		if(!isset($_GET['table']) || !isset($_GET['dims']) || !isset($_GET['meas'])) {
941
			echo 'empty';
942
		} 
943
		else {
944
			//set up the list of dims
945
			$dims = explode(',',$_GET['dims']);
946
			//set up the list of meas
947
			$new_meas = rtrim($_GET['meas'],';');
948
			$meas = explode(';',$new_meas);
949
			//call the db function
950
			$res = $this->database->createNewFact($_GET['table'], $dims, $meas);
951
			if($res == false)
952
				echo 'false';
953
			else
954
				echo 'true';
955
		}
956
	}
957

    
958
	function COM_list_of_fact_tables() {
959
		$res = json_encode($this->database->getFactsNames());
960
		if($res == null)
961
			echo 'null';
962
		else
963
			echo $res;
964
	}
965

    
966
	function COM_list_of_meas() {
967
		if(!isset($_GET['table'])) {
968
			echo 'empty';
969
		} 
970
		else {
971
			$res = $this->database->findMeas($this->database->findTable($_GET['table'],'fact'));
972
			if($res == false)
973
				echo 'false';
974
			else
975
				echo json_encode($res);
976
		}
977
	}
978

    
979
	function COM_list_of_dims() {
980
		$res = $this->database->getDims();
981
		if($res == false)
982
			echo 'false';
983
		else
984
			echo json_encode($res);
985
	}
986

    
987
	function COM_del_meas() {
988
		if(!isset($_GET['facttable']) || !isset($_GET['name'])) {
989
			echo "empty";
990
		}
991
		else {
992
			$res = $this->database->delMeas($_GET['facttable'], $_GET['name']);
993
			if($res == true)
994
				echo "true";
995
			else 
996
				echo "false";
997
		}
998
	}
999

    
1000
	function COM_add_meas() {
1001
		if(!isset($_GET['facttable']) || !isset($_GET['name']) || !isset($_GET['formal_name']) || !isset($_GET['type'])) {
1002
			echo "empty";
1003
		}
1004
		else {
1005
			$res = $this->database->addMeas($_GET['facttable'], $_GET['name'], $_GET['formal_name'], $_GET['type']);
1006
			if($res == true)
1007
				echo "true";
1008
			else 
1009
				echo "false";
1010
		}
1011
	}
1012

    
1013
	function COM_meas_range_data() {
1014
		if(!isset($_GET['facttable']) || !isset($_GET['measurement'])) {
1015
			echo "empty";
1016
		}
1017
		else {
1018
			$res = $this->database->measRangeData($_GET['facttable'],$_GET['measurement']);
1019
			echo json_encode($res);
1020
		}
1021
	}
1022

    
1023
	function COM_get_dims_fields_list(){
1024
		if(!isset($_GET['table'])) {
1025
			echo "empty";
1026
		}
1027
		else {
1028
			$res = $this->database->getDimsList($_GET['table']);
1029

    
1030
			if($res == false)
1031
				echo "false";
1032
			else if($res == null)
1033
				echo "null";
1034
			else
1035
				echo json_encode($res);
1036
		}
1037
	}
1038

    
1039

    
1040
	function fetchData($table, $dim1, $dim2, $meas, $constraints = null) {
1041
		return $this->database->getJsonData($table, $dim1, $dim2, $meas, $constraints);
1042
	}
1043

    
1044
	function readData($table, $dim1, $dim2, $meas, $constraints = null) {
1045
		return $this->database->readData($table, $dim1, $dim2, $meas, $constraints);
1046
	}
1047

    
1048
	function timeload($start,$end) {
1049
		$this->database->loadTime($start,$end);
1050
	}
1051

    
1052
	function readtest($dimensions,$measures,$table,$aggr) {
1053
		$data = $this->database->readtest($dimensions,$measures,$table,$aggr);
1054
		//echo json_encode($data,JSON_NUMERIC_CHECK);
1055
		echo json_encode($data);
1056
	}
1057
	
1058
	
1059
	/////////////////////////////////////////////////////////////////////////////////////
1060

    
1061
}
1062

    
1063
/*
1064

    
1065
	function createChartDataGroup($givenType) {
1066
		//exoume anagkastika ena mono yaxis
1067
		//ena series gia kathe diaforetiki timi tou tritou pediou
1068
		if($givenType == 'chart'){
1069
			$this->chart['xAxis']['categories'] = array();
1070
			
1071
		}
1072
		else{
1073
			unset($this->chart['xAxis']['categories']);
1074
		}
1075
		$this->chart['series'] = array();
1076
		
1077
		$currentSeries = "";
1078
		$seriesCnt = -1;
1079
		$numOfColumns = count($this->queryResult[0]);
1080
		if(count($this->data['series']) == 0)
1081
			$sNameIndex = -1;
1082
		else
1083
			$sNameIndex = count($this->data['fields']) +1;
1084
			//$sNameIndex = $numOfColumns-1;
1085
		$xaxisIndex = 0;
1086
		$fStartindex = 1;
1087
		$groupindex = 2;
1088
		$this->chart['xAxis']['title']['text'] = $this->data['xaxis']['name'];
1089
		//arxikopoiisi
1090
		$this->chart['yAxis'] = array();
1091
		$this->chart['series'] = array();
1092
		$this->chart['legend']['enabled'] = false;
1093
		//edw tha ektelestei mono mia fora <-------NA TO ALLAKSW
1094
		for($i=0; $i<count($this->data['fields']);$i++){
1095
			//gia kathe field, exoume enan yaxis kai ena series
1096
			$this->chart['yAxis'][] = array();
1097
			$this->chart['yAxis'][$i]['labels'] = array();
1098
			$this->chart['yAxis'][$i]['offset'] = 70;
1099
			//$this->chart['yAxis'][$i]['labels']['formatter'] = 'simple';
1100
			$this->chart['yAxis'][$i]['title'] = array();
1101
			$this->chart['yAxis'][$i]['title']['text'] = $this->data['fields'][$i]['fld'];
1102
			if($i>0){
1103
				$this->chart['yAxis'][$i]['opposite'] = true;
1104
				$this->chart['yAxis'][$i]['gridLineWidth'] = 0;
1105
			}
1106

    
1107
			//$this->chart['series'][] = array();
1108
			//$this->chart['series'][$i]['name'] = $this->data['fields'][$i]['fld'];
1109
			
1110
			//if($i>0) {
1111
			//	$this->chart['series'][$i]['yAxis'] = $i;
1112
			//}
1113
			//$this->chart['series'][$i]['data'] = array();
1114
			//$seriesData[$i] = array();
1115
		}
1116
		
1117
		$res = $this->queryResult['data'];
1118
		//gia kathe diaforetiki timi tou pediou 2, kainourgio category an exoume chart
1119
		//gia kathe diaforetiki timi tou pediou 3, kainourgio series me onoma tin timi tou pediou 3
1120
		//oso eisai sto idio series, apla prosthese ta data
1121
		//an allakseis ftiakse kainourgio
1122
		for($line=0;$line<count($this->queryResult['data']);$line++){
1123
			//list with x axis categories
1124
			if($givenType == 'chart'){
1125
				if(!in_array($res[$line][$xaxisIndex],$this->chart['xAxis']['categories'])){
1126
					$this->chart['xAxis']['categories'][] = $res[$line][$xaxisIndex];
1127
				}
1128
			}
1129
			//new series? 
1130
			if($res[$line][$groupindex] != $currentSeries){
1131
				$currentSeries = $res[$line][$groupindex];
1132
				$this->chart['series'][] = array();
1133
				$seriesCnt++;
1134
				$this->chart['series'][$seriesCnt]['name'] = $currentSeries;
1135
				$this->chart['series'][$seriesCnt]['data'] = array();
1136
			}
1137
			$this->chart['series'][$seriesCnt]['data'][] = $res[$line][$fStartindex];
1138
		}
1139

    
1140
		if(count($this->chart['xAxis']['categories']) > 15){
1141
			$this->chart['xAxis']['labels']['formatter'] = 'trim';
1142
			$this->chart['xAxis']['labels']['rotation'] = 45;
1143
		}
1144

    
1145
	}
1146
*/
1147
?>
(5-5/19)