-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.php
93 lines (82 loc) · 2.42 KB
/
api.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
<?php
require_once 'libs/funcs.php';
switch ($_GET['action']) {
case 'get_cities':
$where = array();
if ($_GET['country']) {
$where['countries_iso'] = $_GET['country'];
}
$dbSchoolsCities = DbSchoolsCities::get_instance();
$cities = $dbSchoolsCities->gets($where, '`city` ASC');
foreach ($cities as $city) {
$cities_simple[] = $city['city'];
}
echo json_encode($cities_simple);
break;
case 'get_countries':
$where = array(
'`countries_iso` > 0'
);
if ($_GET['term']) {
$_GET['term'] = strtolower($_GET['term']);
$where[] = "LOWER(`country`) LIKE '{$_GET['term']}%'";
}
if ($_GET['all']) {
$dbCountries = DbCountries::get_instance();
$countries = $dbCountries->gets($where, 'country');
} else {
$dbSchoolsCountries = DbSchoolsCountries::get_instance();
$countries = $dbSchoolsCountries->gets($where, 'country');
}
foreach ($countries as $country) {
$countries_simple[] = array(
'label' => $country['country'],
'value' => $country['country_short']
);
}
echo json_encode($countries_simple);
break;
case 'get_actions':
if (! $_GET['old']) {
$where[] = "`is_old` = 'no'";
}
if ($_GET['term']) {
$_GET['term'] = strtolower($_GET['term']);
if (is_numeric($_GET['term'])) {
$where[] = "`actions_number` = {$_GET['term']}";
} else {
$where[] = "LOWER(`action`) LIKE '%{$_GET['term']}%'";
}
}
$dbActions = DbActions::get_instance();
$actions = $dbActions->gets($where, 'actions_number');
foreach ($actions as $action) {
$actions_simple[] = array(
'label' => $action['actions_number_nice'] . ' ' . $action['action'],
'value' => $action['actions_number']
);
}
echo json_encode($actions_simple);
break;
case 'get_schools':
if ($_GET['term']) {
$_GET['term'] = strtolower($_GET['term']);
if (is_numeric($_GET['term'])) {
$where_or[] = "`member_schools_number` = {$_GET['term']}";
}
$where_or[] = "LOWER(`school`) LIKE '%{$_GET['term']}%'";
$where = implode(' OR ', $where_or);
}
$dbSchools = DbSchools::get_instance();
$schools = $dbSchools->gets($where, 'school');
foreach ($schools as $school) {
$schools_simple[] = array(
'label' => '#' . $school['member_schools_number'] . ' ' . $school['school'] . ', ' . $school['city'] . ', ' . $school['country_short'],
'value' => $school['member_schools_number']
);
}
echo json_encode($schools_simple);
break;
default:
break;
}