Example #1
0
 public static function clearCache()
 {
     Tools::clearSmartyCache();
     Tools::clearXMLCache();
     Media::clearCache();
     Tools::generateIndex();
 }
 public function ajaxProcessuploadThumbnailImages()
 {
     $category = new Category((int) Tools::getValue('id_category'));
     if (isset($_FILES['thumbnail'])) {
         //Get total of image already present in directory
         $files = scandir(_PS_CAT_IMG_DIR_);
         $assigned_keys = array();
         $allowed_keys = array(0, 1, 2);
         foreach ($files as $file) {
             $matches = array();
             if (preg_match('/' . $category->id . '-([0-9])?_thumb.jpg/i', $file, $matches) === 1) {
                 $assigned_keys[] = (int) $matches[1];
             }
         }
         $available_keys = array_diff($allowed_keys, $assigned_keys);
         $helper = new HelperImageUploader('thumbnail');
         $files = $helper->process();
         $total_errors = array();
         if (count($available_keys) < count($files)) {
             $total_errors[] = sprintf(Tools::displayError('You cannot upload more than %s files'), count($available_keys));
             die;
         }
         foreach ($files as $key => &$file) {
             $id = array_shift($available_keys);
             $errors = array();
             // Evaluate the memory required to resize the image: if it's too much, you can't resize it.
             if (!ImageManager::checkImageMemoryLimit($file['save_path'])) {
                 $errors[] = Tools::displayError('Due to memory limit restrictions, this image cannot be loaded. Please increase your memory_limit value via your server\'s configuration settings. ');
             }
             // Copy new image
             if (empty($errors) && !ImageManager::resize($file['save_path'], _PS_CAT_IMG_DIR_ . (int) Tools::getValue('id_category') . '-' . $id . '_thumb.jpg')) {
                 $errors[] = Tools::displayError('An error occurred while uploading the image.');
             }
             if (count($errors)) {
                 $total_errors = array_merge($total_errors, $errors);
             }
             unlink($file['save_path']);
             //Necesary to prevent hacking
             unset($file['save_path']);
             //Add image preview and delete url
             $file['image'] = ImageManager::thumbnail(_PS_CAT_IMG_DIR_ . (int) $category->id . '-' . $id . '_thumb.jpg', $this->context->controller->table . '_' . (int) $category->id . '-' . $id . '_thumb.jpg', 100, 'jpg', true, true);
             $file['delete_url'] = Context::getContext()->link->getAdminLink('AdminBlockCategories') . '&deleteThumb=' . $id . '&id_category=' . (int) $category->id . '&updatecategory';
         }
         if (count($total_errors)) {
             $this->context->controller->errors = array_merge($this->context->controller->errors, $total_errors);
         } else {
             Tools::clearSmartyCache();
         }
         die(Tools::jsonEncode(array('thumbnail' => $files)));
     }
 }
    public function beforeUpdateOptions()
    {
        if (!Tools::getValue('PS_STOCK_MANAGEMENT', true)) {
            $_POST['PS_ORDER_OUT_OF_STOCK'] = 1;
            $_POST['PS_DISPLAY_QTIES'] = 0;
        }
        // if advanced stock management is disabled, updates concerned tables
        if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') == 1 && (int) Tools::getValue('PS_ADVANCED_STOCK_MANAGEMENT') == 0 && Context::getContext()->shop->getContext() == Shop::CONTEXT_ALL) {
            ObjectModel::updateMultishopTable('Product', array('advanced_stock_management' => 0), 'product_shop.`advanced_stock_management` = 1');
            Db::getInstance()->execute('UPDATE `' . _DB_PREFIX_ . 'stock_available`
				 SET `depends_on_stock` = 0, `quantity` = 0
				 WHERE `depends_on_stock` = 1');
        }
        if (Tools::getIsset('PS_CATALOG_MODE')) {
            Tools::clearSmartyCache();
            Media::clearCache();
        }
    }
    public function beforeUpdateOptions()
    {
        if (!Tools::getValue('PS_STOCK_MANAGEMENT', true)) {
            $_POST['PS_ORDER_OUT_OF_STOCK'] = 1;
            $_POST['PS_DISPLAY_QTIES'] = 0;
        }
        // if advanced stock management is disabled, updates concerned tables
        if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') == 1 && (int) Tools::getValue('PS_ADVANCED_STOCK_MANAGEMENT') == 0) {
            $id_shop_list = Shop::getContextListShopID();
            $sql_shop = 'UPDATE `' . _DB_PREFIX_ . 'product_shop` SET `advanced_stock_management` = 0 WHERE
			`advanced_stock_management` = 1 AND (`id_shop` = ' . implode(' OR `id_shop` = ', $id_shop_list) . ')';
            $sql_stock = 'UPDATE `' . _DB_PREFIX_ . 'stock_available` SET `depends_on_stock` = 0, `quantity` = 0
					 WHERE `depends_on_stock` = 1 AND (`id_shop` = ' . implode(' OR `id_shop` = ', $id_shop_list) . ')';
            $sql = 'UPDATE `' . _DB_PREFIX_ . 'product` SET `advanced_stock_management` = 0 WHERE
			`advanced_stock_management` = 1 AND (`id_shop_default` = ' . implode(' OR `id_shop_default` = ', $id_shop_list) . ')';
            Db::getInstance()->execute($sql_shop);
            Db::getInstance()->execute($sql_stock);
            Db::getInstance()->execute($sql);
        }
        if (Tools::getIsset('PS_CATALOG_MODE')) {
            Tools::clearSmartyCache();
            Media::clearCache();
        }
    }
 /**
  * Toggle show prices flag
  */
 public function processChangeShowPricesVal()
 {
     $group = new Group($this->id_object);
     if (!Validate::isLoadedObject($group)) {
         $this->errors[] = Tools::displayError('An error occurred while updating this group.');
     }
     $update = Db::getInstance()->execute('UPDATE `' . _DB_PREFIX_ . 'group` SET show_prices = ' . ($group->show_prices ? 0 : 1) . ' WHERE `id_group` = ' . (int) $group->id);
     if (!$update) {
         $this->errors[] = Tools::displayError('An error occurred while updating this group.');
     }
     Tools::clearSmartyCache();
     Tools::redirectAdmin(self::$currentIndex . '&token=' . $this->token);
 }
    public function postProcess()
    {
        /* PrestaShop demo mode */
        if (_PS_MODE_DEMO_) {
            $this->errors[] = Tools::displayError('This functionality has been disabled.');
            return;
        }
        Hook::exec('action' . get_class($this) . ucfirst($this->action) . 'Before', array('controller' => $this));
        if (Tools::isSubmit('submitAddServer')) {
            if ($this->tabAccess['add'] === '1') {
                if (!Tools::getValue('memcachedIp')) {
                    $this->errors[] = Tools::displayError('The Memcached IP is missing.');
                }
                if (!Tools::getValue('memcachedPort')) {
                    $this->errors[] = Tools::displayError('The Memcached port is missing.');
                }
                if (!Tools::getValue('memcachedWeight')) {
                    $this->errors[] = Tools::displayError('The Memcached weight is missing.');
                }
                if (!count($this->errors)) {
                    if (CacheMemcache::addServer(pSQL(Tools::getValue('memcachedIp')), (int) Tools::getValue('memcachedPort'), (int) Tools::getValue('memcachedWeight'))) {
                        Tools::redirectAdmin(self::$currentIndex . '&token=' . Tools::getValue('token') . '&conf=4');
                    } else {
                        $this->errors[] = Tools::displayError('The Memcached server cannot be added.');
                    }
                }
            } else {
                $this->errors[] = Tools::displayError('You do not have permission to add this.');
            }
        }
        if (Tools::getValue('deleteMemcachedServer')) {
            if ($this->tabAccess['add'] === '1') {
                if (CacheMemcache::deleteServer((int) Tools::getValue('deleteMemcachedServer'))) {
                    Tools::redirectAdmin(self::$currentIndex . '&token=' . Tools::getValue('token') . '&conf=4');
                } else {
                    $this->errors[] = Tools::displayError('There was an error when attempting to delete the Memcached server.');
                }
            } else {
                $this->errors[] = Tools::displayError('You do not have permission to delete this.');
            }
        }
        $redirectAdmin = false;
        if ((bool) Tools::getValue('smarty_up')) {
            if ($this->tabAccess['edit'] === '1') {
                Configuration::updateValue('PS_SMARTY_FORCE_COMPILE', Tools::getValue('smarty_force_compile', _PS_SMARTY_NO_COMPILE_));
                Configuration::updateValue('PS_SMARTY_CACHE', Tools::getValue('smarty_cache', 0));
                Configuration::updateValue('PS_SMARTY_CONSOLE', Tools::getValue('smarty_console', 0));
                Configuration::updateValue('PS_SMARTY_CONSOLE_KEY', Tools::getValue('smarty_console_key', 'SMARTY_DEBUG'));
                $redirecAdmin = true;
            } else {
                $this->errors[] = Tools::displayError('You do not have permission to edit this.');
            }
        }
        if ((bool) Tools::getValue('features_detachables_up')) {
            if ($this->tabAccess['edit'] === '1') {
                if (Tools::getValue('combination') || !Combination::isCurrentlyUsed()) {
                    Configuration::updateValue('PS_COMBINATION_FEATURE_ACTIVE', Tools::getValue('combination'));
                }
                if (Tools::getValue('customer_group') && !Group::isCurrentlyUsed()) {
                    Configuration::updateValue('PS_GROUP_FEATURE_ACTIVE', Tools::getValue('customer_group'));
                }
                Configuration::updateValue('PS_FEATURE_FEATURE_ACTIVE', Tools::getValue('feature'));
                $redirectAdmin = true;
            } else {
                $this->errors[] = Tools::displayError('You do not have permission to edit this.');
            }
        }
        if ((bool) Tools::getValue('ccc_up')) {
            if ($this->tabAccess['edit'] === '1') {
                $theme_cache_directory = _PS_ALL_THEMES_DIR_ . $this->context->shop->theme_directory . '/cache/';
                if (((bool) Tools::getValue('PS_CSS_THEME_CACHE') || (bool) Tools::getValue('PS_JS_THEME_CACHE')) && !is_writable($theme_cache_directory)) {
                    $this->errors[] = Tools::displayError(sprintf($this->l('To use Smart Cache directory %s must be writable.'), realpath($theme_cache_directory)));
                }
                if (!Configuration::updateValue('PS_CSS_THEME_CACHE', (int) Tools::getValue('PS_CSS_THEME_CACHE')) || !Configuration::updateValue('PS_JS_THEME_CACHE', (int) Tools::getValue('PS_JS_THEME_CACHE')) || !Configuration::updateValue('PS_HTML_THEME_COMPRESSION', (int) Tools::getValue('PS_HTML_THEME_COMPRESSION')) || !Configuration::updateValue('PS_JS_HTML_THEME_COMPRESSION', (int) Tools::getValue('PS_JS_HTML_THEME_COMPRESSION')) || !Configuration::updateValue('PS_HTACCESS_CACHE_CONTROL', (int) Tools::getValue('PS_HTACCESS_CACHE_CONTROL'))) {
                    $this->errors[] = Tools::displayError('Unknown error.');
                } else {
                    $redirectAdmin = true;
                    if (Configuration::get('PS_HTACCESS_CACHE_CONTROL')) {
                        Tools::generateHtaccess();
                    }
                }
            } else {
                $this->errors[] = Tools::displayError('You do not have permission to edit this.');
            }
        }
        if ((bool) Tools::getValue('media_server_up')) {
            if ($this->tabAccess['edit'] === '1') {
                if (Tools::getValue('_MEDIA_SERVER_1_') != null && !Validate::isFileName(Tools::getValue('_MEDIA_SERVER_1_'))) {
                    $this->errors[] = Tools::displayError('Media server #1 is invalid');
                }
                if (Tools::getValue('_MEDIA_SERVER_2_') != null && !Validate::isFileName(Tools::getValue('_MEDIA_SERVER_2_'))) {
                    $this->errors[] = Tools::displayError('Media server #2 is invalid');
                }
                if (Tools::getValue('_MEDIA_SERVER_3_') != null && !Validate::isFileName(Tools::getValue('_MEDIA_SERVER_3_'))) {
                    $this->errors[] = Tools::displayError('Media server #3 is invalid');
                }
                if (!count($this->errors)) {
                    $base_urls = array();
                    $base_urls['_MEDIA_SERVER_1_'] = Tools::getValue('_MEDIA_SERVER_1_');
                    $base_urls['_MEDIA_SERVER_2_'] = Tools::getValue('_MEDIA_SERVER_2_');
                    $base_urls['_MEDIA_SERVER_3_'] = Tools::getValue('_MEDIA_SERVER_3_');
                    if ($base_urls['_MEDIA_SERVER_1_'] || $base_urls['_MEDIA_SERVER_2_'] || $base_urls['_MEDIA_SERVER_3_']) {
                        Configuration::updateValue('PS_MEDIA_SERVERS', 1);
                    } else {
                        Configuration::updateValue('PS_MEDIA_SERVERS', 0);
                    }
                    rewriteSettingsFile($base_urls, null, null);
                    Tools::clearSmartyCache();
                    Media::clearCache();
                    Tools::generateHtaccess(null, null, null, '', null, array($base_urls['_MEDIA_SERVER_1_'], $base_urls['_MEDIA_SERVER_2_'], $base_urls['_MEDIA_SERVER_3_']));
                    unset($this->_fieldsGeneral['_MEDIA_SERVER_1_']);
                    unset($this->_fieldsGeneral['_MEDIA_SERVER_2_']);
                    unset($this->_fieldsGeneral['_MEDIA_SERVER_3_']);
                    $redirectAdmin = true;
                }
            } else {
                $this->errors[] = Tools::displayError('You do not have permission to edit this.');
            }
        }
        if ((bool) Tools::getValue('ciphering_up') && Configuration::get('PS_CIPHER_ALGORITHM') != (int) Tools::getValue('PS_CIPHER_ALGORITHM')) {
            if ($this->tabAccess['edit'] === '1') {
                $algo = (int) Tools::getValue('PS_CIPHER_ALGORITHM');
                $prev_settings = file_get_contents(_PS_ROOT_DIR_ . '/config/settings.inc.php');
                $new_settings = $prev_settings;
                if ($algo) {
                    if (!function_exists('mcrypt_encrypt')) {
                        $this->errors[] = Tools::displayError('The "Mcrypt" PHP extension is not activated on this server.');
                    } else {
                        if (!strstr($new_settings, '_RIJNDAEL_KEY_')) {
                            $key_size = mcrypt_get_key_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB);
                            $key = Tools::passwdGen($key_size);
                            $new_settings = preg_replace('/define\\(\'_COOKIE_KEY_\', \'([a-z0-9=\\/+-_]+)\'\\);/i', 'define(\'_COOKIE_KEY_\', \'\\1\');' . "\n" . 'define(\'_RIJNDAEL_KEY_\', \'' . $key . '\');', $new_settings);
                        }
                        if (!strstr($new_settings, '_RIJNDAEL_IV_')) {
                            $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB);
                            $iv = base64_encode(mcrypt_create_iv($iv_size, MCRYPT_RAND));
                            $new_settings = preg_replace('/define\\(\'_COOKIE_IV_\', \'([a-z0-9=\\/+-_]+)\'\\);/i', 'define(\'_COOKIE_IV_\', \'\\1\');' . "\n" . 'define(\'_RIJNDAEL_IV_\', \'' . $iv . '\');', $new_settings);
                        }
                    }
                }
                if (!count($this->errors)) {
                    // If there is not settings file modification or if the backup and replacement of the settings file worked
                    if ($new_settings == $prev_settings || copy(_PS_ROOT_DIR_ . '/config/settings.inc.php', _PS_ROOT_DIR_ . '/config/settings.old.php') && (bool) file_put_contents(_PS_ROOT_DIR_ . '/config/settings.inc.php', $new_settings)) {
                        Configuration::updateValue('PS_CIPHER_ALGORITHM', $algo);
                        $redirectAdmin = true;
                    } else {
                        $this->errors[] = Tools::displayError('The settings file cannot be overwritten.');
                    }
                }
            } else {
                $this->errors[] = Tools::displayError('You do not have permission to edit this.');
            }
        }
        if ((bool) Tools::getValue('cache_up')) {
            if ($this->tabAccess['edit'] === '1') {
                $new_settings = $prev_settings = file_get_contents(_PS_ROOT_DIR_ . '/config/settings.inc.php');
                $cache_active = (bool) Tools::getValue('cache_active');
                if ($caching_system = Tools::getValue('caching_system')) {
                    $new_settings = preg_replace('/define\\(\'_PS_CACHING_SYSTEM_\', \'([a-z0-9=\\/+-_]*)\'\\);/Ui', 'define(\'_PS_CACHING_SYSTEM_\', \'' . $caching_system . '\');', $new_settings);
                } else {
                    $cache_active = false;
                    $this->errors[] = Tools::displayError('The caching system is missing.');
                }
                if ($cache_active) {
                    if ($caching_system == 'CacheMemcache' && !extension_loaded('memcache')) {
                        $this->errors[] = Tools::displayError('To use Memcached, you must install the Memcache PECL extension on your server.') . '
							<a href="http://www.php.net/manual/en/memcache.installation.php">http://www.php.net/manual/en/memcache.installation.php</a>';
                    } elseif ($caching_system == 'CacheApc' && !extension_loaded('apc')) {
                        $this->errors[] = Tools::displayError('To use APC cache, you must install the APC PECL extension on your server.') . '
							<a href="http://fr.php.net/manual/fr/apc.installation.php">http://fr.php.net/manual/fr/apc.installation.php</a>';
                    } elseif ($caching_system == 'CacheXcache' && !extension_loaded('xcache')) {
                        $this->errors[] = Tools::displayError('To use Xcache, you must install the Xcache extension on your server.') . '
							<a href="http://xcache.lighttpd.net">http://xcache.lighttpd.net</a>';
                    } elseif ($caching_system == 'CacheXcache' && !ini_get('xcache.var_size')) {
                        $this->errors[] = Tools::displayError('To use Xcache, you must configure "xcache.var_size" for the Xcache extension (recommended value 16M to 64M).') . '
							<a href="http://xcache.lighttpd.net/wiki/XcacheIni">http://xcache.lighttpd.net/wiki/XcacheIni</a>';
                    } elseif ($caching_system == 'CacheFs') {
                        if (!is_dir(_PS_CACHEFS_DIRECTORY_)) {
                            @mkdir(_PS_CACHEFS_DIRECTORY_, 0777, true);
                        } elseif (!is_writable(_PS_CACHEFS_DIRECTORY_)) {
                            $this->errors[] = sprintf(Tools::displayError('To use CacheFS, the directory %s must be writable.'), realpath(_PS_CACHEFS_DIRECTORY_));
                        }
                    }
                    if ($caching_system == 'CacheFs') {
                        if (!($depth = Tools::getValue('ps_cache_fs_directory_depth'))) {
                            $this->errors[] = Tools::displayError('Please set a directory depth.');
                        }
                        if (!count($this->errors)) {
                            CacheFs::deleteCacheDirectory();
                            CacheFs::createCacheDirectories((int) $depth);
                            Configuration::updateValue('PS_CACHEFS_DIRECTORY_DEPTH', (int) $depth);
                        }
                    } elseif ($caching_system == 'CacheMemcache' && !_PS_CACHE_ENABLED_ && _PS_CACHING_SYSTEM_ == 'CacheMemcache') {
                        Cache::getInstance()->flush();
                    }
                }
                if (!count($this->errors)) {
                    $new_settings = preg_replace('/define\\(\'_PS_CACHE_ENABLED_\', \'([01]?)\'\\);/Ui', 'define(\'_PS_CACHE_ENABLED_\', \'' . (int) $cache_active . '\');', $new_settings);
                    // If there is not settings file modification or if the backup and replacement of the settings file worked
                    if ($new_settings == $prev_settings || copy(_PS_ROOT_DIR_ . '/config/settings.inc.php', _PS_ROOT_DIR_ . '/config/settings.old.php') && (bool) file_put_contents(_PS_ROOT_DIR_ . '/config/settings.inc.php', $new_settings)) {
                        $redirectAdmin = true;
                    } else {
                        $this->errors[] = Tools::displayError('The settings file cannot be overwritten.');
                    }
                }
            } else {
                $this->errors[] = Tools::displayError('You do not have permission to edit this.');
            }
        }
        if ((bool) Tools::getValue('empty_smarty_cache')) {
            $redirectAdmin = true;
            Tools::clearSmartyCache();
            Tools::clearXMLCache();
            Media::clearCache();
            PrestaShopAutoload::getInstance()->generateIndex();
        }
        if (Tools::isSubmit('submitAddconfiguration') && _PS_MODE_DEV_) {
            Configuration::updateGlobalValue('PS_DISABLE_NON_NATIVE_MODULE', (int) Tools::getValue('native_module'));
            Configuration::updateGlobalValue('PS_DISABLE_OVERRIDES', (int) Tools::getValue('overrides'));
            if (Tools::getValue('overrides')) {
                PrestaShopAutoload::getInstance()->_include_override_path = false;
            }
            PrestaShopAutoload::getInstance()->generateIndex();
        }
        if ($redirectAdmin && (!isset($this->errors) || !count($this->errors))) {
            Hook::exec('action' . get_class($this) . ucfirst($this->action) . 'After', array('controller' => $this, 'return' => ''));
            Tools::redirectAdmin(self::$currentIndex . '&token=' . Tools::getValue('token') . '&conf=4');
        }
    }
 public function processSave()
 {
     /** @var ShopUrl $object */
     $object = $this->loadObject(true);
     if ($object->canAddThisUrl(Tools::getValue('domain'), Tools::getValue('domain_ssl'), Tools::getValue('physical_uri'), Tools::getValue('virtual_uri'))) {
         $this->errors[] = $this->trans('A shop URL that uses this domain already exists.', array(), 'Admin.Notifications.Error');
     }
     $unallowed = str_replace('/', '', Tools::getValue('virtual_uri'));
     if ($unallowed == 'c' || $unallowed == 'img' || is_numeric($unallowed)) {
         $this->errors[] = $this->trans('A shop virtual URL cannot be "%URL%"', array('%URL%' => $unallowed), 'Admin.Notifications.Error');
     }
     $return = parent::processSave();
     if (!$this->errors) {
         Tools::generateHtaccess();
         Tools::clearSmartyCache();
         Media::clearCache();
     }
     return $return;
 }
 public function postProcess()
 {
     Tools::clearSmartyCache();
     return parent::postProcess();
 }
 public function processSave()
 {
     $object = $this->loadObject(true);
     if ($object->canAddThisUrl(Tools::getValue('domain'), Tools::getValue('domain_ssl'), Tools::getValue('physical_uri'), Tools::getValue('virtual_uri'))) {
         $this->errors[] = Tools::displayError('A shop URL that uses this domain already exists.');
     }
     $return = parent::processSave();
     if (!$this->errors) {
         Tools::generateHtaccess();
         Tools::clearSmartyCache();
         Media::clearCache();
     }
     return $return;
 }
    public function getContent()
    {
        global $cookie;
        $errors = array();
        $html = '<div style="width:550px">
            <p style="text-align:center;"><a href="https://www.payubiz.in" target="_blank"><img src="' . __PS_BASE_URI__ . 'modules/payubiz/payu_logo_pack.png" alt="PayUbiz" boreder="0" /></a></p><br />';
        /* Update configuration variables */
        if (Tools::isSubmit('submitPAYUBIZ')) {
            if ($paynow_text = Tools::getValue('payubiz_paynow_text')) {
                Configuration::updateValue('PAYUBIZ_PAYNOW_TEXT', $paynow_text);
            }
            if ($paynow_logo = Tools::getValue('payubiz_paynow_logo')) {
                Configuration::updateValue('PAYUBIZ_PAYNOW_LOGO', $paynow_logo);
            }
            if ($paynow_align = Tools::getValue('payubiz_paynow_align')) {
                Configuration::updateValue('PAYUBIZ_PAYNOW_ALIGN', $paynow_align);
            }
            if ($merchant_id = Tools::getValue('payubiz_merchant_id')) {
                Configuration::updateValue('PAYUBIZ_MERCHANT_ID', $merchant_id);
            }
            if ($merchant_salt = Tools::getValue('payubiz_merchant_salt')) {
                Configuration::updateValue('PAYUBIZ_MERCHANT_SALT', $merchant_salt);
            }
            if ($payubiz_pg = Tools::getValue('pg')) {
                Configuration::updateValue('PAYUBIZ_PG', $payubiz_pg);
            }
            if ($payubiz_bankcode = Tools::getValue('bankcode')) {
                Configuration::updateValue('PAYUBIZ_BANKCODE', $payubiz_bankcode);
            }
            if ($payubiz_mode = Tools::getValue('payubiz_mode')) {
                Configuration::updateValue('PAYUBIZ_MODE', $payubiz_mode);
            }
            if (Tools::getValue('payubiz_logs')) {
                Configuration::updateValue('PAYUBIZ_LOGS', 1);
            } else {
                Configuration::updateValue('PAYUBIZ_LOGS', 0);
            }
            foreach (array('displayLeftColumn', 'displayRightColumn', 'displayFooter') as $hookName) {
                if ($this->isRegisteredInHook($hookName)) {
                    $this->unregisterHook($hookName);
                }
            }
            if (Tools::getValue('logo_position') == self::LEFT_COLUMN) {
                $this->registerHook('displayLeftColumn');
            } else {
                if (Tools::getValue('logo_position') == self::RIGHT_COLUMN) {
                    $this->registerHook('displayRightColumn');
                } else {
                    if (Tools::getValue('logo_position') == self::FOOTER) {
                        $this->registerHook('displayFooter');
                    }
                }
            }
            if (method_exists('Tools', 'clearSmartyCache')) {
                Tools::clearSmartyCache();
            }
        }
        /* Display errors */
        if (sizeof($errors)) {
            $html .= '<ul style="color: red; font-weight: bold; margin-bottom: 30px; width: 506px; background: #FFDFDF; border: 1px dashed #BBB; padding: 10px;">';
            foreach ($errors as $error) {
                $html .= '<li>' . $error . '</li>';
            }
            $html .= '</ul>';
        }
        $blockPositionList = array(self::DISABLE => $this->l('Disable'), self::FOOTER => $this->l('Enable'));
        if ($this->isRegisteredInHook('displayLeftColumn')) {
            $currentLogoBlockPosition = self::LEFT_COLUMN;
        } elseif ($this->isRegisteredInHook('displayRightColumn')) {
            $currentLogoBlockPosition = self::RIGHT_COLUMN;
        } elseif ($this->isRegisteredInHook('displayFooter')) {
            $currentLogoBlockPosition = self::FOOTER;
        } else {
            $currentLogoBlockPosition = -1;
        }
        /* Display settings form */
        $html .= '
        <form action="' . $_SERVER['REQUEST_URI'] . '" method="post">
          <fieldset>
          <legend><img src="' . __PS_BASE_URI__ . 'modules/payubiz/logo.png" />' . $this->l('Settings') . '</legend>
            <p>' . $this->l('Use the "Test" mode to test out the module then you can use the "Live" mode if no problems arise. Remember to insert your merchant key and ID for the live mode.') . '</p>
            <label>
              ' . $this->l('Mode') . '
            </label>
            <div class="margin-form" style="width:110px;">
              <select name="payubiz_mode">
                <option value="live"' . (Configuration::get('PAYUBIZ_MODE') == 'live' ? ' selected="selected"' : '') . '>' . $this->l('Live') . '&nbsp;&nbsp;</option>
                <option value="test"' . (Configuration::get('PAYUBIZ_MODE') == 'test' ? ' selected="selected"' : '') . '>' . $this->l('Test') . '&nbsp;&nbsp;</option>
              </select>
            </div>

            <p>' . $this->l('You can find your Merchant ID and Merchant Salt in your PayUbiz account.') . '</p>
            <label>
              ' . $this->l('Merchant ID') . '
            </label>
            <div class="margin-form">
              <input type="text" name="payubiz_merchant_id" value="' . Tools::getValue('payubiz_merchant_id', Configuration::get('PAYUBIZ_MERCHANT_ID')) . '" />
            </div>
            <label>
              ' . $this->l('Merchant Salt') . '
            </label>
            <div class="margin-form">
              <input type="text" name="payubiz_merchant_salt" value="' . trim(Tools::getValue('payubiz_merchant_salt', Configuration::get('PAYUBIZ_MERCHANT_SALT'))) . '" />
            </div> 

          

            <p>' . $this->l('Select Your pg value as per you need Please Select PayUbiz by default') . '</p>

              <label>
              ' . $this->l('Payment Gateway') . '
            </label>
            <div class="margin-form" style="width:110px;">
              <select name="pg">
                <option value="null"' . (Configuration::get('PAYUBIZ_PG') == 'null' ? ' selected="selected"' : '') . '>' . $this->l('PayUBiz') . '&nbsp;&nbsp;</option>
                <option value="CC"' . (Configuration::get('PAYUBIZ_PG') == 'CC' ? ' selected="selected"' : '') . '>' . $this->l('Credit Card') . '&nbsp;&nbsp;</option>

                <option value="DC"' . (Configuration::get('PAYUBIZ_PG') == 'DC' ? ' selected="selected"' : '') . '>' . $this->l('Debit Card') . '&nbsp;&nbsp;</option>
                <option value="NB"' . (Configuration::get('PAYUBIZ_PG') == 'NB' ? ' selected="selected"' : '') . '>' . $this->l('NetBanking') . '&nbsp;&nbsp;</option>
                <option value="wallet"' . (Configuration::get('PAYUBIZ_PG') == 'wallet' ? ' selected="selected"' : '') . '>' . $this->l('PayUMoney') . '&nbsp;&nbsp;</option>
                </select>
            </div>

             <p>' . $this->l('Select Your bankcode value as per you need Please Select PayUbiz by default') . '</p>

              <label>
              ' . $this->l('Bankcode') . '
            </label>
            <div class="margin-form" style="width:110px;">
              <select name="bankcode">
                <option value="null"' . (Configuration::get('PAYUBIZ_BANKCODE') == 'null' ? ' selected="selected"' : '') . '>' . $this->l('PayUbiz') . '&nbsp;&nbsp;</option>
                <option value="payuw"' . (Configuration::get('PAYUBIZ_BANKCODE') == 'payuw' ? ' selected="selected"' : '') . '>' . $this->l('PayUw- PayUMoney') . '&nbsp;&nbsp;</option>
                <option value="BBCB"' . (Configuration::get('PAYUBIZ_BANKCODE') == 'BBCB' ? ' selected="selected"' : '') . '>' . $this->l('Bank of Baroda Corporate Banking') . '&nbsp;&nbsp;</option>
                <option value="ALLB"' . (Configuration::get('PAYUBIZ_BANKCODE') == 'ALLB' ? ' selected="selected"' : '') . '>' . $this->l('Allahabad Bank NetBanking') . '&nbsp;&nbsp;</option>

                <option value="ADBB"' . (Configuration::get('PAYUBIZ_BANKCODE') == 'ADBB' ? ' selected="selected"' : '') . '>' . $this->l('Andhra Bank') . '&nbsp;&nbsp;</option>

                    <option value="AXIB"' . (Configuration::get('PAYUBIZ_BANKCODE') == 'AXIB' ? ' selected="selected"' : '') . '>' . $this->l('AXIS Bank NetBanking') . '&nbsp;&nbsp;</option>
                    <option value="BBKB"' . (Configuration::get('PAYUBIZ_BANKCODE') == 'BBKB' ? ' selected="selected"' : '') . '>' . $this->l('Bank of Bahrain and Kuwait') . '&nbsp;&nbsp;</option>
                    <option value="BBRB"' . (Configuration::get('PAYUBIZ_BANKCODE') == 'BBRB' ? ' selected="selected"' : '') . '>' . $this->l('Bank of Baroda Retail Banking') . '&nbsp;&nbsp;</option>
                    <option value="BOIB"' . (Configuration::get('PAYUBIZ_BANKCODE') == 'BOIB' ? ' selected="selected"' : '') . '>' . $this->l('Bank of India') . '&nbsp;&nbsp;</option>

                    <option value="BOMB"' . (Configuration::get('PAYUBIZ_BANKCODE') == 'BOMB' ? ' selected="selected"' : '') . '>' . $this->l('Bank of Maharashtra') . '&nbsp;&nbsp;</option>

                    <option value="CABB"' . (Configuration::get('PAYUBIZ_BANKCODE') == 'CABB' ? ' selected="selected"' : '') . '>' . $this->l('Canara Bank') . '&nbsp;&nbsp;</option>

                    <option value="CSBN"' . (Configuration::get('PAYUBIZ_BANKCODE') == 'CSBN' ? ' selected="selected"' : '') . '>' . $this->l('Catholic Syrian Bank') . '&nbsp;&nbsp;</option>

                    <option value="CBIB"' . (Configuration::get('PAYUBIZ_BANKCODE') == 'CBIB' ? ' selected="selected"' : '') . '>' . $this->l('Central Bank Of India') . '&nbsp;&nbsp;</option>

                    <option value="CITNB"' . (Configuration::get('PAYUBIZ_BANKCODE') == 'CITNB' ? ' selected="selected"' : '') . '>' . $this->l('Citi Bank NetBanking') . '&nbsp;&nbsp;</option>

                    <option value="CUBB"' . (Configuration::get('PAYUBIZ_BANKCODE') == 'CUBB' ? ' selected="selected"' : '') . '>' . $this->l('CityUnion') . '&nbsp;&nbsp;</option>

                    <option value="CRPB"' . (Configuration::get('PAYUBIZ_BANKCODE') == 'CRPB' ? ' selected="selected"' : '') . '>' . $this->l('Corporation Bank') . '&nbsp;&nbsp;</option>

                    <option value="DCBCORP"' . (Configuration::get('PAYUBIZ_BANKCODE') == 'DCBCORP' ? ' selected="selected"' : '') . '>' . $this->l('DCB Bank - Corporate Netbanking') . '&nbsp;&nbsp;</option>
                    <option value="DENN"' . (Configuration::get('PAYUBIZ_BANKCODE') == 'DENN' ? ' selected="selected"' : '') . '>' . $this->l('Dena Bank') . '&nbsp;&nbsp;</option>

                    <option value="DSHB"' . (Configuration::get('PAYUBIZ_BANKCODE') == 'DSHB' ? ' selected="selected"' : '') . '>' . $this->l('Deutsche Bank') . '&nbsp;&nbsp;</option>

                    <option value="DCBB"' . (Configuration::get('PAYUBIZ_BANKCODE') == 'DCBB' ? ' selected="selected"' : '') . '>' . $this->l('Development Credit Bank') . '&nbsp;&nbsp;</option>

                    <option value="FEDB"' . (Configuration::get('PAYUBIZ_BANKCODE') == 'FEDB' ? ' selected="selected"' : '') . '>' . $this->l('Federal Bank') . '&nbsp;&nbsp;</option>

                    <option value="HDFB"' . (Configuration::get('PAYUBIZ_BANKCODE') == 'HDFB' ? ' selected="selected"' : '') . '>' . $this->l('HDFC Bank') . '&nbsp;&nbsp;</option>

                    <option value="ICIB"' . (Configuration::get('PAYUBIZ_BANKCODE') == 'ICIB' ? ' selected="selected"' : '') . '>' . $this->l('ICICI Netbanking') . '&nbsp;&nbsp;</option>

                    <option value="INDB"' . (Configuration::get('PAYUBIZ_BANKCODE') == 'Indian Bank' ? ' selected="selected"' : '') . '>' . $this->l('Indian Bank') . '&nbsp;&nbsp;</option>

                    <option value="INOB"' . (Configuration::get('PAYUBIZ_BANKCODE') == 'INOB' ? ' selected="selected"' : '') . '>' . $this->l('Indian Overseas Bank') . '&nbsp;&nbsp;</option>


                    <option value="INIB"' . (Configuration::get('PAYUBIZ_BANKCODE') == 'INIB' ? ' selected="selected"' : '') . '>' . $this->l('IndusInd Bank') . '&nbsp;&nbsp;</option>

                    <option value="IDBB"' . (Configuration::get('PAYUBIZ_BANKCODE') == 'IDBB' ? ' selected="selected"' : '') . '>' . $this->l('Industrial Development Bank of India') . '&nbsp;&nbsp;</option>

                    <option value="INGB"' . (Configuration::get('PAYUBIZ_BANKCODE') == 'INGB' ? ' selected="selected"' : '') . '>' . $this->l('ING Vysya Bank') . '&nbsp;&nbsp;</option>

                    <option value="JAKB"' . (Configuration::get('PAYUBIZ_BANKCODE') == 'JAKB' ? ' selected="selected"' : '') . '>' . $this->l('Jammu and Kashmir Bank') . '&nbsp;&nbsp;</option>

                    <option value="KRKB"' . (Configuration::get('PAYUBIZ_BANKCODE') == 'KRKB' ? ' selected="selected"' : '') . '>' . $this->l('Karnataka Bank') . '&nbsp;&nbsp;</option>

                    <option value="KRVB"' . (Configuration::get('PAYUBIZ_BANKCODE') == 'KRVB' ? ' selected="selected"' : '') . '>' . $this->l('Karur Vysya') . '&nbsp;&nbsp;</option>

                    <option value="KRVB"' . (Configuration::get('PAYUBIZ_BANKCODE') == 'KRVB' ? ' selected="selected"' : '') . '>' . $this->l('Karur Vysya - Corporate Netbanking') . '&nbsp;&nbsp;</option>

                    <option value="162B"' . (Configuration::get('PAYUBIZ_BANKCODE') == '162B' ? ' selected="selected"' : '') . '>' . $this->l('Kotak Bank') . '&nbsp;&nbsp;</option>

                    <option value="LVCB"' . (Configuration::get('PAYUBIZ_BANKCODE') == 'LVCB' ? ' selected="selected"' : '') . '>' . $this->l('Laxmi Vilas Bank-Corporate') . '&nbsp;&nbsp;</option>

                    <option value="LVRB"' . (Configuration::get('PAYUBIZ_BANKCODE') == 'LVRB' ? ' selected="selected"' : '') . '>' . $this->l('Laxmi Vilas Bank-Retail') . '&nbsp;&nbsp;</option>

                    <option value="OBCB"' . (Configuration::get('PAYUBIZ_BANKCODE') == 'OBCB' ? ' selected="selected"' : '') . '>' . $this->l('Oriental Bank of Commerce') . '&nbsp;&nbsp;</option>

                    <option value="PNBB"' . (Configuration::get('PAYUBIZ_BANKCODE') == 'PNBB' ? ' selected="selected"' : '') . '>' . $this->l('Punjab National Bank - Retail Banking') . '&nbsp;&nbsp;</option>

                    <option value="CPNB"' . (Configuration::get('PAYUBIZ_BANKCODE') == 'CPNB' ? ' selected="selected"' : '') . '>' . $this->l('Punjab National Bank-Corporate') . '&nbsp;&nbsp;</option>

                    <option value="RTN"' . (Configuration::get('PAYUBIZ_BANKCODE') == 'RTN' ? ' selected="selected"' : '') . '>' . $this->l('Ratnakar Bank') . '&nbsp;&nbsp;</option>

                    <option value="SRSWT"' . (Configuration::get('PAYUBIZ_BANKCODE') == 'SRSWT' ? ' selected="selected"' : '') . '>' . $this->l('Saraswat Bank') . '&nbsp;&nbsp;</option>

                    <option value="SVCB"' . (Configuration::get('PAYUBIZ_BANKCODE') == 'SVCB' ? ' selected="selected"' : '') . '>' . $this->l('Shamrao Vitthal Co-operative Bank') . '&nbsp;&nbsp;</option>

                    <option value="SOIB"' . (Configuration::get('PAYUBIZ_BANKCODE') == 'SOIB' ? ' selected="selected"' : '') . '>' . $this->l('South Indian Bank') . '&nbsp;&nbsp;</option>

                    <option value="SDCB"' . (Configuration::get('PAYUBIZ_BANKCODE') == 'SDCB' ? ' selected="selected"' : '') . '>' . $this->l('Standard Chartered Bank') . '&nbsp;&nbsp;</option>

                    <option value="SBBJB"' . (Configuration::get('PAYUBIZ_BANKCODE') == 'SBBJB' ? ' selected="selected"' : '') . '>' . $this->l('State Bank of Bikaner and Jaipur') . '&nbsp;&nbsp;</option>

                    <option value="SBHB"' . (Configuration::get('PAYUBIZ_BANKCODE') == 'SBHB' ? ' selected="selected"' : '') . '>' . $this->l('State Bank of Hyderabad') . '&nbsp;&nbsp;</option>

                    <option value="SBIB"' . (Configuration::get('PAYUBIZ_BANKCODE') == 'SBIB' ? ' selected="selected"' : '') . '>' . $this->l('State Bank of India') . '&nbsp;&nbsp;</option>

                    <option value="SBMB"' . (Configuration::get('PAYUBIZ_BANKCODE') == 'SBMB' ? ' selected="selected"' : '') . '>' . $this->l('State Bank of Mysore') . '&nbsp;&nbsp;</option>

                    <option value="SBPB"' . (Configuration::get('PAYUBIZ_BANKCODE') == ' SBPB' ? ' selected="selected"' : '') . '>' . $this->l('State Bank of Patiala') . '&nbsp;&nbsp;</option>

                    <option value="SBTB"' . (Configuration::get('PAYUBIZ_BANKCODE') == 'SBTB' ? ' selected="selected"' : '') . '>' . $this->l('State Bank of Travancore') . '&nbsp;&nbsp;</option>

                    <option value="UBIBC"' . (Configuration::get('PAYUBIZ_BANKCODE') == 'UBIBC' ? ' selected="selected"' : '') . '>' . $this->l('Union Bank - Corporate Netbanking') . '&nbsp;&nbsp;</option>

                    <option value="UBIB"' . (Configuration::get('PAYUBIZ_BANKCODE') == 'UBIB' ? ' selected="selected"' : '') . '>' . $this->l('Union Bank of India') . '&nbsp;&nbsp;</option>

                    <option value="UNIB"' . (Configuration::get('PAYUBIZ_BANKCODE') == 'UNIB' ? ' selected="selected"' : '') . '>' . $this->l('United Bank Of India') . '&nbsp;&nbsp;</option>

                    <option value="VJYB"' . (Configuration::get('PAYUBIZ_BANKCODE') == 'VJYB' ? ' selected="selected"' : '') . '>' . $this->l('Vijaya Bank') . '&nbsp;&nbsp;</option>

                    <option value="YESB"' . (Configuration::get('PAYUBIZ_BANKCODE') == 'YESB' ? ' selected="selected"' : '') . '>' . $this->l('Yes Bank') . '&nbsp;&nbsp;</option>
                </select>
            </div>

            
            
            <p>' . $this->l('You can log the server-to-server communication. The log file for debugging can be found at ') . ' ' . __PS_BASE_URI__ . 'modules/payubiz/payubiz.log. ' . $this->l('If activated, be sure to protect it by putting a .htaccess file in the same directory. If not, the file will be readable by everyone.') . '</p>       
            <label>
              ' . $this->l('Debug') . '
            </label>
            <div class="margin-form" style="margin-top:5px">
              <input type="checkbox" name="payubiz_logs"' . (Tools::getValue('payubiz_logs', Configuration::get('PAYUBIZ_LOGS')) ? ' checked="checked"' : '') . ' />
            </div>
            <p>' . $this->l('During checkout the following is what the client gets to click on to pay with PayUbiz.') . '</p>            
            <label>&nbsp;</label>
            <div class="margin-form" style="margin-top:5px">
                ' . Configuration::get('PAYUBIZ_PAYNOW_TEXT');
        if (Configuration::get('PAYUBIZ_PAYNOW_LOGO') == 'on') {
            $html .= '<img align="' . Configuration::get('PAYUBIZ_PAYNOW_ALIGN') . '" alt="Pay Now With PayUbiz" title="Pay Now With PayUbiz" src="' . __PS_BASE_URI__ . 'modules/payubiz/logo.png">';
        }
        $html .= '</div>
            <label>
            ' . $this->l('PayNow Text') . '
            </label>
            <div class="margin-form" style="margin-top:5px">
                <input type="text" name="payubiz_paynow_text" value="' . Configuration::get('PAYUBIZ_PAYNOW_TEXT') . '">
            </div>
            <label>
            ' . $this->l('PayNow Logo') . '
            </label>
            <div class="margin-form" style="margin-top:5px">
                <input type="radio" name="payubiz_paynow_logo" value="off" ' . (Configuration::get('PAYUBIZ_PAYNOW_LOGO') == 'off' ? ' checked="checked"' : '') . '"> &nbsp; ' . $this->l('None') . '<br>
                <input type="radio" name="payubiz_paynow_logo" value="on" ' . (Configuration::get('PAYUBIZ_PAYNOW_LOGO') == 'on' ? ' checked="checked"' : '') . '"> &nbsp; <img src="' . __PS_BASE_URI__ . 'modules/payubiz/logo.png">
            </div>
            <label>
            ' . $this->l('PayNow Logo Align') . '
            </label>
            <div class="margin-form" style="margin-top:5px">
                <input type="radio" name="payubiz_paynow_align" value="left" ' . (Configuration::get('PAYUBIZ_PAYNOW_ALIGN') == 'left' ? ' checked="checked"' : '') . '"> &nbsp; ' . $this->l('Left') . '<br>
                <input type="radio" name="payubiz_paynow_align" value="right" ' . (Configuration::get('PAYUBIZ_PAYNOW_ALIGN') == 'right' ? ' checked="checked"' : '') . '"> &nbsp; ' . $this->l('Right') . '
            </div>
            <p>' . $this->l('Where would you like the the Secure Payments made with PayUbiz image to appear on your website?') . '</p>
            <label>
            ' . $this->l('Select the image position') . '
            </label>
            <div class="margin-form" style="margin-bottom:18px;width:110px;">
                  <select name="logo_position">';
        foreach ($blockPositionList as $position => $translation) {
            $selected = $currentLogoBlockPosition == $position ? 'selected="selected"' : '';
            $html .= '<option value="' . $position . '" ' . $selected . '>' . $translation . '</option>';
        }
        $html .= '</select></div>

            <div style="float:right;"><input type="submit" name="submitPAYUBIZ" class="button" value="' . $this->l('   Save   ') . '" /></div><div class="clear"></div>
          </fieldset>
        </form>
        <br /><br />
        <fieldset>
          <legend><img src="../img/admin/warning.gif" />' . $this->l('Information') . '</legend>
          <p>- ' . $this->l('In order to use your PayUbiz module, you must insert your PayUbiz Merchant ID and Merchant Salt above.') . '</p>         
        </fieldset>
        </div>';
        return $html;
    }
<?php

include dirname(__FILE__) . '/../config/config.inc.php';
include dirname(__FILE__) . '/../init.php';
Tools::clearSmartyCache();
 public function processSave()
 {
     $object = $this->loadObject(true);
     if ($object->canAddThisUrl(Tools::getValue('domain'), Tools::getValue('domain_ssl'), Tools::getValue('physical_uri'), Tools::getValue('virtual_uri'))) {
         $this->errors[] = Tools::displayError('A shop URL that uses this domain already exists.');
     }
     if (str_replace('/', '', Tools::getValue('virtual_uri')) == 'c') {
         $this->errors[] = Tools::displayError('A shop virtual URL can not be "/c/", because "/c/" is the virtual url prefix for category images.');
     }
     $return = parent::processSave();
     if (!$this->errors) {
         Tools::generateHtaccess();
         Tools::clearSmartyCache();
         Media::clearCache();
     }
     return $return;
 }
Example #13
0
 function psmClearCache()
 {
     Tools::clearSmartyCache();
     Media::clearCache();
     Tools::generateIndex();
 }
Example #14
0
 public static function clear_smarty_cache()
 {
     $configuration = PS_CLI_Configure::getConfigurationInstance();
     echo "Clearing cache...\n";
     if ($configuration->verbose) {
         echo "Smarty cache ";
     }
     Tools::clearSmartyCache();
     if ($configuration->verbose) {
         echo "[OK]\nXML cache ";
     }
     Tools::clearXMLCache();
     if ($configuration->verbose) {
         echo "[OK]\nClearing media cache ";
     }
     Media::clearCache();
     if ($configuration->verbose) {
         echo "[OK]\nRegenerating index ";
     }
     Tools::generateIndex();
     if ($configuration->verbose) {
         echo "[OK]\n";
     }
     echo "Done !\n";
     return true;
 }
    public function postProcess()
    {
        /* PrestaShop demo mode */
        if (_PS_MODE_DEMO_) {
            $this->errors[] = $this->trans('This functionality has been disabled.', array(), 'Admin.Notifications.Error');
            return;
        }
        Hook::exec('action' . get_class($this) . ucfirst($this->action) . 'Before', array('controller' => $this));
        if (Tools::isSubmit('submitAddServer')) {
            if ($this->access('add')) {
                if (!Tools::getValue('memcachedIp')) {
                    $this->errors[] = $this->trans('The Memcached IP is missing.', array(), 'Admin.Parameters.Notification');
                }
                if (!Tools::getValue('memcachedPort')) {
                    $this->errors[] = $this->trans('The Memcached port is missing.', array(), 'Admin.Parameters.Notification');
                }
                if (!Tools::getValue('memcachedWeight')) {
                    $this->errors[] = $this->trans('The Memcached weight is missing.', array(), 'Admin.Parameters.Notification');
                }
                if (!count($this->errors)) {
                    if (CacheMemcache::addServer(pSQL(Tools::getValue('memcachedIp')), (int) Tools::getValue('memcachedPort'), (int) Tools::getValue('memcachedWeight'))) {
                        Tools::redirectAdmin(self::$currentIndex . '&token=' . Tools::getValue('token') . '&conf=4');
                    } else {
                        $this->errors[] = $this->trans('The Memcached server cannot be added.', array(), 'Admin.Parameters.Notification');
                    }
                }
            } else {
                $this->errors[] = $this->trans('You do not have permission to add this.', array(), 'Admin.Notifications.Error');
            }
        }
        if (Tools::getValue('deleteMemcachedServer')) {
            if ($this->access('add')) {
                if (CacheMemcache::deleteServer((int) Tools::getValue('deleteMemcachedServer'))) {
                    Tools::redirectAdmin(self::$currentIndex . '&token=' . Tools::getValue('token') . '&conf=4');
                } else {
                    $this->errors[] = $this->trans('There was an error when attempting to delete the Memcached server.', array(), 'Admin.Parameters.Notification');
                }
            } else {
                $this->errors[] = $this->trans('You do not have permission to delete this.', array(), 'Admin.Notifications.Error');
            }
        }
        $redirectAdmin = false;
        if ((bool) Tools::getValue('smarty_up')) {
            if ($this->access('edit')) {
                Configuration::updateValue('PS_SMARTY_FORCE_COMPILE', Tools::getValue('smarty_force_compile', _PS_SMARTY_NO_COMPILE_));
                if (Configuration::get('PS_SMARTY_CACHE') != Tools::getValue('smarty_cache')) {
                    Tools::clearSmartyCache();
                }
                Configuration::updateValue('PS_SMARTY_CACHE', Tools::getValue('smarty_cache', 0));
                Configuration::updateValue('PS_SMARTY_CLEAR_CACHE', Tools::getValue('smarty_clear_cache'));
                Configuration::updateValue('PS_SMARTY_LOCAL', Tools::getValue('smarty_local', 0));
                $redirectAdmin = true;
            } else {
                $this->errors[] = $this->trans('You do not have permission to edit this.', array(), 'Admin.Notifications.Error');
            }
        }
        if ((bool) Tools::getValue('features_detachables_up')) {
            if ($this->access('edit')) {
                if (Tools::isSubmit('combination')) {
                    if ((!Tools::getValue('combination') && Combination::isCurrentlyUsed()) === false) {
                        Configuration::updateValue('PS_COMBINATION_FEATURE_ACTIVE', (bool) Tools::getValue('combination'));
                    }
                }
                if (Tools::isSubmit('customer_group')) {
                    if ((!Tools::getValue('customer_group') && Group::isCurrentlyUsed()) === false) {
                        Configuration::updateValue('PS_GROUP_FEATURE_ACTIVE', (bool) Tools::getValue('customer_group'));
                    }
                }
                Configuration::updateValue('PS_FEATURE_FEATURE_ACTIVE', (bool) Tools::getValue('feature'));
                $redirectAdmin = true;
            } else {
                $this->errors[] = $this->trans('You do not have permission to edit this.', array(), 'Admin.Notifications.Error');
            }
        }
        if ((bool) Tools::getValue('ccc_up')) {
            if ($this->access('edit')) {
                $theme_cache_directory = _PS_ALL_THEMES_DIR_ . $this->context->shop->theme_directory . '/cache/';
                @mkdir($theme_cache_directory, 0777, true);
                if (((bool) Tools::getValue('PS_CSS_THEME_CACHE') || (bool) Tools::getValue('PS_JS_THEME_CACHE')) && !is_writable($theme_cache_directory)) {
                    $this->errors[] = $this->trans('To use Smart Cache, the directory %directorypath% must be writable.', array('%directorypath%' => realpath($theme_cache_directory)), 'Admin.Parameters.Notification');
                }
                if ($tmp = (int) Tools::getValue('PS_CSS_THEME_CACHE')) {
                    $version = (int) Configuration::get('PS_CCCCSS_VERSION');
                    if (Configuration::get('PS_CSS_THEME_CACHE') != $tmp) {
                        Configuration::updateValue('PS_CCCCSS_VERSION', ++$version);
                    }
                }
                if ($tmp = (int) Tools::getValue('PS_JS_THEME_CACHE')) {
                    $version = (int) Configuration::get('PS_CCCJS_VERSION');
                    if (Configuration::get('PS_JS_THEME_CACHE') != $tmp) {
                        Configuration::updateValue('PS_CCCJS_VERSION', ++$version);
                    }
                }
                if (!Configuration::updateValue('PS_CSS_THEME_CACHE', (int) Tools::getValue('PS_CSS_THEME_CACHE')) || !Configuration::updateValue('PS_JS_THEME_CACHE', (int) Tools::getValue('PS_JS_THEME_CACHE')) || !Configuration::updateValue('PS_HTML_THEME_COMPRESSION', (int) Tools::getValue('PS_HTML_THEME_COMPRESSION')) || !Configuration::updateValue('PS_JS_HTML_THEME_COMPRESSION', (int) Tools::getValue('PS_JS_HTML_THEME_COMPRESSION')) || !Configuration::updateValue('PS_JS_DEFER', (int) Tools::getValue('PS_JS_DEFER')) || !Configuration::updateValue('PS_HTACCESS_CACHE_CONTROL', (int) Tools::getValue('PS_HTACCESS_CACHE_CONTROL'))) {
                    $this->errors[] = $this->trans('Unknown error.', array(), 'Admin.Notifications.Error');
                } else {
                    $redirectAdmin = true;
                    if (Configuration::get('PS_HTACCESS_CACHE_CONTROL')) {
                        if (is_writable(_PS_ROOT_DIR_ . '/.htaccess')) {
                            Tools::generateHtaccess();
                        } else {
                            $message = $this->l('Before being able to use this tool, you need to:');
                            $message .= '<br />- ' . $this->l('Create a blank .htaccess in your root directory.');
                            $message .= '<br />- ' . $this->l('Give it write permissions (CHMOD 666 on Unix system).');
                            $this->errors[] = Tools::displayError($message, false);
                            Configuration::updateValue('PS_HTACCESS_CACHE_CONTROL', false);
                        }
                    }
                }
            } else {
                $this->errors[] = $this->trans('You do not have permission to edit this.', array(), 'Admin.Notifications.Error');
            }
        }
        if ((bool) Tools::getValue('media_server_up') && !defined('_PS_HOST_MODE_')) {
            if ($this->access('edit')) {
                if (Tools::getValue('_MEDIA_SERVER_1_') != null && !Validate::isFileName(Tools::getValue('_MEDIA_SERVER_1_'))) {
                    $this->errors[] = $this->trans('Media server #1 is invalid', array(), 'Admin.Parameters.Notification');
                }
                if (Tools::getValue('_MEDIA_SERVER_2_') != null && !Validate::isFileName(Tools::getValue('_MEDIA_SERVER_2_'))) {
                    $this->errors[] = $this->trans('Media server #2 is invalid', array(), 'Admin.Parameters.Notification');
                }
                if (Tools::getValue('_MEDIA_SERVER_3_') != null && !Validate::isFileName(Tools::getValue('_MEDIA_SERVER_3_'))) {
                    $this->errors[] = $this->trans('Media server #3 is invalid', array(), 'Admin.Parameters.Notification');
                }
                if (!count($this->errors)) {
                    $base_urls = array();
                    $base_urls['_MEDIA_SERVER_1_'] = Tools::getValue('_MEDIA_SERVER_1_');
                    $base_urls['_MEDIA_SERVER_2_'] = Tools::getValue('_MEDIA_SERVER_2_');
                    $base_urls['_MEDIA_SERVER_3_'] = Tools::getValue('_MEDIA_SERVER_3_');
                    if ($base_urls['_MEDIA_SERVER_1_'] || $base_urls['_MEDIA_SERVER_2_'] || $base_urls['_MEDIA_SERVER_3_']) {
                        Configuration::updateValue('PS_MEDIA_SERVERS', 1);
                    } else {
                        Configuration::updateValue('PS_MEDIA_SERVERS', 0);
                    }
                    rewriteSettingsFile($base_urls, null, null);
                    Configuration::updateValue('PS_MEDIA_SERVER_1', Tools::getValue('_MEDIA_SERVER_1_'));
                    Configuration::updateValue('PS_MEDIA_SERVER_2', Tools::getValue('_MEDIA_SERVER_2_'));
                    Configuration::updateValue('PS_MEDIA_SERVER_3', Tools::getValue('_MEDIA_SERVER_3_'));
                    Tools::clearSmartyCache();
                    Media::clearCache();
                    if (is_writable(_PS_ROOT_DIR_ . '/.htaccess')) {
                        Tools::generateHtaccess(null, null, null, '', null, array($base_urls['_MEDIA_SERVER_1_'], $base_urls['_MEDIA_SERVER_2_'], $base_urls['_MEDIA_SERVER_3_']));
                        unset($this->_fieldsGeneral['_MEDIA_SERVER_1_']);
                        unset($this->_fieldsGeneral['_MEDIA_SERVER_2_']);
                        unset($this->_fieldsGeneral['_MEDIA_SERVER_3_']);
                        $redirectAdmin = true;
                    } else {
                        $message = $this->l('Before being able to use this tool, you need to:');
                        $message .= '<br />- ' . $this->l('Create a blank .htaccess in your root directory.');
                        $message .= '<br />- ' . $this->l('Give it write permissions (CHMOD 666 on Unix system).');
                        $this->errors[] = Tools::displayError($message, false);
                        Configuration::updateValue('PS_HTACCESS_CACHE_CONTROL', false);
                    }
                }
            } else {
                $this->errors[] = $this->trans('You do not have permission to edit this.', array(), 'Admin.Notifications.Error');
            }
        }
        if ((bool) Tools::getValue('cache_up')) {
            if ($this->access('edit')) {
                $config = Yaml::parse(_PS_ROOT_DIR_ . '/app/config/parameters.yml');
                $cache_active = (bool) Tools::getValue('cache_active');
                if ($caching_system = preg_replace('[^a-zA-Z0-9]', '', Tools::getValue('caching_system'))) {
                    $config['parameters']['ps_caching'] = $caching_system;
                } else {
                    $cache_active = false;
                    $this->errors[] = $this->trans('The caching system is missing.', array(), 'Admin.Parameters.Notification');
                }
                if ($cache_active) {
                    if ($caching_system == 'CacheMemcache' && !extension_loaded('memcache')) {
                        $this->errors[] = $this->trans('To use Memcached, you must install the Memcache PECL extension on your server.', array(), 'Admin.Parameters.Notification') . '
							<a href="http://www.php.net/manual/en/memcache.installation.php">http://www.php.net/manual/en/memcache.installation.php</a>';
                    } elseif ($caching_system == 'CacheMemcached' && !extension_loaded('memcached')) {
                        $this->errors[] = $this->trans('To use Memcached, you must install the Memcached PECL extension on your server.', array(), 'Admin.Parameters.Notification') . '
							<a href="http://www.php.net/manual/en/memcached.installation.php">http://www.php.net/manual/en/memcached.installation.php</a>';
                    } elseif ($caching_system == 'CacheApc' && !extension_loaded('apc') && !extension_loaded('apcu')) {
                        $this->errors[] = $this->trans('To use APC cache, you must install the APC PECL extension on your server.', array(), 'Admin.Parameters.Notification') . '
							<a href="http://fr.php.net/manual/fr/apc.installation.php">http://fr.php.net/manual/fr/apc.installation.php</a>';
                    } elseif ($caching_system == 'CacheXcache' && !extension_loaded('xcache')) {
                        $this->errors[] = $this->trans('To use Xcache, you must install the Xcache extension on your server.', array(), 'Admin.Parameters.Notification') . '
							<a href="http://xcache.lighttpd.net">http://xcache.lighttpd.net</a>';
                    } elseif ($caching_system == 'CacheXcache' && !ini_get('xcache.var_size')) {
                        $this->errors[] = $this->trans('To use Xcache, you must configure "xcache.var_size" for the Xcache extension (recommended value 16M to 64M).', array(), 'Admin.Parameters.Notification') . '
							<a href="http://xcache.lighttpd.net/wiki/XcacheIni">http://xcache.lighttpd.net/wiki/XcacheIni</a>';
                    } elseif ($caching_system == 'CacheFs') {
                        if (!is_dir(_PS_CACHEFS_DIRECTORY_)) {
                            @mkdir(_PS_CACHEFS_DIRECTORY_, 0777, true);
                        } elseif (!is_writable(_PS_CACHEFS_DIRECTORY_)) {
                            $this->errors[] = $this->trans('To use CacheFS, the directory %directorypath% must be writable.', array('%directorypath%' => realpath(_PS_CACHEFS_DIRECTORY_)), 'Admin.Parameters.Notification');
                        }
                    }
                    if ($caching_system == 'CacheFs') {
                        if (!($depth = Tools::getValue('ps_cache_fs_directory_depth'))) {
                            $this->errors[] = $this->trans('Please set a directory depth.', array(), 'Admin.Parameters.Notification');
                        }
                        if (!count($this->errors)) {
                            CacheFs::deleteCacheDirectory();
                            CacheFs::createCacheDirectories((int) $depth);
                            Configuration::updateValue('PS_CACHEFS_DIRECTORY_DEPTH', (int) $depth);
                        }
                    } elseif ($caching_system == 'CacheMemcache' && !_PS_CACHE_ENABLED_ && _PS_CACHING_SYSTEM_ == 'CacheMemcache') {
                        Cache::getInstance()->flush();
                    } elseif ($caching_system == 'CacheMemcached' && !_PS_CACHE_ENABLED_ && _PS_CACHING_SYSTEM_ == 'CacheMemcached') {
                        Cache::getInstance()->flush();
                    }
                }
                if (!count($this->errors)) {
                    $config['parameters']['ps_cache_enable'] = $cache_active;
                    // If there is not settings file modification or if the backup and replacement of the settings file worked
                    if (file_put_contents(_PS_ROOT_DIR_ . '/app/config/parameters.yml', Yaml::dump($config))) {
                        if (function_exists('opcache_invalidate')) {
                            opcache_invalidate(_PS_ROOT_DIR_ . '/app/config/parameters.yml');
                        }
                        $redirectAdmin = true;
                    } else {
                        $this->errors[] = $this->trans('The settings file cannot be overwritten.', array(), 'Admin.Parameters.Notification');
                    }
                }
            } else {
                $this->errors[] = $this->trans('You do not have permission to edit this.', array(), 'Admin.Notifications.Error');
            }
        }
        if ((bool) Tools::getValue('empty_smarty_cache')) {
            $redirectAdmin = true;
            Tools::clearSmartyCache();
            Tools::clearXMLCache();
            Media::clearCache();
            Tools::generateIndex();
        }
        if ((bool) Tools::getValue('empty_sf2_cache')) {
            $redirectAdmin = true;
            $sf2Refresh = new \PrestaShopBundle\Service\Cache\Refresh();
            $sf2Refresh->addCacheClear(_PS_MODE_DEV_ ? 'dev' : 'prod');
            $sf2Refresh->execute();
        }
        if (Tools::isSubmit('submitAddconfiguration')) {
            Configuration::updateGlobalValue('PS_DISABLE_NON_NATIVE_MODULE', (int) Tools::getValue('native_module'));
            Configuration::updateGlobalValue('PS_DISABLE_OVERRIDES', (int) Tools::getValue('overrides'));
            if (Tools::isSubmit('debug_mode') && (bool) Tools::getValue('debug_mode')) {
                $debug_mode_status = $this->enableDebugMode();
            } else {
                $debug_mode_status = $this->disableDebugMode();
            }
            if (!empty($debug_mode_status)) {
                switch ($debug_mode_status) {
                    case self::DEBUG_MODE_ERROR_COULD_NOT_BACKUP:
                        $this->errors[] = Tools::displayError(sprintf($this->l('Error: could not write to file. Make sure that the correct permissions are set on the file %s'), _PS_ROOT_DIR_ . '/config/defines.old.php'));
                        break;
                    case self::DEBUG_MODE_ERROR_NO_DEFINITION_FOUND:
                        $this->errors[] = Tools::displayError(sprintf($this->l('Error: could not find whether debug mode is enabled. Make sure that the correct permissions are set on the file %s'), _PS_ROOT_DIR_ . '/config/defines.inc.php'));
                        break;
                    case self::DEBUG_MODE_ERROR_NO_WRITE_ACCESS:
                        $this->errors[] = Tools::displayError(sprintf($this->l('Error: could not write to file. Make sure that the correct permissions are set on the file %s'), _PS_ROOT_DIR_ . '/config/defines.inc.php'));
                        break;
                    case self::DEBUG_MODE_ERROR_NO_WRITE_ACCESS_CUSTOM:
                        $this->errors[] = Tools::displayError(sprintf($this->l('Error: could not write to file. Make sure that the correct permissions are set on the file %s'), _PS_ROOT_DIR_ . '/config/defines_custom.inc.php'));
                        break;
                    case self::DEBUG_MODE_ERROR_NO_READ_ACCESS:
                        $this->errors[] = Tools::displayError(sprintf($this->l('Error: could not read file. Make sure that the correct permissions are set on the file %s'), _PS_ROOT_DIR_ . '/config/defines.inc.php'));
                        break;
                    default:
                        break;
                }
            }
            Tools::generateIndex();
        }
        if ($redirectAdmin && (!isset($this->errors) || !count($this->errors))) {
            Hook::exec('action' . get_class($this) . ucfirst($this->action) . 'After', array('controller' => $this, 'return' => ''));
            Tools::redirectAdmin(self::$currentIndex . '&token=' . Tools::getValue('token') . '&conf=4');
        }
    }