forked from profis/pc_shop_delivery_sdek
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PC_api.php
34 lines (31 loc) · 760 Bytes
/
PC_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
<?php
/**
* @var PC_core $core
* @var PC_site $site
* @var PC_database $db
* @var PC_routes $routes
*/
switch( $routes->Get_last() ) {
case 'getCityList':
$sdek = new SdekPlugin();
$countries = $sdek->getCountries();
if( !isset($_REQUEST['countryId']) || !isset($countries[$_REQUEST['countryId']]) ) {
@header('HTTP/1.1 404 File Not Found', true, 404);
exit;
}
if( isset($_REQUEST['lang']) && preg_match('#^[a-z]{2}$#', $_REQUEST['lang']) )
$site->ln = $_REQUEST['lang'];
header('Content-Type: application/json');
echo '[';
$idx = 0;
foreach( $sdek->getCities($_REQUEST['countryId']) as $k => $v ) {
if( $idx++ )
echo ',';
echo json_encode(array(
'id' => $k,
'name' => $v,
));
}
echo ']';
break;
}