' . "\n" .
+ '
' . "\n";
+
+ print '
' . "\n" .
+ '
' . "\n";
+
+ print '
';
+ print '';
+ }
+
+ if (file_exists (CONFIG_FILE)) {
+ require_once (CONFIG_FILE);
+ } else if (isset ($_POST["db_form_submit"])) { // user has submitted form
+
+ function _unquote($gpc_str) {
+ if (!isset ($gpc_str)) {
+ return $gpc_str;
+ }
+ if (get_magic_quotes_gpc ()) {
+ return stripslashes ($gpc_str);
+ } else {
+ return $gpc_str;
+ }
+ }
+
+ define (DBHOST, _unquote ($_POST ["db_host"]));
+ define (DBNAME, _unquote ($_POST ["db_name"]));
+ define (DBUSER, _unquote ($_POST ["db_user"]));
+ define (DBPWD, _unquote ($_POST ["db_pass"]));
+ define (DBPREFIX, _unquote ($_POST ["db_prefix"]));
+ define (SITETITLE, _unquote ($_POST ["site_title"]));
+
+ // default values
+ define (UPLOADDIR, "upload");
+ define (THUMBSDIR, "upload/_thumbs");
+ } else {
+ if (!is_writable (dirname (CONFIG_FILE))) {
+ error_unwritable_config ();
+ }
+
+ create_install_form ();
+ leave ();
+ }
+
+ require_once ("./inc/db/mysql.php");
+ require_once ("./inc/utils.php");
+
+ try {
+ $connection->connect (DBHOST, DBUSER, DBPWD, DBNAME, DBPREFIX);
+ } catch (Exception $e) {
+ switch ($e->getMessage ()) {
+ case anydbConnection::err_driver_unavailable:
+ par_error ($connection->getdbname() . ': ' . trans ('not supported'));
+ break;
+ case anydbConnection::err_connection:
+ par_error (trans ('Could not connect to database.'));
+ break;
+ case anydbConnection::err_unknown_database:
+ par_error (trans ('Database does not exist.'));
+ break;
+ default:
+ par_error (trans ('Unknown error when connecting to database.'));
+ break;
+ }
+
+ if (isset ($_POST ["db_form_submit"])) {
+ // user had submited database informations. They seem to be wrong.
+ // Ask again.
+ create_install_form ();
+ }
+ leave ();
+ }
+
+ // we can connect to table. If config file does not exist, try to create it now.
+ if (!file_exists (CONFIG_FILE)) {
+ $handle = fopen ("./inc/settings.php.in", "r");
+ $lines = array();
+ if ($handle) {
+ while (!feof ($handle)) {
+ $line = fgets ($handle, 4096);
+ foreach (array ("DBHOST", "DBNAME", "DBUSER", "DBPWD", "DBPREFIX", "SITETITLE") as $value) {
+ $pattern = "(define\s+\(\s*\"$value\"\s*,\s*\")[^\"]*(\"\s*\)\s*;)";
+ if (preg_match( "/$pattern/", $line, $match )) {
+ $line = $match[1] . addslashes (constant ($value)) . $match[2];
+ break;
+ }
+ }
+ array_push ($lines, $line);
+ }
+ fclose ($handle);
+ } else {
+ par_error_and_leave (trans ('Could not read
inc/settings.php.in
'));
+ }
+
+ $handle = fopen(CONFIG_FILE, 'w');
+ if (!$handle) {
+ error_unwritable_config ();
+ }
+ fwrite ($handle, join($lines));
+ par_success (trans ('Config file created'));
+ } else {
+ par_success (trans ('Config file exists'));
+ }
+
+ try {
+ $users_table_exists = $connection->users_table_exists ();
+ } catch(Exception $e) {
+ par_error_and_leave (trans ('Unknown error when checking user table.'));
+ }
+
+ if ($users_table_exists) {
+ par_success (trans ('Found user table.'));
+ } else {
+ if (isset($_POST ["admin_pass"])) {
+ try {
+ $connection->create_users_table (true);
+ } catch (Exception $e) {
+ par_error_and_leave (trans ('Error when creating user table.'));
+ }
+ par_success (trans ('User table created.'));
+ try {
+ $connection->setpwd ("admin", $_POST ["admin_pass"]);
+ } catch (Exception $e) {
+ par_error_and_leave (trans ('Error when initializing password.'));
+ }
+ par_success (trans ('Admin password initialized.'));
+
+ } else {
+ print ('
');
+ leave ();
+ }
+ }
+
+ try {
+ $items_table_exists = $connection->items_table_exists ();
+ } catch (Exception $e) {
+ par_error_and_leave (trans ('Unknown error when checking data table.'));
+ }
+ if ($items_table_exists) {
+ par_success (trans ('Found data table.'));
+ } else {
+ try {
+ $connection->create_items_table (true);
+ } catch (Exception $e) {
+ par_error_and_leave (trans ('Error when creating data table.'));
+ }
+ par_success (trans ('Data table created.'));
+ }
+
+ safe_create_writable_dir (UPLOADDIR);
+ safe_create_writable_dir (getthumbsdir ());
+
+ if (!function_exists ("gd_info")) {
+ par_warn (trans ('It looks like GD extension is not installed.'));
+ }
+
+ par_success (trans ('SYP is installed. You can now go to
admin area'));
+?>
+
+
+