Feature #272 - Installation scripts: Cleaning & reformatting, second pass. Some minor corrections.

skala
Ivan Tcholakov 16 years ago
parent 0dc20d6ef9
commit 9bec6eca66
  1. 2
      main/install/INSTALL.txt
  2. 240
      main/install/compare_db.php
  3. 14
      main/install/index.php
  4. 11
      main/install/install_db.inc.php
  5. 209
      main/install/install_functions.inc.php
  6. 25
      main/install/install_upgrade.lib.php
  7. 400
      main/install/update-db-1.6.x-1.8.0.inc.php
  8. 3
      main/install/update-db-1.8.0-1.8.2.inc.php
  9. 3
      main/install/update-db-1.8.2-1.8.3.inc.php
  10. 3
      main/install/update-db-1.8.3-1.8.4.inc.php
  11. 3
      main/install/update-db-1.8.4-1.8.5.inc.php
  12. 3
      main/install/update-db-1.8.5-1.8.6.inc.php
  13. 3
      main/install/update-db-1.8.6-1.8.6.1.inc.php
  14. 3
      main/install/update-db-1.8.6.1-1.8.6.2.inc.php
  15. 3
      main/install/update-db-1.8.6.2-1.8.7.inc.php
  16. 540
      main/install/update-db-scorm-1.6.x-1.8.0.inc.php
  17. 134
      main/install/update-files-1.6.x-1.8.0.inc.php
  18. 53
      main/install/update-files-1.8.3-1.8.4.inc.php
  19. 51
      main/install/update-files-1.8.4-1.8.5.inc.php
  20. 67
      main/install/update-files-1.8.5-1.8.6.inc.php
  21. 64
      main/install/update-files-1.8.6-1.8.6.1.inc.php
  22. 84
      main/install/update-files-1.8.6.1-1.8.6.2.inc.php
  23. 24
      main/install/update-files-1.8.6.2-1.8.7.inc.php
  24. 91
      main/install/update_courses.php
  25. 3
      main/install/update_db.inc.php
  26. 92
      main/install/update_files.inc.php
  27. 378
      main/install/upgrade.php
  28. 95
      main/install/upgrade_lib.php

@ -1,2 +1,2 @@
For installation help, see installation_guide.html or INSTALL.txt at the Dokeos root directory For installation help, see installation_guide.html or INSTALL.txt at the Chamilo root directory
(which should be two directories up from this) (which should be two directories up from this)

@ -21,27 +21,25 @@
* Also, make sure about the prefix possibly used in front of the normal prefix for courses * Also, make sure about the prefix possibly used in front of the normal prefix for courses
* databases (i.e. 'zPrefix_course' contains 'z' as additional prefix). * databases (i.e. 'zPrefix_course' contains 'z' as additional prefix).
*/ */
$sql_server_new='localhost'; $sql_server_new = 'localhost';
$sql_user_new='root'; $sql_user_new = 'root';
$sql_pass_new=''; $sql_pass_new = '';
$prefix_new = 'dokeos180_'; $prefix_new = 'dokeos180_';
$bases_new=array($prefix_new.'dokeos_main',$prefix_new.'dokeos_stats',$prefix_new.'dokeos_user','z'.$prefix_new.'COURSE',$prefix_new.'dokeos_scorm'); $bases_new = array($prefix_new.'dokeos_main', $prefix_new.'dokeos_stats', $prefix_new.'dokeos_user', 'z'.$prefix_new.'COURSE', $prefix_new.'dokeos_scorm');
$db_new = mysql_connect($sql_server_new,$sql_user_new,$sql_pass_new) or die(mysql_error());
// The system has not been designed to use special SQL modes that were introduced since MySQL 5 $db_new = mysql_connect($sql_server_new, $sql_user_new, $sql_pass_new) or die(mysql_error());
@mysql_query("set session sql_mode='';", $db_new); @mysql_query("set session sql_mode='';", $db_new); // Disabling special SQL modes (MySQL 5)
$sql_server_old='localhost'; $sql_server_old = 'localhost';
$sql_user_old='root'; $sql_user_old = 'root';
$sql_pass_old=''; $sql_pass_old = '';
$prefix_old = 'dokeos160_'; $prefix_old = 'dokeos160_';
$bases_old=array($prefix_old.'dokeos_main',$prefix_old.'dokeos_stats',$prefix_old.'dokeos_user',$prefix_old.'COURSE',$prefix_old.'dokeos_scorm'); $bases_old = array($prefix_old.'dokeos_main', $prefix_old.'dokeos_stats', $prefix_old.'dokeos_user', $prefix_old.'COURSE', $prefix_old.'dokeos_scorm');
$db_old = mysql_connect($sql_server_old,$sql_user_old,$sql_pass_old) or die(mysql_error());
// The system has not been designed to use special SQL modes that were introduced since MySQL 5 $db_old = mysql_connect($sql_server_old, $sql_user_old, $sql_pass_old) or die(mysql_error());
@mysql_query("set session sql_mode='';", $db_old); @mysql_query("set session sql_mode='';", $db_old); // Disabling special SQL modes (MySQL 5)
$field_details = array(0=>'Field',1=>'Type',2=>'Null',3=>'Key',4=>'Default',5=>'Extra'); $field_details = array(0 => 'Field', 1 => 'Type', 2 => 'Null', 3 => 'Key', 4 => 'Default', 5 => 'Extra');
/********************************/ /********************************/
@ -49,48 +47,48 @@ $all_db_changes = array();
echo "<h1>Databases structure comparison script</h1>"; echo "<h1>Databases structure comparison script</h1>";
//iterate through databases given above (checking from the 'new' database side) // Iterate through databases given above (checking from the 'new' database side)
foreach($bases_new as $num_base=>$base) foreach ($bases_new as $num_base => $base) {
{
//init tables lists for this database //init tables lists for this database
$modif_tables=array(); $modif_tables = array();
$tables_db_new=array(); $tables_db_new = array();
$tables_db_old=array(); $tables_db_old = array();
$dump=array(); $dump = array();
//display current processed database // Display current processed database
echo "<h2>Now analysing differences between databases <em>$base</em> and <em>".$bases_old[$num_base]."</em></h2>"; echo "<h2>Now analysing differences between databases <em>$base</em> and <em>".$bases_old[$num_base]."</em></h2>";
//get a list of tables for this database // Get a list of tables for this database
$query_new="SHOW TABLES FROM ".$bases_new[$num_base]; $query_new = "SHOW TABLES FROM ".$bases_new[$num_base];
$result_new=mysql_query($query_new,$db_new); $result_new = mysql_query($query_new, $db_new);
if ($result_new) { //if there are tables in this database
if($result_new) //if there are tables in this database
{
$i=0; $i=0;
//as there are tables, process them one by one //as there are tables, process them one by one
while($row_new=mysql_fetch_row($result_new)) while ($row_new = mysql_fetch_row($result_new)) {
{
$dump[$i]['table_name']=$row_new[0]; $dump[$i]['table_name'] = $row_new[0];
$dump[$i]['fields']=array(); $dump[$i]['fields'] = array();
$query_old="SHOW FIELDS FROM ".$bases_new[$num_base].".".$row_new[0]; $query_old = "SHOW FIELDS FROM ".$bases_new[$num_base].".".$row_new[0];
$result_old=mysql_query($query_old,$db_old) or die(mysql_error()); $result_old = mysql_query($query_old,$db_old) or die(mysql_error());
$j=0; $j=0;
//get the fields details (numbered fields) //get the fields details (numbered fields)
while($row_old=mysql_fetch_row($result_old)) while ($row_old = mysql_fetch_row($result_old)) {
{
$dump[$i]['fields'][$j][0]=$row_old[0]; $dump[$i]['fields'][$j][0] = $row_old[0];
$dump[$i]['fields'][$j][1]=$row_old[1]; $dump[$i]['fields'][$j][1] = $row_old[1];
$dump[$i]['fields'][$j][2]=$row_old[2]; $dump[$i]['fields'][$j][2] = $row_old[2];
$dump[$i]['fields'][$j][3]=$row_old[3]; $dump[$i]['fields'][$j][3] = $row_old[3];
$dump[$i]['fields'][$j][4]=$row_old[4]; $dump[$i]['fields'][$j][4] = $row_old[4];
$dump[$i]['fields'][$j][5]=$row_old[5]; $dump[$i]['fields'][$j][5] = $row_old[5];
//get the field name in one special element of this array //get the field name in one special element of this array
$dump[$i]['field_names'][$row_old[0]]=$j; $dump[$i]['field_names'][$row_old[0]] = $j;
$j++; $j++;
} }
@ -98,102 +96,103 @@ foreach($bases_new as $num_base=>$base)
$i++; $i++;
} }
foreach($dump as $table) foreach ($dump as $table) {
{
$query="SHOW FIELDS FROM ".$bases_old[$num_base].".".$table['table_name']; $query = "SHOW FIELDS FROM ".$bases_old[$num_base].".".$table['table_name'];
$result=mysql_query($query,$db_old); $result = mysql_query($query,$db_old);
if (!$result) {
if(!$result)
{
$modif_tables[]='**'.$table['table_name'].'**'; $modif_tables[]='**'.$table['table_name'].'**';
}
else } else {
{
$i=0; $i = 0;
//check for removed, new or modified fields //check for removed, new or modified fields
$fields_old = array(); $fields_old = array();
$fields_new = array(); $fields_new = array();
//list the new fields in a enumeration array //list the new fields in a enumeration array
foreach($table['field_names'] as $dummy_key=>$dummy_field){ foreach($table['field_names'] as $dummy_key => $dummy_field) {
$fields_new[] = $dummy_key; $fields_new[] = $dummy_key;
} }
//list the old fields in an enumeration array and check if their corresponding
//field in the new table is different (if any) //list the old fields in an enumeration array and check if their corresponding field in the new table is different (if any)
$modif_fields = array(); $modif_fields = array();
while($row_old = mysql_fetch_row($result)){ while ($row_old = mysql_fetch_row($result)) {
$fields_old[] = $row_old[0]; $fields_old[] = $row_old[0];
$modif_field = ''; $modif_field = '';
if(isset($table['fields'][$table['field_names'][$row_old[0]]])){
$field_infos=$table['fields'][$table['field_names'][$row_old[0]]]; if (isset($table['fields'][$table['field_names'][$row_old[0]]])) {
foreach($row_old as $key=>$enreg) $field_info = $table['fields'][$table['field_names'][$row_old[0]]];
{ foreach ($row_old as $key => $enreg) {
//if the old field information of this kind doesn't match the new, record it //if the old field information of this kind doesn't match the new, record it
if($row_old[$key] != $field_infos[$key]) if ($row_old[$key] != $field_info[$key]) {
{ $modif_field .= '~+~'.$field_details[$key].'~+~,';
$modif_field .='~+~'.$field_details[$key].'~+~,'; break;
break;
} }
} }
//only record the whole stuff if the string is not empty //only record the whole stuff if the string is not empty
if(strlen($modif_field)>0){ if(strlen($modif_field) > 0) {
$modif_fields[$row_old[0]] .= substr($modif_field,0,-1); $modif_fields[$row_old[0]] .= substr($modif_field, 0, -1);
} }
} }
} }
$new_fields = array_diff($fields_new,$fields_old);
foreach($new_fields as $dummy=>$val){ $new_fields = array_diff($fields_new, $fields_old);
foreach ($new_fields as $dummy => $val) {
$new_fields[$dummy] = '++'.$val.'++'; $new_fields[$dummy] = '++'.$val.'++';
} }
$old_fields = array_diff($fields_old,$fields_new);
foreach($old_fields as $dummy=>$val){ $old_fields = array_diff($fields_old, $fields_new);
foreach ($old_fields as $dummy => $val) {
$old_fields[$dummy] = '--'.$val.'--'; $old_fields[$dummy] = '--'.$val.'--';
} }
if(count($old_fields)>0 or count($modif_fields)>0 or count($new_fields)>0 ){
$modif_tables[]=array( if (count($old_fields) > 0 or count($modif_fields) > 0 or count($new_fields) > 0 ) {
'table'=>$table['table_name'], $modif_tables[] = array(
'old_fields'=>$old_fields, 'table' => $table['table_name'],
'changed_fields'=>$modif_fields, 'old_fields' => $old_fields,
'new_fields'=>$new_fields, 'changed_fields' => $modif_fields,
'new_fields' => $new_fields,
); );
} }
} }
$tables_db_new[]=$table['table_name']; $tables_db_new[] = $table['table_name'];
} }
$query="SHOW TABLES FROM ".$bases_old[$num_base]; $query = "SHOW TABLES FROM ".$bases_old[$num_base];
$result=mysql_query($query,$db_old) or die(mysql_error()); $result = mysql_query($query, $db_old) or die(mysql_error());
while($row=mysql_fetch_row($result)) while ($row = mysql_fetch_row($result)) {
{ $tables_db_old[] = $row[0];
$tables_db_old[]=$row[0];
} }
$diff=array_diff($tables_db_old,$tables_db_new); $diff = array_diff($tables_db_old, $tables_db_new);
foreach($diff as $enreg) foreach ($diff as $enreg) {
{ $modif_tables[] = '---'.$enreg.'---';
$modif_tables[]='---'.$enreg.'---';
} }
//$modif_tables=array_unique($modif_tables); //deprecated with the structure complexification //$modif_tables = array_unique($modif_tables); //deprecated with the structure complexification
}else{ //this database was removed in the new version } else { //this database was removed in the new version
$query="SHOW TABLES FROM ".$bases_old[$num_base];
$result=mysql_query($query,$db_old) or die(mysql_error());
while($row=mysql_fetch_row($result)) $query = "SHOW TABLES FROM ".$bases_old[$num_base];
{ $result = mysql_query($query, $db_old) or die(mysql_error());
$tables_db_old[]=$row[0];
while ($row = mysql_fetch_row($result)) {
$tables_db_old[] = $row[0];
} }
$diff=array_diff($tables_db_old,$tables_db_new); $diff = array_diff($tables_db_old, $tables_db_new);
foreach($diff as $enreg) foreach ($diff as $enreg) {
{ $modif_tables[] = '---'.$enreg.'---';
$modif_tables[]='---'.$enreg.'---';
} }
$modif_tables=array_unique($modif_tables); $modif_tables = array_unique($modif_tables);
echo "<h3>This database has been removed!</h3>"; echo "<h3>This database has been removed!</h3>";
} }
echo "<h3>Differences between each table</h3>" . echo "<h3>Differences between each table</h3>" .
@ -203,7 +202,7 @@ foreach($bases_new as $num_base=>$base)
"- new fields are surrounded by '++',<br />" . "- new fields are surrounded by '++',<br />" .
"- removed fields are surrounded by '--',<br />" . "- removed fields are surrounded by '--',<br />" .
"- modified fields are surrounded by '~+~',<br />"; "- modified fields are surrounded by '~+~',<br />";
echo '<pre>'.print_r($modif_tables,true).'</pre>'; echo '<pre>'.print_r($modif_tables, true).'</pre>';
$all_db_changes[$base] = $modif_tables; $all_db_changes[$base] = $modif_tables;
} }
@ -211,48 +210,56 @@ mysql_close($db_new);
mysql_close($db_old); mysql_close($db_old);
echo "<h2>Generating SQL</h2>"; echo "<h2>Generating SQL</h2>";
//going through all databases changes //going through all databases changes
foreach($all_db_changes as $base => $changes){ foreach ($all_db_changes as $base => $changes) {
echo "<h3>SQL for DB $base</h3>"; echo "<h3>SQL for DB $base</h3>";
foreach($changes as $table){
if(is_array($table)){ foreach ($changes as $table) {
if (is_array($table)) {
//we have a field-level difference //we have a field-level difference
$mytable = $table['table']; $mytable = $table['table'];
$myold = $table['old_fields']; $myold = $table['old_fields'];
$mychanged = $table['changed_fields']; $mychanged = $table['changed_fields'];
$mynew = $table['new_fields']; $mynew = $table['new_fields'];
foreach($myold as $myname){
foreach ($myold as $myname) {
//column lost, display DROP command //column lost, display DROP command
$myname = str_replace('--','',$myname); $myname = str_replace('--', '', $myname);
echo "ALTER TABLE ".$mytable." DROP ".$myname."<br />"; echo "ALTER TABLE ".$mytable." DROP ".$myname."<br />";
} }
foreach($mychanged as $myname=>$myprop){
foreach ($mychanged as $myname => $myprop) {
//field changed, display SET command //field changed, display SET command
$myprops = split(',',$myprop); $myprops = split(',', $myprop);
$myprops_string = ''; $myprops_string = '';
foreach($myprops as $myprop){ foreach ($myprops as $myprop) {
$myprop = str_replace('~+~','',$myprop); $myprop = str_replace('~+~', '', $myprop);
$myprops_string .= $myprop." "; $myprops_string .= $myprop." ";
} }
echo "ALTER TABLE ".$mytable." CHANGE $myname $myname $myprops_string<br />"; echo "ALTER TABLE ".$mytable." CHANGE $myname $myname $myprops_string<br />";
} }
foreach($mynew as $myname){
foreach ($mynew as $myname) {
//column created, display ADD command //column created, display ADD command
$myname = str_replace('++','',$myname); $myname = str_replace('++', '', $myname);
echo "ALTER TABLE ".$mytable." ADD $myname...<br />"; echo "ALTER TABLE ".$mytable." ADD $myname...<br />";
} }
}else{
} else {
//we have a table-level difference //we have a table-level difference
$open_tag = substr($table,0,2); $open_tag = substr($table, 0, 2);
switch($open_tag){ switch ($open_tag) {
case '**': case '**':
//new table, display CREATE TABLE command //new table, display CREATE TABLE command
$table = str_replace('**','',$table); $table = str_replace('**', '', $table);
echo "CREATE TABLE ".$table."();<br />"; echo "CREATE TABLE ".$table."();<br />";
break; break;
case '--': case '--':
//dropped table, display DROP TABLE command //dropped table, display DROP TABLE command
$table = str_replace('---','',$table); $table = str_replace('---', '', $table);
echo "DROP TABLE ".$table."();<br />"; echo "DROP TABLE ".$table."();<br />";
break; break;
default: default:
@ -262,4 +269,3 @@ foreach($all_db_changes as $base => $changes){
} }
} }
} }
?>

@ -187,7 +187,7 @@ if ($_POST['step2_install'] || $_POST['step2_update_8'] || $_POST['step2_update_
} }
} }
} }
} elseif($_POST['step1']) { } elseif ($_POST['step1']) {
$_POST['updatePath'] = ''; $_POST['updatePath'] = '';
$installType = ''; $installType = '';
$updateFromConfigFile = ''; $updateFromConfigFile = '';
@ -244,7 +244,9 @@ if (!isset($_GET['running'])) {
$singleDbForm = 0; $singleDbForm = 0;
$encryptPassForm = 'md5'; $encryptPassForm = 'md5';
$session_lifetime = 360000; $session_lifetime = 360000;
} else { } else {
foreach($_POST as $key => $val) { foreach($_POST as $key => $val) {
$magic_quotes_gpc = ini_get('magic_quotes_gpc') ? true : false; $magic_quotes_gpc = ini_get('magic_quotes_gpc') ? true : false;
if (is_string($val)) { if (is_string($val)) {
@ -253,7 +255,7 @@ if (!isset($_GET['running'])) {
} }
$val = trim($val); $val = trim($val);
$_POST[$key] = $val; $_POST[$key] = $val;
} elseif(is_array($val)) { } elseif (is_array($val)) {
foreach ($val as $key2 => $val2) { foreach ($val as $key2 => $val2) {
if ($magic_quotes_gpc) { if ($magic_quotes_gpc) {
$val2 = stripslashes($val2); $val2 = stripslashes($val2);
@ -603,7 +605,7 @@ if ($_POST['step2']) {
</blockquote> </blockquote>
<?php if($installType == 'new'): ?> <?php if ($installType == 'new'): ?>
<div style="background-color:#FFFFFF"> <div style="background-color:#FFFFFF">
<p align="center"><strong><font color="red"> <p align="center"><strong><font color="red">
<?php echo get_lang('Warning');?> !<br /> <?php echo get_lang('Warning');?> !<br />
@ -620,10 +622,12 @@ if ($_POST['step2']) {
</table> </table>
<?php <?php
} elseif($_POST['step6']) { } elseif ($_POST['step6']) {
//STEP 6 : INSTALLATION PROCESS //STEP 6 : INSTALLATION PROCESS
if ($installType == 'update') { if ($installType == 'update') {
if (empty($my_old_version)) { $my_old_version = '1.8.6'; } //we guess if (empty($my_old_version)) { $my_old_version = '1.8.6'; } //we guess
$_configuration['main_database'] = $dbNameForm; $_configuration['main_database'] = $dbNameForm;
//$urlAppendPath = get_config_param('urlAppend'); //$urlAppendPath = get_config_param('urlAppend');
@ -674,7 +678,9 @@ if ($_POST['step2']) {
default: default:
break; break;
} }
} else { } else {
include 'install_db.inc.php'; include 'install_db.inc.php';
include 'install_files.inc.php'; include 'install_files.inc.php';
} }

@ -45,15 +45,14 @@ if (mysql_errno() > 0) {
exit(); exit();
} }
// The system has not been designed to use special SQL modes that were introduced since MySQL 5 @mysql_query("set session sql_mode='';"); // Disabling special SQL modes (MySQL 5)
@mysql_query("set session sql_mode='';");
// Initialization of the database encoding to be used. // Initialization of the database encoding to be used.
mysql_query("SET SESSION character_set_server='utf8';"); mysql_query("SET SESSION character_set_server='utf8';");
mysql_query("SET SESSION collation_server='utf8_general_ci';"); mysql_query("SET SESSION collation_server='utf8_general_ci';");
mysql_query("SET CHARACTER SET 'utf8';"); mysql_query("SET CHARACTER SET 'utf8';");
if ($urlForm[strlen($urlForm)-1] != '/') { if ($urlForm[strlen($urlForm) - 1] != '/') {
$urlForm = $urlForm.'/'; $urlForm = $urlForm.'/';
} }
@ -92,15 +91,15 @@ $mysqlStatsDb = $dbStatsForm;
$mysqlUserDb = $dbUserForm; $mysqlUserDb = $dbUserForm;
if (empty($mysqlMainDb) || $mysqlMainDb == 'mysql' || $mysqlMainDb == $dbPrefixForm) { if (empty($mysqlMainDb) || $mysqlMainDb == 'mysql' || $mysqlMainDb == $dbPrefixForm) {
$mysqlMainDb=$dbPrefixForm.'main'; $mysqlMainDb = $dbPrefixForm.'main';
} }
if (empty($mysqlStatsDb) || $mysqlStatsDb == 'mysql' || $mysqlStatsDb == $dbPrefixForm) { if (empty($mysqlStatsDb) || $mysqlStatsDb == 'mysql' || $mysqlStatsDb == $dbPrefixForm) {
$mysqlStatsDb=$dbPrefixForm.'stats'; $mysqlStatsDb = $dbPrefixForm.'stats';
} }
if (empty($mysqlUserDb) || $mysqlUserDb == 'mysql' || $mysqlUserDb == $dbPrefixForm) { if (empty($mysqlUserDb) || $mysqlUserDb == 'mysql' || $mysqlUserDb == $dbPrefixForm) {
$mysqlUserDb=$dbPrefixForm.'user'; $mysqlUserDb = $dbPrefixForm.'user';
} }
$result = mysql_query("SHOW VARIABLES LIKE 'datadir'") or die(mysql_error()); $result = mysql_query("SHOW VARIABLES LIKE 'datadir'") or die(mysql_error());

@ -38,7 +38,7 @@ function check_extension($extension_name, $return_success = 'Yes', $return_failu
if (extension_loaded($extension_name)) { if (extension_loaded($extension_name)) {
return '<strong><font color="green">'.$return_success.'</font></strong>'; return '<strong><font color="green">'.$return_success.'</font></strong>';
} else { } else {
if ($optional === true) { if ($optional) {
return '<strong><font color="#ff9900">'.$return_failure.'</font></strong>'; return '<strong><font color="#ff9900">'.$return_failure.'</font></strong>';
} else { } else {
return '<strong><font color="red">'.$return_failure.'</font></strong>'; return '<strong><font color="red">'.$return_failure.'</font></strong>';
@ -76,14 +76,14 @@ function get_php_setting($val) {
/** /**
* This function checks if the given folder is writable * This function checks if the given folder is writable
*/ */
function check_writable($folder,$suggestion=false) { function check_writable($folder, $suggestion = false) {
if (is_writable('../'.$folder)) { if (is_writable('../'.$folder)) {
return '<strong><font color="green">'.get_lang('Writable').'</font></strong>'; return '<strong><font color="green">'.get_lang('Writable').'</font></strong>';
} else { } else {
if ($suggestion == true) { if ($suggestion) {
return '<strong><font color="#ff9900">'.get_lang('NotWritable').'</font></strong>'; return '<strong><font color="#ff9900">'.get_lang('NotWritable').'</font></strong>';
} else { } else {
return '<strong><font color="red">'.get_lang('NotWritable').'</font></strong>'; return '<strong><font color="red">'.get_lang('NotWritable').'</font></strong>';
} }
} }
} }
@ -109,8 +109,7 @@ function file_to_array($filename) {
$fp = fopen($filename, 'rb'); $fp = fopen($filename, 'rb');
$buffer = fread($fp, filesize($filename)); $buffer = fread($fp, filesize($filename));
fclose($fp); fclose($fp);
$result = explode('<br />', nl2br($buffer)); return explode('<br />', nl2br($buffer));
return $result;
} }
/** /**
@ -124,120 +123,98 @@ function file_to_array($filename) {
* @return string the value of the parameter * @return string the value of the parameter
* @author Olivier Brouckaert * @author Olivier Brouckaert
*/ */
function get_config_param($param,$updatePath='') function get_config_param($param, $updatePath = '') {
{
global $configFile, $updateFromConfigFile; global $configFile, $updateFromConfigFile;
//look if we already have the queried param //look if we already have the queried param
if(is_array($configFile) && isset($configFile[$param])) if (is_array($configFile) && isset($configFile[$param])) {
{
return $configFile[$param]; return $configFile[$param];
} }
if(empty($updatePath) && !empty($_POST['updatePath'])) if (empty($updatePath) && !empty($_POST['updatePath'])) {
{
$updatePath = $_POST['updatePath']; $updatePath = $_POST['updatePath'];
} }
$updatePath = realpath($updatePath).'/'; $updatePath = realpath($updatePath).'/';
$updateFromInstalledVersionFile = ''; $updateFromInstalledVersionFile = '';
if(empty($updateFromConfigFile)) //if update from previous install was requested if (empty($updateFromConfigFile)) { //if update from previous install was requested
{
//try to recover old config file from dokeos 1.8.x //try to recover old config file from dokeos 1.8.x
if(file_exists($updatePath.'main/inc/conf/configuration.php')) 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')) {
elseif(file_exists($updatePath.'claroline/inc/conf/claro_main.conf.php'))
{
$updateFromConfigFile='claroline/inc/conf/claro_main.conf.php'; $updateFromConfigFile='claroline/inc/conf/claro_main.conf.php';
} } else { //give up recovering
//give up recovering
else
{
error_log('Could not find config file in '.$updatePath.' in get_config_param()',0); error_log('Could not find config file in '.$updatePath.' in get_config_param()',0);
return null; return null;
} }
} }
if(file_exists($updatePath.'main/inc/installedVersion.inc.php'))
{ if (file_exists($updatePath.'main/inc/installedVersion.inc.php')) {
$updateFromInstalledVersionFile = $updatePath.'main/inc/installedVersion.inc.php'; $updateFromInstalledVersionFile = $updatePath.'main/inc/installedVersion.inc.php';
}
//the param was not found in global vars, so look into the old config file } 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))
{
//make sure the installedVersion file is read first so it is overwritten //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) //by the config file if the config file contains the version (from 1.8.4)
$temp2 = array(); $temp2 = array();
if(file_exists($updatePath.$updateFromInstalledVersionFile)) if (file_exists($updatePath.$updateFromInstalledVersionFile)) {
{
$temp2 = file_to_array($updatePath.$updateFromInstalledVersionFile); $temp2 = file_to_array($updatePath.$updateFromInstalledVersionFile);
} }
$configFile=array(); $configFile = array();
$temp=file_to_array($updatePath.$updateFromConfigFile); $temp = file_to_array($updatePath.$updateFromConfigFile);
$temp = array_merge($temp,$temp2); $temp = array_merge($temp, $temp2);
$val=''; $val = '';
//parse the config file (TODO clarify why it has to be so complicated) //parse the config file (TODO clarify why it has to be so complicated)
foreach($temp as $enreg) foreach ($temp as $enreg) {
{ if (strstr($enreg, '=')) {
if(strstr($enreg,'=')) $enreg = explode('=', $enreg);
{
$enreg=explode('=',$enreg);
$enreg[0] = trim($enreg[0]); $enreg[0] = trim($enreg[0]);
if($enreg[0][0] == '$') if ($enreg[0][0] == '$') {
{ list($enreg[1]) = explode(' //', $enreg[1]);
list($enreg[1])=explode(' //',$enreg[1]);
$enreg[0] = trim(str_replace('$', '', $enreg[0]));
$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('(^"|"$)','',substr(trim($enreg[1]),0,-1))); $enreg[1] = str_replace('\'', '"', ereg_replace('(^\'|\'$)', '', $enreg[1]));
$enreg[1]=str_replace('\'','"',ereg_replace('(^\'|\'$)','',$enreg[1])); if (strtolower($enreg[1]) == 'true') {
if(strtolower($enreg[1]) == 'true') $enreg[1] = 1;
{
$enreg[1]=1;
}
if(strtolower($enreg[1]) == 'false')
{
$enreg[1]=0;
} }
else if (strtolower($enreg[1]) == 'false') {
{ $enreg[1] = 0;
} else {
$implode_string=' '; $implode_string=' ';
if(!strstr($enreg[1],'." ".') && strstr($enreg[1],'.$')) if (!strstr($enreg[1], '." ".') && strstr($enreg[1], '.$')) {
{ $enreg[1] = str_replace('.$', '." ".$', $enreg[1]);
$enreg[1]=str_replace('.$','." ".$',$enreg[1]); $implode_string = '';
$implode_string='';
} }
$tmp=explode('." ".',$enreg[1]); $tmp = explode('." ".', $enreg[1]);
foreach($tmp as $tmp_key=>$tmp_val) foreach ($tmp as $tmp_key => $tmp_val) {
{ if (eregi('^\$[a-z_][a-z0-9_]*$', $tmp_val)) {
if(eregi('^\$[a-z_][a-z0-9_]*$',$tmp_val)) $tmp[$tmp_key] = get_config_param(str_replace('$', '', $tmp_val));
{
$tmp[$tmp_key]=get_config_param(str_replace('$','',$tmp_val));
} }
} }
$enreg[1]=implode($implode_string,$tmp); $enreg[1] = implode($implode_string, $tmp);
} }
$configFile[$enreg[0]]=$enreg[1]; $configFile[$enreg[0]] = $enreg[1];
$a=explode("'",$enreg[0]); $a = explode("'", $enreg[0]);
$key_tmp=$a[1]; $key_tmp = $a[1];
if($key_tmp== $param) if ($key_tmp == $param) {
{ $val = $enreg[1];
$val=$enreg[1];
} }
} }
} }
} }
return $val; return $val;
}
else } else {
{ error_log('Config array could not be found in get_config_param()', 0);
error_log('Config array could not be found in get_config_param()',0);
return null; return null;
} }
} }
@ -252,12 +229,12 @@ function get_config_param($param,$updatePath='')
* @return mixed The parameter value or null if not found * @return mixed The parameter value or null if not found
*/ */
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);
// The system has not been designed to use special SQL modes that were introduced since MySQL 5 $mydb = mysql_connect($host, $login, $pass);
@mysql_query("set session sql_mode='';"); @mysql_query("set session sql_mode='';"); // Disabling special SQL modes (MySQL 5)
$myconnect = mysql_select_db($db_name); $myconnect = mysql_select_db($db_name);
$sql = "SELECT * FROM settings_current WHERE variable = '$param'"; $sql = "SELECT * FROM settings_current WHERE variable = '$param'";
$res = mysql_query($sql); $res = mysql_query($sql);
if ($res === false) { if ($res === false) {
@ -273,12 +250,14 @@ function get_config_param_from_db($host, $login, $pass, $db_name, $param = '') {
} }
/** /**
* TODO: The main API is accessible here. Then we could use a function for this purpose from there?
*
* Return a list of language directories. * Return a list of language directories.
* @todo function does not belong here, move to code library, * @todo function does not belong here, move to code library,
* also see infocours.php which contains similar function * also see infocours.php which contains similar function
*/ */
function get_language_folder_list($dirname) { function get_language_folder_list($dirname) {
if ($dirname[strlen($dirname)-1] != '/') { if ($dirname[strlen($dirname) - 1] != '/') {
$dirname .= '/'; $dirname .= '/';
} }
$handle = opendir($dirname); $handle = opendir($dirname);
@ -309,13 +288,13 @@ function get_language_folder_list($dirname) {
*/ */
function display_language_selection_box() { function display_language_selection_box() {
//get language list //get language list
$dirname = '../lang/'; $dirname = '../lang/'; // TODO: Check api_get_path() and use it.
$language_list = get_language_folder_list($dirname); $language_list = get_language_folder_list($dirname);
sort($language_list); sort($language_list);
//Reduce the number of languages shown to only show those with higher than 90% translation in DLTT //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 //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 = $language_list;
$language_to_display = array('asturian','bulgarian','english','italian','french','slovenian','slovenian_unicode','spanish'); $language_to_display = array('asturian', 'bulgarian', 'english', 'italian', 'french', 'slovenian', 'slovenian_unicode', 'spanish');
//display //display
echo "\t\t<select name=\"language_list\">\n"; echo "\t\t<select name=\"language_list\">\n";
@ -657,7 +636,7 @@ function display_requirements($installType, $badUpdatePath, $updatePath = '', $u
?> ?>
<p align="center"> <p align="center">
<button type="submit" name="step1" class="back" onclick="window.location='index.php';return false;" value="&lt; <?php echo get_lang('Previous'); ?>" ><?php echo get_lang('Previous'); ?></button> <button type="submit" name="step1" class="back" onclick="window.location='index.php';return false;" value="&lt; <?php echo get_lang('Previous'); ?>" ><?php echo get_lang('Previous'); ?></button>
<button type="submit" name="step2_install" class="add" value="<?php echo get_lang("NewInstallation"); ?>" <?php if($error) if($error)echo 'disabled="disabled"'; ?> ><?php echo get_lang('NewInstallation'); ?></button> <button type="submit" name="step2_install" class="add" value="<?php echo get_lang("NewInstallation"); ?>" <?php if ($error) echo 'disabled="disabled"'; ?> ><?php echo get_lang('NewInstallation'); ?></button>
<input type="hidden" name="is_executable" id="is_executable" value="-" /> <input type="hidden" name="is_executable" id="is_executable" value="-" />
<?php <?php
//real code //real code
@ -724,24 +703,19 @@ function display_license_agreement() {
function display_database_parameter($install_type, $parameter_name, $form_field_name, $parameter_value, $extra_notice, $display_when_update = true, $tr_attribute = '') { function display_database_parameter($install_type, $parameter_name, $form_field_name, $parameter_value, $extra_notice, $display_when_update = true, $tr_attribute = '') {
echo "<tr ".$tr_attribute.">\n"; echo "<tr ".$tr_attribute.">\n";
echo "<td>$parameter_name&nbsp;&nbsp;</td>\n"; echo "<td>$parameter_name&nbsp;&nbsp;</td>\n";
if ($install_type == INSTALL_TYPE_UPDATE && $display_when_update) { if ($install_type == INSTALL_TYPE_UPDATE && $display_when_update) {
echo '<td><input type="hidden" name="'.$form_field_name.'" id="'.$form_field_name.'" value="'.htmlentities($parameter_value).'" />'.$parameter_value."</td>\n";
echo '<td><input type="hidden" name="'.$form_field_name.'" id="'.$form_field_name.'" value="'.api_htmlentities($parameter_value).'" />'.$parameter_value."</td>\n";
} else { } else {
if ($form_field_name == 'dbPassForm') {
$inputtype = 'password';
} else {
$inputtype = 'text';
}
//Slightly limit the length of the database prefix to avoid $inputtype = $form_field_name == 'dbPassForm' ? 'password' : 'text';
//having to cut down the databases names later on
if ($form_field_name == 'dbPrefixForm') { //Slightly limit the length of the database prefix to avoid having to cut down the databases names later on
$maxlength = '15'; $maxlength = $form_field_name == 'dbPrefixForm' ? '15' : MAX_FORM_FIELD_LENGTH;
} else {
$maxlength = MAX_FORM_FIELD_LENGTH;
}
echo '<td><input type="'.$inputtype.'" size="'.DATABASE_FORM_FIELD_DISPLAY_LENGTH.'" maxlength="'.$maxlength.'" name="'.$form_field_name.'" id="'.$form_field_name.'" value="'.htmlentities($parameter_value).'" />'."</td>\n"; echo '<td><input type="'.$inputtype.'" size="'.DATABASE_FORM_FIELD_DISPLAY_LENGTH.'" maxlength="'.$maxlength.'" name="'.$form_field_name.'" id="'.$form_field_name.'" value="'.api_htmlentities($parameter_value).'" />'."</td>\n";
echo "<td>$extra_notice</td>\n"; echo "<td>$extra_notice</td>\n";
} }
echo "</tr>\n"; echo "</tr>\n";
@ -753,9 +727,11 @@ function display_database_parameter($install_type, $parameter_name, $form_field_
* or multiple databases, tracking or not... * or multiple databases, tracking or not...
*/ */
function display_database_settings_form($installType, $dbHostForm, $dbUsernameForm, $dbPassForm, $dbPrefixForm, $enableTrackingForm, $singleDbForm, $dbNameForm, $dbStatsForm, $dbScormForm, $dbUserForm) { function display_database_settings_form($installType, $dbHostForm, $dbUsernameForm, $dbPassForm, $dbPrefixForm, $enableTrackingForm, $singleDbForm, $dbNameForm, $dbStatsForm, $dbScormForm, $dbUserForm) {
if ($installType == 'update') { if ($installType == 'update') {
global $_configuration, $update_from_version_6; global $_configuration, $update_from_version_6;
if (in_array($_POST['old_version'],$update_from_version_6)) {
if (in_array($_POST['old_version'], $update_from_version_6)) {
$dbHostForm = get_config_param('dbHost'); $dbHostForm = get_config_param('dbHost');
$dbUsernameForm = get_config_param('dbLogin'); $dbUsernameForm = get_config_param('dbLogin');
$dbPassForm = get_config_param('dbPass'); $dbPassForm = get_config_param('dbPass');
@ -790,15 +766,13 @@ function display_database_settings_form($installType, $dbHostForm, $dbUsernameFo
} }
} }
if (empty($dbUserForm)) { if (empty($dbUserForm)) {
if ($singleDbForm) { $dbUserForm = $singleDbForm ? $dbNameForm : $dbPrefixForm.'chamilo_user';
$dbUserForm = $dbNameForm;
} else {
$dbUserForm = $dbPrefixForm.'chamilo_user';
}
} }
echo '<h2>' . display_step_sequence() .get_lang('DBSetting') . '</h2>'; echo '<h2>' . display_step_sequence() .get_lang('DBSetting') . '</h2>';
echo get_lang('DBSettingUpgradeIntro'); echo get_lang('DBSettingUpgradeIntro');
} else { } else {
if (empty($dbPrefixForm)) { //make sure there is a default value for db prefix if (empty($dbPrefixForm)) { //make sure there is a default value for db prefix
$dbPrefixForm = 'chamilo_'; $dbPrefixForm = 'chamilo_';
} }
@ -826,22 +800,27 @@ function display_database_settings_form($installType, $dbHostForm, $dbUsernameFo
</tr> </tr>
<?php <?php
//database user username //database user username
$example_login = get_lang('EG').' root'; $example_login = get_lang('EG').' root';
display_database_parameter($installType, get_lang('DBLogin'), 'dbUsernameForm', $dbUsernameForm, $example_login); display_database_parameter($installType, get_lang('DBLogin'), 'dbUsernameForm', $dbUsernameForm, $example_login);
//database user password //database user password
$example_password = get_lang('EG').' '.api_generate_password(); $example_password = get_lang('EG').' '.api_generate_password();
display_database_parameter($installType, get_lang('DBPassword'), 'dbPassForm', $dbPassForm, $example_password); display_database_parameter($installType, get_lang('DBPassword'), 'dbPassForm', $dbPassForm, $example_password);
//database prefix //database prefix
display_database_parameter($installType, get_lang('DbPrefixForm'), 'dbPrefixForm', $dbPrefixForm, get_lang('DbPrefixCom')); display_database_parameter($installType, get_lang('DbPrefixForm'), 'dbPrefixForm', $dbPrefixForm, get_lang('DbPrefixCom'));
//fields for the four standard Chamilo databases //fields for the four standard Chamilo databases
echo '<tr><td colspan="3"><a href="" onclick="javascript: show_hide_option();return false;" id="optionalparameters"><img style="vertical-align:middle;" src="../img/div_show.gif" alt="show-hide" /> '.get_lang('OptionalParameters', '').'</a></td></tr>'; echo '<tr><td colspan="3"><a href="" onclick="javascript: show_hide_option();return false;" id="optionalparameters"><img style="vertical-align:middle;" src="../img/div_show.gif" alt="show-hide" /> '.get_lang('OptionalParameters', '').'</a></td></tr>';
display_database_parameter($installType, get_lang('MainDB'), 'dbNameForm', $dbNameForm, '&nbsp;', null, 'id="optional_param1" style="display:none;"'); display_database_parameter($installType, get_lang('MainDB'), 'dbNameForm', $dbNameForm, '&nbsp;', null, 'id="optional_param1" style="display:none;"');
display_database_parameter($installType, get_lang('StatDB'), 'dbStatsForm', $dbStatsForm, '&nbsp;', null, 'id="optional_param2" style="display:none;"'); display_database_parameter($installType, get_lang('StatDB'), 'dbStatsForm', $dbStatsForm, '&nbsp;', null, 'id="optional_param2" style="display:none;"');
if ($installType == 'update' && in_array($_POST['old_version'],$update_from_version_6)) { if ($installType == 'update' && in_array($_POST['old_version'], $update_from_version_6)) {
display_database_parameter($installType, get_lang('ScormDB'), 'dbScormForm', $dbScormForm, '&nbsp;', null, 'id="optional_param3" style="display:none;"'); display_database_parameter($installType, get_lang('ScormDB'), 'dbScormForm', $dbScormForm, '&nbsp;', null, 'id="optional_param3" style="display:none;"');
} }
display_database_parameter($installType, get_lang('UserDB'), 'dbUserForm', $dbUserForm, '&nbsp;', null, 'id="optional_param4" style="display:none;"'); display_database_parameter($installType, get_lang('UserDB'), 'dbUserForm', $dbUserForm, '&nbsp;', null, 'id="optional_param4" style="display:none;"');
?> ?>
<tr id="optional_param5" style="display:none;"> <tr id="optional_param5" style="display:none;">
<td><?php echo get_lang('EnableTracking'); ?> </td> <td><?php echo get_lang('EnableTracking'); ?> </td>
@ -860,7 +839,7 @@ function display_database_settings_form($installType, $dbHostForm, $dbUsernameFo
<tr id="optional_param6" style="display:none;"> <tr id="optional_param6" style="display:none;">
<td><?php echo get_lang('SingleDb'); ?> </td> <td><?php echo get_lang('SingleDb'); ?> </td>
<?php if($installType == 'update'): ?> <?php if ($installType == 'update'): ?>
<td><input type="hidden" name="singleDbForm" value="<?php echo $singleDbForm; ?>" /><?php echo $singleDbForm ? get_lang('One') : get_lang('Several'); ?></td> <td><input type="hidden" name="singleDbForm" value="<?php echo $singleDbForm; ?>" /><?php echo $singleDbForm ? get_lang('One') : get_lang('Several'); ?></td>
<?php else: ?> <?php else: ?>
<td> <td>
@ -947,14 +926,16 @@ function display_configuration_settings_form($installType, $urlForm, $languageFo
//First parameter: language //First parameter: language
echo "<tr>\n"; echo "<tr>\n";
echo '<td>'.get_lang('MainLang')."&nbsp;&nbsp;</td>\n"; echo '<td>'.get_lang('MainLang')."&nbsp;&nbsp;</td>\n";
if ($installType == 'update') { if ($installType == 'update') {
echo '<td><input type="hidden" name="languageForm" value="'.api_htmlentities($languageForm, ENT_QUOTES).'" />'.$languageForm."</td>\n"; echo '<td><input type="hidden" name="languageForm" value="'.api_htmlentities($languageForm, ENT_QUOTES).'" />'.$languageForm."</td>\n";
} else { // new installation } else { // new installation
echo '<td>'; echo '<td>';
$array_lang = array('asturian','english','italian','french','slovenian','spanish'); $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. ////Only display Language have 90% + // TODO: Ivan: Is this policy actual? I am going to change it.
echo "\t\t<select name=\"languageForm\">\n"; echo "\t\t<select name=\"languageForm\">\n";
@ -1076,7 +1057,7 @@ function display_configuration_settings_form($installType, $urlForm, $languageFo
<td><?php echo get_lang('AllowSelfReg'); ?> :</td> <td><?php echo get_lang('AllowSelfReg'); ?> :</td>
<?php if ($installType == 'update'): ?> <?php if ($installType == 'update'): ?>
<td><input type="hidden" name="allowSelfReg" value="<?php echo $allowSelfReg; ?>" /><?php echo $allowSelfReg? get_lang('Yes') : get_lang('No'); ?></td> <td><input type="hidden" name="allowSelfReg" value="<?php echo $allowSelfReg; ?>" /><?php echo $allowSelfReg ? get_lang('Yes') : get_lang('No'); ?></td>
<?php else: ?> <?php else: ?>
<td> <td>
<input class="checkbox" type="radio" name="allowSelfReg" value="1" id="allowSelfReg1" <?php echo $allowSelfReg ? 'checked="checked" ' : ''; ?>/> <label for="allowSelfReg1"><?php echo get_lang('Yes').' '.get_lang('Recommended'); ?></label> <input class="checkbox" type="radio" name="allowSelfReg" value="1" id="allowSelfReg1" <?php echo $allowSelfReg ? 'checked="checked" ' : ''; ?>/> <label for="allowSelfReg1"><?php echo get_lang('Yes').' '.get_lang('Recommended'); ?></label>
@ -1151,15 +1132,11 @@ function test_db_connect($dbHostForm, $dbUsernameForm, $dbPassForm, $singleDbFor
} }
} elseif ($singleDbForm == 0) { } elseif ($singleDbForm == 0) {
$res = @mysql_connect($dbHostForm, $dbUsernameForm, $dbPassForm); $res = @mysql_connect($dbHostForm, $dbUsernameForm, $dbPassForm);
if ($res === false) {
return $res;
}
if ($res !== false) { if ($res !== false) {
// The system has not been designed to use special SQL modes that were introduced since MySQL 5 @mysql_query("set session sql_mode='';"); // Disabling special SQL modes (MySQL 5)
@mysql_query("set session sql_mode='';"); $multipleDbCheck = @mysql_query("CREATE DATABASE ".$dbPrefixForm."test_chamilo_connection");
$multipleDbCheck = @mysql_query("CREATE DATABASE ".$dbPrefixForm."test_dokeos_connection");
if ($multipleDbCheck !== false) { if ($multipleDbCheck !== false) {
$multipleDbCheck = @mysql_query("DROP DATABASE IF EXISTS ".$dbPrefixForm."test_dokeos_connection"); $multipleDbCheck = @mysql_query("DROP DATABASE IF EXISTS ".$dbPrefixForm."test_chamilo_connection");
if ($multipleDbCheck !== false) { if ($multipleDbCheck !== false) {
$dbConnect = 1; $dbConnect = 1;
} else { } else {

@ -33,8 +33,7 @@ require_once api_get_path(LIBRARY_PATH).'database.lib.php';
*/ */
/** /**
* We assume this function is called from install scripts that reside inside * We assume this function is called from install scripts that reside inside the install folder.
* the install folder.
*/ */
function set_file_folder_permissions() { function set_file_folder_permissions() {
@chmod('.', 0755); //set permissions on install dir @chmod('.', 0755); //set permissions on install dir
@ -72,6 +71,7 @@ function write_courses_htaccess_file($url_append) {
* @param string $path Path to the config file * @param string $path Path to the config file
*/ */
function write_dokeos_config_file($path) { function write_dokeos_config_file($path) {
global $dbHostForm; global $dbHostForm;
global $dbUsernameForm; global $dbUsernameForm;
global $dbPassForm; global $dbPassForm;
@ -92,11 +92,13 @@ function write_dokeos_config_file($path) {
global $session_lifetime; global $session_lifetime;
global $new_version; global $new_version;
global $new_version_stable; global $new_version_stable;
// TODO: api_get_path() to be tested here.
$seek = array('\\', '//'); $seek = array('\\', '//');
$destroy = array('/', '/'); $destroy = array('/', '/');
$rootSys = str_replace($seek, $destroy, realpath($pathForm).'/'); $rootSys = str_replace($seek, $destroy, realpath($pathForm).'/');
$file_path = dirname(__FILE__).'/'.DOKEOS_CONFIG_FILENAME; $file_path = dirname(__FILE__).'/'.DOKEOS_CONFIG_FILENAME;
$content = file_get_contents($file_path); $content = file_get_contents($file_path);
$config['{DATE_GENERATED}'] = date('r'); $config['{DATE_GENERATED}'] = date('r');
$config['{DATABASE_HOST}'] = $dbHostForm; $config['{DATABASE_HOST}'] = $dbHostForm;
@ -112,7 +114,7 @@ function write_dokeos_config_file($path) {
$config['{DATABASE_SCORM}'] = (($singleDbForm && empty($dbScormForm)) ? $dbNameForm : $dbScormForm); $config['{DATABASE_SCORM}'] = (($singleDbForm && empty($dbScormForm)) ? $dbNameForm : $dbScormForm);
$config['{DATABASE_PERSONAL}'] =(($singleDbForm && empty($dbUserForm)) ? $dbNameForm : $dbUserForm); $config['{DATABASE_PERSONAL}'] =(($singleDbForm && empty($dbUserForm)) ? $dbNameForm : $dbUserForm);
$config['{ROOT_WEB}'] = $urlForm; $config['{ROOT_WEB}'] = $urlForm;
$config['{ROOT_SYS}'] = str_replace('\\', '/', $rootSys); $config['{ROOT_SYS}'] = $rootSys;
$config['{URL_APPEND_PATH}'] = $urlAppendPath; $config['{URL_APPEND_PATH}'] = $urlAppendPath;
$config['{PLATFORM_LANGUAGE}'] = $languageForm; $config['{PLATFORM_LANGUAGE}'] = $languageForm;
$config['{SECURITY_KEY}'] = md5(uniqid(rand().time())); $config['{SECURITY_KEY}'] = md5(uniqid(rand().time()));
@ -121,6 +123,7 @@ function write_dokeos_config_file($path) {
$config['SESSION_LIFETIME'] = $session_lifetime; $config['SESSION_LIFETIME'] = $session_lifetime;
$config['{NEW_VERSION}'] = $new_version; $config['{NEW_VERSION}'] = $new_version;
$config['NEW_VERSION_STABLE'] = trueFalse($new_version_stable); $config['NEW_VERSION_STABLE'] = trueFalse($new_version_stable);
foreach ($config as $key => $value) { foreach ($config as $key => $value) {
$content = str_replace($key, $value, $content); $content = str_replace($key, $value, $content);
} }
@ -141,9 +144,9 @@ function write_dokeos_config_file($path) {
Please go back to step 5. Please go back to step 5.
<p><input type="submit" name="step5" value="&lt; Back" /></p> <p><input type="submit" name="step5" value="&lt; Back" /></p>
</td></tr></table></form></body></html>'; </td></tr></table></form></body></html>';
exit (); exit ();
} }
fwrite($fp, $content); fwrite($fp, $content);
fclose($fp); fclose($fp);
} }
@ -344,22 +347,23 @@ function get_sql_file_contents($file, $section, $print_errors = true) {
} }
if (!in_array($section, array('main', 'user', 'stats', 'scorm', 'course'))) { if (!in_array($section, array('main', 'user', 'stats', 'scorm', 'course'))) {
$error = "Section '$section' is not authorized in get_sql_file_contents()"; $error = "Section '$section' is not authorized in get_sql_file_contents()";
if($print_errors) echo $error; if ($print_errors) echo $error;
return false; return false;
} }
$filepath = getcwd().'/'.$file; $filepath = getcwd().'/'.$file;
if (!is_file($filepath) or !is_readable($filepath)) { if (!is_file($filepath) or !is_readable($filepath)) {
$error = "File $filepath not found or not readable in get_sql_file_contents()"; $error = "File $filepath not found or not readable in get_sql_file_contents()";
if($print_errors) echo $error; if ($print_errors) echo $error;
return false; return false;
} }
//read the file in an array //read the file in an array
$file_contents = file($filepath); $file_contents = file($filepath);
if (!is_array($file_contents) or count($file_contents) < 1) { if (!is_array($file_contents) or count($file_contents) < 1) {
$error = "File $filepath looks empty in get_sql_file_contents()"; $error = "File $filepath looks empty in get_sql_file_contents()";
if($print_errors) echo $error; if ($print_errors) echo $error;
return false; return false;
} }
//prepare the resulting array //prepare the resulting array
$section_contents = array(); $section_contents = array();
$record = false; $record = false;
@ -373,14 +377,14 @@ function get_sql_file_contents($file, $section, $print_errors = true) {
$record = true; $record = true;
} else { } else {
//we have another section's header. If we were recording, stop now and exit loop //we have another section's header. If we were recording, stop now and exit loop
if ($record == true) { if ($record) {
break; break;
} }
$record = false; $record = false;
} }
} }
} else { } else {
if ($record == true) { if ($record) {
if (!empty($line)) { if (!empty($line)) {
$section_contents[] = $line; $section_contents[] = $line;
} }
@ -391,6 +395,7 @@ function get_sql_file_contents($file, $section, $print_errors = true) {
return $section_contents; return $section_contents;
} }
// 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();
if ($handle = opendir($directory)) { if ($handle = opendir($directory)) {

@ -37,15 +37,14 @@
*/ */
//load helper functions //load helper functions
require_once("install_upgrade.lib.php"); require_once 'install_upgrade.lib.php';
//remove memory and time limits as much as possible as this might be a long process... //remove memory and time limits as much as possible as this might be a long process...
if(function_exists('ini_set')) if (function_exists('ini_set')) {
{ ini_set('memory_limit', -1);
ini_set('memory_limit',-1); ini_set('max_execution_time', 0);
ini_set('max_execution_time',0); } else {
}else{ error_log('Update-db script: could not change memory and time limits', 0);
error_log('Update-db script: could not change memory and time limits',0);
} }
/* /*
@ -55,11 +54,10 @@ if(function_exists('ini_set'))
*/ */
//check if we come from index.php or update_courses.php - otherwise display error msg //check if we come from index.php or update_courses.php - otherwise display error msg
if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE')) if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE')) {
{
//check if the current Dokeos install is elligible for update //check if the current Dokeos install is elligible for update
if (empty ($updateFromConfigFile) || !file_exists($_POST['updatePath'].$updateFromConfigFile) || !in_array(get_config_param('clarolineVersion'), $update_from_version_6)) if (empty ($updateFromConfigFile) || !file_exists($_POST['updatePath'].$updateFromConfigFile) || !in_array(get_config_param('clarolineVersion'), $update_from_version_6)) {
{
echo '<strong>'.get_lang('Error').' !</strong> Dokeos '.implode('|', $updateFromVersion).' '.get_lang('HasNotBeenFound').'.<br /><br /> echo '<strong>'.get_lang('Error').' !</strong> Dokeos '.implode('|', $updateFromVersion).' '.get_lang('HasNotBeenFound').'.<br /><br />
'.get_lang('PleasGoBackToStep1').'. '.get_lang('PleasGoBackToStep1').'.
<p><button type="submit" class="back" name="step1" value="&lt; '.get_lang('Back').'">'.get_lang('Back').'</button></p> <p><button type="submit" class="back" name="step1" value="&lt; '.get_lang('Back').'">'.get_lang('Back').'</button></p>
@ -72,8 +70,7 @@ if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE'))
//actually gets the param from //actually gets the param from
$_configuration['db_glue'] = get_config_param('dbGlu'); $_configuration['db_glue'] = get_config_param('dbGlu');
if ($singleDbForm) if ($singleDbForm) {
{
$_configuration['table_prefix'] = get_config_param('courseTablePrefix'); $_configuration['table_prefix'] = get_config_param('courseTablePrefix');
$_configuration['main_database'] = get_config_param('mainDbName'); $_configuration['main_database'] = get_config_param('mainDbName');
$_configuration['db_prefix'] = get_config_param('dbNamePrefix'); $_configuration['db_prefix'] = get_config_param('dbNamePrefix');
@ -81,20 +78,17 @@ if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE'))
$dbScormForm = eregi_replace('[^a-z0-9_-]', '', $dbScormForm); $dbScormForm = eregi_replace('[^a-z0-9_-]', '', $dbScormForm);
if (!empty ($dbPrefixForm) && !ereg('^'.$dbPrefixForm, $dbScormForm)) if (!empty ($dbPrefixForm) && !ereg('^'.$dbPrefixForm, $dbScormForm)) {
{
$dbScormForm = $dbPrefixForm.$dbScormForm; $dbScormForm = $dbPrefixForm.$dbScormForm;
} }
if (empty ($dbScormForm) || $dbScormForm == 'mysql' || $dbScormForm == $dbPrefixForm) if (empty ($dbScormForm) || $dbScormForm == 'mysql' || $dbScormForm == $dbPrefixForm) {
{
$dbScormForm = $dbPrefixForm.'scorm'; $dbScormForm = $dbPrefixForm.'scorm';
} }
$res = @mysql_connect($dbHostForm, $dbUsernameForm, $dbPassForm); $res = @mysql_connect($dbHostForm, $dbUsernameForm, $dbPassForm);
//if error on connection to the database, show error and exit //if error on connection to the database, show error and exit
if ($res === false) if ($res === false) {
{
//$no = mysql_errno(); //$no = mysql_errno();
//$msg = mysql_error(); //$msg = mysql_error();
@ -111,8 +105,7 @@ if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE'))
exit (); exit ();
} }
// The system has not been designed to use special SQL modes that were introduced since MySQL 5 @mysql_query("set session sql_mode='';"); // Disabling special SQL modes (MySQL 5)
@mysql_query("set session sql_mode='';");
$dblistres = mysql_list_dbs(); $dblistres = mysql_list_dbs();
$dblist = array(); $dblist = array();
@ -129,48 +122,45 @@ if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE'))
// that we want to change the main databases as well... // that we want to change the main databases as well...
$only_test = false; $only_test = false;
$log = 0; $log = 0;
if (defined('DOKEOS_INSTALL'))
{ if (defined('DOKEOS_INSTALL')) {
if ($singleDbForm)
{ if ($singleDbForm) {
if(empty($dbStatsForm)) $dbStatsForm = $dbNameForm; if (empty($dbStatsForm)) $dbStatsForm = $dbNameForm;
if(empty($dbScormForm)) $dbScormForm = $dbNameForm; if (empty($dbScormForm)) $dbScormForm = $dbNameForm;
if(empty($dbUserForm)) $dbUserForm = $dbNameForm; if (empty($dbUserForm)) $dbUserForm = $dbNameForm;
} }
/** /**
* Update the databases "pre" migration * Update the databases "pre" migration
*/ */
include ("../lang/english/create_course.inc.php"); include '../lang/english/create_course.inc.php';
if ($languageForm != 'english') if ($languageForm != 'english') {
{
//languageForm has been escaped in index.php //languageForm has been escaped in index.php
include ("../lang/$languageForm/create_course.inc.php"); include '../lang/'.$languageForm.'/create_course.inc.php';
} }
//get the main queries list (m_q_list) //get the main queries list (m_q_list)
$m_q_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-pre.sql','main'); $m_q_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-pre.sql', 'main');
if(count($m_q_list)>0) if (count($m_q_list) > 0) {
{
//now use the $m_q_list //now use the $m_q_list
/** /**
* We connect to the right DB first to make sure we can use the queries * We connect to the right DB first to make sure we can use the queries
* without a database name * without a database name
*/ */
if(strlen($dbNameForm)>40){ if (strlen($dbNameForm) > 40) {
error_log('Database name '.$dbNameForm.' is too long, skipping',0); error_log('Database name '.$dbNameForm.' is too long, skipping', 0);
}elseif(!in_array($dbNameForm,$dblist)){ } elseif (!in_array($dbNameForm, $dblist)) {
error_log('Database '.$dbNameForm.' was not found, skipping',0); error_log('Database '.$dbNameForm.' was not found, skipping', 0);
}else{ } else {
mysql_select_db($dbNameForm); mysql_select_db($dbNameForm);
foreach($m_q_list as $query){ foreach ($m_q_list as $query) {
if($only_test){ if ($only_test) {
error_log("mysql_query($dbNameForm,$query)",0); error_log("mysql_query($dbNameForm,$query)", 0);
}else{ } else {
$res = mysql_query($query); $res = mysql_query($query);
if($log) if ($log) {
{ error_log("In $dbNameForm, executed: $query", 0);
error_log("In $dbNameForm, executed: $query",0);
} }
} }
} }
@ -178,53 +168,51 @@ if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE'))
} }
//get the stats queries list (s_q_list) //get the stats queries list (s_q_list)
$s_q_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-pre.sql','stats'); $s_q_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-pre.sql', 'stats');
if(count($s_q_list)>0) if (count($s_q_list) > 0) {
{
//now use the $s_q_list //now use the $s_q_list
/** /**
* We connect to the right DB first to make sure we can use the queries * We connect to the right DB first to make sure we can use the queries
* without a database name * without a database name
*/ */
if(strlen($dbStatsForm)>40){ if (strlen($dbStatsForm) > 40){
error_log('Database name '.$dbStatsForm.' is too long, skipping',0); error_log('Database name '.$dbStatsForm.' is too long, skipping', 0);
}elseif(!in_array($dbStatsForm,$dblist)){ } elseif (!in_array($dbStatsForm,$dblist)){
error_log('Database '.$dbStatsForm.' was not found, skipping',0); error_log('Database '.$dbStatsForm.' was not found, skipping', 0);
}else{ } else {
mysql_select_db($dbStatsForm); mysql_select_db($dbStatsForm);
foreach($s_q_list as $query){ foreach($s_q_list as $query) {
if($only_test){ if ($only_test) {
error_log("mysql_query($dbStatsForm,$query)",0); error_log("mysql_query($dbStatsForm,$query)", 0);
}else{ } else {
$res = mysql_query($query); $res = mysql_query($query);
if($log) if ($log) {
{ error_log("In $dbStatsForm, executed: $query", 0);
error_log("In $dbStatsForm, executed: $query",0);
} }
} }
} }
} }
} }
//get the user queries list (u_q_list) //get the user queries list (u_q_list)
$u_q_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-pre.sql','user'); $u_q_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-pre.sql', 'user');
if(count($u_q_list)>0) if (count($u_q_list) > 0) {
{
//now use the $u_q_list //now use the $u_q_list
/** /**
* We connect to the right DB first to make sure we can use the queries * We connect to the right DB first to make sure we can use the queries
* without a database name * without a database name
*/ */
if(strlen($dbUserForm)>40){ if (strlen($dbUserForm) > 40) {
error_log('Database name '.$dbUserForm.' is too long, skipping',0); error_log('Database name '.$dbUserForm.' is too long, skipping', 0);
}elseif(!in_array($dbUserForm,$dblist)){ } elseif (!in_array($dbUserForm, $dblist)){
error_log('Database '.$dbUserForm.' was not found, skipping',0); error_log('Database '.$dbUserForm.' was not found, skipping', 0);
}else{ } else {
mysql_select_db($dbUserForm); mysql_select_db($dbUserForm);
foreach($u_q_list as $query){ foreach ($u_q_list as $query){
if($only_test){ if ($only_test){
error_log("mysql_query($dbUserForm,$query)",0); error_log("mysql_query($dbUserForm,$query)", 0);
error_log("In $dbUserForm, executed: $query",0); error_log("In $dbUserForm, executed: $query", 0);
}else{ } else {
$res = mysql_query($query); $res = mysql_query($query);
} }
} }
@ -247,60 +235,52 @@ if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE'))
*/ */
$prefix = ''; $prefix = '';
if ($singleDbForm) if ($singleDbForm) {
{
$prefix = $_configuration['table_prefix']; $prefix = $_configuration['table_prefix'];
} }
//get the courses databases queries list (c_q_list) //get the courses databases queries list (c_q_list)
$c_q_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-pre.sql','course'); $c_q_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-pre.sql', 'course');
if(count($c_q_list)>0) if (count($c_q_list) > 0) {
{
//get the courses list //get the courses list
if(strlen($dbNameForm)>40){ if (strlen($dbNameForm) > 40) {
error_log('Database name '.$dbNameForm.' is too long, skipping',0); error_log('Database name '.$dbNameForm.' is too long, skipping', 0);
}elseif(!in_array($dbNameForm,$dblist)){ } elseif (!in_array($dbNameForm, $dblist)) {
error_log('Database '.$dbNameForm.' was not found, skipping',0); error_log('Database '.$dbNameForm.' was not found, skipping', 0);
}else{ } else {
mysql_select_db($dbNameForm); mysql_select_db($dbNameForm);
$res = mysql_query("SELECT code,db_name,directory,course_language FROM course WHERE target_course_code IS NULL"); $res = mysql_query("SELECT code,db_name,directory,course_language FROM course WHERE target_course_code IS NULL");
if($res===false){die('Error while querying the courses list in update_db-1.6.x-1.8.0.inc.php');} if ($res === false) { die('Error while querying the courses list in update_db-1.6.x-1.8.0.inc.php'); }
if(mysql_num_rows($res)>0) if (mysql_num_rows($res) > 0) {
{ $i = 0;
$i=0;
$list = array(); $list = array();
//while( ($i < MAX_COURSE_TRANSFER) && ($row = mysql_fetch_array($res))) //while( ($i < MAX_COURSE_TRANSFER) && ($row = mysql_fetch_array($res)))
while($row = mysql_fetch_array($res)) while($row = mysql_fetch_array($res)) {
{
$list[] = $row; $list[] = $row;
$i++; $i++;
} }
foreach($list as $row_course) foreach($list as $row_course) {
{
//now use the $c_q_list //now use the $c_q_list
/** /**
* We connect to the right DB first to make sure we can use the queries * We connect to the right DB first to make sure we can use the queries
* without a database name * without a database name
*/ */
if (!$singleDbForm) //otherwise just use the main one if (!$singleDbForm) { //otherwise just use the main one
{
mysql_select_db($row_course['db_name']); mysql_select_db($row_course['db_name']);
} }
foreach($c_q_list as $query) foreach($c_q_list as $query) {
{ if ($singleDbForm) { //otherwise just use the main one
if ($singleDbForm) //otherwise just use the main one $query = preg_replace('/^(UPDATE|ALTER TABLE|CREATE TABLE|DROP TABLE|INSERT INTO|DELETE FROM)\s+(\w*)(.*)$/', "$1 $prefix{$row_course['db_name']}_$2$3", $query);
{
$query = preg_replace('/^(UPDATE|ALTER TABLE|CREATE TABLE|DROP TABLE|INSERT INTO|DELETE FROM)\s+(\w*)(.*)$/',"$1 $prefix{$row_course['db_name']}_$2$3",$query);
} }
if($only_test) if ($only_test) {
{ error_log("mysql_query(".$row_course['db_name'].",$query)", 0);
error_log("mysql_query(".$row_course['db_name'].",$query)",0); } else {
}else{
$res = mysql_query($query); $res = mysql_query($query);
if($log) if ($log) {
{ error_log("In ".$row_course['db_name'].", executed: $query", 0);
error_log("In ".$row_course['db_name'].", executed: $query",0);
} }
} }
} }
@ -313,8 +293,7 @@ if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE'))
" WHERE cu.course_code = '".$row_course['code']."' " . " WHERE cu.course_code = '".$row_course['code']."' " .
" AND u.user_id = cu.user_id"; " AND u.user_id = cu.user_id";
$res_uc = mysql_query($sql_uc); $res_uc = mysql_query($sql_uc);
while($user_row = mysql_fetch_array($res_uc)) while($user_row = mysql_fetch_array($res_uc)) {
{
$users_list[$user_row['fn'].' '.$user_row['ln']] = $user_row['ui']; $users_list[$user_row['fn'].' '.$user_row['ln']] = $user_row['ui'];
} }
@ -326,16 +305,15 @@ if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE'))
//update forum tables (migrate from bb_ tables to forum_ tables) //update forum tables (migrate from bb_ tables to forum_ tables)
//migrate categories //migrate categories
$prefix_course = $prefix; $prefix_course = $prefix;
if($singleDbForm) if ($singleDbForm) {
{
$prefix_course = $prefix.$row_course['db_name']."_"; $prefix_course = $prefix.$row_course['db_name']."_";
} }
$sql_orig = "SELECT * FROM ".$prefix_course."bb_categories"; $sql_orig = "SELECT * FROM ".$prefix_course."bb_categories";
$res_orig = mysql_query($sql_orig); $res_orig = mysql_query($sql_orig);
$order = 1; $order = 1;
while($row = mysql_fetch_array($res_orig)){ while ($row = mysql_fetch_array($res_orig)) {
$myorder = (empty($row['cat_order'])?$order:$row['cat_order']); $myorder = (empty($row['cat_order']) ? $order : $row['cat_order']);
$sql = "INSERT INTO ".$prefix_course."forum_category " . $sql = "INSERT INTO ".$prefix_course."forum_category " .
"(cat_id,cat_title,cat_comment,cat_order,locked) VALUES " . "(cat_id,cat_title,cat_comment,cat_order,locked) VALUES " .
"('".$row['cat_id']."','".mysql_real_escape_string($row['cat_title'])."','','".$myorder."',0)"; "('".$row['cat_id']."','".mysql_real_escape_string($row['cat_title'])."','','".$myorder."',0)";
@ -349,10 +327,11 @@ if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE'))
$res = mysql_query($sql); $res = mysql_query($sql);
//error_log($sql,0); //error_log($sql,0);
} }
$sql_orig = "SELECT * FROM ".$prefix_course."bb_forums ORDER BY forum_last_post_id desc"; $sql_orig = "SELECT * FROM ".$prefix_course."bb_forums ORDER BY forum_last_post_id desc";
$res_orig = mysql_query($sql_orig); $res_orig = mysql_query($sql_orig);
$order = 1; $order = 1;
while($row = mysql_fetch_array($res_orig)){ while ($row = mysql_fetch_array($res_orig)) {
$sql = "INSERT INTO ".$prefix_course."forum_forum " . $sql = "INSERT INTO ".$prefix_course."forum_forum " .
"(forum_id,forum_category,allow_edit,forum_comment," . "(forum_id,forum_category,allow_edit,forum_comment," .
"forum_title," . "forum_title," .
@ -375,19 +354,16 @@ if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE'))
$res = mysql_query($sql); $res = mysql_query($sql);
//error_log($sql,0); //error_log($sql,0);
} }
$sql_orig = "SELECT * FROM ".$prefix_course."bb_topics"; $sql_orig = "SELECT * FROM ".$prefix_course."bb_topics";
$res_orig = mysql_query($sql_orig); $res_orig = mysql_query($sql_orig);
while($row = mysql_fetch_array($res_orig)){ while ($row = mysql_fetch_array($res_orig)) {
$name = $row['prenom'].' '.$row['nom']; $name = $row['prenom'].' '.$row['nom'];
//check if user id is reusable //check if user id is reusable
if($row['topic_poster'] <= 1 ) if ($row['topic_poster'] <= 1) {
{ if (isset($users_list[$name])) {
if(isset($users_list[$name]))
{
$poster_id = $users_list[$name]; $poster_id = $users_list[$name];
} } else {
else
{
$poster_id = $row['topic_poster']; $poster_id = $row['topic_poster'];
} }
} }
@ -413,19 +389,16 @@ if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE'))
$res = mysql_query($sql); $res = mysql_query($sql);
//error_log($sql,0); //error_log($sql,0);
} }
$sql_orig = "SELECT * FROM ".$prefix_course."bb_posts bp, ".$prefix_course."bb_posts_text bpt WHERE bp.post_id = bpt.post_id"; $sql_orig = "SELECT * FROM ".$prefix_course."bb_posts bp, ".$prefix_course."bb_posts_text bpt WHERE bp.post_id = bpt.post_id";
$res_orig = mysql_query($sql_orig); $res_orig = mysql_query($sql_orig);
while($row = mysql_fetch_array($res_orig)){ while ($row = mysql_fetch_array($res_orig)) {
$name = $row['prenom'].' '.$row['nom']; $name = $row['prenom'].' '.$row['nom'];
//check if user id is reusable //check if user id is reusable
if($row['poster_id'] <= 0 ) if ($row['poster_id'] <= 0 ) {
{ if (isset($users_list[$name])) {
if(isset($users_list[$name]))
{
$poster_id = $users_list[$name]; $poster_id = $users_list[$name];
} } else {
else
{
$poster_id = $row['poster_id']; $poster_id = $row['poster_id'];
} }
} }
@ -456,7 +429,7 @@ if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE'))
$sql_orig = "SELECT id, tutor_id FROM ".$prefix_course."group_info"; $sql_orig = "SELECT id, tutor_id FROM ".$prefix_course."group_info";
$res_orig = mysql_query($sql_orig); $res_orig = mysql_query($sql_orig);
$order = 1; $order = 1;
while($row = mysql_fetch_array($res_orig)){ while ($row = mysql_fetch_array($res_orig)) {
$sql = "INSERT INTO ".$prefix_course."group_rel_tutor " . $sql = "INSERT INTO ".$prefix_course."group_rel_tutor " .
"(user_id,group_id) VALUES " . "(user_id,group_id) VALUES " .
"('".$row['tutor_id']."','".$row['id']."')"; "('".$row['tutor_id']."','".$row['id']."')";
@ -466,43 +439,40 @@ if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE'))
} }
} }
} }
//load the old-scorm to new-scorm migration script //load the old-scorm to new-scorm migration script
//TODO: deal with the fact that this should only act on MAX_COURSE_TRANSFER courses //TODO: deal with the fact that this should only act on MAX_COURSE_TRANSFER courses
if(!$only_test){ if (!$only_test){
include('update-db-scorm-1.6.x-1.8.0.inc.php'); include('update-db-scorm-1.6.x-1.8.0.inc.php');
} }
if (defined('DOKEOS_INSTALL')) if (defined('DOKEOS_INSTALL')) {
{ if ($singleDbForm) {
if ($singleDbForm)
{
if(empty($dbStatsForm)) $dbStatsForm = $dbNameForm; if(empty($dbStatsForm)) $dbStatsForm = $dbNameForm;
if(empty($dbScormForm)) $dbScormForm = $dbNameForm; if(empty($dbScormForm)) $dbScormForm = $dbNameForm;
if(empty($dbUserForm)) $dbUserForm = $dbNameForm; if(empty($dbUserForm)) $dbUserForm = $dbNameForm;
} }
//deal with migrate-db-1.6.x-1.8.0-post.sql //deal with migrate-db-1.6.x-1.8.0-post.sql
//get the main queries list (m_q_list) //get the main queries list (m_q_list)
$m_q_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-post.sql','main'); $m_q_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-post.sql', 'main');
if(count($m_q_list)>0) if (count($m_q_list) > 0) {
{
//now use the $m_q_list //now use the $m_q_list
/** /**
* We connect to the right DB first to make sure we can use the queries * We connect to the right DB first to make sure we can use the queries
* without a database name * without a database name
*/ */
if(strlen($dbNameForm)>40){ if (strlen($dbNameForm) > 40) {
error_log('Database name '.$dbNameForm.' is too long, skipping',0); error_log('Database name '.$dbNameForm.' is too long, skipping', 0);
}elseif(!in_array($dbNameForm,$dblist)){ } elseif (!in_array($dbNameForm, $dblist)) {
error_log('Database '.$dbNameForm.' was not found, skipping',0); error_log('Database '.$dbNameForm.' was not found, skipping', 0);
}else{ } else {
mysql_select_db($dbNameForm); mysql_select_db($dbNameForm);
foreach($m_q_list as $query){ foreach ($m_q_list as $query) {
if($only_test){ if ($only_test){
error_log("mysql_query($dbNameForm,$query)",0); error_log("mysql_query($dbNameForm,$query)", 0);
}else{ } else {
$res = mysql_query($query); $res = mysql_query($query);
if($log) if ($log) {
{ error_log("In $dbNameForm, executed: $query", 0);
error_log("In $dbNameForm, executed: $query",0);
} }
} }
} }
@ -510,56 +480,53 @@ if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE'))
} }
//get the stats queries list (s_q_list) //get the stats queries list (s_q_list)
$s_q_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-post.sql','stats'); $s_q_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-post.sql', 'stats');
if(count($s_q_list)>0) if (count($s_q_list) > 0) {
{
//now use the $s_q_list //now use the $s_q_list
/** /**
* We connect to the right DB first to make sure we can use the queries * We connect to the right DB first to make sure we can use the queries
* without a database name * without a database name
*/ */
if(strlen($dbStatsForm)>40){ if (strlen($dbStatsForm) > 40) {
error_log('Database name '.$dbStatsForm.' is too long, skipping',0); error_log('Database name '.$dbStatsForm.' is too long, skipping', 0);
}elseif(!in_array($dbNameForm,$dblist)){ } elseif (!in_array($dbNameForm, $dblist)){
error_log('Database '.$dbNameForm.' was not found, skipping',0); error_log('Database '.$dbNameForm.' was not found, skipping', 0);
}else{ } else {
mysql_select_db($dbStatsForm); mysql_select_db($dbStatsForm);
foreach($s_q_list as $query){ foreach ($s_q_list as $query) {
if($only_test){ if ($only_test) {
error_log("mysql_query($dbStatsForm,$query)",0); error_log("mysql_query($dbStatsForm,$query)", 0);
}else{ } else {
$res = mysql_query($query); $res = mysql_query($query);
if($log) if ($log) {
{ error_log("In $dbStatsForm, executed: $query", 0);
error_log("In $dbStatsForm, executed: $query",0);
} }
} }
} }
} }
} }
//get the user queries list (u_q_list) //get the user queries list (u_q_list)
$u_q_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-post.sql','user'); $u_q_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-post.sql', 'user');
if(count($u_q_list)>0) if (count($u_q_list) > 0) {
{
//now use the $u_q_list //now use the $u_q_list
/** /**
* We connect to the right DB first to make sure we can use the queries * We connect to the right DB first to make sure we can use the queries
* without a database name * without a database name
*/ */
if(strlen($dbUserForm)>40){ if (strlen($dbUserForm) > 40) {
error_log('Database name '.$dbUserForm.' is too long, skipping',0); error_log('Database name '.$dbUserForm.' is too long, skipping', 0);
}elseif(!in_array($dbUserForm,$dblist)){ } elseif (!in_array($dbUserForm,$dblist)) {
error_log('Database '.$dbUserForm.' was not found, skipping',0); error_log('Database '.$dbUserForm.' was not found, skipping', 0);
}else{ } else {
mysql_select_db($dbUserForm); mysql_select_db($dbUserForm);
foreach($u_q_list as $query){ foreach ($u_q_list as $query) {
if($only_test){ if ($only_test) {
error_log("mysql_query($dbUserForm,$query)",0); error_log("mysql_query($dbUserForm,$query)", 0);
}else{ } else {
$res = mysql_query($query); $res = mysql_query($query);
if($log) if ($log) {
{ error_log("In $dbUserForm, executed: $query", 0);
error_log("In $dbUserForm, executed: $query",0);
} }
} }
} }
@ -567,57 +534,49 @@ if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE'))
} }
//the SCORM database should need a drop in the post-migrate part. However, we will keep these tables a bit more, just in case... //the SCORM database should need a drop in the post-migrate part. However, we will keep these tables a bit more, just in case...
} }
//get the courses databases queries list (c_q_list) //get the courses databases queries list (c_q_list)
$c_q_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-post.sql','course'); $c_q_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-post.sql', 'course');
if(count($c_q_list)>0) if (count($c_q_list) > 0) {
{
//get the courses list //get the courses list
if(strlen($dbNameForm)>40){ if (strlen($dbNameForm) > 40) {
error_log('Database name '.$dbNameForm.' is too long, skipping',0); error_log('Database name '.$dbNameForm.' is too long, skipping', 0);
}elseif(!in_array($dbNameForm,$dblist)){ } elseif (!in_array($dbNameForm,$dblist)) {
error_log('Database '.$dbNameForm.' was not found, skipping',0); error_log('Database '.$dbNameForm.' was not found, skipping', 0);
}else{ } else {
mysql_select_db($dbNameForm); mysql_select_db($dbNameForm);
$res = mysql_query("SELECT code,db_name,directory,course_language FROM course WHERE target_course_code IS NULL"); $res = mysql_query("SELECT code,db_name,directory,course_language FROM course WHERE target_course_code IS NULL");
if($res===false){die('Error while querying the courses list in update_db-1.6.x-1.8.0.inc.php');} if ($res === false) { die('Error while querying the courses list in update_db-1.6.x-1.8.0.inc.php'); }
if(mysql_num_rows($res)>0) if (mysql_num_rows($res) > 0) {
{ $i = 0;
$i=0;
//while( ($i < MAX_COURSE_TRANSFER) && ($row = mysql_fetch_array($res))) //while( ($i < MAX_COURSE_TRANSFER) && ($row = mysql_fetch_array($res)))
while($row = mysql_fetch_array($res)) while ($row = mysql_fetch_array($res)) {
{
$list[] = $row; $list[] = $row;
$i++; $i++;
} }
foreach($list as $row) foreach ($list as $row) {
{
//now use the $c_q_list //now use the $c_q_list
/** /**
* We connect to the right DB first to make sure we can use the queries * We connect to the right DB first to make sure we can use the queries
* without a database name * without a database name
*/ */
$prefix_course = $prefix; $prefix_course = $prefix;
if($singleDbForm) if ($singleDbForm) {
{
$prefix_course = $prefix.$row['db_name']."_"; $prefix_course = $prefix.$row['db_name']."_";
}else{ } else {
mysql_select_db($row['db_name']); mysql_select_db($row['db_name']);
} }
foreach($c_q_list as $query) foreach($c_q_list as $query) {
{ if ($singleDbForm) { //otherwise just use the main one
if ($singleDbForm) //otherwise just use the main one
{
$query = preg_replace('/^(UPDATE|ALTER TABLE|CREATE TABLE|DROP TABLE|INSERT INTO|DELETE FROM)\s+(\w*)(.*)$/',"$1 $prefix$2$3",$query); $query = preg_replace('/^(UPDATE|ALTER TABLE|CREATE TABLE|DROP TABLE|INSERT INTO|DELETE FROM)\s+(\w*)(.*)$/',"$1 $prefix$2$3",$query);
} }
if($only_test) if ($only_test) {
{ error_log("mysql_query(".$row['db_name'].",$query)", 0);
error_log("mysql_query(".$row['db_name'].",$query)",0); } else {
}else{
$res = mysql_query($query); $res = mysql_query($query);
if($log) if ($log) {
{ error_log("In ".$row['db_name'].", executed: $query", 0);
error_log("In ".$row['db_name'].", executed: $query",0);
} }
} }
} }
@ -629,19 +588,15 @@ if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE'))
// upgrade user categories sort // upgrade user categories sort
$table_user_categories = $dbUserForm.'.user_course_category'; $table_user_categories = $dbUserForm.'.user_course_category';
$sql = 'SELECT * FROM '.$table_user_categories.' ORDER BY user_id, title'; $sql = 'SELECT * FROM '.$table_user_categories.' ORDER BY user_id, title';
$rs = Database::query($sql); $rs = Database::query($sql);
$sort = 0; $sort = 0;
$old_user = 0; $old_user = 0;
while($cat = Database :: fetch_array($rs)) while ($cat = Database::fetch_array($rs)) {
{ if ($old_user != $cat['user_id']) {
if($old_user != $cat['user_id']) $old_user = $cat['user_id'];
{ $sort = 0;
$old_user = $cat['user_id'];
$sort = 0;
} }
$sort++; $sort++;
$sql = 'UPDATE '.$table_user_categories.' SET $sql = 'UPDATE '.$table_user_categories.' SET
@ -650,10 +605,7 @@ if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE'))
Database::query($sql); Database::query($sql);
} }
} else {
}
else
{
echo 'You are not allowed here !'; echo 'You are not allowed here !';
} }
?>

@ -111,8 +111,7 @@ if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE'))
exit (); exit ();
} }
// The system has not been designed to use special SQL modes that were introduced since MySQL 5 @mysql_query("set session sql_mode='';"); // Disabling special SQL modes (MySQL 5)
@mysql_query("set session sql_mode='';");
$dblistres = mysql_list_dbs(); $dblistres = mysql_list_dbs();
$dblist = array(); $dblist = array();

@ -111,8 +111,7 @@ if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE'))
exit (); exit ();
} }
// The system has not been designed to use special SQL modes that were introduced since MySQL 5 @mysql_query("set session sql_mode='';"); // Disabling special SQL modes (MySQL 5)
@mysql_query("set session sql_mode='';");
$dblistres = mysql_list_dbs(); $dblistres = mysql_list_dbs();
$dblist = array(); $dblist = array();

@ -111,8 +111,7 @@ if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE'))
exit (); exit ();
} }
// The system has not been designed to use special SQL modes that were introduced since MySQL 5 @mysql_query("set session sql_mode='';"); // Disabling special SQL modes (MySQL 5)
@mysql_query("set session sql_mode='';");
$dblistres = mysql_list_dbs(); $dblistres = mysql_list_dbs();
$dblist = array(); $dblist = array();

@ -93,8 +93,7 @@ if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE'))
exit (); exit ();
} }
// The system has not been designed to use special SQL modes that were introduced since MySQL 5 @mysql_query("set session sql_mode='';"); // Disabling special SQL modes (MySQL 5)
@mysql_query("set session sql_mode='';");
$dblistres = mysql_list_dbs(); $dblistres = mysql_list_dbs();
$dblist = array(); $dblist = array();

@ -93,8 +93,7 @@ if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE'))
exit (); exit ();
} }
// The system has not been designed to use special SQL modes that were introduced since MySQL 5 @mysql_query("set session sql_mode='';"); // Disabling special SQL modes (MySQL 5)
@mysql_query("set session sql_mode='';");
$dblistres = mysql_list_dbs(); $dblistres = mysql_list_dbs();
$dblist = array(); $dblist = array();

@ -93,8 +93,7 @@ if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE'))
exit (); exit ();
} }
// The system has not been designed to use special SQL modes that were introduced since MySQL 5 @mysql_query("set session sql_mode='';"); // Disabling special SQL modes (MySQL 5)
@mysql_query("set session sql_mode='';");
$dblistres = mysql_list_dbs(); $dblistres = mysql_list_dbs();
$dblist = array(); $dblist = array();

@ -93,8 +93,7 @@ if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE'))
exit (); exit ();
} }
// The system has not been designed to use special SQL modes that were introduced since MySQL 5 @mysql_query("set session sql_mode='';"); // Disabling special SQL modes (MySQL 5)
@mysql_query("set session sql_mode='';");
$dblistres = mysql_list_dbs(); $dblistres = mysql_list_dbs();
$dblist = array(); $dblist = array();

@ -93,8 +93,7 @@ if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE'))
exit (); exit ();
} }
// The system has not been designed to use special SQL modes that were introduced since MySQL 5 @mysql_query("set session sql_mode='';"); // Disabling special SQL modes (MySQL 5)
@mysql_query("set session sql_mode='';");
$dblistres = mysql_list_dbs(); $dblistres = mysql_list_dbs();
$dblist = array(); $dblist = array();

File diff suppressed because it is too large Load Diff

@ -41,21 +41,22 @@
============================================================================== ==============================================================================
*/ */
require_once("../inc/lib/main_api.lib.php"); require_once '../inc/lib/main_api.lib.php';
require_once("../inc/lib/fileUpload.lib.php"); require_once '../inc/lib/fileUpload.lib.php';
require_once('../inc/lib/database.lib.php'); require_once '../inc/lib/database.lib.php';
require_once('install_upgrade.lib.php'); require_once 'install_upgrade.lib.php';
/* /*
============================================================================== ==============================================================================
FUNCTIONS FUNCTIONS
============================================================================== ==============================================================================
*/ */
function insert_db($db_name, $folder_name, $text){ function insert_db($db_name, $folder_name, $text) {
// TODO: The (global?) variable $_course has not been declared/initialized.
$_course['dbName'] = $db_name; $_course['dbName'] = $db_name;
$doc_id = add_document_180($_course, '/'.$folder_name, 'folder', 0, ucfirst($text)); $doc_id = add_document_180($_course, '/'.$folder_name, 'folder', 0, api_ucfirst($text));
api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', 1); api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', 1);
} }
@ -66,80 +67,88 @@ function insert_db($db_name, $folder_name, $text){
============================================================================== ==============================================================================
*/ */
if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE')) if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE')) {
{
$sys_course_path = $pathForm.'courses/'; $sys_course_path = $pathForm.'courses/';
//$tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE); //$tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
mysql_select_db($dbNameForm); mysql_select_db($dbNameForm);
$db_name = $dbNameForm; $db_name = $dbNameForm;
$sql = "SELECT * FROM course"; $sql = "SELECT * FROM course";
error_log('Getting courses for files updates: '.$sql,0); error_log('Getting courses for files updates: '.$sql, 0);
$result=mysql_query($sql); $result = mysql_query($sql);
$perm = api_get_setting('permissions_for_new_directories'); $perm = api_get_setting('permissions_for_new_directories');
$perm = octdec(!empty($perm)?$perm:'0770'); $perm = octdec(!empty($perm) ? $perm : '0770');
$old_umask = umask(0);
while($courses_directories=mysql_fetch_array($result)){ //$old_umask = umask(0); // This function is not thread-safe.
while ($courses_directories = mysql_fetch_array($result)) {
$currentCourseRepositorySys = $sys_course_path.$courses_directories["directory"]."/"; $currentCourseRepositorySys = $sys_course_path.$courses_directories["directory"]."/";
$db_name = $courses_directories["db_name"]; $db_name = $courses_directories["db_name"];
$origCRS = $updatePath.'courses/'.$courses_directories["directory"]; $origCRS = $updatePath.'courses/'.$courses_directories["directory"];
if(!is_dir($origCRS)){ if (!is_dir($origCRS)) {
error_log('Directory '.$origCRS.' does not exist. Skipping.',0); error_log('Directory '.$origCRS.' does not exist. Skipping.', 0);
continue; continue;
} }
//move everything to the new hierarchy (from old path to new path) //move everything to the new hierarchy (from old path to new path)
error_log('Renaming '.$origCRS.' to '.$sys_course_path.$courses_directories["directory"],0); error_log('Renaming '.$origCRS.' to '.$sys_course_path.$courses_directories["directory"], 0);
rename($origCRS,$sys_course_path.$courses_directories["directory"]); rename($origCRS,$sys_course_path.$courses_directories["directory"]);
error_log('Creating dirs in '.$currentCourseRepositorySys,0); error_log('Creating dirs in '.$currentCourseRepositorySys, 0);
//FOLDER DOCUMENT //FOLDER DOCUMENT
//document > audio //document > audio
if(!is_dir($currentCourseRepositorySys."document/audio")){ if (!is_dir($currentCourseRepositorySys."document/audio")) {
mkdir($currentCourseRepositorySys."document/audio",$perm); mkdir($currentCourseRepositorySys."document/audio", $perm);
insert_db($db_name,"audio",get_lang('Audio')); insert_db($db_name, "audio", get_lang('Audio'));
} }
//document > flash //document > flash
if(!is_dir($currentCourseRepositorySys."document/flash")){ if (!is_dir($currentCourseRepositorySys."document/flash")) {
mkdir($currentCourseRepositorySys."document/flash",$perm); mkdir($currentCourseRepositorySys."document/flash", $perm);
insert_db($db_name,"flash",get_lang('Flash')); insert_db($db_name,"flash",get_lang('Flash'));
} }
//document > images //document > images
if(!is_dir($currentCourseRepositorySys."document/images")){ if (!is_dir($currentCourseRepositorySys."document/images")) {
mkdir($currentCourseRepositorySys."document/images",$perm); mkdir($currentCourseRepositorySys."document/images", $perm);
insert_db($db_name,"images",get_lang('Images')); insert_db($db_name,"images",get_lang('Images'));
} }
//document > video //document > video
if(!is_dir($currentCourseRepositorySys."document/video")){ if (!is_dir($currentCourseRepositorySys."document/video")) {
mkdir($currentCourseRepositorySys."document/video",$perm); mkdir($currentCourseRepositorySys."document/video", $perm);
insert_db($db_name,"video",get_lang('Video')); insert_db($db_name,"video",get_lang('Video'));
} }
//document > video > flv //document > video > flv
if(!is_dir($currentCourseRepositorySys."document/video/flv")){ if (!is_dir($currentCourseRepositorySys."document/video/flv")) {
mkdir($currentCourseRepositorySys."document/video/flv",$perm); mkdir($currentCourseRepositorySys."document/video/flv", $perm);
insert_db($db_name,"video",get_lang('Video')." (flv)"); insert_db($db_name,"video",get_lang('Video')." (flv)");
} }
//FOLDER UPLOAD //FOLDER UPLOAD
//upload //upload
if(!is_dir($currentCourseRepositorySys."upload")){ if (!is_dir($currentCourseRepositorySys."upload")) {
mkdir($currentCourseRepositorySys."upload",$perm); mkdir($currentCourseRepositorySys."upload", $perm);
} }
//upload > blog //upload > blog
if(!is_dir($currentCourseRepositorySys."upload/blog")){ if (!is_dir($currentCourseRepositorySys."upload/blog")) {
mkdir($currentCourseRepositorySys."upload/blog",$perm); mkdir($currentCourseRepositorySys."upload/blog", $perm);
} }
//upload > forum //upload > forum
if(!is_dir($currentCourseRepositorySys."upload/forum")){ if (!is_dir($currentCourseRepositorySys."upload/forum")) {
mkdir($currentCourseRepositorySys."upload/forum",$perm); mkdir($currentCourseRepositorySys."upload/forum", $perm);
} }
//upload > test //upload > test
if(!is_dir($currentCourseRepositorySys."upload/test")){ if (!is_dir($currentCourseRepositorySys."upload/test")) {
mkdir($currentCourseRepositorySys."upload/test",$perm); mkdir($currentCourseRepositorySys."upload/test", $perm);
} }
//Updating index file in courses directories to change claroline/ into main/ //Updating index file in courses directories to change claroline/ into main/
@ -150,48 +159,47 @@ if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE'))
'?>'; '?>';
unlink($currentCourseRepositorySys.'index.php'); unlink($currentCourseRepositorySys.'index.php');
$fp = @ fopen($currentCourseRepositorySys.'index.php', 'w'); $fp = @ fopen($currentCourseRepositorySys.'index.php', 'w');
if ($fp) if ($fp) {
{ error_log('Writing redirection file in '.$currentCourseRepositorySys.'index.php', 0);
error_log('Writing redirection file in '.$currentCourseRepositorySys.'index.php',0);
fwrite($fp, $content); fwrite($fp, $content);
fclose($fp); fclose($fp);
}else{ } else {
error_log('Could not open file '.$currentCourseRepositorySys.'index.php',0); error_log('Could not open file '.$currentCourseRepositorySys.'index.php', 0);
} }
} }
umask($old_umask); //umask($old_umask); // This function is not thread-safe.
// Write the Dokeos config file // Write the Dokeos config file
write_dokeos_config_file('../inc/conf/configuration.php'); write_dokeos_config_file('../inc/conf/configuration.php');
// Write a distribution file with the config as a backup for the admin // Write a distribution file with the config as a backup for the admin
write_dokeos_config_file('../inc/conf/configuration.dist.php'); write_dokeos_config_file('../inc/conf/configuration.dist.php');
// Write a .htaccess file in the course repository // Write a .htaccess file in the course repository
write_courses_htaccess_file($urlAppendPath); write_courses_htaccess_file($urlAppendPath);
copy($updatePath.'claroline/inc/conf/add_course.conf.php',$pathForm.'main/inc/conf/add_course.conf.php'); copy($updatePath.'claroline/inc/conf/add_course.conf.php', $pathForm.'main/inc/conf/add_course.conf.php');
copy($updatePath.'claroline/inc/conf/course_info.conf.php',$pathForm.'main/inc/conf/course_info.conf.php'); copy($updatePath.'claroline/inc/conf/course_info.conf.php', $pathForm.'main/inc/conf/course_info.conf.php');
copy($updatePath.'claroline/inc/conf/mail.conf.php',$pathForm.'main/inc/conf/mail.conf.php'); copy($updatePath.'claroline/inc/conf/mail.conf.php', $pathForm.'main/inc/conf/mail.conf.php');
copy($updatePath.'claroline/inc/conf/profile.conf.inc.php',$pathForm.'main/inc/conf/profile.conf.php'); copy($updatePath.'claroline/inc/conf/profile.conf.inc.php', $pathForm.'main/inc/conf/profile.conf.php');
error_log('Renaming '.$updatePath.'claroline/upload/users to '.$pathForm.'main/upload/users',0); error_log('Renaming '.$updatePath.'claroline/upload/users to '.$pathForm.'main/upload/users', 0);
rename($updatePath.'claroline/upload/users',$pathForm.'main/upload/users'); rename($updatePath.'claroline/upload/users', $pathForm.'main/upload/users');
error_log('Renaming '.$updatePath.'claroline/upload/audio to '.$pathForm.'main/upload/audio',0); error_log('Renaming '.$updatePath.'claroline/upload/audio to '.$pathForm.'main/upload/audio', 0);
rename($updatePath.'claroline/upload/audio',$pathForm.'main/upload/audio'); rename($updatePath.'claroline/upload/audio', $pathForm.'main/upload/audio');
error_log('Renaming '.$updatePath.'claroline/upload/images to '.$pathForm.'main/upload/images',0); error_log('Renaming '.$updatePath.'claroline/upload/images to '.$pathForm.'main/upload/images', 0);
rename($updatePath.'claroline/upload/images',$pathForm.'main/upload/images'); rename($updatePath.'claroline/upload/images', $pathForm.'main/upload/images');
error_log('Renaming '.$updatePath.'claroline/upload/linked_files to '.$pathForm.'main/upload/linked_files',0); error_log('Renaming '.$updatePath.'claroline/upload/linked_files to '.$pathForm.'main/upload/linked_files', 0);
rename($updatePath.'claroline/upload/linked_files',$pathForm.'main/upload/linked_files'); rename($updatePath.'claroline/upload/linked_files', $pathForm.'main/upload/linked_files');
error_log('Renaming '.$updatePath.'claroline/upload/video to '.$pathForm.'main/upload/video',0); error_log('Renaming '.$updatePath.'claroline/upload/video to '.$pathForm.'main/upload/video', 0);
rename($updatePath.'claroline/upload/video',$pathForm.'main/upload/video'); rename($updatePath.'claroline/upload/video', $pathForm.'main/upload/video');
/* /*
if (defined('DOKEOS_INSTALL')) if (defined('DOKEOS_INSTALL')) {
{
//nothing to do this time //nothing to do this time
} }
*/ */
}
else } else {
{
echo 'You are not allowed here !'; echo 'You are not allowed here !';
} }
?>

@ -36,53 +36,44 @@
* @package dokeos.install * @package dokeos.install
============================================================================== ==============================================================================
*/ */
require_once("../inc/lib/main_api.lib.php"); require_once '../inc/lib/main_api.lib.php';
require_once("../inc/lib/fileUpload.lib.php"); require_once '../inc/lib/fileUpload.lib.php';
require_once('../inc/lib/database.lib.php'); require_once '../inc/lib/database.lib.php';
if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE')) {
if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE'))
{
// Edit the Dokeos config file // Edit the Dokeos config file
$file = file('../inc/conf/configuration.php'); $file = file('../inc/conf/configuration.php');
$fh = fopen('../inc/conf/configuration.php','w'); $fh = fopen('../inc/conf/configuration.php', 'w');
$found_version = false; $found_version = false;
$found_stable = false; $found_stable = false;
foreach($file as $line) foreach ($file as $line) {
{
$ignore = false; $ignore = false;
if(stristr($line,'$_configuration[\'dokeos_version\']')) if(stristr($line, '$_configuration[\'dokeos_version\']')) {
{
$found_version = true; $found_version = true;
$line = '$_configuration[\'dokeos_version\'] = \''.$new_version.'\';'."\r\n"; $line = '$_configuration[\'dokeos_version\'] = \''.$new_version.'\';'."\r\n";
} } elseif(stristr($line, '$_configuration[\'dokeos_stable\']')) {
elseif(stristr($line,'$_configuration[\'dokeos_stable\']'))
{
$found_stable = true; $found_stable = true;
$line = '$_configuration[\'dokeos_stable\'] = '.($new_version_stable?'true':'false').';'."\r\n"; $line = '$_configuration[\'dokeos_stable\'] = '.($new_version_stable ? 'true' : 'false').';'."\r\n";
} } elseif (stristr($line, '?>')) {
elseif(stristr($line,'?>'))
{
//ignore the line //ignore the line
$ignore = true; $ignore = true;
} }
if(!$ignore) if (!$ignore) {
{ fwrite($fh, $line);
fwrite($fh,$line);
} }
} }
if(!$found_version) if (!$found_version) {
{ fwrite($fh, '$_configuration[\'dokeos_version\'] = \''.$new_version.'\';'."\r\n");
fwrite($fh,'$_configuration[\'dokeos_version\'] = \''.$new_version.'\';'."\r\n");
} }
if(!$found_stable) if (!$found_stable) {
{ fwrite($fh, '$_configuration[\'dokeos_stable\'] = '.($new_version_stable?'true':'false').';'."\r\n");
fwrite($fh,'$_configuration[\'dokeos_stable\'] = '.($new_version_stable?'true':'false').';'."\r\n");
} }
fwrite($fh,'?>'); fwrite($fh, '?>');
fclose($fh); fclose($fh);
}
else } else {
{
echo 'You are not allowed here !'; echo 'You are not allowed here !';
} }
?>

@ -15,53 +15,44 @@
* @package dokeos.install * @package dokeos.install
============================================================================== ==============================================================================
*/ */
require_once("../inc/lib/main_api.lib.php"); require_once '../inc/lib/main_api.lib.php';
require_once("../inc/lib/fileUpload.lib.php"); require_once '../inc/lib/fileUpload.lib.php';
require_once('../inc/lib/database.lib.php'); require_once '../inc/lib/database.lib.php';
if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE')) {
if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE'))
{
// Edit the Dokeos config file // Edit the Dokeos config file
$file = file('../inc/conf/configuration.php'); $file = file('../inc/conf/configuration.php');
$fh = fopen('../inc/conf/configuration.php','w'); $fh = fopen('../inc/conf/configuration.php', 'w');
$found_version = false; $found_version = false;
$found_stable = false; $found_stable = false;
foreach($file as $line) foreach ($file as $line) {
{
$ignore = false; $ignore = false;
if(stristr($line,'$_configuration[\'dokeos_version\']')) if (stristr($line, '$_configuration[\'dokeos_version\']')) {
{
$found_version = true; $found_version = true;
$line = '$_configuration[\'dokeos_version\'] = \''.$new_version.'\';'."\r\n"; $line = '$_configuration[\'dokeos_version\'] = \''.$new_version.'\';'."\r\n";
} } elseif (stristr($line, '$_configuration[\'dokeos_stable\']')) {
elseif(stristr($line,'$_configuration[\'dokeos_stable\']'))
{
$found_stable = true; $found_stable = true;
$line = '$_configuration[\'dokeos_stable\'] = '.($new_version_stable?'true':'false').';'."\r\n"; $line = '$_configuration[\'dokeos_stable\'] = '.($new_version_stable?'true':'false').';'."\r\n";
} } elseif(stristr($line, '?>')) {
elseif(stristr($line,'?>'))
{
//ignore the line //ignore the line
$ignore = true; $ignore = true;
} }
if(!$ignore) if (!$ignore) {
{ fwrite($fh, $line);
fwrite($fh,$line);
} }
} }
if(!$found_version) if (!$found_version) {
{ fwrite($fh, '$_configuration[\'dokeos_version\'] = \''.$new_version.'\';'."\r\n");
fwrite($fh,'$_configuration[\'dokeos_version\'] = \''.$new_version.'\';'."\r\n");
} }
if(!$found_stable) if (!$found_stable) {
{ fwrite($fh, '$_configuration[\'dokeos_stable\'] = '.($new_version_stable?'true':'false').';'."\r\n");
fwrite($fh,'$_configuration[\'dokeos_stable\'] = '.($new_version_stable?'true':'false').';'."\r\n");
} }
fwrite($fh,'?>'); fwrite($fh, '?>');
fclose($fh); fclose($fh);
}
else } else {
{
echo 'You are not allowed here !'; echo 'You are not allowed here !';
} }
?>

@ -15,53 +15,42 @@
* @package dokeos.install * @package dokeos.install
============================================================================== ==============================================================================
*/ */
require_once("../inc/lib/main_api.lib.php"); require_once '../inc/lib/main_api.lib.php';
require_once("../inc/lib/fileUpload.lib.php"); require_once '../inc/lib/fileUpload.lib.php';
require_once('../inc/lib/database.lib.php'); require_once '../inc/lib/database.lib.php';
if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE')) {
if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE'))
{
// Edit the Dokeos config file // Edit the Dokeos config file
$file = file('../inc/conf/configuration.php'); $file = file('../inc/conf/configuration.php');
$fh = fopen('../inc/conf/configuration.php','w'); $fh = fopen('../inc/conf/configuration.php', 'w');
$found_version = false; $found_version = false;
$found_stable = false; $found_stable = false;
foreach($file as $line) foreach ($file as $line) {
{
$ignore = false; $ignore = false;
if(stristr($line,'$_configuration[\'dokeos_version\']')) if (stristr($line, '$_configuration[\'dokeos_version\']')) {
{
$found_version = true; $found_version = true;
$line = '$_configuration[\'dokeos_version\'] = \''.$new_version.'\';'."\r\n"; $line = '$_configuration[\'dokeos_version\'] = \''.$new_version.'\';'."\r\n";
} } elseif(stristr($line, '$_configuration[\'dokeos_stable\']')) {
elseif(stristr($line,'$_configuration[\'dokeos_stable\']'))
{
$found_stable = true; $found_stable = true;
$line = '$_configuration[\'dokeos_stable\'] = '.($new_version_stable?'true':'false').';'."\r\n"; $line = '$_configuration[\'dokeos_stable\'] = '.($new_version_stable?'true':'false').';'."\r\n";
} } elseif(stristr($line,'$userPasswordCrypted')) {
elseif(stristr($line,'$userPasswordCrypted'))
{
$line = '$userPasswordCrypted = \''.($userPasswordCrypted).'\';'."\r\n"; $line = '$userPasswordCrypted = \''.($userPasswordCrypted).'\';'."\r\n";
} } elseif(stristr($line, '?>')) {
elseif(stristr($line,'?>'))
{
//ignore the line //ignore the line
$ignore = true; $ignore = true;
} }
if(!$ignore) if (!$ignore) {
{ fwrite($fh, $line);
fwrite($fh,$line);
} }
} }
if(!$found_version) if (!$found_version) {
{ fwrite($fh, '$_configuration[\'dokeos_version\'] = \''.$new_version.'\';'."\r\n");
fwrite($fh,'$_configuration[\'dokeos_version\'] = \''.$new_version.'\';'."\r\n");
} }
if(!$found_stable) if (!$found_stable) {
{ fwrite($fh, '$_configuration[\'dokeos_stable\'] = '.($new_version_stable?'true':'false').';'."\r\n");
fwrite($fh,'$_configuration[\'dokeos_stable\'] = '.($new_version_stable?'true':'false').';'."\r\n");
} }
fwrite($fh,'?>'); fwrite($fh, '?>');
fclose($fh); fclose($fh);
$sys_course_path = $pathForm.'courses/'; $sys_course_path = $pathForm.'courses/';
@ -69,30 +58,30 @@ if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE'))
//$tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE); //$tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
//linking //linking
$link = mysql_connect($dbHostForm, $dbUsernameForm, $dbPassForm); $link = mysql_connect($dbHostForm, $dbUsernameForm, $dbPassForm);
mysql_select_db($dbNameForm,$link); mysql_select_db($dbNameForm, $link);
$db_name = $dbNameForm; $db_name = $dbNameForm;
$sql = "SELECT * FROM $db_name.course"; $sql = "SELECT * FROM $db_name.course";
error_log('Getting courses for files updates: '.$sql,0); error_log('Getting courses for files updates: '.$sql, 0);
$result=mysql_query($sql); $result = mysql_query($sql);
$perm = api_get_setting('permissions_for_new_directories'); $perm = api_get_setting('permissions_for_new_directories');
$perm = octdec(!empty($perm)?$perm:'0770'); $perm = octdec(!empty($perm) ? $perm : '0770');
$old_umask = umask(0);
//$old_umask = umask(0); // This function is not thread-safe.
while($courses_directories = mysql_fetch_array($result)) {
while($courses_directories=mysql_fetch_array($result))
{
$currentCourseRepositorySys = $sys_course_path.$courses_directories['directory'].'/'; $currentCourseRepositorySys = $sys_course_path.$courses_directories['directory'].'/';
$db_name = $courses_directories['db_name']; $db_name = $courses_directories['db_name'];
$origCRS = $updatePath.'courses/'.$courses_directories['directory']; $origCRS = $updatePath.'courses/'.$courses_directories['directory'];
if(!is_dir($origCRS)){ if (!is_dir($origCRS)) {
error_log('Directory '.$origCRS.' does not exist. Skipping.',0); error_log('Directory '.$origCRS.' does not exist. Skipping.', 0);
continue; continue;
} }
//move everything to the new hierarchy (from old path to new path) //move everything to the new hierarchy (from old path to new path)
error_log('Renaming '.$origCRS.' to '.$sys_course_path.$courses_directories['directory'],0); error_log('Renaming '.$origCRS.' to '.$sys_course_path.$courses_directories['directory'], 0);
rename($origCRS,$sys_course_path.$courses_directories['directory']); rename($origCRS,$sys_course_path.$courses_directories['directory']);
error_log('Creating dirs in '.$currentCourseRepositorySys,0); error_log('Creating dirs in '.$currentCourseRepositorySys,0);

@ -15,69 +15,57 @@
* @package dokeos.install * @package dokeos.install
============================================================================== ==============================================================================
*/ */
require_once("../inc/lib/main_api.lib.php"); require_once '../inc/lib/main_api.lib.php';
require_once("../inc/lib/fileUpload.lib.php"); require_once '../inc/lib/fileUpload.lib.php';
require_once('../inc/lib/database.lib.php'); require_once '../inc/lib/database.lib.php';
if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE')) {
if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE'))
{
// Edit the Dokeos config file // Edit the Dokeos config file
$file = file('../inc/conf/configuration.php'); $file = file('../inc/conf/configuration.php');
$fh = fopen('../inc/conf/configuration.php','w'); $fh = fopen('../inc/conf/configuration.php', 'w');
$found_version = false; $found_version = false;
$found_stable = false; $found_stable = false;
foreach($file as $line) foreach ($file as $line) {
{
$ignore = false; $ignore = false;
if(stristr($line,'$_configuration[\'dokeos_version\']')) if(stristr($line, '$_configuration[\'dokeos_version\']')) {
{
$found_version = true; $found_version = true;
$line = '$_configuration[\'dokeos_version\'] = \''.$new_version.'\';'."\r\n"; $line = '$_configuration[\'dokeos_version\'] = \''.$new_version.'\';'."\r\n";
} } elseif(stristr($line, '$_configuration[\'dokeos_stable\']')) {
elseif(stristr($line,'$_configuration[\'dokeos_stable\']'))
{
$found_stable = true; $found_stable = true;
$line = '$_configuration[\'dokeos_stable\'] = '.($new_version_stable?'true':'false').';'."\r\n"; $line = '$_configuration[\'dokeos_stable\'] = '.($new_version_stable?'true':'false').';'."\r\n";
} } elseif(stristr($line, '$userPasswordCrypted')) {
elseif(stristr($line,'$userPasswordCrypted'))
{
$line = '$userPasswordCrypted = \''.($userPasswordCrypted).'\';'."\r\n"; $line = '$userPasswordCrypted = \''.($userPasswordCrypted).'\';'."\r\n";
} } elseif(stristr($line, '?>')) {
elseif(stristr($line,'?>'))
{
//ignore the line //ignore the line
$ignore = true; $ignore = true;
} }
if(!$ignore) if (!$ignore) {
{ fwrite($fh, $line);
fwrite($fh,$line);
} }
} }
if(!$found_version) if (!$found_version) {
{ fwrite($fh, '$_configuration[\'dokeos_version\'] = \''.$new_version.'\';'."\r\n");
fwrite($fh,'$_configuration[\'dokeos_version\'] = \''.$new_version.'\';'."\r\n");
} }
if(!$found_stable) if (!$found_stable) {
{ fwrite($fh, '$_configuration[\'dokeos_stable\'] = '.($new_version_stable?'true':'false').';'."\r\n");
fwrite($fh,'$_configuration[\'dokeos_stable\'] = '.($new_version_stable?'true':'false').';'."\r\n");
} }
fwrite($fh,'?>'); fwrite($fh, '?>');
fclose($fh); fclose($fh);
$perm = api_get_setting('permissions_for_new_directories'); $perm = api_get_setting('permissions_for_new_directories');
$perm = octdec(!empty($perm)?$perm:'0770'); $perm = octdec(!empty($perm) ? $perm : '0770');
$old_umask = umask(0);
//$old_umask = umask(0); // This function is not thread-safe.
////create a specific directory for global thumbails ////create a specific directory for global thumbails
//home > default_platform_document > template_thumb //home > default_platform_document > template_thumb
if(!is_dir($pathForm.'home/default_platform_document/template_thumb')){ if (!is_dir($pathForm.'home/default_platform_document/template_thumb')) {
mkdir($pathForm.'home/default_platform_document/template_thumb',$perm); mkdir($pathForm.'home/default_platform_document/template_thumb', $perm);
} }
} } else {
else
{
echo 'You are not allowed here !'; echo 'You are not allowed here !';
} }
?>

@ -9,89 +9,77 @@
* @package dokeos.install * @package dokeos.install
============================================================================== ==============================================================================
*/ */
require_once("../inc/lib/main_api.lib.php"); require_once '../inc/lib/main_api.lib.php';
require_once("../inc/lib/fileUpload.lib.php"); require_once '../inc/lib/fileUpload.lib.php';
require_once('../inc/lib/database.lib.php'); require_once '../inc/lib/database.lib.php';
if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE')) if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE')) {
{
// Edit the Dokeos config file // Edit the Dokeos config file
$file = file('../inc/conf/configuration.php'); $file = file('../inc/conf/configuration.php');
$fh = fopen('../inc/conf/configuration.php','w'); $fh = fopen('../inc/conf/configuration.php', 'w');
$found_version = false; $found_version = false;
$found_stable = false; $found_stable = false;
foreach($file as $line) foreach ($file as $line) {
{
$ignore = false; $ignore = false;
if(stristr($line,'$_configuration[\'dokeos_version\']')) if (stristr($line, '$_configuration[\'dokeos_version\']')) {
{
$found_version = true; $found_version = true;
$line = '$_configuration[\'dokeos_version\'] = \''.$new_version.'\';'."\r\n"; $line = '$_configuration[\'dokeos_version\'] = \''.$new_version.'\';'."\r\n";
} } elseif(stristr($line, '$_configuration[\'dokeos_stable\']')) {
elseif(stristr($line,'$_configuration[\'dokeos_stable\']'))
{
$found_stable = true; $found_stable = true;
$line = '$_configuration[\'dokeos_stable\'] = '.($new_version_stable?'true':'false').';'."\r\n"; $line = '$_configuration[\'dokeos_stable\'] = '.($new_version_stable?'true':'false').';'."\r\n";
} } elseif(stristr($line,'$userPasswordCrypted')) {
elseif(stristr($line,'$userPasswordCrypted'))
{
$line = '$userPasswordCrypted = \''.($userPasswordCrypted).'\';'."\r\n"; $line = '$userPasswordCrypted = \''.($userPasswordCrypted).'\';'."\r\n";
} } elseif(stristr($line, '?>')) {
elseif(stristr($line,'?>'))
{
//ignore the line //ignore the line
$ignore = true; $ignore = true;
} }
if(!$ignore) if (!$ignore) {
{ fwrite($fh, $line);
fwrite($fh,$line);
} }
} }
if(!$found_version) if (!$found_version) {
{ fwrite($fh, '$_configuration[\'dokeos_version\'] = \''.$new_version.'\';'."\r\n");
fwrite($fh,'$_configuration[\'dokeos_version\'] = \''.$new_version.'\';'."\r\n");
} }
if(!$found_stable) if (!$found_stable) {
{ fwrite($fh, '$_configuration[\'dokeos_stable\'] = '.($new_version_stable?'true':'false').';'."\r\n");
fwrite($fh,'$_configuration[\'dokeos_stable\'] = '.($new_version_stable?'true':'false').';'."\r\n");
} }
fwrite($fh,'?>'); fwrite($fh, '?>');
fclose($fh); fclose($fh);
$sys_course_path = $pathForm.'courses/'; $sys_course_path = $pathForm.'courses/';
$perm = api_get_setting('permissions_for_new_directories'); $perm = api_get_setting('permissions_for_new_directories');
$perm = octdec(!empty($perm)?$perm:'0770'); $perm = octdec(!empty($perm) ? $perm : '0770');
$old_umask = umask(0);
//$old_umask = umask(0); // This function is not thread-safe.
$link = mysql_connect($dbHostForm, $dbUsernameForm, $dbPassForm); $link = mysql_connect($dbHostForm, $dbUsernameForm, $dbPassForm);
mysql_select_db($dbNameForm,$link); mysql_select_db($dbNameForm, $link);
$db_name = $dbNameForm; $db_name = $dbNameForm;
$sql = "SELECT * FROM $db_name.course"; $sql = "SELECT * FROM $db_name.course";
error_log('Getting courses for files updates: '.$sql,0); error_log('Getting courses for files updates: '.$sql, 0);
$result=mysql_query($sql); $result = mysql_query($sql);
while ($courses_directories=mysql_fetch_array($result)) { while ($courses_directories = mysql_fetch_array($result)) {
$currentCourseRepositorySys = $sys_course_path.$courses_directories['directory'].'/'; $currentCourseRepositorySys = $sys_course_path.$courses_directories['directory'].'/';
//upload > announcements //upload > announcements
if(!is_dir($currentCourseRepositorySys."upload/announcements")){ if (!is_dir($currentCourseRepositorySys."upload/announcements")){
mkdir($currentCourseRepositorySys."upload/announcements",$perm); mkdir($currentCourseRepositorySys."upload/announcements", $perm);
} }
//upload > announcements > images //upload > announcements > images
if(!is_dir($currentCourseRepositorySys."upload/announcements/images")){ if (!is_dir($currentCourseRepositorySys."upload/announcements/images")) {
mkdir($currentCourseRepositorySys."upload/announcements/images",$perm); mkdir($currentCourseRepositorySys."upload/announcements/images", $perm);
} }
} }
////create a specific directory for global thumbails ////create a specific directory for global thumbails
//home > default_platform_document > template_thumb //home > default_platform_document > template_thumb
if(!is_dir($pathForm.'home/default_platform_document/template_thumb')){ if (!is_dir($pathForm.'home/default_platform_document/template_thumb')) {
mkdir($pathForm.'home/default_platform_document/template_thumb',$perm); mkdir($pathForm.'home/default_platform_document/template_thumb', $perm);
} }
} } else {
else
{
echo 'You are not allowed here !'; echo 'You are not allowed here !';
} }
?>

@ -1,24 +1,24 @@
<?php <?php
/* See license terms in /dokeos_license.txt */ /* See license terms in /chamilo_license.txt */
/** /**
============================================================================== ==============================================================================
* Updates the Dokeos files from version 1.8.6.2 to version 1.8.7 * Updates the Chamilo files from version 1.8.6.2 to version 1.8.7
* This script operates only in the case of an update, and only to change the * This script operates only in the case of an update, and only to change the
* active version number (and other things that might need a change) in the * active version number (and other things that might need a change) in the
* current configuration file. * current configuration file.
* @package dokeos.install * @package chamilo.install
============================================================================== ==============================================================================
*/ */
require_once("../inc/lib/main_api.lib.php"); require_once '../inc/lib/main_api.lib.php';
require_once("../inc/lib/fileUpload.lib.php"); require_once '../inc/lib/fileUpload.lib.php';
require_once('../inc/lib/database.lib.php'); require_once '../inc/lib/database.lib.php';
if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE')) if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE')) {
{
// Start coding here...
} else {
}
else
{
echo 'You are not allowed here !'; echo 'You are not allowed here !';
} }
?>

@ -1,5 +1,8 @@
<?php //$id: $ <?php //$id: $
/* For licensing terms, see /dokeos_license.txt */ /* For licensing terms, see /dokeos_license.txt */
// TODO: Ivan, 13-FEB-2010: Is this file really needed?
/** /**
============================================================================== ==============================================================================
* GOAL: Updates courses separately * GOAL: Updates courses separately
@ -30,8 +33,8 @@ require '../lang/english/install.inc.php';
//load for get_config_param() //load for get_config_param()
require_once 'install_functions.inc.php'; require_once 'install_functions.inc.php';
define('DOKEOS_COURSE_UPDATE',1); define('DOKEOS_COURSE_UPDATE', 1);
define('MAX_COURSE_TRANSFER',100); define('MAX_COURSE_TRANSFER', 100);
error_reporting(E_COMPILE_ERROR | E_ERROR | E_CORE_ERROR); error_reporting(E_COMPILE_ERROR | E_ERROR | E_CORE_ERROR);
@ -39,7 +42,7 @@ error_reporting(E_COMPILE_ERROR | E_ERROR | E_CORE_ERROR);
$update_path=trim(stripslashes($_GET['update_path'])); $update_path=trim(stripslashes($_GET['update_path']));
$update_from_version=array('1.5','1.5.4','1.5.5'); $update_from_version = array('1.5', '1.5.4', '1.5.5');
/* /*
============================================================================== ==============================================================================
@ -50,59 +53,51 @@ $update_from_version=array('1.5','1.5.4','1.5.5');
============================================================================== ==============================================================================
*/ */
$updateFromConfigFile=''; // leave empty $updateFromConfigFile = ''; // leave empty
$badUpdatePath=false; $badUpdatePath = false;
if($_POST['step2']) if ($_POST['step2']) {
{
if(empty($_POST['updatePath']))
{
$_POST['step1']=1;
}
else
{
if($_POST['updatePath'][strlen($_POST['updatePath'])-1] != '/')
{
$_POST['updatePath'].='/';
}
if(!file_exists($_POST['updatePath'])) if (empty($_POST['updatePath'])) {
{
$badUpdatePath=true;
$_POST['step2']=0; $_POST['step1'] = 1;
}
elseif(!in_array(get_config_param('clarolineVersion'),$update_from_version)) } else {
{
$badUpdatePath=true;
$_POST['step2']=0; if ($_POST['updatePath'][strlen($_POST['updatePath'])-1] != '/') {
$_POST['updatePath'] .= '/';
} }
else
{ if (!file_exists($_POST['updatePath'])) {
$urlAppendPath=str_replace('/main/install/update_courses.php','',api_get_self()); $badUpdatePath = true;
$urlForm='http://'.$_SERVER['HTTP_HOST'].$urlAppendPath.'/'; $_POST['step2'] = 0;
} elseif (!in_array(get_config_param('clarolineVersion'), $update_from_version)) {
$singleDbForm=get_config_param('singleDbEnabled'); $badUpdatePath = true;
$dbNameForm=get_config_param('mainDbName'); $_POST['step2'] = 0;
$dbHostForm=get_config_param('dbHost'); } else {
$dbUsernameForm=get_config_param('dbLogin'); $urlAppendPath = str_replace('/main/install/update_courses.php', '', api_get_self());
$dbPassForm=get_config_param('dbPass'); $urlForm = 'http://'.$_SERVER['HTTP_HOST'].$urlAppendPath.'/'; // What about https? See api_get_path().
$singleDbForm = get_config_param('singleDbEnabled');
$dbNameForm = get_config_param('mainDbName');
$dbHostForm = get_config_param('dbHost');
$dbUsernameForm = get_config_param('dbLogin');
$dbPassForm = get_config_param('dbPass');
} }
} }
}
elseif($_POST['step1']) } elseif ($_POST['step1']) {
{
$_POST['updatePath']=''; $_POST['updatePath'] = '';
} }
?> ?>
<html> <html>
<head> <head>
<?php /* There is no metadata about current language and encoding. */ ?>
<title>-- Dokeos course update -- version <?php echo $dokeos_version; ?></title> <title>-- Dokeos course update -- version <?php echo $dokeos_version; ?></title>
<link rel="stylesheet" href="../css/chamilo/default.css" type="text/css"> <link rel="stylesheet" href="../css/chamilo/default.css" type="text/css">
</head> </head>
<body bgcolor="white" dir="<?php echo $text_dir ?>"> <body bgcolor="white" dir="<?php echo $text_dir; ?>">
<form method="post" action="<?php echo api_get_self(); ?>"> <form method="post" action="<?php echo api_get_self(); ?>">
<table cellpadding="6" cellspacing="0" border="0" width="650" bgcolor="#E6E6E6" align="center"> <table cellpadding="6" cellspacing="0" border="0" width="650" bgcolor="#E6E6E6" align="center">
@ -129,8 +124,8 @@ elseif($_POST['step1'])
============================================================================== ==============================================================================
*/ */
if($_POST['step2']) if ($_POST['step2']) {
{
include('update_db.inc.php'); include('update_db.inc.php');
include('update_files.inc.php'); include('update_files.inc.php');
?> ?>
@ -162,8 +157,7 @@ if($_POST['step2'])
============================================================================== ==============================================================================
*/ */
else else {
{
?> ?>
<h2>Step 1 of 2 &ndash; Configuration</h2> <h2>Step 1 of 2 &ndash; Configuration</h2>
@ -172,8 +166,7 @@ else
<strong>Notice:</strong> Please run this update script only if you've just updated (incompletely) Dokeos <?php echo implode('&nbsp;|&nbsp;',$update_from_version); ?> to Dokeos <?php echo $dokeos_version; ?>! <strong>Notice:</strong> Please run this update script only if you've just updated (incompletely) Dokeos <?php echo implode('&nbsp;|&nbsp;',$update_from_version); ?> to Dokeos <?php echo $dokeos_version; ?>!
<br /><br /> <br /><br />
<?php <?php
if($badUpdatePath) if ($badUpdatePath) {
{
?> ?>
<br /><br /> <br /><br />
<div style="background-color:white; color:red; text-align:center; font-weight:bold;"> <div style="background-color:white; color:red; text-align:center; font-weight:bold;">
@ -181,9 +174,7 @@ else
Dokeos <?php echo implode('|',$update_from_version); ?> has not been found in that directory. Dokeos <?php echo implode('|',$update_from_version); ?> has not been found in that directory.
</div> </div>
<?php <?php
} } else {
else
{
echo '<br />'; echo '<br />';
} }
?> ?>

@ -102,8 +102,7 @@ if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE'))
exit (); exit ();
} }
// The system has not been designed to use special SQL modes that were introduced since MySQL 5 @mysql_query("set session sql_mode='';"); // Disabling special SQL modes (MySQL 5)
@mysql_query("set session sql_mode='';");
/* /*
----------------------------------------------------------- -----------------------------------------------------------

@ -1,4 +1,7 @@
<?php <?php
// TODO: Ivan, 13-FEB-2010: Is this file really needed?
/* /*
============================================================================== ==============================================================================
Dokeos - elearning and course management software Dokeos - elearning and course management software
@ -76,60 +79,48 @@ function fill_document_table($dir)
$documentPath = $newPath.'courses/'.$course.'/document'; $documentPath = $newPath.'courses/'.$course.'/document';
if (!@ $opendir = opendir($dir)) if (!@ $opendir = opendir($dir)) {
{
return false; return false;
} }
while ($readdir = readdir($opendir)) while ($readdir = readdir($opendir)) {
{
if ($readdir != '..' && $readdir != '.' && $readdir != '.htaccess') if ($readdir != '..' && $readdir != '.' && $readdir != '.htaccess') {
{
$path = str_replace($documentPath, '', $dir.'/'.$readdir); $path = str_replace($documentPath, '', $dir.'/'.$readdir);
$file_date = date("Y-m-d H:i:s", filemtime($dir.'/'.$readdir)); $file_date = date("Y-m-d H:i:s", filemtime($dir.'/'.$readdir));
if (is_file($dir.'/'.$readdir)) if (is_file($dir.'/'.$readdir)) {
{
$file_size = filesize($dir.'/'.$readdir); $file_size = filesize($dir.'/'.$readdir);
$result = mysql_query("SELECT id,visibility FROM `$mysql_base_course".$_configuration['db_glue']."document` WHERE path='".addslashes($path)."' LIMIT 0,1"); $result = mysql_query("SELECT id,visibility FROM `$mysql_base_course".$_configuration['db_glue']."document` WHERE path='".addslashes($path)."' LIMIT 0,1");
if (list ($id, $visibility) = mysql_fetch_row($result)) if (list ($id, $visibility) = mysql_fetch_row($result)) {
{
mysql_query("UPDATE `$mysql_base_course".$_configuration['db_glue']."document` SET filetype='file',title='".addslashes($readdir)."',size='$file_size' WHERE id='$id' AND path='".addslashes($path)."'"); mysql_query("UPDATE `$mysql_base_course".$_configuration['db_glue']."document` SET filetype='file',title='".addslashes($readdir)."',size='$file_size' WHERE id='$id' AND path='".addslashes($path)."'");
} } else {
else
{
mysql_query("INSERT INTO `$mysql_base_course".$_configuration['db_glue']."document`(path,filetype,title,size) VALUES('".addslashes($path)."','file','".addslashes($readdir)."','$file_size')"); mysql_query("INSERT INTO `$mysql_base_course".$_configuration['db_glue']."document`(path,filetype,title,size) VALUES('".addslashes($path)."','file','".addslashes($readdir)."','$file_size')");
$id = mysql_insert_id(); $id = mysql_insert_id();
} }
$visibility = ($visibility == 'v') ? 1 : 0; $visibility = ($visibility == 'v') ? 1 : 0;
mysql_query("INSERT INTO `$mysql_base_course".$_configuration['db_glue']."item_property`(tool,ref,visibility,lastedit_type,to_group_id,insert_date,lastedit_date) VALUES('document','$id','$visibility','DocumentAdded','0','".$file_date."','".$file_date."')"); mysql_query("INSERT INTO `$mysql_base_course".$_configuration['db_glue']."item_property`(tool,ref,visibility,lastedit_type,to_group_id,insert_date,lastedit_date) VALUES('document','$id','$visibility','DocumentAdded','0','".$file_date."','".$file_date."')");
}
elseif (is_dir($dir.'/'.$readdir)) } elseif (is_dir($dir.'/'.$readdir)) {
{
$result = mysql_query("SELECT id,visibility FROM `$mysql_base_course".$_configuration['db_glue']."document` WHERE path='".addslashes($path)."' LIMIT 0,1"); $result = mysql_query("SELECT id,visibility FROM `$mysql_base_course".$_configuration['db_glue']."document` WHERE path='".addslashes($path)."' LIMIT 0,1");
if (list ($id, $visibility) = mysql_fetch_row($result)) if (list ($id, $visibility) = mysql_fetch_row($result)) {
{
mysql_query("UPDATE `$mysql_base_course".$_configuration['db_glue']."document` SET filetype='folder',title='".addslashes($readdir)."' WHERE id='$id' AND path='".addslashes($path)."'"); mysql_query("UPDATE `$mysql_base_course".$_configuration['db_glue']."document` SET filetype='folder',title='".addslashes($readdir)."' WHERE id='$id' AND path='".addslashes($path)."'");
} } else {
else
{
mysql_query("INSERT INTO `$mysql_base_course".$_configuration['db_glue']."document`(path,filetype,title) VALUES('".addslashes($path)."','folder','".addslashes($readdir)."')"); mysql_query("INSERT INTO `$mysql_base_course".$_configuration['db_glue']."document`(path,filetype,title) VALUES('".addslashes($path)."','folder','".addslashes($readdir)."')");
$id = mysql_insert_id(); $id = mysql_insert_id();
} }
$visibility = ($visibility == 'v') ? 1 : 0; $visibility = ($visibility == 'v') ? 1 : 0;
mysql_query("INSERT INTO `$mysql_base_course".$_configuration['db_glue']."item_property`(tool,ref,visibility, lastedit_type, to_group_id,insert_date,lastedit_date) VALUES('document','$id','$visibility','FolderCreated','0','".$file_date."','".$file_date."')"); mysql_query("INSERT INTO `$mysql_base_course".$_configuration['db_glue']."item_property`(tool,ref,visibility, lastedit_type, to_group_id,insert_date,lastedit_date) VALUES('document','$id','$visibility','FolderCreated','0','".$file_date."','".$file_date."')");
if (!fill_document_table($dir.'/'.$readdir)) if (!fill_document_table($dir.'/'.$readdir)) {
{
return false; return false;
} }
} }
@ -147,33 +138,26 @@ function fill_document_table($dir)
============================================================================== ==============================================================================
*/ */
if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE')) if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE')) {
{
$newPath = str_replace('\\', '/', realpath('../..')).'/'; $newPath = str_replace('\\', '/', realpath('../..')).'/';
$oldPath = $_POST['updatePath']; $oldPath = $_POST['updatePath'];
$perm = api_get_setting('permissions_for_new_directories'); $perm = api_get_setting('permissions_for_new_directories');
$perm = octdec(!empty($perm)?$perm:'0770'); $perm = octdec(!empty($perm) ? $perm : '0770');
foreach ($coursePath as $key => $course) foreach ($coursePath as $key => $course) {
{
$mysql_base_course = $courseDB[$key]; $mysql_base_course = $courseDB[$key];
@ unlink($oldPath.$course.'/document/.htaccess'); @ unlink($oldPath.$course.'/document/.htaccess');
@ unlink($oldPath.$course.'/group/index.php'); @ unlink($oldPath.$course.'/group/index.php');
if ($fp = @ fopen($oldPath.$course.'/group/index.php', 'w')) if ($fp = @ fopen($oldPath.$course.'/group/index.php', 'w')) {
{
fputs($fp, '<html></html>'); fputs($fp, '<html></html>');
fclose($fp); fclose($fp);
} }
@ unlink($oldPath.$course.'/index.php'); @ unlink($oldPath.$course.'/index.php');
if ($fp = @ fopen($oldPath.$course.'/index.php', 'w')) if ($fp = @ fopen($oldPath.$course.'/index.php', 'w')) {
{
fputs($fp, '<?php fputs($fp, '<?php
$cidReq = "'.$key.'"; $cidReq = "'.$key.'";
$dbname = "'.str_replace($dbPrefixForm, '', $mysql_base_course).'"; $dbname = "'.str_replace($dbPrefixForm, '', $mysql_base_course).'";
@ -186,25 +170,19 @@ if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE'))
@ mkdir($oldPath.$course.'/temp', $perm); @ mkdir($oldPath.$course.'/temp', $perm);
@ chmod($oldPath.$course.'/temp', $perm); @ chmod($oldPath.$course.'/temp', $perm);
@ rename($oldPath.$course, $newPath.'courses/'.$course); @ rename($oldPath.$course, $newPath.'courses/'.$course);
// Move group documents to document folder of the course // Move group documents to document folder of the course
$group_dir = $newPath.'courses/'.$course.'/group'; $group_dir = $newPath.'courses/'.$course.'/group';
if ($dir = @ opendir($group_dir)) if ($dir = @ opendir($group_dir)) {
{ while (($entry = readdir($dir)) !== false) {
while (($entry = readdir($dir)) !== false) if ($entry != '.' && $entry != '..' && is_dir($group_dir.'/'.$entry)) {
{
if ($entry != '.' && $entry != '..' && is_dir($group_dir.'/'.$entry))
{
$from_dir = $group_dir.'/'.$entry; $from_dir = $group_dir.'/'.$entry;
$to_dir = $newPath.'courses/'.$course.'/document/'.$entry; $to_dir = $newPath.'courses/'.$course.'/document/'.$entry;
@ rename($from_dir, $to_dir); @ rename($from_dir, $to_dir);
} }
} }
closedir($dir); closedir($dir);
} }
@ -216,25 +194,28 @@ if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE'))
$sql = "SELECT d.id AS doc_id, g.id AS group_id FROM `$mysql_base_course".$_configuration['db_glue']."group_info` g,`$mysql_base_course".$_configuration['db_glue']."document` d WHERE path LIKE CONCAT(g.secret_directory,'%')"; $sql = "SELECT d.id AS doc_id, g.id AS group_id FROM `$mysql_base_course".$_configuration['db_glue']."group_info` g,`$mysql_base_course".$_configuration['db_glue']."document` d WHERE path LIKE CONCAT(g.secret_directory,'%')";
$res = mysql_query($sql); $res = mysql_query($sql);
while ($group_doc = mysql_fetch_object($res)) while ($group_doc = mysql_fetch_object($res)) {
{
$sql = "UPDATE `$mysql_base_course".$_configuration['db_glue']."item_property` SET to_group_id = '".$group_doc->group_id."', visibility = '1' WHERE ref = '".$group_doc->doc_id."' AND tool = '".TOOL_DOCUMENT."'"; $sql = "UPDATE `$mysql_base_course".$_configuration['db_glue']."item_property` SET to_group_id = '".$group_doc->group_id."', visibility = '1' WHERE ref = '".$group_doc->doc_id."' AND tool = '".TOOL_DOCUMENT."'";
mysql_query($sql); mysql_query($sql);
} }
} }
if (defined('DOKEOS_INSTALL')) if (defined('DOKEOS_INSTALL')) {
{
// Write the Dokeos config file // Write the Dokeos config file
write_dokeos_config_file($newPath.'main/inc/conf/configuration.php'); write_dokeos_config_file($newPath.'main/inc/conf/configuration.php');
// Write a distribution file with the config as a backup for the admin // Write a distribution file with the config as a backup for the admin
write_dokeos_config_file($newPath.'main/inc/conf/configuration.dist.php'); write_dokeos_config_file($newPath.'main/inc/conf/configuration.dist.php');
// Write a .htaccess file in the course repository // Write a .htaccess file in the course repository
write_courses_htaccess_file($urlAppendPath); write_courses_htaccess_file($urlAppendPath);
require_once ('../inc/lib/fileManage.lib.php'); require_once ('../inc/lib/fileManage.lib.php');
// First remove the upload/users directory in the new installation // First remove the upload/users directory in the new installation
removeDir($newPath.'main/upload/users'); removeDir($newPath.'main/upload/users');
// Move the old user images to the new installation // Move the old user images to the new installation
@ rename($oldPath.'main/img/users', $newPath.'main/upload/users'); @ rename($oldPath.'main/img/users', $newPath.'main/upload/users');
@ -243,9 +224,6 @@ if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE'))
unlink($oldPath.'main/inc/conf/configuration.php'); unlink($oldPath.'main/inc/conf/configuration.php');
} }
} }
} } else {
else
{
echo 'You are not allowed here !'; echo 'You are not allowed here !';
} }
?>

@ -1,4 +1,7 @@
<?php // $Id: upgrade.php 22577 2009-08-03 04:31:24Z yannoo $ <?php // $Id: upgrade.php 22577 2009-08-03 04:31:24Z yannoo $
// TODO: Ivan, 13-FEB-2010: Is this file needed? It looks like unfinished business.
/* For licensing terms, see /dokeos_license.txt */ /* For licensing terms, see /dokeos_license.txt */
/** /**
============================================================================== ==============================================================================
@ -43,43 +46,43 @@
*/ */
session_start(); session_start();
ini_set('include_path',ini_get('include_path').PATH_SEPARATOR.'../inc/lib/pear'); // TODO: It is not a good idea to refer to external PEAR packages due to version/customizations related problems.
ini_set('include_path', ini_get('include_path').PATH_SEPARATOR.'../inc/lib/pear');
//echo ini_get('include_path'); //DEBUG //echo ini_get('include_path'); //DEBUG
require_once 'HTML/QuickForm/Controller.php'; require_once 'HTML/QuickForm/Controller.php';
require_once 'HTML/QuickForm/Rule.php'; require_once 'HTML/QuickForm/Rule.php';
require_once 'HTML/QuickForm/Action/Display.php'; require_once 'HTML/QuickForm/Action/Display.php';
//
require('../inc/installedVersion.inc.php'); require '../inc/installedVersion.inc.php';
require('../inc/lib/main_api.lib.php'); require '../inc/lib/main_api.lib.php';
require('../lang/english/trad4all.inc.php'); require '../lang/english/trad4all.inc.php';
require('../lang/english/install.inc.php'); require '../lang/english/install.inc.php';
require_once('install_upgrade.lib.php'); require_once 'install_upgrade.lib.php';
require_once('upgrade_lib.php'); require_once 'upgrade_lib.php';
define('DOKEOS_INSTALL',1); define('DOKEOS_INSTALL', 1);
define('MAX_COURSE_TRANSFER',100); define('MAX_COURSE_TRANSFER', 100);
define('INSTALL_TYPE_UPDATE', 'update'); define('INSTALL_TYPE_UPDATE', 'update');
define('FORM_FIELD_DISPLAY_LENGTH', 40); define('FORM_FIELD_DISPLAY_LENGTH', 40);
define('DATABASE_FORM_FIELD_DISPLAY_LENGTH', 25); define('DATABASE_FORM_FIELD_DISPLAY_LENGTH', 25);
define('MAX_FORM_FIELD_LENGTH', 50); define('MAX_FORM_FIELD_LENGTH', 50);
define('DEFAULT_LANGUAGE', 'english'); define('DEFAULT_LANGUAGE', 'english'); //TODO: What is the purpose of this constant?
//error_reporting(E_COMPILE_ERROR | E_ERROR | E_CORE_ERROR); //error_reporting(E_COMPILE_ERROR | E_ERROR | E_CORE_ERROR);
error_reporting(E_ALL); error_reporting(E_ALL);
@set_time_limit(0); @set_time_limit(0);
if(function_exists('ini_set')) if (function_exists('ini_set')) {
{ ini_set('memory_limit', -1);
ini_set('memory_limit',-1); ini_set('max_execution_time', 0);
ini_set('max_execution_time',0);
} }
$update_from_version=array('1.6','1.6.1','1.6.2','1.6.3','1.6.4','1.6.5','1.8.0','1.8.1','1.8.2'); $update_from_version = array('1.6', '1.6.1', '1.6.2', '1.6.3', '1.6.4', '1.6.5', '1.8.0', '1.8.1', '1.8.2');
$update_from_16_version = array('1.6','1.6.1','1.6.2','1.6.3','1.6.4','1.6.5'); $update_from_16_version = array('1.6', '1.6.1', '1.6.2', '1.6.3', '1.6.4', '1.6.5');
$update_from_18_version = array('1.8.0','1.8.1','1.8.2'); $update_from_18_version = array('1.8.0', '1.8.1', '1.8.2'); // TODO: ...
/* /*
============================================================================== ==============================================================================
@ -91,18 +94,17 @@ $update_from_18_version = array('1.8.0','1.8.1','1.8.2');
* Page in the install wizard to select the language which will be used during * Page in the install wizard to select the language which will be used during
* the installation process. * the installation process.
*/ */
class Page_Language extends HTML_QuickForm_Page class Page_Language extends HTML_QuickForm_Page {
{
function get_title() function get_title() {
{
return get_lang('WelcomeToDokeosInstaller'); return get_lang('WelcomeToDokeosInstaller');
} }
function get_info()
{ function get_info() {
return 'Please select the language you\'d like to use while installing:'; return 'Please select the language you\'d like to use while installing:';
} }
function buildForm()
{ function buildForm() {
$this->_formBuilt = true; $this->_formBuilt = true;
$this->addElement('select', 'install_language', get_lang('InstallationLanguage'), get_language_folder_list()); $this->addElement('select', 'install_language', get_lang('InstallationLanguage'), get_language_folder_list());
$buttons[0] = & HTML_QuickForm :: createElement('submit', $this->getButtonName('next'), get_lang('Next').' >>'); $buttons[0] = & HTML_QuickForm :: createElement('submit', $this->getButtonName('next'), get_lang('Next').' >>');
@ -117,64 +119,54 @@ class Page_Language extends HTML_QuickForm_Page
* - necessary and optional extensions * - necessary and optional extensions
* - folders which have to be writable * - folders which have to be writable
*/ */
class Page_Requirements extends HTML_QuickForm_Page class Page_Requirements extends HTML_QuickForm_Page {
{
/** /**
* this function checks if a php extension exists or not * this function checks if a php extension exists or not
* *
* @param string $extentionName name of the php extension to be checked * @param string $extentionName name of the php extension to be checked
* @param boolean $echoWhenOk true => show ok when the extension exists * @param boolean $echoWhenOk true => show ok when the extension exists
* @author Christophe Gesché * @author Christophe Gesché
*/ */
function check_extension($extentionName) function check_extension($extentionName) {
{ if (extension_loaded($extentionName)) {
if (extension_loaded($extentionName))
{
return '<li>'.$extentionName.' - ok</li>'; return '<li>'.$extentionName.' - ok</li>';
} } else {
else
{
return '<li><strong>'.$extentionName.'</strong> <font color="red">is missing (Dokeos can work without)</font> (<a href="http://www.php.net/'.$extentionName.'" target="_blank">'.$extentionName.'</a>)</li>'; return '<li><strong>'.$extentionName.'</strong> <font color="red">is missing (Dokeos can work without)</font> (<a href="http://www.php.net/'.$extentionName.'" target="_blank">'.$extentionName.'</a>)</li>';
} }
} }
function get_not_writable_folders()
{ function get_not_writable_folders() {
$writable_folders = array ('../inc/conf', '../upload', '../../archive', '../../courses', '../../home'); $writable_folders = array('../inc/conf', '../upload', '../../archive', '../../courses', '../../home');
$not_writable = array (); $not_writable = array();
$perm = api_get_setting('permissions_for_new_directories'); $perm = api_get_setting('permissions_for_new_directories');
$perm = octdec(!empty($perm)?$perm:'0770'); $perm = octdec(!empty($perm) ? $perm : '0770');
foreach ($writable_folders as $index => $folder) foreach ($writable_folders as $index => $folder) {
{ if (!is_writable($folder) && !@ chmod($folder, $perm)) {
if (!is_writable($folder) && !@ chmod($folder, $perm))
{
$not_writable[] = $folder; $not_writable[] = $folder;
} }
} }
return $not_writable; return $not_writable;
} }
function get_title()
{ function get_title() {
return get_lang("Requirements"); return get_lang("Requirements");
} }
function get_info()
{ function get_info() {
$not_writable = $this->get_not_writable_folders(); $not_writable = $this->get_not_writable_folders();
if (count($not_writable) > 0) if (count($not_writable) > 0) {
{
$info[] = '<div style="margin:20px;padding:10px;width: 50%;color:#FF6600;border:2px solid #FF6600;">'; $info[] = '<div style="margin:20px;padding:10px;width: 50%;color:#FF6600;border:2px solid #FF6600;">';
$info[] = 'Some files or folders don\'t have writing permission. To be able to install Dokeos you should first change their permissions (using CHMOD). Please read the <a href="../../installation_guide.html" target="blank">installation guide</a>.'; $info[] = 'Some files or folders don\'t have writing permission. To be able to install Dokeos you should first change their permissions (using CHMOD). Please read the <a href="../../installation_guide.html" target="blank">installation guide</a>.';
$info[] = '<ul>'; $info[] = '<ul>';
foreach ($not_writable as $index => $folder) foreach ($not_writable as $index => $folder) {
{
$info[] = '<li>'.$folder.'</li>'; $info[] = '<li>'.$folder.'</li>';
} }
$info[] = '</ul>'; $info[] = '</ul>';
$info[] = '</div>'; $info[] = '</div>';
$this->disableNext = true; $this->disableNext = true;
} } elseif (file_exists('../inc/conf/claro_main.conf.php')) {
elseif (file_exists('../inc/conf/claro_main.conf.php'))
{
$info[] = '<div style="margin:20px;padding:10px;width: 50%;color:#FF6600;border:2px solid #FF6600;text-align:center;">'; $info[] = '<div style="margin:20px;padding:10px;width: 50%;color:#FF6600;border:2px solid #FF6600;text-align:center;">';
$info[] = get_lang("WarningExistingDokeosInstallationDetected"); $info[] = get_lang("WarningExistingDokeosInstallationDetected");
$info[] = '</div>'; $info[] = '</div>';
@ -197,8 +189,8 @@ class Page_Requirements extends HTML_QuickForm_Page
$info[] = get_lang('MoreDetails').", <a href=\"../../installation_guide.html\" target=\"blank\">read the installation guide</a>."; $info[] = get_lang('MoreDetails').", <a href=\"../../installation_guide.html\" target=\"blank\">read the installation guide</a>.";
return implode("\n",$info); return implode("\n",$info);
} }
function buildForm()
{ function buildForm() {
global $updateFromVersion; global $updateFromVersion;
$this->_formBuilt = true; $this->_formBuilt = true;
$this->addElement('radio', 'installation_type', get_lang('InstallType'), get_lang('NewInstall'), 'new'); $this->addElement('radio', 'installation_type', get_lang('InstallType'), get_lang('NewInstall'), 'new');
@ -207,8 +199,7 @@ class Page_Requirements extends HTML_QuickForm_Page
$prevnext[] = & $this->createElement('submit', $this->getButtonName('back'), '<< '.get_lang('Previous')); $prevnext[] = & $this->createElement('submit', $this->getButtonName('back'), '<< '.get_lang('Previous'));
$prevnext[] = & $this->createElement('submit', $this->getButtonName('next'), get_lang('Next').' >>'); $prevnext[] = & $this->createElement('submit', $this->getButtonName('next'), get_lang('Next').' >>');
$not_writable = $this->get_not_writable_folders(); $not_writable = $this->get_not_writable_folders();
if (count($not_writable) > 0) if (count($not_writable) > 0) {
{
$el = $prevnext[1]; $el = $prevnext[1];
$el->updateAttributes('disabled="disabled"'); $el->updateAttributes('disabled="disabled"');
} }
@ -220,18 +211,17 @@ class Page_Requirements extends HTML_QuickForm_Page
/** /**
* Page in the install wizard to select the location of the old Dokeos installation. * Page in the install wizard to select the location of the old Dokeos installation.
*/ */
class Page_LocationOldVersion extends HTML_QuickForm_Page class Page_LocationOldVersion extends HTML_QuickForm_Page {
{
function get_title() function get_title() {
{
return 'Old version root path'; return 'Old version root path';
} }
function get_info()
{ function get_info() {
return 'Give location of your old Dokeos installation '; return 'Give location of your old Dokeos installation ';
} }
function buildForm()
{ function buildForm() {
$this->_formBuilt = true; $this->_formBuilt = true;
$this->addElement('text', 'old_version_path', 'Old version root path'); $this->addElement('text', 'old_version_path', 'Old version root path');
$this->applyFilter('old_version_path', 'trim'); $this->applyFilter('old_version_path', 'trim');
@ -248,18 +238,16 @@ class Page_LocationOldVersion extends HTML_QuickForm_Page
* Class for license page * Class for license page
* Displays the GNU GPL license that has to be accepted to install Dokeos. * Displays the GNU GPL license that has to be accepted to install Dokeos.
*/ */
class Page_License extends HTML_QuickForm_Page class Page_License extends HTML_QuickForm_Page {
{ function get_title() {
function get_title()
{
return get_lang('Licence'); return get_lang('Licence');
} }
function get_info()
{ function get_info() {
return get_lang('DokeosLicenseInfo'); return get_lang('DokeosLicenseInfo');
} }
function buildForm()
{ function buildForm() {
$this->_formBuilt = true; $this->_formBuilt = true;
$this->addElement('textarea', 'license', get_lang('Licence'), array ('cols' => 80, 'rows' => 20, 'disabled' => 'disabled', 'style'=>'background-color: white;')); $this->addElement('textarea', 'license', get_lang('Licence'), array ('cols' => 80, 'rows' => 20, 'disabled' => 'disabled', 'style'=>'background-color: white;'));
$this->addElement('checkbox','license_accept','',get_lang('IAccept')); $this->addElement('checkbox','license_accept','',get_lang('IAccept'));
@ -277,18 +265,17 @@ class Page_License extends HTML_QuickForm_Page
* regarding the databases - login and password, names, prefixes, single * regarding the databases - login and password, names, prefixes, single
* or multiple databases, tracking or not... * or multiple databases, tracking or not...
*/ */
class Page_DatabaseSettings extends HTML_QuickForm_Page class Page_DatabaseSettings extends HTML_QuickForm_Page {
{
function get_title() function get_title() {
{
return get_lang('DBSetting'); return get_lang('DBSetting');
} }
function get_info()
{ function get_info() {
return get_lang('DBSettingIntro'); return get_lang('DBSettingIntro');
} }
function buildForm()
{ function buildForm() {
$this->_formBuilt = true; $this->_formBuilt = true;
$this->addElement('text', 'database_host', get_lang("DBHost"), array ('size' => '40')); $this->addElement('text', 'database_host', get_lang("DBHost"), array ('size' => '40'));
$this->addRule('database_host', 'ThisFieldIsRequired', 'required'); $this->addRule('database_host', 'ThisFieldIsRequired', 'required');
@ -318,8 +305,8 @@ class Page_DatabaseSettings extends HTML_QuickForm_Page
$enable_tracking[] = & $this->createElement('radio', 'enable_tracking', null, get_lang("Yes"), 1); $enable_tracking[] = & $this->createElement('radio', 'enable_tracking', null, get_lang("Yes"), 1);
$enable_tracking[] = & $this->createElement('radio', 'enable_tracking', null, get_lang("No"), 0); $enable_tracking[] = & $this->createElement('radio', 'enable_tracking', null, get_lang("No"), 0);
$this->addGroup($enable_tracking, 'tracking', get_lang("EnableTracking"), '&nbsp;', false); $this->addGroup($enable_tracking, 'tracking', get_lang("EnableTracking"), '&nbsp;', false);
$several_db[] = & $this->createElement('radio', 'database_single', null, get_lang("One"),1); $several_db[] = & $this->createElement('radio', 'database_single', null, get_lang("One"), 1);
$several_db[] = & $this->createElement('radio', 'database_single', null, get_lang("Several"),0); $several_db[] = & $this->createElement('radio', 'database_single', null, get_lang("Several"), 0);
$this->addGroup($several_db, 'db', get_lang("SingleDb"), '&nbsp;', false); $this->addGroup($several_db, 'db', get_lang("SingleDb"), '&nbsp;', false);
$prevnext[] = & $this->createElement('submit', $this->getButtonName('back'), '<< '.get_lang('Previous')); $prevnext[] = & $this->createElement('submit', $this->getButtonName('back'), '<< '.get_lang('Previous'));
$prevnext[] = & $this->createElement('submit', $this->getButtonName('next'), get_lang('Next').' >>'); $prevnext[] = & $this->createElement('submit', $this->getButtonName('next'), get_lang('Next').' >>');
@ -327,15 +314,14 @@ class Page_DatabaseSettings extends HTML_QuickForm_Page
$this->setDefaultAction('next'); $this->setDefaultAction('next');
} }
} }
class ValidateDatabaseConnection extends HTML_QuickForm_Rule
{ class ValidateDatabaseConnection extends HTML_QuickForm_Rule {
public function validate($parameters)
{ public function validate($parameters) {
$db_host = $parameters[0]; $db_host = $parameters[0];
$db_user = $parameters[1]; $db_user = $parameters[1];
$db_password = $parameters[2]; $db_password = $parameters[2];
if(mysql_connect($db_host,$db_user,$db_password)) if (mysql_connect($db_host, $db_user, $db_password)) {
{
return true; return true;
} }
return false; return false;
@ -346,18 +332,17 @@ class ValidateDatabaseConnection extends HTML_QuickForm_Rule
* Page in the install wizard in which some config settings are asked to the * Page in the install wizard in which some config settings are asked to the
* user. * user.
*/ */
class Page_ConfigSettings extends HTML_QuickForm_Page class Page_ConfigSettings extends HTML_QuickForm_Page {
{
function get_title() function get_title() {
{
return get_lang('CfgSetting'); return get_lang('CfgSetting');
} }
function get_info()
{ function get_info() {
return get_lang('ConfigSettingsInfo'); return get_lang('ConfigSettingsInfo');
} }
function buildForm()
{ function buildForm() {
$this->_formBuilt = true; $this->_formBuilt = true;
$languages = array (); $languages = array ();
$languages['dutch'] = 'dutch'; $languages['dutch'] = 'dutch';
@ -402,21 +387,19 @@ class Page_ConfigSettings extends HTML_QuickForm_Page
* Page in the install wizard in which a final overview of all settings is * Page in the install wizard in which a final overview of all settings is
* displayed. * displayed.
*/ */
class Page_ConfirmSettings extends HTML_QuickForm_Page class Page_ConfirmSettings extends HTML_QuickForm_Page {
{
function get_title() function get_title() {
{
return get_lang('LastCheck'); return get_lang('LastCheck');
} }
function get_info()
{ function get_info() {
return 'Here are the values you entered return 'Here are the values you entered
<br /> <br />
<strong>Print this page to remember your password and other settings</strong>'; <strong>Print this page to remember your password and other settings</strong>';
} }
function buildForm()
{ function buildForm() {
$wizard = $this->controller; $wizard = $this->controller;
$values = $wizard->exportValues(); $values = $wizard->exportValues();
$this->addElement('static', 'confirm_platform_language', get_lang("MainLang"), $values['platform_language']); $this->addElement('static', 'confirm_platform_language', get_lang("MainLang"), $values['platform_language']);
@ -441,14 +424,13 @@ class Page_ConfirmSettings extends HTML_QuickForm_Page
/** /**
* Class to render a page in the install wizard. * Class to render a page in the install wizard.
*/ */
class ActionDisplay extends HTML_QuickForm_Action_Display class ActionDisplay extends HTML_QuickForm_Action_Display {
{
/** /**
* Displays the HTML-code of a page in the wizard * Displays the HTML-code of a page in the wizard
* @param HTML_Quickform_Page $page The page to display. * @param HTML_Quickform_Page $page The page to display.
*/ */
function _renderForm(& $current_page) function _renderForm(& $current_page) {
{
global $charset; global $charset;
global $dokeos_version, $installType, $updateFromVersion; global $dokeos_version, $installType, $updateFromVersion;
@ -481,16 +463,12 @@ class ActionDisplay extends HTML_QuickForm_Action_Display
$current_page_number = 0; $current_page_number = 0;
$page_number = 0; $page_number = 0;
echo '<ol>'; echo '<ol>';
foreach($all_pages as $index => $page) foreach($all_pages as $index => $page) {
{
$page_number++; $page_number++;
if($page->get_title() == $current_page->get_title()) if ($page->get_title() == $current_page->get_title()) {
{
$current_page_number = $page_number; $current_page_number = $page_number;
echo '<li style="font-weight: bold;">'.$page->get_title().'</li>'; echo '<li style="font-weight: bold;">'.$page->get_title().'</li>';
} } else {
else
{
echo '<li>'.$page->get_title().'</li>'; echo '<li>'.$page->get_title().'</li>';
} }
} }
@ -519,10 +497,10 @@ class ActionDisplay extends HTML_QuickForm_Action_Display
* Here happens the actual installation action after collecting * Here happens the actual installation action after collecting
* all the required data. * all the required data.
*/ */
class ActionProcess extends HTML_QuickForm_Action class ActionProcess extends HTML_QuickForm_Action {
{
function perform(& $page, $actionName) function perform(& $page, $actionName) {
{
global $charset; global $charset;
global $dokeos_version, $installType, $updateFromVersion; global $dokeos_version, $installType, $updateFromVersion;
@ -584,8 +562,7 @@ class ActionProcess extends HTML_QuickForm_Action
============================================================================== ==============================================================================
*/ */
function display_upgrade_header($text_dir, $dokeos_version, $install_type, $update_from_version) function display_upgrade_header($text_dir, $dokeos_version, $install_type, $update_from_version) {
{
?> ?>
<!DOCTYPE html <!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
@ -614,22 +591,20 @@ function display_upgrade_header($text_dir, $dokeos_version, $install_type, $upda
} }
/** /**
* Return a list of language directories. * TODO: Copy/paste again. Find an existing function for this job.
* @todo function does not belong here, move to code library, * Return a list of language directories.
* also see infocours.php which contains similar function * @todo function does not belong here, move to code library,
*/ * also see infocours.php which contains similar function
function get_language_folder_list() */
{ function get_language_folder_list() {
$dirname = dirname(__FILE__).'/../lang'; $dirname = dirname(__FILE__).'/../lang';
if ($dirname[strlen($dirname) - 1] != '/') if ($dirname[strlen($dirname) - 1] != '/')
$dirname .= '/'; $dirname .= '/';
$handle = opendir($dirname); $handle = opendir($dirname);
while ($entries = readdir($handle)) while ($entries = readdir($handle)) {
{
if ($entries == '.' || $entries == '..' || $entries == '.svn') if ($entries == '.' || $entries == '..' || $entries == '.svn')
continue; continue;
if (is_dir($dirname.$entries)) if (is_dir($dirname.$entries)) {
{
$language_list[$entries] = api_ucfirst($entries); $language_list[$entries] = api_ucfirst($entries);
} }
} }
@ -638,9 +613,7 @@ function get_language_folder_list()
return $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" />';
echo '<ol>'; echo '<ol>';
@ -659,39 +632,31 @@ function display_installation_overview()
* This function prints class=active_step $current_step=$param * This function prints class=active_step $current_step=$param
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
*/ */
function step_active($this_step) function step_active($this_step) {
{
global $current_active_step; global $current_active_step;
if ($current_active_step == $this_step) if ($current_active_step == $this_step) {
{
return ' class="current_step" '; return ' class="current_step" ';
} }
} }
// Rule to check update path // Rule to check update path
function check_update_path($path) function check_update_path($path) {
{
global $update_from_version; global $update_from_version;
// Make sure path has a trailing / // Make sure path has a trailing /
$path = substr($path,-1) != '/' ? $path.'/' : $path; $path = substr($path, -1) != '/' ? $path.'/' : $path;
// Check the path // Check the path
if (file_exists($path)) if (file_exists($path)) {
{
//search for 1.6.x installation //search for 1.6.x installation
$version = get_installed_version($path, 'platformVersion'); $version = get_installed_version($path, 'platformVersion');
//search for 1.8.x installation //search for 1.8.x installation
//if (! isset($version) || $version == '') //if (! isset($version) || $version == '') {
//{
// $version = get_installed_version($path, 'dokeos_version'); // $version = get_installed_version($path, 'dokeos_version');
//} //}
if (in_array($version, $update_from_version)) if (in_array($version, $update_from_version)) {
{
return true; return true;
} } else {
else
{
return false; return false;
} }
} }
@ -703,16 +668,13 @@ function check_update_path($path)
* the older installation to upgrade by checking the * the older installation to upgrade by checking the
* claroline/inc/installedVersion.inc.php file. * claroline/inc/installedVersion.inc.php file.
*/ */
function get_installed_version($old_installation_path, $parameter) function get_installed_version($old_installation_path, $parameter) {
{ if (file_exists($old_installation_path.'claroline/inc/installedVersion.inc.php')) {
if( file_exists($old_installation_path.'claroline/inc/installedVersion.inc.php') )
{
$version_info_file = 'claroline/inc/installedVersion.inc.php'; $version_info_file = 'claroline/inc/installedVersion.inc.php';
} }
// with include_once inside a function, variables aren't remembered for later use // with include_once inside a function, variables aren't remembered for later use
include($old_installation_path.$version_info_file); include($old_installation_path.$version_info_file);
if (isset($$parameter)) if (isset($$parameter)) {
{
return $$parameter; return $$parameter;
} }
} }
@ -734,77 +696,56 @@ function get_installed_version($old_installation_path, $parameter)
* @return string the value of the parameter * @return string the value of the parameter
* @author Olivier Brouckaert * @author Olivier Brouckaert
*/ */
function get_config_param($param,$path) function get_config_param($param, $path) {
{
global $configFile, $updateFromConfigFile; global $configFile, $updateFromConfigFile;
if (empty ($updateFromConfigFile)) if (empty($updateFromConfigFile)) {
{ if (file_exists($path.'claroline/include/config.inc.php')) {
if (file_exists($path.'claroline/include/config.inc.php'))
{
$updateFromConfigFile = 'claroline/include/config.inc.php'; $updateFromConfigFile = 'claroline/include/config.inc.php';
} } elseif (file_exists($path.'claroline/inc/conf/claro_main.conf.php')) {
elseif (file_exists($path.'claroline/inc/conf/claro_main.conf.php'))
{
$updateFromConfigFile = 'claroline/inc/conf/claro_main.conf.php'; $updateFromConfigFile = 'claroline/inc/conf/claro_main.conf.php';
} } else {
else
{
return; return;
} }
} }
//echo "reading from file $path$updateFromConfigFile, which exists..."; //echo "reading from file $path$updateFromConfigFile, which exists...";
if (is_array($configFile) && isset ($configFile[$param])) if (is_array($configFile) && isset($configFile[$param])) {
{
return $configFile[$param]; return $configFile[$param];
} } elseif (file_exists($path.$updateFromConfigFile)) {
elseif (file_exists($path.$updateFromConfigFile)) $configFile = array();
{
$configFile = array ();
$temp = file($path.$updateFromConfigFile); $temp = file($path.$updateFromConfigFile);
$val = ''; $val = '';
foreach ($temp as $enreg) {
foreach ($temp as $enreg) if (strstr($enreg, '=')) {
{
if (strstr($enreg, '='))
{
$enreg = explode('=', $enreg); $enreg = explode('=', $enreg);
if ($enreg[0][0] == '$') if ($enreg[0][0] == '$') {
{
list ($enreg[1]) = explode(' //', $enreg[1]); list ($enreg[1]) = explode(' //', $enreg[1]);
$enreg[0] = trim(str_replace('$', '', $enreg[0])); $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('(^"|"$)', '', substr(trim($enreg[1]), 0, -1)));
if (strtolower($enreg[1]) == 'true') if (strtolower($enreg[1]) == 'true') {
{
$enreg[1] = 1; $enreg[1] = 1;
} }
if (strtolower($enreg[1]) == 'false') if (strtolower($enreg[1]) == 'false') {
{
$enreg[1] = 0; $enreg[1] = 0;
} } else {
else
{
$implode_string = ' '; $implode_string = ' ';
if (!strstr($enreg[1], '." ".') && strstr($enreg[1], '.$')) if (!strstr($enreg[1], '." ".') && strstr($enreg[1], '.$')) {
{
$enreg[1] = str_replace('.$', '." ".$', $enreg[1]); $enreg[1] = str_replace('.$', '." ".$', $enreg[1]);
$implode_string = ''; $implode_string = '';
} }
$tmp = explode('." ".', $enreg[1]); $tmp = explode('." ".', $enreg[1]);
foreach ($tmp as $tmp_key => $tmp_val) foreach ($tmp as $tmp_key => $tmp_val) {
{ if (eregi('^\$[a-z_][a-z0-9_]*$', $tmp_val)) {
if (eregi('^\$[a-z_][a-z0-9_]*$', $tmp_val))
{
$tmp[$tmp_key] = get_config_param(str_replace('$', '', $tmp_val), $path); $tmp[$tmp_key] = get_config_param(str_replace('$', '', $tmp_val), $path);
} }
} }
@ -814,8 +755,7 @@ function get_config_param($param,$path)
$configFile[$enreg[0]] = $enreg[1]; $configFile[$enreg[0]] = $enreg[1];
if ($enreg[0] == $param) if ($enreg[0] == $param) {
{
$val = $enreg[1]; $val = $enreg[1];
} }
} }
@ -845,8 +785,8 @@ $wizard = & new HTML_QuickForm_Controller('regWizard', true);
//$wizard->addPage(new Page_Requirements('page_requirements')); //$wizard->addPage(new Page_Requirements('page_requirements'));
$wizard->addPage(new Page_LocationOldVersion('page_location_old_version')); $wizard->addPage(new Page_LocationOldVersion('page_location_old_version'));
$values = $wizard->exportValues(); $values = $wizard->exportValues();
if( isset($values['old_version_path']) && $values['old_version_path'] != '/var/www/html/old_version/' )
{ if (isset($values['old_version_path']) && $values['old_version_path'] != '/var/www/html/old_version/') {
$path = $values['old_version_path']; $path = $values['old_version_path'];
$defaults['platform_language'] = get_config_param('platformLanguage',$path); $defaults['platform_language'] = get_config_param('platformLanguage',$path);
$defaults['platform_url'] = 'http://'.$_SERVER['HTTP_HOST'].$urlAppendPath.'/'; $defaults['platform_url'] = 'http://'.$_SERVER['HTTP_HOST'].$urlAppendPath.'/';
@ -883,9 +823,7 @@ if( isset($values['old_version_path']) && $values['old_version_path'] != '/var/w
} }
//$defaults['encrypt_password'] = get_config_param('userPasswordCrypted',$path); //$defaults['encrypt_password'] = get_config_param('userPasswordCrypted',$path);
$defaults['self_reg'] = get_config_param('allowSelfReg',$path); $defaults['self_reg'] = get_config_param('allowSelfReg',$path);
} } else {
else
{
//old version path not correct yet //old version path not correct yet
} }
@ -909,10 +847,10 @@ $wizard->addAction('display', new ActionDisplay());
// Set the installation language // Set the installation language
$install_language = $wizard->exportValue('page_language', 'install_language'); $install_language = $wizard->exportValue('page_language', 'install_language');
require_once ('../lang/english/trad4all.inc.php'); require_once '../lang/english/trad4all.inc.php';
require_once ('../lang/english/install.inc.php'); require_once '../lang/english/install.inc.php';
include_once ("../lang/$install_language/trad4all.inc.php"); include_once '../lang/'.$install_language.'/trad4all.inc.php';
include_once ("../lang/$install_language/install.inc.php"); include_once '../lang/'.$install_language.'/install.inc.php';
// Set default platform language to the selected install language // Set default platform language to the selected install language
$defaults['platform_language'] = $install_language; $defaults['platform_language'] = $install_language;
@ -923,11 +861,9 @@ $wizard->run();
// Set the installation language // Set the installation language
$install_language = $wizard->exportValue('page_language', 'install_language'); $install_language = $wizard->exportValue('page_language', 'install_language');
require_once ('../lang/english/trad4all.inc.php'); require_once '../lang/english/trad4all.inc.php';
require_once ('../lang/english/install.inc.php'); require_once '../lang/english/install.inc.php';
include_once ("../lang/$install_language/trad4all.inc.php"); include_once '../lang/'.$install_language.'/trad4all.inc.php');
include_once ("../lang/$install_language/install.inc.php"); include_once '../lang/'.$install_language.'/install.inc.php');
//$values = $wizard->exportValues(); //$values = $wizard->exportValues();
?>

@ -44,8 +44,8 @@
* - migrate-db-1.6.x-1.8.0-pre.sql * - migrate-db-1.6.x-1.8.0-pre.sql
* @todo remove code duplication in this function * @todo remove code duplication in this function
*/ */
function upgrade_16x_to_180($values) function upgrade_16x_to_180($values) {
{
$is_single_database = $values['database_single']; $is_single_database = $values['database_single'];
$main_database = $values['database_main_db']; $main_database = $values['database_main_db'];
$tracking_database = $values['database_tracking']; $tracking_database = $values['database_tracking'];
@ -58,36 +58,30 @@ function upgrade_16x_to_180($values)
//MAIN database section //MAIN database section
//Get the list of queries to upgrade the main database //Get the list of queries to upgrade the main database
$main_query_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-pre.sql','main'); $main_query_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-pre.sql', 'main');
if(count($main_query_list) > 0) if (count($main_query_list) > 0) {
{
mysql_select_db($main_database); mysql_select_db($main_database);
foreach($main_query_list as $this_query) foreach ($main_query_list as $this_query) {
{
mysql_query($this_query); mysql_query($this_query);
} }
} }
//TRACKING database section //TRACKING database section
//Get the list of queries to upgrade the statistics/tracking database //Get the list of queries to upgrade the statistics/tracking database
$tracking_query_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-pre.sql','stats'); $tracking_query_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-pre.sql', 'stats');
if(count($tracking_query_list) > 0) if (count($tracking_query_list) > 0) {
{
mysql_select_db($tracking_database); mysql_select_db($tracking_database);
foreach($tracking_query_list as $this_query) foreach ($tracking_query_list as $this_query) {
{
mysql_query($this_query); mysql_query($this_query);
} }
} }
//USER database section //USER database section
//Get the list of queries to upgrade the user database //Get the list of queries to upgrade the user database
$user_query_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-pre.sql','user'); $user_query_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-pre.sql', 'user');
if(count($user_query_list) > 0) if (count($user_query_list) > 0) {
{
mysql_select_db($user_database); mysql_select_db($user_database);
foreach($user_query_list as $this_query) foreach ($user_query_list as $this_query) {
{
mysql_query($this_query); mysql_query($this_query);
} }
} }
@ -98,14 +92,12 @@ function upgrade_16x_to_180($values)
*/ */
$prefix = ''; $prefix = '';
global $singleDbForm, $_configuration; global $singleDbForm, $_configuration;
if ($singleDbForm) if ($singleDbForm) {
{
$prefix = $_configuration['table_prefix']; $prefix = $_configuration['table_prefix'];
} }
//get the course databases queries list (c_q_list) //get the course databases queries list (c_q_list)
$course_query_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-pre.sql','course'); $course_query_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-pre.sql', 'course');
if(count($course_query_list) > 0) if (count($course_query_list) > 0) {
{
//upgrade course databases //upgrade course databases
} }
@ -119,65 +111,52 @@ function upgrade_16x_to_180($values)
POST SECTION POST SECTION
UPGRADES TO GENERAL DATABASES after course upgrades UPGRADES TO GENERAL DATABASES after course upgrades
*/ */
$main_query_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-post.sql','main'); $main_query_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-post.sql', 'main');
if(count($main_query_list) > 0) if (count($main_query_list) > 0) {
{
mysql_select_db($main_database); mysql_select_db($main_database);
foreach($main_query_list as $this_query) foreach ($main_query_list as $this_query) {
{
mysql_query($this_query); mysql_query($this_query);
} }
} }
$tracking_query_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-post.sql','stats'); $tracking_query_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-post.sql', 'stats');
$tracking_query_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-pre.sql','stats'); $tracking_query_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-pre.sql', 'stats');
if(count($tracking_query_list) > 0) if (count($tracking_query_list) > 0) {
{
mysql_select_db($tracking_database); mysql_select_db($tracking_database);
foreach($tracking_query_list as $this_query) foreach ($tracking_query_list as $this_query) {
{
mysql_query($this_query); mysql_query($this_query);
} }
} }
$user_query_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-post.sql','user'); $user_query_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-post.sql', 'user');
if(count($user_query_list) > 0) if (count($user_query_list) > 0) {
{
mysql_select_db($user_database); mysql_select_db($user_database);
foreach($user_query_list as $this_query) foreach ($user_query_list as $this_query) {
{
mysql_query($this_query); mysql_query($this_query);
} }
} }
$prefix = ''; $prefix = '';
if ($singleDbForm) if ($singleDbForm) {
{
$prefix = $_configuration['table_prefix']; $prefix = $_configuration['table_prefix'];
} }
//get the course databases queries list (c_q_list) //get the course databases queries list (c_q_list)
$course_query_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-pre.sql','course'); $course_query_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-pre.sql', 'course');
if(count($course_query_list) > 0) if (count($course_query_list) > 0) {
{
//upgrade course databases //upgrade course databases
mysql_select_db($main_database); mysql_select_db($main_database);
$sql_result = mysql_query("SELECT code,db_name,directory,course_language FROM course WHERE target_course_code IS NULL"); $sql_result = mysql_query("SELECT code,db_name,directory,course_language FROM course WHERE target_course_code IS NULL");
if(mysql_num_rows($sql_result) > 0) if (mysql_num_rows($sql_result) > 0) {
{ while ($row = mysql_fetch_array($sql_result)) {
while($row = mysql_fetch_array($sql_result))
{
$course_list[] = $row; $course_list[] = $row;
} }
//for each course in the course list... //for each course in the course list...
foreach($course_list as $this_course) foreach ($course_list as $this_course) {
{
mysql_select_db($this_course['db_name']); mysql_select_db($this_course['db_name']);
//... execute the list of course update queries //... execute the list of course update queries
foreach($course_query_list as $this_query) foreach ($course_query_list as $this_query) {
{ if ($is_single_database) { //otherwise just use the main one
if ($is_single_database) //otherwise just use the main one $query = preg_replace('/^(UPDATE|ALTER TABLE|CREATE TABLE|DROP TABLE|INSERT INTO|DELETE FROM)\s+(\w*)(.*)$/', "$1 $prefix$2$3", $query);
{
$query = preg_replace('/^(UPDATE|ALTER TABLE|CREATE TABLE|DROP TABLE|INSERT INTO|DELETE FROM)\s+(\w*)(.*)$/',"$1 $prefix$2$3",$query);
} }
mysql_query($this_query); mysql_query($this_query);
} }
@ -193,14 +172,10 @@ function upgrade_16x_to_180($values)
* - update-db-1.8.0-1.8.2.inc.php * - update-db-1.8.0-1.8.2.inc.php
* - migrate-db-1.8.0-1.8.2-pre.sql * - migrate-db-1.8.0-1.8.2-pre.sql
*/ */
function upgrade_180_to_182($values) function upgrade_180_to_182($values) {
{
} }
function upgrade_182_to_183($values) function upgrade_182_to_183($values) {
{
//no database/file structure changes needed? //no database/file structure changes needed?
} }
?>
Loading…
Cancel
Save