c5d417f710d2b0d0dac559939b9573935c3bd27a
[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         if (!isset($path_to_root)) 
13         {
14                 $path_to_root = ".";
15         }
16
17     include_once($path_to_root . "/includes/current_user.inc");
18
19     include_once($path_to_root . "/config.php");
20
21     include_once($path_to_root . "/includes/main.inc");
22
23     //----------------------------------------------------------------------------------------
24
25         function kill_login() 
26         {
27         session_unset();
28                 session_destroy();
29         }
30
31         //----------------------------------------------------------------------------------------
32
33         function login_fail() 
34         {
35         echo "<center><br><br><font size='5' color='red'><b>" . _("Incorrect Password") . "<b></font><br><br>";
36         echo "<b>" . _("The user and password combination is not valid for the system.") . "<b><br><br>";
37
38         echo _("If you are not an authorized user, please contact your system administrator to obtain an account to enable you to use the system.");
39                 echo "<br><a href='javascript:history.go(-1)'>" . _("Back") . "</a>";
40         echo "</center>";
41
42         kill_login();
43         die();
44         }
45
46         //----------------------------------------------------------------------------------------
47
48         function check_page_security($page_security) 
49         {
50                 if (!$_SESSION["wa_current_user"]->check_user_access()) 
51                 {
52                         echo "<br><br><br><center>";
53                         echo "<b>" . _("Security settings have not been defined for your user account.");
54                         echo "<br>" . _("Please contact your system administrator.") . "</b>";
55
56                         kill_login();
57                         exit;
58                 }
59
60                 if (!$_SESSION["wa_current_user"]->can_access_page($page_security)) 
61                 {
62                         page(_("Access denied"));
63                         echo "<center><br><br><br><b>";
64                         echo _("The security settings on your account do not permit you to access this function");
65                         echo "</b>";
66                         echo "<br><br><a href='javascript:history.go(-1)'>" . _("Back") . "</a>";
67                         echo "<br><br><br><br>";
68                         //echo '<script type="text/javascript">';
69                         //echo 'alert("' . _("The security settings on your account do not permit you to access this function") . '");';
70                         //echo 'history.go(-1)';
71                         //echo '</script>'
72                         end_page();
73                         //kill_login();
74                         exit;
75                 }
76         }
77
78         //----------------------------------------------------------------------------------------
79         if (!isset($_SESSION["wa_current_user"]) ||
80                 (isset($_SESSION["wa_current_user"]) && !$_SESSION["wa_current_user"]->logged_in())) 
81         {
82
83                 $_SESSION["wa_current_user"] = new current_user();
84
85         // Show login screen
86         if (!isset($_POST["user_name_entry_field"]) or $_POST["user_name_entry_field"] == "") 
87         {
88                 include($path_to_root . "/access/login.php");
89             exit;
90         }
91         }
92
93         if (isset($_POST["user_name_entry_field"])) 
94         {
95                 $succeed = $_SESSION["wa_current_user"]->login($_POST["company_login_name"],
96                         $_POST["user_name_entry_field"],
97                         md5($_POST["password"]));
98
99                 if (!$succeed) 
100                 {
101                         // Incorrect password
102                         login_fail();
103                 }
104         }
105
106         global $js_lib, $js_static, $js_path;
107         $js_path = $path_to_root.'/js/';
108         // standard external js scripts included in all files
109         $js_static = array('behaviour.js');
110         // additional js source included in header
111         $js_lib = array();
112         
113         add_js_user_num(); // add user native numeric input functions
114
115     // Run with debugging messages for the system administrator(s) but not anyone else
116     /*if (in_array(15, $security_groups[$_SESSION["AccessLevel"]])) {
117         $debug = 1;
118     } else {
119         $debug = 0;
120     }*/
121
122         //----------------------------------------------------------------------------------------
123         check_page_security($page_security);
124 ?>