-
Notifications
You must be signed in to change notification settings - Fork 3
/
viewDevice.php
356 lines (322 loc) · 16 KB
/
viewDevice.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
<?php
session_start();
include "class/db.class.php";
if(isset($_GET['deviceID']) && !isset($_GET['action']) && is_numeric($_GET['deviceID']))
{
// we need custom close links depdending if we're showing this in a modal or embedded
if(isset($_GET['close']) && $_GET['close']=='min')
$closeString='<a href="#" onclick="$(\'#deviceHolder\').hide();$(\'#deviceMiniMap\').hide();$(\'#deviceManagement\').hide();$(\'#deviceSearchResults\').slideDown(500);" class="closeDOMWindow closeLink"><img src="images/icons/close_module.gif" border="0" alt="Close" /></a>';
else
$closeString='<a href="#" class="closeLink closeDOMWindow"><img src="images/icons/close_module.gif" border="0" alt="Close" /></a>';
$device = new device($_GET['deviceID']);
// get the attributes for the device and some other details for use later
$device->fillCategories(1,1);
// get the owner of this device which we use later
$owner = new owner($device->ownerID);
$categoriesClass = new attrcategories;
$listOfCategories=$categoriesClass->getAll();
if(!$device)
{
?>
<div <?php if(isset($_GET['close']) && $_GET['close']=="min") { echo "class='module' "; }?>id="viewDevice" >
<strong>Error</strong>
<?php echo $closeString;?>
<br/><font color="red" >Unable to find the device you requested.<br/>Please refresh the page and try again.</font>
</div>
<?php
exit();
}
?>
<div id="viewDevice" >
<div class="sectionHeader" >
<strong><?php echo $device->name; ?></strong>
<?php echo $closeString; ?>
</tr></table>
</div>
<div class="categoryData" >
<table class="formTable">
<colgroup class="tblfirstRow"></colgroup>
<tr><td align="right" width="150px">Hostname:</td><td width="200px;"><?php echo $device->name; ?></td>
<td rowspan="4" valign="top">
<?php
$emptyTraits=false;
foreach($device->categories as $key=>$cat)
{
if(empty($cat) && !($key==HAS_NETWORK_PORTS||$key==IS_PATCH))
$emptyTraits.= "<li>".$listOfCategories[$key]->name."</li>";
}
if($emptyTraits)
echo '<strong>Generic Traits</strong><ul>'.$emptyTraits.'</ul>';
?>
</td></tr>
<tr><td align="right">Model:</td><td><?php
if(isset($device->categories[1][12]))
echo $device->categories[1][12]->value." ";
if(isset($device->categories[1][42]))
echo $device->categories[1][42]->value;
?></td></tr>
<tr><td align="right">Owner:</td><td><?php echo $owner->name; ?></td></tr>
<tr><td align="right">Parent:</td><td><?php
if($device->parentName!="")
echo $device->parentName;
else
echo $device->parentType;
?></td></tr>
</table>
<?php
// Get all the attributes associated with this device
$names = new attrnames;
/*echo "<pre>";
print_r($device->categories);
echo "</pre>";*/
foreach($listOfCategories as $category)
{
// if cat does exist, isn't network related and is empty we want to skip it.
if(empty($device->categories[$category->attrcategoryid]) && !($category->attrcategoryid==HAS_NETWORK_PORTS||$category->attrcategoryid==IS_PATCH))
continue;
// check to see if the device has this category
// if not we want to continue to the next
if(isset($device->categories[$category->attrcategoryid]))
echo "<div id='category".$category->attrcategoryid."' >";
else
continue;
?>
<strong style="display:block;padding:5px;"><?php echo $category->name; ?></strong>
<table class="formTable" cellpadding="5">
<colgroup class="tblfirstRow"></colgroup>
<?php
// pickup the custom forms for ports and patches
switch($category->attrcategoryid)
{
case HAS_NETWORK_PORTS:
echo "<tr><td colspan='2'>";
$portsClass = new ports;
$portsClass->showPorts($device->deviceID);
echo "</td></tr>";
$attributesfound = true;
break;
case IS_PATCH:
echo "<tr><td colspan='2'><strong>Patch Ports:</strong>";
$joins = new joins;
$joins->showPatchFull($device->deviceID);
echo "</td></tr>";
$attributesfound = true;
break;
}
// we now have 2 lists of categories
// list of categories contains everything
// template->category[<catID>][<nameID>]-> contains registered values
foreach($names->getByParent($category->attrcategoryid, 'attrcategory') as $name)
{
$itemName="";
$itemValue="";
// display the title, hide it if the internal list of values doesnt exist (value isnt set)
if(isset($device->categories[$category->attrcategoryid]) && is_array($device->categories[$category->attrcategoryid]))
{
$itemName="name".$name->attrnameid;
// as the item may be from a template and now actually associated with this device
// we need to check it has a value before we go ahead to set it
if(isset($device->categories[$category->attrcategoryid][$name->attrnameid]->value))
$itemValue=$device->categories[$category->attrcategoryid][$name->attrnameid]->value;
}
echo "<tr><td width='150px' align='right'>".$name->name."</td><td>";
// Values that already exist we name differently in the form
// existing<attrvalueid> so we can simply update the existing record (or delete as needed)
// new values all get named name<attrnameid>
switch ($name->type)
{
case "Textbox":
case "Date":
case "Text Area":
case "Checkbox":
case "Checkbox List":
case "Dropdown List":
case "Radio Buttons":
echo $itemValue;
break;
case "Number":
if($itemValue)
echo $itemValue." ".$name->units;
break;
case "File":
$hasFileUpload=1;
break;
case "Image":
$hasFileUpload=1;
break;
}
echo "</td></tr>";
}
echo "</table></div>";
}
echo "</div>";
/*
echo "<table width='80%' ><tr><td> ";
// Display options for a device / switch
if($device->deviceTypeID != 7)
{
$ports = new ports;
$ports = $ports->getByDevice($device->deviceID);
if(count($ports) > 0)
{
$i=0;
echo "<div class='patchPanel' ><ul class='devicePorts' >";
foreach($ports as $port)
{
echo "<li class='port'>";
if($port->connectedToPortID >0)
echo "<a class='connected' >";
elseif(isset($port->cableID) && $port->cableID > 0 && $device->deviceTypeID!=7)
echo "<a class='singleconnected' >";
else
echo "<a class='disconnected' >";
echo ($i+1);
$i++;
if($port->connectedToPortID >0)
{
echo "<strong style='display:none;'>";
echo "Connected to ".$port->connectedToDeviceName." » ".$port->connectedToPortName;
echo "</strong>";
}
elseif($port->cableID >0)
{
echo "<strong style='display:none;'>";
echo "Cable only connected at this end";
echo "</strong>";
}
echo '</li>';
}
echo "</ul></div>";
echo "</td></tr>
<tr><td><div class='hoverMenu' ></div>";
}
else
echo "This device has no ports";
}
else
{
$joins = new joins;
$joins = $joins->getByDevice($device->deviceID);
if(count($joins) > 0)
{
$i=0;
echo "<div class='patchPanel' ><ul class='devicePorts' >";
foreach($joins as $join)
{
echo "<li class='port'>";
if($join->primPort >0 && $join->secPort > 0)
echo "<a class='connected' >";
elseif($join->primPort > 0)
echo "<a class='singleconnected' >";
elseif($join->secPort > 0)
echo "<a class='singleconnected' >";
else
echo "<a class='disconnected' >";
echo ($i+1);
$i++;
if($join->primPort >0 && $join->secPort > 0)
{
echo "<strong style='display:none;'>";
echo "Front connected to ".$join->primConnectedToDeviceName." Port ".$join->primConnectedToPortName."<br/>";
echo "Back connected to ".$join->secConnectedToDeviceName." Port ".$join->secConnectedToPortName;
echo "</strong>";
}
else if($join->primPort >0)
{
echo "<strong style='display:none;'>";
echo "Front connected to ".$join->primConnectedToDeviceName." Port ".$join->primConnectedToPortName."<br/>";
echo "</strong>";
}
else if($join->secPort >0)
{
echo "<strong style='display:none;'>";
echo "Back connected to ".$join->secConnectedToDeviceName." Port ".$join->secConnectedToPortName."<br/>";
echo "</strong>";
}
echo '</li>';
}
echo "</ul></div>";
echo "</td></tr>
<tr><td><div class='hoverMenu' ></div>";
}
else
echo "This patch panel has no ports - system error?";
}
echo "</td></tr></table>";
echo "</div></td></tr></table>";*/
}
elseif(isset($_GET['action']) && $_GET['action']=="deviceMenu" && isset($_GET['deviceID']) && is_numeric($_GET['deviceID']))
{
$device=new device($_GET['deviceID']);
$device->fillCategories(1,1,GENERIC,HAS_NETWORK_PORTS,IS_PATCH);
?>
<div class='popupMenu' style='float:left;'>
<div class='title'>
<table onclick="$('#deviceDetails').slideToggle('normal');$('#portsAttach').hide();">
<thead><tr>
<th width='100%'><?php echo $device->name; ?></th>
<th onclick='$("#menus").fadeOut("fast",function() { $("#menus").html(""); });deviceMenu=false;' >
<img src="images/icons/close_rack.gif" border="0" alt="Close">
</th>
</tr></thead>
</table>
</div>
<div class='desc' ><table><tr><td width='100%' valign='bottom'>
<?php
if(isset($device->categories[GENERIC][12]->value) || isset($device->categories[HAS_OS][28]->value))
echo "<strong>Details</strong><br/>";
if(isset($device->categories[GENERIC][12]) && isset($device->categories[GENERIC][12]->value))
echo "Model: ".$device->categories[GENERIC][12]->value." ".$device->categories[GENERIC][42]->value;
if(isset($device->categories[HAS_OS][28]) && isset($device->categories[HAS_OS][28]->value))
echo "OS: ".$device->categories[HAS_OS][28]->value." ".$device->categories[HAS_OS][29]->value;
echo "<br/><a href='#".$device->deviceID."' class='moreDeviceDetails' >View Configuration</a></td>
<td align='right' valign='top'><a href='#".$device->deviceID."' class='editDevice' >[Edit]</a><br/>";
//if(deviceInfo.uploads==1)
// menu += "<a href='#"+deviceID+"device' class='manageAttachments' >[Files]</a><br/>";
echo "<a href='#".$device->deviceID."' class='deleteDevice' >[Delete]</a><br/>
<a href='#".$device->deviceID."' class='upgradeDevice' >[Upgrade]</a></div><br/>
</td></tr></table></div>";
if(isset($device->categories[IS_PATCH]))
{
echo "<div class='subtitle' style='cursor:pointer;border-bottom:0px;' onclick=\"$('.patchPanel').slideToggle('fast');return false;\">
<table><thead><tr><th align='left'>Patches</th></tr></thead></table></div>
<div class='patchPanel' >";
$joins = new joins;
$joins->showPatchFull($device->deviceID,1,8);
echo "</div>";
}
if(isset($device->categories[HAS_NETWORK_PORTS]))
{
echo "<div class='subtitle' style='cursor:pointer;border-bottom:0px;' onclick=\"$('.devicePorts').slideToggle('fast');return false;\">
<table style='border-bottom:0px;'><thead><tr><th align='left'>Ports</th></tr></thead></table></div>
<div class='devicePorts' >";
$ports = new ports;
$ports->showPorts($device->deviceID,0,5);
echo "</div>";
}
?>
<div class='title subtitle devicePortSummary' id='hoverMenu' style='display:none;'></div>
</div>
<div id='cableConnectionMenu' class='popupMenu' style="display:none;">
<div class='subtitle' >
<table>
<thead><tr>
<th width="100%" >Cable Management</strong></th>
<th align="right"><img onclick="$('#cableConnectionMenu').fadeOut('fast');" src='images/icons/slide_left.gif' border='0' alt='Close Cable Menu'></th>
</tr></thead>
</table>
</div>
<div class='navMenu' >
<table cellpadding="2" cellspacing="0">
<tr>
<td id="backText" style="border-right: 1px solid #000000;">< Previous</td>
<td id="currentTitle">Minimap Name</td>
</tr>
</table>
</div>
<div id='displayArea' class='popupMenu'>displayArea
</div>
</div>
<?php
}
?>