<?php
/**********************************************************************
Copyright (C) FrontAccounting, LLC.
- Released under the terms of the GNU Affero General Public License,
- AGPL, as published by the Free Software Foundation, either version
- 3 of the License, or (at your option) any later version.
+ Released under the terms of the GNU General Public License, GPL,
+ as published by the Free Software Foundation, either version 3
+ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- See the License here <http://www.gnu.org/licenses/agpl-3.0.html>.
+ See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
***********************************************************************/
-
-function get_post($name, $dflt='')
-{
- return ((!isset($_POST[$name]) || $_POST[$name] === '') ? $dflt : $_POST[$name]);
-}
//
// Sets local POST value and adds Value to ajax posting if needed
//
else
return $ret;
}
-
-function submit($name, $value, $echo=true, $title=false, $async=false, $icon=false)
+/*
+ Universal submit form button.
+ $atype - type of submit:
+ Normal submit:
+ false - normal button; optional icon
+ null - button visible only in fallback mode; optional icon
+ Ajax submit:
+ true - standard button; optional icon
+ 'process' - displays progress bar during call; optional icon
+ 'default' - default form submit on Ctrl-Enter press; dflt ICON_OK icon
+ 'cancel' - cancel form entry on Escape press; dflt ICON_CANCEL
+*/
+function submit($name, $value, $echo=true, $title=false, $atype=false, $icon=false)
{
global $path_to_root;
-
+
+ $aspect='';
+ if (!is_bool($atype)) // necessary: switch uses '=='
+ switch($atype) {
+ case 'process':
+ $aspect = " aspect='process'"; break;
+ case 'default':
+ $aspect = " aspect='default'";
+ if ($icon===false) $icon=ICON_SUBMIT; break;
+ case 'cancel':
+ $aspect = " aspect='cancel'";
+ if ($icon===false) $icon=ICON_ESCAPE; break;
+ case null:
+ $aspect = fallback_mode() ?
+ " aspect='fallback'" : " style='display:none;'"; break;
+ }
+
default_focus($name);
$submit_str = "<button class=\""
- .($async ? 'ajaxsubmit' : 'inputsubmit')
+ .($atype ? 'ajaxsubmit' : 'inputsubmit')
."\" type=\"submit\""
- .($async === null ? (fallback_mode() ? ' aspect="fallback"' : " style='display:none;'" ):
- ($async === 'process' ? 'aspect="process"' : '') )
+ .$aspect
." name=\"$name\" id=\"$name\" value=\"$value\""
.($title ? " title='$title'" : '')
- ."><span>$value</span>"
+ .">"
.($icon ? "<img src='$path_to_root/themes/".user_theme()."/images/$icon'>" : '')
+ ."<span>$value</span>"
."</button>\n";
if ($echo)
echo $submit_str;
submit($name, $value, true, $title, $async, $icon);
echo "</center>";
}
-
+/*
+ For following controls:
+ 'both' - use both Ctrl-Enter and Escape hotkeys
+ 'cancel' - apply to 'RESET' button
+*/
function submit_add_or_update($add=true, $title=false, $async=false)
{
+ $cancel = $async;
+
+ if ($async === 'both') {
+ $async = 'default'; $cancel = 'cancel';
+ }
+ else if ($async === 'default')
+ $cancel = true;
+ else if ($async === 'cancel')
+ $async = true;
+
if ($add)
submit('ADD_ITEM', _("Add new"), true, $title, $async);
else {
submit('UPDATE_ITEM', _("Update"), true, $title, $async);
- submit('RESET', _("Cancel"), true, $title, $async);
+ submit('RESET', _("Cancel"), true, $title, $cancel);
}
}
echo "</center>";
}
-/*
-function submit_add_or_update_row($add=true)
-{
- echo "<tr><td colspan=99 align=center>";
- submit_add_or_update($add);
- echo "</td></tr>\n";
-}
-*/
function submit_add_or_update_row($add=true, $right=true, $extra="", $title=false, $async=false)
{
echo "<tr>";
submit($name, $value, true, $title, $async);
}
}
+
+function submit_js_confirm($name, $msg) {
+ add_js_source(
+ "_validate.$name=function(){ return confirm('$msg');};");
+};
//-----------------------------------------------------------------------------------
function set_icon($icon, $title=false)
function button_cell($name, $value, $title=false, $icon=false)
{
- echo "<td>";
+ echo "<td align='center'>";
echo button($name, $value, $title, $icon);
echo "</td>";
}
echo checkbox($label, $name, $value, $submit_on_change, $title);
}
-function check_cells($label, $name, $value, $submit_on_change=false, $title=false)
+function check_cells($label, $name, $value, $submit_on_change=false, $title=false,
+ $params='')
{
if ($label != null)
echo "<td>$label</td>\n";
- echo "<td>";
+ echo "<td $params>";
echo check(null, $name, $value, $submit_on_change, $title);
echo "</td>";
}
//-----------------------------------------------------------------------------------
-function text_cells($label, $name, $value=null, $size="", $max="", $title=false, $params="", $post_label="", $disabled="")
+function text_cells($label, $name, $value=null, $size="", $max="", $title=false,
+ $labparams="", $post_label="", $inparams="")
{
global $Ajax;
default_focus($name);
if ($label != null)
- label_cell($label, $params);
+ label_cell($label, $labparams);
echo "<td>";
if ($value === null)
$value = get_post($name);
- echo "<input $disabled type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$max\" value=\"$value\""
+ echo "<input $inparams 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, $submit_on_change=false)
+function text_cells_ex($label, $name, $size, $max=null, $init=null, $title=null,
+ $labparams=null, $post_label=null, $submit_on_change=false)
{
global $Ajax;
$_POST[$name] = "";
}
if ($label != null)
- label_cell($label, $params);
+ label_cell($label, $labparams);
if (!isset($max))
$max = $size;
//-----------------------------------------------------------------------------------
function email_row($label, $name, $value, $size, $max, $title=null, $params="", $post_label="")
{
- text_row("<a href='Mailto:".$_POST[$name]."'>$label</a>", $name, $value, $size, $max, $title, $params, $post_label);
+ if (get_post($name))
+ $label = "<a href='Mailto:".$_POST[$name]."'>$label</a>";
+ text_row($label, $name, $value, $size, $max, $title, $params, $post_label);
}
function email_row_ex($label, $name, $size, $max=null, $title=null, $value=null, $params=null, $post_label=null)
{
- text_row_ex("<a href='Mailto:".$_POST[$name]."'>$label</a>", $name, $size, $max, $title, $value, $params, $post_label);
+ if (get_post($name))
+ $label = "<a href='Mailto:".$_POST[$name]."'>$label</a>";
+ text_row_ex($label, $name, $size, $max, $title, $value, $params, $post_label);
}
function link_row($label, $name, $value, $size, $max, $title=null, $params="", $post_label="")
{
- text_row("<a href='".$_POST[$name]."' target='_blank'>$label</a>", $name, $value, $size, $max, $title, $params, $post_label);
+ $val = get_post($name);
+ if ($val) {
+ if (strpos($val,'http://')===false)
+ $val = 'http://'.$val;
+ $label = "<a href='$val' target='_blank'>$label</a>";
+ }
+ text_row($label, $name, $value, $size, $max, $title, $params, $post_label);
}
function link_row_ex($label, $name, $size, $max=null, $title=null, $value=null, $params=null, $post_label=null)
{
- text_row_ex("<a href='".$_POST[$name]."' target='_blank'>$label</a>", $name, $size, $max, $title, $value, $params, $post_label);
+ $val = get_post($name);
+ if ($val) {
+ if (strpos($val,'http://')===false)
+ $val = 'http://'.$val;
+ $label = "<a href='$val' target='_blank'>$label</a>";
+ }
+ text_row_ex($label, $name, $size, $max, $title, $value, $params, $post_label);
}
//-----------------------------------------------------------------------------------
-
-function date_cells($label, $name, $title = null, $init=null, $inc_days=0,
+//
+// Since FA 2.2 $init parameter is superseded by $check.
+// When $check!=null current date is displayed in red when set to other
+// than current date.
+//
+function date_cells($label, $name, $title = null, $check=null, $inc_days=0,
$inc_months=0, $inc_years=0, $params=null, $submit_on_change=false)
{
- global $use_date_picker, $path_to_root;
+ global $use_date_picker, $path_to_root, $Ajax;
+
if (!isset($_POST[$name]) || $_POST[$name] == "")
{
- if (!$init)
+ if ($inc_years == 1001)
+ $_POST[$name] = null;
+ else
{
- if ($inc_years == 1001)
- $_POST[$name] = null;
- else
- {
- $dd = Today();
- if ($inc_days != 0)
- $dd = add_days($dd, $inc_days);
- if ($inc_months != 0)
- $dd = add_months($dd, $inc_months);
- if ($inc_years != 0)
- $dd = add_years($dd, $inc_years);
- $_POST[$name] = $dd;
- }
+ $dd = Today();
+ if ($inc_days != 0)
+ $dd = add_days($dd, $inc_days);
+ if ($inc_months != 0)
+ $dd = add_months($dd, $inc_months);
+ if ($inc_years != 0)
+ $dd = add_years($dd, $inc_years);
+ $_POST[$name] = $dd;
}
- else
- $_POST[$name] = $init;
}
if ($use_date_picker)
$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 = "";
- text_cells_ex($label, $name, 9, 12, $_POST[$name], $title, $params, $post_label, $submit_on_change);
+
+ if ($label != null)
+ label_cell($label, $params);
+
+ echo "<td>";
+
+ $class = $submit_on_change ? 'class="searchbox"' : '';
+
+ $aspect = $check ? 'aspect="cdate"' : '';
+ if ($check && (get_post($name) != Today()))
+ $aspect .= ' style="color:#FF0000"';
+
+ echo "<input type=\"text\" name=\"$name\" $class $aspect size=\"9\" maxlength=\"12\" value=\""
+ . $_POST[$name]. "\""
+ .($title ? " title='$title'": '')." > $post_label";
+ echo "</td>\n";
+ $Ajax->addUpdate($name, $name, $_POST[$name]);
}
-function date_row($label, $name, $title=null, $init=null, $inc_days=0, $inc_months=0,
+function date_row($label, $name, $title=null, $check=null, $inc_days=0, $inc_months=0,
$inc_years=0, $params=null, $submit_on_change=false)
{
echo "<tr>";
- date_cells($label, $name, $title, $init, $inc_days, $inc_months,
+ date_cells($label, $name, $title, $check, $inc_days, $inc_months,
$inc_years, $params, $submit_on_change);
echo "</tr>\n";
}
}
*/
//-----------------------------------------------------------------------------------
+//
+// When show_inactive page option is set
+// displays value of inactive field as checkbox cell.
+// Also updates database record after status change.
+//
+function inactive_control_cell($id, $value, $table, $key)
+{
+ global $Ajax;
+ $name = "Inactive". $id;
+ $value = $value ? 1:0;
+ if (check_value('show_inactive')) {
+ if (isset($_POST['LInact'][$id]) && (get_post('_Inactive'.$id.'_update') ||
+ get_post('Update')) && (check_value('Inactive'.$id) != $value)) {
+ update_record_status($id, !$value, $table, $key);
+ }
+ echo '<td align="center">'. checkbox(null, $name, $value, true, '', "align='center'")
+ . hidden("LInact[$id]", $value, false) . '</td>';
+ }
+}
+//
+// Displays controls for optional display of inactive records
+//
+function inactive_control_row($th) {
+ echo "<tr><td colspan=".(count($th)).">"
+ ."<div style='float:left;'>"
+ . checkbox(null, 'show_inactive', null, true). _("Show also Inactive")
+ ."</div><div style='float:right;'>"
+ . submit('Update', _('Update'), false, '', null)
+ ."</div></td></tr>";
+}
+//
+// Inserts additional column header when display of inactive records is on.
+//
+function inactive_control_column(&$th) {
+ global $Ajax;
+
+ if (check_value('show_inactive'))
+ array_insert($th, count($th)-2 , _("Inactive"));
+ if (get_post('_show_inactive_update')) {
+ $Ajax->activate('_page_body');
+ }
+}
?>
\ No newline at end of file