forked from opendcim/openDCIM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rackrequest.php
498 lines (449 loc) · 19.1 KB
/
rackrequest.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
<?php
require_once "db.inc.php";
require_once "facilities.inc.php";
$subheader=__("Data Center Rack Request");
if($config->ParameterArray["RackRequests"] != "enabled" || !$person->RackRequest){
// No soup for you.
header('Location: '.redirect());
exit;
}
$Dept=new Department();
$cab=new Cabinet();
$dev=new Device();
$req=new RackRequest();
$contact=new People();
$tmpContact=new People();
$formfix=$error='';
$contactList=$person->GetUserList();
# defaulting to None
$validHypervisors=array( "None", "ESX", "ProxMox");
//We only need to worry about sending email in the event this is a new submission and no other time.
if(isset($_POST["action"])){
if(isset($_REQUEST['requestid']) && $_REQUEST['requestid'] >0){
$req->RequestID=$_REQUEST['requestid'];
$req->GetRequest();
$contact->PersonID=$req->RequestorID;
$contact->GetPerson();
}
$tmpContact->PersonID=$_POST["requestorid"];
$tmpContact->GetPerson();
$mail = new DCIMMail(true);
$mail->addAddress($tmpContact->Email);
$mail->addAddress($config->ParameterArray['MailToAddr']);
$mail->addAttachment( $config->ParameterArray["PDFLogoFile"], "logo.png" );
$htmlMessage='<!doctype html><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>ITS Data Center Inventory</title></head><body><div id="header" style="padding: 5px 0;background: '.$config->ParameterArray["HeaderColor"].';"><center><img src="'.$logo.'"></center></div><div class="page"><p><h3>'.__("ITS Facilities Rack Request").'</h3>'."\n";
if($_POST['action'] == 'Create'){
$req->RequestorID=$_POST['requestorid'];
$req->RequestedAction=$_POST['requestedaction'];
$req->Label=$_POST['label'];
$req->SerialNo=$_POST['serialno'];
$req->MfgDate=$_POST['mfgdate'];
$req->AssetTag=$_POST['assettag'];
$req->Hypervisor=$_POST['hypervisor'];
$req->Owner=$_POST['owner'];
$req->DeviceHeight=$_POST['deviceheight'];
$req->EthernetCount=$_POST['ethernetcount'];
$req->VLANList=$_POST['vlanlist'];
$req->SANCount=$_POST['sancount'];
$req->SANList=$_POST['sanlist'];
$req->DeviceClass=$_POST['deviceclass'];
$req->DeviceType=$_POST['devicetype'];
$req->LabelColor=$_POST['labelcolor'];
$req->CurrentLocation=$_POST['currentlocation'];
$req->SpecialInstructions=$_POST['specialinstructions'];
$req->CreateRequest();
$contact->PersonID=$req->RequestorID;
$contact->GetPerson();
$htmlMessage.="<p>".sprintf(__('Your request for racking up the device labeled %1$s has been received.
The Network Operations Center will examine the request and contact you if more information is needed
before the request can be processed. You will receive a notice when this request has been completed.
Please allow up to 2 business days for requests to be completed.'),$req->Label)."</p>
<p>".sprintf(__('Your Request ID is %1$d and you may view the request online at'),$req->RequestID)."
<a href=\"https://{$_SERVER['SERVER_NAME']}{$_SERVER['SCRIPT_NAME']}?requestid=$req->RequestID\">
".__("this link")."</a>.</p>
</body></html>";
$mail->Body = $htmlMessage;
try {
$mail->send();
} catch (Exception $e) {
error_log( "Mailer error: {$mail->ErrorInfo}" );
}
}elseif(($_POST['action']=='Update Request'||$_POST['action']=='Move to Rack') && (($person->RackRequest && $person->UserID==$contact->UserID)||$person->RackAdmin)){
$req->RequestorID=$_POST['requestorid'];
$req->RequestedAction=$_POST['requestedaction'];
$req->Label=$_POST['label'];
$req->SerialNo=$_POST['serialno'];
$req->MfgDate=date('Y-m-d',strtotime($_POST["mfgdate"]));
$req->AssetTag=$_POST['assettag'];
$req->Hypervisor=$_POST['hypervisor'];
$req->Owner=$_POST['owner'];
$req->DeviceHeight=$_POST['deviceheight'];
$req->EthernetCount=$_POST['ethernetcount'];
$req->VLANList=$_POST['vlanlist'];
$req->SANCount=$_POST['sancount'];
$req->SANList=$_POST['sanlist'];
$req->DeviceClass=$_POST['deviceclass'];
$req->DeviceType=$_POST['devicetype'];
$req->LabelColor=$_POST['labelcolor'];
$req->CurrentLocation=$_POST['currentlocation'];
$req->SpecialInstructions=$_POST['specialinstructions'];
$req->UpdateRequest();
if($person->RackAdmin && $_POST['action']=='Move to Rack'){
$req->CompleteRequest();
$dev->Label=$req->Label;
$dev->SerialNo=$req->SerialNo;
$dev->MfgDate=$req->MfgDate;
$dev->InstallDate=date('Y-m-d');
$dev->AssetTag=$req->AssetTag;
$dev->Hypervisor=$req->Hypervisor;
$dev->Owner=$req->Owner;
$dev->Cabinet=$_POST['CabinetID'];
$dev->Position=$_POST['position'];
$dev->Height=$req->DeviceHeight;
$dev->Ports=$req->EthernetCount;
$dev->DeviceType=$req->DeviceType;
$dev->TemplateID=$req->DeviceClass;
$dev->CreateDevice();
$htmlMessage.="<p>".sprintf(__('Your request for racking up the device labeled %1$s has been completed.'),$req->Label)."</p>";
$htmlMessage.="<p>".sprintf(__('To view your device in its final location click %1$s'),
"<a href=\"".redirect("devices.php?DeviceID=$dev->DeviceID")."\"> ".__("this link")."</a>.</p>
</body></html>");
$mail->Body = $htmlMessage;
try {
$mail->send();
} catch (Exception $e) {
error_log( "Mailer error: {$mail->ErrorInfo}" );
}
header('Location: '.redirect("devices.php?DeviceID=$dev->DeviceID"));
exit;
}
}elseif($_POST['action']=='Delete Request'){
if($person->RackAdmin||$person->UserID==$contact->UserID){
$req->DeleteRequest();
header('Location: '.redirect('index.php'));
exit;
}else{
// This should never be hit under normal circumstatnces.
$error.=__("You do not have permission to delete this request");
}
}
}
// If requestid is set we are either looking up a request or performing an action on one already. Refresh the object from the DB
if(isset($_REQUEST['requestid']) && $_REQUEST['requestid']>0){
$req->RequestID=$_REQUEST['requestid'];
$req->GetRequest();
$formfix="?requestid=$req->RequestID";
$contact->PersonID=$req->RequestorID;
$contact->GetPerson();
}
// When opening a new request, set the default value for the "Requestor" field's <select> to the logged in person
if(!isset($contact->UserID) && !isset($_POST["action"])){
$contact = $person;
}
?>
<!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>openDCIM Facilities Cabinet Maintenance</title>
<link rel="stylesheet" href="css/inventory.php" type="text/css">
<link rel="stylesheet" href="css/jquery-ui.css" type="text/css">
<link rel="stylesheet" href="css/validationEngine.jquery.css" type="text/css">
<!--[if lt IE 9]>
<link rel="stylesheet" href="css/ie.css" type="text/css">
<![endif]-->
<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.validationEngine-en.js"></script>
<script type="text/javascript" src="scripts/jquery.validationEngine.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$(function(){
<?php
print " $('#deviceform').validationEngine({'custom_error_messages' : {
'#vlanlist' : {
'condRequired': {
'message': '".__("You must specify the VLAN information for the ethernet connections").".'
}
},
'#sanlist' : {
'condRequired': {
'message': '".__("You must specify the SAN port information to continue").".'
}
},
'#currentlocation' : {
'required': {
'message': '".__("You must specify the current location of the equipment").".'
}
}
}
});";
?>
$('#mfgdate').datepicker({dateFormat: "yy-mm-dd"});
$('#deviceclass').change( function(){
$.get('scripts/ajax_template.php?q='+$(this).val(), function(data) {
$('#deviceheight').val(data['Height']);
$('#devicetype').val(data['DeviceType']);
});
});
});
// Disable the form validation so that the delete button will work
$('input[value|="Delete Request"]').click(function(){
$('#deviceform').validationEngine('detach');
});
<?php
if($person->RackAdmin && ($req->RequestID>0)){
?>
$('#position').focus(function() {
var cab=$("select#CabinetID").val();
$.get('scripts/ajax_cabinetuse.php?cabinet='+cab, function(data) {
var ucount=0;
$.each(data, function(i,inuse){
ucount++;
});
var rackhtmlleft='';
var rackhtmlright='';
for(ucount=ucount; ucount>0; ucount--){
if(data[ucount]){var cssclass='notavail'}else{var cssclass=''};
rackhtmlleft+='<div>'+ucount+'</div>';
rackhtmlright+='<div val='+ucount+' class="'+cssclass+'"></div>';
}
var rackhtml='<div class="table border positionselector"><div><div>'+rackhtmlleft+'</div><div>'+rackhtmlright+'</div></div></div>';
$('#Positionselector').html(rackhtml);
setTimeout(function(){
var divwidth=$('.positionselector').width();
$('#Positionselector').width(divwidth);
$('#CabinetID').focus(function(){$('#Positionselector').css({'left': '-1000px'});});
$('#specialinstructions').focus(function(){$('#Positionselector').css({'left': '-1000px'});});
$('#Positionselector').css({'left':(($('#position').position().left)+(divwidth+20))});
$('#Positionselector').mouseleave(function(){
$('#Positionselector').css({'left': '-1000px'});
});
$('.positionselector > div > div + div > div').mouseover(function(){
$('.positionselector > div > div + div > div').each(function(){
$(this).removeAttr('style');
});
var unum=$("#deviceheight").val();
if(unum>=1 && $(this).attr('class')!='notavail'){
var test='';
var background='green';
// check each element start with pointer
for (var x=0; x<unum; x++){
if(x!=0){
test+='.prev()';
eval("if($(this)"+test+".attr('class')=='notavail' || $(this)"+test+".length ==0){background='red';}");
}else{
if($(this).attr('class')=='notavail'){background='red';}
}
}
test='';
if(background=='red'){var pointer='default'}else{var pointer='pointer'}
for (x=0; x<unum; x++){
if(x!=0){
test+='.prev()';
eval("$(this)"+test+".css({'background-color': '"+background+"'})");
}else{
$(this).css({'background-color': background, 'cursor': pointer});
if(background=='green'){
$(this).click(function(){
$('#position').val($(this).attr('val'));
$('#Positionselector').css({'left': '-1000px'});
});
}
}
}
}
});
},100);
});
});
<?php
}
?>
});
</script>
</head>
<body>
<?php include( 'header.inc.php' ); ?>
<div class="page request">
<?php
include('sidebar.inc.php');
echo '<div class="main">';
if($error!=""){echo '<fieldset class="exception border error"><legend>Errors</legend>'.$error.'</fieldset>';}
echo '<div class="center"><div>
<div id="Positionselector"></div>
<form name="deviceform" id="deviceform" action="',$_SERVER["SCRIPT_NAME"],$formfix,'" method="POST">
<input type="hidden" name="requestid" value="',$req->RequestID,'">';
echo '<div class="table">
<div>
<div><label for="requestorid">',__("Requestor"),'</label></div>
<div>
<select name="requestorid" id="requestorid">';
foreach($contactList as $tmpContact){
if($tmpContact->UserID==$contact->UserID){$selected=" selected";}else{$selected="";}
print " <option value=\"$tmpContact->PersonID\"$selected>$tmpContact->LastName, $tmpContact->FirstName</option>";
}
echo ' </select>
</div>
</div>';
if(isset($config->ParameterArray['RackRequestsActions']) && $config->ParameterArray['RackRequestsActions'] == 'enabled') {
echo '
<div>
<div><label for="requestedaction">',__("Action").'</label></div>
<div>
<select name="requestedaction" id="requestedaction" class="validate[required]">
<option value="">',__("Select"),'...</option>
<option value="new" ',($req->RequestedAction == "new" ? "selected" : ""),'>',__("New"),'</option>
<option value="move" ',($req->RequestedAction == "move" ? "selected" : ""),'>',__("Move"),'</option>
<option value="change" ',($req->RequestedAction == "change" ? "selected" : ""),'>',__("Change"),'</option>
<option value="retire" ',($req->RequestedAction == "retire" ? "selected" : ""),'>',__("Retire"),'</option>
</select>
</div>
</div>
';
} else {
echo '
<input type="hidden" name="requestedaction" value="',$req->RequestedAction,'" />
';
}
echo '
<div>
<div><label for="label">',__("Label").'</label></div>
<div><input type="text" name="label" id="label" class="validate[required,minSize[3],maxSize[50]]" size="50" value="',$req->Label,'"></div>
</div>
<div>
<div><label for="labelcolor">',__("Label Color").'</label></div>
<div>
<select name="labelcolor" id="labelcolor">';
foreach(array(__("White"),__("Yellow"),__("Red")) as $colorCode){
if($req->LabelColor==$colorCode){$selected=' selected';}else{$selected='';}
print " <option value=\"$colorCode\"$selected>$colorCode</option>\n";
}
echo ' </select>
</div>
</div>
<div>
<div><label for="serialno">',__("Serial Number"),'</label></div>
<div><input type="text" name="serialno" id="serialno" class="validate[required]" size="50" value="',$req->SerialNo,'"></div>
</div>
<div>
<div><label for="mfgdate">',__("Manufacture Date"),'</label></div>
<div><input type="text" name="mfgdate" id="mfgdate" size="20" value="',date('Y-m-d',strtotime($req->MfgDate)),'"></div>
</div>
<div>
<div><label for="assettag">',__("Asset Tag"),'</label></div>
<div><input type="text" name="assettag" id="assettag" size="20" value="',$req->AssetTag,'"></div>
</div>
<div>
<div><label for="Hypervisor">',__("Hypervisor?"),'</label></div>
<div><select name="hypervisor" id="hypervisor">';
foreach($validHypervisors as $h){
$selected=($req->Hypervisor==$h)?" selected":"";
print "\t\t\t<option value=\"$h\" $selected>$h</option>\n";
}
echo '
</select></div>
</div>
<div>
<div><label for="owner">',__("Departmental Owner"),'</label></div>
<div>
<select name="owner" id="owner" class="validate[required]">
<option value=0>',__("Unassigned"),'</option>';
$deptList = $Dept->GetDepartmentList();
foreach($deptList as $deptRow){
if($req->Owner==$deptRow->DeptID){$selected=' selected';}else{$selected='';}
print " <option value=\"$deptRow->DeptID\"$selected>$deptRow->Name</option>\n";
}
echo ' </select>
</div>
</div>
<div>
<div><label for="deviceclass">',__("Device Class"),'</label></div>
<div>
<select name="deviceclass" id="deviceclass">
<option value=0>',__("Select a template"),'...</option>';
$templ=new DeviceTemplate();
$templateList=$templ->GetTemplateList();
$mfg=new Manufacturer();
foreach($templateList as $tempRow){
if($req->DeviceClass==$tempRow->TemplateID){$selected = ' selected';}else{$selected = '';}
$mfg->ManufacturerID=$tempRow->ManufacturerID;
$mfg->GetManufacturerByID();
print " <option value=\"$tempRow->TemplateID\"$selected>$mfg->Name - $tempRow->Model</option>\n";
}
echo ' </select>
</div>
</div>
<div>
<div><label for="deviceheight">',__("Height"),'</label></div>
<div><input type="text" name="deviceheight" id="deviceheight" class="validate[required,custom[onlyNumberSp]]" size="15" value="',$req->DeviceHeight,'"></div>
</div>
<div>
<div><label for="ethernetcount">',__("Number of Ethernet Connections"),'</label></div>
<div><input type="text" name="ethernetcount" id="ethernetcount" class="validate[optional,custom[onlyNumberSp],min[1]]" size="15" value="'.(($req->EthernetCount!=0) ? $req->EthernetCount : '').'"></div>
</div>
<div>
<div><label for="vlanlist">',__("VLAN Settings"),'<span>(ie - eth0 on 973, eth1 on 600)</span></label></div>
<div><input type="text" name="vlanlist" id="vlanlist" class="validate[condRequired[ethernetcount]]" size="50" value="',$req->VLANList,'"></div>
</div>
<div>
<div><label for="sancount">',__("Number of SAN Connections"),'</label></div>
<div><input type="text" name="sancount" id="sancount" class="validate[optional,custom[onlyNumberSp],min[1]]" size="15" value="'.(($req->SANCount!=0) ? $req->SANCount : '').'"></div>
</div>
<div>
<div><label for="sanlist">',__("SAN Port Assignments"),'</label></div>
<div><input type="text" name="sanlist" id="sanlist" class="validate[condRequired[sancount]]" size="50" value="',$req->SANList,'"></div>
</div>
<div>
<div><label for="devicetype">',__("Device Type"),'</label></div>
<div>
<select name="devicetype" id="devicetype" class="validate[required]">
<option value=0>',__("Select"),'...</option>
<option value="Server"'.(($req->DeviceType=="Server")?' selected':'').'>',__("Server"),'</option>
<option value="Appliance"'.(($req->DeviceType=="Appliance")?' selected':'').'>',__("Appliance"),'</option>
<option value="Storage Array"'.(($req->DeviceType=="Storage Array")?' selected':'').'>',__("Storage Array"),'</option>
<option value="Switch"'.(($req->DeviceType=="Switch")?' selected':'').'>',__("Switch"),'</option>
<option value="Chassis"'.(($req->DeviceType=="Chassis")?' selected':'').'>',__("Chassis"),'</option>
<option value="Patch Panel"'.(($req->DeviceType=="Patch Panel")?' selected':'').'>',__("Patch Panel"),'</option>
<option value="Physical Infrastructure"'.(($req->DeviceType=="Physical Infrastructure")?' selected':'').'>',__("Physical Infrastructure"),'</option>
</select>
</div>
</div>
<div>
<div><label for="currentlocation">',__("Current Location"),'</label></div>
<div><input type="text" name="currentlocation" id="currentlocation" class="validate[required]" size="50" value="',$req->CurrentLocation,'"></div>
</div>
<div>
<div><label for="specialinstructions">',__("Special Instructions"),'</label></div>
<div><textarea name="specialinstructions" id="specialinstructions" cols=50 rows=5>',$req->SpecialInstructions,'</textarea></div>
</div>';
if($person->RackAdmin && ($req->RequestID>0)){
echo '<div><div><label for="CabinetID">',__("Select Rack Location"),':</label></div><div>'.$cab->GetCabinetSelectList().' <label for="position">',__("Position"),':</label> <input type="text" name="position" id="position" size=5></div></div>';
}
?>
<div class="caption">
<?php
if($person->RackRequest||$person->RackAdmin){
if($req->RequestID >0){
if($person->RackAdmin||($person->UserID==$contact->UserID)){
echo '<button type="submit" name="action" value="Update Request">',__("Update Request"),'</button>';
echo '<button type="submit" name="action" value="Delete Request">',__("Delete Request"),'</button>';
}
if($person->RackAdmin){
echo '<button type="submit" name="action" value="Move to Rack">',__("Move to Rack"),'</button>';
}
}else{
echo '<button type="submit" name="action" value="Create">',__("Create"),'</button>';
}
}
?>
</div>
</div> <!-- END div.table -->
</form>
</div></div>
<?php echo '<a href="index.php">[ ',__("Return to Main Menu"),' ]</a>'; ?>
</div> <!-- END div.main -->
</div> <!-- END div.page -->
</body>
</html>