Checking options parameter for combos
[fa-stable.git] / includes / ui / ui_input.inc
index 753fc3d94745b8190a02a05f4b4e6d101e77b3a5..b775ede018e5b8ae68d83ae3f734f3e812043bc3 100644 (file)
@@ -32,24 +32,58 @@ function find_submit($prefix, $numeric=true)
     }
     return $numeric ? -1 : null;
 }
+//------------------------------------------------------------------------------
+//
+// Helper function for simple db table editor pages
+//
+function simple_page_mode($numeric_id = true)
+{
+       global $Ajax, $Mode, $selected_id;
+
+       $default = $numeric_id ? -1 : '';
+       $selected_id = get_post('selected_id', $default);
+       foreach (array('ADD_ITEM', 'UPDATE_ITEM', 'RESET') as $m) {
+               if (isset($_POST[$m])) {
+                       $Ajax->activate('_page_body');
+                       if ($m == 'RESET') 
+                               $selected_id = $default;
+                       $Mode = $m; return;
+               }
+       }
+       foreach (array('Edit', 'Delete') as $m) {
+               foreach ($_POST as $p => $pvar) {
+                       if (strpos($p, $m) === 0) {
+                               $selected_id = substr($p, strlen($m));
+                               $Ajax->activate('_page_body');
+                               $Mode = $m;
+                               return;
+                       }
+               }
+       }
+       $Mode = '';
+}
 
 //------------------------------------------------------------------------------
 //
 //     Read numeric value from user formatted input
 //
-function input_num($postname=null)
+function input_num($postname=null, $dflt=null)
 {
        if (!isset($_POST[$postname]))
-               return null;
+               return $dflt;
 
     return user_numeric($_POST[$postname]);
 }
 
 //---------------------------------------------------------------------------------
 
-function hidden($name, $value, $echo=true)
+function hidden($name, $value=null, $echo=true)
 {
        global $Ajax;
+       
+       if ($value === null) 
+               $value = get_post($name);
+       
        $ret = "<input type=\"hidden\" name=\"$name\" value=\"$value\">";
        $Ajax->addUpdate($name, $name, $value);
        if ($echo)
@@ -59,13 +93,21 @@ function hidden($name, $value, $echo=true)
 }
 
 //---------------------------------------------------------------------------------
-
+//     Submit button.
+//     $async parameter can have 3 values:
+//             false - normal submit via form action
+//             true  - when js is on submition via ajax call
+//             null - fallback button not visible in js enabled mode
+//
 function submit($name, $value, $echo=true, $title=false, $async=false)
 {
+
        default_focus($name);
        $submit_str = "<input type=\"submit\" class=\""
            .($async ? 'ajaxsubmit' : 'inputsubmit')
-           ."\" name=\"$name\"  id=\"$name\" value=\"$value\""
+               ."\""
+               .($async === null ? (in_ajax() ? " style='display:none;'" : ' fallback="1"' ): '')
+           ." name=\"$name\"  id=\"$name\" value=\"$value\""
            .($title ? " title='$title'" : '')
            .">\n";
        if ($echo)
@@ -98,9 +140,11 @@ function submit_center_last($name, $value, $title=false, $async=false)
 function submit_add_or_update($add=true, $title=false, $async=false)
 {
        if ($add)
-               submit('ADD_ITEM', _("Save"), true, $title, $async);
-       else
+               submit('ADD_ITEM', _("Add new"), true, $title, $async);
+       else {
                submit('UPDATE_ITEM', _("Update"), true, $title, $async);
+               submit('RESET', _("Cancel"), true, $title, $async);
+       }
 }
 
 function submit_add_or_update_center($add=true, $title=false, $async=false)
@@ -140,7 +184,7 @@ function submit_row($name, $value, $right=true, $extra="", $title=false, $async=
        echo "<tr>";
        if ($right)
                echo "<td>&nbsp;</td>\n";
-       submit_cells($name, $value, $extra, $title);
+       submit_cells($name, $value, $extra, $title, $async);
        echo "</tr>\n";
 }
 //---------------------------------------------------------------------------------
@@ -169,7 +213,7 @@ function check_value($name)
        return 1;
 }
 
-function check($label, $name, $value, $submit_on_change=false, $title=false)
+function check($label, $name, $value=null, $submit_on_change=false, $title=false)
 {
        global $Ajax;
 
@@ -177,13 +221,13 @@ function check($label, $name, $value, $submit_on_change=false, $title=false)
        if ($label)
                echo $label . "  ";
 
-       if ($value == null)
-               $value = (!isset($_POST[$name]) ? 0 : $_POST[$name]);
+       if ($value === null)
+               $value = get_post($name,0);
 
                echo "<input"
                    .($value == 1 ? ' checked':'')
                    ." type='checkbox' name='$name' value='1'"
-                   .($submit_on_change ? " onclick='this.form.submit();'" : '')
+                   .($submit_on_change ? " onclick='JsHttpRequest.request(\"_{$name}_update\", this.form);'" : '')
                    .($title ? " title='$title'" : '')
                    ." >\n";
        $Ajax->addUpdate($name, $name, $value);
@@ -270,7 +314,7 @@ function label_row($label, $value, $params="", $params2="", $leftfill=0)
 
 //-----------------------------------------------------------------------------------
 
-function text_cells($label, $name, $value, $size="", $max="", $title=false, $params="", $post_label="", $disabled="")
+function text_cells($label, $name, $value=null, $size="", $max="", $title=false, $params="", $post_label="", $disabled="")
 {
        global $Ajax;
 
@@ -279,8 +323,8 @@ function text_cells($label, $name, $value, $size="", $max="", $title=false, $par
                label_cell($label, $params);
        echo "<td>";
 
-       if ($value == null)
-               $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
+       if ($value === null)
+               $value = get_post($name);
        echo "<input $disabled type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" value=\"$value\""
            .($title ? " title='$title'" : '')
            .">";
@@ -406,7 +450,7 @@ function percent_row($label, $name, $init=null)
 
        if (!isset($_POST[$name]) || $_POST[$name]=="")
        {
-               $_POST[$name] = $init== null ? '' : $init;
+               $_POST[$name] = $init == null ? '' : $init;
        }
 
        small_amount_row($label, $name, $_POST[$name], null, "%", user_percent_dec());
@@ -420,7 +464,7 @@ function amount_cells_ex($label, $name, $size, $max=null, $init=null, $params=nu
                $dec = user_price_dec();
        if (!isset($_POST[$name]) || $_POST[$name] == "")
        {
-               if ($init)
+               if ($init !== null)
                        $_POST[$name] = $init;
                else
                        $_POST[$name] = '';
@@ -440,6 +484,7 @@ function amount_cells_ex($label, $name, $size, $max=null, $init=null, $params=nu
 
        echo "</td>\n";
        $Ajax->addUpdate($name, $name, $_POST[$name]);
+       $Ajax->addAssign($name, $name, 'dec', $dec);
 }