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

    
82
 $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))";
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
// ERI - TODO egi timeline has been updated- change it everywhere 
95
                $this->myqueries['egiTimeline']['q'] = "select r.year as xfield, count(r.id) as field0 from result r,result_concepts rc, concept con, context ctx, category cat where rc.id=r.id  and  con.id=rc.concept and con.category= cat.id and lower(cat.context)= lower(ctx.name)  and cat.context ='egi' group by r.year order by r.year asc;";
96

    
97

    
98
		$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;";
99
		$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;";
100
		$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";
101

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

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

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

    
140

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

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

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

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

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

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

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

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

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

    
234
		
235
			return $this->computeChartObject($viztype);
236
		}
237
	}
238

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
461

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

    
585
	}
586

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

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

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

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

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

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

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

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

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

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

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

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

    
823
		$query = urldecode($_GET['query']);
824

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

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

    
867

    
868
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
869
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
870
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
871
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
872
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
873
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
874

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

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

    
894
			$this->size = $this->data['size'];
895

    
896
			echo $this->computeChartObject($viztype);
897
		}
898
	}
899

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1041

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

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

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

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

    
1063
}
1064

    
1065
/*
1066

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

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

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

    
1147
	}
1148
*/
1149
?>
(7-7/29)