@ -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_splitSqlF ile()' function
} // end of the 'split_sql_f ile()' 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;
}
}
}
}