r3310 renderObjectVLANSync(): added some improvements to the form
authorDenis Ovsienko <infrastation@yandex.ru>
Tue, 2 Mar 2010 15:38:42 +0000 (15:38 +0000)
committerDenis Ovsienko <infrastation@yandex.ru>
Tue, 2 Mar 2010 15:38:42 +0000 (15:38 +0000)
processVLANSyncRequest(): initial implementation

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

index c0877c0..38870b3 100644 (file)
@@ -1522,7 +1522,7 @@ function showMessageOrError ()
                                176 => array ('code' => 'error', 'format' => 'This network already exists'),
                                177 => array ('code' => 'error', 'format' => 'commitUpdateRack() failed'),
                                178 => array ('code' => 'error', 'format' => 'file not found'),
-                               179 => array ('code' => 'error', 'format' => 'Declining outdated text. Re-edit the file for consistency.'),
+                               179 => array ('code' => 'error', 'format' => 'Expired form has been declined.'),
                                180 => array ('code' => 'error', 'format' => 'Error saving file, all changes lost!'),
                                181 => array ('code' => 'error', 'format' => "file uploads not allowed, change 'file_uploads' parameter in php.ini"),
                                182 => array ('code' => 'error', 'format' => 'SQL query failed: %s'),
@@ -6718,7 +6718,7 @@ function renderPortVLANConfig ($port_id, $object_id, $allowed, $native)
                printImageHREF ('CLEAR gray');
        else
        {
-               printOpFormIntro ('savePortVLANConfig', array ('port_id' => $port_id));
+               printOpFormIntro ('savePortVLANConfig', array ('port_id' => $port_id, 'mutex_rev' => $vswitch['mutex_rev']));
                printImageHREF ('CLEAR', 'Unassign all VLANs', TRUE);
                echo '</form>';
        }
@@ -6887,18 +6887,21 @@ function renderObjectVLANSync ($object_id)
                                $radio['right'] = FALSE;
                }
                echo "<tr class=row_${order}><td>${port['port_name']}</td>";
-               echo "<td>${desired_cfgstring}</td>";
+               echo "<td><label for=i_${port_id}_left>${desired_cfgstring}</label></td>";
                foreach ($radio as $pos => $enabled)
                {
                        echo '<td>';
                        if (!$enabled)
                                echo '&nbsp;';
                        else
-                               echo "<input name=radio_${port_id} type=radio value=${pos}" . $checked[$pos] . ">";
+                               echo "<input id=i_${port_id}_${pos} name=i_${port_id} type=radio value=${pos}" . $checked[$pos] . ">";
                        echo '</td>';
                }
-               echo "<td>${running_cfgstring}</td>";
+               echo "<td><label for=i_${port_id}_right>${running_cfgstring}</label></td>";
                echo '</tr>';
+               echo "<input type=hidden name=rn_${port_id} value=${port['running_native']}>";
+               foreach ($port['running_allowed'] as $a)
+                       echo "<input type=hidden name=ra_${port_id}[] value=${a}>";
                $order = $nextorder[$order];
        }
        echo '<tr><td colspan=6 align=center>';
index b5e6cc3..8339630 100644 (file)
@@ -150,6 +150,7 @@ $ophandler['object']['snmpportfinder']['querySNMPData'] = 'querySNMPData';
 $ophandler['object']['vlanconfig']['bind'] = 'addVLANSwitchBinding';
 $ophandler['object']['vlanconfig']['unbind'] = 'delVLANSwitchBinding';
 $ophandler['object']['vlanports']['savePortVLANConfig'] = 'savePortVLANConfig';
+$ophandler['object']['vlansync']['sync'] = 'processVLANSyncRequest';
 $delayauth['object']['livevlans']['setPortVLAN'] = TRUE;
 
 $page['ipv4space']['title'] = 'IPv4 space';
index afbfc87..6e07bc3 100644 (file)
@@ -2212,4 +2212,49 @@ function unbindVLANfromIPv4 ()
        return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR');
 }
 
+$msgcode['processVLANSyncRequest']['OK'] = 63;
+$msgcode['processVLANSyncRequest']['ERR'] = 179;
+function processVLANSyncRequest ()
+{
+       global $sic;
+       assertUIntArg ('mutex_rev');
+       // Divide submitted radio buttons into 4 groups:
+       // left (produce and send commands to switch)
+       // asis (ignore)
+       // right (fetch config from switch and save into database)
+       $object = spotEntity ('object', $_REQUEST['object_id']);
+       $allowed = getAllowedVLANsForObjectPorts ($sic['object_id']);
+       $from_running = array();
+       foreach ($allowed as $port_id => $vlanlist)
+       {
+               if (!array_key_exists ("i_${port_id}", $sic))
+                       continue;
+               switch ($sic["i_${port_id}"])
+               {
+               case 'left':
+                       // FIXME: queue sub-task of DB->switch request
+                       break;
+               case 'right':
+                       $from_running[] = array
+                       (
+                               'port_id' => $port_id,
+                               'allowed' => $sic["ra_${port_id}"],
+                               'native' => $sic["rn_${port_id}"],
+                       );
+                       break;
+               default:
+                       // don't care
+               }
+       }
+       try
+       {
+               setSwitchVLANConfig ($sic['object_id'], $sic['mutex_rev'], $from_running);
+       }
+       catch (Exception $e)
+       {
+               buildRedirectURL (__FUNCTION__, 'ERR');
+       }
+       return buildRedirectURL (__FUNCTION__, 'OK', array (count ($from_running)));
+}
+
 ?>