Feature #272 - Installation scripts: The code for the)language selection box has been reworked. It is about language during installation procedure. Some other minor reworks.

skala
Ivan Tcholakov 15 years ago
parent b78abc370f
commit e3e823d8f6
  1. 85
      main/install/install_functions.inc.php
  2. 83
      main/install/install_upgrade.lib.php
  3. 23
      main/install/upgrade.php

@ -231,52 +231,19 @@ function get_config_param($param, $updatePath = '') {
*/ */
function get_config_param_from_db($host, $login, $pass, $db_name, $param = '') { function get_config_param_from_db($host, $login, $pass, $db_name, $param = '') {
$mydb = mysql_connect($host, $login, $pass); Database::connect(array('server' => $host, 'username' => $login, 'password' => $pass));
@mysql_query("set session sql_mode='';"); // Disabling special SQL modes (MySQL 5) Database::query("set session sql_mode='';"); // Disabling special SQL modes (MySQL 5)
Database::select_db($db_name);
$myconnect = mysql_select_db($db_name);
$sql = "SELECT * FROM settings_current WHERE variable = '$param'"; if (($res = Database::query("SELECT * FROM settings_current WHERE variable = '$param'")) !== false) {
$res = mysql_query($sql); if (Database::num_rows($res) > 0) {
if ($res === false) { $row = Database::fetch_array($res);
return null; return $row['selected_value'];
} }
if (mysql_num_rows($res) > 0) {
$row = mysql_fetch_array($res);
$value = $row['selected_value'];
return $value;
} }
return null; return null;
} }
/**
* TODO: The main API is accessible here. Then we could use a function for this purpose from there?
*
* Return a list of language directories.
* @todo function does not belong here, move to code library,
* also see infocours.php which contains similar function
*/
function get_language_folder_list($dirname) {
if ($dirname[strlen($dirname) - 1] != '/') {
$dirname .= '/';
}
$handle = opendir($dirname);
$language_list = array();
while ($entries = readdir($handle)) {
if ($entries == '.' || $entries == '..' || $entries=='CVS' || $entries == '.svn') {
continue;
}
if (is_dir($dirname.$entries)) {
$language_list[] = $entries;
}
}
closedir($handle);
return $language_list;
}
/* /*
============================================================================== ==============================================================================
DISPLAY FUNCTIONS DISPLAY FUNCTIONS
@ -284,34 +251,38 @@ function get_language_folder_list($dirname) {
*/ */
/** /**
* Displays a form (drop down menu) so the user can select * Displays a drop down box for selection the preferred language.
* his/her preferred language.
*/ */
function display_language_selection_box() { function display_language_selection_box() {
//get language list // Reading language list.
$language_list = get_language_folder_list(api_get_path(SYS_LANG_PATH)); $language_list = get_language_folder_list();
sort($language_list);
//Reduce the number of languages shown to only show those with higher than 90% translation in DLTT
//This option can be easily removed later on. The aim is to test people response to less choice
//$language_to_display = $language_list;
$language_to_display = array('asturian', 'bulgarian', 'english', 'italian', 'french', 'slovenian', 'slovenian_unicode', 'spanish');
//display /*
echo "\t\t<select name=\"language_list\">\n"; // Reduction of the number of languages shown. Enable this fragment of code for customization purposes.
// Modify the language list according to your preference. Don't exclude the 'english' item.
$language_to_display = array('asturian', 'bulgarian', 'english', 'italian', 'french', 'slovenian', 'slovenian_unicode', 'spanish');
foreach ($language_list as $key => & $value) {
if (!in_array($key, $language_to_display)) {
unset($language_list[$key]);
}
}
*/
// The default selection, it may be customized too.
$default_language = 'english'; $default_language = 'english';
foreach ($language_to_display as $key => $value) {
if ($value == $default_language) { // Displaying the box.
echo "\t\t<select name=\"language_list\">\n";
foreach ($language_list as $key => $value) {
if ($key == $default_language) {
$option_end = ' selected="selected">'; $option_end = ' selected="selected">';
} else { } else {
$option_end = '>'; $option_end = '>';
} }
echo "\t\t\t<option value=\"$value\"$option_end"; echo "\t\t\t<option value=\"$key\"$option_end";
echo $value;
echo api_ucfirst($value);
echo "</option>\n"; echo "</option>\n";
} }
echo "\t\t</select>\n"; echo "\t\t</select>\n";
} }

@ -46,8 +46,8 @@ function set_file_folder_permissions() {
*/ */
function fill_track_countries_table($track_countries_table) { function fill_track_countries_table($track_countries_table) {
$file_path = dirname(__FILE__).'/'.COUNTRY_DATA_FILENAME; $file_path = dirname(__FILE__).'/'.COUNTRY_DATA_FILENAME;
$add_country_sql = "LOAD DATA INFILE '".mysql_real_escape_string($file_path)."' INTO TABLE $track_countries_table FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\'';"; $add_country_sql = "LOAD DATA INFILE '".Database::escape_string($file_path)."' INTO TABLE $track_countries_table FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\'';";
@ mysql_query($add_country_sql); @ Database::query($add_country_sql);
} }
/** /**
@ -165,7 +165,7 @@ function load_main_database($installation_settings, $db_script = '') {
//replace symbolic parameters with user-specified values //replace symbolic parameters with user-specified values
foreach ($installation_settings as $key => $value) { foreach ($installation_settings as $key => $value) {
$dokeos_main_sql_file_string = str_replace($key, mysql_real_escape_string($value), $dokeos_main_sql_file_string); $dokeos_main_sql_file_string = str_replace($key, Database::escape_string($value), $dokeos_main_sql_file_string);
} }
//split in array of sql strings //split in array of sql strings
@ -176,7 +176,7 @@ function load_main_database($installation_settings, $db_script = '') {
$count = count($sql_instructions); $count = count($sql_instructions);
for ($i = 0; $i < $count; $i++) { for ($i = 0; $i < $count; $i++) {
$this_sql_query = $sql_instructions[$i]['query']; $this_sql_query = $sql_instructions[$i]['query'];
mysql_query($this_sql_query); Database::query($this_sql_query);
} }
} }
@ -195,7 +195,7 @@ function load_database_script($db_script) {
$count = count($sql_instructions); $count = count($sql_instructions);
for ($i = 0; $i < $count; $i++) { for ($i = 0; $i < $count; $i++) {
$this_sql_query = $sql_instructions[$i]['query']; $this_sql_query = $sql_instructions[$i]['query'];
mysql_query($this_sql_query); Database::query($this_sql_query);
} }
} }
@ -222,8 +222,8 @@ function split_sql_file(&$ret, $sql) {
$sql_len = strlen($sql); $sql_len = strlen($sql);
$char = ''; $char = '';
$string_start = ''; $string_start = '';
$in_string = FALSE; $in_string = false;
$nothing = TRUE; $nothing = true;
$time0 = time(); $time0 = time();
for ($i = 0; $i < $sql_len; ++$i) { for ($i = 0; $i < $sql_len; ++$i) {
@ -238,21 +238,21 @@ function split_sql_file(&$ret, $sql) {
// returned array // returned array
if (!$i) { if (!$i) {
$ret[] = $sql; $ret[] = $sql;
return TRUE; return true;
} }
// Backquotes or no backslashes before quotes: it's indeed the // Backquotes or no backslashes before quotes: it's indeed the
// end of the string -> exit the loop // end of the string -> exit the loop
else if ($string_start == '`' || $sql[$i-1] != '\\') { elseif ($string_start == '`' || $sql[$i - 1] != '\\') {
$string_start = ''; $string_start = '';
$in_string = FALSE; $in_string = false;
break; break;
} }
// one or more Backslashes before the presumed end of string... // one or more Backslashes before the presumed end of string...
else { else {
// ... first checks for escaped backslashes // ... first checks for escaped backslashes
$j = 2; $j = 2;
$escaped_backslash = FALSE; $escaped_backslash = false;
while ($i-$j > 0 && $sql[$i-$j] == '\\') { while ($i - $j > 0 && $sql[$i - $j] == '\\') {
$escaped_backslash = !$escaped_backslash; $escaped_backslash = !$escaped_backslash;
$j++; $j++;
} }
@ -260,7 +260,7 @@ function split_sql_file(&$ret, $sql) {
// string -> exit the loop // string -> exit the loop
if ($escaped_backslash) { if ($escaped_backslash) {
$string_start = ''; $string_start = '';
$in_string = FALSE; $in_string = false;
break; break;
} }
// ... else loop // ... else loop
@ -272,39 +272,39 @@ function split_sql_file(&$ret, $sql) {
} // end if (in string) } // end if (in string)
// lets skip comments (/*, -- and #) // lets skip comments (/*, -- and #)
else if (($char == '-' && $sql_len > $i + 2 && $sql[$i + 1] == '-' && $sql[$i + 2] <= ' ') || $char == '#' || ($char == '/' && $sql_len > $i + 1 && $sql[$i + 1] == '*')) { elseif (($char == '-' && $sql_len > $i + 2 && $sql[$i + 1] == '-' && $sql[$i + 2] <= ' ') || $char == '#' || ($char == '/' && $sql_len > $i + 1 && $sql[$i + 1] == '*')) {
$i = strpos($sql, $char == '/' ? '*/' : "\n", $i); $i = strpos($sql, $char == '/' ? '*/' : "\n", $i);
// didn't we hit end of string? // didn't we hit end of string?
if ($i === FALSE) { if ($i === false) {
break; break;
} }
if ($char == '/') $i++; if ($char == '/') $i++;
} }
// We are not in a string, first check for delimiter... // We are not in a string, first check for delimiter...
else if ($char == ';') { elseif ($char == ';') {
// if delimiter found, add the parsed part to the returned array // if delimiter found, add the parsed part to the returned array
$ret[] = array('query' => substr($sql, 0, $i), 'empty' => $nothing); $ret[] = array('query' => substr($sql, 0, $i), 'empty' => $nothing);
$nothing = TRUE; $nothing = true;
$sql = ltrim(substr($sql, min($i + 1, $sql_len))); $sql = ltrim(substr($sql, min($i + 1, $sql_len)));
$sql_len = strlen($sql); $sql_len = strlen($sql);
if ($sql_len) { if ($sql_len) {
$i = -1; $i = -1;
} else { } else {
// The submited statement(s) end(s) here // The submited statement(s) end(s) here
return TRUE; return true;
} }
} // end else if (is delimiter) } // end elseif (is delimiter)
// ... then check for start of a string,... // ... then check for start of a string,...
else if (($char == '"') || ($char == '\'') || ($char == '`')) { elseif (($char == '"') || ($char == '\'') || ($char == '`')) {
$in_string = TRUE; $in_string = true;
$nothing = FALSE; $nothing = false;
$string_start = $char; $string_start = $char;
} // end else if (is start of string) } // end elseif (is start of string)
elseif ($nothing) { elseif ($nothing) {
$nothing = FALSE; $nothing = false;
} }
// loic1: send a fake header each 30 sec. to bypass browser timeout // loic1: send a fake header each 30 sec. to bypass browser timeout
@ -320,8 +320,8 @@ function split_sql_file(&$ret, $sql) {
$ret[] = array('query' => $sql, 'empty' => $nothing); $ret[] = array('query' => $sql, 'empty' => $nothing);
} }
return TRUE; return true;
} // end of the 'PMA_splitSqlFile()' function } // end of the 'split_sql_file()' function
/** /**
* Get an SQL file's contents * Get an SQL file's contents
@ -367,7 +367,7 @@ function get_sql_file_contents($file, $section, $print_errors = true) {
if (substr($line, 0, 2) == '--') { if (substr($line, 0, 2) == '--') {
//This is a comment. Check if section name, otherwise ignore //This is a comment. Check if section name, otherwise ignore
$result = array(); $result = array();
if (preg_match('/^-- xx([A-Z]*)xx/', $line,$result)) { //we got a section name here if (preg_match('/^-- xx([A-Z]*)xx/', $line, $result)) { //we got a section name here
if ($result[1] == strtoupper($section)) { if ($result[1] == strtoupper($section)) {
//we have the section we are looking for, start recording //we have the section we are looking for, start recording
$record = true; $record = true;
@ -391,6 +391,29 @@ function get_sql_file_contents($file, $section, $print_errors = true) {
return $section_contents; return $section_contents;
} }
/**
* Returns a list of language directories.
*/
function get_language_folder_list() {
$result = array();
$exceptions = array('.', '..', 'CVS', '.svn');
$search = array('_latin', '_unicode', '_corporate', '_org' , '_KM', '_');
$replace_with = array(' (Latin)', ' (unicode)', ' (corporate)', ' (org)', ' (KM)', ' ');
$dirname = api_get_path(SYS_LANG_PATH);
$handle = opendir($dirname);
while ($entries = readdir($handle)) {
if (in_array($entries, $exceptions)) {
continue;
}
if (is_dir($dirname.$entries)) {
$result[$entries] = ucwords(str_replace($search, $replace_with, $entries));
}
}
closedir($handle);
asort($result);
return $result;
}
// TODO: Maybe within the main API there is already a suitable function? // TODO: Maybe within the main API there is already a suitable function?
function my_directory_to_array($directory) { function my_directory_to_array($directory) {
$array_items = array(); $array_items = array();
@ -426,10 +449,10 @@ function add_document_180($_course, $path, $filetype, $filesize, $title, $commen
VALUES ('$path','$filetype','$filesize','". VALUES ('$path','$filetype','$filesize','".
Database::escape_string($title)."', '$comment')"; Database::escape_string($title)."', '$comment')";
if (Database::query($sql)) { if (Database::query($sql)) {
//display_message("Added to database (id ".mysql_insert_id().")!"); //display_message("Added to database (id ".Database::insert_id().")!");
return mysql_insert_id(); return Database::insert_id();
} else { } else {
//display_error("The uploaded file could not be added to the database (".mysql_error().")!"); //display_error("The uploaded file could not be added to the database (".Database::error().")!");
return false; return false;
} }
} }

@ -589,29 +589,6 @@ function display_upgrade_header($text_dir, $dokeos_version, $install_type, $upda
<?php <?php
} }
/**
* TODO: Copy/paste again. Find an existing function for this job.
* Return a list of language directories.
* @todo function does not belong here, move to code library,
* also see infocours.php which contains similar function
*/
function get_language_folder_list() {
$dirname = dirname(__FILE__).'/../lang';
if ($dirname[strlen($dirname) - 1] != '/')
$dirname .= '/';
$handle = opendir($dirname);
while ($entries = readdir($handle)) {
if ($entries == '.' || $entries == '..' || $entries == '.svn')
continue;
if (is_dir($dirname.$entries)) {
$language_list[$entries] = api_ucfirst($entries);
}
}
closedir($handle);
asort($language_list);
return $language_list;
}
function display_installation_overview() { function display_installation_overview() {
echo '<div id="installation_steps">'; echo '<div id="installation_steps">';
echo '<img src="../img/bluelogo.gif" hspace="10" vspace="10" alt="Dokeos logo" />'; echo '<img src="../img/bluelogo.gif" hspace="10" vspace="10" alt="Dokeos logo" />';

Loading…
Cancel
Save