Skip to content

Commit 12bb259

Browse files
committed
Merge pull request phpipam#327 from phpipam/master
Added l2 domain info phpipam#286
2 parents 7b4f9cb + 3638190 commit 12bb259

File tree

6 files changed

+44
-5
lines changed

6 files changed

+44
-5
lines changed

app/subnets/subnet-details.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@
6363

6464
if(!empty($vlan['name'])) { print ' - '.$vlan['name']; } //Print name if provided
6565
if(!empty($vlan['description'])) { print ' ['. $vlan['description'] .']'; } //Print description if provided
66+
// domain
67+
$l2domain = $Tools->fetch_object("vlanDomains", "id", $vlan['domainId']);
68+
if($l2domain!==false) { print " <span class='badge badge1 badge5' rel='tooltip' title='VLAN is in domain $l2domain->name'>$l2domain->name "._('Domain')." </span>"; }
6669
?>
6770
</td>
6871
</tr>

app/vlan/vlan-details.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@
3232
<?php print $vlan['name']; ?>
3333
</td>
3434
</tr>
35+
<tr>
36+
<th><?php print _('Domain'); ?></th>
37+
<td>
38+
<?php
39+
// domain
40+
$l2domain = $Tools->fetch_object("vlanDomains", "id", $vlan['domainId']);
41+
if($l2domain!==false) { print $l2domain->name; }
42+
?>
43+
</td>
44+
</tr>
3545
<tr>
3646
<th><?php print _('Description'); ?></th>
3747
<td><?php print $vlan['description']; ?></td>

css/1.2/bootstrap/bootstrap-custom.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,9 @@ td#actions .btn-group .btn {
315315
.badge.badge4 {
316316
cursor: default;
317317
}
318+
.badge.badge5 {
319+
padding: 2px 6px;
320+
}
318321
ul.submenu-dns {
319322
line-height: 14px;
320323
padding: 3px;

functions/classes/class.Sections.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ private function get_all_section_and_subsection_ids ($id) {
328328
*/
329329
public function fetch_section_vlans ($sectionId) {
330330
# set query
331-
$query = "select distinct(`v`.`vlanId`),`v`.`name`,`v`.`number`, `v`.`description` from `subnets` as `s`,`vlans` as `v` where `s`.`sectionId` = ? and `s`.`vlanId`=`v`.`vlanId` order by `v`.`number` asc;";
331+
$query = "select distinct(`v`.`vlanId`),`v`.`name`,`v`.`number`,`v`.`domainId`, `v`.`description` from `subnets` as `s`,`vlans` as `v` where `s`.`sectionId` = ? and `s`.`vlanId`=`v`.`vlanId` order by `v`.`number` asc;";
332332
# fetch
333333
try { $vlans = $this->Database->getObjectsQuery($query, array($sectionId)); }
334334
catch (Exception $e) {

functions/classes/class.Subnets.php

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2155,6 +2155,8 @@ public function print_subnets_menu( $user, $section_subnets, $rootId = 0 ) {
21552155
public function print_vlan_menu( $user, $vlans, $sectionId ) {
21562156
# initialize html array
21572157
$html = array();
2158+
# tools
2159+
$Tools = new Tools($this->Database);
21582160
# must be numeric
21592161
if(isset($_GET['section'])) if(!is_numeric($_GET['section'])) { $this->Result->show("danger",_("Invalid ID"), true); }
21602162
if(isset($_GET['subnetId'])) if(!is_numeric($_GET['subnetId'])) { $this->Result->show("danger",_("Invalid ID"), true); }
@@ -2181,9 +2183,18 @@ public function print_vlan_menu( $user, $vlans, $sectionId ) {
21812183
$leafClass="fa-gray";
21822184
}
21832185

2186+
# domain
2187+
$item['l2domain'] = "";
2188+
if($item['domainId']!=1) {
2189+
$domain = $Tools->fetch_object("vlanDomains", "id", $item['domainId']);
2190+
if ($domain!==false) {
2191+
$item['l2domain'] = " <span class='badge badge1 badge5' rel='tooltip' title='VLAN is in domain $domain->name'>$domain->name</span>";
2192+
}
2193+
}
2194+
21842195
# new item
21852196
$html[] = '<li class="folder folder-'.$open.' '.$active.'"><i class="fa fa-gray fa-folder-'.$open.'-o" rel="tooltip" data-placement="right" data-html="true" title="'._('VLAN contains subnets').'.<br>'._('Click on folder to open/close').'"></i>';
2186-
$html[] = '<a href="proxy.php?url=https%3A%2F%2Fgithub.com.%2F%3C%2Fspan%3E%27%3C%2Fspan%3E.%3Cspan+class%3D"pl-en">create_link("vlan",$sectionId,$item['vlanId']).'" rel="tooltip" data-placement="right" title="'.$item['description'].'">'.$item['number'].' ('.$item['name'].')</a>';
2197+
$html[] = '<a href="proxy.php?url=https%3A%2F%2Fgithub.com.%2F%3C%2Fspan%3E%27%3C%2Fspan%3E.%3Cspan+class%3D"pl-en">create_link("vlan",$sectionId,$item['vlanId']).'" rel="tooltip" data-placement="right" title="'.$item['description'].'">'.$item['number'].' ('.$item['name'].') '.$item['l2domain'].'</a>';
21872198

21882199
# fetch all subnets in VLAN
21892200
$subnets = $this->fetch_vlan_subnets ($item['vlanId'], $sectionId);
@@ -2365,6 +2376,15 @@ public function print_subnets_tools( $user, $subnets, $custom_fields ) {
23652376
# old count
23662377
$old_count = 0;
23672378

2379+
# fetch all vlans and domains and reindex
2380+
$vlans_and_domains = $Tools->fetch_all_domains_and_vlans ();
2381+
if (!$vlans_and_domains) { $all_vlans = array(); }
2382+
else {
2383+
foreach ($vlans_and_domains as $vd) {
2384+
$all_vlans[$vd->id] = $vd;
2385+
}
2386+
}
2387+
23682388
# return table content (tr and td's)
23692389
while ( $loop && ( ( $option = each( $children_subnets[$parent] ) ) || ( $parent > $rootId ) ) )
23702390
{
@@ -2388,9 +2408,11 @@ public function print_subnets_tools( $user, $subnets, $custom_fields ) {
23882408
# count levels
23892409
$count = count( $parent_stack ) + 1;
23902410

2391-
# get VLAN
2392-
$vlan = (array) $Tools->fetch_object("vlans", "vlanId", $option['value']['vlanId']);
2393-
if(@$vlan[0]===false) { $vlan['number'] = ""; } # no VLAN
2411+
# vlan
2412+
if (!array_key_exists ($option['value']['vlanId'], $all_vlans)) { $vlan['number'] = ""; }
2413+
else {
2414+
$vlan['number'] = $all_vlans[$option['value']['vlanId']]->domainId==1 ? $all_vlans[$option['value']['vlanId']]->number : $all_vlans[$option['value']['vlanId']]->number." <span class='badge badge1 badge5' rel='tooltip' title='VLAN is in domain ".$all_vlans[$option['value']['vlanId']]->domainName."'>".$all_vlans[$option['value']['vlanId']]->domainName."</span>";
2415+
}
23942416

23952417
# description
23962418
$description = strlen($option['value']['description'])==0 ? "/" : $option['value']['description'];

functions/classes/class.Tools.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2011,6 +2011,7 @@ public function fetch_all_domains_and_vlans ($search = false) {
20112011
$query[] = " `d`.`description` as `domainDescription`,";
20122012
$query[] = " `v`.`domainId` as `domainId`,";
20132013
$query[] = " `v`.`name` as `name`,";
2014+
$query[] = " `d`.`name` as `domainName`,";
20142015
$query[] = " `v`.`number` as `number`,";
20152016
$query[] = " `v`.`description` as `description`,";
20162017
// fetch custom fields

0 commit comments

Comments
 (0)