dokeos-install
[ class tree: dokeos-install ] [ index: dokeos-install ] [ all elements ]

Source for file install_db.inc.php

Documentation is available at install_db.inc.php

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

Documentation generated on Thu, 12 Jun 2008 13:52:46 -0500 by phpDocumentor 1.4.1