Skip to content

Commit

Permalink
Dynamic generation of floor plan, cabinets have width, depth, offset …
Browse files Browse the repository at this point in the history
…and direction entries
  • Loading branch information
chrisb123 committed May 15, 2012
1 parent 4f4cf5a commit 2716938
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 76 deletions.
33 changes: 32 additions & 1 deletion assets.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ class Cabinet {
var $MapY1;
var $MapX2;
var $MapY2;
var $MapXY;
var $depth;
var $width;
var $offset;
var $direction;

function CreateCabinet( $db ) {
$insert_sql = "insert into fac_Cabinet set DataCenterID=\"" . intval($this->DataCenterID) . "\", Location=\"" . addslashes($this->Location) . "\", AssignedTo=\"" . intval($this->AssignedTo) . "\", ZoneID=\"" . intval($this->ZoneID) . "\", CabinetHeight=\"" . intval($this->CabinetHeight) . "\", Model=\"" . addslashes($this->Model) . "\", MaxKW=\"" . floatval($this->MaxKW) . "\", MaxWeight=\"" . intval( $this->MaxWeight ). "\", InstallationDate=\"" . date( "Y-m-d", strtotime( $this->InstallationDate ) ) . "\", MapX1=\"" . intval($this->MapX1) . "\", MapY1=\"" . intval($this->MapY1) . "\", MapX2=\"" . intval($this->MapX2) . "\", MapY2=\"" . intval($this->MapY2) . "\"";
Expand All @@ -60,7 +65,25 @@ function CreateCabinet( $db ) {
}

function UpdateCabinet( $db ) {
$update_sql = "update fac_Cabinet set DataCenterID=\"" . intval($this->DataCenterID) . "\", Location=\"" . addslashes($this->Location) . "\", AssignedTo=\"" . intval($this->AssignedTo) . "\", ZoneID=\"" . intval($this->ZoneID) . "\", CabinetHeight=\"" . intval($this->CabinetHeight) . "\", Model=\"" . addslashes($this->Model) . "\", MaxKW=\"" . floatval($this->MaxKW) . "\", MaxWeight=\"" . intval( $this->MaxWeight ) . "\", InstallationDate=\"" . date( "Y-m-d", strtotime( $this->InstallationDate ) ) . "\", MapX1=\"" . intval($this->MapX1) . "\", MapY1=\"" . intval($this->MapY1) . "\", MapX2=\"" . intval($this->MapX2) . "\", MapY2=\"" . intval($this->MapY2) . "\" where CabinetID=\"" . intval($this->CabinetID) . "\"";
$update_sql = "update fac_Cabinet set DataCenterID=\"" . intval($this->DataCenterID) . "\",
Location=\"" . addslashes($this->Location) . "\",
AssignedTo=\"" . intval($this->AssignedTo) . "\",
ZoneID=\"" . intval($this->ZoneID) . "\",
CabinetHeight=\"" . intval($this->CabinetHeight) . "\",
Model=\"" . addslashes($this->Model) . "\",
MaxKW=\"" . floatval($this->MaxKW) . "\",
MaxWeight=\"" . intval( $this->MaxWeight ) . "\",
InstallationDate=\"" . date( "Y-m-d", strtotime( $this->InstallationDate ) ) . "\",
MapX1=\"" . intval($this->MapX1) . "\",
MapY1=\"" . intval($this->MapY1) . "\",
MapX2=\"" . intval($this->MapX2) . "\",
MapY2=\"" . intval($this->MapY2) . "\",
MapXY=\"" . intval($this->MapXY) . "\",
width=\"" . intval($this->width) . "\",
depth=\"" . intval($this->depth) . "\",
offset=\"" . intval($this->offset) . "\",
direction=\"" . addslashes($this->direction) . "\"
where CabinetID=\"" . intval($this->CabinetID) . "\"";

if ( ! $result = mysql_query( $update_sql, $db ) ) {
return -1;
Expand Down Expand Up @@ -107,6 +130,11 @@ function GetCabinet( $db ) {
$this->MapY1 = $cabinetRow["MapY1"];
$this->MapX2 = $cabinetRow["MapX2"];
$this->MapY2 = $cabinetRow["MapY2"];
$this->MapXY = $cabinetRow["MapXY"];
$this->width = $cabinetRow["width"];
$this->depth = $cabinetRow["depth"];
$this->offset = $cabinetRow["offset"];
$this->direction = $cabinetRow["direction"];

return 0;
}
Expand Down Expand Up @@ -138,6 +166,9 @@ function ListCabinets( $db ) {
$cabinetList[ $cabID ]->MapY1 = $cabinetRow[ "MapY1" ];
$cabinetList[ $cabID ]->MapX2 = $cabinetRow[ "MapX2" ];
$cabinetList[ $cabID ]->MapY2 = $cabinetRow[ "MapY2" ];
$cabinetList[ $cabID ]->MapXY = $cabinetRow[ "MapXY" ];
$cabinetList[ $cabID ]->depth = $cabinetRow[ "depth" ];
$cabinetList[ $cabID ]->direction = $cabinetRow[ "direction" ];
}

return $cabinetList;
Expand Down
58 changes: 52 additions & 6 deletions cabinets.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
$dc=new DataCenter();
$dc->DataCenterID=$_REQUEST['datacenterid'];
$dc->GetDataCenter($facDB);
var_dump($dc);

if(isset($_REQUEST['cabinetid'])){
$cab->CabinetID=$_REQUEST['cabinetid'];
Expand All @@ -34,6 +33,10 @@
$cab->MaxKW=$_REQUEST['maxkw'];
$cab->MaxWeight=$_REQUEST['maxweight'];
$cab->InstallationDate=$_REQUEST['installationdate'];
$cab->width=$_REQUEST['width'];
$cab->depth=$_REQUEST['depth'];
$cab->offset=$_REQUEST['offset'];
$cab->direction=$_REQUEST['direction'];

$rows = $dc->rows; #number of rows
$cols = $dc->cols; #number of cols
Expand All @@ -58,22 +61,41 @@
}
$refx = $xgrid; #grid ref x
$refy = $ygrid; #grid ref y
$width = 600; #in mm
$depth = 900; #in mm
$offset = 0; #for offset racks
$width = $cab->width; #in mm
$depth = $cab->depth; #in mm
$offset = $cab->offset; #for offset racks
$mmpd = 600; #mm per tile
$dir = 'N'; #direction of rack;
$dir = $cab->direction; #direction of rack;
if ($dir == 'N') {
$x1 = ($refx+1)*$div-$offset/$mmpd*$div;
$y1 = ($refy+0)*$div;
$x2 = $x1-($width/$mmpd*$div);
$y2 = $y1+($depth/$mmpd*$div);
$y3 = $y1+($depth*.2/$mmpd*$div);}
$xy = $y1+($depth*.2/$mmpd*$div);}
if ($dir == 'S') {
$x1 = ($refx+0)*$div+$offset/$mmpd*$div;
$y1 = ($refy+1)*$div;
$x2 = $x1+($width/$mmpd*$div);
$y2 = $y1-($depth/$mmpd*$div);
$xy = $y1-($depth*.2/$mmpd*$div);}
if ($dir == 'E') {
$x1 = ($refx+1)*$div;
$y1 = ($refy+0)*$div-$offset/$mmpd*$div;
$y2 = $y1+($width/$mmpd*$div);
$x2 = $x1-($depth/$mmpd*$div);
$xy = $x1-($depth*.2/$mmpd*$div);}
if ($dir == 'W') {
$x1 = ($refx+0)*$div;
$y1 = ($refy+0)*$div+$offset/$mmpd*$div;
$y2 = $y1+($width/$mmpd*$div);
$x2 = $x1+($depth/$mmpd*$div);
$xy = $x1+($depth*.2/$mmpd*$div);}

$cab->MapX1=$x1;
$cab->MapX2=$x2;
$cab->MapY1=$y1;
$cab->MapY2=$y2;
$cab->MapXY=$xy;
$cab->UpdateCabinet($facDB);
}elseif($_REQUEST['action']=='Create'){
$cab->DataCenterID=$_REQUEST['datacenterid'];
Expand All @@ -84,6 +106,10 @@
$cab->MaxKW=$_REQUEST['maxkw'];
$cab->MaxWeight=$_REQUEST['maxweight'];
$cab->InstallationDate=$_REQUEST['installationdate'];
$cab->width=$_REQUEST['width'];
$cab->depth=$_REQUEST['depth'];
$cab->offset=$_REQUEST['offset'];
$cab->direction=$_REQUEST['direction'];
$cab->CreateCabinet($facDB);
}
}
Expand All @@ -99,6 +125,10 @@
$cab->MaxKW=null;
$cab->MaxWeight=null;
$cab->InstallationDate=date('m/d/Y');
$cab->width=600;
$cab->depth=900;
$cab->offset=0;
$cab->direction="N";
}

$deptList=$dept->GetDepartmentList($facDB);
Expand Down Expand Up @@ -185,6 +215,22 @@
<div>Date of Installation</div>
<div><input type='text' name='installationdate' size='15' value='<?php echo date('m/d/Y', strtotime($cab->InstallationDate)); ?>'></div>
</div>
<div>
<div>Width</div>
<div><input type='text' name='width' size='15' value='<?php echo $cab->width; ?>'></div>
</div>
<div>
<div>Depth</div>
<div><input type='text' name='depth' size='15' value='<?php echo $cab->depth; ?>'></div>
</div>
<div>
<div>Offset</div>
<div><input type='text' name='offset' size='15' value='<?php echo $cab->offset; ?>'></div>
</div>
<div>
<div>Direction</div>
<div><input type='text' name='direction' size='15' value='<?php echo $cab->direction; ?>'></div>
</div>
<?php
if($user->WriteAccess){
echo '<div class=\'caption\'>';
Expand Down
86 changes: 17 additions & 69 deletions dc_stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,78 +190,22 @@ function uselessie(){
$cabloc[][] = "";
$cabnum = 0;
foreach($cabList as $cab) {
$len = strlen($cab->Location);
if ($len == 4) {
$yref = substr($cab->Location,0,2);
} else {
$yref = substr($location,0,1);
}
$xref = substr($cab->Location, -2);
$xgrid = $xref - $start_col + 1;

$ygrid = 1;
$i = $start_row;
while($i != $yref) {
$i++;
$ygrid++;
}
$dir = $cab->direction;

$refx = $xgrid; #grid ref x
$refy = $ygrid; #grid ref y
$width = 600; #in mm
$depth = 900; #in mm
$offset = 0; #for offset racks
#$width = 600; #in mm
$depth = $cab->depth; #in mm
#$offset = 0; #for offset racks
$mmpd = 600; #mm per tile
$dir = 'N'; #direction of rack;
if ($dir == 'N') {
$x1 = ($refx+1)*$div-$offset/$mmpd*$div;
$y1 = ($refy+0)*$div;
$x2 = $x1-($width/$mmpd*$div);
$y2 = $y1+($depth/$mmpd*$div);
$y3 = $y1+($depth*.2/$mmpd*$div);}
if ($dir == 'S') {
$x1 = ($refx+0)*$div+$offset/$mmpd*$div;
$y1 = ($refy+1)*$div;
$x2 = $x1+($width/$mmpd*$div);
$y2 = $y1-($depth/$mmpd*$div);
$y3 = $y1-($depth*.2/$mmpd*$div);}
if ($dir == 'E') {
$x1 = ($refx+1)*$div;
$y1 = ($refy+0)*$div-$offset/$mmpd*$div;
$y2 = $y1+($width/$mmpd*$div);
$x2 = $x1-($depth/$mmpd*$div);
$x3 = $x1-($depth*.2/$mmpd*$div);}
if ($dir == 'W') {
$x1 = ($refx+0)*$div;
$y1 = ($refy+0)*$div+$offset/$mmpd*$div;
$y2 = $y1+($width/$mmpd*$div);
$x2 = $x1+($depth/$mmpd*$div);
$x3 = $x1+($depth*.2/$mmpd*$div);}
imagefilledrectangle($img, $MapX1, $MapY1, $MapX2, $MapY2, $lightgrey);
$cabloc[$cabnum][x1] = $x1;
$cabloc[$cabnum][y1] = $y1;
$cabloc[$cabnum][x2] = $x2;
$cabloc[$cabnum][y2] = $y2;
$cabloc[$cabnum][CabinetID] = $cab->CabinetID;
$cabloc[$cabnum][Location] = $cab->Location;
$cabnum++;
#$cur_row = $start_row;
#$jt = $i;
#while ( $jt > 1) {
#$jt--;
#$cur_row++;
#}
#$cur_col = $start_col + $j - 1;
#if ($cur_col < 10) { $cur_col = "0" . $cur_col;}
$rn = ($yref ) . ($xref);
if ($dir == 'N') {imagefttext($img, $div*.5, 90, $x1-$div*.2, $y1+$depth/$mmpd*$div, $red, $font, $rn);}
if ($dir == 'S') {imagefttext($img, $div*.5, -90, $x1+$div*.2, $y1-$depth/$mmpd*$div, $red, $font, $rn);}
if ($dir == 'E') {imagefttext($img, $div*.5, 0, $x1-$depth/$mmpd*$div*.95, $y1+$div*.8, $red, $font, $rn);}
if ($dir == 'W') {imagefttext($img, $div*.5, 0, $x1+$div*.4, $y1+$div*.8, $red, $font, $rn);}
$rn = $cab->Location;
if ($dir == 'N') {imagefttext($img, $div*.5, 90, $cab->MapX1-$div*.2, $cab->MapY1+$depth/$mmpd*$div, $red, $font, $rn);}
if ($dir == 'S') {imagefttext($img, $div*.5, -90, $cab->MapX1+$div*.2, $cab->MapY1-$depth/$mmpd*$div, $red, $font, $rn);}
if ($dir == 'E') {imagefttext($img, $div*.5, 0, $cab->MapX1-$depth/$mmpd*$div*.95, $cab->MapY1+$div*.8, $red, $font, $rn);}
if ($dir == 'W') {imagefttext($img, $div*.5, 0, $cab->MapX1+$div*.4, $cab->MapY1+$div*.8, $red, $font, $rn);}
if ($dir == 'N' or $dir == 'S' ) {
imagefilledrectangle($img, $x1, $y1, $x2, $y3, $green);
imagefilledrectangle($img, $cab->MapX1, $cab->MapY1, $cab->MapX2, $cab->MapXY, $green);
} else {
imagefilledrectangle($img, $x1, $y1, $x3, $y2, $green);
imagefilledrectangle($img, $cab->MapX1, $cab->MapY1, $cab->MapXY, $cab->MapY2, $green);
}
}

Expand All @@ -284,8 +228,12 @@ function uselessie(){

#while ( $cabRow = mysql_fetch_array( $result ) ) {
#$mapHTML.="<area href=\"cabnavigator.php?cabinetid=" . $cabRow["CabinetID"] . "\" shape=\"rect\" coords=\"" . $cabRow["MapX1"] . ", " . $cabRow["MapY1"] . ", " . $cabRow["MapX2"] . ", " . $cabRow["MapY2"] . "\" alt=\"".$cabRow["Location"]."\" title=\"".$cabRow["Location"]."\">\n";
foreach ( $cabloc as $cabRow ) {
$mapHTML.="<area href=\"cabnavigator.php?cabinetid=" . $cabRow["CabinetID"] . "\" shape=\"rect\" coords=\"" . $cabRow["x1"] . ", " . $cabRow["y1"] . ", " . $cabRow["x2"] . ", " . $cabRow["y2"] . "\" alt=\"".$cabRow["Location"]."\" title=\"".$cabRow["Location"]."\">\n";
#foreach ( $cabloc as $cabRow ) {
foreach($cabList as $cabRow) {
$mapHTML.="<area href=\"cabnavigator.php?cabinetid=" . $cabRow->CabinetID . "\" shape=\"rect\" coords=\"" .
$cabRow->MapX1 . ", " . $cabRow->MapY1 . ", " .
$cabRow->MapX2 . ", " . $cabRow->MapY2 . "\"
alt=\"".$cabRow->Location."\" title=\"".$cabRow->Location."\">\n";
}

$mapHTML.="</map>\n";
Expand Down

0 comments on commit 2716938

Please sign in to comment.