diff --git a/api/v1/index.php b/api/v1/index.php index 38e5f1b01..2c984331f 100644 --- a/api/v1/index.php +++ b/api/v1/index.php @@ -337,7 +337,8 @@ function authenticate(\Slim\Route $route) { $app->get( '/cabinet/bydept/:deptid', function($deptid) { $cab = new Cabinet; $dc = new DataCenter(); - $cList = $cab->ListCabinets(intval($deptid)); + $cab->DeptID=$deptid; + $cList = $cab->GetCabinetsByDept(); $response['error'] = false; $response['errorcode'] = 200; @@ -658,4 +659,4 @@ function authenticate(\Slim\Route $route) { }); $app->run(); -?> \ No newline at end of file +?> diff --git a/assets.inc.php b/assets.inc.php index 40e1ebf1f..9724cda66 100644 --- a/assets.inc.php +++ b/assets.inc.php @@ -208,13 +208,15 @@ function GetCabinet(){ } } - static function ListCabinets($deptid=null) { + static function ListCabinets($orderbydc=null){ global $dbh; - + global $config; + $cabinetList=array(); - $dept=(!is_null($deptid))?" WHERE AssignedTo=".intval($deptid):''; - $sql="SELECT * FROM fac_Cabinet$dept ORDER BY DataCenterID, Location ASC, LENGTH(Location);"; + // if AppendCabDC is set then we will be appending the DC to lists so sort them accordingly + $orderbydc=(!is_null($orderby) || $config->ParameterArray['AppendCabDC']=='enabled')?'DataCenterID, ':''; + $sql="SELECT * FROM fac_Cabinet ORDER BY $orderbydc LocationSortable ASC;"; foreach($dbh->query($sql) as $cabinetRow){ $cabinetList[]=Cabinet::RowToObject($cabinetRow); @@ -228,19 +230,45 @@ function ListCabinetsByDC($limit=false,$limitzone=false){ $this->MakeSafe(); - $hascoords=($limit)?'AND MapX1!=MapX2 AND MapY1!=MapY2':''; - $limitzone=($limitzone && $this->ZoneID>0)?" AND ZoneID=$this->ZoneID":''; + $cabinetList=$this->ListCabinets(true); + foreach($cabinetList as $i => $cab){ + if( + ($cab->DataCenterID!=$this->DataCenterID) && + ($limitzone && $this->ZoneID>0 && $cab->ZoneID!=$this->ZoneID) && + ($limit && $cab->MapX1!=$cab->MapX2 && $cab->MapY1!=$cab->MapY2) + ) + {unset($cabinetList[$i]);} + } - $sql="SELECT * FROM fac_Cabinet WHERE DataCenterID=$this->DataCenterID $hascoords$limitzone ORDER BY Location ASC, LENGTH(Location);"; + return $cabinetList; + } - $cabinetList=array(); - foreach($dbh->query($sql) as $cabinetRow){ - $cabinetList[]=Cabinet::RowToObject($cabinetRow); + function GetCabinetsByDept(){ + global $dbh; + + $this->MakeSafe(); + + $cabinetList=$this->ListCabinets(); + foreach($cabinetList as $i => $cab){ + if($cab->DeptID!=$this->DeptID){unset($cabinetList[$i]);} } return $cabinetList; } + function GetCabinetsByZone(){ + global $dbh; + + $this->MakeSafe(); + + $cabinetList=$this->ListCabinets(); + foreach($cabinetList as $i => $cab){ + if($cab->ZoneID!=$this->ZoneID){unset($cabinetList[$i]);} + } + + return $cabinetList; + } + function CabinetOccupancy($CabinetID){ global $dbh; @@ -361,7 +389,7 @@ function GetCabinetsByRow($rear=false){ // Order first by row layout then by natural sort $sql="SELECT * FROM fac_Cabinet WHERE CabRowID=$cabrow->CabRowID ORDER BY $order - Location ASC, LENGTH(Location);"; + LocationSortable ASC;"; $cabinetList=array(); foreach($dbh->query($sql) as $cabinetRow){ @@ -375,20 +403,6 @@ function GetCabinetsByRow($rear=false){ return $cabinetList; } - function GetCabinetsByZone(){ - global $dbh; - - $this->MakeSafe(); - - $sql="SELECT * FROM fac_Cabinet WHERE ZoneID=$this->ZoneID;"; - - $cabinetList=array(); - foreach($dbh->query($sql) as $cabinetRow){ - $cabinetList[]=Cabinet::RowToObject($cabinetRow); - } - return $cabinetList; - } - function GetCabRowSelectList(){ global $dbh; @@ -434,9 +448,9 @@ function BuildCabinetTree(){ global $dbh; $dc=new DataCenter(); - $dept=new Department(); - + $deptList=Department::GetDepartmentListIndexedbyID(); $dcList=$dc->GetDCList(); + $cabList=Cabinet::ListCabinets(true); if(count($dcList) >0){ $tree="