information.php (16898B)
1 <?php 2 class ControllerCatalogInformation extends Controller { 3 private $error = array(); 4 5 public function index() { 6 $this->load->language('catalog/information'); 7 8 $this->document->setTitle($this->language->get('heading_title')); 9 10 $this->load->model('catalog/information'); 11 12 $this->getList(); 13 } 14 15 public function add() { 16 $this->load->language('catalog/information'); 17 18 $this->document->setTitle($this->language->get('heading_title')); 19 20 $this->load->model('catalog/information'); 21 22 if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { 23 $this->model_catalog_information->addInformation($this->request->post); 24 25 $this->session->data['success'] = $this->language->get('text_success'); 26 27 $url = ''; 28 29 if (isset($this->request->get['sort'])) { 30 $url .= '&sort=' . $this->request->get['sort']; 31 } 32 33 if (isset($this->request->get['order'])) { 34 $url .= '&order=' . $this->request->get['order']; 35 } 36 37 if (isset($this->request->get['page'])) { 38 $url .= '&page=' . $this->request->get['page']; 39 } 40 41 $this->response->redirect($this->url->link('catalog/information', 'user_token=' . $this->session->data['user_token'] . $url, true)); 42 } 43 44 $this->getForm(); 45 } 46 47 public function edit() { 48 $this->load->language('catalog/information'); 49 50 $this->document->setTitle($this->language->get('heading_title')); 51 52 $this->load->model('catalog/information'); 53 54 if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { 55 $this->model_catalog_information->editInformation($this->request->get['information_id'], $this->request->post); 56 57 $this->session->data['success'] = $this->language->get('text_success'); 58 59 $url = ''; 60 61 if (isset($this->request->get['sort'])) { 62 $url .= '&sort=' . $this->request->get['sort']; 63 } 64 65 if (isset($this->request->get['order'])) { 66 $url .= '&order=' . $this->request->get['order']; 67 } 68 69 if (isset($this->request->get['page'])) { 70 $url .= '&page=' . $this->request->get['page']; 71 } 72 73 $this->response->redirect($this->url->link('catalog/information', 'user_token=' . $this->session->data['user_token'] . $url, true)); 74 } 75 76 $this->getForm(); 77 } 78 79 public function delete() { 80 $this->load->language('catalog/information'); 81 82 $this->document->setTitle($this->language->get('heading_title')); 83 84 $this->load->model('catalog/information'); 85 86 if (isset($this->request->post['selected']) && $this->validateDelete()) { 87 foreach ($this->request->post['selected'] as $information_id) { 88 $this->model_catalog_information->deleteInformation($information_id); 89 } 90 91 $this->session->data['success'] = $this->language->get('text_success'); 92 93 $url = ''; 94 95 if (isset($this->request->get['sort'])) { 96 $url .= '&sort=' . $this->request->get['sort']; 97 } 98 99 if (isset($this->request->get['order'])) { 100 $url .= '&order=' . $this->request->get['order']; 101 } 102 103 if (isset($this->request->get['page'])) { 104 $url .= '&page=' . $this->request->get['page']; 105 } 106 107 $this->response->redirect($this->url->link('catalog/information', 'user_token=' . $this->session->data['user_token'] . $url, true)); 108 } 109 110 $this->getList(); 111 } 112 113 protected function getList() { 114 if (isset($this->request->get['sort'])) { 115 $sort = $this->request->get['sort']; 116 } else { 117 $sort = 'id.title'; 118 } 119 120 if (isset($this->request->get['order'])) { 121 $order = $this->request->get['order']; 122 } else { 123 $order = 'ASC'; 124 } 125 126 if (isset($this->request->get['page'])) { 127 $page = $this->request->get['page']; 128 } else { 129 $page = 1; 130 } 131 132 $url = ''; 133 134 if (isset($this->request->get['sort'])) { 135 $url .= '&sort=' . $this->request->get['sort']; 136 } 137 138 if (isset($this->request->get['order'])) { 139 $url .= '&order=' . $this->request->get['order']; 140 } 141 142 if (isset($this->request->get['page'])) { 143 $url .= '&page=' . $this->request->get['page']; 144 } 145 146 $data['breadcrumbs'] = array(); 147 148 $data['breadcrumbs'][] = array( 149 'text' => $this->language->get('text_home'), 150 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) 151 ); 152 153 $data['breadcrumbs'][] = array( 154 'text' => $this->language->get('heading_title'), 155 'href' => $this->url->link('catalog/information', 'user_token=' . $this->session->data['user_token'] . $url, true) 156 ); 157 158 $data['add'] = $this->url->link('catalog/information/add', 'user_token=' . $this->session->data['user_token'] . $url, true); 159 $data['delete'] = $this->url->link('catalog/information/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); 160 161 $data['informations'] = array(); 162 163 $filter_data = array( 164 'sort' => $sort, 165 'order' => $order, 166 'start' => ($page - 1) * $this->config->get('config_limit_admin'), 167 'limit' => $this->config->get('config_limit_admin') 168 ); 169 170 $information_total = $this->model_catalog_information->getTotalInformations(); 171 172 $results = $this->model_catalog_information->getInformations($filter_data); 173 174 foreach ($results as $result) { 175 $data['informations'][] = array( 176 'information_id' => $result['information_id'], 177 'title' => $result['title'], 178 'sort_order' => $result['sort_order'], 179 'edit' => $this->url->link('catalog/information/edit', 'user_token=' . $this->session->data['user_token'] . '&information_id=' . $result['information_id'] . $url, true) 180 ); 181 } 182 183 if (isset($this->error['warning'])) { 184 $data['error_warning'] = $this->error['warning']; 185 } else { 186 $data['error_warning'] = ''; 187 } 188 189 if (isset($this->session->data['success'])) { 190 $data['success'] = $this->session->data['success']; 191 192 unset($this->session->data['success']); 193 } else { 194 $data['success'] = ''; 195 } 196 197 if (isset($this->request->post['selected'])) { 198 $data['selected'] = (array)$this->request->post['selected']; 199 } else { 200 $data['selected'] = array(); 201 } 202 203 $url = ''; 204 205 if ($order == 'ASC') { 206 $url .= '&order=DESC'; 207 } else { 208 $url .= '&order=ASC'; 209 } 210 211 if (isset($this->request->get['page'])) { 212 $url .= '&page=' . $this->request->get['page']; 213 } 214 215 $data['sort_title'] = $this->url->link('catalog/information', 'user_token=' . $this->session->data['user_token'] . '&sort=id.title' . $url, true); 216 $data['sort_sort_order'] = $this->url->link('catalog/information', 'user_token=' . $this->session->data['user_token'] . '&sort=i.sort_order' . $url, true); 217 218 $url = ''; 219 220 if (isset($this->request->get['sort'])) { 221 $url .= '&sort=' . $this->request->get['sort']; 222 } 223 224 if (isset($this->request->get['order'])) { 225 $url .= '&order=' . $this->request->get['order']; 226 } 227 228 $pagination = new Pagination(); 229 $pagination->total = $information_total; 230 $pagination->page = $page; 231 $pagination->limit = $this->config->get('config_limit_admin'); 232 $pagination->url = $this->url->link('catalog/information', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); 233 234 $data['pagination'] = $pagination->render(); 235 236 $data['results'] = sprintf($this->language->get('text_pagination'), ($information_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($information_total - $this->config->get('config_limit_admin'))) ? $information_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $information_total, ceil($information_total / $this->config->get('config_limit_admin'))); 237 238 $data['sort'] = $sort; 239 $data['order'] = $order; 240 241 $data['header'] = $this->load->controller('common/header'); 242 $data['column_left'] = $this->load->controller('common/column_left'); 243 $data['footer'] = $this->load->controller('common/footer'); 244 245 $this->response->setOutput($this->load->view('catalog/information_list', $data)); 246 } 247 248 protected function getForm() { 249 $data['text_form'] = !isset($this->request->get['information_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); 250 251 if (isset($this->error['warning'])) { 252 $data['error_warning'] = $this->error['warning']; 253 } else { 254 $data['error_warning'] = ''; 255 } 256 257 if (isset($this->error['title'])) { 258 $data['error_title'] = $this->error['title']; 259 } else { 260 $data['error_title'] = array(); 261 } 262 263 if (isset($this->error['description'])) { 264 $data['error_description'] = $this->error['description']; 265 } else { 266 $data['error_description'] = array(); 267 } 268 269 if (isset($this->error['meta_title'])) { 270 $data['error_meta_title'] = $this->error['meta_title']; 271 } else { 272 $data['error_meta_title'] = array(); 273 } 274 275 if (isset($this->error['keyword'])) { 276 $data['error_keyword'] = $this->error['keyword']; 277 } else { 278 $data['error_keyword'] = ''; 279 } 280 281 $url = ''; 282 283 if (isset($this->request->get['sort'])) { 284 $url .= '&sort=' . $this->request->get['sort']; 285 } 286 287 if (isset($this->request->get['order'])) { 288 $url .= '&order=' . $this->request->get['order']; 289 } 290 291 if (isset($this->request->get['page'])) { 292 $url .= '&page=' . $this->request->get['page']; 293 } 294 295 $data['breadcrumbs'] = array(); 296 297 $data['breadcrumbs'][] = array( 298 'text' => $this->language->get('text_home'), 299 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) 300 ); 301 302 $data['breadcrumbs'][] = array( 303 'text' => $this->language->get('heading_title'), 304 'href' => $this->url->link('catalog/information', 'user_token=' . $this->session->data['user_token'] . $url, true) 305 ); 306 307 if (!isset($this->request->get['information_id'])) { 308 $data['action'] = $this->url->link('catalog/information/add', 'user_token=' . $this->session->data['user_token'] . $url, true); 309 } else { 310 $data['action'] = $this->url->link('catalog/information/edit', 'user_token=' . $this->session->data['user_token'] . '&information_id=' . $this->request->get['information_id'] . $url, true); 311 } 312 313 $data['cancel'] = $this->url->link('catalog/information', 'user_token=' . $this->session->data['user_token'] . $url, true); 314 315 if (isset($this->request->get['information_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { 316 $information_info = $this->model_catalog_information->getInformation($this->request->get['information_id']); 317 } 318 319 $data['user_token'] = $this->session->data['user_token']; 320 321 $this->load->model('localisation/language'); 322 323 $data['languages'] = $this->model_localisation_language->getLanguages(); 324 325 if (isset($this->request->post['information_description'])) { 326 $data['information_description'] = $this->request->post['information_description']; 327 } elseif (isset($this->request->get['information_id'])) { 328 $data['information_description'] = $this->model_catalog_information->getInformationDescriptions($this->request->get['information_id']); 329 } else { 330 $data['information_description'] = array(); 331 } 332 333 $this->load->model('setting/store'); 334 335 $data['stores'] = array(); 336 337 $data['stores'][] = array( 338 'store_id' => 0, 339 'name' => $this->language->get('text_default') 340 ); 341 342 $stores = $this->model_setting_store->getStores(); 343 344 foreach ($stores as $store) { 345 $data['stores'][] = array( 346 'store_id' => $store['store_id'], 347 'name' => $store['name'] 348 ); 349 } 350 351 if (isset($this->request->post['information_store'])) { 352 $data['information_store'] = $this->request->post['information_store']; 353 } elseif (isset($this->request->get['information_id'])) { 354 $data['information_store'] = $this->model_catalog_information->getInformationStores($this->request->get['information_id']); 355 } else { 356 $data['information_store'] = array(0); 357 } 358 359 if (isset($this->request->post['bottom'])) { 360 $data['bottom'] = $this->request->post['bottom']; 361 } elseif (!empty($information_info)) { 362 $data['bottom'] = $information_info['bottom']; 363 } else { 364 $data['bottom'] = 0; 365 } 366 367 if (isset($this->request->post['status'])) { 368 $data['status'] = $this->request->post['status']; 369 } elseif (!empty($information_info)) { 370 $data['status'] = $information_info['status']; 371 } else { 372 $data['status'] = true; 373 } 374 375 if (isset($this->request->post['sort_order'])) { 376 $data['sort_order'] = $this->request->post['sort_order']; 377 } elseif (!empty($information_info)) { 378 $data['sort_order'] = $information_info['sort_order']; 379 } else { 380 $data['sort_order'] = ''; 381 } 382 383 if (isset($this->request->post['information_seo_url'])) { 384 $data['information_seo_url'] = $this->request->post['information_seo_url']; 385 } elseif (isset($this->request->get['information_id'])) { 386 $data['information_seo_url'] = $this->model_catalog_information->getInformationSeoUrls($this->request->get['information_id']); 387 } else { 388 $data['information_seo_url'] = array(); 389 } 390 391 if (isset($this->request->post['information_layout'])) { 392 $data['information_layout'] = $this->request->post['information_layout']; 393 } elseif (isset($this->request->get['information_id'])) { 394 $data['information_layout'] = $this->model_catalog_information->getInformationLayouts($this->request->get['information_id']); 395 } else { 396 $data['information_layout'] = array(); 397 } 398 399 $this->load->model('design/layout'); 400 401 $data['layouts'] = $this->model_design_layout->getLayouts(); 402 403 $data['header'] = $this->load->controller('common/header'); 404 $data['column_left'] = $this->load->controller('common/column_left'); 405 $data['footer'] = $this->load->controller('common/footer'); 406 407 $this->response->setOutput($this->load->view('catalog/information_form', $data)); 408 } 409 410 protected function validateForm() { 411 if (!$this->user->hasPermission('modify', 'catalog/information')) { 412 $this->error['warning'] = $this->language->get('error_permission'); 413 } 414 415 foreach ($this->request->post['information_description'] as $language_id => $value) { 416 if ((utf8_strlen($value['title']) < 1) || (utf8_strlen($value['title']) > 64)) { 417 $this->error['title'][$language_id] = $this->language->get('error_title'); 418 } 419 420 if (utf8_strlen($value['description']) < 3) { 421 $this->error['description'][$language_id] = $this->language->get('error_description'); 422 } 423 424 if ((utf8_strlen($value['meta_title']) < 1) || (utf8_strlen($value['meta_title']) > 255)) { 425 $this->error['meta_title'][$language_id] = $this->language->get('error_meta_title'); 426 } 427 } 428 429 if ($this->request->post['information_seo_url']) { 430 $this->load->model('design/seo_url'); 431 432 foreach ($this->request->post['information_seo_url'] as $store_id => $language) { 433 foreach ($language as $language_id => $keyword) { 434 if (!empty($keyword)) { 435 if (count(array_keys($language, $keyword)) > 1) { 436 $this->error['keyword'][$store_id][$language_id] = $this->language->get('error_unique'); 437 } 438 439 $seo_urls = $this->model_design_seo_url->getSeoUrlsByKeyword($keyword); 440 441 foreach ($seo_urls as $seo_url) { 442 if (($seo_url['store_id'] == $store_id) && (!isset($this->request->get['information_id']) || ($seo_url['query'] != 'information_id=' . $this->request->get['information_id']))) { 443 $this->error['keyword'][$store_id][$language_id] = $this->language->get('error_keyword'); 444 } 445 } 446 } 447 } 448 } 449 } 450 451 if ($this->error && !isset($this->error['warning'])) { 452 $this->error['warning'] = $this->language->get('error_warning'); 453 } 454 455 return !$this->error; 456 } 457 458 protected function validateDelete() { 459 if (!$this->user->hasPermission('modify', 'catalog/information')) { 460 $this->error['warning'] = $this->language->get('error_permission'); 461 } 462 463 $this->load->model('setting/store'); 464 465 foreach ($this->request->post['selected'] as $information_id) { 466 if ($this->config->get('config_account_id') == $information_id) { 467 $this->error['warning'] = $this->language->get('error_account'); 468 } 469 470 if ($this->config->get('config_checkout_id') == $information_id) { 471 $this->error['warning'] = $this->language->get('error_checkout'); 472 } 473 474 if ($this->config->get('config_affiliate_id') == $information_id) { 475 $this->error['warning'] = $this->language->get('error_affiliate'); 476 } 477 478 if ($this->config->get('config_return_id') == $information_id) { 479 $this->error['warning'] = $this->language->get('error_return'); 480 } 481 482 $store_total = $this->model_setting_store->getTotalStoresByInformationId($information_id); 483 484 if ($store_total) { 485 $this->error['warning'] = sprintf($this->language->get('error_store'), $store_total); 486 } 487 } 488 489 return !$this->error; 490 } 491 }