2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2002-2008 by Greg Gay, Joel Kronenberg, Heidi Hazelton */
8 /* This program is free software. You can redistribute it and/or */
9 /* modify it under the terms of the GNU General Public License */
10 /* as published by the Free Software Foundation. */
11 /************************************************************************/
14 if (!defined('AT_INCLUDE_PATH')) { exit; }
16 if(isset($_POST['submit'])) {
20 //check DB & table connection
22 $db = @mysql_connect($_POST['db_host'] . ':' . $_POST['db_port'], $_POST['db_login'], $_POST['db_password']);
24 $errors[] = 'Unable to connect to database server.';
26 // check mysql version number
27 $sql = "SELECT VERSION() AS version";
28 $result = mysql_query($sql, $db);
29 $row = mysql_fetch_assoc($result);
30 $row['version'] = str_replace (array('-community-nt', '-max', '-standard'), '', strtolower($row['version']));
31 if (version_compare($row['version'], '4.1.10', '>=') === FALSE) {
32 $errors[] = 'MySQL version '.$row['version'].' was detected. ATutor requires version 4.1.10 or later.';
36 if (!mysql_select_db($_POST['db_name'], $db)) {
37 $sql = "CREATE DATABASE `$_POST[db_name]` CHARACTER SET utf8 COLLATE utf8_general_ci";
38 $result = mysql_query($sql, $db);
40 $errors[] = 'Unable to select or create database <b>'.$_POST['db_name'].'</b>.';
42 $progress[] = 'Database <b>'.$_POST['db_name'].'</b> created successfully.';
43 mysql_select_db($_POST['db_name'], $db);
46 /* Check if the database that existed is in UTF-8, if not, ask for retry */
47 $sql = "SHOW CREATE DATABASE `$_POST[db_name]`";
48 $result = mysql_query($sql, $db);
49 $row = mysql_fetch_assoc($result);
51 if (!preg_match('/CHARACTER SET utf8/i', $row['Create Database'])){
52 $sql2 = 'ALTER DATABASE `'.$_POST['db_name'].'` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci';
53 $result2 = mysql_query($sql2);
55 $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>.';
61 if (!isset($errors)) {
62 $progress[] = 'Connected to database <b>'.$_POST['db_name'].'</b> successfully.';
65 /* @See include/classes/dbmanager.php */
66 queryFromFile('db/atutor_schema.sql');
67 queryFromFile('db/atutor_language_text.sql');
70 print_progress($step);
72 unset($_POST['submit']);
73 unset($_POST['action']);
75 print_feedback($progress);
77 echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post" name="form">
78 <input type="hidden" name="step" value="3" />';
80 echo '<p align="center"><input type="submit" class="button" value="Next » " name="submit" /></p></form>';
88 print_progress($step);
91 echo '<p>Please enter your database information: </p>';
94 if (isset($progress)) {
95 print_feedback($progress);
99 print_errors($errors);
104 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
105 <input type="hidden" name="action" value="process" />
106 <input type="hidden" name="step" value="2" />
107 <input type="hidden" name="new_version" value="<?php echo $_POST['new_version']; ?>" />
109 <table width="65%" class="tableborder" cellspacing="0" cellpadding="1" border="0" align="center">
111 <td class="row1"><div class="required" title="Required Field">*</div><b><label for="db">Database Hostname:</label></b><br />
112 Hostname of the database server. Default: <kbd>localhost</kbd></td>
113 <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>
116 <td class="row1"><div class="required" title="Required Field">*</div><b><label for="port">Database Port:</label></b><br />
117 The port to the database server. Default: <kbd>3306</kbd></td>
118 <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>
121 <td class="row1"><div class="required" title="Required Field">*</div><b><label for="username">Database Username:</label></b><br />
122 The username to the database server.</td>
123 <td class="row1"><input type="text" name="db_login" id="username" value="<?php echo stripslashes(htmlspecialchars($_POST['db_login'])); ?>" class="formfield" /></td>
126 <td class="row1"><div class="required" title="Required Field">*</div><b><label for="pass">Database Password:</label></b><br />
127 The password to the database server.</td>
128 <td class="row1"><input type="text" name="db_password" id="pass" value="<?php echo stripslashes(htmlspecialchars($_POST['db_password'])); ?>" class="formfield" /></td>
131 <td class="row1"><div class="required" title="Required Field">*</div><b><label for="name">Database Name:</label></b><br />
132 The name of the database to use. It will be created if it does not exist.<br />Default: <kbd>atutor</kbd></td>
133 <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>
136 <td class="row1"><div class="optional" title="Optional Field">?</div><b><label for="prefix">Table Prefix:</label></b><br />
137 The prefix to add to table names to avoid conflicts with existing tables.<br />
138 Default: <kbd>AT_</kbd></td>
139 <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>
143 <br /><br /><p align="center"><input type="submit" class="button" value="Next » " name="submit" /></p>