r3975 Merging of #3968:
authorAlexey Andriyanov <alan@al-an.info>
Tue, 19 Oct 2010 04:47:14 +0000 (04:47 +0000)
committerAlexey Andriyanov <alan@al-an.info>
Tue, 19 Oct 2010 04:47:14 +0000 (04:47 +0000)
Links added for displaying object lists filtered by dictionary keys.
Links added to object view tab and chapter view page.

ChangeLog
inc/database.php
inc/interface.php

index e0dc748..fa6de88 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -18,6 +18,7 @@
        new feature: {$attr_X_Y} autotags (by Alexey Andrianov)
        new feature: action "reset object" deleting it's non-hardware properties (Boris Lytochkin)
        new feature: LLDP neighbour support on Cisco IOS switches (by Boris Lytochkin)
+       new feature: Links added for displaying object lists filtered by dictionary keys (Alexey Andrianov)
        bugfix: fixed an issue with LiveCDP remote device names of Nexus switches
        update: users could set MAX_UNFILTERED_ENTITIES cfg var to suppress display of entire entity sets before filters are applied (Alexey Andrianov)
        update: objects' ports are now sorted by module numbers in all tabs
index a33e497..a618c20 100644 (file)
@@ -3995,4 +3995,12 @@ function lookupEntityByString ($realm, $value, $column = 'name')
        return $rows[0]['id'];
 }
 
+// returns an array of attribute_id`s wich use specified chapter id.  
+function getChapterAttributes($chapter_id)
+{
+       $prepared = usePreparedSelectBlade ('SELECT DISTINCT attr_id FROM AttributeMap WHERE chapter_id = ?', array ($chapter_id));
+       $rows = $prepared->fetchAll (PDO::FETCH_COLUMN);
+       return is_array($rows) ? $rows : array();
+}
+
 ?>
index c454aca..8270d14 100644 (file)
@@ -948,9 +948,13 @@ function renderRackObject ($object_id)
                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) as $attr_id => $record)
                if (strlen ($record['value']))
-                       echo "<tr><th width='50%' class=sticker>${record['name']}:</th><td class=sticker>${record['a_value']}</td></tr>\n";
+               {
+                       echo "<tr><th width='50%' class=sticker>${record['name']}:</th><td class=sticker>" .
+                               formatAttributeValue($attr_id, $record) .
+                               "</td></tr>\n";
+               }
        printTagTRs
        (
                $info,
@@ -3174,13 +3178,9 @@ function renderSearchResults ()
                                                        $aval = getAttrValues ($obj['id']);
                                                        foreach ($obj['by_sticker'] as $attr_id)
                                                        {
-                                                               $record = array
-                                                               (
-                                                                       'name' => $aval[$attr_id]['name'],
-                                                                       'a_value' => $aval[$attr_id]['a_value']
-                                                               );
+                                                               $record = $aval[$attr_id];
                                                                echo "<tr><th width='50%' class=sticker>${record['name']}:</th>";
-                                                               echo "<td class=sticker>${record['a_value']}</td></tr>";
+                                                               echo "<td class=sticker>" . formatAttributeValue($attr_id, $record) . "</td></tr>";
                                                        }
                                                        echo '</table>';
                                                }
@@ -3563,6 +3563,7 @@ function renderChapter ($tgt_chapter_no)
                return;
        }
        $refcnt = getChapterRefc ($tgt_chapter_no, array_keys ($words));
+       $attrs = getChapterAttributes($tgt_chapter_no);
        echo "<br><table class=cooltable border=0 cellpadding=5 cellspacing=0 align=center>\n";
        echo "<tr><th colspan=3>${wc} record(s)</th></tr>\n";
        echo "<tr><th>Origin</th><th>Refcnt</th><th>Word</th></tr>\n";
@@ -3573,7 +3574,32 @@ function renderChapter ($tgt_chapter_no)
                printImageHREF (($key <= $max_dict_key[CODE_VERSION]) ? 'computer' : 'favorite');
                echo '</td><td>';
                if ($refcnt[$key])
-                       echo $refcnt[$key];
+               {
+                       $cfe = '';
+                       foreach ($attrs as $attr_id)
+                       {
+                               if (! empty($cfe))
+                                       $cfe .= ' or ';
+                               $cfe .= '{$attr_' . $attr_id . '_' . $key . '}';
+                       }
+                       
+                       if (! empty($cfe))
+                       {
+                               $href = makeHref
+                               (
+                                       array
+                                       (
+                                               'page'=>'depot',
+                                               'tab'=>'default',
+                                               'andor' => 'and',
+                                               'cfe' => $cfe
+                                       )
+                               );
+                               echo '<a href="' . $href . '">' . $refcnt[$key] . '</a>';
+                       }
+                       else
+                               echo $refcnt[$key];
+               }
                echo "</td><td><div title='key=${key}'>${value}</div></td></tr>\n";
                $order = $nextorder[$order];
        }
@@ -8112,4 +8138,20 @@ function renderDiscoveredNeighbors ($object_id)
        echo '</table></form>';
 }
 
+function formatAttributeValue($attribute_id, $record)
+{
+       if (isset ($record['key'])) // if record is a dictionary value, generate href with autotag in cfe
+               $href = makeHref
+               (
+                       array
+                       (
+                               'page'=>'depot',
+                               'tab'=>'default',
+                               'andor' => 'and',
+                               'cfe' => '{$attr_' . $attribute_id . '_' . $record['key'] . '}',
+                       )
+               );
+       return isset($href) ? "<a href=\"$href\">${record['a_value']}</a>" : $record['a_value'];        
+}
+
 ?>