install_db.inc.php 6.6 KB

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