moved code up one level to eliminate the docs subdirectory
[acontent.git] / install / include / step2.php
1 <?php
2 /************************************************************************/
3 /* AContent                                                             */
4 /************************************************************************/
5 /* Copyright (c) 2010                                                   */
6 /* Inclusive Design Institute                                           */
7 /*                                                                      */
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 /************************************************************************/
12
13 if (!defined('TR_INCLUDE_PATH')) { exit; }
14
15 if(isset($_POST['submit'])) {
16         unset($errors);
17         unset($progress);
18
19         //check DB & table connection
20
21         $db = @mysql_connect($_POST['db_host'] . ':' . $_POST['db_port'], $_POST['db_login'], $_POST['db_password']);
22         if (!$db) {
23                 $errors[] = 'Unable to connect to database server.';
24         } else {
25                 // check mysql version number
26                 $sql = "SELECT VERSION() AS version";
27                 $result = mysql_query($sql, $db);
28                 $row = mysql_fetch_assoc($result);
29                 if (version_compare($row['version'], '4.1.10', '>=') === FALSE) {
30                         $errors[] = 'MySQL version '.$row['version'].' was detected. AContent requires version 4.1.10 or later.';
31                 }
32
33                 if (!isset($errors)){
34                         if (!mysql_select_db($_POST['db_name'], $db)) {
35                                 $sql = "CREATE DATABASE $_POST[db_name] CHARACTER SET utf8 COLLATE utf8_general_ci";
36                                 $result = mysql_query($sql, $db);
37                                 if (!$result) {
38                                         $errors[] = 'Unable to select or create database <b>'.$_POST['db_name'].'</b>.';
39                                 } else {
40                                         $progress[] = 'Database <b>'.$_POST['db_name'].'</b> created successfully.';
41                                         mysql_select_db($_POST['db_name'], $db);
42                                 }
43                         } else {
44                                 /* Check if the database that existed is in UTF-8, if not, ask for retry */
45                                 $sql = "SHOW CREATE DATABASE $_POST[db_name]";
46                                 $result = mysql_query($sql, $db);
47                                 $row = mysql_fetch_assoc($result);
48                                 
49                                 if (!preg_match('/CHARACTER SET utf8/i', $row['Create Database'])){
50                                         $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: ALTER DATABASE `'.$_POST['db_name'].'` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci.  To use ALTER DATABASE, you need the ALTER privilege on the database.';
51                                 }
52                         }
53                 }
54
55                 if (!isset($errors)) {
56                         $progress[] = 'Connected to database <b>'.$_POST['db_name'].'</b> successfully.';
57                         $errors = array();
58                         
59                         /* @See include/classes/dbmanager.php */
60                         queryFromFile('db/db_schema.sql');
61                         queryFromFile('db/language_text.sql');
62                         queryFromFile('db/HowTo_lesson.sql');
63
64                         if (!$errors) {
65                                 print_progress($step);
66
67                                 unset($_POST['submit']);
68                                 unset($_POST['action']);
69                                 store_steps($step);
70                                 print_feedback($progress);
71
72                                 echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post" name="form">
73                                 <input type="hidden" name="step" value="3" />';
74                                 print_hidden(3);
75                                 echo '<p align="center"><input type="submit" class="button" value="Next &raquo; " name="submit" /></p></form>';
76                                 return;
77                         }
78                 }
79
80         }
81 }
82
83 print_progress($step);
84
85
86 echo '<p>Please enter your database information: </p>';
87
88
89 if (isset($progress)) {
90         print_feedback($progress);
91 }
92
93 if (isset($errors)) {
94         print_errors($errors);
95 }
96
97 ?>
98
99 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
100         <input type="hidden" name="action" value="process" />
101         <input type="hidden" name="step" value="2" />
102         <input type="hidden" name="new_version" value="<?php echo $_POST['new_version']; ?>" />
103
104         <table width="65%" class="tableborder" cellspacing="0" cellpadding="1" border="0" align="center">
105         <tr>
106                 <td class="row1"><div class="required" title="Required Field">*</div><b><label for="db">Database Hostname:</label></b><br />
107                         Hostname of the database server. Default: <kbd>localhost</kbd></td>
108                 <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>
109         </tr>
110         <tr>
111                 <td class="row1"><div class="required" title="Required Field">*</div><b><label for="port">Database Port:</label></b><br />
112                         The port to the database server. Default: <kbd>3306</kbd></td>
113                 <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>
114         </tr>
115         <tr>
116                 <td class="row1"><div class="required" title="Required Field">*</div><b><label for="username">Database Username:</label></b><br />
117                         The username to the database server.</td>
118                 <td class="row1"><input type="text" name="db_login" id="username" value="<?php echo stripslashes(htmlspecialchars($_POST['db_login'])); ?>" class="formfield" /></td>
119         </tr>
120         <tr>
121                 <td class="row1"><div class="required" title="Required Field">*</div><b><label for="pass">Database Password:</label></b><br />
122                         The password to the database server.</td>
123                 <td class="row1"><input type="text" name="db_password" id="pass" value="<?php echo stripslashes(htmlspecialchars($_POST['db_password'])); ?>" class="formfield" /></td>
124         </tr>
125         <tr>
126                 <td class="row1"><div class="required" title="Required Field">*</div><b><label for="name">Database Name:</label></b><br />
127                         The name of the database to use. It will be created if it does not exist.<br />Default: <kbd>acontent</kbd></td>
128                 <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 'acontent'; } ?>" class="formfield" /></td>
129         </tr>
130         <tr>
131                 <td class="row1"><div class="optional" title="Optional Field">?</div><b><label for="prefix">Table Prefix:</label></b><br />
132                         The prefix to add to table names to avoid conflicts with existing tables.<br />
133                         Default: <kbd>AC_</kbd></td>
134                 <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 'AC_'; } ?>" class="formfield" /></td>
135         </tr>
136         </table>
137
138         <br /><br /><p align="center"><input type="submit" class="button" value="Next &raquo; " name="submit" /></p>
139
140 </form>