45 lines
1.3 KiB
PHP
45 lines
1.3 KiB
PHP
<?php
|
|
class ControllerCommonCity extends Controller {
|
|
public function index() {
|
|
$this->load->model('localisation/zone');
|
|
|
|
$country_id = $this->config->get('config_country_id');
|
|
|
|
$zones = $this->model_localisation_zone->getZonesByCountryId($country_id);
|
|
|
|
$current_zone_id = isset($this->session->data['city_id']) ? (int)$this->session->data['city_id'] : (int)$this->config->get('config_zone_id');
|
|
|
|
$data['zones'] = array();
|
|
|
|
foreach ($zones as $zone) {
|
|
$data['zones'][] = array(
|
|
'zone_id' => $zone['zone_id'],
|
|
'name' => $zone['name'],
|
|
'active' => ($zone['zone_id'] == $current_zone_id),
|
|
);
|
|
}
|
|
|
|
$data['action'] = $this->url->link('common/city/save');
|
|
|
|
$this->response->setOutput($this->load->view('common/city_list', $data));
|
|
}
|
|
|
|
public function save() {
|
|
$json = array();
|
|
|
|
if (isset($this->request->post['city_id'])) {
|
|
$this->session->data['city_id'] = (int)$this->request->post['city_id'];
|
|
$json['success'] = true;
|
|
|
|
$this->load->model('localisation/zone');
|
|
$zone = $this->model_localisation_zone->getZone($this->session->data['city_id']);
|
|
$json['name'] = $zone ? $zone['name'] : '';
|
|
} else {
|
|
$json['success'] = false;
|
|
}
|
|
|
|
$this->response->addHeader('Content-Type: application/json');
|
|
$this->response->setOutput(json_encode($json));
|
|
}
|
|
}
|