commit
10dac7be50
@ -1,2 +0,0 @@ |
|||||||
For installation help, see installation_guide.html or INSTALL.txt at the Chamilo root directory |
|
||||||
(which should be two directories up from this) |
|
||||||
@ -1,271 +0,0 @@ |
|||||||
<?php // $Id: compare_db.php 22577 2009-08-03 04:31:24Z yannoo $
|
|
||||||
/* For licensing terms, see /license.txt */ |
|
||||||
/** |
|
||||||
============================================================================== |
|
||||||
* This script allows you to know which tables have been modified |
|
||||||
* between two versions of Dokeos databases. |
|
||||||
* |
|
||||||
* @package chamilo.install |
|
||||||
============================================================================== |
|
||||||
*/ |
|
||||||
|
|
||||||
/** |
|
||||||
* Database configuration |
|
||||||
* INSTRUCTIONS |
|
||||||
* ============ |
|
||||||
* Change these parameters to compare between an old and a new database install. |
|
||||||
* You will need to create a course called 'COURSE' on each side to be able to compare the |
|
||||||
* courses databases. |
|
||||||
* If you have given fancy names to your databases, you will need to modify these names |
|
||||||
* in the two $bases_* variables definitions below. |
|
||||||
* 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). |
|
||||||
*/ |
|
||||||
$sql_server_new = 'localhost'; |
|
||||||
$sql_user_new = 'root'; |
|
||||||
$sql_pass_new = ''; |
|
||||||
$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'); |
|
||||||
|
|
||||||
$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); // Disabling special SQL modes (MySQL 5) |
|
||||||
|
|
||||||
$sql_server_old = 'localhost'; |
|
||||||
$sql_user_old = 'root'; |
|
||||||
$sql_pass_old = ''; |
|
||||||
$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'); |
|
||||||
|
|
||||||
$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); // Disabling special SQL modes (MySQL 5) |
|
||||||
|
|
||||||
$field_details = array(0 => 'Field', 1 => 'Type', 2 => 'Null', 3 => 'Key', 4 => 'Default', 5 => 'Extra'); |
|
||||||
|
|
||||||
/********************************/ |
|
||||||
|
|
||||||
$all_db_changes = array(); |
|
||||||
|
|
||||||
echo "<h1>Databases structure comparison script</h1>"; |
|
||||||
|
|
||||||
// Iterate through databases given above (checking from the 'new' database side) |
|
||||||
foreach ($bases_new as $num_base => $base) { |
|
||||||
|
|
||||||
//init tables lists for this database |
|
||||||
$modif_tables = array(); |
|
||||||
$tables_db_new = array(); |
|
||||||
$tables_db_old = array(); |
|
||||||
$dump = array(); |
|
||||||
|
|
||||||
// Display current processed database |
|
||||||
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 |
|
||||||
$query_new = "SHOW TABLES FROM ".$bases_new[$num_base]; |
|
||||||
$result_new = mysql_query($query_new, $db_new); |
|
||||||
|
|
||||||
if ($result_new) { //if there are tables in this database |
|
||||||
|
|
||||||
$i=0; |
|
||||||
|
|
||||||
//as there are tables, process them one by one |
|
||||||
while ($row_new = mysql_fetch_row($result_new)) { |
|
||||||
|
|
||||||
$dump[$i]['table_name'] = $row_new[0]; |
|
||||||
$dump[$i]['fields'] = array(); |
|
||||||
|
|
||||||
$query_old = "SHOW FIELDS FROM ".$bases_new[$num_base].".".$row_new[0]; |
|
||||||
$result_old = mysql_query($query_old,$db_old) or die(mysql_error()); |
|
||||||
|
|
||||||
$j=0; |
|
||||||
|
|
||||||
//get the fields details (numbered fields) |
|
||||||
while ($row_old = mysql_fetch_row($result_old)) { |
|
||||||
|
|
||||||
$dump[$i]['fields'][$j][0] = $row_old[0]; |
|
||||||
$dump[$i]['fields'][$j][1] = $row_old[1]; |
|
||||||
$dump[$i]['fields'][$j][2] = $row_old[2]; |
|
||||||
$dump[$i]['fields'][$j][3] = $row_old[3]; |
|
||||||
$dump[$i]['fields'][$j][4] = $row_old[4]; |
|
||||||
$dump[$i]['fields'][$j][5] = $row_old[5]; |
|
||||||
//get the field name in one special element of this array |
|
||||||
$dump[$i]['field_names'][$row_old[0]] = $j; |
|
||||||
|
|
||||||
$j++; |
|
||||||
} |
|
||||||
|
|
||||||
$i++; |
|
||||||
} |
|
||||||
|
|
||||||
foreach ($dump as $table) { |
|
||||||
|
|
||||||
$query = "SHOW FIELDS FROM ".$bases_old[$num_base].".".$table['table_name']; |
|
||||||
$result = mysql_query($query,$db_old); |
|
||||||
|
|
||||||
if (!$result) { |
|
||||||
|
|
||||||
$modif_tables[]='**'.$table['table_name'].'**'; |
|
||||||
|
|
||||||
} else { |
|
||||||
|
|
||||||
$i = 0; |
|
||||||
|
|
||||||
//check for removed, new or modified fields |
|
||||||
$fields_old = array(); |
|
||||||
$fields_new = array(); |
|
||||||
|
|
||||||
//list the new fields in a enumeration array |
|
||||||
foreach ($table['field_names'] as $dummy_key => $dummy_field) { |
|
||||||
$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) |
|
||||||
$modif_fields = array(); |
|
||||||
while ($row_old = mysql_fetch_row($result)) { |
|
||||||
|
|
||||||
$fields_old[] = $row_old[0]; |
|
||||||
$modif_field = ''; |
|
||||||
|
|
||||||
if (isset($table['fields'][$table['field_names'][$row_old[0]]])) { |
|
||||||
$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 ($row_old[$key] != $field_info[$key]) { |
|
||||||
$modif_field .= '~+~'.$field_details[$key].'~+~,'; |
|
||||||
break; |
|
||||||
} |
|
||||||
} |
|
||||||
//only record the whole stuff if the string is not empty |
|
||||||
if (strlen($modif_field) > 0) { |
|
||||||
$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[$dummy] = '++'.$val.'++'; |
|
||||||
} |
|
||||||
|
|
||||||
$old_fields = array_diff($fields_old, $fields_new); |
|
||||||
foreach ($old_fields as $dummy => $val) { |
|
||||||
$old_fields[$dummy] = '--'.$val.'--'; |
|
||||||
} |
|
||||||
|
|
||||||
if (count($old_fields) > 0 or count($modif_fields) > 0 or count($new_fields) > 0 ) { |
|
||||||
$modif_tables[] = array( |
|
||||||
'table' => $table['table_name'], |
|
||||||
'old_fields' => $old_fields, |
|
||||||
'changed_fields' => $modif_fields, |
|
||||||
'new_fields' => $new_fields, |
|
||||||
); |
|
||||||
} |
|
||||||
} |
|
||||||
$tables_db_new[] = $table['table_name']; |
|
||||||
} |
|
||||||
|
|
||||||
$query = "SHOW TABLES FROM ".$bases_old[$num_base]; |
|
||||||
$result = mysql_query($query, $db_old) or die(mysql_error()); |
|
||||||
|
|
||||||
while ($row = mysql_fetch_row($result)) { |
|
||||||
$tables_db_old[] = $row[0]; |
|
||||||
} |
|
||||||
|
|
||||||
$diff = array_diff($tables_db_old, $tables_db_new); |
|
||||||
|
|
||||||
foreach ($diff as $enreg) { |
|
||||||
$modif_tables[] = '---'.$enreg.'---'; |
|
||||||
} |
|
||||||
//$modif_tables = array_unique($modif_tables); //deprecated with the structure complexification |
|
||||||
|
|
||||||
} 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)) { |
|
||||||
$tables_db_old[] = $row[0]; |
|
||||||
} |
|
||||||
|
|
||||||
$diff = array_diff($tables_db_old, $tables_db_new); |
|
||||||
|
|
||||||
foreach ($diff as $enreg) { |
|
||||||
$modif_tables[] = '---'.$enreg.'---'; |
|
||||||
} |
|
||||||
|
|
||||||
$modif_tables = array_unique($modif_tables); |
|
||||||
echo "<h3>This database has been removed!</h3>"; |
|
||||||
} |
|
||||||
echo "<h3>Differences between each table</h3>" . |
|
||||||
"- fields display under each table's name, <br />" . |
|
||||||
"- new tables are surrounded by '**', <br />" . |
|
||||||
"- removed tables are surrounded by '---',<br />" . |
|
||||||
"- new fields are surrounded by '++',<br />" . |
|
||||||
"- removed fields are surrounded by '--',<br />" . |
|
||||||
"- modified fields are surrounded by '~+~',<br />"; |
|
||||||
echo '<pre>'.print_r($modif_tables, true).'</pre>'; |
|
||||||
$all_db_changes[$base] = $modif_tables; |
|
||||||
} |
|
||||||
|
|
||||||
mysql_close($db_new); |
|
||||||
mysql_close($db_old); |
|
||||||
|
|
||||||
echo "<h2>Generating SQL</h2>"; |
|
||||||
|
|
||||||
//going through all databases changes |
|
||||||
foreach ($all_db_changes as $base => $changes) { |
|
||||||
echo "<h3>SQL for DB $base</h3>"; |
|
||||||
|
|
||||||
foreach ($changes as $table) { |
|
||||||
|
|
||||||
if (is_array($table)) { |
|
||||||
//we have a field-level difference |
|
||||||
$mytable = $table['table']; |
|
||||||
$myold = $table['old_fields']; |
|
||||||
$mychanged = $table['changed_fields']; |
|
||||||
$mynew = $table['new_fields']; |
|
||||||
|
|
||||||
foreach ($myold as $myname) { |
|
||||||
//column lost, display DROP command |
|
||||||
$myname = str_replace('--', '', $myname); |
|
||||||
echo "ALTER TABLE ".$mytable." DROP ".$myname."<br />"; |
|
||||||
} |
|
||||||
|
|
||||||
foreach ($mychanged as $myname => $myprop) { |
|
||||||
//field changed, display SET command |
|
||||||
$myprops = split(',', $myprop); |
|
||||||
$myprops_string = ''; |
|
||||||
foreach ($myprops as $myprop) { |
|
||||||
$myprop = str_replace('~+~', '', $myprop); |
|
||||||
$myprops_string .= $myprop." "; |
|
||||||
} |
|
||||||
echo "ALTER TABLE ".$mytable." CHANGE $myname $myname $myprops_string<br />"; |
|
||||||
} |
|
||||||
|
|
||||||
foreach ($mynew as $myname) { |
|
||||||
//column created, display ADD command |
|
||||||
$myname = str_replace('++', '', $myname); |
|
||||||
echo "ALTER TABLE ".$mytable." ADD $myname...<br />"; |
|
||||||
} |
|
||||||
|
|
||||||
} else { |
|
||||||
|
|
||||||
//we have a table-level difference |
|
||||||
$open_tag = substr($table, 0, 2); |
|
||||||
switch ($open_tag) { |
|
||||||
case '**': |
|
||||||
//new table, display CREATE TABLE command |
|
||||||
$table = str_replace('**', '', $table); |
|
||||||
echo "CREATE TABLE ".$table."();<br />"; |
|
||||||
break; |
|
||||||
case '--': |
|
||||||
//dropped table, display DROP TABLE command |
|
||||||
$table = str_replace('---', '', $table); |
|
||||||
echo "DROP TABLE ".$table."();<br />"; |
|
||||||
break; |
|
||||||
default: |
|
||||||
echo "Unknown table problem: ".$table."<br />"; |
|
||||||
break; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
@ -1,201 +0,0 @@ |
|||||||
<?php //$id: $
|
|
||||||
/* For licensing terms, see /license.txt */ |
|
||||||
|
|
||||||
// TODO: Ivan, 13-FEB-2010: Is this file really needed? |
|
||||||
|
|
||||||
/** |
|
||||||
============================================================================== |
|
||||||
* GOAL: Updates courses separately |
|
||||||
* |
|
||||||
* After upgrading a previous version to Dokeos 1.6, there are only |
|
||||||
* MAX_COURSE_TRANSFER courses converted to the new format - with |
|
||||||
* MAX_COURSE_TRANSFER in install/index.php being 100 as default. |
|
||||||
* |
|
||||||
* To update the rest of the courses you need to run this script. |
|
||||||
* |
|
||||||
* @package chamilo.install |
|
||||||
* @todo remove duplication: MAX_COURSE_TRANSFER is defined here and |
|
||||||
* also in install.index.php |
|
||||||
============================================================================== |
|
||||||
*/ |
|
||||||
|
|
||||||
/* |
|
||||||
============================================================================== |
|
||||||
INIT SECTION |
|
||||||
============================================================================== |
|
||||||
*/ |
|
||||||
@include '../inc/installedVersion.inc.php'; |
|
||||||
require '../inc/lib/main_api.lib.php'; |
|
||||||
|
|
||||||
require '../lang/english/trad4all.inc.php'; |
|
||||||
require '../lang/english/install.inc.php'; |
|
||||||
|
|
||||||
//load for get_config_param() |
|
||||||
require_once 'install_functions.inc.php'; |
|
||||||
|
|
||||||
define('DOKEOS_COURSE_UPDATE', 1); |
|
||||||
define('MAX_COURSE_TRANSFER', 100); |
|
||||||
|
|
||||||
error_reporting(E_COMPILE_ERROR | E_ERROR | E_CORE_ERROR); |
|
||||||
|
|
||||||
@set_time_limit(0); |
|
||||||
|
|
||||||
$update_path=trim(stripslashes($_GET['update_path'])); |
|
||||||
|
|
||||||
$update_from_version = array('1.5', '1.5.4', '1.5.5'); |
|
||||||
|
|
||||||
/* |
|
||||||
============================================================================== |
|
||||||
INITIALISE FORM VARIABLES |
|
||||||
(If this is the first visit to this script.) |
|
||||||
Variables are read from the configuration file |
|
||||||
of the old Dokeos version (configuration.php). |
|
||||||
============================================================================== |
|
||||||
*/ |
|
||||||
|
|
||||||
$updateFromConfigFile = ''; // leave empty |
|
||||||
$badUpdatePath = false; |
|
||||||
|
|
||||||
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'])) { |
|
||||||
$badUpdatePath = true; |
|
||||||
$_POST['step2'] = 0; |
|
||||||
} elseif (!in_array(get_config_param('clarolineVersion'), $update_from_version)) { |
|
||||||
$badUpdatePath = true; |
|
||||||
$_POST['step2'] = 0; |
|
||||||
} else { |
|
||||||
$urlAppendPath = str_replace('/main/install/update_courses.php', '', api_get_self()); |
|
||||||
$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']) { |
|
||||||
|
|
||||||
$_POST['updatePath'] = ''; |
|
||||||
} |
|
||||||
?> |
|
||||||
|
|
||||||
<html> |
|
||||||
<head> |
|
||||||
<?php /* There is no metadata about current language and encoding. */ ?> |
|
||||||
<title>-- Dokeos course update -- version <?php echo $dokeos_version; ?></title>
|
|
||||||
<link rel="stylesheet" href="../css/chamilo/default.css" type="text/css"> |
|
||||||
</head> |
|
||||||
<body bgcolor="white" dir="<?php echo $text_dir; ?>">
|
|
||||||
|
|
||||||
<form method="post" action="<?php echo api_get_self(); ?>">
|
|
||||||
<table cellpadding="6" cellspacing="0" border="0" width="650" bgcolor="#E6E6E6" align="center"> |
|
||||||
<tr bgcolor="#4171B5""> |
|
||||||
<td valign="top"> |
|
||||||
<big><font color="white">Dokeos course update - version <?php echo $dokeos_version; ?></font></big>
|
|
||||||
</td> |
|
||||||
</tr> |
|
||||||
<tr bgcolor="#E6E6E6"> |
|
||||||
<td> |
|
||||||
|
|
||||||
<img src="../img/bluelogo.gif" align="right" hspace="10" vspace="10"> |
|
||||||
|
|
||||||
<?php |
|
||||||
|
|
||||||
|
|
||||||
/* |
|
||||||
============================================================================== |
|
||||||
STEP 2 - COURSE UPDATE PROCESS |
|
||||||
|
|
||||||
the included files, update_db.inc.php and update_files.inc.php |
|
||||||
do the actual work of converting the course database |
|
||||||
and the files, respectively |
|
||||||
============================================================================== |
|
||||||
*/ |
|
||||||
|
|
||||||
if ($_POST['step2']) { |
|
||||||
|
|
||||||
include('update_db.inc.php'); |
|
||||||
include('update_files.inc.php'); |
|
||||||
?> |
|
||||||
|
|
||||||
<h2>Step 2 of 2 – Course Update</h2> |
|
||||||
|
|
||||||
<?php echo sizeof($coursePath); ?> courses have been successfully updated.
|
|
||||||
<br /><br /> |
|
||||||
|
|
||||||
<?php if($nbr_courses > MAX_COURSE_TRANSFER): ?> |
|
||||||
<font color="red"><strong>Warning:</strong> You have more than <?php echo MAX_COURSE_TRANSFER; ?> courses on your Dokeos platform ! Only <?php echo MAX_COURSE_TRANSFER; ?> courses have been updated. To update the other courses, <a href="update_courses.php?update_path=<?php echo urlencode($updatePath); ?>"><font color="red">click here</font></a>.</font>
|
|
||||||
<?php else: ?> |
|
||||||
<br /><br /> |
|
||||||
<?php endif; ?> |
|
||||||
|
|
||||||
<br /><br /><br /><br /> |
|
||||||
|
|
||||||
</form> |
|
||||||
<form method="get" action="../../"> |
|
||||||
<p align="right"><input type="submit" value="Go to your Dokeos portal" /></p> |
|
||||||
|
|
||||||
<?php |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
/* |
|
||||||
============================================================================== |
|
||||||
STEP 1 : CONFIGURATION |
|
||||||
============================================================================== |
|
||||||
*/ |
|
||||||
|
|
||||||
else { |
|
||||||
?> |
|
||||||
<h2>Step 1 of 2 – Configuration</h2> |
|
||||||
|
|
||||||
Please enter the path where the older version of Dokeos is installed (<?php echo implode(' | ',$update_from_version); ?>). The courses will be moved from that location to the Dokeos path.
|
|
||||||
<br /><br /> |
|
||||||
<strong>Notice:</strong> Please run this update script only if you've just updated (incompletely) Dokeos <?php echo implode(' | ',$update_from_version); ?> to Dokeos <?php echo $dokeos_version; ?>!
|
|
||||||
<br /><br /> |
|
||||||
<?php |
|
||||||
if ($badUpdatePath) { |
|
||||||
?> |
|
||||||
<br /><br /> |
|
||||||
<div style="background-color:white; color:red; text-align:center; font-weight:bold;"> |
|
||||||
Error!<br /> |
|
||||||
Dokeos <?php echo implode('|',$update_from_version); ?> has not been found in that directory.
|
|
||||||
</div> |
|
||||||
<?php |
|
||||||
} else { |
|
||||||
echo '<br />'; |
|
||||||
} |
|
||||||
?> |
|
||||||
<table border="0" cellpadding="5" width="100%" align="center"> |
|
||||||
<tr> |
|
||||||
<td>Where are the courses to be updated: </td> |
|
||||||
<td><input type="text" name="updatePath" size="50" value="<?php echo empty($update_path)?($badUpdatePath?htmlentities($_POST['updatePath']):$_SERVER['DOCUMENT_ROOT'].'/old_version/'):htmlentities($update_path); ?>" /></td>
|
|
||||||
</tr> |
|
||||||
</table> |
|
||||||
|
|
||||||
<p align="center"> |
|
||||||
<input type="submit" name="step2" value="Update courses" onclick="javascript:if(this.value == 'Please Wait...') return false; else this.value='Please Wait...';" /> |
|
||||||
</p> |
|
||||||
<?php |
|
||||||
} |
|
||||||
?> |
|
||||||
|
|
||||||
</td> |
|
||||||
</tr> |
|
||||||
</table> |
|
||||||
</form> |
|
||||||
|
|
||||||
</body> |
|
||||||
</html> |
|
||||||
@ -1,681 +0,0 @@ |
|||||||
<?php |
|
||||||
/* |
|
||||||
THIS FILE IS DEPRECATED - ONLY REMAINING FOR LEGACY CODE STUDY FOR NOW - YW20070129 |
|
||||||
|
|
||||||
============================================================================== |
|
||||||
Dokeos - elearning and course management software |
|
||||||
|
|
||||||
Copyright (c) 2004-2007 Dokeos S.A. |
|
||||||
Copyright (c) 2003 Ghent University (UGent) |
|
||||||
Copyright (c) 2001 Universite catholique de Louvain (UCL) |
|
||||||
Copyright (c) various contributors |
|
||||||
|
|
||||||
For a full list of contributors, see "credits.txt". |
|
||||||
The full license can be read in "license.txt". |
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or |
|
||||||
modify it under the terms of the GNU General Public License |
|
||||||
as published by the Free Software Foundation; either version 2 |
|
||||||
of the License, or (at your option) any later version. |
|
||||||
|
|
||||||
See the GNU General Public License for more details. |
|
||||||
|
|
||||||
Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium |
|
||||||
Mail: info@dokeos.com |
|
||||||
============================================================================== |
|
||||||
*/ |
|
||||||
/** |
|
||||||
============================================================================== |
|
||||||
* Update the Dokeos database from an older version |
|
||||||
* Notice : This script has to be included by index.php or update_courses.php |
|
||||||
* |
|
||||||
* @package chamilo.install |
|
||||||
* @todo |
|
||||||
* - conditional changing of tables. Currently we execute for example |
|
||||||
* ALTER TABLE `$dbNameForm`.`cours` instructions without checking wether this is necessary. |
|
||||||
* - reorganise code into functions |
|
||||||
* @todo use database library |
|
||||||
============================================================================== |
|
||||||
*/ |
|
||||||
|
|
||||||
//load helper functions |
|
||||||
require_once("install_upgrade.lib.php"); |
|
||||||
|
|
||||||
/* |
|
||||||
============================================================================== |
|
||||||
MAIN CODE |
|
||||||
============================================================================== |
|
||||||
*/ |
|
||||||
|
|
||||||
//check if we come from index.php or update_courses.php - otherwise display error msg |
|
||||||
if (defined('SYSTEM_INSTALLATION') || defined('DOKEOS_COURSE_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)) |
|
||||||
{ |
|
||||||
echo '<strong>'.get_lang('Error').' !</strong> Dokeos '.implode('|', $updateFromVersion).' '.get_lang('HasNotBeenFound').'.<br /><br /> |
|
||||||
'.get_lang('PleasGoBackToStep1').'. |
|
||||||
<p><button type="submit" class="back" name="step1" value="< '.get_lang('Back').'">'.get_lang('Back').'</button></p> |
|
||||||
</td></tr></table></form></body></html>'; |
|
||||||
|
|
||||||
exit (); |
|
||||||
} |
|
||||||
|
|
||||||
//get_config_param() comes from install_functions.inc.php and |
|
||||||
//actually gets the param from |
|
||||||
$_configuration['db_glue'] = get_config_param('dbGlu'); |
|
||||||
|
|
||||||
if ($singleDbForm) |
|
||||||
{ |
|
||||||
$_configuration['table_prefix'] = get_config_param('courseTablePrefix'); |
|
||||||
} |
|
||||||
|
|
||||||
$dbScormForm = preg_replace('/[^a-zA-Z0-9_\-]/', '', $dbScormForm); |
|
||||||
|
|
||||||
if (!empty($dbPrefixForm) && strpos($dbScormForm, $dbPrefixForm) !== 0) |
|
||||||
{ |
|
||||||
$dbScormForm = $dbPrefixForm.$dbScormForm; |
|
||||||
} |
|
||||||
|
|
||||||
if (empty($dbScormForm) || $dbScormForm == 'mysql' || $dbScormForm == $dbPrefixForm) |
|
||||||
{ |
|
||||||
$dbScormForm = $dbPrefixForm.'scorm'; |
|
||||||
} |
|
||||||
|
|
||||||
@Database::connect(array('server' => $dbHostForm, 'username' => $dbUsernameForm, 'password' => $dbPassForm)); |
|
||||||
|
|
||||||
//if error on connection to the database, show error and exit |
|
||||||
if (Database::errno() > 0) |
|
||||||
{ |
|
||||||
$no = Database::errno(); |
|
||||||
$msg = Database::error(); |
|
||||||
|
|
||||||
echo '<hr />['.$no.'] - '.$msg.'<hr /> |
|
||||||
'.get_lang('DBServerDoesntWorkOrLoginPassIsWrong').'.<br /><br /> |
|
||||||
'.get_lang('PleaseCheckTheseValues').' :<br /><br /> |
|
||||||
<strong>'.get_lang('DBHost').'</strong> : '.$dbHostForm.'<br /> |
|
||||||
<strong>'.get_lang('DBLogin').'</strong> : '.$dbUsernameForm.'<br /> |
|
||||||
<strong>'.get_lang('DBPassword').'</strong> : '.$dbPassForm.'<br /><br /> |
|
||||||
'.get_lang('PleaseGoBackToStep').' '. (defined('SYSTEM_INSTALLATION') ? '3' : '1').'. |
|
||||||
<p><buton class="back" type="submit" name="step'. (defined('SYSTEM_INSTALLATION') ? '3' : '1').'" value="< '.get_lang('Back').'">'.get_lang('Back').'</button></p> |
|
||||||
</td></tr></table></form></body></html>'; |
|
||||||
|
|
||||||
exit (); |
|
||||||
} |
|
||||||
|
|
||||||
@Database::query("set session sql_mode='';"); // Disabling special SQL modes (MySQL 5) |
|
||||||
|
|
||||||
/* |
|
||||||
----------------------------------------------------------- |
|
||||||
Normal upgrade procedure: |
|
||||||
start by updating main, statistic, user databases |
|
||||||
----------------------------------------------------------- |
|
||||||
*/ |
|
||||||
//if this script has been included by index.php, not update_courses.php, so |
|
||||||
// that we want to change the main databases as well... |
|
||||||
$only_test = false; |
|
||||||
if (defined('SYSTEM_INSTALLATION')) |
|
||||||
{ |
|
||||||
/** |
|
||||||
* Update the databases "pre" migration |
|
||||||
*/ |
|
||||||
include ("../lang/english/create_course.inc.php"); |
|
||||||
|
|
||||||
if ($languageForm != 'english') |
|
||||||
{ |
|
||||||
//languageForm has been escaped in index.php |
|
||||||
include ("../lang/$languageForm/create_course.inc.php"); |
|
||||||
} |
|
||||||
|
|
||||||
//TODO deal with migrate-db-1.6.x-1.8.0-pre.sql here |
|
||||||
//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'); |
|
||||||
if(count($m_q_list)>0) |
|
||||||
{ |
|
||||||
//now use the $m_q_list |
|
||||||
/** |
|
||||||
* We connect to the right DB first to make sure we can use the queries |
|
||||||
* without a database name |
|
||||||
*/ |
|
||||||
Database::select_db($dbNameForm); |
|
||||||
foreach($m_q_list as $query){ |
|
||||||
if($only_test){ |
|
||||||
echo "Database::query($dbNameForm,$query)<br />"; |
|
||||||
}else{ |
|
||||||
$res = Database::query($query); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
//manual updates in here |
|
||||||
//update all registration_date, expiration_date and active fields |
|
||||||
//$sql_upd = "UPDATE user SET registration_date=NOW()"; |
|
||||||
//$res_upd = Database::query($sql_upd); |
|
||||||
//end of manual updates |
|
||||||
|
|
||||||
//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'); |
|
||||||
if(count($s_q_list)>0) |
|
||||||
{ |
|
||||||
//now use the $s_q_list |
|
||||||
/** |
|
||||||
* We connect to the right DB first to make sure we can use the queries |
|
||||||
* without a database name |
|
||||||
*/ |
|
||||||
Database::select_db($dbStatsForm); |
|
||||||
foreach($s_q_list as $query){ |
|
||||||
if($only_test){ |
|
||||||
echo "Database::query($dbStatsForm,$query)<br />"; |
|
||||||
}else{ |
|
||||||
$res = Database::query($query); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
//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'); |
|
||||||
if(count($u_q_list)>0) |
|
||||||
{ |
|
||||||
//now use the $u_q_list |
|
||||||
/** |
|
||||||
* We connect to the right DB first to make sure we can use the queries |
|
||||||
* without a database name |
|
||||||
*/ |
|
||||||
Database::select_db($dbUserForm); |
|
||||||
foreach($u_q_list as $query){ |
|
||||||
if($only_test){ |
|
||||||
echo "Database::query($dbUserForm,$query)<br />"; |
|
||||||
}else{ |
|
||||||
$res = Database::query($query); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
//the SCORM database doesn't need a change in the pre-migrate part - ignore |
|
||||||
|
|
||||||
die(); |
|
||||||
//TODO only update this table |
|
||||||
/* |
|
||||||
//set the settings from the form or the old config into config settings. |
|
||||||
//These settings are considered "safe" because they are entered by the admin |
|
||||||
$installation_settings['institution_form'] = $institutionForm; |
|
||||||
$installation_settings['institution_url_form'] = $institutionUrlForm; |
|
||||||
$installation_settings['campus_form'] = $campusForm; |
|
||||||
$installation_settings['email_form'] = $emailForm; |
|
||||||
$installation_settings['admin_last_name'] = $adminLastName; |
|
||||||
$installation_settings['admin_first_name'] = $adminFirstName; |
|
||||||
$installation_settings['language_form'] = $languageForm; |
|
||||||
$installation_settings['allow_self_registration'] = $allowSelfReg; |
|
||||||
$installation_settings['allow_teacher_self_registration'] = $allowSelfRegProf; |
|
||||||
$installation_settings['admin_phone_form'] = $adminPhoneForm; |
|
||||||
|
|
||||||
//Database::query("INSERT INTO `$dbNameForm`.`course_module` (`name`,`link`,`image`,`row`,`column`,`position`) VALUES |
|
||||||
// ('AddedLearnpath', NULL, 'scormbuilder.gif', 0, 0, 'external'), |
|
||||||
// ('".TOOL_BACKUP."', 'coursecopy/backup.php' , 'backup.gif', 2, 1, 'courseadmin'), |
|
||||||
// ('".TOOL_COPY_COURSE_CONTENT."', 'coursecopy/copy_course.php' , 'copy.gif', 2, 2, 'courseadmin'), |
|
||||||
// ('".TOOL_RECYCLE_COURSE."', 'coursecopy/recycle_course.php' , 'recycle.gif', 2, 3, 'courseadmin')"); |
|
||||||
//... |
|
||||||
//Database::query("UPDATE `$dbNameForm`.`course_module` SET name='".TOOL_LEARNPATH."' WHERE link LIKE 'scorm/%'"); |
|
||||||
*/ |
|
||||||
} |
|
||||||
|
|
||||||
/* |
|
||||||
----------------------------------------------------------- |
|
||||||
Update the Dokeos course databases |
|
||||||
this part can be accessed in two ways: |
|
||||||
- from the normal upgrade process |
|
||||||
- from the script update_courses.php, |
|
||||||
which is used to upgrade more than MAX_COURSE_TRANSFER courses |
|
||||||
|
|
||||||
Every time this script is accessed, only |
|
||||||
MAX_COURSE_TRANSFER courses are upgraded. |
|
||||||
----------------------------------------------------------- |
|
||||||
*/ |
|
||||||
|
|
||||||
//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'); |
|
||||||
if(count($c_q_list)>0) |
|
||||||
{ |
|
||||||
//get the courses list |
|
||||||
Database::select_db($dbNameForm); |
|
||||||
$res = Database::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.inc.php');} |
|
||||||
if(Database::num_rows($res)>0) |
|
||||||
{ |
|
||||||
while($row = Database::fetch_array($res)) |
|
||||||
{ |
|
||||||
$list[] = $row; |
|
||||||
} |
|
||||||
foreach($list as $row) |
|
||||||
{ |
|
||||||
//now use the $c_q_list |
|
||||||
/** |
|
||||||
* We connect to the right DB first to make sure we can use the queries |
|
||||||
* without a database name |
|
||||||
*/ |
|
||||||
Database::select_db($row['db_name']); |
|
||||||
foreach($c_q_list as $query) |
|
||||||
{ |
|
||||||
if($only_test) |
|
||||||
{ |
|
||||||
echo "Database::query(".$row['db_name'].",$query)<br />"; |
|
||||||
}else{ |
|
||||||
$res = Database::query($query); |
|
||||||
} |
|
||||||
} |
|
||||||
//update course manually |
|
||||||
//update group_category.forum_state |
|
||||||
//update group_info.tutor_id (put it in group_tutor table?) |
|
||||||
//update group_info.forum_state, forum_id |
|
||||||
|
|
||||||
//update forum tables (migrate from bb_ tables to forum_ tables) |
|
||||||
//migrate categories |
|
||||||
$sql_orig = "SELECT * FROM bb_categories"; |
|
||||||
$res_orig = Database::query($sql_orig); |
|
||||||
while($row = Database::fetch_array($res_orig)){ |
|
||||||
$sql = "INSERT INTO forum_category " . |
|
||||||
"(cat_id,cat_title,cat_comment,cat_order,locked) VALUES " . |
|
||||||
"('".$row['cat_id']."','".$row['cat_title']."','','".$row['cat_order']."',0)"; |
|
||||||
$res = Database::query($sql); |
|
||||||
} |
|
||||||
$sql_orig = "SELECT * FROM bb_forums ORDER BY forum_last_post_id desc"; |
|
||||||
$res_orig = Database::query($sql_orig); |
|
||||||
$order = 1; |
|
||||||
while($row = Database::fetch_array($res_orig)){ |
|
||||||
$sql = "INSERT INTO forum_forum " . |
|
||||||
"(forum_id,forum_category,allow_edit,forum_comment," . |
|
||||||
"forum_title," . |
|
||||||
"forum_last_post, forum_threads," . |
|
||||||
"locked, forum_posts, " . |
|
||||||
"allow_new_threads, forum_order) VALUES " . |
|
||||||
"('".$row['forum_id']."','".$row['cat_id']."',1,'".$row['forum_desc']."'," . |
|
||||||
"'".$row['forum_name']."'," . |
|
||||||
"'".$row['forum_last_post_id']."','".$row['forum_topics']."'," . |
|
||||||
"0,'".$row['forum_posts']."'," . |
|
||||||
"1,$order)"; |
|
||||||
$res = Database::query($sql); |
|
||||||
$order++; |
|
||||||
} |
|
||||||
$sql_orig = "SELECT * FROM bb_topics"; |
|
||||||
$res_orig = Database::query($sql_orig); |
|
||||||
while($row = Database::fetch_array($res_orig)){ |
|
||||||
//convert time from varchar to datetime |
|
||||||
$time = $row['topic_time']; |
|
||||||
$name = $row['prenom']." ".$row['nom']; |
|
||||||
$sql = "INSERT INTO forum_thread " . |
|
||||||
"(thread_id,forum_id,thread_poster_id," . |
|
||||||
"locked,thread_replies,thread_sticky,thread_title," . |
|
||||||
"thread_poster_name, thread_date, thread_last_post," . |
|
||||||
"thread_views) VALUES " . |
|
||||||
"('".$row['topic_id']."','".$row['forum_id']."','".$row['topic_poster']."'," . |
|
||||||
"0,'".$row['topic_replies']."',0,'".$row['topic_title']."'," . |
|
||||||
"'$name','$time','".$row['topic_last_post_id']."'," . |
|
||||||
"'".$row['topic_views']."')"; |
|
||||||
$res = Database::query($sql); |
|
||||||
} |
|
||||||
$sql_orig = "SELECT * FROM bb_posts, bb_posts_text WHERE bb_posts.post_id = bb_posts_text.post_id"; |
|
||||||
$res_orig = Database::query($sql_orig); |
|
||||||
while($row = Database::fetch_array($res_orig)){ |
|
||||||
//convert time from varchar to datetime |
|
||||||
$time = $row['post_time']; |
|
||||||
$name = $row['prenom']." ".$row['nom']; |
|
||||||
$sql = "INSERT INTO forum_post " . |
|
||||||
"(post_id,forum_id,thread_id," . |
|
||||||
"poster_id,post_parent_id,visible, " . |
|
||||||
"post_title,poster_name, post_text, " . |
|
||||||
"post_date, post_notification) VALUES " . |
|
||||||
"('".$row['post_id']."','".$row['forum_id']."','".$row['topic_id']."'," . |
|
||||||
"'".$row['poster_id']."','".$row['parent_id']."',1," . |
|
||||||
"'".$row['post_title']."','$name', '".$row['post_text']."'," . |
|
||||||
"'$time',0)"; |
|
||||||
$res = Database::query($sql); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
$newPath = str_replace('\\', '/', realpath('../..')).'/'; |
|
||||||
|
|
||||||
$coursePath = array (); |
|
||||||
$courseDB = array (); |
|
||||||
$nbr_courses = 0; |
|
||||||
|
|
||||||
if ($result = Database::query("SELECT code,db_name,directory,course_language FROM `$dbNameForm`.`course` WHERE target_course_code IS NULL")) |
|
||||||
{ |
|
||||||
$i = 0; |
|
||||||
|
|
||||||
$nbr_courses = Database::num_rows($result); |
|
||||||
|
|
||||||
while ($i < MAX_COURSE_TRANSFER && (list ($course_code, $db_base_course, $directory, $languageCourse) = Database::fetch_row($result))) |
|
||||||
{ |
|
||||||
if (!file_exists($newPath.'courses/'.$directory)) |
|
||||||
{ |
|
||||||
if ($singleDbForm) |
|
||||||
{ |
|
||||||
$prefix = $_configuration['table_prefix'].$db_base_course.$_configuration['db_glue']; |
|
||||||
|
|
||||||
$db_base_course = $dbNameForm.'`.`'.$_configuration['table_prefix'].$db_base_course; |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
$prefix = ''; |
|
||||||
} |
|
||||||
|
|
||||||
$coursePath[$course_code] = $directory; |
|
||||||
$courseDB[$course_code] = $db_base_course; |
|
||||||
|
|
||||||
include ("../lang/english/create_course.inc.php"); |
|
||||||
|
|
||||||
if ($languageCourse != 'english') |
|
||||||
{ |
|
||||||
include ("../lang/$languageCourse/create_course.inc.php"); |
|
||||||
} |
|
||||||
|
|
||||||
//TODO process the whole course database migration here. Call an external |
|
||||||
//script/function to keep this script tidy |
|
||||||
|
|
||||||
// Set item-properties of dropbox files |
|
||||||
/* |
|
||||||
$sql = "SELECT * FROM `$db_base_course".$_configuration['db_glue']."dropbox_file` f, `".$_configuration['db_glue']."_base_course".$_configuration['db_glue']."dropbox_post` p WHERE f.id = p.file_id"; |
|
||||||
$res = Database::query($sql); |
|
||||||
while ($obj = Database::fetch_object($res)) |
|
||||||
{ |
|
||||||
$sql = "INSERT INTO `$db_base_course".$_configuration['db_glue']."item_property` SET "; |
|
||||||
$sql .= " tool = '".TOOL_DROPBOX."', "; |
|
||||||
$sql .= " insert_date = '".$obj->upload_date."', "; |
|
||||||
$sql .= " lastedit_date = '".$obj->last_upload_date."', "; |
|
||||||
$sql .= " ref = '".$obj->id."', "; |
|
||||||
$sql .= " lastedit_type = 'DropboxFileAdded', "; |
|
||||||
$sql .= " to_group_id = '0', "; |
|
||||||
$sql .= " to_user_id = '".$obj->dest_user_id."', "; |
|
||||||
$sql .= " insert_user_id = '".$obj->uploader_id."'"; |
|
||||||
Database::query($sql); |
|
||||||
} |
|
||||||
*/ |
|
||||||
|
|
||||||
$i ++; |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
$nbr_courses --; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
echo 'You are not allowed here !'; |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** |
|
||||||
* This function stores the forum category in the database. The new category is added to the end. |
|
||||||
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University |
|
||||||
* @todo is this the same function as in forumfunction.inc.php? If this is the case then it should not appear here. |
|
||||||
*/ |
|
||||||
function store_forumcategory($values) |
|
||||||
{ |
|
||||||
global $table_categories; |
|
||||||
global $_course; |
|
||||||
global $_user; |
|
||||||
|
|
||||||
// find the max cat_order. The new forum category is added at the end => max cat_order + & |
|
||||||
$sql="SELECT MAX(cat_order) as sort_max FROM ".Database::escape_string($table_categories); |
|
||||||
$result=Database::query($sql); |
|
||||||
$row=Database::fetch_array($result); |
|
||||||
$new_max=$row['sort_max']+1; |
|
||||||
|
|
||||||
$sql="INSERT INTO ".$table_categories." (cat_title, cat_comment, cat_order) VALUES ('".Database::real_escape_string($values['forum_category_title'])."','".Database::escape_string($values['forum_category_comment'])."','".Database::escape_string($new_max)."')"; |
|
||||||
Database::query($sql); |
|
||||||
$last_id=Database::insert_id(); |
|
||||||
api_item_property_update($_course, TOOL_FORUM_CATEGORY, $last_id,"ForumCategoryAdded", $_user['user_id']); |
|
||||||
return array('id'=>$last_id,'title'=>$values['forum_category_title']) ; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* This function stores the forum in the database. The new forum is added to the end. |
|
||||||
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University |
|
||||||
* @todo is this the same function as in forumfunction.inc.php? If this is the case then it should not appear here. |
|
||||||
*/ |
|
||||||
function store_forum($values) |
|
||||||
{ |
|
||||||
global $table_forums; |
|
||||||
global $_course; |
|
||||||
global $_user; |
|
||||||
|
|
||||||
// find the max forum_order for the given category. The new forum is added at the end => max cat_order + & |
|
||||||
$sql="SELECT MAX(forum_order) as sort_max FROM ".$table_forums." WHERE forum_category=".Database::escape_string($values['forum_category']); |
|
||||||
$result=Database::query($sql); |
|
||||||
$row=Database::fetch_array($result); |
|
||||||
$new_max=$row['sort_max']+1; |
|
||||||
|
|
||||||
|
|
||||||
$sql="INSERT INTO ".$table_forums." |
|
||||||
(forum_title, forum_comment, forum_category, allow_anonymous, allow_edit, approval_direct_post, allow_attachments, allow_new_threads, default_view, forum_of_group, forum_group_public_private, forum_order) |
|
||||||
VALUES ('".Database::escape_string($values['forum_title'])."', |
|
||||||
'".Database::escape_string($values['forum_comment'])."', |
|
||||||
'".Database::escape_string($values['forum_category'])."', |
|
||||||
'".Database::escape_string($values['allow_anonymous_group']['allow_anonymous'])."', |
|
||||||
'".Database::escape_string($values['students_can_edit_group']['students_can_edit'])."', |
|
||||||
'".Database::escape_string($values['approval_direct_group']['approval_direct'])."', |
|
||||||
'".Database::escape_string($values['allow_attachments_group']['allow_attachments'])."', |
|
||||||
'".Database::escape_string($values['allow_new_threads_group']['allow_new_threads'])."', |
|
||||||
'".Database::escape_string($values['default_view_type_group']['default_view_type'])."', |
|
||||||
'".Database::escape_string($values['group_forum'])."', |
|
||||||
'".Database::escape_string($values['public_private_group_forum_group']['public_private_group_forum'])."', |
|
||||||
'".Database::escape_string($new_max)."')"; |
|
||||||
Database::query($sql); |
|
||||||
$last_id=Database::insert_id(); |
|
||||||
api_item_property_update($_course, TOOL_FORUM, $last_id,"ForumCategoryAdded", $_user['user_id']); |
|
||||||
return array('id'=>$last_id, 'title'=>$values['forum_title']); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* This function stores a new thread. This is done through an entry in the forum_thread table AND |
|
||||||
* in the forum_post table because. The threads are also stored in the item_property table. (forum posts are not (yet)) |
|
||||||
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University |
|
||||||
* @todo is this the same function as in forumfunction.inc.php? If this is the case then it should not appear here. |
|
||||||
*/ |
|
||||||
function store_thread($values) |
|
||||||
{ |
|
||||||
global $table_threads; |
|
||||||
global $table_posts; |
|
||||||
global $_user; |
|
||||||
global $_course; |
|
||||||
global $current_forum; |
|
||||||
|
|
||||||
// We first store an entry in the forum_thread table because the thread_id is used in the forum_post table |
|
||||||
$sql="INSERT INTO $table_threads (thread_title, forum_id, thread_poster_id, thread_poster_name, thread_views, thread_date, thread_sticky) |
|
||||||
VALUES ('".Database::escape_string($values['post_title'])."', |
|
||||||
'".Database::escape_string($values['forum_id'])."', |
|
||||||
'".Database::escape_string($values['user_id'])."', |
|
||||||
'".Database::escape_string($values['poster_name'])."', |
|
||||||
'".Database::escape_string($values['topic_views'])."', |
|
||||||
'".Database::escape_string($values['post_date'])."', |
|
||||||
'".Database::escape_string($values['thread_sticky'])."')"; |
|
||||||
$result=Database::query($sql); |
|
||||||
$last_thread_id=Database::insert_id(); |
|
||||||
api_item_property_update($_course, TOOL_FORUM_THREAD, $last_thread_id,"ForumThreadAdded", $_user['user_id']); |
|
||||||
// if the forum properties tell that the posts have to be approved we have to put the whole thread invisible |
|
||||||
// because otherwise the students will see the thread and not the post in the thread. |
|
||||||
// we also have to change $visible because the post itself has to be visible in this case (otherwise the teacher would have |
|
||||||
// to make the thread visible AND the post |
|
||||||
if ($values['visible']==0) |
|
||||||
{ |
|
||||||
api_item_property_update($_course, TOOL_FORUM_THREAD, $last_thread_id,"invisible", $_user['user_id']); |
|
||||||
$visible=1; |
|
||||||
} |
|
||||||
|
|
||||||
return $last_thread_id; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* This function migrates the threads of a given phpbb forum to a new forum of the new forum tool |
|
||||||
* @param $phpbb_forum_id the forum_id of the old (phpbb) forum |
|
||||||
* @param $new_forum_id the forum_id in the new forum |
|
||||||
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University |
|
||||||
* @todo is this the same function as in forumfunction.inc.php? If this is the case then it should not appear here. |
|
||||||
*/ |
|
||||||
function migrate_threads_of_forum($phpbb_forum_id, $new_forum_id) |
|
||||||
{ |
|
||||||
global $phpbb_threads; |
|
||||||
global $table_forums; |
|
||||||
|
|
||||||
$table_users = Database :: get_main_table(TABLE_MAIN_USER); |
|
||||||
|
|
||||||
$sql_phpbb_threads="SELECT forum.*, users.user_id |
|
||||||
FROM $phpbb_threads forum, $table_users users |
|
||||||
WHERE forum_id='".Database::escape_string($phpbb_forum_id)."' |
|
||||||
AND forum.nom=users.lastname AND forum.prenom=users.firstname |
|
||||||
"; |
|
||||||
$result_phpbb_threads=Database::query($sql_phpbb_threads); |
|
||||||
$threads_counter=0; |
|
||||||
while ($row_phpbb_threads=Database::fetch_array($result_phpbb_threads)) |
|
||||||
{ |
|
||||||
$values['post_title']=$row_phpbb_threads['topic_title']; |
|
||||||
$values['forum_id']=$new_forum_id; |
|
||||||
$values['user_id']=$row_phpbb_threads['user_id']; |
|
||||||
$values['poster_name']=0; |
|
||||||
$values['topic_views']=$row_phpbb_threads['topic_views']; |
|
||||||
$values['post_date']=$row_phpbb_threads['topic_time']; |
|
||||||
$values['thread_sticky']=0; |
|
||||||
$values['visible']=$row_phpbb_threads['visible']; |
|
||||||
//my_print_r($values); |
|
||||||
$new_forum_thread_id=store_thread($values); |
|
||||||
|
|
||||||
// now we migrate the posts of the given thread |
|
||||||
$posts_counter=$posts_counter+migrate_posts_of_thread($row_phpbb_threads['topic_id'], $new_forum_thread_id, $new_forum_id); |
|
||||||
|
|
||||||
$threads_counter++; |
|
||||||
} |
|
||||||
|
|
||||||
// Now we update the forum_forum table with the total number of posts for the given forum. |
|
||||||
$sql="UPDATE $table_forums |
|
||||||
SET forum_posts='".Database::escape_string($posts_counter)."', |
|
||||||
forum_threads='".Database::escape_string($threads_counter)."' |
|
||||||
WHERE forum_id='".Database::escape_string($new_forum_id)."'"; |
|
||||||
//echo $sql; |
|
||||||
$result=Database::query($sql); |
|
||||||
return array("threads"=>$threads_counter, "posts"=>$posts_counter); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* This function migrates the posts of a given phpbb thread (topic) to a thread in the new forum tool |
|
||||||
* @param $phpbb_forum_id the forum_id of the old (phpbb) forum |
|
||||||
* @param $new_forum_id the forum_id in the new forum |
|
||||||
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University |
|
||||||
* @todo is this the same function as in forumfunction.inc.php? If this is the case then it should not appear here. |
|
||||||
*/ |
|
||||||
function migrate_posts_of_thread($phpbb_thread_id, $new_forum_thread_id, $new_forum_id) |
|
||||||
{ |
|
||||||
global $phpbb_posts; |
|
||||||
global $phpbb_poststext; |
|
||||||
global $table_posts; |
|
||||||
global $table_threads; |
|
||||||
global $added_resources; |
|
||||||
|
|
||||||
$table_users = Database :: get_main_table(TABLE_MAIN_USER); |
|
||||||
$table_added_resources = Database::get_course_table(TABLE_LINKED_RESOURCES); |
|
||||||
|
|
||||||
|
|
||||||
$post_counter=0; |
|
||||||
|
|
||||||
$sql_phpbb_posts="SELECT posts.*, posts_text.*, users.user_id, users.lastname, users.firstname FROM $phpbb_posts posts, $phpbb_poststext posts_text, $table_users users |
|
||||||
WHERE posts.post_id=posts_text.post_id |
|
||||||
AND posts.nom=users.lastname |
|
||||||
AND posts.prenom=users.firstname |
|
||||||
AND posts.topic_id='".Database::escape_string($phpbb_thread_id)."' |
|
||||||
"; |
|
||||||
$result_phpbb_posts=Database::query($sql_phpbb_posts); |
|
||||||
while($row_phpbb_posts=Database::fetch_array($result_phpbb_posts)) |
|
||||||
{ |
|
||||||
$values=array(); |
|
||||||
$values['post_title']=$row_phpbb_posts['post_title']; |
|
||||||
$values['post_text']=$row_phpbb_posts['post_text']; |
|
||||||
$values['thread_id']=$new_forum_thread_id; |
|
||||||
$values['forum_id']=$new_forum_id; |
|
||||||
$values['user_id']=$row_phpbb_posts['user_id']; |
|
||||||
$values['post_date']=$row_phpbb_posts['post_time']; |
|
||||||
$values['post_notification']=$row_phpbb_posts['topic_notify']; |
|
||||||
$values['post_parent_id']=0; |
|
||||||
$values['visible']=1; |
|
||||||
|
|
||||||
// We first store an entry in the forum_post table |
|
||||||
$sql="INSERT INTO $table_posts (post_title, post_text, thread_id, forum_id, poster_id, post_date, post_notification, post_parent_id, visible) |
|
||||||
VALUES ('".Database::escape_string($values['post_title'])."', |
|
||||||
'".Database::escape_string($values['post_text'])."', |
|
||||||
'".Database::escape_string($values['thread_id'])."', |
|
||||||
'".Database::escape_string($values['forum_id'])."', |
|
||||||
'".Database::escape_string($values['user_id'])."', |
|
||||||
'".Database::escape_string($values['post_date'])."', |
|
||||||
'".Database::escape_string($values['post_notification'])."', |
|
||||||
'".Database::escape_string($values['post_parent_id'])."', |
|
||||||
'".Database::escape_string($values['visible'])."')"; |
|
||||||
$result=Database::query($sql); |
|
||||||
$post_counter++; |
|
||||||
$last_post_id=Database::insert_id(); |
|
||||||
|
|
||||||
|
|
||||||
// We check if there added resources and if so we update them |
|
||||||
if (in_array($row_phpbb_posts['post_id'],$added_resources)) |
|
||||||
{ |
|
||||||
$sql_update_added_resource="UPDATE $table_added_resources |
|
||||||
SET source_type='forum_post', source_id='".Database::escape_string($last_post_id)."' |
|
||||||
WHERE source_type='".Database::escape_string(TOOL_BB_POST)."' AND source_id='".Database::escape_string($row_phpbb_posts['post_id'])."'"; |
|
||||||
echo $sql_update_added_resource; |
|
||||||
$result=Database::query($sql_update_added_resource); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
// update the thread_last_post of the post table AND the |
|
||||||
$sql="UPDATE $table_threads SET thread_last_post='".Database::escape_string($last_post_id)."', |
|
||||||
thread_replies='".Database::escape_string($post_counter-1)."' |
|
||||||
WHERE thread_id='".Database::escape_string($new_forum_thread_id)."'"; |
|
||||||
//echo $sql; |
|
||||||
$result=Database::query($sql); |
|
||||||
//echo $sql; |
|
||||||
return $post_counter; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* This function gets all the added resources for phpbb forum posts |
|
||||||
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University |
|
||||||
* @todo is this the same function as in forumfunction.inc.php? If this is the case then it should not appear here. |
|
||||||
*/ |
|
||||||
function get_added_resources() |
|
||||||
{ |
|
||||||
$table_added_resources = Database::get_course_table(TABLE_LINKED_RESOURCES); |
|
||||||
$return_array=array(); |
|
||||||
|
|
||||||
// TODO: now we also migrate the added resources. |
|
||||||
$sql_added_resources="SELECT * FROM $table_added_resources WHERE source_type='".Database::escape_string(TOOL_BB_POST)."'"; |
|
||||||
$result=Database::query($sql_added_resources); |
|
||||||
while ($row=Database::fetch_array($result)) |
|
||||||
{ |
|
||||||
$return_array[]=$row['source_id']; |
|
||||||
} |
|
||||||
return $return_array; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* This function gets the forum category information based on the name |
|
||||||
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University |
|
||||||
* @todo is this the same function as in forumfunction.inc.php? If this is the case then it should not appear here. |
|
||||||
*/ |
|
||||||
function get_forumcategory_id_by_name($forum_category_name) |
|
||||||
{ |
|
||||||
global $table_categories; |
|
||||||
|
|
||||||
$sql="SELECT cat_id FROM $table_categories WHERE cat_title='".Database::escape_string($forum_category_name)."'"; |
|
||||||
//echo $sql; |
|
||||||
$result=Database::query($sql); |
|
||||||
$row=Database::fetch_array($result); |
|
||||||
//echo $row['cat_id']; |
|
||||||
return $row['cat_id']; |
|
||||||
} |
|
||||||
?> |
|
||||||
@ -1,228 +0,0 @@ |
|||||||
<?php |
|
||||||
|
|
||||||
// TODO: Ivan, 13-FEB-2010: Is this file really needed? |
|
||||||
|
|
||||||
/* |
|
||||||
============================================================================== |
|
||||||
Dokeos - elearning and course management software |
|
||||||
|
|
||||||
Copyright (c) 2004 Dokeos S.A. |
|
||||||
Copyright (c) 2003 Ghent University (UGent) |
|
||||||
Copyright (c) 2001 Universite catholique de Louvain (UCL) |
|
||||||
|
|
||||||
For a full list of contributors, see "credits.txt". |
|
||||||
The full license can be read in "license.txt". |
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or |
|
||||||
modify it under the terms of the GNU General Public License |
|
||||||
as published by the Free Software Foundation; either version 2 |
|
||||||
of the License, or (at your option) any later version. |
|
||||||
|
|
||||||
See the GNU General Public License for more details. |
|
||||||
|
|
||||||
Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium |
|
||||||
Mail: info@dokeos.com |
|
||||||
============================================================================== |
|
||||||
*/ |
|
||||||
/** |
|
||||||
============================================================================== |
|
||||||
* Updates the Dokeos files from an older version |
|
||||||
* IMPORTANT: This script has to be included by install/index.php and update_courses.php |
|
||||||
* |
|
||||||
* SYSTEM_INSTALLATION is defined in the install/index.php |
|
||||||
* DOKEOS_COURSE_UPDATE is defined in update_courses.php |
|
||||||
* |
|
||||||
* When SYSTEM_INSTALLATION or DOKEOS_COURSE_UPDATE is defined, do for every course: |
|
||||||
* - remove the .htaccess in the document folder |
|
||||||
* - remove the index.php in the group folder |
|
||||||
* - write a new group/index.php file, make it an empty html file |
|
||||||
* - remove the index.php of the course folder |
|
||||||
* - write a new index.php file in the course folder, with some settings |
|
||||||
* - create a 'temp' directory in the course folder |
|
||||||
* - move the course folder inside the courses folder of the new Dokeos installation |
|
||||||
* - move the group documents from the group folder to the document folder, |
|
||||||
* keeping subfolders intact |
|
||||||
* - stores all documents inside the database (document and item_property tables) |
|
||||||
* - remove the visibility field from the document table |
|
||||||
* - update the item properties of the group documents |
|
||||||
* |
|
||||||
* Additionally, when SYSTEM_INSTALLATION is defined |
|
||||||
* - write a config file, configuration.php, with important settings |
|
||||||
* - write a .htaccess file (with instructions for Apache) in the courses directory |
|
||||||
* - remove the new main/upload/users directory and rename the main/img/users |
|
||||||
* directory of the old version to main/upload/users |
|
||||||
* - rename the old configuration.php to configuration.php.old, |
|
||||||
* or if this fails delete the old configuration.php |
|
||||||
* |
|
||||||
* @package chamilo.install |
|
||||||
============================================================================== |
|
||||||
*/ |
|
||||||
/* |
|
||||||
============================================================================== |
|
||||||
FUNCTIONS |
|
||||||
============================================================================== |
|
||||||
*/ |
|
||||||
|
|
||||||
/** |
|
||||||
* This function puts the documents of the upgraded courses |
|
||||||
* into the necessary tables of the new version: |
|
||||||
* the document and item_property tables. |
|
||||||
* |
|
||||||
* It is used to upgrade from Dokeos 1.5.x versions to |
|
||||||
* Dokeos 1.6 |
|
||||||
* |
|
||||||
* @return boolean true if everything worked, false otherwise |
|
||||||
*/ |
|
||||||
function fill_document_table($dir) |
|
||||||
{ |
|
||||||
global $newPath, $course, $db_base_course, $_configuration; |
|
||||||
|
|
||||||
$documentPath = $newPath.'courses/'.$course.'/document'; |
|
||||||
|
|
||||||
if (!@ $opendir = opendir($dir)) { |
|
||||||
return false; |
|
||||||
} |
|
||||||
|
|
||||||
while ($readdir = readdir($opendir)) { |
|
||||||
|
|
||||||
if ($readdir != '..' && $readdir != '.' && $readdir != '.htaccess') { |
|
||||||
|
|
||||||
$path = str_replace($documentPath, '', $dir.'/'.$readdir); |
|
||||||
$file_date = date("Y-m-d H:i:s", filemtime($dir.'/'.$readdir)); |
|
||||||
|
|
||||||
if (is_file($dir.'/'.$readdir)) { |
|
||||||
|
|
||||||
$file_size = filesize($dir.'/'.$readdir); |
|
||||||
|
|
||||||
$result = Database::query("SELECT id,visibility FROM `$db_base_course".$_configuration['db_glue']."document` WHERE path='".addslashes($path)."' LIMIT 0,1"); |
|
||||||
|
|
||||||
if (list ($id, $visibility) = Database::fetch_row($result)) { |
|
||||||
Database::query("UPDATE `$db_base_course".$_configuration['db_glue']."document` SET filetype='file',title='".addslashes($readdir)."',size='$file_size' WHERE id='$id' AND path='".addslashes($path)."'"); |
|
||||||
} else { |
|
||||||
Database::query("INSERT INTO `$db_base_course".$_configuration['db_glue']."document`(path,filetype,title,size) VALUES('".addslashes($path)."','file','".addslashes($readdir)."','$file_size')"); |
|
||||||
$id =Database::insert_id(); |
|
||||||
} |
|
||||||
|
|
||||||
$visibility = ($visibility == 'v') ? 1 : 0; |
|
||||||
Database::query("INSERT INTO `$db_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)) { |
|
||||||
|
|
||||||
$result = Database::query("SELECT id,visibility FROM `$db_base_course".$_configuration['db_glue']."document` WHERE path='".addslashes($path)."' LIMIT 0,1"); |
|
||||||
|
|
||||||
if (list ($id, $visibility) = Database::fetch_row($result)) { |
|
||||||
Database::query("UPDATE `$db_base_course".$_configuration['db_glue']."document` SET filetype='folder',title='".addslashes($readdir)."' WHERE id='$id' AND path='".addslashes($path)."'"); |
|
||||||
} else { |
|
||||||
Database::query("INSERT INTO `$db_base_course".$_configuration['db_glue']."document`(path,filetype,title) VALUES('".addslashes($path)."','folder','".addslashes($readdir)."')"); |
|
||||||
$id = Database::insert_id(); |
|
||||||
} |
|
||||||
|
|
||||||
$visibility = ($visibility == 'v') ? 1 : 0; |
|
||||||
Database::query("INSERT INTO `$db_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)) { |
|
||||||
return false; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
closedir($opendir); |
|
||||||
|
|
||||||
return true; |
|
||||||
} |
|
||||||
|
|
||||||
/* |
|
||||||
============================================================================== |
|
||||||
INIT SECTION |
|
||||||
============================================================================== |
|
||||||
*/ |
|
||||||
|
|
||||||
if (defined('SYSTEM_INSTALLATION') || defined('DOKEOS_COURSE_UPDATE')) { |
|
||||||
|
|
||||||
$newPath = str_replace('\\', '/', realpath('../..')).'/'; |
|
||||||
$oldPath = $_POST['updatePath']; |
|
||||||
|
|
||||||
$perm = api_get_permissions_for_new_directories(); |
|
||||||
|
|
||||||
foreach ($coursePath as $key => $course) { |
|
||||||
$db_base_course = $courseDB[$key]; |
|
||||||
@ unlink($oldPath.$course.'/document/.htaccess'); |
|
||||||
@ unlink($oldPath.$course.'/group/index.php'); |
|
||||||
|
|
||||||
if ($fp = @ fopen($oldPath.$course.'/group/index.php', 'w')) { |
|
||||||
fputs($fp, '<html></html>'); |
|
||||||
fclose($fp); |
|
||||||
} |
|
||||||
@ unlink($oldPath.$course.'/index.php'); |
|
||||||
|
|
||||||
if ($fp = @ fopen($oldPath.$course.'/index.php', 'w')) { |
|
||||||
fputs($fp, '<?php |
|
||||||
$cidReq = "'.$key.'"; |
|
||||||
$dbname = "'.str_replace($dbPrefixForm, '', $db_base_course).'"; |
|
||||||
|
|
||||||
include("../../main/course_home/course_home.php"); |
|
||||||
?>'); |
|
||||||
|
|
||||||
fclose($fp); |
|
||||||
} |
|
||||||
|
|
||||||
@ mkdir($oldPath.$course.'/temp', $perm); |
|
||||||
@ chmod($oldPath.$course.'/temp', $perm); |
|
||||||
@ rename($oldPath.$course, $newPath.'courses/'.$course); |
|
||||||
|
|
||||||
// Move group documents to document folder of the course |
|
||||||
$group_dir = $newPath.'courses/'.$course.'/group'; |
|
||||||
|
|
||||||
if ($dir = @ opendir($group_dir)) { |
|
||||||
while (($entry = readdir($dir)) !== false) { |
|
||||||
if ($entry != '.' && $entry != '..' && is_dir($group_dir.'/'.$entry)) { |
|
||||||
$from_dir = $group_dir.'/'.$entry; |
|
||||||
$to_dir = $newPath.'courses/'.$course.'/document/'.$entry; |
|
||||||
@ rename($from_dir, $to_dir); |
|
||||||
} |
|
||||||
} |
|
||||||
closedir($dir); |
|
||||||
} |
|
||||||
|
|
||||||
fill_document_table($newPath.'courses/'.$course.'/document'); |
|
||||||
|
|
||||||
Database::query("ALTER TABLE `$db_base_course".$_configuration['db_glue']."document` DROP `visibility`"); |
|
||||||
|
|
||||||
// Update item_properties of group documents |
|
||||||
$sql = "SELECT d.id AS doc_id, g.id AS group_id FROM `$db_base_course".$_configuration['db_glue']."group_info` g,`$db_base_course".$_configuration['db_glue']."document` d WHERE path LIKE CONCAT(g.secret_directory,'%')"; |
|
||||||
$res = Database::query($sql); |
|
||||||
|
|
||||||
while ($group_doc = Database::fetch_object($res)) { |
|
||||||
$sql = "UPDATE `$db_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."'"; |
|
||||||
Database::query($sql); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
if (defined('SYSTEM_INSTALLATION')) { |
|
||||||
|
|
||||||
// Write the Dokeos config file |
|
||||||
write_system_config_file($newPath.'main/inc/conf/configuration.php'); |
|
||||||
|
|
||||||
// Write a distribution file with the config as a backup for the admin |
|
||||||
write_system_config_file($newPath.'main/inc/conf/configuration.dist.php'); |
|
||||||
|
|
||||||
// Write a .htaccess file in the course repository |
|
||||||
write_courses_htaccess_file($urlAppendPath); |
|
||||||
|
|
||||||
require_once ('../inc/lib/fileManage.lib.php'); |
|
||||||
|
|
||||||
// First remove the upload/users directory in the new installation |
|
||||||
removeDir($newPath.'main/upload/users'); |
|
||||||
|
|
||||||
// Move the old user images to the new installation |
|
||||||
@ rename($oldPath.'main/img/users', $newPath.'main/upload/users'); |
|
||||||
|
|
||||||
if (!@ rename($oldPath.'main/inc/conf/configuration.php', $oldPath.'main/inc/conf/configuration.php.old')) |
|
||||||
{ |
|
||||||
unlink($oldPath.'main/inc/conf/configuration.php'); |
|
||||||
} |
|
||||||
} |
|
||||||
} else { |
|
||||||
echo 'You are not allowed here !'; |
|
||||||
} |
|
||||||
@ -1,839 +0,0 @@ |
|||||||
<?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 /license.txt */ |
|
||||||
/** |
|
||||||
============================================================================== |
|
||||||
* In this file we're working on a well-organised upgrade script to |
|
||||||
* upgrade directly from Dokeos 1.6.x to Dokeos 1.8.3 |
|
||||||
* |
|
||||||
* For this upgrade we assume there is an old_dokeos directory and the new |
|
||||||
* software is in a new_dokeos directory. While we're busy developing we |
|
||||||
* work in this one - large - separate file so not to disturb the other |
|
||||||
* existing classes - the existing code remains working. |
|
||||||
* |
|
||||||
* This script uses PEAR QuickForm and QuickFormController classes. |
|
||||||
* |
|
||||||
* First version |
|
||||||
* - ask for old version path |
|
||||||
* - check version (1.6.x or 1.8.x, no others supported at the moment) |
|
||||||
* - get settings from old version |
|
||||||
* - perform necessary upgrade functions based on version |
|
||||||
|
|
||||||
* Future improvements |
|
||||||
* - ask user if she agrees to detected version (chance to cancel) |
|
||||||
* - ability to do in-place upgrade |
|
||||||
* - ability to let old databases remain and clone them for new install so |
|
||||||
* Dokeos admins can have old and new version running side by side |
|
||||||
* |
|
||||||
* @package chamilo.install |
|
||||||
============================================================================== |
|
||||||
*/ |
|
||||||
/* |
|
||||||
* ABOUT DETECTING OLDER VERSIONS |
|
||||||
* Dokeos versions 1.6.x and 1.8.x have an installedVersion.inc.php file. |
|
||||||
* In 1.6.x they have a parameter $platformVersion, |
|
||||||
* in 1.8.x a parameter $dokeos_version. |
|
||||||
* The function get_installed_version($old_installation_path, $parameter) |
|
||||||
* can be used to detect version numbers. |
|
||||||
*/ |
|
||||||
|
|
||||||
/* |
|
||||||
============================================================================== |
|
||||||
INIT SECTION |
|
||||||
============================================================================== |
|
||||||
*/ |
|
||||||
session_start(); |
|
||||||
|
|
||||||
// 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 |
|
||||||
require_once 'HTML/QuickForm/Controller.php'; |
|
||||||
require_once 'HTML/QuickForm/Rule.php'; |
|
||||||
require_once 'HTML/QuickForm/Action/Display.php'; |
|
||||||
// |
|
||||||
|
|
||||||
require '../inc/installedVersion.inc.php'; |
|
||||||
require '../inc/lib/main_api.lib.php'; |
|
||||||
|
|
||||||
require '../lang/english/trad4all.inc.php'; |
|
||||||
require '../lang/english/install.inc.php'; |
|
||||||
require_once 'install_upgrade.lib.php'; |
|
||||||
require_once 'upgrade_lib.php'; |
|
||||||
|
|
||||||
define('SYSTEM_INSTALLATION', 1); |
|
||||||
define('MAX_COURSE_TRANSFER', 100); |
|
||||||
define('INSTALL_TYPE_UPDATE', 'update'); |
|
||||||
define('FORM_FIELD_DISPLAY_LENGTH', 40); |
|
||||||
define('DATABASE_FORM_FIELD_DISPLAY_LENGTH', 25); |
|
||||||
define('MAX_FORM_FIELD_LENGTH', 50); |
|
||||||
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_ALL); |
|
||||||
|
|
||||||
@set_time_limit(0); |
|
||||||
|
|
||||||
if (function_exists('ini_set')) { |
|
||||||
ini_set('memory_limit', -1); |
|
||||||
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_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'); // TODO: ... |
|
||||||
|
|
||||||
/* |
|
||||||
============================================================================== |
|
||||||
CLASSES |
|
||||||
============================================================================== |
|
||||||
*/ |
|
||||||
|
|
||||||
/** |
|
||||||
* Page in the install wizard to select the language which will be used during |
|
||||||
* the installation process. |
|
||||||
*/ |
|
||||||
class Page_Language extends HTML_QuickForm_Page { |
|
||||||
|
|
||||||
function get_title() { |
|
||||||
return get_lang('WelcomeToDokeosInstaller'); |
|
||||||
} |
|
||||||
|
|
||||||
function get_info() { |
|
||||||
return 'Please select the language you\'d like to use while installing:'; |
|
||||||
} |
|
||||||
|
|
||||||
function buildForm() { |
|
||||||
$this->_formBuilt = true; |
|
||||||
$this->addElement('select', 'install_language', get_lang('InstallationLanguage'), get_language_folder_list()); |
|
||||||
$buttons[0] = & HTML_QuickForm :: createElement('submit', $this->getButtonName('next'), get_lang('Next').' >>'); |
|
||||||
$this->addGroup($buttons, 'buttons', '', ' ', false); |
|
||||||
$this->setDefaultAction('next'); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Class for requirements page |
|
||||||
* This checks and informs about some requirements for installing Dokeos: |
|
||||||
* - necessary and optional extensions |
|
||||||
* - folders which have to be writable |
|
||||||
*/ |
|
||||||
class Page_Requirements extends HTML_QuickForm_Page { |
|
||||||
|
|
||||||
/** |
|
||||||
* this function checks if a php extension exists or not |
|
||||||
* |
|
||||||
* @param string $extentionName name of the php extension to be checked |
|
||||||
* @param boolean $echoWhenOk true => show ok when the extension exists |
|
||||||
* @author Christophe Gesché |
|
||||||
*/ |
|
||||||
function check_extension($extentionName) { |
|
||||||
if (extension_loaded($extentionName)) { |
|
||||||
return '<li>'.$extentionName.' - ok</li>'; |
|
||||||
} 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>'; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
function get_not_writable_folders() { |
|
||||||
$writable_folders = array('../inc/conf', '../upload', '../../archive', '../../courses', '../../home'); |
|
||||||
$not_writable = array(); |
|
||||||
$perm = api_get_permissions_for_new_directories(); |
|
||||||
foreach ($writable_folders as $index => $folder) { |
|
||||||
if (!is_writable($folder) && !@ chmod($folder, $perm)) { |
|
||||||
$not_writable[] = $folder; |
|
||||||
} |
|
||||||
} |
|
||||||
return $not_writable; |
|
||||||
} |
|
||||||
|
|
||||||
function get_title() { |
|
||||||
return get_lang("Requirements"); |
|
||||||
} |
|
||||||
|
|
||||||
function get_info() { |
|
||||||
$not_writable = $this->get_not_writable_folders(); |
|
||||||
|
|
||||||
if (count($not_writable) > 0) { |
|
||||||
$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[] = '<ul>'; |
|
||||||
foreach ($not_writable as $index => $folder) { |
|
||||||
$info[] = '<li>'.$folder.'</li>'; |
|
||||||
} |
|
||||||
$info[] = '</ul>'; |
|
||||||
$info[] = '</div>'; |
|
||||||
$this->disableNext = true; |
|
||||||
} 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[] = get_lang("WarningExistingDokeosInstallationDetected"); |
|
||||||
$info[] = '</div>'; |
|
||||||
} |
|
||||||
$info[] = '<strong>'.get_lang("ReadThoroughly").'</strong>'; |
|
||||||
$info[] = '<br />'; |
|
||||||
$info[] = get_lang("DokeosNeedFollowingOnServer"); |
|
||||||
$info[] = "<ul>"; |
|
||||||
$info[] = "<li>Webserver with PHP 5.x"; |
|
||||||
$info[] = '<ul>'; |
|
||||||
$info[] = $this->check_extension('standard'); |
|
||||||
$info[] = $this->check_extension('session'); |
|
||||||
$info[] = $this->check_extension('mysql'); |
|
||||||
$info[] = $this->check_extension('zlib'); |
|
||||||
$info[] = $this->check_extension('pcre'); |
|
||||||
$info[] = '</ul></li>'; |
|
||||||
$info[] = "<li>MySQL + login/password allowing to access and create at least one database</li>"; |
|
||||||
$info[] = "<li>Write access to web directory where Dokeos files have been put</li>"; |
|
||||||
$info[] = "</ul>"; |
|
||||||
$info[] = get_lang('MoreDetails').", <a href=\"../../installation_guide.html\" target=\"blank\">read the installation guide</a>."; |
|
||||||
return implode("\n",$info); |
|
||||||
} |
|
||||||
|
|
||||||
function buildForm() { |
|
||||||
global $updateFromVersion; |
|
||||||
$this->_formBuilt = true; |
|
||||||
$this->addElement('radio', 'installation_type', get_lang('InstallType'), get_lang('NewInstall'), 'new'); |
|
||||||
$update_group[0] = & HTML_QuickForm :: createElement('radio', 'installation_type', null, 'Update from Dokeos '.implode('|', $updateFromVersion).'', 'update'); |
|
||||||
//$this->addGroup($update_group, 'update_group', '', ' ', false); |
|
||||||
$prevnext[] = & $this->createElement('submit', $this->getButtonName('back'), '<< '.get_lang('Previous')); |
|
||||||
$prevnext[] = & $this->createElement('submit', $this->getButtonName('next'), get_lang('Next').' >>'); |
|
||||||
$not_writable = $this->get_not_writable_folders(); |
|
||||||
if (count($not_writable) > 0) { |
|
||||||
$el = $prevnext[1]; |
|
||||||
$el->updateAttributes('disabled="disabled"'); |
|
||||||
} |
|
||||||
$this->addGroup($prevnext, 'buttons', '', ' ', false); |
|
||||||
$this->setDefaultAction('next'); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Page in the install wizard to select the location of the old Dokeos installation. |
|
||||||
*/ |
|
||||||
class Page_LocationOldVersion extends HTML_QuickForm_Page { |
|
||||||
|
|
||||||
function get_title() { |
|
||||||
return 'Old version root path'; |
|
||||||
} |
|
||||||
|
|
||||||
function get_info() { |
|
||||||
return 'Give location of your old Dokeos installation '; |
|
||||||
} |
|
||||||
|
|
||||||
function buildForm() { |
|
||||||
$this->_formBuilt = true; |
|
||||||
$this->addElement('text', 'old_version_path', 'Old version root path'); |
|
||||||
$this->applyFilter('old_version_path', 'trim'); |
|
||||||
$this->addRule('old_version_path', get_lang('ThisFieldIsRequired'), 'required'); |
|
||||||
$this->addRule('old_version_path', get_lang('BadUpdatePath'), 'callback', 'check_update_path'); |
|
||||||
$prevnext[] = & $this->createElement('submit', $this->getButtonName('back'), '<< '.get_lang('Previous')); |
|
||||||
$prevnext[] = & $this->createElement('submit', $this->getButtonName('next'), get_lang('Next').' >>'); |
|
||||||
$this->addGroup($prevnext, 'buttons', '', ' ', false); |
|
||||||
$this->setDefaultAction('next'); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Class for license page |
|
||||||
* Displays the GNU GPL license that has to be accepted to install Dokeos. |
|
||||||
*/ |
|
||||||
class Page_License extends HTML_QuickForm_Page { |
|
||||||
function get_title() { |
|
||||||
return get_lang('Licence'); |
|
||||||
} |
|
||||||
|
|
||||||
function get_info() { |
|
||||||
return get_lang('DokeosLicenseInfo'); |
|
||||||
} |
|
||||||
|
|
||||||
function buildForm() { |
|
||||||
$this->_formBuilt = true; |
|
||||||
$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->addRule('license_accept',get_lang('ThisFieldIsRequired'),'required'); |
|
||||||
$prevnext[] = & $this->createElement('submit', $this->getButtonName('back'), '<< '.get_lang('Previous')); |
|
||||||
$prevnext[] = & $this->createElement('submit', $this->getButtonName('next'), get_lang('Next').' >>'); |
|
||||||
$this->addGroup($prevnext, 'buttons', '', ' ', false); |
|
||||||
$this->setDefaultAction('next'); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Class for database settings page |
|
||||||
* Displays a form where the user can enter the installation settings |
|
||||||
* regarding the databases - login and password, names, prefixes, single |
|
||||||
* or multiple databases, tracking or not... |
|
||||||
*/ |
|
||||||
class Page_DatabaseSettings extends HTML_QuickForm_Page { |
|
||||||
|
|
||||||
function get_title() { |
|
||||||
return get_lang('DBSetting'); |
|
||||||
} |
|
||||||
|
|
||||||
function get_info() { |
|
||||||
return get_lang('DBSettingIntro'); |
|
||||||
} |
|
||||||
|
|
||||||
function buildForm() { |
|
||||||
$this->_formBuilt = true; |
|
||||||
$this->addElement('text', 'database_host', get_lang("DBHost"), array ('size' => '40')); |
|
||||||
$this->addRule('database_host', 'ThisFieldIsRequired', 'required'); |
|
||||||
$this->addElement('text', 'database_username', get_lang("DBLogin"), array ('size' => '40')); |
|
||||||
$this->addElement('password', 'database_password', get_lang("DBPassword"), array ('size' => '40')); |
|
||||||
$this->addRule(array('database_host','database_username','database_password'),get_lang('CouldNotConnectToDatabase'),new ValidateDatabaseConnection()); |
|
||||||
$this->addElement('text', 'database_prefix', get_lang("DbPrefixForm"), array ('size' => '40')); |
|
||||||
$this->addElement('text', 'database_main_db', get_lang("MainDB"), array ('size' => '40')); |
|
||||||
$this->addRule('database_main_db', 'ThisFieldIsRequired', 'required'); |
|
||||||
$this->addElement('text', 'database_tracking', get_lang("StatDB"), array ('size' => '40')); |
|
||||||
$this->addRule('database_tracking', 'ThisFieldIsRequired', 'required'); |
|
||||||
$this->addElement('text', 'database_scorm', get_lang("ScormDB"), array ('size' => '40')); |
|
||||||
$this->addRule('database_scorm', 'ThisFieldIsRequired', 'required'); |
|
||||||
$this->addElement('text', 'database_user', get_lang("UserDB"), array ('size' => '40')); |
|
||||||
$this->addRule('database_user', 'ThisFieldIsRequired', 'required'); |
|
||||||
//$this->addElement('text', 'database_repository', get_lang("RepositoryDatabase"), array ('size' => '40')); |
|
||||||
//$this->addRule('database_repository', 'ThisFieldIsRequired', 'required'); |
|
||||||
//$this->addElement('text', 'database_weblcms', get_lang("WeblcmsDatabase"), array ('size' => '40')); |
|
||||||
//$this->addRule('database_weblcms', 'ThisFieldIsRequired', 'required'); |
|
||||||
//$this->addElement('text', 'database_personal_calendar', get_lang("PersonalCalendarDatabase"), array ('size' => '40')); |
|
||||||
//$this->addRule('database_personal_calendar', 'ThisFieldIsRequired', 'required'); |
|
||||||
//$this->addElement('text', 'database_personal_messenger', get_lang("PersonalMessageDatabase"), array ('size' => '40')); |
|
||||||
//$this->addRule('database_personal_messenger', 'ThisFieldIsRequired', 'required'); |
|
||||||
//$this->addElement('text', 'database_profiler', get_lang("ProfilerDatabase"), array ('size' => '40')); |
|
||||||
//$this->addRule('database_profiler', 'ThisFieldIsRequired', 'required'); |
|
||||||
|
|
||||||
$enable_tracking[] = & $this->createElement('radio', 'enable_tracking', null, get_lang("Yes"), 1); |
|
||||||
$enable_tracking[] = & $this->createElement('radio', 'enable_tracking', null, get_lang("No"), 0); |
|
||||||
$this->addGroup($enable_tracking, 'tracking', get_lang("EnableTracking"), ' ', false); |
|
||||||
$several_db[] = & $this->createElement('radio', 'database_single', null, get_lang("One"), 1); |
|
||||||
$several_db[] = & $this->createElement('radio', 'database_single', null, get_lang("Several"), 0); |
|
||||||
$this->addGroup($several_db, 'db', get_lang("SingleDb"), ' ', false); |
|
||||||
$prevnext[] = & $this->createElement('submit', $this->getButtonName('back'), '<< '.get_lang('Previous')); |
|
||||||
$prevnext[] = & $this->createElement('submit', $this->getButtonName('next'), get_lang('Next').' >>'); |
|
||||||
$this->addGroup($prevnext, 'buttons', '', ' ', false); |
|
||||||
$this->setDefaultAction('next'); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
class ValidateDatabaseConnection extends HTML_QuickForm_Rule { |
|
||||||
|
|
||||||
public function validate($parameters) { |
|
||||||
return Database::connect(array('server' => $parameters[0], 'username' => $parameters[1], 'password' => $parameters[2])) !== false; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Page in the install wizard in which some config settings are asked to the |
|
||||||
* user. |
|
||||||
*/ |
|
||||||
class Page_ConfigSettings extends HTML_QuickForm_Page { |
|
||||||
|
|
||||||
function get_title() { |
|
||||||
return get_lang('CfgSetting'); |
|
||||||
} |
|
||||||
|
|
||||||
function get_info() { |
|
||||||
return get_lang('ConfigSettingsInfo'); |
|
||||||
} |
|
||||||
|
|
||||||
function buildForm() { |
|
||||||
$this->_formBuilt = true; |
|
||||||
$languages = array (); |
|
||||||
$languages['dutch'] = 'dutch'; |
|
||||||
$this->addElement('select', 'platform_language', get_lang("MainLang"), get_language_folder_list()); |
|
||||||
$this->addElement('text', 'platform_url', get_lang("DokeosURL"), array ('size' => '40')); |
|
||||||
$this->addRule('platform_url', get_lang('ThisFieldIsRequired'), 'required'); |
|
||||||
$this->addElement('text', 'admin_email', get_lang("AdminEmail"), array ('size' => '40')); |
|
||||||
$this->addRule('admin_email', get_lang('ThisFieldIsRequired'), 'required'); |
|
||||||
$this->addRule('admin_email', get_lang('WrongEmail'), 'email'); |
|
||||||
$this->addElement('text', 'admin_lastname', get_lang("AdminLastName"), array ('size' => '40')); |
|
||||||
$this->addRule('admin_lastname', get_lang('ThisFieldIsRequired'), 'required'); |
|
||||||
$this->addElement('text', 'admin_firstname', get_lang("AdminFirstName"), array ('size' => '40')); |
|
||||||
$this->addRule('admin_firstname', get_lang('ThisFieldIsRequired'), 'required'); |
|
||||||
$this->addElement('text', 'admin_phone', get_lang("AdminPhone"), array ('size' => '40')); |
|
||||||
$this->addElement('text', 'admin_username', get_lang("AdminLogin"), array ('size' => '40')); |
|
||||||
$this->addRule('admin_username', get_lang('ThisFieldIsRequired'), 'required'); |
|
||||||
$this->addElement('text', 'admin_password', get_lang("AdminPass"), array ('size' => '40')); |
|
||||||
$this->addRule('admin_password', get_lang('ThisFieldIsRequired'), 'required'); |
|
||||||
$this->addElement('text', 'platform_name', get_lang("CampusName"), array ('size' => '40')); |
|
||||||
$this->addRule('platform_name', get_lang('ThisFieldIsRequired'), 'required'); |
|
||||||
$this->addElement('text', 'organization_name', get_lang("InstituteShortName"), array ('size' => '40')); |
|
||||||
$this->addRule('organization_name', get_lang('ThisFieldIsRequired'), 'required'); |
|
||||||
$this->addElement('text', 'organization_url', get_lang("InstituteURL"), array ('size' => '40')); |
|
||||||
$this->addRule('organization_url', get_lang('ThisFieldIsRequired'), 'required'); |
|
||||||
$encrypt[] = & $this->createElement('radio', 'encrypt_password', null, get_lang('Yes'), 1); |
|
||||||
$encrypt[] = & $this->createElement('radio', 'encrypt_password', null, get_lang('No'), 0); |
|
||||||
$this->addGroup($encrypt, 'tracking', get_lang("EncryptUserPass"), ' ', false); |
|
||||||
$self_reg[] = & $this->createElement('radio', 'self_reg', null, get_lang('Yes'), 1); |
|
||||||
$self_reg[] = & $this->createElement('radio', 'self_reg', null, get_lang('No'), 0); |
|
||||||
$this->addGroup($self_reg, 'tracking', get_lang("AllowSelfReg"), ' ', false); |
|
||||||
$self_reg_teacher[] = & $this->createElement('radio', 'self_reg_teacher', null, get_lang('Yes'), 1); |
|
||||||
$self_reg_teacher[] = & $this->createElement('radio', 'self_reg_teacher', null, get_lang('No'), 0); |
|
||||||
$this->addGroup($self_reg_teacher, 'tracking', get_lang("AllowSelfRegProf"), ' ', false); |
|
||||||
$prevnext[] = & $this->createElement('submit', $this->getButtonName('back'), '<< '.get_lang('Previous')); |
|
||||||
$prevnext[] = & $this->createElement('submit', $this->getButtonName('next'), get_lang('Next').' >>'); |
|
||||||
$this->addGroup($prevnext, 'buttons', '', ' ', false); |
|
||||||
$this->setDefaultAction('next'); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Page in the install wizard in which a final overview of all settings is |
|
||||||
* displayed. |
|
||||||
*/ |
|
||||||
class Page_ConfirmSettings extends HTML_QuickForm_Page { |
|
||||||
|
|
||||||
function get_title() { |
|
||||||
return get_lang('LastCheck'); |
|
||||||
} |
|
||||||
|
|
||||||
function get_info() { |
|
||||||
return 'Here are the values you entered |
|
||||||
<br /> |
|
||||||
<strong>Print this page to remember your password and other settings</strong>'; |
|
||||||
} |
|
||||||
|
|
||||||
function buildForm() { |
|
||||||
$wizard = $this->controller; |
|
||||||
$values = $wizard->exportValues(); |
|
||||||
$this->addElement('static', 'confirm_platform_language', get_lang("MainLang"), $values['platform_language']); |
|
||||||
$this->addElement('static', 'confirm_platform_url', get_lang("DokeosURL"), $values['platform_url']); |
|
||||||
$this->addElement('static', 'confirm_admin_email', get_lang("AdminEmail"), $values['admin_email']); |
|
||||||
$this->addElement('static', 'confirm_admin_lastname', get_lang("AdminLastName"), $values['admin_lastname']); |
|
||||||
$this->addElement('static', 'confirm_admin_firstname', get_lang("AdminFirstName"), $values['admin_firstname']); |
|
||||||
$this->addElement('static', 'confirm_admin_phone', get_lang("AdminPhone"), $values['admin_phone']); |
|
||||||
$this->addElement('static', 'confirm_admin_username', get_lang("AdminLogin"), $values['admin_username']); |
|
||||||
$this->addElement('static', 'confirm_admin_password', get_lang("AdminPass"), $values['admin_password']); |
|
||||||
$this->addElement('static', 'confirm_platform_name', get_lang("CampusName"), $values['platform_name']); |
|
||||||
$this->addElement('static', 'confirm_organization_name', get_lang("InstituteShortName"), $values['organization_name']); |
|
||||||
$this->addElement('static', 'confirm_organization_url', get_lang("InstituteURL"), $values['organization_url']); |
|
||||||
$prevnext[] = & $this->createElement('submit', $this->getButtonName('back'), '<< '.get_lang('Previous')); |
|
||||||
$prevnext[] = & $this->createElement('submit', $this->getButtonName('next'), get_lang('Next').' >>'); |
|
||||||
$this->addGroup($prevnext, 'buttons', '', ' ', false); |
|
||||||
$this->setDefaultAction('next'); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
/** |
|
||||||
* Class to render a page in the install wizard. |
|
||||||
*/ |
|
||||||
class ActionDisplay extends HTML_QuickForm_Action_Display { |
|
||||||
|
|
||||||
/** |
|
||||||
* Displays the HTML-code of a page in the wizard |
|
||||||
* @param HTML_Quickform_Page $page The page to display. |
|
||||||
*/ |
|
||||||
function _renderForm(& $current_page) { |
|
||||||
global $charset; |
|
||||||
|
|
||||||
global $dokeos_version, $installType, $updateFromVersion; |
|
||||||
$renderer = & $current_page->defaultRenderer(); |
|
||||||
$current_page->setRequiredNote('<font color="#FF0000">*</font> '.get_lang('ThisFieldIsRequired')); |
|
||||||
$element_template = "\n\t<tr>\n\t\t<td valign=\"top\"><!-- BEGIN required --><span style=\"color: #ff0000\">*</span> <!-- END required -->{label}</td>\n\t\t<td valign=\"top\" align=\"left\"><!-- BEGIN error --><span style=\"color: #ff0000;font-size:x-small;margin:2px;\">{error}</span><br /><!-- END error -->\t{element}</td>\n\t</tr>"; |
|
||||||
$renderer->setElementTemplate($element_template); |
|
||||||
$header_template = "\n\t<tr>\n\t\t<td valign=\"top\" colspan=\"2\">{header}</td>\n\t</tr>"; |
|
||||||
$renderer->setHeaderTemplate($header_template); |
|
||||||
HTML_QuickForm :: setRequiredNote('<font color="red">*</font> <small>'.get_lang('ThisFieldIsRequired').'</small>'); |
|
||||||
$current_page->accept($renderer); |
|
||||||
?> |
|
||||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> |
|
||||||
<head> |
|
||||||
<title>-- Dokeos - upgrade to version <?php echo $dokeos_version; ?></title>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo $charset; ?>" />
|
|
||||||
<link rel="stylesheet" href="../css/chamilo/default.css" type="text/css"/> |
|
||||||
</head> |
|
||||||
<body dir="<?php echo get_lang('text_dir'); ?>">
|
|
||||||
<div id="header1"> |
|
||||||
Dokeos - upgrade to version <?php echo $dokeos_version; ?><?php if($installType == 'new') echo ' - New installation'; else if($installType == 'update') echo ' - Update from Dokeos '.implode('|',$updateFromVersion); ?> |
|
||||||
</div> |
|
||||||
<div style="float: left; background-color:#EFEFEF;margin-right: 20px;padding: 10px;"> |
|
||||||
<img src="../img/bluelogo.gif" alt="logo"/> |
|
||||||
<?php |
|
||||||
|
|
||||||
$all_pages = $current_page->controller->_pages; |
|
||||||
$total_number_of_pages = count($all_pages); |
|
||||||
$current_page_number = 0; |
|
||||||
$page_number = 0; |
|
||||||
echo '<ol>'; |
|
||||||
foreach($all_pages as $index => $page) { |
|
||||||
$page_number++; |
|
||||||
if ($page->get_title() == $current_page->get_title()) { |
|
||||||
$current_page_number = $page_number; |
|
||||||
echo '<li style="font-weight: bold;">'.$page->get_title().'</li>'; |
|
||||||
} else { |
|
||||||
echo '<li>'.$page->get_title().'</li>'; |
|
||||||
} |
|
||||||
} |
|
||||||
echo '</ol>'; |
|
||||||
echo '</div>'; |
|
||||||
echo '<div style="margin: 10px;">'; |
|
||||||
echo '<h2>'.get_lang('Step').' '.$current_page_number.' '.get_lang('of').' '.$total_number_of_pages.' – '.$current_page->get_title().'</h2>'; |
|
||||||
echo '<div>'; |
|
||||||
echo $current_page->get_info(); |
|
||||||
echo '</div>'; |
|
||||||
echo $renderer->toHtml(); |
|
||||||
?> |
|
||||||
</div> |
|
||||||
<div style="clear:both;"></div> |
|
||||||
<div id="footer"> |
|
||||||
© <?php echo $dokeos_version; ?> |
|
||||||
</div> |
|
||||||
</body> |
|
||||||
</html> |
|
||||||
<?php |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Class for form processing |
|
||||||
* Here happens the actual installation action after collecting |
|
||||||
* all the required data. |
|
||||||
*/ |
|
||||||
class ActionProcess extends HTML_QuickForm_Action { |
|
||||||
|
|
||||||
function perform(& $page, $actionName) { |
|
||||||
|
|
||||||
global $charset; |
|
||||||
|
|
||||||
global $dokeos_version, $installType, $updateFromVersion; |
|
||||||
$values = $page->controller->exportValues(); |
|
||||||
?> |
|
||||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> |
|
||||||
<head> |
|
||||||
<title>-- Dokeos installation -- version <?php echo $dokeos_version; ?></title>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo $charset; ?>" />
|
|
||||||
<link rel="stylesheet" href="../css/chamilo/default.css" type="text/css"/> |
|
||||||
</head> |
|
||||||
<body dir="<?php echo get_lang('text_dir'); ?>">
|
|
||||||
<div style="background-color:#4171B5;color:white;font-size:x-large;"> |
|
||||||
Dokeos installation - version <?php echo $dokeos_version; ?><?php if($installType == 'new') echo ' - New installation'; else if($installType == 'update') echo ' - Update from Dokeos '.implode('|',$updateFromVersion); ?> |
|
||||||
</div> |
|
||||||
<div style="margin:50px;"> |
|
||||||
<img src="../img/bluelogo.gif" alt="logo" align="right"/> |
|
||||||
<?php |
|
||||||
echo '<pre>'; |
|
||||||
|
|
||||||
global $repository_database; |
|
||||||
global $weblcms_database; |
|
||||||
global $personal_calendar_database; |
|
||||||
global $user_database; |
|
||||||
global $personal_messenger_database; |
|
||||||
global $profiler_database; |
|
||||||
|
|
||||||
$repository_database = $values['database_repository']; |
|
||||||
$weblcms_database = $values['database_weblcms']; |
|
||||||
$personal_calendar_database = $values['database_personal_calendar']; |
|
||||||
$user_database = $values['database_user']; |
|
||||||
$personal_messenger_database = $values['database_personal_messenger']; |
|
||||||
$profiler_database = $values['database_profiler']; |
|
||||||
|
|
||||||
/*full_database_install($values); |
|
||||||
full_file_install($values); |
|
||||||
create_admin_in_user_table($values); |
|
||||||
create_default_categories_in_weblcms();*/ |
|
||||||
echo "<p>Performing upgrade to latest version....</p>"; |
|
||||||
|
|
||||||
//upgrade_16x_to_180($values); |
|
||||||
|
|
||||||
echo '</pre>'; |
|
||||||
$page->controller->container(true); |
|
||||||
?> |
|
||||||
<a class="portal" href="../../index.php"><?php echo get_lang('GoToYourNewlyCreatedPortal'); ?></a>
|
|
||||||
</div> |
|
||||||
</body> |
|
||||||
</html> |
|
||||||
<?php |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
/* |
|
||||||
============================================================================== |
|
||||||
FUNCTIONS |
|
||||||
============================================================================== |
|
||||||
*/ |
|
||||||
|
|
||||||
function display_upgrade_header($text_dir, $dokeos_version, $install_type, $update_from_version) { |
|
||||||
?> |
|
||||||
<!DOCTYPE html |
|
||||||
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
|
||||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml"> |
|
||||||
<head> |
|
||||||
<title>— <?php echo get_lang('DokeosInstallation').' — '.get_lang('Version_').' '.$dokeos_version; ?></title>
|
|
||||||
<style type="text/css" media="screen, projection"> |
|
||||||
/*<![CDATA[*/ |
|
||||||
@import "../css/chamilo/default.css"; |
|
||||||
/*]]>*/ |
|
||||||
</style> |
|
||||||
<?php if(!empty($charset)){ ?> |
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo $charset ?>" />
|
|
||||||
<?php } ?> |
|
||||||
</head> |
|
||||||
<body dir="<?php echo $text_dir ?>">
|
|
||||||
|
|
||||||
<div id="header"> |
|
||||||
<div id="header1"><?php echo get_lang('DokeosInstallation').' — '.get_lang('Version_').' '.$dokeos_version; ?><?php if($install_type == 'new') echo ' – '.get_lang('NewInstallation'); else if($install_type == 'update') echo ' – '.get_lang('UpdateFromDokeosVersion').implode('|',$update_from_version); ?></div>
|
|
||||||
<div class="clear"></div> |
|
||||||
<div id="header2"> </div> |
|
||||||
<div id="header3"> </div> |
|
||||||
</div> |
|
||||||
<?php |
|
||||||
} |
|
||||||
|
|
||||||
function display_installation_overview() { |
|
||||||
echo '<div id="installation_steps">'; |
|
||||||
echo '<img src="../img/bluelogo.gif" hspace="10" vspace="10" alt="Dokeos logo" />'; |
|
||||||
echo '<ol>'; |
|
||||||
echo '<li ' . step_active('1') . '> ' . get_lang('InstallationLanguage') . '</li>'; |
|
||||||
echo '<li ' . step_active('2') . '> ' . get_lang('Requirements') . '</li>'; |
|
||||||
echo '<li ' . step_active('3') . '> ' . get_lang('Licence') . '</li>'; |
|
||||||
echo '<li ' . step_active('4') . '> ' . get_lang('DBSetting') . '</li>'; |
|
||||||
echo '<li ' . step_active('5') . '> ' . get_lang('CfgSetting') . '</li>'; |
|
||||||
echo '<li ' . step_active('6') . '> ' . get_lang('PrintOverview') . '</li>'; |
|
||||||
echo '<li ' . step_active('7') . '> ' . get_lang('Installing') . '</li>'; |
|
||||||
echo '</ol>'; |
|
||||||
echo '</div>'; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* This function prints class=active_step $current_step=$param |
|
||||||
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University |
|
||||||
*/ |
|
||||||
function step_active($this_step) { |
|
||||||
global $current_active_step; |
|
||||||
if ($current_active_step == $this_step) { |
|
||||||
return ' class="current_step" '; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
// Rule to check update path |
|
||||||
function check_update_path($path) { |
|
||||||
global $update_from_version; |
|
||||||
// Make sure path has a trailing / |
|
||||||
$path = substr($path, -1) != '/' ? $path.'/' : $path; |
|
||||||
// Check the path |
|
||||||
if (file_exists($path)) { |
|
||||||
//search for 1.6.x installation |
|
||||||
$version = get_installed_version($path, 'platformVersion'); |
|
||||||
|
|
||||||
//search for 1.8.x installation |
|
||||||
//if (! isset($version) || $version == '') { |
|
||||||
// $version = get_installed_version($path, 'dokeos_version'); |
|
||||||
//} |
|
||||||
|
|
||||||
if (in_array($version, $update_from_version)) { |
|
||||||
return true; |
|
||||||
} else { |
|
||||||
return false; |
|
||||||
} |
|
||||||
} |
|
||||||
return false; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* This function returns the installed version of |
|
||||||
* the older installation to upgrade by checking the |
|
||||||
* claroline/inc/installedVersion.inc.php file. |
|
||||||
*/ |
|
||||||
function get_installed_version($old_installation_path, $parameter) { |
|
||||||
if (file_exists($old_installation_path.'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 |
|
||||||
include($old_installation_path.$version_info_file); |
|
||||||
if (isset($$parameter)) { |
|
||||||
return $$parameter; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* This function returns a the value of a parameter from the configuration file |
|
||||||
* of a previous installation. |
|
||||||
* |
|
||||||
* IMPORTANT |
|
||||||
* - Before Dokeos 1.8 the main code folder was called 'claroline'. Since Dokeos 1.8 |
|
||||||
* this folder is called 'main' -> we have to make a difference based on previous |
|
||||||
* version. |
|
||||||
* - The version may be in the config file or in the installedVersion file... |
|
||||||
* |
|
||||||
* WARNING - this function relies heavily on global variables $updateFromConfigFile |
|
||||||
* and $configFile, and also changes these globals. This can be rewritten. |
|
||||||
* |
|
||||||
* @param string $param the parameter which the value is returned for |
|
||||||
* @return string the value of the parameter |
|
||||||
* @author Olivier Brouckaert |
|
||||||
*/ |
|
||||||
function get_config_param($param, $path) { |
|
||||||
global $configFile, $updateFromConfigFile; |
|
||||||
|
|
||||||
if (empty($updateFromConfigFile)) { |
|
||||||
if (file_exists($path.'claroline/include/config.inc.php')) { |
|
||||||
$updateFromConfigFile = 'claroline/include/config.inc.php'; |
|
||||||
} elseif (file_exists($path.'claroline/inc/conf/claro_main.conf.php')) { |
|
||||||
$updateFromConfigFile = 'claroline/inc/conf/claro_main.conf.php'; |
|
||||||
} else { |
|
||||||
return; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
//echo "reading from file $path$updateFromConfigFile, which exists..."; |
|
||||||
|
|
||||||
if (is_array($configFile) && isset($configFile[$param])) { |
|
||||||
return $configFile[$param]; |
|
||||||
} elseif (file_exists($path.$updateFromConfigFile)) { |
|
||||||
$configFile = array(); |
|
||||||
|
|
||||||
$temp = file($path.$updateFromConfigFile); |
|
||||||
$val = ''; |
|
||||||
foreach ($temp as $enreg) { |
|
||||||
|
|
||||||
if (strstr($enreg, '=')) { |
|
||||||
$enreg = explode('=', $enreg); |
|
||||||
|
|
||||||
if ($enreg[0][0] == '$') { |
|
||||||
list ($enreg[1]) = explode(' //', $enreg[1]); |
|
||||||
|
|
||||||
$enreg[0] = trim(str_replace('$', '', $enreg[0])); |
|
||||||
$enreg[1] = str_replace('\"', '"', preg_replace('/^"|"$/', '', substr(trim($enreg[1]), 0, -1))); |
|
||||||
|
|
||||||
if (strtolower($enreg[1]) == 'true') { |
|
||||||
$enreg[1] = 1; |
|
||||||
} |
|
||||||
if (strtolower($enreg[1]) == 'false') { |
|
||||||
$enreg[1] = 0; |
|
||||||
} else { |
|
||||||
$implode_string = ' '; |
|
||||||
|
|
||||||
if (!strstr($enreg[1], '." ".') && strstr($enreg[1], '.$')) { |
|
||||||
$enreg[1] = str_replace('.$', '." ".$', $enreg[1]); |
|
||||||
$implode_string = ''; |
|
||||||
} |
|
||||||
|
|
||||||
$tmp = explode('." ".', $enreg[1]); |
|
||||||
|
|
||||||
foreach ($tmp as $tmp_key => $tmp_val) { |
|
||||||
if (preg_match('/^\$[a-zA-Z_][a-zA-Z0-9_]*$/', $tmp_val)) { |
|
||||||
$tmp[$tmp_key] = get_config_param(str_replace('$', '', $tmp_val), $path); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
$enreg[1] = implode($implode_string, $tmp); |
|
||||||
} |
|
||||||
|
|
||||||
$configFile[$enreg[0]] = $enreg[1]; |
|
||||||
|
|
||||||
if ($enreg[0] == $param) { |
|
||||||
$val = $enreg[1]; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
return $val; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/* |
|
||||||
============================================================================== |
|
||||||
MAIN CODE |
|
||||||
============================================================================== |
|
||||||
*/ |
|
||||||
global $current_active_step; |
|
||||||
$current_active_step = '1'; |
|
||||||
$install_type = 'update'; |
|
||||||
//display_upgrade_header($text_dir, $dokeos_version, $install_type, $update_from_version); |
|
||||||
//display_installation_overview(); |
|
||||||
|
|
||||||
// Create a new wizard |
|
||||||
$wizard = & new HTML_QuickForm_Controller('regWizard', true); |
|
||||||
|
|
||||||
//Add pages to wizard - path to follow for upgrade |
|
||||||
//$wizard->addPage(new Page_Language('page_language')); |
|
||||||
//$wizard->addPage(new Page_Requirements('page_requirements')); |
|
||||||
$wizard->addPage(new Page_LocationOldVersion('page_location_old_version')); |
|
||||||
$values = $wizard->exportValues(); |
|
||||||
|
|
||||||
if (isset($values['old_version_path']) && $values['old_version_path'] != '/var/www/html/old_version/') { |
|
||||||
$path = $values['old_version_path']; |
|
||||||
$defaults['platform_language'] = get_config_param('platformLanguage',$path); |
|
||||||
$defaults['platform_url'] = 'http://'.$_SERVER['HTTP_HOST'].$urlAppendPath.'/'; |
|
||||||
//to keep debug output readable: |
|
||||||
//$defaults['license'] = 'GNU GPL v2'; |
|
||||||
//actual license: |
|
||||||
$defaults['license'] = implode("\n", file('../../documentation/license.txt')); |
|
||||||
$defaults['database_host'] = get_config_param('dbHost',$path); |
|
||||||
$defaults['database_main_db'] = get_config_param('mainDbName',$path); |
|
||||||
$defaults['database_tracking'] = get_config_param('statsDbName',$path); |
|
||||||
$defaults['database_scorm'] = get_config_param('scormDbName',$path); |
|
||||||
$defaults['database_user'] = get_config_param('user_personal_database',$path); |
|
||||||
//$defaults['database_repository'] = 'dokeos_repository'; |
|
||||||
//$defaults['database_weblcms'] = 'dokeos_weblcms'; |
|
||||||
$defaults['database_username'] = get_config_param('dbLogin',$path); |
|
||||||
$defaults['database_password'] = get_config_param('dbPass',$path); |
|
||||||
$defaults['database_prefix'] = get_config_param('dbNamePrefix',$path); |
|
||||||
$defaults['enable_tracking'] = get_config_param('is_trackingEnabled',$path); |
|
||||||
$defaults['database_single'] = get_config_param('singleDbEnabled',$path); |
|
||||||
$defaults['admin_lastname'] = 'Doe'; |
|
||||||
$defaults['admin_firstname'] = mt_rand(0,1)?'John':'Jane'; |
|
||||||
$defaults['admin_email'] = get_config_param('emailAdministrator',$path); |
|
||||||
$defaults['admin_username'] = 'admin'; |
|
||||||
$defaults['admin_password'] = api_generate_password(); |
|
||||||
$defaults['admin_phone'] = get_config_param('administrator["phone"]',$path); |
|
||||||
$defaults['platform_name'] = get_config_param('siteName',$path); |
|
||||||
$defaults['encrypt_password'] = 1; |
|
||||||
$defaults['organization_name'] = get_config_param('institution["name"]',$path); |
|
||||||
$defaults['organization_url'] = get_config_param('institution["url"]',$path); |
|
||||||
if (get_config_param('userPasswordCrypted',$path)==1) { |
|
||||||
$defaults['encrypt_password'] = 'md5'; |
|
||||||
} elseif (get_config_param('userPasswordCrypted',$path)==0){ |
|
||||||
$defaults['encrypt_password'] = 'none'; |
|
||||||
} |
|
||||||
//$defaults['encrypt_password'] = get_config_param('userPasswordCrypted',$path); |
|
||||||
$defaults['self_reg'] = get_config_param('allowSelfReg',$path); |
|
||||||
} else { |
|
||||||
//old version path not correct yet |
|
||||||
} |
|
||||||
|
|
||||||
$wizard->addPage(new Page_License('page_license')); |
|
||||||
$wizard->addPage(new Page_DatabaseSettings('page_databasesettings')); |
|
||||||
$wizard->addPage(new Page_ConfigSettings('page_configsettings')); |
|
||||||
$wizard->addPage(new Page_ConfirmSettings('page_confirmsettings')); |
|
||||||
|
|
||||||
$defaults['install_language'] = 'english'; |
|
||||||
//$defaults['old_version_path'] = '/var/www/html/old_version/'; |
|
||||||
$defaults['old_version_path'] = ''; |
|
||||||
|
|
||||||
// Set the default values |
|
||||||
$wizard->setDefaults($defaults); |
|
||||||
|
|
||||||
// Add the process action to the wizard |
|
||||||
$wizard->addAction('process', new ActionProcess()); |
|
||||||
|
|
||||||
// Add the display action to the wizard |
|
||||||
$wizard->addAction('display', new ActionDisplay()); |
|
||||||
|
|
||||||
// Set the installation language |
|
||||||
$install_language = $wizard->exportValue('page_language', 'install_language'); |
|
||||||
require_once '../lang/english/trad4all.inc.php'; |
|
||||||
require_once '../lang/english/install.inc.php'; |
|
||||||
include_once '../lang/'.$install_language.'/trad4all.inc.php'; |
|
||||||
include_once '../lang/'.$install_language.'/install.inc.php'; |
|
||||||
|
|
||||||
// Set default platform language to the selected install language |
|
||||||
$defaults['platform_language'] = $install_language; |
|
||||||
$wizard->setDefaults($defaults); |
|
||||||
|
|
||||||
// Start the wizard |
|
||||||
$wizard->run(); |
|
||||||
|
|
||||||
// Set the installation language |
|
||||||
$install_language = $wizard->exportValue('page_language', 'install_language'); |
|
||||||
require_once '../lang/english/trad4all.inc.php'; |
|
||||||
require_once '../lang/english/install.inc.php'; |
|
||||||
include_once '../lang/'.$install_language.'/trad4all.inc.php'); |
|
||||||
include_once '../lang/'.$install_language.'/install.inc.php'); |
|
||||||
|
|
||||||
//$values = $wizard->exportValues(); |
|
||||||
@ -1,181 +0,0 @@ |
|||||||
<?php |
|
||||||
/* |
|
||||||
============================================================================== |
|
||||||
Dokeos - elearning and course management software |
|
||||||
|
|
||||||
Copyright (c) 2007, various contributors |
|
||||||
|
|
||||||
For a full list of contributors, see "credits.txt". |
|
||||||
The full license can be read in "license.txt". |
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or |
|
||||||
modify it under the terms of the GNU General Public License |
|
||||||
as published by the Free Software Foundation; either version 2 |
|
||||||
of the License, or (at your option) any later version. |
|
||||||
|
|
||||||
See the GNU General Public License for more details. |
|
||||||
|
|
||||||
Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium |
|
||||||
Mail: info@dokeos.com |
|
||||||
============================================================================== |
|
||||||
*/ |
|
||||||
/** |
|
||||||
============================================================================== |
|
||||||
* This file contains functions used by the new upgrade script. |
|
||||||
============================================================================== |
|
||||||
*/ |
|
||||||
/* |
|
||||||
============================================================================== |
|
||||||
CONSTANTS |
|
||||||
============================================================================== |
|
||||||
*/ |
|
||||||
|
|
||||||
/* |
|
||||||
============================================================================== |
|
||||||
FUNCTIONS |
|
||||||
============================================================================== |
|
||||||
*/ |
|
||||||
|
|
||||||
/** |
|
||||||
* see |
|
||||||
* - update-db-1.6.x-1.8.0.inc.php |
|
||||||
* - update-db-scorm-1.6.x-1.8.0.inc.php |
|
||||||
* - migrate-db-1.6.x-1.8.0-post.sql |
|
||||||
* - migrate-db-1.6.x-1.8.0-pre.sql |
|
||||||
* @todo remove code duplication in this function |
|
||||||
*/ |
|
||||||
function upgrade_16x_to_180($values) { |
|
||||||
|
|
||||||
$is_single_database = $values['database_single']; |
|
||||||
$main_database = $values['database_main_db']; |
|
||||||
$tracking_database = $values['database_tracking']; |
|
||||||
$user_database = $values['database_user']; |
|
||||||
|
|
||||||
/* |
|
||||||
PRE SECTION |
|
||||||
UPGRADES TO GENERAL DATABASES before course upgrades |
|
||||||
*/ |
|
||||||
|
|
||||||
//MAIN database section |
|
||||||
//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'); |
|
||||||
if (count($main_query_list) > 0) { |
|
||||||
Database::select_db($main_database); |
|
||||||
foreach ($main_query_list as $this_query) { |
|
||||||
Database::query($this_query); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
//TRACKING database section |
|
||||||
//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'); |
|
||||||
if (count($tracking_query_list) > 0) { |
|
||||||
Database::select_db($tracking_database); |
|
||||||
foreach ($tracking_query_list as $this_query) { |
|
||||||
Database::query($this_query); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
//USER database section |
|
||||||
//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'); |
|
||||||
if (count($user_query_list) > 0) { |
|
||||||
Database::select_db($user_database); |
|
||||||
foreach ($user_query_list as $this_query) { |
|
||||||
Database::query($this_query); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/* |
|
||||||
COURSE SECTION |
|
||||||
UPGRADES TO COURSE DATABASES |
|
||||||
*/ |
|
||||||
$prefix = ''; |
|
||||||
global $singleDbForm, $_configuration; |
|
||||||
if ($singleDbForm) { |
|
||||||
$prefix = $_configuration['table_prefix']; |
|
||||||
} |
|
||||||
//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'); |
|
||||||
if (count($course_query_list) > 0) { |
|
||||||
//upgrade course databases |
|
||||||
} |
|
||||||
|
|
||||||
/* |
|
||||||
SCORM SECTION |
|
||||||
*/ |
|
||||||
//see include('update-db-scorm-1.6.x-1.8.0.inc.php'); |
|
||||||
//deploy in separate function! |
|
||||||
|
|
||||||
/* |
|
||||||
POST SECTION |
|
||||||
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'); |
|
||||||
if (count($main_query_list) > 0) { |
|
||||||
Database::select_db($main_database); |
|
||||||
foreach ($main_query_list as $this_query) { |
|
||||||
Database::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-pre.sql', 'stats'); |
|
||||||
if (count($tracking_query_list) > 0) { |
|
||||||
Database::select_db($tracking_database); |
|
||||||
foreach ($tracking_query_list as $this_query) { |
|
||||||
Database::query($this_query); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
$user_query_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-post.sql', 'user'); |
|
||||||
if (count($user_query_list) > 0) { |
|
||||||
Database::select_db($user_database); |
|
||||||
foreach ($user_query_list as $this_query) { |
|
||||||
Database::query($this_query); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
$prefix = ''; |
|
||||||
if ($singleDbForm) { |
|
||||||
$prefix = $_configuration['table_prefix']; |
|
||||||
} |
|
||||||
//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'); |
|
||||||
if (count($course_query_list) > 0) { |
|
||||||
//upgrade course databases |
|
||||||
Database::select_db($main_database); |
|
||||||
$sql_result = Database::query("SELECT code,db_name,directory,course_language FROM course WHERE target_course_code IS NULL"); |
|
||||||
if (Database::num_rows($sql_result) > 0) { |
|
||||||
while ($row = Database::fetch_array($sql_result)) { |
|
||||||
$course_list[] = $row; |
|
||||||
} |
|
||||||
//for each course in the course list... |
|
||||||
foreach ($course_list as $this_course) { |
|
||||||
Database::select_db($this_course['db_name']); |
|
||||||
//... execute the list of course update queries |
|
||||||
foreach ($course_query_list as $this_query) { |
|
||||||
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); |
|
||||||
} |
|
||||||
Database::query($this_query); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Note - there is no 1.8.1, |
|
||||||
* 1.8.2 is the version that came after 1.8.0 |
|
||||||
* see |
|
||||||
* - update-db-1.8.0-1.8.2.inc.php |
|
||||||
* - migrate-db-1.8.0-1.8.2-pre.sql |
|
||||||
*/ |
|
||||||
function upgrade_180_to_182($values) { |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
function upgrade_182_to_183($values) { |
|
||||||
//no database/file structure changes needed? |
|
||||||
} |
|
||||||
@ -1,547 +0,0 @@ |
|||||||
<?php //$id: $
|
|
||||||
/* For licensing terms, see /license.txt */ |
|
||||||
/** |
|
||||||
============================================================================== |
|
||||||
* This file contains functions used by the install and upgrade scripts. |
|
||||||
* The current functions are used to |
|
||||||
* - fill existing tables with data; |
|
||||||
* - write a .htaccess file in the courses folder for extra security; |
|
||||||
* - write the system config file containing important settings like database names |
|
||||||
* and paswords and other options. |
|
||||||
* |
|
||||||
* Ideas for future additions: |
|
||||||
* - a function get_old_version_settings to retrieve the config file settings |
|
||||||
* of older versions before upgrading. |
|
||||||
============================================================================== |
|
||||||
*/ |
|
||||||
/* |
|
||||||
============================================================================== |
|
||||||
CONSTANTS |
|
||||||
============================================================================== |
|
||||||
*/ |
|
||||||
define("SYSTEM_MAIN_DATABASE_FILE", "dokeos_main.sql"); |
|
||||||
define("COUNTRY_DATA_FILENAME", "country_data.csv"); |
|
||||||
define("COURSES_HTACCESS_FILENAME", "htaccess.dist"); |
|
||||||
define("SYSTEM_CONFIG_FILENAME", "configuration.dist.php"); |
|
||||||
|
|
||||||
require_once api_get_path(LIBRARY_PATH).'database.lib.php'; |
|
||||||
|
|
||||||
/* |
|
||||||
============================================================================== |
|
||||||
DATABASE FUNCTIONS |
|
||||||
============================================================================== |
|
||||||
*/ |
|
||||||
|
|
||||||
/** |
|
||||||
* We assume this function is called from install scripts that reside inside the install folder. |
|
||||||
*/ |
|
||||||
function set_file_folder_permissions() { |
|
||||||
@chmod('.', 0755); //set permissions on install dir |
|
||||||
@chmod('..', 0755); //set permissions on parent dir of install dir |
|
||||||
@chmod('country_data.csv.csv', 0755); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Fills the countries table with a list of countries. |
|
||||||
*/ |
|
||||||
function fill_track_countries_table($track_countries_table) { |
|
||||||
$file_path = dirname(__FILE__).'/'.COUNTRY_DATA_FILENAME; |
|
||||||
$add_country_sql = "LOAD DATA INFILE '".Database::escape_string($file_path)."' INTO TABLE $track_countries_table FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\'';"; |
|
||||||
@ Database::query($add_country_sql); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Add's a .htaccess file to the courses directory |
|
||||||
* @param string $url_append The path from your webroot to your chamilo root |
|
||||||
*/ |
|
||||||
function write_courses_htaccess_file($url_append) { |
|
||||||
$file_path = dirname(__FILE__).'/'.COURSES_HTACCESS_FILENAME; |
|
||||||
$content = file_get_contents($file_path); |
|
||||||
$content = str_replace('{DOKEOS_URL_APPEND_PATH}', $url_append, $content); |
|
||||||
$fp = @ fopen('../../courses/.htaccess', 'w'); |
|
||||||
if ($fp) { |
|
||||||
fwrite($fp, $content); |
|
||||||
return fclose($fp); |
|
||||||
} |
|
||||||
return false; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Write the main system config file |
|
||||||
* @param string $path Path to the config file |
|
||||||
*/ |
|
||||||
function write_system_config_file($path) { |
|
||||||
|
|
||||||
global $dbHostForm; |
|
||||||
global $dbUsernameForm; |
|
||||||
global $dbPassForm; |
|
||||||
global $enableTrackingForm; |
|
||||||
global $singleDbForm; |
|
||||||
global $dbPrefixForm; |
|
||||||
global $dbNameForm; |
|
||||||
global $dbStatsForm; |
|
||||||
global $dbScormForm; |
|
||||||
global $dbUserForm; |
|
||||||
global $urlForm; |
|
||||||
global $pathForm; |
|
||||||
global $urlAppendPath; |
|
||||||
global $languageForm; |
|
||||||
global $encryptPassForm; |
|
||||||
global $installType; |
|
||||||
global $updatePath; |
|
||||||
global $session_lifetime; |
|
||||||
global $new_version; |
|
||||||
global $new_version_stable; |
|
||||||
|
|
||||||
$root_sys = api_add_trailing_slash(str_replace('\\', '/', realpath($pathForm))); |
|
||||||
$content = file_get_contents(dirname(__FILE__).'/'.SYSTEM_CONFIG_FILENAME); |
|
||||||
|
|
||||||
$config['{DATE_GENERATED}'] = date('r'); |
|
||||||
$config['{DATABASE_HOST}'] = $dbHostForm; |
|
||||||
$config['{DATABASE_USER}'] = $dbUsernameForm; |
|
||||||
$config['{DATABASE_PASSWORD}'] = $dbPassForm; |
|
||||||
$config['TRACKING_ENABLED'] = true_false($enableTrackingForm); |
|
||||||
$config['SINGLE_DATABASE'] = true_false($singleDbForm); |
|
||||||
$config['{COURSE_TABLE_PREFIX}'] = ($singleDbForm ? 'crs_' : ''); |
|
||||||
$config['{DATABASE_GLUE}'] = ($singleDbForm ? '_' : '`.`'); |
|
||||||
$config['{DATABASE_PREFIX}'] = $dbPrefixForm; |
|
||||||
$config['{DATABASE_MAIN}'] = $dbNameForm; |
|
||||||
$config['{DATABASE_STATS}'] = (($singleDbForm && empty($dbStatsForm)) ? $dbNameForm : $dbStatsForm); |
|
||||||
$config['{DATABASE_SCORM}'] = (($singleDbForm && empty($dbScormForm)) ? $dbNameForm : $dbScormForm); |
|
||||||
$config['{DATABASE_PERSONAL}'] =(($singleDbForm && empty($dbUserForm)) ? $dbNameForm : $dbUserForm); |
|
||||||
$config['{ROOT_WEB}'] = $urlForm; |
|
||||||
$config['{ROOT_SYS}'] = $root_sys; |
|
||||||
$config['{URL_APPEND_PATH}'] = $urlAppendPath; |
|
||||||
$config['{PLATFORM_LANGUAGE}'] = $languageForm; |
|
||||||
$config['{SECURITY_KEY}'] = md5(uniqid(rand().time())); |
|
||||||
$config['{ENCRYPT_PASSWORD}'] = $encryptPassForm; |
|
||||||
|
|
||||||
$config['SESSION_LIFETIME'] = $session_lifetime; |
|
||||||
$config['{NEW_VERSION}'] = $new_version; |
|
||||||
$config['NEW_VERSION_STABLE'] = true_false($new_version_stable); |
|
||||||
|
|
||||||
foreach ($config as $key => $value) { |
|
||||||
$content = str_replace($key, $value, $content); |
|
||||||
} |
|
||||||
|
|
||||||
$fp = @ fopen($path, 'w'); |
|
||||||
|
|
||||||
if (!$fp) { |
|
||||||
echo '<strong><font color="red">Your script doesn\'t have write access to the config directory</font></strong><br /> |
|
||||||
<em>('.str_replace('\\', '/', realpath($path)).')</em><br /><br /> |
|
||||||
You probably do not have write access on Chamilo root directory, |
|
||||||
i.e. you should <em>CHMOD 777</em> or <em>755</em> or <em>775</em>.<br /><br /> |
|
||||||
Your problems can be related on two possible causes:<br /> |
|
||||||
<ul> |
|
||||||
<li>Permission problems.<br />Try initially with <em>chmod -R 777</em> and increase restrictions gradually.</li> |
|
||||||
<li>PHP is running in <a href="http://www.php.net/manual/en/features.safe-mode.php" target="_blank">Safe-Mode</a>. If possible, try to switch it off.</li> |
|
||||||
</ul> |
|
||||||
<a href="http://forum.chamilo.org/" target="_blank">Read about this problem in Support Forum</a><br /><br /> |
|
||||||
Please go back to step 5. |
|
||||||
<p><input type="submit" name="step5" value="< Back" /></p> |
|
||||||
</td></tr></table></form></body></html>'; |
|
||||||
exit (); |
|
||||||
} |
|
||||||
|
|
||||||
fwrite($fp, $content); |
|
||||||
fclose($fp); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Creates the structure of the main database and fills it |
|
||||||
* with data. Placeholder symbols in the main database file |
|
||||||
* have to be replaced by the settings entered by the user during installation. |
|
||||||
* |
|
||||||
* @param array $installation_settings list of settings entered by the user |
|
||||||
* @param string optional path about the script for database |
|
||||||
* @return void |
|
||||||
*/ |
|
||||||
function load_main_database($installation_settings, $db_script = '') { |
|
||||||
if (!empty($db_script)) { |
|
||||||
$sql_text = file_get_contents($db_script); |
|
||||||
} else { |
|
||||||
$sql_text = file_get_contents(SYSTEM_MAIN_DATABASE_FILE); |
|
||||||
} |
|
||||||
|
|
||||||
//replace symbolic parameters with user-specified values |
|
||||||
foreach ($installation_settings as $key => $value) { |
|
||||||
$sql_text = str_replace($key, Database::escape_string($value), $sql_text); |
|
||||||
} |
|
||||||
|
|
||||||
//split in array of sql strings |
|
||||||
$sql_instructions = array(); |
|
||||||
$success = split_sql_file($sql_instructions, $sql_text); |
|
||||||
|
|
||||||
//execute the sql instructions |
|
||||||
$count = count($sql_instructions); |
|
||||||
for ($i = 0; $i < $count; $i++) { |
|
||||||
$this_sql_query = $sql_instructions[$i]['query']; |
|
||||||
Database::query($this_sql_query); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Creates the structure of the stats database |
|
||||||
* @param string Name of the file containing the SQL script inside the install directory |
|
||||||
*/ |
|
||||||
function load_database_script($db_script) { |
|
||||||
$sql_text = file_get_contents($db_script); |
|
||||||
|
|
||||||
//split in array of sql strings |
|
||||||
$sql_instructions = array(); |
|
||||||
$success = split_sql_file($sql_instructions, $sql_text); |
|
||||||
|
|
||||||
//execute the sql instructions |
|
||||||
$count = count($sql_instructions); |
|
||||||
for ($i = 0; $i < $count; $i++) { |
|
||||||
$this_sql_query = $sql_instructions[$i]['query']; |
|
||||||
Database::query($this_sql_query); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Function copied and adapted from phpMyAdmin 2.6.0 PMA_splitSqlFile (also GNU GPL) |
|
||||||
* |
|
||||||
* Removes comment lines and splits up large sql files into individual queries |
|
||||||
* |
|
||||||
* Last revision: September 23, 2001 - gandon |
|
||||||
* |
|
||||||
* @param array the splitted sql commands |
|
||||||
* @param string the sql commands |
|
||||||
* @param integer the MySQL release number (because certains php3 versions |
|
||||||
* can't get the value of a constant from within a function) |
|
||||||
* |
|
||||||
* @return boolean always true |
|
||||||
* |
|
||||||
* @access public |
|
||||||
*/ |
|
||||||
function split_sql_file(&$ret, $sql) { |
|
||||||
// do not trim, see bug #1030644 |
|
||||||
//$sql = trim($sql); |
|
||||||
$sql = rtrim($sql, "\n\r"); |
|
||||||
$sql_len = strlen($sql); |
|
||||||
$char = ''; |
|
||||||
$string_start = ''; |
|
||||||
$in_string = false; |
|
||||||
$nothing = true; |
|
||||||
$time0 = time(); |
|
||||||
|
|
||||||
for ($i = 0; $i < $sql_len; ++$i) { |
|
||||||
$char = $sql[$i]; |
|
||||||
|
|
||||||
// We are in a string, check for not escaped end of strings except for |
|
||||||
// backquotes that can't be escaped |
|
||||||
if ($in_string) { |
|
||||||
for (;;) { |
|
||||||
$i = strpos($sql, $string_start, $i); |
|
||||||
// No end of string found -> add the current substring to the |
|
||||||
// returned array |
|
||||||
if (!$i) { |
|
||||||
$ret[] = $sql; |
|
||||||
return true; |
|
||||||
} |
|
||||||
// Backquotes or no backslashes before quotes: it's indeed the |
|
||||||
// end of the string -> exit the loop |
|
||||||
elseif ($string_start == '`' || $sql[$i - 1] != '\\') { |
|
||||||
$string_start = ''; |
|
||||||
$in_string = false; |
|
||||||
break; |
|
||||||
} |
|
||||||
// one or more Backslashes before the presumed end of string... |
|
||||||
else { |
|
||||||
// ... first checks for escaped backslashes |
|
||||||
$j = 2; |
|
||||||
$escaped_backslash = false; |
|
||||||
while ($i - $j > 0 && $sql[$i - $j] == '\\') { |
|
||||||
$escaped_backslash = !$escaped_backslash; |
|
||||||
$j++; |
|
||||||
} |
|
||||||
// ... if escaped backslashes: it's really the end of the |
|
||||||
// string -> exit the loop |
|
||||||
if ($escaped_backslash) { |
|
||||||
$string_start = ''; |
|
||||||
$in_string = false; |
|
||||||
break; |
|
||||||
} |
|
||||||
// ... else loop |
|
||||||
else { |
|
||||||
$i++; |
|
||||||
} |
|
||||||
} // end if...elseif...else |
|
||||||
} // end for |
|
||||||
} // end if (in string) |
|
||||||
|
|
||||||
// lets skip comments (/*, -- and #) |
|
||||||
elseif (($char == '-' && $sql_len > $i + 2 && $sql[$i + 1] == '-' && $sql[$i + 2] <= ' ') || $char == '#' || ($char == '/' && $sql_len > $i + 1 && $sql[$i + 1] == '*')) { |
|
||||||
$i = strpos($sql, $char == '/' ? '*/' : "\n", $i); |
|
||||||
// didn't we hit end of string? |
|
||||||
if ($i === false) { |
|
||||||
break; |
|
||||||
} |
|
||||||
if ($char == '/') $i++; |
|
||||||
} |
|
||||||
|
|
||||||
// We are not in a string, first check for delimiter... |
|
||||||
elseif ($char == ';') { |
|
||||||
// if delimiter found, add the parsed part to the returned array |
|
||||||
$ret[] = array('query' => substr($sql, 0, $i), 'empty' => $nothing); |
|
||||||
$nothing = true; |
|
||||||
$sql = ltrim(substr($sql, min($i + 1, $sql_len))); |
|
||||||
$sql_len = strlen($sql); |
|
||||||
if ($sql_len) { |
|
||||||
$i = -1; |
|
||||||
} else { |
|
||||||
// The submited statement(s) end(s) here |
|
||||||
return true; |
|
||||||
} |
|
||||||
} // end elseif (is delimiter) |
|
||||||
|
|
||||||
// ... then check for start of a string,... |
|
||||||
elseif (($char == '"') || ($char == '\'') || ($char == '`')) { |
|
||||||
$in_string = true; |
|
||||||
$nothing = false; |
|
||||||
$string_start = $char; |
|
||||||
} // end elseif (is start of string) |
|
||||||
|
|
||||||
elseif ($nothing) { |
|
||||||
$nothing = false; |
|
||||||
} |
|
||||||
|
|
||||||
// loic1: send a fake header each 30 sec. to bypass browser timeout |
|
||||||
$time1 = time(); |
|
||||||
if ($time1 >= $time0 + 30) { |
|
||||||
$time0 = $time1; |
|
||||||
header('X-pmaPing: Pong'); |
|
||||||
} // end if |
|
||||||
} // end for |
|
||||||
|
|
||||||
// add any rest to the returned array |
|
||||||
if (!empty($sql) && preg_match('@[^[:space:]]+@', $sql)) { |
|
||||||
$ret[] = array('query' => $sql, 'empty' => $nothing); |
|
||||||
} |
|
||||||
|
|
||||||
return true; |
|
||||||
} // end of the 'split_sql_file()' function |
|
||||||
|
|
||||||
/** |
|
||||||
* Get an SQL file's contents |
|
||||||
* |
|
||||||
* This function bases its parsing on the pre-set format of the specific SQL files in |
|
||||||
* the install/upgrade procedure: |
|
||||||
* Lines starting with "--" are comments (but need to be taken into account as they also hold sections names) |
|
||||||
* Other lines are considered to be one-line-per-query lines (this is checked quickly by this function) |
|
||||||
* @param string File to parse (in the current directory) |
|
||||||
* @param string Section to return |
|
||||||
* @param boolean Print (true) or hide (false) error texts when they occur |
|
||||||
*/ |
|
||||||
function get_sql_file_contents($file, $section, $print_errors = true) { |
|
||||||
//check given parameters |
|
||||||
if (empty($file)) { |
|
||||||
$error = "Missing name of file to parse in get_sql_file_contents()"; |
|
||||||
if ($print_errors) echo $error; |
|
||||||
return false; |
|
||||||
} |
|
||||||
if (!in_array($section, array('main', 'user', 'stats', 'scorm', 'course'))) { |
|
||||||
$error = "Section '$section' is not authorized in get_sql_file_contents()"; |
|
||||||
if ($print_errors) echo $error; |
|
||||||
return false; |
|
||||||
} |
|
||||||
$filepath = getcwd().'/'.$file; |
|
||||||
if (!is_file($filepath) or !is_readable($filepath)) { |
|
||||||
$error = "File $filepath not found or not readable in get_sql_file_contents()"; |
|
||||||
if ($print_errors) echo $error; |
|
||||||
return false; |
|
||||||
} |
|
||||||
//read the file in an array |
|
||||||
$file_contents = file($filepath); |
|
||||||
if (!is_array($file_contents) or count($file_contents) < 1) { |
|
||||||
$error = "File $filepath looks empty in get_sql_file_contents()"; |
|
||||||
if ($print_errors) echo $error; |
|
||||||
return false; |
|
||||||
} |
|
||||||
|
|
||||||
//prepare the resulting array |
|
||||||
$section_contents = array(); |
|
||||||
$record = false; |
|
||||||
foreach ($file_contents as $index => $line) { |
|
||||||
if (substr($line, 0, 2) == '--') { |
|
||||||
//This is a comment. Check if section name, otherwise ignore |
|
||||||
$result = array(); |
|
||||||
if (preg_match('/^-- xx([A-Z]*)xx/', $line, $result)) { //we got a section name here |
|
||||||
if ($result[1] == strtoupper($section)) { |
|
||||||
//we have the section we are looking for, start recording |
|
||||||
$record = true; |
|
||||||
} else { |
|
||||||
//we have another section's header. If we were recording, stop now and exit loop |
|
||||||
if ($record) { |
|
||||||
break; |
|
||||||
} |
|
||||||
$record = false; |
|
||||||
} |
|
||||||
} |
|
||||||
} else { |
|
||||||
if ($record) { |
|
||||||
if (!empty($line)) { |
|
||||||
$section_contents[] = $line; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
//now we have our section's SQL statements group ready, return |
|
||||||
return $section_contents; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Tries to detect browser's language. |
|
||||||
* @return string Returns a language identificator, i.e. 'english', 'spanish', ... |
|
||||||
*/ |
|
||||||
function detect_browser_language() { |
|
||||||
static $language_index = array( |
|
||||||
'ar' => 'arabic', |
|
||||||
'ast' => 'asturian', |
|
||||||
'bg' => 'bulgarian', |
|
||||||
'bs' => 'bosnian', |
|
||||||
'ca' => 'catalan', |
|
||||||
'zh' => 'simpl_chinese', |
|
||||||
'zh-tw' => 'trad_chinese', |
|
||||||
'cs' => 'czech', |
|
||||||
'da' => 'danish', |
|
||||||
'prs' => 'dari', |
|
||||||
'de' => 'german', |
|
||||||
'el' => 'greek', |
|
||||||
'en' => 'english', |
|
||||||
'es' => 'spanish', |
|
||||||
'eo' => 'esperanto', |
|
||||||
'eu' => 'euskera', |
|
||||||
'fa' => 'persian', |
|
||||||
'fr' => 'french', |
|
||||||
'fur' => 'friulian', |
|
||||||
'gl' => 'galician', |
|
||||||
'ka' => 'georgian', |
|
||||||
'hr' => 'croatian', |
|
||||||
'he' => 'hebrew', |
|
||||||
'id' => 'indonesian', |
|
||||||
'it' => 'italian', |
|
||||||
'ko' => 'korean', |
|
||||||
'lv' => 'latvian', |
|
||||||
'lt' => 'lithuanian', |
|
||||||
'mk' => 'macedonian', |
|
||||||
'hu' => 'hungarian', |
|
||||||
'ms' => 'malay', |
|
||||||
'nl' => 'dutch', |
|
||||||
'ja' => 'japanese', |
|
||||||
'no' => 'norwegian', |
|
||||||
'oc' => 'occitan', |
|
||||||
'ps' => 'pashto', |
|
||||||
'pl' => 'polish', |
|
||||||
'pt' => 'portuguese', |
|
||||||
'pt-br' => 'brazilian', |
|
||||||
'ro' => 'romanian', |
|
||||||
'qu' => 'quechua_cusco', |
|
||||||
'ru' => 'russian', |
|
||||||
'sk' => 'slovak', |
|
||||||
'sl' => 'slovenian', |
|
||||||
'sr' => 'serbian', |
|
||||||
'fi' => 'finnish', |
|
||||||
'sv' => 'swedish', |
|
||||||
'th' => 'thai', |
|
||||||
'tr' => 'turkce', |
|
||||||
'uk' => 'ukrainian', |
|
||||||
'vi' => 'vietnamese', |
|
||||||
'sw' => 'swahili', |
|
||||||
'yo' => 'yoruba' |
|
||||||
); |
|
||||||
|
|
||||||
$system_available_languages = & get_language_folder_list(); |
|
||||||
|
|
||||||
$accept_languages = strtolower(str_replace('_', '-', $_SERVER['HTTP_ACCEPT_LANGUAGE'])); |
|
||||||
|
|
||||||
foreach ($language_index as $code => $language) { |
|
||||||
if (strpos($accept_languages, $code) === 0) { |
|
||||||
if (!empty($system_available_languages[$language])) { |
|
||||||
return $language; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
$user_agent = strtolower(str_replace('_', '-', $_SERVER['HTTP_USER_AGENT'])); |
|
||||||
|
|
||||||
foreach ($language_index as $code => $language) { |
|
||||||
if (preg_match("/[[( ]{$code}[;,_-)]/", $user_agent)) { |
|
||||||
if (!empty($system_available_languages[$language])) { |
|
||||||
return $language; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
return 'english'; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Returns a list of language directories. |
|
||||||
*/ |
|
||||||
function & get_language_folder_list() { |
|
||||||
static $result; |
|
||||||
if (!is_array($result)) { |
|
||||||
$result = array(); |
|
||||||
$exceptions = array('.', '..', 'CVS', '.svn'); |
|
||||||
$search = array('_latin', '_unicode', '_corporate', '_org' , '_KM', '_'); |
|
||||||
$replace_with = array(' (Latin)', ' (unicode)', ' (corporate)', ' (org)', ' (KM)', ' '); |
|
||||||
$dirname = api_get_path(SYS_LANG_PATH); |
|
||||||
$handle = opendir($dirname); |
|
||||||
while ($entries = readdir($handle)) { |
|
||||||
if (in_array($entries, $exceptions)) { |
|
||||||
continue; |
|
||||||
} |
|
||||||
if (is_dir($dirname.$entries)) { |
|
||||||
$result[$entries] = ucwords(str_replace($search, $replace_with, $entries)); |
|
||||||
} |
|
||||||
} |
|
||||||
closedir($handle); |
|
||||||
asort($result); |
|
||||||
} |
|
||||||
return $result; |
|
||||||
} |
|
||||||
|
|
||||||
// TODO: Maybe within the main API there is already a suitable function? |
|
||||||
function my_directory_to_array($directory) { |
|
||||||
$array_items = array(); |
|
||||||
if ($handle = opendir($directory)) { |
|
||||||
while (false !== ($file = readdir($handle))) { |
|
||||||
if ($file != "." && $file != "..") { |
|
||||||
if (is_dir($directory. "/" . $file)) { |
|
||||||
$array_items = array_merge($array_items, my_directory_to_array($directory. '/' . $file)); |
|
||||||
$file = $directory . "/" . $file; |
|
||||||
$array_items[] = preg_replace("/\/\//si", '/', $file); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
closedir($handle); |
|
||||||
} |
|
||||||
return $array_items; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Adds a new document to the database - specific to version 1.8.0 |
|
||||||
* |
|
||||||
* @param array $_course |
|
||||||
* @param string $path |
|
||||||
* @param string $filetype |
|
||||||
* @param int $filesize |
|
||||||
* @param string $title |
|
||||||
* @return id if inserted document |
|
||||||
*/ |
|
||||||
function add_document_180($_course, $path, $filetype, $filesize, $title, $comment = null) { |
|
||||||
$table_document = Database::get_course_table(TABLE_DOCUMENT, $_course['dbName']); |
|
||||||
$sql = "INSERT INTO $table_document |
|
||||||
(`path`,`filetype`,`size`,`title`, `comment`) |
|
||||||
VALUES ('$path','$filetype','$filesize','". |
|
||||||
Database::escape_string($title)."', '$comment')"; |
|
||||||
if (Database::query($sql)) { |
|
||||||
//display_message("Added to database (id ".Database::insert_id().")!"); |
|
||||||
return Database::insert_id(); |
|
||||||
} else { |
|
||||||
//display_error("The uploaded file could not be added to the database (".Database::error().")!"); |
|
||||||
return false; |
|
||||||
} |
|
||||||
} |
|
||||||
@ -0,0 +1,42 @@ |
|||||||
|
<?php |
||||||
|
require_once api_get_path(SYS_CODE_PATH).'exercice/question.class.php'; |
||||||
|
|
||||||
|
class TestExerciseLib extends UnitTestCase { |
||||||
|
/*public $eQuestion; |
||||||
|
|
||||||
|
public function TestExerciseLib() { |
||||||
|
$this->UnitTestCase(''); |
||||||
|
} |
||||||
|
|
||||||
|
public function setUp() { |
||||||
|
|
||||||
|
$this->eQuestion = new Question(); |
||||||
|
} |
||||||
|
|
||||||
|
public function tearDown() { |
||||||
|
$this->eQuestion = null; |
||||||
|
}*/ |
||||||
|
/** |
||||||
|
* @param int question id |
||||||
|
* @param boolean only answers |
||||||
|
* @param boolean origin i.e = learnpath |
||||||
|
* @param int current item from the list of questions |
||||||
|
* @param int number of total questions |
||||||
|
*/ |
||||||
|
|
||||||
|
function testshowQuestion() { |
||||||
|
global $_course; |
||||||
|
$questionId = 1; |
||||||
|
$current_item = 1 ; |
||||||
|
$total_item = 1; |
||||||
|
//$objQuestionTmp = $question->read($questionId); |
||||||
|
$res = showQuestion($questionId, $onlyAnswers=false, $origin=false,$current_item, $total_item); |
||||||
|
$this->assertTrue(is_null($res)); |
||||||
|
var_dump($res); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
?> |
||||||
@ -0,0 +1,45 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
class TestFillBlanksClass extends UnitTestCase { |
||||||
|
|
||||||
|
public $fFillBlanks; |
||||||
|
|
||||||
|
public function TestFillBlanksClass() { |
||||||
|
$this->UnitTestCase(''); |
||||||
|
} |
||||||
|
|
||||||
|
public function setUp() { |
||||||
|
$this->fFillBlanks = new FillBlanks(); |
||||||
|
} |
||||||
|
|
||||||
|
public function tearDown() { |
||||||
|
$this->fFillBlanks = null; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* function which redifines Question::createAnswersForm |
||||||
|
* @param the formvalidator instance |
||||||
|
*/ |
||||||
|
/* |
||||||
|
function testcreateAnswersForm() { |
||||||
|
$form = new FormValidator('introduction_text'); |
||||||
|
$res = $this->fFillBlanks->createAnswersForm($form); |
||||||
|
$this->assertTrue(is_null($res)); |
||||||
|
var_dump($res); |
||||||
|
}*/ |
||||||
|
|
||||||
|
/** |
||||||
|
* abstract function which creates the form to create / edit the answers of the question |
||||||
|
* @param the formvalidator instance |
||||||
|
*/ |
||||||
|
/* |
||||||
|
function testprocessAnswersCreation() { |
||||||
|
global $charset; |
||||||
|
$form = new FormValidator('introduction_text'); |
||||||
|
$res = $this->fFillBlanks->processAnswersCreation($form); |
||||||
|
$this->assertTrue(is_null($res)); |
||||||
|
var_dump($res); |
||||||
|
}*/ |
||||||
|
|
||||||
|
} |
||||||
|
?> |
||||||
@ -0,0 +1,29 @@ |
|||||||
|
<?php |
||||||
|
class TestFreeanswer extends UnitTestCase { |
||||||
|
|
||||||
|
/** |
||||||
|
* function which redifines Question::createAnswersForm |
||||||
|
* @param the formvalidator instance |
||||||
|
*/ |
||||||
|
|
||||||
|
function testcreateAnswersForm () { |
||||||
|
$form = new FormValidator('exercise_admin', 'post', api_get_self().'?exerciseId='.$_GET['exerciseId']); |
||||||
|
$res =FreeAnswer::createAnswersForm($form); |
||||||
|
$this->assertTrue(is_null($res)); |
||||||
|
//var_dump($res); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* abstract function which creates the form to create / edit the answers of the question |
||||||
|
* @param the formvalidator instance |
||||||
|
*/ |
||||||
|
|
||||||
|
function testprocessAnswersCreation () { |
||||||
|
$form = new FormValidator('exercise_admin', 'post', api_get_self().'?exerciseId='.$_GET['exerciseId']); |
||||||
|
$res =FreeAnswer::processAnswersCreation($form); |
||||||
|
$this->assertTrue(is_null($res)); |
||||||
|
//var_dump($res); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
?> |
||||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue