r3033 - maintenance->trunk sync of changeset:3024
authorDenis Ovsienko <infrastation@yandex.ru>
Tue, 4 Aug 2009 09:39:28 +0000 (09:39 +0000)
committerDenis Ovsienko <infrastation@yandex.ru>
Tue, 4 Aug 2009 09:39:28 +0000 (09:39 +0000)
inc/database.php
inc/interface.php

index e6c7d24e9808afa09ae262ad5964ee9ee90b274e..a6398b5d3003fb636d0b4bf5f060ed2349483e40 100644 (file)
@@ -125,6 +125,18 @@ $SQLSchema = array
        ),
 );
 
+$searchfunc = array
+(
+       'object' => array
+       (
+               'by_sticker' => 'getStickerSearchResults',
+               'by_port' => 'getPortSearchResults',
+               'by_attr' => 'getObjectAttrsSearchResults',
+               'by_iface' => 'getObjectIfacesSearchResults',
+               'by_nat' => 'getObjectNATSearchResults',
+       ),
+);
+
 function isInnoDBSupported ($dbh = FALSE) {
        global $dbxlink;
 
@@ -1598,31 +1610,13 @@ function getSearchResultByField ($tname, $rcolumns, $scolumn, $terms, $ocolumn =
 function getObjectSearchResults ($what)
 {
        $ret = array();
-       foreach (getStickerSearchResults ($what) as $objRecord)
-       {
-               $ret[$objRecord['id']]['id'] = $objRecord['id'];
-               $ret[$objRecord['id']]['by_sticker'] = $objRecord['by_sticker'];
-       }
-       foreach (getPortSearchResults ($what) as $objRecord)
-       {
-               $ret[$objRecord['id']]['id'] = $objRecord['id'];
-               $ret[$objRecord['id']]['by_port'] = $objRecord['by_port'];
-       }
-       foreach (getObjectAttrsSearchResults ($what) as $objRecord)
-       {
-               $ret[$objRecord['id']]['id'] = $objRecord['id'];
-               $ret[$objRecord['id']]['by_attr'] = $objRecord['by_attr'];
-       }
-       foreach (getObjectIfacesSearchResults ($what) as $objRecord)
-       {
-               $ret[$objRecord['id']]['id'] = $objRecord['id'];
-               $ret[$objRecord['id']]['by_iface'] = $objRecord['by_iface'];
-       }
-       foreach (getObjectNATSearchResults ($what) as $objRecord)
-       {
-               $ret[$objRecord['id']]['id'] = $objRecord['id'];
-               $ret[$objRecord['id']]['by_nat'] = $objRecord['by_nat'];
-       }
+       global $searchfunc;
+       foreach ($searchfunc['object'] as $method => $func)
+               foreach ($func ($what) as $objRecord)
+               {
+                       $ret[$objRecord['id']]['id'] = $objRecord['id'];
+                       $ret[$objRecord['id']][$method] = $objRecord[$method];
+               }
        return $ret;
 }
 
@@ -1679,7 +1673,7 @@ function getPortSearchResults ($what)
        $ports = getSearchResultByField
        (
                'Port',
-               array ('object_id', 'id'),
+               array ('object_id', 'id', 'reservation_comment'),
                'reservation_comment',
                $what,
                'object_id',
@@ -1689,14 +1683,14 @@ function getPortSearchResults ($what)
        foreach ($ports as $port)
        {
                $ret[$port['object_id']]['id'] = $port['object_id'];
-               $ret[$port['object_id']]['by_port'][] = $port['id'];
+               $ret[$port['object_id']]['by_port'][$port['id']] = $port['reservation_comment'];
        }
        if (NULL === ($db_l2address = l2addressForDatabase ($what)))
                return $ret;
        $ports = getSearchResultByField
        (
                'Port',
-               array ('object_id', 'id'),
+               array ('object_id', 'id', 'l2address'),
                'l2address',
                $db_l2address,
                'object_id',
@@ -1705,7 +1699,7 @@ function getPortSearchResults ($what)
        foreach ($ports as $port)
        {
                $ret[$port['object_id']]['id'] = $port['object_id'];
-               $ret[$port['object_id']]['by_port'][] = $port['id'];
+               $ret[$port['object_id']]['by_port'][$port['id']] = $port['l2address'];
        }
        return $ret;
 }
index 8130aa108a76f8357e183d727ba2e0166e825400..bdc934513e1e99582eb670cfbc2141915d8ceafa 100644 (file)
@@ -2855,7 +2855,11 @@ function renderSearchResults ()
                                echo "';//</script>";
                                break;
                        case 'object':
-                               echo "<script language='Javascript'>document.location='${root}?page=object&object_id=${record['id']}';//</script>";
+                               if (isset ($record['by_port']) and 1 == count ($record['by_port']))
+                                       $hl = '&hl_port_id=' . key ($record['by_port']);
+                               else
+                                       $hl = '';
+                               echo "<script language='Javascript'>document.location='${root}?page=object&object_id=${record['id']}${hl}';//</script>";
                                break;
                        case 'ipv4rspool':
                                echo "<script language='Javascript'>document.location='${root}?page=ipv4rspool&pool_id=${record['id']}';//</script>";
@@ -2921,12 +2925,12 @@ function renderSearchResults ()
                                                {
                                                        echo '<table>';
                                                        $ports = getObjectPortsAndLinks ($obj['id']);
-                                                       foreach ($obj['by_port'] as $port_id)
+                                                       foreach ($obj['by_port'] as $port_id => $text)
                                                                foreach ($ports as $port)
                                                                        if ($port['id'] == $port_id)
                                                                        {
-                                                                               echo "<tr><td>port ${port['name']} (${port['type']} ${port['l2address']}):</td>";
-                                                                               echo "<td class=tdleft>${port['reservation_comment']}</td></tr>";
+                                                                               echo "<tr><td>port ${port['name']}:</td>";
+                                                                               echo "<td class=tdleft>${text}</td></tr>";
                                                                                break; // next reason
                                                                        }
                                                        echo '</table>';