2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU General Public License, GPL,
5 as published by the Free Software Foundation, either version 3
6 of the License, or (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 function output_html($text)
14 global $before_box, $Ajax, $messages;
15 // Fatal errors are not send to error_handler,
16 // so we must check the output
17 if ($text && preg_match('/\bFatal error(<.*?>)?:(.*)/i', $text, $m)) {
18 $Ajax->aCommands = array(); // Don't update page via ajax on errors
19 $text = preg_replace('/\bFatal error(<.*?>)?:(.*)/i','', $text);
20 $messages[] = array(E_ERROR, $m[2], null, null);
23 return in_ajax() ? fmt_errors() : ($before_box.fmt_errors().$text);
25 //----------------------------------------------------------------------------------------
32 //----------------------------------------------------------------------------------------
36 header("HTTP/1.1 401 Authorization Required");
37 echo "<center><br><br><font size='5' color='red'><b>" . _("Incorrect Password") . "<b></font><br><br>";
38 echo "<b>" . _("The user and password combination is not valid for the system.") . "<b><br><br>";
40 echo _("If you are not an authorized user, please contact your system administrator to obtain an account to enable you to use the system.");
41 echo "<br><a href='javascript:history.go(-1)'>" . _("Back") . "</a>";
48 //----------------------------------------------------------------------------------------
50 function check_page_security($page_security)
52 if (!$_SESSION["wa_current_user"]->check_user_access())
54 echo "<br><br><br><center>";
55 echo "<b>" . _("Security settings have not been defined for your user account.");
56 echo "<br>" . _("Please contact your system administrator.") . "</b>";
62 if (!$_SESSION["wa_current_user"]->can_access_page($page_security))
64 // no_menu parameter guess here is ugly hack, but works for now.
65 // Better solution is to use global switch for menu, set before
66 // session.inc inclusion.
67 page(_("Access denied"), strpos($_SERVER['PHP_SELF'], '/view/'));
69 echo "<center><br><br><br><b>";
70 echo _("The security settings on your account do not permit you to access this function");
72 echo "<br><br><br><br></center>";
79 //-----------------------------------------------------------------------------
80 // Removing magic quotes from nested arrays/variables
82 function strip_quotes($data)
84 if(get_magic_quotes_gpc()) {
86 foreach($data as $k => $v) {
87 $data[$k] = strip_quotes($data[$k]);
90 return stripslashes($data);
95 //============================================================================
98 function login_timeout()
100 if ($_SESSION["wa_current_user"]->logged) {
101 $tout = $_SESSION["wa_current_user"]->timeout;
102 if ($tout && (time() > $_SESSION["wa_current_user"]->last_act + $tout))
104 $_SESSION["wa_current_user"]->logged = false;
106 $_SESSION["wa_current_user"]->last_act = time();
109 //============================================================================
110 if (!isset($path_to_root))
115 // Prevent register_globals vulnerability
116 if (isset($_GET['path_to_root']) || isset($_POST['path_to_root']))
117 die("Restricted access");
119 include_once($path_to_root . "/frontaccounting.php");
120 include_once($path_to_root . "/includes/current_user.inc");
121 include_once($path_to_root . "/includes/lang/language.php");
122 include_once($path_to_root . "/config_db.php");
123 include_once($path_to_root . "/includes/ajax.inc");
124 include_once($path_to_root . "/includes/ui/ui_msgs.inc");
127 Uncomment the setting below when using FA on shared hosting
128 to avoid unexpeced session timeouts.
129 Make sure this directory exists and is writable!
131 //ini_set('session.save_path', dirname(__FILE__).'/../tmp/');
133 ini_set('session.gc_maxlifetime', 36000); // 10hrs
135 session_name('FrontAccounting');
137 // this is to fix the "back-do-you-want-to-refresh" issue - thanx PHPFreaks
138 header("Cache-control: private");
142 // Page Initialisation
143 if (!isset($_SESSION['languages']))
145 language::load_languages(); // sets also default $_SESSION['language']
148 language::set_language($_SESSION['language']->code);
150 // include $Hooks object if locale file exists
151 if(@include_once($path_to_root . "/lang/".$_SESSION['language']->code."/locale.inc"))
153 $Hooks = new Hooks();
156 include_once($path_to_root . "/config.php");
157 include_once($path_to_root . "/includes/main.inc");
159 // Ajax communication object
162 // js/php validation rules container
164 // bindings for editors
166 // page help. Currently help for function keys.
169 // intercept all output to destroy it in case of ajax call
170 register_shutdown_function('end_flush');
171 ob_start('output_html',0);
173 // colect all error msgs
174 set_error_handler('error_handler' /*, errtypes */);
176 if (!isset($_SESSION["wa_current_user"]))
177 $_SESSION["wa_current_user"] = new current_user();
179 set_global_connection();
183 if (!$_SESSION["wa_current_user"]->logged_in())
186 if (!isset($_POST["user_name_entry_field"]) or $_POST["user_name_entry_field"] == "")
188 if (strstr($_SERVER['PHP_SELF'], 'timeout.php') == false)
189 $_SESSION['timeout'] = array( 'uri'=> $_SERVER['REQUEST_URI'],
193 include($path_to_root . "/access/login.php");
195 // ajax update of current page elements - open login window in popup
196 // to not interfere with ajaxified page.
197 $Ajax->popup($path_to_root . "/access/timeout.php");
201 $succeed = $_SESSION["wa_current_user"]->login($_POST["company_login_name"],
202 $_POST["user_name_entry_field"],
203 md5($_POST["password"]));
204 // select full vs fallback ui mode on login
205 $_SESSION["wa_current_user"]->ui_mode = $_POST['ui_mode'];
208 // Incorrect password
211 $lang = $_SESSION['language'];
212 language::set_language($_SESSION['language']->code);
216 if (!isset($_SESSION["App"])) {
217 $_SESSION["App"] = new front_accounting();
218 $_SESSION["App"]->init();
221 // Run with debugging messages for the system administrator(s) but not anyone else
222 /*if (in_array(15, $security_groups[$_SESSION["AccessLevel"]])) {
228 //----------------------------------------------------------------------------------------
230 check_page_security($page_security);
232 // POST vars cleanup needed for direct reuse.
233 // We quote all values later with db_escape() before db update.
234 $_POST = strip_quotes($_POST);