/**
  * isUpgradeAllowed checks if all server configuration is valid for upgrade
  * 
  * @return void
  */
 public function isUpgradeAllowed()
 {
     $allowed = ConfigurationTest::test_fopen() && $this->rootWritable;
     if (!defined('_PS_MODE_DEV_') or !_PS_MODE_DEV_) {
         $allowed &= $this->upgrader->autoupgrade;
     }
     return $allowed;
 }
    /** this returns fieldset containing the configuration points you need to use autoupgrade
     * @return string
     */
    private function _displayCurrentConfiguration()
    {
        $current_ps_config = $this->getcheckCurrentPsConfig();
        $this->_html .= '<div class="bootstrap" id="currentConfigurationBlock">
            <div class="panel">
                <div class="panel-heading">
                  ' . $this->l('The pre-Upgrade checklist') . '
                </div>';
        if (!$this->configOk()) {
            $this->_html .= '<p class="alert alert-warning">' . $this->l('The checklist is not OK. You can only upgrade your shop once all indicators are green.') . '</p>';
        }
        $this->_html .= '<div id="currentConfiguration">
							<p class="alert alert-info">' . $this->l('Before starting the upgrade process, please make sure this checklist is all green.') . '</p>';
        $pic_ok = '<img src="../img/admin/enabled.gif" alt="ok"/>';
        $pic_nok = '<img src="../img/admin/disabled.gif" alt="nok"/>';
        $pic_warn = '<img src="../img/admin/warning.gif" alt="warn"/>';
        // module version : checkAutoupgradeLastVersion
        $this->_html .= '<table class="table" cellpadding="0" cellspacing="0">
				<tr>
					<td>' . sprintf($this->l('The 1-click upgrade module is up-to-date (your current version is v%s)'), $this->getModuleVersion()) . '
					' . ($current_ps_config['module_version_ok'] ? '' : '&nbsp;&nbsp;' . (version_compare(_PS_VERSION_, '1.5.3.0', '>') ? '<strong><a href="index.php?controller=AdminModules&amp;token=' . Tools14::getAdminTokenLite('AdminModules') . '&update=autoupgrade">' . $this->l('Update') . '</a></strong> - ' : '') . '<strong><a class="_blank" href="http://addons.prestashop.com/en/administration-tools-prestashop-modules/5496-1-click-upgrade-autoupgrade.html">' . $this->l('Download') . '</a><strong> ') . '
					</td>
					<td>' . ($current_ps_config['module_version_ok'] ? $pic_ok : $pic_nok) . '</td>
				</tr>';
        // root : getRootWritable()
        $this->_html .= '
			<tr>
				<td>' . $this->l('Your store\'s root directory is writable (with appropriate CHMOD permissions)') . '</td>
				<td>' . ($current_ps_config['root_writable'] ? $pic_ok : $pic_nok . ' ' . $this->root_writable_report) . '</td>
			</tr>';
        $admin_dir = trim(str_replace($this->prodRootDir, '', $this->adminDir), DIRECTORY_SEPARATOR);
        $report = '';
        ConfigurationTest::test_dir($admin_dir . DIRECTORY_SEPARATOR . $this->autoupgradeDir, true, $report);
        if ($report) {
            $this->_html .= '
				<tr>
					<td>' . $this->l('The "/admin/autoupgrade" directory is writable (appropriate CHMOD permissions)') . '</td>
					<td>' . ($current_ps_config['admin_au_writable'] ? $pic_ok : $pic_nok . ' ' . $report) . '</td>
				</tr>';
        }
        //check safe_mod
        if (!($safe_mode = @ini_get('safe_mode'))) {
            $safe_mode = '';
        }
        $safe_mode = in_array(Tools14::strtolower($safe_mode), array(1, 'on'));
        $this->_html .= '
			<tr><td>' . $this->l('PHP\'s "Safe mode" option is turned off') . '</td>
			<td>' . (!$safe_mode ? $pic_ok : $pic_warn) . '</td></tr>';
        $this->_html .= '
			<tr><td>' . $this->l('PHP\'s "allow_url_fopen" option is turned on, or cURL is installed') . '</td>
			<td>' . (ConfigurationTest::test_fopen() || ConfigurationTest::test_curl() ? $pic_ok : $pic_nok) . '</td></tr>';
        // shop enabled
        $this->_html .= '
			<tr><td>' . $this->l('Your store is in maintenance mode') . ' ' . (!$current_ps_config['shop_deactivated'] ? '<br><form method="post" action="' . $this->currentIndex . '&token=' . $this->token . '"><input type="submit" class="button" name="putUnderMaintenance" value="' . $this->l('Click here to put your shop under maintenance') . '"></form>' : '') . '</td>
			<td>' . ($current_ps_config['shop_deactivated'] ? $pic_ok : $pic_nok) . '</td></tr>';
        $this->_html .= '
			<tr><td>' . $this->l('PrestaShop\'s caching features are disabled') . '</td>
			<td>' . ($current_ps_config['cache_deactivated'] ? $pic_ok : $pic_nok) . '</td></tr>';
        // for informaiton, display time limit
        $max_exec_time = ini_get('max_execution_time');
        $this->_html .= '
			<tr><td>' . sprintf($this->l('PHP\'s max_execution_time setting has a high value or is disabled entirely (current value: %s)'), $max_exec_time == 0 ? $this->l('unlimited') : sprintf($this->l('%s seconds'), $max_exec_time)) . '</td>
			<td>' . ($max_exec_time == 0 ? $pic_ok : $pic_warn) . '</td></tr>
        </table>
        <br/>
        <p class="alert alert-info">' . $this->l('Please also make sure you make a full manual backup of your files and database.') . '</p>
        </div>
        </div>
		</div>';
    }
    /** this returns fieldset containing the configuration points you need to use autoupgrade
     * @return string
     */
    private function _displayCurrentConfiguration()
    {
        $current_ps_config = $this->getcheckCurrentPsConfig();
        $this->_html .= '
		<fieldset id="currentConfigurationBlock" class="width autoupgrade" style="float: left; width: 60%; margin-left: 30px;">
			<legend>' . $this->l('The pre-Upgrade checklist') . '</legend>';
        if (!$this->configOk()) {
            $this->_html .= '<div class="clear"><br></div><p class="warn">' . $this->l('The checklist is not ok. You can not upgrade your shop until every indicator will not be green.') . '</p>';
        }
        $this->_html .= '<div id="currentConfiguration">
							<p>' . $this->l('Before starting the upgrade process, please make sure this checklist is all green.') . '</p>
				<table class="table" cellpadding="0" cellspacing="0">';
        $pic_ok = '<img src="../img/admin/enabled.gif" alt="ok"/>';
        $pic_nok = '<img src="../img/admin/disabled.gif" alt="nok"/>';
        $pic_warn = '<img src="../img/admin/warning.gif" alt="warn"/>';
        // module version : checkAutoupgradeLastVersion
        $this->_html .= '
				<tr>
					<td>' . sprintf($this->l('The 1-click upgrade module is up-to-date (your current version is v%s)'), $this->getModuleVersion()) . '
					' . ($current_ps_config['module_version_ok'] ? '' : '&nbsp;&nbsp;' . (version_compare(_PS_VERSION_, '1.5.3.0', '>') ? '<strong><a href="index.php?controller=AdminModules&amp;token=' . Tools14::getAdminTokenLite('AdminModules') . '&update=autoupgrade">' . $this->l('Update') . '</a></strong> - ' : '') . '<strong><a class="_blank" href="http://addons.prestashop.com/en/administration-tools-prestashop-modules/5496-1-click-upgrade-autoupgrade.html">' . $this->l('Download') . '</a><strong> ') . '
					</td>
					<td>' . ($current_ps_config['module_version_ok'] ? $pic_ok : $pic_nok) . '</td>
				</tr>';
        // root : getRootWritable()
        $this->_html .= '
			<tr>
				<td>' . $this->l('Your store root directory must be writeable (appropriate CHMOD permissions)') . '</td>
				<td>' . ($current_ps_config['root_writable'] ? $pic_ok : $pic_nok . ' ' . $this->root_writable_report) . '</td>
			</tr>';
        //check safe_mod
        if (!($safe_mode = @ini_get('safe_mode'))) {
            $safe_mode = '';
        }
        $safe_mode = in_array(Tools14::strtolower($safe_mode), array(1, 'on'));
        $this->_html .= '
			<tr><td>' . $this->l('The PHP "Safe mode" option must be turned off') . '</td>
			<td>' . (!$safe_mode ? $pic_ok : $pic_warn) . '</td></tr>';
        $this->_html .= '
			<tr><td>' . $this->l('The PHP "allow_url_fopen" option must be turned on or CURL must be installed') . '</td>
			<td>' . (ConfigurationTest::test_fopen() || ConfigurationTest::test_curl() ? $pic_ok : $pic_nok) . '</td></tr>';
        // shop enabled
        $this->_html .= '
			<tr><td>' . $this->l('You must put your store under maintenance') . ' ' . (!$current_ps_config['shop_deactivated'] ? '<br><form method="post" action="' . $this->currentIndex . '&token=' . $this->token . '"><input type="submit" class="button" name="putUnderMaintenance" value="' . $this->l('Click here to put your shop under maintenance') . '"></form>' : '') . '</td>
			<td>' . ($current_ps_config['shop_deactivated'] ? $pic_ok : $pic_nok) . '</td></tr>';
        $this->_html .= '
			<tr><td>' . $this->l('You must disable the Caching features of PrestaShop') . '</td>
			<td>' . ($current_ps_config['cache_deactivated'] ? $pic_ok : $pic_nok) . '</td></tr>';
        // for informaiton, display time limit
        $max_exec_time = ini_get('max_execution_time');
        $this->_html .= '
			<tr><td>' . sprintf($this->l('The PHP time limit must be either high or disabled (Current value: %s)'), $max_exec_time == 0 ? $this->l('unlimited') : $max_exec_time . ' ' . $this->l('seconds')) . '</td>
			<td>' . ($max_exec_time == 0 ? $pic_ok : $pic_warn) . '</td></tr>
				</table>
				<p>' . $this->l('Please also make sure you proceeded to a full manual backup of your files and database.') . '</p>
			</div>
		</fieldset>';
    }
    /** this returns fieldset containing the configuration points you need to use autoupgrade
     * @return string
     */
    private function _displayCurrentConfiguration()
    {
        global $currentIndex;
        $current_ps_config = $this->getcheckCurrentPsConfig();
        $this->_html .= '
		<fieldset id="currentConfigurationBlock" class="width autoupgrade" style="float: left; width: 60%; margin-left: 30px;">
			<legend>' . $this->l('The pre-Upgrade checklist') . '</legend>';
        if (!$this->configOk()) {
            $this->_html .= '<div class="clear"><br></div><p class="warn">' . $this->l('The checklist is not ok. You can not upgrade your shop until every indicator will not be green.') . '</p>';
        }
        $this->_html .= '<div id="currentConfiguration">
				<table class="table" cellpadding="0" cellspacing="0">
				<p>' . $this->l('Before starting the upgrade process, please make sure this checklist is all green.') . '</p>';
        $pic_ok = '<img src="../img/admin/enabled.gif" alt="ok"/>';
        $pic_nok = '<img src="../img/admin/disabled.gif" alt="nok"/>';
        $pic_warn = '<img src="../img/admin/warning.gif" alt="warn"/>';
        // module version : checkAutoupgradeLastVersion
        $this->_html .= '
				<tr>
					<th>' . sprintf($this->l('The 1-click upgrade module is up-to-date (your current version is v%s)'), $this->getModuleVersion()) . '</th>
					<td>' . ($current_ps_config['module_version_ok'] ? $pic_ok : $pic_nok) . '</td>
				</tr>';
        // root : getRootWritable()
        $this->_html .= '<th>' . $this->l('Your store root directory must be writeable (appropriate CHMOD permissions)') . '</th>
			<td>' . ($current_ps_config['root_writable'] ? $pic_ok : $pic_nok . ' ' . $this->root_writable_report) . '</td></tr>';
        //check safe_mod
        $this->_html .= '<th>' . $this->l('The PHP "Safe mode" option must be turned off') . '</th>
			<td>' . (!ini_get('safe_mode') ? $pic_ok : $pic_warn) . '</td></tr>';
        $this->_html .= '<th>' . $this->l('The PHP "allow_url_fopen" option must be turned on or CURL must be installed') . '</th>
			<td>' . (ConfigurationTest::test_fopen() || ConfigurationTest::test_curl() ? $pic_ok : $pic_nok) . '</td></tr>';
        // shop enabled
        $this->_html .= '<th>' . $this->l('You must put your store under maintenance') . ' ' . (!$current_ps_config['shop_deactivated'] ? '<br><form method="post" action="' . $currentIndex . '&token=' . $this->token . '"><input type="submit" class="button" name="putUnderMaintenance" value="' . $this->l('Click here to put your shop under maintenance') . '"></form>' : '') . '</th>
			<td>' . ($current_ps_config['shop_deactivated'] ? $pic_ok : $pic_nok) . '</td></tr>';
        $this->_html .= '<th>' . $this->l('You must disable the Caching features of PrestaShop') . '</th>
			<td>' . ($current_ps_config['cache_deactivated'] ? $pic_ok : $pic_nok) . '</td></tr>';
        // for informaiton, display time limit
        $max_exec_time = ini_get('max_execution_time');
        $this->_html .= '<th>' . sprintf($this->l('The PHP time limit must be either high or disabled (Current value: %s)'), $max_exec_time == 0 ? $this->l('unlimited') : $max_exec_time . ' ' . $this->l('seconds')) . '</th>
			<td>' . ($max_exec_time == 0 ? $pic_ok : $pic_warn) . '</td></tr>
				</table>
				<p>' . $this->l('Please also make sure you proceeded to a full manual backup of your files and database.') . '</p>
			</div>
		</fieldset>';
    }
 public function getcheckCurrentConfig()
 {
     static $allowed_array;
     if (empty($allowed_array)) {
         $allowed_array = array();
         $allowed_array['fopen'] = ConfigurationTest::test_fopen();
         $allowed_array['root_writable'] = $this->getRootWritable();
         $allowed_array['shop_deactivated'] = !Configuration::get('PS_SHOP_ENABLE');
         // xml can enable / disable upgrade
         $allowed_array['autoupgrade_allowed'] = $this->upgrader->autoupgrade;
         $allowed_array['need_upgrade'] = $this->upgrader->need_upgrade;
         $allowed_array['module_version_ok'] = $this->checkAutoupgradeLastVersion();
         // if one option has been defined, all options are.
         $allowed_array['module_configured'] = Configuration::get('PS_AUTOUP_KEEP_MAILS') !== false;
     }
     return $allowed_array;
 }
 public function getCheckCurrentPsConfig()
 {
     static $allowed_array;
     if (empty($allowed_array)) {
         $allowed_array = array();
         $allowed_array['fopen'] = ConfigurationTest::test_fopen();
         $allowed_array['root_writable'] = $this->getRootWritable();
         $allowed_array['shop_deactivated'] = !Configuration::get('PS_SHOP_ENABLE');
         $allowed_array['cache_deactivated'] = !(defined('_PS_CACHE_ENABLED_') && _PS_CACHE_ENABLED_);
         $allowed_array['module_version_ok'] = $this->checkAutoupgradeLastVersion();
     }
     return $allowed_array;
 }