/** * Process posting data */ public function postProcess() { $languages = Language::getLanguages(false); $current_theme = Theme::getThemeInfo($this->context->shop->id_theme); //$theme_arr['theme_id'] = $theme->id; // $theme_arr['theme_name'] = $theme->name; // $theme_arr['theme_directory'] = $theme->directory; if (Tools::isSubmit('submitnewOption')) { $id_option = Tools::getValue('id_option'); if ($id_option && Validate::isUnsignedId($id_option)) { $option = new Options($id_option); $addaction = false; } else { $option = new Options(); $addaction = true; } $option->column = Tools::getValue('colselected'); $option->theme = strtolower($current_theme['theme_name']); $option->alias = Tools::getValue('alias'); $option->active = (int) Tools::getValue('active'); $name_set = false; $option_name = Tools::getValue('option_name'); if (strlen($option_name) > 0) { $name_set = true; $option->name = $option_name; } if (!$name_set) { $lang_title = Language::getLanguage($this->context->language->id); $this->errors[] = Tools::displayError('This item title field is required'); } if (strlen($option->alias) > 0) { if (OvicLayoutControl::isAvailablebyAlias($option->alias) > 0) { $this->errors[] = Tools::displayError('Alias is avaiable in database'); } } else { $this->errors[] = Tools::displayError('This item alias field is required'); } if (isset($_FILES['option_img']) && strlen($_FILES['option_img']['name']) > 0) { $img_name = time() . $_FILES['option_img']['name']; $img_name = preg_replace('/[^A-Za-z0-9\\-.]/', '', $img_name); // Removes special chars. //_PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $this->name .DIRECTORY_SEPARATOR $main_name = _PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . 'oviclayoutcontrol' . DIRECTORY_SEPARATOR . 'thumbnails' . DIRECTORY_SEPARATOR . $img_name; if (!move_uploaded_file($_FILES['option_img']['tmp_name'], $main_name)) { $this->errors[] = Tools::displayError('An error occurred during the image upload.'); } else { $option->image = $img_name; if (Tools::getValue('old_img') != '') { $filename = Tools::getValue('old_img'); if (file_exists(_PS_MODULE_DIR_ . 'oviclayoutcontrol/thumbnails/' . $filename)) { @unlink(_PS_MODULE_DIR_ . 'oviclayoutcontrol/thumbnails/' . $filename); } } } } else { $option->image = Tools::getValue('old_img'); } if (!count($this->errors)) { if ($addaction) { if (!$option->add()) { $this->errors[] = Tools::displayError('An error occurred while saving data.'); } else { if (Tools::getIsset('id_copy_option')) { $id_copy_option = (int) Tools::getValue('id_copy_option'); $source_option = new Options($id_copy_option); OvicLayoutControl::copyHookModule($source_option, $option); OvicLayoutControl::copyOptionStyle($source_option, $option); } else { OvicLayoutControl::registerDefaultHookModule($option->id); } } } else { if (!$option->update()) { $this->errors[] = Tools::displayError('An error occurred while update data.'); } } if (!count($this->errors)) { Tools::redirectAdmin(self::$currentIndex . '&conf=3&token=' . Tools::getValue('token')); } } } elseif (Tools::isSubmit('changeactive')) { $id_option = Tools::getValue('id_option'); if ($id_option && Validate::isUnsignedId($id_option)) { $option = new Options($id_option); $option->active = !$option->active; if (!$option->update()) { $this->errors[] = Tools::displayError('Could not change'); } else { Tools::redirectAdmin(self::$currentIndex . '&conf=5&token=' . Tools::getValue('token')); } } } elseif (Tools::isSubmit('removeoption')) { $id_option = Tools::getValue('id_option'); if ($id_option && Validate::isUnsignedId($id_option)) { $option = new Options($id_option); if (!$option->delete()) { $this->errors[] = Tools::displayError('An error occurred during deletion'); } else { Tools::redirectAdmin(self::$currentIndex . '&conf=1&token=' . Tools::getValue('token')); } } } elseif (Tools::isSubmit('submitMultiSave')) { $id_option = (int) Tools::getValue('id_option'); if ($id_option && Validate::isUnsignedId($id_option)) { $fonts = array(); foreach (OvicLayoutControl::$OptionFonts as $font) { $fonts[$font] = Tools::getValue($font); } $colors = array(); foreach (OvicLayoutControl::$OptionColors as $color) { $colors[$color] = Tools::getValue($color); } $option = new Options($id_option); $where = "`theme` = '" . $option->theme . "' AND `alias` = '" . $option->alias . "'"; $sql = 'SELECT `alias` FROM `' . _DB_PREFIX_ . 'ovic_options_style` WHERE ' . $where; if (Db::getInstance()->getRow($sql)) { $result = Db::getInstance()->update('ovic_options_style', array('color' => Tools::jsonEncode($colors), 'font' => Tools::jsonEncode($fonts)), $where); } else { // Register module in hook $result = Db::getInstance()->insert('ovic_options_style', array('theme' => $option->theme, 'alias' => $option->alias, 'color' => Tools::jsonEncode($colors), 'font' => Tools::jsonEncode($fonts))); } if ($result) { Tools::redirectAdmin(self::$currentIndex . '&conf=4&token=' . Tools::getValue('token') . '&view=detail&id_option=' . $id_option); } else { $this->errors[] = Tools::displayError('An error occurred while saving data.'); } } } parent::postProcess(); }