X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=install%2Fsave.php;h=b11263a3e3d2836ac75ae25fa4d495e9ecaeb1e8;hb=967f3b0f52a7f6e4afedea35bf2303414a41022f;hp=1396d806fb169bdd5b09a9e7847755d6adef9c4d;hpb=63ac6425e9e925da331083f83706cfa34fe853d4;p=fa-stable.git diff --git a/install/save.php b/install/save.php index 1396d806..b11263a3 100644 --- a/install/save.php +++ b/install/save.php @@ -1,13 +1,10 @@ . + This installer is based on code from the + Website Baker Project + Copyright (C) 2004-2007, Ryan Djurovich. + The code is released under GPLv3 + modified by FrontAcounting, LLC. ***********************************************************************/ error_reporting(E_ALL); ini_set("display_errors", "On"); @@ -21,6 +18,11 @@ if(!defined('SESSION_STARTED')) define('SESSION_STARTED', true); } +if (!function_exists("_")) { + function _($msg) { + return $msg; + } +} // Installer version of display_error function. // function display_error($message) @@ -32,42 +34,15 @@ function display_error($message) if(isset($_POST['company_name'])) { $_SESSION['ba_url'] = $_POST['ba_url']; - if(!isset($_POST['operating_system'])) - { - $_SESSION['operating_system'] = 'linux'; - } - else - { - $_SESSION['operating_system'] = $_POST['operating_system']; - } - if(!isset($_POST['world_writeable'])) - { - $_SESSION['world_writeable'] = false; - } - else - { - $_SESSION['world_writeable'] = true; - } + $_SESSION['operating_system'] = isset($_POST['operating_system']); + $_SESSION['world_writeable'] = isset($_POST['world_writeable']); $_SESSION['database_host'] = $_POST['database_host']; $_SESSION['database_username'] = $_POST['database_username']; $_SESSION['database_password'] = $_POST['database_password']; $_SESSION['database_name'] = $_POST['database_name']; - if(!isset($_POST['table_prefix'])) - { - $_SESSION['table_prefix'] = false; - } - else - { - $_SESSION['table_prefix'] = true; - } - if(!isset($_POST['install_tables'])) - { - $_SESSION['install_tables'] = false; - } - else - { - $_SESSION['install_tables'] = true; - } + $_SESSION['demo_data'] = isset($_POST['demo_data']); + $_SESSION['table_prefix'] = isset($_POST['table_prefix']); + $_SESSION['install_tables'] = isset($_POST['install_tables']); $_SESSION['company_name'] = $_POST['company_name']; $_SESSION['admin_email'] = $_POST['admin_email']; $_SESSION['admin_password'] = $_POST['admin_password']; @@ -276,7 +251,7 @@ else // End website company name // Check if the user has entered a correct path -if (!file_exists($path_to_root.'/sql/en_US-demo.sql')) +if (!file_exists($path_to_root.'/sql/en_US-'.(isset($_POST['demo_data']) ? 'demo':'new').'.sql')) { display_error('It appears the Absolute path that you entered is incorrect'); } @@ -320,9 +295,33 @@ if ($admin_password != $admin_repassword) } // End admin user details code +if (!file_exists($path_to_root . "/config.php")) { + copy($path_to_root. "/config.default.php", $path_to_root. "/config.php"); +} + include_once($path_to_root . "/includes/db/connect_db.inc"); include_once($path_to_root . "/admin/db/maintenance_db.inc"); -include_once($path_to_root . "/config_db.php"); + +if (!file_exists($path_to_root . "/installed_extensions.php")) { + $next_extension_id = 1; + write_extensions(array()); + write_extensions(array(),0); +} +if (!file_exists($path_to_root . "/lang/installed_languages.inc")) { + $installed_languages = array ( + 0 => array ('code' => 'en_GB', 'name' => 'English', 'encoding' => 'iso-8859-1')); + $dflt_lang = 'en_GB'; + write_lang(); +} + +if (file_exists($path_to_root . "/config_db.php")) + include_once($path_to_root . "/config_db.php"); + else +{ + $def_coy = 0; + $tb_pref_counter = 0; + $db_connections = array (); +} $id = count($db_connections); if ($table_prefix != "" && $id > 0) @@ -338,47 +337,53 @@ $def_coy = $id; $config_filename = $path_to_root . '/config_db.php'; -$err = write_config_db($table_prefix != ""); -if ($err == -1) - display_error("Cannot open the configuration file ($config_filename)"); -else if ($err == -2) - display_error("Cannot write to the configuration file ($config_filename)"); -else if ($err == -3) - display_error("The configuration file $config_filename is not writable. Change its permissions so it is, then re-run step 4."); - // Try connecting to database $db = mysql_connect($database_host, $database_username, $database_password); if (!$db) { display_error('Database host name, username and/or password incorrect. MySQL Error:
'.mysql_error()); -} - -if($install_tables == true) -{ - if (!mysql_select_db($database_name, $db)) - { - - // Try to create the database - mysql_query('CREATE DATABASE '.$database_name); - mysql_select_db($database_name, $db); +} else { + $result = true; + if($install_tables == true) + { + if (!mysql_select_db($database_name, $db)) + { + // Try to create the database + if (!($result = mysql_query('CREATE DATABASE '.$database_name))) { + display_error(_("Cannot create database"). + " '$database_name'"); + } else + $result = mysql_select_db($database_name, $db); + } + if($result) { + $import_filename = $path_to_root.'/sql/en_US-'.(isset($_POST['demo_data']) ? 'demo':'new').'.sql'; + db_import($import_filename, $db_connections[$id]); + } + } + else + { + $result = mysql_select_db($database_name, $db); + } + if ($result) { + $sql = "UPDATE ".$table_prefix."users SET password = '" . md5($admin_password) . "', email = ".db_escape($admin_email)." WHERE user_id = 'admin'"; + db_query($sql, "could not update admin account"); + $sql = "UPDATE ".$table_prefix."company SET coy_name = ".db_escape($company_name)." WHERE coy_code = 1"; + db_query($sql, "could not update company name. Do it manually later in Setup"); + + $err = write_config_db($table_prefix != ""); + if ($err == -1) + display_error("Cannot open the configuration file ($config_filename)"); + else if ($err == -2) + display_error("Cannot write to the configuration file ($config_filename)"); + else if ($err == -3) + display_error("The configuration file $config_filename is not writable. Change its permissions so it is, then re-run step 4."); } - $import_filename = $path_to_root."/sql/en_US-demo.sql"; - db_import($import_filename, $db_connections[$id]); -} -else -{ - mysql_select_db($database_name, $db); } -$sql = "UPDATE ".$table_prefix."users SET password = '" . md5($admin_password) . "', email = ".db_escape($admin_email)." WHERE user_id = 'admin'"; -db_query($sql, "could not update admin account"); -$sql = "UPDATE ".$table_prefix."company SET coy_name = ".db_escape($company_name)." WHERE coy_code = 1"; -db_query($sql, "could not update company name. Do it manually later in Setup"); session_unset(); session_destroy(); $_SESSION = array(); - header("Location: ".$path_to_root."/index.php"); exit();