-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshared.php
152 lines (132 loc) · 5.55 KB
/
shared.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
/*===================================================================
CompanyMaps 8.1 SharedLibs
Release date 2023-03-20
Copyright (c) 2016-2022 by MavoDev
see https://www.mavodev.de for more details
==================================================================== */
# include config file
include __DIR__ ."/../config_cmaps.php";
# check database availability
function checkDB() {
global $dbServer,$dbUser,$dbPass,$dbName;
$checkLink = mysqli_connect($dbServer,$dbUser,$dbPass,$dbName);
if (!$checkLink) {
return 'false';
}
else {
return 'true';
}
}
# shared function for the substitution of the old mysql function
function mysqli_result($result, $row, $field = 0) {
# Adjust the result pointer to that specific row
$result->data_seek($row);
# Fetch result array
$data = $result->fetch_array();
return $data[$field];
}
# shared function to create log entries
function auditlog($EventType, $EventUser, $EventInfo) {
global $dbServer, $dbName, $dbUser, $dbPass;
$dbTable = 'auditlog';
$dbLink = mysqli_connect($dbServer,$dbUser,$dbPass,$dbName);
$date = date_create();
$EventTime = date_format($date, 'Y-m-d H:i:s') . "\n";
$EventUser = str_replace("\\", "\\\\", $EventUser);
# sanitize input
$EventUser = htmlspecialchars($EventUser, ENT_QUOTES);
$EventInfo = htmlspecialchars($EventInfo, ENT_QUOTES);
mysqli_query($dbLink, "INSERT INTO `$dbName`.`$dbTable` (`ID`, `EventTime`, `EventType`, `EventUser`, `EventInfo`) VALUES (NULL, '$EventTime', '$EventType', '$EventUser', '$EventInfo');");
mysqli_close($dbLink);
}
# Permission check for current logged-in user. Returns level of permission (0=none, 1=read, 2=write)
function permcheck($PermUser, $Permission) {
global $dbServer, $dbName, $dbUser, $dbPass;
$userLink = mysqli_connect($dbServer,$dbUser,$dbPass,$dbName);
$userQuery = mysqli_query($userLink, "SELECT * FROM `config_mapadmins`");
$userNum = mysqli_num_rows ($userQuery);
for ($t = 0; $t < $userNum; $t++) {
$user = mysqli_result($userQuery,$t,1);
$role = mysqli_result($userQuery,$t,2);
if ($user == $PermUser) {
# connect to roletable to get permissions for role
$roleLink = mysqli_connect($dbServer,$dbUser,$dbPass,$dbName);
$roleDetails = mysqli_query($roleLink, "SELECT * FROM `config_roles`");
$roleNum = mysqli_num_rows ($roleDetails);
for ($r = 0; $r < $roleNum; $r++) {
$roleID = mysqli_result($roleDetails,$r,0);
$roleName = mysqli_result($roleDetails,$r,1);
if ($role == $roleID) {
$PermissionField = 'perm_'.$Permission;
$rolePermissions = mysqli_query($roleLink, "SELECT `$PermissionField` FROM `config_roles` WHERE `ID` = $roleID");
return $roleName = mysqli_result($rolePermissions,0,0);
break;
}
}
}
}
mysqli_close($userLink);
return 0;
}
# Output debug messages into browser console
function debug_to_console( $data ) {
$output = $data;
if ( is_array( $output ) )
$output = implode( ',', $output);
echo "<script>console.log( 'Debug Objects: " . $output . "' );</script>";
}
if (checkDB() == 'false') {
include __DIR__ ."/tools/create_db.php";
}
# get departments from DB
$dbLink = mysqli_connect($dbServer,$dbUser,$dbPass,$dbName);
$query = mysqli_query($dbLink, "SELECT * FROM `config_department_list` ORDER BY `department-name`");
$num = mysqli_num_rows ($query);
$department_list = array();
for ($t = 0; $t < $num; $t++) {
$depname = mysqli_result($query,$t,1);
array_push($department_list, $depname);
}
mysqli_close($dbLink);
# get general variables from DB
$dbLink = mysqli_connect($dbServer,$dbUser,$dbPass,$dbName);
$query = mysqli_query($dbLink, "SELECT * FROM `config_general`");
$num = mysqli_num_rows ($query);
for ($t = 0; $t < $num; $t++) {
$variable = mysqli_result($query,$t,1);
$value = mysqli_result($query,$t,2);
$$variable = $value;
}
mysqli_close($dbLink);
if ($logo_regular == '') {$logo_regular='images/cmaps-regular.png';}
if ($logo_hover == '') {$logo_hover='images/cmaps-hover.png';}
if ($apptitle == '') {$apptitle='CompanyMaps';}
# get mapadmins from DB
$dbLink = mysqli_connect($dbServer,$dbUser,$dbPass,$dbName);
$query = mysqli_query($dbLink, "SELECT * FROM `config_mapadmins`");
$num = mysqli_num_rows ($query);
$mapadmins = array();
for ($t = 0; $t < $num; $t++) {
$user = mysqli_result($query,$t,1);
$role = mysqli_result($query,$t,2);
array_push($mapadmins, $user);
}
mysqli_close($dbLink);
# get maplist and scales from DB
$dbLink = mysqli_connect($dbServer,$dbUser,$dbPass,$dbName);
$query = mysqli_query($dbLink, "SELECT * FROM `config_maplist` order by mapname");
$num = mysqli_num_rows ($query);
$maplist = array();
for ($t = 0; $t < $num; $t++) {
$mapname = mysqli_result($query,$t,1);
$mapactive = mysqli_result($query,$t,3);
${'itemscale_'.$mapname} = mysqli_result($query,$t,2);
if ($mapactive == 'yes') {
array_push($maplist, $mapname);
}
}
# create empty tables if missing
mysqli_query($dbLink, "CREATE TABLE IF NOT EXISTS `$dbName`.`config_robinspaces` ( `ID` INT NOT NULL AUTO_INCREMENT , `spacename` TEXT NOT NULL , `spaceid` INT NOT NULL , PRIMARY KEY (`ID`)) ENGINE = InnoDB; ");
mysqli_close($dbLink);
?>