forked from opendcim/openDCIM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ajax_cabinetuse.php
70 lines (65 loc) · 1.99 KB
/
ajax_cabinetuse.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
<?php
require_once( "../db.inc.php" );
require_once( "../facilities.inc.php" );
$cabinetuse=array();
// if user has read rights then return a search if not return blank
$cab=new Cabinet();
$dev=new Device();
if(isset($_GET["DeviceID"])){
$dev->DeviceID=$_GET["DeviceID"];
}
$cab->CabinetID=$dev->Cabinet=intval($_GET['cabinet']);
$devList=$dev->ViewDevicesByCabinet();
$cab->GetCabinet();
$dev->BackSide=(isset($_GET['backside']))?($_GET['backside']=='true'?true:false):false;
$dev->HalfDepth=(isset($_GET['halfdepth']))?($_GET['halfdepth']=='true'?true:false):false;
if (!$dev->BackSide){
// Build array of each position used
foreach($devList as $key => $device) {
// Only count space occupied by devices other than the current one
if ( $dev->DeviceID != $device->DeviceID && (!$device->BackSide || !$device->HalfDepth || !$dev->HalfDepth)) {
if($device->Height > 0){
$i=$device->Height;
while($i>0){
$i--;
if(!$device->HalfDepth){
$cabinetuse[$device->Position+$i]=true;
} else {
$cabinetuse[$device->Position+$i]=(!$device->BackSide || !$dev->HalfDepth);
}
}
}
}
}
} else {
// Build array of each position used
foreach($devList as $key => $device) {
// Only count space occupied by devices other than the current one
if ( $dev->DeviceID != $device->DeviceID && ($device->BackSide || !$device->HalfDepth || !$dev->HalfDepth)) {
if($device->Height > 0){
$i=$device->Height;
while($i>0){
$i--;
if(!$device->HalfDepth){
$cabinetuse[$device->Position+$i]=true;
} else {
$cabinetuse[$device->Position+$i]=($device->BackSide || !$dev->HalfDepth);
}
}
}
}
}
}
$i=$cab->CabinetHeight;
// Fill in unused rack positions for true/false checks
while($i>0){
if(!isset($cabinetuse[$i])){
$cabinetuse[$i]=false;
}
$i--;
}
// Reverse sort by rack position
krsort($cabinetuse);
header('Content-Type: application/json');
echo json_encode($cabinetuse);
?>