-
Notifications
You must be signed in to change notification settings - Fork 208
/
cabnavigator.php
823 lines (729 loc) · 28.2 KB
/
cabnavigator.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
<?php
require_once( "db.inc.php" );
require_once( "facilities.inc.php" );
$subheader=__("Data Center Cabinet Inventory");
if((isset($_REQUEST["cabinetid"]) && (intval($_REQUEST["cabinetid"])==0)) || !isset($_REQUEST["cabinetid"])){
// No soup for you.
header('Location: '.redirect());
exit;
}
/**
* Merge the tags into one HTML string
*
* @param Device|Cabinet $dev
* @return string
* a string of tag names where the tag names are embedded in span tags
*/
function renderTagsToString($obj)
{
$tagsString = '';
foreach ($obj->GetTags() as $tag)
{
$tagsString .= '<span class="text-label">' . $tag . '</span>';
}
return $tagsString;
}
/**
* Render cabinet properties into this view.
*
* The cabinet properties zone, row, model, maximum weight and installation date
* are rendered to be for this page. It checks if the user is allowed to see the
* content of the cabinet and only if the user does the information is provided.
*
* @param Cabinet $cab
* @param CabinetAudit $audit
* @param string $AuditorName
*/
function renderCabinetProps($cab, $audit, $AuditorName){
$tmpDC=new DataCenter();
$tmpDC->DataCenterID=$cab->DataCenterID;
$tmpDC->GetDataCenter();
$AuditorName=($AuditorName!='')?"<br>$AuditorName":"";
$renderedHTML="\t\t<table id=\"cabprop\">
\t\t<tr><td>".__("Last Audit").":</td><td id=\"lastaudit\">$audit->AuditStamp$AuditorName</td></tr>
\t\t<tr><td>".__("Model").":</td><td>$cab->Model</td></tr>
\t\t<tr><td>".__("Data Center").":</td><td>$tmpDC->Name</td></tr>
\t\t<tr><td>".__("Install Date").":</td><td>$cab->InstallationDate</td></tr>\n";
if($cab->ZoneID){
$zone=new Zone();
$zone->ZoneID=$cab->ZoneID;
$zone->GetZone();
$renderedHTML.="\t\t\t<tr><td>".__("Zone").":</td><td>$zone->Description</td></tr>\n";
}
if($cab->CabRowID){
$cabrow=new CabRow();
$cabrow->CabRowID=$cab->CabRowID;
$cabrow->GetCabRow();
$renderedHTML.="\t\t\t<tr><td>".__("Row").":</td><td>$cabrow->Name</td></tr>\n";
}
$renderedHTML.="\t\t\t<tr><td>".__("Tags").":</td><td>".renderTagsToString($cab)."</td></tr>\n";
$renderedHTML.="\t\t</table>\n";
return $renderedHTML;
}
/**
* Render the indicator that a device has no ownership or template assigned.
*
* @param boolean $noTemplFlag flag indicating no template is assigned to device
* @param boolean $noOwnerFlag flag indicating no ownership is assigned to device
* @param Device $device
* @return (boolean|boolean|string)[] CSS class or empty stringtype
*/
function renderUnassignedTemplateOwnership($noTemplFlag, $noOwnerFlag, $device) {
$retstr=$noTemplate=$noOwnership='';
if ($device->TemplateID == 0) {
$noTemplate = '(T)';
$noTemplFlag = true;
}
if ($device->Owner == 0) {
$noOwnership = '(O)';
$noOwnerFlag = true;
}
if ($noTemplFlag or $noOwnerFlag) {
$retstr = '<span class="hlight">' . $noTemplate . $noOwnership . '</span>';
}
return array($noTemplFlag, $noOwnerFlag, $retstr);
}
$cab=new Cabinet();
$cab->CabinetID=$_REQUEST["cabinetid"];
$cab->GetCabinet();
// Check to see if this user is allowed to see anything in ihere
if(!$person->SiteAdmin && !$person->ReadAccess && $cab->Rights=='None' && !array_intersect($person->isMemberOf(),Cabinet::GetOccupants($cab->CabinetID))){
// This cabinet belongs to a department you don't have affiliation with, so no viewing at all
header('Location: '.redirect());
exit;
}
// If you're deleting the cabinet, no need to pull in the rest of the information, so get it out of the way
// Only a site administrator can create or delete a cabinet
if(isset($_POST["delete"]) && $_POST["delete"]=="yes" && $person->SiteAdmin ) {
$cab->DeleteCabinet();
header('Content-Type: application/json');
echo json_encode(array('url' => redirect("dc_stats.php?dc=$cab->DataCenterID")));
exit;
}
$head=$legend=$zeroheight=$body=$deptcolor=$AuditorName="";
$audit=new CabinetAudit();
$dev=new Device();
$pdu=new PowerDistribution();
$pan=new PowerPanel();
$templ=new DeviceTemplate();
$tempPDU=new PowerDistribution();
$tempDept=new Department();
$dc=new DataCenter();
$dcID=$cab->DataCenterID;
$dc->DataCenterID=$dcID;
$dc->GetDataCenterbyID();
if ( !$person->SiteAdmin && ($config->ParameterArray["GDPRCountryIsolation"] == "enabled" && ( $dc->countryCode != $person->countryCode ) ) ) {
error_log( "GDPR Isolation Enabled: User country: ".$person->countryCode." denied access to Data Center country: ".$dc->countryCode );
header('Location: '.redirect());
exit;
}
$audit->CabinetID=$cab->CabinetID;
// You just have WriteAccess in order to perform/certify a rack audit
if(isset($_POST["audit"]) && $_POST["audit"]=="yes" && $person->CanWrite($cab->AssignedTo)){
$audit->Comments=sanitize($_POST["comments"]);
// Log the response
$audit->CertifyAudit();
// I'm lazy as fuck so retrieve what we just wrong
$audit->GetLastAudit();
$tmpUser=new People();
$tmpUser->UserID=$audit->UserID;
$tmpUser->GetUserRights();
$audit->UserID=($tmpUser->FirstName=="" && $tmpUser->LastName=="")?$audit->UserID:$tmpUser->FirstName." ".$tmpUser->LastName;
// Give it back to the user to update the page
header('Content-Type: application/json');
echo json_encode($audit);
exit;
}
$audit->AuditStamp=__("Never");
$audit->GetLastAudit();
if($audit->UserID!=""){
$tmpUser=new People();
$tmpUser->UserID=$audit->UserID;
$tmpUser->GetUserRights();
$AuditorName=$tmpUser->FirstName." ".$tmpUser->LastName;
}
$pdu->CabinetID=$cab->CabinetID;
$PDUList=$pdu->GetPDUbyCabinet();
$dev->Cabinet=$cab->CabinetID;
$devList=$dev->ViewDevicesByCabinet();
$search=new Device();
$search->Cabinet=$cab->CabinetID;
$search->DeviceType="Sensor";
$SensorList=$search->Search();
$stats=$cab->getStats($cab->CabinetID);
$totalWatts=$stats->Wattage;
$totalWeight=$stats->Weight;
$legend.='<div class="legenditem hide"><span style="background-color:'.$config->ParameterArray['CriticalColor'].'; text-align:center" class="error colorbox border">*</span> - '.__("Above defined rack height").'</div>'."\n";
// Set up the classes for color coding based upon status
$dsList=DeviceStatus::getStatusList();
$head.=" <style type=\"text/css\">
.freespace {background-color: {$config->ParameterArray['FreeSpaceColor']};}\n";
if($config->ParameterArray["FreeSpaceColor"] != "#FFFFFF"){
$legend.='<div class="legenditem"><span class="freespace colorbox border"></span> - '.__("Free Space").'</div>'."\n";
}
foreach($dsList as $stat){
if($stat->ColorCode != "#FFFFFF"){
$stName=str_replace(' ','_',$stat->Status);
$head.="\t\t\t.$stName {background-color: {$stat->ColorCode} !important;}\n";
$legend.="\t\t<div class=\"legenditem hide\"><span class=\"$stName colorbox border\"></span> - $stat->Status</div>\n";
}
}
$noOwnerFlag=false;
$noTemplFlag=false;
$noReservationFlag=false;
$backside=true;
// This function with no argument will build the front cabinet face. Specify
// rear and it will build the back.
// Generate rack view
$body.=BuildCabinet($cab->CabinetID);
// Generate rear rack view if needed
$body.=($backside)?BuildCabinet($cab->CabinetID,'rear'):'';
$used=$cab->CabinetOccupancy($cab->CabinetID);
@$SpacePercent=($cab->CabinetHeight>0)?number_format($used/$cab->CabinetHeight*100,0):0;
@$WeightPercent=($cab->MaxWeight>0)?number_format($totalWeight/$cab->MaxWeight*100,0):0;
@$PowerPercent=($cab->MaxKW>0)?number_format(($totalWatts/1000)/$cab->MaxKW*100,0):0;
$measuredWatts = $pdu->GetWattageByCabinet( $cab->CabinetID );
@$MeasuredPercent=($cab->MaxKW>0)?number_format(($measuredWatts/1000)/$cab->MaxKW*100,0):0;
$CriticalColor=$config->ParameterArray["CriticalColor"];
$CautionColor=$config->ParameterArray["CautionColor"];
$GoodColor=$config->ParameterArray["GoodColor"];
if($SpacePercent>100){$SpacePercent=100;}
if($WeightPercent>100){$WeightPercent=100;}
if($PowerPercent>100){$PowerPercent=100;}
if($MeasuredPercent>100){$MeasuredPercent=100;}
$SpaceColor=($SpacePercent>intval($config->ParameterArray["SpaceRed"])?$CriticalColor:($SpacePercent >intval($config->ParameterArray["SpaceYellow"])?$CautionColor:$GoodColor));
$WeightColor=($WeightPercent>intval($config->ParameterArray["WeightRed"])?$CriticalColor:($WeightPercent>intval($config->ParameterArray["WeightYellow"])?$CautionColor:$GoodColor));
$PowerColor=($PowerPercent>intval($config->ParameterArray["PowerRed"])?$CriticalColor:($PowerPercent>intval($config->ParameterArray["PowerYellow"])?$CautionColor:$GoodColor));
$MeasuredColor=($MeasuredPercent>intval($config->ParameterArray["PowerRed"])?$CriticalColor:($MeasuredPercent>intval($config->ParameterArray["PowerYellow"])?$CautionColor:$GoodColor));
if($cab->MaxWeight==0){
$cab->MaxWeight=$WeightPercent=__("Maximum Weight Not Set");
$WeightColor=$CriticalColor;
}
foreach(Department::GetDepartmentListIndexedbyID() as $deptid => $d){
// Add a style container for these
$head=($head=="")?"\t\t<style type=\"text/css\">\n":$head;
$head.="\t\t\t.dept$deptid {background-color:$d->DeptColor;}\n";
$legend.="\t\t<div class=\"legenditem hide\"><span class=\"border colorbox dept$deptid\"></span> - <span>$d->Name</span></div>\n";
}
// add legend for the flags which actually are used in the cabinet
$legend.="\t\t<div class=\"legenditem hide\"><span class=\"hlight owner\">(O)</span> - ".__("Owner Unassigned")."</div>\n";
$legend.="\t\t<div class=\"legenditem hide\"><span class=\"hlight template\">(T)</span> - ".__("Template Unassigned")."</div>\n";
$body.='<div id="infopanel">
<fieldset id="legend">
<legend>'.__("Markup Key")."</legend>\n"
.$legend.'
</fieldset>
<fieldset id="metrics">
<legend>'.__("Cabinet Metrics").'</legend>
<table style="background: white;" border=1>
<tr>
<td>'.__("Space").'
<div class="meter-wrap">
<div class="meter-value" style="background-color: '.$SpaceColor.'; width: '.$SpacePercent.'%;">
<div class="meter-text">'.$SpacePercent.'%</div>
</div>
</div>
</td>
</tr>
<tr>
<td>'.__("Weight").' ['.$cab->MaxWeight.']
<div class="meter-wrap">
<div class="meter-value" style="background-color: '.$WeightColor.'; width: '.$WeightPercent.'%;">
<div class="meter-text">'.$WeightPercent.'%</div>
</div>
</div>
</td>
</tr>
<tr>
<td>'.__("Computed Watts").'
<div class="meter-wrap">
<div class="meter-value" style="background-color: '.$PowerColor.'; width: '.$PowerPercent.'%;">
<div class="meter-text">'; $body.=sprintf("%.2f kW / %d kW",$totalWatts/1000,$cab->MaxKW);$body.='</div>
</div>
</div>
</td>
</tr>
<tr>
<td>'.__("Measured Watts").'
<div class="meter-wrap">
<div class="meter-value" style="background-color: '.$MeasuredColor.'; width: '.$MeasuredPercent.'%;">
<div class="meter-text">'; $body.=sprintf("%.2f kW / %d kW",$measuredWatts/1000,$cab->MaxKW);$body.='</div>
</div>
</div>
</td>
</tr>
</table>
<p>'.__("Approximate Center of Gravity").': <span id="tippingpoint"></span></p>
</fieldset>
<fieldset id="keylock">
<legend>'.__("Key/Lock Information").'</legend>
<div>
'.$cab->Keylock.'
</div>
</fieldset>
<fieldset id="zerou" class="hide">
<legend>'.__("Zero-U Devices").'</legend>
<div>
</div>
</fieldset>
<fieldset name="pdu">
<legend>'.__("Power Distribution").'</legend>
<div>';
foreach($PDUList as $PDUdev){
$lastreading=$PDUdev->GetLastReading();
$pduDraw=($lastreading)?$lastreading->Wattage:0;
$pan->PanelID=$PDUdev->PanelID;
$pan->getPanel();
if($PDUdev->BreakerSize==1){
$maxDraw=$PDUdev->InputAmperage * $pan->PanelVoltage / 1.732;
}elseif($PDUdev->BreakerSize==2){
$maxDraw=$PDUdev->InputAmperage * $pan->PanelVoltage;
}else{
$maxDraw=$PDUdev->InputAmperage * $pan->PanelVoltage * 1.732;
}
// De-rate all breakers to 80% sustained load
$maxDraw*=0.8;
if($maxDraw>0){
$PDUPercent=intval($pduDraw/$maxDraw*100);
}else{
$PDUPercent=0;
}
$PDUColor=($PDUPercent>intval($config->ParameterArray["PowerRed"])?$CriticalColor:($PDUPercent>intval($config->ParameterArray["PowerYellow"])?$CautionColor:$GoodColor));
$body.=sprintf("\n\t\t\t<a href=\"devices.php?DeviceID=%d\">CDU %s</a><br>(%.2f kW) / (%.2f kW Max)<br>\n", $PDUdev->PDUID, $PDUdev->Label, $pduDraw / 1000, $maxDraw / 1000 );
$body.="\t\t\t\t<div class=\"meter-wrap\">\n\t\t\t\t\t<div class=\"meter-value\" style=\"background-color: $PDUColor; width: $PDUPercent%;\">\n\t\t\t\t\t\t<div class=\"meter-text\">$PDUPercent%</div>\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t<br>\n";
if ( $PDUdev->FailSafe ) {
$tmpl = new CDUTemplate();
$tmpl->TemplateID = $PDUdev->TemplateID;
$tmpl->GetTemplate();
$ATSStatus = $PDUdev->getATSStatus();
if ( $ATSStatus == "" ) {
$ATSColor = "rs.png";
$ATSStatus = __("Unknown Status");
} elseif ( $ATSStatus == $tmpl->ATSDesiredResult ) {
$ATSColor = "gs.png";
$ATSStatus = __("ATS Feeds OK");
} else {
$ATSColor = "ys.png";
$ATSStatus = __("ATS Feeds Abnormal");
}
$body.="<div><img src=\"images/$ATSColor\">$ATSStatus</div>\n";
}
}
if($person->CanWrite($cab->AssignedTo)){
$body.="\n\t\t<ul class=\"nav\"><a href=\"devices.php?action=new&CabinetID=$cab->CabinetID&DeviceType=CDU\"><li>".__("Add CDU")."</li></a></ul>\n";
}
$body.="\t\t</div>\n\t</fieldset>\n";
$body.=' <fieldset id="sensors">
<legend>'.__("Environmental Sensors").'</legend>
<div>';
foreach($SensorList as $Sensor){
$body.="\t\t<a href=\"devices.php?DeviceID=$Sensor->DeviceID\">$Sensor->Label</a><br>\n";
}
if($person->CanWrite($cab->AssignedTo)){
$body.="\n\t\t<ul class=\"nav\"><a href=\"devices.php?action=new&CabinetID=$cab->CabinetID&DeviceType=Sensor\"><li>".__("Add Sensor")."</li></a></ul>\n";
}
$body.="\t\t</div>\n\t</fieldset>\n";
if ($person->CanWrite($cab->AssignedTo) || $person->SiteAdmin) {
$body.="\t<fieldset>\n";
if ($person->CanWrite($cab->AssignedTo) ) {
$body .= renderCabinetProps($cab, $audit, $AuditorName);
}
$body.="\t\t<ul class=\"nav\">";
if($person->CanWrite($cab->AssignedTo)){
$body.="
<a href=\"#\" id=\"verifyaudit\"><li>".__("Certify Audit")."</li></a>
<a href=\"devices.php?action=new&CabinetID=$cab->CabinetID\"><li>".__("Add Device")."</li></a>
<a href=\"cabaudit.php?cabinetid=$cab->CabinetID\"><li>".__("Audit Report")."</li></a>
<a href=\"mapmaker.php?cabinetid=$cab->CabinetID\"><li>".__("Map Coordinates")."</li></a>
<a href=\"cabinets.php?cabinetid=$cab->CabinetID\"><li>".__("Edit Cabinet")."</li></a>\n";
}
if($person->SiteAdmin){
$body.="\t\t\t<a href=\"#\" id=\"verifydelete\"><li>".__("Delete Cabinet")."</li></a>";
}
$body.="\n\t\t</ul>\n </fieldset>";
}
$body.='
<fieldset id="cabnotes">
<legend>'.__("Cabinet Notes").'</legend>
<div>
'.$cab->Notes.'
</div>
</fieldset>
</div> <!-- END div#infopanel -->';
// If $head isn't empty then we must have added some style information so close the tag up.
if($head!=""){
$head.=' </style>';
}
$title=($cab->Location!='')?"$cab->Location :: $dc->Name":__("Facilities Cabinet Maintenance");
?>
<!doctype html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><?php echo $title; ?></title>
<link rel="stylesheet" href="css/inventory.php" type="text/css">
<link rel="stylesheet" href="css/print.css" type="text/css" media="print">
<link rel="stylesheet" href="css/jquery-ui.css" type="text/css">
<!--[if lt IE 9]>
<link rel="stylesheet" href="css/ie.css" type="text/css" />
<![endif]-->
<?php
echo $head,' <script type="text/javascript" src="scripts/jquery.min.js"></script>
<script type="text/javascript" src="scripts/jquery-ui.min.js"></script>
<script type="text/javascript" src="scripts/jquery.cookie.js"></script>
<script type="text/javascript" src="scripts/jquery-json.min.js"></script>
<script type="text/javascript" src="scripts/common.js?v',filemtime('scripts/common.js'),'"></script>
<script type="text/javascript" src="scripts/masonry.pkgd.min.js"></script>
<script type="text/javascript">
window.weight=',$totalWeight,';
var form=$("<form>").attr({ method: "post", action: "cabnavigator.php" });
$("<input>").attr({ type: "hidden", name: "cabinetid", value: "',$cab->CabinetID,'"}).appendTo(form);
(function ($) {
$.fn.extend({
cookieList: function (cookieName, expireTime) {
var cookie = $.cookie(cookieName);
var items = cookie ? $.secureEvalJSON(cookie) : [];
return {
add: function (val) {
var index = items.indexOf(val);
if ( index == -1) {
items.push(val);
$.cookie(cookieName, $.toJSON(items), {expires: expireTime });
}
},
remove: function (val) {
var index = items.indexOf(val);
if ( index != -1 ) {
items.splice(index, 1);
$.cookie(cookieName, $.toJSON(items), {expires: expireTime });
}
},
indexOf: function(val) {
return items.indexOf(val);
},
clear: function() {
items = null;
$.cookie(cookieName, null, { expires: expireTime });
},
items: function() {
return items;
},
length: function() {
return items.length;
},
join: function( separator ) {
return items.join(separator);
}
};
}
});
})(jQuery);
$(document).ready(function() {
$(".cabinet .error").append("*");
if($("#legend *").length==1){$("#legend").hide();}
if($("#keylock div").text().trim()==""){$("#keylock").hide();}
if($("#cabnotes div").text().trim()==""){$("#cabnotes").hide();}
if($("#sensors div").text().trim()==""){$("#sensors").hide();}
if($("fieldset[name=pdu] div").text().trim()==""){$("fieldset[name=pdu]").hide();}
$("#verifyaudit").click(function(e){
e.preventDefault();
$("#auditmodal").dialog({
width: 600,
modal: true,
buttons: {
Yes: function(e){
$.post("",{audit: "yes", cabinetid: ',$cab->CabinetID,', comments: $("#comments").val()}).done(function(data){
$("#lastaudit").html(data.AuditStamp+"<br>"+data.UserID).effect("highlight", {color: "lightgreen"}, 2500);
$("#auditmodal").dialog("destroy");
});
},
No: function(e){
$("#auditmodal").dialog("destroy");
}
},
close: function(){
$(this).dialog("destroy");
}
});
});
$("#verifydelete").click(function(e){
e.preventDefault();
$("#deletemodal").dialog({
width: 600,
modal: true,
draggable: false,
buttons: {
Yes: function(e){
$("#doublecheck").dialog({
width: 600,
modal: true,
draggable: false,
buttons: {
Yes: function(e){
// they are really sure they want to delete so do it
$.post("",{delete: "yes", cabinetid: ',$cab->CabinetID,'}).done(function(data){
location.href=data.url;
});
},
No: function(e){
$("#doublecheck").dialog("destroy");
$("#deletemodal").dialog("destroy");
}
},
close: function(){
$(this).dialog("destroy");
$("#deletemodal").dialog("destroy");
}
});
},
No: function(e){
$(this).dialog("destroy");
}
},
close: function(){
$(this).dialog("destroy");
}
});
});
';
if( $config->ParameterArray["ToolTips"]=='enabled' ){
?>
$('.cabinet div[id^="servercontainer"], #infopanel').on('mouseenter', 'div > div.genericdevice, div > div a > img, #zerou div > a', function(){
var lblbtn=$('.cabinet tr:first-child button + button');
var srctest=(typeof $(this).attr('src')==="undefined")?'css/blank.gif':$(this).attr('src');
if(srctest!='css/blank.gif'){
$(this).parents('div').children('div.label').hide();
}
var pos=$(this).offset();
var tooltip=$('<div />').css({
'left':pos.left+this.getBoundingClientRect().width+15+'px',
'top':pos.top+(this.getBoundingClientRect().height/2)-15+'px'
}).addClass('arrow_left border cabnavigator tooltip').attr('id','tt').append('<span class="ui-icon ui-icon-refresh rotate"></span>');
$.post('scripts/ajax_tooltip.php',{tooltip: $(this).data('deviceid'), dev: 1}, function(data){
tooltip.html(data);
});
$('body').append(tooltip);
$(this).mouseleave(function(){
if(!lblbtn.data('show')){
$(this).parents('div').children('div.label').show();
}
tooltip.remove();
});
});
<?php
}
if($config->ParameterArray["CDUToolTips"]=='enabled'){
?>
$('fieldset[name="pdu"] div > a').mouseenter(function(){
var pos=$(this).offset();
var tooltip=$('<div />').css({
'left':pos.left+$(this).outerWidth()+15+'px',
'top':pos.top+($(this).outerHeight()/2)-15+'px'
}).addClass('arrow_left border cabnavigator tooltip').attr('id','tt').append('<span class="ui-icon ui-icon-refresh rotate"></span>');
var id=$(this).attr('href');
id=id.substring(id.lastIndexOf('=')+1,id.length);
$.post('scripts/ajax_tooltip.php',{tooltip: id, cdu: 1}, function(data){
tooltip.html(data);
});
$('body').append(tooltip);
$(this).mouseleave(function(){
tooltip.remove();
});
});
<?php
}
?>
// This is gonna confuse the fuck out of me when I see this again
$('fieldset').wrap($('<div>').addClass('item').css('width','235px'));
$('#cabnotes').parent('div').css('width','470px');
$('#infopanel').css({'max-width':'480px','width':'480px'}).masonry();
$('#infopanel').masonry('option', { columnWidth: 240, itemSelector: '.item'});
$('#infopanel').masonry('layout');
$('#cabnotes > div').html($('#cabnotes > div').text());
// Add sensor data to the page
$('#sensors a:not([href$=Sensor])').each(function(){
var link=this;
$.get('api/v1/device/'+link.href.split('=').pop()+'/getsensorreadings',function(data){
if(!data.error){
$(link).after('<br>Temp: '+data.sensor.Temperature+'° Humidity: '+data.sensor.Humidity+'<br>');
}else{
$(link).after('<br>'+data.message+'<br>');
}
// When we add data to the box it grows so we need to adjust the bricks
$('#infopanel').masonry('layout');
});
});
});
</script>
<style type="text/css">
@page{size: <?php echo $config->ParameterArray['PageSize']; ?> portrait}
</style>
</head>
<body>
<?php include( 'header.inc.php' ); ?>
<div class="page">
<?php
include( "sidebar.inc.php" );
?>
<div class="main cabnavigator">
<div class="center"><div>
<div id="centeriehack">
<?php
echo $body;
?>
</div> <!-- END div#centeriehack -->
</div></div>
<?php
if($cab->ZoneID){
$zone=new Zone();
$zone->ZoneID=$cab->ZoneID;
$zone->GetZone();
echo '<a href="zone_stats.php?zone=',$zone->ZoneID,'">[ ',sprintf(__("Return to Zone %s"),$zone->Description),' ]</a><br>';
}
if ($cab->CabRowID) {
$cabrow=new CabRow();
$cabrow->CabRowID=$cab->CabRowID;
$cabrow->GetCabRow();
echo '<a href="rowview.php?row=',$cabrow->CabRowID,'">[ ',sprintf(__("Return to Row %s"),$cabrow->Name),' ]</a><br>';
}
?>
<?php echo '<a href="dc_stats.php?dc=',$dcID,'">[ ',sprintf(__("Return to %s"),$dc->Name),' ]</a>
<!-- hiding modal dialogs here so they can be translated easily -->
<div class="hide">
<div title="',__("Audit Confirmation"),'" id="auditmodal">
<div id="modaltext"><span style="float:left; margin:0 7px 20px 0;" class="ui-icon ui-icon-alert"></span>',__("Do you certify that you have completed an audit of this cabinet?"),'
<br><br><br>
<label for="comments">Comments:</label>
<br><br>
<textarea name="comments" id="comments" rows=8 cols=80></textarea>
</div>
</div>
<div title="',__("Cabinet delete confirmation"),'" id="deletemodal">
<div id="modaltext"><span style="float:left; margin:0 7px 20px 0;" class="ui-icon ui-icon-alert"></span>',__("Are you sure that you want to delete this cabinet and all the devices in it?"),'
<br><br>
</div>
</div>
<div title="',__("Are you REALLY sure?"),'" id="doublecheck">
<div id="modaltext" class="warning"><span style="float:left; margin:0 7px 20px 0;" class="ui-icon ui-icon-alert"></span>',__("Are you sure REALLY sure? There is no undo!!"),'
<br><br>
</div>
</div>
</div>'; ?>
</div> <!-- END div.main -->
<?php
if($person->CanWrite($cab->AssignedTo) || $person->SiteAdmin) {
echo '<div><input type="hidden" name="cabinetdraggable" id="cabinetdraggable" value="yes"></div>';
}
?>
<div class="clear"></div>
</div>
<script type="text/javascript">
$(document).ready(function() {
// Move the cabinet labels around
$('.cabnavigator div.picture > div.label > div').each(function(){
var offset=this.getBoundingClientRect().height;
var container=$(this).parents('.picture')[0].getBoundingClientRect().height;
$(this).parent('.label').css('top', (container-offset)/2/2);
});
// Don't attempt to open the datacenter tree until it is loaded
function opentree(){
if($('#datacenters .bullet').length==0){
setTimeout(function(){
opentree();
},500);
}else{
expandToItem('datacenters','cab<?php echo $cab->CabinetID;?>');
}
}
opentree();
// Combine the two racks into one table so the sizes are equal
if($('.cabinet + .cabinet').length >0){
var width=$('#centeriehack > .cabinet:first-child').width();
$('.cabinet tr > td:first-child').addClass('pos');
$('.cabinet + .cabinet').find('tr').each(function(i){
$(this).prepend($('#centeriehack > .cabinet:first-child').find('tr').eq(i).find('td, th'));
});
$('.cabinet td').each(function(){
$(this).css('width',($(this).hasClass('pos'))?'auto':'45%');
});
$('#centeriehack > .cabinet:first-child').remove();
$('.cabinet').width(width*2).css('max-width',width*2+'px');
}
// Damn translators not using abreviations
// This will lock the cabinet into the correct size
$('.cabinet #cabid').parent('tr').next('tr').find('.cabpos').css('padding','0px').wrapInner($('<div>').css({'overflow':'hidden','width':'30px'}));
});
<?php
if ( $config->ParameterArray["WorkOrderBuilder"]=='enabled' ) {
?>
var workOrder = $.fn.cookieList("workOrder");
// This is a shitty hack and we should do something better
if(!$.cookie('workOrder')){
workOrder.add(0);
}
function bindworkorder(obj){
obj.find('div.genericdevice, div a > img, .picture a > div').each(function(){
var devid=$(this).data('deviceid');
var target=(this.nodeName=="IMG"||this.parentNode.parentNode.parentNode.nodeName=="DIV")?this.parentElement.parentElement:this;
var clickpos=(this.parentNode.parentNode.className=="rotar_d")?' left: 0;':' right: 0;';
var style=(this.nodeName=="IMG")?'position: absolute; top: 0; background-color: white; z-index: 99;'+clickpos:'position: absolute; top: 2px; right: -4px; background-color: white; z-index: 99;';
// nested children needed a slight nudge for positions
if($('.picture').find('div[data-deviceid='+devid+']').length>0){
style=style.replace('2px','0px').replace('-4px','2px');
}
// move the chassis position to the opposite side, this looks dumb
if($(target).find('div:not(.label):not(.label > div)').length>0){
style=style.replace('right','left');
}
// Make a point for us to click to add to this nonsense
var span=$('<span>').attr('style',style).addClass('ui-icon');
span.addClass(($.parseJSON($.cookie('workOrder')).indexOf(devid)==-1)?'ui-icon-circle-plus':'ui-icon-circle-check');
// Bind the click action
span.on('click', function(){
sneaky.sneak();
flippyfloppy();
// reload the page to show the workorder button if it isn't showing
if(workOrder.items().length>1){
$('a[href="workorder.php"]').removeClass('hide');
}else{
$('a[href="workorder.php"]').addClass('hide');
}
});
function findall(devid){
var objects=[];
$('*[data-deviceid='+devid+']').each(function(){
if(this.nodeName=="IMG" || this.classList.contains('noimage')){
objects.push($(this).parent().parent().find('> span'));
}else{
objects.push($(this).find('span:not(.hlight)'));
}
});
return objects;
}
// Set the sign on the element according to if it is in the array or not
function flippyfloppy(){
if($.parseJSON($.cookie('workOrder')).indexOf(devid)==-1){
workOrder.add(devid);
var objects=findall(devid);
for(var i in objects){
objects[i].addClass('ui-icon-circle-check').removeClass('ui-icon-circle-plus');
}
}else{
workOrder.remove(devid);
var objects=findall(devid);
for(var i in objects){
objects[i].removeClass('ui-icon-circle-check').addClass('ui-icon-circle-plus');
}
}
}
// Add the click target to the page
$(target).append(span);
});
}
<?php
}
?>
</script>
</body>
</html>