diff --git a/main/inc/lib/database.lib.php b/main/inc/lib/database.lib.php
index a35ac01a33..2d19ac891e 100755
--- a/main/inc/lib/database.lib.php
+++ b/main/inc/lib/database.lib.php
@@ -239,7 +239,6 @@ define('TABLE_USER_COURSE_CATEGORY', 'user_course_category');
// @TODO: Are these MAIN tables or course tables?
// @TODO: Probably these constants are obsolete.
define('TABLE_MAIN_SURVEY', 'survey');
-define('TABLE_MAIN_GROUP', 'survey_group');
define('TABLE_MAIN_SURVEYQUESTION', 'questions');
// Survey
diff --git a/main/inc/lib/internationalization.lib.php b/main/inc/lib/internationalization.lib.php
index 14460477f3..a74ffe5aae 100755
--- a/main/inc/lib/internationalization.lib.php
+++ b/main/inc/lib/internationalization.lib.php
@@ -3243,10 +3243,11 @@ function api_is_valid_utf8(&$string) {
// wrongly detected as UTF-8. Possibly, there would be problems with other
// languages too. An alternative implementation will be used.
- $len = api_byte_count($string);
+ $str = (string)$string;
+ $len = api_byte_count($str);
$i = 0;
while ($i < $len) {
- $byte1 = ord($string[$i++]); // Here the current character begins. Its size is
+ $byte1 = ord($str[$i++]); // Here the current character begins. Its size is
// determined by the senior bits in the first byte.
if (($byte1 & 0x80) == 0x00) { // 0xxxxxxx
@@ -3267,7 +3268,7 @@ function api_is_valid_utf8(&$string) {
return false; // Here the string ends unexpectedly.
}
- if (!((ord($string[$i++]) & 0xC0) == 0x80))
+ if (!((ord($str[$i++]) & 0xC0) == 0x80))
return false; // Invalid second byte, invalid string.
}
@@ -3280,13 +3281,13 @@ function api_is_valid_utf8(&$string) {
if ($i == $len) {
return false; // Unexpected end of the string.
}
- if (!((ord($string[$i++]) & 0xC0) == 0x80)) {
+ if (!((ord($str[$i++]) & 0xC0) == 0x80)) {
return false; // Invalid second byte.
}
if ($i == $len) {
return false; // Unexpected end of the string.
}
- if (!((ord($string[$i++]) & 0xC0) == 0x80)) {
+ if (!((ord($str[$i++]) & 0xC0) == 0x80)) {
return false; // Invalid third byte, invalid string.
}
}
@@ -3300,19 +3301,19 @@ function api_is_valid_utf8(&$string) {
if ($i == $len) {
return false;
}
- if (!((ord($string[$i++]) & 0xC0) == 0x80)) {
+ if (!((ord($str[$i++]) & 0xC0) == 0x80)) {
return false;
}
if ($i == $len) {
return false;
}
- if (!((ord($string[$i++]) & 0xC0) == 0x80)) {
+ if (!((ord($str[$i++]) & 0xC0) == 0x80)) {
return false;
}
if ($i == $len) {
return false;
}
- if (!((ord($string[$i++]) & 0xC0) == 0x80)) {
+ if (!((ord($str[$i++]) & 0xC0) == 0x80)) {
return false;
}
}
@@ -3326,25 +3327,25 @@ function api_is_valid_utf8(&$string) {
if ($i == $len) {
return false;
}
- if (!((ord($string[$i++]) & 0xC0) == 0x80)) {
+ if (!((ord($str[$i++]) & 0xC0) == 0x80)) {
return false;
}
if ($i == $len) {
return false;
}
- if (!((ord($string[$i++]) & 0xC0) == 0x80)) {
+ if (!((ord($str[$i++]) & 0xC0) == 0x80)) {
return false;
}
if ($i == $len) {
return false;
}
- if (!((ord($string[$i++]) & 0xC0) == 0x80)) {
+ if (!((ord($str[$i++]) & 0xC0) == 0x80)) {
return false;
}
if ($i == $len) {
return false;
}
- if (!((ord($string[$i++]) & 0xC0) == 0x80)) {
+ if (!((ord($str[$i++]) & 0xC0) == 0x80)) {
return false;
}
}
@@ -3358,31 +3359,31 @@ function api_is_valid_utf8(&$string) {
if ($i == $len) {
return false;
}
- if (!((ord($string[$i++]) & 0xC0) == 0x80)) {
+ if (!((ord($str[$i++]) & 0xC0) == 0x80)) {
return false;
}
if ($i == $len) {
return false;
}
- if (!((ord($string[$i++]) & 0xC0) == 0x80)) {
+ if (!((ord($str[$i++]) & 0xC0) == 0x80)) {
return false;
}
if ($i == $len) {
return false;
}
- if (!((ord($string[$i++]) & 0xC0) == 0x80)) {
+ if (!((ord($str[$i++]) & 0xC0) == 0x80)) {
return false;
}
if ($i == $len) {
return false;
}
- if (!((ord($string[$i++]) & 0xC0) == 0x80)) {
+ if (!((ord($str[$i++]) & 0xC0) == 0x80)) {
return false;
}
if ($i == $len) {
return false;
}
- if (!((ord($string[$i++]) & 0xC0) == 0x80)) {
+ if (!((ord($str[$i++]) & 0xC0) == 0x80)) {
return false;
}
}
@@ -3428,17 +3429,21 @@ function api_is_valid_ascii(&$string) {
* @link http://php.net/manual/en/function.str-getcsv.php (exists as of PHP 5 >= 5.3.0)
*/
function & api_str_getcsv(& $string, $delimiter = ',', $enclosure = '"', $escape = '\\') {
+ $delimiter = (string)$delimiter;
if (api_byte_count($delimiter) > 1) { $delimiter = $delimiter[1]; }
+ $enclosure = (string)$enclosure;
if (api_byte_count($enclosure) > 1) { $enclosure = $enclosure[1]; }
+ $escape = (string)$escape;
if (api_byte_count($escape) > 1) { $escape = $escape[1]; }
- $len = api_byte_count($string);
+ $str = (string)$string;
+ $len = api_byte_count($str);
$enclosed = false;
$escaped = false;
$value = '';
$result = array();
for ($i = 0; $i < $len; $i++) {
- $char = $string[$i];
+ $char = $str[$i];
if ($char == $escape) {
if (!$escaped) {
$escaped = true;
@@ -3448,7 +3453,7 @@ function & api_str_getcsv(& $string, $delimiter = ',', $enclosure = '"', $escape
$escaped = false;
switch ($char) {
case $enclosure:
- if ($enclosed && $string[$i + 1] == $enclosure) {
+ if ($enclosed && $str[$i + 1] == $enclosure) {
$value .= $char;
$i++;
} else {
diff --git a/main/inc/lib/internationalization_internal.lib.php b/main/inc/lib/internationalization_internal.lib.php
index b8f7fb632b..c9dd95e18a 100755
--- a/main/inc/lib/internationalization_internal.lib.php
+++ b/main/inc/lib/internationalization_internal.lib.php
@@ -331,45 +331,46 @@ function _api_clean_person_name($person_name) {
* @param string $from_encoding The encoding that $string is being converted from.
* @return string Returns the converted string.
*/
-function _api_convert_encoding($string, $to_encoding, $from_encoding) {
+function _api_convert_encoding(&$string, $to_encoding, $from_encoding) {
+ $str = (string)$string;
static $character_map = array();
static $utf8_compatible = array('UTF-8', 'US-ASCII');
- if (empty($string)) {
- return $string;
+ if (empty($str)) {
+ return $str;
}
$to_encoding = api_refine_encoding_id($to_encoding);
$from_encoding = api_refine_encoding_id($from_encoding);
if (api_equal_encodings($to_encoding, $from_encoding)) {
- return $string;
+ return $str;
}
if ($to_encoding == 'HTML-ENTITIES') {
- return api_htmlentities($string, ENT_QUOTES, $from_encoding);
+ return api_htmlentities($str, ENT_QUOTES, $from_encoding);
}
if ($from_encoding == 'HTML-ENTITIES') {
- return api_html_entity_decode($string, ENT_QUOTES, $to_encoding);
+ return api_html_entity_decode($str, ENT_QUOTES, $to_encoding);
}
$to = _api_get_character_map_name($to_encoding);
$from = _api_get_character_map_name($from_encoding);
if (empty($to) || empty($from) || $to == $from || (in_array($to, $utf8_compatible) && in_array($from, $utf8_compatible))) {
- return $string;
+ return $str;
}
if (!isset($character_map[$to])) {
$character_map[$to] = &_api_parse_character_map($to);
}
if ($character_map[$to] === false) {
- return $string;
+ return $str;
}
if (!isset($character_map[$from])) {
$character_map[$from] = &_api_parse_character_map($from);
}
if ($character_map[$from] === false) {
- return $string;
+ return $str;
}
if ($from != 'UTF-8') {
- $len = api_byte_count($string);
+ $len = api_byte_count($str);
$codepoints = array();
for ($i = 0; $i < $len; $i++) {
- $ord = ord($string[$i]);
+ $ord = ord($str[$i]);
if ($ord > 127) {
if (isset($character_map[$from]['local'][$ord])) {
$codepoints[] = $character_map[$from]['local'][$ord];
@@ -381,7 +382,7 @@ function _api_convert_encoding($string, $to_encoding, $from_encoding) {
}
}
} else {
- $codepoints = _api_utf8_to_unicode($string);
+ $codepoints = _api_utf8_to_unicode($str);
}
if ($to != 'UTF-8') {
foreach ($codepoints as $i => &$codepoint) {
@@ -395,11 +396,11 @@ function _api_convert_encoding($string, $to_encoding, $from_encoding) {
$codepoint = chr($codepoint);
}
}
- $string = implode($codepoints);
+ $str = implode($codepoints);
} else {
- $string = _api_utf8_from_unicode($codepoints);
+ $str = _api_utf8_from_unicode($codepoints);
}
- return $string;
+ return $str;
}
/**
@@ -468,16 +469,16 @@ function &_api_parse_character_map($name) {
* @link http://hsivonen.iki.fi/php-utf8/
* @author Ivan Tcholakov, August 2009, adaptation for the Dokeos LMS.
*/
-function _api_utf8_to_unicode($string) {
- if (!is_string($string)) { $string = (string)$string; } // A quick workaround after testing.
+function _api_utf8_to_unicode(&$string) {
+ $str = (string)$string;
$state = 0; // cached expected number of octets after the current octet
// until the beginning of the next UTF8 character sequence
$codepoint = 0; // cached Unicode character
$bytes = 1; // cached expected number of octets in the current sequence
$result = array();
- $len = api_byte_count($string);
+ $len = api_byte_count($str);
for ($i = 0; $i < $len; $i++) {
- $byte = ord($string[$i]);
+ $byte = ord($str[$i]);
if ($state == 0) {
// When state is zero we expect either a US-ASCII character or a multi-octet sequence.
if (0 == (0x80 & ($byte))) {
diff --git a/main/inc/lib/main_api.lib.php b/main/inc/lib/main_api.lib.php
index 13c9e260fe..c3032b930f 100755
--- a/main/inc/lib/main_api.lib.php
+++ b/main/inc/lib/main_api.lib.php
@@ -331,7 +331,6 @@ function api_get_path($path_type, $path = null) {
WEB_PATH => '',
SYS_PATH => '',
REL_PATH => '',
- REL_SYS_PATH => '',
WEB_SERVER_ROOT_PATH => '',
SYS_SERVER_ROOT_PATH => '',
WEB_COURSE_PATH => '',
@@ -2557,20 +2556,21 @@ function api_get_languages_combo($name = 'language') {
* @return void Display the box directly
*/
function api_display_language_form($hide_if_no_choice = false) {
- $platformLanguage = api_get_setting('platformLanguage');
- $dirname = api_get_path(SYS_PATH).'main/lang/'; // TODO: this line is probably no longer needed
+
// retrieve a complete list of all the languages.
$language_list = api_get_languages();
if (count($language_list['name']) <= 1 && $hide_if_no_choice) {
return; //don't show any form
}
+
// the the current language of the user so that his/her language occurs as selected in the dropdown menu
if (isset($_SESSION['user_language_choice'])) {
$user_selected_language = $_SESSION['user_language_choice'];
}
- if (!isset($user_selected_language)) {
- $user_selected_language = $platformLanguage;
+ if (empty($user_selected_language)) {
+ $user_selected_language = api_get_setting('platformLanguage');
}
+
$original_languages = $language_list['name'];
$folder = $language_list['folder']; // this line is probably no longer needed
?>
@@ -3136,11 +3136,11 @@ function api_chmod_R($path, $filemode) {
*/
function parse_info_file($filename) {
$info = array();
-
+
if (!file_exists($filename)) {
return $info;
}
-
+
$data = file_get_contents($filename);
if (preg_match_all('
@^\s* # Start at the beginning of a line, ignoring leading whitespace
@@ -3162,12 +3162,12 @@ function api_chmod_R($path, $filemode) {
$$var = isset($match[++$i]) ? $match[$i] : '';
}
$value = stripslashes(substr($value1, 1, -1)) . stripslashes(substr($value2, 1, -1)) . $value3;
-
+
// Parse array syntax
$keys = preg_split('/\]?\[/', rtrim($key, ']'));
$last = array_pop($keys);
$parent = &$info;
-
+
// Create nested arrays
foreach ($keys as $key) {
if ($key == '') {
@@ -3178,12 +3178,12 @@ function api_chmod_R($path, $filemode) {
}
$parent = &$parent[$key];
}
-
+
// Handle PHP constants
if (defined($value)) {
$value = constant($value);
}
-
+
// Insert actual value
if ($last == '') {
$last = count($parent);
diff --git a/main/install/index.php b/main/install/index.php
index c871e75f97..6d6f2621fe 100755
--- a/main/install/index.php
+++ b/main/install/index.php
@@ -40,7 +40,6 @@ if (!function_exists('version_compare') || version_compare( phpversion(), REQUIR
session_start();
// Including necessary core libraries.
-//@include '../inc/installedVersion.inc.php'; //TODO: This line is to be removed.
require '../inc/lib/main_api.lib.php';
require api_get_path(LIBRARY_PATH).'database.lib.php';
@@ -54,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'])) {
@@ -91,7 +91,7 @@ require_once 'install_upgrade.lib.php'; //also defines constants
require_once 'install_functions.inc.php';
// Some constants
-define('DOKEOS_INSTALL', 1);
+define('SYSTEM_INSTALLATION', 1);
define('MAX_COURSE_TRANSFER', 100);
define('INSTALL_TYPE_UPDATE', 'update');
define('FORM_FIELD_DISPLAY_LENGTH', 40);
@@ -155,14 +155,7 @@ if ($_POST['step2_install'] || $_POST['step2_update_8'] || $_POST['step2_update_
$installType = 'update';
if ($_POST['step2_update_8']) {
$emptyUpdatePath = false;
- if (empty($_POST['updatePath'])) {
- $proposedUpdatePath = $_SERVER['DOCUMENT_ROOT'];
- } else {
- $proposedUpdatePath = $_POST['updatePath'];
- }
- if (substr($proposedUpdatePath,-1) != '/') {
- $proposedUpdatePath .= '/';
- }
+ $proposedUpdatePath = api_add_trailing_slash(empty($_POST['updatePath']) ? $_SERVER['DOCUMENT_ROOT'] : $_POST['updatePath']);
if (file_exists($proposedUpdatePath)) {
if (in_array($my_old_version, $update_from_version_8)) {
$_POST['step2'] = 1;
@@ -177,10 +170,7 @@ if ($_POST['step2_install'] || $_POST['step2_update_8'] || $_POST['step2_update_
$_POST['step1'] = 1;
} else {
$emptyUpdatePath = false;
- if (substr($_POST['updatePath'], -1) != '/') {
- $_POST['updatePath'] .= '/';
- }
-
+ $_POST['updatePath'] = api_add_trailing_slash($_POST['updatePath']);
if (file_exists($_POST['updatePath'])) {
//1.6.x
$my_old_version = get_config_param('clarolineVersion', $_POST['updatePath']);
@@ -213,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));
@@ -243,21 +233,23 @@ 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 {
foreach ($_POST as $key => $val) {
- $magic_quotes_gpc = ini_get('magic_quotes_gpc') ? true : false;
+ $magic_quotes_gpc = ini_get('magic_quotes_gpc');
if (is_string($val)) {
if ($magic_quotes_gpc) {
$val = stripslashes($val);
@@ -547,7 +539,7 @@ if ($_POST['step2']) {
}
display_configuration_settings_form($installType, $urlForm, $languageForm, $emailForm, $adminFirstName, $adminLastName, $adminPhoneForm, $campusForm, $institutionForm, $institutionUrlForm, $encryptPassForm, $allowSelfReg, $allowSelfRegProf, $loginForm, $passForm);
-} elseif($_POST['step5']) {
+} elseif ($_POST['step5']) {
//STEP 6 : LAST CHECK BEFORE INSTALL
?>
@@ -600,7 +592,7 @@ if ($_POST['step2']) {
?>
-
+
'.$loginForm; ?>
'.$passForm; /* TODO: Maybe this password should be hidden too? */ ?>
@@ -617,7 +609,7 @@ if ($_POST['step2']) {
diff --git a/main/install/install_db.inc.php b/main/install/install_db.inc.php
index a7bad26ad3..9078c6eb2a 100755
--- a/main/install/install_db.inc.php
+++ b/main/install/install_db.inc.php
@@ -2,7 +2,7 @@
/* For licensing terms, see /chamilo_license.txt */
/**
==============================================================================
-* Install the Dokeos database
+* Install the Chamilo database
* Notice : This script has to be included by index.php
*
* @package chamilo.install
@@ -17,9 +17,9 @@ require_once 'install_upgrade.lib.php';
==============================================================================
*/
-//this page can only be access through including from the install script.
+// This page can only be access through including from the install script.
-if (!defined('DOKEOS_INSTALL')) {
+if (!defined('SYSTEM_INSTALLATION')) {
echo 'You are not allowed here!';
exit;
}
@@ -53,9 +53,7 @@ Database::query("SET SESSION character_set_server='utf8';");
Database::query("SET SESSION collation_server='utf8_general_ci';");
Database::query("SET CHARACTER SET 'utf8';");
-if ($urlForm[strlen($urlForm) - 1] != '/') {
- $urlForm = $urlForm.'/';
-}
+$urlForm = api_add_trailing_slash($urlForm);
switch ($encryptPassForm) {
case 'md5' :
@@ -69,36 +67,34 @@ switch ($encryptPassForm) {
break;
}
-$dbPrefixForm = eregi_replace('[^a-z0-9_-]', '', $dbPrefixForm);
-
-$dbNameForm = eregi_replace('[^a-z0-9_-]', '', $dbNameForm);
-$dbStatsForm = eregi_replace('[^a-z0-9_-]', '', $dbStatsForm);
-$dbUserForm = eregi_replace('[^a-z0-9_-]', '', $dbUserForm);
+$dbPrefixForm = preg_replace('/[^a-zA-Z0-9_-]/', '', $dbPrefixForm);
-if (!empty($dbPrefixForm) && !ereg('^'.$dbPrefixForm, $dbNameForm)) {
+$dbNameForm = preg_replace('/[^a-zA-Z0-9_-]/', '', $dbNameForm);
+if (!empty($dbPrefixForm) && strpos($dbNameForm, $dbPrefixForm) !== 0) {
$dbNameForm = $dbPrefixForm.$dbNameForm;
}
-if (!empty($dbPrefixForm) && !ereg('^'.$dbPrefixForm, $dbStatsForm)) {
+$dbStatsForm = preg_replace('/[^a-zA-Z0-9_-]/', '', $dbStatsForm);
+if (!empty($dbPrefixForm) && strpos($dbStatsForm, $dbPrefixForm) !== 0) {
$dbStatsForm = $dbPrefixForm.$dbStatsForm;
}
-if (!empty($dbPrefixForm) && !ereg('^'.$dbPrefixForm, $dbUserForm)) {
+$dbUserForm = preg_replace('/[^a-zA-Z0-9_-]/', '', $dbUserForm);
+if (!empty($dbPrefixForm) && strpos($dbUserForm, $dbPrefixForm) !== 0) {
$dbUserForm = $dbPrefixForm.$dbUserForm;
}
$mysqlMainDb = $dbNameForm;
-$mysqlStatsDb = $dbStatsForm;
-$mysqlUserDb = $dbUserForm;
-
if (empty($mysqlMainDb) || $mysqlMainDb == 'mysql' || $mysqlMainDb == $dbPrefixForm) {
$mysqlMainDb = $dbPrefixForm.'main';
}
+$mysqlStatsDb = $dbStatsForm;
if (empty($mysqlStatsDb) || $mysqlStatsDb == 'mysql' || $mysqlStatsDb == $dbPrefixForm) {
$mysqlStatsDb = $dbPrefixForm.'stats';
}
+$mysqlUserDb = $dbUserForm;
if (empty($mysqlUserDb) || $mysqlUserDb == 'mysql' || $mysqlUserDb == $dbPrefixForm) {
$mysqlUserDb = $dbPrefixForm.'user';
}
@@ -113,13 +109,13 @@ if (!$singleDbForm) {
}
Database::query("CREATE DATABASE IF NOT EXISTS `$mysqlMainDb`") or die(Database::error());
-if($mysqlStatsDb == $mysqlMainDb && $mysqlUserDb == $mysqlMainDb) {
+if ($mysqlStatsDb == $mysqlMainDb && $mysqlUserDb == $mysqlMainDb) {
$singleDbForm = true;
}
/**
-* CREATING THE STATISTICS DATABASE
-*/
+ * CREATING THE STATISTICS DATABASE
+ */
if ($mysqlStatsDb != $mysqlMainDb) {
if (!$singleDbForm) {
// multi DB mode AND tracking has its own DB so create it
@@ -132,8 +128,8 @@ if ($mysqlStatsDb != $mysqlMainDb) {
}
/**
-* CREATING THE USER DATABASE
-*/
+ * CREATING THE USER DATABASE
+ */
if ($mysqlUserDb != $mysqlMainDb) {
if (!$singleDbForm) {
// multi DB mode AND user data has its own DB so create it
@@ -145,23 +141,23 @@ if ($mysqlUserDb != $mysqlMainDb) {
}
}
-include '../lang/english/create_course.inc.php';
+include api_get_path(SYS_LANG_PATH).'english/create_course.inc.php';
if ($languageForm != 'english') {
- include '../lang/'.$languageForm.'/create_course.inc.php';
+ include api_get_path(SYS_LANG_PATH).$languageForm.'/create_course.inc.php';
}
/**
-* creating the tables of the main database
-*/
+ * creating the tables of the main database
+ */
Database::select_db($mysqlMainDb) or die(Database::error());
$installation_settings['{ORGANISATIONNAME}'] = $institutionForm;
$installation_settings['{ORGANISATIONURL}'] = $institutionUrlForm;
$installation_settings['{CAMPUSNAME}'] = $campusForm;
$installation_settings['{PLATFORMLANGUAGE}'] = $languageForm;
-$installation_settings['{ALLOWSELFREGISTRATION}'] = trueFalse($allowSelfReg);
-$installation_settings['{ALLOWTEACHERSELFREGISTRATION}'] = trueFalse($allowSelfRegProf);
+$installation_settings['{ALLOWSELFREGISTRATION}'] = true_false($allowSelfReg);
+$installation_settings['{ALLOWTEACHERSELFREGISTRATION}'] = true_false($allowSelfRegProf);
$installation_settings['{ADMINLASTNAME}'] = $adminLastName;
$installation_settings['{ADMINFIRSTNAME}'] = $adminFirstName;
$installation_settings['{ADMINLOGIN}'] = $loginForm;
@@ -174,8 +170,8 @@ $installation_settings['{HASHFUNCTIONMODE}'] = $encryptPassForm;
load_main_database($installation_settings);
/**
-* creating the tables of the tracking database
-*/
+ * creating the tables of the tracking database
+ */
Database::select_db($mysqlStatsDb) or die(Database::error());
@@ -185,9 +181,9 @@ $track_countries_table = "track_c_countries";
fill_track_countries_table($track_countries_table);
/**
-* creating the tables of the USER database
-* this is where the personal agenda items are storen, the user defined course categories (sorting of my courses)
-*/
+ * creating the tables of the USER database
+ * this is where the personal agenda items are storen, the user defined course categories (sorting of my courses)
+ */
Database::select_db($mysqlUserDb) or die(Database::error());
diff --git a/main/install/install_files.inc.php b/main/install/install_files.inc.php
index 6b6f8ad81c..b55abd411a 100755
--- a/main/install/install_files.inc.php
+++ b/main/install/install_files.inc.php
@@ -15,13 +15,13 @@
==============================================================================
*/
-if (defined('DOKEOS_INSTALL')) {
+if (defined('SYSTEM_INSTALLATION')) {
// Write the system config file
- write_dokeos_config_file('../inc/conf/configuration.php');
+ write_system_config_file('../inc/conf/configuration.php');
// Write a distribution file with the config as a backup for the admin
- write_dokeos_config_file('../inc/conf/configuration.dist.php');
+ write_system_config_file('../inc/conf/configuration.dist.php');
// Write a .htaccess file in the course repository
write_courses_htaccess_file($urlAppendPath);
diff --git a/main/install/install_functions.inc.php b/main/install/install_functions.inc.php
index b156151c0d..5255451d37 100755
--- a/main/install/install_functions.inc.php
+++ b/main/install/install_functions.inc.php
@@ -69,8 +69,7 @@ function check_php_setting($php_setting, $recommended_value, $return_success = f
* @author Joomla
*/
function get_php_setting($val) {
- $r = ini_get($val) == '1' ? 1 : 0;
- return $r ? 'ON' : 'OFF';
+ return ini_get($val) == '1' ? 'ON' : 'OFF';
}
/**
@@ -95,7 +94,7 @@ function check_writable($folder, $suggestion = false) {
* @return string the string "true" or "false"
* @author Christophe Gesché
*/
-function trueFalse($var) {
+function true_false($var) {
return $var ? 'true' : 'false';
}
@@ -122,11 +121,12 @@ function file_to_array($filename) {
* @param string If we want to give the path rather than take it from POST
* @return string the value of the parameter
* @author Olivier Brouckaert
+ * @author Reworked by Ivan Tcholakov, 2010
*/
function get_config_param($param, $updatePath = '') {
global $configFile, $updateFromConfigFile;
- //look if we already have the queried param
+ // Look if we already have the queried parameter.
if (is_array($configFile) && isset($configFile[$param])) {
return $configFile[$param];
}
@@ -136,14 +136,16 @@ function get_config_param($param, $updatePath = '') {
$updatePath = realpath($updatePath).'/';
$updateFromInstalledVersionFile = '';
- if (empty($updateFromConfigFile)) { //if update from previous install was requested
- //try to recover old config file from dokeos 1.8.x
+ if (empty($updateFromConfigFile)) {
+ // If update from previous install was requested,
+ // try to recover old config file from dokeos 1.8.x.
if (file_exists($updatePath.'main/inc/conf/configuration.php')) {
- $updateFromConfigFile='main/inc/conf/configuration.php';
+ $updateFromConfigFile = 'main/inc/conf/configuration.php';
} elseif (file_exists($updatePath.'claroline/inc/conf/claro_main.conf.php')) {
- $updateFromConfigFile='claroline/inc/conf/claro_main.conf.php';
- } else { //give up recovering
- error_log('Could not find config file in '.$updatePath.' in get_config_param()',0);
+ $updateFromConfigFile = 'claroline/inc/conf/claro_main.conf.php';
+ } else {
+ // Give up recovering.
+ error_log('Could not find config file in '.$updatePath.' in get_config_param()', 0);
return null;
}
}
@@ -152,60 +154,93 @@ function get_config_param($param, $updatePath = '') {
$updateFromInstalledVersionFile = $updatePath.'main/inc/installedVersion.inc.php';
- } elseif (file_exists($updatePath.$updateFromConfigFile)) { //the param was not found in global vars, so look into the old config file
+ } elseif (file_exists($updatePath.$updateFromConfigFile)) {
+
+ // The parameter was not found among the global variables, so look into the old configuration file.
- //make sure the installedVersion file is read first so it is overwritten
- //by the config file if the config file contains the version (from 1.8.4)
- $temp2 = array();
+ // Make sure the installedVersion file is read first so it is overwritten
+ // by the config file if the config file contains the version (from 1.8.4).
+ $config_data_2 = array();
if (file_exists($updatePath.$updateFromInstalledVersionFile)) {
- $temp2 = file_to_array($updatePath.$updateFromInstalledVersionFile);
+ $config_data_2 = file_to_array($updatePath.$updateFromInstalledVersionFile);
}
$configFile = array();
- $temp = file_to_array($updatePath.$updateFromConfigFile);
- $temp = array_merge($temp, $temp2);
+ $config_data = file_to_array($updatePath.$updateFromConfigFile);
+ $config_data = array_merge($config_data, $config_data_2);
$val = '';
- //parse the config file (TODO clarify why it has to be so complicated)
- foreach ($temp as $enreg) {
- if (strstr($enreg, '=')) {
- $enreg = explode('=', $enreg);
- $enreg[0] = trim($enreg[0]);
- if ($enreg[0][0] == '$') {
- list($enreg[1]) = explode(' //', $enreg[1]);
-
- $enreg[0] = trim(str_replace('$', '', $enreg[0]));
- $enreg[1] = str_replace('\"', '"', ereg_replace('(^"|"$)', '', substr(trim($enreg[1]), 0, -1)));
- $enreg[1] = str_replace('\'', '"', ereg_replace('(^\'|\'$)', '', $enreg[1]));
- if (strtolower($enreg[1]) == 'true') {
- $enreg[1] = 1;
- }
- if (strtolower($enreg[1]) == 'false') {
- $enreg[1] = 0;
+ // Parse the configuration file, statement by statement (line by line, actually).
+ foreach ($config_data as $php_statement) {
+
+ if (strpos($php_statement, '=') !== false) {
+ // Variable assignment statement have been detected (probably).
+ // It is expected to be as follows:
+ // $variable = 'some_value'; // A comment that is not mandatory.
+
+ // Split the statement into its left and right sides.
+ $php_statement = explode('=', $php_statement);
+ $variable = trim($php_statement[0]);
+ $value = $php_statement[1];
+
+ if (substr($variable, 0, 1) == '$') {
+ // We have for sure a php variable assignment detected.
+
+ // On the left side: Retrieve the pure variable's name
+ $variable = trim(str_replace('$', '', $variable));
+
+ // On the right side: Remove the comment, if it exists.
+ list($value) = explode(' //', $value);
+ // Remove extra whitespace, if any. Remove the trailing semicolon (;).
+ $value = substr(trim($value), 0, -1);
+ // Remove surroundig quotes, restore escaped quotes.
+ $value = str_replace('\"', '"', preg_replace('/^"|"$/', '', $value));
+ $value = str_replace('\'', '"', preg_replace('/^\'|\'$/', '', $value));
+
+ if (strtolower($value) == 'true') {
+
+ // A boolean true value have been recognized.
+ $value = 1;
+
+ } elseif (strtolower($value) == 'false') {
+
+ // A boolean false value have been recognized.
+ $value = 0;
+
} else {
- $implode_string=' ';
- if (!strstr($enreg[1], '." ".') && strstr($enreg[1], '.$')) {
- $enreg[1] = str_replace('.$', '." ".$', $enreg[1]);
+ // Probably we have a string value, but also we have to check
+ // possible string concatenations that may include string values
+ // and other configuration variables. I this case we have to
+ // get the calculated result of the concatenation.
+ $implode_string = ' ';
+ if (!strstr($value, '." ".') && strstr($value, '.$')) {
+ // Yes, there is concatenation, insert a special separator string.
+ $value = str_replace('.$', '." ".$', $value);
$implode_string = '';
}
- $tmp = explode('." ".', $enreg[1]);
+ // Split the concatenated values, if they are more than one.
+ $sub_strings = explode('." ".', $value);
- foreach ($tmp as $tmp_key => $tmp_val) {
- if (eregi('^\$[a-z_][a-z0-9_]*$', $tmp_val)) {
- $tmp[$tmp_key] = get_config_param(str_replace('$', '', $tmp_val));
+ // Seek for variables and retrieve their values.
+ foreach ($sub_strings as $key => & $sub_string) {
+ if (preg_match('/^\$[a-zA-Z_][a-zA-Z0-9_]*$/', $sub_string)) {
+ // A variable has been detected, read it by recursive call.
+ $sub_string = get_config_param(str_replace('$', '', $sub_string));
}
}
- $enreg[1] = implode($implode_string, $tmp);
+ // Concatenate everything into the final, the calculated string value.
+ $value = implode($implode_string, $sub_strings);
}
- $configFile[$enreg[0]] = $enreg[1];
+ // Cache the result value.
+ $configFile[$variable] = $value;
- $a = explode("'", $enreg[0]);
+ $a = explode("'", $variable);
$key_tmp = $a[1];
if ($key_tmp == $param) {
- $val = $enreg[1];
+ $val = $value;
}
}
}
@@ -230,50 +265,17 @@ function get_config_param($param, $updatePath = '') {
*/
function get_config_param_from_db($host, $login, $pass, $db_name, $param = '') {
- $mydb = mysql_connect($host, $login, $pass);
- @mysql_query("set session sql_mode='';"); // Disabling special SQL modes (MySQL 5)
-
- $myconnect = mysql_select_db($db_name);
+ Database::connect(array('server' => $host, 'username' => $login, 'password' => $pass));
+ Database::query("set session sql_mode='';"); // Disabling special SQL modes (MySQL 5)
+ Database::select_db($db_name);
- $sql = "SELECT * FROM settings_current WHERE variable = '$param'";
- $res = mysql_query($sql);
- if ($res === false) {
- return null;
- }
-
- if (mysql_num_rows($res) > 0) {
- $row = mysql_fetch_array($res);
- $value = $row['selected_value'];
- return $value;
- }
- 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;
+ if (($res = Database::query("SELECT * FROM settings_current WHERE variable = '$param'")) !== false) {
+ if (Database::num_rows($res) > 0) {
+ $row = Database::fetch_array($res);
+ return $row['selected_value'];
}
}
-
- closedir($handle);
- return $language_list;
+ return null;
}
/*
@@ -283,35 +285,53 @@ function get_language_folder_list($dirname) {
*/
/**
- * Displays a form (drop down menu) so the user can select
- * his/her preferred language.
+ * Displays a drop down box for selection the preferred language.
*/
-function display_language_selection_box() {
- //get language list
- $dirname = '../lang/'; // TODO: Check api_get_path() and use it.
- $language_list = get_language_folder_list($dirname);
- 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;
+function display_language_selection_box($name = 'language_list', $default_language = 'english') {
+ // Reading language list.
+ $language_list = get_language_folder_list();
+
+ /*
+ // 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]);
+ }
+ }
+ */
- //display
- echo "\t\t