-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdata.php
69 lines (57 loc) · 2.11 KB
/
data.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
<?php
/**
* Developer: ONUR KAYA
* Contact: empatisoft@gmail.com
*/
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$local = true;
$hostname = 'localhost';
$username = 'root';
$password = 'root';
$database = 'adresler';
$port = 3306;
if($local != true) {
$hostname = '';
$username = '';
$password = '';
$database = '';
$port = 3306;
}
define('DB_SERVER', $hostname);
define('DB_USERNAME', $username);
define('DB_PASSWORD', $password);
define('DB_NAME', $database);
define('DB_PORT', $port);
require_once 'Database.php';
$db = new Database();
$type = filter_input(INPUT_GET, 'type', FILTER_SANITIZE_STRING);
$type = empty($type) ? 'country' : $type;
$country_id = filter_input(INPUT_GET, 'country_id', FILTER_SANITIZE_NUMBER_INT);
$country_id = isset($country_id) && !empty($country_id) ? $country_id : 1;
$city_id = filter_input(INPUT_GET, 'city_id', FILTER_SANITIZE_NUMBER_INT);
$city_id = isset($city_id) && !empty($city_id) ? $city_id : 0;
$county_id = filter_input(INPUT_GET, 'county_id', FILTER_SANITIZE_NUMBER_INT);
$county_id = isset($county_id) && !empty($county_id) ? $county_id : 0;
$data = NULL;
if($type == 'country') {
$data = $db->result('SELECT country_id, name FROM address_country WHERE is_active = 1 ORDER BY name ASC');
} else if($type == 'city') {
$data = $db->result(
'SELECT kimlikNo, bilesenAdi FROM address_city WHERE is_active = 1 AND country_id = :country_id ORDER BY bilesenAdi ASC',
array('country_id' => $country_id)
);
} else if($type == 'county') {
$data = $db->result(
'SELECT ilceKayitNo as kimlikNo, bilesenAdi FROM address_county WHERE is_active = 1 AND ilKayitNo = :city_id ORDER BY bilesenAdi ASC',
array('city_id' => $city_id)
);
} else if($type == 'neighborhood') {
$data = $db->result(
'SELECT kimlikNo, bilesenAdi FROM address_neighborhood WHERE is_active = 1 AND ilceKayitNo = :county_id ORDER BY bilesenAdi ASC',
array('county_id' => $county_id)
);
}
header('Content-type: application/json');
echo json_encode($data, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);