/** * Displays step 3 - a form where the user can enter the installation settings * regarding the databases - login and password, names, prefixes, single * or multiple databases, tracking or not... */ function display_database_settings_form($installType, $dbHostForm, $dbUsernameForm, $dbPassForm, $dbPrefixForm, $enableTrackingForm, $singleDbForm, $dbNameForm, $dbStatsForm, $dbScormForm, $dbUserForm) { if ($installType == 'update') { global $_configuration, $update_from_version_6; if (in_array($_POST['old_version'], $update_from_version_6)) { $dbHostForm = get_config_param('dbHost'); $dbUsernameForm = get_config_param('dbLogin'); $dbPassForm = get_config_param('dbPass'); $dbPrefixForm = get_config_param('dbNamePrefix'); $enableTrackingForm = get_config_param('is_trackingEnabled'); $singleDbForm = get_config_param('singleDbEnabled'); $dbHostForm = get_config_param('mainDbName'); $dbStatsForm = get_config_param('statsDbName'); $dbScormForm = get_config_param('scormDbName'); $dbUserForm = get_config_param('user_personal_database'); $dbScormExists = true; } else { $dbHostForm = $_configuration['db_host']; $dbUsernameForm = $_configuration['db_user']; $dbPassForm = $_configuration['db_password']; $dbPrefixForm = $_configuration['db_prefix']; $enableTrackingForm = $_configuration['tracking_enabled']; $singleDbForm = $_configuration['single_database']; $dbNameForm = $_configuration['main_database']; $dbStatsForm = $_configuration['statistics_database']; $dbScormForm = $_configuration['scorm_database']; $dbUserForm = $_configuration['user_personal_database']; $dbScormExists = true; } if (empty($dbScormForm)) { if ($singleDbForm) { $dbScormForm = $dbNameForm; } else { $dbScormForm = $dbPrefixForm.'scorm'; $dbScormExists = false; } } if (empty($dbUserForm)) { $dbUserForm = $singleDbForm ? $dbNameForm : $dbPrefixForm.'chamilo_user'; } echo '<div class="RequirementHeading"><h2>' . display_step_sequence() .get_lang('DBSetting') . '</h2></div>'; echo '<div class="RequirementContent">'; echo get_lang('DBSettingUpgradeIntro'); echo '</div>'; } else { if (empty($dbPrefixForm)) { //make sure there is a default value for db prefix $dbPrefixForm = ''; } echo '<div class="RequirementHeading"><h2>' . display_step_sequence() .get_lang('DBSetting') . '</h2></div>'; echo '<div class="RequirementContent">'; echo get_lang('DBSettingIntro'); echo '</div>'; } ?> </td> </tr> <tr> <td> <table class="data_table_no_border"> <tr> <td width="40%"><?php echo get_lang('DBHost'); ?> </td> <?php if ($installType == 'update'): ?> <td width="30%"><input type="hidden" name="dbHostForm" value="<?php echo htmlentities($dbHostForm); ?>" /><?php echo $dbHostForm; ?></td> <td width="30%"> </td> <?php else: ?> <td width="30%"><input type="text" size="25" maxlength="50" name="dbHostForm" value="<?php echo htmlentities($dbHostForm); ?>" /></td> <td width="30%"><?php echo get_lang('EG').' localhost'; ?></td> <?php endif; ?> </tr> <tr> <?php //database user username $example_login = get_lang('EG').' root'; display_database_parameter($installType, get_lang('DBLogin'), 'dbUsernameForm', $dbUsernameForm, $example_login); //database user password $example_password = get_lang('EG').' '.api_generate_password(); display_database_parameter($installType, get_lang('DBPassword'), 'dbPassForm', $dbPassForm, $example_password); echo '<input type="hidden" name="enableTrackingForm" value="1" />'; $style = ''; if ($installType == INSTALL_TYPE_UPDATE) { $style = ''; } //Database Name fix replace weird chars if ($installType != INSTALL_TYPE_UPDATE) { $dbNameForm = str_replace(array('-','*', '$', ' ', '.'), '', $dbNameForm); $dbNameForm = replace_dangerous_char($dbNameForm); } display_database_parameter($installType, get_lang('MainDB'), 'dbNameForm', $dbNameForm, ' ', null, 'id="optional_param1" '.$style); //Only for updates we show this options if ($installType == INSTALL_TYPE_UPDATE) { display_database_parameter($installType, get_lang('StatDB'), 'dbStatsForm', $dbStatsForm, ' ', null, 'id="optional_param2" '.$style); if ($installType == INSTALL_TYPE_UPDATE && in_array($_POST['old_version'], $update_from_version_6)) { display_database_parameter($installType, get_lang('ScormDB'), 'dbScormForm', $dbScormForm, ' ', null, 'id="optional_param3" '.$style); } display_database_parameter($installType, get_lang('UserDB'), 'dbUserForm', $dbUserForm, ' ', null, 'id="optional_param4" '.$style); } ?> <tr> <td></td> <td> <button type="submit" class="btn" name="step3" value="<?php echo get_lang('CheckDatabaseConnection'); ?>" > <?php echo get_lang('CheckDatabaseConnection'); ?></button> </td> </tr> <tr> <td> <?php $dbConnect = test_db_connect($dbHostForm, $dbUsernameForm, $dbPassForm, $singleDbForm, $dbPrefixForm, $dbNameForm); $database_exists_text = ''; if (database_exists($dbNameForm)) { $database_exists_text = '<div class="warning-message">'.get_lang('ADatabaseWithTheSameNameAlreadyExists').'</div>'; } else { if ($dbConnect == -1) { $database_exists_text = '<div class="warning-message">'.sprintf(get_lang('UserXCantHaveAccessInTheDatabaseX'), $dbUsernameForm, $dbNameForm).'</div>'; } else { //Try to create the database $user_can_create_databases = false; $multipleDbCheck = @Database::query("CREATE DATABASE ".mysql_real_escape_string($dbNameForm)); if ($multipleDbCheck !== false) { $multipleDbCheck = @Database::query("DROP DATABASE IF EXISTS ".mysql_real_escape_string($dbNameForm)); $user_can_create_databases = true; } if ($user_can_create_databases) { $database_exists_text = '<div class="normal-message">'.sprintf(get_lang('DatabaseXWillBeCreated'), $dbNameForm, $dbUsernameForm).'</div>'; } else { $dbConnect = 0; $database_exists_text = '<div class="warning-message">'.sprintf(get_lang('DatabaseXCantBeCreatedUserXDoestHaveEnoughPermissions'), $dbNameForm, $dbUsernameForm).'</div>'; } } } if ($dbConnect == 1): ?> <td colspan="2"> <?php echo $database_exists_text ?> <div id="db_status" class="confirmation-message"> Database host: <strong><?php echo Database::get_host_info(); ?></strong><br /> Database server version: <strong><?php echo Database::get_server_info(); ?></strong><br /> Database client version: <strong><?php echo Database::get_client_info(); ?></strong><br /> Database protocol version: <strong><?php echo Database::get_proto_info(); ?></strong> <div style="clear:both;"></div> </div> </td> <?php else: ?> <td colspan="2"> <?php echo $database_exists_text ?> <div id="db_status" style="float:left;" class="error-message"> <div style="float:left;"> <strong><?php echo get_lang('FailedConectionDatabase'); ?></strong><br /> <strong>Database error: <?php echo Database::errno(); ?></strong><br /> <?php echo Database::error().'<br />'; ?> </div> </div> </td> <?php endif; ?> </tr> <tr> <td> <button type="submit" name="step2" class="back" value="< <?php echo get_lang('Previous'); ?>" ><?php echo get_lang('Previous'); ?></button> </td> <td> </td> <td align="right"> <input type="hidden" name="is_executable" id="is_executable" value="-" /> <?php if ($dbConnect == 1) { ?> <button type="submit" class="btn next" name="step4" value="<?php echo get_lang('Next'); ?> >" /><?php echo get_lang('Next'); ?></button> <?php } else { ?> <button disabled="disabled" type="submit" class="btn next disabled" name="step4" value="<?php echo get_lang('Next'); ?> >" /><?php echo get_lang('Next'); ?></button> <?php } ?> </td> </tr> </table> <?php }
$mysqlUserDb = $dbUserForm; if (empty($mysqlUserDb) || $mysqlUserDb == 'mysql' || $mysqlUserDb == $dbPrefixForm) { $mysqlUserDb = $dbPrefixForm.'user'; } //This parameter is needed to run a command line to install Chamilo using BNPanel + ISPConfig see #1799 if (!defined('CLI_INSTALLATION')) { $result = Database::query("SHOW VARIABLES LIKE 'datadir'") or die(Database::error()); $mysqlRepositorySys = Database::fetch_array($result); $mysqlRepositorySys = $mysqlRepositorySys['Value']; $create_database = true; if (database_exists($mysqlMainDb)) { $create_database = false; } //Create database if ($create_database) { $sql = "CREATE DATABASE IF NOT EXISTS `$mysqlMainDb`"; Database::query($sql) or die(Database::error()); } } $mysqlStatsDb = $mysqlMainDb; $mysqlUserDb = $mysqlMainDb; // This parameter is needed to run a command line install of Chamilo (needed for Phing) if (!defined('CLI_INSTALLATION')) { include api_get_path(SYS_LANG_PATH).'english/create_course.inc.php';
define('DEMO_MODULE', 'hermes'); $base_url = 'http://' . $_SERVER["SERVER_NAME"] . dirname($_SERVER["PHP_SELF"]); $base_path = realpath(dirname(realpath(__FILE__)) . '/..') . '/'; $config_php = $base_path . '/etc/config.php'; if (file_exists($config_php)) { fatal('E01', 'You are already configurated'); } else { if (!is_writable($base_path . 'etc/')) { fatal('E02', "Can't write config file: make etc/ writable"); } else { if ($_SERVER['REQUEST_METHOD'] == 'POST') { //### TODO: fix inconsistent names $conf = array('url' => $base_url, 'module' => DEMO_MODULE, 'db_user' => $_POST['db_user'], 'db_pass' => $_POST['db_pass'], 'db_database' => $_POST['db_database'], 'db_server' => $_POST['db_server'], 'db_wart' => ''); // If database exists -- bail out if (database_exists($conf)) { fatal('E03', "Database exists"); } //### TODO: Error handling //### 2. Fields not filled in -- all req'd except password // Create config $f = fopen($config_php, 'w'); fwrite($f, make_config_file($conf)); fclose($f); // Create database $mysql_args = "--host={$conf['db_server']} --user={$conf['db_user']} --password={$conf['db_pass']}"; $shell_cmd = "{$base_path}bin/modinstall -m \"{$mysql_args}\" -s {$conf['module']} {$conf['db_database']}"; $response = array(); call_shell($shell_cmd, $response); // Print response //### TODO: should redirect???