This repository has been archived by the owner on May 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
94 lines (74 loc) · 2.54 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
// Load configuration
include_once dirname(__FILE__).'/utils/conf.php.inc';
global $conf;
// Load classes
include_once dirname(__FILE__).'/database/regions.php.inc';
include_once dirname(__FILE__).'/utils/layout.php.inc';
include_once dirname(__FILE__).'/utils/utils.php.inc';
include_once dirname(__FILE__).'/utils/kml.php.inc';
function placeholder($conf) {
$layout = new Layout(LAYOUT_FRONT);
echo $layout;
}
// Encode regions information
function encodeRegions($type) {
global $conf;
// Load regions from database
$regions = new Regions();
$current_regions = null;
switch ($type) {
case REGION_SELECTED:
$current_regions = $regions->getAllSelectRegions();
break;
case REGION_INTERESTED:
$current_regions = $regions->getAllInterestedRegions();
break;
case REGION_NOT_INTERESTED:
$current_regions = $regions->getAllNotInterestedRegions();
break;
case REGION_NOT_SELECTED:
$current_regions = $regions->getAllNonSelectedRegions();
break;
}
// Load regions polygons and encode them
foreach ($current_regions as $key => $region) {
$kml = new kml($region['name'], $conf->getKmlPath() . $region[file]);
$regions_polygons[] = $kml->getRegionPolygons();
$data[$key] = array('name' => $region['name'],
'color' => $region['color'],
'population' => $region['population'],
'region_polygons' => $regions_polygons);
// Empty it, as it have been add to data array
$regions_polygons = null;
}
return $data;
}
// Take action
try {$action = strtolower(Utils::getParam('action'));} catch (Exception $e) {};
switch ($action) {
case 'loadselectedregions':
echo json_encode(array('status' => "selected_regions", 'regions' => encodeRegions(REGION_SELECTED)));
break;
case 'loadnotselectedregions':
echo json_encode(array('status' => "selected_regions", 'regions' => encodeRegions(REGION_NOT_SELECTED)));
break;
case 'loadpopulation':
$regions = new Regions();
echo json_encode(array('status' => "population", 'population' => $regions->getPopulation()));
break;
case 'loadinterestedregions':
echo json_encode(array('status' => "selected_regions", 'regions' => encodeRegions(REGION_INTERESTED)));
break;
case 'loadnotinterestedregions':
echo json_encode(array('status' => "selected_regions", 'regions' => encodeRegions(REGION_NOT_INTERESTED)));
break;
case 'embedded':
$layout = new Layout(LAYOUT_EMBEDDED);
echo $layout;
break;
default:
echo placeholder($conf);
break;
}
?>