r1244 Attached is a patch which lets you edit config options.
authorDenis Yeldandi <dyeldandi@gmail.com>
Thu, 1 Nov 2007 09:33:23 +0000 (09:33 +0000)
committerDenis Yeldandi <dyeldandi@gmail.com>
Thu, 1 Nov 2007 09:33:23 +0000 (09:33 +0000)
By Aaron Dummer <aaron@dummer.info>

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

index da37cb3..c51708a 100644 (file)
@@ -1760,6 +1760,25 @@ function commitUseupPort ($port_id = 0)
        
 }
 
+function commitUpdateUI ($varname, $vartype, $emptyok, $varvalue, $description)
+{
+       if (empty ($varname) || empty ($vartype) || empty ($emptyok) || empty ($varvalue)|| empty ($description))
+       {
+               showError ('Not all required args to commitUpdateUI() are present.');
+               return FALSE;
+       }
+       global $dbxlink;
+       $query = "UPDATE Config SET vartype='${vartype}', emptyok='${emptyok}', varvalue='${varvalue}', description='${description}' " .
+                       "WHERE varname='${varname}'";
+       $result = $dbxlink->query ($query);
+       if ($result->rowCount() != 1)
+       {
+               showError ('Error updating config in commitUpdateUI()');
+               return FALSE;
+       }
+       return TRUE;
+}
+
 // This is a swiss-knife blade to insert a record into a table.
 // The first argument is table name.
 // The second argument is an array of "name" => "value" pairs.
@@ -1802,7 +1821,7 @@ function useDeleteBlade ($tablename, $keyname, $keyvalue, $quotekey = TRUE)
 function loadConfigCache ()
 {
        global $dbxlink;
-       $query = 'select varname, varvalue, vartype, is_hidden, emptyok, description from Config';
+       $query = 'SELECT varname, varvalue, vartype, is_hidden, emptyok, description FROM Config ORDER BY varname';
        $result = $dbxlink->query ($query);
        if ($result == NULL)
        {
index c2f2832..8981585 100644 (file)
@@ -2863,20 +2863,87 @@ function renderReportSummary ()
 
 function renderUIConfig ()
 {
-       global $configCache;
+       global $configCache, $nextorder;
+       showMessageOrError();
        startPortlet ('Current configuration');
-       echo '<table border=0 class=cooltable align=center>';
-       echo '<tr><th>name</th><th>type</th><th>Ok&nbsp;if&nbsp;empty?</th><th>value</th></tr>';
+       echo '<table class=cooltable border=0 cellpadding=5 cellspacing=0 align=center>';
+       echo '<tr><th class=tdleft>Name</th><th class=tdleft>Type</th><th class=tdleft>Ok<br>if<br>empty?</th><th class=tdleft>Value</th><th class=tdleft>Description</th></tr>';
+       $order = 'odd';
        foreach ($configCache as $v)
+       {
                if ($v['is_hidden'] == 'no')
-                       echo
-                               '<tr><td class=tdleft>' . $v['varname'] . '</td><td class=tdleft>' . $v['vartype'] .
-                               '</td><td class=tdleft>' . $v['emptyok'] . '</td><td class=tdleft>' .
-                               $v['varvalue'] . '</td></tr>';
+               {
+                       echo "<tr class=row_${order}>";
+                       echo "<td class=tdleft>${v['varname']}</td>";
+                       echo "<td class=tdleft>${v['vartype']}</td>";
+                       echo "<td class=tdleft>${v['emptyok']}</td>"; 
+                       echo "<td class=tdleft>${v['varvalue']}</td>";
+                       echo "<td class=tdleft>${v['description']}</td></tr>\n";
+                       $order = $nextorder[$order];
+               }
+       }
        echo "</table>\n";
        finishPortlet();
 }
 
+function renderUIConfigEditForm ()
+{
+       global $root, $configCache;
+       showMessageOrError();
+       startPortlet ('Current configuration');
+       echo "<table cellspacing=0 cellpadding=5 align=center class=widetable>\n";
+       echo "<tr><th class=tdleft>Name</th>";
+       echo "<th class=tdleft>Type</th>";
+       echo "<th class=tdleft>Ok<br>if<br>empty?</th>";
+       echo "<th class=tdleft>Value</th>";
+       echo "<th class=tdleft>Description</th></tr>\n";
+       echo "<form action='${root}process.php'>";
+       echo "<input type=hidden name=op value='upd'>";
+       echo "<input type=hidden name=page value='ui'>\n";
+       echo "<input type=hidden name=tab value='edit'>\n";
+
+       $i = 0;
+       foreach ($configCache as $v)
+       {
+               if ($v['is_hidden'] == 'no')
+               {
+                       echo "<input type=hidden name=${i}_varname value='${v['varname']}'>";
+                       echo "<tr><td class=tdleft>${v['varname']}</td>";
+
+                       echo "<td class=tdleft><select name=${i}_vartype>";
+                       echo "<option value=string";
+                       if ($v['vartype'] == 'string')
+                               echo " selected";
+                       echo ">string</option>";
+                       echo "<option value=uint";
+                       if ($v['vartype'] == 'uint')
+                               echo " selected";
+                       echo ">uint</option>";
+                       echo "</select></td>";
+
+                       echo "<td class=tdleft><select name=${i}_emptyok>";
+                       echo "<option value=no";
+                       if ($v['emptyok'] == 'no')
+                               echo " selected";
+                       echo ">no</option>";
+                       echo "<option value=yes";
+                       if ($v['emptyok'] == 'yes')
+                               echo " selected";
+                       echo ">yes</option>";
+                       echo "</select></td>";
+                       
+                       echo "<td><input type=text name=${i}_varvalue value='${v['varvalue']}' size=24></td>";
+                       echo "<td><input type=text name=${i}_description value='${v['description']}' size=64></td>";
+                       echo "</tr>\n";
+                       $i++;
+               }
+       }
+       echo "<input type=hidden name=num_vars value=${i}>\n";
+       echo "<tr><td colspan=5><input type=submit value='Save changes'></td></tr>";
+       echo "</form>";
+       finishPortlet();
+}
+
 // This function queries the gateway about current VLAN configuration and
 // renders a form suitable for submit. Ah, and it does submit processing as well.
 function renderVLANMembership ($object_id = 0)
index cbadcd5..6f26cda 100644 (file)
@@ -181,7 +181,8 @@ $page['ui']['title'] = 'static_title';
 $page['ui']['handler'] = 'handler_ui';
 $page['ui']['parent'] = 'config';
 $tab['ui']['default'] = 'View';
-$tab['ui']['edit'] = '[ Change ]';
+$tab['ui']['edit'] = 'Change';
+$ophandler['ui']['edit']['upd'] = 'updateUI';
 
 $page['reports']['title'] = 'static_title';
 $page['reports']['handler'] = 'handler_reports';
index 6bf2bed..7232803 100644 (file)
@@ -909,4 +909,43 @@ function updateVLANMembership ()
 
 }
 
+function updateUI ()
+{
+       global $root;
+       $oldvalues = loadConfigCache();
+
+       assertUIntArg ('num_vars');
+       $num_vars = $_REQUEST['num_vars'];
+       $result = array();
+
+       for ($i = 0; $i < $num_vars; $i++)
+       {
+               assertStringArg ("${i}_varname");
+               assertStringArg ("${i}_vartype");
+               assertStringArg ("${i}_emptyok");
+               assertStringArg ("${i}_varvalue");
+               assertStringArg ("${i}_description");
+               $varname = $_REQUEST["${i}_varname"];
+               $vartype = $_REQUEST["${i}_vartype"];
+               $emptyok = $_REQUEST["${i}_emptyok"];
+               $varvalue = $_REQUEST["${i}_varvalue"];
+               $description = $_REQUEST["${i}_description"];
+
+               // If form values = values in DB, don't bother updating DB
+               if ($oldvalues[$varname]['vartype'] == $vartype && 
+                       $oldvalues[$varname]['emptyok'] == $emptyok && 
+                       $oldvalues[$varname]['varvalue'] == $varvalue && 
+                       $oldvalues[$varname]['description'] == $description)
+                       continue;
+
+               // Note if the queries succeed or not, it determines which page they see.
+               $result[] = commitUpdateUI ($varname, $vartype, $emptyok, $varvalue, $description);
+       }
+
+       if (in_array(false, $result))
+               return "${root}?page=ui&tab=default&error=" . urlencode ("Update failed!");
+
+       return "${root}?page=ui&tab=default&message=" . urlencode ("Update succeeded.");
+}
+
 ?>
index 4700816..d1861b8 100644 (file)
@@ -282,6 +282,9 @@ function handler_ui ($tabno)
                case 'default':
                        renderUIConfig();
                        break;
+               case 'edit':
+                       renderUIConfigEditForm();
+                       break;
                default:
                        showError ("Invalid tab '${tabno}' requested in handler_ui().");
        }