r2973 - maintenance->trunk sync of changeset:2938
authorDenis Ovsienko <infrastation@yandex.ru>
Mon, 20 Jul 2009 16:45:09 +0000 (16:45 +0000)
committerDenis Ovsienko <infrastation@yandex.ru>
Mon, 20 Jul 2009 16:45:09 +0000 (16:45 +0000)
inc/database.php
inc/interface.php

index 5a9c9c1376f4ab5bbb81869331b0b8315cc09022..e29a0d0c9f3fdff836fd5699626c84b88cdf477d 100644 (file)
@@ -1657,6 +1657,25 @@ function getObjectAttrsSearchResults ($what)
        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.
@@ -1719,25 +1738,24 @@ function getPortSearchResults ($what)
        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)
+// search in port "reservation comment" column
+function getPortRsvSearchResults ($what)
 {
-       $stickers = getSearchResultByField
+       $ports = getSearchResultByField
        (
-               'AttributeValue',
-               array ('object_id', 'attr_id'),
-               'string_value',
+               'Port',
+               array ('object_id', 'id'),
+               'reservation_comment',
                $what,
                'object_id',
-               1
+               0
        );
-       $map = getAttrMap();
        $ret = array();
-       foreach ($stickers as $sticker)
-               if ($map[$sticker['attr_id']]['type'] == 'string')
-                       $ret[] = $sticker;
+       foreach ($ports as $port)
+       {
+               $ret[$port['object_id']]['id'] = $port['object_id'];
+               $ret[$port['object_id']]['by_portrsv'][] = $port['id'];
+       }
        return $ret;
 }
 
index a733f960e85507b2fb46f50bd8d0c997f02d671a..4816f313f3a68f10ad5d534b35634485aee27ebf 100644 (file)
@@ -2767,6 +2767,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))
                {
@@ -2844,6 +2851,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':
@@ -2926,6 +2934,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>';