+ echo "</div>";
+}
+
+//-----------------------------------------------------------------------------
+// Tabbed area:
+// $name - prefix for widget internal elements:
+// Nth tab submit name: {$name}_N
+// div id: _{$name}_div
+// sel (hidden) name: _{$name}_sel
+// $tabs - array of tabs; string: tab title or array(tab_title, enabled_status)
+
+function tabbed_content_start($name, $tabs, $dft='') {
+ global $Ajax;
+
+ $selname = '_'.$name.'_sel';
+ $div = '_'.$name.'_div';
+
+ $sel = find_submit($name.'_', false);
+ if($sel==null)
+ $sel = get_post($selname, (string)($dft==='' ? key($tabs) : $dft));
+
+ if ($sel!==@$_POST[$selname])
+ $Ajax->activate($name);
+
+ $_POST[$selname] = $sel;
+
+ div_start($name);
+ $str = "<ul class='ajaxtabs' rel='$div'>\n";
+ foreach($tabs as $tab_no => $tab) {
+
+ $acc = access_string(is_array($tab) ? $tab[0] : $tab);
+ $disabled = (is_array($tab) && !$tab[1]) ? 'disabled ' : '';
+ $str .= ( "<li>"
+ ."<button type='submit' name='{$name}_".$tab_no
+ ."' class='".((string)$tab_no===$sel ? 'current':'ajaxbutton')."' $acc[1] $disabled>"
+ ."<span>$acc[0]</span>"
+ ."</button>\n"
+ ."</li>\n" );
+ }
+
+ $str .= "</ul>\n";
+ $str .= "<div class='spaceBox'></div>\n";
+ $str .= "<input type='hidden' name='$selname' value='$sel'>\n";
+ $str .= "<div class='contentBox' id='$div'>\n";
+ echo $str;
+}
+
+function tabbed_content_end() {
+ output_hidden();
+ echo "</div>"; // content box (don't change to div_end() unless div_start() is used above)
+ div_end(); // tabs widget
+}
+
+function tab_changed($name)
+{
+ $to = find_submit("{$name}_", false);
+ if (!$to) return null;
+
+ return array('from' => $from = get_post("_{$name}_sel"),
+ 'to' => $to);
+}
+/*
+ Check whether tab has been just switched on
+*/
+function tab_opened($name, $tab)
+{
+ return (get_post('_'.$name.'_sel') != $tab) && (find_submit($name.'_', false) == $tab);
+}
+/*
+ Check whether tab has been just switched off
+*/
+function tab_closed($name, $tab)
+{
+ return (get_post('_'.$name.'_sel') == $tab) && (find_submit($name.'_', false) != $tab);
+}
+/*
+ Check whether tab is visible on current page
+*/
+function tab_visible($name, $tab)
+{
+ $new = find_submit($name.'_', false);
+ return (get_post('_'.$name.'_sel') == $tab && !$new) || $new==$tab;
+}
+
+/* Table editor interfaces. Key is editor type
+ 0 => url of editor page
+ 1 => hotkey code
+ 2 => context help
+*/
+$popup_editors = array(
+ 'customer' => array('/sales/manage/customers.php?debtor_no=',
+ 113, _("Customers"), 900, 600),
+ 'branch' => array('/sales/manage/customer_branches.php?SelectedBranch=',
+ 114, _("Branches"), 900, 700),
+ 'supplier' => array('/purchasing/manage/suppliers.php?supplier_id=',
+ 113, _("Suppliers"), 900, 700),
+ 'item' => array('/inventory/manage/items.php?stock_id=',
+ 115, _("Items"), 800, 600),
+ 'fa_item' => array('/inventory/manage/items.php?FixedAsset=1&stock_id=',
+ 115, _("Items"), 800, 600)
+);
+/*
+ Bind editors for various selectors.
+ $type - type of editor
+ $input - name of related input field
+ $caller - optional function key code (available values F1-F12: 112-123,
+ true: default)
+*/
+function set_editor($type, $input, $caller=true)
+{
+ global $path_to_root, $Editors, $popup_editors, $Pagehelp;
+
+ $key = $caller===true ? $popup_editors[$type][1] : $caller;
+
+ $Editors[$key] = array( $path_to_root . $popup_editors[$type][0], $input,
+ $popup_editors[$type][3], $popup_editors[$type][4]);
+
+ $help = 'F' . ($key - 111) . ' - ';
+ $help .= $popup_editors[$type][2];
+ $Pagehelp[] = $help;
+}
+//------------------------------------------------------------------------------
+// Procedures below are now obsolete. Preserved for eventual future use.
+
+/*
+ External page call with saving current context.
+ $call - url of external page
+ $ctx - optional. name of SESSION context object or array of names of POST
+ variables saved on call
+*/
+function context_call($call, $ctx='')
+{
+ if (is_array($ctx))
+ {
+ foreach($ctx as $postname)
+ {
+ $context[$postname] = get_post($postname);
+ }
+ } else
+ $context = isset($_SESSION[$ctx]) ? $_SESSION[$ctx] : null;
+
+ array_unshift($_SESSION['Context'], array('name' => $ctx,
+ 'ctx' => $context,
+ 'caller' => $_SERVER['PHP_SELF'],
+ 'ret' => array()));
+ meta_forward($call);
+}
+/*
+ Restores context after external page call and
+ returns array of data passed by external page.
+*/
+function context_restore()
+{
+ if ( count($_SESSION['Context'])) {
+ if ($_SERVER['PHP_SELF'] == $_SESSION['Context'][0]['caller']) {
+ $ctx = array_shift($_SESSION['Context']);
+ if ($ctx) {
+ if (is_array($ctx['ctx'])) {
+ foreach($ctx['ctx'] as $name => $val)
+ {
+ $_POST[$name] = $val;
+ }
+ } else
+ if ($ctx['name']!='')
+ $_SESSION[$ctx['name']] = $ctx['ctx'];
+ return $ctx['ret'];
+ }
+ }
+ }
+ return false;
+}
+
+/*
+ Return to caller page if the page was called from external context.
+*/
+function context_return($ret)
+{
+ if ( count($_SESSION['Context'])) {
+ $ctx = &$_SESSION['Context'][0];
+ $ctx['ret'] = $ret;
+ meta_forward( $ctx['caller'] );
+ }
+}
+/*
+ Clearing context stack after page cancel.
+*/
+function context_reset()
+{
+ $_SESSION['Context'] = array();
+}
+/*
+ Context stack initialization
+*/
+if (!isset($_SESSION['Context'])) {
+ context_reset();
+}
+/*
+ Redirector for selector F4 calls.
+ $sel_editors is array of selname=>editor_page
+*/
+function editor_redirect($sel_editors, $save_fun='') {
+ foreach ($sel_editors as $selname=>$editor)
+ if (isset($_POST['_'.$selname.'_editor'])) {
+ if (function_exists($save_fun))
+ $save_fun();
+ unset($_POST['_'.$selname.'_editor']);
+ context_call($editor, array_keys($_POST));
+ }
+}
+/*
+ Return procedure for selector F4 calls
+*/
+function editor_return($vars, $restore_fun='') {
+ if (function_exists($restore_fun))
+ $restore_fun();
+
+ if ($ret = context_restore()) {
+ foreach ($vars as $postname=>$retname)
+ if (isset($ret[$retname])) {
+ $_POST[$postname] = $ret[$retname];
+ set_focus($postname);
+ }
+ }
+}
+
+function confirm_dialog($submit, $msg) {
+ if (find_post($submit)) {
+ display_warning($msg);
+ br();
+ submit_center_first('DialogConfirm', _("Proceed"), '', true);
+ submit_center_last('DialogCancel', _("Cancel"), '', 'cancel');
+ return 0;
+ } else
+ return get_post('DialogConfirm', 0);
+}
+/*
+ Confirm dialog to be used optionally in final form checking routine.
+ Displays warning conditionally unless it was displayed
+*/
+function display_confirmation($msg)
+{
+ global $Ajax;
+
+ if (!get_post('_confirmed'))
+ {
+ $_POST['_confirmed'] = 1;
+ display_warning($msg);
+ return false;
+ } else
+ return true;
+}
+/*
+ Block menu/shortcut links during transaction procesing.
+*/
+function page_processing($msg = false)
+{
+ global $Ajax;
+
+ if ($msg === true)
+ $msg = _("Entered data has not been saved yet.\nDo you want to abandon changes?");
+
+ $js = "_validate._processing=" . (
+ $msg ? '\''.strtr($msg, array("\n"=>'\\n')) . '\';' : 'null;');
+ if (in_ajax()) {
+ $Ajax->addScript(true, $js);
+ } else
+ add_js_source($js);
+}
+
+function page_modified($status = true)
+{
+ global $Ajax;
+
+ $js = "_validate._modified=" . ($status ? 1:0).';';
+ if (in_ajax()) {
+ $Ajax->addScript(true, $js);
+ } else
+ add_js_source($js);