upgrade.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941
  1. <?php // $Id:$
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2007 various contributors
  6. For a full list of contributors, see "credits.txt".
  7. The full license can be read in "license.txt".
  8. This program is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU General Public License
  10. as published by the Free Software Foundation; either version 2
  11. of the License, or (at your option) any later version.
  12. See the GNU General Public License for more details.
  13. Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
  14. Mail: info@dokeos.com
  15. ==============================================================================
  16. */
  17. /**
  18. ==============================================================================
  19. * In this file we're working on a well-organised upgrade script to
  20. * upgrade directly from Dokeos 1.6.x to Dokeos 1.8.3
  21. *
  22. * For this upgrade we assume there is an old_dokeos directory and the new
  23. * software is in a new_dokeos directory. While we're busy developing we
  24. * work in this one - large - separate file so not to disturb the other
  25. * existing classes - the existing code remains working.
  26. *
  27. * This script uses PEAR QuickForm and QuickFormController classes.
  28. *
  29. * First version
  30. * - ask for old version path
  31. * - check version (1.6.x or 1.8.x, no others supported at the moment)
  32. * - get settings from old version
  33. * - perform necessary upgrade functions based on version
  34. * Future improvements
  35. * - ask user if she agrees to detected version (chance to cancel)
  36. * - ability to do in-place upgrade
  37. * - ability to let old databases remain and clone them for new install so
  38. * Dokeos admins can have old and new version running side by side
  39. *
  40. * @package dokeos.install
  41. ==============================================================================
  42. */
  43. /*
  44. * ABOUT DETECTING OLDER VERSIONS
  45. * Dokeos versions 1.6.x and 1.8.x have an installedVersion.inc.php file.
  46. * In 1.6.x they have a parameter $platformVersion,
  47. * in 1.8.x a parameter $dokeos_version.
  48. * The function get_installed_version($old_installation_path, $parameter)
  49. * can be used to detect version numbers.
  50. */
  51. /*
  52. ==============================================================================
  53. INIT SECTION
  54. ==============================================================================
  55. */
  56. session_start();
  57. ini_set('include_path',ini_get('include_path').PATH_SEPARATOR.'../inc/lib/pear');
  58. //echo ini_get('include_path'); //DEBUG
  59. require_once 'HTML/QuickForm/Controller.php';
  60. require_once 'HTML/QuickForm/Rule.php';
  61. require_once 'HTML/QuickForm/Action/Display.php';
  62. require('../inc/installedVersion.inc.php');
  63. require('../inc/lib/main_api.lib.php');
  64. require('../lang/english/trad4all.inc.php');
  65. require('../lang/english/install.inc.php');
  66. require_once('install_upgrade.lib.php');
  67. require_once('upgrade_lib.php');
  68. define('DOKEOS_INSTALL',1);
  69. define('MAX_COURSE_TRANSFER',100);
  70. define('INSTALL_TYPE_UPDATE', 'update');
  71. define('FORM_FIELD_DISPLAY_LENGTH', 40);
  72. define('DATABASE_FORM_FIELD_DISPLAY_LENGTH', 25);
  73. define('MAX_FORM_FIELD_LENGTH', 50);
  74. define('DEFAULT_LANGUAGE', 'english');
  75. //error_reporting(E_COMPILE_ERROR | E_ERROR | E_CORE_ERROR);
  76. error_reporting(E_ALL);
  77. @set_time_limit(0);
  78. if(function_exists('ini_set'))
  79. {
  80. ini_set('memory_limit',-1);
  81. ini_set('max_execution_time',0);
  82. }
  83. $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');
  84. $update_from_16_version = array('1.6','1.6.1','1.6.2','1.6.3','1.6.4','1.6.5');
  85. $update_from_18_version = array('1.8.0','1.8.1','1.8.2');
  86. /*
  87. ==============================================================================
  88. CLASSES
  89. ==============================================================================
  90. */
  91. /**
  92. * Page in the install wizard to select the language which will be used during
  93. * the installation process.
  94. */
  95. class Page_Language extends HTML_QuickForm_Page
  96. {
  97. function get_title()
  98. {
  99. return get_lang('WelcomeToDokeosInstaller');
  100. }
  101. function get_info()
  102. {
  103. return 'Please select the language you\'d like to use while installing:';
  104. }
  105. function buildForm()
  106. {
  107. $this->_formBuilt = true;
  108. $this->addElement('select', 'install_language', get_lang('InstallationLanguage'), get_language_folder_list());
  109. $buttons[0] = & HTML_QuickForm :: createElement('submit', $this->getButtonName('next'), get_lang('Next').' >>');
  110. $this->addGroup($buttons, 'buttons', '', '&nbsp', false);
  111. $this->setDefaultAction('next');
  112. }
  113. }
  114. /**
  115. * Class for requirements page
  116. * This checks and informs about some requirements for installing Dokeos:
  117. * - necessary and optional extensions
  118. * - folders which have to be writable
  119. */
  120. class Page_Requirements extends HTML_QuickForm_Page
  121. {
  122. /**
  123. * this function checks if a php extension exists or not
  124. *
  125. * @param string $extentionName name of the php extension to be checked
  126. * @param boolean $echoWhenOk true => show ok when the extension exists
  127. * @author Christophe Gesche
  128. */
  129. function check_extension($extentionName)
  130. {
  131. if (extension_loaded($extentionName))
  132. {
  133. return '<li>'.$extentionName.' - ok</li>';
  134. }
  135. else
  136. {
  137. return '<li><b>'.$extentionName.'</b> <font color="red">is missing (Dokeos can work without)</font> (<a href="http://www.php.net/'.$extentionName.'" target="_blank">'.$extentionName.'</a>)</li>';
  138. }
  139. }
  140. function get_not_writable_folders()
  141. {
  142. $writable_folders = array ('../inc/conf', '../garbage', '../upload', '../../archive', '../../courses', '../../home');
  143. $not_writable = array ();
  144. $perm = api_get_setting('permissions_for_new_directories');
  145. $perm = octdec(!empty($perm)?$perm:'0770');
  146. foreach ($writable_folders as $index => $folder)
  147. {
  148. if (!is_writable($folder) && !@ chmod($folder, $perm))
  149. {
  150. $not_writable[] = $folder;
  151. }
  152. }
  153. return $not_writable;
  154. }
  155. function get_title()
  156. {
  157. return get_lang("Requirements");
  158. }
  159. function get_info()
  160. {
  161. $not_writable = $this->get_not_writable_folders();
  162. if (count($not_writable) > 0)
  163. {
  164. $info[] = '<div style="margin:20px;padding:10px;width: 50%;color:#FF6600;border:2px solid #FF6600;">';
  165. $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>.';
  166. $info[] = '<ul>';
  167. foreach ($not_writable as $index => $folder)
  168. {
  169. $info[] = '<li>'.$folder.'</li>';
  170. }
  171. $info[] = '</ul>';
  172. $info[] = '</div>';
  173. $this->disableNext = true;
  174. }
  175. elseif (file_exists('../inc/conf/claro_main.conf.php'))
  176. {
  177. $info[] = '<div style="margin:20px;padding:10px;width: 50%;color:#FF6600;border:2px solid #FF6600;text-align:center;">';
  178. $info[] = get_lang("WarningExistingDokeosInstallationDetected");
  179. $info[] = '</div>';
  180. }
  181. $info[] = '<b>'.get_lang("ReadThoroughly").'</b>';
  182. $info[] = '<br />';
  183. $info[] = get_lang("DokeosNeedFollowingOnServer");
  184. $info[] = "<ul>";
  185. $info[] = "<li>Webserver with PHP 5.x";
  186. $info[] = '<ul>';
  187. $info[] = $this->check_extension('standard');
  188. $info[] = $this->check_extension('session');
  189. $info[] = $this->check_extension('mysql');
  190. $info[] = $this->check_extension('zlib');
  191. $info[] = $this->check_extension('pcre');
  192. $info[] = '</ul></li>';
  193. $info[] = "<li>MySQL + login/password allowing to access and create at least one database</li>";
  194. $info[] = "<li>Write access to web directory where Dokeos files have been put</li>";
  195. $info[] = "</ul>";
  196. $info[] = get_lang('MoreDetails').", <a href=\"../../installation_guide.html\" target=\"blank\">read the installation guide</a>.";
  197. return implode("\n",$info);
  198. }
  199. function buildForm()
  200. {
  201. global $updateFromVersion;
  202. $this->_formBuilt = true;
  203. $this->addElement('radio', 'installation_type', get_lang('InstallType'), get_lang('NewInstall'), 'new');
  204. $update_group[0] = & HTML_QuickForm :: createElement('radio', 'installation_type', null, 'Update from Dokeos '.implode('|', $updateFromVersion).'', 'update');
  205. //$this->addGroup($update_group, 'update_group', '', '&nbsp', false);
  206. $prevnext[] = & $this->createElement('submit', $this->getButtonName('back'), '<< '.get_lang('Previous'));
  207. $prevnext[] = & $this->createElement('submit', $this->getButtonName('next'), get_lang('Next').' >>');
  208. $not_writable = $this->get_not_writable_folders();
  209. if (count($not_writable) > 0)
  210. {
  211. $el = $prevnext[1];
  212. $el->updateAttributes('disabled="disabled"');
  213. }
  214. $this->addGroup($prevnext, 'buttons', '', '&nbsp;', false);
  215. $this->setDefaultAction('next');
  216. }
  217. }
  218. /**
  219. * Page in the install wizard to select the location of the old Dokeos installation.
  220. */
  221. class Page_LocationOldVersion extends HTML_QuickForm_Page
  222. {
  223. function get_title()
  224. {
  225. return 'Old version root path';
  226. }
  227. function get_info()
  228. {
  229. return 'Give location of your old Dokeos installation ';
  230. }
  231. function buildForm()
  232. {
  233. $this->_formBuilt = true;
  234. $this->addElement('text', 'old_version_path', 'Old version root path');
  235. $this->applyFilter('old_version_path', 'trim');
  236. $this->addRule('old_version_path', get_lang('ThisFieldIsRequired'), 'required');
  237. $this->addRule('old_version_path', get_lang('BadUpdatePath'), 'callback', 'check_update_path');
  238. $prevnext[] = & $this->createElement('submit', $this->getButtonName('back'), '<< '.get_lang('Previous'));
  239. $prevnext[] = & $this->createElement('submit', $this->getButtonName('next'), get_lang('Next').' >>');
  240. $this->addGroup($prevnext, 'buttons', '', '&nbsp;', false);
  241. $this->setDefaultAction('next');
  242. }
  243. }
  244. /**
  245. * Class for license page
  246. * Displays the GNU GPL license that has to be accepted to install Dokeos.
  247. */
  248. class Page_License extends HTML_QuickForm_Page
  249. {
  250. function get_title()
  251. {
  252. return get_lang('Licence');
  253. }
  254. function get_info()
  255. {
  256. return get_lang('DokeosLicenseInfo');
  257. }
  258. function buildForm()
  259. {
  260. $this->_formBuilt = true;
  261. $this->addElement('textarea', 'license', get_lang('Licence'), array ('cols' => 80, 'rows' => 20, 'disabled' => 'disabled', 'style'=>'background-color: white;'));
  262. $this->addElement('checkbox','license_accept','',get_lang('IAccept'));
  263. $this->addRule('license_accept',get_lang('ThisFieldIsRequired'),'required');
  264. $prevnext[] = & $this->createElement('submit', $this->getButtonName('back'), '<< '.get_lang('Previous'));
  265. $prevnext[] = & $this->createElement('submit', $this->getButtonName('next'), get_lang('Next').' >>');
  266. $this->addGroup($prevnext, 'buttons', '', '&nbsp;', false);
  267. $this->setDefaultAction('next');
  268. }
  269. }
  270. /**
  271. * Class for database settings page
  272. * Displays a form where the user can enter the installation settings
  273. * regarding the databases - login and password, names, prefixes, single
  274. * or multiple databases, tracking or not...
  275. */
  276. class Page_DatabaseSettings extends HTML_QuickForm_Page
  277. {
  278. function get_title()
  279. {
  280. return get_lang('DBSetting');
  281. }
  282. function get_info()
  283. {
  284. return get_lang('DBSettingIntro');
  285. }
  286. function buildForm()
  287. {
  288. $this->_formBuilt = true;
  289. $this->addElement('text', 'database_host', get_lang("DBHost"), array ('size' => '40'));
  290. $this->addRule('database_host', 'ThisFieldIsRequired', 'required');
  291. $this->addElement('text', 'database_username', get_lang("DBLogin"), array ('size' => '40'));
  292. $this->addElement('password', 'database_password', get_lang("DBPassword"), array ('size' => '40'));
  293. $this->addRule(array('database_host','database_username','database_password'),get_lang('CouldNotConnectToDatabase'),new ValidateDatabaseConnection());
  294. $this->addElement('text', 'database_prefix', get_lang("DbPrefixForm"), array ('size' => '40'));
  295. $this->addElement('text', 'database_main_db', get_lang("MainDB"), array ('size' => '40'));
  296. $this->addRule('database_main_db', 'ThisFieldIsRequired', 'required');
  297. $this->addElement('text', 'database_tracking', get_lang("StatDB"), array ('size' => '40'));
  298. $this->addRule('database_tracking', 'ThisFieldIsRequired', 'required');
  299. $this->addElement('text', 'database_scorm', get_lang("ScormDB"), array ('size' => '40'));
  300. $this->addRule('database_scorm', 'ThisFieldIsRequired', 'required');
  301. $this->addElement('text', 'database_user', get_lang("UserDB"), array ('size' => '40'));
  302. $this->addRule('database_user', 'ThisFieldIsRequired', 'required');
  303. //$this->addElement('text', 'database_repository', get_lang("RepositoryDatabase"), array ('size' => '40'));
  304. //$this->addRule('database_repository', 'ThisFieldIsRequired', 'required');
  305. //$this->addElement('text', 'database_weblcms', get_lang("WeblcmsDatabase"), array ('size' => '40'));
  306. //$this->addRule('database_weblcms', 'ThisFieldIsRequired', 'required');
  307. //$this->addElement('text', 'database_personal_calendar', get_lang("PersonalCalendarDatabase"), array ('size' => '40'));
  308. //$this->addRule('database_personal_calendar', 'ThisFieldIsRequired', 'required');
  309. //$this->addElement('text', 'database_personal_messenger', get_lang("PersonalMessageDatabase"), array ('size' => '40'));
  310. //$this->addRule('database_personal_messenger', 'ThisFieldIsRequired', 'required');
  311. //$this->addElement('text', 'database_profiler', get_lang("ProfilerDatabase"), array ('size' => '40'));
  312. //$this->addRule('database_profiler', 'ThisFieldIsRequired', 'required');
  313. $enable_tracking[] = & $this->createElement('radio', 'enable_tracking', null, get_lang("Yes"), 1);
  314. $enable_tracking[] = & $this->createElement('radio', 'enable_tracking', null, get_lang("No"), 0);
  315. $this->addGroup($enable_tracking, 'tracking', get_lang("EnableTracking"), '&nbsp;', false);
  316. $several_db[] = & $this->createElement('radio', 'database_single', null, get_lang("One"),1);
  317. $several_db[] = & $this->createElement('radio', 'database_single', null, get_lang("Several"),0);
  318. $this->addGroup($several_db, 'db', get_lang("SingleDb"), '&nbsp;', false);
  319. $prevnext[] = & $this->createElement('submit', $this->getButtonName('back'), '<< '.get_lang('Previous'));
  320. $prevnext[] = & $this->createElement('submit', $this->getButtonName('next'), get_lang('Next').' >>');
  321. $this->addGroup($prevnext, 'buttons', '', '&nbsp;', false);
  322. $this->setDefaultAction('next');
  323. }
  324. }
  325. class ValidateDatabaseConnection extends HTML_QuickForm_Rule
  326. {
  327. public function validate($parameters)
  328. {
  329. $db_host = $parameters[0];
  330. $db_user = $parameters[1];
  331. $db_password = $parameters[2];
  332. if(mysql_connect($db_host,$db_user,$db_password))
  333. {
  334. return true;
  335. }
  336. return false;
  337. }
  338. }
  339. /**
  340. * Page in the install wizard in which some config settings are asked to the
  341. * user.
  342. */
  343. class Page_ConfigSettings extends HTML_QuickForm_Page
  344. {
  345. function get_title()
  346. {
  347. return get_lang('CfgSetting');
  348. }
  349. function get_info()
  350. {
  351. return get_lang('ConfigSettingsInfo');
  352. }
  353. function buildForm()
  354. {
  355. $this->_formBuilt = true;
  356. $languages = array ();
  357. $languages['dutch'] = 'dutch';
  358. $this->addElement('select', 'platform_language', get_lang("MainLang"), get_language_folder_list());
  359. $this->addElement('text', 'platform_url', get_lang("DokeosURL"), array ('size' => '40'));
  360. $this->addRule('platform_url', get_lang('ThisFieldIsRequired'), 'required');
  361. $this->addElement('text', 'admin_email', get_lang("AdminEmail"), array ('size' => '40'));
  362. $this->addRule('admin_email', get_lang('ThisFieldIsRequired'), 'required');
  363. $this->addRule('admin_email', get_lang('WrongEmail'), 'email');
  364. $this->addElement('text', 'admin_lastname', get_lang("AdminLastName"), array ('size' => '40'));
  365. $this->addRule('admin_lastname', get_lang('ThisFieldIsRequired'), 'required');
  366. $this->addElement('text', 'admin_firstname', get_lang("AdminFirstName"), array ('size' => '40'));
  367. $this->addRule('admin_firstname', get_lang('ThisFieldIsRequired'), 'required');
  368. $this->addElement('text', 'admin_phone', get_lang("AdminPhone"), array ('size' => '40'));
  369. $this->addElement('text', 'admin_username', get_lang("AdminLogin"), array ('size' => '40'));
  370. $this->addRule('admin_username', get_lang('ThisFieldIsRequired'), 'required');
  371. $this->addElement('text', 'admin_password', get_lang("AdminPass"), array ('size' => '40'));
  372. $this->addRule('admin_password', get_lang('ThisFieldIsRequired'), 'required');
  373. $this->addElement('text', 'platform_name', get_lang("CampusName"), array ('size' => '40'));
  374. $this->addRule('platform_name', get_lang('ThisFieldIsRequired'), 'required');
  375. $this->addElement('text', 'organization_name', get_lang("InstituteShortName"), array ('size' => '40'));
  376. $this->addRule('organization_name', get_lang('ThisFieldIsRequired'), 'required');
  377. $this->addElement('text', 'organization_url', get_lang("InstituteURL"), array ('size' => '40'));
  378. $this->addRule('organization_url', get_lang('ThisFieldIsRequired'), 'required');
  379. $encrypt[] = & $this->createElement('radio', 'encrypt_password', null, get_lang('Yes'), 1);
  380. $encrypt[] = & $this->createElement('radio', 'encrypt_password', null, get_lang('No'), 0);
  381. $this->addGroup($encrypt, 'tracking', get_lang("EncryptUserPass"), '&nbsp;', false);
  382. $self_reg[] = & $this->createElement('radio', 'self_reg', null, get_lang('Yes'), 1);
  383. $self_reg[] = & $this->createElement('radio', 'self_reg', null, get_lang('No'), 0);
  384. $this->addGroup($self_reg, 'tracking', get_lang("AllowSelfReg"), '&nbsp;', false);
  385. $self_reg_teacher[] = & $this->createElement('radio', 'self_reg_teacher', null, get_lang('Yes'), 1);
  386. $self_reg_teacher[] = & $this->createElement('radio', 'self_reg_teacher', null, get_lang('No'), 0);
  387. $this->addGroup($self_reg_teacher, 'tracking', get_lang("AllowSelfRegProf"), '&nbsp;', false);
  388. $prevnext[] = & $this->createElement('submit', $this->getButtonName('back'), '<< '.get_lang('Previous'));
  389. $prevnext[] = & $this->createElement('submit', $this->getButtonName('next'), get_lang('Next').' >>');
  390. $this->addGroup($prevnext, 'buttons', '', '&nbsp;', false);
  391. $this->setDefaultAction('next');
  392. }
  393. }
  394. /**
  395. * Page in the install wizard in which a final overview of all settings is
  396. * displayed.
  397. */
  398. class Page_ConfirmSettings extends HTML_QuickForm_Page
  399. {
  400. function get_title()
  401. {
  402. return get_lang('LastCheck');
  403. }
  404. function get_info()
  405. {
  406. return 'Here are the values you entered
  407. <br />
  408. <strong>Print this page to remember your password and other settings</strong>';
  409. }
  410. function buildForm()
  411. {
  412. $wizard = $this->controller;
  413. $values = $wizard->exportValues();
  414. $this->addElement('static', 'confirm_platform_language', get_lang("MainLang"), $values['platform_language']);
  415. $this->addElement('static', 'confirm_platform_url', get_lang("DokeosURL"), $values['platform_url']);
  416. $this->addElement('static', 'confirm_admin_email', get_lang("AdminEmail"), $values['admin_email']);
  417. $this->addElement('static', 'confirm_admin_lastname', get_lang("AdminLastName"), $values['admin_lastname']);
  418. $this->addElement('static', 'confirm_admin_firstname', get_lang("AdminFirstName"), $values['admin_firstname']);
  419. $this->addElement('static', 'confirm_admin_phone', get_lang("AdminPhone"), $values['admin_phone']);
  420. $this->addElement('static', 'confirm_admin_username', get_lang("AdminLogin"), $values['admin_username']);
  421. $this->addElement('static', 'confirm_admin_password', get_lang("AdminPass"), $values['admin_password']);
  422. $this->addElement('static', 'confirm_platform_name', get_lang("CampusName"), $values['platform_name']);
  423. $this->addElement('static', 'confirm_organization_name', get_lang("InstituteShortName"), $values['organization_name']);
  424. $this->addElement('static', 'confirm_organization_url', get_lang("InstituteURL"), $values['organization_url']);
  425. $prevnext[] = & $this->createElement('submit', $this->getButtonName('back'), '<< '.get_lang('Previous'));
  426. $prevnext[] = & $this->createElement('submit', $this->getButtonName('next'), get_lang('Next').' >>');
  427. $this->addGroup($prevnext, 'buttons', '', '&nbsp;', false);
  428. $this->setDefaultAction('next');
  429. }
  430. }
  431. /**
  432. * Class to render a page in the install wizard.
  433. */
  434. class ActionDisplay extends HTML_QuickForm_Action_Display
  435. {
  436. /**
  437. * Displays the HTML-code of a page in the wizard
  438. * @param HTML_Quickform_Page $page The page to display.
  439. */
  440. function _renderForm(& $current_page)
  441. {
  442. global $dokeos_version, $installType, $updateFromVersion;
  443. $renderer = & $current_page->defaultRenderer();
  444. $current_page->setRequiredNote('<font color="#FF0000">*</font> '.get_lang('ThisFieldIsRequired'));
  445. $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>";
  446. $renderer->setElementTemplate($element_template);
  447. $header_template = "\n\t<tr>\n\t\t<td valign=\"top\" colspan=\"2\">{header}</td>\n\t</tr>";
  448. $renderer->setHeaderTemplate($header_template);
  449. HTML_QuickForm :: setRequiredNote('<font color="red">*</font> <small>'.get_lang('ThisFieldIsRequired').'</small>');
  450. $current_page->accept($renderer);
  451. ?>
  452. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  453. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  454. <head>
  455. <title>-- Dokeos - upgrade to version <?php echo $dokeos_version; ?></title>
  456. <link rel="stylesheet" href="../css/default/default.css" type="text/css"/>
  457. </head>
  458. <body dir="<?php echo get_lang('text_dir'); ?>">
  459. <div id="header1">
  460. 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); ?>
  461. </div>
  462. <div style="float: left; background-color:#EFEFEF;margin-right: 20px;padding: 10px;">
  463. <img src="../img/bluelogo.gif" alt="logo"/>
  464. <?php
  465. $all_pages = $current_page->controller->_pages;
  466. $total_number_of_pages = count($all_pages);
  467. $current_page_number = 0;
  468. $page_number = 0;
  469. echo '<ol>';
  470. foreach($all_pages as $index => $page)
  471. {
  472. $page_number++;
  473. if($page->get_title() == $current_page->get_title())
  474. {
  475. $current_page_number = $page_number;
  476. echo '<li style="font-weight: bold;">'.$page->get_title().'</li>';
  477. }
  478. else
  479. {
  480. echo '<li>'.$page->get_title().'</li>';
  481. }
  482. }
  483. echo '</ol>';
  484. echo '</div>';
  485. echo '<div style="margin: 10px;">';
  486. echo '<h2>'.get_lang('Step').' '.$current_page_number.' '.get_lang('of').' '.$total_number_of_pages.' &ndash; '.$current_page->get_title().'</h2>';
  487. echo '<div>';
  488. echo $current_page->get_info();
  489. echo '</div>';
  490. echo $renderer->toHtml();
  491. ?>
  492. </div>
  493. <div style="clear:both;"></div>
  494. <div id="footer">
  495. &copy; <?php echo $dokeos_version; ?>
  496. </div>
  497. </body>
  498. </html>
  499. <?php
  500. }
  501. }
  502. /**
  503. * Class for form processing
  504. * Here happens the actual installation action after collecting
  505. * all the required data.
  506. */
  507. class ActionProcess extends HTML_QuickForm_Action
  508. {
  509. function perform(& $page, $actionName)
  510. {
  511. global $dokeos_version, $installType, $updateFromVersion;
  512. $values = $page->controller->exportValues();
  513. ?>
  514. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  515. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  516. <head>
  517. <title>-- Dokeos installation -- version <?php echo $dokeos_version; ?></title>
  518. <link rel="stylesheet" href="../css/default.css" type="text/css"/>
  519. </head>
  520. <body dir="<?php echo get_lang('text_dir'); ?>">
  521. <div style="background-color:#4171B5;color:white;font-size:x-large;">
  522. Dokeos installation - version <?php echo $dokeos_version; ?><?php if($installType == 'new') echo ' - New installation'; else if($installType == 'update') echo ' - Update from Dokeos '.implode('|',$updateFromVersion); ?>
  523. </div>
  524. <div style="margin:50px;">
  525. <img src="../img/bluelogo.gif" alt="logo" align="right"/>
  526. <?php
  527. echo '<pre>';
  528. global $repository_database;
  529. global $weblcms_database;
  530. global $personal_calendar_database;
  531. global $user_database;
  532. global $personal_messenger_database;
  533. global $profiler_database;
  534. $repository_database = $values['database_repository'];
  535. $weblcms_database = $values['database_weblcms'];
  536. $personal_calendar_database = $values['database_personal_calendar'];
  537. $user_database = $values['database_user'];
  538. $personal_messenger_database = $values['database_personal_messenger'];
  539. $profiler_database = $values['database_profiler'];
  540. /*full_database_install($values);
  541. full_file_install($values);
  542. create_admin_in_user_table($values);
  543. create_default_categories_in_weblcms();*/
  544. echo "<p>Performing upgrade to latest version....</p>";
  545. //upgrade_16x_to_180($values);
  546. echo '</pre>';
  547. $page->controller->container(true);
  548. ?>
  549. <a href="../../index.php"><?php echo get_lang('GoToYourNewlyCreatedPortal'); ?></a>
  550. </div>
  551. </body>
  552. </html>
  553. <?php
  554. }
  555. }
  556. /*
  557. ==============================================================================
  558. FUNCTIONS
  559. ==============================================================================
  560. */
  561. function display_upgrade_header($text_dir, $dokeos_version, $install_type, $update_from_version)
  562. {
  563. ?>
  564. <!DOCTYPE html
  565. PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  566. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  567. <html xmlns="http://www.w3.org/1999/xhtml">
  568. <head>
  569. <title>&mdash; <?php echo get_lang('DokeosInstallation').' &mdash; '.get_lang('Version_').' '.$dokeos_version; ?></title>
  570. <style type="text/css" media="screen, projection">
  571. /*<![CDATA[*/
  572. @import "../css/default/default.css";
  573. /*]]>*/
  574. </style>
  575. <?php if(!empty($charset)){ ?>
  576. <meta http-equiv="Content-Type" content="text/html; charset=<?php echo $charset ?>" />
  577. <?php } ?>
  578. </head>
  579. <body dir="<?php echo $text_dir ?>">
  580. <div id="header">
  581. <div id="header1"><?php echo get_lang('DokeosInstallation').' &mdash; '.get_lang('Version_').' '.$dokeos_version; ?><?php if($install_type == 'new') echo ' &ndash; '.get_lang('NewInstallation'); else if($install_type == 'update') echo ' &ndash; '.get_lang('UpdateFromDokeosVersion').implode('|',$update_from_version); ?></div>
  582. <div class="clear"></div>
  583. <div id="header2">&nbsp;</div>
  584. <div id="header3">&nbsp;</div>
  585. </div>
  586. <?php
  587. }
  588. /**
  589. * Return a list of language directories.
  590. * @todo function does not belong here, move to code library,
  591. * also see infocours.php which contains similar function
  592. */
  593. function get_language_folder_list()
  594. {
  595. $dirname = dirname(__FILE__).'/../lang';
  596. if ($dirname[strlen($dirname) - 1] != '/')
  597. $dirname .= '/';
  598. $handle = opendir($dirname);
  599. while ($entries = readdir($handle))
  600. {
  601. if ($entries == '.' || $entries == '..' || $entries == '.svn')
  602. continue;
  603. if (is_dir($dirname.$entries))
  604. {
  605. $language_list[$entries] = ucfirst($entries);
  606. }
  607. }
  608. closedir($handle);
  609. asort($language_list);
  610. return $language_list;
  611. }
  612. function display_installation_overview()
  613. {
  614. echo '<div id="installation_steps">';
  615. echo '<img src="../img/bluelogo.gif" hspace="10" vspace="10" alt="Dokeos logo" />';
  616. echo '<ol>';
  617. echo '<li ' . step_active('1') . '> ' . get_lang('InstallationLanguage') . '</li>';
  618. echo '<li ' . step_active('2') . '> ' . get_lang('Requirements') . '</li>';
  619. echo '<li ' . step_active('3') . '> ' . get_lang('Licence') . '</li>';
  620. echo '<li ' . step_active('4') . '> ' . get_lang('DBSetting') . '</li>';
  621. echo '<li ' . step_active('5') . '> ' . get_lang('CfgSetting') . '</li>';
  622. echo '<li ' . step_active('6') . '> ' . get_lang('PrintOverview') . '</li>';
  623. echo '<li ' . step_active('7') . '> ' . get_lang('Installing') . '</li>';
  624. echo '</ol>';
  625. echo '</div>';
  626. }
  627. /**
  628. * This function prints class=active_step $current_step=$param
  629. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  630. */
  631. function step_active($this_step)
  632. {
  633. global $current_active_step;
  634. if ($current_active_step == $this_step)
  635. {
  636. return ' class="current_step" ';
  637. }
  638. }
  639. // Rule to check update path
  640. function check_update_path($path)
  641. {
  642. global $update_from_version;
  643. // Make sure path has a trailing /
  644. $path = substr($path,-1) != '/' ? $path.'/' : $path;
  645. // Check the path
  646. if (file_exists($path))
  647. {
  648. //search for 1.6.x installation
  649. $version = get_installed_version($path, 'platformVersion');
  650. //search for 1.8.x installation
  651. //if (! isset($version) || $version == '')
  652. //{
  653. // $version = get_installed_version($path, 'dokeos_version');
  654. //}
  655. if (in_array($version, $update_from_version))
  656. {
  657. return true;
  658. }
  659. else
  660. {
  661. return false;
  662. }
  663. }
  664. return false;
  665. }
  666. /**
  667. * This function returns the installed version of
  668. * the older installation to upgrade by checking the
  669. * claroline/inc/installedVersion.inc.php file.
  670. */
  671. function get_installed_version($old_installation_path, $parameter)
  672. {
  673. if( file_exists($old_installation_path.'claroline/inc/installedVersion.inc.php') )
  674. {
  675. $version_info_file = 'claroline/inc/installedVersion.inc.php';
  676. }
  677. // with include_once inside a function, variables aren't remembered for later use
  678. include($old_installation_path.$version_info_file);
  679. if (isset($$parameter))
  680. {
  681. return $$parameter;
  682. }
  683. }
  684. /**
  685. * This function returns a the value of a parameter from the configuration file
  686. * of a previous installation.
  687. *
  688. * IMPORTANT
  689. * - Before Dokeos 1.8 the main code folder was called 'claroline'. Since Dokeos 1.8
  690. * this folder is called 'main' -> we have to make a difference based on previous
  691. * version.
  692. * - The version may be in the config file or in the installedVersion file...
  693. *
  694. * WARNING - this function relies heavily on global variables $updateFromConfigFile
  695. * and $configFile, and also changes these globals. This can be rewritten.
  696. *
  697. * @param string $param the parameter which the value is returned for
  698. * @return string the value of the parameter
  699. * @author Olivier Brouckaert
  700. */
  701. function get_config_param($param,$path)
  702. {
  703. global $configFile, $updateFromConfigFile;
  704. if (empty ($updateFromConfigFile))
  705. {
  706. if (file_exists($path.'claroline/include/config.inc.php'))
  707. {
  708. $updateFromConfigFile = 'claroline/include/config.inc.php';
  709. }
  710. elseif (file_exists($path.'claroline/inc/conf/claro_main.conf.php'))
  711. {
  712. $updateFromConfigFile = 'claroline/inc/conf/claro_main.conf.php';
  713. }
  714. else
  715. {
  716. return;
  717. }
  718. }
  719. //echo "reading from file $path$updateFromConfigFile, which exists...";
  720. if (is_array($configFile) && isset ($configFile[$param]))
  721. {
  722. return $configFile[$param];
  723. }
  724. elseif (file_exists($path.$updateFromConfigFile))
  725. {
  726. $configFile = array ();
  727. $temp = file($path.$updateFromConfigFile);
  728. $val = '';
  729. foreach ($temp as $enreg)
  730. {
  731. if (strstr($enreg, '='))
  732. {
  733. $enreg = explode('=', $enreg);
  734. if ($enreg[0][0] == '$')
  735. {
  736. list ($enreg[1]) = explode(' //', $enreg[1]);
  737. $enreg[0] = trim(str_replace('$', '', $enreg[0]));
  738. $enreg[1] = str_replace('\"', '"', ereg_replace('(^"|"$)', '', substr(trim($enreg[1]), 0, -1)));
  739. if (strtolower($enreg[1]) == 'true')
  740. {
  741. $enreg[1] = 1;
  742. }
  743. if (strtolower($enreg[1]) == 'false')
  744. {
  745. $enreg[1] = 0;
  746. }
  747. else
  748. {
  749. $implode_string = ' ';
  750. if (!strstr($enreg[1], '." ".') && strstr($enreg[1], '.$'))
  751. {
  752. $enreg[1] = str_replace('.$', '." ".$', $enreg[1]);
  753. $implode_string = '';
  754. }
  755. $tmp = explode('." ".', $enreg[1]);
  756. foreach ($tmp as $tmp_key => $tmp_val)
  757. {
  758. if (eregi('^\$[a-z_][a-z0-9_]*$', $tmp_val))
  759. {
  760. $tmp[$tmp_key] = get_config_param(str_replace('$', '', $tmp_val), $path);
  761. }
  762. }
  763. $enreg[1] = implode($implode_string, $tmp);
  764. }
  765. $configFile[$enreg[0]] = $enreg[1];
  766. if ($enreg[0] == $param)
  767. {
  768. $val = $enreg[1];
  769. }
  770. }
  771. }
  772. }
  773. return $val;
  774. }
  775. }
  776. /*
  777. ==============================================================================
  778. MAIN CODE
  779. ==============================================================================
  780. */
  781. global $current_active_step;
  782. $current_active_step = '1';
  783. $install_type = 'update';
  784. //display_upgrade_header($text_dir, $dokeos_version, $install_type, $update_from_version);
  785. //display_installation_overview();
  786. // Create a new wizard
  787. $wizard = & new HTML_QuickForm_Controller('regWizard', true);
  788. //Add pages to wizard - path to follow for upgrade
  789. //$wizard->addPage(new Page_Language('page_language'));
  790. //$wizard->addPage(new Page_Requirements('page_requirements'));
  791. $wizard->addPage(new Page_LocationOldVersion('page_location_old_version'));
  792. $values = $wizard->exportValues();
  793. if( isset($values['old_version_path']) && $values['old_version_path'] != '/var/www/html/old_version/' )
  794. {
  795. $path = $values['old_version_path'];
  796. $defaults['platform_language'] = get_config_param('platformLanguage',$path);
  797. $defaults['platform_url'] = 'http://'.$_SERVER['HTTP_HOST'].$urlAppendPath.'/';
  798. //to keep debug output readable:
  799. //$defaults['license'] = 'GNU GPL v2';
  800. //actual license:
  801. $defaults['license'] = implode("\n", file('../../documentation/license.txt'));
  802. $defaults['database_host'] = get_config_param('dbHost',$path);
  803. $defaults['database_main_db'] = get_config_param('mainDbName',$path);
  804. $defaults['database_tracking'] = get_config_param('statsDbName',$path);
  805. $defaults['database_scorm'] = get_config_param('scormDbName',$path);
  806. $defaults['database_user'] = get_config_param('user_personal_database',$path);
  807. //$defaults['database_repository'] = 'dokeos_repository';
  808. //$defaults['database_weblcms'] = 'dokeos_weblcms';
  809. $defaults['database_username'] = get_config_param('dbLogin',$path);
  810. $defaults['database_password'] = get_config_param('dbPass',$path);
  811. $defaults['database_prefix'] = get_config_param('dbNamePrefix',$path);
  812. $defaults['enable_tracking'] = get_config_param('is_trackingEnabled',$path);
  813. $defaults['database_single'] = get_config_param('singleDbEnabled',$path);
  814. $defaults['admin_lastname'] = 'Doe';
  815. $defaults['admin_firstname'] = mt_rand(0,1)?'John':'Jane';
  816. $defaults['admin_email'] = get_config_param('emailAdministrator',$path);
  817. $defaults['admin_username'] = 'admin';
  818. $defaults['admin_password'] = api_generate_password();
  819. $defaults['admin_phone'] = get_config_param('administrator["phone"]',$path);
  820. $defaults['platform_name'] = get_config_param('siteName',$path);
  821. $defaults['encrypt_password'] = 1;
  822. $defaults['organization_name'] = get_config_param('institution["name"]',$path);
  823. $defaults['organization_url'] = get_config_param('institution["url"]',$path);
  824. $defaults['encrypt_password'] = get_config_param('userPasswordCrypted',$path);
  825. $defaults['self_reg'] = get_config_param('allowSelfReg',$path);
  826. }
  827. else
  828. {
  829. //old version path not correct yet
  830. }
  831. $wizard->addPage(new Page_License('page_license'));
  832. $wizard->addPage(new Page_DatabaseSettings('page_databasesettings'));
  833. $wizard->addPage(new Page_ConfigSettings('page_configsettings'));
  834. $wizard->addPage(new Page_ConfirmSettings('page_confirmsettings'));
  835. $defaults['install_language'] = 'english';
  836. //$defaults['old_version_path'] = '/var/www/html/old_version/';
  837. $defaults['old_version_path'] = '';
  838. // Set the default values
  839. $wizard->setDefaults($defaults);
  840. // Add the process action to the wizard
  841. $wizard->addAction('process', new ActionProcess());
  842. // Add the display action to the wizard
  843. $wizard->addAction('display', new ActionDisplay());
  844. // Set the installation language
  845. $install_language = $wizard->exportValue('page_language', 'install_language');
  846. require_once ('../lang/english/trad4all.inc.php');
  847. require_once ('../lang/english/install.inc.php');
  848. include_once ("../lang/$install_language/trad4all.inc.php");
  849. include_once ("../lang/$install_language/install.inc.php");
  850. // Set default platform language to the selected install language
  851. $defaults['platform_language'] = $install_language;
  852. $wizard->setDefaults($defaults);
  853. // Start the wizard
  854. $wizard->run();
  855. // Set the installation language
  856. $install_language = $wizard->exportValue('page_language', 'install_language');
  857. require_once ('../lang/english/trad4all.inc.php');
  858. require_once ('../lang/english/install.inc.php');
  859. include_once ("../lang/$install_language/trad4all.inc.php");
  860. include_once ("../lang/$install_language/install.inc.php");
  861. //$values = $wizard->exportValues();
  862. ?>