@ -1,4 +1,7 @@
<?php // $Id: upgrade.php 22577 2009-08-03 04:31:24Z yannoo $
// TODO: Ivan, 13-FEB-2010: Is this file needed? It looks like unfinished business.
/* For licensing terms, see /dokeos_license.txt */
/**
==============================================================================
@ -43,43 +46,43 @@
*/
session_start();
ini_set('include_path',ini_get('include_path').PATH_SEPARATOR.'../inc/lib/pear');
// TODO: It is not a good idea to refer to external PEAR packages due to version/customizations related problems.
ini_set('include_path', ini_get('include_path').PATH_SEPARATOR.'../inc/lib/pear');
//echo ini_get('include_path'); //DEBUG
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 '../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') ;
require '../lang/english/trad4all.inc.php' ;
require '../lang/english/install.inc.php' ;
require_once 'install_upgrade.lib.php' ;
require_once 'upgrade_lib.php' ;
define('DOKEOS_INSTALL',1);
define('MAX_COURSE_TRANSFER',100);
define('DOKEOS_INSTALL', 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');
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);
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');
$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: ...
/*
==============================================================================
@ -91,18 +94,17 @@ $update_from_18_version = array('1.8.0','1.8.1','1.8.2');
* Page in the install wizard to select the language which will be used during
* the installation process.
*/
class Page_Language extends HTML_QuickForm_Page
{
function get_title()
{
class Page_Language extends HTML_QuickForm_Page {
function get_title() {
return get_lang('WelcomeToDokeosInstaller');
}
function get_info()
{
function get_info() {
return 'Please select the language you\'d like to use while installing:';
}
function buildForm()
{
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').' >>');
@ -117,64 +119,54 @@ class Page_Language extends HTML_QuickForm_Page
* - necessary and optional extensions
* - folders which have to be writable
*/
class Page_Requirements extends HTML_QuickForm_Page
{
class Page_Requirements extends HTML_QuickForm_Page {
/**
* this function checks if a php extension exists or not
*
* @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))
{
* 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
{
} 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 ();
function get_not_writable_folders() {
$writable_folders = array('../inc/conf', '../upload', '../../archive', '../../courses', '../../home');
$not_writable = array();
$perm = api_get_setting('permissions_for_new_directories');
$perm = octdec(!empty($perm)?$perm:'0770');
foreach ($writable_folders as $index => $folder)
{
if (!is_writable($folder) & & !@ chmod($folder, $perm))
{
$perm = octdec(!empty($perm) ? $perm : '0770');
foreach ($writable_folders as $index => $folder) {
if (!is_writable($folder) & & !@ chmod($folder, $perm)) {
$not_writable[] = $folder;
}
}
return $not_writable;
}
function get_title()
{
function get_title() {
return get_lang("Requirements");
}
function get_info()
{
function get_info() {
$not_writable = $this->get_not_writable_folders();
if (count($not_writable) > 0)
{
if (count($not_writable) > 0) {
$info[] = '< div style = "margin:20px;padding:10px;width: 50%;color:#FF6600;border:2px solid #FF6600;" > ';
$info[] = '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)
{
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'))
{
} 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 > ';
@ -197,8 +189,8 @@ class Page_Requirements extends HTML_QuickForm_Page
$info[] = get_lang('MoreDetails').", < a href = \"../../installation_guide.html\" target = \"blank\" > read the installation guide< / a > .";
return implode("\n",$info);
}
function buildForm()
{
function buildForm() {
global $updateFromVersion;
$this->_formBuilt = true;
$this->addElement('radio', 'installation_type', get_lang('InstallType'), get_lang('NewInstall'), 'new');
@ -207,8 +199,7 @@ class Page_Requirements extends HTML_QuickForm_Page
$prevnext[] = & $this->createElement('submit', $this->getButtonName('back'), '< < '.get_lang('Previous'));
$prevnext[] = & $this->createElement('submit', $this->getButtonName('next'), get_lang('Next').' >>');
$not_writable = $this->get_not_writable_folders();
if (count($not_writable) > 0)
{
if (count($not_writable) > 0) {
$el = $prevnext[1];
$el->updateAttributes('disabled="disabled"');
}
@ -220,18 +211,17 @@ class Page_Requirements extends HTML_QuickForm_Page
/**
* Page in the install wizard to select the location of the old Dokeos installation.
*/
class Page_LocationOldVersion extends HTML_QuickForm_Page
{
function get_title()
{
class Page_LocationOldVersion extends HTML_QuickForm_Page {
function get_title() {
return 'Old version root path';
}
function get_info()
{
function get_info() {
return 'Give location of your old Dokeos installation ';
}
function buildForm()
{
function buildForm() {
$this->_formBuilt = true;
$this->addElement('text', 'old_version_path', 'Old version root path');
$this->applyFilter('old_version_path', 'trim');
@ -248,18 +238,16 @@ class Page_LocationOldVersion extends HTML_QuickForm_Page
* 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()
{
class Page_License extends HTML_QuickForm_Page {
function get_title() {
return get_lang('Licence');
}
function get_info()
{
function get_info() {
return get_lang('DokeosLicenseInfo');
}
function buildForm()
{
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'));
@ -277,18 +265,17 @@ class Page_License extends HTML_QuickForm_Page
* 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()
{
class Page_DatabaseSettings extends HTML_QuickForm_Page {
function get_title() {
return get_lang('DBSetting');
}
function get_info()
{
function get_info() {
return get_lang('DBSettingIntro');
}
function buildForm()
{
function buildForm() {
$this->_formBuilt = true;
$this->addElement('text', 'database_host', get_lang("DBHost"), array ('size' => '40'));
$this->addRule('database_host', 'ThisFieldIsRequired', 'required');
@ -318,8 +305,8 @@ class Page_DatabaseSettings extends HTML_QuickForm_Page
$enable_tracking[] = & $this->createElement('radio', 'enable_tracking', null, get_lang("Yes"), 1);
$enable_tracking[] = & $this->createElement('radio', 'enable_tracking', null, get_lang("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);
$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').' >>');
@ -327,15 +314,14 @@ class Page_DatabaseSettings extends HTML_QuickForm_Page
$this->setDefaultAction('next');
}
}
class ValidateDatabaseConnection extends HTML_QuickForm_Rule
{
public function validate($parameters)
{
class ValidateDatabaseConnection extends HTML_QuickForm_Rule {
public function validate($parameters) {
$db_host = $parameters[0];
$db_user = $parameters[1];
$db_password = $parameters[2];
if(mysql_connect($db_host,$db_user,$db_password))
{
if (mysql_connect($db_host, $db_user, $db_password)) {
return true;
}
return false;
@ -346,18 +332,17 @@ class ValidateDatabaseConnection extends HTML_QuickForm_Rule
* Page in the install wizard in which some config settings are asked to the
* user.
*/
class Page_ConfigSettings extends HTML_QuickForm_Page
{
function get_title()
{
class Page_ConfigSettings extends HTML_QuickForm_Page {
function get_title() {
return get_lang('CfgSetting');
}
function get_info()
{
function get_info() {
return get_lang('ConfigSettingsInfo');
}
function buildForm()
{
function buildForm() {
$this->_formBuilt = true;
$languages = array ();
$languages['dutch'] = 'dutch';
@ -402,21 +387,19 @@ class Page_ConfigSettings extends HTML_QuickForm_Page
* Page in the install wizard in which a final overview of all settings is
* displayed.
*/
class Page_ConfirmSettings extends HTML_QuickForm_Page
{
function get_title()
{
class Page_ConfirmSettings extends HTML_QuickForm_Page {
function get_title() {
return get_lang('LastCheck');
}
function get_info()
{
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()
{
function buildForm() {
$wizard = $this->controller;
$values = $wizard->exportValues();
$this->addElement('static', 'confirm_platform_language', get_lang("MainLang"), $values['platform_language']);
@ -441,14 +424,13 @@ class Page_ConfirmSettings extends HTML_QuickForm_Page
/**
* Class to render a page in the install wizard.
*/
class ActionDisplay extends HTML_QuickForm_Action_Display
{
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)
{
function _renderForm(& $current_page) {
global $charset;
global $dokeos_version, $installType, $updateFromVersion;
@ -481,16 +463,12 @@ class ActionDisplay extends HTML_QuickForm_Action_Display
$current_page_number = 0;
$page_number = 0;
echo '< ol > ';
foreach($all_pages as $index => $page)
{
foreach($all_pages as $index => $page) {
$page_number++;
if($page->get_title() == $current_page->get_title())
{
if ($page->get_title() == $current_page->get_title()) {
$current_page_number = $page_number;
echo '< li style = "font-weight: bold;" > '.$page->get_title().'< / li > ';
}
else
{
} else {
echo '< li > '.$page->get_title().'< / li > ';
}
}
@ -519,10 +497,10 @@ class ActionDisplay extends HTML_QuickForm_Action_Display
* Here happens the actual installation action after collecting
* all the required data.
*/
class ActionProcess extends HTML_QuickForm_Action
{
function perform(& $page, $actionName)
{
class ActionProcess extends HTML_QuickForm_Action {
function perform(& $page, $actionName) {
global $charset;
global $dokeos_version, $installType, $updateFromVersion;
@ -584,8 +562,7 @@ class ActionProcess extends HTML_QuickForm_Action
==============================================================================
*/
function display_upgrade_header($text_dir, $dokeos_version, $install_type, $update_from_version)
{
function display_upgrade_header($text_dir, $dokeos_version, $install_type, $update_from_version) {
?>
< !DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
@ -614,22 +591,20 @@ function display_upgrade_header($text_dir, $dokeos_version, $install_type, $upda
}
/**
* Return a list of language directories .
* @todo function does not belong here, move to code library,
* also see infocours.php which contains similar function
*/
function get_language_folder_list()
{
* TODO: Copy/paste again. Find an existing function for this job .
* Return a list of language directories.
* @todo function does not belong here, move to code library,
* also see infocours.php which contains similar function
*/
function get_language_folder_list() {
$dirname = dirname(__FILE__).'/../lang';
if ($dirname[strlen($dirname) - 1] != '/')
$dirname .= '/';
$handle = opendir($dirname);
while ($entries = readdir($handle))
{
while ($entries = readdir($handle)) {
if ($entries == '.' || $entries == '..' || $entries == '.svn')
continue;
if (is_dir($dirname.$entries))
{
if (is_dir($dirname.$entries)) {
$language_list[$entries] = api_ucfirst($entries);
}
}
@ -638,9 +613,7 @@ function get_language_folder_list()
return $language_list;
}
function display_installation_overview()
{
function display_installation_overview() {
echo '< div id = "installation_steps" > ';
echo '< img src = "../img/bluelogo.gif" hspace = "10" vspace = "10" alt = "Dokeos logo" / > ';
echo '< ol > ';
@ -659,39 +632,31 @@ function display_installation_overview()
* This function prints class=active_step $current_step=$param
* @author Patrick Cool < patrick.cool @ UGent . be > , Ghent University
*/
function step_active($this_step)
{
function step_active($this_step) {
global $current_active_step;
if ($current_active_step == $this_step)
{
if ($current_active_step == $this_step) {
return ' class="current_step" ';
}
}
// Rule to check update path
function check_update_path($path)
{
function check_update_path($path) {
global $update_from_version;
// Make sure path has a trailing /
$path = substr($path,-1) != '/' ? $path.'/' : $path;
$path = substr($path, -1) != '/' ? $path.'/' : $path;
// Check the path
if (file_exists($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 == '')
//{
//if (! isset($version) || $version == '') {
// $version = get_installed_version($path, 'dokeos_version');
//}
if (in_array($version, $update_from_version))
{
if (in_array($version, $update_from_version)) {
return true;
}
else
{
} else {
return false;
}
}
@ -703,16 +668,13 @@ function check_update_path($path)
* 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') )
{
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))
{
if (isset($$parameter)) {
return $$parameter;
}
}
@ -734,77 +696,56 @@ function get_installed_version($old_installation_path, $parameter)
* @return string the value of the parameter
* @author Olivier Brouckaert
*/
function get_config_param($param,$path)
{
function get_config_param($param, $path) {
global $configFile, $updateFromConfigFile;
if (empty ($updateFromConfigFile))
{
if (file_exists($path.'claroline/include/config.inc.php'))
{
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'))
{
} elseif (file_exists($path.'claroline/inc/conf/claro_main.conf.php')) {
$updateFromConfigFile = 'claroline/inc/conf/claro_main.conf.php';
}
else
{
} else {
return;
}
}
//echo "reading from file $path$updateFromConfigFile, which exists...";
if (is_array($configFile) & & isset ($configFile[$param]))
{
if (is_array($configFile) & & isset($configFile[$param])) {
return $configFile[$param];
}
elseif (file_exists($path.$updateFromConfigFile))
{
$configFile = array ();
} elseif (file_exists($path.$updateFromConfigFile)) {
$configFile = array();
$temp = file($path.$updateFromConfigFile);
$val = '';
foreach ($temp as $enreg) {
foreach ($temp as $enreg)
{
if (strstr($enreg, '='))
{
if (strstr($enreg, '=')) {
$enreg = explode('=', $enreg);
if ($enreg[0][0] == '$')
{
if ($enreg[0][0] == '$') {
list ($enreg[1]) = explode(' //', $enreg[1]);
$enreg[0] = trim(str_replace('$', '', $enreg[0]));
$enreg[1] = str_replace('\"', '"', ereg_replace('(^"|"$)', '', substr(trim($enreg[1]), 0, -1)));
if (strtolower($enreg[1]) == 'true')
{
if (strtolower($enreg[1]) == 'true') {
$enreg[1] = 1;
}
if (strtolower($enreg[1]) == 'false')
{
if (strtolower($enreg[1]) == 'false') {
$enreg[1] = 0;
}
else
{
} else {
$implode_string = ' ';
if (!strstr($enreg[1], '." ".') & & strstr($enreg[1], '.$'))
{
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 (eregi('^\$[a-z_][a-z0-9_]*$', $tmp_val))
{
foreach ($tmp as $tmp_key => $tmp_val) {
if (eregi('^\$[a-z_][a-z0-9_]*$', $tmp_val)) {
$tmp[$tmp_key] = get_config_param(str_replace('$', '', $tmp_val), $path);
}
}
@ -814,8 +755,7 @@ function get_config_param($param,$path)
$configFile[$enreg[0]] = $enreg[1];
if ($enreg[0] == $param)
{
if ($enreg[0] == $param) {
$val = $enreg[1];
}
}
@ -845,8 +785,8 @@ $wizard = & new HTML_QuickForm_Controller('regWizard', true);
//$wizard->addPage(new Page_Requirements('page_requirements'));
$wizard->addPage(new Page_LocationOldVersion('page_location_old_version'));
$values = $wizard->exportValues();
if( isset($values['old_version_path']) & & $values['old_version_path'] != '/var/www/html/old_version/' )
{
if (isset($values['old_version_path']) & & $values['old_version_path'] != '/var/www/html/old_version/') {
$path = $values['old_version_path'];
$defaults['platform_language'] = get_config_param('platformLanguage',$path);
$defaults['platform_url'] = 'http://'.$_SERVER['HTTP_HOST'].$urlAppendPath.'/';
@ -883,9 +823,7 @@ if( isset($values['old_version_path']) && $values['old_version_path'] != '/var/w
}
//$defaults['encrypt_password'] = get_config_param('userPasswordCrypted',$path);
$defaults['self_reg'] = get_config_param('allowSelfReg',$path);
}
else
{
} else {
//old version path not correct yet
}
@ -909,10 +847,10 @@ $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") ;
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;
@ -923,11 +861,9 @@ $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" );
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();
?>