From e4601ecbe842aafa7f0424abc67ec7ba55139dff Mon Sep 17 00:00:00 2001 From: Janusz Dobrowolski Date: Tue, 20 Oct 2009 21:47:33 +0000 Subject: [PATCH] Conditional config files generation - prevents overwrite during upgrade. --- CHANGELOG.txt | 17 ++++++++ admin/db/maintenance_db.inc | 70 +++++++++++++++++++++++++++++- admin/inst_lang.php | 68 ----------------------------- company/0/installed_extensions.php | 10 ----- config.php => config.default.php | 2 +- config_db.php | 36 --------------- includes/session.inc | 2 +- install/index.php | 16 +++++-- install/save.php | 27 +++++++++++- installed_extensions.php | 23 ---------- lang/installed_languages.inc | 19 -------- 11 files changed, 124 insertions(+), 166 deletions(-) delete mode 100644 company/0/installed_extensions.php rename config.php => config.default.php (99%) delete mode 100644 config_db.php delete mode 100644 installed_extensions.php delete mode 100644 lang/installed_languages.inc diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 6e1977d9..e40ca10e 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -19,6 +19,23 @@ Legend: ! -> Note $ -> Affected files + +20-Oct-2009 Janusz Dobrowolski +! Conditional config files generation - prevents overwrite during upgrade. +$ /config.php (removed) + /installed_extensions.php (removed) + /company/0/installed_extensions.php (removed) + /config.default.php (new initial default) + /config_db.php (removed initial version) + /admin/inst_lang.php (removed initial version) + /admin/db/maintenance_db.inc + /includes/session.inc + /install/index.php + /install/save.php + /lang/installed_languages.inc (removed initial version) +$ Moving control to install wizard when config file does not exists. +$ /index.php + 18-Oct-2009 Janusz Dobrowolski (merged changes for 2.1.7 from main branch) ! Added html_entity_decode() in db_escape() for correct INSERT>SELECT>INSERT sequences. $ /includes/db/connect_db.inc diff --git a/admin/db/maintenance_db.inc b/admin/db/maintenance_db.inc index f018ea1d..ceccb076 100644 --- a/admin/db/maintenance_db.inc +++ b/admin/db/maintenance_db.inc @@ -60,7 +60,6 @@ function array_natsort($aryData, $strIndex, $strSortBy, $strSortType=false) function write_config_db($new = false) { global $path_to_root, $def_coy, $db_connections, $tb_pref_counter; - include_once($path_to_root . "/config_db.php"); if ($new) $tb_pref_counter++; @@ -99,7 +98,7 @@ function write_config_db($new = false) $filename = $path_to_root . "/config_db.php"; // Check if the file exists and is writable first. - if (file_exists($filename) && is_writable($filename)) + if (!file_exists($filename) || (is_writable($path_to_root) && is_writable($filename))) { if (!$zp = fopen($filename, 'w')) { @@ -199,6 +198,73 @@ function write_extensions($extensions=null, $company = -1) return true; } +function write_lang() +{ + global $path_to_root, $installed_languages, $dflt_lang; + + $conn = array_natsort($installed_languages, 'code', 'code'); + $installed_languages = $conn; + //reset($installed_languages); + $n = count($installed_languages); + $msg = " ')\n"; + $msg .= "-- 'code' should match the name of the directory for the language under \\lang\n"; + $msg .= "-- 'name' is the name that will be displayed in the language selection list (in Users and Display Setup)\n"; + $msg .= "-- 'rtl' only needs to be set for right-to-left languages like Arabic and Hebrew\n\n"; + $msg .= "*/\n\n\n"; + + $msg .= "\$installed_languages = array (\n"; + if ($n > 0) + $msg .= "\t0 => "; + for ($i = 0; $i < $n; $i++) + { + if ($i > 0) + $msg .= "\t\tarray "; + else + $msg .= "array "; + $msg .= "('code' => '" . $installed_languages[$i]['code'] . "', "; + $msg .= "'name' => '" . $installed_languages[$i]['name'] . "', "; + $msg .= "'encoding' => '" . $installed_languages[$i]['encoding'] . "'"; + if (isset($installed_languages[$i]['rtl']) && $installed_languages[$i]['rtl']) + $msg .= ", 'rtl' => true),\n"; + else + $msg .= "),\n"; + } + + $msg .= "\t);\n"; + $msg .= "\n\$dflt_lang = '$dflt_lang';\n?>\n"; + + $path = $path_to_root . "/lang"; + $filename = $path.'/installed_languages.inc'; + // Check if directory exists and is writable first. + if (file_exists($path) && is_writable($path)) + { + if (!$zp = fopen($filename, 'w')) + { + display_error(_("Cannot open the languages file - ") . $filename); + return false; + } + else + { + if (!fwrite($zp, $msg)) + { + display_error(_("Cannot write to the language file - ") . $filename); + fclose($zp); + return false; + } + // Close file + fclose($zp); + } + } + else + { + display_error(_("The language files folder ") . $path . _(" is not writable. Change its permissions so it is, then re-run the operation.")); + return false; + } + return true; +} function db_create_db($connection) { diff --git a/admin/inst_lang.php b/admin/inst_lang.php index 9c8ea4b5..214a1dce 100644 --- a/admin/inst_lang.php +++ b/admin/inst_lang.php @@ -44,74 +44,6 @@ function check_data() return true; } -function write_lang() -{ - global $path_to_root, $installed_languages, $dflt_lang; - include_once($path_to_root . "/lang/installed_languages.inc"); - - $conn = array_natsort($installed_languages, 'code', 'code'); - $installed_languages = $conn; - //reset($installed_languages); - $n = count($installed_languages); - $msg = " ')\n"; - $msg .= "-- 'code' should match the name of the directory for the language under \\lang\n"; - $msg .= "-- 'name' is the name that will be displayed in the language selection list (in Users and Display Setup)\n"; - $msg .= "-- 'rtl' only needs to be set for right-to-left languages like Arabic and Hebrew\n\n"; - $msg .= "*/\n\n\n"; - - $msg .= "\$installed_languages = array (\n"; - if ($n > 0) - $msg .= "\t0 => "; - for ($i = 0; $i < $n; $i++) - { - if ($i > 0) - $msg .= "\t\tarray "; - else - $msg .= "array "; - $msg .= "('code' => '" . $installed_languages[$i]['code'] . "', "; - $msg .= "'name' => '" . $installed_languages[$i]['name'] . "', "; - $msg .= "'encoding' => '" . $installed_languages[$i]['encoding'] . "'"; - if (isset($installed_languages[$i]['rtl']) && $installed_languages[$i]['rtl']) - $msg .= ", 'rtl' => true),\n"; - else - $msg .= "),\n"; - } - - $msg .= "\t);\n"; - $msg .= "\n\$dflt_lang = '$dflt_lang';\n?>\n"; - - $filename = $path_to_root . "/lang/installed_languages.inc"; - // Check if the file exists and is writable first. - if (file_exists($filename) && is_writable($filename)) - { - if (!$zp = fopen($filename, 'w')) - { - display_error(_("Cannot open the languages file - ") . $filename); - return false; - } - else - { - if (!fwrite($zp, $msg)) - { - display_error(_("Cannot write to the language file - ") . $filename); - fclose($zp); - return false; - } - // Close file - fclose($zp); - } - } - else - { - display_error(_("The language file ") . $filename . _(" is not writable. Change its permissions so it is, then re-run the operation.")); - return false; - } - return true; -} - //--------------------------------------------------------------------------------------------- function handle_submit() diff --git a/company/0/installed_extensions.php b/company/0/installed_extensions.php deleted file mode 100644 index 390ab592..00000000 --- a/company/0/installed_extensions.php +++ /dev/null @@ -1,10 +0,0 @@ - \ No newline at end of file diff --git a/config.php b/config.default.php similarity index 99% rename from config.php rename to config.default.php index c39a3e32..a709a9e3 100644 --- a/config.php +++ b/config.default.php @@ -56,7 +56,7 @@ if (!isset($path_to_root) || isset($_GET['path_to_root']) || isset($_POST['path_ // Main Title $app_title = "FrontAccounting"; // application version - $version = "2.2 Beta"; + $version = "2.2 RC"; // Build for development purposes $build_version = date("d.m.Y", filemtime("$path_to_root/CHANGELOG.txt")); diff --git a/config_db.php b/config_db.php deleted file mode 100644 index 1c06397b..00000000 --- a/config_db.php +++ /dev/null @@ -1,36 +0,0 @@ - array ('name' => 'Training Co.', - 'host' => 'localhost', - 'dbuser' => 'your_db_user_name', - 'dbpassword' => 'your_db_password', - 'dbname' => 'your_db_name', - 'tbpref' => '0_') - ); -*/ - -$tb_pref_counter = 0; - -$db_connections = array (); - -?> \ No newline at end of file diff --git a/includes/session.inc b/includes/session.inc index 04acec51..734c1703 100644 --- a/includes/session.inc +++ b/includes/session.inc @@ -165,7 +165,7 @@ header("Cache-control: private"); get_text_init(); // Page Initialisation -if (!isset($_SESSION['languages'])) +if (!isset($_SESSION['language'])) { load_languages(); // sets also default $_SESSION['language'] } diff --git a/install/index.php b/install/index.php index 7ba272d4..56924549 100644 --- a/install/index.php +++ b/install/index.php @@ -21,6 +21,7 @@ if(!isset($_GET['sessions_checked']) || $_GET['sessions_checked'] != 'true') { // Set session variable $_SESSION['session_support'] = 'Enabled'; + $_SESSION['message'] = ''; // Reload page header('Location: index.php?sessions_checked=true'); exit(0); @@ -87,8 +88,15 @@ function change_os(type) {
Logo
- - +
Error: Seems you have FrontAccounting application already installed.
+After logging as an admin to first installed company you can: +
+
Error:
config_db.php - Writeable'; } elseif(!file_exists($path_to_root.'/config_db.php')) { echo 'File Not Found'; } else { echo 'Unwriteable'; } ?> + Writeable'; } elseif(file_exists($path_to_root.'/config_db.php')) { echo 'File Exists'; } else { echo 'Unwriteable'; } ?> modules/ - Writeable'; } elseif(!file_exists($path_to_root.'/lang/')) { echo 'Directory Not Found'; } else { echo 'Unwriteable'; } ?> + Writeable'; } elseif(!file_exists($path_to_root.'/modules/')) { echo 'Directory Not Found'; } else { echo 'Unwriteable'; } ?> lang/ diff --git a/install/save.php b/install/save.php index facba388..b11263a3 100644 --- a/install/save.php +++ b/install/save.php @@ -295,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) @@ -360,7 +384,6 @@ if (!$db) session_unset(); session_destroy(); $_SESSION = array(); - header("Location: ".$path_to_root."/index.php"); exit(); diff --git a/installed_extensions.php b/installed_extensions.php deleted file mode 100644 index 8afb638b..00000000 --- a/installed_extensions.php +++ /dev/null @@ -1,23 +0,0 @@ - \ No newline at end of file diff --git a/lang/installed_languages.inc b/lang/installed_languages.inc deleted file mode 100644 index 158bab00..00000000 --- a/lang/installed_languages.inc +++ /dev/null @@ -1,19 +0,0 @@ - ') --- 'code' should match the name of the directory for the language under \lang --- 'name' is the name that will be displayed in the language selection list (in Users and Display Setup) --- 'rtl' only needs to be set for right-to-left languages like Arabic and Hebrew - -*/ - - -$installed_languages = array ( - 0 => array ('code' => 'en_GB', 'name' => 'English', 'encoding' => 'iso-8859-1'), - array ('code' => 'en_US', 'name' => 'English (US)', 'encoding' => 'iso-8859-1'), - ); - -$dflt_lang = 'en_GB'; -?> \ No newline at end of file -- 2.30.2