Ejemplo n.º 1
0
 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);
         }
     }
 }
Ejemplo n.º 2
0
function checkingTab($tab)
{
    global $adminObj, $cookie;
    $tab = trim($tab);
    if (!Validate::isTabName($tab)) {
        return false;
    }
    $row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql = 'SELECT id_tab, module FROM `' . _DB_PREFIX_ . 'tab` WHERE class_name = \'' . pSQL($tab) . '\'');
    if (!$row['id_tab']) {
        if (isset(AdminTab::$tabParenting[$tab])) {
            Tools14::redirectAdmin('?tab=' . AdminTab::$tabParenting[$tab] . '&token=' . Tools14::getAdminTokenLite(AdminTab::$tabParenting[$tab]));
        }
        echo Tools14::displayError('Tab cannot be found.');
        return false;
    }
    if ($row['module'] and file_exists(_PS_MODULE_DIR_ . '/' . $row['module'] . '/' . $tab . '.php')) {
        include_once _PS_MODULE_DIR_ . '/' . $row['module'] . '/' . $tab . '.php';
    } elseif (file_exists(PS_ADMIN_DIR . '/tabs/' . $tab . '.php')) {
        include_once PS_ADMIN_DIR . '/tabs/' . $tab . '.php';
    }
    if (!class_exists($tab, false) or !$row['id_tab']) {
        echo Tools14::displayError('Tab file cannot be found.');
        return false;
    }
    $adminObj = new $tab();
    if (!$adminObj->viewAccess()) {
        $adminObj->_errors = array(Tools14::displayError('Access denied'));
        echo $adminObj->displayErrors();
        return false;
    }
    return $row['id_tab'];
}
Ejemplo n.º 3
0
    public function display()
    {
        $this->_html .= '<script type="text/javascript">var jQueryVersionPS = parseInt($().jquery.replace(/\\./g, ""));</script>
		<script type="text/javascript" src="' . __PS_BASE_URI__ . 'modules/autoupgrade/js/jquery-1.6.2.min.js"></script>
		<script type="text/javascript">if (jQueryVersionPS >= 162) jq162 = jQuery.noConflict(true);</script>';
        /* PrestaShop demo mode */
        if (defined('_PS_MODE_DEMO_') && _PS_MODE_DEMO_) {
            echo '<div class="error">' . $this->l('This functionality has been disabled.') . '</div>';
            return;
        }
        if (!file_exists($this->autoupgradePath . DIRECTORY_SEPARATOR . 'ajax-upgradetab.php')) {
            echo '<div class="error">' . '<img src="../img/admin/warning.gif" /> ' . $this->l('[TECHNICAL ERROR] ajax-upgradetab.php is missing. Please reinstall or reset the module.') . '</div>';
            return false;
        }
        /* PrestaShop demo mode*/
        // in order to not use Tools class
        $upgrader = new Upgrader();
        preg_match('#([0-9]+\\.[0-9]+)(?:\\.[0-9]+){1,2}#', _PS_VERSION_, $matches);
        $upgrader->branch = $matches[1];
        $channel = $this->getConfig('channel');
        switch ($channel) {
            case 'archive':
                $upgrader->channel = 'archive';
                $upgrader->version_num = $this->getConfig('archive.version_num');
                break;
            case 'directory':
                $upgrader->channel = 'directory';
                $upgrader->version_num = $this->getConfig('directory.version_num');
                break;
            default:
                $upgrader->channel = $channel;
                if (isset($_GET['refreshCurrentVersion'])) {
                    // delete the potential xml files we saved in config/xml (from last release and from current)
                    $upgrader->clearXmlMd5File(_PS_VERSION_);
                    $upgrader->clearXmlMd5File($upgrader->version_num);
                    if ($this->getConfig('channel') == 'private' && !$this->getConfig('private_allow_major')) {
                        $upgrader->checkPSVersion(true, array('private', 'minor'));
                    } else {
                        $upgrader->checkPSVersion(true, array('minor'));
                    }
                    Tools14::redirectAdmin($this->currentIndex . '&conf=5&token=' . Tools14::getValue('token'));
                } else {
                    if ($this->getConfig('channel') == 'private' && !$this->getConfig('private_allow_major')) {
                        $upgrader->checkPSVersion(false, array('private', 'minor'));
                    } else {
                        $upgrader->checkPSVersion(false, array('minor'));
                    }
                }
        }
        $this->upgrader = $upgrader;
        $this->_html .= '<link type="text/css" rel="stylesheet" href="' . __PS_BASE_URI__ . 'modules/autoupgrade/css/styles.css" />';
        $this->_html .= '<div class="bootstrap" id="informationBlock">
            <div class="panel">
                <div class="panel-heading">
                  ' . $this->l('Welcome!') . '
                </div>
                <p>
                    ' . $this->l('With the PrestaShop 1-Click Upgrade module, upgrading your store to the latest version available has never been easier!') . '<br /><br />
                    <span style="color:#CC0000;font-weight:bold">' . $this->l('Please always perform a full manual backup of your files and database before starting any upgrade.') . '</span><br />
                    ' . $this->l('Double-check the integrity of your backup and that you can easily manually roll-back if necessary.') . '<br />
                    ' . $this->l('If you do not know how to proceed, ask your hosting provider.') . '
                </p>
            </div>
            </div>';
        /* Make sure the user has configured the upgrade options, or set default values */
        $configuration_keys = array('PS_AUTOUP_UPDATE_DEFAULT_THEME' => 1, 'PS_AUTOUP_CHANGE_DEFAULT_THEME' => 0, 'PS_AUTOUP_KEEP_MAILS' => 0, 'PS_AUTOUP_CUSTOM_MOD_DESACT' => 1, 'PS_AUTOUP_MANUAL_MODE' => 0, 'PS_AUTOUP_PERFORMANCE' => 1, 'PS_DISPLAY_ERRORS' => 0);
        foreach ($configuration_keys as $k => $default_value) {
            if (Configuration::get($k) == '') {
                Configuration::updateValue($k, $default_value);
            }
        }
        /* Checks/requirements and "Upgrade PrestaShop now" blocks */
        $this->_displayCurrentConfiguration();
        $this->_displayBlockUpgradeButton();
        $this->_displayComparisonBlock();
        $this->_displayBlockActivityLog();
        $this->_displayRollbackForm();
        $this->_html .= '<br/>';
        $this->_html .= '<form action="' . $this->currentIndex . '&amp;customSubmitAutoUpgrade=1&amp;token=' . $this->token . '" method="post" class="form-horizontal" enctype="multipart/form-data">';
        $this->_displayForm('backupOptions', $this->_fieldsBackupOptions, '<a href="#" name="backup-options" id="backup-options">' . $this->l('Backup Options') . '</a>', '', 'database_gear');
        $this->_displayForm('upgradeOptions', $this->_fieldsUpgradeOptions, '<a href="#" name="upgrade-options" id="upgrade-options">' . $this->l('Upgrade Options') . '</a>', '', 'prefs');
        $this->_html .= '</form>';
        $this->_html .= '<script type="text/javascript" src="' . __PS_BASE_URI__ . 'modules/autoupgrade/js/jquery.xml2json.js"></script>';
        $this->_html .= '<script type="text/javascript">' . $this->_getJsInit() . '</script>';
        echo $this->_html;
    }