forked from opendcim/openDCIM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinfrastructure.inc.php
2824 lines (2373 loc) · 94 KB
/
infrastructure.inc.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
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
openDCIM
This is the main class library for the openDCIM application, which
is a PHP/Web based data center infrastructure management system.
This application was originally written by Scott A. Milliken while
employed at Vanderbilt University in Nashville, TN, as the
Data Center Manager, and released under the GNU GPL.
Copyright (C) 2011 Scott A. Milliken
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
by the Free Software Foundation, version 3.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
For further details on the license, see http://www.gnu.org/licenses
Classes Defined Here:
DataCenter: A logical/physical container for assets. This may be a room, or
even just a portion of a room. It does need to be a contiguous
space for mapping purposes. Large data centers may want to break
up the space into quadrants for easier management, but it can
easily be handled as a whole (in terms of the software and database).
Any mappings for larger than approximately 2500 SF become difficult
to see on a laptop screen, because each cabinet takes up such a small
portion of the overall map.
DeviceTemplate: A template with default values for height, wattage, and weight.
Height and wattage values can be overridden at the device level.
Templates are completely optional, but are a very good way to
manage the power capacity of the data center.
Manufacturer: Used only in DeviceTemplate, so if you choose not to utilize
templates, there is no need to enter Manufacturers.
Zone: A logical grouping of DataCenter components, so that if a large data
center has been broken down into smaller components, it can be
reported on as a single entity. For example, Building A may have
data centers in Room 100, Room 109, and Room 205. All three can
be placed in a single zone for reporting on Building A data center
metrics.
NOT YET IMPLEMENTED
*/
class BinAudits {
var $BinID;
var $UserID;
var $AuditStamp;
function MakeSafe(){
$this->BinID=intval($this->BinID);
$this->UserID=addslashes(trim($this->UserID));
$this->AuditStamp=addslashes(trim($this->AuditStamp));
}
function MakeDisplay(){
$this->UserID=stripslashes($this->UserID);
$this->AuditStamp=stripslashes($this->AuditStamp);
}
function exec($sql){
global $dbh;
return $dbh->exec($sql);
}
function AddAudit(){
$this->AuditStamp=date("Y-m-d",strtotime($this->AuditStamp));
$this->MakeSafe();
$sql="INSERT INTO fac_BinAudits SET BinID=$this->BinID, UserID=\"$this->UserID\", AuditStamp=\"$this->AuditStamp\";";
$this->exec($sql);
}
}
class BinContents {
var $BinID;
var $SupplyID;
var $Count;
function MakeSafe(){
$this->BinID=intval($this->BinID);
$this->SupplyID=intval($this->SupplyID);
$this->Count=intval($this->Count);
}
static function RowToObject($row){
$bin=new BinContents();
$bin->BinID=$row["BinID"];
$bin->SupplyID=$row["SupplyID"];
$bin->Count=$row["Count"];
return $bin;
}
function query($sql){
global $dbh;
return $dbh->query($sql);
}
function exec($sql){
global $dbh;
return $dbh->exec($sql);
}
function AddContents(){
$sql="INSERT INTO fac_BinContents SET BinID=$this->BinID, SupplyID=$this->SupplyID, Count=$this->Count;";
return $this->exec($sql);
}
function GetBinContents(){
$this->MakeSafe();
/* Return all of the supplies found in this bin */
$sql="SELECT * FROM fac_BinContents WHERE BinID=$this->BinID;";
$binList=array();
foreach($this->query($sql) as $row){
$binList[]=BinContents::RowToObject($row);
}
return $binList;
}
function FindSupplies(){
$this->MakeSafe();
/* Return all of the bins where this SupplyID is found */
$sql="SELECT a.* FROM fac_BinContents a, fac_SupplyBin b WHERE
a.SupplyID=$this->SupplyID AND a.BinID=b.BinID ORDER BY b.Location ASC;";
$binList=array();
foreach($this->query($sql) as $row){
$binList[]=BinContents::RowToObject($row);
}
return $binList;
}
function UpdateCount(){
$this->MakeSafe();
$sql="UPDATE fac_BinContents SET Count=$this->Count WHERE BinID=$this->BinID
AND SupplyID=$this->SupplyID;";
return $this->query($sql);
}
function RemoveContents(){
$this->MakeSafe();
$sql="DELETE FROM fac_BinContents WHERE BinID=$this->BinID AND
SupplyID=$this->SupplyID;";
return $this->exec($sql);
}
function EmptyBin(){
$this->MakeSafe();
$sql="DELETE FROM fac_BinContents WHERE BinID=$this->BinID;";
return $this->exec($sql);
}
}
class DataCenter {
var $DataCenterID;
var $Name;
var $SquareFootage;
var $DeliveryAddress;
var $Administrator;
var $MaxkW;
var $DrawingFileName;
var $EntryLogging;
var $dcconfig;
var $ContainerID;
var $MapX;
var $MapY;
function MakeSafe(){
$this->DataCenterID=intval($this->DataCenterID);
$this->Name=addslashes(trim($this->Name));
$this->SquareFootage=intval($this->SquareFootage);
$this->DeliveryAddress=addslashes(trim($this->DeliveryAddress));
$this->Administrator=addslashes(trim($this->Administrator));
$this->MaxkW=intval($this->MaxkW);
$this->DrawingFileName=addslashes(trim($this->DrawingFileName));
$this->EntryLogging=intval($this->EntryLogging);
$this->ContainerID=intval($this->ContainerID);
$this->MapX=abs($this->MapX);
$this->MapY=abs($this->MapY);
}
function MakeDisplay(){
$this->Name=stripslashes($this->Name);
$this->DeliveryAddress=stripslashes($this->DeliveryAddress);
$this->Administrator=stripslashes($this->Administrator);
$this->DrawingFileName=stripslashes($this->DrawingFileName);
}
static function RowToObject($row){
$dc=New DataCenter();
$dc->DataCenterID=$row["DataCenterID"];
$dc->Name=$row["Name"];
$dc->SquareFootage=$row["SquareFootage"];
$dc->DeliveryAddress=$row["DeliveryAddress"];
$dc->Administrator=$row["Administrator"];
$dc->MaxkW=$row["MaxkW"];
$dc->DrawingFileName=$row["DrawingFileName"];
$dc->EntryLogging=$row["EntryLogging"];
$dc->ContainerID=$row["ContainerID"];
$dc->MapX=$row["MapX"];
$dc->MapY=$row["MapY"];
$dc->MakeDisplay();
return $dc;
}
function query($sql){
global $dbh;
return $dbh->query($sql);
}
function exec($sql){
global $dbh;
return $dbh->exec($sql);
}
function CreateDataCenter(){
$this->MakeSafe();
$sql="INSERT INTO fac_DataCenter SET Name=\"$this->Name\",
SquareFootage=$this->SquareFootage, DeliveryAddress=\"$this->DeliveryAddress\",
Administrator=\"$this->Administrator\", MaxkW=$this->MaxkW,
DrawingFileName=\"$this->DrawingFileName\", EntryLogging=0,
ContainerID=$this->ContainerID, MapX=$this->MapX, MapY=$this->MapY;";
return $this->exec($sql);
}
function UpdateDataCenter(){
$this->MakeSafe();
$sql="UPDATE fac_DataCenter SET Name=\"$this->Name\",
SquareFootage=$this->SquareFootage, DeliveryAddress=\"$this->DeliveryAddress\",
Administrator=\"$this->Administrator\", MaxkW=$this->MaxkW,
DrawingFileName=\"$this->DrawingFileName\", EntryLogging=0,
ContainerID=$this->ContainerID, MapX=$this->MapX, MapY=$this->MapY WHERE
DataCenterID=$this->DataCenterID;";
$this->MakeDisplay();
return $this->query($sql);
}
function GetDataCenter(){
$this->MakeSafe();
$sql="SELECT * FROM fac_DataCenter WHERE DataCenterID=$this->DataCenterID;";
if($row=$this->query($sql)->fetch()){
foreach(DataCenter::RowToObject($row) as $prop => $value){
$this->$prop=$value;
}
return true;
}else{
return false;
}
}
function GetDCList(){
$sql="SELECT * FROM fac_DataCenter ORDER BY Name ASC;";
$datacenterList=array();
foreach($this->query($sql) as $row){
$datacenterList[]=DataCenter::RowToObject($row);
}
return $datacenterList;
}
function GetDataCenterbyID(){
// Not sure why this was duplicated but this will do til we clear up the references
return $this->GetDataCenter();
}
/**
* Returns an array with all the hierarchy of containers the data center
* belongs to.
* @param type $containerList
* @return type
*/
public function getContainerList($containerID = 0)
{
$container = new Container();
if ($containerID == 0) {
$container->ContainerID = $this->ContainerID;
} else {
$container->ContainerID = $containerID;
}
$container->GetContainer();
$containerList[] = $container->Name;
if ($container->ParentID > 0) {
$childContainerList = $this->getContainerList($container->ParentID);
$containerList = array_merge($childContainerList, $containerList);
}
return $containerList;
}
function MakeImageMap($nolinks=null) {
$this->MakeSafe();
$mapHTML="";
if(strlen($this->DrawingFileName)>0){
$mapfile="drawings".DIRECTORY_SEPARATOR.$this->DrawingFileName;
if(file_exists($mapfile)){
list($width, $height, $type, $attr)=getimagesize($mapfile);
$mapHTML.="<div class=\"canvas\" style=\"background-image: url('drawings/$this->DrawingFileName')\">\n";
$mapHTML.="<img src=\"css/blank.gif\" usemap=\"#datacenter\" width=\"$width\" height=\"$height\" alt=\"clearmap over canvas\">\n";
$mapHTML.="<map name=\"datacenter\">\n";
if(is_null($nolinks)){
$sql="SELECT * FROM fac_Cabinet WHERE DataCenterID=$this->DataCenterID;";
if($racks=$this->query($sql)){
foreach($racks as $row){
$mapHTML.="<area name=\"cab\" href=\"cabnavigator.php?cabinetid={$row["CabinetID"]}\" shape=\"rect\"";
$mapHTML.=" coords=\"{$row["MapX1"]},{$row["MapY1"]},{$row["MapX2"]},{$row["MapY2"]}\"";
$mapHTML.=" alt=\"{$row["Location"]}\" data-zone=\"zone{$row["ZoneID"]}\">\n";
}
}
$sql="SELECT * FROM fac_Zone WHERE DataCenterID=$this->DataCenterID;";
if($zones=$this->query($sql)){
foreach($zones as $row){
$mapHTML.="<area name=\"zone{$row["ZoneID"]}\" href=\"zone_stats.php?zone={$row["ZoneID"]}\" shape=\"rect\"";
$mapHTML.=" coords=\"{$row["MapX1"]},{$row["MapY1"]},{$row["MapX2"]},{$row["MapY2"]}\"";
$mapHTML.=" alt=\"{$row["Description"]}\" title=\"{$row["Description"]}\">\n";
}
}
// What is this for?
$mapHTML.="<area name=\"dc\" shape=\"rect\"";
$mapHTML.=" coords=\"0,0,{$width},{$height}\"";
$mapHTML.=" alt=\"{$this->Name}\" title=\"{$this->Name}\">\n";
}
$mapHTML.="</map>\n";
$mapHTML.="<canvas id=\"mapCanvas\" width=\"$width\" height=\"$height\"></canvas>\n";
$mapHTML .= "<br><br><br><br><br><br><br><br></div>\n";
}
}
return $mapHTML;
}
function MakeZoneJS(){
$this->MakeSafe();
$js='';
if(strlen($this->DrawingFileName)>0){
$sql="SELECT * FROM fac_Zone WHERE DataCenterID=$this->DataCenterID;";
if($zones=$this->query($sql)){
foreach($zones as $row){
$zone=Zone::RowToObject($row);
if($zone->MapX1==0 && $zone->MapX2==0 && $zone->MapY1==0 && $zone->MapY2==0){
// zone exists but has no shape, ignore it.
}else{
if(strlen($js)>0){
//Already have an initial if so add an else if
$else="\t\t\t}else ";
}else{
$else="";
}
$js.=$else."if((e.pageX>(cpos.left+$zone->MapX1) && e.pageX<(cpos.left+$zone->MapX2)) && (e.pageY>(cpos.top+$zone->MapY1) && e.pageY<(cpos.top+$zone->MapY2))){
if(!redraw){
$('#maptitle .nav select').trigger('change');
HilightZone('zone$zone->ZoneID');
redraw=true;
}\n";
}
}
if(strlen($js)>0){
// add the first and last bits needs to make the loops function
$hilight="\n
function HilightZone(area){
context.globalCompositeOperation='source-over';
//there has to be a better way to do this. stupid js
area=$('area[name='+area+']').prop('coords').split(',');
context.save();
context.lineWidth='4';
context.strokeStyle='red';
context.strokeRect(area[0],area[1],(area[2]-area[0]),(area[3]-area[1]));
context.restore();
}\n";
$js="$hilight
var redraw=false;
var cpos=$('#mapCanvas').offset();
$('.canvas').mousemove(function(e){
$js\t\t\t}else if(redraw){
$('#maptitle .nav select').trigger('change');
redraw=false;
}
});\n";
}
}
}
return $js;
}
function DrawCanvas(){
$this->MakeSafe();
$script="";
// check to see if map was set
if(strlen($this->DrawingFileName)){
$mapfile="drawings".DIRECTORY_SEPARATOR.$this->DrawingFileName;
// map was set in config check to ensure a file exists before we attempt to use it
if(file_exists($mapfile)){
$this->dcconfig=new Config();
$dev=new Device();
$templ=new DeviceTemplate();
$cab=new Cabinet();
// get all color codes and limits for use with loop below
$CriticalColor=html2rgb($this->dcconfig->ParameterArray["CriticalColor"]);
$CautionColor=html2rgb($this->dcconfig->ParameterArray["CautionColor"]);
$GoodColor=html2rgb($this->dcconfig->ParameterArray["GoodColor"]);
$SpaceRed=intval($this->dcconfig->ParameterArray["SpaceRed"]);
$SpaceYellow=intval($this->dcconfig->ParameterArray["SpaceYellow"]);
$WeightRed=intval($this->dcconfig->ParameterArray["WeightRed"]);
$WeightYellow=intval($this->dcconfig->ParameterArray["WeightYellow"]);
$PowerRed=intval($this->dcconfig->ParameterArray["PowerRed"]);
$PowerYellow=intval($this->dcconfig->ParameterArray["PowerYellow"]);
// Temperature
$unknounColor=html2rgb('FFFFFF');
//$TemperatureGreen=20;
$TemperatureYellow=intval($this->dcconfig->ParameterArray["TemperatureYellow"]);
$TemperatureRed=intval($this->dcconfig->ParameterArray["TemperatureRed"]);
// Humidity
$HumidityMin=intval($this->dcconfig->ParameterArray["HumidityRedLow"]);
$HumidityMedMin=intval($this->dcconfig->ParameterArray["HumidityYellowLow"]);
$HumidityMedMax=intval($this->dcconfig->ParameterArray["HumidityYellowHigh"]);
$HumidityMax=intval($this->dcconfig->ParameterArray["HumidityRedHigh"]);
//Real Power
$RealPowerRed=intval($this->dcconfig->ParameterArray["PowerRed"]);
$RealPowerYellow=intval($this->dcconfig->ParameterArray["PowerYellow"]);
// get image file attributes and type
list($width, $height, $type, $attr)=getimagesize($mapfile);
$script.="\n\t\tvar maptitle=$('#maptitle span');
var mycanvas=document.getElementById(\"mapCanvas\");
var context=mycanvas.getContext('2d');
context.globalCompositeOperation='destination-over';
context.save();
function clearcanvas(){
// erase anything on the canvas
context.clearRect(0,0, mycanvas.width, mycanvas.height);
// create a new image for the canvas
var img=new Image();
// draw after the image has loaded
img.onload=function(){
// changed to eliminate the flickering of reloading the background image on a redraw
//context.drawImage(img,0,0);
airflow();
}
// give it an image to load
img.src=\"$mapfile\";
}
function loadCanvas(){\n\t\t\tclearcanvas();\n";
$space="\t\tfunction space(){\n\t\t\tclearcanvas();\n";
$weight="\t\tfunction weight(){\n\t\t\tclearcanvas();\n";
$power="\t\tfunction power(){\n\t\t\tclearcanvas();\n";
$temperature="\t\tfunction temperatura(){\n\t\t\tclearcanvas();\n";
$humidity="\t\tfunction humedad(){\n\t\t\tclearcanvas();\n";
$realpower="\t\tfunction realpower(){\n\t\t\tclearcanvas();\n";
$airflow="\t\tfunction airflow(){\n\t\t\t\n";
/*
$sql="SELECT C.*, Temps.Temp, Temps.Humidity, Stats.Wattage AS RealPower,
Temps.LastRead, Temps.LastRead AS RPLastRead FROM fac_Cabinet AS C
LEFT JOIN fac_CabinetTemps AS Temps ON C.CabinetID=Temps.CabinetID
LEFT JOIN fac_PowerDistribution AS P ON C.CabinetID=P.CabinetID
LEFT JOIN fac_PDUStats AS Stats ON P.PDUID=Stats.PDUID
WHERE C.DataCenterID=$this->DataCenterID GROUP BY CabinetID;";
*/
$sql="SELECT C.*, T.Temp, T.Humidity, P.RealPower, T.LastRead, PLR.RPLastRead
FROM ((fac_Cabinet C LEFT JOIN fac_CabinetTemps T ON C.CabinetId = T.CabinetID) LEFT JOIN
(SELECT CabinetID, SUM(Wattage) RealPower
FROM fac_PowerDistribution PD LEFT JOIN fac_PDUStats PS ON PD.PDUID=PS.PDUID
GROUP BY CabinetID) P ON C.CabinetId = P.CabinetID) LEFT JOIN
(SELECT CabinetID, MAX(LastRead) RPLastRead
FROM fac_PowerDistribution PD LEFT JOIN fac_PDUStats PS ON PD.PDUID=PS.PDUID
GROUP BY CabinetID) PLR ON C.CabinetId = PLR.CabinetID
WHERE C.DataCenterID=".intval($this->DataCenterID).";";
$fechaLecturaTemps=0;
$fechaLecturaRP=0;
if($racks=$this->query($sql)){
// read all cabinets and draw image map
foreach($racks as $cabRow){
$cab->CabinetID=$cabRow["CabinetID"];
if (!$cab->GetCabinet()){
continue;
}
if ($cab->MapX1==$cab->MapX2 || $cab->MapY1==$cab->MapY2){
continue;
}
$dev->Cabinet=$cab->CabinetID;
$dev->Location=$cab->Location; //$dev->Location ???
$devList=$dev->ViewDevicesByCabinet();
$currentHeight = $cab->CabinetHeight;
$totalWatts = $totalWeight = $totalMoment =0;
$currentTemperature=$cabRow["Temp"];
$currentHumidity=$cabRow["Humidity"];
$currentRealPower=$cabRow["RealPower"];
while(list($devID,$device)=each($devList)){
$totalWatts+=$device->GetDeviceTotalPower();
$DeviceTotalWeight=$device->GetDeviceTotalWeight();
$totalWeight+=$DeviceTotalWeight;
$totalMoment+=($DeviceTotalWeight*($device->Position+($device->Height/2)));
}
$used=$cab->CabinetOccupancy($cab->CabinetID);
// check to make sure the cabinet height is set to keep errors out of the logs
if(!isset($cab->CabinetHeight)||$cab->CabinetHeight==0){$SpacePercent=100;}else{$SpacePercent=number_format($used /$cab->CabinetHeight *100,0);}
// check to make sure there is a weight limit set to keep errors out of logs
if(!isset($cab->MaxWeight)||$cab->MaxWeight==0){$WeightPercent=0;}else{$WeightPercent=number_format($totalWeight /$cab->MaxWeight *100,0);}
// check to make sure there is a kilowatt limit set to keep errors out of logs
if(!isset($cab->MaxKW)||$cab->MaxKW==0){$PowerPercent=0;}else{$PowerPercent=number_format(($totalWatts /1000 ) /$cab->MaxKW *100,0);}
if(!isset($cab->MaxKW)||$cab->MaxKW==0){$RealPowerPercent=0;}else{$RealPowerPercent=number_format(($currentRealPower /1000 ) /$cab->MaxKW *100,0, ",", ".");}
//Decide which color to paint on the canvas depending on the thresholds
if($SpacePercent>$SpaceRed){$scolor=$CriticalColor;}elseif($SpacePercent>$SpaceYellow){$scolor=$CautionColor;}else{$scolor=$GoodColor;}
if($WeightPercent>$WeightRed){$wcolor=$CriticalColor;}elseif($WeightPercent>$WeightYellow){$wcolor=$CautionColor;}else{$wcolor=$GoodColor;}
if($PowerPercent>$PowerRed){$pcolor=$CriticalColor;}elseif($PowerPercent>$PowerYellow){$pcolor=$CautionColor;}else{$pcolor=$GoodColor;}
if($RealPowerPercent>$RealPowerRed){$rpcolor=$CriticalColor;}elseif($RealPowerPercent>$RealPowerYellow){$rpcolor=$CautionColor;}else{$rpcolor=$GoodColor;}
/* Example for continuous color range for temperature
if($currentTemperature==0){$tcolor=$unknounColor;}
elseif($currentTemperature>$TemperatureRed){$tcolor=$CriticalColor;}
elseif($currentTemperature<$TemperatureGreen){$tcolor=$GoodColor;}
elseif($currentTemperature<$TemperatureYellow){
$tcolor[0]=intval(($CautionColor[0]-$GoodColor[0])/($TemperatureYellow-$TemperatureGreen)*($currentTemperature-$TemperatureGreen)+$GoodColor[0]);
$tcolor[1]=intval(($CautionColor[1]-$GoodColor[1])/($TemperatureYellow-$TemperatureGreen)*($currentTemperature-$TemperatureGreen)+$GoodColor[1]);
$tcolor[2]=intval(($CautionColor[2]-$GoodColor[2])/($TemperatureYellow-$TemperatureGreen)*($currentTemperature-$TemperatureGreen)+$GoodColor[2]);}
else{
$tcolor[0]=intval(($CriticalColor[0]-$CautionColor[0])/($TemperatureRed-$TemperatureYellow)*($currentTemperature-$TemperatureYellow)+$CautionColor[0]);
$tcolor[1]=intval(($CriticalColor[1]-$CautionColor[1])/($TemperatureRed-$TemperatureYellow)*($currentTemperature-$TemperatureYellow)+$CautionColor[1]);
$tcolor[2]=intval(($CriticalColor[2]-$CautionColor[2])/($TemperatureRed-$TemperatureYellow)*($currentTemperature-$TemperatureYellow)+$CautionColor[2]);}
*/
if($currentTemperature==0){$tcolor=$unknounColor;}
elseif($currentTemperature>$TemperatureRed){$tcolor=$CriticalColor;}
elseif($currentTemperature>$TemperatureYellow){$tcolor=$CautionColor;}
else{$tcolor=$GoodColor;}
if($currentHumidity==0){$hcolor=$unknounColor;}
elseif($currentHumidity>$HumidityMax || $currentHumidity<$HumidityMin){$hcolor=$CriticalColor;}
elseif($currentHumidity>$HumidityMedMax || $currentHumidity<$HumidityMedMin) {$hcolor=$CautionColor;}
else{$hcolor=$GoodColor;}
if($SpacePercent>$SpaceRed || $WeightPercent>$WeightRed || $PowerPercent>$PowerRed ||
$currentTemperature>$TemperatureRed || $currentHumidity>$HumidityMax ||
$currentHumidity<$HumidityMin && $currentHumidity!=0 ||
$RealPowerPercent>$RealPowerRed){$color=$CriticalColor;}
elseif($SpacePercent>$SpaceYellow || $WeightPercent>$WeightYellow || $PowerPercent>$PowerYellow ||
$currentTemperature>$TemperatureYellow || $currentHumidity>$HumidityMedMax ||
$currentHumidity<$HumidityMedMin && $currentHumidity!=0 ||
$RealPowerPercent>$RealPowerYellow){$color=$CautionColor;}
else{$color=$GoodColor;}
$width=$cab->MapX2-$cab->MapX1;
$height=$cab->MapY2-$cab->MapY1;
$textstrlen=strlen($dev->Location);
$textXcoord=$cab->MapX1+3;
$textYcoord=$cab->MapY1+floor($height*2/3);
$border="\n\t\t\tcontext.strokeStyle='#000000';\n\t\t\tcontext.lineWidth=1;\n\t\t\tcontext.strokeRect($cab->MapX1,$cab->MapY1,$width,$height);";
$statuscolor="\n\t\t\tcontext.fillRect($cab->MapX1,$cab->MapY1,$width,$height);";
$airflow.="\n\t\t\tdrawArrow(context,$cab->MapX1,$cab->MapY1,$width,$height,'$cab->FrontEdge');";
$label="\n\t\t\tcontext.fillStyle='#000000';\n\t\t\tcontext.font='10px arial';\n\t\t\tcontext.fillText('$dev->Location',$textXcoord,$textYcoord);\n";
$labelsp="\n\t\t\tcontext.fillStyle='#000000';\n\t\t\tcontext.font='bold 12px arial';\n\t\t\tcontext.fillText('".number_format($used,0, ",", ".")."',$textXcoord,$textYcoord);\n";
$labelwe="\n\t\t\tcontext.fillStyle='#000000';\n\t\t\tcontext.font='bold 12px arial';\n\t\t\tcontext.fillText('".number_format($totalWeight,0, ",", ".")."',$textXcoord,$textYcoord);\n";
$labelpo="\n\t\t\tcontext.fillStyle='#000000';\n\t\t\tcontext.font='10px arial';\n\t\t\tcontext.fillText('".number_format($totalWatts/1000,2, ",", ".")."',$textXcoord,$textYcoord);\n";
$labelte="\n\t\t\tcontext.fillStyle='#000000';\n\t\t\tcontext.font='10px arial';\n\t\t\tcontext.fillText('".(($currentTemperature>0)?number_format($currentTemperature,0, ",", "."):"")."',$textXcoord,$textYcoord);\n";
$labelhu="\n\t\t\tcontext.fillStyle='#000000';\n\t\t\tcontext.font='10px arial';\n\t\t\tcontext.fillText('".(($currentHumidity>0)?number_format($currentHumidity,0, ",", ".")."%":"")."',$textXcoord,$textYcoord);\n";
$labelrp="\n\t\t\tcontext.fillStyle='#000000';\n\t\t\tcontext.font='10px arial';\n\t\t\tcontext.fillText('".(($currentRealPower>0)?number_format($currentRealPower/1000,2, ",", "."):"")."',$textXcoord,$textYcoord);\n";
// Comment this to add borders and rack labels to the canvas drawing of the data center.
// Discuss moving this into a configuration item for the future.
$border=$label=$labelsp=$labelwe=$labelpo=$labelte=$labelhu=$labelrp="";
$script.="\t\t\tcontext.fillStyle=\"rgba({$color[0]}, {$color[1]}, {$color[2]}, 0.35)\";$border$statuscolor$label\n";
$space.="\t\t\tcontext.fillStyle=\"rgba({$scolor[0]}, {$scolor[1]}, {$scolor[2]}, .35)\";$border$statuscolor$labelsp\n";
$weight.="\t\t\tcontext.fillStyle=\"rgba({$wcolor[0]}, {$wcolor[1]}, {$wcolor[2]}, 0.35)\";$border$statuscolor$labelwe\n";
$power.="\t\t\tcontext.fillStyle=\"rgba({$pcolor[0]}, {$pcolor[1]}, {$pcolor[2]}, 0.35)\";$border$statuscolor$labelpo\n";
$temperature.="\t\t\tcontext.fillStyle=\"rgba({$tcolor[0]}, {$tcolor[1]}, {$tcolor[2]}, 0.35)\";$border$statuscolor$labelte\n";
$humidity.="\t\t\tcontext.fillStyle=\"rgba({$hcolor[0]}, {$hcolor[1]}, {$hcolor[2]}, 0.35)\";$border$statuscolor$labelhu\n";
$realpower.="\t\t\tcontext.fillStyle=\"rgba({$rpcolor[0]}, {$rpcolor[1]}, {$rpcolor[2]}, 0.35)\";$border$statuscolor$labelrp\n";
$fechaLecturaTemps=(!is_null($cabRow["LastRead"])&&($cabRow["LastRead"]>$fechaLecturaTemps))?date('d-m-Y',strtotime(($cabRow["LastRead"]))):$fechaLecturaTemps;
$fechaLecturaRP=(!is_null($cabRow["RPLastRead"])&&($cabRow["RPLastRead"]>$fechaLecturaRP))?date('d-m-Y',strtotime(($cabRow["RPLastRead"]))):$fechaLecturaRP;
}
}
}
//Key
$leyenda="\t\t\tmaptitle.html('".__("Worst state of cabinets")."');";
$leyendasp="\t\t\tmaptitle.html('".__("Occupied space")."');";
$leyendawe="\t\t\tmaptitle.html('".__("Calculated weight")."');";
$leyendapo="\t\t\tmaptitle.html('".__("Calculated power usage")."');";
$leyendate="\t\t\tmaptitle.html('".($fechaLecturaTemps>0?__("Measured on")." ".$fechaLecturaTemps:__("no data"))."');";
$leyendahu="\t\t\tmaptitle.html('".($fechaLecturaTemps>0?__("Measured on")." ".$fechaLecturaTemps:__("no data"))."');";
$leyendarp="\t\t\tmaptitle.html('".($fechaLecturaRP>0?__("Measured on")." ".$fechaLecturaRP:__("no data"))."');";
/*
$leyenda="\n\t\tcontext.fillStyle='#000000';\n\t\tcontext.font='15px arial';
\n\t\tcontext.fillText('".__("OVERVIEW: worse state of cabinets")."',5,20);";
$leyendasp="\n\t\tcontext.fillStyle='#000000';\n\t\tcontext.font='15px arial';
\n\t\tcontext.fillText('".__("SPACE: occupation of cabinets")."',5,20);";
$leyendawe="\n\t\tcontext.fillStyle='#000000';\n\t\tcontext.font='15px arial';
\n\t\tcontext.fillText('".__("WEIGHT: Supported weight by cabinets")."',5,20);";
$leyendapo="\n\t\tcontext.fillStyle='#000000';\n\t\tcontext.font='15px arial';
\n\t\tcontext.fillText('".__("POWER: Computed from devices power supplies")."',5,20);";
$leyendate="\n\t\tcontext.fillStyle='#000000';\n\t\tcontext.font='15px arial';
\n\t\tcontext.fillText('".__("TEMPERATURE: Measured on")." ".$fechaLecturaTemps."',5,20);";
$leyendahu="\n\t\tcontext.fillStyle='#000000';\n\t\tcontext.font='15px arial';
\n\t\tcontext.fillText('".__("HUMIDITY: % Measured on")." ".$fechaLecturaTemps."',5,20);";
$leyendarp="\n\t\tcontext.fillStyle='#000000';\n\t\tcontext.font='15px arial';
\n\t\tcontext.fillText('".__("REAL POWER: Measured on")." ".$fechaLecturaRP."',5,20);";
*/
$space.=$leyendasp."\n\t\t}\n";
$weight.=$leyendawe."\n\t\t}\n";
$power.=$leyendapo."\n\t\t}\n";
$temperature.=$leyendate."\n\t\t}\n";
$humidity.=$leyendahu."\n\t\t}\n";
$realpower.=$leyendarp."\n\t\t}\n";
$airflow.="\n\t\t}\n";
$script.=$leyenda."\n\t\t}\n";
$script.=$space.$weight.$power.$temperature.$humidity.$realpower.$airflow;
}
return $script;
}
function GetDCStatistics(){
$this->GetDataCenter();
$sql="SELECT SUM(CabinetHeight) as TotalU FROM fac_Cabinet WHERE
DataCenterID=$this->DataCenterID;";
$dcStats["TotalU"]=($test=$this->query($sql)->fetchColumn())?$test:0;
$sql="SELECT SUM(a.Height) as TotalU FROM fac_Device a,fac_Cabinet b WHERE
a.Cabinet=b.CabinetID AND b.DataCenterID=$this->DataCenterID AND
a.DeviceType NOT IN ('Server','Storage Array');";
$dcStats["Infrastructure"]=($test=$this->query($sql)->fetchColumn())?$test:0;
$sql="SELECT SUM(a.Height) as TotalU FROM fac_Device a,fac_Cabinet b WHERE
a.Cabinet=b.CabinetID AND b.DataCenterID=$this->DataCenterID AND
a.Reservation=false AND a.DeviceType IN ('Server', 'Storage Array');";
$dcStats["Occupied"]=($test=$this->query($sql)->fetchColumn())?$test:0;
$sql="SELECT SUM(a.Height) FROM fac_Device a,fac_Cabinet b WHERE
a.Cabinet=b.CabinetID AND a.Reservation=true AND b.DataCenterID=$this->DataCenterID;";
$dcStats["Allocated"]=($test=$this->query($sql)->fetchColumn())?$test:0;
$dcStats["Available"]=$dcStats["TotalU"] - $dcStats["Occupied"] - $dcStats["Infrastructure"] - $dcStats["Allocated"];
// Perform two queries - one is for the wattage overrides (where NominalWatts > 0) and one for the template (default) values
$sql="SELECT SUM(NominalWatts) as TotalWatts FROM fac_Device a,fac_Cabinet b WHERE
a.Cabinet=b.CabinetID AND a.NominalWatts>0 AND
b.DataCenterID=$this->DataCenterID;";
$dcStats["ComputedWatts"]=($test=$this->query($sql)->fetchColumn())?$test:0;
$sql="SELECT SUM(c.Wattage) as TotalWatts FROM fac_Device a, fac_Cabinet b,
fac_DeviceTemplate c WHERE a.Cabinet=b.CabinetID AND
a.TemplateID=c.TemplateID AND a.NominalWatts=0 AND
b.DataCenterID=$this->DataCenterID;";
$dcStats["ComputedWatts"]+=($test=$this->query($sql)->fetchColumn())?$test:0;
$pdu=new PowerDistribution();
$dcStats["MeasuredWatts"]=$pdu->GetWattageByDC($this->DataCenterID);
return $dcStats;
}
function AddDCToTree($lev=0) {
$dept=new Department();
$zone=new Zone();
$classType = "liClosed";
$tree=str_repeat(" ",$lev+1)."<li class=\"$classType\" id=\"dc$this->DataCenterID\"><a class=\"DC\" href=\"dc_stats.php?dc="
."$this->DataCenterID\">$this->Name</a>\n";
$tree.=str_repeat(" ",$lev+2)."<ul>\n";
$zone->DataCenterID=$this->DataCenterID;
$zoneList=$zone->GetZonesByDC();
while(list($zoneNum,$myzone)=each($zoneList)){
$tree.=str_repeat(" ",$lev+3)."<li class=\"liClosed\" id=\"zone$myzone->ZoneID\"><a class=\"ZONE\" href=\"zone_stats.php?zone="
."$myzone->ZoneID\">$myzone->Description</a>\n";
$tree.=str_repeat(" ",$lev+4)."<ul>\n";
//Rows
$sql="SELECT CabRowID, Name AS Fila FROM fac_CabRow WHERE
ZoneID=$myzone->ZoneID ORDER BY Fila;";
foreach($this->query($sql) as $filaRow){
$tree.=str_repeat(" ",$lev+5)."<li class=\"liClosed\" id=\"fila{$filaRow['Fila']}\">".
"<a class=\"CABROW\" href=\"rowview.php?row={$filaRow['CabRowID']}\">".__("Row ")."{$filaRow['Fila']}</a>\n";
$tree.=str_repeat(" ",$lev+6)."<ul>\n";
// DataCenterID and ZoneID are redundant if fac_cabrow is defined and is CabrowID set in fac_cabinet
$cabsql="SELECT * FROM fac_Cabinet WHERE DataCenterID=$this->DataCenterID
AND ZoneID=$myzone->ZoneID AND CabRowID={$filaRow['CabRowID']} ORDER
BY LENGTH(Location),Location ASC;";
foreach($this->query($cabsql) as $cabRow){
$tree.=str_repeat(" ",$lev+7)."<li id=\"cab{$cabRow['CabinetID']}\"><a class=\"RACK\" href=\"cabnavigator.php?cabinetid={$cabRow['CabinetID']}\">{$cabRow['Location']}</a></li>\n";
}
$tree.=str_repeat(" ",$lev+6)."</ul>\n";
$tree.=str_repeat(" ",$lev+5)."</li>\n";
}
//Cabinets without CabRowID
$cabsql="SELECT * FROM fac_Cabinet WHERE DataCenterID=$this->DataCenterID AND
ZoneID=$myzone->ZoneID AND CabRowID=0 ORDER BY Location ASC;";
foreach($this->query($cabsql) as $cabRow){
$tree.=str_repeat(" ",$lev+5)."<li id=\"cab{$cabRow['CabinetID']}\"><a class=\"RACK\" href=\"cabnavigator.php?cabinetid={$cabRow['CabinetID']}\">{$cabRow['Location']}</a></li>\n";
}
$tree.=str_repeat(" ",$lev+4)."</ul>\n";
$tree.=str_repeat(" ",$lev+3)."</li>\n";
} //zone
//Cabinets without ZoneID
$cabsql="SELECT * FROM fac_Cabinet WHERE DataCenterID=$this->DataCenterID AND
ZoneID=0 ORDER BY Location ASC;";
foreach($this->query($cabsql) as $cabRow){
$tree.=str_repeat(" ",$lev+3)."<li id=\"cab{$cabRow['CabinetID']}\"><a class=\"RACK\" href=\"cabnavigator.php?cabinetid={$cabRow['CabinetID']}\">{$cabRow['Location']}</a></li>\n";
}
//StorageRoom for this DC
$tree.="<li class=\"liOpen\" id=\"dc-1\"><a href=\"storageroom.php?dc=$this->DataCenterID\">".__("Storage Room")."</a></li>\n";
$tree.=str_repeat(" ",$lev+2)."</ul>\n";
$tree.=str_repeat(" ",$lev+1)."</li>\n";
return $tree;
}
}
class DeviceTemplate {
var $TemplateID;
var $ManufacturerID;
var $Model;
var $Height;
var $Weight;
var $Wattage;
var $DeviceType;
var $PSCount;
var $NumPorts;
var $Notes;
var $FrontPictureFile;
var $RearPictureFile;
var $ChassisSlots;
var $RearChassisSlots;
function MakeSafe(){
$validDeviceTypes=array('Server','Appliance','Storage Array','Switch','Chassis','Patch Panel','Physical Infrastructure');
$this->TemplateID=intval($this->TemplateID);
$this->ManufacturerID=intval($this->ManufacturerID);
$this->Model=addslashes(trim($this->Model));
$this->Height=intval($this->Height);
$this->Weight=intval($this->Weight);
$this->Wattage=intval($this->Wattage);
$this->DeviceType=(in_array($this->DeviceType, $validDeviceTypes))?$this->DeviceType:'Server';
$this->PSCount=intval($this->PSCount);
$this->NumPorts=intval($this->NumPorts);
$this->Notes=addslashes(trim($this->Notes));
$this->FrontPictureFile=addslashes(trim($this->FrontPictureFile));
$this->RearPictureFile=addslashes(trim($this->RearPictureFile));
$this->ChassisSlots=intval($this->ChassisSlots);
$this->RearChassisSlots=intval($this->RearChassisSlots);
}
function MakeDisplay(){
$this->Model=stripslashes($this->Model);
$this->Notes=stripslashes($this->Notes);
$this->FrontPictureFile=stripslashes($this->FrontPictureFile);
$this->RearPictureFile=stripslashes($this->RearPictureFile);
}
static function RowToObject($row){
$Template=new DeviceTemplate();
$Template->TemplateID=$row["TemplateID"];
$Template->ManufacturerID=$row["ManufacturerID"];
$Template->Model=$row["Model"];
$Template->Height=$row["Height"];
$Template->Weight=$row["Weight"];
$Template->Wattage=$row["Wattage"];
$Template->DeviceType=$row["DeviceType"];
$Template->PSCount=$row["PSCount"];
$Template->NumPorts=$row["NumPorts"];
$Template->Notes=$row["Notes"];
$Template->FrontPictureFile=$row["FrontPictureFile"];
$Template->RearPictureFile=$row["RearPictureFile"];
$Template->ChassisSlots=$row["ChassisSlots"];
$Template->RearChassisSlots=$row["RearChassisSlots"];
$Template->MakeDisplay();
return $Template;
}
function query($sql){
global $dbh;
return $dbh->query($sql);
}
function exec($sql){
global $dbh;
return $dbh->exec($sql);
}
function CreateTemplate(){
global $dbh;
$this->MakeSafe();
$sql="INSERT INTO fac_DeviceTemplate SET ManufacturerID=$this->ManufacturerID,
Model=\"$this->Model\", Height=$this->Height, Weight=$this->Weight,
Wattage=$this->Wattage, DeviceType=\"$this->DeviceType\",
PSCount=$this->PSCount, NumPorts=$this->NumPorts, Notes=\"$this->Notes\",
FrontPictureFile=\"$this->FrontPictureFile\", RearPictureFile=\"$this->RearPictureFile\",
ChassisSlots=$this->ChassisSlots, RearChassisSlots=$this->RearChassisSlots;";
if(!$dbh->exec($sql)){
error_log( "SQL Error: " . $sql );
return false;
}else{
$this->TemplateID=$dbh->lastInsertID();
$this->MakeDisplay();
return true;
}
}
function UpdateTemplate(){
$this->MakeSafe();
$sql="UPDATE fac_DeviceTemplate SET ManufacturerID=$this->ManufacturerID,
Model=\"$this->Model\", Height=$this->Height, Weight=$this->Weight,
Wattage=$this->Wattage, DeviceType=\"$this->DeviceType\",
PSCount=$this->PSCount, NumPorts=$this->NumPorts, Notes=\"$this->Notes\",
FrontPictureFile=\"$this->FrontPictureFile\", RearPictureFile=\"$this->RearPictureFile\",
ChassisSlots=$this->ChassisSlots, RearChassisSlots=$this->RearChassisSlots
WHERE TemplateID=$this->TemplateID;";
if(!$this->query($sql)){
return false;
}else{
$this->MakeDisplay();
return true;
}
}
function DeleteTemplate(){
$this->MakeSafe();
$sql="DELETE FROM fac_DeviceTemplate WHERE TemplateID=$this->TemplateID;";
return $this->exec($sql);
}
function GetTemplateByID(){
$this->MakeSafe();
$sql="SELECT * FROM fac_DeviceTemplate WHERE TemplateID=$this->TemplateID;";
//JMGA Reset object in case of a lookup failure
$this->ManufacturerID=0;
$this->Model="";
$this->Height=0;
$this->Weight=0;
$this->Wattage=0;
$this->DeviceType='Server';
$this->PSCount=0;
$this->NumPorts=0;
$this->Notes="";
$this->FrontPictureFile="";
$this->RearPictureFile="";
$this->ChassisSlots=0;
$this->RearChassisSlots=0;
// Reset object in case of a lookup failure
//foreach($this as $prop => $value){
// $value=($prop!='TemplateID')?null:$value;
//}
if($row=$this->query($sql)->fetch()){
foreach(DeviceTemplate::RowToObject($row) as $prop => $value){
$this->$prop=$value;
}
return true;
}else{
return false;
}
}
function GetTemplateList(){
$sql="SELECT * FROM fac_DeviceTemplate a, fac_Manufacturer b WHERE
a.ManufacturerID=b.ManufacturerID ORDER BY Name ASC, Model ASC;";
$templateList=array();
foreach($this->query($sql) as $row){
$templateList[]=DeviceTemplate::RowToObject($row);
}
return $templateList;
}
/**
* Return a list of the templates indexed by the TemplateID
*
* @param DbLink $db
* @return multitype:DeviceTemplate
*/
function getTemplateListIndexedbyID ()
{
global $dbh;
$templateList = array();
$stmt = $dbh->prepare('select * from fac_DeviceTemplate');
$stmt->execute();
while ($row = $stmt->fetch()) {
$devTempl = DeviceTemplate::RowToObject($row);
$templateList[$devTempl->TemplateID] = $devTempl;
}
return $templateList;
}
function GetMissingMfgDates(){
$this->MakeSafe();
$sql="SELECT a.* FROM fac_Device a, fac_DeviceTemplate b WHERE
a.TemplateID=b.TemplateID AND b.ManufacturerID=$this->ManufacturerID AND
a.MfgDate<'1970-01-01'";
$devList=array();
foreach($this->query($sql) as $row){
$devList[]=Device::RowToObject($row);
}
$this->MakeDisplay();
return $devList;
}
function UpdateDevices(){
/* This will cause every device with a TemplateID matching this one to display
the updated values. We are not touching DeviceType or NumPorts at this time
because those have alternate side effects that i'm not sure we really need
to address here
*/
$this->MakeSafe();
$sql="UPDATE fac_Device SET Height=$this->Height, NominalWatts=$this->Wattage,
PowerSupplyCount=$this->PSCount WHERE TemplateID=$this->TemplateID;";
return $this->query($sql);
}
function DeleteSlots(){
$this->MakeSafe();
$sql="DELETE FROM fac_Slots WHERE TemplateID=$this->TemplateID";
if(!$this->query($sql)){
return false;
}
return true;
}
function DeletePorts(){