-
-
Notifications
You must be signed in to change notification settings - Fork 160
/
Copy pathclient_racks.php
350 lines (312 loc) · 21.4 KB
/
client_racks.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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
<?php
// Default Column Sortby Filter
$sort = "rack_name";
$order = "ASC";
require_once "includes/inc_all_client.php";
// Perms
enforceUserPermission('module_support');
// Rebuild URL
$url_query_strings_sort = http_build_query($get_copy);
$sql = mysqli_query(
$mysqli,
"SELECT SQL_CALC_FOUND_ROWS * FROM racks
LEFT JOIN locations ON location_id = rack_location_id
WHERE rack_client_id = $client_id
AND rack_$archive_query
AND (rack_name LIKE '%$q%' OR rack_type LIKE '%$q%' OR rack_units LIKE '%$q%')
ORDER BY $sort $order LIMIT $record_from, $record_to"
);
$num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
?>
<div class="card card-dark">
<div class="card-header py-2">
<h3 class="card-title mt-2"><i class="fas fa-fw fa-server mr-2"></i>Network Racks</h3>
<div class="card-tools">
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#addRackModal">
<i class="fas fa-plus mr-2"></i>New Rack
</button>
</div>
</div>
<div class="card-body">
<form autocomplete="off">
<input type="hidden" name="client_id" value="<?php echo $client_id; ?>">
<input type="hidden" name="archived" value="<?php echo $archived; ?>">
<div class="row">
<div class="col-md-4">
<div class="input-group mb-3 mb-md-0">
<input type="search" class="form-control" name="q" value="<?php if (isset($q)) { echo stripslashes(nullable_htmlentities($q)); } ?>" placeholder="Search Racks">
<div class="input-group-append">
<button class="btn btn-dark"><i class="fa fa-search"></i></button>
</div>
</div>
</div>
<div class="col-md-8">
<div class="float-right">
<a href="?client_id=<?php echo $client_id; ?>&archived=<?php if($archived == 1){ echo 0; } else { echo 1; } ?>"
class="btn btn-<?php if($archived == 1){ echo "primary"; } else { echo "default"; } ?>">
<i class="fa fa-fw fa-archive mr-2"></i>Archived
</a>
</div>
</div>
</div>
</form>
<hr>
<div class="row">
<?php
while ($row = mysqli_fetch_array($sql)) {
$rack_id = intval($row['rack_id']);
$rack_name = nullable_htmlentities($row['rack_name']);
$rack_description = nullable_htmlentities($row['rack_description']);
$rack_model = nullable_htmlentities($row['rack_model']);
$rack_depth = nullable_htmlentities($row['rack_depth']);
$rack_type = nullable_htmlentities($row['rack_type']);
$rack_units = intval($row['rack_units']);
$rack_photo = nullable_htmlentities($row['rack_photo']);
$rack_physical_location = nullable_htmlentities($row['rack_physical_location']);
$rack_notes = nullable_htmlentities($row['rack_notes']);
$rack_location_id = nullable_htmlentities($row['rack_location_id']);
$rack_location_name = nullable_htmlentities($row['location_name']);
$rack_created_at = nullable_htmlentities($row['rack_created_at']);
// Fetch rack units
$unit_sql = mysqli_query($mysqli, "SELECT * FROM rack_units LEFT JOIN assets ON unit_asset_id = asset_id WHERE unit_rack_id = $rack_id ORDER BY unit_start_number ASC");
$rack_units_data = [];
while ($unit_row = mysqli_fetch_assoc($unit_sql)) {
$rack_units_data[] = $unit_row;
}
?>
<div class="col-md-6">
<div class="card card-dark">
<div class="card-header">
<h3 class="card-title"><i class="fas fa-fw fa-server mr-2"></i><?php echo "$rack_name - $rack_units"; ?>U</h3>
<div class="card-tools">
<div class="dropdown dropleft">
<button class="btn btn-tool" type="button" data-toggle="dropdown">
<i class="fas fa-fw fa-ellipsis-v"></i>
</button>
<div class="dropdown-menu">
<a class="dropdown-item text-dark" href="#" data-toggle="modal" data-target="#addRackUnitModal<?php echo $rack_id; ?>">
<i class="fas fa-fw fa-plus text-secondary mr-2"></i>Add Device
</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item text-dark" href="#" data-toggle="modal" data-target="#editRackModal<?php echo $rack_id; ?>">
<i class="fas fa-fw fa-edit text-secondary mr-2"></i>Edit
</a>
<?php if ($session_user_role == 3) { ?>
<div class="dropdown-divider"></div>
<a class="dropdown-item text-danger confirm-link" href="post.php?archive_rack=<?php echo $rack_id; ?>">
<i class="fas fa-fw fa-archive mr-2"></i>Archive
</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item text-danger text-bold confirm-link" href="post.php?delete_rack=<?php echo $rack_id; ?>">
<i class="fas fa-fw fa-trash mr-2"></i>Delete
</a>
<?php } ?>
</div>
</div>
</div>
</div>
<div class="card-body">
<div class="row">
<div class="col-md-6">
<?php if ($rack_photo) { ?>
<img class="img-thumbnail mb-3" alt="rack_photo" src="<?php echo "uploads/clients/$client_id/$rack_photo"; ?>">
<?php } ?>
<table class="table table-sm table-borderless border">
<tbody>
<?php if ($rack_description) { ?>
<tr>
<th colspan="2">Description</th>
</tr>
<tr>
<td colspan="2"><?php echo $rack_description; ?></td>
</tr>
<?php } ?>
<?php if ($rack_type) { ?>
<tr>
<th>Type</th>
<td><?php echo $rack_type; ?></td>
</tr>
<?php } ?>
<?php if ($rack_model) { ?>
<tr>
<th>Model</th>
<td><?php echo $rack_model; ?></td>
</tr>
<?php } ?>
<?php if ($rack_depth) { ?>
<tr>
<th>Depth</th>
<td><?php echo $rack_depth; ?></td>
</tr>
<?php } ?>
<?php if ($rack_location_name) { ?>
<tr>
<th>Location</th>
<td><?php echo $rack_location_name; ?></td>
</tr>
<?php } ?>
<?php if ($rack_physical_location) { ?>
<tr>
<th>Physical Location</th>
<td><?php echo $rack_physical_location; ?></td>
</tr>
<?php } ?>
<?php if ($rack_notes) { ?>
<tr>
<th colspan="2">Notes</th>
</tr>
<tr>
<td><?php echo $rack_notes; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<div class="col-md-6">
<table class="table table-sm border">
<thead class="thead-dark">
<tr>
<th class="text-center px-0">U</th>
<th class="text-center">Device</th>
<th class=""></th>
</tr>
</thead>
<tbody>
<?php
// Keep track of which device_ids we've already printed
$printedDevices = [];
for ($i = $rack_units; $i >= 1; $i--) {
// Find all devices that occupy the current unit $i
$unit_devices = [];
foreach ($rack_units_data as $unit_data) {
$start = (int) $unit_data['unit_start_number'];
$end = (int) $unit_data['unit_end_number'];
// If $i is between start and end, device occupies this unit
if ($i >= $start && $i <= $end) {
$unit_devices[] = [
'unit_id' => (int) $unit_data['unit_id'],
'unit_device' => nullable_htmlentities($unit_data['unit_device']),
'unit_start_number'=> $start,
'unit_end_number' => $end,
'asset_id' => (int) $unit_data['asset_id'],
'asset_name' => nullable_htmlentities($unit_data['asset_name']),
'asset_type' => nullable_htmlentities($unit_data['asset_type']),
'icon' => getAssetIcon($unit_data['asset_type'])
];
}
}
?>
<tr>
<!-- Always print the left-hand U #, for reference -->
<td class="px-0 text-center bg-light border">
<?php echo sprintf('%02d', $i); ?>
</td>
<?php
// If there's exactly one device in this row, attempt to rowSpan it.
// (If you can have multiple overlapping devices, you'll need more logic.)
if (count($unit_devices) === 1) {
$d = $unit_devices[0];
$deviceId = $d['unit_id'];
// If not already printed, this is the *first* row of the device
if (!in_array($deviceId, $printedDevices)) {
// Mark it printed so it won't appear in later rows
$printedDevices[] = $deviceId;
// Calculate how many rows (U's) it spans
$span = $d['unit_end_number'] - $d['unit_start_number'] + 1;
if ($span < 1) {
$span = 1; // safety check
}
// Print the device cell and action cell with rowSpan
?>
<td class="text-center align-middle" rowspan="<?php echo $span; ?>">
<!-- DEVICE INFO HERE -->
<?php
echo $d['unit_device'];
if (!empty($d['asset_name'])) {
$icon = $d['icon']; // already from getAssetIcon
?>
<i class="fa fa-<?php echo $icon; ?>"></i>
<a href="client_asset_details.php?client_id=<?php echo $client_id; ?>&asset_id=<?php echo $d['asset_id']; ?>"
target="_blank">
<?php echo $d['asset_name']; ?>
<i class="fas fa-external-link-alt ml-1"></i>
</a>
<?php
}
?>
</td>
<td class="px-0 text-right align-middle" rowspan="<?php echo $span; ?>">
<!-- ACTION ICON / DROPDOWN -->
<div class="dropdown dropleft">
<button class="btn btn-tool" type="button" data-toggle="dropdown">
<i class="fas fa-fw fa-ellipsis-v"></i>
</button>
<div class="dropdown-menu">
<a class="dropdown-item text-danger text-bold confirm-link"
href="post.php?remove_rack_unit=<?php echo $d['unit_id']; ?>">
<i class="fas fa-fw fa-minus mr-2"></i>Remove
</a>
</div>
</div>
</td>
<?php
} else {
// This device was already spanned from a higher row, so skip printing device cell
// but we still have the left column (U #).
}
} elseif (count($unit_devices) > 1) {
// If your data might have multiple devices in the same row,
// you have to decide how to handle them.
// For now, we can fallback to older logic or display them all in one cell, etc.
?>
<td class="text-center">
<?php foreach ($unit_devices as $d) { ?>
<?php echo $d['unit_device']; ?><br>
<?php // Could also show asset_name, etc. ?>
<?php } ?>
</td>
<td class="text-right">
<div class="dropdown dropleft">
<button class="btn btn-tool" type="button" data-toggle="dropdown">
<i class="fas fa-fw fa-ellipsis-v"></i>
</button>
<div class="dropdown-menu">
<?php foreach ($unit_devices as $d) { ?>
<a class="dropdown-item text-danger text-bold confirm-link"
href="post.php?remove_rack_unit=<?php echo $d['unit_id']; ?>">
<i class="fas fa-fw fa-minus mr-2"></i>Remove
</a>
<?php } ?>
</div>
</div>
</td>
<?php
} else {
// No device in this row
?>
<td class="text-center">No device</td>
<td></td>
<?php
}
?>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<?php require "modals/client_rack_edit_modal.php"; ?>
<?php require "modals/client_rack_unit_add_modal.php"; ?>
<?php } ?>
</div>
</div>
</div>
<?php
require_once "modals/client_rack_add_modal.php";
require_once "includes/footer.php";
?>