📁 PHP Dosya Yöneticisi
/
/
home
/
demodesigncom
/
e-ticaretv11.demodesign.com.tr
/
propanel
/
controller
/
extension
/
module
📝
city.php
← Geri Dön
<?php /* * IT IS NOT FREE, YOU SHOULD BUY / REFISTER A LICENSE AT HTTPS://MMOSolution.COM * CONTACT: toan@MMOSOLUTION.COM * AUTHOR: MMOSOLUTION TEAM AT VIETNAM * All code within this file is copyright MMOSOLUTION.COM TEAM | FOUNDED @2012 * You can not copy or reuse code within this file without written permission. */ class ControllerExtensionModuleCity extends Controller { private $error = array(); public function index() { $this->load->language('extension/module/city'); $this->document->setTitle($this->language->get('heading_title')); $this->load->model('extension/module/city'); $this->load->model('setting/setting'); if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { $this->model_setting_setting->editSetting('city', $this->request->post); $this->session->data['country_id'] = $this->request->post['country_id']; $this->session->data['zone_id'] = $this->request->post['zone_id']; $this->model_extension_module_city->editCity($this->request->post); $this->session->data['success'] = $this->language->get('text_success'); $this->response->redirect($this->url->link('extension/module/city', 'user_token=' . $this->session->data['user_token'], true)); } $data['row'] = 0; $data = array_merge($data, $this->load->language('extension/module/city')); $data['error_country_id'] = $this->language->get('error_country_id'); $data['error_zone_id'] = $this->language->get('error_zone_id'); $data['MMOS_version'] = '1.0'; $data['MMOS_code_id'] = 'MMOSOC211'; if (isset($this->error['warning'])) { $data['error_warning'] = $this->error['warning']; } else { $data['error_warning'] = ''; } if (isset($this->session->data['error'])) { $data['error_warning'] = $this->session->data['error']; unset($this->session->data['error']); } else { $data['error_warning'] = ''; } if (isset($this->session->data['success'])) { $data['success'] = $this->session->data['success']; unset($this->session->data['success']); } else { $data['success'] = ''; } if (isset($this->session->data['zone_id_incorrect'])) { $zone_id_incorrect = ''; $total_zone_id_incorrect = count($this->session->data['zone_id_incorrect']); foreach ($this->session->data['zone_id_incorrect'] as $zone_id) { if ($total_zone_id_incorrect > 1) { $zone_id_incorrect .= $zone_id . ','; } else { $zone_id_incorrect = $zone_id; } } $data['error_warning'] = $this->language->get('error_zone_ids') . $zone_id_incorrect; unset($this->session->data['zone_id_incorrect']); } if (isset($this->error['name'])) { $data['error_name'] = $this->error['name']; } else { $data['error_name'] = array(); } if (isset($this->error['zone'])) { $data['error_zone'] = $this->error['zone']; } else { $data['error_zone'] = ''; } $data['breadcrumbs'] = array(); $data['breadcrumbs'][] = array( 'text' => $this->language->get('text_home'), 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) ); $data['breadcrumbs'][] = array( 'text' => $this->language->get('heading_title'), 'href' => $this->url->link('extension/module/city', 'user_token=' . $this->session->data['user_token'], true) ); $data['action'] = $this->url->link('extension/module/city', 'user_token=' . $this->session->data['user_token'], true); $data['export'] = $this->url->link('extension/module/city/export', 'user_token=' . $this->session->data['user_token'], 'SSL'); $data['uploadfile'] = $this->url->link('extension/module/city/uploadfile', 'user_token=' . $this->session->data['user_token'], 'SSL'); $data['cancel'] = $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true); $data['zone_to_cities'] = array(); if (isset($this->request->post['zone_to_city'])) { $data['zone_to_cities'] = $this->request->post['zone_to_city']; $data['country_id'] = $this->request->post['country_id']; $data['zone_id'] = $this->request->post['zone_id']; } else { $data['country_id'] = $this->config->get('config_country_id'); $data['zone_id'] = $this->config->get('config_zone_id'); $data['zone_to_cities'] = $this->model_extension_module_city->getCity($data['zone_id']); } if (isset($this->request->post['module_city_status'])) { $data['module_city_status'] = $this->request->post['module_city_status']; } else { $data['module_city_status'] = $this->config->get('module_city_status'); } if (isset($this->request->post['module_city_postcode'])) { $data['module_city_postcode'] = $this->request->post['module_city_postcode']; } else { $data['module_city_postcode'] = $this->config->get('module_city_postcode'); } $this->load->model('localisation/country'); $data['countries'] = $this->model_localisation_country->getCountries(); $data['user_token'] = $this->session->data['user_token']; $data['header'] = $this->load->controller('common/header'); $data['column_left'] = $this->load->controller('common/column_left'); $data['footer'] = $this->load->controller('common/footer'); $this->response->setOutput($this->load->view('extension/module/city', $data)); } protected function validateForm() { if (!$this->user->hasPermission('modify', 'extension/module/city')) { $this->error['warning'] = $this->language->get('error_permission'); } if (empty($this->request->post['zone_id'])) { $this->error['zone'] = $this->language->get('error_zone_id'); } if (isset($this->request->post['zone_to_city'])) { foreach ($this->request->post['zone_to_city'] as $key => $value) { if (empty($value['name'])) { $this->error['name'][$key] = $this->language->get('error_name'); } } } return !$this->error; } protected function validate() { if (!$this->user->hasPermission('modify', 'extension/module/city')) { $this->error['warning'] = $this->language->get('error_permission'); } return !$this->error; } public function savecity() { $this->load->model('extension/module/city'); $this->load->language('extension/module/city'); $json = array(); if (!$this->user->hasPermission('modify', 'extension/module/city')) { $json['permission'] = $this->language->get('error_permission'); } else { $this->load->model('setting/setting'); if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { $this->model_setting_setting->editSetting('module_city', $this->request->post); } if (empty($this->request->post['zone_id'])) { $json['error']['warning']['country_id'] = $this->language->get('error_country_id'); } if (empty($this->request->post['zone_id'])) { $json['error']['warning']['zone_id'] = $this->language->get('error_zone_id'); } // if (empty($this->request->post['zone_to_city'])) { // $json['error']['warning']['zone_to_city'] = $this->language->get('error_zone_to_city'); // } if (!isset($json['error'])) { foreach ($this->request->post['zone_to_city'] as $key => $value) { if (empty($value['name'])) { $json['error']['name'][$key] = $this->language->get('error_name'); } } } if (!isset($json['error'])) { $this->model_extension_module_city->editCity($this->request->post); $json['success'] = $this->language->get('text_success'); $this->load->model('setting/setting'); $config = array( 'citiesdropdown_country_id' => $this->request->post['country_id'], 'citiesdropdown_zone_id' => $this->request->post['zone_id'] ); $this->model_setting_setting->editSetting('citiesdropdown', $config); } } $this->response->addHeader('Content-Type: application/json'); $this->response->setOutput(json_encode($json)); } public function zone() { $this->load->language('extension/module/city'); $this->load->model('localisation/zone'); $results = $this->model_localisation_zone->getZonesByCountryId($this->request->get['country_id']); $output = '<option value="0">' . $this->language->get('text_select') . '</option>'; foreach ($results as $result) { $output .= '<option value="' . $result['zone_id'] . '"'; if ($this->request->get['zone_id'] == $result['zone_id']) { $output .= ' selected="selected"'; } $output .= '>' . $result['name'] . ' - ( ' . $result['zone_id'] . ' )' . '</option>'; } $this->response->setOutput($output); } public function ajaxcity() { $json = array(); $this->load->language('extension/module/city'); $this->load->model('extension/module/city'); $cities = $this->model_extension_module_city->getCity($this->request->post['zone_id']); $html = ''; $row = 0; foreach ($cities as $city) { if ($city['status'] == 1) { $status_enabled = 'selected'; $status_disabled = ''; } else { $status_enabled = ''; $status_disabled = 'selected'; } $html .= '<tr id = "zone-to-city-row' . $row . '">'; $html .= '<input type = "hidden" name = "zone_to_city[' . $row . '][city_id]" value = "' . $city['city_id'] . '"/>'; $html .= '<td class = "text-left"><input type = "text" name = "zone_to_city[' . $row . '][name]" value = "' . $city['name'] . '" class = "form-control"/></td>'; $html .= '<td class = "text-left"><input type = "text" name = "zone_to_city[' . $row . '][code]" value = "' . $city['code'] . '" class = "form-control"/></td>'; $html .= '<td class = "text-left"><input type = "text" name = "zone_to_city[' . $row . '][sort_order]" value = "' . $city['sort_order'] . '" class = "form-control"/></td>'; $html .= '<td class="text-center">'; $html .= ' <select name="zone_to_city[' . $row . '][status]" class="form-control">'; $html .= ' <option value="1" ' . $status_enabled . '>' . $this->language->get('text_enabled') . '</option>'; $html .= ' <option value="0" ' . $status_disabled . '>' . $this->language->get('text_disabled') . '</option>'; $html .= ' </select>'; $html .= '</td>'; $html .= '<td class="text-left"><button type="button" onclick="$(\'#zone-to-city-row' . $row . '\').remove();" data-toggle="tooltip" title="<?php echo $button_remove; ?>" class="btn btn-danger"><i class="fa fa-minus-circle"></i></button></td>'; $html .= '</tr>'; $row++; } $json['html'] = $html; $json['row'] = $row; $this->response->addHeader('Content-Type: application/json'); $this->response->setOutput(json_encode($json)); } public function export() { $this->load->language('extension/module/city'); if ($this->validate()) { if (isset($this->request->get['country_id']) && $this->request->get['country_id'] != 0) { $this->response->addheader('Pragma: public'); $this->response->addheader('Expires: 0'); $this->response->addheader('Content-Description: File Transfer'); $this->response->addheader('Content-Type: application/octet-stream'); $this->response->addheader('Content-Disposition: attachment; filename=Cities_Dropdown_' . date('Y-m-d_H-i-s', time()) . '.csv'); $this->response->addheader('Content-Transfer-Encoding: binary'); $city_list = array(); $zone_list = array(); if (!$this->request->get['all'] || $this->request->get['zone_id'] == 0) { $zone_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "zone WHERE country_id = '" . (int) $this->request->get['country_id'] . "'"); foreach ($zone_query->rows as $zone) { $city_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "city WHERE zone_id = '" . (int) $zone['zone_id'] . "'"); $city_list = array_merge($city_list, $city_query->rows); $zone_list[$zone['zone_id']] = $zone['name']; } } else { $country_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "zone WHERE zone_id = '" . (int) $this->request->get['zone_id'] . "'"); $zone_list[$this->request->get['zone_id']] = $country_query->row['name']; if ($country_query->row && $country_query->row['country_id'] == $this->request->get['country_id']) { $city_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "city WHERE zone_id = '" . (int) $this->request->get['zone_id'] . "'"); $city_list = $city_query->rows; } } $header = array(); $header[] = $this->language->get('export_zone_id'); $header[] = $this->language->get('export_zone_name'); $header[] = $this->language->get('export_id'); $header[] = $this->language->get('export_city_name'); $header[] = $this->language->get('export_code'); $header[] = $this->language->get('export_sort_order'); $header[] = $this->language->get('export_status'); $output = '"' . implode('","', $header) . '"'; $output .= "\n"; if ($city_list) { foreach ($city_list as $city) { $data_out = array(); $data_out[] = (int) $city['zone_id']; $data_out[] = isset($zone_list[$city['zone_id']]) ? $zone_list[$city['zone_id']] : ''; $data_out[] = (int) $city['city_id']; $data_out[] = stripslashes($city['name']); $data_out[] = stripslashes($city['code']); $data_out[] = (int) $city['sort_order']; $data_out[] = (int) $city['status']; $output .= '"' . implode('","', $data_out) . '"'; $output .= "\n"; } } $this->response->setOutput($output); } else { $this->session->data['error'] = $this->language->get('error_contry_id'); $this->response->redirect($this->url->link('extension/module/city', 'user_token=' . $this->session->data['user_token'], true)); } } } public function uploadfile() { if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { if (is_uploaded_file($this->request->files['import']['tmp_name'])) { $this->import($this->request->files['import']['tmp_name']); } } $this->response->redirect($this->url->link('extension/module/city', 'user_token=' . $this->session->data['user_token'], 'SSL')); } private function import($file) { $this->load->language('extension/module/city'); if ($file && $this->validate()) { $row = 1; $status = false; if (($handle = fopen($file, "r")) !== false) { while (($data = fgetcsv($handle, 1000, ",")) !== false) { if ($data[0] == $this->language->get('export_zone_id') && $data[1] == $this->language->get('export_zone_name') && $data[2] == $this->language->get('export_id') && $data[3] == $this->language->get('export_city_name') && $data[4] == $this->language->get('export_code') && $data[5] == $this->language->get('export_sort_order') && $data[6] == $this->language->get('export_status')) { $status = true; break; } } if ($status) { $query_zone = $this->db->query("SELECT zone_id FROM " . DB_PREFIX . "zone"); $zone_ids = array(); foreach ($query_zone->rows as $zone_id) { $zone_ids[] = $zone_id['zone_id']; } while (($data = fgetcsv($handle, 1000, ",")) !== false) { $query_city = $this->db->query("SELECT * FROM " . DB_PREFIX . "city WHERE city_id = '" . (int) $data[2] . "'"); if (in_array($data[0], $zone_ids)) { if (isset($data[2])) { if ($query_city->row) { $this->db->query("UPDATE " . DB_PREFIX . "city SET `zone_id` = '" . (int) $data[0] . "', `name` = '" . $this->db->escape($data[3]) . "', `code` = '" . $this->db->escape($data[4]) . "', `sort_order` = '" . (int) $data[5] . "', `status` = '" . (int) $data[6] . "' WHERE city_id = '" . (int) $data[2] . "'"); } else { if ($data[0]) { $this->db->query("INSERT INTO " . DB_PREFIX . "city SET `city_id` = '" . (int) $data[2] . "', `zone_id` = '" . (int) $data[0] . "', `name` = '" . $this->db->escape($data[3]) . "', `code` = '" . $this->db->escape($data[4]) . "', `sort_order` = '" . (int) $data[5] . "', `status` = '" . (int) $data[6] . "'"); } } } else { $this->db->query("INSERT INTO " . DB_PREFIX . "city SET `zone_id` = '" . (int) $data[0] . "', `name` = '" . $this->db->escape($data[3]) . "', `code` = '" . $this->db->escape($data[4]) . "', `sort_order` = '" . (int) $data[5] . ", `status` = '" . (int) $data[6] . "'"); } } else { $this->session->data['zone_id_incorrect'][] = $data[0]; } $row++; } fclose($handle); $this->session->data['success'] = $this->language->get('text_import_success'); } else { $this->session->data['error'] = $this->language->get('error_import_invalid'); } } } else { $this->session->data['error'] = $this->language->get('error_import'); } } public function install() { $this->load->model('extension/module/city'); $this->model_extension_module_city->install(); $permissions = array("city"); $this->load->model('user/user_group'); foreach ($permissions as $p) { $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/module/' . $p); $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/module/' . $p); } } }
💾 Kaydet
İptal
📝 Yeniden Adlandır
İptal
Kaydet
🔐 Dosya İzinleri (chmod)
İzin Değeri:
Hızlı Seçim:
777
755
644
600
777
= Herkes okur/yazar/çalıştırır
755
= Sahip tam, diğerleri okur/çalıştırır
644
= Sahip okur/yazar, diğerleri okur
600
= Sadece sahip okur/yazar
İptal
Uygula