oct_slideshow_plus.php 22.7 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518
<?php
/**
 * @copyright    OCTemplates
 * @support      https://octemplates.net/
 * @license      LICENSE.txt
 */

class ControllerOCTemplatesDesignOctSlideshowPlus extends Controller {
    private $error = [];

    public function index() {
        $this->load->language('octemplates/design/oct_slideshow_plus');

        $this->document->setTitle($this->language->get('heading_title'));

        $this->load->model('octemplates/design/oct_slideshow_plus');

        $this->getList();
    }

    public function add() {
        $this->load->language('octemplates/design/oct_slideshow_plus');

        $this->document->setTitle($this->language->get('heading_title'));

        $this->load->model('octemplates/design/oct_slideshow_plus');

        if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
            $this->model_octemplates_design_oct_slideshow_plus->addSlideshow($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('octemplates/design/oct_slideshow_plus', 'user_token=' . $this->session->data['user_token'] . $url, true));
        }

        $this->getForm();
    }

    public function edit() {
        $this->load->language('octemplates/design/oct_slideshow_plus');

        $this->document->setTitle($this->language->get('heading_title'));

        $this->load->model('octemplates/design/oct_slideshow_plus');

        if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
            $this->model_octemplates_design_oct_slideshow_plus->editSlideshow($this->request->get['slideshow_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('octemplates/design/oct_slideshow_plus', 'user_token=' . $this->session->data['user_token'] . $url, true));
        }

        $this->getForm();
    }

    public function delete() {
        $this->load->language('octemplates/design/oct_slideshow_plus');

        $this->document->setTitle($this->language->get('heading_title'));

        $this->load->model('octemplates/design/oct_slideshow_plus');

        if (isset($this->request->post['selected']) && $this->validateDelete()) {
            foreach ($this->request->post['selected'] as $slideshow_id) {
                $this->model_octemplates_design_oct_slideshow_plus->deleteSlideshow($slideshow_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('octemplates/design/oct_slideshow_plus', 'user_token=' . $this->session->data['user_token'] . $url, true));
        }

        $this->getList();
    }

    protected function getList() {
	    $this->document->addScript('view/javascript/octemplates/bootstrap-notify/bootstrap-notify.min.js');
		$this->document->addScript('view/javascript/octemplates/oct_main.js');
		$this->document->addStyle('view/stylesheet/oct_deals.css');

        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 = (int)$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']   = [];

        $data['breadcrumbs'][] = [
            'text' => $this->language->get('text_home'),
            'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true)
        ];

        $data['breadcrumbs'][] = [
            'text' => $this->language->get('heading_title'),
            'href' => $this->url->link('octemplates/design/oct_slideshow_plus', 'user_token=' . $this->session->data['user_token'] . $url, true)
        ];

        $data['add']                 = $this->url->link('octemplates/design/oct_slideshow_plus/add', 'user_token=' . $this->session->data['user_token'] . $url, true);
        $data['delete']              = $this->url->link('octemplates/design/oct_slideshow_plus/delete', 'user_token=' . $this->session->data['user_token'] . $url, true);
        $data['oct_slideshow_pluss'] = [];

        $filter_data = [
            'sort' => $sort,
            'order' => $order,
            'start' => ($page - 1) * $this->config->get('config_limit_admin'),
            'limit' => $this->config->get('config_limit_admin')
        ];

        $oct_slideshow_plus_total = $this->model_octemplates_design_oct_slideshow_plus->getTotalSlideshows();
        $results                  = $this->model_octemplates_design_oct_slideshow_plus->getSlideshows($filter_data);

        foreach ($results as $result) {
            $data['oct_slideshow_pluss'][] = [
                'slideshow_id' => $result['slideshow_id'],
                'name' => $result['name'],
                'status' => ($result['status'] ? $this->language->get('text_enabled') : $this->language->get('text_disabled')),
                'edit' => $this->url->link('octemplates/design/oct_slideshow_plus/edit', 'user_token=' . $this->session->data['user_token'] . '&slideshow_id=' . $result['slideshow_id'] . $url, true)
            ];
        }

        $data['heading_title']   = $this->language->get('heading_title');
        $data['text_list']       = $this->language->get('text_list');
        $data['text_no_results'] = $this->language->get('text_no_results');
        $data['text_confirm']    = $this->language->get('text_confirm');
        $data['column_name']     = $this->language->get('column_name');
        $data['column_status']   = $this->language->get('column_status');
        $data['column_action']   = $this->language->get('column_action');
        $data['button_add']      = $this->language->get('button_add');
        $data['button_edit']     = $this->language->get('button_edit');
        $data['button_delete']   = $this->language->get('button_delete');

        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'] = [];
        }

        $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('octemplates/design/oct_slideshow_plus', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url, true);
        $data['sort_status'] = $this->url->link('octemplates/design/oct_slideshow_plus', 'user_token=' . $this->session->data['user_token'] . '&sort=status' . $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   = $oct_slideshow_plus_total;
        $pagination->page    = $page;
        $pagination->limit   = $this->config->get('config_limit_admin');
        $pagination->url     = $this->url->link('octemplates/design/oct_slideshow_plus', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}
		', true);

        $data['pagination']  = $pagination->render();
        $data['results']     = sprintf($this->language->get('text_pagination'), ($oct_slideshow_plus_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($oct_slideshow_plus_total - $this->config->get('config_limit_admin'))) ? $oct_slideshow_plus_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $oct_slideshow_plus_total, ceil($oct_slideshow_plus_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('octemplates/design/oct_slideshow_plus_list', $data));
    }

    protected function getForm() {
	    $this->document->addScript('view/javascript/octemplates/bootstrap-notify/bootstrap-notify.min.js');
  		$this->document->addScript('view/javascript/octemplates/oct_main.js');
  		$this->document->addStyle('view/stylesheet/oct_deals.css');

  		//Add Spectrum
  		$this->document->addStyle('view/javascript/octemplates/spectrum/spectrum.css');
  		$this->document->addScript('view/javascript/octemplates/spectrum/spectrum.js');

        $data['text_form'] = !isset($this->request->get['slideshow_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['empty_image'])) {
            $data['error_empty_image'] = $this->error['empty_image'];
        } else {
            $data['error_empty_image'] = '';
        }

        if (isset($this->error['empty_mobile_image'])) {
            $data['error_empty_mobile_image'] = $this->error['empty_mobile_image'];
        } else {
            $data['error_empty_mobile_image'] = '';
        }

        if (isset($this->error['oct_slideshow_plus_image'])) {
            $data['error_oct_slideshow_plus_image'] = $this->error['oct_slideshow_plus_image'];
        } else {
            $data['error_oct_slideshow_plus_image'] = [];
        }

        $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']   = [];

        $data['breadcrumbs'][] = [
            'text' => $this->language->get('text_home'),
            'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true)
        ];

        $data['breadcrumbs'][] = [
            'text' => $this->language->get('heading_title'),
            'href' => $this->url->link('octemplates/design/oct_slideshow_plus', 'user_token=' . $this->session->data['user_token'] . $url, true)
        ];

        if (!isset($this->request->get['slideshow_id'])) {
            $data['action'] = $this->url->link('octemplates/design/oct_slideshow_plus/add', 'user_token=' . $this->session->data['user_token'] . $url, true);
        } else {
            $data['action'] = $this->url->link('octemplates/design/oct_slideshow_plus/edit', 'user_token=' . $this->session->data['user_token'] . '&slideshow_id=' . $this->request->get['slideshow_id'] . $url, true);
        }

        $data['cancel'] = $this->url->link('octemplates/design/oct_slideshow_plus', 'user_token=' . $this->session->data['user_token'] . $url, true);

        if (isset($this->request->get['slideshow_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) {
            $oct_slideshow_plus_info = $this->model_octemplates_design_oct_slideshow_plus->getSlideshow($this->request->get['slideshow_id']);
        }

        $data['user_token'] = $this->session->data['user_token'];

        if (isset($this->request->post['name'])) {
            $data['name'] = $this->request->post['name'];
        } else if (!empty($oct_slideshow_plus_info)) {
            $data['name'] = $oct_slideshow_plus_info['name'];
        } else {
            $data['name'] = '';
        }

        if (isset($this->request->post['status_additional_banners'])) {
            $data['status_additional_banners'] = $this->request->post['status_additional_banners'];
        } else if (!empty($oct_slideshow_plus_info)) {
            $data['status_additional_banners'] = $oct_slideshow_plus_info['status_additional_banners'];
        } else {
            $data['status_additional_banners'] = 1;
        }

        if (isset($this->request->post['full'])) {
            $data['full'] = $this->request->post['full'];
        } else if (!empty($oct_slideshow_plus_info) && isset($oct_slideshow_plus_info['full'])) {
            $data['full'] = $oct_slideshow_plus_info['full'];
        } else {
            $data['full'] = 0;
        }

        if (isset($this->request->post['status'])) {
            $data['status'] = $this->request->post['status'];
        } else if (!empty($oct_slideshow_plus_info)) {
            $data['status'] = $oct_slideshow_plus_info['status'];
        } else {
            $data['status'] = true;
        }

        $this->load->model('localisation/language');

        $data['languages'] = $this->model_localisation_language->getLanguages();

        $this->load->model('tool/image');

        if (isset($this->request->post['oct_slideshow_plus_image']) && isset($this->request->post['oct_discount_products'])) {
            $oct_slideshow_plus_images = $this->request->post['oct_slideshow_plus_image'];
			$products = $this->request->post['oct_discount_products'];
		} else if (isset($this->request->get['slideshow_id'])) {
            $oct_slideshow_plus_images = $this->model_octemplates_design_oct_slideshow_plus->getSlideshowImages($this->request->get['slideshow_id']);
            $products = $this->model_octemplates_design_oct_slideshow_plus->getDiscountProduct($this->request->get['slideshow_id']);
        } else {
            $oct_slideshow_plus_images = [];
            $products = [];
        }

        $this->load->model('catalog/product');

        $data['products'] = [];

        if ($products) {
            foreach ($products as $product_id) {
                $product_info = $this->model_catalog_product->getProduct($product_id);

                if ($product_info) {
                    $data['products'][] = [
                        'product_id' => $product_info['product_id'],
                        'name' => $product_info['name']
                    ];
                }
            }
        }

        $data['oct_slideshow_plus_images'] = [];

		$data['oct_default_colors'] = [
			'background_color' => 'rgb(34, 164, 132)',
			'title_color' => 'rgb(255, 255, 255)',
			'text_color' => 'rgb(255, 255, 255)',
			'button_color' => 'rgb(255, 255, 255)',
			'button_background' => 'rgb(255, 255, 255)',
			'button_color_hover' => 'rgb(48, 51, 76)',
			'button_background_hover' => 'rgb(226, 244, 250)'
		];

        foreach ($oct_slideshow_plus_images as $key=>$oct_slideshow_plus_image) {
            $key++;

            $image = $thumb = $mobile_image = $mobile_thumb = [];

            foreach ($oct_slideshow_plus_image['image'] as $lang_id => $img) {
                if (is_file(DIR_IMAGE . $img)) {
                    $image[$lang_id] = $img;
                    $thumb[$lang_id] = $this->model_tool_image->resize($img, 100, 100);
                } else {
                    $image[$lang_id] = '';
                    $thumb[$lang_id] = $this->model_tool_image->resize('no_image.png', 100, 100);
                }
            }

            foreach ($oct_slideshow_plus_image['mobile_image'] as $lang_id => $img_mobile) {
                if (is_file(DIR_IMAGE . $img_mobile)) {
                    $mobile_image[$lang_id] = $img_mobile;
                    $mobile_thumb[$lang_id] = $this->model_tool_image->resize($img_mobile, 100, 100);
                } else {
                    $mobile_image[$lang_id] = '';
                    $mobile_thumb[$lang_id] = $this->model_tool_image->resize('no_image.png', 100, 100);
                }
            }

            $data['oct_slideshow_plus_images'][] = [
                'oct_slideshow_plus_image_description' => $oct_slideshow_plus_image['oct_slideshow_plus_image_description'],
                'title' => (isset($oct_slideshow_plus_image['oct_slideshow_plus_image_description'][(int)$this->config->get('config_language_id')]['title']) && !empty($oct_slideshow_plus_image['oct_slideshow_plus_image_description'][(int)$this->config->get('config_language_id')]['title'])) ? $oct_slideshow_plus_image['oct_slideshow_plus_image_description'][(int)$this->config->get('config_language_id')]['title'] : $this->language->get('text_banner_title') . $key,
                'image' => $image,
                'thumb' => $thumb,
                'mobile_image' => $mobile_image,
                'mobile_thumb' => $mobile_thumb,
                'background_color' => $oct_slideshow_plus_image['background_color'] ? $oct_slideshow_plus_image['background_color'] : $data['oct_default_colors']['background_color'],
                'title_color' => $oct_slideshow_plus_image['title_color'] ? $oct_slideshow_plus_image['title_color'] : $data['oct_default_colors']['title_color'],
                'text_color' => $oct_slideshow_plus_image['text_color'] ? $oct_slideshow_plus_image['text_color'] : $data['oct_default_colors']['text_color'],
                'button_color' => $oct_slideshow_plus_image['button_color'] ? $oct_slideshow_plus_image['button_color'] : $data['oct_default_colors']['button_color'],
                'button_background' => $oct_slideshow_plus_image['button_background'] ? $oct_slideshow_plus_image['button_background'] : $data['oct_default_colors']['button_background'],
                'button_color_hover' => $oct_slideshow_plus_image['button_color_hover'] ? $oct_slideshow_plus_image['button_color_hover'] : $data['oct_default_colors']['button_color_hover'],
                'button_background_hover' => $oct_slideshow_plus_image['button_background_hover'] ? $oct_slideshow_plus_image['button_background_hover'] : $data['oct_default_colors']['button_background_hover'],
                'sort_order' => $oct_slideshow_plus_image['sort_order']
            ];
        }

        $data['placeholder'] = $this->model_tool_image->resize('no_image.png', 100, 100);

        $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('octemplates/design/oct_slideshow_plus_form', $data));
    }

    protected function validateForm() {
        if (!$this->user->hasPermission('modify', 'octemplates/design/oct_slideshow_plus')) {
            $this->error['warning'] = $this->language->get('error_permission');
        }

        if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 64)) {
            $this->error['name'] = $this->language->get('error_name');
        }

        if (isset($this->request->post['oct_slideshow_plus_image'])) {
            foreach ($this->request->post['oct_slideshow_plus_image'] as $slideshow_image_id => $oct_slideshow_plus_image) {
                foreach ($oct_slideshow_plus_image['oct_slideshow_plus_image_description'] as $language_id => $oct_slideshow_plus_image_description) {
                    if (((utf8_strlen($oct_slideshow_plus_image_description['title']) < 2) || (utf8_strlen($oct_slideshow_plus_image_description['title']) > 64)) && !isset($this->request->post['full'])) {
                        $this->error['oct_slideshow_plus_image'][$slideshow_image_id][$language_id] = $this->language->get('error_title');
                    }
                }
            }
        }

        if (isset($this->request->post['full']) && $this->request->post['full'] == "on") {
            foreach ($this->request->post['oct_slideshow_plus_image'] as $slide) {
                foreach ($slide['image'] as $index => $image) {
                    if (empty($image)) {
                        $this->error['empty_image'] = $this->language->get('error_image');
                    }
                }
                foreach ($slide['mobile_image'] as $index => $mobile_image) {
                    if (empty($mobile_image)) {
                        $this->error['empty_mobile_image'] = $this->language->get('error_mobile_image');
                    }
                }
            }
        }

        return !$this->error;
    }

    protected function validateDelete() {
        if (!$this->user->hasPermission('modify', 'octemplates/design/oct_slideshow_plus')) {
            $this->error['warning'] = $this->language->get('error_permission');
        }

        return !$this->error;
    }
}