diff options
Diffstat (limited to 'public/admin/controller/localisation')
-rw-r--r-- | public/admin/controller/localisation/country.php | 438 | ||||
-rw-r--r-- | public/admin/controller/localisation/currency.php | 463 | ||||
-rw-r--r-- | public/admin/controller/localisation/geo_zone.php | 377 | ||||
-rw-r--r-- | public/admin/controller/localisation/language.php | 438 | ||||
-rw-r--r-- | public/admin/controller/localisation/length_class.php | 375 | ||||
-rw-r--r-- | public/admin/controller/localisation/location.php | 427 | ||||
-rw-r--r-- | public/admin/controller/localisation/order_status.php | 366 | ||||
-rw-r--r-- | public/admin/controller/localisation/return_action.php | 345 | ||||
-rw-r--r-- | public/admin/controller/localisation/return_reason.php | 345 | ||||
-rw-r--r-- | public/admin/controller/localisation/return_status.php | 355 | ||||
-rw-r--r-- | public/admin/controller/localisation/stock_status.php | 346 | ||||
-rw-r--r-- | public/admin/controller/localisation/tax_class.php | 373 | ||||
-rw-r--r-- | public/admin/controller/localisation/tax_rate.php | 403 | ||||
-rw-r--r-- | public/admin/controller/localisation/weight_class.php | 375 | ||||
-rw-r--r-- | public/admin/controller/localisation/zone.php | 393 |
15 files changed, 5819 insertions, 0 deletions
diff --git a/public/admin/controller/localisation/country.php b/public/admin/controller/localisation/country.php new file mode 100644 index 0000000..dadc056 --- /dev/null +++ b/public/admin/controller/localisation/country.php @@ -0,0 +1,438 @@ +<?php +class ControllerLocalisationCountry extends Controller { + private $error = array(); + + public function index() { + $this->load->language('localisation/country'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/country'); + + $this->getList(); + } + + public function add() { + $this->load->language('localisation/country'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/country'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_country->addCountry($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('localisation/country', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('localisation/country'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/country'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_country->editCountry($this->request->get['country_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('localisation/country', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('localisation/country'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/country'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $country_id) { + $this->model_localisation_country->deleteCountry($country_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('localisation/country', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'name'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $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('localisation/country', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('localisation/country/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('localisation/country/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['countries'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $country_total = $this->model_localisation_country->getTotalCountries(); + + $results = $this->model_localisation_country->getCountries($filter_data); + + foreach ($results as $result) { + $data['countries'][] = array( + 'country_id' => $result['country_id'], + 'name' => $result['name'] . (($result['country_id'] == $this->config->get('config_country_id')) ? $this->language->get('text_default') : null), + 'iso_code_2' => $result['iso_code_2'], + 'iso_code_3' => $result['iso_code_3'], + 'edit' => $this->url->link('localisation/country/edit', 'user_token=' . $this->session->data['user_token'] . '&country_id=' . $result['country_id'] . $url, true) + ); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } 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->request->post['selected'])) { + $data['selected'] = (array)$this->request->post['selected']; + } else { + $data['selected'] = array(); + } + + $url = ''; + + if ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_name'] = $this->url->link('localisation/country', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url, true); + $data['sort_iso_code_2'] = $this->url->link('localisation/country', 'user_token=' . $this->session->data['user_token'] . '&sort=iso_code_2' . $url, true); + $data['sort_iso_code_3'] = $this->url->link('localisation/country', 'user_token=' . $this->session->data['user_token'] . '&sort=iso_code_3' . $url, true); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + $pagination = new Pagination(); + $pagination->total = $country_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('localisation/country', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($country_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($country_total - $this->config->get('config_limit_admin'))) ? $country_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $country_total, ceil($country_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + $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('localisation/country_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['country_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = ''; + } + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $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('localisation/country', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['country_id'])) { + $data['action'] = $this->url->link('localisation/country/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('localisation/country/edit', 'user_token=' . $this->session->data['user_token'] . '&country_id=' . $this->request->get['country_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('localisation/country', 'user_token=' . $this->session->data['user_token'] . $url, true); + + if (isset($this->request->get['country_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $country_info = $this->model_localisation_country->getCountry($this->request->get['country_id']); + } + + if (isset($this->request->post['name'])) { + $data['name'] = $this->request->post['name']; + } elseif (!empty($country_info)) { + $data['name'] = $country_info['name']; + } else { + $data['name'] = ''; + } + + if (isset($this->request->post['iso_code_2'])) { + $data['iso_code_2'] = $this->request->post['iso_code_2']; + } elseif (!empty($country_info)) { + $data['iso_code_2'] = $country_info['iso_code_2']; + } else { + $data['iso_code_2'] = ''; + } + + if (isset($this->request->post['iso_code_3'])) { + $data['iso_code_3'] = $this->request->post['iso_code_3']; + } elseif (!empty($country_info)) { + $data['iso_code_3'] = $country_info['iso_code_3']; + } else { + $data['iso_code_3'] = ''; + } + + if (isset($this->request->post['address_format'])) { + $data['address_format'] = $this->request->post['address_format']; + } elseif (!empty($country_info)) { + $data['address_format'] = $country_info['address_format']; + } else { + $data['address_format'] = ''; + } + + if (isset($this->request->post['postcode_required'])) { + $data['postcode_required'] = $this->request->post['postcode_required']; + } elseif (!empty($country_info)) { + $data['postcode_required'] = $country_info['postcode_required']; + } else { + $data['postcode_required'] = 0; + } + + if (isset($this->request->post['status'])) { + $data['status'] = $this->request->post['status']; + } elseif (!empty($country_info)) { + $data['status'] = $country_info['status']; + } else { + $data['status'] = '1'; + } + + $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('localisation/country_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'localisation/country')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ((utf8_strlen($this->request->post['name']) < 1) || (utf8_strlen($this->request->post['name']) > 128)) { + $this->error['name'] = $this->language->get('error_name'); + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'localisation/country')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + $this->load->model('setting/store'); + $this->load->model('customer/customer'); + $this->load->model('localisation/zone'); + $this->load->model('localisation/geo_zone'); + + foreach ($this->request->post['selected'] as $country_id) { + if ($this->config->get('config_country_id') == $country_id) { + $this->error['warning'] = $this->language->get('error_default'); + } + + $store_total = $this->model_setting_store->getTotalStoresByCountryId($country_id); + + if ($store_total) { + $this->error['warning'] = sprintf($this->language->get('error_store'), $store_total); + } + + $address_total = $this->model_customer_customer->getTotalAddressesByCountryId($country_id); + + if ($address_total) { + $this->error['warning'] = sprintf($this->language->get('error_address'), $address_total); + } + + $zone_total = $this->model_localisation_zone->getTotalZonesByCountryId($country_id); + + if ($zone_total) { + $this->error['warning'] = sprintf($this->language->get('error_zone'), $zone_total); + } + + $zone_to_geo_zone_total = $this->model_localisation_geo_zone->getTotalZoneToGeoZoneByCountryId($country_id); + + if ($zone_to_geo_zone_total) { + $this->error['warning'] = sprintf($this->language->get('error_zone_to_geo_zone'), $zone_to_geo_zone_total); + } + } + + return !$this->error; + } + + public function country() { + $json = array(); + + $this->load->model('localisation/country'); + + $country_info = $this->model_localisation_country->getCountry($this->request->get['country_id']); + + if ($country_info) { + $this->load->model('localisation/zone'); + + $json = array( + 'country_id' => $country_info['country_id'], + 'name' => $country_info['name'], + 'iso_code_2' => $country_info['iso_code_2'], + 'iso_code_3' => $country_info['iso_code_3'], + 'address_format' => $country_info['address_format'], + 'postcode_required' => $country_info['postcode_required'], + 'zone' => $this->model_localisation_zone->getZonesByCountryId($this->request->get['country_id']), + 'status' => $country_info['status'] + ); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } +}
\ No newline at end of file diff --git a/public/admin/controller/localisation/currency.php b/public/admin/controller/localisation/currency.php new file mode 100644 index 0000000..68a0c97 --- /dev/null +++ b/public/admin/controller/localisation/currency.php @@ -0,0 +1,463 @@ +<?php +class ControllerLocalisationCurrency extends Controller { + private $error = array(); + + public function index() { + $this->load->language('localisation/currency'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/currency'); + + $this->getList(); + } + + public function add() { + $this->load->language('localisation/currency'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/currency'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_currency->addCurrency($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('localisation/currency', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('localisation/currency'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/currency'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_currency->editCurrency($this->request->get['currency_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('localisation/currency', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('localisation/currency'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/currency'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $currency_id) { + $this->model_localisation_currency->deleteCurrency($currency_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('localisation/currency', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + public function refresh() { + $this->load->language('localisation/currency'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/currency'); + + if ($this->validateRefresh()) { + $this->model_localisation_currency->refresh(true); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + //$this->response->redirect($this->url->link('localisation/currency', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'title'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $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('localisation/currency', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('localisation/currency/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('localisation/currency/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['refresh'] = $this->url->link('localisation/currency/refresh', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['currencies'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $currency_total = $this->model_localisation_currency->getTotalCurrencies(); + + $results = $this->model_localisation_currency->getCurrencies($filter_data); + + foreach ($results as $result) { + $data['currencies'][] = array( + 'currency_id' => $result['currency_id'], + 'title' => $result['title'] . (($result['code'] == $this->config->get('config_currency')) ? $this->language->get('text_default') : null), + 'code' => $result['code'], + 'value' => $result['value'], + 'date_modified' => date($this->language->get('date_format_short'), strtotime($result['date_modified'])), + 'edit' => $this->url->link('localisation/currency/edit', 'user_token=' . $this->session->data['user_token'] . '¤cy_id=' . $result['currency_id'] . $url, true) + ); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } 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->request->post['selected'])) { + $data['selected'] = (array)$this->request->post['selected']; + } else { + $data['selected'] = array(); + } + + $url = ''; + + if ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_title'] = $this->url->link('localisation/currency', 'user_token=' . $this->session->data['user_token'] . '&sort=title' . $url, true); + $data['sort_code'] = $this->url->link('localisation/currency', 'user_token=' . $this->session->data['user_token'] . '&sort=code' . $url, true); + $data['sort_value'] = $this->url->link('localisation/currency', 'user_token=' . $this->session->data['user_token'] . '&sort=value' . $url, true); + $data['sort_date_modified'] = $this->url->link('localisation/currency', 'user_token=' . $this->session->data['user_token'] . '&sort=date_modified' . $url, true); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + $pagination = new Pagination(); + $pagination->total = $currency_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('localisation/currency', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($currency_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($currency_total - $this->config->get('config_limit_admin'))) ? $currency_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $currency_total, ceil($currency_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + $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('localisation/currency_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['currency_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['title'])) { + $data['error_title'] = $this->error['title']; + } else { + $data['error_title'] = ''; + } + + if (isset($this->error['code'])) { + $data['error_code'] = $this->error['code']; + } else { + $data['error_code'] = ''; + } + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $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('localisation/currency', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['currency_id'])) { + $data['action'] = $this->url->link('localisation/currency/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('localisation/currency/edit', 'user_token=' . $this->session->data['user_token'] . '¤cy_id=' . $this->request->get['currency_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('localisation/currency', 'user_token=' . $this->session->data['user_token'] . $url, true); + + if (isset($this->request->get['currency_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $currency_info = $this->model_localisation_currency->getCurrency($this->request->get['currency_id']); + } + + if (isset($this->request->post['title'])) { + $data['title'] = $this->request->post['title']; + } elseif (!empty($currency_info)) { + $data['title'] = $currency_info['title']; + } else { + $data['title'] = ''; + } + + if (isset($this->request->post['code'])) { + $data['code'] = $this->request->post['code']; + } elseif (!empty($currency_info)) { + $data['code'] = $currency_info['code']; + } else { + $data['code'] = ''; + } + + if (isset($this->request->post['symbol_left'])) { + $data['symbol_left'] = $this->request->post['symbol_left']; + } elseif (!empty($currency_info)) { + $data['symbol_left'] = $currency_info['symbol_left']; + } else { + $data['symbol_left'] = ''; + } + + if (isset($this->request->post['symbol_right'])) { + $data['symbol_right'] = $this->request->post['symbol_right']; + } elseif (!empty($currency_info)) { + $data['symbol_right'] = $currency_info['symbol_right']; + } else { + $data['symbol_right'] = ''; + } + + if (isset($this->request->post['decimal_place'])) { + $data['decimal_place'] = $this->request->post['decimal_place']; + } elseif (!empty($currency_info)) { + $data['decimal_place'] = $currency_info['decimal_place']; + } else { + $data['decimal_place'] = ''; + } + + if (isset($this->request->post['value'])) { + $data['value'] = $this->request->post['value']; + } elseif (!empty($currency_info)) { + $data['value'] = $currency_info['value']; + } else { + $data['value'] = ''; + } + + if (isset($this->request->post['status'])) { + $data['status'] = $this->request->post['status']; + } elseif (!empty($currency_info)) { + $data['status'] = $currency_info['status']; + } else { + $data['status'] = ''; + } + + $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('localisation/currency_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'localisation/currency')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ((utf8_strlen($this->request->post['title']) < 3) || (utf8_strlen($this->request->post['title']) > 32)) { + $this->error['title'] = $this->language->get('error_title'); + } + + if (utf8_strlen($this->request->post['code']) != 3) { + $this->error['code'] = $this->language->get('error_code'); + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'localisation/currency')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + $this->load->model('setting/store'); + $this->load->model('sale/order'); + + foreach ($this->request->post['selected'] as $currency_id) { + $currency_info = $this->model_localisation_currency->getCurrency($currency_id); + + if ($currency_info) { + if ($this->config->get('config_currency') == $currency_info['code']) { + $this->error['warning'] = $this->language->get('error_default'); + } + + $store_total = $this->model_setting_store->getTotalStoresByCurrency($currency_info['code']); + + if ($store_total) { + $this->error['warning'] = sprintf($this->language->get('error_store'), $store_total); + } + } + + $order_total = $this->model_sale_order->getTotalOrdersByCurrencyId($currency_id); + + if ($order_total) { + $this->error['warning'] = sprintf($this->language->get('error_order'), $order_total); + } + } + + return !$this->error; + } + + protected function validateRefresh() { + if (!$this->user->hasPermission('modify', 'localisation/currency')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/localisation/geo_zone.php b/public/admin/controller/localisation/geo_zone.php new file mode 100644 index 0000000..5174e4d --- /dev/null +++ b/public/admin/controller/localisation/geo_zone.php @@ -0,0 +1,377 @@ +<?php +class ControllerLocalisationGeoZone extends Controller { + private $error = array(); + + public function index() { + $this->load->language('localisation/geo_zone'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/geo_zone'); + + $this->getList(); + } + + public function add() { + $this->load->language('localisation/geo_zone'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/geo_zone'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_geo_zone->addGeoZone($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('localisation/geo_zone', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('localisation/geo_zone'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/geo_zone'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_geo_zone->editGeoZone($this->request->get['geo_zone_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('localisation/geo_zone', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('localisation/geo_zone'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/geo_zone'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $geo_zone_id) { + $this->model_localisation_geo_zone->deleteGeoZone($geo_zone_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('localisation/geo_zone', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'name'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $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('localisation/geo_zone', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('localisation/geo_zone/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('localisation/geo_zone/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['geo_zones'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $geo_zone_total = $this->model_localisation_geo_zone->getTotalGeoZones(); + + $results = $this->model_localisation_geo_zone->getGeoZones($filter_data); + + foreach ($results as $result) { + $data['geo_zones'][] = array( + 'geo_zone_id' => $result['geo_zone_id'], + 'name' => $result['name'], + 'description' => $result['description'], + 'edit' => $this->url->link('localisation/geo_zone/edit', 'user_token=' . $this->session->data['user_token'] . '&geo_zone_id=' . $result['geo_zone_id'] . $url, true) + ); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } 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->request->post['selected'])) { + $data['selected'] = (array)$this->request->post['selected']; + } else { + $data['selected'] = array(); + } + + $url = ''; + + if ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_name'] = $this->url->link('localisation/geo_zone', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url, true); + $data['sort_description'] = $this->url->link('localisation/geo_zone', 'user_token=' . $this->session->data['user_token'] . '&sort=description' . $url, true); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + $pagination = new Pagination(); + $pagination->total = $geo_zone_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('localisation/geo_zone', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($geo_zone_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($geo_zone_total - $this->config->get('config_limit_admin'))) ? $geo_zone_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $geo_zone_total, ceil($geo_zone_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + $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('localisation/geo_zone_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['geo_zone_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = ''; + } + + if (isset($this->error['description'])) { + $data['error_description'] = $this->error['description']; + } else { + $data['error_description'] = ''; + } + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $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('localisation/geo_zone', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['geo_zone_id'])) { + $data['action'] = $this->url->link('localisation/geo_zone/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('localisation/geo_zone/edit', 'user_token=' . $this->session->data['user_token'] . '&geo_zone_id=' . $this->request->get['geo_zone_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('localisation/geo_zone', 'user_token=' . $this->session->data['user_token'] . $url, true); + + if (isset($this->request->get['geo_zone_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $geo_zone_info = $this->model_localisation_geo_zone->getGeoZone($this->request->get['geo_zone_id']); + } + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->request->post['name'])) { + $data['name'] = $this->request->post['name']; + } elseif (!empty($geo_zone_info)) { + $data['name'] = $geo_zone_info['name']; + } else { + $data['name'] = ''; + } + + if (isset($this->request->post['description'])) { + $data['description'] = $this->request->post['description']; + } elseif (!empty($geo_zone_info)) { + $data['description'] = $geo_zone_info['description']; + } else { + $data['description'] = ''; + } + + $this->load->model('localisation/country'); + + $data['countries'] = $this->model_localisation_country->getCountries(); + + if (isset($this->request->post['zone_to_geo_zone'])) { + $data['zone_to_geo_zones'] = $this->request->post['zone_to_geo_zone']; + } elseif (isset($this->request->get['geo_zone_id'])) { + $data['zone_to_geo_zones'] = $this->model_localisation_geo_zone->getZoneToGeoZones($this->request->get['geo_zone_id']); + } else { + $data['zone_to_geo_zones'] = array(); + } + + $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('localisation/geo_zone_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'localisation/geo_zone')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 32)) { + $this->error['name'] = $this->language->get('error_name'); + } + + if ((utf8_strlen($this->request->post['description']) < 3) || (utf8_strlen($this->request->post['description']) > 255)) { + $this->error['description'] = $this->language->get('error_description'); + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'localisation/geo_zone')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + $this->load->model('localisation/tax_rate'); + + foreach ($this->request->post['selected'] as $geo_zone_id) { + $tax_rate_total = $this->model_localisation_tax_rate->getTotalTaxRatesByGeoZoneId($geo_zone_id); + + if ($tax_rate_total) { + $this->error['warning'] = sprintf($this->language->get('error_tax_rate'), $tax_rate_total); + } + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/localisation/language.php b/public/admin/controller/localisation/language.php new file mode 100644 index 0000000..8090282 --- /dev/null +++ b/public/admin/controller/localisation/language.php @@ -0,0 +1,438 @@ +<?php +class ControllerLocalisationLanguage extends Controller { + private $error = array(); + + public function index() { + $this->load->language('localisation/language'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/language'); + + $this->getList(); + } + + public function add() { + $this->load->language('localisation/language'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/language'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_language->addLanguage($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('localisation/language', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('localisation/language'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/language'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_language->editLanguage($this->request->get['language_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('localisation/language', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('localisation/language'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/language'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $language_id) { + $this->model_localisation_language->deleteLanguage($language_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('localisation/language', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'name'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $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('localisation/language', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('localisation/language/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('localisation/language/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['languages'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $language_total = $this->model_localisation_language->getTotalLanguages(); + + $results = $this->model_localisation_language->getLanguages($filter_data); + + foreach ($results as $result) { + $data['languages'][] = array( + 'language_id' => $result['language_id'], + 'name' => $result['name'] . (($result['code'] == $this->config->get('config_language')) ? $this->language->get('text_default') : null), + 'code' => $result['code'], + 'sort_order' => $result['sort_order'], + 'edit' => $this->url->link('localisation/language/edit', 'user_token=' . $this->session->data['user_token'] . '&language_id=' . $result['language_id'] . $url, true) + ); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } 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->request->post['selected'])) { + $data['selected'] = (array)$this->request->post['selected']; + } else { + $data['selected'] = array(); + } + + $url = ''; + + if ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_name'] = $this->url->link('localisation/language', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url, true); + $data['sort_code'] = $this->url->link('localisation/language', 'user_token=' . $this->session->data['user_token'] . '&sort=code' . $url, true); + $data['sort_sort_order'] = $this->url->link('localisation/language', 'user_token=' . $this->session->data['user_token'] . '&sort=sort_order' . $url, true); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + $pagination = new Pagination(); + $pagination->total = $language_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('localisation/language', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($language_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($language_total - $this->config->get('config_limit_admin'))) ? $language_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $language_total, ceil($language_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + $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('localisation/language_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['language_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = ''; + } + + if (isset($this->error['code'])) { + $data['error_code'] = $this->error['code']; + } else { + $data['error_code'] = ''; + } + + if (isset($this->error['locale'])) { + $data['error_locale'] = $this->error['locale']; + } else { + $data['error_locale'] = ''; + } + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $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('localisation/language', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['language_id'])) { + $data['action'] = $this->url->link('localisation/language/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('localisation/language/edit', 'user_token=' . $this->session->data['user_token'] . '&language_id=' . $this->request->get['language_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('localisation/language', 'user_token=' . $this->session->data['user_token'] . $url, true); + + if (isset($this->request->get['language_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $language_info = $this->model_localisation_language->getLanguage($this->request->get['language_id']); + } + + if (isset($this->request->post['name'])) { + $data['name'] = $this->request->post['name']; + } elseif (!empty($language_info)) { + $data['name'] = $language_info['name']; + } else { + $data['name'] = ''; + } + + if (isset($this->request->post['code'])) { + $data['code'] = $this->request->post['code']; + } elseif (!empty($language_info)) { + $data['code'] = $language_info['code']; + } else { + $data['code'] = ''; + } + + $data['languages'] = array(); + + $folders = glob(DIR_LANGUAGE . '*', GLOB_ONLYDIR); + + foreach ($folders as $folder) { + $data['languages'][] = basename($folder); + } + + if (isset($this->request->post['locale'])) { + $data['locale'] = $this->request->post['locale']; + } elseif (!empty($language_info)) { + $data['locale'] = $language_info['locale']; + } else { + $data['locale'] = ''; + } + + if (isset($this->request->post['sort_order'])) { + $data['sort_order'] = $this->request->post['sort_order']; + } elseif (!empty($language_info)) { + $data['sort_order'] = $language_info['sort_order']; + } else { + $data['sort_order'] = 1; + } + + if (isset($this->request->post['status'])) { + $data['status'] = $this->request->post['status']; + } elseif (!empty($language_info)) { + $data['status'] = $language_info['status']; + } else { + $data['status'] = true; + } + + $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('localisation/language_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'localisation/language')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 32)) { + $this->error['name'] = $this->language->get('error_name'); + } + + if (utf8_strlen($this->request->post['code']) < 2) { + $this->error['code'] = $this->language->get('error_code'); + } + + if (!$this->request->post['locale']) { + $this->error['locale'] = $this->language->get('error_locale'); + } + + $language_info = $this->model_localisation_language->getLanguageByCode($this->request->post['code']); + + if (!isset($this->request->get['language_id'])) { + if ($language_info) { + $this->error['warning'] = $this->language->get('error_exists'); + } + } else { + if ($language_info && ($this->request->get['language_id'] != $language_info['language_id'])) { + $this->error['warning'] = $this->language->get('error_exists'); + } + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'localisation/language')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + $this->load->model('setting/store'); + $this->load->model('sale/order'); + + foreach ($this->request->post['selected'] as $language_id) { + $language_info = $this->model_localisation_language->getLanguage($language_id); + + if ($language_info) { + if ($this->config->get('config_language') == $language_info['code']) { + $this->error['warning'] = $this->language->get('error_default'); + } + + if ($this->config->get('config_admin_language') == $language_info['code']) { + $this->error['warning'] = $this->language->get('error_admin'); + } + + $store_total = $this->model_setting_store->getTotalStoresByLanguage($language_info['code']); + + if ($store_total) { + $this->error['warning'] = sprintf($this->language->get('error_store'), $store_total); + } + } + + $order_total = $this->model_sale_order->getTotalOrdersByLanguageId($language_id); + + if ($order_total) { + $this->error['warning'] = sprintf($this->language->get('error_order'), $order_total); + } + } + + return !$this->error; + } +} diff --git a/public/admin/controller/localisation/length_class.php b/public/admin/controller/localisation/length_class.php new file mode 100644 index 0000000..8a5ce59 --- /dev/null +++ b/public/admin/controller/localisation/length_class.php @@ -0,0 +1,375 @@ +<?php +class ControllerLocalisationLengthClass extends Controller { + private $error = array(); + + public function index() { + $this->load->language('localisation/length_class'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/length_class'); + + $this->getList(); + } + + public function add() { + $this->load->language('localisation/length_class'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/length_class'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_length_class->addLengthClass($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('localisation/length_class', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('localisation/length_class'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/length_class'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_length_class->editLengthClass($this->request->get['length_class_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('localisation/length_class', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('localisation/length_class'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/length_class'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $length_class_id) { + $this->model_localisation_length_class->deleteLengthClass($length_class_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('localisation/length_class', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'title'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $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('localisation/length_class', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('localisation/length_class/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('localisation/length_class/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['length_classes'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $length_class_total = $this->model_localisation_length_class->getTotalLengthClasses(); + + $results = $this->model_localisation_length_class->getLengthClasses($filter_data); + + foreach ($results as $result) { + $data['length_classes'][] = array( + 'length_class_id' => $result['length_class_id'], + 'title' => $result['title'] . (($result['length_class_id'] == $this->config->get('config_length_class_id')) ? $this->language->get('text_default') : null), + 'unit' => $result['unit'], + 'value' => $result['value'], + 'edit' => $this->url->link('localisation/length_class/edit', 'user_token=' . $this->session->data['user_token'] . '&length_class_id=' . $result['length_class_id'] . $url, true) + ); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } 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->request->post['selected'])) { + $data['selected'] = (array)$this->request->post['selected']; + } else { + $data['selected'] = array(); + } + + $url = ''; + + if ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_title'] = $this->url->link('localisation/length_class', 'user_token=' . $this->session->data['user_token'] . '&sort=title' . $url, true); + $data['sort_unit'] = $this->url->link('localisation/length_class', 'user_token=' . $this->session->data['user_token'] . '&sort=unit' . $url, true); + $data['sort_value'] = $this->url->link('localisation/length_class', 'user_token=' . $this->session->data['user_token'] . '&sort=value' . $url, true); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + $pagination = new Pagination(); + $pagination->total = $length_class_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('localisation/length_class', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($length_class_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($length_class_total - $this->config->get('config_limit_admin'))) ? $length_class_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $length_class_total, ceil($length_class_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + $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('localisation/length_class_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['length_class_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['title'])) { + $data['error_title'] = $this->error['title']; + } else { + $data['error_title'] = array(); + } + + if (isset($this->error['unit'])) { + $data['error_unit'] = $this->error['unit']; + } else { + $data['error_unit'] = array(); + } + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $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('localisation/length_class', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['length_class_id'])) { + $data['action'] = $this->url->link('localisation/length_class/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('localisation/length_class/edit', 'user_token=' . $this->session->data['user_token'] . '&length_class_id=' . $this->request->get['length_class_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('localisation/length_class', 'user_token=' . $this->session->data['user_token'] . $url, true); + + if (isset($this->request->get['length_class_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $length_class_info = $this->model_localisation_length_class->getLengthClass($this->request->get['length_class_id']); + } + + $this->load->model('localisation/language'); + + $data['languages'] = $this->model_localisation_language->getLanguages(); + + if (isset($this->request->post['length_class_description'])) { + $data['length_class_description'] = $this->request->post['length_class_description']; + } elseif (isset($this->request->get['length_class_id'])) { + $data['length_class_description'] = $this->model_localisation_length_class->getLengthClassDescriptions($this->request->get['length_class_id']); + } else { + $data['length_class_description'] = array(); + } + + if (isset($this->request->post['value'])) { + $data['value'] = $this->request->post['value']; + } elseif (!empty($length_class_info)) { + $data['value'] = $length_class_info['value']; + } else { + $data['value'] = ''; + } + + $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('localisation/length_class_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'localisation/length_class')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + foreach ($this->request->post['length_class_description'] as $language_id => $value) { + if ((utf8_strlen($value['title']) < 3) || (utf8_strlen($value['title']) > 32)) { + $this->error['title'][$language_id] = $this->language->get('error_title'); + } + + if (!$value['unit'] || (utf8_strlen($value['unit']) > 4)) { + $this->error['unit'][$language_id] = $this->language->get('error_unit'); + } + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'localisation/length_class')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + $this->load->model('catalog/product'); + + foreach ($this->request->post['selected'] as $length_class_id) { + if ($this->config->get('config_length_class_id') == $length_class_id) { + $this->error['warning'] = $this->language->get('error_default'); + } + + $product_total = $this->model_catalog_product->getTotalProductsByLengthClassId($length_class_id); + + if ($product_total) { + $this->error['warning'] = sprintf($this->language->get('error_product'), $product_total); + } + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/localisation/location.php b/public/admin/controller/localisation/location.php new file mode 100644 index 0000000..d01ba17 --- /dev/null +++ b/public/admin/controller/localisation/location.php @@ -0,0 +1,427 @@ +<?php +class ControllerLocalisationLocation extends Controller { + private $error = array(); + + public function index() { + $this->load->language('localisation/location'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/location'); + + $this->getList(); + } + + public function add() { + $this->load->language('localisation/location'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/location'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_location->addLocation($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('localisation/location', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('localisation/location'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/location'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_location->editLocation($this->request->get['location_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('localisation/location', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('localisation/location'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/location'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $location_id) { + $this->model_localisation_location->deleteLocation($location_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('localisation/location', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'name'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $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('localisation/location', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('localisation/location/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('localisation/location/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['location'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $location_total = $this->model_localisation_location->getTotalLocations(); + + $results = $this->model_localisation_location->getLocations($filter_data); + + foreach ($results as $result) { + $data['location'][] = array( + 'location_id' => $result['location_id'], + 'name' => $result['name'], + 'address' => $result['address'], + 'edit' => $this->url->link('localisation/location/edit', 'user_token=' . $this->session->data['user_token'] . '&location_id=' . $result['location_id'] . $url, true) + ); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } 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->request->post['selected'])) { + $data['selected'] = (array)$this->request->post['selected']; + } else { + $data['selected'] = array(); + } + + $url = ''; + + if ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_name'] = $this->url->link('localisation/location', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url, true); + $data['sort_address'] = $this->url->link('localisation/location', 'user_token=' . $this->session->data['user_token'] . '&sort=address' . $url, true); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + $pagination = new Pagination(); + $pagination->total = $location_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('localisation/location', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($location_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($location_total - $this->config->get('config_limit_admin'))) ? $location_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $location_total, ceil($location_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + $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('localisation/location_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['location_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = ''; + } + + if (isset($this->error['address'])) { + $data['error_address'] = $this->error['address']; + } else { + $data['error_address'] = ''; + } + + if (isset($this->error['telephone'])) { + $data['error_telephone'] = $this->error['telephone']; + } else { + $data['error_telephone'] = ''; + } + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $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('localisation/location', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['location_id'])) { + $data['action'] = $this->url->link('localisation/location/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('localisation/location/edit', 'user_token=' . $this->session->data['user_token'] . '&location_id=' . $this->request->get['location_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('localisation/location', 'user_token=' . $this->session->data['user_token'] . $url, true); + + if (isset($this->request->get['location_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $location_info = $this->model_localisation_location->getLocation($this->request->get['location_id']); + } + + $data['user_token'] = $this->session->data['user_token']; + + $this->load->model('setting/store'); + + if (isset($this->request->post['name'])) { + $data['name'] = $this->request->post['name']; + } elseif (!empty($location_info)) { + $data['name'] = $location_info['name']; + } else { + $data['name'] = ''; + } + + if (isset($this->request->post['address'])) { + $data['address'] = $this->request->post['address']; + } elseif (!empty($location_info)) { + $data['address'] = $location_info['address']; + } else { + $data['address'] = ''; + } + + if (isset($this->request->post['geocode'])) { + $data['geocode'] = $this->request->post['geocode']; + } elseif (!empty($location_info)) { + $data['geocode'] = $location_info['geocode']; + } else { + $data['geocode'] = ''; + } + + if (isset($this->request->post['telephone'])) { + $data['telephone'] = $this->request->post['telephone']; + } elseif (!empty($location_info)) { + $data['telephone'] = $location_info['telephone']; + } else { + $data['telephone'] = ''; + } + + if (isset($this->request->post['fax'])) { + $data['fax'] = $this->request->post['fax']; + } elseif (!empty($location_info)) { + $data['fax'] = $location_info['fax']; + } else { + $data['fax'] = ''; + } + + if (isset($this->request->post['image'])) { + $data['image'] = $this->request->post['image']; + } elseif (!empty($location_info)) { + $data['image'] = $location_info['image']; + } else { + $data['image'] = ''; + } + + $this->load->model('tool/image'); + + if (isset($this->request->post['image']) && is_file(DIR_IMAGE . $this->request->post['image'])) { + $data['thumb'] = $this->model_tool_image->resize($this->request->post['image'], 100, 100); + } elseif (!empty($location_info) && is_file(DIR_IMAGE . $location_info['image'])) { + $data['thumb'] = $this->model_tool_image->resize($location_info['image'], 100, 100); + } else { + $data['thumb'] = $this->model_tool_image->resize('no_image.png', 100, 100); + } + + $data['placeholder'] = $this->model_tool_image->resize('no_image.png', 100, 100); + + if (isset($this->request->post['open'])) { + $data['open'] = $this->request->post['open']; + } elseif (!empty($location_info)) { + $data['open'] = $location_info['open']; + } else { + $data['open'] = ''; + } + + if (isset($this->request->post['comment'])) { + $data['comment'] = $this->request->post['comment']; + } elseif (!empty($location_info)) { + $data['comment'] = $location_info['comment']; + } else { + $data['comment'] = ''; + } + + $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('localisation/location_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'localisation/location')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 32)) { + $this->error['name'] = $this->language->get('error_name'); + } + + if ((utf8_strlen($this->request->post['address']) < 3) || (utf8_strlen($this->request->post['address']) > 128)) { + $this->error['address'] = $this->language->get('error_address'); + } + + if ((utf8_strlen($this->request->post['telephone']) < 3) || (utf8_strlen($this->request->post['telephone']) > 32)) { + $this->error['telephone'] = $this->language->get('error_telephone'); + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'localisation/location')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/localisation/order_status.php b/public/admin/controller/localisation/order_status.php new file mode 100644 index 0000000..7092113 --- /dev/null +++ b/public/admin/controller/localisation/order_status.php @@ -0,0 +1,366 @@ +<?php +class ControllerLocalisationOrderStatus extends Controller { + private $error = array(); + + public function index() { + $this->load->language('localisation/order_status'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/order_status'); + + $this->getList(); + } + + public function add() { + $this->load->language('localisation/order_status'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/order_status'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_order_status->addOrderStatus($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('localisation/order_status', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('localisation/order_status'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/order_status'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_order_status->editOrderStatus($this->request->get['order_status_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('localisation/order_status', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('localisation/order_status'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/order_status'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $order_status_id) { + $this->model_localisation_order_status->deleteOrderStatus($order_status_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('localisation/order_status', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'name'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $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('localisation/order_status', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('localisation/order_status/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('localisation/order_status/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['order_statuses'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $order_status_total = $this->model_localisation_order_status->getTotalOrderStatuses(); + + $results = $this->model_localisation_order_status->getOrderStatuses($filter_data); + + foreach ($results as $result) { + $data['order_statuses'][] = array( + 'order_status_id' => $result['order_status_id'], + 'name' => $result['name'] . (($result['order_status_id'] == $this->config->get('config_order_status_id')) ? $this->language->get('text_default') : null), + 'edit' => $this->url->link('localisation/order_status/edit', 'user_token=' . $this->session->data['user_token'] . '&order_status_id=' . $result['order_status_id'] . $url, true) + ); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } 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->request->post['selected'])) { + $data['selected'] = (array)$this->request->post['selected']; + } else { + $data['selected'] = array(); + } + + $url = ''; + + if ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_name'] = $this->url->link('localisation/order_status', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url, true); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + $pagination = new Pagination(); + $pagination->total = $order_status_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('localisation/order_status', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($order_status_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($order_status_total - $this->config->get('config_limit_admin'))) ? $order_status_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $order_status_total, ceil($order_status_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + $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('localisation/order_status_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['order_status_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = array(); + } + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $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('localisation/order_status', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['order_status_id'])) { + $data['action'] = $this->url->link('localisation/order_status/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('localisation/order_status/edit', 'user_token=' . $this->session->data['user_token'] . '&order_status_id=' . $this->request->get['order_status_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('localisation/order_status', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $this->load->model('localisation/language'); + + $data['languages'] = $this->model_localisation_language->getLanguages(); + + if (isset($this->request->post['order_status'])) { + $data['order_status'] = $this->request->post['order_status']; + } elseif (isset($this->request->get['order_status_id'])) { + $data['order_status'] = $this->model_localisation_order_status->getOrderStatusDescriptions($this->request->get['order_status_id']); + } else { + $data['order_status'] = array(); + } + + $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('localisation/order_status_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'localisation/order_status')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + foreach ($this->request->post['order_status'] as $language_id => $value) { + if ((utf8_strlen($value['name']) < 3) || (utf8_strlen($value['name']) > 32)) { + $this->error['name'][$language_id] = $this->language->get('error_name'); + } + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'localisation/order_status')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + $this->load->model('setting/store'); + $this->load->model('sale/order'); + + foreach ($this->request->post['selected'] as $order_status_id) { + if ($this->config->get('config_order_status_id') == $order_status_id) { + $this->error['warning'] = $this->language->get('error_default'); + } + + if ($this->config->get('config_download_status_id') == $order_status_id) { + $this->error['warning'] = $this->language->get('error_download'); + } + + $store_total = $this->model_setting_store->getTotalStoresByOrderStatusId($order_status_id); + + if ($store_total) { + $this->error['warning'] = sprintf($this->language->get('error_store'), $store_total); + } + + $order_total = $this->model_sale_order->getTotalOrdersByOrderStatusId($order_status_id); + + if ($order_total) { + $this->error['warning'] = sprintf($this->language->get('error_order'), $order_total); + } + + $order_total = $this->model_sale_order->getTotalOrderHistoriesByOrderStatusId($order_status_id); + + if ($order_total) { + $this->error['warning'] = sprintf($this->language->get('error_order'), $order_total); + } + } + + return !$this->error; + } +} diff --git a/public/admin/controller/localisation/return_action.php b/public/admin/controller/localisation/return_action.php new file mode 100644 index 0000000..6dc5ff9 --- /dev/null +++ b/public/admin/controller/localisation/return_action.php @@ -0,0 +1,345 @@ +<?php +class ControllerLocalisationReturnAction extends Controller { + private $error = array(); + + public function index() { + $this->load->language('localisation/return_action'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/return_action'); + + $this->getList(); + } + + public function add() { + $this->load->language('localisation/return_action'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/return_action'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_return_action->addReturnAction($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('localisation/return_action', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('localisation/return_action'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/return_action'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_return_action->editReturnAction($this->request->get['return_action_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('localisation/return_action', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('localisation/return_action'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/return_action'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $return_action_id) { + $this->model_localisation_return_action->deleteReturnAction($return_action_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('localisation/return_action', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'name'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $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('localisation/return_action', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('localisation/return_action/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('localisation/return_action/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['return_actions'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $return_action_total = $this->model_localisation_return_action->getTotalReturnActions(); + + $results = $this->model_localisation_return_action->getReturnActions($filter_data); + + foreach ($results as $result) { + $data['return_actions'][] = array( + 'return_action_id' => $result['return_action_id'], + 'name' => $result['name'], + 'edit' => $this->url->link('localisation/return_action/edit', 'user_token=' . $this->session->data['user_token'] . '&return_action_id=' . $result['return_action_id'] . $url, true) + ); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } 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->request->post['selected'])) { + $data['selected'] = (array)$this->request->post['selected']; + } else { + $data['selected'] = array(); + } + + $url = ''; + + if ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_name'] = $this->url->link('localisation/return_action', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url, true); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + $pagination = new Pagination(); + $pagination->total = $return_action_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('localisation/return_action', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($return_action_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($return_action_total - $this->config->get('config_limit_admin'))) ? $return_action_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $return_action_total, ceil($return_action_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + $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('localisation/return_action_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['return_action_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = array(); + } + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $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('localisation/return_action', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['return_action_id'])) { + $data['action'] = $this->url->link('localisation/return_action/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('localisation/return_action/edit', 'user_token=' . $this->session->data['user_token'] . '&return_action_id=' . $this->request->get['return_action_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('localisation/return_action', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $this->load->model('localisation/language'); + + $data['languages'] = $this->model_localisation_language->getLanguages(); + + if (isset($this->request->post['return_action'])) { + $data['return_action'] = $this->request->post['return_action']; + } elseif (isset($this->request->get['return_action_id'])) { + $data['return_action'] = $this->model_localisation_return_action->getReturnActionDescriptions($this->request->get['return_action_id']); + } else { + $data['return_action'] = array(); + } + + $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('localisation/return_action_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'localisation/return_action')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + foreach ($this->request->post['return_action'] as $language_id => $value) { + if ((utf8_strlen($value['name']) < 3) || (utf8_strlen($value['name']) > 64)) { + $this->error['name'][$language_id] = $this->language->get('error_name'); + } + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'localisation/return_action')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + $this->load->model('sale/return'); + + foreach ($this->request->post['selected'] as $return_action_id) { + $return_total = $this->model_sale_return->getTotalReturnsByReturnActionId($return_action_id); + + if ($return_total) { + $this->error['warning'] = sprintf($this->language->get('error_return'), $return_total); + } + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/localisation/return_reason.php b/public/admin/controller/localisation/return_reason.php new file mode 100644 index 0000000..4be8c54 --- /dev/null +++ b/public/admin/controller/localisation/return_reason.php @@ -0,0 +1,345 @@ +<?php +class ControllerLocalisationReturnReason extends Controller { + private $error = array(); + + public function index() { + $this->load->language('localisation/return_reason'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/return_reason'); + + $this->getList(); + } + + public function add() { + $this->load->language('localisation/return_reason'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/return_reason'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_return_reason->addReturnReason($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('localisation/return_reason', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('localisation/return_reason'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/return_reason'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_return_reason->editReturnReason($this->request->get['return_reason_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('localisation/return_reason', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('localisation/return_reason'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/return_reason'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $return_reason_id) { + $this->model_localisation_return_reason->deleteReturnReason($return_reason_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('localisation/return_reason', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'name'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $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('localisation/return_reason', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('localisation/return_reason/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('localisation/return_reason/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['return_reasons'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $return_reason_total = $this->model_localisation_return_reason->getTotalReturnReasons(); + + $results = $this->model_localisation_return_reason->getReturnReasons($filter_data); + + foreach ($results as $result) { + $data['return_reasons'][] = array( + 'return_reason_id' => $result['return_reason_id'], + 'name' => $result['name'], + 'edit' => $this->url->link('localisation/return_reason/edit', 'user_token=' . $this->session->data['user_token'] . '&return_reason_id=' . $result['return_reason_id'] . $url, true) + ); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } 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->request->post['selected'])) { + $data['selected'] = (array)$this->request->post['selected']; + } else { + $data['selected'] = array(); + } + + $url = ''; + + if ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_name'] = $this->url->link('localisation/return_reason', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url, true); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + $pagination = new Pagination(); + $pagination->total = $return_reason_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('localisation/return_reason', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($return_reason_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($return_reason_total - $this->config->get('config_limit_admin'))) ? $return_reason_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $return_reason_total, ceil($return_reason_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + $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('localisation/return_reason_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['return_reason_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = array(); + } + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $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('localisation/return_reason', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['return_reason_id'])) { + $data['action'] = $this->url->link('localisation/return_reason/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('localisation/return_reason/edit', 'user_token=' . $this->session->data['user_token'] . '&return_reason_id=' . $this->request->get['return_reason_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('localisation/return_reason', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $this->load->model('localisation/language'); + + $data['languages'] = $this->model_localisation_language->getLanguages(); + + if (isset($this->request->post['return_reason'])) { + $data['return_reason'] = $this->request->post['return_reason']; + } elseif (isset($this->request->get['return_reason_id'])) { + $data['return_reason'] = $this->model_localisation_return_reason->getReturnReasonDescriptions($this->request->get['return_reason_id']); + } else { + $data['return_reason'] = array(); + } + + $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('localisation/return_reason_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'localisation/return_reason')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + foreach ($this->request->post['return_reason'] as $language_id => $value) { + if ((utf8_strlen($value['name']) < 3) || (utf8_strlen($value['name']) > 128)) { + $this->error['name'][$language_id] = $this->language->get('error_name'); + } + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'localisation/return_reason')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + $this->load->model('sale/return'); + + foreach ($this->request->post['selected'] as $return_reason_id) { + $return_total = $this->model_sale_return->getTotalReturnsByReturnReasonId($return_reason_id); + + if ($return_total) { + $this->error['warning'] = sprintf($this->language->get('error_return'), $return_total); + } + } + + return !$this->error; + } +} diff --git a/public/admin/controller/localisation/return_status.php b/public/admin/controller/localisation/return_status.php new file mode 100644 index 0000000..42d2b4a --- /dev/null +++ b/public/admin/controller/localisation/return_status.php @@ -0,0 +1,355 @@ +<?php +class ControllerLocalisationReturnStatus extends Controller { + private $error = array(); + + public function index() { + $this->load->language('localisation/return_status'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/return_status'); + + $this->getList(); + } + + public function add() { + $this->load->language('localisation/return_status'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/return_status'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_return_status->addReturnStatus($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('localisation/return_status', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('localisation/return_status'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/return_status'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_return_status->editReturnStatus($this->request->get['return_status_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('localisation/return_status', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('localisation/return_status'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/return_status'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $return_status_id) { + $this->model_localisation_return_status->deleteReturnStatus($return_status_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('localisation/return_status', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'name'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $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('localisation/return_status', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('localisation/return_status/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('localisation/return_status/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['return_statuses'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $return_status_total = $this->model_localisation_return_status->getTotalReturnStatuses(); + + $results = $this->model_localisation_return_status->getReturnStatuses($filter_data); + + foreach ($results as $result) { + $data['return_statuses'][] = array( + 'return_status_id' => $result['return_status_id'], + 'name' => $result['name'] . (($result['return_status_id'] == $this->config->get('config_return_status_id')) ? $this->language->get('text_default') : null), + 'edit' => $this->url->link('localisation/return_status/edit', 'user_token=' . $this->session->data['user_token'] . '&return_status_id=' . $result['return_status_id'] . $url, true) + ); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } 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->request->post['selected'])) { + $data['selected'] = (array)$this->request->post['selected']; + } else { + $data['selected'] = array(); + } + + $url = ''; + + if ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_name'] = $this->url->link('localisation/return_status', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url, true); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + $pagination = new Pagination(); + $pagination->total = $return_status_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('localisation/return_status', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($return_status_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($return_status_total - $this->config->get('config_limit_admin'))) ? $return_status_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $return_status_total, ceil($return_status_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + $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('localisation/return_status_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['return_status_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = array(); + } + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $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('localisation/return_status', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['return_status_id'])) { + $data['action'] = $this->url->link('localisation/return_status/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('localisation/return_status/edit', 'user_token=' . $this->session->data['user_token'] . '&return_status_id=' . $this->request->get['return_status_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('localisation/return_status', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $this->load->model('localisation/language'); + + $data['languages'] = $this->model_localisation_language->getLanguages(); + + if (isset($this->request->post['return_status'])) { + $data['return_status'] = $this->request->post['return_status']; + } elseif (isset($this->request->get['return_status_id'])) { + $data['return_status'] = $this->model_localisation_return_status->getReturnStatusDescriptions($this->request->get['return_status_id']); + } else { + $data['return_status'] = array(); + } + + $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('localisation/return_status_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'localisation/return_status')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + foreach ($this->request->post['return_status'] as $language_id => $value) { + if ((utf8_strlen($value['name']) < 3) || (utf8_strlen($value['name']) > 32)) { + $this->error['name'][$language_id] = $this->language->get('error_name'); + } + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'localisation/return_status')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + $this->load->model('sale/return'); + + foreach ($this->request->post['selected'] as $return_status_id) { + if ($this->config->get('config_return_status_id') == $return_status_id) { + $this->error['warning'] = $this->language->get('error_default'); + } + + $return_total = $this->model_sale_return->getTotalReturnsByReturnStatusId($return_status_id); + + if ($return_total) { + $this->error['warning'] = sprintf($this->language->get('error_return'), $return_total); + } + + $return_total = $this->model_sale_return->getTotalReturnHistoriesByReturnStatusId($return_status_id); + + if ($return_total) { + $this->error['warning'] = sprintf($this->language->get('error_return'), $return_total); + } + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/localisation/stock_status.php b/public/admin/controller/localisation/stock_status.php new file mode 100644 index 0000000..27e6df4 --- /dev/null +++ b/public/admin/controller/localisation/stock_status.php @@ -0,0 +1,346 @@ +<?php +class ControllerLocalisationStockStatus extends Controller { + private $error = array(); + + public function index() { + $this->load->language('localisation/stock_status'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/stock_status'); + + $this->getList(); + } + + public function add() { + $this->load->language('localisation/stock_status'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/stock_status'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_stock_status->addStockStatus($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('localisation/stock_status', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('localisation/stock_status'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/stock_status'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_stock_status->editStockStatus($this->request->get['stock_status_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('localisation/stock_status', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('localisation/stock_status'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/stock_status'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $stock_status_id) { + $this->model_localisation_stock_status->deleteStockStatus($stock_status_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('localisation/stock_status', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'name'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $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('localisation/stock_status', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('localisation/stock_status/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('localisation/stock_status/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['stock_statuses'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $stock_status_total = $this->model_localisation_stock_status->getTotalStockStatuses(); + + $results = $this->model_localisation_stock_status->getStockStatuses($filter_data); + + foreach ($results as $result) { + $data['stock_statuses'][] = array( + 'stock_status_id' => $result['stock_status_id'], + 'name' => $result['name'], + 'edit' => $this->url->link('localisation/stock_status/edit', 'user_token=' . $this->session->data['user_token'] . '&stock_status_id=' . $result['stock_status_id'] . $url, true) + ); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } 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->request->post['selected'])) { + $data['selected'] = (array)$this->request->post['selected']; + } else { + $data['selected'] = array(); + } + + $url = ''; + + if ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_name'] = $this->url->link('localisation/stock_status', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url, true); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + $pagination = new Pagination(); + $pagination->total = $stock_status_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('localisation/stock_status', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($stock_status_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($stock_status_total - $this->config->get('config_limit_admin'))) ? $stock_status_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $stock_status_total, ceil($stock_status_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + $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('localisation/stock_status_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['stock_status_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = array(); + } + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $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('localisation/stock_status', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['stock_status_id'])) { + $data['action'] = $this->url->link('localisation/stock_status/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('localisation/stock_status/edit', 'user_token=' . $this->session->data['user_token'] . '&stock_status_id=' . $this->request->get['stock_status_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('localisation/stock_status', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $this->load->model('localisation/language'); + + $data['languages'] = $this->model_localisation_language->getLanguages(); + + if (isset($this->request->post['stock_status'])) { + $data['stock_status'] = $this->request->post['stock_status']; + } elseif (isset($this->request->get['stock_status_id'])) { + $data['stock_status'] = $this->model_localisation_stock_status->getStockStatusDescriptions($this->request->get['stock_status_id']); + } else { + $data['stock_status'] = array(); + } + + $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('localisation/stock_status_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'localisation/stock_status')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + foreach ($this->request->post['stock_status'] as $language_id => $value) { + if ((utf8_strlen($value['name']) < 3) || (utf8_strlen($value['name']) > 32)) { + $this->error['name'][$language_id] = $this->language->get('error_name'); + } + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'localisation/stock_status')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + $this->load->model('setting/store'); + $this->load->model('catalog/product'); + + foreach ($this->request->post['selected'] as $stock_status_id) { + $product_total = $this->model_catalog_product->getTotalProductsByStockStatusId($stock_status_id); + + if ($product_total) { + $this->error['warning'] = sprintf($this->language->get('error_product'), $product_total); + } + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/localisation/tax_class.php b/public/admin/controller/localisation/tax_class.php new file mode 100644 index 0000000..77a239c --- /dev/null +++ b/public/admin/controller/localisation/tax_class.php @@ -0,0 +1,373 @@ +<?php +class ControllerLocalisationTaxClass extends Controller { + private $error = array(); + + public function index() { + $this->load->language('localisation/tax_class'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/tax_class'); + + $this->getList(); + } + + public function add() { + $this->load->language('localisation/tax_class'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/tax_class'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_tax_class->addTaxClass($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('localisation/tax_class', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('localisation/tax_class'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/tax_class'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_tax_class->editTaxClass($this->request->get['tax_class_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('localisation/tax_class', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('localisation/tax_class'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/tax_class'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $tax_class_id) { + $this->model_localisation_tax_class->deleteTaxClass($tax_class_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('localisation/tax_class', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'title'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $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('localisation/tax_class', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('localisation/tax_class/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('localisation/tax_class/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['tax_classes'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $tax_class_total = $this->model_localisation_tax_class->getTotalTaxClasses(); + + $results = $this->model_localisation_tax_class->getTaxClasses($filter_data); + + foreach ($results as $result) { + $data['tax_classes'][] = array( + 'tax_class_id' => $result['tax_class_id'], + 'title' => $result['title'], + 'edit' => $this->url->link('localisation/tax_class/edit', 'user_token=' . $this->session->data['user_token'] . '&tax_class_id=' . $result['tax_class_id'] . $url, true) + ); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } 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->request->post['selected'])) { + $data['selected'] = (array)$this->request->post['selected']; + } else { + $data['selected'] = array(); + } + + $url = ''; + + if ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_title'] = $this->url->link('localisation/tax_class', 'user_token=' . $this->session->data['user_token'] . '&sort=title' . $url, true); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + $pagination = new Pagination(); + $pagination->total = $tax_class_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('localisation/tax_class', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($tax_class_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($tax_class_total - $this->config->get('config_limit_admin'))) ? $tax_class_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $tax_class_total, ceil($tax_class_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + $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('localisation/tax_class_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['tax_class_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['title'])) { + $data['error_title'] = $this->error['title']; + } else { + $data['error_title'] = ''; + } + + if (isset($this->error['description'])) { + $data['error_description'] = $this->error['description']; + } else { + $data['error_description'] = ''; + } + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $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('localisation/tax_class', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['tax_class_id'])) { + $data['action'] = $this->url->link('localisation/tax_class/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('localisation/tax_class/edit', 'user_token=' . $this->session->data['user_token'] . '&tax_class_id=' . $this->request->get['tax_class_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('localisation/tax_class', 'user_token=' . $this->session->data['user_token'] . $url, true); + + if (isset($this->request->get['tax_class_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $tax_class_info = $this->model_localisation_tax_class->getTaxClass($this->request->get['tax_class_id']); + } + + if (isset($this->request->post['title'])) { + $data['title'] = $this->request->post['title']; + } elseif (!empty($tax_class_info)) { + $data['title'] = $tax_class_info['title']; + } else { + $data['title'] = ''; + } + + if (isset($this->request->post['description'])) { + $data['description'] = $this->request->post['description']; + } elseif (!empty($tax_class_info)) { + $data['description'] = $tax_class_info['description']; + } else { + $data['description'] = ''; + } + + $this->load->model('localisation/tax_rate'); + + $data['tax_rates'] = $this->model_localisation_tax_rate->getTaxRates(); + + if (isset($this->request->post['tax_rule'])) { + $data['tax_rules'] = $this->request->post['tax_rule']; + } elseif (isset($this->request->get['tax_class_id'])) { + $data['tax_rules'] = $this->model_localisation_tax_class->getTaxRules($this->request->get['tax_class_id']); + } else { + $data['tax_rules'] = array(); + } + + $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('localisation/tax_class_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'localisation/tax_class')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ((utf8_strlen($this->request->post['title']) < 3) || (utf8_strlen($this->request->post['title']) > 32)) { + $this->error['title'] = $this->language->get('error_title'); + } + + if ((utf8_strlen($this->request->post['description']) < 3) || (utf8_strlen($this->request->post['description']) > 255)) { + $this->error['description'] = $this->language->get('error_description'); + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'localisation/tax_class')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + $this->load->model('catalog/product'); + + foreach ($this->request->post['selected'] as $tax_class_id) { + $product_total = $this->model_catalog_product->getTotalProductsByTaxClassId($tax_class_id); + + if ($product_total) { + $this->error['warning'] = sprintf($this->language->get('error_product'), $product_total); + } + } + + return !$this->error; + } +} diff --git a/public/admin/controller/localisation/tax_rate.php b/public/admin/controller/localisation/tax_rate.php new file mode 100644 index 0000000..5cf8f58 --- /dev/null +++ b/public/admin/controller/localisation/tax_rate.php @@ -0,0 +1,403 @@ +<?php +class ControllerLocalisationTaxRate extends Controller { + private $error = array(); + + public function index() { + $this->load->language('localisation/tax_rate'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/tax_rate'); + + $this->getList(); + } + + public function add() { + $this->load->language('localisation/tax_rate'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/tax_rate'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_tax_rate->addTaxRate($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('localisation/tax_rate', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('localisation/tax_rate'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/tax_rate'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_tax_rate->editTaxRate($this->request->get['tax_rate_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('localisation/tax_rate', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('localisation/tax_rate'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/tax_rate'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $tax_rate_id) { + $this->model_localisation_tax_rate->deleteTaxRate($tax_rate_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('localisation/tax_rate', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'tr.name'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $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('localisation/tax_rate', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('localisation/tax_rate/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('localisation/tax_rate/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['tax_rates'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $tax_rate_total = $this->model_localisation_tax_rate->getTotalTaxRates(); + + $results = $this->model_localisation_tax_rate->getTaxRates($filter_data); + + foreach ($results as $result) { + $data['tax_rates'][] = array( + 'tax_rate_id' => $result['tax_rate_id'], + 'name' => $result['name'], + 'rate' => $result['rate'], + 'type' => ($result['type'] == 'F' ? $this->language->get('text_amount') : $this->language->get('text_percent')), + 'geo_zone' => $result['geo_zone'], + 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])), + 'date_modified' => date($this->language->get('date_format_short'), strtotime($result['date_modified'])), + 'edit' => $this->url->link('localisation/tax_rate/edit', 'user_token=' . $this->session->data['user_token'] . '&tax_rate_id=' . $result['tax_rate_id'] . $url, true) + ); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } 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->request->post['selected'])) { + $data['selected'] = (array)$this->request->post['selected']; + } else { + $data['selected'] = array(); + } + + $url = ''; + + if ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_name'] = $this->url->link('localisation/tax_rate', 'user_token=' . $this->session->data['user_token'] . '&sort=tr.name' . $url, true); + $data['sort_rate'] = $this->url->link('localisation/tax_rate', 'user_token=' . $this->session->data['user_token'] . '&sort=tr.rate' . $url, true); + $data['sort_type'] = $this->url->link('localisation/tax_rate', 'user_token=' . $this->session->data['user_token'] . '&sort=tr.type' . $url, true); + $data['sort_geo_zone'] = $this->url->link('localisation/tax_rate', 'user_token=' . $this->session->data['user_token'] . '&sort=gz.name' . $url, true); + $data['sort_date_added'] = $this->url->link('localisation/tax_rate', 'user_token=' . $this->session->data['user_token'] . '&sort=tr.date_added' . $url, true); + $data['sort_date_modified'] = $this->url->link('localisation/tax_rate', 'user_token=' . $this->session->data['user_token'] . '&sort=tr.date_modified' . $url, true); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + $pagination = new Pagination(); + $pagination->total = $tax_rate_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('localisation/tax_rate', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($tax_rate_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($tax_rate_total - $this->config->get('config_limit_admin'))) ? $tax_rate_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $tax_rate_total, ceil($tax_rate_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + $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('localisation/tax_rate_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['tax_rate_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = ''; + } + + if (isset($this->error['rate'])) { + $data['error_rate'] = $this->error['rate']; + } else { + $data['error_rate'] = ''; + } + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $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('localisation/tax_rate', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['tax_rate_id'])) { + $data['action'] = $this->url->link('localisation/tax_rate/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('localisation/tax_rate/edit', 'user_token=' . $this->session->data['user_token'] . '&tax_rate_id=' . $this->request->get['tax_rate_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('localisation/tax_rate', 'user_token=' . $this->session->data['user_token'] . $url, true); + + if (isset($this->request->get['tax_rate_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $tax_rate_info = $this->model_localisation_tax_rate->getTaxRate($this->request->get['tax_rate_id']); + } + + if (isset($this->request->post['name'])) { + $data['name'] = $this->request->post['name']; + } elseif (!empty($tax_rate_info)) { + $data['name'] = $tax_rate_info['name']; + } else { + $data['name'] = ''; + } + + if (isset($this->request->post['rate'])) { + $data['rate'] = $this->request->post['rate']; + } elseif (!empty($tax_rate_info)) { + $data['rate'] = $tax_rate_info['rate']; + } else { + $data['rate'] = ''; + } + + if (isset($this->request->post['type'])) { + $data['type'] = $this->request->post['type']; + } elseif (!empty($tax_rate_info)) { + $data['type'] = $tax_rate_info['type']; + } else { + $data['type'] = ''; + } + + if (isset($this->request->post['tax_rate_customer_group'])) { + $data['tax_rate_customer_group'] = $this->request->post['tax_rate_customer_group']; + } elseif (isset($this->request->get['tax_rate_id'])) { + $data['tax_rate_customer_group'] = $this->model_localisation_tax_rate->getTaxRateCustomerGroups($this->request->get['tax_rate_id']); + } else { + $data['tax_rate_customer_group'] = array($this->config->get('config_customer_group_id')); + } + + $this->load->model('customer/customer_group'); + + $data['customer_groups'] = $this->model_customer_customer_group->getCustomerGroups(); + + if (isset($this->request->post['geo_zone_id'])) { + $data['geo_zone_id'] = $this->request->post['geo_zone_id']; + } elseif (!empty($tax_rate_info)) { + $data['geo_zone_id'] = $tax_rate_info['geo_zone_id']; + } else { + $data['geo_zone_id'] = ''; + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + $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('localisation/tax_rate_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'localisation/tax_rate')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 32)) { + $this->error['name'] = $this->language->get('error_name'); + } + + if (!$this->request->post['rate']) { + $this->error['rate'] = $this->language->get('error_rate'); + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'localisation/tax_rate')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + $this->load->model('localisation/tax_class'); + + foreach ($this->request->post['selected'] as $tax_rate_id) { + $tax_rule_total = $this->model_localisation_tax_class->getTotalTaxRulesByTaxRateId($tax_rate_id); + + if ($tax_rule_total) { + $this->error['warning'] = sprintf($this->language->get('error_tax_rule'), $tax_rule_total); + } + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/localisation/weight_class.php b/public/admin/controller/localisation/weight_class.php new file mode 100644 index 0000000..6ef50e0 --- /dev/null +++ b/public/admin/controller/localisation/weight_class.php @@ -0,0 +1,375 @@ +<?php +class ControllerLocalisationWeightClass extends Controller { + private $error = array(); + + public function index() { + $this->load->language('localisation/weight_class'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/weight_class'); + + $this->getList(); + } + + public function add() { + $this->load->language('localisation/weight_class'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/weight_class'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_weight_class->addWeightClass($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('localisation/weight_class', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('localisation/weight_class'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/weight_class'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_weight_class->editWeightClass($this->request->get['weight_class_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('localisation/weight_class', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('localisation/weight_class'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/weight_class'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $weight_class_id) { + $this->model_localisation_weight_class->deleteWeightClass($weight_class_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('localisation/weight_class', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'title'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $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('localisation/weight_class', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('localisation/weight_class/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('localisation/weight_class/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['weight_classes'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $weight_class_total = $this->model_localisation_weight_class->getTotalWeightClasses(); + + $results = $this->model_localisation_weight_class->getWeightClasses($filter_data); + + foreach ($results as $result) { + $data['weight_classes'][] = array( + 'weight_class_id' => $result['weight_class_id'], + 'title' => $result['title'] . (($result['weight_class_id'] == $this->config->get('config_weight_class_id')) ? $this->language->get('text_default') : null), + 'unit' => $result['unit'], + 'value' => $result['value'], + 'edit' => $this->url->link('localisation/weight_class/edit', 'user_token=' . $this->session->data['user_token'] . '&weight_class_id=' . $result['weight_class_id'] . $url, true) + ); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } 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->request->post['selected'])) { + $data['selected'] = (array)$this->request->post['selected']; + } else { + $data['selected'] = array(); + } + + $url = ''; + + if ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_title'] = $this->url->link('localisation/weight_class', 'user_token=' . $this->session->data['user_token'] . '&sort=title' . $url, true); + $data['sort_unit'] = $this->url->link('localisation/weight_class', 'user_token=' . $this->session->data['user_token'] . '&sort=unit' . $url, true); + $data['sort_value'] = $this->url->link('localisation/weight_class', 'user_token=' . $this->session->data['user_token'] . '&sort=value' . $url, true); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + $pagination = new Pagination(); + $pagination->total = $weight_class_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('localisation/weight_class', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($weight_class_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($weight_class_total - $this->config->get('config_limit_admin'))) ? $weight_class_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $weight_class_total, ceil($weight_class_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + $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('localisation/weight_class_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['weight_class_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['title'])) { + $data['error_title'] = $this->error['title']; + } else { + $data['error_title'] = array(); + } + + if (isset($this->error['unit'])) { + $data['error_unit'] = $this->error['unit']; + } else { + $data['error_unit'] = array(); + } + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $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('localisation/weight_class', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['weight_class_id'])) { + $data['action'] = $this->url->link('localisation/weight_class/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('localisation/weight_class/edit', 'user_token=' . $this->session->data['user_token'] . '&weight_class_id=' . $this->request->get['weight_class_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('localisation/weight_class', 'user_token=' . $this->session->data['user_token'] . $url, true); + + if (isset($this->request->get['weight_class_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $weight_class_info = $this->model_localisation_weight_class->getWeightClass($this->request->get['weight_class_id']); + } + + $this->load->model('localisation/language'); + + $data['languages'] = $this->model_localisation_language->getLanguages(); + + if (isset($this->request->post['weight_class_description'])) { + $data['weight_class_description'] = $this->request->post['weight_class_description']; + } elseif (isset($this->request->get['weight_class_id'])) { + $data['weight_class_description'] = $this->model_localisation_weight_class->getWeightClassDescriptions($this->request->get['weight_class_id']); + } else { + $data['weight_class_description'] = array(); + } + + if (isset($this->request->post['value'])) { + $data['value'] = $this->request->post['value']; + } elseif (!empty($weight_class_info)) { + $data['value'] = $weight_class_info['value']; + } else { + $data['value'] = ''; + } + + $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('localisation/weight_class_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'localisation/weight_class')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + foreach ($this->request->post['weight_class_description'] as $language_id => $value) { + if ((utf8_strlen($value['title']) < 3) || (utf8_strlen($value['title']) > 32)) { + $this->error['title'][$language_id] = $this->language->get('error_title'); + } + + if (!$value['unit'] || (utf8_strlen($value['unit']) > 4)) { + $this->error['unit'][$language_id] = $this->language->get('error_unit'); + } + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'localisation/weight_class')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + $this->load->model('catalog/product'); + + foreach ($this->request->post['selected'] as $weight_class_id) { + if ($this->config->get('config_weight_class_id') == $weight_class_id) { + $this->error['warning'] = $this->language->get('error_default'); + } + + $product_total = $this->model_catalog_product->getTotalProductsByWeightClassId($weight_class_id); + + if ($product_total) { + $this->error['warning'] = sprintf($this->language->get('error_product'), $product_total); + } + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/localisation/zone.php b/public/admin/controller/localisation/zone.php new file mode 100644 index 0000000..df3c262 --- /dev/null +++ b/public/admin/controller/localisation/zone.php @@ -0,0 +1,393 @@ +<?php +class ControllerLocalisationZone extends Controller { + private $error = array(); + + public function index() { + $this->load->language('localisation/zone'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/zone'); + + $this->getList(); + } + + public function add() { + $this->load->language('localisation/zone'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/zone'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_zone->addZone($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('localisation/zone', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('localisation/zone'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/zone'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_localisation_zone->editZone($this->request->get['zone_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('localisation/zone', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('localisation/zone'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('localisation/zone'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $zone_id) { + $this->model_localisation_zone->deleteZone($zone_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('localisation/zone', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'c.name'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $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('localisation/zone', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('localisation/zone/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('localisation/zone/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['zones'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $zone_total = $this->model_localisation_zone->getTotalZones(); + + $results = $this->model_localisation_zone->getZones($filter_data); + + foreach ($results as $result) { + $data['zones'][] = array( + 'zone_id' => $result['zone_id'], + 'country' => $result['country'], + 'name' => $result['name'] . (($result['zone_id'] == $this->config->get('config_zone_id')) ? $this->language->get('text_default') : null), + 'code' => $result['code'], + 'edit' => $this->url->link('localisation/zone/edit', 'user_token=' . $this->session->data['user_token'] . '&zone_id=' . $result['zone_id'] . $url, true) + ); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } 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->request->post['selected'])) { + $data['selected'] = (array)$this->request->post['selected']; + } else { + $data['selected'] = array(); + } + + $url = ''; + + if ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_country'] = $this->url->link('localisation/zone', 'user_token=' . $this->session->data['user_token'] . '&sort=c.name' . $url, true); + $data['sort_name'] = $this->url->link('localisation/zone', 'user_token=' . $this->session->data['user_token'] . '&sort=z.name' . $url, true); + $data['sort_code'] = $this->url->link('localisation/zone', 'user_token=' . $this->session->data['user_token'] . '&sort=z.code' . $url, true); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + $pagination = new Pagination(); + $pagination->total = $zone_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('localisation/zone', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($zone_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($zone_total - $this->config->get('config_limit_admin'))) ? $zone_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $zone_total, ceil($zone_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + $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('localisation/zone_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['zone_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = ''; + } + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $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('localisation/zone', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['zone_id'])) { + $data['action'] = $this->url->link('localisation/zone/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('localisation/zone/edit', 'user_token=' . $this->session->data['user_token'] . '&zone_id=' . $this->request->get['zone_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('localisation/zone', 'user_token=' . $this->session->data['user_token'] . $url, true); + + if (isset($this->request->get['zone_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $zone_info = $this->model_localisation_zone->getZone($this->request->get['zone_id']); + } + + if (isset($this->request->post['status'])) { + $data['status'] = $this->request->post['status']; + } elseif (!empty($zone_info)) { + $data['status'] = $zone_info['status']; + } else { + $data['status'] = '1'; + } + + if (isset($this->request->post['name'])) { + $data['name'] = $this->request->post['name']; + } elseif (!empty($zone_info)) { + $data['name'] = $zone_info['name']; + } else { + $data['name'] = ''; + } + + if (isset($this->request->post['code'])) { + $data['code'] = $this->request->post['code']; + } elseif (!empty($zone_info)) { + $data['code'] = $zone_info['code']; + } else { + $data['code'] = ''; + } + + if (isset($this->request->post['country_id'])) { + $data['country_id'] = $this->request->post['country_id']; + } elseif (!empty($zone_info)) { + $data['country_id'] = $zone_info['country_id']; + } else { + $data['country_id'] = ''; + } + + $this->load->model('localisation/country'); + + $data['countries'] = $this->model_localisation_country->getCountries(); + + $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('localisation/zone_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'localisation/zone')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ((utf8_strlen($this->request->post['name']) < 1) || (utf8_strlen($this->request->post['name']) > 64)) { + $this->error['name'] = $this->language->get('error_name'); + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'localisation/zone')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + $this->load->model('setting/store'); + $this->load->model('customer/customer'); + $this->load->model('localisation/geo_zone'); + + foreach ($this->request->post['selected'] as $zone_id) { + if ($this->config->get('config_zone_id') == $zone_id) { + $this->error['warning'] = $this->language->get('error_default'); + } + + $store_total = $this->model_setting_store->getTotalStoresByZoneId($zone_id); + + if ($store_total) { + $this->error['warning'] = sprintf($this->language->get('error_store'), $store_total); + } + + $address_total = $this->model_customer_customer->getTotalAddressesByZoneId($zone_id); + + if ($address_total) { + $this->error['warning'] = sprintf($this->language->get('error_address'), $address_total); + } + + $zone_to_geo_zone_total = $this->model_localisation_geo_zone->getTotalZoneToGeoZoneByZoneId($zone_id); + + if ($zone_to_geo_zone_total) { + $this->error['warning'] = sprintf($this->language->get('error_zone_to_geo_zone'), $zone_to_geo_zone_total); + } + } + + return !$this->error; + } +}
\ No newline at end of file |