PageRenderTime 28ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/install/include/step2.php

https://github.com/harriswong/ATutor
PHP | 144 lines | 107 code | 23 blank | 14 comment | 25 complexity | d154f1377408bb41d8f4165d250f0311 MD5 | raw file
  1. <?php
  2. /************************************************************************/
  3. /* ATutor */
  4. /************************************************************************/
  5. /* Copyright (c) 2002-2010 */
  6. /* http://atutor.ca */
  7. /* This program is free software. You can redistribute it and/or */
  8. /* modify it under the terms of the GNU General Public License */
  9. /* as published by the Free Software Foundation. */
  10. /************************************************************************/
  11. // $Id$
  12. if (!defined('AT_INCLUDE_PATH')) { exit; }
  13. if(isset($_POST['submit'])) {
  14. unset($errors);
  15. unset($progress);
  16. //check DB & table connection
  17. $db = @mysql_connect($_POST['db_host'] . ':' . $_POST['db_port'], $_POST['db_login'], $_POST['db_password']);
  18. if (!$db) {
  19. $errors[] = 'Unable to connect to database server.';
  20. } else {
  21. // check mysql version number
  22. $sql = "SELECT VERSION() AS version";
  23. $result = mysql_query($sql, $db);
  24. $row = mysql_fetch_assoc($result);
  25. $row['version'] = str_replace (array('-community-nt', '-max', '-standard'), '', strtolower($row['version']));
  26. if (version_compare($row['version'], '4.1.10', '>=') === FALSE) {
  27. $errors[] = 'MySQL version '.$row['version'].' was detected. ATutor requires version 4.1.10 or later.';
  28. }
  29. if (!isset($errors)){
  30. if (!mysql_select_db($_POST['db_name'], $db)) {
  31. $sql = "CREATE DATABASE `$_POST[db_name]` CHARACTER SET utf8 COLLATE utf8_general_ci";
  32. $result = mysql_query($sql, $db);
  33. if (!$result) {
  34. $errors[] = 'Unable to select or create database <b>'.$_POST['db_name'].'</b>.';
  35. } else {
  36. $progress[] = 'Database <b>'.$_POST['db_name'].'</b> created successfully.';
  37. mysql_select_db($_POST['db_name'], $db);
  38. }
  39. } else {
  40. /* Check if the database that existed is in UTF-8, if not, ask for retry */
  41. $sql = "SHOW CREATE DATABASE `$_POST[db_name]`";
  42. $result = mysql_query($sql, $db);
  43. $row = mysql_fetch_assoc($result);
  44. if (!preg_match('/CHARACTER SET utf8/i', $row['Create Database'])){
  45. $sql2 = 'ALTER DATABASE `'.$_POST['db_name'].'` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci';
  46. $result2 = mysql_query($sql2);
  47. if (!$result2){
  48. $errors[] = 'Database <b>'.$_POST['db_name'].'</b> is not in UTF8. Please set the database character set to UTF8 before continuing by using the following query: <br /> ALTER DATABASE `'.$_POST['db_name'].'` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci. <br />To use ALTER DATABASE, you need the ALTER privilege on the database. You can also check the MySQL manual <a href="http://dev.mysql.com/doc/refman/4.1/en/alter-database.html" target="mysql_window">here</a>.';
  49. }
  50. }
  51. }
  52. }
  53. if (!isset($errors)) {
  54. $progress[] = 'Connected to database <b>'.$_POST['db_name'].'</b> successfully.';
  55. $errors = array();
  56. /* @See include/classes/dbmanager.php */
  57. queryFromFile('db/atutor_schema.sql');
  58. queryFromFile('db/atutor_language_text.sql');
  59. if (!$errors) {
  60. print_progress($step);
  61. unset($_POST['submit']);
  62. unset($_POST['action']);
  63. store_steps($step);
  64. print_feedback($progress);
  65. echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post" name="form">
  66. <input type="hidden" name="step" value="3" />';
  67. print_hidden(3);
  68. echo '<p align="center"><input type="submit" class="button" value="Next &raquo; " name="submit" /></p></form>';
  69. return;
  70. }
  71. }
  72. }
  73. }
  74. print_progress($step);
  75. echo '<p>Please enter your database information: </p>';
  76. if (isset($progress)) {
  77. print_feedback($progress);
  78. }
  79. if (isset($errors)) {
  80. print_errors($errors);
  81. }
  82. ?>
  83. <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
  84. <input type="hidden" name="action" value="process" />
  85. <input type="hidden" name="step" value="2" />
  86. <input type="hidden" name="new_version" value="<?php echo $_POST['new_version']; ?>" />
  87. <table width="65%" class="tableborder" cellspacing="0" cellpadding="1" border="0" align="center">
  88. <tr>
  89. <td class="row1"><span class="required" title="Required Field">*</span><b><label for="db">Database Hostname:</label></b><br />
  90. Hostname of the database server. Default: <kbd>localhost</kbd></td>
  91. <td class="row1" valign="middle"><input type="text" name="db_host" id="db" value="<?php if (!empty($_POST['db_host'])) { echo stripslashes(htmlspecialchars($_POST['db_host'])); } else { echo 'localhost'; } ?>" class="formfield" /></td>
  92. </tr>
  93. <tr>
  94. <td class="row1"><span class="required" title="Required Field">*</span><b><label for="port">Database Port:</label></b><br />
  95. The port to the database server. Default: <kbd>3306</kbd></td>
  96. <td class="row1"><input type="text" name="db_port" id="port" value="<?php if (!empty($_POST['db_port'])) { echo stripslashes(htmlspecialchars($_POST['db_port'])); } else { echo '3306'; } ?>" class="formfield" /></td>
  97. </tr>
  98. <tr>
  99. <td class="row1"><span class="required" title="Required Field">*</span><b><label for="username">Database Username:</label></b><br />
  100. The username to the database server.</td>
  101. <td class="row1"><input type="text" name="db_login" id="username" value="<?php echo stripslashes(htmlspecialchars($_POST['db_login'])); ?>" class="formfield" /></td>
  102. </tr>
  103. <tr>
  104. <td class="row1"><span class="required" title="Required Field">*</span><b><label for="pass">Database Password:</label></b><br />
  105. The password to the database server.</td>
  106. <td class="row1"><input type="text" name="db_password" id="pass" value="<?php echo stripslashes(htmlspecialchars($_POST['db_password'])); ?>" class="formfield" /></td>
  107. </tr>
  108. <tr>
  109. <td class="row1"><span class="required" title="Required Field">*</span><b><label for="name">Database Name:</label></b><br />
  110. The name of the database to use. It will be created if it does not exist.<br />Default: <kbd>atutor</kbd></td>
  111. <td class="row1"><input type="text" name="db_name" id="name" value="<?php if (!empty($_POST['db_name'])) { echo stripslashes(htmlspecialchars($_POST['db_name'])); } else { echo 'atutor'; } ?>" class="formfield" /></td>
  112. </tr>
  113. <tr>
  114. <td class="row1"><div class="optional" title="Optional Field">?</div><b><label for="prefix">Table Prefix:</label></b><br />
  115. The prefix to add to table names to avoid conflicts with existing tables.<br />
  116. Default: <kbd>AT_</kbd></td>
  117. <td class="row1"><input type="text" name="tb_prefix" id="prefix" value="<?php if (!empty($_POST['tb_prefix'])) { echo stripslashes(htmlspecialchars($_POST['tb_prefix'])); } else { echo 'AT_'; } ?>" class="formfield" /></td>
  118. </tr>
  119. </table>
  120. <br /><br /><p align="center"><input type="submit" class="button" value="Next &raquo; " name="submit" /></p>
  121. </form>