Fixed many minor bugs, new ones as well as debtor_trans related.
[fa-stable.git] / includes / session.inc
1 <?php
2         /*--------------------------------------------------\
3         |               |               | session.inc       |
4         |---------------------------------------------------|
5     | front_accounting                                                                  |
6     | http://open-accounting.sourceforge.net/                   |
7     | by KylieTech Consulting                           |
8     | http://frontaccounting.com/                               |
9     | by Joe Hunt Consulting         |
10         \--------------------------------------------------*/
11
12         function output_html($text)
13         {
14           global $before_box;
15           return  in_ajax() ? fmt_errors() : ($before_box.fmt_errors().$text);
16         }
17
18         if (!isset($path_to_root))
19         {
20                 $path_to_root = ".";
21         }
22
23     include_once($path_to_root . "/includes/current_user.inc");
24
25 /*
26         // Make sure this directory exists and is writable!
27         $session_save_path = dirname(__FILE__).'/tmp/';
28 */
29
30         $session_save_path = session_save_path();
31         if (strpos($session_save_path, ";") !== false)
32                 $session_save_path = substr($session_save_path, strpos($session_save_path, ";") + 1);
33
34         if (isset($session_save_path))
35         {
36                 session_save_path($session_save_path);
37                 unset($session_save_path);
38         }
39         if (!isset($path_to_root) || isset($_GET['path_to_root']) || isset($_POST['path_to_root']))
40                 die("Restricted access");
41         include_once($path_to_root . "/includes/lang/language.php");
42         include_once($path_to_root . "/config_db.php");
43         include_once($path_to_root . "/config.php");
44         include_once($path_to_root . "/includes/ajax.inc");
45         $Ajax =& new Ajax();
46
47         include_once($path_to_root . "/includes/main.inc");
48
49     //----------------------------------------------------------------------------------------
50
51         function kill_login()
52         {
53         session_unset();
54                 session_destroy();
55         }
56
57         //----------------------------------------------------------------------------------------
58
59         function login_fail()
60         {
61         echo "<center><br><br><font size='5' color='red'><b>" . _("Incorrect Password") . "<b></font><br><br>";
62         echo "<b>" . _("The user and password combination is not valid for the system.") . "<b><br><br>";
63
64         echo _("If you are not an authorized user, please contact your system administrator to obtain an account to enable you to use the system.");
65                 echo "<br><a href='javascript:history.go(-1)'>" . _("Back") . "</a>";
66         echo "</center>";
67
68         kill_login();
69         die();
70         }
71
72         //----------------------------------------------------------------------------------------
73
74         function check_page_security($page_security)
75         {
76                 if (!$_SESSION["wa_current_user"]->check_user_access())
77                 {
78                         echo "<br><br><br><center>";
79                         echo "<b>" . _("Security settings have not been defined for your user account.");
80                         echo "<br>" . _("Please contact your system administrator.") . "</b>";
81
82                         kill_login();
83                         exit;
84                 }
85
86                 if (!$_SESSION["wa_current_user"]->can_access_page($page_security))
87                 {
88                         page(_("Access denied"));
89                         echo "<center><br><br><br><b>";
90                         echo _("The security settings on your account do not permit you to access this function");
91                         echo "</b>";
92                         echo "<br><br><a href='javascript:history.go(-1)'>" . _("Back") . "</a>";
93                         echo "<br><br><br><br></center>";
94                         //echo '<script type="text/javascript">';
95                         //echo 'alert("' . _("The security settings on your account do not permit you to access this function") . '");';
96                         //echo 'history.go(-1)';
97                         //echo '</script>'
98                         end_page();
99                         //kill_login();
100                         exit;
101                 }
102         }
103
104         //----------------------------------------------------------------------------------------
105         if (!isset($_SESSION["wa_current_user"]) ||
106                 (isset($_SESSION["wa_current_user"]) && !$_SESSION["wa_current_user"]->logged_in()))
107         {
108
109                 $_SESSION["wa_current_user"] = new current_user();
110
111         // Show login screen
112         if (!isset($_POST["user_name_entry_field"]) or $_POST["user_name_entry_field"] == "")
113         {
114                 include($path_to_root . "/access/login.php");
115                 $Ajax->redirect($path_to_root . "/access/login.php");
116             exit;
117         }
118         }
119         include_once($path_to_root . "/includes/ui/ui_msgs.inc");
120         // intercept all output to destroy it in case of ajax call
121         register_shutdown_function('ob_end_flush');
122         ob_start('output_html',0);
123         // colect all error msgs
124         set_error_handler('error_handler' /*, errtypes */);
125
126         if (isset($_POST["user_name_entry_field"]))
127         {
128                 $succeed = $_SESSION["wa_current_user"]->login($_POST["company_login_name"],
129                         $_POST["user_name_entry_field"],
130                         md5($_POST["password"]));
131
132                 if (!$succeed)
133                 {
134                         // Incorrect password
135                         login_fail();
136                 }
137         }
138
139     // Run with debugging messages for the system administrator(s) but not anyone else
140     /*if (in_array(15, $security_groups[$_SESSION["AccessLevel"]])) {
141         $debug = 1;
142     } else {
143         $debug = 0;
144     }*/
145
146         //----------------------------------------------------------------------------------------
147
148         check_page_security($page_security);
149
150
151
152 ?>