diff --git a/main/install/index.php b/main/install/index.php index 44743e4909..817467c700 100644 --- a/main/install/index.php +++ b/main/install/index.php @@ -178,12 +178,21 @@ $app->match('/', function() use($app) { ->before($blockInstallation); $app->match('/requirements', function() use($app) { + + $allowedToContinue = checkRequiredSettings(); + $request = $app['request']; - $form = $app['form.factory']->createBuilder('form') - ->add('continue', 'submit', array('attr' => array('class' => 'btn'))) - ->getForm(); + $builder = $app['form.factory']->createBuilder('form'); + if ($allowedToContinue) { + $builder->add('continue', 'submit', array('attr' => array('class' => 'btn-default'))); + } else { + $message = $app['translator']->trans("You need to check your server settings."); + $app['session']->getFlashBag()->add('error', $message); + } + + $form = $builder->getForm(); - $req = display_requirements($app, 'new'); + //$req = display_requirements($app, 'new'); if (phpversion() < REQUIRED_PHP_VERSION) { $phpError = ''.translate('PHPVersionError').''; @@ -191,13 +200,14 @@ $app->match('/requirements', function() use($app) { $phpError = ''.translate('PHPVersionOK').' '.phpversion().''; } - if ('POST' == $request->getMethod()) { $url = $app['url_generator']->generate('check-database'); return $app->redirect($url); } - $reqs = drawRequirements($app['translator']); + $requirements = drawRequirements($app['translator']); + $options = drawOptions($app['translator']); + $permissions = drawPermissionsSettings($app); return $app['twig']->render( 'requirements.tpl', @@ -206,11 +216,14 @@ $app->match('/requirements', function() use($app) { 'required_php_version' => REQUIRED_PHP_VERSION, 'required_php_version_validation' => phpversion() < REQUIRED_PHP_VERSION, 'php_version' => phpversion(), - 'reqs' => $reqs, + 'requirements' => $requirements, + 'options' => $options, + 'permissions' => $permissions, 'php_error' => $phpError, - 'requirements' => $req + 'allow_to_continue' => $allowedToContinue ) ); + })->bind('requirements'); $app->match('/check-database', function() use($app) { diff --git a/main/install/install.lib.php b/main/install/install.lib.php index 0441f24024..74d161c1d4 100755 --- a/main/install/install.lib.php +++ b/main/install/install.lib.php @@ -901,17 +901,20 @@ function display_language_selection() trans($variable); } -function getRequirements() { +function getRequirements() +{ return array( 'required' => array( //'session' => array('url' => 'http://php.net/manual/en/book.session.php', 'recommend' => Display::label('OFF', 'success')), 'mysql' => array('url' => 'http://php.net/manual/en/book.mysql.php'), + 'curl' => array('url' => 'http://php.net/manual/fr/book.curl.php'), 'zlib' => array('url' => 'http://php.net/manual/en/book.zlib.php'), 'pcre' => array('url' => 'http://php.net/manual/en/book.pcre.php'), 'xml' => array('url' => 'http://php.net/manual/en/book.xml.php'), @@ -924,138 +927,197 @@ function getRequirements() { 'optional' => array( 'imagick' => array('url' => 'http://php.net/manual/en/book.imagick.php'), 'ldap' => array('url' => 'http://php.net/manual/en/book.ldap.php'), - 'xapian' => array('url' => 'http://php.net/manual/en/book.xapian.php'), - 'curl' => array('url' => 'http://php.net/manual/en/book.curl.php') + 'xapian' => array('url' => 'http://php.net/manual/en/book.xapian.php') ) ); } +/** + * @param Symfony\Component\Translation\Translator $translator + * @return array + */ +function getOptions($translator) +{ + return array( + array( + 'name' => 'Safe Mode', + 'url' => 'http://php.net/manual/features.safe-mode.php', + 'recommended' => Display::label('OFF', 'success'), + 'current' => check_php_setting('safe_mode', 'OFF'), + ), + array( + 'name' => 'Display Errors', + 'url' => 'http://php.net/manual/ref.errorfunc.php#ini.display-errors', + 'recommended' => Display::label('ON', 'success'), + 'current' => check_php_setting('display_errors', 'OFF'), + ), + array( + 'name' => 'File Uploads', + 'url' => 'http://php.net/manual/ini.core.php#ini.file-uploads', + 'recommended' => Display::label('OFF', 'success'), + 'current' => check_php_setting('file_uploads', 'ON'), + ), + array( + 'name' => 'Magic Quotes GPC', + 'url' => 'http://php.net/manual/ref.info.php#ini.magic-quotes-gpc', + 'recommended' => Display::label('OFF', 'success'), + 'current' => check_php_setting('magic_quotes_gpc', 'OFF'), + ), + array( + 'name' => 'Magic Quotes Runtime', + 'url' => 'http://php.net/manual/ref.info.php#ini.magic-quotes-runtime', + 'recommended' => Display::label('OFF', 'success'), + 'current' => check_php_setting('magic_quotes_runtime', 'OFF'), + ), + array( + 'name' => 'Register Globals', + 'url' => 'http://php.net/manual/security.globals.php', + 'recommended' => Display::label('OFF', 'success'), + 'current' => check_php_setting('register_globals', 'OFF'), + ), + array( + 'name' => 'Session auto start', + 'url' => 'http://php.net/manual/ref.session.php#ini.session.auto-start', + 'recommended' => Display::label('OFF', 'success'), + 'current' => check_php_setting('auto_start', 'OFF'), + ), + array( + 'name' => 'Short Open Tag', + 'url' => 'http://php.net/manual/ini.core.php#ini.short-open-tag', + 'recommended' => Display::label('OFF', 'success'), + 'current' => check_php_setting('short_open_tag', 'OFF'), + ), + array( + 'name' => 'Cookie HTTP Only', + 'url' => 'http://www.php.net/manual/en/session.configuration.php#ini.session.cookie-httponly', + 'recommended' => Display::label('ON', 'success'), + 'current' => check_php_setting('session.cookie_httponly', 'ON'), + ), + array( + 'name' => 'Maximum upload file size', + 'url' => 'http://php.net/manual/ini.core.php#ini.upload-max-filesize', + 'recommended' => Display::label('>= '.REQUIRED_MIN_UPLOAD_MAX_FILESIZE.'M', 'success'), + 'current' => compare_setting_values(ini_get('upload_max_filesize'), REQUIRED_MIN_UPLOAD_MAX_FILESIZE), + ), + array( + 'name' => 'Maximum post size', + 'url' => 'http://php.net/manual/ini.core.php#ini.post-max-size', + 'recommended' => Display::label('>= '.REQUIRED_MIN_POST_MAX_SIZE.'M', 'success'), + 'current' => compare_setting_values(ini_get('post_max_size'), REQUIRED_MIN_POST_MAX_SIZE), + ), + array( + 'name' => 'Memory Limit', + 'url' => 'http://www.php.net/manual/en/ini.core.php#ini.memory-limit', + 'recommended' => Display::label('>= '.REQUIRED_MIN_MEMORY_LIMIT.'M', 'success'), + 'current' => compare_setting_values(ini_get('memory_limit'), REQUIRED_MIN_MEMORY_LIMIT), + ) + ); +} + +/** + * Check if current system is allowed to install + * @return bool + */ +function checkRequiredSettings() +{ + $requirements = getRequirements(); + $requiredSettings = $requirements['required']; + + foreach ($requiredSettings as $extension => $options) { + if (!extension_loaded($extension)) { + return false; + } + } + + return true; +} + /** * @param Symfony\Component\Translation\Translator $translator * @return null|string */ function drawRequirements($translator) { - $requeriments = getRequirements(); + $requirements = getRequirements(); $html = null; + $html .= ' + + '.$translator->trans('Required').' + + + + '; - foreach ($requeriments['required'] as $extension => $req) { + foreach ($requirements['required'] as $extension => $req) { + $checkExtension = check_extension( + $extension, + $translator->trans('Yes'), + $translator->trans('No') + ); $html .= ' '.$extension.' - '.check_extension( - $extension, - $translator->trans('Yes'), - $translator->trans('No') - ).' + '.$checkExtension.' '; } - foreach ($requeriments['optional'] as $extension => $req) { + $html .= ' + + '.$translator->trans('Optional').' + + + + '; + + foreach ($requirements['optional'] as $extension => $req) { + + $checkExtension = check_extension( + $extension, + $translator->trans('Yes'), + $translator->trans('No') + ); + $html .= ' '.$extension.' - '.check_extension( - $extension, - $translator->trans('Yes'), - $translator->trans('No'), - true - ).' + '.$checkExtension.' '; } + return $html; } -function display_requirements($app, $installType) +function drawOptions($translator) { - $html = null; + $options = getOptions($translator); + $html = null; + foreach ($options as $option) { + $html .= ' + + '.$option['name'].' + + + '.$option['recommended'].' + + + '.$option['current'].' + + '; + } + return $html; +} - // RECOMMENDED SETTINGS - // Note: these are the settings for Joomla, does this also apply for Chamilo? - // Note: also add upload_max_filesize here so that large uploads are possible - $html .= '

'.translate('RecommendedSettings').'

'; - $html .= '
'.translate('RecommendedSettingsInfo').'
'; - $html .= '
'; - $html .= ' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
'.translate('Setting').''.translate('Recommended').''.translate('Actual').'
Safe Mode'.check_php_setting('safe_mode', 'OFF').'
Display Errors'.check_php_setting('display_errors', 'OFF').'
File Uploads'.check_php_setting('file_uploads', 'ON').'
Magic Quotes GPC'.check_php_setting('magic_quotes_gpc', 'OFF').'
Magic Quotes Runtime'.check_php_setting('magic_quotes_runtime', 'OFF').'
Register Globals'.check_php_setting('register_globals', 'OFF').'
Session auto start'.check_php_setting('session.auto_start', 'OFF').'
Short Open Tag'.check_php_setting('short_open_tag', 'OFF').'
Cookie HTTP Only'.check_php_setting('session.cookie_httponly', 'ON').'
Maximum upload file size'.compare_setting_values(ini_get('upload_max_filesize'), REQUIRED_MIN_UPLOAD_MAX_FILESIZE ).'
Maximum post size'.compare_setting_values(ini_get('post_max_size'), REQUIRED_MIN_POST_MAX_SIZE ).'
Memory Limit'.compare_setting_values( ini_get('memory_limit'), REQUIRED_MIN_MEMORY_LIMIT - ).'
'; - $html .= '
'; - $html .= '
'; +function drawPermissionsSettings($app) +{ + $html = null; // DIRECTORY AND FILE PERMISSIONS - $html .= '

'.translate('DirectoryAndFilePermissions').'

'; - $html .= '
'.translate('DirectoryAndFilePermissionsInfo').'
'; $html .= '
'; $course_attempt_name = '__XxTestxX__'; @@ -1229,37 +1291,7 @@ function display_requirements($app, $installType) $html .= translate('WarningExistingDokeosInstallationDetected'); $html .= '
'; } - - /* - // And now display the choice buttons (go back or install) - ?> -

- - - - '.translate('UpgradeFromDokeos18x').''; - echo ' '; - echo '

';*/ - return $html; - } /** diff --git a/main/install/templates/requirements.tpl b/main/install/templates/requirements.tpl index 3a5038c2c0..12869b01f3 100644 --- a/main/install/templates/requirements.tpl +++ b/main/install/templates/requirements.tpl @@ -12,11 +12,7 @@ {{ 'ReadTheInstallGuide' | trans }} -
-

{{ 'ServerRequirements' | trans }}

-
- -
{{ 'ServerRequirementsInfo' | trans }}
+

{{ 'ServerRequirements' | trans }}

@@ -31,18 +27,32 @@ {% autoescape false %} - {# reqs #} + {{ requirements }} + {% endautoescape %} +
+ + +

{{ 'PHPSettings' | trans }}

+ + + + + + + + + {% autoescape false %} + {{ options }} {% endautoescape %}
{{ 'Name' | trans }}{{ 'Recommended' | trans }}{{ 'Current' | trans }}
+

{{ 'DirectoryAndFilePermissions' | trans }}

+ {% autoescape false %} - {{ requirements }} + {{ permissions }} {% endautoescape %}
{{ form_widget(form) }}
- - {% endblock %} -