-
Notifications
You must be signed in to change notification settings - Fork 1
/
assets.php
217 lines (206 loc) · 11.4 KB
/
assets.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<?php
include 'config.php';
session_start();
if (!isset($_SESSION['loggedin'])) {
header('Location: login.php');
exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Asset Management System</title>
<link rel="stylesheet" href="style.css?v=1.1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"
integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous">
</script>
<link rel="icon" type="image/x-icon" href="white.png">
<link href="https://unpkg.com/bootstrap-table@1.22.1/dist/bootstrap-table.min.css" rel="stylesheet">
<script src="https://unpkg.com/bootstrap-table@1.22.1/dist/bootstrap-table.min.js"></script>
<script src="https://unpkg.com/bootstrap-table@1.22.1/dist/extensions/print/bootstrap-table-print.min.js"></script>
<script>
function confirmAction() {
return confirm("Are you sure?");
}
</script>
</head>
<body>
<?php include 'nav.php'; ?>
<div class="container">
<div class="row">
<div class="col">
<h1>Assets</h1>
<input type="text" id="searchInput" class="form-control form-control-lg d-print-none"
placeholder="Search for an asset..."><br>
<select id="assetType" class="form-select form-select d-print-none">
<option value="">All</option>
<option value="Office Equipment">Office Equipment</option>
<option value="Furnitures and Fixtures">Furnitures and Fixtures</option>
<option value="Aircon Equipment">Aircon Equipment</option>
</select>
<script>
var searchInput = document.getElementById('searchInput');
var assetType = document.getElementById('assetType');
searchInput.addEventListener('input', function() {
var searchQuery = searchInput.value;
var selectedAssetType = assetType.value;
searchAssets(searchQuery, selectedAssetType);
});
assetType.addEventListener('change', function() {
var searchQuery = searchInput.value;
var selectedAssetType = assetType.value;
searchAssets(searchQuery, selectedAssetType);
});
function searchAssets(query, assetType) {
var table = document.getElementById('assetsTable');
var rows = table.getElementsByTagName('tr');
for (var i = 1; i < rows.length; i++) {
var found = false;
var cells = rows[i].getElementsByTagName('td');
for (var j = 0; j < cells.length; j++) {
if ([0, 1, 2, 3, 4, 5, 6, 9, 10].includes(j)) {
var name = cells[j].textContent || cells[j].innerText;
if ((name.toLowerCase().indexOf(query.toLowerCase()) > -1) &&
(assetType === '' || assetType === cells[1].textContent)) {
found = true;
break;
}
}
}
if (found) {
rows[i].style.display = '';
} else {
rows[i].style.display = 'none';
}
}
}
</script>
<br>
<div class="table-responsive">
<table class="table table-striped table-bordered border-start" id="assetsTable"
data-show-print="true">
<thead>
<tr>
<th>Asset Tag</th>
<th>Asset Type</th>
<th>Brand</th>
<th>Model</th>
<th>Equipment Name</th>
<th>Serial Number</th>
<th>Status</th>
<th>Date Acquired</th>
<th>Price Value</th>
<th>Location</th>
<th>Remarks</th>
<th>Date Updated and User</th>
<th>Documents</th>
<?php if ($_SESSION['account_type'] === "admin" || $_SESSION['account_type'] === "superadmin") {
echo "<th class='d-print-none'>Actions</th>";
} ?>
</tr>
</thead>
<tbody>
<?php
$sql = "SELECT * FROM assets";
$result = $mysqli->query($sql);
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$sql2 = "SELECT * FROM users WHERE user_id = '" . $row["user_id"] . "'";
$result2 = $mysqli->query($sql2);
$row2 = $result2->fetch_assoc();
$param = $row["documents"];
$array = explode(",", $param);
if (!empty($param)) {
echo "<tr>
<td style='font-family: consolas'>" . $row["asset_tag"] . "</td>
<td>" . $row["asset_type"] . "</td>
<td>" . $row["brand"] . "</td>
<td>" . $row["model"] . "</td>
<td>" . $row["equipment_name"] . "</td>
<td>" . $row["serial_number"] . "</td>
<td>" . $row["status"] . "</td>
<td>" . $row["date_acquired"] . "</td>
<td> ₱" . number_format(intval($row["price_value"]), 2) . "</td>
<td>" . $row["location_asset"] . "</td>
<td>" . $row["remarks"] . "</td>
<td>" . $row["updated_at"] . " by " . $row2["firstname"] . "</td>
<td>";
foreach ($array as $document) {
echo "<a href='uploads/$document' class='btn btn-sm btn-outline-secondary' target='_blank'>$document</a><br>";
}
echo "</td>";
if ($_SESSION['account_type'] === "admin" || $_SESSION['account_type'] === "superadmin") {
echo "<td class='d-print-none actions'>
<a href='update_asset.php?asset_tag=" . $row["asset_tag"] . "' class='btn btn-sm btn-outline-secondary'>Edit</a><br>
<a href='delete_asset.php?asset_tag=" . $row["asset_tag"] . "' class='btn btn-sm btn-outline-secondary' onclick='return confirmAction();'>Delete</a><br>
</td>
</tr>";
} else {
echo "</tr>";
}
} else {
echo "<tr>
<td style='font-family: consolas'>" . $row["asset_tag"] . "</td>
<td>" . $row["asset_type"] . "</td>
<td>" . $row["brand"] . "</td>
<td>" . $row["model"] . "</td>
<td>" . $row["equipment_name"] . "</td>
<td>" . $row["serial_number"] . "</td>
<td>" . $row["status"] . "</td>
<td>" . $row["date_acquired"] . "</td>
<td> ₱" . number_format(intval($row["price_value"]), 2) . "</td>
<td>" . $row["location_asset"] . "</td>
<td>" . $row["remarks"] . "</td>
<td>" . $row["updated_at"] . " by " . $row2["firstname"] . "</td>
<td></td>";
if ($_SESSION['account_type'] === "admin" || $_SESSION['account_type'] === "superadmin") {
echo "<td class='d-print-none actions'>
<a href='update_asset.php?asset_tag=" . $row["asset_tag"] . "' class='btn btn-sm btn-outline-secondary'>Edit</a><br>
<a href='delete_asset.php?asset_tag=" . $row["asset_tag"] . "' class='btn btn-sm btn-outline-secondary' onclick='return confirmAction();'>Delete</a><br>
</td>
</tr>";
} else {
echo "</tr>";
}
}
}
} else {
echo "<tr><td colspan='100%'><center>No Data Available</center></td></tr>";
}
?>
</tbody>
</table>
</div>
<input type="button" onclick="printTable()" value="Print Everything"
class="d-print-none btn btn-primary" />
<input type="button" onclick="window.location.href='insert_asset.php'"
class="d-print-none btn btn-primary" value="Add Asset" />
</div>
</div>
</div>
<script>
function printTable() {
var table = document.getElementById("assetsTable");
var newWin = window.open("", "_blank");
var newDoc = newWin.document;
newDoc.open();
newDoc.write(
'<html><head><title>Print</title></head><style>.body{font-family: sans-serif; text-align: left;}</style><body>'
);
newDoc.write(
'<style>@media print{.actions{display:none;} body{font-family:sans-serif;}}</style><h1>Asset List</h1>');
newDoc.write(table.outerHTML);
newDoc.write('</body></html>');
newDoc.close();
newWin.onafterprint = function() {
newWin.close();
};
newWin.print();
}
</script>
</body>
</html>