*** empty log message ***
[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
80         if (!isset($_SESSION["wa_current_user"]) ||
81                 (isset($_SESSION["wa_current_user"]) && !$_SESSION["wa_current_user"]->logged_in())) 
82         {
83
84                 $_SESSION["wa_current_user"] = new current_user();
85
86         // Show login screen
87         if (!isset($_POST["user_name_entry_field"]) or $_POST["user_name_entry_field"] == "") 
88         {
89                 include($path_to_root . "/access/login.php");
90             exit;
91         }
92         }
93
94         if (isset($_POST["user_name_entry_field"])) 
95         {
96                 $succeed = $_SESSION["wa_current_user"]->login($_POST["company_login_name"],
97                         $_POST["user_name_entry_field"],
98                         md5($_POST["password"]));
99
100                 if (!$succeed) 
101                 {
102                         // Incorrect password
103                         login_fail();
104                 }
105         }
106
107         check_page_security($page_security);
108
109     // Run with debugging messages for the system administrator(s) but not anyone else
110     /*if (in_array(15, $security_groups[$_SESSION["AccessLevel"]])) {
111         $debug = 1;
112     } else {
113         $debug = 0;
114     }*/
115
116         //----------------------------------------------------------------------------------------
117 ?>