}
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 = strtr(substr($p, strlen($m)), array('%2E'=>'.'));
+ unset($_POST['_focus']); // focus on first form entry
+ $selected_id = quoted_printable_decode(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)
}
//---------------------------------------------------------------------------------
-
+// Submit button.
+// $async parameter can have 3 values:
+// null - fallback button not visible in js enabled mode
+// false - normal submit via form action
+// true - when js is on submition via ajax call
+// 'process' - ditto with processing indicator in msgbox
+//
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;'" : ' aspect="fallback"' ):
+ ($async === 'process' ? 'aspect="process"' : '') )
+ ." name=\"$name\" id=\"$name\" value=\"$value\""
.($title ? " title='$title'" : '')
.">\n";
if ($echo)
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)
echo "<tr>";
if ($right)
echo "<td> </td>\n";
- submit_cells($name, $value, $extra, $title);
+ submit_cells($name, $value, $extra, $title, $async);
echo "</tr>\n";
}
//---------------------------------------------------------------------------------
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;
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);
else
label_cell(percent_format($label), "nowrap align=right", $id);
}
-
+// 2008-06-15. Changed
function qty_cell($label, $bold=false, $dec=null, $id=null)
{
+ if ($dec == null)
+ $dec = get_qty_dec();
if ($bold)
- label_cell("<b>".qty_format($label, $dec)."</b>", "nowrap align=right", $id);
+ label_cell("<b>".number_format2($label, $dec)."</b>", "nowrap align=right", $id);
else
- label_cell(qty_format($label, $dec), "nowrap align=right", $id);
+ label_cell(number_format2($label, $dec), "nowrap align=right", $id);
}
function label_cells($label, $value, $params="", $params2="")
//-----------------------------------------------------------------------------------
-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;
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'" : '')
.">";
$Ajax->addUpdate($name, $name, $value);
}
-function text_cells_ex($label, $name, $size, $max=null, $init=null, $title=null, $params=null, $post_label=null)
+function text_cells_ex($label, $name, $size, $max=null, $init=null, $title=null, $params=null, $post_label=null, $submit_on_change=false)
{
global $Ajax;
$max = $size;
echo "<td>";
-
- echo "<input type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" value=\"" . $_POST[$name]. "\""
+ $class = $submit_on_change ? 'class="searchbox"' : '';
+ echo "<input $class type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" value=\"" . $_POST[$name]. "\""
.($title ? " title='$title'": '')." >";
if ($post_label)
$_POST[$name] = $init;
}
if ($use_date_picker)
- $post_label = "<a tabindex='-1' href=\"javascript:date_picker(document.forms[0].$name);\">"
+ $post_label = "<a tabindex='-1' href=\"javascript:date_picker(document.getElementsByName('$name')[0]);\">"
. " <img src='$path_to_root/themes/default/images/cal.gif' width='16' height='16' border='0' alt='"._('Click Here to Pick up the date')."'></a>\n";
else
$post_label = "";
//-----------------------------------------------------------------------------------
-function ref_cells($label, $name, $title=null, $init=null, $params=null)
+function ref_cells($label, $name, $title=null, $init=null, $params=null, $submit_on_change=false)
{
- text_cells_ex($label, $name, 16, 18, $init, $title, $params);
+ text_cells_ex($label, $name, 16, 18, $init, $title, $params, null, $submit_on_change);
}
//-----------------------------------------------------------------------------------
-function ref_row($label, $name, $title=null, $init=null)
+function ref_row($label, $name, $title=null, $init=null, $submit_on_change=false)
{
echo "<tr>";
- ref_cells($label, $name, $title, $init);
+ ref_cells($label, $name, $title, $init, null, $submit_on_change);
echo "</tr>\n";
}
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());
$dec = user_price_dec();
if (!isset($_POST[$name]) || $_POST[$name] == "")
{
- if ($init)
+ if ($init !== null)
$_POST[$name] = $init;
else
$_POST[$name] = '';
echo "</td>\n";
$Ajax->addUpdate($name, $name, $_POST[$name]);
+ $Ajax->addAssign($name, $name, 'dec', $dec);
}