index.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004 Dokeos S.A.
  6. Copyright (c) 2003 Ghent University (UGent)
  7. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  8. Copyright (c) Olivier Brouckaert
  9. Copyright (c) Roan Embrechts, Vrije Universiteit Brussel
  10. For a full list of contributors, see "credits.txt".
  11. The full license can be read in "license.txt".
  12. This program is free software; you can redistribute it and/or
  13. modify it under the terms of the GNU General Public License
  14. as published by the Free Software Foundation; either version 2
  15. of the License, or (at your option) any later version.
  16. See the GNU General Public License for more details.
  17. Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
  18. Mail: info@dokeos.com
  19. ==============================================================================
  20. */
  21. /**
  22. ==============================================================================
  23. * GOAL : Dokeos installation
  24. * As seen from the user, the installation proceeds in 6 steps.
  25. * The user is presented with several webpages where he/she has to make choices
  26. * and/or fill in data.
  27. *
  28. * The aim is, as always, to have good default settings and suggestions.
  29. *
  30. * @todo reduce high level of duplication in this code
  31. * @todo (busy) organise code into functions
  32. * @package dokeos.install
  33. ==============================================================================
  34. */
  35. /*
  36. ==============================================================================
  37. INIT SECTION
  38. ==============================================================================
  39. */
  40. session_start();
  41. // Including necessary files
  42. require('../inc/installedVersion.inc.php');
  43. require('../inc/lib/main_api.lib.php');
  44. require('../lang/english/trad4all.inc.php');
  45. require('../lang/english/install.inc.php');
  46. if (!empty($_POST['language_list']))
  47. {
  48. $search = array('../','\\0');
  49. $install_language = str_replace($search,'',urldecode($_POST['language_list']));
  50. include_once("../lang/$install_language/trad4all.inc.php");
  51. include_once("../lang/$install_language/install.inc.php");
  52. api_session_register('install_language');
  53. }
  54. elseif ( isset($_SESSION['install_language']) && $_SESSION['install_language'] )
  55. {
  56. $install_language = $_SESSION['install_language'];
  57. include_once("../lang/$install_language/trad4all.inc.php");
  58. include_once("../lang/$install_language/install.inc.php");
  59. }
  60. require_once('install_upgrade.lib.php');
  61. require_once('install_functions.inc.php');
  62. // Some constants
  63. define('DOKEOS_INSTALL',1);
  64. define('MAX_COURSE_TRANSFER',100);
  65. define("INSTALL_TYPE_UPDATE", "update");
  66. define("FORM_FIELD_DISPLAY_LENGTH", 40);
  67. define("DATABASE_FORM_FIELD_DISPLAY_LENGTH", 25);
  68. define("MAX_FORM_FIELD_LENGTH", 50);
  69. define("DEFAULT_LANGUAGE", "english");
  70. // setting the error reporting
  71. error_reporting(E_COMPILE_ERROR | E_ERROR | E_CORE_ERROR);
  72. // overriding the timelimit (for large campusses that have to be migrated)
  73. @set_time_limit(0);
  74. //we hope in the future to add the ability to upgrade from 1.5.x versions
  75. //to 1.8 as well.
  76. $old_update_from_version=array('1.5','1.5.4','1.5.5','1.6');
  77. $update_from_version=array('1.6','1.6.1','1.6.2','1.6.3','1.6.4','1.6.5');
  78. /*
  79. ==============================================================================
  80. STEP 1 : INITIALIZES FORM VARIABLES IF IT IS THE FIRST VISIT
  81. ==============================================================================
  82. */
  83. $badUpdatePath=false;
  84. $emptyUpdatePath=true;
  85. if($_POST['step2_install'] || $_POST['step2_update'])
  86. {
  87. if($_POST['step2_install'])
  88. {
  89. $installType='new';
  90. $_POST['step2']=1;
  91. }
  92. else
  93. {
  94. $installType='update';
  95. if(empty($_POST['updatePath']))
  96. {
  97. $_POST['step1']=1;
  98. }
  99. else
  100. {
  101. $emptyUpdatePath = false;
  102. if($_POST['updatePath'][strlen($_POST['updatePath'])-1] != '/')
  103. {
  104. $_POST['updatePath'].='/';
  105. }
  106. if(file_exists($_POST['updatePath']))
  107. {
  108. if(in_array(get_config_param('clarolineVersion'),$update_from_version))
  109. {
  110. $_POST['step2']=1;
  111. }
  112. else
  113. {
  114. $badUpdatePath=true;
  115. }
  116. }
  117. else
  118. {
  119. $badUpdatePath=true;
  120. }
  121. }
  122. }
  123. }
  124. elseif($_POST['step1'])
  125. {
  126. $_POST['updatePath']='';
  127. $installType='';
  128. $updateFromConfigFile='';
  129. unset($_GET['running']);
  130. }
  131. else
  132. {
  133. $installType=$_GET['installType'];
  134. $updateFromConfigFile=$_GET['updateFromConfigFile'];
  135. }
  136. if(!isset($_GET['running']))
  137. {
  138. $dbHostForm='localhost';
  139. $dbUsernameForm='root';
  140. $dbPassForm='';
  141. $dbPrefixForm='';
  142. $dbNameForm='dokeos_main';
  143. $dbStatsForm='dokeos_stats';
  144. $dbScormForm='dokeos_scorm';
  145. $dbUserForm='dokeos_user';
  146. // extract the path to append to the url if Dokeos is not installed on the web root directory
  147. $urlAppendPath=str_replace('/main/install/index.php','',$_SERVER['PHP_SELF']);
  148. $urlForm='http://'.$_SERVER['HTTP_HOST'].$urlAppendPath.'/';
  149. $pathForm=str_replace('\\','/',realpath('../..')).'/';
  150. $emailForm=$_SERVER['SERVER_ADMIN'];
  151. $email_parts = explode('@',$emailForm);
  152. if($email_parts[1] == 'localhost')
  153. {
  154. $emailForm .= '.localdomain';
  155. }
  156. $adminLastName='Doe';
  157. $adminFirstName='John';
  158. $loginForm='admin';
  159. $passForm=api_generate_password();
  160. $campusForm='My campus';
  161. $educationForm='Albert Einstein';
  162. $adminPhoneForm='(000) 001 02 03';
  163. $institutionForm='My Organisation';
  164. $institutionUrlForm='http://www.dokeos.com';
  165. $languageForm='english';
  166. $checkEmailByHashSent=0;
  167. $ShowEmailnotcheckedToStudent=1;
  168. $userMailCanBeEmpty=1;
  169. $allowSelfReg=1;
  170. $allowSelfRegProf=1;
  171. $enableTrackingForm=1;
  172. $singleDbForm=0;
  173. $encryptPassForm=1;
  174. }
  175. else
  176. {
  177. foreach($_POST as $key=>$val)
  178. {
  179. $magic_quotes_gpc=ini_get('magic_quotes_gpc')?true:false;
  180. if(is_string($val))
  181. {
  182. if($magic_quotes_gpc)
  183. {
  184. $val=stripslashes($val);
  185. }
  186. $val=trim($val);
  187. $_POST[$key]=$val;
  188. }
  189. elseif(is_array($val))
  190. {
  191. foreach($val as $key2=>$val2)
  192. {
  193. if($magic_quotes_gpc)
  194. {
  195. $val2=stripslashes($val2);
  196. }
  197. $val2=trim($val2);
  198. $_POST[$key][$key2]=$val2;
  199. }
  200. }
  201. $GLOBALS[$key]=$_POST[$key];
  202. }
  203. }
  204. // The Steps
  205. $total_steps=7;
  206. if (!$_POST)
  207. {
  208. $current_step=1;
  209. }
  210. elseif (!empty($_POST['language_list']) or !empty($_POST['step1']) or (!empty($_POST['step2_update']) && ($emptyUpdatePath or $badUpdatePath)))
  211. {
  212. $current_step=2;
  213. }
  214. elseif (!empty($_POST['step2']) or !empty($_POST['step2_update']))
  215. {
  216. $current_step=3;
  217. }
  218. elseif (!empty($_POST['step3']))
  219. {
  220. $current_step=4;
  221. }
  222. elseif (!empty($_POST['step4']))
  223. {
  224. $current_step=5;
  225. }
  226. elseif (!empty($_POST['step5']))
  227. {
  228. $current_step=6;
  229. }
  230. ?>
  231. <!DOCTYPE html
  232. PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  233. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  234. <html xmlns="http://www.w3.org/1999/xhtml">
  235. <head>
  236. <title>&mdash; <?php echo get_lang('DokeosInstallation').' &mdash; '.get_lang('Version_').' '.$dokeos_version; ?></title>
  237. <style type="text/css" media="screen, projection">
  238. /*<![CDATA[*/
  239. @import "../css/default/default.css";
  240. /*]]>*/
  241. </style>
  242. </head>
  243. <body dir="<?php echo $text_dir ?>">
  244. <div id="header">
  245. <div id="header1"><?php echo get_lang('DokeosInstallation').' &mdash; '.get_lang('Version_').' '.$dokeos_version; ?><?php if($installType == 'new') echo ' &ndash; '.get_lang('NewInstallation'); else if($installType == 'update') echo ' &ndash; '.get_lang('UpdateFromDokeosVersion').implode('|',$update_from_version); ?></div>
  246. <div class="clear"></div>
  247. <div id="header2">&nbsp;</div>
  248. <div id="header3">&nbsp;</div>
  249. </div>
  250. <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>?running=1&amp;installType=<?php echo $installType; ?>&amp;updateFromConfigFile=<?php echo urlencode($updateFromConfigFile); ?>" autocomplete="off">
  251. <div id="installation_steps">
  252. <img src="../img/bluelogo.gif" hspace="10" vspace="10" alt="Dokeos logo" />
  253. <ol>
  254. <li <?php step_active('1'); ?>><?php echo get_lang('InstallationLanguage'); ?></li>
  255. <li <?php step_active('2'); ?>><?php echo get_lang('Requirements'); ?></li>
  256. <li <?php step_active('3'); ?>><?php echo get_lang('Licence'); ?></li>
  257. <li <?php step_active('4'); ?>><?php echo get_lang('DBSetting'); ?></li>
  258. <li <?php step_active('5'); ?>><?php echo get_lang('CfgSetting'); ?></li>
  259. <li <?php step_active('6'); ?>><?php echo get_lang('PrintOverview'); ?></li>
  260. <li <?php step_active('7'); ?>><?php echo get_lang('Installing'); ?></li>
  261. </ol>
  262. </div>
  263. <table cellpadding="6" cellspacing="0" border="0" width="80%" align="center">
  264. <tr>
  265. <td>
  266. <input type="hidden" name="updatePath" value="<?php if(!$badUpdatePath) echo htmlentities($_POST['updatePath']); ?>" />
  267. <input type="hidden" name="urlAppendPath" value="<?php echo htmlentities($urlAppendPath); ?>" />
  268. <input type="hidden" name="pathForm" value="<?php echo htmlentities($pathForm); ?>" />
  269. <input type="hidden" name="urlForm" value="<?php echo htmlentities($urlForm); ?>" />
  270. <input type="hidden" name="dbHostForm" value="<?php echo htmlentities($dbHostForm); ?>" />
  271. <input type="hidden" name="dbUsernameForm" value="<?php echo htmlentities($dbUsernameForm); ?>" />
  272. <input type="hidden" name="dbPassForm" value="<?php echo htmlentities($dbPassForm); ?>" />
  273. <input type="hidden" name="singleDbForm" value="<?php echo htmlentities($singleDbForm); ?>" />
  274. <input type="hidden" name="dbPrefixForm" value="<?php echo htmlentities($dbPrefixForm); ?>" />
  275. <input type="hidden" name="dbNameForm" value="<?php echo htmlentities($dbNameForm); ?>" />
  276. <input type="hidden" name="dbStatsForm" value="<?php echo htmlentities($dbStatsForm); ?>" />
  277. <input type="hidden" name="dbScormForm" value="<?php echo htmlentities($dbScormForm); ?>" />
  278. <input type="hidden" name="dbUserForm" value="<?php echo htmlentities($dbUserForm); ?>" />
  279. <input type="hidden" name="enableTrackingForm" value="<?php echo htmlentities($enableTrackingForm); ?>" />
  280. <input type="hidden" name="allowSelfReg" value="<?php echo htmlentities($allowSelfReg); ?>" />
  281. <input type="hidden" name="allowSelfRegProf" value="<?php echo htmlentities($allowSelfRegProf); ?>" />
  282. <input type="hidden" name="emailForm" value="<?php echo htmlentities($emailForm); ?>" />
  283. <input type="hidden" name="adminLastName" value="<?php echo htmlentities($adminLastName); ?>" />
  284. <input type="hidden" name="adminFirstName" value="<?php echo htmlentities($adminFirstName); ?>" />
  285. <input type="hidden" name="adminPhoneForm" value="<?php echo htmlentities($adminPhoneForm); ?>" />
  286. <input type="hidden" name="loginForm" value="<?php echo htmlentities($loginForm); ?>" />
  287. <input type="hidden" name="passForm" value="<?php echo htmlentities($passForm); ?>" />
  288. <input type="hidden" name="languageForm" value="<?php echo htmlentities($languageForm); ?>" />
  289. <input type="hidden" name="campusForm" value="<?php echo htmlentities($campusForm); ?>" />
  290. <input type="hidden" name="educationForm" value="<?php echo htmlentities($educationForm); ?>" />
  291. <input type="hidden" name="institutionForm" value="<?php echo htmlentities($institutionForm); ?>" />
  292. <input type="hidden" name="institutionUrlForm" value="<?php echo stristr($institutionUrlForm,'http://')?htmlentities($institutionUrlForm):'http://'.htmlentities($institutionUrlForm); ?>" />
  293. <input type="hidden" name="checkEmailByHashSent" value="<?php echo htmlentities($checkEmailByHashSent); ?>" />
  294. <input type="hidden" name="ShowEmailnotcheckedToStudent" value="<?php echo htmlentities($ShowEmailnotcheckedToStudent); ?>" />
  295. <input type="hidden" name="userMailCanBeEmpty" value="<?php echo htmlentities($userMailCanBeEmpty); ?>" />
  296. <input type="hidden" name="encryptPassForm" value="<?php echo htmlentities($encryptPassForm); ?>" />
  297. <?php
  298. if($_POST['step2'])
  299. {
  300. //STEP 3 : LICENSE
  301. display_license_agreement();
  302. }
  303. elseif($_POST['step3'])
  304. {
  305. //STEP 4 : MYSQL DATABASE SETTINGS
  306. display_database_settings_form($installType, $dbHostForm, $dbUsernameForm, $dbPassForm, $dbPrefixForm, $enableTrackingForm, $singleDbForm, $dbNameForm, $dbStatsForm, $dbScormForm, $dbUserForm);
  307. }
  308. elseif($_POST['step4'])
  309. {
  310. //STEP 5 : CONFIGURATION SETTINGS
  311. //if update, try getting settings from the database...
  312. if($installType == 'update')
  313. {
  314. $db_name = $dbNameForm;
  315. $tmp = get_config_param_from_db($dbHostForm,$dbUsernameForm,$dbPassForm,$db_name,'platformLanguage');
  316. if(!empty($tmp)) $languageForm = $tmp;
  317. $tmp = get_config_param_from_db($dbHostForm,$dbUsernameForm,$dbPassForm,$db_name,'emailAdministrator');
  318. if(!empty($tmp)) $emailForm = $tmp;
  319. $tmp = get_config_param_from_db($dbHostForm,$dbUsernameForm,$dbPassForm,$db_name,'administratorName');
  320. if(!empty($tmp)) $adminFirstName = $tmp;
  321. $tmp = get_config_param_from_db($dbHostForm,$dbUsernameForm,$dbPassForm,$db_name,'administratorSurname');
  322. if(!empty($tmp)) $adminLastName = $tmp;
  323. $tmp = get_config_param_from_db($dbHostForm,$dbUsernameForm,$dbPassForm,$db_name,'administratorTelephone');
  324. if(!empty($tmp)) $adminPhoneForm = $tmp;
  325. $tmp = get_config_param_from_db($dbHostForm,$dbUsernameForm,$dbPassForm,$db_name,'siteName');
  326. if(!empty($tmp)) $campusForm = $tmp;
  327. $tmp = get_config_param_from_db($dbHostForm,$dbUsernameForm,$dbPassForm,$db_name,'Institution');
  328. if(!empty($tmp)) $institutionForm = $tmp;
  329. $tmp = get_config_param_from_db($dbHostForm,$dbUsernameForm,$dbPassForm,$db_name,'InstitutionUrl');
  330. if(!empty($tmp)) $institutionUrlForm = $tmp;
  331. $urlForm = get_config_param('rootWeb');
  332. $encryptPassForm = get_config_param('userPasswordCrypted');
  333. $allowSelfReg = get_config_param('allowSelfReg');
  334. $allowSelfRegProf = get_config_param('allowSelfRegProf');
  335. }
  336. display_configuration_settings_form($installType, $urlForm, $languageForm, $emailForm, $adminFirstName, $adminLastName, $adminPhoneForm, $campusForm, $institutionForm, $institutionUrlForm, $encryptPassForm, $allowSelfReg, $allowSelfRegProf, $loginForm, $passForm);
  337. }
  338. elseif($_POST['step5'])
  339. {
  340. //STEP 6 : LAST CHECK BEFORE INSTALL
  341. ?>
  342. <h2><?php echo display_step_sequence().get_lang('LastCheck'); ?></h2>
  343. <?php echo get_lang('HereAreTheValuesYouEntered');?>
  344. <br>
  345. <b><?php echo get_lang('PrintThisPageToRememberPassAndOthers');?></b>
  346. <blockquote>
  347. <?php echo get_lang('MainLang').' : '.$languageForm; ?><br><br>
  348. <?php echo get_lang('DBHost').' : '.$dbHostForm; ?><br>
  349. <?php echo get_lang('DBLogin').' : '.$dbUsernameForm; ?><br>
  350. <?php echo get_lang('DBPassword').' : '.$dbPassForm; ?><br>
  351. <?php if(!empty($dbPrefixForm)) echo get_lang('DbPrefixForm').' : '.$dbPrefixForm.'<br>'; ?>
  352. <?php echo get_lang('MainDB').' : <b>'.$dbNameForm; ?></b><?php if($installType == 'new') echo ' (<font color="#cc0033">'.get_lang('ReadWarningBelow').'</font>)'; ?><br>
  353. <?php if(!$singleDbForm) { ?>
  354. <?php echo get_lang('StatDB').' : <b>'.$dbStatsForm; ?></b><?php if($installType == 'new') echo ' (<font color="#cc0033">'.get_lang('ReadWarningBelow').'</font>)'; ?><br>
  355. <?php echo get_lang('ScormDB').' : <b>'.$dbScormForm; ?></b><?php if($installType == 'new') echo ' (<font color="#cc0033">'.get_lang('ReadWarningBelow').'</font>)'; ?><br>
  356. <?php echo get_lang('UserDB').' : <b>'.$dbUserForm; ?></b><?php if($installType == 'new') echo ' (<font color="#cc0033">'.get_lang('ReadWarningBelow').'</font>)'; ?><br>
  357. <?php } ?>
  358. <?php echo get_lang('EnableTracking').' : '.($enableTrackingForm?$langYes:$langNo); ?><br>
  359. <?php echo get_lang('SingleDb').' : '.($singleDbForm?$langOne:$langSeveral); ?><br><br>
  360. <?php echo get_lang('AllowSelfReg').' : '.($allowSelfReg?$langYes:$langNo); ?><br>
  361. <?php echo get_lang('EncryptUserPass').' : '.($encryptPassForm?$langYes:$langNo); ?><br><br>
  362. <?php echo get_lang('AdminEmail').' : '.$emailForm; ?><br>
  363. <?php echo get_lang('AdminLastName').' : '.$adminLastName; ?><br>
  364. <?php echo get_lang('AdminFirstName').' : '.$adminFirstName; ?><br>
  365. <?php echo get_lang('AdminPhone').' : '.$adminPhoneForm; ?><br>
  366. <?php if($installType == 'new'): ?>
  367. <?php echo get_lang('AdminLogin').' : <b>'.$loginForm; ?></b><br>
  368. <?php echo get_lang('AdminPass').' : <b>'.$passForm; ?></b><br><br>
  369. <?php else: ?>
  370. <br>
  371. <?php endif; ?>
  372. <?php echo get_lang('CampusName').' : '.$campusForm; ?><br>
  373. <?php echo get_lang('InstituteShortName').' : '.$institutionForm; ?><br>
  374. <?php echo get_lang('InstituteURL').' : '.$institutionUrlForm; ?><br>
  375. <?php echo get_lang('DokeosURL').' : '.$urlForm; ?><br>
  376. </blockquote>
  377. <?php if($installType == 'new'): ?>
  378. <div style="background-color:#FFFFFF">
  379. <p align="center"><b><font color="red">
  380. <?php echo get_lang('Warning');?> !<br>
  381. <?php echo get_lang('TheInstallScriptWillEraseAllTables');?>
  382. </font></b></p>
  383. </div>
  384. <?php endif; ?>
  385. <table width="100%">
  386. <tr>
  387. <td><input type="submit" name="step4" value="&lt; <?php echo get_lang('Previous'); ?>" /></td>
  388. <td align="right"><input type="submit" name="step6" value="<?php echo get_lang('InstallDokeos'); ?> &gt;" onclick="javascript:if(this.value == '<?php echo get_lang('PleaseWait');?>...') return false; else this.value='<?php echo get_lang('PleaseWait');?>...';" /></td>
  389. </tr>
  390. </table>
  391. <?php
  392. }
  393. elseif($_POST['step6'])
  394. {
  395. //STEP 6 : INSTALLATION PROCESS
  396. if($installType == 'update')
  397. {
  398. $_configuration['main_database'] = $dbNameForm;
  399. //$urlAppendPath = get_config_param('urlAppend');
  400. include('update-db-1.6.x-1.8.0.inc.php');
  401. include('update-files-1.6.x-1.8.0.inc.php');
  402. }
  403. else
  404. {
  405. include('install_db.inc.php');
  406. include('install_files.inc.php');
  407. }
  408. display_after_install_message($installType, $nbr_courses);
  409. }
  410. elseif($_POST['step1'] || $badUpdatePath)
  411. {
  412. //STEP 1 : REQUIREMENTS
  413. display_requirements($installType, $badUpdatePath, $update_from_version);
  414. }
  415. else
  416. {
  417. //start screen
  418. display_language_selection();
  419. }
  420. ?>
  421. </td>
  422. </tr>
  423. </table>
  424. </form>
  425. <br style="clear:both;" />
  426. <div id="footer">
  427. <div class="copyright"><?php echo get_lang('Platform');?> <a href="http://www.dokeos.com"> Dokeos <?php echo $dokeos_version ?></a> &copy; <?php echo date('Y'); ?> </div>
  428. &nbsp;
  429. </div>
  430. </body>
  431. </html>