1 |
rodolico |
1 |
<?php
|
50 |
rodolico |
2 |
$VERSION='2.0.1';
|
|
|
3 |
$BUILD_DATE='20211010';
|
36 |
rodolico |
4 |
$DB_REQUIRED_VERSION = '0.1';
|
45 |
rodolico |
5 |
include_once( dirname(__FILE__) . '/include/functions.php');
|
|
|
6 |
global $configuration;
|
57 |
rodolico |
7 |
global $activeOnly;
|
|
|
8 |
$activeOnly = true;
|
36 |
rodolico |
9 |
$error = '';
|
1 |
rodolico |
10 |
|
45 |
rodolico |
11 |
$configStuff = loadConfig();
|
|
|
12 |
if ( $configStuff['error'] ) {
|
|
|
13 |
print $configStuff['error'];
|
|
|
14 |
die;
|
|
|
15 |
} else {
|
|
|
16 |
$configuration = $configStuff['configuration'];
|
|
|
17 |
$configPath = $configStuff['path'];
|
|
|
18 |
unset( $configStuff );
|
|
|
19 |
}
|
61 |
rodolico |
20 |
|
|
|
21 |
// read all session settings and set them up
|
|
|
22 |
// https://stackoverflow.com/questions/8311320/how-to-change-the-session-timeout-in-php
|
|
|
23 |
foreach ( $configuration['session'] as $key => $value ) {
|
|
|
24 |
ini_set( "session.$key", $value );
|
|
|
25 |
}
|
|
|
26 |
|
45 |
rodolico |
27 |
// get include directories for libraries
|
46 |
rodolico |
28 |
foreach ( $configuration['locations']['include_dirs'] as $key => $dir ) {
|
45 |
rodolico |
29 |
ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . $dir );
|
|
|
30 |
}
|
|
|
31 |
|
|
|
32 |
include_once( 'UsersPermissions.class.php' );
|
|
|
33 |
include_once( 'UsersPermissionsDataSourceMySQLi.class.php' );
|
63 |
rodolico |
34 |
include_once( 'DBQueryHTML.class.php' );
|
45 |
rodolico |
35 |
include_once( 'functions.php' );
|
|
|
36 |
|
|
|
37 |
// since we are storing some user defined classes in the session, session
|
|
|
38 |
// MUST be started after the class definitions are loaded
|
|
|
39 |
session_start();
|
|
|
40 |
|
66 |
rodolico |
41 |
/*
|
|
|
42 |
* $_SESSION will contain the following:
|
|
|
43 |
* 'user'
|
|
|
44 |
* a copy of the login and permissions
|
|
|
45 |
* ['workingon'][ClassName]
|
|
|
46 |
* an id entry for each class (Owner, Location and Device) recently worked on (used in filtering)
|
|
|
47 |
* ['data'][ClassName]
|
|
|
48 |
* The data from the most recent load for the class in question
|
|
|
49 |
* ['restrictions'][ClassName]
|
|
|
50 |
* a list of restrictions for the current user
|
|
|
51 |
*/
|
|
|
52 |
|
36 |
rodolico |
53 |
// make the database connection
|
|
|
54 |
$dbVersion = '';
|
63 |
rodolico |
55 |
$dbConnection = new DBQueryHTML( $configuration['database']['dbserver'],$configuration['database']['dbusername'], $configuration['database']['dbpassword'], $configuration['database']['dbname'] );
|
36 |
rodolico |
56 |
if ( $dbConnection->connect_errno ) {
|
|
|
57 |
$error = "Failed to connect to MySQL: (" . $dbConnection->connect_errno . ") " . $dbConnection->connect_error;
|
|
|
58 |
} else {
|
|
|
59 |
$dbVersion = $dbConnection->getOneDBValue( "select key_value from _system where group_name = 'database' and key_name = 'version'" );
|
21 |
rodolico |
60 |
}
|
20 |
rodolico |
61 |
|
45 |
rodolico |
62 |
//print "<pre>\nSession" . print_r($configuration,true) . '</pre>';
|
|
|
63 |
|
36 |
rodolico |
64 |
|
45 |
rodolico |
65 |
// create a connection for the Users class
|
|
|
66 |
global $connection;
|
|
|
67 |
$connection = new usersPermissionsDataSourceMySQLi(
|
|
|
68 |
$dbConnection,
|
|
|
69 |
$configuration['customUsersFields']
|
|
|
70 |
);
|
|
|
71 |
// if they are not logged in, set up for logging in
|
46 |
rodolico |
72 |
if ( ! isset( $_SESSION['user'] ) ) {
|
45 |
rodolico |
73 |
$_SESSION['user'] = new UsersPermissions( $configuration['customUsersFields'] );
|
|
|
74 |
}
|
36 |
rodolico |
75 |
|
45 |
rodolico |
76 |
|
|
|
77 |
// check if the user has request a log out.
|
|
|
78 |
if ( isset( $_REQUEST['logout'] ) )
|
|
|
79 |
$_SESSION['user']->logout();
|
36 |
rodolico |
80 |
//Setup our HTML header here.
|
|
|
81 |
if(!isset($page_title)) { $page_title = "Untitled"; }
|
45 |
rodolico |
82 |
// set up our "here I am" variable
|
|
|
83 |
$url = htmlentities($configuration['locations']['base_url'] . '/' . $configuration['locations']['main_script'] );
|
|
|
84 |
$baseURL = htmlentities($configuration['locations']['base_url'] );
|
|
|
85 |
|
36 |
rodolico |
86 |
?>
|
45 |
rodolico |
87 |
|
36 |
rodolico |
88 |
<html>
|
42 |
rodolico |
89 |
<head>
|
|
|
90 |
<title><?php echo $page_title;?></title>
|
|
|
91 |
<script language="javascript">
|
|
|
92 |
function eToggle(anctag,darg) {
|
|
|
93 |
var ele = document.getElementById(darg);
|
|
|
94 |
var text = document.getElementById(anctag);
|
|
|
95 |
if(ele.style.display == "block") {
|
|
|
96 |
ele.style.display = "none";
|
|
|
97 |
text.innerHTML = "Show " + darg;
|
|
|
98 |
} else {
|
|
|
99 |
ele.style.display = "block";
|
|
|
100 |
text.innerHTML = "Hide " + darg;
|
|
|
101 |
}
|
|
|
102 |
}
|
|
|
103 |
</script>
|
46 |
rodolico |
104 |
<link rel="stylesheet" type="text/css" href="camp.css">
|
42 |
rodolico |
105 |
</head>
|
|
|
106 |
<body>
|
46 |
rodolico |
107 |
<div class="grid-container">
|
|
|
108 |
<div class="titleimage">
|
42 |
rodolico |
109 |
<h1>
|
|
|
110 |
Computer Asset Management Program
|
|
|
111 |
</h1>
|
|
|
112 |
<h2>
|
|
|
113 |
Version <?php print "$VERSION, $BUILD_DATE"; ?>
|
|
|
114 |
</h2>
|
|
|
115 |
</div>
|
|
|
116 |
<?php
|
|
|
117 |
if ( $error ) {
|
|
|
118 |
print "<h1>Serious Error encountered</h1><p>$error</p>";
|
|
|
119 |
die($error);
|
|
|
120 |
}
|
|
|
121 |
if ( $dbVersion != $DB_REQUIRED_VERSION ) {
|
|
|
122 |
print "<h1><b>Warning</b>: Database is version $dbVersion, but requires version $DB_REQUIRED_VERSION. Repair immediately</h1>";
|
|
|
123 |
die;
|
|
|
124 |
}
|
|
|
125 |
?>
|
46 |
rodolico |
126 |
<?php
|
50 |
rodolico |
127 |
if ( isset( $_SESSION['user'] ) && $_SESSION['user']->name() === null ) {
|
46 |
rodolico |
128 |
/*
|
|
|
129 |
* we have to run this first since the last call, where name
|
|
|
130 |
* is actually populated, returns an empty screen, but the
|
|
|
131 |
* div still exists, so we check first, then if it is not
|
|
|
132 |
* empty, do the div and page.
|
|
|
133 |
*/
|
|
|
134 |
$page = $_SESSION['user']->HTML($connection);
|
|
|
135 |
if ( $page ) {
|
|
|
136 |
print "<div class='login'>\n$page\n</div>\n";
|
42 |
rodolico |
137 |
}
|
54 |
rodolico |
138 |
}
|
|
|
139 |
if ( ! isset( $_SESSION['restrictions'] ) && isset( $_SESSION['user'] ) && $_SESSION['user']->name() !== null ) {
|
46 |
rodolico |
140 |
// this must be new, so we have to build our where clause
|
|
|
141 |
buildRestrictions();
|
|
|
142 |
}
|
|
|
143 |
?>
|
45 |
rodolico |
144 |
|
|
|
145 |
|