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