/**
  *
  */
 public function postProcess()
 {
     if (Tools::getValue('exportProfile')) {
         if ($this->profile->id) {
             $export = array();
             $export['layout'] = $this->profile->layout;
             $export['widget'] = $this->profile->widget;
             $export_file = fopen(_PAGEBUILDER_EXPORT_DIR_ . $this->profile->name . '.txt', 'w') or die('Unable to open file!');
             fwrite($export_file, serialize($export));
             fclose($export_file);
             $this->context->smarty->assign(array('export_msg' => $this->l('Successful export: ') . _PAGEBUILDER_EXPORT_DIR_ . $this->profile->name . '.txt'));
         }
     }
     /* import data */
     if (Tools::isSubmit('submitpspagebuilderImport') && isset($_FILES['import_file'])) {
         $tmp = $_FILES['import_file']['tmp_name'];
         $content = trim(Tools::file_get_contents($tmp));
         if ($content) {
             $data = unserialize($content);
             if (isset($data['layout']) && isset($data['widget'])) {
                 $profile = new PsPagebuilderprofile();
                 $profile->layout = $data['layout'];
                 $name = trim(Tools::getValue('import_name'));
                 $profile->name = $name ? $name : 'profile-' . time();
                 $profile->widget = $data['widget'];
                 if ($profile->id <= 0) {
                     if (!$profile->add()) {
                         $this->displayError($this->l('The slide could not be added.'));
                     }
                 } else {
                     $this->errors[] = Tools::displayError('You do not have permission to add this.');
                 }
             }
         }
         $this->module->clearBLHLCache();
     }
     if (Tools::getIsset('duplicateprofile')) {
         if ($this->tabAccess['add'] === '1') {
             $this->processDuplicate();
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to add this.');
         }
         $this->module->clearBLHLCache();
     }
     if (Tools::isSubmit('savelayoutbuilder')) {
         $profile = new PsPagebuilderprofile(Tools::getValue('id_pagebuilderprofile'));
         $profile->layout = Tools::getValue('wpolayout');
         $wpowidget = Tools::getValue('wpowidget');
         if ($wpowidget) {
             foreach ($wpowidget as &$value) {
                 $value['config'] = Tools::stripslashes($value['config']);
             }
         }
         $profile->widget = serialize($wpowidget);
         $name = trim(Tools::getValue('name'));
         $profile->name = $name ? $name : 'profile-' . time();
         $errors = array();
         if ($profile->id && !$profile->update()) {
             $errors[] = $this->displayError($this->l('The slide could not be updated.'));
         } else {
             if ($profile->id <= 0 && !$profile->add()) {
                 $errors[] = $this->displayError($this->l('The slide could not be added.'));
             }
         }
         $this->module->clearBLHLCache();
         Tools::redirectAdmin(AdminController::$currentIndex . '&id_pagebuilderprofile=' . $profile->id . '&token=' . Tools::getAdminTokenLite('AdminPspagebuilderProfile'));
     }
     if (Tools::getValue('setdefault')) {
         $profile = new PsPagebuilderprofile(Tools::getValue('id_pagebuilderprofile'));
         $profile->setDefault();
         $this->module->clearBLHLCache();
         Tools::redirectAdmin(AdminController::$currentIndex . '&id_pagebuilderprofile=' . $profile->id . '&token=' . Tools::getAdminTokenLite('AdminPspagebuilderProfile'));
     }
 }
Ejemplo n.º 2
0
 public function dupplicatForAllLanguages()
 {
     $id_lang_default = Configuration::get('PS_LANG_DEFAULT');
     $languages = Language::getLanguages(false);
     $obj = new PsPagebuilderprofile();
     $profiles = $obj->getList();
     $fprofiles = $obj->getListByFooter();
     $profiles = array_merge($profiles, $fprofiles);
     if ($profiles) {
         foreach ($profiles as &$profile) {
             $ws = unserialize(PsPagebuilderHelper::clearUnexpected(trim($profile['widget'])));
             if ($ws) {
                 foreach ($ws as &$config) {
                     $configs = unserialize(PsPagebuilderHelper::clearUnexpected(trim($config['config'])));
                     if (isset($configs['widget']) && $configs['widget']) {
                         foreach ($configs['widget'] as $k => $p) {
                             $arrs = explode('_', $k);
                             $end = end($arrs);
                             array_pop($arrs);
                             if ($end == $id_lang_default) {
                                 foreach ($languages as $language) {
                                     if ($language['id_lang'] != $id_lang_default) {
                                         $configs['widget'][implode('_', $arrs) . '_' . $language['id_lang']] = $p;
                                     }
                                 }
                             }
                         }
                     }
                     $config['config'] = serialize($configs);
                 }
                 $profile['widget'] = serialize($ws);
             }
             // save data here
             $new_obj = new PsPagebuilderprofile($profile['id_pagebuilderprofile']);
             $new_obj->widget = $profile['widget'];
             $new_obj->update();
         }
     }
 }