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 $type = $_POST ["db_type"];
58 $host = $_POST ["db_host"];
59 $name = $_POST ["db_name"];
60 $user = $_POST ["db_user"];
61 $prefix = $_POST ["db_prefix"];
62 $title = $_POST ["site_title"];
72 print '<form method="post" action="' . $_SERVER ["REQUEST_URI"] . '"><fieldset>' . "\n";
73 print '<legend>' . trans ("SYP configuration") . '</legend>' . "\n";
76 $handle = opendir("./inc/db");
78 par_error_and_leave (trans ('Could not list <code>inc/db</code> directory'));
80 while (false !== ($file = readdir($handle))) {
81 if ($file == "." or $file == "..") {
84 $driver_name = substr($file,0,strrpos($file,'.'));
85 if ($driver_name == "anydb") {
88 array_push ($drivers, $driver_name);
93 print '<div><label for="db_type" title="' .
94 trans ("You can specify a database backend. Mysql is the most available for standard web hosting services.") .
95 '">' . trans ("database backend:") . '</label>' . "\n" .
96 '<select id="db_type" name="db_type">'. "\n";
97 foreach ($drivers as $driver) {
98 if ($driver == $type) {
99 print '<option name="' . $driver . '" selected="true">' . $driver . '</option>' . "\n";
101 print '<option name="' . $driver . '">' . $driver . '</option>' . "\n";
104 print "</select>" . "\n";
106 print '<div><label for="db_host" title="' .
107 trans ("address of the database server (example: localhost, db.myhost.com or 192.168.0.15).") .
108 '">' . trans ("database server hostname:") . '</label>' . "\n" .
109 '<input id="db_host" name="db_host" value="' . $host . '"></div>' . "\n";
111 print '<div><label for="db_name" title="' .
112 trans ("The name of the database that SYP will be installed into. The database must exist.") .
113 '">' . trans ("database name:") . '</label>' . "\n" .
114 '<input id="db_name" name="db_name" value="' . $name . '"></div>' . "\n";
116 print '<div><label for="db_user" title="' .
117 trans ("The username with which you connect to the database.") .
118 '">' . trans ("database user:") . '</label>' . "\n" .
119 '<input id="db_user" name="db_user" value="' . $user . '"></div>' . "\n";
121 print '<div><label for="db_pass" title="' .
122 trans ("The password with which you connect to the database.") .
123 '">' . trans ("database password:") . '</label>' . "\n" .
124 '<input id="db_pass" name="db_pass" type="password"></div>' . "\n";
126 print '<div><label for="db_prefix" title="' .
127 trans ("You can specify a table prefix. This way you can run multiple SYP installations in the same database, each with its own prefix.") .
128 '">' . trans ("tables prefix:") . '</label>' . "\n" .
129 '<input id="db_prefix" name="db_prefix" value="' . $prefix . '">' . "\n";
131 print '<div><label for="site_title" title="' .
132 trans ("The title you want to give to your SYP site.") .
133 '">' . trans ("site title:") . '</label>' . "\n" .
134 '<input id="site_title" name="site_title" value="' . $title . '">' . "\n";
136 print '<div><input id="db_form_submit" name="db_form_submit" type="submit" value="' . trans ("Start install") . '"></div>';
137 print '</fieldset></form>';
140 if (file_exists (CONFIG_FILE)) {
141 require_once (CONFIG_FILE);
142 } else if (isset ($_POST["db_form_submit"])) { // user has submitted form
144 function _unquote($gpc_str) {
145 if (!isset ($gpc_str)) {
148 if (get_magic_quotes_gpc ()) {
149 return stripslashes ($gpc_str);
155 define (DBTYPE, _unquote ($_POST ["db_type"]));
156 define (DBHOST, _unquote ($_POST ["db_host"]));
157 define (DBNAME, _unquote ($_POST ["db_name"]));
158 define (DBUSER, _unquote ($_POST ["db_user"]));
159 define (DBPWD, _unquote ($_POST ["db_pass"]));
160 define (DBPREFIX, _unquote ($_POST ["db_prefix"]));
161 define (SITETITLE, _unquote ($_POST ["site_title"]));
164 define (UPLOADDIR, "upload");
165 define (THUMBSDIR, "upload/_thumbs");
167 if (!is_writable (dirname (CONFIG_FILE))) {
168 error_unwritable_config ();
171 create_install_form ();
175 if (!include_once ("./inc/db/" . DBTYPE . ".php")) {
176 par_error_and_leave (trans("Unkown backend: ", DBTYPE));
178 require_once ("./inc/utils.php");
181 $connection->connect (DBHOST, DBUSER, DBPWD, DBNAME, DBPREFIX);
182 } catch (Exception $e) {
183 switch ($e->getMessage ()) {
184 case anydbConnection::err_driver_unavailable:
185 par_error ($connection->getdbname() . ': ' . trans ('not supported'));
187 case anydbConnection::err_connection:
188 par_error (trans ('Could not connect to database.'));
190 case anydbConnection::err_unknown_database:
191 par_error (trans ('Database does not exist.'));
194 par_error (trans ('Unknown error when connecting to database.'));
198 if (isset ($_POST ["db_form_submit"])) {
199 // user had submited database informations. They seem to be wrong.
201 create_install_form ();
206 // we can connect to table. If config file does not exist, try to create it now.
207 if (!file_exists (CONFIG_FILE)) {
208 $handle = fopen ("./inc/settings.php.in", "r");
211 while (!feof ($handle)) {
212 $line = fgets ($handle, 4096);
213 foreach (array ("DBTYPE", "DBHOST", "DBNAME", "DBUSER", "DBPWD", "DBPREFIX", "SITETITLE") as $value) {
214 $pattern = "(define\s+\(\s*\"$value\"\s*,\s*\")[^\"]*(\"\s*\)\s*;)";
215 if (preg_match( "/$pattern/", $line, $match )) {
216 $line = $match[1] . addslashes (constant ($value)) . $match[2];
220 array_push ($lines, $line);
224 par_error_and_leave (trans ('Could not read <code>inc/settings.php.in</code>'));
227 $handle = fopen(CONFIG_FILE, 'w');
229 error_unwritable_config ();
231 fwrite ($handle, join($lines));
232 par_success (trans ('Config file created'));
234 par_success (trans ('Config file exists'));
238 $users_table_exists = $connection->users_table_exists ();
239 } catch(Exception $e) {
240 par_error_and_leave (trans ('Unknown error when checking user table.'));
243 if ($users_table_exists) {
244 par_success (trans ('Found user table.'));
246 $empty_pass = (isset ($_POST ["admin_pass"]) && (strlen ($_POST ["admin_pass"]) == 0));
247 if (isset ($_POST["admin_pass"]) and $_POST ["admin_pass"]) {
249 $connection->create_users_table (true);
250 } catch (Exception $e) {
251 par_error_and_leave (trans ('Error when creating user table.'));
253 par_success (trans ('User table created.'));
255 $connection->setpwd ("admin", $_POST ["admin_pass"]);
256 } catch (Exception $e) {
257 par_error_and_leave (trans ('Error when initializing password.'));
259 par_success (trans ('Admin password initialized.'));
262 print ('<form class="center" method="post" action="" onsubmit="return checkpwd()">
263 <label for="admin_pass">' . trans ("choose admin password") . '</label>
264 <input id="admin_pass" name="admin_pass" type="password">');
266 print ('<p class="error" id="empty_pass_error">' . trans('Password cannot be empty') . '</p>');
268 print ('<p class="error" style="display: none" id="empty_pass_error"></p>');
270 print ('<br><input type="submit"></form>');
276 $items_table_exists = $connection->items_table_exists ();
277 } catch (Exception $e) {
278 par_error_and_leave (trans ('Unknown error when checking data table.'));
280 if ($items_table_exists) {
281 par_success (trans ('Found data table.'));
284 $connection->create_items_table (true);
285 } catch (Exception $e) {
286 par_error_and_leave (trans ('Error when creating data table.'));
288 par_success (trans ('Data table created.'));
291 safe_create_writable_dir (UPLOADDIR);
292 safe_create_writable_dir (getthumbsdir ());
294 if (!function_exists ("gd_info")) {
295 par_warn (trans ('It looks like GD extension is not installed.'));
298 par_success (trans ('SYP is installed. You can now go to <a href="admin.en.php">admin area</a>'));