install_db.inc.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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> : '.str_repeat('*',strlen($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. // The Dokeos system has not been designed to use special SQL modes that were introduced since MySQL 5
  58. @mysql_query("set session sql_mode='';");
  59. if($urlForm[strlen($urlForm)-1] != '/')
  60. {
  61. $urlForm=$urlForm.'/';
  62. }
  63. if($encryptPassForm)
  64. {
  65. $passToStore=md5($passForm);
  66. }
  67. else
  68. {
  69. $passToStore=($passForm);
  70. }
  71. $dbPrefixForm=eregi_replace('[^a-z0-9_-]','',$dbPrefixForm);
  72. $dbNameForm=eregi_replace('[^a-z0-9_-]','',$dbNameForm);
  73. $dbStatsForm=eregi_replace('[^a-z0-9_-]','',$dbStatsForm);
  74. $dbUserForm=eregi_replace('[^a-z0-9_-]','',$dbUserForm);
  75. if(!empty($dbPrefixForm) && !ereg('^'.$dbPrefixForm,$dbNameForm))
  76. {
  77. $dbNameForm=$dbPrefixForm.$dbNameForm;
  78. }
  79. if(!empty($dbPrefixForm) && !ereg('^'.$dbPrefixForm,$dbStatsForm))
  80. {
  81. $dbStatsForm=$dbPrefixForm.$dbStatsForm;
  82. }
  83. if(!empty($dbPrefixForm) && !ereg('^'.$dbPrefixForm,$dbUserForm))
  84. {
  85. $dbUserForm=$dbPrefixForm.$dbUserForm;
  86. }
  87. $mysqlMainDb=$dbNameForm;
  88. $mysqlStatsDb=$dbStatsForm;
  89. $mysqlUserDb=$dbUserForm;
  90. if(empty($mysqlMainDb) || $mysqlMainDb == 'mysql' || $mysqlMainDb == $dbPrefixForm)
  91. {
  92. $mysqlMainDb=$dbPrefixForm.'main';
  93. }
  94. if(empty($mysqlStatsDb) || $mysqlStatsDb == 'mysql' || $mysqlStatsDb == $dbPrefixForm)
  95. {
  96. $mysqlStatsDb=$dbPrefixForm.'stats';
  97. }
  98. if(empty($mysqlUserDb) || $mysqlUserDb == 'mysql' || $mysqlUserDb == $dbPrefixForm)
  99. {
  100. $mysqlUserDb=$dbPrefixForm.'user';
  101. }
  102. $result=mysql_query("SHOW VARIABLES LIKE 'datadir'") or die(mysql_error());
  103. $mysqlRepositorySys=mysql_fetch_array($result);
  104. $mysqlRepositorySys=$mysqlRepositorySys['Value'];
  105. if(!$singleDbForm)
  106. {
  107. mysql_query("DROP DATABASE IF EXISTS `$mysqlMainDb`") or die(mysql_error());
  108. }
  109. mysql_query("CREATE DATABASE IF NOT EXISTS `$mysqlMainDb`") or die(mysql_error());
  110. if($mysqlStatsDb == $mysqlMainDb && $mysqlUserDb == $mysqlMainDb)
  111. {
  112. $singleDbForm=true;
  113. }
  114. /**
  115. * CREATING THE STATISTICS DATABASE
  116. */
  117. if($mysqlStatsDb != $mysqlMainDb)
  118. {
  119. if(!$singleDbForm)
  120. {
  121. // multi DB mode AND tracking has its own DB so create it
  122. mysql_query("DROP DATABASE IF EXISTS `$mysqlStatsDb`") or die(mysql_error());
  123. mysql_query("CREATE DATABASE `$mysqlStatsDb`") or die(mysql_error());
  124. }
  125. else
  126. {
  127. // single DB mode so $mysqlStatsDb MUST BE the SAME than $mysqlMainDb
  128. $mysqlStatsDb=$mysqlMainDb;
  129. }
  130. }
  131. /**
  132. * CREATING THE USER DATABASE
  133. */
  134. if($mysqlUserDb != $mysqlMainDb)
  135. {
  136. if(!$singleDbForm)
  137. {
  138. // multi DB mode AND user data has its own DB so create it
  139. mysql_query("DROP DATABASE IF EXISTS `$mysqlUserDb`") or die(mysql_error());
  140. mysql_query("CREATE DATABASE `$mysqlUserDb`") or die(mysql_error());
  141. }
  142. else
  143. {
  144. // single DB mode so $mysqlUserDb MUST BE the SAME than $mysqlMainDb
  145. $mysqlUserDb=$mysqlMainDb;
  146. }
  147. }
  148. include("../lang/english/create_course.inc.php");
  149. if($languageForm != 'english')
  150. {
  151. include("../lang/$languageForm/create_course.inc.php");
  152. }
  153. /**
  154. * creating the tables of the main database
  155. */
  156. mysql_select_db($mysqlMainDb) or die(mysql_error());
  157. $installation_settings['{ORGANISATIONNAME}'] = $institutionForm;
  158. $installation_settings['{ORGANISATIONURL}'] = $institutionUrlForm;
  159. $installation_settings['{CAMPUSNAME}'] = $campusForm;
  160. $installation_settings['{PLATFORMLANGUAGE}'] = $languageForm;
  161. $installation_settings['{ALLOWSELFREGISTRATION}'] = trueFalse($allowSelfReg);
  162. $installation_settings['{ALLOWTEACHERSELFREGISTRATION}'] = trueFalse($allowSelfRegProf);
  163. $installation_settings['{ADMINLASTNAME}'] = $adminLastName;
  164. $installation_settings['{ADMINFIRSTNAME}'] = $adminFirstName;
  165. $installation_settings['{ADMINLOGIN}'] = $loginForm;
  166. $installation_settings['{ADMINPASSWORD}'] = $passToStore;
  167. $installation_settings['{ADMINEMAIL}'] = $emailForm;
  168. $installation_settings['{ADMINPHONE}'] = $adminPhoneForm;
  169. $installation_settings['{PLATFORM_AUTH_SOURCE}'] = PLATFORM_AUTH_SOURCE;
  170. $installation_settings['{ADMINLANGUAGE}'] = $languageForm;
  171. load_main_database($installation_settings);
  172. /**
  173. * creating the tables of the tracking database
  174. */
  175. mysql_select_db($mysqlStatsDb) or die(mysql_error());
  176. load_database_script('dokeos_stats.sql');
  177. $track_countries_table = "track_c_countries";
  178. fill_track_countries_table($track_countries_table);
  179. /**
  180. * creating the tables of the USER database
  181. * this is where the personal agenda items are storen, the user defined course categories (sorting of my courses)
  182. */
  183. mysql_select_db($mysqlUserDb) or die(mysql_error());
  184. load_database_script('dokeos_user.sql');
  185. ?>