upgrade.php 35 KB

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