2 /* Copyright (c) 2009 Arnaud Renevier, Inc, published under the modified BSD
5 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
6 "http://www.w3.org/TR/html4/loose.dtd">
7 <html lang="<?php echo $lang?>">
9 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" >
10 <link rel="stylesheet" href="./media/install.css" type="text/css" >
11 <title><?php ptrans ('SYP wizard')?></title>
12 <script type="text/javascript">
14 if (document.getElementById('db_host')) {
15 document.getElementById('db_host').focus();
16 document.getElementById('db_host').select();
17 } else if (document.getElementById('admin_pass')) {
18 document.getElementById('admin_pass').focus();
19 document.getElementById('admin_pass').select();
24 <body onload="init()">
28 define ("CONFIG_FILE", "./inc/settings.php");
30 require_once ("./inc/install_utils.php");
32 if (version_compare (PHP_VERSION, '5.0.0', '<')) {
33 par_error_and_leave (trans ("You need at least PHP version 5"));
36 function error_unwritable_config () {
37 par_error_and_leave (trans ("Cannot save config file. You need either to set inc/ writable, or use manual method. See README.txt for more informations."));
40 function create_install_form () {
41 if (isset ($_POST ["db_form_submit"])) {
42 $host = $_POST ["db_host"];
43 $name = $_POST ["db_name"];
44 $user = $_POST ["db_user"];
45 $prefix = $_POST ["db_prefix"];
46 $title = $_POST ["site_title"];
55 print '<form method="post" action="' . $_SERVER ["REQUEST_URI"] . '"><fieldset>' . "\n";
56 print '<legend>' . trans ("SYP configuration") . '</legend>' . "\n";
58 print '<div><label for="db_host" title="' .
59 trans ("address of the database server (example: localhost, db.myhost.com or 192.168.0.15).") .
60 '">' . trans ("database server hostname:") . '</label>' . "\n" .
61 '<input id="db_host" name="db_host" value="' . $host . '"></div>' . "\n";
63 print '<div><label for="db_name" title="' .
64 trans ("The name of the database that SYP will be installed into. The database must exist.") .
65 '">' . trans ("database name:") . '</label>' . "\n" .
66 '<input id="db_name" name="db_name" value="' . $name . '"></div>' . "\n";
68 print '<div><label for="db_user" title="' .
69 trans ("The username with which you connect to the database.") .
70 '">' . trans ("database user:") . '</label>' . "\n" .
71 '<input id="db_user" name="db_user" value="' . $user . '"></div>' . "\n";
73 print '<div><label for="db_pass" title="' .
74 trans ("The password with which you connect to the database.") .
75 '">' . trans ("database password:") . '</label>' . "\n" .
76 '<input id="db_pass" name="db_pass" type="password"></div>' . "\n";
78 print '<div><label for="db_prefix" title="' .
79 trans ("You can specify a table prefix. This way you can run multiple SYP installations in the same database, each with its own prefix.") .
80 '">' . trans ("tables prefix:") . '</label>' . "\n" .
81 '<input id="db_prefix" name="db_prefix" value="' . $prefix . '">' . "\n";
83 print '<div><label for="site_title" title="' .
84 trans ("The title you want to give to your SYP site.") .
85 '">' . trans ("site title:") . '</label>' . "\n" .
86 '<input id="site_title" name="site_title" value="' . $title . '">' . "\n";
88 print '<div><input id="db_form_submit" name="db_form_submit" type="submit" value="' . trans ("Start install") . '"></div>';
89 print '</fieldset></form>';
92 if (file_exists (CONFIG_FILE)) {
93 require_once (CONFIG_FILE);
94 } else if (isset ($_POST["db_form_submit"])) { // user has submitted form
96 function _unquote($gpc_str) {
97 if (!isset ($gpc_str)) {
100 if (get_magic_quotes_gpc ()) {
101 return stripslashes ($gpc_str);
107 define (DBHOST, _unquote ($_POST ["db_host"]));
108 define (DBNAME, _unquote ($_POST ["db_name"]));
109 define (DBUSER, _unquote ($_POST ["db_user"]));
110 define (DBPWD, _unquote ($_POST ["db_pass"]));
111 define (DBPREFIX, _unquote ($_POST ["db_prefix"]));
112 define (SITETITLE, _unquote ($_POST ["site_title"]));
115 define (UPLOADDIR, "upload");
116 define (THUMBSDIR, "upload/_thumbs");
118 if (!is_writable (dirname (CONFIG_FILE))) {
119 error_unwritable_config ();
122 create_install_form ();
126 require_once ("./inc/db/mysql.php");
127 require_once ("./inc/utils.php");
130 $connection->connect (DBHOST, DBUSER, DBPWD, DBNAME, DBPREFIX);
131 } catch (Exception $e) {
132 switch ($e->getMessage ()) {
133 case anydbConnection::err_driver_unavailable:
134 par_error ($connection->getdbname() . ': ' . trans ('not supported'));
136 case anydbConnection::err_connection:
137 par_error (trans ('Could not connect to database.'));
139 case anydbConnection::err_unknown_database:
140 par_error (trans ('Database does not exist.'));
143 par_error (trans ('Unknown error when connecting to database.'));
147 if (isset ($_POST ["db_form_submit"])) {
148 // user had submited database informations. They seem to be wrong.
150 create_install_form ();
155 // we can connect to table. If config file does not exist, try to create it now.
156 if (!file_exists (CONFIG_FILE)) {
157 $handle = fopen ("./inc/settings.php.in", "r");
160 while (!feof ($handle)) {
161 $line = fgets ($handle, 4096);
162 foreach (array ("DBHOST", "DBNAME", "DBUSER", "DBPWD", "DBPREFIX", "SITETITLE") as $value) {
163 $pattern = "(define\s+\(\s*\"$value\"\s*,\s*\")[^\"]*(\"\s*\)\s*;)";
164 if (preg_match( "/$pattern/", $line, $match )) {
165 $line = $match[1] . addslashes (constant ($value)) . $match[2];
169 array_push ($lines, $line);
173 par_error_and_leave (trans ('Could not read <code>inc/settings.php.in</code>'));
176 $handle = fopen(CONFIG_FILE, 'w');
178 error_unwritable_config ();
180 fwrite ($handle, join($lines));
181 par_success (trans ('Config file created'));
183 par_success (trans ('Config file exists'));
187 $users_table_exists = $connection->users_table_exists ();
188 } catch(Exception $e) {
189 par_error_and_leave (trans ('Unknown error when checking user table.'));
192 if ($users_table_exists) {
193 par_success (trans ('Found user table.'));
195 if (isset($_POST ["admin_pass"])) {
197 $connection->create_users_table (true);
198 } catch (Exception $e) {
199 par_error_and_leave (trans ('Error when creating user table.'));
201 par_success (trans ('User table created.'));
203 $connection->setpwd ("admin", $_POST ["admin_pass"]);
204 } catch (Exception $e) {
205 par_error_and_leave (trans ('Error when initializing password.'));
207 par_success (trans ('Admin password initialized.'));
210 print ('<form class="center" method="post" action="">
211 <label for="admin_pass">' . trans ("choose admin password") . '</label>
212 <input id="admin_pass" name="admin_pass" type="password">
213 <input type="submit">
220 $items_table_exists = $connection->items_table_exists ();
221 } catch (Exception $e) {
222 par_error_and_leave (trans ('Unknown error when checking data table.'));
224 if ($items_table_exists) {
225 par_success (trans ('Found data table.'));
228 $connection->create_items_table (true);
229 } catch (Exception $e) {
230 par_error_and_leave (trans ('Error when creating data table.'));
232 par_success (trans ('Data table created.'));
235 safe_create_writable_dir (UPLOADDIR);
236 safe_create_writable_dir (getthumbsdir ());
238 if (!function_exists ("gd_info")) {
239 par_warn (trans ('It looks like GD extension is not installed.'));
242 par_success (trans ('SYP is installed. You can now go to <a href="admin.en.php">admin area</a>'));