浏览代码

Feature #272 - Installation scripts: More reworks about the language selection boxes.

Ivan Tcholakov 15 年之前
父节点
当前提交
46b029e0af
共有 3 个文件被更改,包括 46 次插入64 次删除
  1. 19 16
      main/install/index.php
  2. 21 42
      main/install/install_functions.inc.php
  3. 6 6
      main/install/install_upgrade.lib.php

+ 19 - 16
main/install/index.php

@@ -53,6 +53,7 @@ $_setting = array(
 );
 
 // Loading language files.
+// TODO: It would be nice browser's intrface language to be detected at this point.
 require api_get_path(SYS_LANG_PATH).'english/trad4all.inc.php';
 require api_get_path(SYS_LANG_PATH).'english/install.inc.php';
 if (!empty($_POST['language_list'])) {
@@ -202,14 +203,14 @@ if ($installType == 'update' && in_array($my_old_version, $update_from_version_8
 
 if (!isset($_GET['running'])) {
 
-	$dbHostForm		='localhost';
-	$dbUsernameForm	='root';
-	$dbPassForm		='';
- 	$dbPrefixForm	='';
-	$dbNameForm		='chamilo_main';
-	$dbStatsForm	='chamilo_stats';
-	$dbScormForm	='chamilo_scorm';
-	$dbUserForm		='chamilo_user';
+	$dbHostForm		= 'localhost';
+	$dbUsernameForm	= 'root';
+	$dbPassForm		= '';
+ 	$dbPrefixForm	= '';
+	$dbNameForm		= 'chamilo_main';
+	$dbStatsForm	= 'chamilo_stats';
+	$dbScormForm	= 'chamilo_scorm';
+	$dbUserForm		= 'chamilo_user';
 
 	// Extract the path to append to the url if Chamilo is not installed on the web root directory.
 	$urlAppendPath = api_remove_trailing_slash(api_get_path(REL_PATH));
@@ -232,16 +233,18 @@ if (!isset($_GET['running'])) {
 	$institutionForm    = 'My Organisation';
 	$institutionUrlForm = 'http://www.chamilo.org';
 	$languageForm	    = 'english';
+	// TODO: A better choice to be tested:
+	//$languageForm	    = api_get_interface_language();
 
-	$checkEmailByHashSent = 0;
+	$checkEmailByHashSent	= 0;
 	$ShowEmailnotcheckedToStudent = 1;
-	$userMailCanBeEmpty = 1;
-	$allowSelfReg = 1;
-	$allowSelfRegProf = 1;
-	$enableTrackingForm = 1;
-	$singleDbForm = 0;
-	$encryptPassForm = 'md5';
-	$session_lifetime = 360000;
+	$userMailCanBeEmpty		= 1;
+	$allowSelfReg			= 1;
+	$allowSelfRegProf		= 1;
+	$enableTrackingForm		= 1;
+	$singleDbForm			= 0;
+	$encryptPassForm		= 'md5';
+	$session_lifetime		= 360000;
 
 } else {
 

+ 21 - 42
main/install/install_functions.inc.php

@@ -253,7 +253,7 @@ function get_config_param_from_db($host, $login, $pass, $db_name, $param = '') {
 /**
  *	Displays a drop down box for selection the preferred language.
  */
-function display_language_selection_box() {
+function display_language_selection_box($name = 'language_list', $default_language = 'english') {
 	// Reading language list.
 	$language_list = get_language_folder_list();
 
@@ -268,11 +268,26 @@ function display_language_selection_box() {
 	}
 	*/
 
-	// The default selection, it may be customized too.
-	$default_language = 'english';
+	// Sanity checks due to the possibility for customizations.
+	if (!is_array($language_list) || empty($language_list)) {
+		$language_list = array('english' => 'English');
+	}
+
+	// Sorting again, if it is necessary.
+	//asort($language_list);
+
+	// More sanity checks.
+	if (!array_key_exists($default_language, $language_list)) {
+		if (array_key_exists('english', $language_list)) {
+			$default_language = 'english';
+		} else {
+			$language_keys = array_keys($language_list);
+			$default_language = $language_keys[0];
+		}
+	}
 
 	// Displaying the box.
-	echo "\t\t<select name=\"language_list\">\n";
+	echo "\t\t<select name=\"$name\">\n";
 	foreach ($language_list as $key => $value) {
 		if ($key == $default_language) {
 			$option_end = ' selected="selected">';
@@ -295,7 +310,7 @@ function display_language_selection() { ?>
 	<h2><?php echo display_step_sequence(); ?><?php echo get_lang('InstallationLanguage'); ?></h2>
 	<p><?php echo get_lang('PleaseSelectInstallationProcessLanguage'); ?>:</p>
 	<form id="lang_form" method="post" action="<?php echo api_get_self(); ?>">
-<?php display_language_selection_box(); ?>
+<?php display_language_selection_box('language_list', api_get_interface_language()); ?>
 	<button type="submit" name="step1" class="next" value="<?php get_lang('Next'); ?> &gt;"><?php echo get_lang('Next'); ?></button>
 	<input type="hidden" name="is_executable" id="is_executable" value="-" />
 	</form>
@@ -903,44 +918,8 @@ function display_configuration_settings_form($installType, $urlForm, $languageFo
 
 		echo '<td>';
 
-		$array_lang = array('asturian', 'bulgarian', 'english', 'italian', 'french', 'slovenian', 'spanish');
-
-		////Only display Language have 90% + // TODO: Ivan: Is this policy actual? I am going to change it.
-		echo "\t\t<select name=\"languageForm\">\n";
-
-		foreach ($array_lang as $key => $value)	{
-			echo '<option value="'.$value.'"';
-			if ($value == $languageForm) {
-				echo ' selected="selected"';
-			}
-			echo ">$value</option>\n";
-		}
-
-		echo "\t\t</select>\n";
-
-		//Display all language
-		/*echo "<select name=\"languageForm\">\n";
-		$dirname = '../lang/';
+		display_language_selection_box('languageForm', $languageForm);
 
-		if ($dir = @opendir($dirname)) {
-			$lang_files = array();
-			while (($file = readdir($dir)) !== false) {
-				if($file != '.' && $file != '..' && $file != 'CVS' && $file != '.svn' && is_dir($dirname.$file)){
-					array_push($lang_files, $file);
-				}
-			}
-			closedir($dir);
-		}
-		sort($lang_files);
-
-		foreach ($lang_files as $file) {
-			echo '<option value="'.$file.'"';
-			if ($file == $languageForm) {
-				echo ' selected="selected"';
-			}
-			echo ">$file</option>\n";
-		}
-		echo '</select>';*/
 		echo "</td>\n";
 	}
 	echo "</tr>\n";

+ 6 - 6
main/install/install_upgrade.lib.php

@@ -158,19 +158,19 @@ function write_system_config_file($path) {
  */
 function load_main_database($installation_settings, $db_script = '') {
 	if (!empty($db_script)) {
-		$dokeos_main_sql_file_string = file_get_contents($db_script);
+		$sql_text = file_get_contents($db_script);
 	} else {
-		$dokeos_main_sql_file_string = file_get_contents(SYSTEM_MAIN_DATABASE_FILE);
+		$sql_text = file_get_contents(SYSTEM_MAIN_DATABASE_FILE);
 	}
 
 	//replace symbolic parameters with user-specified values
 	foreach ($installation_settings as $key => $value) {
-		$dokeos_main_sql_file_string = str_replace($key, Database::escape_string($value), $dokeos_main_sql_file_string);
+		$sql_text = str_replace($key, Database::escape_string($value), $sql_text);
 	}
 
 	//split in array of sql strings
 	$sql_instructions = array();
-	$success = split_sql_file($sql_instructions, $dokeos_main_sql_file_string);
+	$success = split_sql_file($sql_instructions, $sql_text);
 
 	//execute the sql instructions
 	$count = count($sql_instructions);
@@ -185,11 +185,11 @@ function load_main_database($installation_settings, $db_script = '') {
  * @param	string	Name of the file containing the SQL script inside the install directory
  */
 function load_database_script($db_script) {
-	$dokeos_sql_file_string = file_get_contents($db_script);
+	$sql_text = file_get_contents($db_script);
 
 	//split in array of sql strings
 	$sql_instructions = array();
-	$success = split_sql_file($sql_instructions, $dokeos_sql_file_string);
+	$success = split_sql_file($sql_instructions, $sql_text);
 
 	//execute the sql instructions
 	$count = count($sql_instructions);