3725d5f0daedac6c7dcaee2336ddbde230679687
[acontent.git] / docs / 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
63                         if (!$errors) {
64                                 print_progress($step);
65
66                                 unset($_POST['submit']);
67                                 unset($_POST['action']);
68                                 store_steps($step);
69                                 print_feedback($progress);
70
71                                 echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post" name="form">
72                                 <input type="hidden" name="step" value="3" />';
73                                 print_hidden(3);
74                                 echo '<p align="center"><input type="submit" class="button" value="Next &raquo; " name="submit" /></p></form>';
75                                 return;
76                         }
77                 }
78
79         }
80 }
81
82 print_progress($step);
83
84
85 echo '<p>Please enter your database information: </p>';
86
87
88 if (isset($progress)) {
89         print_feedback($progress);
90 }
91
92 if (isset($errors)) {
93         print_errors($errors);
94 }
95
96 ?>
97
98 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
99         <input type="hidden" name="action" value="process" />
100         <input type="hidden" name="step" value="2" />
101         <input type="hidden" name="new_version" value="<?php echo $_POST['new_version']; ?>" />
102
103         <table width="65%" class="tableborder" cellspacing="0" cellpadding="1" border="0" align="center">
104         <tr>
105                 <td class="row1"><div class="required" title="Required Field">*</div><b><label for="db">Database Hostname:</label></b><br />
106                         Hostname of the database server. Default: <kbd>localhost</kbd></td>
107                 <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>
108         </tr>
109         <tr>
110                 <td class="row1"><div class="required" title="Required Field">*</div><b><label for="port">Database Port:</label></b><br />
111                         The port to the database server. Default: <kbd>3306</kbd></td>
112                 <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>
113         </tr>
114         <tr>
115                 <td class="row1"><div class="required" title="Required Field">*</div><b><label for="username">Database Username:</label></b><br />
116                         The username to the database server.</td>
117                 <td class="row1"><input type="text" name="db_login" id="username" value="<?php echo stripslashes(htmlspecialchars($_POST['db_login'])); ?>" class="formfield" /></td>
118         </tr>
119         <tr>
120                 <td class="row1"><div class="required" title="Required Field">*</div><b><label for="pass">Database Password:</label></b><br />
121                         The password to the database server.</td>
122                 <td class="row1"><input type="text" name="db_password" id="pass" value="<?php echo stripslashes(htmlspecialchars($_POST['db_password'])); ?>" class="formfield" /></td>
123         </tr>
124         <tr>
125                 <td class="row1"><div class="required" title="Required Field">*</div><b><label for="name">Database Name:</label></b><br />
126                         The name of the database to use. It will be created if it does not exist.<br />Default: <kbd>acontent</kbd></td>
127                 <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>
128         </tr>
129         <tr>
130                 <td class="row1"><div class="optional" title="Optional Field">?</div><b><label for="prefix">Table Prefix:</label></b><br />
131                         The prefix to add to table names to avoid conflicts with existing tables.<br />
132                         Default: <kbd>AC_</kbd></td>
133                 <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>
134         </tr>
135         </table>
136
137         <br /><br /><p align="center"><input type="submit" class="button" value="Next &raquo; " name="submit" /></p>
138
139 </form>