Index: html/includes/entities/port.inc.php
===================================================================
--- html/includes/entities/port.inc.php	(revision 7353)
+++ html/includes/entities/port.inc.php	(working copy)
@@ -264,6 +264,11 @@
 
 function print_port_row($port, $vars = array())
 {
+  echo generate_port_row($port, $vars);
+}
+
+function generate_port_row($port, $vars = array())
+{
   global $config, $cache;
 
   $device = device_by_id_cache($port['device_id']);
@@ -270,7 +275,7 @@
 
   humanize_port($port);
 
-  if(!isset($vars['view'])) { $vars['view'] = "basic"; }
+  if (!isset($vars['view'])) { $vars['view'] = "basic"; }
 
   // Populate $port_adsl if the port has ADSL-MIB data
   if (!isset($cache['ports_option']['ports_adsl']) || in_array($port['port_id'], $cache['ports_option']['ports_adsl']))
@@ -324,25 +329,26 @@
   $port['pps_in']  = format_si($port['ifInUcastPkts_rate'])."pps";
   $port['pps_out'] = format_si($port['ifOutUcastPkts_rate'])."pps";
 
+  $string = '';
 
-  if($vars['view'] == "basic" || $vars['view'] == "graphs")  // Print basic view table row
+  if ($vars['view'] == "basic" || $vars['view'] == "graphs")  // Print basic view table row
   {
     $table_cols = '8';
 
-    echo('<tr class="' . $port['row_class'] . '">
+    $string .= '<tr class="' . $port['row_class'] . '">
             <td class="state-marker"></td>
-            <td style="width: 1px;"></td>');
+            <td style="width: 1px;"></td>';
 
-    if($vars['page'] != "device") // Print device name link if we're not inside the device page hierarchy.
+    if ($vars['page'] != "device") // Print device name link if we're not inside the device page hierarchy.
     {
       $table_cols++; // Increment table columns by one to make sure graph line draws correctly
 
-      echo('    <td style="width: 200px;"><span class=entity>' . generate_device_link($device, short_hostname($device['hostname'], "20")) . '</span><br />
-                <span class=em>' . escape_html(truncate($port['location'], 32, "")) . '</span></td>');
+      $string .= '    <td style="width: 200px;"><span class="entity">' . generate_device_link($device, short_hostname($device['hostname'], "20")) . '</span><br />
+                <span class="em">' . escape_html(truncate($port['location'], 32, "")) . '</span></td>';
     }
 
-    echo("    <td><span class=entity>" . generate_port_link($port, rewrite_ifname($port['port_label'])) . " " . $port['tags'] . "</span><br />
-                <span class=em>" . escape_html(truncate($port['ifAlias'], 50, '')) . "</span></td>" .
+    $string .= '    <td><span class="entity">' . generate_port_link($port, rewrite_ifname($port['port_label'])) . ' ' . $port['tags'] . '</span><br />
+                <span class="em">' . escape_html(truncate($port['ifAlias'], 50, '')) . '</span></td>' .
 
       '<td style="width: 110px;"> <i class="icon-circle-arrow-down" style="' . $port['bps_in_style'] . '"></i>  <span class="small" style="' . $port['bps_in_style'] . '">' . formatRates($port['in_rate']) . '</span><br />' .
       '<i class="icon-circle-arrow-up" style="' . $port['bps_out_style'] . '"></i> <span class="small" style="' . $port['bps_out_style'] . '">' . formatRates($port['out_rate']) . '</span><br /></td>' .
@@ -353,44 +359,44 @@
       '<td style="width: 110px;"><i class="icon-circle-arrow-down" style="' . $port['pps_in_style'] . '"></i>  <span class="small" style="' . $port['pps_in_style'] . '">' . format_bi($port['ifInUcastPkts_rate']) . 'pps</span><br />' .
       '<i class="icon-circle-arrow-up" style="' . $port['pps_out_style'] . '"></i> <span class="small" style="' . $port['pps_out_style'] . '">' . format_bi($port['ifOutUcastPkts_rate']) . 'pps</span></td>' .
 
-      '<td style="width: 110px;"><small>' . $port['human_speed'] . "<br />" . $port['ifMtu'] . "</small></td>
-            <td ><small>" . $port['human_type'] . "<br />" . $port['human_mac'] . "</small></td>
-          </tr>\n");
+      '<td style="width: 110px;"><small>' . $port['human_speed'] . '<br />' . $port['ifMtu'] . '</small></td>
+            <td ><small>' . $port['human_type'] . '<br />' . $port['human_mac'] . '</small></td>
+          </tr>';
   }
-  else if($vars['view'] == "details" || $vars['view'] == "detail") // Print detailed view table row
+  else if ($vars['view'] == "details" || $vars['view'] == "detail") // Print detailed view table row
   {
     $table_cols = '9';
 
-    echo('<tr class="' . $port['row_class'] . '"');
-    if($vars['tab'] != "port") { echo (' onclick="location.href=\'' . generate_port_url($port) . '\'" style="cursor: pointer;"'); }
-    echo('>');
-    echo('         <td class="state-marker"></td>
-         <td style="width: 1px;"></td>');
+    $string .= '<tr class="' . $port['row_class'] . '"';
+    if ($vars['tab'] != "port") { $string .= ' onclick="location.href=\'' . generate_port_url($port) . '\'" style="cursor: pointer;"'; }
+    $string .= '>';
+    $string .= '         <td class="state-marker"></td>
+         <td style="width: 1px;"></td>';
 
-    if($vars['page'] != "device") // Print device name link if we're not inside the device page hierarchy.
+    if ($vars['page'] != "device") // Print device name link if we're not inside the device page hierarchy.
     {
       $table_cols++; // Increment table columns by one to make sure graph line draws correctly
 
-      echo('    <td width="200"><span class=entity>' . generate_device_link($device, short_hostname($device['hostname'], "20")) . '</span><br />
-                <span class=em>' . escape_html(truncate($port['location'], 32, "")) . '</span></td>');
+      $string .= '    <td width="200"><span class="entity">' . generate_device_link($device, short_hostname($device['hostname'], "20")) . '</span><br />
+                <span class="em">' . escape_html(truncate($port['location'], 32, "")) . '</span></td>';
     }
 
-    echo('
-         <td style="min-width: 250px;">');
+    $string .= '
+         <td style="min-width: 250px;">';
 
-    echo("        <span class='entity-title'>
-              " . generate_port_link($port) . " ".$port['tags']."
-           </span><br /><span class=small>".escape_html($port['ifAlias'])."</span>");
+    $string .= '        <span class="entity-title">
+              ' . generate_port_link($port) . ' '.$port['tags'].'
+           </span><br /><span class="small">'.escape_html($port['ifAlias']).'</span>';
 
-    if ($port['ifAlias']) { echo("<br />"); }
+    if ($port['ifAlias']) { $string .= '<br />'; }
 
-    unset ($break);
+    unset($break);
 
     if (!isset($cache['ports_option']['ipv4_addresses']) || in_array($port['port_id'], $cache['ports_option']['ipv4_addresses']))
     {
       foreach (dbFetchRows("SELECT * FROM `ipv4_addresses` WHERE `port_id` = ?", array($port['port_id'])) as $ip)
       {
-        echo($break . generate_popup_link('ip', $ip['ipv4_address'].'/'.$ip['ipv4_prefixlen'], NULL, 'small'));
+        $string .= $break . generate_popup_link('ip', $ip['ipv4_address'].'/'.$ip['ipv4_prefixlen'], NULL, 'small');
         $break = "<br />";
       }
     }
@@ -398,46 +404,46 @@
     {
       foreach (dbFetchRows("SELECT * FROM `ipv6_addresses` WHERE `port_id` = ?", array($port['port_id'])) as $ip6)
       {
-        echo($break . generate_popup_link('ip', $ip6['ipv6_address'].'/'.$ip6['ipv6_prefixlen'], NULL, 'small'));
+        $string .= $break . generate_popup_link('ip', $ip6['ipv6_address'].'/'.$ip6['ipv6_prefixlen'], NULL, 'small');
         $break = "<br />";
       }
     }
 
-    //echo("</span>");
+    //$string .= '</span>';
 
-    echo('</td>');
+    $string .= '</td>';
 
     // Print port graph thumbnails
-    echo('<td style="width: 147px;">');
+    $string .= '<td style="width: 147px;">';
     $port['graph_type'] = "port_bits";
-    echo(generate_port_link($port, "<img src='graph.php?type=port_bits&amp;id=".$port['port_id']."&amp;from=".$config['time']['day']."&amp;to=".$config['time']['now']."&amp;width=100&amp;height=20&amp;legend=no' alt=\"\" />"));
+    $string .= generate_port_link($port, "<img src='graph.php?type=port_bits&amp;id=".$port['port_id']."&amp;from=".$config['time']['day']."&amp;to=".$config['time']['now']."&amp;width=100&amp;height=20&amp;legend=no' alt=\"\" />");
     $port['graph_type'] = "port_upkts";
-    echo(generate_port_link($port, "<img src='graph.php?type=port_upkts&amp;id=".$port['port_id']."&amp;from=".$config['time']['day']."&amp;to=".$config['time']['now']."&amp;width=100&amp;height=20&amp;legend=no' alt=\"\" />"));
+    $string .= generate_port_link($port, "<img src='graph.php?type=port_upkts&amp;id=".$port['port_id']."&amp;from=".$config['time']['day']."&amp;to=".$config['time']['now']."&amp;width=100&amp;height=20&amp;legend=no' alt=\"\" />");
     $port['graph_type'] = "port_errors";
-    echo(generate_port_link($port, "<img src='graph.php?type=port_errors&amp;id=".$port['port_id']."&amp;from=".$config['time']['day']."&amp;to=".$config['time']['now']."&amp;width=100&amp;height=20&amp;legend=no' alt=\"\" />"));
-    echo('</td>');
+    $string .= generate_port_link($port, "<img src='graph.php?type=port_errors&amp;id=".$port['port_id']."&amp;from=".$config['time']['day']."&amp;to=".$config['time']['now']."&amp;width=100&amp;height=20&amp;legend=no' alt=\"\" />");
+    $string .= '</td>';
 
-    echo('<td style="width: 100px; white-space: nowrap;">');
+    $string .= '<td style="width: 100px; white-space: nowrap;">';
 
     if ($port['ifOperStatus'] == "up" || $port['ifOperStatus'] == "monitoring")
     {
       // Colours generated by humanize_port
-      echo '<i class="icon-circle-arrow-down" style="',$port['bps_in_style'], '"></i> <span class="small" style="',$port['bps_in_style'], '">' , formatRates($port['in_rate']) , '</span><br />',
-      '<i class="icon-circle-arrow-up"   style="',$port['bps_out_style'],'"></i> <span class="small" style="',$port['bps_out_style'],'">' , formatRates($port['out_rate']), '</span><br />',
-      '<i class="icon-circle-arrow-down" style="',$port['pps_in_style'], '"></i> <span class="small" style="',$port['pps_in_style'], '">' , format_bi($port['ifInUcastPkts_rate']), 'pps</span><br />',
-      '<i class="icon-circle-arrow-up"   style="',$port['pps_out_style'],'"></i> <span class="small" style="',$port['pps_out_style'],'">' , format_bi($port['ifOutUcastPkts_rate']),'pps</span>';
+      $string .= '<i class="icon-circle-arrow-down" style="'.$port['bps_in_style']. '"></i> <span class="small" style="'.$port['bps_in_style']. '">' . formatRates($port['in_rate']) . '</span><br />
+      <i class="icon-circle-arrow-up"   style="'.$port['bps_out_style'].'"></i> <span class="small" style="'.$port['bps_out_style'].'">' . formatRates($port['out_rate']). '</span><br />
+      <i class="icon-circle-arrow-down" style="'.$port['pps_in_style']. '"></i> <span class="small" style="'.$port['pps_in_style']. '">' . format_bi($port['ifInUcastPkts_rate']). 'pps</span><br />
+      <i class="icon-circle-arrow-up"   style="'.$port['pps_out_style'].'"></i> <span class="small" style="'.$port['pps_out_style'].'">' . format_bi($port['ifOutUcastPkts_rate']).'pps</span>';
     }
 
-    echo('</td><td style="width: 110px;">');
-    if ($port['ifType'] && $port['ifType'] != "") { echo("<span class=small>" . $port['human_type'] . "</span>"); } else { echo("-"); }
-    echo ('<br />');
-    if ($port['ifSpeed']) { echo("<span class=small>".humanspeed($port['ifSpeed'])."</span>"); }
-    if ($port['ifDuplex'] && $port['ifDuplex'] != "unknown") { echo('<span class=small> (' . str_replace("Duplex", "", $port['ifDuplex']) . ')</span>'); }
-    echo("<br />");
-    if ($port['ifMtu'] && $port['ifMtu'] != "") { echo("<span class=small>MTU " . $port['ifMtu'] . "</span>"); } else { echo("<span class=small>Unknown MTU</span>"); }
-    // if ($ifHardType && $ifHardType != "") { echo("<span class=small>" . $ifHardType . "</span>"); } else { echo("-"); }
+    $string .= '</td><td style="width: 110px;">';
+    if ($port['ifType'] && $port['ifType'] != "") { $string .= '<span class="small">' . $port['human_type'] . '</span>'; } else { $string .= '-'; }
+    $string .= '<br />';
+    if ($port['ifSpeed']) { $string .= '<span class="small">'.humanspeed($port['ifSpeed']).'</span>'; }
+    if ($port['ifDuplex'] && $port['ifDuplex'] != "unknown") { $string .= '<span class="small"> (' . str_replace("Duplex", "", $port['ifDuplex']) . ')</span>'; }
+    $string .= '<br />';
+    if ($port['ifMtu'] && $port['ifMtu'] != "") { $string .= '<span class="small">MTU ' . $port['ifMtu'] . '</span>'; } else { $string .= '<span class="small">Unknown MTU</span>'; }
+    // if ($ifHardType && $ifHardType != "") { $string .= '<span class="small">" . $ifHardType . "</span>"); } else { $string .= '-'; }
 
-    //echo ('<br />');
+    //$string .= '<br />';
 
     // Set VLAN data if the port has ifTrunk populated
     if ($port['ifTrunk'])
@@ -459,7 +465,7 @@
           case 'forwarding': $class = 'text-success'; break;
           default:           $class = 'muted';
         }
-        if (empty($native_name)) {$native_name = 'VLAN'.str_pad($port['ifVlan'], 4, '0', STR_PAD_LEFT); }
+        if (empty($native_name)) { $native_name = 'VLAN'.str_pad($port['ifVlan'], 4, '0', STR_PAD_LEFT); }
         $native_tooltip = 'NATIVE: <strong class='.$class.'>'.$port['ifVlan'].' ['.$native_name.']</strong><br />';
       }
 
@@ -473,10 +479,10 @@
       }
       $vlans_count = count($vlans);
       $rel = ($vlans_count || $native_tooltip) ? 'tooltip' : ''; // Hide tooltip for empty
-      echo('<p class="small"><a class="label label-info" data-rel="'.$rel.'" data-tooltip="<div class=\'small\' style=\'max-width: 320px; text-align: justify;\'>'.$native_tooltip);
+      $string .= '<p class="small"><a class="label label-info" data-rel="'.$rel.'" data-tooltip="<div class=\'small\' style=\'max-width: 320px; text-align: justify;\'>'.$native_tooltip;
       if ($vlans_count)
       {
-        echo('ALLOWED: ');
+        $string .= 'ALLOWED: ';
         $vlans_aggr = array();
         foreach ($vlans as $vlan)
         {
@@ -493,16 +499,16 @@
               default:           $class = 'muted';
             }
             if (empty($vlan['vlan_name'])) { 'VLAN'.str_pad($vlan['vlan'], 4, '0', STR_PAD_LEFT); }
-            echo("<strong class=".$class.">".$vlan['vlan'] ." [".$vlan['vlan_name']."]</strong><br />");
+            $string .= '<strong class='.$class.'>'.$vlan['vlan'] .' ['.$vlan['vlan_name'].']</strong><br />';
           }
         }
         if ($vlans_count > 20)
         {
           // End aggregate VLANs
-          echo('<strong>'.range_to_list($vlans_aggr, ', ').'</strong>');
+          $string .= '<strong>'.range_to_list($vlans_aggr, ', ').'</strong>';
         }
       }
-      echo('</div>">'.$port['ifTrunk'].'</a></p>');
+      $string .= '</div>">'.$port['ifTrunk'].'</a></p>';
     }
     else if ($port['ifVlan'])
     {
@@ -521,39 +527,39 @@
         default:           $class = '';
       }
       $rel = ($native_name) ? 'tooltip' : ''; // Hide tooltip for empty
-      echo('<br /><span data-rel="'.$rel.'" class="label '.$class.'"  data-tooltip="<strong class=\'small '.$class.'\'>'.$port['ifVlan'].' ['.$native_name.']</strong>">VLAN ' . $port['ifVlan'] . '</span>');
+      $string .= '<br /><span data-rel="'.$rel.'" class="label '.$class.'"  data-tooltip="<strong class=\'small '.$class.'\'>'.$port['ifVlan'].' ['.$native_name.']</strong>">VLAN ' . $port['ifVlan'] . '</span>';
     }
     else if ($port['ifVrf']) // Print the VRF name if the port is assigned to a VRF
     {
       $vrf_name = dbFetchCell("SELECT `vrf_name` FROM `vrfs` WHERE `vrf_id` = ?", array($port['ifVrf']));
-      echo('<br /><span class="small badge badge-success" data-rel="tooltip" data-tooltip="VRF">'.$vrf_name.'</span>');
+      $string .= '<br /><span class="small badge badge-success" data-rel="tooltip" data-tooltip="VRF">'.$vrf_name.'</span>';
     }
 
-    echo ('</td>');
+    $string .= '</td>';
 
     // If the port is ADSL, print ADSL port data.
     if ($port_adsl['adslLineCoding'])
     {
-      echo('<td style="width: 200px;"><span class="small">');
-      echo('<span class="label">'.$port_adsl['adslLineCoding'].'</span> <span class="label">' . rewrite_adslLineType($port_adsl['adslLineType']).'</span>');
-      echo("<br />");
-      echo('SYN <i class="icon-circle-arrow-down green"></i> '.formatRates($port_adsl['adslAtucChanCurrTxRate']) . ' <i class="icon-circle-arrow-up blue"></i> '. formatRates($port_adsl['adslAturChanCurrTxRate']));
-      echo("<br />");
-      //echo("Max:".formatRates($port_adsl['adslAtucCurrAttainableRate']) . "/". formatRates($port_adsl['adslAturCurrAttainableRate']));
-      //echo("<br />");
-      echo('ATN <i class="icon-circle-arrow-down green"></i> '.$port_adsl['adslAtucCurrAtn'] . 'dBm <i class="icon-circle-arrow-up blue"></i> '. $port_adsl['adslAturCurrAtn'] . 'dBm');
-      echo('<br />');
-      echo('SNR <i class="icon-circle-arrow-down green"></i> '.$port_adsl['adslAtucCurrSnrMgn'] . 'dB <i class="icon-circle-arrow-up blue"></i> '. $port_adsl['adslAturCurrSnrMgn']. 'dB');
-      echo('</span>');
+      $string .= '<td style="width: 200px;"><span class="small">';
+      $string .= '<span class="label">'.$port_adsl['adslLineCoding'].'</span> <span class="label">' . rewrite_adslLineType($port_adsl['adslLineType']).'</span>';
+      $string .= '<br />';
+      $string .= 'SYN <i class="icon-circle-arrow-down green"></i> '.formatRates($port_adsl['adslAtucChanCurrTxRate']) . ' <i class="icon-circle-arrow-up blue"></i> '. formatRates($port_adsl['adslAturChanCurrTxRate']);
+      $string .= '<br />';
+      //$string .= 'Max:'.formatRates($port_adsl['adslAtucCurrAttainableRate']) . '/'. formatRates($port_adsl['adslAturCurrAttainableRate']);
+      //$string .= '<br />';
+      $string .= 'ATN <i class="icon-circle-arrow-down green"></i> '.$port_adsl['adslAtucCurrAtn'] . 'dBm <i class="icon-circle-arrow-up blue"></i> '. $port_adsl['adslAturCurrAtn'] . 'dBm';
+      $string .= '<br />';
+      $string .= 'SNR <i class="icon-circle-arrow-down green"></i> '.$port_adsl['adslAtucCurrSnrMgn'] . 'dB <i class="icon-circle-arrow-up blue"></i> '. $port_adsl['adslAturCurrSnrMgn']. 'dB';
+      $string .= '</span>';
     } else {
       // Otherwise print normal port data
-      echo("<td style='width: 150px;'><span class=small>");
-      if ($port['ifPhysAddress'] && $port['ifPhysAddress'] != "") { echo($port['human_mac']); } else { echo("-"); }
-      echo("<br />" . $port['ifLastChange'] . "</span>");
+      $string .= '<td style="width: 150px;"><span class="small">';
+      if ($port['ifPhysAddress'] && $port['ifPhysAddress'] != "") { $string .= $port['human_mac']; } else { $string .= '-'; }
+      $string .= '<br />' . $port['ifLastChange'] . '</span>';
     }
 
-    echo('</td>');
-    echo('<td style="min-width: 200px" class=small>');
+    $string .= '</td>';
+    $string .= '<td style="min-width: 200px" class="small">';
 
 
     if (strpos($port['port_label'], "oopback") === FALSE && !$graph_type)
@@ -566,7 +572,7 @@
         foreach (dbFetchRows('SELECT * FROM `neighbours` WHERE `port_id` = ?', array($port['port_id'])) as $neighbour)
         {
           // print_r($link);
-          if($neighbour['remote_port_id']) {
+          if ($neighbour['remote_port_id']) {
             $int_links[$neighbour['remote_port_id']] = $neighbour['remote_port_id'];
             $int_links_phys[$neighbour['remote_port_id']] = 1;
           } else {
@@ -626,17 +632,17 @@
       {
         $link_if  = get_port_by_id_cache($int_link);
         $link_dev = device_by_id_cache($link_if['device_id']);
-        echo($br);
+        $string .= $br;
 
-        if ($int_links_phys[$int_link]) { echo('<a alt="Directly connected" class="oicon-connect"></a> '); }
-        else { echo('<a alt="Same subnet" class="oicon-network-hub"></a> '); }
+        if ($int_links_phys[$int_link]) { $string .= '<a data-alt="Directly connected" class="oicon-connect"></a> '; }
+        else { $string .= '<a data-alt="Same subnet" class="oicon-network-hub"></a> '; }
 
-        echo("<b>" . generate_port_link($link_if, $link_if['port_label_short']) . " on " . generate_device_link($link_dev, short_hostname($link_dev['hostname'])) . "</b>");
+        $string .= '<b>' . generate_port_link($link_if, $link_if['port_label_short']) . ' on ' . generate_device_link($link_dev, short_hostname($link_dev['hostname'])) . '</b>';
 
         ## FIXME -- do something fancy here.
 
-        if ($int_links_v6[$int_link]) { echo ' ', overlib_link('', '<span class="label label-success">IPv6</span>', implode("<br />", $int_links_v6[$int_link]), NULL); }
-        if ($int_links_v4[$int_link]) { echo ' ', overlib_link('', '<span class="label label-info">IPv4</span>', implode("<br />", $int_links_v4[$int_link]), NULL); }
+        if ($int_links_v6[$int_link]) { $string .= '&nbsp;'.overlib_link('', '<span class="label label-success">IPv6</span>', implode("<br />", $int_links_v6[$int_link]), NULL); }
+        if ($int_links_v4[$int_link]) { $string .= '&nbsp;'.overlib_link('', '<span class="label label-info">IPv4</span>', implode("<br />", $int_links_v4[$int_link]), NULL); }
         $br = "<br />";
       }
 
@@ -645,14 +651,12 @@
       foreach ($int_links_unknown as $int_link)
       {
         // FIXME -- Expose platform and version here.
-        echo('<a alt="Directly connected" class="oicon-plug-connect"></a> ');
-        echo('<b><i>'.short_ifname($int_link['remote_port']).'</i></b> on ');
+        $string .= '<a data-alt="Directly connected" class="oicon-plug-connect"></a> ';
+        $string .= '<b><i>'.short_ifname($int_link['remote_port']).'</i></b> on ';
 
-        echo('<b><i><a data-rel="tooltip" data-tooltip="<div class=\'small\' style=\'max-width: 500px;\'><b>'.$int_link['remote_platform'].'</b><br />'.$int_link['remote_version'].'</div>" data-hasqtip="4" aria-describedby="qtip-4">'.$int_link['remote_hostname'].'</a></i></b>');
-        echo('<br />');
+        $string .= '<i><b>'.generate_tooltip_link(NULL, $int_link['remote_hostname'], '<div class="small" style="max-width: 500px;"><b>'.$int_link['remote_platform'].'</b><br />'.$int_link['remote_version'].'</div>').'</b></i>';
+        $string .= '<br />';
       }
-
-
     }
 
     if (!isset($cache['ports_option']['pseudowires']) || in_array($port['port_id'], $cache['ports_option']['pseudowires']))
@@ -669,12 +673,12 @@
         if (is_array($pw_peer_int))
         {
           humanize_port($pw_peer_int);
-          echo($br.'<i class="oicon-arrow-switch"></i> <strong>' . generate_port_link($pw_peer_int, $pw_peer_int['port_label_short']) .' on '. generate_device_link($pw_peer_dev, short_hostname($pw_peer_dev['hostname'])) . '</strong>');
+          $string .= $br.'<i class="oicon-arrow-switch"></i> <strong>' . generate_port_link($pw_peer_int, $pw_peer_int['port_label_short']) .' on '. generate_device_link($pw_peer_dev, short_hostname($pw_peer_dev['hostname'])) . '</strong>';
         } else {
-          echo($br.'<i class="oicon-arrow-switch"></i> <strong> VC ' . $pseudowire['pwID'] .' on '. $pseudowire['peer_addr'] . '</strong>');
+          $string .= $br.'<i class="oicon-arrow-switch"></i> <strong> VC ' . $pseudowire['pwID'] .' on '. $pseudowire['peer_addr'] . '</strong>';
         }
-        echo ' <span class="label">'.$pseudowire['pwPsnType'].'</span>';
-        echo ' <span class="label">'.$pseudowire['pwType'].'</span>';
+        $string .= ' <span class="label">'.$pseudowire['pwPsnType'].'</span>';
+        $string .= ' <span class="label">'.$pseudowire['pwType'].'</span>';
         $br = "<br />";
       }
     }
@@ -685,7 +689,7 @@
       {
         humanize_port($member);
         $pagp[$device['device_id']][$port['ifIndex']][$member['ifIndex']] = TRUE;
-        echo($br.'<i class="oicon-arrow-join"></i> <strong>' . generate_port_link($member) . ' [PAgP]</strong>');
+        $string .= $br.'<i class="oicon-arrow-join"></i> <strong>' . generate_port_link($member) . ' [PAgP]</strong>';
         $br = "<br />";
       }
     }
@@ -695,7 +699,7 @@
       $pagp[$device['device_id']][$port['pagpGroupIfIndex']][$port['ifIndex']] = TRUE;
       $parent = dbFetchRow("SELECT * FROM `ports` WHERE `ifIndex` = ? and `device_id` = ?", array($port['pagpGroupIfIndex'], $device['device_id']));
       humanize_port($parent);
-      echo($br.'<i class="oicon-arrow-split"></i> <strong>' . generate_port_link($parent) . ' [PAgP]</strong>');
+      $string .= $br.'<i class="oicon-arrow-split"></i> <strong>' . generate_port_link($parent) . ' [PAgP]</strong>';
       $br = "<br />";
     }
 
@@ -709,7 +713,7 @@
           $this_port = get_port_by_index_cache($device['device_id'], $higher_if['port_id_high']);
           if (is_array($this_port))
           {
-            echo($br.'<i class="oicon-arrow-split"></i> <strong>' . generate_port_link($this_port) . '</strong>');
+            $string .= $br.'<i class="oicon-arrow-split"></i> <strong>' . generate_port_link($this_port) . '</strong>';
             $br = "<br />";
           }
         }
@@ -726,7 +730,7 @@
           $this_port = get_port_by_index_cache($device['device_id'], $lower_if['port_id_low']);
           if (is_array($this_port))
           {
-            echo($br.'<i class="oicon-arrow-join"></i> <strong>' . generate_port_link($this_port) . "</strong>");
+            $string .= $br.'<i class="oicon-arrow-join"></i> <strong>' . generate_port_link($this_port) . '</strong>';
             $br = "<br />";
           }
         }
@@ -735,7 +739,7 @@
 
     unset($int_links, $int_links_v6, $int_links_v4, $int_links_phys, $br);
 
-    echo("</td></tr>");
+    $string .= '</td></tr>';
   } // End Detailed View
 
   // If we're showing graphs, generate the graph and print the img tags
@@ -750,17 +754,19 @@
   if ($vars['graph'] && is_file($graph_file))
   {
 
-    echo('<tr><td colspan="'.$table_cols.'">');
+    $string .= '<tr><td colspan="'.$table_cols.'">';
 
     $graph_array['to']     = $config['time']['now'];
     $graph_array['id']     = $port['port_id'];
     $graph_array['type']   = 'port_'.$vars['graph'];
 
-    print_graph_row($graph_array);
+    $string .= generate_graph_row($graph_array);
 
-    echo('</td></tr>');
+    $string .= '</td></tr>';
 
   }
+  
+  return $string;
 }
 
 // EOF
Index: html/includes/navbar.inc.php
===================================================================
--- html/includes/navbar.inc.php	(revision 7353)
+++ html/includes/navbar.inc.php	(working copy)
@@ -428,7 +428,7 @@
 
   ksort($array['entries']);
 
-  echo('<ul class="dropdown-menu">');
+  echo('<ul role="menu" class="dropdown-menu">');
 
   if (count($array['entries']) > "5")
   {
@@ -511,7 +511,7 @@
 function navbar_submenu($entry, $level = 1)
 {
   echo(str_pad('',($level-1)*2) . '                <li class="dropdown-submenu">' . generate_menu_link($entry['url'], '<i class="menu-icon ' . $entry['icon'] . '"></i>&nbsp;' . $entry['title'], $entry['count']) . PHP_EOL);
-  echo(str_pad('',($level-1)*2) . '                  <ul class="dropdown-menu">' . PHP_EOL);
+  echo(str_pad('',($level-1)*2) . '                  <ul role="menu" class="dropdown-menu">' . PHP_EOL);
 
   foreach ($entry['entries'] as $subentry)
   {
@@ -558,7 +558,7 @@
   echo('                <i class="' . $dropdown['icon'] . '"></i> ' . $dropdown['title'] . ' <b class="caret"></b></a>' . PHP_EOL);
   echo('              <a href="' . $dropdown['url'] . '" class="visible-sm dropdown-toggle" data-hover="dropdown" data-toggle="dropdown">' . PHP_EOL);
   echo('                <i class="' . $dropdown['icon'] . '"></i> <b class="caret"></b></a>' . PHP_EOL);
-  echo('              <ul class="dropdown-menu">' . PHP_EOL);
+  echo('              <ul role="menu" class="dropdown-menu">' . PHP_EOL);
 
   foreach ($dropdown['entries'] as $entry)
   {
Index: html/includes/port-sort-select.inc.php
===================================================================
--- html/includes/port-sort-select.inc.php	(revision 7353)
+++ html/includes/port-sort-select.inc.php	(working copy)
@@ -35,10 +35,10 @@
     $select .= ',`ifUcastPkts_rate`';
     break;
   case 'packets_in':
-    $select .= ',`ifInUcastOctets_rate`';
+    $select .= ',`ifInUcastPkts_rate`';
     break;
   case 'packets_out':
-    $select .= ',`ifOutUcastOctets_rate`';
+    $select .= ',`ifOutUcastPkts_rate`';
     break;
   case 'errors':
     $select .= ',`ifErrors_rate`';
Index: html/includes/port-sort.inc.php
===================================================================
--- html/includes/port-sort.inc.php	(revision 7353)
+++ html/includes/port-sort.inc.php	(working copy)
@@ -35,10 +35,10 @@
     $ports = array_sort($ports, 'ifUcastPkts_rate', 'SORT_DESC');
     break;
   case 'packets_in':
-    $ports = array_sort($ports, 'ifInUcastOctets_rate', 'SORT_DESC');
+    $ports = array_sort($ports, 'ifInUcastPkts_rate', 'SORT_DESC');
     break;
   case 'packets_out':
-    $ports = array_sort($ports, 'ifOutUcastOctets_rate', 'SORT_DESC');
+    $ports = array_sort($ports, 'ifOutUcastPkts_rate', 'SORT_DESC');
     break;
   case 'errors':
     $ports = array_sort($ports, 'ifErrors_rate', 'SORT_DESC');
Index: html/includes/print/alert.inc.php
===================================================================
--- html/includes/print/alert.inc.php	(revision 7353)
+++ html/includes/print/alert.inc.php	(working copy)
@@ -34,23 +34,19 @@
       {
         // Search by device_id if we have a device or device_id
         case 'device_id':
-          $where .= ' AND `device_id` = ?';
-          $param[] = $value;
+          $where .= generate_query_values($value, 'device_id');
           break;
         case 'entity_type':
           if ($value != 'all')
           {
-            $where .= ' AND `entity_type` = ?';
-            $param[] = $value;
+            $where .= generate_query_values($value, 'entity_type');
           }
           break;
         case 'entity_id':
-          $where .= ' AND `entity_id` = ?';
-          $param[] = $value;
+          $where .= generate_query_values($value, 'entity_id');
           break;
         case 'alert_test_id':
-          $where .= ' AND `alert_test_id` = ?';
-          $param[] = $value;
+          $where .= generate_query_values($value, 'alert_test_id');
           break;
         case 'status':
           if ($value == 'failed_delayed') {
Index: html/includes/print/dot1xtable.inc.php
===================================================================
--- html/includes/print/dot1xtable.inc.php	(revision 7353)
+++ html/includes/print/dot1xtable.inc.php	(working copy)
@@ -42,16 +42,14 @@
         case 'address':
           if (isset($vars['searchby']) && $vars['searchby'] == 'ip')
           {
-            $where .= ' AND `ipv4_addr` LIKE ?';
             $value = trim($value);
-            $param[] = '%'.$value.'%';
+            $where .= generate_query_values($value, 'ipv4_addr', '%LIKE%');
           } else if (isset($vars['searchby']) && $vars['searchby'] == 'mac') {
-            $where .= ' AND `M`.`mac_addr` LIKE ?';
-            $param[] = '%'.str_replace(array(':', ' ', '-', '.', '0x'),'', $value).'%';
+            $value = str_replace(array(':', ' ', '-', '.', '0x'), '', $value);
+            $where .= generate_query_values($value, 'M.mac_addr', '%LIKE%');
           } else {
-            $where .= ' AND `username` LIKE ?';
             $value = trim($value);
-            $param[] = '%'.$value.'%';
+            $where .= generate_query_values($value, 'username', '%LIKE%');
           }
           break;
       }
@@ -108,7 +106,7 @@
     $interface = $aps_sorted_db[$ap_id]['name'];
     $string .= '  <tr>' . PHP_EOL;
     $string .= '    <td style="width: 140px;">' . generate_popup_link('mac', format_mac($entry['session_mac'])) . '</td>' . PHP_EOL;
-    $string .= '    <td style="width: 140px;">' . $entry['ipv4_addr'] . '</td>' . PHP_EOL;
+    $string .= '    <td style="width: 140px;">' . generate_popup_link('ip', $entry['ipv4_addr']) . '</td>' . PHP_EOL;
     $string .= '    <td style="white-space: nowrap;">' . $entry['username'] . '</td>' . PHP_EOL;
     $string .= '    <td style="width: 140px;">' . $entry['ssid'] . '</td>' . PHP_EOL;
     $string .= '    <td style="white-space: nowrap;">' . $entry['timestamp'] . '</td>' . PHP_EOL;
Index: html/includes/print/mac_addresses.inc.php
===================================================================
--- html/includes/print/mac_addresses.inc.php	(revision 7353)
+++ html/includes/print/mac_addresses.inc.php	(working copy)
@@ -42,12 +42,11 @@
           $where .= generate_query_values($value, 'device_id');
           break;
         case 'interface':
-          $where .= ' AND `ifDescr` LIKE ?';
-          $param[] = $value;
+          $where .= generate_query_values($value, 'ifDescr', 'LIKE');
           break;
         case 'address':
-          $where .= ' AND `ifPhysAddress` LIKE ?';
-          $param[] = '%'.str_replace(array(':', ' ', '-', '.', '0x'),'', $value).'%';
+          $value = str_replace(array(':', ' ', '-', '.', '0x'), '', $value);
+          $where .= generate_query_values($value, 'ifPhysAddress', '%LIKE%');
           break;
       }
     }
Index: html/includes/print/navbar.inc.php
===================================================================
--- html/includes/print/navbar.inc.php	(revision 7353)
+++ html/includes/print/navbar.inc.php	(working copy)
@@ -121,6 +121,7 @@
           echo('<i class="'.$array['icon'].'"></i> ');
           $array['text'] = '<span>'.$array['text'].'</span>'; // Added span for allow hide by class 'icon'
         }
+        if (isset($array['image'])) { echo('<img src="' . $array['image'] . '" alt="" /> '); }
         echo($array['text'].'</a>');
         echo('</li>');
       } else {
Index: html/includes/print/neighbours.inc.php
===================================================================
--- html/includes/print/neighbours.inc.php	(revision 7353)
+++ html/includes/print/neighbours.inc.php	(working copy)
@@ -151,6 +151,14 @@
         case 'version':
           $where .= generate_query_values($value, 'remote_version');
           break;
+        case 'remote_port_id':
+          if ($value != 0)
+          {
+            $where .= ' AND `remote_port_id` != 0';
+          } else {
+            $where .= generate_query_values($value, 'remote_port_id');
+          }
+          break;        
       }
     }
   }
Index: html/pages/alert_check.inc.php
===================================================================
--- html/pages/alert_check.inc.php	(revision 7353)
+++ html/pages/alert_check.inc.php	(working copy)
@@ -207,7 +207,7 @@
 <?php
 if ($_SESSION['userlevel'] == 10) {
 ?>
-      <div style="margin-right: 5px;" class="widget-controls"><a href="#add_assoc_modal" data-toggle="modal"><i class="oicon-plus-circle"></i> Add</a></div>
+      <div class="widget-controls"><a href="#add_assoc_modal" data-toggle="modal"><i class="oicon-plus-circle"></i> Add</a></div>
 <?php } ?>
 
         </div>
Index: html/pages/alert_maintenance.inc.php
===================================================================
--- html/pages/alert_maintenance.inc.php	(revision 7353)
+++ html/pages/alert_maintenance.inc.php	(working copy)
@@ -88,9 +88,8 @@
           $item = array('id'          => 'maint_global',
                         //'size'        => 'small',
                         'value'       => $maint['maint_global']);
-          echo(generate_form_element($item, 'checkbox'));
+          echo(generate_form_element($item, 'switch'));
         ?>
-        </label>
         </div>
       </div>
 
Index: html/pages/alert_maintenance_add.inc.php
===================================================================
--- html/pages/alert_maintenance_add.inc.php	(revision 7353)
+++ html/pages/alert_maintenance_add.inc.php	(working copy)
@@ -18,14 +18,15 @@
   include($config['html_dir']."/includes/maintenance-navbar.inc.php");
 ?>
 
-<form name="add_maintenance" method="post" action="<?php echo(generate_url(array('page' => 'alert_maintenance'))); ?>" class="form-horizontal">
 
 <div class="row">
-  <div class="col-md-2">
-  </div>
   <div class="col-md-8">
-    <div class="widget-content">
-<h2>Add Scheduled Maintenance</h2>
+    <div class="box box-solid">
+    <div class="box-header">
+      <h3 class="box-title">Add Scheduled Maintenance</h3>
+    </div>
+    <div class="box-content">
+<form name="add_maintenance" method="post" action="<?php echo(generate_url(array('page' => 'alert_maintenance'))); ?>" class="form-horizontal">
 
   <fieldset>
 
@@ -77,7 +78,6 @@
                         'value'       => 1);
           echo(generate_form_element($item, 'switch'));
         ?>
-        </label>
         </div>
       </div>
 
@@ -92,6 +92,7 @@
                 'value'       => 'add_maintenance');
   echo(generate_form_element($item, 'submit'));
   ?>
+  </form>
 </div>
 
   </div>
@@ -98,8 +99,9 @@
 
 </div>
 
-</form>
+</div>
 
+
 <?php
 
 } else {
Index: html/pages/apps.inc.php
===================================================================
--- html/pages/apps.inc.php	(revision 7353)
+++ html/pages/apps.inc.php	(working copy)
@@ -23,6 +23,11 @@
   }
   $navbar['options'][$app['app_type']]['url']  = generate_url(array('page' => 'apps', 'app' => $app['app_type']));
   $navbar['options'][$app['app_type']]['text'] = nicecase($app['app_type']);
+
+  $image = $config['html_dir'].'/images/icons/'.$app['app_type'].'.png';
+  $icon = (is_file($image) ? $app['app_type'] : 'apps');
+  $navbar['options'][$app['app_type']]['image'] = 'images/icons/'.$icon.'.png';
+
   $app_types[$app['app_type']] = array();
 }
 
Index: html/pages/apps/default.inc.php
===================================================================
--- html/pages/apps/default.inc.php	(revision 7353)
+++ html/pages/apps/default.inc.php	(working copy)
@@ -36,7 +36,7 @@
 {
   print_device_row($app_device);
 
-  echo('<tr><td colspan=8>');
+  echo('<tr><td colspan="6">');
 
   foreach ($config['app'][$vars['app']]['top'] as $graph_type)
   {
Index: html/pages/bill.inc.php
===================================================================
--- html/pages/bill.inc.php	(revision 7353)
+++ html/pages/bill.inc.php	(working copy)
@@ -11,18 +11,12 @@
  *
  */
 
-if (!is_file($config['html_dir'].'/includes/jpgraph/src/jpgraph.php'))
+if (!is_file($config['html_dir'].'/includes/jpgraph/src/jpgrah.php'))
 {
-?>
-
-<div class="alert alert-error">
-  <h4>No Jpgraph installed</h4>
+print_warning('<h4>No Jpgraph installed</h4>
   <i>Jpgraph has been removed from the Observium repositories and must now be installed separately</i> <br />
   * Please download from <a href="http://jpgraph.net/download/">http://jpgraph.net/download/</a> and unpack to html/includes/jpgraph.<br />
-  * Remove the theme definition from the bottom of html/includes/jpgraph/src/jpg-config.inc.php
-</div>
-
-  <?php
+  * Remove the theme definition from the bottom of html/includes/jpgraph/src/jpg-config.inc.php');
 }
 
 $bill_id    = $vars['bill_id'];
Index: html/pages/bills.inc.php
===================================================================
--- html/pages/bills.inc.php	(revision 7353)
+++ html/pages/bills.inc.php	(working copy)
@@ -15,18 +15,12 @@
 
 if (!is_file($config['html_dir'].'/includes/jpgraph/src/jpgraph.php') || defined('DEFAULT_THEME_CLASS'))
 {
-  ?>
-
-<div class="alert alert-error">
- <h4>JpGraph configuration error</h4>
- <p><i>JpGraph has been removed from the Observium repositories and must now be installed separately.</i></p>
- <ul style="margin-left: 30px"> <!-- ugly css hax, someone please FIXME -->
-   <li>Please download from <a href="http://jpgraph.net/download/">http://jpgraph.net/download/</a> and unpack to html/includes/jpgraph.</li>
-   <li>Remove the theme definition from the bottom of html/includes/jpgraph/src/jpg-config.inc.php</li>
- </ul>
-</div>
-
-  <?php
+  print_warning('<h4>JpGraph configuration error</h4>
+   <p><i>JpGraph has been removed from the Observium repositories and must now be installed separately.</i></p>
+   <ul style="margin-left: 30px"> <!-- ugly css hax, someone please FIXME -->
+     <li>Please download from <a href="http://jpgraph.net/download/">http://jpgraph.net/download/</a> and unpack to html/includes/jpgraph.</li>
+     <li>Remove the theme definition from the bottom of html/includes/jpgraph/src/jpg-config.inc.php</li>
+   </ul>');
 }
 
 $isAdmin    = (($_SESSION['userlevel'] == "10") ? true : false);
@@ -95,8 +89,8 @@
     include($config['html_dir']."/pages/bills/month.inc.php");
 }
 
-echo("<script src=\"".$config['base_url']."js/bootstrap-tooltip.js\"></script>\n");
-echo("<script src=\"".$config['base_url']."js/bootstrap-tab.js\"></script>\n");
-echo("<script src=\"".$config['base_url']."js/billing.js\"></script>\n");
+$GLOBALS['cache_html']['js'][] = 'js/bootstrap-tooltip.js';
+$GLOBALS['cache_html']['js'][] = 'js/bootstrap-tab.js';
+$GLOBALS['cache_html']['js'][] = 'js/billing.js';
 
 // EOF
Index: html/pages/bills/searchaction.inc.php
===================================================================
--- html/pages/bills/searchaction.inc.php	(revision 7353)
+++ html/pages/bills/searchaction.inc.php	(working copy)
@@ -22,14 +22,12 @@
       switch($item)
       {
         case "billingname":
-          $where  .= " AND `bill_name` LIKE ?";
-          $param[] = "%".$value."%";
+          $where .= generate_query_values($value, 'bill_name', '%LIKE%');
           break;
         case "billingtype":
           if ($value == "cdr" || $value == "quota")
           {
-            $where  .= " AND `bill_type` = ?";
-            $param[] = $value;
+            $where .= generate_query_values($value, 'bill_type');
           }
           break;
         /// TODO: FIX this to allow over and under usage
Index: html/pages/delhost.inc.php
===================================================================
--- html/pages/delhost.inc.php	(revision 7353)
+++ html/pages/delhost.inc.php	(working copy)
@@ -39,7 +39,7 @@
                     'space'     => '20px',
                     'title'     => 'Delete device <strong>'. $device['hostname'] . '</strong>',
                     'icon'      => 'oicon-server--minus',
-                    'class'     => 'widget',
+                    'class'     => 'box box-solid',
                     'url'       => 'delhost/'
                     );
 
@@ -87,7 +87,7 @@
                     'space'     => '20px',
                     'title'     => 'Delete device',
                     'icon'      => 'oicon-server--minus',
-                    'class'     => 'widget',
+                    'class'     => 'box box-solid',
                     'url'       => 'delhost/'
                     );
 
Index: html/pages/device.inc.php
===================================================================
--- html/pages/device.inc.php	(revision 7353)
+++ html/pages/device.inc.php	(working copy)
@@ -564,7 +564,7 @@
                     'space'     => '20px',
                     'title'     => 'Delete device',
                     'icon'      => 'oicon-server--minus',
-                    'class'     => 'widget',
+                    'class'     => 'box box-solid',
                     'url'       => 'delhost/'
                     );
 
Index: html/pages/device/alert.inc.php
===================================================================
--- html/pages/device/alert.inc.php	(revision 7353)
+++ html/pages/device/alert.inc.php	(working copy)
@@ -65,11 +65,11 @@
 
 <div class="row">
   <div class="col-md-4">
-    <div class="widget widget-table">
-      <div class="widget-header">
-        <i class="oicon-bell"></i><h3>Alert Details</h3>
+    <div class="box box-solid">
+      <div class="box-header with-border">
+        <!-- <i class="oicon-bell"></i> --><h3 class="box-title">Alert Details</h3>
       </div>
-      <div class="widget-content">
+      <div class="box-content">
         <table class="table table-condensed  table-striped ">
           <tbody>
             <tr><th>Type</th><td><?php echo '<i class="' . $config['entities'][$alert['entity_type']]['icon'] . '"></i> ' . nicecase($entry['entity_type']); ?></td></tr>
@@ -83,11 +83,11 @@
   </div>
 
   <div class="col-md-4">
-    <div class="widget widget-table">
-      <div class="widget-header">
-        <i class="oicon-time"></i><h3>Status</h3>
+    <div class="box box-solid">
+      <div class="box-header with-border">
+        <!-- <i class="oicon-time"></i> --><h3 class="box-title">Status</h3>
       </div>
-      <div class="widget-content">
+      <div class="box-content">
 
         <table class="table table-condensed  table-striped ">
           <tr><th>Status</th><td><span class="<?php echo $entry['class']; ?>"><?php echo $entry['last_message']; ?></span></td></tr>
@@ -101,11 +101,11 @@
   </div>
 
   <div class="col-md-4">
-    <div class="widget widget-table">
-      <div class="widget-header">
-        <i class="oicon-gear"></i><h3>Settings</h3>
+    <div class="box box-solid">
+      <div class="box-header with-border">
+        <!-- <i class="oicon-gear"></i> --><h3 class="box-title">Settings</h3>
       </div>
-      <div class="widget-content">
+      <div class="box-content">
         <table class="table table-condensed  table-striped ">
           <tr><th>Ignore Until</th>
             <td>
@@ -129,7 +129,7 @@
           </tr>
           <tr><th>Ignore Until OK</th>
             <td>
-              <input type=checkbox data-toggle="switch-mini" data-on-color="danger" data-off-color="primary" name="ignore_until_ok" <?php echo($entry['ignore_until_ok'] ? 'checked' : ''); ?>>
+              <input type="checkbox" data-toggle="switch-mini" data-on-color="danger" data-off-color="primary" name="ignore_until_ok" <?php echo($entry['ignore_until_ok'] ? 'checked' : ''); ?>>
             </td>
           </tr>
         </table>
@@ -152,8 +152,9 @@
   $graph_array['type']   = 'alert_status';
   print_graph_row($graph_array);
 ?>
-</td></tr>
-</table>
+    </div>
+  </div>
+  </div>
 
 <?php
 
Index: html/pages/device/apps.inc.php
===================================================================
--- html/pages/device/apps.inc.php	(revision 7353)
+++ html/pages/device/apps.inc.php	(working copy)
@@ -60,6 +60,10 @@
       }
       $navbar['options'][$app['app_type']]['text'] = $name;
       $navbar['options'][$app['app_type']]['url'] = $url;
+
+      $image = $config['html_dir'].'/images/icons/'.$app['app_type'].'.png';
+      $icon = (is_file($image) ? $app['app_type'] : 'apps');
+      $navbar['options'][$app['app_type']]['image'] = 'images/icons/'.$icon.'.png';
     }
 
     // If there is more than one instance of the current app type we need to determine how to render the navbar
Index: html/pages/device/data.inc.php
===================================================================
--- html/pages/device/data.inc.php	(revision 7353)
+++ html/pages/device/data.inc.php	(working copy)
@@ -11,8 +11,12 @@
  *
  */
 
-if ($_SESSION['userlevel'] > '7')
+if ($_SESSION['userlevel'] < 7)
 {
+  print_error_permission();
+  return;
+}
+
   $export_device = $device;
   if ($config['snmp']['hide_auth'])
   {
@@ -62,8 +66,5 @@
   }
 
   unset($export_device, $params, $param);
-} else {
-  include("includes/error-no-perm.inc.php");
-}
 
 // EOF
Index: html/pages/device/edit/agent.inc.php
===================================================================
--- html/pages/device/edit/agent.inc.php	(revision 7353)
+++ html/pages/device/edit/agent.inc.php	(working copy)
@@ -50,30 +50,34 @@
 }
 
 $device = dbFetchRow("SELECT * FROM `devices` WHERE `device_id` = ?", array($device['device_id']));
-$descr  = $device['purpose'];
 
-?>
+      $form = array('type'      => 'horizontal',
+                    'id'        => 'edit',
+                    'space'     => '20px',
+                    'title'     => 'Agent Connectivity',
+                    //'icon'      => 'oicon-gear',
+                    'class'     => 'box box-solid',
+                    'fieldset'  => array('edit' => ''),
+                    );
+ 
+      $form['row'][0]['editing']   = array(
+                                      'type'        => 'hidden',
+                                      'value'       => 'yes');
+      $form['row'][1]['agent_port'] = array(
+                                      'type'        => 'text',
+                                      'name'        => 'Agent Port',
+                                      'width'       => '250px',
+                                      'readonly'    => $readonly,
+                                      'value'       => escape_html(get_dev_attrib($device, 'agent_port')));
+      $form['row'][2]['submit']    = array(
+                                      'type'        => 'submit',
+                                      'name'        => 'Save Changes',
+                                      'icon'        => 'icon-ok icon-white',
+                                      'class'       => 'btn-primary',
+                                      'readonly'    => $readonly,
+                                      'value'       => 'save');
 
-<form id="edit" name="edit" method="post" class="form-horizontal" action="">
-  <input type=hidden name="editing" value="yes">
+      print_form($form);
+      unset($form);
 
-  <div id="agent">
-    <fieldset>
-      <legend>Agent Connectivity</legend>
-      <div class="control-group">
-        <label class="control-label" for="agent_port">Agent Port</label>
-        <div class="controls">
-          <input type=text name="agent_port" size="32" value="<?php echo(escape_html(get_dev_attrib($device, 'agent_port'))); ?>"/>
-        </div>
-      </div>
-    </fieldset>
-  </div>
-
-  <div class="form-actions">
-    <button type="submit" class="btn btn-primary" name="submit" value="save"><i class="icon-ok icon-white"></i> Save Changes</button>
-  </div>
-
-</form>
-<?php
-
 // EOF
Index: html/pages/device/edit/ipmi.inc.php
===================================================================
--- html/pages/device/edit/ipmi.inc.php	(revision 7353)
+++ html/pages/device/edit/ipmi.inc.php	(working copy)
@@ -53,86 +53,76 @@
   }
 }
 
-?>
+$ipmi_userlevels = array();
+foreach ($config['ipmi']['userlevels'] as $type => $descr)
+{
+  $ipmi_userlevels[$type] = array('name' => $descr['text']);
+}
+$ipmi_interfaces = array();
+foreach ($config['ipmi']['interfaces'] as $type => $descr)
+{
+  $ipmi_interfaces[$type] = array('name' => $descr['text']);
+}
 
-<form id="edit" name="edit" method="post" action="" class="form-horizontal">
+      $form = array('type'      => 'horizontal',
+                    'id'        => 'edit',
+                    'space'     => '20px',
+                    'title'     => 'IPMI Settings',
+                    //'icon'      => 'oicon-gear',
+                    'class'     => 'box box-solid',
+                    'fieldset'  => array('edit' => ''),
+                    );
 
-<div class="box box-solid">
-  <div class="box-header with-border">
-  <h3 class="box-title">IPMI Settings</h3>
-  </div>
- <div class="box-content" style="padding-top: 10px;">
-  <input type="hidden" name="editing" value="yes">
+      $form['row'][0]['editing']   = array(
+                                      'type'        => 'hidden',
+                                      'value'       => 'yes');
+      $form['row'][1]['ipmi_hostname'] = array(
+                                      'type'        => 'text',
+                                      'name'        => 'IPMI Hostname',
+                                      'width'       => '250px',
+                                      'readonly'    => $readonly,
+                                      'value'       => escape_html(get_dev_attrib($device, 'ipmi_hostname')));
+      $form['row'][2]['ipmi_port'] = array(
+                                      'type'        => 'text',
+                                      'name'        => 'IPMI Port',
+                                      'width'       => '250px',
+                                      'readonly'    => $readonly,
+                                      'value'       => escape_html(get_dev_attrib($device, 'ipmi_port')));
+      $form['row'][3]['ipmi_username'] = array(
+                                      'type'        => 'text',
+                                      'name'        => 'IPMI Username',
+                                      'width'       => '250px',
+                                      'readonly'    => $readonly,
+                                      'value'       => escape_html(get_dev_attrib($device, 'ipmi_username')));
+      $form['row'][4]['ipmi_password'] = array(
+                                      'type'        => 'password',
+                                      'name'        => 'IPMI Password',
+                                      'width'       => '250px',
+                                      'readonly'    => $readonly,
+                                      'show_password' => !$readonly,
+                                      'value'       => escape_html(get_dev_attrib($device, 'ipmi_password')));
+      $form['row'][5]['ipmi_userlevel'] = array(
+                                      'type'        => 'select',
+                                      'name'        => 'IPMI Userlevel',
+                                      'width'       => '250px',
+                                      'readonly'    => $readonly,
+                                      'values'      => $ipmi_userlevels,                                      
+                                      'value'       => escape_html(get_dev_attrib($device, 'ipmi_userlevel')));
+      $form['row'][6]['ipmi_interface'] = array(
+                                      'type'        => 'select',
+                                      'name'        => 'IPMI Interface',
+                                      'width'       => '250px',
+                                      'readonly'    => $readonly,
+                                      'values'      => $ipmi_interfaces,                                
+                                      'value'       => escape_html(get_dev_attrib($device, 'ipmi_interface')));
+      $form['row'][7]['submit']    = array(
+                                      'type'        => 'submit',
+                                      'name'        => 'Save Changes',
+                                      'icon'        => 'icon-ok icon-white',
+                                      'class'       => 'btn-primary',
+                                      'readonly'    => $readonly,
+                                      'value'       => 'save');
+      print_form($form);
+      unset($form);
 
-  <div class="control-group">
-    <label class="control-label" for="ipmi_hostname">IPMI Hostname</label>
-    <div class="controls">
-      <input name="ipmi_hostname" type="text" size="32" value="<?php echo(escape_html(get_dev_attrib($device, 'ipmi_hostname'))); ?>"/>
-    </div>
-  </div>
-
-  <div class="control-group">
-    <label class="control-label" for="ipmi_port">IPMI Port</label>
-    <div class="controls">
-      <input type=text name="ipmi_port" size="32" value="<?php echo(escape_html(get_dev_attrib($device, 'ipmi_port'))); ?>"/>
-    </div>
-  </div>
-
-  <div class="control-group">
-    <label class="control-label" for="ipmi_username">IPMI Username</label>
-    <div class="controls">
-      <input name="ipmi_username" type="text" size="32" value="<?php echo(escape_html(get_dev_attrib($device, 'ipmi_username'))); ?>"/>
-    </div>
-  </div>
-
-  <div class="control-group">
-    <label class="control-label" for="ipmi_password">IPMI Password</label>
-    <div class="controls">
-      <input name="ipmi_password" type="password" size="32" value="<?php echo(escape_html(get_dev_attrib($device, 'ipmi_password'))); // FIXME. For passwords we should use filter instead escape! ?>"/>
-    </div>
-  </div>
-
-  <div class="control-group">
-  <label class="control-label" for="ipmi_interface">IPMI Userlevel</label>
-    <div class="controls">
-      <select class="selectpicker" name="ipmi_userlevel">
-        <?php
-        foreach ($config['ipmi']['userlevels'] as $type => $descr)
-        {
-          echo("<option value='".$type."'");
-          if ($type == get_dev_attrib($device,'ipmi_userlevel')) { echo(" selected='selected'"); }
-          echo(">".$descr['text']."</option>");
-        }
-        ?>
-      </select>
-    </div>
-  </div>
-
-  <div class="control-group">
-  <label class="control-label" for="ipmi_interface">IPMI Interface</label>
-    <div class="controls">
-      <select class="selectpicker" name="ipmi_interface">
-        <?php
-        foreach ($config['ipmi']['interfaces'] as $type => $descr)
-        {
-          echo("<option value='".$type."'");
-          if ($type == get_dev_attrib($device,'ipmi_interface')) { echo(" selected='selected'"); }
-          echo(">".$descr['text']."</option>");
-        }
-        ?>
-      </select>
-    </div>
-  </div>
-
-  <div class="form-actions">
-    <button type="submit" class="btn btn-primary" name="submit" value="save"><i class="icon-ok icon-white"></i> Save Changes</button>
-    <span class="help-inline">To disable IPMI polling, please clear the setting fields and click <strong>Save Changes</strong>.</span>
-  </div>
-
-</div>
-</div>
-</form>
-
-<?php
-
 // EOF
Index: html/pages/device/edit/ssh.inc.php
===================================================================
--- html/pages/device/edit/ssh.inc.php	(revision 7353)
+++ html/pages/device/edit/ssh.inc.php	(working copy)
@@ -46,7 +46,6 @@
 }
 
 $device = dbFetchRow("SELECT * FROM `devices` WHERE `device_id` = ?", array($device['device_id']));
-$descr  = $device['purpose'];
 
 if ($updated && $update_message)
 {
@@ -57,28 +56,33 @@
 
 print_warning("For now this option used only by 'libvirt-vminfo' discovery module (on linux devices).");
 
-?>
+      $form = array('type'      => 'horizontal',
+                    'id'        => 'edit',
+                    'space'     => '20px',
+                    'title'     => 'SSH Connectivity',
+                    //'icon'      => 'oicon-gear',
+                    'class'     => 'box box-solid',
+                    'fieldset'  => array('edit' => ''),
+                    );
+ 
+      $form['row'][0]['editing']   = array(
+                                      'type'        => 'hidden',
+                                      'value'       => 'yes');
+      $form['row'][1]['ssh_port']  = array(
+                                      'type'        => 'text',
+                                      'name'        => 'SSH Port',
+                                      'width'       => '250px',
+                                      'readonly'    => $readonly,
+                                      'value'       => escape_html($device['ssh_port']));
+      $form['row'][2]['submit']    = array(
+                                      'type'        => 'submit',
+                                      'name'        => 'Save Changes',
+                                      'icon'        => 'icon-ok icon-white',
+                                      'class'       => 'btn-primary',
+                                      'readonly'    => $readonly,
+                                      'value'       => 'save');
 
-<form id="edit" name="edit" method="post" class="form-horizontal" action="">
-  <input type=hidden name="editing" value="yes">
-
-  <div id="ssh">
-    <fieldset>
-      <legend>SSH Connectivity</legend>
-      <div class="control-group">
-        <label class="control-label" for="ssh_port">SSH Port</label>
-        <div class="controls">
-          <input type=text name="ssh_port" size="32" value="<?php echo(escape_html($device['ssh_port'])); ?>"/>
-        </div>
-      </div>
-    </fieldset>
-  </div>
-
-  <div class="form-actions">
-    <button type="submit" class="btn btn-primary" name="submit" value="save"><i class="icon-ok icon-white"></i> Save Changes</button>
-  </div>
-
-</form>
-<?php
-
+      print_form($form);
+      unset($form);
+      
 // EOF
Index: html/pages/device/edit/wmi.inc.php
===================================================================
--- html/pages/device/edit/wmi.inc.php	(revision 7353)
+++ html/pages/device/edit/wmi.inc.php	(working copy)
@@ -76,7 +76,7 @@
   <div class="col-md-6">
     <div class="box box-solid">
     <div class="box-header with-border">
-      <i class="oicon-lock-warning"></i><h3 class="box-title">WMI Authentication</h3>
+      <!-- <i class="oicon-lock-warning"></i> --><h3 class="box-title">WMI Authentication</h3>
     </div>
     <div class="box-content" style="padding-top: 10px;">
       <form id="edit" name="edit" method="post" action="" class="form-horizontal">
@@ -128,7 +128,7 @@
   <div class="col-md-6">
     <div class="box box-solid">
     <div class="box-header with-border">
-      <i class="oicon-gear"></i><h3 class="box-title">WMI Poller Modules</h3>
+      <!-- <i class="oicon-gear"></i> --><h3 class="box-title">WMI Poller Modules</h3>
     </div>
     <div class="box-content">
       <table class="table  table-striped table-condensed ">
@@ -161,12 +161,20 @@
   }
 
   echo('</td><td>');
+  
+        $form = array('type'  => 'simple');
+      // Elements
+      $form['row'][0]['toggle_poller']  = array('type'     => 'hidden',
+                                             'value'    => $module);
+      $form['row'][0]['editing']      = array('type'     => 'submit',
+                                             'name'     => $toggle,
+                                             'class'    => 'btn-mini '.$btn_class,
+                                             //'icon'     => $btn_icon,
+                                             'right'    => TRUE,
+                                             'readonly' => $readonly,
+                                             'value'    => 'toggle_poller');
+      print_form($form); unset($form);
 
-  echo('<form id="toggle_poller" name="toggle_poller" method="post" action="">
-          <input type=hidden name="toggle_poller" value="'.$module.'" />
-          <button type="submit" class="btn btn-mini '.$btn_class.'" name="Submit" value="Toggle">'.$toggle.'</button>
-          </label>
-        </form>');
   echo('</td></tr>');
 }
 
Index: html/pages/device/overview/alertlog.inc.php
===================================================================
--- html/pages/device/overview/alertlog.inc.php	(revision 7353)
+++ html/pages/device/overview/alertlog.inc.php	(working copy)
@@ -15,7 +15,7 @@
   <div class="box box-solid">
     <div class="box-header">
       <a href="<?php echo(generate_url(array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'logs', 'section' => 'alertlog'))); ?>">
-        <i class="oicon-bell--exclamation"></i> <h3 class="box-title">Alert Log</h3>
+        <i class="oicon-bell--exclamation"></i><h3 class="box-title">Alert Log</h3>
       </a>
     </div>
     <div class="box-content">
Index: html/pages/device/overview/alerts.inc.php
===================================================================
--- html/pages/device/overview/alerts.inc.php	(revision 7353)
+++ html/pages/device/overview/alerts.inc.php	(working copy)
@@ -15,7 +15,7 @@
   <div class="box box-solid">
     <div class="box-header ">
       <a href="<?php echo(generate_url(array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'logs', 'section' => 'syslog'))); ?>">
-        <i class="oicon-bell"></i> <h3 class="box-title">Alerts</h3>
+        <i class="oicon-bell"></i><h3 class="box-title">Alerts</h3>
       </a>
     </div>
     <div class="box-content">
Index: html/pages/device/overview/c6kxbar.inc.php
===================================================================
--- html/pages/device/overview/c6kxbar.inc.php	(revision 7353)
+++ html/pages/device/overview/c6kxbar.inc.php	(working copy)
@@ -15,7 +15,7 @@
 
   <div class="box box-solid">
     <div class="box-header ">
-      <i class="oicon-arrow-switch"></i> <h3 class="box-title">c6500/7600 Crossbar</h3>
+      <i class="oicon-arrow-switch"></i><h3 class="box-title">c6500/7600 Crossbar</h3>
     </div>
     <div class="box-content">
 
Index: html/pages/device/overview/events.inc.php
===================================================================
--- html/pages/device/overview/events.inc.php	(revision 7353)
+++ html/pages/device/overview/events.inc.php	(working copy)
@@ -15,7 +15,7 @@
   <div class="box box-solid">
     <div class="box-header ">
       <a href="<?php echo(generate_url(array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'logs', 'section' => 'eventlog'))); ?>">
-        <i class="oicon-clipboard-audit"></i> <h3 class="box-title">Eventlog</h3>
+        <i class="oicon-clipboard-audit"></i><h3 class="box-title">Eventlog</h3>
       </a>
     </div>
     <div class="box-content">
Index: html/pages/device/overview/mempools.inc.php
===================================================================
--- html/pages/device/overview/mempools.inc.php	(revision 7353)
+++ html/pages/device/overview/mempools.inc.php	(working copy)
@@ -26,7 +26,7 @@
     <div class="box box-solid">
       <div class="box-header ">
         <a href="<?php echo(generate_url(array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'health', 'metric' => 'mempool'))); ?>">
-          <i class="oicon-memory"></i> <h3 class="box-title">Memory</h3>
+          <i class="oicon-memory"></i><h3 class="box-title">Memory</h3>
         </a>
       </div>
       <div class="box-content">
Index: html/pages/device/overview/ports.inc.php
===================================================================
--- html/pages/device/overview/ports.inc.php	(revision 7353)
+++ html/pages/device/overview/ports.inc.php	(working copy)
@@ -25,7 +25,7 @@
 <div class="box box-solid">
   <div class="box-header ">
     <a href="<?php echo(generate_url(array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'ports'))); ?>">
-      <i class="oicon-network-ethernet"></i> <h3 class="box-title">Ports</h3>
+      <i class="oicon-network-ethernet"></i><h3 class="box-title">Ports</h3>
     </a>
   </div>
   <div class="body-box no-padding">
Index: html/pages/device/overview/processors-unix.inc.php
===================================================================
--- html/pages/device/overview/processors-unix.inc.php	(revision 7353)
+++ html/pages/device/overview/processors-unix.inc.php	(working copy)
@@ -36,7 +36,7 @@
         <div class="box box-solid">
           <div class="box-header ">
             <a href="<?php echo(generate_url(array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'health', 'metric' => 'processor'))); ?>">
-              <i class="oicon-processor"></i> <h3 class="box-title">Processors</h3>
+              <i class="oicon-processor"></i><h3 class="box-title">Processors</h3>
             </a>
           </div>
           <div class="box-content">
Index: html/pages/device/overview/processors.inc.php
===================================================================
--- html/pages/device/overview/processors.inc.php	(revision 7353)
+++ html/pages/device/overview/processors.inc.php	(working copy)
@@ -37,7 +37,7 @@
         <div class="box box-solid">
           <div class="box-header ">
             <a href="<?php echo(generate_url(array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'health', 'metric' => 'processor'))); ?>">
-              <i class="oicon-processor"></i> <h3 class="box-title">Processors</h3>
+              <i class="oicon-processor"></i><h3 class="box-title">Processors</h3>
             </a>
           </div>
           <div class="box-content">
Index: html/pages/device/overview/sensors.inc.php
===================================================================
--- html/pages/device/overview/sensors.inc.php	(revision 7353)
+++ html/pages/device/overview/sensors.inc.php	(working copy)
@@ -98,7 +98,7 @@
   <div class="box box-solid">
     <div class="box-header ">
       <a href="<?php echo(generate_url(array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'health', 'metric' => $sensor_type))); ?>">
-        <i class="<?php echo($config['sensor_types'][$sensor_type]['icon']); ?>"></i> <h3 class="box-title"><?php echo(nicecase($sensor_type)) ?></h3>
+        <i class="<?php echo($config['sensor_types'][$sensor_type]['icon']); ?>"></i><h3 class="box-title"><?php echo(nicecase($sensor_type)) ?></h3>
       </a>
     </div>
     <div class="box-content">
Index: html/pages/device/overview/services.inc.php
===================================================================
--- html/pages/device/overview/services.inc.php	(revision 7353)
+++ html/pages/device/overview/services.inc.php	(working copy)
@@ -24,7 +24,7 @@
 
   <div class="box box-solid">
     <div class="box-header">
-      <i class="oicon-gear"></i> <h3 class="box-title">Services</h3>
+      <i class="oicon-gear"></i><h3 class="box-title">Services</h3>
     </div>
     <div class="box-content">
 
Index: html/pages/device/overview/status.inc.php
===================================================================
--- html/pages/device/overview/status.inc.php	(revision 7353)
+++ html/pages/device/overview/status.inc.php	(working copy)
@@ -24,7 +24,7 @@
   <div class="box box-solid">
     <div class="box-header ">
       <a href="<?php echo(generate_url(array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'health', 'metric' => 'status'))); ?>">
-        <i class="<?php echo($config['entities']['status']['icon']); ?>"></i> <h3 class="box-title">Status Indicators</h3>
+        <i class="<?php echo($config['entities']['status']['icon']); ?>"></i><h3 class="box-title">Status Indicators</h3>
       </a>
     </div>
     <div class="box-content">
Index: html/pages/device/overview/storage.inc.php
===================================================================
--- html/pages/device/overview/storage.inc.php	(revision 7353)
+++ html/pages/device/overview/storage.inc.php	(working copy)
@@ -28,7 +28,7 @@
   <div class="box box-solid">
     <div class="box-header ">
       <a href="<?php echo(generate_url(array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'health', 'metric' => 'storage'))); ?>">
-        <i class="oicon-drive"></i> <h3 class="box-title">Storage</h3>
+        <i class="oicon-drive"></i><h3 class="box-title">Storage</h3>
       </a>
     </div>
     <div class="box-content">
Index: html/pages/device/overview/syslog.inc.php
===================================================================
--- html/pages/device/overview/syslog.inc.php	(revision 7353)
+++ html/pages/device/overview/syslog.inc.php	(working copy)
@@ -20,7 +20,7 @@
   <div class="box box-solid">
     <div class="box-header ">
       <a href="<?php echo(generate_url(array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'logs', 'section' => 'syslog'))); ?>">
-        <i class="oicon-clipboard-eye"></i> <h3 class="box-title">Syslog</h3>
+        <i class="oicon-clipboard-eye"></i><h3 class="box-title">Syslog</h3>
       </a>
     </div>
     <div class="box-content">
Index: html/pages/device/overview/toner.inc.php
===================================================================
--- html/pages/device/overview/toner.inc.php	(revision 7353)
+++ html/pages/device/overview/toner.inc.php	(working copy)
@@ -22,7 +22,7 @@
   <div class="box box-solid">
     <div class="box-header ">
       <a href="<?php echo(generate_url(array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'printing'))); ?>">
-        <i class="oicon-contrast"></i> <h3 class="box-title">Toner</h3>
+        <i class="oicon-contrast"></i><h3 class="box-title">Toner</h3>
       </a>
     </div>
     <div class="box-content">
Index: html/pages/device/overview/ucd_mem.inc.php
===================================================================
--- html/pages/device/overview/ucd_mem.inc.php	(revision 7353)
+++ html/pages/device/overview/ucd_mem.inc.php	(working copy)
@@ -15,7 +15,7 @@
     <div class="box box-solid">
       <div class="box-header ">
         <a href="<?php echo(generate_url(array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'health', 'metric' => 'mempool'))); ?>">
-           <i class="oicon-memory"></i> <h3 class="box-title">Memory</h3>
+           <i class="oicon-memory"></i><h3 class="box-title">Memory</h3>
         </a>
       </div>
       <div class="box-content">
Index: html/pages/device/port/vlans.inc.php
===================================================================
--- html/pages/device/port/vlans.inc.php	(revision 7353)
+++ html/pages/device/port/vlans.inc.php	(working copy)
@@ -26,7 +26,7 @@
   echo('<tr>');
 
   echo('<td style="width: 100px;" class="entity-title"> Vlan ' . $vlan['vlan'] . '</td>');
-  echo('<td style="width: 200px;" class="small">' . $vlan['vlan_descr'] . '</td>');
+  echo('<td style="width: 200px;" class="small">' . $vlan['vlan_name'] . '</td>');
 
   if ($vlan['state'] == "blocking") { $class="red"; } elseif ($vlan['state'] == "forwarding" ) { $class="green"; } else { $class = "none"; }
 
Index: html/pages/edituser.inc.php
===================================================================
--- html/pages/edituser.inc.php	(revision 7353)
+++ html/pages/edituser.inc.php	(working copy)
@@ -958,11 +958,11 @@
 
         echo('<tr class="'.$user['row_class'].'">');
         echo('<td class="state-marker"></td>');
-        echo('<td><strong><a href="'.$user['edit_url'].'">'.$user['username'].'</a></strong></td>');
+        echo('<td><strong><a href="'.$user['edit_url'].'">'.escape_html($user['username']).'</a></strong></td>');
         //echo('<td><strong>'.$user['level'].'</strong></td>');
-        echo('<td><span class="label label-'.$user['row_class'].'">'.$user['level_label'].'</span></td>');
-        echo('<td><strong>'.$user['realname'].'</strong></td>');
-        echo('<td><strong>'.$user['email'].'</strong></td>');
+        echo('<td><i class="'.$user['icon'].'"></i> <span class="label label-'.$user['row_class'].'">'.$user['level_label'].'</span></td>');
+        echo('<td><strong>'.escape_html($user['realname']).'</strong></td>');
+        echo('<td><strong>'.escape_html($user['email']).'</strong></td>');
 
         echo('</tr>');
       }
Index: html/pages/eventlog.inc.php
===================================================================
--- html/pages/eventlog.inc.php	(revision 7353)
+++ html/pages/eventlog.inc.php	(working copy)
@@ -53,6 +53,7 @@
                   'id'      => 'message',
                   'width'   => '150px',
                   'placeholder' => 'Message',
+                  'submit_by_key' => TRUE,
                   'value'   => $vars['message']);
 
 //Severity field
Index: html/pages/front/default.php
===================================================================
--- html/pages/front/default.php	(revision 7353)
+++ html/pages/front/default.php	(working copy)
@@ -38,17 +38,10 @@
     case "custom_traffic":
       show_customtraffic($config);
       break;
-
     case "alert_table":
-      echo '<div class="box box-solid">';
-      echo '  <div class="box-header with-border">';
-      echo '    <h3 class="box-title"><a href="/alerts/">Current Alerts</a></h3>';
-      echo '  </div>';
-      echo '  <div class="box-content no-padding">';
+      echo generate_box_open(array('title' => '<a href="/alerts/">Current Alerts</a>', 'header-border' => TRUE));
       print_alert_table(array('status' => 'failed', 'pagination' => FALSE));
-      echo '  </div>';
-      echo '</div>';
-
+      echo generate_box_close();
       break;
     case "splitlog":
       show_splitlog($config);
@@ -99,13 +92,11 @@
   } else {
     print_error("Unknown map type: $map");
   }
-
 ?>
   </div>
 </div>
 <?php
-}
-  // End show_map
+} // End show_map
 
   function show_traffic($config)
   {
@@ -195,12 +186,11 @@
         echo('</div>');
       }
     }
-  }
-  // End show_traffic
+  } // End show_traffic
 
   function show_customtraffic($config)
   {
-  // Show Custom Traffic
+    // Show Custom Traffic
     if ($_SESSION['userlevel'] >= '5')
     {
       $config['frontpage']['custom_traffic']['title'] = (empty($config['frontpage']['custom_traffic']['title']) ? "Custom Traffic" : $config['frontpage']['custom_traffic']['title']);
@@ -331,12 +321,9 @@
   function show_status($config)
   {
     // Show Status
-    echo('<div class="row">' . PHP_EOL);
-    echo('  <div class="col-sm-12">' . PHP_EOL);
-    echo('    <h3><a href="/alerts/">Device Alerts</a></h3>' . PHP_EOL);
+    echo generate_box_open(array('title' => '<a href="/alerts/">Device Alerts</a>', 'header-border' => TRUE));
     print_status($config['frontpage']['device_status']);
-    echo('  </div>' . PHP_EOL);
-    echo('</div>' . PHP_EOL);
+    echo generate_box_close();
   } // End show_status
 
   function show_status_boxes($config)
@@ -352,25 +339,16 @@
   function show_syslog($config)
   {
     // Show syslog
-    echo('<div class="row">' . PHP_EOL);
-    echo('  <div class="col-sm-12 ">' . PHP_EOL);
-    echo('    <h3><a href="/syslog/">Recent Syslog Messages</a></h3>' . PHP_EOL);
+    echo generate_box_open(array('title' => '<a href="/syslog/">Recent Syslog Messages</a>', 'header-border' => TRUE));
     print_syslogs(array('short' => TRUE, 'pagesize' => $config['frontpage']['syslog']['items'], 'priority' => $config['frontpage']['syslog']['priority']));
-    echo('  </div>' . PHP_EOL);
-    echo('</div>' . PHP_EOL);
+    echo generate_box_close();
   } // End show_syslog
 
   function show_eventlog($config)
   {
-
-    echo '<div class="box box-solid">';
-    echo '  <div class="box-header with-border">';
-    echo '    <h3 class="box-title"><a href="/alerts/">Recent Events</a></h3>';
-    echo '  </div>';
-    echo '  <div class="box-content no-padding">';
+    echo generate_box_open(array('title' => '<a href="/eventlog/">Recent Events</a>', 'header-border' => TRUE));
     print_events(array('short' => TRUE, 'pagesize' => $config['frontpage']['eventlog']['items'], 'severity' => $config['frontpage']['eventlog']['severity']));
-    echo '  </div>';
-    echo '</div>';
+    echo generate_box_close();
   } // End show_eventlog
 
   function show_splitlog($config)
@@ -377,28 +355,17 @@
   {
     echo '<div class="row">' . PHP_EOL;
     echo '  <div class="col-sm-6">' . PHP_EOL;
-    echo '    <div class="box box-solid">';
-    echo '      <div class="box-header with-border">';
-    echo '        <h3 class="box-title"><a href="/eventlog/">Recent Events</a></h3>';
-    echo '      </div>';
-    echo '      <div class="box-content no-padding">';
+    echo generate_box_open(array('title' => '<a href="/eventlog/">Recent Events</a>', 'header-border' => TRUE));
     print_events(array('short' => TRUE, 'pagesize' => $config['frontpage']['eventlog']['items'], 'severity' => $config['frontpage']['eventlog']['severity']));
-    echo '      </div>';
-    echo '    </div>';
+    echo generate_box_close();
     echo '  </div>';
 
     echo '  <div class="col-sm-6">' . PHP_EOL;
-    echo '    <div class="box box-solid">';
-    echo '      <div class="box-header with-border">';
-    echo '        <h3 class="box-title"><a href="/syslog/">Recent Syslog Messages</a></h3>';
-    echo '      </div>';
-    echo '      <div class="box-content no-padding">';
+    echo generate_box_open(array('title' => '<a href="/syslog/">Recent Syslog Messages</a>', 'header-border' => TRUE));
     print_syslogs(array('short' => true, 'pagesize' => $config['frontpage']['syslog']['items'], 'priority' => $config['frontpage']['syslog']['priority']));
-    echo '      </div>';
-    echo '    </div>';
+    echo generate_box_close();
     echo '  </div>';
     echo '</div>';
-
   }
 
 // EOF
Index: html/pages/group.inc.php
===================================================================
--- html/pages/group.inc.php	(revision 7353)
+++ html/pages/group.inc.php	(working copy)
@@ -136,7 +136,7 @@
             <td>', $group['group_id'], '</td>
             <td><i class="', $entity_type['icon'], '"></i> ', nicecase($group['entity_type']), '</td>
             <td><strong>', escape_html($group['group_name']), '</strong><br /><i>', escape_html($group['group_descr']), '</i></td>
-            <td><span class="badge badge-info" style="float:right;">', $group['member_count'], '</span></td>
+            <td><span class="label" style="float:right;">', $group['member_count'], '</span></td>
           </tr>
         </tbody>
        </table>
Index: html/pages/groups.inc.php
===================================================================
--- html/pages/groups.inc.php	(revision 7353)
+++ html/pages/groups.inc.php	(working copy)
@@ -134,7 +134,7 @@
   // Print the count of entities this alert applies to and a popup containing a list and Print breakdown of entities by status.
   // We assume each row here is going to be two lines, so we just <br /> them.
   echo '<td>';
-  echo '<i><span class="label">' . $group['member_count'] . '</span></i><br />';
+  echo '<span class="label">' . $group['member_count'] . '</span><br />';
 
   echo '<i class="' . $entity_type['icon'], '"></i> ', nicecase($group['entity_type']);
 
Index: html/pages/neighbours.inc.php
===================================================================
--- html/pages/neighbours.inc.php	(revision 7353)
+++ html/pages/neighbours.inc.php	(working copy)
@@ -77,7 +77,14 @@
                   'width'   => '180px',
                   'value'   => escape_html($vars['version']),
                   'values'  => $versions_array);
-
+//Known field
+$search[] = array('type'    => 'select',
+                  //'title'   => 'All Devices',
+                  'id'      => 'remote_port_id',
+                  'width'   => '180px',
+                  'value'   => escape_html($vars['remote_port_id']),
+                  'values'  => array('' => 'All Devices', '1' => 'Known Devices', '0' => 'Unknown Devices'));
+                  
 print_search($search, 'Neighbours', NULL, 'neighbours/');
 
 $vars['pagination'] = 1;
Index: html/pages/packages.inc.php
===================================================================
--- html/pages/packages.inc.php	(revision 7353)
+++ html/pages/packages.inc.php	(working copy)
@@ -18,8 +18,7 @@
     switch ($var)
     {
       case 'name':
-        $where .= " AND `$var` = ?";
-        $param[] = $value;
+        $where .= generate_query_values($value, $var);
         break;
     }
   }
Index: html/pages/ports.inc.php
===================================================================
--- html/pages/ports.inc.php	(revision 7353)
+++ html/pages/ports.inc.php	(working copy)
@@ -24,6 +24,7 @@
 
 $param = array();
 
+if (!isset($vars['sort'])) { $vars['sort'] = 'device'; }
 //if (!isset($vars['ignore']))   { $vars['ignore'] = "0"; }
 if (!isset($vars['disabled'])) { $vars['disabled'] = "0"; }
 if (!isset($vars['deleted']))  { $vars['deleted'] = "0"; }
Index: html/pages/routing/vrf.inc.php
===================================================================
--- html/pages/routing/vrf.inc.php	(revision 7353)
+++ html/pages/routing/vrf.inc.php	(working copy)
@@ -11,12 +11,15 @@
  *
  */
 
+if ($_SESSION['userlevel'] < 5)
+{
+  print_error_permission();
+  return;
+}
+
 $link_array = array('page'    => 'routing',
                     'protocol' => 'vrf');
 
-if ($_SESSION['userlevel'] >= '5')
-{
-
   $navbar = array('brand' => "VRFs", 'class' => "navbar-narrow");
 
   $navbar['options']['vrf']['text']   = 'All VRFs';
@@ -187,8 +190,5 @@
       echo('<div style="height: 10px;"></div>');
     }
   }
-} else {
-  include("includes/error-no-perm.inc.php");
-} // End Permission if
 
 // EOF