install_db.inc.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2005 Dokeos S.A.
  6. Copyright (c) 2003 Ghent University (UGent)
  7. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  8. Copyright (c) various contributors
  9. For a full list of contributors, see "credits.txt".
  10. The full license can be read in "license.txt".
  11. This program is free software; you can redistribute it and/or
  12. modify it under the terms of the GNU General Public License
  13. as published by the Free Software Foundation; either version 2
  14. of the License, or (at your option) any later version.
  15. See the GNU General Public License for more details.
  16. Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
  17. Mail: info@dokeos.com
  18. ==============================================================================
  19. */
  20. /**
  21. ==============================================================================
  22. * Install the Dokeos database
  23. * Notice : This script has to be included by index.php
  24. *
  25. * @package dokeos.install
  26. ==============================================================================
  27. */
  28. require_once("install_upgrade.lib.php");
  29. /*
  30. ==============================================================================
  31. MAIN CODE
  32. ==============================================================================
  33. */
  34. //this page can only be access through including from the install script.
  35. if( ! defined('DOKEOS_INSTALL'))
  36. {
  37. echo 'You are not allowed here!';
  38. exit;
  39. }
  40. set_file_folder_permissions();
  41. @mysql_connect($dbHostForm,$dbUsernameForm,$dbPassForm);
  42. if(mysql_errno() > 0)
  43. {
  44. $no=mysql_errno();
  45. $msg=mysql_error();
  46. echo '<hr />['.$no.'] &ndash; '.$msg.'<hr>
  47. The MySQL server doesn\'t work or login / pass is bad.<br /><br />
  48. Please check these values:<br /><br />
  49. <b>host</b> : '.$dbHostForm.'<br />
  50. <b>user</b> : '.$dbUsernameForm.'<br />
  51. <b>password</b> : '.$dbPassForm.'<br /><br />
  52. Please go back to step 3.
  53. <p><input type="submit" name="step3" value="&lt; Back" /></p>
  54. </td></tr></table></form></body></html>';
  55. exit();
  56. }
  57. if($urlForm[strlen($urlForm)-1] != '/')
  58. {
  59. $urlForm=$urlForm.'/';
  60. }
  61. if($encryptPassForm)
  62. {
  63. $passToStore=md5($passForm);
  64. }
  65. else
  66. {
  67. $passToStore=($passForm);
  68. }
  69. $dbPrefixForm=eregi_replace('[^a-z0-9_-]','',$dbPrefixForm);
  70. $dbNameForm=eregi_replace('[^a-z0-9_-]','',$dbNameForm);
  71. $dbStatsForm=eregi_replace('[^a-z0-9_-]','',$dbStatsForm);
  72. $dbUserForm=eregi_replace('[^a-z0-9_-]','',$dbUserForm);
  73. if(!empty($dbPrefixForm) && !ereg('^'.$dbPrefixForm,$dbNameForm))
  74. {
  75. $dbNameForm=$dbPrefixForm.$dbNameForm;
  76. }
  77. if(!empty($dbPrefixForm) && !ereg('^'.$dbPrefixForm,$dbStatsForm))
  78. {
  79. $dbStatsForm=$dbPrefixForm.$dbStatsForm;
  80. }
  81. if(!empty($dbPrefixForm) && !ereg('^'.$dbPrefixForm,$dbUserForm))
  82. {
  83. $dbUserForm=$dbPrefixForm.$dbUserForm;
  84. }
  85. $mysqlMainDb=$dbNameForm;
  86. $mysqlStatsDb=$dbStatsForm;
  87. $mysqlUserDb=$dbUserForm;
  88. if(empty($mysqlMainDb) || $mysqlMainDb == 'mysql' || $mysqlMainDb == $dbPrefixForm)
  89. {
  90. $mysqlMainDb=$dbPrefixForm.'main';
  91. }
  92. if(empty($mysqlStatsDb) || $mysqlStatsDb == 'mysql' || $mysqlStatsDb == $dbPrefixForm)
  93. {
  94. $mysqlStatsDb=$dbPrefixForm.'stats';
  95. }
  96. if(empty($mysqlUserDb) || $mysqlUserDb == 'mysql' || $mysqlUserDb == $dbPrefixForm)
  97. {
  98. $mysqlUserDb=$dbPrefixForm.'user';
  99. }
  100. $result=mysql_query("SHOW VARIABLES LIKE 'datadir'") or die(mysql_error());
  101. $mysqlRepositorySys=mysql_fetch_array($result);
  102. $mysqlRepositorySys=$mysqlRepositorySys['Value'];
  103. if(!$singleDbForm)
  104. {
  105. mysql_query("DROP DATABASE IF EXISTS `$mysqlMainDb`") or die(mysql_error());
  106. }
  107. mysql_query("CREATE DATABASE IF NOT EXISTS `$mysqlMainDb`") or die(mysql_error());
  108. if($mysqlStatsDb == $mysqlMainDb && $mysqlUserDb == $mysqlMainDb)
  109. {
  110. $singleDbForm=true;
  111. }
  112. /**
  113. * CREATING THE STATISTICS DATABASE
  114. */
  115. if($mysqlStatsDb != $mysqlMainDb)
  116. {
  117. if(!$singleDbForm)
  118. {
  119. // multi DB mode AND tracking has its own DB so create it
  120. mysql_query("DROP DATABASE IF EXISTS `$mysqlStatsDb`") or die(mysql_error());
  121. mysql_query("CREATE DATABASE `$mysqlStatsDb`") or die(mysql_error());
  122. }
  123. else
  124. {
  125. // single DB mode so $mysqlStatsDb MUST BE the SAME than $mysqlMainDb
  126. $mysqlStatsDb=$mysqlMainDb;
  127. }
  128. }
  129. /**
  130. * CREATING THE USER DATABASE
  131. */
  132. if($mysqlUserDb != $mysqlMainDb)
  133. {
  134. if(!$singleDbForm)
  135. {
  136. // multi DB mode AND user data has its own DB so create it
  137. mysql_query("DROP DATABASE IF EXISTS `$mysqlUserDb`") or die(mysql_error());
  138. mysql_query("CREATE DATABASE `$mysqlUserDb`") or die(mysql_error());
  139. }
  140. else
  141. {
  142. // single DB mode so $mysqlUserDb MUST BE the SAME than $mysqlMainDb
  143. $mysqlUserDb=$mysqlMainDb;
  144. }
  145. }
  146. include("../lang/english/create_course.inc.php");
  147. if($languageForm != 'english')
  148. {
  149. include("../lang/$languageForm/create_course.inc.php");
  150. }
  151. /**
  152. * creating the tables of the main database
  153. */
  154. mysql_select_db($mysqlMainDb) or die(mysql_error());
  155. $installation_settings['{ORGANISATIONNAME}'] = $institutionForm;
  156. $installation_settings['{ORGANISATIONURL}'] = $institutionUrlForm;
  157. $installation_settings['{CAMPUSNAME}'] = $campusForm;
  158. $installation_settings['{PLATFORMLANGUAGE}'] = $languageForm;
  159. $installation_settings['{ALLOWSELFREGISTRATION}'] = trueFalse($allowSelfReg);
  160. $installation_settings['{ALLOWTEACHERSELFREGISTRATION}'] = trueFalse($allowSelfRegProf);
  161. $installation_settings['{ADMINLASTNAME}'] = $adminLastName;
  162. $installation_settings['{ADMINFIRSTNAME}'] = $adminFirstName;
  163. $installation_settings['{ADMINLOGIN}'] = $loginForm;
  164. $installation_settings['{ADMINPASSWORD}'] = $passToStore;
  165. $installation_settings['{ADMINEMAIL}'] = $emailForm;
  166. $installation_settings['{ADMINPHONE}'] = $adminPhoneForm;
  167. $installation_settings['{PLATFORM_AUTH_SOURCE}'] = PLATFORM_AUTH_SOURCE;
  168. load_main_database($installation_settings);
  169. /**
  170. * creating the tables of the tracking database
  171. */
  172. mysql_select_db($mysqlStatsDb) or die(mysql_error());
  173. load_database_script('dokeos_stats.sql');
  174. $track_countries_table = "track_c_countries";
  175. fill_track_countries_table($track_countries_table);
  176. /**
  177. * creating the tables of the USER database
  178. * this is where the personal agenda items are storen, the user defined course categories (sorting of my courses)
  179. */
  180. mysql_select_db($mysqlUserDb) or die(mysql_error());
  181. load_database_script('dokeos_user.sql');
  182. ?>