r2674 - bugfix: don't generate warning about {$unmounted} autotag
authorDenis Ovsienko <infrastation@yandex.ru>
Wed, 29 Apr 2009 13:15:38 +0000 (13:15 +0000)
committerDenis Ovsienko <infrastation@yandex.ru>
Wed, 29 Apr 2009 13:15:38 +0000 (13:15 +0000)
 - introduce DEFAULT_FILTER_FORMAT and DEFAULT_FILTER_BOOLOP
 - getCellFilter(): toss code around once more
 - renderCellFilterPortlet(): idem
 - renderIPv4Space(): switch to renderCellFilterPortlet()

inc/code.php
inc/functions.php
inc/interface.php
inc/ophandlers.php
install/init-dictbase.sql
upgrade.php

index 30fba1aa10497cdd7362a3c8e24d1fb9e22c6b8d..06d025c12dbd186963fdecfee2a2e3bde9216cc3 100644 (file)
@@ -1126,6 +1126,7 @@ function findAutoTagWarnings ($expr)
                                case (mb_ereg_match ('^\$typeid_[[:digit:]]+$', $expr['load'])): // FIXME: check value validity
                                case (mb_ereg_match ('^\$cn_.+$', $expr['load'])): // FIXME: check name validity and asset existence
                                case (mb_ereg_match ('^\$lgcn_.+$', $expr['load'])): // FIXME: check name validity
+                               case (mb_ereg_match ('^\$unmounted$', $expr['load'])):
                                        return array();
                                default:
                                        return array (array
index 723bee6562fffc508b2d7c3e01307a2c96e2118f..d1a4fc526f5d4460848a169566cb5e5be8690b00 100644 (file)
@@ -1238,74 +1238,87 @@ function buildCellFilter ()
 
 function getCellFilter ()
 {
-       $boolop = '';
-       if (!isset ($_REQUEST['cfv']) or $_REQUEST['cfv'] == 1 or $_REQUEST['cfv'] == 2)
+       // cfv variable isn't present in URLs generated by RackTables versions
+       // prior to 0.17.0. We treat those URLs as format type 1.
+       if (isset ($_REQUEST['tagfilter']) and is_array ($_REQUEST['tagfilter']))
+               $format = 1;
+       elseif (isset ($_REQUEST['cfv']))
+               $format = $_REQUEST['cfv'];
+       else
+               $format = getConfigVar ('DEFAULT_FILTER_FORMAT');
+       $ret = array
+       (
+               'version' => $format,
+               'text' => '',
+               'expression' => array()
+       );
+       $text = '';
+       switch ($format)
        {
-               $ret = array
-               (
-                       'version' => 1,
-                       'tagidlist' => array(),
-                       'tnamelist' => array(),
-                       'pnamelist' => array(),
-                       'text' => '',
-                       'expression' => array() 
-               );
+       case 1:
+               $boolop = '';
+               $ret['tagidlist'] = array();
+               $ret['tnamelist'] = array();
+               $ret['boolop'] = getConfigVar ('DEFAULT_FILTER_BOOLOP');
                global $taglist;
-               // Both tags and predicates, which don't exist, should be
-               // handled somehow. Discard them silently for now.
                if (isset ($_REQUEST['tagfilter']) and is_array ($_REQUEST['tagfilter']))
                        foreach ($_REQUEST['tagfilter'] as $req_id)
                                if (isset ($taglist[$req_id]))
                                {
                                        $ret['tagidlist'][] = $req_id;
                                        $ret['tnamelist'][] = $taglist[$req_id]['tag'];
-                                       $ret['text'] .= $boolop . '{' . $taglist[$req_id]['tag'] . '}';
-                                       $boolop = ' or ';
+                                       $text .= $boolop . '{' . $taglist[$req_id]['tag'] . '}';
+                                       $boolop = ' ' . $ret['boolop'] . ' ';
                                }
-               if ($_REQUEST['cfv'] == 2)
+               break;
+       case 2:
+               $boolop = '';
+               $ret['tagidlist'] = array();
+               $ret['tnamelist'] = array();
+               $ret['pnamelist'] = array();
+               $ret['boolop'] = getConfigVar ('DEFAULT_FILTER_BOOLOP');
+               global $taglist;
+               // Both tags and predicates, which don't exist, should be
+               // handled somehow. Discard them silently for now.
+               if (isset ($_REQUEST['cft']) and is_array ($_REQUEST['cft']))
+                       foreach ($_REQUEST['cft'] as $req_id)
+                               if (isset ($taglist[$req_id]))
+                               {
+                                       $ret['tagidlist'][] = $req_id;
+                                       $ret['tnamelist'][] = $taglist[$req_id]['tag'];
+                                       $text .= $boolop . '{' . $taglist[$req_id]['tag'] . '}';
+                                       $boolop = ' ' . $ret['boolop'] . ' ';
+                               }
+               if (isset ($_REQUEST['cfp']) and is_array ($_REQUEST['cfp']))
                {
-                       $ret['version'] = 2;
                        global $pTable;
-                       if (isset ($_REQUEST['cfp']) and is_array ($_REQUEST['cfp']))
-                               foreach ($_REQUEST['cfp'] as $req_name)
-                                       if (isset ($pTable[$req_name]))
-                                       {
-                                               $ret['pnamelist'][] = $req_name;
-                                               $ret['text'] .= $boolop . '[' . $req_name . ']';
-                                               $boolop = ' or ';
-                                       }
-               }
-               if (!empty ($ret['text']))
-               {
-                       $parse = spotPayload ($ret['text'], 'SYNT_EXPR');
-                       $ret['expression'] = $parse['load'];
+                       foreach ($_REQUEST['cfp'] as $req_name)
+                               if (isset ($pTable[$req_name]))
+                               {
+                                       $ret['pnamelist'][] = $req_name;
+                                       $text .= $boolop . '[' . $req_name . ']';
+                                       $boolop = ' ' . $ret['boolop'] . ' ';
+                               }
                }
-               return $ret;
+               break;
+       case 3:
+               if (isset ($_REQUEST['cfe']))
+                       $text = $_REQUEST['cfe'];
+               break;
+       default:
+               showError ('Configuration error (filter version number)', __FUNCTION__);
+               return NULL;
        }
-       elseif ($_REQUEST['cfv'] == 3)
+       if (strlen ($text))
        {
-               $ret = array
-               (
-                       'version' => 3,
-                       'text' => '',
-                       'expression' => array() 
-               );
-               if (isset ($_REQUEST['cfe']))
+               $parse = spotPayload ($text, 'SYNT_EXPR');
+               if ($parse['result'] == 'ACK')
                {
-                       $parse = spotPayload ($_REQUEST['cfe'], 'SYNT_EXPR');
-                       if ($parse['result'] == 'ACK')
-                       {
-                               $ret['text'] = $_REQUEST['cfe'];
-                               $ret['expression'] = $parse['load'];
-                       }
+                       $ret['text'] = $text;
+                       $ret['expression'] = $parse['load'];
                }
-               return $ret;
-       }
-       else
-       {
-               showError ('Cannot dispatch cell list filter data', __FUNCTION__);
-               return NULL;
        }
+       return $ret;
 }
 
 function buildWideRedirectURL ($log, $nextpage = NULL, $nexttab = NULL, $moreArgs = array())
index 0e4d6a05746fd6d1e81f93f29ada8894dd74eb68..6b3623d3461cf2a3282461bbed795a02ea9a3a16 100644 (file)
@@ -2093,7 +2093,6 @@ function renderIPv4SpaceRecords ($tree, &$tagcache, $baseurl, $target = 0, $leve
 function renderIPv4Space ()
 {
        global $pageno, $tabno;
-       $tagfilter = getTagFilter();
        $cellfilter = getCellFilter();
        $netlist = filterCellList (listCells ('ipv4net'), $cellfilter['expression']);
        array_walk ($netlist, 'amplifyCell');
@@ -2122,12 +2121,12 @@ function renderIPv4Space ()
                echo "<th>routed by</th>";
        echo "</tr>\n";
        $tagcache = array();
-       $baseurl = makeHref(array('page'=>$pageno, 'tab'=>$tabno)) . getTagFilterStr ($tagfilter);
+       $baseurl = makeHref(array('page'=>$pageno, 'tab'=>$tabno)) . getTagFilterStr (getTagFilter());
        renderIPv4SpaceRecords ($tree, $tagcache, $baseurl, $eid);
        echo "</table>\n";
        finishPortlet();
        echo '</td><td class=pcright>';
-       renderTagFilterPortlet ($tagfilter, 'ipv4net');
+       renderCellFilterPortlet ($cellfilter, 'ipv4net');
        echo "</td></tr></table>\n";
 }
 
@@ -5099,68 +5098,81 @@ function renderTagFilterPortlet ($tagfilter, $realm, $bypass_name = '', $bypass_
 // This one is going to replace the tag filter.
 function renderCellFilterPortlet ($preselect, $realm, $bypass_name = '', $bypass_value = '')
 {
-       $cfv = 2;
+       $cfv = $preselect['version'];
        global $pageno, $tabno, $taglist, $tagtree;
        startPortlet ('filter');
+       echo "<form method=get>\n";
+       echo "<input type=hidden name=page value=${pageno}>\n";
+       echo "<input type=hidden name=tab value=${tabno}>\n";
+       echo "<input type=hidden name=cfv value=${cfv}>\n";
+       if ($bypass_name != '')
+               echo "<input type=hidden name=${bypass_name} value='${bypass_value}'>\n";
+       echo '<table border=0 align=center>';
        switch ($cfv)
        {
        case 1:
-       case 2:
                $objectivetags = getObjectiveTagTree ($tagtree, $realm);
                if (!count ($objectivetags))
                {
                        echo "None used in current realm.<br>";
                        break;
                }
-               echo "<form method=get>\n";
-               echo "<input type=hidden name=page value=${pageno}>\n";
-               echo "<input type=hidden name=tab value=${tabno}>\n";
-               echo "<input type=hidden name=cfv value=${cfv}>\n";
-               if ($bypass_name != '')
-                       echo "<input type=hidden name=${bypass_name} value='${bypass_value}'>\n";
-               echo '<table border=0 align=center>';
-               echo '<tr><td colspan=2>';
                // Show a tree of tags, pre-select according to currently requested list filter.
                foreach ($objectivetags as $taginfo)
                        renderTagCheckbox ('tagfilter', buildTagChainFromIds ($preselect['tagidlist']), $taginfo);
-               if ($cfv == 2)
+               break;
+       case 2:
+               $objectivetags = getObjectiveTagTree ($tagtree, $realm);
+               if (!count ($objectivetags))
+                       echo "<tr><td colspan=2 class='tagbox sparenetwork'>(nothing is tagged yet)</td></tr>";
+               else
+                       foreach ($objectivetags as $taginfo)
+                               renderTagCheckbox ('cft', buildTagChainFromIds ($preselect['tagidlist']), $taginfo);
+               global $pTable;
+               $myPredicates = array();
+               $psieve = getConfigVar ('FILTER_PREDICATE_SIEVE');
+               // Repack matching predicates in a way, which tagOnChain() understands.
+               foreach (array_keys ($pTable) as $pname)
+                       if (mb_ereg_match ($psieve, $pname))
+                               $myPredicates[] = array ('id' => $pname, 'tag' => $pname, 'kids' => array());
+               if (count ($myPredicates))
                {
-                       global $pTable;
-                       $myPredicates = array();
-                       $psieve = getConfigVar ('FILTER_PREDICATE_SIEVE');
-                       // Repack matching predicates in a way, which tagOnChain() understands.
-                       foreach (array_keys ($pTable) as $pname)
-                               if (mb_ereg_match ($psieve, $pname))
-                                       $myPredicates[] = array ('id' => $pname, 'tag' => $pname, 'kids' => array());
-                       if (count ($myPredicates))
-                       {
-                               // Repack preselect likewise.
-                               $myPreselect = array();
-                               foreach ($preselect['pnamelist'] as $pname)
-                                       $myPreselect[] = array ('id' => $pname);
-                               echo '<tr><td colspan=2 class=tagbox><hr></td></tr>';
-                               foreach ($myPredicates as $pinfo)
-                                       renderTagCheckbox ('cfp', $myPreselect, $pinfo);
-                       }
+                       // Repack preselect likewise.
+                       $myPreselect = array();
+                       foreach ($preselect['pnamelist'] as $pname)
+                               $myPreselect[] = array ('id' => $pname);
+                       echo '<tr><td colspan=2 class=tagbox><hr></td></tr>';
+                       foreach ($myPredicates as $pinfo)
+                               renderTagCheckbox ('cfp', $myPreselect, $pinfo);
                }
-               echo '<tr><td colspan=2 class=tagbox><hr></td></tr>';
-               echo '</td></tr><tr><td>';
-               printImageHREF ('apply', 'Apply filter', TRUE);
-               echo "</form></td><td>";
-
-               // "reset"
-               echo "<form method=get>\n";
-               echo "<input type=hidden name=page value=${pageno}>\n";
-               echo "<input type=hidden name=tab value=${tabno}>\n";
-               echo "<input type=hidden name=cfv value=${cfv}>\n";
-               if ($bypass_name != '')
-                       echo "<input type=hidden name=${bypass_name} value='${bypass_value}'>\n";
-               printImageHREF ('clear', 'reset', TRUE);
-               echo '</td></tr></table></form>';
                break;
        case 3:
+               dragon();
+               break;
+       default:
+               showError ('Format version error', __FUNCTION__);
                break;
        }
+       echo "<input type=hidden name=page value=${pageno}>\n";
+       echo "<input type=hidden name=tab value=${tabno}>\n";
+       echo "<input type=hidden name=cfv value=${cfv}>\n";
+       if ($bypass_name != '')
+               echo "<input type=hidden name=${bypass_name} value='${bypass_value}'>\n";
+       echo '<tr><td colspan=2 class=tagbox><hr></td></tr>';
+       // "apply"
+       echo '</td></tr><tr><td>';
+       printImageHREF ('apply', 'Apply filter', TRUE);
+       echo "</form></td><td>";
+
+       // "reset"
+       echo "<form method=get>\n";
+       echo "<input type=hidden name=page value=${pageno}>\n";
+       echo "<input type=hidden name=tab value=${tabno}>\n";
+       echo "<input type=hidden name=cfv value=${cfv}>\n";
+       if ($bypass_name != '')
+               echo "<input type=hidden name=${bypass_name} value='${bypass_value}'>\n";
+       printImageHREF ('clear', 'reset', TRUE);
+       echo '</form></td></tr></table>';
        finishPortlet();
 }
 
index 52136ee35fafb165099cd69a0010d6c46afaaa51..57ac3228207020a3825e10135396b7d0a3c8fa25 100644 (file)
@@ -941,6 +941,8 @@ function resetUIConfig()
        setConfigVar ('NAMEWARN_LISTSRC','{$typeid_4} or {$typeid_7} or {$typeid_8}');
        setConfigVar ('RACKS_PER_ROW','12');
        setConfigVar ('FILTER_PREDICATE_SIEVE','');
+       setConfigVar ('DEFAULT_FILTER_FORMAT','2');
+       setConfigVar ('DEFAULT_FILTER_BOOLOP','or');
        return buildRedirectURL (__FUNCTION__, 'OK');
 }
 
index a9c23ca9f9b770fbe93e46e16e694e24ea4bcc85..1ac72b48a72110dcf0242d46c36c6e817835183a 100644 (file)
@@ -293,6 +293,8 @@ INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, descriptio
 ('NAMEWARN_LISTSRC','{$typeid_4} or {$typeid_7} or {$typeid_8}','string','yes','no','List source: object, for which common name should be set'),
 ('RACKS_PER_ROW','12','unit','yes','no','Racks per row'),
 ('FILTER_PREDICATE_SIEVE','','string','yes','no','Predicate sieve regex(7)'),
+('DEFAULT_FILTER_FORMAT','2','string','no','no','Default list filter format'),
+('DEFAULT_FILTER_BOOLOP','or','string','no','no','Default list filter boolean operation (or/and)'),
 ('DB_VERSION','0.17.0','string','no','yes','Database version.');
 
 INSERT INTO `Script` VALUES ('RackCode','allow {$userid_1}');
index 3242bae8973011b251b73597db830d7f702b77e3..e365f88d2ee3a48e3a3ee573437148001ca60011 100644 (file)
@@ -184,6 +184,8 @@ CREATE TABLE `FileLink` (
                        $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('NAMEWARN_LISTSRC','{$typeid_4} or {$typeid_7} or {$typeid_8}','string','yes','no','List source: object, for which common name should be set')";
                        $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('RACKS_PER_ROW','12','unit','yes','no','Racks per row')";
                        $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('FILTER_PREDICATE_SIEVE','','string','yes','no','Predicate sieve regex(7)')";
+                       $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('DEFAULT_FILTER_FORMAT','2','string','no','no','Default list filter format')')";
+                       $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('DEFAULT_FILTER_BOOLOP','or','string','no','no','Default list filter boolean operation (or/and)')')";
                        $query[] = "delete from Config where varname = 'USER_AUTH_SRC'";
                        $query[] = "delete from Config where varname = 'COOKIE_TTL'";
                        $query[] = "delete from Config where varname = 'rtwidth_0'";