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