r3299 renderObjectVLANPorts(): rewrite with a new layout
authorDenis Ovsienko <infrastation@yandex.ru>
Sun, 28 Feb 2010 13:13:20 +0000 (13:13 +0000)
committerDenis Ovsienko <infrastation@yandex.ru>
Sun, 28 Feb 2010 13:13:20 +0000 (13:13 +0000)
renderPortVLANConfig(): new function to process both allowed and native records at once
savePortVLANConfig(): idem
commitSaveAllowedVLANs(): dismissed
commitSaveNativeVLAN(): dismissed
renderPortAllowedVLANs(): dismissed
renderPortNativeVLAN(): dismissed
setAllowedVLANs(): dismissed
setNativeVLAN(): dismissed

inc/database.php
inc/interface.php
inc/navigation.php
inc/ophandlers.php

index b9c7d93..2d2b6ef 100644 (file)
@@ -3670,26 +3670,6 @@ function getAllowedVLANsForObjectPorts ($object_id)
        return $ret;
 }
 
-function commitSaveAllowedVLANs ($port_id, $vlan_id_list)
-{
-       global $dbxlink;
-       $dbxlink->beginTransaction();
-       // the below cascades down to PortNativeVLAN
-       if (FALSE === usePreparedDeleteBlade ('PortAllowedVLAN', 'port_id', $port_id))
-       {
-               $dbxlink->rollBack();
-               return FALSE;
-       }
-       foreach ($vlan_id_list as $vlan_id)
-               if (!usePreparedInsertBlade ('PortAllowedVLAN', array ('port_id' => $port_id, 'vlan_id' => $vlan_id)))
-               {
-                       $dbxlink->rollBack();
-                       return FALSE;
-               }
-       $dbxlink->commit();
-       return TRUE;
-}
-
 function getNativeVLANsForObjectPorts ($object_id)
 {
        global $dbxlink;
@@ -3704,25 +3684,6 @@ function getNativeVLANsForObjectPorts ($object_id)
        return $ret;
 }
 
-// When the new native VLAN ID is 0, only delete the old row (if it exists).
-function commitSaveNativeVLAN ($port_id, $vlan_id = 0)
-{
-       global $dbxlink;
-       $dbxlink->beginTransaction();
-       if (FALSE === usePreparedDeleteBlade ('PortNativeVLAN', 'port_id', $port_id))
-       {
-               $dbxlink->rollBack();
-               return FALSE;
-       }
-       if ($vlan_id and !usePreparedInsertBlade ('PortNativeVLAN', array ('port_id' => $port_id, 'vlan_id' => $vlan_id)))
-       {
-               $dbxlink->rollBack();
-               return FALSE;
-       }
-       $dbxlink->commit();
-       return TRUE;
-}
-
 // Replace current port configuration with the provided one. If the new
 // native VLAN ID doesn't belong to the allowed list, don't issue
 // INSERT query, which would always trigger an FK exception.
@@ -3740,6 +3701,7 @@ function setPortVLANConfig ($port_id, $allowed, $native)
        foreach ($allowed as $vlan_id)
                if (!usePreparedInsertBlade ('PortAllowedVLAN', array ('port_id' => $port_id, 'vlan_id' => $vlan_id)))
                        return FALSE;
+       // When the new native VLAN ID is 0, only delete the old row (if it exists).
        if
        (
                $native and
index 5905980..3998e10 100644 (file)
@@ -6594,97 +6594,76 @@ function renderVLANDomainVLANList ($vdom_id)
 // and a form to edits VLANs it runs.
 function renderObjectVLANPorts ($object_id)
 {
-       global $pageno, $tabno;
+       global $pageno, $tabno, $sic;
        $allowed = getAllowedVLANsForObjectPorts ($object_id);
        $native = getNativeVLANsForObjectPorts ($object_id);
-       if (!isset ($_REQUEST['port_id']))
-       {
-               $object = spotEntity ('object', $object_id);
-               amplifyCell ($object);
-               echo '<table cellspacing=0 cellpadding=5 align=center class=widetable>';
-               echo '<tr><th>&nbsp;</th><th>port name</th><th>VLANs</th><th>&nbsp;</th></tr>';
-               foreach ($object['ports'] as $port)
-                       if (array_key_exists ($port['id'], $allowed)) // eligible for 802.1Q
-                       {
-                               echo "<tr><td>&nbsp;";
-                               echo "</td><td><a href='" . makeHref
-                               (
-                                       array
-                                       (
-                                               'page' => $pageno,
-                                               'tab' => $tabno,
-                                               'object_id' => $object_id,
-                                               'port_id' => $port['id'],
-                                       )
-                               );
-                               echo "'>${port['name']}</a></td><td>";
-                               echo serializeVLANPack
+       $object = spotEntity ('object', $object_id);
+       amplifyCell ($object);
+       $port_id = array_key_exists ('port_id', $sic) ? $sic['port_id'] : 0;
+       echo '<table border=1 width="100%"><tr valign=top><td class=tdleft width="30%">';
+       // port list
+       echo '<table cellspacing=0 cellpadding=5 align=center class=widetable>';
+       echo '<tr><th>port name</th><th>current config</th></tr>';
+       foreach ($object['ports'] as $port)
+               if (array_key_exists ($port['id'], $allowed)) // eligible for 802.1Q
+               {
+                       $tdclass = $port['id'] == $port_id ? 'seltagbox' : 'tagbox';
+                       echo "<tr><td class=${tdclass}><a href='" . makeHref
+                       (
+                               array
                                (
-                                       array_key_exists ($port['id'], $native) ? $native[$port['id']] : 0,
-                                       array_key_exists ($port['id'], $allowed) ? $allowed[$port['id']] : array()
-                               );
-                               echo '</td></tr>';
-                       }
-               echo '</table>';
-       }
+                                       'page' => $pageno,
+                                       'tab' => $tabno,
+                                       'object_id' => $object_id,
+                                       'port_id' => $port['id'],
+                               )
+                       );
+                       echo "'>${port['name']}</a></td><td class=${tdclass}>";
+                       echo serializeVLANPack
+                       (
+                               array_key_exists ($port['id'], $native) ? $native[$port['id']] : 0,
+                               array_key_exists ($port['id'], $allowed) ? $allowed[$port['id']] : array()
+                       );
+                       echo '</td></tr>';
+               }
+       echo '</table>';
+       echo '</td>';
+       // configuration of currently selected port, if any
+       if (!$port_id)
+               echo '<td colspan=2>&nbsp;</td>';
        else
        {
-               $port_id = $_REQUEST['port_id'];
-               global $sic;
-               $portinfo = getPortInfo ($sic['port_id']);
+               $portinfo = getPortInfo ($port_id);
                if ($portinfo['object_id'] != $object_id)
                {
                        showError ('Invalid port_id', __FUNCTION__);
                        return;
                }
-               $header = "port '${portinfo['name']}' (<a href='" . makeHref
-               (
-                       array
-                       (
-                               'page' => $pageno,
-                               'tab' => $tabno,
-                               'object_id' => $object_id,
-                       )
-               ) . "'>show all</a>)";
-               $vdom_id = getObjectVLANDomainID ($object_id);
-               $objectdomain = getVLANDomain ($vdom_id);
-               echo '<table border=0 class=objectview cellspacing=0 cellpadding=0>';
-               echo "<tr><td colspan=2 align=center><h1>${header}</h1></td></tr>";
-               echo "<tr valign=top><td class=pcleft width='50%'>";
-               startPortlet ('allowed VLAN(s)');
-               renderPortAllowedVLANs
+               renderPortVLANConfig
                (
                        $port_id,
-                       $objectdomain,
-                       array_key_exists ($port_id, $allowed) ? $allowed[$port_id] : array()
-               );
-               finishPortlet();
-               echo '</td><td>';
-               startPortlet ('native VLAN');
-               renderPortNativeVLAN
-               (
-                       $port_id,
-                       $objectdomain,
+                       getVLANDomain (getObjectVLANDomainID ($object_id)),
                        array_key_exists ($port_id, $allowed) ? $allowed[$port_id] : array(),
                        array_key_exists ($port_id, $native) ? $native[$port_id] : 0
                );
-               finishPortlet();
-               echo '</td></tr></table>';
        }
+       echo '</tr></table>';
 }
 
-function renderPortAllowedVLANs ($port_id, $vdom, $preselect)
+function renderPortVLANConfig ($port_id, $vdom, $allowed, $native)
 {
        if (!count ($vdom['vlanlist']))
        {
-               echo '(no VLANs in assigned domain)';
+               echo '<td colspan=2>(configured VLAN domain is empty)</td>';
                return;
        }
-       printOpFormIntro ('setAllowedVLANs', array ('port_id' => $port_id));
+       printOpFormIntro ('savePortVLANConfig', array ('port_id' => $port_id));
+       echo '<td width="35%">';
        echo '<table border=0 cellspacing=0 cellpadding=3 align=center>';
+       echo '<tr><th colspan=2>allowed</th></tr>';
        foreach ($vdom['vlanlist'] as $vlan_id => $vlan_info)
        {
-               if (in_array ($vlan_id, $preselect))
+               if (in_array ($vlan_id, $allowed))
                {
                        $selected = ' checked';
                        $class = 'seltagbox';
@@ -6695,69 +6674,51 @@ function renderPortAllowedVLANs ($port_id, $vdom, $preselect)
                        $class = 'tagbox';
                }
                echo "<tr><td colspan=2 class=${class}>";
-               echo "<label><input type=checkbox name='vlan_id[]' value='${vlan_id}'${selected}> ";
+               echo "<label><input type=checkbox name='allowed_id[]' value='${vlan_id}'${selected}> ";
                echo formatVLANName ($vlan_info) . "</label></td></tr>";
        }
-       echo '<tr><td class=tdleft>';
-       printImageHREF ('SAVE', 'Save changes', TRUE);
-       echo "</form></td><td class=tdright>";
-       if (!count ($preselect))
-               printImageHREF ('CLEAR gray');
-       else
-       {
-               printOpFormIntro ('setAllowedVLANs', array ('port_id' => $port_id));
-               printImageHREF ('CLEAR', 'Unassign all VLANs', TRUE);
-               echo '</form>';
-       }
-       echo '</td></tr></table>';
-}
-
-function renderPortNativeVLAN ($port_id, $vdom, $allowed = array(), $native = 0)
-{
-       if (!count ($allowed))
-       {
-               echo '(no allowed VLANs for this port)';
-               return;
-       }
-       // There is at least 1 item on the list. "Save" button requires a form,
-       // and only makes sense when there is at least one unchecked button in it.
-       if (count ($allowed) >= ($native ? 2 : 1))
-               printOpFormIntro ('setNativeVLAN', array ('port_id' => $port_id));
+       echo '</table>';
+       echo '</td><td width="35%">';
+       // rightmost table also contains form buttons
        echo '<table border=0 cellspacing=0 cellpadding=3 align=center>';
-       foreach ($allowed as $vlan_id)
+       echo '<tr><th colspan=2>native</th></tr>';
+       if (!count ($allowed))
+               echo '<tr><td colspan=2>(no allowed VLANs for this port)</td></tr>';
+       else
        {
-               if ($vlan_id == $native)
-               {
-                       $selected = ' checked';
-                       $class = 'seltagbox';
-               }
-               else
+               $native_options = array (0 => '-- NONE --');
+               foreach ($allowed as $allowed_id)
+                       $native_options[$allowed_id] = formatVLANName ($vdom['vlanlist'][$allowed_id]);
+               foreach ($native_options as $vlan_id => $vlan_text)
                {
-                       $selected = '';
-                       $class = 'tagbox';
+                       if ($vlan_id == $native)
+                       {
+                               $selected = ' checked';
+                               $class = 'seltagbox';
+                       }
+                       else
+                       {
+                               $selected = '';
+                               $class = 'tagbox';
+                       }
+                       echo "<tr><td colspan=2 class=${class}>";
+                       echo "<label><input type=radio name='native_id' value='${vlan_id}'${selected}> ";
+                       echo $vlan_text . "</label></td></tr>";
                }
-               echo "<tr><td colspan=2 class=${class}>";
-               echo "<label><input type=radio name='vlan_id' value='${vlan_id}'${selected}> ";
-               echo formatVLANName ($vdom['vlanlist'][$vlan_id]) . "</label></td></tr>";
        }
        echo '<tr><td class=tdleft>';
-       if (count ($allowed) >= ($native ? 2 : 1))
-       {
-               printImageHREF ('SAVE', 'Save changes', TRUE);
-               echo '</form>';
-       }
-       else
-               printImageHREF ('NOSAVE', 'nothing to save');
-       echo "</td><td class=tdright>";
-       if (!$native)
+       printImageHREF ('SAVE', 'Save changes', TRUE);
+       echo '</form></td><td class=tdright>';
+       if (!count ($allowed))
                printImageHREF ('CLEAR gray');
        else
        {
-               printOpFormIntro ('setNativeVLAN', array ('port_id' => $port_id, 'vlan_id' => 0));
-               printImageHREF ('CLEAR', 'Reset native VLAN', TRUE);
+               printOpFormIntro ('savePortVLANConfig', array ('port_id' => $port_id));
+               printImageHREF ('CLEAR', 'Unassign all VLANs', TRUE);
                echo '</form>';
        }
        echo '</td></tr></table>';
+       echo '</td>';
 }
 
 function renderVLANInfo ($vlan_ck)
index 2ded6c8..f750c00 100644 (file)
@@ -147,8 +147,7 @@ $ophandler['object']['lvsconfig']['submitSLBConfig'] = 'submitSLBConfig';
 $ophandler['object']['snmpportfinder']['querySNMPData'] = 'querySNMPData';
 $ophandler['object']['vlanconfig']['bind'] = 'addVLANSwitchBinding';
 $ophandler['object']['vlanconfig']['unbind'] = 'delVLANSwitchBinding';
-$ophandler['object']['vlanports']['setAllowedVLANs'] = 'setAllowedVLANs';
-$ophandler['object']['vlanports']['setNativeVLAN'] = 'setNativeVLAN';
+$ophandler['object']['vlanports']['savePortVLANConfig'] = 'savePortVLANConfig';
 $delayauth['object']['livevlans']['setPortVLAN'] = TRUE;
 
 $page['ipv4space']['title'] = 'IPv4 space';
index 95b5db7..08379dd 100644 (file)
@@ -2166,34 +2166,28 @@ function updateVLANDomain ()
        return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR');
 }
 
-$msgcode['setAllowedVLANs']['OK'] = 17;
-$msgcode['setAllowedVLANs']['ERR1'] = 160;
-$msgcode['setAllowedVLANs']['ERR2'] = 109;
-function setAllowedVLANs ()
+$msgcode['savePortVLANConfig']['OK'] = 43;
+$msgcode['savePortVLANConfig']['ERR1'] = 160;
+$msgcode['savePortVLANConfig']['ERR2'] = 109;
+function savePortVLANConfig ()
 {
        assertUIntArg ('port_id');
-       global $sic;
-       $portinfo = getPortInfo ($sic['port_id']);
-       if ($portinfo['object_id'] != $sic['object_id'])
-               return buildRedirectURL (__FUNCTION__, 'ERR1');
-       $vlan_id_list = isset ($sic['vlan_id']) ? $sic['vlan_id'] : array();
-       $result = commitSaveAllowedVLANs ($sic['port_id'], $vlan_id_list);
-       return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR2', array(), NULL, NULL, array ('port_id' => $sic['port_id']));
-}
-
-$msgcode['setNativeVLAN']['OK'] = 43;
-$msgcode['setNativeVLAN']['ERR1'] = 160;
-$msgcode['setNativeVLAN']['ERR2'] = 109;
-function setNativeVLAN ()
-{
-       assertUIntArg ('port_id');
-       global $sic;
+       global $sic, $dbxlink;
        $vlan_id = isset ($sic['vlan_id']) ? $sic['vlan_id'] : 0; // 0 means "reset"
        $portinfo = getPortInfo ($sic['port_id']);
        if ($portinfo['object_id'] != $sic['object_id'])
-               return buildRedirectURL (__FUNCTION__, 'ERR1');
-       $result = commitSaveNativeVLAN ($sic['port_id'], $vlan_id);
-       return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR2', array(), NULL, NULL, array ('port_id' => $sic['port_id']));
+               // should we throw instead?
+               return buildRedirectURL (__FUNCTION__, 'ERR1', array(), NULL, NULL, array ('port_id' => $sic['port_id']));
+       $allowed = isset ($sic['allowed_id']) ? $sic['allowed_id'] : array();
+       $native = isset ($sic['native_id']) ? $sic['native_id'] : 0; // 0 means "reset"
+       $dbxlink->beginTransaction();
+       if (setPortVLANConfig ($sic['port_id'], $allowed, $native))
+       {
+               $dbxlink->commit();
+               return buildRedirectURL (__FUNCTION__, 'OK', array(), NULL, NULL, array ('port_id' => $sic['port_id']));
+       }
+       $dbxlink->rollBack();
+       return buildRedirectURL (__FUNCTION__, 'ERR2', array(), NULL, NULL, array ('port_id' => $sic['port_id']));
 }
 
 $msgcode['bindVLANtoIPv4']['OK'] = 48;