2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2002-2010 */
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 /************************************************************************/
13 if (!defined('AT_INCLUDE_PATH')) { exit; }
15 if(isset($_POST['submit'])) {
19 //check DB & table connection
21 $db = @mysql_connect($_POST['db_host'] . ':' . $_POST['db_port'], $_POST['db_login'], $_POST['db_password']);
23 $errors[] = 'Unable to connect to database server.';
25 // check mysql version number
26 $sql = "SELECT VERSION() AS version";
27 $result = mysql_query($sql, $db);
28 $row = mysql_fetch_assoc($result);
29 $row['version'] = str_replace (array('-community-nt', '-max', '-standard'), '', strtolower($row['version']));
30 if (version_compare($row['version'], '4.1.10', '>=') === FALSE) {
31 $errors[] = 'MySQL version '.$row['version'].' was detected. ATutor requires version 4.1.10 or later.';
35 if (!mysql_select_db($_POST['db_name'], $db)) {
36 $sql = "CREATE DATABASE `$_POST[db_name]` CHARACTER SET utf8 COLLATE utf8_general_ci";
37 $result = mysql_query($sql, $db);
39 $errors[] = 'Unable to select or create database <b>'.$_POST['db_name'].'</b>.';
41 $progress[] = 'Database <b>'.$_POST['db_name'].'</b> created successfully.';
42 mysql_select_db($_POST['db_name'], $db);
45 /* Check if the database that existed is in UTF-8, if not, ask for retry */
46 $sql = "SHOW CREATE DATABASE `$_POST[db_name]`";
47 $result = mysql_query($sql, $db);
48 $row = mysql_fetch_assoc($result);
50 if (!preg_match('/CHARACTER SET utf8/i', $row['Create Database'])){
51 $sql2 = 'ALTER DATABASE `'.$_POST['db_name'].'` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci';
52 $result2 = mysql_query($sql2);
54 $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>.';
60 if (!isset($errors)) {
61 $progress[] = 'Connected to database <b>'.$_POST['db_name'].'</b> successfully.';
64 /* @See include/classes/dbmanager.php */
65 queryFromFile('db/atutor_schema.sql');
66 queryFromFile('db/atutor_language_text.sql');
69 print_progress($step);
71 unset($_POST['submit']);
72 unset($_POST['action']);
74 print_feedback($progress);
76 echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post" name="form">
77 <input type="hidden" name="step" value="3" />';
79 echo '<p align="center"><input type="submit" class="button" value="Next » " name="submit" /></p></form>';
87 print_progress($step);
90 echo '<p>Please enter your database information: </p>';
93 if (isset($progress)) {
94 print_feedback($progress);
98 print_errors($errors);
103 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
104 <input type="hidden" name="action" value="process" />
105 <input type="hidden" name="step" value="2" />
106 <input type="hidden" name="new_version" value="<?php echo $_POST['new_version']; ?>" />
108 <table width="65%" class="tableborder" cellspacing="0" cellpadding="1" border="0" align="center">
110 <td class="row1"><span class="required" title="Required Field">*</span><b><label for="db">Database Hostname:</label></b><br />
111 Hostname of the database server. Default: <kbd>localhost</kbd></td>
112 <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>
115 <td class="row1"><span class="required" title="Required Field">*</span><b><label for="port">Database Port:</label></b><br />
116 The port to the database server. Default: <kbd>3306</kbd></td>
117 <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>
120 <td class="row1"><span class="required" title="Required Field">*</span><b><label for="username">Database Username:</label></b><br />
121 The username to the database server.</td>
122 <td class="row1"><input type="text" name="db_login" id="username" value="<?php echo stripslashes(htmlspecialchars($_POST['db_login'])); ?>" class="formfield" /></td>
125 <td class="row1"><span class="required" title="Required Field">*</span><b><label for="pass">Database Password:</label></b><br />
126 The password to the database server.</td>
127 <td class="row1"><input type="text" name="db_password" id="pass" value="<?php echo stripslashes(htmlspecialchars($_POST['db_password'])); ?>" class="formfield" /></td>
130 <td class="row1"><span class="required" title="Required Field">*</span><b><label for="name">Database Name:</label></b><br />
131 The name of the database to use. It will be created if it does not exist.<br />Default: <kbd>atutor</kbd></td>
132 <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>
135 <td class="row1"><div class="optional" title="Optional Field">?</div><b><label for="prefix">Table Prefix:</label></b><br />
136 The prefix to add to table names to avoid conflicts with existing tables.<br />
137 Default: <kbd>AT_</kbd></td>
138 <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>
142 <br /><br /><p align="center"><input type="submit" class="button" value="Next » " name="submit" /></p>