Cleaning startup code.
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Tue, 24 Feb 2009 21:03:50 +0000 (21:03 +0000)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Tue, 24 Feb 2009 21:03:50 +0000 (21:03 +0000)
includes/db/connect_db.inc
includes/lang/gettext.php
includes/lang/language.php
includes/session.inc
index.php

index 181651ffdeed9f9169deb37deea7da0384c78c22..fa57b678fc4d530e3f98961a96725ee93cb74487 100644 (file)
@@ -9,7 +9,6 @@
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
 ***********************************************************************/
-set_global_connection();
 
 function set_global_connection()
 {
index 7bdb69a8636553aa17bd907f20d2f8a4f706b161..4c4f163396691c2314fb0e8e4ebbaa4406aa7421 100644 (file)
@@ -94,9 +94,9 @@ class get_text
         } 
         elseif (!isset($support_obj)) 
         {
-            trigger_error("get_text not initialized !". endl.
+            trigger_error("get_text not initialized !". '\n'.
                "Please call get_text::init() before calling ".
-                "any get_text function !" . endl , E_USER_ERROR);
+                "any get_text function !" . '\n' , E_USER_ERROR);
         }
         return $support_obj;
     }
@@ -216,7 +216,7 @@ class get_text
 }
 
 function raise_error($str) {
-       //echo "$str";
+//     echo "$str";
        return 1;
 }
 
index 62866f0b0279564036e144e42a07576351652d18..059901cfc66cfee89278b72f929ea583d6973b3e 100644 (file)
@@ -9,8 +9,6 @@
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
 ***********************************************************************/
-if (!isset($path_to_root) || isset($_GET['path_to_root']) || isset($_POST['path_to_root']))
-       die(_("Restricted access"));
 include_once($path_to_root . "/lang/installed_languages.inc");
 include_once($path_to_root . "/includes/lang/gettext.php");
 
@@ -36,7 +34,6 @@ class language
                return "lang/" . $this->code;
        }
 
-
        function get_current_language_dir() 
        {
                $lang = $_SESSION['language'];
@@ -46,9 +43,9 @@ class language
        function set_language($code) 
        {
            global $comp_path, $path_to_root;
-           
-               if (isset($_SESSION['languages'][$code]) &&
-                       $_SESSION['language'] != $_SESSION['languages'][$code]) 
+               
+               $changed = $_SESSION['language']->code != $code;
+               if (isset($_SESSION['languages'][$code]) && $changed)
                {
                // flush cache as we can use several languages in one account
                    flush_dir($comp_path.'/'.user_company().'/js_cache');
@@ -57,6 +54,17 @@ class language
                        // check id file exists only once for session
                        $_SESSION['language']->is_locale_file = file_exists($locale);
                }
+
+               $lang = $_SESSION['language'];
+               get_text::set_language($lang->code, $lang->encoding);
+               get_text::add_domain($lang->code, $path_to_root . "/lang");
+               
+               // Necessary for ajax calls. Due to bug in php 4.3.10 for this 
+               // version set globally in php.ini
+               ini_set('default_charset', $lang->encoding);
+
+               if (isset($_SESSION['App']) && $changed)
+                       $_SESSION['App']->init(); // refresh menu
        }
 
        /**
@@ -106,26 +114,6 @@ function _set($key,$value)
        get_text::set_var($key,$value);
 }
 
-function reload_page($msg) 
-{
-       global $Ajax;
-//     header("Location: $_SERVER['PHP_SELF']."");
-//     exit;
-       echo "<html>";
-       echo "<head>";
-    echo "<title>Changing Languages</title>";
-       echo '<meta http-equiv="refresh" content="0;url=' . $_SERVER['PHP_SELF'] . '">';
-       echo '</head>';
-       echo '<body>';
-       echo '<div>';
-       if ($msg != "")
-               echo $msg . " " . $_SERVER['PHP_SELF'];
-       echo "</div>";  
-       echo "</body>";
-       echo "</html>";
-       $Ajax->redirect($_SERVER['PHP_SELF']);
-}
-
 if (!function_exists("_")) 
 {
        function _($text) 
index 4a67da7aa964d5e5f68e941dff95a9ee355eaded..a6662a7ee0988c58ae3bce3a44a5cb359a4f1303 100644 (file)
@@ -103,6 +103,8 @@ include_once($path_to_root . "/includes/current_user.inc");
 include_once($path_to_root . "/includes/lang/language.php");
 include_once($path_to_root . "/config_db.php");
 include_once($path_to_root . "/includes/ajax.inc");
+include_once($path_to_root . "/includes/main.inc");
+include_once($path_to_root . "/includes/ui/ui_msgs.inc");
 
 /*
        Make sure this directory exists and is writable!
@@ -114,31 +116,23 @@ session_start();
 // this is to fix the "back-do-you-want-to-refresh" issue - thanx PHPFreaks
 header("Cache-control: private");
 
+get_text::init();
+
 // Page Initialisation
 if (!isset($_SESSION['languages'])) 
 {
-       language::load_languages();
+       language::load_languages(); // sets also default $_SESSION['language']
 }
 
-$lang = $_SESSION['language'];
-
-// get_text support
-get_text::init();
-get_text::set_language($lang->code, $lang->encoding);
-//get_text::add_domain("wa", $path_to_root . "/lang");
-get_text::add_domain($lang->code, $path_to_root . "/lang");
-
-// Necessary for ajax calls. Due to bug in php 4.3.10 for this 
-// version set globally in php.ini
-ini_set('default_charset', $_SESSION['language']->encoding);
+language::set_language($_SESSION['language']->code);
 
 include_once($path_to_root . "/config.php");
 
 $Ajax =& new Ajax();
 
-include_once($path_to_root . "/includes/main.inc");
+//include_once($path_to_root . "/includes/main.inc");
 
-include_once($path_to_root . "/includes/ui/ui_msgs.inc");
+//include_once($path_to_root . "/includes/ui/ui_msgs.inc");
 
 // intercept all output to destroy it in case of ajax call
 register_shutdown_function('ob_end_flush');
@@ -149,6 +143,7 @@ set_error_handler('error_handler' /*, errtypes */);
 
 if (!isset($_SESSION["wa_current_user"]))
        $_SESSION["wa_current_user"] = new current_user();
+set_global_connection();
 
 if (!$_SESSION["wa_current_user"]->logged_in())
 {
@@ -170,10 +165,14 @@ if (!$_SESSION["wa_current_user"]->logged_in())
                        login_fail();
                }
                $lang = $_SESSION['language'];
-               get_text::set_language($lang->code, $lang->encoding);
+               language::set_language($_SESSION['language']->code);
        }
 }
 
+if (!isset($_SESSION["App"])) {
+       $_SESSION["App"] = new front_accounting();
+       $_SESSION["App"]->init();
+}
 
 // Run with debugging messages for the system administrator(s) but not anyone else
 /*if (in_array(15, $security_groups[$_SESSION["AccessLevel"]])) {
index 5074e17457e882afdd1b3445179686e031a4b8f8..269636a04eedb243f8b3a786e917cee502355ff0 100644 (file)
--- a/index.php
+++ b/index.php
@@ -14,8 +14,6 @@
        ini_set('xdebug.auto_trace',1);
        include_once("includes/session.inc");
 
-       if (!isset($_SESSION["App"]))
-               $_SESSION["App"] = new front_accounting();
        $app = &$_SESSION["App"];
        if (isset($_GET['application']))
                $app->selected_application = $_GET['application'];