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 emptyPasswordError: "<?php ptrans('Password cannot be empty')?>"
18 if (document.getElementById('db_host')) {
19 document.getElementById('db_host').focus();
20 document.getElementById('db_host').select();
21 } else if (document.getElementById('admin_pass')) {
22 document.getElementById('admin_pass').focus();
23 document.getElementById('admin_pass').select();
27 function checkpwd () {
28 var pass = document.getElementById('admin_pass').value;
30 document.getElementById('empty_pass_error').innerHTML = sypStrings.emptyPasswordError;
31 document.getElementById('empty_pass_error').style.display = "block";
32 document.getElementById('admin_pass').focus();
39 <body onload="init()">
43 define ("CONFIG_FILE", "./inc/settings.php");
45 require_once ("./inc/install_utils.php");
47 if (version_compare (PHP_VERSION, '5.0.0', '<')) {
48 par_error_and_leave (trans ("You need at least PHP version 5"));
51 function error_unwritable_config () {
52 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."));
55 function create_install_form () {
56 if (isset ($_POST ["db_form_submit"])) {
57 $host = $_POST ["db_host"];
58 $name = $_POST ["db_name"];
59 $user = $_POST ["db_user"];
60 $prefix = $_POST ["db_prefix"];
61 $title = $_POST ["site_title"];
70 print '<form method="post" action="' . $_SERVER ["REQUEST_URI"] . '"><fieldset>' . "\n";
71 print '<legend>' . trans ("SYP configuration") . '</legend>' . "\n";
73 print '<div><label for="db_host" title="' .
74 trans ("address of the database server (example: localhost, db.myhost.com or 192.168.0.15).") .
75 '">' . trans ("database server hostname:") . '</label>' . "\n" .
76 '<input id="db_host" name="db_host" value="' . $host . '"></div>' . "\n";
78 print '<div><label for="db_name" title="' .
79 trans ("The name of the database that SYP will be installed into. The database must exist.") .
80 '">' . trans ("database name:") . '</label>' . "\n" .
81 '<input id="db_name" name="db_name" value="' . $name . '"></div>' . "\n";
83 print '<div><label for="db_user" title="' .
84 trans ("The username with which you connect to the database.") .
85 '">' . trans ("database user:") . '</label>' . "\n" .
86 '<input id="db_user" name="db_user" value="' . $user . '"></div>' . "\n";
88 print '<div><label for="db_pass" title="' .
89 trans ("The password with which you connect to the database.") .
90 '">' . trans ("database password:") . '</label>' . "\n" .
91 '<input id="db_pass" name="db_pass" type="password"></div>' . "\n";
93 print '<div><label for="db_prefix" title="' .
94 trans ("You can specify a table prefix. This way you can run multiple SYP installations in the same database, each with its own prefix.") .
95 '">' . trans ("tables prefix:") . '</label>' . "\n" .
96 '<input id="db_prefix" name="db_prefix" value="' . $prefix . '">' . "\n";
98 print '<div><label for="site_title" title="' .
99 trans ("The title you want to give to your SYP site.") .
100 '">' . trans ("site title:") . '</label>' . "\n" .
101 '<input id="site_title" name="site_title" value="' . $title . '">' . "\n";
103 print '<div><input id="db_form_submit" name="db_form_submit" type="submit" value="' . trans ("Start install") . '"></div>';
104 print '</fieldset></form>';
107 if (file_exists (CONFIG_FILE)) {
108 require_once (CONFIG_FILE);
109 } else if (isset ($_POST["db_form_submit"])) { // user has submitted form
111 function _unquote($gpc_str) {
112 if (!isset ($gpc_str)) {
115 if (get_magic_quotes_gpc ()) {
116 return stripslashes ($gpc_str);
122 define (DBHOST, _unquote ($_POST ["db_host"]));
123 define (DBNAME, _unquote ($_POST ["db_name"]));
124 define (DBUSER, _unquote ($_POST ["db_user"]));
125 define (DBPWD, _unquote ($_POST ["db_pass"]));
126 define (DBPREFIX, _unquote ($_POST ["db_prefix"]));
127 define (SITETITLE, _unquote ($_POST ["site_title"]));
130 define (UPLOADDIR, "upload");
131 define (THUMBSDIR, "upload/_thumbs");
133 if (!is_writable (dirname (CONFIG_FILE))) {
134 error_unwritable_config ();
137 create_install_form ();
141 require_once ("./inc/db/mysql.php");
142 require_once ("./inc/utils.php");
145 $connection->connect (DBHOST, DBUSER, DBPWD, DBNAME, DBPREFIX);
146 } catch (Exception $e) {
147 switch ($e->getMessage ()) {
148 case anydbConnection::err_driver_unavailable:
149 par_error ($connection->getdbname() . ': ' . trans ('not supported'));
151 case anydbConnection::err_connection:
152 par_error (trans ('Could not connect to database.'));
154 case anydbConnection::err_unknown_database:
155 par_error (trans ('Database does not exist.'));
158 par_error (trans ('Unknown error when connecting to database.'));
162 if (isset ($_POST ["db_form_submit"])) {
163 // user had submited database informations. They seem to be wrong.
165 create_install_form ();
170 // we can connect to table. If config file does not exist, try to create it now.
171 if (!file_exists (CONFIG_FILE)) {
172 $handle = fopen ("./inc/settings.php.in", "r");
175 while (!feof ($handle)) {
176 $line = fgets ($handle, 4096);
177 foreach (array ("DBHOST", "DBNAME", "DBUSER", "DBPWD", "DBPREFIX", "SITETITLE") as $value) {
178 $pattern = "(define\s+\(\s*\"$value\"\s*,\s*\")[^\"]*(\"\s*\)\s*;)";
179 if (preg_match( "/$pattern/", $line, $match )) {
180 $line = $match[1] . addslashes (constant ($value)) . $match[2];
184 array_push ($lines, $line);
188 par_error_and_leave (trans ('Could not read <code>inc/settings.php.in</code>'));
191 $handle = fopen(CONFIG_FILE, 'w');
193 error_unwritable_config ();
195 fwrite ($handle, join($lines));
196 par_success (trans ('Config file created'));
198 par_success (trans ('Config file exists'));
202 $users_table_exists = $connection->users_table_exists ();
203 } catch(Exception $e) {
204 par_error_and_leave (trans ('Unknown error when checking user table.'));
207 if ($users_table_exists) {
208 par_success (trans ('Found user table.'));
210 $empty_pass = (isset ($_POST ["admin_pass"]) && (strlen ($_POST ["admin_pass"]) == 0));
211 if ($_POST ["admin_pass"]) {
213 $connection->create_users_table (true);
214 } catch (Exception $e) {
215 par_error_and_leave (trans ('Error when creating user table.'));
217 par_success (trans ('User table created.'));
219 $connection->setpwd ("admin", $_POST ["admin_pass"]);
220 } catch (Exception $e) {
221 par_error_and_leave (trans ('Error when initializing password.'));
223 par_success (trans ('Admin password initialized.'));
226 print ('<form class="center" method="post" action="" onsubmit="return checkpwd()">
227 <label for="admin_pass">' . trans ("choose admin password") . '</label>
228 <input id="admin_pass" name="admin_pass" type="password">');
230 print ('<p class="error" id="empty_pass_error">' . trans('Password cannot be empty') . '</p>');
232 print ('<p class="error" style="display: none" id="empty_pass_error"></p>');
234 print ('<br><input type="submit"></form>');
240 $items_table_exists = $connection->items_table_exists ();
241 } catch (Exception $e) {
242 par_error_and_leave (trans ('Unknown error when checking data table.'));
244 if ($items_table_exists) {
245 par_success (trans ('Found data table.'));
248 $connection->create_items_table (true);
249 } catch (Exception $e) {
250 par_error_and_leave (trans ('Error when creating data table.'));
252 par_success (trans ('Data table created.'));
255 safe_create_writable_dir (UPLOADDIR);
256 safe_create_writable_dir (getthumbsdir ());
258 if (!function_exists ("gd_info")) {
259 par_warn (trans ('It looks like GD extension is not installed.'));
262 par_success (trans ('SYP is installed. You can now go to <a href="admin.en.php">admin area</a>'));