upgrade.php 35 KB

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