r4080 genericAssertion(): add "string0" assertion case
authorDenis Ovsienko <infrastation@yandex.ru>
Fri, 7 Jan 2011 15:52:50 +0000 (15:52 +0000)
committerDenis Ovsienko <infrastation@yandex.ru>
Fri, 7 Jan 2011 15:52:50 +0000 (15:52 +0000)
tableHandler(): make "table_colname" optional; perform NULL value cast on request
addVLANDescription(): dismiss, obsoleted by tableHandler

inc/functions.php
inc/navigation.php
inc/ophandlers.php

index 93c22cc7c5942a51613bc1541c2b2f5c421e3383..aec5d9ca55d50a122c0cde45f104b15e3d5c05fe 100644 (file)
@@ -223,6 +223,9 @@ function genericAssertion ($argname, $argtype)
        case 'string':
                assertStringArg ($argname);
                break;
+       case 'string0':
+               assertStringArg ($argname, TRUE);
+               break;
        case 'uint':
                assertUIntArg ($argname);
                break;
index ead580106f2f1e65aed3dddc49226d96f542863a..cee56c56dc3892e34ec2157aaba6951ae31ab8cb 100644 (file)
@@ -38,7 +38,7 @@ $ophandler['rackspace']['edit']['addRow'] = array
        'action' => 'INSERT',
        'arglist' => array
        (
-               array ('url_argname' => 'name', 'table_colname' => 'name', 'assertion' => 'string')
+               array ('url_argname' => 'name', 'assertion' => 'string')
        ),
 );
 
@@ -595,9 +595,20 @@ $tabhandler['vlandomain']['8021qorder'] = 'render8021QOrderForm';
 $tabhandler['vlandomain']['vlanlist'] = 'renderVLANDomainVLANList';
 $ophandler['vlandomain']['8021qorder']['add'] = 'add8021QOrder';
 $ophandler['vlandomain']['8021qorder']['del'] = 'del8021QOrder';
-$ophandler['vlandomain']['vlanlist']['add'] = 'addVLANDescription';
 $ophandler['vlandomain']['vlanlist']['del'] = 'delVLANDescription';
 $ophandler['vlandomain']['vlanlist']['upd'] = 'updVLANDescription';
+$ophandler['vlandomain']['vlanlist']['add'] = array
+(
+       'table' => 'VLANDescription',
+       'action' => 'INSERT',
+       'arglist' => array
+       (
+               array ('url_argname' => 'vdom_id', 'table_colname' => 'domain_id', 'assertion' => 'uint'),
+               array ('url_argname' => 'vlan_id', 'assertion' => 'uint'),
+               array ('url_argname' => 'vlan_type', 'assertion' => 'string'), // ENUM actually
+               array ('url_argname' => 'vlan_descr', 'assertion' => 'string0', 'if_empty' => 'NULL'),
+       ),
+);
 
 $page['vlan']['parent'] = 'vlandomain';
 $page['vlan']['bypass'] = 'vlan_ck';
index 8786dfd0baffdfecda20813a5fbef982eeed7177..5e9a8fe66b4f44a8a8978b74ddc6c15d9185a390 100644 (file)
@@ -2252,31 +2252,6 @@ function del8021QOrder ()
        return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR', array(), NULL, NULL, $focus_hints);
 }
 
-$msgcode['addVLANDescription']['OK'] = 48;
-$msgcode['addVLANDescription']['ERR1'] = 190;
-$msgcode['addVLANDescription']['ERR2'] = 110;
-function addVLANDescription ()
-{
-       assertUIntArg ('vlan_id');
-       assertStringArg ('vlan_type', TRUE);
-       assertStringArg ('vlan_descr', TRUE);
-       global $sic;
-       if (!($sic['vlan_id'] >= VLAN_MIN_ID + 1 and $sic['vlan_id'] <= VLAN_MAX_ID))
-               return buildRedirectURL (__FUNCTION__, 'ERR1', array ($sic['vlan_id']));
-       $result = usePreparedInsertBlade
-       (
-               'VLANDescription',
-               array
-               (
-                       'domain_id' => $sic['vdom_id'],
-                       'vlan_id' => $sic['vlan_id'],
-                       'vlan_type' => $sic['vlan_type'],
-                       'vlan_descr' => mb_strlen ($sic['vlan_descr']) ? $sic['vlan_descr'] : NULL
-               )
-       );
-       return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR2');
-}
-
 $msgcode['delVLANDescription']['OK'] = 49;
 $msgcode['delVLANDescription']['ERR1'] = 105;
 $msgcode['delVLANDescription']['ERR2'] = 111;
@@ -2833,7 +2808,31 @@ function tableHandler ($opspec)
        foreach ($opspec['arglist'] as $argspec)
        {
                genericAssertion ($argspec['url_argname'], $argspec['assertion']);
-               $columns[$argspec['table_colname']] = $sic[$argspec['url_argname']];
+               // "table_colname" is normally used for an override, if it is not
+               // set, use the URL argument name
+               $table_colname = array_key_exists ('table_colname', $argspec) ?
+                       $argspec['table_colname'] :
+                       $argspec['url_argname'];
+               $arg_value = $sic[$argspec['url_argname']];
+               if
+               (
+                       ($argspec['assertion'] == 'uint0' and $arg_value == 0)
+                       or ($argspec['assertion'] == 'string0' and $arg_value == '')
+               )
+                       switch (TRUE)
+                       {
+                       case !array_key_exists ('if_empty', $argspec): // no action requested
+                               break;
+                       case $argspec['if_empty'] == 'NULL':
+                               $arg_value = NULL;
+                               break;
+// A trick below is likely to break non-INSERT queries.
+//                     case $argspec['if_empty'] == 'omit':
+//                             continue 2;
+                       default:
+                               throw new InvalidArgException ('opspec', '(malformed array structure)', '"if_empty" not recognized');
+                       }
+               $columns[$table_colname] = $arg_value;
        }
        switch ($opspec['action'])
        {