r1788 + printSelect(): detect and render option groups, if appropriate
authorDenis Ovsienko <infrastation@yandex.ru>
Mon, 17 Mar 2008 22:44:10 +0000 (22:44 +0000)
committerDenis Ovsienko <infrastation@yandex.ru>
Mon, 17 Mar 2008 22:44:10 +0000 (22:44 +0000)
ChangeLog
inc/interface.php

index 1b81fbb033438c874d1c4192af37c0fac5bc484b..2fa194b3ab35ee15acfe60500e7bc2ecc16b442f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,7 @@
 0.14.13
        new feature: SSV format for RS import
        new feature: complex VLAN IDs in switchvlans gateway
+       new feature: automatic option groups
        update: added Force10, NETGEAR, D-Link and Extreme Networks switches,
                Raisecom MUXes, updated Cisco routers
        update: async port type has been split
index 24a19aabf90f4d4955c9c001a79b54320d480fa6..9c5a4294a2eaaeaccce76699cff2e3a77558fc20 100644 (file)
@@ -511,13 +511,57 @@ function renderEditRackForm ($rack_id)
 // This is a helper for creators and editors.
 function printSelect ($rowList, $select_name, $selected_id = 1)
 {
-       echo "<select name=${select_name}>";
+       // First collect all data for OPTGROUPs, then ouput it and dump
+       // the rest of records as is.
+       $optgroup = array();
+       $other = array();
        foreach ($rowList as $dict_key => $dict_value)
        {
-               echo "<option value=${dict_key}";
-               if ($dict_key == $selected_id)
-                       echo ' selected';
-               echo ">${dict_value}</option>";
+               if (strpos ($dict_value, '|') !== FALSE)
+               {
+                       $tmp = explode ('|', $dict_value, 2);
+                       $optgroup[$tmp[0]][$dict_key] = $tmp[1];
+               }
+               else
+                       $other[$dict_key] = $dict_value;
+       }
+       echo "<select name=${select_name}>";
+       if (!count ($optgroup))
+       {
+               foreach ($other as $dict_key => $dict_value)
+               {
+                       echo "<option value=${dict_key}";
+                       if ($dict_key == $selected_id)
+                               echo ' selected';
+                       echo ">${dict_value}</option>";
+               }
+       }
+       else
+       {
+               foreach ($optgroup as $groupname => $groupdata)
+               {
+                       echo "<optgroup label='${groupname}'>";
+                       foreach ($groupdata as $dict_key => $dict_value)
+                       {
+                               echo "<option value=${dict_key}";
+                               if ($dict_key == $selected_id)
+                                       echo ' selected';
+                               echo ">${dict_value}</option>";
+                       }
+                       echo "</optgroup>\n";
+               }
+               if (count ($other))
+               {
+                       echo "<optgroup label='other'>\n";
+                       foreach ($other as $dict_key => $dict_value)
+                       {
+                               echo "<option value=${dict_key}";
+                               if ($dict_key == $selected_id)
+                                       echo ' selected';
+                               echo ">${dict_value}</option>";
+                       }
+                       echo "</optgroup>\n";
+               }
        }
        echo "</select>";
 }