r1940 + align allocations table according to the current style
[racktables] / inc / interface.php
index a7ee351..21b2ed0 100644 (file)
@@ -59,20 +59,25 @@ function renderIndex ()
 
 function renderRackspace ()
 {
-?>
-       <table border=0 cellpadding=10 cellpadding=1>
-<?php
+       $tagfilter = getTagFilter();
+       $tagfilter_str = getTagFilterStr ($tagfilter);
+       echo "<table class=objview border=0 width='100%'><tr><td class=pcleft>";
+       renderTagFilterPortlet ($tagfilter, 'rack');
+       echo '</td><td class=pcright>';
+       echo '<table border=0 cellpadding=10 cellpadding=1>';
        // generate thumb gallery
-       $rackrowList = getRackRowInfo();
+       $rackrowList = getRackspace ($tagfilter);
        global $root, $nextorder;
        $rackwidth = getConfigVar ('rtwidth_0') + getConfigVar ('rtwidth_1') + getConfigVar ('rtwidth_2');
        $order = 'odd';
        foreach ($rackrowList as $rackrow)
        {
-               echo "<tr class=row_${order}><th><a href='${root}?page=row&row_id=${rackrow['dict_key']}'>${rackrow['dict_value']}</a></th>";
-               $rackList = getRacksForRow ($rackrow['dict_key']);
+               echo "<tr class=row_${order}><th class=tdleft>";
+               echo "<a href='${root}?page=row&row_id=${rackrow['row_id']}${tagfilter_str}'>";
+               echo "${rackrow['row_name']}</a></th>";
+               $rackList = getRacksForRow ($rackrow['row_id'], $tagfilter);
                echo "<td><table border=0 cellspacing=5><tr>";
-               foreach ($rackList as $dummy => $rack)
+               foreach ($rackList as $rack)
                {
                        echo "<td align=center><a href='${root}?page=rack&rack_id=${rack['id']}'>";
                        echo "<img border=0 width=${rackwidth} height=";
@@ -85,6 +90,7 @@ function renderRackspace ()
                $order = $nextorder[$order];
        }
        echo "</table>\n";
+       echo "</td></tr></table>\n";
 }
 
 function renderRow ($row_id)
@@ -99,7 +105,8 @@ function renderRow ($row_id)
                showError ('getRackRowInfo() failed', __FUNCTION__);
                return;
        }
-       $rackList = getRacksForRow ($row_id);
+       $tagfilter = getTagFilter();
+       $rackList = getRacksForRow ($row_id, $tagfilter);
        // Main layout starts.
        echo "<table border=0 class=objectview cellspacing=0 cellpadding=0>";
 
@@ -115,14 +122,14 @@ function renderRow ($row_id)
        echo "</table><br>\n";
        finishPortlet();
 
-       echo "</td><td class=pcright>";
+       echo "</td><td class=pcright rowspan=2>";
 
        global $root, $nextorder;
        $rackwidth = getConfigVar ('rtwidth_0') + getConfigVar ('rtwidth_1') + getConfigVar ('rtwidth_2');
        $order = 'odd';
        startPortlet ('Racks');
        echo "<table border=0 cellspacing=5 align='center'><tr>";
-       foreach ($rackList as $dummy => $rack)
+       foreach ($rackList as $rack)
        {
                echo "<td align=center class=row_${order}><a href='${root}?page=rack&rack_id=${rack['id']}'>";
                echo "<img border=0 width=" . $rackwidth * getConfigVar ('ROW_SCALE') . " height=";
@@ -134,7 +141,10 @@ function renderRow ($row_id)
        }
        echo "</tr></table>\n";
        finishPortlet();
+       echo "</td></tr>";
 
+       echo "<tr><td class=pcleft>";
+       renderTagFilterPortlet ($tagfilter, 'rack', 'row_id', $row_id);
        echo "</td></tr></table>";
 }
 
@@ -169,14 +179,23 @@ function renderRack ($rack_id = 0, $hl_obj_id = 0)
        markupObjectProblems ($rackData);
        $prev_id = getPrevIDforRack ($rackData['row_id'], $rack_id);
        $next_id = getNextIDforRack ($rackData['row_id'], $rack_id);
-       echo "<center>\n<h2><a href='${root}?page=row&row_id=${rackData['row_id']}'>${rackData['row_name']}</a> :";
+       echo "<center><table border=0><tr valign=middle>";
+       echo "<td><h2><a href='${root}?page=row&row_id=${rackData['row_id']}'>${rackData['row_name']}</a> :</h2></td>";
        // FIXME: use 'bypass'?
        if ($prev_id != NULL)
-               echo " <a href='${root}?page=rack&rack_id=${prev_id}'>&lt; &lt; &lt;</a>";
-       echo " <a href='${root}?page=rack&rack_id=${rackData['id']}'>${rackData['name']}</a>";
+       {
+               echo "<td><a href='${root}?page=rack&rack_id=${prev_id}'>";
+               printImageHREF ('prev', 'previous rack');
+               echo "</a></td>";
+       }
+       echo "<td><h2><a href='${root}?page=rack&rack_id=${rackData['id']}'>${rackData['name']}</a></h2></td>";
        if ($next_id != NULL)
-               echo " <a href='${root}?page=rack&rack_id=${next_id}'>&gt; &gt; &gt;</a>";
-       echo "</h2>\n";
+       {
+               echo "<td><a href='${root}?page=rack&rack_id=${next_id}'>";
+               printImageHREF ('next', 'next rack');
+               echo "</a></td>";
+       }
+       echo "</h2></td></tr></table>\n";
        if ($rackData['left_is_front'] == 'yes')
                $markup = array ('left' => 'Front', 'right' => 'Back');
        else
@@ -236,74 +255,52 @@ function renderRack ($rack_id = 0, $hl_obj_id = 0)
        echo "</table></center>\n";
 }
 
-function renderNewObjectForm ()
-{
-       global $pageno, $tabno;
-
-       // Look for current submit.
-       if (isset ($_REQUEST['got_data']))
-       {
-               $log = array();
-               assertUIntArg ('object_type_id');
-               assertStringArg ('object_name', TRUE);
-               assertStringArg ('object_label', TRUE);
-               assertStringArg ('object_barcode', TRUE);
-               assertStringArg ('object_asset_no', TRUE);
-               $type_id = $_REQUEST['object_type_id'];
-               $name = $_REQUEST['object_name'];
-               $label = $_REQUEST['object_label'];
-               $asset_no = $_REQUEST['object_asset_no'];
-               $barcode = $_REQUEST['object_barcode'];
-
-               if (commitAddObject ($name, $label, $barcode, $type_id, $asset_no) === TRUE)
-                       $log[] = array ('code' => 'success', 'message' => "Added new object '${name}'");
-               else
-                       $log[] = array ('code' => 'error', 'message' => __FUNCTION__ . ': commitAddObject() failed');
-               printLog ($log);
-       }
-
-       // Render a form for the next.
-       startPortlet ('Object attributes');
-       echo '<form>';
-       echo "<input type=hidden name=page value=${pageno}>";
-       echo "<input type=hidden name=tab value=${tabno}>";
-       echo '<table border=0 align=center>';
-       echo "<tr><th class=tdright>Type:</th><td class=tdleft>";
-       printSelect (getObjectTypeList(), 'object_type_id');
-       echo "</td></tr>\n";
-       echo "<tr><th class=tdright>Common name:</th><td class=tdleft><input type=text name=object_name></td></tr>\n";
-       echo "<tr><th class=tdright>Visible label:</th><td class=tdleft><input type=text name=object_label></td></tr>\n";
-       echo "<tr><th class=tdright>Asset tag:</th><td class=tdleft><input type=text name=object_asset_no></td></tr>\n";
-       echo "<tr><th class=tdright>Barcode:</th><td class=tdleft><input type=text name=object_barcode></td></tr>\n";
-       echo "<tr><td class=submit colspan=2><input type=submit name=got_data value='Create'></td></tr>\n";
-       echo '</form></table>';
-       finishPortlet();
-}
-
 function renderNewRackForm ($row_id)
 {
        global $pageno, $tabno;
+       $log = array();
+       $taglist = isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array();
 
        // Look for current submit.
        if (isset ($_REQUEST['got_data']))
        {
-               $log = array();
-               assertStringArg ('rack_name');
-               assertUIntArg ('rack_height');
-               assertStringArg ('rack_comment', TRUE);
+               assertStringArg ('rack_name', __FUNCTION__);
+               assertUIntArg ('rack_height1', __FUNCTION__);
+               assertStringArg ('rack_comment', __FUNCTION__, TRUE);
                $name = $_REQUEST['rack_name'];
-               $height = $_REQUEST['rack_height'];
-               $comment = $_REQUEST['rack_comment'];
 
-               if (commitAddRack ($name, $height, $row_id, $comment) === TRUE)
+               if (commitAddRack ($name, $_REQUEST['rack_height1'], $row_id, $_REQUEST['rack_comment'], $taglist) === TRUE)
                        $log[] = array ('code' => 'success', 'message' => "Added new rack '${name}'");
                else
-                       $log[] = array ('code' => 'error', 'message' => __FUNCTION__ . 'commitAddRack() failed');
-               printLog ($log);
+                       $log[] = array ('code' => 'error', 'message' => __FUNCTION__ . ': commitAddRack() failed');
+       }
+       elseif (isset ($_REQUEST['got_mdata']))
+       {
+               assertUIntArg ('rack_height2', __FUNCTION__);
+               assertStringArg ('rack_names', __FUNCTION__, TRUE);
+               // copy-and-paste from renderAddMultipleObjectsForm()
+               $names1 = explode ('\n', $_REQUEST['rack_names']);
+               $names2 = array();
+               foreach ($names1 as $line)
+               {
+                       $parts = explode ('\r', $line);
+                       reset ($parts);
+                       if (empty ($parts[0]))
+                               continue;
+                       else
+                               $names2[] = rtrim ($parts[0]);
+               }
+               foreach ($names2 as $cname)
+                       if (commitAddRack ($cname, $_REQUEST['rack_height2'], $row_id, '', $taglist) === TRUE)
+                               $log[] = array ('code' => 'success', 'message' => "Added new rack '${cname}'");
+                       else
+                               $log[] = array ('code' => 'error', 'message' => __FUNCTION__ . ': commitAddRack() failed');
        }
+       printLog ($log);
 
+       echo "<table border=0 width='100%'><tr><td valign=top>";
        // Render a form for the next.
-       startPortlet ('Rack attributes');
+       startPortlet ('Add one');
        echo '<form>';
        echo "<input type=hidden name=page value=${pageno}>";
        echo "<input type=hidden name=tab value=${tabno}>";
@@ -312,12 +309,33 @@ function renderNewRackForm ($row_id)
        $defh = getConfigVar ('DEFAULT_RACK_HEIGHT');
        if ($defh == 0)
                $defh = '';
-       echo "<tr><th class=tdright>Name (required):</th><td class=tdleft><input type=text name=rack_name tabindex=1></td></tr>\n";
-       echo "<tr><th class=tdright>Height in units (required):</th><td class=tdleft><input type=text name=rack_height tabindex=2 value='${defh}'></td></tr>\n";
+       echo "<tr><th class=tdright>Rack name (*):</th><td class=tdleft><input type=text name=rack_name tabindex=1></td></tr>\n";
+       echo "<tr><th class=tdright>Height in units (*):</th><td class=tdleft><input type=text name=rack_height1 tabindex=2 value='${defh}'></td></tr>\n";
        echo "<tr><th class=tdright>Comment:</th><td class=tdleft><input type=text name=rack_comment tabindex=3></td></tr>\n";
-       echo "<tr><td class=submit colspan=2><input type=submit name=got_data value='Create'></td></tr>\n";
+       echo "<tr><td class=submit colspan=2><input type=submit name=got_data value='Add'></td></tr>\n";
+       echo '</table>';
+       finishPortlet();
+       echo '</td>';
+
+       echo '<td rowspan=2 valign=top>';
+       startPortlet ('Pre-assigned tags');
+       renderTagSelect();
+       finishPortlet();
+       echo '</td></tr>';
+
+       echo '<tr><td valign=top>';
+       startPortlet ('Add many');
+       echo '<table border=0 align=center>';
+       $defh = getConfigVar ('DEFAULT_RACK_HEIGHT');
+       if ($defh == 0)
+               $defh = '';
+       echo "<tr><th class=tdright>Height in units (*):</th><td class=tdleft><input type=text name=rack_height2 value='${defh}'></td></tr>\n";
+       echo "<tr><th class=tdright>Rack names (*):</th><td class=tdleft><textarea name=rack_names cols=40 rows=25></textarea></td></tr>\n";
+       echo "<tr><td class=submit colspan=2><input type=submit name=got_mdata value='Add'></td></tr>\n";
        echo '</form></table>';
        finishPortlet();
+       echo '</td></tr>';
+       echo '</table>';
 }
 
 function renderEditObjectForm ($object_id)
@@ -328,11 +346,11 @@ function renderEditObjectForm ($object_id)
        {
                $log = array();
                // object_id is already verified by page handler
-               assertUIntArg ('object_type_id');
-               assertStringArg ('object_name', TRUE);
-               assertStringArg ('object_label', TRUE);
-               assertStringArg ('object_barcode', TRUE);
-               assertStringArg ('object_asset_no', TRUE);
+               assertUIntArg ('object_type_id', __FUNCTION__);
+               assertStringArg ('object_name', __FUNCTION__, TRUE);
+               assertStringArg ('object_label', __FUNCTION__, TRUE);
+               assertStringArg ('object_barcode', __FUNCTION__, TRUE);
+               assertStringArg ('object_asset_no', __FUNCTION__, TRUE);
                $type_id = $_REQUEST['object_type_id'];
                if (isset ($_REQUEST['object_has_problems']) and $_REQUEST['object_has_problems'] == 'on')
                        $has_problems = 'yes';
@@ -371,6 +389,7 @@ function renderEditObjectForm ($object_id)
        echo "<input type=hidden name=page value=${pageno}>";
        echo "<input type=hidden name=tab value=${tabno}>";
        echo "<input type=hidden name=object_id value=${object_id}>";
+       echo "<input type=hidden name=got_data value=1>";
        echo '<table border=0 align=center>';
        echo "<tr><th class=tdright>Type:</th><td class=tdleft>";
        printSelect (getObjectTypeList(), 'object_type_id', $object['objtype_id']);
@@ -385,7 +404,9 @@ function renderEditObjectForm ($object_id)
                echo ' checked';
        echo "></td></tr>\n";
        echo "<tr><td colspan=2><b>Comment:</b><br><textarea name=object_comment rows=10 cols=80>${object['comment']}</textarea></td></tr>";
-       echo "<tr><th class=submit colspan=2><input type=submit name=got_data value='Update'></td></tr>\n";
+       echo "<tr><th class=submit colspan=2>";
+       printImageHREF ('SAVE', 'Save changes', TRUE);
+       echo "</td></tr>\n";
        echo '</form></table><br>';
        finishPortlet();
        echo '</td>';
@@ -412,11 +433,11 @@ function renderEditObjectForm ($object_id)
                if (!empty ($record['value']))
                {
                        echo "<a href=${root}process.php?page=${pageno}&tab=${tabno}&op=del&object_id=${object_id}&attr_id=${record['id']}>";
-                       printImageHREF ('delete', 'Delete value');
+                       printImageHREF ('clear', 'Clear value');
                        echo '</a>';
                }
                else
-                       printImageHREF ('nodelete', 'Already empty');
+                       echo '&nbsp;';
                echo '</td>';
                echo "<td class=tdright>${record['name']}:</td><td class=tdleft>";
                switch ($record['type'])
@@ -435,7 +456,9 @@ function renderEditObjectForm ($object_id)
                echo "</td></tr>\n";
                $i++;
        }
-       echo "<tr><td colspan=3><input type=submit value='Update'></td></tr>\n";
+       echo "<tr><td colspan=3>";
+       printImageHREF ('SAVE', 'Save changes', TRUE);
+       echo "</td></tr>\n";
        echo "</form>";
        echo "</table>\n";
        finishPortlet();
@@ -459,10 +482,10 @@ function renderEditRackForm ($rack_id)
        if (isset ($_REQUEST['got_data']))
        {
                $log = array();
-               assertUIntArg ('rack_row_id');
-               assertUIntArg ('rack_height');
-               assertStringArg ('rack_name');
-               assertStringArg ('rack_comment', TRUE);
+               assertUIntArg ('rack_row_id', __FUNCTION__);
+               assertUIntArg ('rack_height', __FUNCTION__);
+               assertStringArg ('rack_name', __FUNCTION__);
+               assertStringArg ('rack_comment', __FUNCTION__, TRUE);
                $row_id = $_REQUEST['rack_row_id'];
                $height = $_REQUEST['rack_height'];
                $name = $_REQUEST['rack_name'];
@@ -509,17 +532,88 @@ function renderEditRackForm ($rack_id)
 // This is a helper for creators and editors.
 function printSelect ($rowList, $select_name, $selected_id = 1)
 {
-       echo "<select name=${select_name}>";
+       // First collect all data for OPTGROUPs, then ouput it and dump
+       // the rest of records as is.
+       $optgroup = array();
+       $other = array();
        foreach ($rowList as $dict_key => $dict_value)
        {
-               echo "<option value=${dict_key}";
-               if ($dict_key == $selected_id)
-                       echo ' selected';
-               echo ">${dict_value}</option>";
+               if (strpos ($dict_value, '%GSKIP%') !== FALSE)
+               {
+                       $tmp = explode ('%GSKIP%', $dict_value, 2);
+                       $optgroup[$tmp[0]][$dict_key] = $tmp[1];
+               }
+               elseif (strpos ($dict_value, '%GPASS%') !== FALSE)
+               {
+                       $tmp = explode ('%GPASS%', $dict_value, 2);
+                       $optgroup[$tmp[0]][$dict_key] = $tmp[1];
+               }
+               else
+                       $other[$dict_key] = $dict_value;
+       }
+       echo "<select name=${select_name}>";
+       if (!count ($optgroup))
+       {
+               foreach ($other as $dict_key => $dict_value)
+               {
+                       echo "<option value=${dict_key}";
+                       if ($dict_key == $selected_id)
+                               echo ' selected';
+                       echo ">${dict_value}</option>";
+               }
+       }
+       else
+       {
+               foreach ($optgroup as $groupname => $groupdata)
+               {
+                       echo "<optgroup label='${groupname}'>";
+                       foreach ($groupdata as $dict_key => $dict_value)
+                       {
+                               echo "<option value=${dict_key}";
+                               if ($dict_key == $selected_id)
+                                       echo ' selected';
+                               echo ">${dict_value}</option>";
+                       }
+                       echo "</optgroup>\n";
+               }
+               if (count ($other))
+               {
+                       echo "<optgroup label='other'>\n";
+                       foreach ($other as $dict_key => $dict_value)
+                       {
+                               echo "<option value=${dict_key}";
+                               if ($dict_key == $selected_id)
+                                       echo ' selected';
+                               echo ">${dict_value}</option>";
+                       }
+                       echo "</optgroup>\n";
+               }
        }
        echo "</select>";
 }
 
+// used by renderGridForm() and renderRackPage()
+function renderRackInfoPortlet ($rackData)
+{
+       global $root;
+       startPortlet ('summary');
+       echo "<table border=0 cellspacing=0 cellpadding=3 width='100%'>\n";
+       echo "<tr><th width='50%' class=tdright>Rack row:</th><td class=tdleft>${rackData['row_name']}</td></tr>\n";
+       echo "<tr><th width='50%' class=tdright>Name:</th><td class=tdleft>${rackData['name']}</td></tr>\n";
+       echo "<tr><th width='50%' class=tdright>Height:</th><td class=tdleft>${rackData['height']}</td></tr>\n";
+       echo "<tr><th width='50%' class=tdright>Utilization:</th><td class=tdleft>";
+       renderProgressBar (getRSUforRack ($rackData));
+       echo "</td></tr>\n";
+       echo "<tr><th width='50%' class=tdright>Objects:</th><td class=tdleft>";
+       echo getObjectCount ($rackData);
+       echo "</td></tr>\n";
+       printTagTRs ("${root}?page=rackspace&");
+       if (!empty ($rackData['comment']))
+               echo "<tr><th width='50%' class=tdright>Comment:</th><td class=tdleft>${rackData['comment']}</td></tr>\n";
+       echo '</table>';
+       finishPortlet();
+}
+
 // This is a universal editor of rack design/waste.
 function renderGridForm ($rack_id = 0, $filter, $header, $submit, $state1, $state2)
 {
@@ -535,14 +629,17 @@ function renderGridForm ($rack_id = 0, $filter, $header, $submit, $state1, $stat
        }
 
        global $root, $pageno, $tabno;
-       $filter($rackData);
+       $filter ($rackData);
        markupObjectProblems ($rackData);
 
        // Process form submit.
        if (isset ($_REQUEST['do_update']))
        {
                $log[] = processGridForm ($rackData, $state1, $state2);
-               printLog($log);
+               printLog ($log);
+               $rackData = getRackData ($rack_id);
+               $filter ($rackData);
+               markupObjectProblems ($rackData);
        }
 
        // Render the result whatever it is.
@@ -552,15 +649,7 @@ function renderGridForm ($rack_id = 0, $filter, $header, $submit, $state1, $stat
 
        // Left column with information portlet.
        echo "<tr><td class=pcleft height='1%' width='50%'>";
-       startPortlet ('Rack information');
-       echo "<table border=0 cellspacing=0 cellpadding=3 width='100%'>\n";
-       echo "<tr><th width='50%' class=tdright>Rack name:</th><td class=tdleft>${rackData['name']}</td></tr>\n";
-       echo "<tr><th width='50%' class=tdright>Height:</th><td class=tdleft>${rackData['height']}</td></tr>\n";
-       echo "<tr><th width='50%' class=tdright>Rack row:</th><td class=tdleft>${rackData['row_name']}</td></tr>\n";
-       echo "<tr><th width='50%' class=tdright>Comment:</th><td class=tdleft>${rackData['comment']}</td></tr>\n";
-       echo "</table>\n";
-       finishPortlet();
-
+       renderRackInfoPortlet ($rackData);
        echo "</td>\n";
        echo "<td class=pcright>";
 
@@ -645,7 +734,8 @@ function renderRackObject ($object_id = 0)
                echo "<tr><th width='50%' class=tdright>Common name:</th><td class=tdleft>${info['name']}</td></tr>\n";
        elseif (in_array ($info['objtype_id'], explode (',', getConfigVar ('NAMEFUL_OBJTYPES'))))
                echo "<tr><td colspan=2 class=msg_error>Common name is missing.</td></tr>\n";
-       echo "<tr><th width='50%' class=tdright>Object type:</th><td class=tdleft>${info['objtype_name']}</td></tr>\n";
+       echo "<tr><th width='50%' class=tdright>Object type:</th>";
+       echo "<td class=tdleft><a href='${root}?page=objgroup&group_id=${info['objtype_id']}'>${info['objtype_name']}</a></td></tr>\n";
        if (!empty ($info['asset_no']))
                echo "<tr><th width='50%' class=tdright>Asset tag:</th><td class=tdleft>${info['asset_no']}</td></tr>\n";
        elseif (in_array ($info['objtype_id'], explode (',', getConfigVar ('REQUIRE_ASSET_TAG_FOR'))))
@@ -656,9 +746,10 @@ function renderRackObject ($object_id = 0)
                echo "<tr><th width='50%' class=tdright>Barcode:</th><td class=tdleft>${info['barcode']}</td></tr>\n";
        if ($info['has_problems'] == 'yes')
                echo "<tr><td colspan=2 class=msg_error>Has problems</td></tr>\n";
-       foreach (getAttrValues ($object_id) as $record)
+       foreach (getAttrValues ($object_id, TRUE) as $record)
                if (!empty ($record['value']))
                        echo "<tr><th width='50%' class=opt_attr_th>${record['name']}:</th><td class=tdleft>${record['a_value']}</td></tr>\n";
+       printTagTRs ("${root}?page=objgroup&group_id=${info['objtype_id']}&");
        echo "</table><br>\n";
        finishPortlet();
 
@@ -679,7 +770,7 @@ function renderRackObject ($object_id = 0)
                        $hl_port_id = 0;
                        if (isset ($_REQUEST['hl_port_id']))
                        {
-                               assertUIntArg ('hl_port_id');
+                               assertUIntArg ('hl_port_id', __FUNCTION__);
                                $hl_port_id = $_REQUEST['hl_port_id'];
                        }
                        echo "<table cellspacing=0 cellpadding='5' align='center' class='widetable'>\n";
@@ -738,7 +829,7 @@ function renderRackObject ($object_id = 0)
                        else 
                                $class='';
 
-                       echo "<tr class='$class'><td>${addr['name']}</td><td><a href='${root}?page=ipaddress&ip=${addr['ip']}'>${addr['ip']}</a></td><td class='description'>$address_name</td><td>\n";
+                       echo "<tr class='$class'><td class=tdleft>${addr['name']}</td><td class=tdleft><a href='${root}?page=ipaddress&ip=${addr['ip']}'>${addr['ip']}</a></td><td class='description'>$address_name</td><td class=tdleft>\n";
 
                        if ($addr['address_reserved']=='yes')
                                echo "<b>Reserved;</b> ";
@@ -795,7 +886,7 @@ function renderRackObject ($object_id = 0)
                finishPortlet();
        }
 
-       $forwards = getObjectForwards ($object_id);
+       $forwards = getNATv4ForObject ($object_id);
        if (count($forwards['in']) or count($forwards['out']))
        {
                startPortlet('NATv4');
@@ -877,7 +968,7 @@ function renderRackObject ($object_id = 0)
                        echo '</a>';
                        if (!empty ($info['name']))
                                echo " (${info['name']})";
-                       echo "</td><td class=tdleft><a href='${root}?page=rspool&id=${info['pool_id']}'>";
+                       echo "</td><td class=tdleft><a href='${root}?page=rspool&pool_id=${info['pool_id']}'>";
                        echo (empty ($info['pool_name']) ? 'ANONYMOUS' : $info['pool_name']);
                        echo '</a></td><td class=tdleft>' . $info['rscount'] . '</td>';
                        echo "<td class=tdleft><pre>${info['vsconfig']}</pre></td>";
@@ -984,11 +1075,13 @@ function renderPortsForObject ($object_id = 0)
                        echo "</a> <input type=text name=reservation_comment>";
                        echo "</td>\n";
                }
-               echo "<td><input type='submit' value='OK'></td>";
-               echo "</form></tr>\n";
+               echo "<td>";
+               printImageHREF ('save', 'Save changes', TRUE);
+               echo "</td></form></tr>\n";
        }
-       echo "<form action='${root}process.php'><tr>";
-       echo "<td colspan=2><input type=text size=10 name=port_name tabindex=100></td>\n";
+       echo "<form action='${root}process.php'><tr><td>";
+       printImageHREF ('add', '', TRUE, 104);
+       echo "</td><td><input type=text size=8 name=port_name tabindex=100></td>\n";
        echo "<td><input type=text size=24 name=port_label tabindex=101></td>";
        echo "<input type=hidden name=op value=addPort>\n";
        echo "<input type=hidden name=object_id value='${object_id}'>\n";
@@ -1006,7 +1099,7 @@ function renderPortsForObject ($object_id = 0)
        }
        echo "</select></td>";
        echo "<td><input type=text name=port_l2address tabindex=103></td>\n";
-       echo "<td colspan=4><input type='submit' value='Add a new port' tabindex=104></td></tr></form>";
+       echo "<td colspan=4>&nbsp;</td></tr></form>";
        echo "</table><br>\n";
        finishPortlet();
 
@@ -1017,11 +1110,8 @@ function renderPortsForObject ($object_id = 0)
        echo "<input type=hidden name=object_id value='${object_id}'>\n";
        echo "<input type=hidden name=op value=addMultiPorts>";
        echo 'Format: <select name=format>';
-       echo '<option value=c2900 disabled>Cisco 2900 series: sh int eth</option>';
-       echo '<option value=c3600eth disabled>Cisco 3600 ethernet: sh arp | inc -</option>';
        echo '<option value=c3600asy>Cisco 3600 async: sh line | inc TTY</option>';
        echo '<option value=fiwg selected>Foundry ServerIron/FastIron WorkGroup/Edge: sh int br</option>';
-       echo '<option value=fiedge disabled>Foundry FastIron Edge: sh int br</option>';
        echo '<option value=fisxii>Foundry FastIron SuperX/II4000: sh int br</option>';
        echo '<option value=ssv1>SSV:&lt;interface name&gt; &lt;MAC address&gt;</option>';
        echo "</select>";
@@ -1079,14 +1169,14 @@ function renderNetworkForObject ($object_id=0)
                echo "<form action='process.php'>";
                echo "<input type=hidden name=page value='${pageno}'>\n";
                echo "<input type=hidden name=tab value='${tabno}'>\n";
-               echo "<input type=hidden name=op value=editAddressFromObject>";
+               echo "<input type=hidden name=op value=updIPv4Allocation>";
                echo "<input type=hidden name=object_id value='$object_id'>";
                echo "<input type=hidden name=ip value='${addr['ip']}'>";
-               echo "<tr class='$class'><td><a href='process.php?op=delAddrFObj&page=${pageno}&tab=${tabno}&ip=${addr['ip']}&object_id=$object_id'>";
+               echo "<tr class='$class'><td><a href='process.php?op=delIPv4Allocation&page=${pageno}&tab=${tabno}&ip=${addr['ip']}&object_id=$object_id'>";
                printImageHREF ('delete', 'Delete this IPv4 address');
                echo "</a></td>";
-               echo "<td><input type='text' name='bond_name' value='${addr['name']}' size=10></td>";
-               echo "<td><a href='${root}?page=ipaddress&ip=${addr['ip']}'>${addr['ip']}</a></td>";
+               echo "<td class=tdleft><input type='text' name='bond_name' value='${addr['name']}' size=10></td>";
+               echo "<td class=tdleft><a href='${root}?page=ipaddress&ip=${addr['ip']}'>${addr['ip']}</a></td>";
                echo "<td class='description'>$address_name</td>\n";
                echo "<td><select name='bond_type'>";
                foreach (array('regular'=>'Regular', 'virtual'=>'Virtual', 'shared'=>'Shared') as $n => $v)
@@ -1144,23 +1234,27 @@ function renderNetworkForObject ($object_id=0)
                        }
                }
 
-               echo "</td><td><input type=submit value='OK'></td></form></tr>\n";
+               echo "</td><td>";
+               printImageHREF ('save', 'Save changes', TRUE);
+               echo "</td></form></tr>\n";
        }
 
 
-       echo "<form action='${root}process.php'><tr><td colspan=2><input type='text' size='10' name='name' tabindex=100></td>\n";
+       echo "<form action='${root}process.php'><tr><td>";
+       printImageHREF ('add', 'Allocate new address', TRUE, 99);
+       echo "</td><td class=tdleft>";
+       echo "<input type='text' size='10' name='bond_name' tabindex=100></td>\n";
        echo "<input type=hidden name=page value='${pageno}'>\n";
        echo "<input type=hidden name=tab value='${tabno}'>\n";
-       echo "<input type=hidden name=op value=addAddrFObj>\n";
+       echo "<input type=hidden name=op value=addIPv4Allocation>\n";
        echo "<input type=hidden name=object_id value='$object_id'>\n";
-
-       echo "<td><input type=text name='ip' tabindex=101>\n";
-       echo "</td><td><select name='type' tabindex=102>";
+       echo "<td class=tdleft><input type=text name='ip' tabindex=101>\n";
+       echo "</td><td>&nbsp;</td><td><select name='bond_type' tabindex=102>";
        echo "<option value='regular'>Regular</option>";
        echo "<option value='virtual'>Virtual</option>";
        echo "<option value='shared'>Shared</option>";
        echo "</select>";
-       echo "</td><td colspan=3><input type='submit' value='Add a new interface' tabindex=103></td></tr></form>";
+       echo "</td><td colspan=2>&nbsp;</td></tr></form>";
        echo "</table><br>\n";
        finishPortlet();
 
@@ -1355,7 +1449,7 @@ function renderMolecule ($mdata, $object_id)
        // sort data out
        $rackpack = array();
        global $loclist;
-       foreach ($mdata as $dummy => $rua)
+       foreach ($mdata as $rua)
        {
                $rack_id = $rua['rack_id'];
                $unit_no = $rua['unit_no'];
@@ -1372,7 +1466,7 @@ function renderMolecule ($mdata, $object_id)
                $rackpack[$rack_id][$unit_no][$loclist[$atom]]['object_id'] = $object_id;
        }
        // now we have some racks to render
-       foreach ($rackpack as $dummy => $rackData)
+       foreach ($rackpack as $rackData)
        {
                markAllSpans ($rackData);
                echo "<table class=molecule cellspacing=0>\n";
@@ -1440,64 +1534,90 @@ function renderProblematicObjectsPortlet ()
        finishPortlet();
 }
 
-function renderObjectGroupSummary ()
+function renderObjectSpace ()
 {
-       global $root;
-       $summary = getObjectGroupInfo();
-       if ($summary === NULL)
+       global $root, $taglist, $tagtree;
+       echo "<table border=0 class=objectview>\n";
+       echo "<tr><td class=pcleft width='50%'>";
+       startPortlet ('View all by type');
+       $groupInfo = getObjectGroupInfo();
+       if ($groupInfo === NULL)
        {
                showError ('getObjectGroupInfo() failed', __FUNCTION__);
                return;
        }
-       echo "<table border=0 class=objectview>\n";
-       echo "<tr><td class=pcleft width='25%'>";
-
-       startPortlet ('Summary');
-       foreach ($summary as $gi)
+       if (count ($groupInfo) == 0)
+               echo "No objects exist in DB";
+       else
        {
-               echo "<a href='${root}?page=objgroup&group_id=${gi['id']}'><b>${gi['name']}</b></a> <i>(${gi['count']})</i><br>";
+               echo '<div align=left><ul>';
+               foreach ($groupInfo as $gi)
+                       echo "<li><a href='${root}?page=objgroup&group_id=${gi['id']}'>${gi['name']}</a> (${gi['count']})</li>";
+               echo '</ul></div>';
        }
        finishPortlet();
 
        echo '</td><td class=pcright>';
-       renderUnmountedObjectsPortlet();
-       echo '</td><td class=pcright>';
-       renderProblematicObjectsPortlet();
+
+       startPortlet ('View all by tag');
+       if (count ($taglist) == 0)
+               echo "No tags exist in DB";
+       else
+               renderTagCloud ('object');
+       finishPortlet();
        echo "</td></tr></table>\n";
 }
 
-function renderObjectGroup ($group_id = 0)
+function renderObjectGroup ()
 {
-       global $root;
-       $summary = getObjectGroupInfo();
-       if ($summary == NULL)
+       global $root, $pageno, $tabno, $nextorder, $taglist, $tagtree;
+       assertUIntArg ('group_id', __FUNCTION__, TRUE);
+       $group_id = $_REQUEST['group_id'];
+       $tagfilter = getTagFilter();
+       $tagfilter_str = getTagFilterStr ($tagfilter);
+       echo "<table border=0 class=objectview>\n";
+       echo "<tr><td class=pcleft width='25%'>";
+       startPortlet ('change type');
+       $groupInfo = getObjectGroupInfo();
+       if ($groupInfo === NULL)
        {
                showError ('getObjectGroupInfo() failed', __FUNCTION__);
                return;
        }
-       $objects = getObjectList ($group_id);
-       if ($objects === NULL)
-       {
-               showError ('getObjectList() failed', __FUNCTION__);
-               return;
-       }
-       echo "<table border=0 class=objectview>\n";
-       echo "<tr><td class=pcleft width='25%'>";
-
-       startPortlet ('All objects');
-       foreach ($summary as $gi)
+       if (count ($groupInfo) == 0)
+               echo "No objects exist in DB";
+       else
        {
-               echo "<a href='${root}?page=objgroup&group_id=${gi['id']}'><b>${gi['name']}</b></a> <i>(${gi['count']})</i><br>";
+               echo '<div align=left><ul>';
+               foreach ($groupInfo as $gi)
+               {
+                       echo "<li><a href='${root}?page=${pageno}&group_id=${gi['id']}${tagfilter_str}'>";
+                       if ($gi['id'] == $group_id)
+                               echo '<strong>';
+                       echo "${gi['name']}</a>";
+                       if ($gi['id'] == $group_id)
+                               echo '</strong>';
+                       echo " (${gi['count']})";
+                       if ($gi['id'] == $group_id)
+                               echo ' &larr;';
+                       echo "</li>";
+               }
+               echo '</ul></div>';
        }
        finishPortlet();
 
-       echo '</td><td class=pcright>';
+       echo '</td><td class=pcleft>';
 
-       startPortlet ('Object group');
+       startPortlet ('Objects');
+       $objects = getObjectList ($group_id, $tagfilter);
+       if ($objects === NULL)
+       {
+               showError ('getObjectList() failed', __FUNCTION__);
+               return;
+       }
        echo '<br><br><table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
        echo '<tr><th>Common name</th><th>Visible label</th><th>Asset tag</th><th>Barcode</th><th>Rack</th></tr>';
        $order = 'odd';
-       global $nextorder;
        foreach ($objects as $obj)
        {
                echo "<tr class=row_${order}><td><a href='${root}?page=object&object_id=${obj['id']}'>${obj['dname']}</a></td>";
@@ -1514,7 +1634,10 @@ function renderObjectGroup ($group_id = 0)
        echo '</table>';
        finishPortlet();
 
-       echo "</td></tr></table>";
+       echo "</td><td class=pcright width='25%'>";
+
+       renderTagFilterPortlet ($tagfilter, 'object', 'group_id', $group_id);
+       echo "</td></tr></table>\n";
 }
 
 function renderEmptyPortsSelect ($port_id, $type_id)
@@ -1668,9 +1791,13 @@ function renderAddressspace ()
 {
        global $root, $page;
 
+       echo "<table border=0 class=objectview>\n";
+       echo "<tr><td class=pcleft>";
+
        startPortlet ('Subnets');
        echo "<table class='widetable' border=0 cellpadding=10 cellspacing=0 align='center'>\n";
-       $addrspaceList = getAddressspaceList();
+       $tagfilter = getTagFilter();
+       $addrspaceList = getAddressspaceList ($tagfilter);
        echo "<tr><th>Subnet</th><th>Name</th><th>Utilization</th></tr>";
        foreach ($addrspaceList as $iprange)
        {
@@ -1684,6 +1811,9 @@ function renderAddressspace ()
        }
        echo "</table>\n";
        finishPortlet();
+       echo '</td><td class=pcright>';
+       renderTagFilterPortlet ($tagfilter, 'ipv4net');
+       echo "</td></tr></table>\n";
 }
 
 function renderIPv4SLB ()
@@ -1737,7 +1867,7 @@ function renderIPv4SLB ()
                                else
                                {
                                        echo $vsdata['lblist'][$lb_object_id]['size'];
-                                       echo " (<a href='${root}?page=rspool&id=";
+                                       echo " (<a href='${root}?page=rspool&pool_id=";
                                        echo $vsdata['lblist'][$lb_object_id]['id'] . "'>";
                                        echo $vsdata['lblist'][$lb_object_id]['name'] . '</a>)';
                                }
@@ -1756,20 +1886,25 @@ function renderAddNewRange ()
        global $root, $pageno, $tabno;
        showMessageOrError();
 
-       echo "<center><h2>Add New</h2></center>\n";
+       startPortlet ("Add New");
        echo "<table class='widetable' border=0 cellpadding=10 align='center'>\n";
-       echo "<tr><th>Address range</th><th>Name</th><th>C&gt;*</th><th>&nbsp;</th></tr>\n";
+       echo "<tr><th>Address range</th><th>Name</th><th>connected network</th><th>assign tags</th><th>&nbsp;</th></tr>\n";
        echo "<form name='add_new_range' action='process.php'>\n";
        echo "<input type=hidden name=op value=addRange>\n";
        echo "<input type=hidden name=page value='${pageno}'>\n";
        echo "<input type=hidden name=tab value='${tabno}'>\n";
-       echo "<tr><td class='tdcenter'><input type=text name='range' size=18 class='live-validate' tabindex=1></td>\n";
+       echo "<tr valign=top><td class='tdcenter'><input type=text name='range' size=18 class='live-validate' tabindex=1></td>\n";
        echo "<td class='tdcenter'><input type=text name='name' size='20' tabindex=2></td>\n";
        echo "<td class='tdcenter'><input type=checkbox name='is_bcast' tabindex=3 checked></td>\n";
-       echo "<td class='tdcenter'><input type=submit value='Add a new range' tabindex=4></td></tr>\n";
+       echo "<td>\n";
+       renderTagSelect();
+       echo "</td>\n";
+       echo "<td class='tdcenter'><input type=submit value='Add a new range' tabindex=4></td>\n";
+       echo "</td></tr>\n";
        echo "</form></table><br><br>\n";
+       finishPortlet();
 
-       echo "<center><h2>Manage Existing</h2></center>\n";
+       startPortlet ("Manage Existing");
        echo "<table class='widetable' border=0 cellpadding=10 align='center'>\n";
        $addrspaceList = getAddressspaceList();
        echo "<tr><th>&nbsp;</th><th>Address range</th><th>Name</th><th>Utilization</th></tr>";
@@ -1787,17 +1922,90 @@ function renderAddNewRange ()
                }
                else
                        printImageHREF ('nodelete', 'There are IP addresses allocated or reserved');
-               echo "</td>\n<td><a href='${root}?page=iprange&id=${iprange['id']}'>${iprange['ip']}/${iprange['mask']}</a></td><td>${iprange['name']}</td><td class=tdleft>";
+               echo "</td>\n<td class=tdleft><a href='${root}?page=iprange&id=${iprange['id']}'>";
+               echo "${iprange['ip']}/${iprange['mask']}</a></td><td class=tdleft>${iprange['name']}";
+               echo "</td><td class=tdleft>";
                renderProgressBar ($usedips / $totalips);
                echo " ${usedips}/${totalips}";
                echo "</td></tr>";
        }
        echo "</table>";
+       finishPortlet();
 }
 
 function renderIPRange ($id)
 {
        global $root, $pageno, $tabno;
+       $netmaskbylen = array
+       (
+               32 => '255.255.255.255',
+               31 => '255.255.255.254',
+               30 => '255.255.255.252',
+               29 => '255.255.255.248',
+               28 => '255.255.255.240',
+               27 => '255.255.255.224',
+               26 => '255.255.255.192',
+               25 => '255.255.255.128',
+               24 => '255.255.255.0',
+               23 => '255.255.254.0',
+               22 => '255.255.252.0',
+               21 => '255.255.248.0',
+               20 => '255.255.240.0',
+               19 => '255.255.224.0',
+               18 => '255.255.192.0',
+               17 => '255.255.128.0',
+               16 => '255.255.0.0',
+               15 => '255.254.0.0',
+               14 => '255.252.0.0',
+               13 => '255.248.0.0',
+               12 => '255.240.0.0',
+               11 => '255.224.0.0',
+               10 => '255.192.0.0',
+               9 => '255.128.0.0',
+               8 => '255.0.0.0',
+               7 => '254.0.0.0',
+               6 => '252.0.0.0',
+               5 => '248.0.0.0',
+               4 => '240.0.0.0',
+               3 => '224.0.0.0',
+               2 => '192.0.0.0',
+               1 => '128.0.0.0'
+       );
+       $wildcardbylen = array
+       (
+               32 => '0.0.0.0',
+               31 => '0.0.0.1',
+               30 => '0.0.0.3',
+               29 => '0.0.0.7',
+               28 => '0.0.0.15',
+               27 => '0.0.0.31',
+               26 => '0.0.0.63',
+               25 => '0.0.0.127',
+               24 => '0.0.0.255',
+               23 => '0.0.1.255',
+               22 => '0.0.3.255',
+               21 => '0.0.7.255',
+               20 => '0.0.15.255',
+               19 => '0.0.31.255',
+               18 => '0.0.63.255',
+               17 => '0.0.127.255',
+               16 => '0.0.255.25',
+               15 => '0.1.255.255',
+               14 => '0.3.255.255',
+               13 => '0.7.255.255',
+               12 => '0.15.255.255',
+               11 => '0.31.255.255',
+               10 => '0.63.255.255',
+               9 => '0.127.255.255',
+               8 => '0.255.255.255',
+               7 => '1.255.255.255',
+               6 => '3.255.255.255',
+               5 => '7.255.255.255',
+               4 => '15.255.255.255',
+               3 => '31.255.255.255',
+               2 => '63.255.255.255',
+               1 => '127.255.255.255'
+       );
        $maxperpage = getConfigVar ('IPV4_ADDRS_PER_PAGE');
        if (isset($_REQUEST['pg']))
                $page = $_REQUEST['pg'];
@@ -1805,8 +2013,30 @@ function renderIPRange ($id)
                $page=0;
 
        $range = getIPRange($id);
-       echo "<center><h1>${range['ip']}/${range['mask']}</h1><h2>${range['name']}</h2></center>\n";
+       echo "<table border=0 class=objectview cellspacing=0 cellpadding=0>";
+       echo "<tr><td colspan=2 align=center><h1>${range['ip']}/${range['mask']}</h1><h2>${range['name']}</h2></td></tr>\n";
+
+       echo "<tr><td class=pcleft width='50%'>";
+       startPortlet ('summary');
+       $total = ($range['ip_bin'] | $range['mask_bin_inv']) - ($range['ip_bin'] & $range['mask_bin']) + 1;
+       $used = count ($range['addrlist']);
+       echo "<table border=0 cellspacing=0 cellpadding=3 width='100%'>\n";
+       echo "<tr><th width='50%' class=tdright>Utilization:</th><td class=tdleft>";
+       renderProgressBar ($used/$total);
+       echo "&nbsp;${used}/${total}</td></tr>\n";
+       echo "<tr><th width='50%' class=tdright>Netmask:</th><td class=tdleft>";
+       echo $netmaskbylen[$range['mask']];
+       echo "</td></tr>\n";
+       echo "<tr><th width='50%' class=tdright>Wildcard bits:</th><td class=tdleft>";
+       echo $wildcardbylen[$range['mask']];
+       echo "</td></tr>\n";
+       printTagTRs ("${root}?page=ipv4space&");
+       echo "</table><br>\n";
+       finishPortlet();
+       echo "</td>\n";
 
+       echo "<td class=pcright>";
+       startPortlet ('details');
        $startip = $range['ip_bin'] & $range['mask_bin'];
        $endip = $range['ip_bin'] | $range['mask_bin_inv'];
        $realstartip = $startip;
@@ -1841,21 +2071,25 @@ function renderIPRange ($id)
                        $numshared = countRefsOfType($range['addrlist'][$ip]['references'], 'shared', 'eq');
                        $numreg = countRefsOfType($range['addrlist'][$ip]['references'], 'regular', 'eq');
                        $numvirt = countRefsOfType($range['addrlist'][$ip]['references'], 'virtual', 'eq');
+                       $numlb = count ($range['addrlist'][$ip]['lbrefs']);
+                       $numrs = count ($range['addrlist'][$ip]['rsrefs']);
                        
                        $addr = $range['addrlist'][$ip];
                        if ( ($numshared > 0 && $numreg > 0) || $numreg > 1 )
                                echo "<tr class='trerror'>";
-                       elseif ( $addr['reserved'] == 'yes' and $numshared+$numreg+$numvirt > 0)
+                       elseif ( $addr['reserved'] == 'yes' and $numshared+$numreg+$numvirt+$numlb+$numrs > 0)
                                echo "<tr class='trerror'>";
                        elseif ( $addr['reserved'] == 'yes')
                                echo "<tr class='trbusy'>";
-                       elseif ( $numshared > 0 || $numreg > 0)
+                       elseif ( $numshared > 0 || $numreg > 0 || $numlb > 0 || $numrs > 0)
                                echo "<tr class='trbusy'>";
                        else
                                echo "<tr>";
 
-                       echo "<td><a href='${root}?page=ipaddress&ip=${addr['ip']}'>${addr['ip']}</a></td><td>${addr['name']}</td><td>";
+                       echo "<td class=tdleft><a href='${root}?page=ipaddress&ip=${addr['ip']}'>${addr['ip']}</a></td>";
+                       echo "<td class=tdleft>${addr['name']}</td><td class=tdleft>";
                        $delim = '';
+                       $prologue = '';
                        if ( $addr['reserved'] == 'yes')
                        {
                                echo "<b>Reserved</b> ";
@@ -1868,6 +2102,33 @@ function renderIPRange ($id)
                                echo "${ref['object_name']}</a>";
                                $delim = '; ';
                        }
+                       if ($delim != '')
+                       {
+                               $delim = '';
+                               $prologue = '<br>';
+                       }
+                       foreach ($range['addrlist'][$ip]['lbrefs'] as $ref)
+                       {
+                               echo $prologue;
+                               $prologue = '';
+                               echo "${delim}<a href='${root}?page=object&object_id=${ref['object_id']}'>";
+                               echo "${ref['object_name']}</a>:<a href='${root}?page=vservice&id=${ref['vs_id']}'>";
+                               echo "${ref['vport']}/${ref['proto']}</a>&rarr;";
+                               $delim = '; ';
+                       }
+                       if ($delim != '')
+                       {
+                               $delim = '';
+                               $prologue = '<br>';
+                       }
+                       foreach ($range['addrlist'][$ip]['rsrefs'] as $ref)
+                       {
+                               echo $prologue;
+                               $prologue = '';
+                               echo "${delim}&rarr;${ref['rsport']}@<a href='${root}?page=rspool&pool_id=${ref['rspool_id']}'>";
+                               echo "${ref['rspool_name']}</a>";
+                               $delim = '; ';
+                       }
                        echo "</td></tr>\n";
                }
                else
@@ -1877,7 +2138,8 @@ function renderIPRange ($id)
        }
 
        echo "</table>";
-       
+       finishPortlet();
+       echo "</td></tr></table>\n";
 }
 
 function renderIPRangeProperties ($id)
@@ -1909,45 +2171,79 @@ function renderIPAddress ()
 //     echo "<table width='100%' cesspadding=5 cellspacing=0 border=0 align='center'>";
 //     echo "<tr valign='top'><td>";
 
-       startPortlet ('Address assignment');
-       echo "<table class='widetable' cesspadding=5 cellspacing=0 border=0 align='center'>\n";
-       echo "<tr><th>Object name</th><th>Interface name</th><th>Interface type</th></tr>\n";
-
        $numshared = countRefsOfType($address['bonds'], 'shared', 'eq');
        $numreg = countRefsOfType($address['bonds'], 'regular', 'eq');
        $numvirt = countRefsOfType($address['bonds'], 'virtual', 'eq');
 
-       
-       if ( ($numshared > 0 && $numreg > 0) || $numreg > 1 )
-               $class='trerror';
-       elseif ( $address['reserved'] == 'yes' and $numshared+$numreg+$numvirt > 0)
-               $class='trerror';
-       else
-               $class='';
+       if ($address['reserved'] == 'yes' or ($numshared + $numreg + $numvirt) > 0)
+       {
+               startPortlet ('Allocation');
+               echo "<table class='widetable' cesspadding=5 cellspacing=0 border=0 align='center'>\n";
+               echo "<tr><th>Object name</th><th>Interface name</th><th>Interface type</th></tr>\n";
+               if ( ($numshared > 0 && $numreg > 0) || $numreg > 1 )
+                       $class='trerror';
+               elseif ( $address['reserved'] == 'yes' and $numshared+$numreg+$numvirt > 0)
+                       $class='trerror';
+               else
+                       $class='';
 
+               if ($address['reserved'] == 'yes')
+                       echo "<tr class='$class'><td colspan='3'><b>RESERVED</b></td></tr>";
+               foreach ($address['bonds'] as $bond)
+               {
+                       echo "<tr class='$class'><td><a href='${root}?page=object&object_id=${bond['object_id']}'>${bond['object_name']}</td><td>${bond['name']}</td><td><b>";
+                       switch ($bond['type'])
+                       {
+                               case 'virtual':
+                                       echo "Virtual";
+                                       break;
+                               case 'shared':
+                                       echo "Shared";
+                                       break;
+                               case 'regular':
+                                       echo "Regular";
+                                       break;
+                       }
+                       echo "</b></td></tr>\n";
+               }
+               echo "</table><br><br>";
+               finishPortlet();
+       }
 
+       if (count ($address['vslist']))
+       {
+               startPortlet ('Virtual services (' . count ($address['vslist']) . ')');
+               echo "<table class='widetable' cesspadding=5 cellspacing=0 border=0 align='center'>\n";
+               echo "<tr><th>VS</th><th>name</th></tr>\n";
+               foreach ($address['vslist'] as $vsinfo)
+               {
+                       echo "<tr><td class=tdleft><a href='${root}?page=vservice&id=${vsinfo['id']}'>";
+                       echo buildVServiceName ($vsinfo) . "</a></td><td class=tdleft>";
+                       echo $vsinfo['name'] . "</td></tr>\n";
+               }
+               echo "</table><br><br>";
+               finishPortlet();
+       }
 
-       if ($address['reserved'] == 'yes')
-               echo "<tr class='$class'><td colspan='3'><b>RESERVED</b></td></tr>";
-       foreach ($address['bonds'] as $bond)
+       if (count ($address['rslist']))
        {
-               echo "<tr class='$class'><td><a href='${root}?page=object&object_id=${bond['object_id']}'>${bond['object_name']}</td><td>${bond['name']}</td><td><b>";
-               switch ($bond['type'])
+               startPortlet ('Real servers (' . count ($address['rslist']) . ')');
+               echo "<table class='widetable' cesspadding=5 cellspacing=0 border=0 align='center'>\n";
+               echo "<tr><th>&nbsp;</th><th>port</th><th>RS pool</th></tr>\n";
+               foreach ($address['rslist'] as $rsinfo)
                {
-                       case 'virtual':
-                               echo "Virtual";
-                               break;
-                       case 'shared':
-                               echo "Shared";
-                               break;
-                       case 'regular':
-                               echo "Regular";
-                               break;
+                       echo "<tr><td>";
+                       if ($rsinfo['inservice'] == 'yes')
+                               printImageHREF ('inservice', 'in service');
+                       else
+                               printImageHREF ('notinservice', 'NOT in service');
+                       echo "</td><td class=tdleft>${rsinfo['rsport']}</td><td class=tdleft><a href='${root}?page=rspool&pool_id=${rsinfo['pool_id']}'>";
+                       echo $rsinfo['poolname'] . "</a></td></tr>\n";
                }
-               echo "</b></td></tr>\n";
+               echo "</table><br><br>";
+               finishPortlet();
        }
-       echo "</table><br><br>";
-       finishPortlet();
+
 
 //     echo "</td><td>";
 //     echo "</td></tr></table>";
@@ -1983,7 +2279,7 @@ function renderIPAddressAssignment ()
 
 
        echo "<table class='widetable' cesspadding=5 cellspacing=0 border=0 align='center'>\n";
-       echo "<tr><th>&nbsp;</th><th>Object name</th><th>Interface name</th><th>Interface type</th><th>&nbsp;</th></tr>\n";
+       echo "<tr><th>&nbsp;</th><th>object name</th><th>object interface</th><th>allocation type</th><th>&nbsp;</th></tr>\n";
 
        $numshared = countRefsOfType($address['bonds'], 'shared', 'eq');
        $numreg = countRefsOfType($address['bonds'], 'regular', 'eq');
@@ -2004,12 +2300,12 @@ function renderIPAddressAssignment ()
        foreach ($address['bonds'] as $bond)
        {
                echo "<tr class='$class'><form action='process.php'>";
-               echo "<input type=hidden name=op value='editBondForAddress'>";
+               echo "<input type=hidden name=op value='updIPv4Allocation'>";
                echo "<input type=hidden name=page value='${pageno}'>";
                echo "<input type=hidden name=tab value='${tabno}'>";
                echo "<input type=hidden name=ip value='$ip'>";
                echo "<input type=hidden name=object_id value='${bond['object_id']}'>";
-               echo "<td><a href='process.php?op=delIpAssignment&page=${pageno}&tab=${tabno}&ip=$ip&object_id=${bond['object_id']}'>";
+               echo "<td><a href='process.php?op=delIPv4Allocation&page=${pageno}&tab=${tabno}&ip=$ip&object_id=${bond['object_id']}'>";
                printImageHREF ('delete', 'Unallocate address');
                echo "</a></td>";
                echo "<td><a href='${root}?page=object&object_id=${bond['object_id']}'>${bond['object_name']}</td>";
@@ -2033,13 +2329,17 @@ function renderIPAddressAssignment ()
                                echo "<option value='shared'>Shared</option>";
                                break;
                }
-               echo "</select></td><td><input type='submit' value='OK'></td></form></tr>\n";
+               echo "</select></td><td>";
+               printImageHREF ('save', 'Save changes', TRUE);
+               echo "</td></form></tr>\n";
        }
-       echo "<form action='process.php'><input type='hidden' name='op' value='bindObjectToIp'>";
+       echo "<form action='process.php'><input type='hidden' name='op' value='addIPv4Allocation'>";
        echo "<input type=hidden name=page value='${pageno}'>\n";
        echo "<input type=hidden name=tab value='${tabno}'>\n";
        echo "<input type='hidden' name='ip' value='$ip'>";
-       echo "<td colspan=2><select name='object_id'>";
+       echo "<td>";
+       printImageHREF ('add', 'new allocation', TRUE);
+       echo "</td><td><select name='object_id'>";
 
        foreach (explode (',', getConfigVar ('IPV4_PERFORMERS')) as $type) 
                foreach (getObjectList ($type) as $object)
@@ -2047,23 +2347,23 @@ function renderIPAddressAssignment ()
 
        echo "</select></td><td><input type='text' name='bond_name' value='' size=10></td>";
        echo "<td><select name='bond_type'><option value='regular'>Regular</option><option value='virtual'>Virtual</option><option value='shared'>Shared</option></select></td>";
-       echo "<td><input type='submit' value='Assign address'></td></form></tr>";
+       echo "<td>&nbsp;</td></form></tr>";
        echo "</table><br><br>";
 
 }
 
-function renderIPAddressPortForwarding ($object_id=0)
+function renderNATv4ForObject ($object_id = 0)
 {
        global $pageno, $tabno, $root;
        
        $info = getObjectInfo ($object_id);
-       $forwards = getObjectForwards ($object_id);
+       $forwards = getNATv4ForObject ($object_id);
        $addresses = getObjectAddresses ($object_id);
        showMessageOrError();
        echo "<center><h2>locally performed NAT</h2></center>";
 
        echo "<table class='widetable' cesspadding=5 cellspacing=0 border=0 align='center'>\n";
-       echo "<tr><th></th><th>Match endpoint</th><th>Translate to</th><th>Target object</th><th>Comment</th></tr>\n";
+       echo "<tr><th></th><th>Match endpoint</th><th>Translate to</th><th>Target object</th><th>Comment</th><th>&nbsp;</th></tr>\n";
 
        foreach ($forwards['out'] as $pf)
        {
@@ -2078,7 +2378,7 @@ function renderIPAddressPortForwarding ($object_id=0)
                        }
 
                echo "<tr class='$class'>";
-               echo "<td><a href='process.php?op=delPortForwarding&localip=${pf['localip']}&localport=${pf['localport']}&remoteip=${pf['remoteip']}&remoteport=${pf['remoteport']}&proto=${pf['proto_bin']}&object_id=$object_id&page=${pageno}&tab=${tabno}'>";
+               echo "<td><a href='process.php?op=delPortForwarding&localip=${pf['localip']}&localport=${pf['localport']}&remoteip=${pf['remoteip']}&remoteport=${pf['remoteport']}&proto=${pf['proto']}&object_id=$object_id&page=${pageno}&tab=${tabno}'>";
                printImageHREF ('delete', 'Delete NAT rule');
                echo "</a></td>";
                echo "<td>${pf['proto']}/${name}: <a href='${root}?page=ipaddress&tab=default&ip=${pf['localip']}'>${pf['localip']}</a>:${pf['localport']}";
@@ -2095,15 +2395,23 @@ function renderIPAddressPortForwarding ($object_id=0)
                                echo "<a href='${root}?page=object&tab=default&object_id=${bond['object_id']}'>${bond['object_name']}(${bond['name']})</a> ";
                elseif (!empty ($pf['remote_addr_name']))
                        echo '(' . $pf['remote_addr_name'] . ')';
-               echo "</td><form action='process.php'><input type='hidden' name='op' value='updPortForwarding'><input type=hidden name=page value='${pageno}'><input type=hidden name=tab value='${tabno}'><input type='hidden' name='object_id' value='$object_id'><input type='hidden' name='localip' value='${pf['localip']}'><input type='hidden' name='localport' value='${pf['localport']}'><input type='hidden' name='remoteip' value='${pf['remoteip']}'><input type='hidden' name='remoteport' value='${pf['remoteport']}'><input type='hidden' name='proto' value='${pf['proto_bin']}'><td class='description'><input type='text' name='description' value='${pf['description']}'> <input type='submit' value='OK'></td></form>";
-               echo "</tr>";
+               echo "</td><form action='process.php'><input type='hidden' name='op' value='updPortForwarding'><input type=hidden name=page value='${pageno}'>";
+               echo "<input type=hidden name=tab value='${tabno}'><input type='hidden' name='object_id' value='$object_id'>";
+               echo "<input type='hidden' name='localip' value='${pf['localip']}'><input type='hidden' name='localport' value='${pf['localport']}'>";
+               echo "<input type='hidden' name='remoteip' value='${pf['remoteip']}'><input type='hidden' name='remoteport' value='${pf['remoteport']}'>";
+               echo "<input type='hidden' name='proto' value='${pf['proto']}'><td class='description'>";
+               echo "<input type='text' name='description' value='${pf['description']}'></td><td>";
+               printImageHREF ('save', 'Save changes', TRUE);
+               echo "</td></form></tr>";
        }
        echo "<form action='process.php'><input type='hidden' name='op' value='forwardPorts'>";
        echo "<input type='hidden' name='object_id' value='$object_id'>";
        echo "<input type=hidden name=page value='${pageno}'>\n";
        echo "<input type=hidden name=tab value='${tabno}'>\n";
-       echo "<tr align='center'><td colspan=2>";
-       printSelect (readChapter ('Protocols'), 'proto');
+       echo "<tr align='center'><td>";
+       printImageHREF ('add', 'Add new NAT rule', TRUE);
+       echo '</td><td>';
+       printSelect (array ('TCP' => 'TCP', 'UDP' => 'UDP'), 'proto');
        echo "<select name='localip' tabindex=1>";
 
        foreach ($addresses as $addr)
@@ -2116,21 +2424,18 @@ function renderIPAddressPortForwarding ($object_id=0)
        printImageHREF ('find', 'Find object');
        echo "</a>";
        echo ":<input type='text' name='remoteport' size='4' tabindex=4></td><td></td>";
-       echo "<td colspan=1><input type='text' name='description' size='20' tabindex=5> <input type='submit' value='Create Forwarding' tabindex=6></td></tr>";
+       echo "<td colspan=1><input type='text' name='description' size='20' tabindex=5></td><td>&nbsp;</td></tr>";
        echo "</form>";
 
        echo "</table><br><br>";
 
-
        echo "<center><h2>arriving NAT connections</h2></center>";
        echo "<table class='widetable' cesspadding=5 cellspacing=0 border=0 align='center'>\n";
        echo "<tr><th></th><th>Source</th><th>Source objects</th><th>Target</th><th>Description</th></tr>\n";
 
        foreach ($forwards['in'] as $pf)
        {
-               echo "<tr>";
-
-               echo "<td><a href='process.php?op=delPortForwarding&localip=${pf['localip']}&localport=${pf['localport']}&remoteip=${pf['remoteip']}&remoteport=${pf['remoteport']}&proto=${pf['proto_bin']}&object_id=${pf['object_id']}&page=${pageno}&tab=${tabno}'>";
+               echo "<tr><td><a href='process.php?op=delPortForwarding&localip=${pf['localip']}&localport=${pf['localport']}&remoteip=${pf['remoteip']}&remoteport=${pf['remoteport']}&proto=${pf['proto']}&object_id=${pf['object_id']}&page=${pageno}&tab=${tabno}'>";
                printImageHREF ('delete', 'Delete NAT rule');
                echo "</a></td>";
                echo "<td>${pf['proto']}/<a href='${root}?page=ipaddress&tab=default&ip=${pf['localip']}'>${pf['localip']}</a>:${pf['localport']}</td>";
@@ -2139,25 +2444,12 @@ function renderIPAddressPortForwarding ($object_id=0)
                echo "<td class='description'>${pf['description']}</td></tr>";
        }
 
-//     echo "<form action='process.php'><input type='hidden' name='op' value='forwardPorts'>";
-//     echo "<input type='hidden' name='object_id' value='$object_id'>";
-//     echo "<input type=hidden name=page value='${pageno}'>\n";
-//     echo "<input type=hidden name=tab value='${tabno}'>\n";
-//     echo "<tr align='center'><td colspan=2><select name='proto'><option value='1'>TCP</option><option value='2'>UDP</option><input type='text' name='localip' size='10'>:<input type='text' name='localport' size='4'></td><td><select name='localip'>";
-//     foreach ($addresses as $addr)
-//             echo "<option value='${addr['ip']}'>${addr['ip']}</option>";
-//
-//     echo "</select>:<input type='text' name='remoteport' size='4'></td><td><input type='text' name='description' size='20'></td><td><input type='submit' value='Create Forwarding'></td></tr>";
-//     echo "</form>";
        echo "</table><br><br>";
-
-
 }
 
-
 function renderAddMultipleObjectsForm ()
 {
-       global $pageno, $tabno, $nextorder;
+       global $root, $pageno, $tabno, $nextorder;
 
        $type_id = array();
        $global_type_id = 0;
@@ -2168,6 +2460,7 @@ function renderAddMultipleObjectsForm ()
        // Look for current submit.
        if (isset ($_REQUEST['got_fast_data']))
        {
+               $taglist = isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array();
                $keepvalues = TRUE;
                $max = getConfigVar ('MASSCOUNT');
                for ($i = 0; $i < $max; $i++)
@@ -2177,11 +2470,11 @@ function renderAddMultipleObjectsForm ()
                                $log[] = array ('code' => 'error', 'message' => "Submitted form is invalid at line " . $i + 1);
                                break;
                        }
-                       assertUIntArg ("${i}_object_type_id", TRUE);
-                       assertStringArg ("${i}_object_name", TRUE);
-                       assertStringArg ("${i}_object_label", TRUE);
-                       assertStringArg ("${i}_object_asset_no", TRUE);
-                       assertStringArg ("${i}_object_barcode", TRUE);
+                       assertUIntArg ("${i}_object_type_id", __FUNCTION__, TRUE);
+                       assertStringArg ("${i}_object_name", __FUNCTION__, TRUE);
+                       assertStringArg ("${i}_object_label", __FUNCTION__, TRUE);
+                       assertStringArg ("${i}_object_asset_no", __FUNCTION__, TRUE);
+                       assertStringArg ("${i}_object_barcode", __FUNCTION__, TRUE);
                        $type_id[$i] = $_REQUEST["${i}_object_type_id"];
                        // Save user input for possible rendering.
                        $name[$i] = $_REQUEST["${i}_object_name"];
@@ -2189,10 +2482,10 @@ function renderAddMultipleObjectsForm ()
                        $asset_no[$i] = $_REQUEST["${i}_object_asset_no"];
                        $barcode[$i] = $_REQUEST["${i}_object_barcode"];
 
-                       // It's better to skip silently than printing a notice.
+                       // It's better to skip silently, than to print a notice.
                        if ($type_id[$i] == 0)
                                continue;
-                       if (commitAddObject ($name[$i], $label[$i], $barcode[$i], $type_id[$i], $asset_no[$i]) === TRUE)
+                       if (commitAddObject ($name[$i], $label[$i], $barcode[$i], $type_id[$i], $asset_no[$i], $taglist) === TRUE)
                                $log[] = array ('code' => 'success', 'message' => "Added new object '${name[$i]}'");
                        else
                                $log[] = array ('code' => 'error', 'message' => __FUNCTION__ . ': commitAddObject() failed');
@@ -2200,9 +2493,10 @@ function renderAddMultipleObjectsForm ()
        }
        elseif (isset ($_REQUEST['got_very_fast_data']))
        {
+               $taglist = isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array();
                $keepvalues = TRUE;
-               assertUIntArg ('global_type_id', TRUE);
-               assertStringArg ('namelist', TRUE);
+               assertUIntArg ('global_type_id', __FUNCTION__, TRUE);
+               assertStringArg ('namelist', __FUNCTION__, TRUE);
                $global_type_id = $_REQUEST['global_type_id'];
                if ($global_type_id == 0)
                {
@@ -2226,7 +2520,7 @@ function renderAddMultipleObjectsForm ()
                                        $names2[] = rtrim ($parts[0]);
                        }
                        foreach ($names2 as $cname)
-                               if (commitAddObject ($cname, '', '', $global_type_id, '') === TRUE)
+                               if (commitAddObject ($cname, '', '', $global_type_id, '', $taglist) === TRUE)
                                        $log[] = array ('code' => 'success', 'message' => "Added new object '${cname}'");
                                else
                                        $log[] = array ('code' => 'error', 'message' => "Could not add '${cname}'");
@@ -2238,53 +2532,63 @@ function renderAddMultipleObjectsForm ()
        $typelist = getObjectTypeList();
        $typelist[0] = 'select type...';
 
-       startPortlet ('Fast way');
-       echo '<form>';
-       echo "<input type=hidden name=page value=${pageno}>";
-       echo "<input type=hidden name=tab value=${tabno}>";
+       startPortlet ('Distinct types, same tags');
+       $max = getConfigVar ('MASSCOUNT');
+       echo "<form name=fastform method=post action='${root}?page=${pageno}&tab=${tabno}'>";
        echo '<table border=0 align=center>';
-       echo "<tr><th>Object type</th><th>Common name</th><th>Visible label</th><th>Asset tag</th><th>Barcode</th></tr>\n";
+       echo "<tr><th>Object type</th><th>Common name</th><th>Visible label</th>";
+       echo "<th>Asset tag</th><th>Barcode</th><th>Tags</th></tr>\n";
        // If a user forgot to select object type on input, we keep his
        // previous input in the form.
-       $max = getConfigVar ('MASSCOUNT');
        for ($i = 0; $i < $max; $i++)
        {
                echo '<tr><td>';
+               // Don't employ DEFAULT_OBJECT_TYPE to avoid creating ghost records for pre-selected empty rows.
                printSelect ($typelist, "${i}_object_type_id", 0);
                echo '</td>';
                echo "<td><input type=text size=30 name=${i}_object_name";
-               if ($keepvalues and $type_id[$i] == 0)
+               if ($keepvalues and isset ($name[$i]) and (!isset ($type_id[$i]) or $type_id[$i] == 0))
                        echo " value='${name[$i]}'";
                echo "></td>";
                echo "<td><input type=text size=30 name=${i}_object_label";
-               if ($keepvalues and $type_id[$i] == 0)
+               if ($keepvalues and isset ($label[$i]) and (!isset ($type_id[$i]) or $type_id[$i] == 0))
                        echo " value='${label[$i]}'";
                echo "></td>";
                echo "<td><input type=text size=20 name=${i}_object_asset_no";
-               if ($keepvalues and $type_id[$i] == 0)
+               if ($keepvalues and isset ($asset_no[$i]) and (!isset ($type_id[$i]) or $type_id[$i] == 0))
                        echo " value='${asset_no[$i]}'";
                echo "></td>";
                echo "<td><input type=text size=10 name=${i}_object_barcode";
-               if ($keepvalues and $type_id[$i] == 0)
+               if ($keepvalues and isset ($barcode[$i]) and (!isset ($type_id[$i]) or $type_id[$i] == 0))
                        echo " value='${barcode[$i]}'";
                echo "></td>";
+               if ($i == 0)
+               {
+                       echo "<td valign=top rowspan=${max}>";
+                       renderTagSelect();
+                       echo "</td>\n";
+               }
                echo "</tr>\n";
        }
-       echo "<tr><td class=submit colspan=5><input type=submit name=got_fast_data value='Create'></td></tr>\n";
+       echo "<tr><td class=submit colspan=5><input type=submit name=got_fast_data value='Go!'></td></tr>\n";
        echo "</form></table>\n";
        finishPortlet();
 
-       startPortlet ('Very fast way');
-       echo '<form>';
-       echo "<input type=hidden name=page value=${pageno}>";
-       echo "<input type=hidden name=tab value=${tabno}>";
-       echo 'For each line shown below create an object of type ';
-       printSelect ($typelist, "global_type_id", 0);
-       echo " <input type=submit name=got_very_fast_data value='Go!'><br>\n";
-       echo "<textarea name=namelist cols=40 rows=25>\n";
+       startPortlet ('Same type, same tags');
+       echo "<form name=veryfastform method=post action='${root}?page=${pageno}&tab=${tabno}'>";
+       echo "<table border=0 align=center><tr><th>names</th><th>type</th></tr>";
+       echo "<tr><td rowspan=3><textarea name=namelist cols=40 rows=25>\n";
        if ($keepvalues and $global_type_id == 0)
                echo $_REQUEST['namelist'];
-       echo "</textarea></form>\n";
+       echo "</textarea></td><td valign=top>";
+       printSelect ($typelist, "global_type_id", getConfigVar ('DEFAULT_OBJECT_TYPE'));
+       echo "</td></tr>";
+       echo "<tr><th>Tags</th></tr>";
+       echo "<tr><td valign=top>";
+       renderTagSelect();
+       echo "</td></tr>";
+       echo "<tr><td colspan=2><input type=submit name=got_very_fast_data value='Go!'></td></tr></table>\n";
+       echo "</form>\n";
        finishPortlet();
 }
 
@@ -2309,38 +2613,28 @@ function renderSearchResults ()
                showError ('You are not authorized for viewing information about objects.', __FUNCTION__);
                return;
        }
+       $nhits = 0;
        // If we search for L2 address, we can either find one or find none.
        if
        (
                preg_match ('/^[0-9a-f][0-9a-f]?:[0-9a-f][0-9a-f]?:[0-9a-f][0-9a-f]?:[0-9a-f][0-9a-f]?:[0-9a-f][0-9a-f]?:[0-9a-f][0-9a-f]?$/i', $terms) or
                preg_match ('/^[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]$/i', $terms) or
-               preg_match ('/^[0-9a-f][0-9a-f][0-9a-f][0-9a-f].[0-9a-f][0-9a-f][0-9a-f][0-9a-f].[0-9a-f][0-9a-f][0-9a-f][0-9a-f]$/i', $terms)
+               preg_match ('/^[0-9a-f][0-9a-f][0-9a-f][0-9a-f].[0-9a-f][0-9a-f][0-9a-f][0-9a-f].[0-9a-f][0-9a-f][0-9a-f][0-9a-f]$/i', $terms) or
+               // STP bridge ID: bridge priotity + port MAC address. Cut off first 4 chars and look for MAC address.
+               preg_match ('/^[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]$/i', $terms)
        )
        // Search for L2 address.
        {
+               $terms = str_replace ('.', '', $terms);
+               $terms = str_replace (':', '', $terms);
+               $terms = substr ($terms, -12);
                $result = searchByl2address ($terms);
                if ($result !== NULL)
                {
-                       echo "<script language='Javascript'>document.location='${root}?page=object";
-                       echo "&hl_port_id=${result['port_id']}";
-                       echo "&object_id=${result['object_id']}';//</script>";
+                       $nhits++;
+                       $lasthit = 'port';
+                       $summary['port'][] = $result;
                }
-               else
-                       echo "L2 address '${terms}' not found!";
-       }
-       elseif (preg_match ('/^[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]$/i', $terms))
-       // STP bridge ID: bridge priotity + port MAC address. Cut off first 4 chars and look for MAC address.
-       {
-               $terms = substr ($terms, 4);
-               $result = searchByl2address ($terms);
-               if ($result !== NULL)
-               {
-                       echo "<script language='Javascript'>document.location='${root}?page=object";
-                       echo "&hl_port_id=${result['port_id']}";
-                       echo "&object_id=${result['object_id']}';//</script>";
-               }
-               else
-                       echo "L2 address '${terms}' not found!";
        }
        elseif (preg_match ('/^[0-9][0-9]?[0-9]?\.[0-9]?[0-9]?[0-9]?\.[0-9][0-9]?[0-9]?\.[0-9]?[0-9]?[0-9]?$/i', $terms))
        // Search for IP address.
@@ -2348,41 +2642,168 @@ function renderSearchResults ()
                $result = getRangeByIp ($terms);
                if ($result !== NULL)
                {
-                       echo "<script language='Javascript'>document.location='${root}?page=ipaddress";
-                       echo "&ip=${terms}";
-                       echo "';//</script>";
+                       $nhits++;
+                       $lasthit = 'ipv4address1';
+                       $summary['ipv4address1'][] = $terms;
                }
-               else
-                       echo "IP address '${terms}' not found!";
-               return;
        }
        else
-       // Search for objects.
+       // Search for objects, addresses, networks, virtual services and RS pools by their description.
        {
-               $objects = getSearchResults ($terms);
-               if (count ($objects) == 1)
+               $tmp = getObjectSearchResults ($terms);
+               if (count ($tmp))
+               {
+                       $nhits += count ($tmp);
+                       $lasthit = 'object';
+                       $summary['object'] = $tmp;
+               }
+               $tmp = getIPv4AddressSearchResult ($terms);
+               if (count ($tmp))
+               {
+                       $nhits += count ($tmp);
+                       $lasthit = 'ipv4address2';
+                       $summary['ipv4address2'] = $tmp;
+               }
+               $tmp = getIPv4PrefixSearchResult ($terms);
+               if (count ($tmp))
+               {
+                       $nhits += count ($tmp);
+                       $lasthit = 'ipv4network';
+                       $summary['ipv4network'] = $tmp;
+               }
+               $tmp = getIPv4RSPoolSearchResult ($terms);
+               if (count ($tmp))
+               {
+                       $nhits += count ($tmp);
+                       $lasthit = 'ipv4rspool';
+                       $summary['ipv4rspool'] = $tmp;
+               }
+               $tmp = getIPv4VServiceSearchResult ($terms);
+               if (count ($tmp))
                {
-                       $obj = current ($objects);
-                       echo "<script language='Javascript'>document.location='${root}?page=object&object_id=${obj['id']}';//</script>";
+                       $nhits += count ($tmp);
+                       $lasthit = 'ipv4vs';
+                       $summary['ipv4vs'] = $tmp;
                }
-               elseif (count ($objects) > 1)
+       }
+       if ($nhits == 0)
+               echo "<center><h2>Nothing found for '${terms}'</h2></center>";
+       elseif ($nhits == 1)
+       {
+               $record = current ($summary[$lasthit]);
+               switch ($lasthit)
                {
-                       echo '<br><br><table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
-                       echo '<tr><th>Common name</th><th>Visible label</th><th>Asset tag</th><th>barcode</th></tr>';
-                       $order = 'odd';
-                       global $nextorder;
-                       foreach ($objects as $obj)
+                       case 'port':
+                               echo "<script language='Javascript'>document.location='${root}?page=object";
+                               echo "&hl_port_id=" . $record['port_id'];
+                               echo "&object_id=" . $record['object_id'] . "';//</script>";
+                               break;
+                       case 'ipv4address1':
+                               echo "<script language='Javascript'>document.location='${root}?page=ipaddress";
+                               echo "&ip=${record}";
+                               echo "';//</script>";
+                               break;
+                       case 'ipv4address2':
+                               echo "<script language='Javascript'>document.location='${root}?page=ipaddress";
+                               echo "&ip=${record['ip']}";
+                               echo "';//</script>";
+                               break;
+                       case 'ipv4network':
+                               echo "<script language='Javascript'>document.location='${root}?page=iprange";
+                               echo "&id=${record['id']}";
+                               echo "';//</script>";
+                               break;
+                       case 'object':
+                               echo "<script language='Javascript'>document.location='${root}?page=object&object_id=${record['id']}';//</script>";
+                               break;
+                       case 'ipv4rspool':
+                               echo "<script language='Javascript'>document.location='${root}?page=rspool&pool_id=${record['pool_id']}';//</script>";
+                               break;
+                       case 'ipv4vs':
+                               echo "<script language='Javascript'>document.location='${root}?page=vservice&id=${record['id']}';//</script>";
+                               break;
+               }
+               return;
+       }
+       else
+       {
+               global $nextorder;
+               $order = 'odd';
+               echo "<center><h2>${nhits} result(s) found for '${terms}'</h2></center>";
+               foreach ($summary as $where => $what)
+                       switch ($where)
                        {
-                               echo "<tr class=row_${order}><td><a href=\"${root}?page=object&object_id=${obj['id']}\">${obj['dname']}</a></td>";
-                               echo "<td>${obj['label']}</td>";
-                               echo "<td>${obj['asset_no']}</td>";
-                               echo "<td>${obj['barcode']}</td></tr>";
-                               $order = $nextorder[$order];
+                               case 'object':
+                                       startPortlet ("<a href='${root}?page=objects'>Objects</a>");
+                                       echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
+                                       echo '<tr><th>Common name</th><th>Visible label</th><th>Asset tag</th><th>barcode</th></tr>';
+                                       foreach ($what as $obj)
+                                       {
+                                               echo "<tr class=row_${order}><td><a href=\"${root}?page=object&object_id=${obj['id']}\">${obj['dname']}</a></td>";
+                                               echo "<td>${obj['label']}</td>";
+                                               echo "<td>${obj['asset_no']}</td>";
+                                               echo "<td>${obj['barcode']}</td></tr>";
+                                               $order = $nextorder[$order];
+                                       }
+                                       echo '</table>';
+                                       finishPortlet();
+                                       break;
+                               case 'ipv4network':
+                                       startPortlet ("<a href='${root}?page=ipv4space'>IPv4 networks</a>");
+                                       echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
+                                       echo '<tr><th>Network</th><th>Descritpion</th></tr>';
+                                       foreach ($what as $net)
+                                       {
+                                               echo "<tr class=row_${order}><td class=tdleft><a href='${root}?page=iprange&id=${net['id']}'>${net['ip']}";
+                                               echo '/' . $net['mask'] . '</a></td>';
+                                               echo "<td class=tdleft>${net['name']}</td></tr>";
+                                               $order = $nextorder[$order];
+                                       }
+                                       echo '</table>';
+                                       finishPortlet();
+                                       break;
+                               case 'ipv4address2':
+                                       startPortlet ('IPv4 addresses');
+                                       echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
+                                       echo '<tr><th>Address</th><th>Descritpion</th></tr>';
+                                       foreach ($what as $addr)
+                                       {
+                                               echo "<tr class=row_${order}><td class=tdleft><a href='${root}?page=ipaddress&ip=${addr['ip']}'>";
+                                               echo "${addr['ip']}</a></td>";
+                                               echo "<td class=tdleft>${addr['name']}</td></tr>";
+                                               $order = $nextorder[$order];
+                                       }
+                                       echo '</table>';
+                                       finishPortlet();
+                                       break;
+                               case 'ipv4rspool':
+                                       startPortlet ("<a href='${root}?page=rspools'>RS pools</a>");
+                                       echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
+                                       foreach ($what as $rspool)
+                                       {
+                                               echo "<tr class=row_${order}><td class=tdleft><a href='${root}?page=rspool&pool_id=${rspool['pool_id']}'>";
+                                               echo buildRSPoolName ($rspool);
+                                               echo "</a></td></tr>";
+                                               $order = $nextorder[$order];
+                                       }
+                                       echo '</table>';
+                                       finishPortlet();
+                                       break;
+                               case 'ipv4vs':
+                                       startPortlet ("<a href='${root}?page=vservices'>Virtual services</a>");
+                                       echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
+                                       echo '<tr><th>VS</th><th>Descritpion</th></tr>';
+                                       foreach ($what as $vs)
+                                       {
+                                               echo "<tr class=row_${order}><td class=tdleft><a href='${root}?page=vservice&id=${vs['id']}'>";
+                                               echo buildVServiceName ($vs);
+                                               echo "</a></td><td>${vs['name']}</td></tr>";
+                                               $order = $nextorder[$order];
+                                       }
+                                       echo '</table>';
+                                       finishPortlet();
+                                       break;
                        }
-                       echo '</table>';
-               }
-               else
-                       echo "Object '${terms}' not found!";
        }
 }
 
@@ -2446,7 +2867,9 @@ function renderAccounts ()
        $order = 'odd';
        foreach ($accounts as $user)
        {
-               echo "<tr class=row_${order}><td class=tdleft>${user['user_name']}</td><td class=tdleft>${user['user_realname']}</td></li>";
+               echo "<tr class=row_${order}><td class=tdleft><div title='\$userid_${user['user_id']}'>";
+               echo "${user['user_name']}</div></td>";
+               echo "<td class=tdleft>${user['user_realname']}</td></li>";
                $order = $nextorder[$order];
        }
        echo '</table>';
@@ -2459,7 +2882,7 @@ function renderAccountsEditForm ()
        startPortlet ('User accounts');
        showMessageOrError();
        echo "<table cellspacing=0 cellpadding=5 align=center class=widetable>\n";
-       echo "<tr><th>op</th><th>Username</th><th>Real name</th><th>Password</th><th>&nbsp;</th></tr>\n";
+       echo "<tr><th>status (click to change)</th><th>Username</th><th>Real name</th><th>Password</th><th>&nbsp;</th></tr>\n";
        foreach ($accounts as $account)
        {
                echo "<form action='${root}process.php'>";
@@ -2484,18 +2907,19 @@ function renderAccountsEditForm ()
                echo "</td>";
                echo "<td><input type=text name=username value='${account['user_name']}' size=16></td>";
                echo "<td><input type=text name=realname value='${account['user_realname']}' size=24></td>";
-               echo "<td><input type=password name=password value='${account['user_password_hash']}' size=64></td>";
-               echo "<td><input type='submit' value='OK'></td>";
-               echo "</form></tr>\n";
+               echo "<td><input type=password name=password value='${account['user_password_hash']}' size=64></td><td>";
+               printImageHREF ('save', 'Save changes', TRUE);
+               echo "</td></form></tr>\n";
        }
        echo "<form action='${root}process.php' method=post><tr>";
        echo "<input type=hidden name=op value=createAccount>\n";
        echo "<input type=hidden name=page value='${pageno}'>\n";
        echo "<input type=hidden name=tab value='${tabno}'>\n";
-       echo "<td colspan=2><input type=text size=16 name=username tabindex=100></td>\n";
+       echo "<td>&nbsp;</td><td><input type=text size=16 name=username tabindex=100></td>\n";
        echo "<td><input type=text size=24 name=realname tabindex=101></td>";
-       echo "<td><input type=password size=64 name=password tabindex=102></td>";
-       echo "<td colspan=4><input type=submit value='Create account' tabindex=103></td></tr></form>";
+       echo "<td><input type=password size=64 name=password tabindex=102></td><td>";
+       printImageHREF ('create', 'Add new account', TRUE, 103);
+       echo "</td></tr></form>";
        echo "</table><br>\n";
        finishPortlet();
 }
@@ -2579,6 +3003,16 @@ function renderPermissionsEditForm ()
        finishPortlet();
 }
 
+function renderPortMapViewer ()
+{
+       renderPortMap (FALSE);
+}
+
+function renderPortMapEditor ()
+{
+       renderPortMap (TRUE);
+}
+
 function renderPortMap ($editable = FALSE)
 {
        global $nextorder, $root, $pageno, $tabno;
@@ -2651,21 +3085,7 @@ function renderRackPage ($rack_id)
 
        // Left column with information.
        echo "<td class=pcleft>";
-       startPortlet ('Rack information');
-       echo "<table border=0 cellspacing=0 cellpadding=3 width='100%'>\n";
-       echo "<tr><th width='50%' class=tdright>Rack row:</th><td class=tdleft>${rackData['row_name']}</td></tr>\n";
-       echo "<tr><th width='50%' class=tdright>Name:</th><td class=tdleft>${rackData['name']}</td></tr>\n";
-       echo "<tr><th width='50%' class=tdright>Height:</th><td class=tdleft>${rackData['height']}</td></tr>\n";
-       echo "<tr><th width='50%' class=tdright>Utilization:</th><td class=tdleft>";
-       renderProgressBar (getRSUforRack ($rackData));
-       echo "</td></tr>\n";
-       echo "<tr><th width='50%' class=tdright>Objects:</th><td class=tdleft>";
-       echo getObjectCount ($rackData);
-       echo "</td></tr>\n";
-       if (!empty ($rackData['comment']))
-               echo "<tr><th width='50%' class=tdright>Comment:</th><td class=tdleft>${rackData['comment']}</td></tr>\n";
-       echo '</table>';
-       finishPortlet();
+       renderRackInfoPortlet ($rackData);
        echo '</td>';
 
        // Right column with rendered rack.
@@ -2681,7 +3101,7 @@ function renderRackPage ($rack_id)
 function renderDictionary ()
 {
        global $nextorder;
-       $dict = getDict();
+       $dict = getDict (TRUE);
        echo "<br><table class=cooltable border=0 cellpadding=5 cellspacing=0 align=center>\n";
        foreach ($dict as $chapter_no => $chapter)
        {
@@ -2707,7 +3127,7 @@ function renderDictionary ()
                        }
                }
        }
-       echo "</table>\n";
+       echo "</table>\n<br>";
 }
 
 function renderDictionaryEditor ()
@@ -2975,46 +3395,58 @@ function printImageHREF ($tag, $title = '', $do_input = FALSE, $tabindex = 0)
        $image['reports']['path'] = 'pix/report.png';
        $image['reports']['width'] = 218;
        $image['reports']['height'] = 200;
-       $image['help']['path'] = 'pix/help.png';
-       $image['help']['width'] = 218;
-       $image['help']['height'] = 200;
-       $image['reserve']['path'] = 'pix/stop.png';
-       $image['reserve']['width'] = 16;
-       $image['reserve']['height'] = 16;
-       $image['useup']['path'] = 'pix/go.png';
+       $image['useup']['path'] = 'pix/tango-edit-clear.png';
        $image['useup']['width'] = 16;
        $image['useup']['height'] = 16;
-       $image['blockuser'] = $image['reserve'];
-       $image['unblockuser'] = $image['useup'];
-       $image['link']['path'] = 'pix/link.png';
-       $image['link']['width'] = 24;
-       $image['link']['height'] = 24;
-       $image['unlink']['path'] = 'pix/unlink.png';
-       $image['unlink']['width'] = 24;
-       $image['unlink']['height'] = 24;
-       $image['add']['path'] = 'pix/greenplus.png';
+       $image['link']['path'] = 'pix/tango-network-wired.png';
+       $image['link']['width'] = 16;
+       $image['link']['height'] = 16;
+       $image['unlink']['path'] = 'pix/tango-edit-clear.png';
+       $image['unlink']['width'] = 16;
+       $image['unlink']['height'] = 16;
+       $image['add']['path'] = 'pix/tango-list-add.png';
        $image['add']['width'] = 16;
        $image['add']['height'] = 16;
-       $image['delete']['path'] = 'pix/delete_s.gif';
+       $image['delete']['path'] = 'pix/tango-list-remove.png';
        $image['delete']['width'] = 16;
        $image['delete']['height'] = 16;
-       $image['nodelete']['path'] = 'pix/delete_g.png';
+       $image['nodelete']['path'] = 'pix/tango-list-remove-shadow.png';
        $image['nodelete']['width'] = 16;
        $image['nodelete']['height'] = 16;
        $image['grant'] = $image['add'];
        $image['revoke'] = $image['delete'];
-       $image['helphint']['path'] = 'pix/helphint.png';
-       $image['helphint']['width'] = 24;
-       $image['helphint']['height'] = 24;
-       $image['inservice']['path'] = 'pix/go.png';
+       $image['inservice']['path'] = 'pix/tango-emblem-system.png';
        $image['inservice']['width'] = 16;
        $image['inservice']['height'] = 16;
-       $image['notinservice']['path'] = 'pix/stop.png';
+       $image['notinservice']['path'] = 'pix/tango-dialog-error.png';
        $image['notinservice']['width'] = 16;
        $image['notinservice']['height'] = 16;
-       $image['find']['path'] = 'pix/find.png';
+       $image['blockuser'] = $image['inservice'];
+       $image['unblockuser'] = $image['notinservice'];
+       $image['find']['path'] = 'pix/tango-system-search.png';
        $image['find']['width'] = 16;
        $image['find']['height'] = 16;
+       $image['spacer']['path'] = 'pix/pixel.png';
+       $image['spacer']['width'] = 16;
+       $image['spacer']['height'] = 16;
+       $image['next']['path'] = 'pix/tango-go-next.png';
+       $image['next']['width'] = 32;
+       $image['next']['height'] = 32;
+       $image['prev']['path'] = 'pix/tango-go-previous.png';
+       $image['prev']['width'] = 32;
+       $image['prev']['height'] = 32;
+       $image['clear']['path'] = 'pix/tango-edit-clear.png';
+       $image['clear']['width'] = 16;
+       $image['clear']['height'] = 16;
+       $image['save']['path'] = 'pix/tango-document-save.png';
+       $image['save']['width'] = 16;
+       $image['save']['height'] = 16;
+       $image['SAVE']['path'] = 'pix/tango-document-save-big.png';
+       $image['SAVE']['width'] = 32;
+       $image['SAVE']['height'] = 32;
+       $image['create']['path'] = 'pix/tango-document-new.png';
+       $image['create']['width'] = 16;
+       $image['create']['height'] = 16;
        if (!isset ($image[$tag]))
                $tag = 'error';
        $img = $image[$tag];
@@ -3068,11 +3500,11 @@ function renderReportSummary ()
 
        echo "</td><td class=pcright>\n";
 
-       startPortlet ("Here be dragons");
-       dragon();
-       dragon();
-       dragon();
-       echo 'ASCII art &copy; Daniel C. Au';
+       startPortlet ("Tag popularity");
+       echo "<table>\n";
+       foreach (getTagStats() as $header => $data)
+               echo "<tr><th class=tdright>${header}:</th><td class=tdleft>${data}</td></tr>\n";
+       echo "</table>\n";
        finishPortlet();
        echo "</td></tr>\n";
        echo "</table>\n";
@@ -3080,6 +3512,7 @@ function renderReportSummary ()
 
 function dragon ()
 {
+       startPortlet ('Here be dragons');
 ?>
 <div class=dragon><pre><font color="#00ff33">
                  \||/
@@ -3096,6 +3529,7 @@ function dragon ()
 
 </font></pre></div>
 <?php
+       finishPortlet();
 }
 
 function renderUIConfig ()
@@ -3174,7 +3608,7 @@ function renderVLANMembership ($object_id = 0)
                // included. The gateway is expected to filter unnecessary changes silently
                // and to provide a list of responses with either error or success message
                // for each of the rest.
-               assertUIntArg ('portcount');
+               assertUIntArg ('portcount', __FUNCTION__);
                $nports = $_REQUEST['portcount'];
                $prefix = 'set ';
                $log = array();
@@ -3257,6 +3691,11 @@ function renderVLANMembership ($object_id = 0)
                        echo "<input type=hidden name=vlanid_${portno} value='trunk'>";
                        echo "<select disabled multiple='multiple' size=1><option>TRUNK</option></select>";
                }
+               elseif ($port['vlanid'] == 'routed')
+               {
+                       echo "<input type=hidden name=vlanid_${portno} value='routed'>";
+                       echo "<select disabled multiple='multiple' size=1><option>ROUTED</option></select>";
+               }
                else
                {
                        echo "<select name=vlanid_${portno}>";
@@ -3339,7 +3778,7 @@ function renderVLANMembership ($object_id = 0)
 // on the current device or displays the result of the scan.
 function renderSNMPPortFinder ($object_id = 0)
 {
-       global $root, $pageno, $tabno, $remote_username;
+       global $pageno, $tabno;
        if ($object_id <= 0)
        {
                showError ('Invalid object_id', __FUNCTION__);
@@ -3348,301 +3787,8 @@ function renderSNMPPortFinder ($object_id = 0)
 // FIXME: check if SNMP PHP extension is available!
        if (isset ($_REQUEST['do_scan']))
        {
-               $log = array();
-// IDs: http://cisco.com/en/US/products/sw/cscowork/ps2064/products_device_support_table09186a0080803bb4.html
-// 2960: http://www.cisco.com/en/US/products/ps6406/prod_models_comparison.html
-// 2970: http://cisco.com/en/US/products/hw/switches/ps5206/products_qanda_item09186a00801b1750.shtml
-// 3500XL: http://cisco.com/en/US/products/hw/switches/ps637/products_eol_models.html
-// 3560: http://cisco.com/en/US/products/hw/switches/ps5528/products_data_sheet09186a00801f3d7f.html
-// 3750: http://cisco.com/en/US/products/hw/switches/ps5023/products_data_sheet09186a008016136f.html
-               $ciscomodel[283] = 'WS-C6509-E (9-slot system)';
-// FIXME: hwtype hardcoded value will become invalid after the Dictionary table transformation
-// in 0.14.7 version. Either the values will have to be adjusted as well or we have to switch
-// to value lookup (not reliable).
-               $hwtype[283] = 148;
-#              $ciscomodel[694] = 'WS-C2960-24TC-L (24 Ethernet 10/100 ports and 2 dual-purpose uplinks)';
-#              $ciscomodel[695] = 'WS-C2960-48TC-L (48 Ethernet 10/100 ports and 2 dual-purpose uplinks)';
-               $ciscomodel[696] = 'WS-C2960G-24TC-L (20 Ethernet 10/100/1000 ports and 4 dual-purpose uplinks)';
-               $hwtype[696] = 167;
-               $ciscomodel[697] = 'WS-C2960G-48TC-L (44 Ethernet 10/100/1000 ports and 4 dual-purpose uplinks)';
-               $hwtype[697] = 166;
-#              $ciscomodel[716] = 'WS-C2960-24TT-L (24 Ethernet 10/100 ports and 2 10/100/1000 uplinks)';
-#              $ciscomodel[717] = 'WS-C2960-48TT-L (48 Ethernet 10/100 ports and 2 10/100/1000 uplinks)';
-               $ciscomodel[527] = 'WS-C2970G-24T (24 Ethernet 10/100/1000 ports)';
-               $hwtype[527] = 210;
-               $ciscomodel[561] = 'WS-C2970G-24TS (24 Ethernet 10/100/1000 ports and 4 10/100/1000 SFP uplinks)';
-               $hwtype[561] = 115;
-#              $ciscomodel[633] = 'WS-C3560-24TS (24 Ethernet 10/100 ports and 2 10/100/1000 SFP uplinks)';
-#              $hwtype[633] = 169;
-               $ciscomodel[634] = 'WS-C3560-48TS (48 Ethernet 10/100 ports and 4 10/100/1000 SFP uplinks)';
-               $hwtype[634] = 170;
-#              $ciscomodel[563] = 'WS-C3560-24PS (24 Ethernet 10/100 POE ports and 2 10/100/1000 SFP uplinks)';
-#              $hwtype[563] = 171;
-               $ciscomodel[564] = 'WS-C3560-48PS (48 Ethernet 10/100 POE ports and 4 10/100/1000 SFP uplinks)';
-               $hwtype[564] = 172;
-               $ciscomodel[614] = 'WS-C3560G-24PS (24 Ethernet 10/100/1000 POE ports and 4 10/100/1000 SFP uplinks)';
-               $hwtype[614] = 175;
-               $ciscomodel[615] = 'WS-C3560G-24TS (24 Ethernet 10/100/1000 ports and 4 10/100/1000 SFP uplinks)';
-               $hwtype[615] = 173;
-               $ciscomodel[616] = 'WS-C3560G-48PS (48 Ethernet 10/100/1000 POE ports and 4 10/100/1000 SFP uplinks)';
-               $hwtype[616] = 176;
-               $ciscomodel[617] = 'WS-C3560G-48TS (48 Ethernet 10/100/1000 ports and 4 10/100/1000 SFP uplinks)';
-               $hwtype[617] = 174;
-               $ciscomodel[58] = 'WS-C4503 (3-slot system)';
-               $hwtype[58] = 145;
-               $ciscomodel[503] = '4503 (3-slot system)';
-               $hwtype[503] = 145;
-               $ciscomodel[59] = 'WS-C4506 (6-slot system)';
-               $hwtype[59] = 156;
-               $ciscomodel[502] = '4506 (6-slot system)';
-               $hwtype[502] = 156;
-               $ciscomodel[626] = 'WS-C4948 (48 Ethernet 10/100/1000 ports and 4 10/100/1000 SFP uplinks)';
-               $hwtype[626] = 147;
-               $ciscomodel[659] = 'WS-C4948-10GE (48 Ethernet 10/100/1000 ports and 2 10Gb X2 uplinks)';
-               $hwtype[659] = 377;
-               assertStringArg ('community');
-               $community = $_REQUEST['community'];
-               $objectInfo = getObjectInfo ($object_id);
-               $endpoints = findAllEndpoints ($object_id, $objectInfo['name']);
-               $sysName = substr (snmpget ($endpoints[0], $community, 'sysName.0'), strlen ('STRING: '));
-               $sysDescr = snmpget ($endpoints[0], $community, 'sysDescr.0');
-               // Strip the object type, it's always string here.
-               $sysDescr = substr ($sysDescr, strlen ('STRING: '));
-               if (strpos ($sysDescr, 'Cisco IOS Software') === 0 or strpos ($sysDescr, 'Cisco Internetwork Operating System Software') === 0)
-                       $log[] = array ('code' => 'success', 'message' => 'Seems to be a Cisco box');
-               else
-               {
-                       $log[] = array ('code' => 'error', 'message' => 'No idea how to handle ' . $sysDescr);
-                       printLog ($log);
-                       return;
-               }
-
-               // It's a Cisco. Go on.
-               $attrs = getAttrValues ($object_id);
-               // Only fill in attribute values, if they are not set.
-               // FIXME: this is hardcoded
-
-               if (empty ($attrs[3]['value']) && !empty ($sysName)) // FQDN
-               {
-                       $error = commitUpdateAttrValue ($object_id, 3, $sysName);
-                       if ($error == TRUE)
-                               $log[] = array ('code' => 'success', 'message' => 'FQDN set to ' . $sysName);
-                       else
-                               $log[] = array ('code' => 'error', 'message' => 'Failed settig FQDN: ' . $error);
-               }
-
-               if (empty ($attrs[5]['value'])) // SW version
-               {
-                       $IOSversion = ereg_replace ('^.*, Version ([^ ]+), .*$', '\\1', $sysDescr);
-                       $error = commitUpdateAttrValue ($object_id, 5, $IOSversion);
-                       if ($error == TRUE)
-                               $log[] = array ('code' => 'success', 'message' => 'SW version set to ' . $IOSversion);
-                       else
-                               $log[] = array ('code' => 'error', 'message' => 'Failed settig SW version: ' . $error);
-               }
-
-               if (empty ($attrs[4]['value']) and substr ($IOSversion, 0, 4) == '12.2') // switch OS type
-               {
-                       $error = commitUpdateAttrValue ($object_id, 4, 252);
-                       if ($error == TRUE)
-                               $log[] = array ('code' => 'success', 'message' => 'Switch OS type set to Cisco IOS 12.2');
-                       else
-                               $log[] = array ('code' => 'error', 'message' => 'Failed settig Switch OS type: ' . $error);
-               }
-
-               $sysObjectID = snmpget ($endpoints[0], $community, 'sysObjectID.0');
-               // Transform OID
-               $sysObjectID = substr ($sysObjectID, strlen ('OID: SNMPv2-SMI::enterprises.9.1.'));
-               if (!isset ($ciscomodel[$sysObjectID]))
-               {
-                       $log[] = array ('code' => 'error', 'message' => 'Could not guess exact HW model!');
-                       printLog ($log);
-                       return;
-               }
-               $log[] = array ('code' => 'success', 'message' => 'HW is ' . $ciscomodel[$sysObjectID]);
-               if (empty ($attrs[2]['value']) and isset ($hwtype[$sysObjectID])) // switch HW type
-               {
-                       $error = commitUpdateAttrValue ($object_id, 2, $hwtype[$sysObjectID]);
-                       if ($error == TRUE)
-                               $log[] = array ('code' => 'success', 'message' => 'HW type updated Ok');
-                       else
-                               $log[] = array ('code' => 'error', 'message' => 'Failed settig HW type: ' . $error);
-               }
-               // Now fetch ifType, ifDescr and ifPhysAddr and let model-specific code sort the data out.
-               $ifType = snmpwalkoid ($endpoints[0], $community, 'ifType');
-               $ifDescr = snmpwalkoid ($endpoints[0], $community, 'ifdescr');
-               $ifPhysAddress = snmpwalkoid ($endpoints[0], $community, 'ifPhysAddress');
-               // Combine 3 tables into 1...
-               $ifList1 = array();
-               foreach ($ifType as $key => $val)
-               {
-                       list ($dummy, $ifIndex) = explode ('.', $key);
-                       list ($dummy, $type) = explode (' ', $val);
-                       $ifList1[$ifIndex]['type'] = $type;
-               }
-               foreach ($ifDescr as $key => $val)
-               {
-                       list ($dummy, $ifIndex) = explode ('.', $key);
-                       list ($dummy, $descr) = explode (' ', $val);
-                       $ifList1[$ifIndex]['descr'] = trim ($descr, '"');
-               }
-               foreach ($ifPhysAddress as $key => $val)
-               {
-                       list ($dummy, $ifIndex) = explode ('.', $key);
-                       list ($dummy, $addr) = explode (':', $val);
-                       $addr = str_replace (' ', '', $addr);
-                       $ifList1[$ifIndex]['phyad'] = $addr;
-               }
-               // ...and then reverse it inside out to make description the key.
-               $ifList2 = array();
-               foreach ($ifList1 as $ifIndex => $data)
-               {
-                       $ifList2[$data['descr']]['type'] = $data['type'];
-                       $ifList2[$data['descr']]['phyad'] = $data['phyad'];
-                       $ifList2[$data['descr']]['idx'] = $ifIndex;
-               }
-               $newports = 0;
-               // Now we can directly pick necessary ports from the table accordingly
-               // to our known hardware model.
-               switch ($sysObjectID)
-               {
-               // FIXME: chassis edge switches often share a common naming scheme, so
-               // the sequences below have to be generalized. Let's have some duplicated
-               // code for the time being, as this is the first implementation ever.
-                       case '697': // WS-C2960G-48TC-L
-                               // 44 copper ports: 1X, 2X, 3X...
-                               // 4 combo ports: 45, 46, 47, 48. Don't list SFP connectors atm, as it's not
-                               // clear how to fit them into current Ports table structure.
-                               for ($i = 1; $i <= 48; $i++)
-                               {
-                                       $label = ($i >= 45) ? "${i}" : "${i}X";
-                                       $error = commitAddPort ($object_id, 'gi0/' . $i, 24, $label, $ifList2["GigabitEthernet0/${i}"]['phyad']);
-                                       if ($error == '')
-                                               $newports++;
-                                       else
-                                               $log[] = array ('code' => 'error', 'message' => 'Failed to add port ' . $label . ': ' . $error);
-                               }
-                               break;
-                       case '696': // WS-C2960G-24TC-L
-                               // Quite similar to the above.
-                               for ($i = 1; $i <= 24; $i++)
-                               {
-                                       $label = ($i >= 21) ? "${i}" : "${i}X";
-                                       $error = commitAddPort ($object_id, 'gi0/' . $i, 24, $label, $ifList2["GigabitEthernet0/${i}"]['phyad']);
-                                       if ($error == '')
-                                               $newports++;
-                                       else
-                                               $log[] = array ('code' => 'error', 'message' => 'Failed to add port ' . $label . ': ' . $error);
-                               }
-                               break;
-                       case '564': // WS-C3560-48PS
-                       case '634': // WS-C3560-48TS
-                               for ($i = 1; $i <= 48; $i++)
-                               {
-                                       $label = "${i}X";
-                                       $error = commitAddPort ($object_id, 'fa0/' . $i, 19, $label, $ifList2["FastEthernet0/${i}"]['phyad']);
-                                       if ($error == '')
-                                               $newports++;
-                                       else
-                                               $log[] = array ('code' => 'error', 'message' => 'Failed to add port ' . $label . ': ' . $error);
-                               }
-                               for ($i = 1; $i <= 4; $i++)
-                               {
-                                       $label = "${i}";
-                                       $error = commitAddPort ($object_id, 'gi0/' . $i, 24, $label, $ifList2["GigabitEthernet0/${i}"]['phyad']);
-                                       if ($error == '')
-                                               $newports++;
-                                       else
-                                               $log[] = array ('code' => 'error', 'message' => 'Failed to add port ' . $label . ': ' . $error);
-                               }
-                               break;
-                       case '614': // WS-C3560G-24PS
-                       case '615': // WS-C3560G-24TS
-                       case '527': // WS-C2970G-24T
-                       case '561': // WS-C2970G-24TS
-                               for ($i = 1; $i <= 24; $i++)
-                               {
-                                       $label = "${i}X";
-                                       $error = commitAddPort ($object_id, 'gi0/' . $i, 24, $label, $ifList2["GigabitEthernet0/${i}"]['phyad']);
-                                       if ($error == '')
-                                               $newports++;
-                                       else
-                                               $log[] = array ('code' => 'error', 'message' => 'Failed to add port ' . $label . ': ' . $error);
-                               }
-                               break;
-                       case '616': // WS-C3560G-48PS
-                       case '617': // WS-C3560G-48TS
-                               for ($i = 1; $i <= 48; $i++)
-                               {
-                                       $label = "${i}X";
-                                       $error = commitAddPort ($object_id, 'gi0/' . $i, 24, $label, $ifList2["GigabitEthernet0/${i}"]['phyad']);
-                                       if ($error == '')
-                                               $newports++;
-                                       else
-                                               $log[] = array ('code' => 'error', 'message' => 'Failed to add port ' . $label . ': ' . $error);
-                               }
-                               break;
-                       case '626': // WS-C4948
-                       case '659': // WS-C4948-10GE
-                               for ($i = 1; $i <= 48; $i++)
-                               {
-                                       $label = "${i}X";
-                                       $error = commitAddPort ($object_id, 'gi1/' . $i, 24, $label, $ifList2["GigabitEthernet1/${i}"]['phyad']);
-                                       if ($error == '')
-                                               $newports++;
-                                       else
-                                               $log[] = array ('code' => 'error', 'message' => 'Failed to add port ' . $label . ': ' . $error);
-                               }
-                               break;
-               // For modular devices we don't iterate over all possible port names,
-               // but use the first list to pick everything that looks legitimate
-               // for this hardware. It would be correct to fetch the list of modules
-               // installed to generate lists of ports, but who is going to implement
-               // this?
-                       case '503': // 4503
-                       case '58': // WS-C4503
-                       case '502': // 4506
-                       case '59': // WS-C4506
-                       case '283': // WS-C6509-E
-                               foreach ($ifList1 as $port)
-                               {
-                                       if ($port['type'] != 'ethernet-csmacd(6)')
-                                               continue;
-                                       // Copper Fa/Gi harvesting is relatively simple, while 10Gig ports can
-                                       // have random samples of transciever units.
-                                       if (strpos ($port['descr'], 'FastEthernet') === 0) // Fa
-                                       {
-                                               $prefix = 'fa';
-                                               $ptype = 19; // RJ-45/100Base-TX
-                                               list ($slotno, $portno) = explode ('/', substr ($port['descr'], strlen ('FastEthernet')));
-                                       }
-                                       elseif (strpos ($port['descr'], 'GigabitEthernet') === 0) // Gi
-                                       {
-                                               $prefix = 'gi';
-                                               $ptype = 24; // RJ-45/1000Base-T
-                                               list ($slotno, $portno) = explode ('/', substr ($port['descr'], strlen ('GigabitEthernet')));
-                                       }
-                                       else continue;
-                                       $label = "slot ${slotno} port ${portno}";
-                                       $pname = "${prefix}${slotno}/${portno}";
-                                       $error = commitAddPort ($object_id, $pname, $ptype, $label, $port['phyad']);
-                                       if ($error == '')
-                                               $newports++;
-                                       else
-                                               $log[] = array ('code' => 'error', 'message' => 'Failed to add port ' . $pname . ': ' . $error);
-                               }
-                               break;
-                       default:
-                               showError ("Unexpected sysObjectID '${sysObjectID}'", __FUNCTION__);
-               }
-               $error = commitAddPort ($object_id, 'con0', 29, 'console', '');
-               if ($error == '')
-                       $newports++;
-               else
-                       $log[] = array ('code' => 'error', 'message' => 'Failed to add console port : ' . $error);
-               if ($newports > 0)
-                       $log[] = array ('code' => 'success', 'message' => "Added ${newports} new ports");
-               printLog ($log);
+               assertStringArg ('community', __FUNCTION__);
+               printLog (doSNMPmining ($object_id, $_REQUEST['community']));
                return;
        }
        echo "<form method=post>\n";
@@ -3746,7 +3892,7 @@ function renderLVSConfig ($object_id = 0)
        }
        if (isset ($_REQUEST['do_activate']))
        {
-               printLog (activateSLBConfig ($object_id, html_entity_decode ($newconfig, ENT_QUOTES)));
+               printLog (activateSLBConfig ($object_id, html_entity_decode ($newconfig, ENT_QUOTES, 'UTF-8')));
        }
        echo "<form method=post action=${root}>";
        echo "<input type=hidden name=page value=${pageno}>";
@@ -3761,7 +3907,7 @@ function renderLVSConfig ($object_id = 0)
 
 function renderVirtualService ()
 {
-       assertUIntArg ('id');
+       assertUIntArg ('id', __FUNCTION__);
        $vsid = $_REQUEST['id'];
        global $root, $nextorder;
        if ($vsid <= 0)
@@ -3783,6 +3929,7 @@ function renderVirtualService ()
        echo "<tr><th width='50%' class=tdright>Protocol:</th><td class=tdleft>${vsinfo['proto']}</td></tr>\n";
        echo "<tr><th width='50%' class=tdright>Virtual IP address:</th><td class=tdleft><a href='${root}?page=ipaddress&tab=default&ip=${vsinfo['vip']}'>${vsinfo['vip']}</a></td></tr>\n";
        echo "<tr><th width='50%' class=tdright>Virtual port:</th><td class=tdleft>${vsinfo['vport']}</td></tr>\n";
+       printTagTRs ("${root}?page=vservices&");
        if (!empty ($vsinfo['vsconfig']))
        {
                echo "<tr><th width='50%' class=tdright>VS configuration:</th><td class=tdleft>&nbsp;</td></tr>\n";
@@ -3807,7 +3954,7 @@ function renderVirtualService ()
                echo "<tr class=row_${order}><td class=tdleft>";
                // Pool info
                echo '<table width=100%>';
-               echo "<tr><td colspan=2><a href='${root}?page=rspool&id=${pool_id}'>";
+               echo "<tr><td colspan=2><a href='${root}?page=rspool&pool_id=${pool_id}'>";
                if (!empty ($poolInfo['name']))
                        echo $poolInfo['name'];
                else
@@ -3866,48 +4013,58 @@ function renderRSPoolServerForm ($pool_id = 0)
        showMessageOrError();
        $poolInfo = getRSPoolInfo ($pool_id);
 
-       $rsc = count ($poolInfo['rslist']);
-       startPortlet ("Manage existing (${rsc})");
-       echo "<table cellspacing=0 cellpadding=5 align=center class=cooltable>\n";
-       echo "<tr><th>&nbsp;</th><th>Address</th><th>Port</th><th>configuration</th><th>&nbsp;</th></tr>\n";
-       $order = 'odd';
-       foreach ($poolInfo['rslist'] as $rsid => $rs)
+       if (($rsc = count ($poolInfo['rslist'])))
        {
-               echo "<form action='${root}process.php'>";
-               echo "<input type=hidden name=page value='${pageno}'>\n";
-               echo "<input type=hidden name=tab value='${tabno}'>\n";
-               echo "<input type=hidden name=op value=updRS>";
-               echo "<input type=hidden name=rs_id value='${rsid}'>";
-               echo "<input type=hidden name=id value='${pool_id}'>";
-               echo "<tr valign=top class=row_${order}><td><a href='${root}process.php?page=${pageno}&tab=${tabno}";
-               echo "&op=delRS&pool_id=${pool_id}&id=${rsid}'>";
-               printImageHREF ('delete', 'Delete this real server');
-               echo "</td><td><input type=text name=rsip value='${rs['rsip']}'></td>";
-               echo "<td><input type=text name=rsport size=5 value='${rs['rsport']}'></td>";
-               echo "<td><textarea name=rsconfig>${rs['rsconfig']}</textarea></td>";
-               echo "<td><input type=submit value='OK'></td>";
-               echo "</tr></form>\n";
-               $order = $nextorder[$order];
+               startPortlet ("Manage existing (${rsc})");
+               echo "<table cellspacing=0 cellpadding=5 align=center class=cooltable>\n";
+               echo "<tr><th>&nbsp;</th><th>Address</th><th>Port</th><th>configuration</th><th>&nbsp;</th></tr>\n";
+               $order = 'odd';
+               foreach ($poolInfo['rslist'] as $rsid => $rs)
+               {
+                       echo "<form action='${root}process.php'>";
+                       echo "<input type=hidden name=page value='${pageno}'>\n";
+                       echo "<input type=hidden name=tab value='${tabno}'>\n";
+                       echo "<input type=hidden name=op value=updRS>";
+                       echo "<input type=hidden name=rs_id value='${rsid}'>";
+                       echo "<input type=hidden name=pool_id value='${pool_id}'>";
+                       echo "<tr valign=top class=row_${order}><td><a href='${root}process.php?page=${pageno}&tab=${tabno}";
+                       echo "&op=delRS&pool_id=${pool_id}&id=${rsid}'>";
+                       printImageHREF ('delete', 'Delete this real server');
+                       echo "</td><td><input type=text name=rsip value='${rs['rsip']}'></td>";
+                       echo "<td><input type=text name=rsport size=5 value='${rs['rsport']}'></td>";
+                       echo "<td><textarea name=rsconfig>${rs['rsconfig']}</textarea></td><td>";
+                       printImageHREF ('save', 'Save changes', TRUE);
+                       echo "</td></tr></form>\n";
+                       $order = $nextorder[$order];
+               }
+               echo "</table>\n";
+               finishPortlet();
        }
-       echo "</table>\n";
-       finishPortlet();
 
        startPortlet ('Add one');
        echo "<table cellspacing=0 cellpadding=5 align=center class=widetable>\n";
-       echo "<tr><th>Address</th><th>Port</th><th>&nbsp;</th></tr>\n";
+       echo "<tr><th>in service</th><th>Address</th><th>Port</th><th>&nbsp;</th></tr>\n";
        echo "<form name=addone action='${root}process.php'>";
        echo "<input type=hidden name=page value='${pageno}'>\n";
        echo "<input type=hidden name=tab value='${tabno}'>\n";
        echo "<input type=hidden name=op value=addRS>";
-       echo "<input type=hidden name=id value='${pool_id}'>";
-       echo "<tr><td><input type=text name=rsip tabindex=1></td>";
+       echo "<input type=hidden name=pool_id value='${pool_id}'>";
+       echo "<tr><td>";
+       if (getConfigVar ('DEFAULT_IPV4_RS_INSERVICE') == 'yes')
+               printImageHREF ('inservice', 'in service');
+       else
+               printImageHREF ('notinservice', 'NOT in service');
+       echo "</td><td><input type=text name=remoteip id=remoteip tabindex=1> ";
+       echo "<a href='javascript:;' onclick='window.open(\"${root}find_object_ip_helper.php\", \"findobjectip\", \"height=700, width=400, location=no, menubar=no, resizable=yes, scrollbars=no, status=no, titlebar=no, toolbar=no\");'>";
+       printImageHREF ('find', 'pick address');
+       echo "</a></td>";
        $default_port = getConfigVar ('DEFAULT_SLB_RS_PORT');
        if ($default_port == 0)
                $default_port = '';
-       echo "<td><input type=text name=rsport size=5 value='${default_port}'  tabindex=2></td>";
-       echo "<td><input type=submit value='OK' tabindex=3></tr>\n";
-       echo "<tr><th colspan=3>configuration</th></tr>";
-       echo "<tr><td colspan=3><textarea name=rsconfig rows=10 cols=80 tabindex=4></textarea></td></tr>";
+       echo "<td><input type=text name=rsport size=5 value='${default_port}'  tabindex=2></td><td>";
+       printImageHREF ('add', 'Add new', TRUE, 3);
+       echo "</td></tr><tr><th colspan=4>configuration</th></tr>";
+       echo "<tr><td colspan=4><textarea name=rsconfig rows=10 cols=80 tabindex=4></textarea></td></tr>";
        echo "</form></table>\n";
        finishPortlet();
 
@@ -3916,12 +4073,22 @@ function renderRSPoolServerForm ($pool_id = 0)
        echo "<input type=hidden name=page value='${pageno}'>\n";
        echo "<input type=hidden name=tab value='${tabno}'>\n";
        echo "<input type=hidden name=op value=addMany>";
-       echo "<input type=hidden name=id value='${pool_id}'>";
-       echo "<table border=0 align=center>\n<tr><td>Format: ";
-       $formats = array ('ipvs_2' => 'ipvsadm -l -n (address and port)', 'ipvs_3' => 'ipvsadm -l -n (address, port and weight)');
+       echo "<input type=hidden name=pool_id value='${pool_id}'>";
+       echo "<table border=0 align=center>\n<tr><td>";
+       if (getConfigVar ('DEFAULT_IPV4_RS_INSERVICE') == 'yes')
+               printImageHREF ('inservice', 'in service');
+       else
+               printImageHREF ('notinservice', 'NOT in service');
+       echo "</td><td>Format: ";
+       $formats = array
+       (
+               'ipvs_2' => 'ipvsadm -l -n (address and port)',
+               'ipvs_3' => 'ipvsadm -l -n (address, port and weight)',
+               'ssv_2' => 'SSV: &lt;IP address&gt; &lt;port&gt;'
+       );
        printSelect ($formats, 'format');
        echo "</td><td><input type=submit value=Parse></td></tr>\n";
-       echo "<tr><td colspan=2><textarea name=rawtext cols=100 rows=50></textarea></td></tr>\n";
+       echo "<tr><td colspan=3><textarea name=rawtext cols=100 rows=50></textarea></td></tr>\n";
        echo "</table>\n";
        finishPortlet();
 }
@@ -3935,37 +4102,42 @@ function renderRSPoolLBForm ($pool_id = 0)
        $vs_list = array ();
        foreach (getVSList() as $vsid => $vsinfo)
                $vs_list[$vsid] = buildVServiceName ($vsinfo) . (empty ($vsinfo['name']) ? '' : " (${vsinfo['name']})");
-       startPortlet ('Manage existing (' . count ($poolInfo['lblist']) . ')');
-       echo "<table cellspacing=0 cellpadding=5 align=center class=cooltable>\n";
-       echo "<tr><th>&nbsp;</th><th>LB</th><th>VS</th><th>VS config</th><th>RS config</th><th>&nbsp;</th></tr>\n";
-       $order = 'odd';
-       foreach ($poolInfo['lblist'] as $object_id => $vslist)
-               foreach ($vslist as $vs_id => $configs)
-               {
-                       $oi = getObjectInfo ($object_id);
-                       echo "<form action='${root}process.php'>";
-                       echo "<input type=hidden name=page value='${pageno}'>\n";
-                       echo "<input type=hidden name=tab value='${tabno}'>\n";
-                       echo "<input type=hidden name=op value=updLB>";
-                       echo "<input type=hidden name=pool_id value='${pool_id}'>";
-                       echo "<input type=hidden name=vs_id value='${vs_id}'>";
-                       echo "<input type=hidden name=object_id value='${object_id}'>";
-                       echo "<tr valign=top class=row_${order}><td><a href='${root}process.php?page=${pageno}&tab=${tabno}&op=delLB&pool_id=${pool_id}&object_id=${object_id}&vs_id=${vs_id}'>";
-                       printImageHREF ('delete', 'Unconfigure');
-                       echo "</a></td>";
-                       echo "<td class=tdleft><a href='${root}?page=object&object_id=${object_id}'>${oi['dname']}</a></td>";
-                       echo "<td class=tdleft><a href='${root}?page=vservice&id=${vs_id}'>";
-                       $vsinfo = getVServiceInfo ($vs_id);
-                       echo buildVServiceName ($vsinfo) . '</a>';
-                       if (!empty ($vsinfo['name']))
-                               echo " (${vsinfo['name']})";
-                       echo "<td><textarea name=vsconfig>${configs['vsconfig']}</textarea></td>";
-                       echo "<td><textarea name=rsconfig>${configs['rsconfig']}</textarea></td>";
-                       echo "<td><input type=submit value=OK></td></tr></form>\n";
-                       $order = $nextorder[$order];
-               }
-       echo "</table>\n";
-       finishPortlet();
+
+       if (count ($poolInfo['lblist']))
+       {
+               startPortlet ('Manage existing (' . count ($poolInfo['lblist']) . ')');
+               echo "<table cellspacing=0 cellpadding=5 align=center class=cooltable>\n";
+               echo "<tr><th>&nbsp;</th><th>LB</th><th>VS</th><th>VS config</th><th>RS config</th><th>&nbsp;</th></tr>\n";
+               $order = 'odd';
+               foreach ($poolInfo['lblist'] as $object_id => $vslist)
+                       foreach ($vslist as $vs_id => $configs)
+                       {
+                               $oi = getObjectInfo ($object_id);
+                               echo "<form action='${root}process.php'>";
+                               echo "<input type=hidden name=page value='${pageno}'>\n";
+                               echo "<input type=hidden name=tab value='${tabno}'>\n";
+                               echo "<input type=hidden name=op value=updLB>";
+                               echo "<input type=hidden name=pool_id value='${pool_id}'>";
+                               echo "<input type=hidden name=vs_id value='${vs_id}'>";
+                               echo "<input type=hidden name=object_id value='${object_id}'>";
+                               echo "<tr valign=top class=row_${order}><td><a href='${root}process.php?page=${pageno}&tab=${tabno}&op=delLB&pool_id=${pool_id}&object_id=${object_id}&vs_id=${vs_id}'>";
+                               printImageHREF ('delete', 'Unconfigure');
+                               echo "</a></td>";
+                               echo "<td class=tdleft><a href='${root}?page=object&object_id=${object_id}'>${oi['dname']}</a></td>";
+                               echo "<td class=tdleft><a href='${root}?page=vservice&id=${vs_id}'>";
+                               $vsinfo = getVServiceInfo ($vs_id);
+                               echo buildVServiceName ($vsinfo) . '</a>';
+                               if (!empty ($vsinfo['name']))
+                                       echo " (${vsinfo['name']})";
+                               echo "<td><textarea name=vsconfig>${configs['vsconfig']}</textarea></td>";
+                               echo "<td><textarea name=rsconfig>${configs['rsconfig']}</textarea></td><td>";
+                               printImageHREF ('save', 'Save changes', TRUE);
+                               echo "</td></tr></form>\n";
+                               $order = $nextorder[$order];
+                       }
+               echo "</table>\n";
+               finishPortlet();
+       }
 
        startPortlet ('Add new');
        echo "<table cellspacing=0 cellpadding=5 align=center class=widetable>\n";
@@ -3983,7 +4155,9 @@ function renderRSPoolLBForm ($pool_id = 0)
        }
        echo "</select> ";
        printSelect ($vs_list, 'vs_id');
-       echo "</td><td><input type=submit value=OK tabindex=2></td></tr>\n";
+       echo "</td><td>";
+       printImageHREF ('add', 'Configure LB', TRUE, 2);
+       echo "</td></tr>\n";
        echo "<tr><th>VS config</th><td colspan=2><textarea name=vsconfig rows=10 cols=80></textarea></td></tr>";
        echo "<tr><th>RS config</th><td colspan=2><textarea name=rsconfig rows=10 cols=80></textarea></td></tr>";
        echo "</form></table>\n";
@@ -4016,6 +4190,7 @@ function renderRSPool ($pool_id = 0)
                echo "<tr><th width='50%' class=tdright>Pool name:</th><td class=tdleft>${poolInfo['name']}</td></tr>\n";
        echo "<tr><th width='50%' class=tdright>Real servers:</th><td class=tdleft>" . count ($poolInfo['rslist']) . "</td></tr>\n";
        echo "<tr><th width='50%' class=tdright>Load balancers:</th><td class=tdleft>" . count ($poolInfo['lblist']) . "</td></tr>\n";
+       printTagTRs ("${root}?page=rspools&");
        echo "</table>";
        finishPortlet();
 
@@ -4060,13 +4235,18 @@ function renderRSPool ($pool_id = 0)
 function renderVSList ()
 {
        global $root, $nextorder;
-       $vslist = getVSList();
+       $tagfilter = getTagFilter();
+       $vslist = getVSList ($tagfilter);
+       echo "<table border=0 class=objectview>\n";
+       echo "<tr><td class=pcleft>";
+
+       startPortlet ('Virtual services');
        echo "<table class=widetable border=0 cellpadding=10 cellspacing=0 align=center>\n";
        echo "<tr><th>endpoint</th><th>name</th><th>VS configuration</th><th>RS configuration</th></tr>";
        $order = 'odd';
        foreach ($vslist as $vsid => $vsinfo)
        {
-               echo "<tr valign=top class=row_${order}><td class=tdleft><a href='${root}?page=vservice&id=${vsid}'>" . buildVServiceName ($vsinfo);
+               echo "<tr align=left valign=top class=row_${order}><td class=tdleft><a href='${root}?page=vservice&id=${vsid}'>" . buildVServiceName ($vsinfo);
                echo "</a></td>";
                echo "<td class=tdleft>${vsinfo['name']}</td>";
                echo "<td><pre>${vsinfo['vsconfig']}</pre></td>";
@@ -4075,6 +4255,10 @@ function renderVSList ()
                $order = $nextorder[$order];
        }
        echo "</table>";
+       finishPortlet();
+       echo '</td><td class=pcright>';
+       renderTagFilterPortlet ($tagfilter, 'ipv4vs');
+       echo '</td></tr></table>';
 }
 
 function renderVSListEditForm ()
@@ -4147,19 +4331,23 @@ function renderVSListEditForm ()
 function renderRSPoolList ()
 {
        global $root, $nextorder;
-       $pool_list = getRSPoolList();
+       $tagfilter = getTagFilter();
+       $pool_list = getRSPoolList ($tagfilter);
        if ($pool_list === NULL)
        {
                showError ('getRSPoolList() failed', __FUNCTION__);
                return;
        }
+       echo "<table border=0 class=objectview>\n";
+       echo "<tr><td class=pcleft>";
+       startPortlet ('RS pools');
        echo "<table class=widetable border=0 cellpadding=10 cellspacing=0 align=center>\n";
        echo "<tr><th>refcnt</th><th>name</th><th>VS configuration</th><th>RS configuration</th></tr>";
        $order = 'odd';
        foreach ($pool_list as $pool_id => $pool_info)
        {
                echo "<tr valign=top class=row_${order}><td>" . ($pool_info['refcnt'] ? $pool_info['refcnt'] : '&nbsp;') . '</td>';
-               echo "<td><a href='${root}?page=rspool&id=${pool_id}'>";
+               echo "<td><a href='${root}?page=rspool&pool_id=${pool_id}'>";
                echo (empty ($pool_info['name']) ? 'ANONYMOUS' : $pool_info['name']) . '</a></td>';
                echo "<td><pre>${pool_info['vsconfig']}</pre></td>";
                echo "<td><pre>${pool_info['rsconfig']}</pre></td>";
@@ -4167,6 +4355,10 @@ function renderRSPoolList ()
                $order = $nextorder[$order];
        }
        echo "</table>";
+       finishPortlet ();
+       echo '</td><td class=pcright>';
+       renderTagFilterPortlet ($tagfilter, 'ipv4rspool');
+       echo '</td></tr></table>';
 }
 
 function editRSPools ()
@@ -4185,13 +4377,13 @@ function editRSPools ()
                echo "<input type=hidden name=page value=${pageno}>\n";
                echo "<input type=hidden name=tab value=${tabno}>\n";
                echo "<input type=hidden name=op value=upd>\n";
-               echo "<input type=hidden name=id value=${pool_id}>\n";
+               echo "<input type=hidden name=pool_id value=${pool_id}>\n";
                echo "<tr valign=top class=row_${order}><td>";
                if ($pool_info['refcnt'])
                        printImageHREF ('nodelete', 'RS pool is used ' . $pool_info['refcnt'] . ' time(s)');
                else
                {
-                       echo "<a href='${root}process.php?page=${pageno}&tab=${tabno}&op=del&id=${pool_id}'>";
+                       echo "<a href='${root}process.php?page=${pageno}&tab=${tabno}&op=del&pool_id=${pool_id}'>";
                        printImageHREF ('delete', 'delete real server pool');
                        echo '</a>';
                }
@@ -4237,7 +4429,7 @@ function renderRealServerList ()
                        $order = $nextorder[$order];
                        $last_pool_id = $rsinfo['rspool_id'];
                }
-               echo "<tr valign=top class=row_${order}><td><a href='${root}?page=rspool&id=${rsinfo['rspool_id']}'>";
+               echo "<tr valign=top class=row_${order}><td><a href='${root}?page=rspool&pool_id=${rsinfo['rspool_id']}'>";
                echo empty ($pool_list[$rsinfo['rspool_id']]['name']) ? 'ANONYMOUS' : $pool_list[$rsinfo['rspool_id']]['name'];
                echo '</a></td><td align=center>';
                if ($rsinfo['inservice'] == 'yes')
@@ -4286,7 +4478,7 @@ function renderRSPoolRSInServiceForm ($pool_id = 0)
        echo "<input type=hidden name=page value=${pageno}>\n";
        echo "<input type=hidden name=tab value=${tabno}>\n";
        echo "<input type=hidden name=op value=upd>\n";
-       echo "<input type=hidden name=id value=${pool_id}>\n";
+       echo "<input type=hidden name=pool_id value=${pool_id}>\n";
        echo "<input type=hidden name=rscount value=${rscount}>\n";
        echo "<table class=widetable border=0 cellpadding=10 cellspacing=0 align=center>\n";
        echo "<tr><th>RS address</th><th>RS port</th><th>RS configuration</th><th>in service</th></tr>\n";
@@ -4299,8 +4491,9 @@ function renderRSPoolRSInServiceForm ($pool_id = 0)
                echo "</tr>";
                $recno++;
        }
-       echo "<tr><td colspan=4 align=center><input type=submit value=OK tabindex=${recno}></td></tr>";
-       echo "</table>\n</form>";
+       echo "<tr><td colspan=4 align=center>";
+       printImageHREF ('SAVE', 'Save changes', TRUE, $recno);
+       echo "</td></tr></table>\n</form>";
 }
 
 function renderLivePTR ($id = 0)
@@ -4389,7 +4582,7 @@ function renderLivePTR ($id = 0)
                        $cnt_mismatch++;
                }
                echo "><td class='tdleft";
-               if ($addr['reserved'] == 'yes')
+               if ($addr['reserved'] == 'yes' or (isset ($range['addrlist'][$ip]) and count ($range['addrlist'][$ip]['references'])))
                        echo ' trbusy';
                echo "'><a href='${root}?page=ipaddress&ip=${straddr}'>${straddr}</a></td>";
                echo "<td class=tdleft>${addr['name']}</td><td class=tdleft>${ptrname}</td><td>";
@@ -4418,4 +4611,349 @@ function renderLivePTR ($id = 0)
        echo "</td></tr></table>\n";
 }
 
+function renderAutoPortsForm ($object_id = 0)
+{
+       global $root, $pageno, $tabno;
+       if ($object_id <= 0)
+       {
+               showError ('Invalid object_id', __FUNCTION__);
+               return;
+       }
+       $info = getObjectInfo ($object_id);
+       $ptlist = readChapter ('PortType');
+       echo "<table class='widetable' border=0 cellspacing=0 cellpadding=5 align='center'>\n";
+       echo "<caption>The following ports can be quickly added:</caption>";
+       echo "<tr><th>type</th><th>name</th></tr>";
+       foreach (getAutoPorts ($info['objtype_id']) as $autoport)
+               echo "<tr><td>" . $ptlist[$autoport['type']] . "</td><td>${autoport['name']}</td></tr>";
+       echo "<form method=post action='${root}process.php'>\n";
+       echo "<input type=hidden name=page value=${pageno}>\n";
+       echo "<input type=hidden name=tab value=${tabno}>\n";
+       echo "<input type=hidden name=object_id value=${object_id}>\n";
+       echo "<input type=hidden name=op value=generate>\n";
+       echo "<tr><td colspan=2 align=center>";
+       echo "<input type=submit value='Generate'>";
+       echo "</td></tr>";
+       echo "</table>";
+}
+
+function renderTagRowForViewer ($taginfo, $level = 0)
+{
+       echo '<tr><td align=left>';
+       for ($i = 0; $i < $level; $i++)
+               printImageHREF ('spacer');
+       echo $taginfo['tag'];
+       echo "</td></tr>\n";
+       foreach ($taginfo['kids'] as $kid)
+               renderTagRowForViewer ($kid, $level + 1);
+}
+
+function renderTagRowForCloud ($taginfo, $realm, $level = 0)
+{
+       global $root;
+       echo '<tr><td align=left>';
+       for ($i = 0; $i < $level; $i++)
+               printImageHREF ('spacer');
+       echo "<a href='${root}?page=objgroup&group_id=0&tagfilter[]=${taginfo['id']}'>";
+       echo $taginfo['tag'] . '</a>';
+       if (isset ($taginfo['refcnt'][$realm]))
+               echo ' (' . $taginfo['refcnt'][$realm] . ')';
+       echo "</td></tr>\n";
+       foreach ($taginfo['kids'] as $kid)
+               renderTagRowForCloud ($kid, $realm, $level + 1);
+}
+
+function renderTagRowForEditor ($taginfo, $level = 0)
+{
+       global $root, $pageno, $tabno, $taglist;
+       echo '<tr><td>';
+       $nrefs = 0;
+       foreach ($taginfo['refcnt'] as $part)
+               $nrefs += $part;
+       if ($nrefs > 0 or count ($taginfo['kids']) > 0)
+               printImageHREF ('nodelete', "${nrefs} references, " . count ($taginfo['kids']) . ' sub-tags');
+       else
+       {
+               echo "<a href='${root}process.php?page=${pageno}&tab=${tabno}&op=destroyTag&tag_id=${taginfo['id']}'>";
+               printImageHREF ('delete', 'Delete tag');
+               echo "</a>";
+       }
+       echo "</td>\n<td>";
+       echo "<form method=post action='${root}process.php?page=${pageno}&tab=${tabno}&op=updateTag'>";
+       echo "<input type=hidden name=tag_id value=${taginfo['id']}><input type=text name=tag_name ";
+       echo "value='${taginfo['tag']}'></td><td><select name=parent_id>";
+       echo "<option value=0>-- NONE --</option>\n";
+       foreach ($taglist as $tlinfo)
+       {
+               echo "<option value=${tlinfo['id']}" . ($tlinfo['id'] == $taginfo['parent_id'] ? ' selected' : '');
+               echo ">${tlinfo['tag']}</option>";
+       }
+       echo "</select></td><td>";
+       printImageHREF ('save', 'Save changes', TRUE);
+       echo "</form></td></tr>\n";
+       foreach ($taginfo['kids'] as $kid)
+               renderTagRowForEditor ($kid, $level + 1);
+}
+
+function renderTagTree ()
+{
+       global $tagtree;
+       echo '<center><table>';
+       foreach ($tagtree as $taginfo)
+       {
+               echo '<tr>';
+               renderTagRowForViewer ($taginfo);
+               echo "</tr>\n";
+       }
+       echo '</table></center>';
+}
+
+function renderTagCloud ($realm = '')
+{
+       global $taglist, $tagtree;
+       echo '<table>';
+       foreach (getObjectiveTagTree ($tagtree, $realm) as $taginfo)
+       {
+               echo '<tr>';
+               renderTagRowForCloud ($taginfo, $realm);
+               echo "</tr>\n";
+       }
+       echo '</table>';
+}
+
+function renderTagTreeEditor ()
+{
+       global $root, $pageno, $tabno, $taglist, $tagtree;
+       showMessageOrError();
+       echo "<table class=objview border=0 width='100%'><tr><td class=pcleft>";
+       startPortlet ('tag tree');
+       echo "<table cellspacing=0 cellpadding=5 align=center class=widetable>\n";
+       echo "<tr><th>&nbsp;</th><th>tag</th><th>parent</th><th>&nbsp;</th></tr>\n";
+       foreach ($tagtree as $taginfo)
+       {
+               renderTagRowForEditor ($taginfo, TRUE);
+       }
+       echo "<form action='${root}process.php' method=post>";
+       echo "<input type=hidden name=page value='${pageno}'>";
+       echo "<input type=hidden name=tab value='${tabno}'>";
+       echo "<input type=hidden name=op value='createTag'>";
+       echo "<tr><td>";
+       printImageHREF ('grant', 'Create tag', TRUE, 102);
+       echo '</td><td><input type=text name=tag_name tabindex=100></td><td><select name=parent_id tabindex=101>';
+       echo "<option value=0>-- NONE --</option>\n";
+       foreach ($taglist as $taginfo)
+               echo "<option value=${taginfo['id']}>${taginfo['tag']}</option>";
+       echo "</select></td><td>&nbsp;</td></tr>";
+       echo "</form>\n";
+       echo '</table>';
+       finishPortlet();
+
+       echo "</td><td><td class=pcright>";
+
+       startPortlet ('fallen leaves');
+       echo "<table cellspacing=0 cellpadding=5 align=center class=widetable>\n";
+       echo "<tr><th>tag</th><th>parent</th><th>&nbsp;</th></tr>\n";
+       foreach (getOrphanedTags() as $taginfo)
+       {
+               echo '<tr><td>';
+               echo "<form method=post action='${root}process.php?page=${pageno}&tab=${tabno}&op=updateTag'>";
+               echo "<input type=hidden name=tag_id value=${taginfo['id']}>";
+               echo "<input type=hidden name=tag_name value=${taginfo['tag']}>";
+               echo "${taginfo['tag']}</td><td><select name=parent_id>";
+               echo "<option value=0>-- NONE --</option>\n";
+               foreach ($taglist as $tlinfo)
+               {
+                       echo "<option value=${tlinfo['id']}" . ($tlinfo['id'] == $taglist[$taginfo['id']]['parent_id'] ? ' selected' : '');
+                       echo ">${tlinfo['tag']}</option>";
+               }
+               echo "</select></td><td>";
+               printImageHREF ('save', 'Save changes', TRUE);
+               echo "</form></td></tr>\n";
+       }
+       echo '</table>';
+       finishPortlet();
+       echo "</td></tr></table>";
+}
+
+// Output a sequence of OPTION elements, selecting those, which are present on the
+// explicit tags list.
+function renderTagOption ($taginfo, $level = 0)
+{
+       global $expl_tags;
+       $selected = '';
+       foreach ($expl_tags as $etaginfo)
+               if ($taginfo['id'] == $etaginfo['id'])
+               {
+                       $selected = ' selected';
+                       break;
+               }
+       echo '<option value=' . $taginfo['id'] . "${selected}>";
+       for ($i = 0; $i < $level; $i++)
+               echo '-- ';
+       echo $taginfo['tag'] . "</option>\n";
+       foreach ($taginfo['kids'] as $kid)
+               renderTagOption ($kid, $level + 1);
+}
+
+// Idem, but select those, which are shown on the $_REQUEST['tagfiler'] array.
+// Ignore tag ids, which can't be found on the tree.
+function renderTagOptionForFilter ($taginfo, $tagfilter, $realm, $level = 0)
+{
+       echo $level;
+       $selected = '';
+       foreach ($tagfilter as $filter_id)
+               if ($taginfo['id'] == $filter_id)
+               {
+                       $selected = ' selected';
+                       break;
+               }
+       echo '<option value=' . $taginfo['id'] . "${selected}>";
+       for ($i = 0; $i < $level; $i++)
+               echo '-- ';
+       echo $taginfo['tag'] . (isset ($taginfo['refcnt'][$realm]) ? ' (' . $taginfo['refcnt'][$realm] . ')' : '') . "</option>\n";
+       foreach ($taginfo['kids'] as $kid)
+               renderTagOptionForFilter ($kid, $tagfilter, $realm, $level + 1);
+}
+
+function renderObjectTags ($id)
+{
+       renderEntityTags ('object', 'object_id', $id);
+}
+
+function renderIPv4PrefixTags ($id)
+{
+       renderEntityTags ('ipv4net', 'id', $id);
+}
+
+function renderRackTags ($id)
+{
+       renderEntityTags ('rack', 'rack_id', $id);
+}
+
+function renderIPv4VSTags ($id)
+{
+       renderEntityTags ('ip4vs', 'id', $id);
+}
+
+function renderIPv4RSPoolTags ($id)
+{
+       renderEntityTags ('ip4rspool', 'pool_id', $id);
+}
+
+function renderEntityTags ($entity_realm = '', $bypass_name, $entity_id = 0)
+{
+       global $tagtree;
+       if ($entity_realm == '' or $entity_id <= 0)
+       {
+               showError ('Invalid or missing arguments', __FUNCTION__);
+               return;
+       }
+       global $root, $pageno, $tabno;
+       showMessageOrError();
+       startPortlet ('Tag list');
+       echo "<form method=post action='${root}process.php'>\n";
+       echo "<input type=hidden name=page value=${pageno}>\n";
+       echo "<input type=hidden name=tab value=${tabno}>\n";
+       echo "<input type=hidden name=${bypass_name} value=${entity_id}>\n";
+       echo "<input type=hidden name=op value=save>\n";
+       echo '<select name=taglist[] multiple size=' . getConfigVar ('MAXSELSIZE') . '>';
+       foreach ($tagtree as $taginfo)
+               renderTagOption ($taginfo);
+       echo '</select><br>';
+       printImageHREF ('SAVE', 'Save changes', TRUE);
+       echo "</form>\n";
+       finishPortlet();
+}
+
+function printTagTRs ($baseurl = '')
+{
+       global $expl_tags, $impl_tags, $auto_tags;
+       if (getConfigVar ('SHOW_EXPLICIT_TAGS') == 'yes' and count ($expl_tags))
+       {
+               echo "<tr><th width='50%' class=tag_list_th>Explicit tags:</th><td class=tdleft>";
+               echo serializeTags ($expl_tags, $baseurl) . "</td></tr>\n";
+       }
+       if (getConfigVar ('SHOW_IMPLICIT_TAGS') == 'yes' and count ($impl_tags))
+       {
+               echo "<tr><th width='50%' class=tag_list_th>Implicit tags:</th><td class=tdleft>";
+               echo serializeTags ($impl_tags, $baseurl) . "</td></tr>\n";
+       }
+       if (getConfigVar ('SHOW_AUTOMATIC_TAGS') == 'yes' and count ($auto_tags))
+       {
+               echo "<tr><th width='50%' class=tag_list_th>Automatic tags:</th><td class=tdleft>";
+               echo serializeTags ($auto_tags) . "</td></tr>\n";
+       }
+}
+
+// Output a portlet, with currently selected tags and prepare a form for update.
+function renderTagFilterPortlet ($tagfilter, $realm, $bypass_name = '', $bypass_value = '')
+{
+       global $pageno, $tabno, $taglist, $tagtree;
+       $objectivetags = getObjectiveTagTree ($tagtree, $realm);
+       startPortlet ('Tag filter');
+       if (!count ($objectivetags))
+       {
+               echo "None defined for current realm.<br>";
+               return;
+       }
+       echo "<form method=get>\n";
+       echo "<input type=hidden name=page value=${pageno}>\n";
+       echo "<input type=hidden name=tab value=${tabno}>\n";
+       if ($bypass_name != '')
+               echo "<input type=hidden name=${bypass_name} value='${bypass_value}'>\n";
+       echo '<select name=tagfilter[] multiple>';
+       foreach ($objectivetags as $taginfo)
+               renderTagOptionForFilter ($taginfo, $tagfilter, $realm);
+       echo '</select><br>';
+       echo "<input type=submit value='Apply'></form>\n";
+       finishPortlet();
+}
+
+// Dump all tags in a single SELECT element.
+function renderTagSelect ()
+{
+       global $taglist, $tagtree;
+       if (!count ($taglist))
+       {
+               echo "No tags defined";
+               return;
+       }
+       echo '<select name=taglist[] multiple>';
+       foreach ($tagtree as $taginfo)
+               renderTagOption ($taginfo);
+       echo '</select><br>';
+}
+
+function renderTagRollerForRow ()
+{
+       dragon();
+}
+
+function renderObjectSLB ()
+{
+       dragon();
+}
+
+function renderEditRSPool ()
+{
+       dragon();
+}
+
+function renderEditVService ()
+{
+       dragon();
+}
+
+function renderEditLBsForVService ()
+{
+       dragon();
+}
+
+function dump ($var)
+{
+       echo '<pre>';
+       print_r ($var);
+       echo '</pre>';
+}
+
 ?>