protected function _postConfig($fields) { global $currentIndex, $smarty; $languages = Language::getLanguages(false); if (method_exists('Tools', 'clearCache')) { Tools14::clearCache($smarty); } /* Check required fields */ foreach ($fields as $field => $values) { if (isset($values['required']) and $values['required']) { if (isset($values['type']) and $values['type'] == 'textLang') { foreach ($languages as $language) { if (($value = Tools14::getValue($field . '_' . $language['id_lang'])) == false and (string) $value != '0') { $this->_errors[] = Tools14::displayError('field') . ' <b>' . $values['title'] . '</b> ' . Tools14::displayError('is required.'); } } } elseif (($value = Tools14::getValue($field)) == false and (string) $value != '0') { $this->_errors[] = Tools14::displayError('field') . ' <b>' . $values['title'] . '</b> ' . Tools14::displayError('is required.'); } } } /* Check fields validity */ foreach ($fields as $field => $values) { if (isset($values['type']) and $values['type'] == 'textLang') { foreach ($languages as $language) { if (Tools14::getValue($field . '_' . $language['id_lang']) and isset($values['validation'])) { if (!Validate::$values['validation'](Tools14::getValue($field . '_' . $language['id_lang']))) { $this->_errors[] = Tools14::displayError('field') . ' <b>' . $values['title'] . '</b> ' . Tools14::displayError('is invalid.'); } } } } elseif (Tools14::getValue($field) and isset($values['validation'])) { if (!Validate::$values['validation'](Tools14::getValue($field))) { $this->_errors[] = Tools14::displayError('field') . ' <b>' . $values['title'] . '</b> ' . Tools14::displayError('is invalid.'); } } } /* Default value if null */ foreach ($fields as $field => $values) { if (!Tools14::getValue($field) and isset($values['default'])) { $_POST[$field] = $values['default']; } } /* Save process */ if (!sizeof($this->_errors)) { if (Tools14::isSubmit('submitAppearanceconfiguration')) { if (isset($_FILES['PS_LOGO']['tmp_name']) and $_FILES['PS_LOGO']['tmp_name']) { if ($error = checkImage($_FILES['PS_LOGO'], 300000)) { $this->_errors[] = $error; } if (!($tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS')) or !move_uploaded_file($_FILES['PS_LOGO']['tmp_name'], $tmpName)) { return false; } elseif (!@imageResize($tmpName, _PS_IMG_DIR_ . 'logo.jpg')) { $this->_errors[] = 'an error occurred during logo copy'; } unlink($tmpName); } if (isset($_FILES['PS_LOGO_MAIL']['tmp_name']) and $_FILES['PS_LOGO_MAIL']['tmp_name']) { if ($error = checkImage($_FILES['PS_LOGO_MAIL'], 300000)) { $this->_errors[] = $error; } if (!($tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS_MAIL')) or !move_uploaded_file($_FILES['PS_LOGO_MAIL']['tmp_name'], $tmpName)) { return false; } elseif (!@imageResize($tmpName, _PS_IMG_DIR_ . 'logo_mail.jpg')) { $this->_errors[] = 'an error occurred during logo copy'; } unlink($tmpName); } if (isset($_FILES['PS_LOGO_INVOICE']['tmp_name']) and $_FILES['PS_LOGO_INVOICE']['tmp_name']) { if ($error = checkImage($_FILES['PS_LOGO_INVOICE'], 300000)) { $this->_errors[] = $error; } if (!($tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS_INVOICE')) or !move_uploaded_file($_FILES['PS_LOGO_INVOICE']['tmp_name'], $tmpName)) { return false; } elseif (!@imageResize($tmpName, _PS_IMG_DIR_ . 'logo_invoice.jpg')) { $this->_errors[] = 'an error occurred during logo copy'; } unlink($tmpName); } if (isset($_FILES['PS_STORES_ICON']['tmp_name']) and $_FILES['PS_STORES_ICON']['tmp_name']) { if ($error = checkImage($_FILES['PS_STORES_ICON'], 300000)) { $this->_errors[] = $error; } if (!($tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS_STORES_ICON')) or !move_uploaded_file($_FILES['PS_STORES_ICON']['tmp_name'], $tmpName)) { return false; } elseif (!@imageResize($tmpName, _PS_IMG_DIR_ . 'logo_stores.gif')) { $this->_errors[] = 'an error occurred during logo copy'; } unlink($tmpName); } $this->uploadIco('PS_FAVICON', _PS_IMG_DIR_ . 'favicon.ico'); } /* Update settings in database */ if (!sizeof($this->_errors)) { foreach ($fields as $field => $values) { unset($val); if (isset($values['type']) and $values['type'] == 'textLang') { foreach ($languages as $language) { $val[$language['id_lang']] = isset($values['cast']) ? $values['cast'](Tools14::getValue($field . '_' . $language['id_lang'])) : Tools14::getValue($field . '_' . $language['id_lang']); } } else { $val = isset($values['cast']) ? $values['cast'](Tools14::getValue($field)) : Tools14::getValue($field); } Configuration::updateValue($field, $val); } Tools14::redirectAdmin($currentIndex . '&conf=6' . '&token=' . $this->token); } } }
public function postProcess() { $this->_setFields(); // set default configuration to default channel & dafault configuration for backup and upgrade // (can be modified in expert mode) $config = $this->getConfig('channel'); if ($config === false) { $config = array(); $config['channel'] = Upgrader::DEFAULT_CHANNEL; $this->writeConfig($config); if (class_exists('Configuration', false)) { Configuration::updateValue('PS_UPGRADE_CHANNEL', $config['channel']); } $this->writeConfig(array('PS_AUTOUP_PERFORMANCE' => '1', 'PS_AUTOUP_CUSTOM_MOD_DESACT' => '1', 'PS_AUTOUP_UPDATE_DEFAULT_THEME' => '1', 'PS_AUTOUP_CHANGE_DEFAULT_THEME' => '0', 'PS_AUTOUP_KEEP_MAILS' => '0', 'PS_AUTOUP_BACKUP' => '1', 'PS_AUTOUP_KEEP_IMAGES' => '0')); } if (Tools14::isSubmit('putUnderMaintenance')) { foreach (Shop::getCompleteListOfShopsID() as $id_shop) { Configuration::updateValue('PS_SHOP_ENABLE', 0, false, null, (int) $id_shop); } Configuration::updateGlobalValue('PS_SHOP_ENABLE', 0); } if (Tools14::isSubmit('customSubmitAutoUpgrade')) { $config_keys = array_keys(array_merge($this->_fieldsUpgradeOptions, $this->_fieldsBackupOptions)); $config = array(); foreach ($config_keys as $key) { if (isset($_POST[$key])) { $config[$key] = $_POST[$key]; } } $res = $this->writeConfig($config); if ($res) { Tools14::redirectAdmin($this->currentIndex . '&conf=6&token=' . Tools14::getValue('token')); } } if (Tools14::isSubmit('deletebackup')) { $res = false; $name = Tools14::getValue('name'); $filelist = scandir($this->backupPath); foreach ($filelist as $filename) { // the following will match file or dir related to the selected backup if (!empty($filename) && $filename[0] != '.' && $filename != 'index.php' && $filename != '.htaccess' && preg_match('#^(auto-backupfiles_|)' . preg_quote($name) . '(\\.zip|)$#', $filename, $matches)) { if (is_file($this->backupPath . DIRECTORY_SEPARATOR . $filename)) { $res &= unlink($this->backupPath . DIRECTORY_SEPARATOR . $filename); } elseif (!empty($name) && is_dir($this->backupPath . DIRECTORY_SEPARATOR . $name . DIRECTORY_SEPARATOR)) { $res = self::deleteDirectory($this->backupPath . DIRECTORY_SEPARATOR . $name . DIRECTORY_SEPARATOR); } } } if ($res) { Tools14::redirectAdmin($this->currentIndex . '&conf=1&token=' . Tools14::getValue('token')); } else { $this->_errors[] = sprintf($this->l('Error when trying to delete backups %s'), $name); } } parent::postProcess(); }