r2941 - maintenance->trunk sync of changeset 2938
authorDenis Ovsienko <infrastation@yandex.ru>
Mon, 13 Jul 2009 09:53:31 +0000 (09:53 +0000)
committerDenis Ovsienko <infrastation@yandex.ru>
Mon, 13 Jul 2009 09:53:31 +0000 (09:53 +0000)
ChangeLog
inc/database.php
inc/interface.php

index 331e1beb979286a08db1e867fd4dd16c57779129..42b516fe91fcef0c5bb43da21a0c91442831c2e5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,7 @@
        new feature: configure default SNMP community (by jthurman)
        new feature: "$untagged" and "$masklen_OP_NN" autotags
        new feature: knight button in IPv4 tree
+       new feature: searching by attribute value or port reservation comment
        update: show appropriate message, if a record cannot be found
        update: add Cisco dictionary entry for WS-CBS3030-DEL. closes ticket 225 (by jthurman)
        update: add OS, router, fibre switch dictionary entries for ticket 238 (by Aaron)
index f2e19b145dd87f90d8934a13130dc87efce30b98..b27626d859939b0b819d00dfffdab72a9c8d58c1 100644 (file)
@@ -1620,6 +1620,71 @@ function getSearchResultByField ($tname, $rcolumns, $scolumn, $terms, $ocolumn =
        return $ret;
 }
 
+// This function will eventually merge the functionality of the "older"
+// searching function. Both ones are used at the moment, and they do
+// search in different value spaces.
+function getObjectSearchResults_new ($what)
+{
+       $ret = array();
+       foreach (getStickerSearchResults ($what) as $objRecord)
+       {
+               $ret[$objRecord['id']]['id'] = $objRecord['id'];
+               $ret[$objRecord['id']]['by_sticker'] = $objRecord['by_sticker'];
+       }
+       foreach (getPortRsvSearchResults ($what) as $objRecord)
+       {
+               $ret[$objRecord['id']]['id'] = $objRecord['id'];
+               $ret[$objRecord['id']]['by_portrsv'] = $objRecord['by_portrsv'];
+       }
+       return $ret;
+}
+
+// Look for EXACT value in stickers and return a list of pairs "object_id-attribute_id",
+// which matched. A partilar object_id could be returned more, than once, if it has
+// multiple matching stickers. Search is only performed on "string" attributes.
+function getStickerSearchResults ($what, $exactness = 0)
+{
+       $stickers = getSearchResultByField
+       (
+               'AttributeValue',
+               array ('object_id', 'attr_id'),
+               'string_value',
+               $what,
+               'object_id',
+               $exactness
+       );
+       $map = getAttrMap();
+       $ret = array();
+       foreach ($stickers as $sticker)
+               if ($map[$sticker['attr_id']]['type'] == 'string')
+               {
+                       $ret[$sticker['object_id']]['id'] = $sticker['object_id'];
+                       $ret[$sticker['object_id']]['by_sticker'][] = $sticker['attr_id'];
+               }
+       return $ret;
+}
+
+// search in port "reservation comment" column
+function getPortRsvSearchResults ($what)
+{
+       $ports = getSearchResultByField
+       (
+               'Port',
+               array ('object_id', 'id'),
+               'reservation_comment',
+               $what,
+               'object_id',
+               0
+       );
+       $ret = array();
+       foreach ($ports as $port)
+       {
+               $ret[$port['object_id']]['id'] = $port['object_id'];
+               $ret[$port['object_id']]['by_portrsv'][] = $port['id'];
+       }
+       return $ret;
+}
+
 // This function returns either port ID or NULL for specified arguments.
 function getPortID ($object_id, $port_name)
 {
index fce6b421e0ef1755ec8a3e521d78db8c9fc5f077..3ef9b873b1bd0d1d11cd0e8ed56e792e19ba8f27 100644 (file)
@@ -2769,6 +2769,13 @@ function renderSearchResults ()
                        $lasthit = 'object';
                        $summary['object'] = $tmp;
                }
+               $tmp = getObjectSearchResults_new ($terms);
+               if (count ($tmp))
+               {
+                       $nhits += count ($tmp);
+                       $lasthit = 'object_new';
+                       $summary['object_new'] = $tmp;
+               }
                $tmp = getIPv4AddressSearchResult ($terms);
                if (count ($tmp))
                {
@@ -2851,6 +2858,7 @@ function renderSearchResults ()
                                echo "';//</script>";
                                break;
                        case 'object':
+                       case 'object_new':
                                echo "<script language='Javascript'>document.location='${root}?page=object&object_id=${record['id']}';//</script>";
                                break;
                        case 'ipv4rspool':
@@ -2892,6 +2900,51 @@ function renderSearchResults ()
                                        echo '</table>';
                                        finishPortlet();
                                        break;
+                               case 'object_new':
+                                       startPortlet ("<a href='${root}?page=depot'>Objects (continued)</a>");
+                                       echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
+                                       echo '<tr><th>what</th><th>why</th></tr>';
+                                       foreach ($what as $obj)
+                                       {
+                                               echo "<tr class=row_${order} valign=top><td>";
+                                               renderCell (spotEntity ('object', $obj['id']));
+                                               echo "</td><td>";
+                                               if (isset ($obj['by_sticker']))
+                                               {
+                                                       echo '<table>';
+                                                       $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']
+                                                               );
+                                                               echo "<tr><th width='50%' class=sticker>${record['name']}:</th>";
+                                                               echo "<td class=sticker>${record['a_value']}</td></tr>";
+                                                       }
+                                                       echo '</table>';
+                                               }
+                                               if (isset ($obj['by_portrsv']))
+                                               {
+                                                       echo '<table>';
+                                                       $ports = getObjectPortsAndLinks ($obj['id']);
+                                                       foreach ($obj['by_portrsv'] as $port_id)
+                                                               foreach ($ports as $port)
+                                                                       if ($port['id'] == $port_id)
+                                                                       {
+                                                                               echo "<tr><td>port ${port['name']} (${port['type']}):</td>";
+                                                                               echo "<td class=tdleft>${port['reservation_comment']}</td></tr>";
+                                                                               break; // next reason
+                                                                       }
+                                                       echo '</table>';
+                                               }
+                                               echo "</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>';