/admin/controller/setting/setting.php

https://github.com/fxiao/shopilex · PHP · 316 lines · 249 code · 67 blank · 0 comment · 58 complexity · 7a1793dc87eff387d7ecdd4fb758490f MD5 · raw file

  1. <?php
  2. class ControllerSettingSetting extends Controller {
  3. private $error = array();
  4. public function index() {
  5. $this->load_language('setting/setting');
  6. $this->document->setTitle($this->language->get('heading_title_store_setting'));
  7. $this->load->model('setting/setting');
  8. if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
  9. $this->model_setting_setting->updateSetting('config', $this->request->post);
  10. if ($this->config->get('config_currency_auto')) {
  11. $this->load->model('localisation/currency');
  12. $this->model_localisation_currency->updateCurrencies();
  13. }
  14. $this->session->data['success'] = $this->language->get('text_success');
  15. $this->redirect($this->url->link('setting/store', 'token=' . $this->session->data['token'], 'SSL'));
  16. }
  17. $this->data['token'] = $this->session->data['token'];
  18. $error_keys=array(
  19. 'warning' => 'error_warning',
  20. 'name' => 'error_name',
  21. 'owner' => 'error_owner',
  22. 'address' => 'error_address',
  23. 'email' => 'error_email',
  24. 'telephone' => 'error_telephone',
  25. 'title' => 'error_title',
  26. 'image_thumb' => 'error_image_thumb',
  27. 'image_popup' => 'error_image_popup',
  28. 'image_product' => 'error_image_product',
  29. 'image_category' => 'error_image_category',
  30. 'image_manufacturer' => 'error_image_manufacturer',
  31. 'image_additional' => 'error_image_additional',
  32. 'image_related' => 'error_image_related',
  33. 'image_compare' => 'error_image_compare',
  34. 'image_wishlist' => 'error_image_additional',
  35. 'image_cart' => 'error_image_cart',
  36. 'error_filename' => 'error_error_filename',
  37. 'catalog_limit' => 'error_catalog_limit',
  38. 'image_wishlist' =>'error_image_wishlist'
  39. );
  40. foreach ($error_keys as $key => $value) {
  41. if (isset($this->error[$key])) {
  42. $this->data[$value] = $this->error[$key];
  43. } else {
  44. $this->data[$value] = '';
  45. }
  46. }
  47. $this->data['breadcrumbs'] = array();
  48. $this->data['breadcrumbs'][] = array(
  49. 'text' => $this->language->get('text_home'),
  50. 'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
  51. 'separator' => false
  52. );
  53. $this->data['breadcrumbs'][] = array(
  54. 'text' => $this->language->get('heading_title'),
  55. 'href' => $this->url->link('setting/setting', 'token=' . $this->session->data['token'], 'SSL'),
  56. 'separator' => $this->language->get('text_breadcrumb_separator')
  57. );
  58. $this->data['breadcrumbs'][] = array(
  59. 'text' => $this->language->get('heading_title_store_setting'),
  60. 'href' => $this->url->link('setting/setting', 'token=' . $this->session->data['token'], 'SSL'),
  61. 'separator' => $this->language->get('text_breadcrumb_separator')
  62. );
  63. if (isset($this->session->data['success'])) {
  64. $this->data['success'] = $this->session->data['success'];
  65. unset($this->session->data['success']);
  66. } else {
  67. $this->data['success'] = '';
  68. }
  69. $this->data['action'] = $this->url->link('setting/setting', 'token=' . $this->session->data['token'], 'SSL');
  70. $this->data['cancel'] = $this->url->link('setting/store', 'token=' . $this->session->data['token'], 'SSL');
  71. $post_keys=array(
  72. 'config_name',
  73. 'config_owner',
  74. 'config_address',
  75. 'config_email',
  76. 'config_telephone',
  77. 'config_fax',
  78. 'config_title',
  79. 'config_meta_description',
  80. 'config_layout_id',
  81. 'config_zone_id',
  82. 'config_template',
  83. 'config_country_id',
  84. 'config_language',
  85. 'config_meta_keyword',
  86. 'config_currency',
  87. 'config_catalog_limit',
  88. 'config_tax',
  89. 'config_customer_group_id',
  90. 'config_customer_price',
  91. 'config_customer_approval',
  92. 'config_guest_checkout',
  93. 'config_account_id',
  94. 'config_checkout_id',
  95. 'config_stock_checkout',
  96. 'config_order_nopay_status_id',
  97. 'config_order_status_id',
  98. 'config_logo',
  99. 'config_stock_display',
  100. 'config_icon',
  101. 'config_image_thumb_width',
  102. 'config_image_thumb_height',
  103. 'config_image_popup_width',
  104. 'config_image_popup_height',
  105. 'config_image_product_width',
  106. 'config_image_product_height',
  107. 'config_image_category_width',
  108. 'config_image_category_height',
  109. 'config_image_manufacturer_width',
  110. 'config_image_manufacturer_height',
  111. 'config_image_additional_width',
  112. 'config_image_additional_height',
  113. 'config_image_related_width',
  114. 'config_image_related_height',
  115. 'config_image_compare_width',
  116. 'config_image_compare_height',
  117. 'config_image_wishlist_width',
  118. 'config_image_wishlist_height',
  119. 'config_image_cart_width',
  120. 'config_image_cart_height'
  121. );
  122. foreach ($post_keys as $value) {
  123. if (isset($this->request->post[$value])) {
  124. $this->data[$value] = $this->request->post[$value];
  125. } else {
  126. $this->data[$value] = $this->config->get($value);
  127. }
  128. }
  129. $this->load->model('design/layout');
  130. $this->data['layouts'] = $this->model_design_layout->getLayouts();
  131. $this->data['templates'] = array();
  132. $directories = glob(DIR_CATALOG . 'view/theme/*', GLOB_ONLYDIR);
  133. foreach ($directories as $directory) {
  134. $this->data['templates'][] = basename($directory);
  135. }
  136. $this->load->model('localisation/country');
  137. $this->data['countries'] = $this->model_localisation_country->getCountries();
  138. $this->load->model('localisation/language');
  139. $this->data['languages'] = $this->model_localisation_language->getLanguages();
  140. $this->load->model('localisation/currency');
  141. $this->data['currencies'] = $this->model_localisation_currency->getCurrencies();
  142. $this->load->model('sale/customer_group');
  143. $this->data['customer_groups'] = $this->model_sale_customer_group->getCustomerGroups();
  144. if (isset($this->request->post['config_commission'])) {
  145. $this->data['config_commission'] = $this->request->post['config_commission'];
  146. } elseif ($this->config->has('config_commission')) {
  147. $this->data['config_commission'] = $this->config->get('config_commission');
  148. } else {
  149. $this->data['config_commission'] = '5.00';
  150. }
  151. $this->load->model('catalog/information');
  152. $this->data['informations'] = $this->model_catalog_information->getInformations();
  153. $this->load->model('localisation/stock_status');
  154. $this->data['stock_statuses'] = $this->model_localisation_stock_status->getStockStatuses();
  155. $this->load->model('localisation/order_status');
  156. $this->data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
  157. $this->load->model('localisation/return_status');
  158. $this->data['return_statuses'] = $this->model_localisation_return_status->getReturnStatuses();
  159. $this->load->model('tool/image');
  160. if ($this->config->get('config_logo') && file_exists(DIR_IMAGE . $this->config->get('config_logo')) && is_file(DIR_IMAGE . $this->config->get('config_logo'))) {
  161. $this->data['logo'] = $this->model_tool_image->resize($this->config->get('config_logo'), 100, 100);
  162. } else {
  163. $this->data['logo'] = $this->model_tool_image->resize('no_image.jpg', 100, 100);
  164. }
  165. if ($this->config->get('config_icon') && file_exists(DIR_IMAGE . $this->config->get('config_icon')) && is_file(DIR_IMAGE . $this->config->get('config_icon'))) {
  166. $this->data['icon'] = $this->model_tool_image->resize($this->config->get('config_icon'), 100, 100);
  167. } else {
  168. $this->data['icon'] = $this->model_tool_image->resize('no_image.jpg', 100, 100);
  169. }
  170. $this->template = 'setting/setting.tpl';
  171. $this->id = 'content';
  172. $this->layout = 'layout/default';
  173. $this->render();
  174. }
  175. private function validate() {
  176. if (!$this->user->hasPermission('modify', 'setting/setting')) {
  177. $this->error['warning'] = $this->language->get('error_permission');
  178. }
  179. if (!$this->request->post['config_name']) {
  180. $this->error['name'] = $this->language->get('error_name');
  181. }
  182. if ((strlen(utf8_decode($this->request->post['config_owner'])) < 1) || (strlen(utf8_decode($this->request->post['config_owner'])) > 64)) {
  183. $this->error['owner'] = $this->language->get('error_owner');
  184. }
  185. if ((strlen(utf8_decode($this->request->post['config_address'])) < 1) || (strlen(utf8_decode($this->request->post['config_address'])) > 256)) {
  186. $this->error['address'] = $this->language->get('error_address');
  187. }
  188. if ((strlen(utf8_decode($this->request->post['config_email'])) > 96) || !preg_match('/^[^\@]+@.*\.[a-z]{2,6}$/i', $this->request->post['config_email'])) {
  189. $this->error['email'] = $this->language->get('error_email');
  190. }
  191. if ((strlen(utf8_decode($this->request->post['config_telephone'])) < 1) || (strlen(utf8_decode($this->request->post['config_telephone'])) > 32)) {
  192. $this->error['telephone'] = $this->language->get('error_telephone');
  193. }
  194. if (!$this->request->post['config_title']) {
  195. $this->error['title'] = $this->language->get('error_title');
  196. }
  197. if (!$this->request->post['config_image_thumb_width'] || !$this->request->post['config_image_thumb_height']) {
  198. $this->error['image_thumb'] = $this->language->get('error_image_thumb');
  199. }
  200. if (!$this->request->post['config_image_popup_width'] || !$this->request->post['config_image_popup_height']) {
  201. $this->error['image_popup'] = $this->language->get('error_image_popup');
  202. }
  203. if (!$this->request->post['config_image_product_width'] || !$this->request->post['config_image_product_height']) {
  204. $this->error['image_product'] = $this->language->get('error_image_product');
  205. }
  206. if (!$this->request->post['config_image_category_width'] || !$this->request->post['config_image_category_height']) {
  207. $this->error['image_category'] = $this->language->get('error_image_category');
  208. }
  209. if (!$this->request->post['config_image_manufacturer_width'] || !$this->request->post['config_image_manufacturer_height']) {
  210. $this->error['image_manufacturer'] = $this->language->get('error_image_manufacturer');
  211. }
  212. if (!$this->request->post['config_image_additional_width'] || !$this->request->post['config_image_additional_height']) {
  213. $this->error['image_additional'] = $this->language->get('error_image_additional');
  214. }
  215. if (!$this->request->post['config_image_related_width'] || !$this->request->post['config_image_related_height']) {
  216. $this->error['image_related'] = $this->language->get('error_image_related');
  217. }
  218. if (!$this->request->post['config_image_compare_width'] || !$this->request->post['config_image_compare_height']) {
  219. $this->error['image_compare'] = $this->language->get('error_image_compare');
  220. }
  221. if (!$this->request->post['config_image_wishlist_width'] || !$this->request->post['config_image_wishlist_height']) {
  222. $this->error['image_wishlist'] = $this->language->get('error_image_wishlist');
  223. }
  224. if (!$this->request->post['config_image_cart_width'] || !$this->request->post['config_image_cart_height']) {
  225. $this->error['image_cart'] = $this->language->get('error_image_cart');
  226. }
  227. if (!$this->request->post['config_catalog_limit']) {
  228. $this->error['catalog_limit'] = $this->language->get('error_limit');
  229. }
  230. if ($this->error && !isset($this->error['warning'])) {
  231. $this->error['warning'] = $this->language->get('error_warning');
  232. }
  233. if (!$this->error) {
  234. return true;
  235. } else {
  236. return false;
  237. }
  238. }
  239. public function template() {
  240. $template = basename($this->request->get['template']);
  241. if (file_exists(DIR_IMAGE . 'templates/' . $template . '.png')) {
  242. $image = HTTPS_IMAGE . 'templates/' . $template . '.png';
  243. } else {
  244. $image = HTTPS_IMAGE . 'no_image.jpg';
  245. }
  246. $this->response->setOutput('<img src="' . $image . '" alt="" title="" style="border: 1px solid #EEEEEE;" />');
  247. }
  248. }
  249. ?>