bootstrap = true; $this->table = 'cookiesplus_finality'; $this->className = 'CookiesPlusFinality'; $this->tabClassName = 'AdminCookiesPlusFinalities'; $this->lang = true; $this->addRowAction('edit'); $this->addRowAction('delete'); parent::__construct(); $this->bulk_actions = [ 'delete' => [ 'text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?'), 'icon' => 'icon-trash', ], ]; $this->context = Context::getContext(); $this->default_form_language = $this->context->language->id; $this->position_identifier = 'position'; $this->fields_list = [ 'id_cookiesplus_finality' => [ 'title' => $this->l('ID'), 'search' => false, ], 'active' => [ 'title' => $this->l('Enabled'), 'active' => 'active', 'type' => 'bool', 'search' => false, ], 'name' => [ 'title' => $this->l('Cookie finality name'), 'filter_key' => 'b!name', 'search' => false, ], 'description' => [ 'title' => $this->l('Cookie finality description'), 'callback' => 'getFinalityDescriptionCallback', 'callback_object' => 'CookiesPlusFinality', 'search' => false, ], 'technical' => [ 'title' => $this->l('Technical'), 'align' => 'text-center', 'active' => 'technical', 'type' => 'bool', 'search' => false, ], 'position' => [ 'title' => $this->l('Position'), 'align' => 'center', 'class' => 'fixed-width-sm', 'position' => 'position', 'search' => false, ], ]; if (Shop::isFeatureActive() && (Shop::getContext() == Shop::CONTEXT_ALL || Shop::getContext() == Shop::CONTEXT_GROUP)) { $this->isShopSelected = false; } $this->shopLinkType = 'shop'; } public function setMedia($isNewTheme = false) { parent::setMedia($isNewTheme); $this->addJqueryPlugin(['typewatch', 'fancybox', 'autocomplete']); $this->addJqueryUI(['ui.datepicker', 'ui.button', 'ui.sortable', 'ui.droppable']); // Tabs /*if (version_compare(_PS_VERSION_, '1.6', '<')) { $this->addCSS(_MODULE_DIR_.$this->module->name.'/views/css/tabs.css'); } $this->addJS(_MODULE_DIR_ . $this->module->name . '/views/js/tabs.js'); */ $this->addCSS(_MODULE_DIR_ . $this->module->name . '/views/css/cookiesplus-back.css'); if ($this->display) { $this->addJS(_MODULE_DIR_ . $this->module->name . '/views/js/cookiesplus-back.js'); $this->addCSS(_MODULE_DIR_ . $this->module->name . '/lib/CodeMirror/lib/codemirror.css'); $this->addCSS(_MODULE_DIR_ . $this->module->name . '/lib/CodeMirror/theme/monokai.css'); $this->addJS(_MODULE_DIR_ . $this->module->name . '/lib/CodeMirror/lib/codemirror.js'); $this->addJS(_MODULE_DIR_ . $this->module->name . '/lib/CodeMirror/addon/display/autorefresh.js'); $this->addJS(_MODULE_DIR_ . $this->module->name . '/lib/CodeMirror/mode/css/css.js'); $this->addJS(_MODULE_DIR_ . $this->module->name . '/lib/CodeMirror/mode/javascript/javascript.js'); } } public function initContent() { if (!$this->isShopSelected && !$this->display) { $this->errors[] = $this->l('You have to select a shop.'); parent::initContent(); return; } if (version_compare($this->module->version, $this->module->getDatabaseVersion(), '>')) { return $this->errors[] = $this->l('Upgrade available'); } if ($this->isShopSelected && ( (version_compare(_PS_VERSION_, '1.5.0.13', '<') && !Module::isInstalled($this->module->name)) || (version_compare(_PS_VERSION_, '1.5.0.13', '>=') && !Module::isEnabled($this->module->name)) ) ) { $this->warnings[] = $this->l('Module is not enabled in this shop.'); } if ($warnings = $this->module->getWarnings(false)) { $this->warnings[] = $warnings; } if (Tools::isSubmit('submitCookiesPlusRevokeCookies')) { Configuration::updateValue('C_P_REVOKE_CONSENT', date('Y-m-d H:i:s', time())); $this->confirmations[] = $this->l('Revoke consent updated'); } parent::initContent(); $this->content .= $this->context->smarty->fetch($this->module->getLocalPath() . 'views/templates/admin/disclaimer.tpl'); if (!$this->display) { if (version_compare(_PS_VERSION_, '1.6', '>=')) { $default_iso_code = 'en'; $local_path = $this->module->getLocalPath(); $readme = null; if (file_exists($local_path . '/readme_' . $this->context->language->iso_code . '.pdf')) { $readme = 'readme_' . $this->context->language->iso_code . '.pdf'; } elseif (file_exists($local_path . '/readme_' . $default_iso_code . '.pdf')) { $readme = 'readme_' . $default_iso_code . '.pdf'; } $this->context->smarty->assign([ 'support_id' => $this->module->addons_id_product, 'readme' => $readme, 'this_path' => $this->module->getPathUri(), ]); if (file_exists($local_path . '/views/templates/admin/company/information_' . $this->context->language->iso_code . '.tpl')) { $this->content .= $this->context->smarty->fetch($local_path . '/views/templates/admin/company/information_' . $this->context->language->iso_code . '.tpl'); } elseif (file_exists($local_path . '/views/templates/admin/company/information_' . $default_iso_code . '.tpl')) { $this->content .= $this->context->smarty->fetch($local_path . '/views/templates/admin/company/information_' . $default_iso_code . '.tpl'); } } $this->context->smarty->assign([ 'content' => $this->content, ]); } } public function initProcess() { parent::initProcess(); if (Tools::isSubmit('activecookiesplus_finality') && $this->id_object) { $this->toggleProperty('active', $this->id_object); if (!$this->errors) { // Remove toggle from URL Tools::redirectAdmin(Context::getContext()->link->getAdminLink($this->tabClassName)); } } if (Tools::isSubmit('technicalcookiesplus_finality') && $this->id_object) { $this->toggleProperty('technical', $this->id_object); if (!$this->errors) { // Remove toggle from URL Tools::redirectAdmin(Context::getContext()->link->getAdminLink($this->tabClassName)); } } } public function toggleProperty($property, $id) { if (version_compare(_PS_VERSION_, '1.7', '<')) { if ($this->tabAccess['edit'] !== '1') { $this->errors[] = $this->l('You do not have permission to edit this.'); return; } } else { if (!$this->access('edit')) { $this->errors[] = $this->l('You do not have permission to edit this.'); return; } } $object = new $this->className($id); if (!Validate::isLoadedObject($object)) { $this->errors[] = $this->l('An error occurred while updating an object.'); } $object->$property = !$object->$property; if (!$object->save()) { $this->errors[] = $this->l('An error occurred while updating an object.'); } } public function initToolbar() { parent::initToolbar(); if (!$this->isShopSelected) { unset($this->toolbar_btn['new']); } } public function initPageHeaderToolbar() { parent::initPageHeaderToolbar(); if (empty($this->display)) { $this->page_header_toolbar_btn['desc-module-new'] = [ 'href' => 'index.php?controller=' . $this->tabClassName . '&add' . $this->table . '&token=' . Tools::getAdminTokenLite($this->tabClassName), 'desc' => $this->l('New'), 'icon' => 'process-icon-new', ]; } if (!$this->isShopSelected) { unset($this->page_header_toolbar_btn['desc-module-new']); } $this->context->smarty->clearAssign('help_link', ''); } public function initModal() { parent::initModal(); $languages = Language::getLanguages(false); $translateLinks = []; if (version_compare(_PS_VERSION_, '1.7.2.1', '>=')) { $module = Module::getInstanceByName($this->module->name); $isNewTranslateSystem = $module->isUsingNewTranslationSystem(); $link = Context::getContext()->link; foreach ($languages as $lang) { if ($isNewTranslateSystem) { $translateLinks[$lang['iso_code']] = $link->getAdminLink('AdminTranslationSf', true, [ 'lang' => $lang['iso_code'], 'type' => 'modules', 'selected' => $module->name, 'locale' => $lang['locale'], ]); } else { $translateLinks[$lang['iso_code']] = $link->getAdminLink('AdminTranslations', true, [], [ 'type' => 'modules', 'module' => $module->name, 'lang' => $lang['iso_code'], ]); } } } $this->context->smarty->assign([ 'trad_link' => 'index.php?tab=AdminTranslations&token=' . Tools::getAdminTokenLite('AdminTranslations') . '&type=modules&module=' . $this->module->name . '&lang=', 'module_languages' => $languages, 'module_name' => $this->module->name, 'translateLinks' => $translateLinks, ]); $modal_content = $this->context->smarty->fetch('controllers/modules/modal_translation.tpl'); $this->modals[] = [ 'modal_id' => 'moduleTradLangSelect', 'modal_class' => 'modal-sm', 'modal_title' => $this->l('Translate this module'), 'modal_content' => $modal_content, ]; } public function renderList() { // Redirect if no object created /*if ($this->isShopSelected && !LoyaltyEditPointsAssignment::getNbObjects()) { $this->redirect_after = 'index.php?controller='.$this->tabClassName.'&add'.$this->table.'&token='.Tools::getAdminTokenLite($this->tabClassName); $this->redirect(); }*/ $this->content .= $this->context->smarty->fetch($this->module->getLocalPath() . 'views/templates/admin/cookie-finalities.tpl'); $this->context->smarty->assign([ 'revokeConsentDate' => Tools::displayDate(date('Y-m-d H:i:s', strtotime(Configuration::get('C_P_REVOKE_CONSENT'))), null, true), ]); $this->content .= $this->context->smarty->fetch($this->module->getLocalPath() . 'views/templates/admin/revoke-consent.tpl'); return parent::renderList(); } public function renderForm() { if (!$this->isShopSelected && $this->display === 'add') { $this->errors[] = $this->l('You have to select a shop.'); return parent::renderForm(); } $this->context->smarty->assign([ 'revokeConsentDate' => Tools::displayDate(date('Y-m-d H:i:s', strtotime(Configuration::get('C_P_REVOKE_CONSENT'))), null, true), ]); $this->content .= $this->context->smarty->fetch($this->module->getLocalPath() . 'views/templates/admin/revoke-consent.tpl'); $object = $this->loadObject(true); $this->multiple_fieldsets = true; $this->default_form_language = $this->context->language->id; // Modules blocked $modules = $this->module->getModuleList(); $selectedModules = (array) json_decode($object->modules); foreach ($modules as &$module) { if (in_array($module['id_module'], $selectedModules)) { $module['checked'] = true; } else { $module['checked'] = false; } $module['sortDisplayName'] = strtolower($module['displayName']); } unset($module); array_multisort( array_column( $modules, 'checked' ), SORT_DESC, array_column( $modules, 'sortDisplayName' ), SORT_ASC, $modules ); $this->context->smarty->assign([ 'allModules' => $modules, 'fieldName' => 'modules', ]); $fieldsFormIndex = 0; $this->fields_form[$fieldsFormIndex]['form'] = [ 'legend' => [ 'title' => $this->l('Cookie finality'), 'icon' => 'icon-cogs', ], 'input' => [ [ 'type' => 'hidden', 'name' => 'id_cookiesplus_finality', ], [ 'type' => 'hidden', 'name' => 'position', ], [ 'type' => (version_compare(_PS_VERSION_, '1.6', '>=')) ? 'switch' : 'radio', 'label' => $this->l('Enabled'), 'name' => 'active', 'class' => 't', 'col' => 8, 'is_bool' => true, 'values' => [ [ 'id' => 'active_on', 'value' => 1, 'label' => $this->l('Yes'), ], [ 'id' => 'active_off', 'value' => 0, 'label' => $this->l('No'), ], ], ], [ 'type' => (version_compare(_PS_VERSION_, '1.6', '>=')) ? 'switch' : 'radio', 'label' => $this->l('This is a Technical finality'), 'name' => 'technical', 'class' => 't', 'col' => 8, 'is_bool' => true, 'values' => [ [ 'id' => 'technical_on', 'value' => 1, 'label' => $this->l('Yes'), ], [ 'id' => 'technical_off', 'value' => 0, 'label' => $this->l('No'), ], ], 'desc' => $this->l('Technical cookies can not be disabled. They are installed automatically.'), ], [ 'type' => 'text', 'label' => $this->l('Cookie finality name'), 'name' => 'name', 'required' => true, 'lang' => true, ], [ 'type' => 'textarea', 'label' => $this->l('Cookie finality description'), 'name' => 'description', 'required' => true, 'lang' => true, 'autoload_rte' => true, 'cols' => 60, 'rows' => 30, ], [ 'type' => 'html', 'col' => 8, 'label' => $this->l('Cookies from this finality'), 'name' => $this->context->smarty->fetch($this->module->getLocalPath() . 'views/templates/admin/cookies-list.tpl') . $this->module->getCookiesPlusCookiesList(), ], [ 'type' => 'html', 'name' => 'html', 'html_content' => (Module::isInstalled('litespeedcache') || Module::isInstalled('stadvancedcache') || Module::isInstalled('jprestaspeedpack') || Module::isInstalled('pagecache')) ? '