/**
 * 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)
{
    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 = isset($_configuration['tracking_enabled']) ? $_configuration['tracking_enabled'] : null;
            $singleDbForm = isset($_configuration['single_database']) ? $_configuration['single_database'] : null;
            $dbNameForm = $_configuration['main_database'];
            $dbStatsForm = isset($_configuration['statistics_database']) ? $_configuration['statistics_database'] : null;
            $dbScormForm = isset($_configuration['scorm_database']) ? $_configuration['scorm_database'] : null;
            $dbUserForm = isset($_configuration['user_personal_database']) ? $_configuration['user_personal_database'] : null;
            $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() . translate('DBSetting') . '</h2></div>';
        echo '<div class="RequirementContent">';
        echo translate('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() . translate('DBSetting') . '</h2></div>';
        echo '<div class="RequirementContent">';
        echo translate('DBSettingIntro');
        echo '</div>';
    }
    ?>
</td>
</tr>
    <tr>
    <td>
    <table class="data_table_no_border">
        <tr>
            <td width="40%"><?php 
    echo translate('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%">&nbsp;</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 translate('EG') . ' localhost';
        ?>
</td>
            <?php 
    }
    ?>
        </tr>
        <tr>
            <?php 
    //database user username
    $example_login = translate('EG') . ' root';
    display_database_parameter($installType, translate('DBLogin'), 'dbUsernameForm', $dbUsernameForm, $example_login);
    //database user password
    $example_password = translate('EG') . ' ' . api_generate_password();
    display_database_parameter($installType, translate('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 = api_replace_dangerous_char($dbNameForm);
    }
    display_database_parameter($installType, translate('MainDB'), 'dbNameForm', $dbNameForm, '&nbsp;', null, 'id="optional_param1" ' . $style);
    ?>
        <tr>
            <td></td>
            <td>
                <button type="submit" class="btn" name="step3"value="<?php 
    echo translate('CheckDatabaseConnection');
    ?>
">
                    <?php 
    echo translate('CheckDatabaseConnection');
    ?>
</button>
            </td>
        </tr>
        <tr>
        <td>
            <?php 
    $dbConnect = testDatabaseConnect($dbHostForm, $dbUsernameForm, $dbPassForm, $singleDbForm, $dbPrefixForm, $dbNameForm);
    $database_exists_text = '';
    if ($dbConnect) {
        $multipleDbCheck = Database::query("CREATE DATABASE " . mysql_real_escape_string($dbNameForm));
        if ($multipleDbCheck !== false) {
            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(translate('DatabaseXWillBeCreated'), $dbNameForm, $dbUsernameForm) . '</div>';
        } else {
            $dbConnect = 0;
            $database_exists_text = '<div class="warning-message">' . sprintf(translate('DatabaseXCantBeCreatedUserXDoestHaveEnoughPermissions'), $dbNameForm, $dbUsernameForm) . '</div>';
        }
    } else {
        echo '<div class="warning-message">' . sprintf(translate('UserXCantHaveAccessInTheDatabaseX'), $dbUsernameForm, $dbNameForm) . '</div>';
    }
    if ($dbConnect == 1) {
        ?>
                <td colspan="2">
                    <?php 
        echo $database_exists_text;
        ?>
                    <div id="db_status" class="confirmation-message">


                        <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 translate('FailedConectionDatabase');
        ?>
</strong><br/>

                        </div>
                    </div>
                </td>
                <?php 
    }
    ?>
        </tr>
        <tr>
            <td>
                <button type="submit" name="step2" class="back"
                        value="&lt; <?php 
    echo translate('Previous');
    ?>
"><?php 
    echo translate('Previous');
    ?>
</button>
            </td>
            <td>&nbsp;</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 translate('Next');
        ?>
 &gt;" <?php 
        if ($dbConnect == 1) {
            echo 'autofocus="autofocus"';
        }
        ?>
 /><?php 
        echo translate('Next');
        ?>
</button>
                <?php 
    } else {
        ?>
                <button disabled="disabled" type="submit" class="btn next disabled" name="step4"
                        value="<?php 
        echo translate('Next');
        ?>
 &gt;"/><?php 
        echo translate('Next');
        ?>
</button>
                <?php 
    }
    ?>
            </td>
        </tr>
    </table>
    <?php 
}
				foreach ($u_q_list as $query) {
					if ($only_test) {
						 Log::notice("iDatabase::query($dbUserForm,$query)");
						 Log::notice("In $dbUserForm, executed: $query");
					} else {
						$res = iDatabase::query($query);
					}
				}
			}
		}
		// The SCORM database doesn't need a change in the pre-migrate part - ignore
	}

	$prefix = '';
	if ($singleDbForm) {
		$prefix =  get_config_param ('table_prefix');
	}

	// Get the courses databases queries list (c_q_list)
	$c_q_list = get_sql_file_contents('migrate-db-'.$old_file_version.'-'.$new_file_version.'-pre.sql', 'course');

	if (count($c_q_list) > 0) {
		// Get the courses list
		if (strlen($dbNameForm) > 40) {
			 Log::error('Database name '.$dbNameForm.' is too long, skipping');
		} elseif (!in_array($dbNameForm, $dblist)) {
			 Log::error('Database '.$dbNameForm.' was not found, skipping');
		} else {
			iDatabase::select_db($dbNameForm);
			$res = iDatabase::query("SELECT code,db_name,directory,course_language FROM course WHERE target_course_code IS NULL ORDER BY code");
Beispiel #3
0
 }
 $tmp = get_config_param_from_db('siteName');
 if (!empty($tmp)) {
     $campusForm = $tmp;
 }
 $tmp = get_config_param_from_db('Institution');
 if (!empty($tmp)) {
     $institutionForm = $tmp;
 }
 $tmp = get_config_param_from_db('InstitutionUrl');
 if (!empty($tmp)) {
     $institutionUrlForm = $tmp;
 }
 // For version 1.9
 $urlForm = $_configuration['root_web'];
 $encryptPassForm = get_config_param('password_encryption');
 // Managing the $encryptPassForm
 if ($encryptPassForm == '1') {
     $encryptPassForm = 'sha1';
 } elseif ($encryptPassForm == '0') {
     $encryptPassForm = 'none';
 }
 $allowSelfReg = false;
 $tmp = get_config_param_from_db('allow_registration');
 if (!empty($tmp)) {
     $allowSelfReg = $tmp;
 }
 $allowSelfRegProf = false;
 $tmp = get_config_param_from_db('allow_registration_as_teacher');
 if (!empty($tmp)) {
     $allowSelfRegProf = $tmp;
Beispiel #4
0
		if (empty($my_old_version)) { $my_old_version = '1.8.6.2'; } //we guess

		$_configuration['main_database'] = $dbNameForm;
		//$urlAppendPath = get_config_param('urlAppend');
        Log::notice('Starting migration process from '.$my_old_version.' ('.time().')');

    	if ($userPasswordCrypted == '1') {
			$userPasswordCrypted = 'md5';
		} elseif ($userPasswordCrypted == '0') {
			$userPasswordCrypted = 'none';
		}
        
        //Setting the single db form
        if (in_array($_POST['old_version'], $update_from_version_6)) {            
            $singleDbForm   	= get_config_param('singleDbEnabled');            
        } else {
            $singleDbForm   	= isset($_configuration['single_database']) ? $_configuration['single_database'] : false;            
        }
        
        Log::notice("singledbForm: '$singleDbForm'");
        
		Database::query("SET storage_engine = MYISAM;");

		if (version_compare($my_old_version, '1.8.7', '>=')) {
			Database::query("SET SESSION character_set_server='utf8';");
			Database::query("SET SESSION collation_server='utf8_general_ci';");
			//Database::query("SET CHARACTER SET 'utf8';"); // See task #1802.
			Database::query("SET NAMES 'utf8';");
		}
    // Check if the current Dokeos install is eligible for update
    if (!file_exists('../inc/conf/configuration.php')) {
        echo '<strong>' . get_lang('Error') . ' !</strong> Dokeos ' . implode('|', $updateFromVersion) . ' ' . get_lang('HasNotBeenFound') . '.<br /><br />
								' . get_lang('PleasGoBackToStep1') . '.
							    <p><button type="submit" class="back" name="step1" value="&lt; ' . get_lang('Back') . '">' . get_lang('Back') . '</button></p>
							    </td></tr></table></form></body></html>';
        exit();
    }

    $_configuration['db_glue'] = get_config_param('dbGlu');

    if ($singleDbForm) {
        $_configuration['table_prefix'] = get_config_param('courseTablePrefix');
        $_configuration['main_database'] = get_config_param('mainDbName');
        $_configuration['db_prefix'] = get_config_param('dbNamePrefix');
    }

    $dbScormForm = preg_replace('/[^a-zA-Z0-9_\-]/', '', $dbScormForm);

    if (!empty($dbPrefixForm) && strpos($dbScormForm, $dbPrefixForm) !== 0) {
        $dbScormForm = $dbPrefixForm . $dbScormForm;
    }

    if (empty($dbScormForm) || $dbScormForm == 'mysql' || $dbScormForm == $dbPrefixForm) {
        $dbScormForm = $dbPrefixForm . 'scorm';
    }

    /* 	Normal upgrade procedure: start by updating main, statistic, user databases */

    // If this script has been included by index.php, not update_courses.php, so
Beispiel #6
0
 }
 $tmp = get_config_param_from_db('siteName');
 if (!empty($tmp)) {
     $campusForm = $tmp;
 }
 $tmp = get_config_param_from_db('Institution');
 if (!empty($tmp)) {
     $institutionForm = $tmp;
 }
 $tmp = get_config_param_from_db('InstitutionUrl');
 if (!empty($tmp)) {
     $institutionUrlForm = $tmp;
 }
 // For version 1.9
 $urlForm = $_configuration['root_web'];
 $encryptPassForm = get_config_param('userPasswordCrypted');
 // Managing the $encryptPassForm
 if ($encryptPassForm == '1') {
     $encryptPassForm = 'sha1';
 } elseif ($encryptPassForm == '0') {
     $encryptPassForm = 'none';
 }
 $allowSelfReg = false;
 $tmp = get_config_param_from_db('allow_registration');
 if (!empty($tmp)) {
     $allowSelfReg = $tmp;
 }
 $allowSelfRegProf = false;
 $tmp = get_config_param_from_db('allow_registration_as_teacher');
 if (!empty($tmp)) {
     $allowSelfRegProf = $tmp;