2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU General Public License, GPL,
5 as published by the Free Software Foundation, either version 3
6 of the License, or (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 function get_post($name, $dflt='')
14 return ((!isset($_POST[$name]) || $_POST[$name] === '') ? $dflt : $_POST[$name]);
16 //---------------------------------------------------------------------------------
18 function start_form($multi=false, $dummy=false, $action="", $name="")
20 // $dummy - leaved for compatibility with 2.0 API
23 $name = "name='$name'";
25 $action = $_SERVER['PHP_SELF'];
28 echo "<form enctype='multipart/form-data' method='post' action='$action' $name>\n";
30 echo "<form method='post' action='$action' $name>\n";
34 //---------------------------------------------------------------------------------
36 function end_form($breaks=0)
40 echo "<input type=\"hidden\" name=\"_focus\" value=\"".get_post('_focus')."\">\n";
44 function start_table($extra="", $padding='2', $spacing='0')
46 echo "<center><table";
49 echo " cellpadding=$padding cellspacing=$spacing>\n";
52 function end_table($breaks=0)
54 echo "</table></center>\n";
59 function start_outer_table($extra="", $padding='2', $spacing='0', $br=false)
63 start_table($extra, $padding, $spacing);
64 echo "<tr valign=top><td>\n"; // outer table
67 function table_section($number=1, $width=false)
72 $width = ($width ? "width=$width" : "");
73 //echo "</td><td class='tableseparator' $width>\n"; // outer table
74 echo "</td><td style='border-left:1px solid #cccccc;' $width>\n"; // outer table
76 echo "<table class='tablestyle_inner'>\n";
79 function end_outer_table($breaks=0, $close_table=true)
89 function vertical_space($params='')
91 echo "</td></tr><tr><td valign=center $params>";
94 function meta_forward($forward_to, $params="")
97 echo "<meta http-equiv='Refresh' content='0; url=$forward_to?$params'>\n";
98 echo "<center><br>" . _("You should automatically be forwarded.");
99 echo " " . _("If this does not happen") . " " . "<a href='$forward_to?$params'>" . _("click here") . "</a> " . _("to continue") . ".<br><br></center>\n";
100 if ($params !='') $params = '?'.$params;
101 $Ajax->redirect($forward_to.$params);
105 //-----------------------------------------------------------------------------------
106 // Find and replace hotkey marker.
107 // if $clean == true marker is removed and clean label is returned
108 // (for use in wiki help system), otherwise result is array of label
109 // with underlined hotkey letter and access property string.
111 function access_string($label, $clean=false)
116 if (preg_match('/(.*)&([a-zA-Z0-9])(.*)/', $label, $slices))
118 $label = $clean ? $slices[1].$slices[2].$slices[3] :
119 $slices[1].'<u>'.$slices[2].'</u>'.$slices[3];
120 $access = " accesskey='".strtoupper($slices[2])."'";
123 $label = str_replace( '&&', '&', $label);
125 return $clean ? $label : array($label, $access);
128 function hyperlink_back($center=true, $no_menu=true)
132 start_table("width=20%");
135 echo "<td align=center><a href='javascript:window.print();'>"._("Print")."</a></td>\n";
136 echo "<td align=center><a href='javascript:goBack();'>".($no_menu ? _("Close") : _("Back"))."</a></td>\n";
144 function hyperlink_no_params($target, $label, $center=true)
146 $id = default_focus();
147 $pars = access_string($label);
149 $target = $_SERVER['PHP_SELF'];
152 echo "<a href='$target' id='$id' $pars[1]>$pars[0]</a>\n";
157 function hyperlink_no_params_td($target, $label)
160 hyperlink_no_params($target, $label);
164 function viewer_link($label, $url='', $class='', $id='', $icon=null)
166 global $path_to_root;
169 $class = " class='$class'";
172 $class = " id='$id'";
176 $pars = access_string($label);
177 if (user_graphic_links() && $icon)
178 $pars[0] = set_icon($icon, $pars[0]);
179 $preview_str = "<a target='_blank' $class $id href='$path_to_root/$url' onclick=\"javascript:openWindow(this.href,this.target); return false;\"$pars[1]>$pars[0]</a>";
182 $preview_str = $label;
187 function menu_link($url, $label, $id=null)
190 $id = default_focus($id);
191 $pars = access_string($label);
192 return "<a href='$url' class='menu_option' id='$id' $pars[1]>$pars[0]</a>";
195 function submenu_option($title, $url, $id=null)
197 global $path_to_root;
198 display_note(menu_link($path_to_root . $url, $title, $id), 0, 1);
201 function submenu_view($title, $type, $number, $id=null)
203 display_note(get_trans_view_str($type, $number, $title, false, 'menu_option', $id), 0, 1);
206 function submenu_print($title, $type, $number, $id=null, $email=0, $extra=0)
208 display_note(print_document_link($number, $title, true, $type, false, 'menu_option', $id, $email, $extra), 0, 1);
210 //-----------------------------------------------------------------------------------
212 function hyperlink_params($target, $label, $params, $center=true)
214 $id = default_focus();
216 $pars = access_string($label);
218 $target = $_SERVER['PHP_SELF'];
221 echo "<a id='$id' href='$target?$params'$pars[1]>$pars[0]</a>\n";
226 function hyperlink_params_td($target, $label, $params)
229 hyperlink_params($target, $label, $params, false);
233 //-----------------------------------------------------------------------------------
235 function hyperlink_params_separate($target, $label, $params, $center=false)
237 $id = default_focus();
239 $pars = access_string($label);
242 echo "<a target='_blank' id='$id' href='$target?$params' $pars[1]>$pars[0]</a>\n";
247 function hyperlink_params_separate_td($target, $label, $params)
250 hyperlink_params_separate($target, $label, $params);
254 //--------------------------------------------------------------------------------------------------
256 function alt_table_row_color(&$k)
260 echo "<tr class='oddrow'>\n";
265 echo "<tr class='evenrow'>\n";
270 function table_section_title($msg, $colspan=2)
272 echo "<tr><td colspan=$colspan class='tableheader'>$msg</td></tr>\n";
275 function table_header($labels, $params='')
278 foreach ($labels as $label)
279 labelheader_cell($label, $params);
282 //-----------------------------------------------------------------------------------
284 function start_row($param="")
287 echo "<tr $param>\n";
299 for ($i = 0; $i < $num; $i++)
303 $ajax_divs = array();
305 function div_start($id='', $trigger=null, $non_ajax=false)
309 if ($non_ajax) { // div for non-ajax elements
310 array_push($ajax_divs, array($id, null));
311 echo "<div style='display:none' class='js_only' ".($id !='' ? "id='$id'" : '').">";
312 } else { // ajax ready div
313 array_push($ajax_divs, array($id, $trigger===null ? $id : $trigger));
314 echo "<div ". ($id !='' ? "id='$id'" : '').">";
321 global $ajax_divs, $Ajax;
323 if (count($ajax_divs))
325 $div = array_pop($ajax_divs);
326 if ($div[1] !== null)
327 $Ajax->addUpdate($div[1], $div[0], ob_get_flush());
332 /* Table editor interfaces. Key is editor type
333 0 => url of editor page
337 $popup_editors = array(
338 'customer' => array('/sales/manage/customers.php?debtor_no=',
339 113, _("Customers")),
340 'branch' => array('/sales/manage/customer_branches.php?SelectedBranch=',
342 'supplier' => array('/purchasing/manage/suppliers.php?supplier_id=',
343 113, _("Suppliers")),
344 'item' => array('/inventory/manage/items.php?stock_id=',
348 Bind editors for various selectors.
349 $type - type of editor
350 $input - name of related input field
351 $caller - optional function key code (available values F1-F12: 112-123,
354 function set_editor($type, $input, $caller=true)
356 global $path_to_root, $Editors, $popup_editors, $Pagehelp;
358 $key = $caller===true ? $popup_editors[$type][1] : $caller;
360 $Editors[$key] = array( $path_to_root . $popup_editors[$type][0], $input);
362 $help = 'F' . ($key - 111) . ' - ';
363 $help .= $popup_editors[$type][2];
366 //------------------------------------------------------------------------------
367 // Procedures below are now obsolete. Preserved for eventual future use.
370 External page call with saving current context.
371 $call - url of external page
372 $ctx - optional. name of SESSION context object or array of names of POST
373 variables saved on call
375 function context_call($call, $ctx='')
379 foreach($ctx as $postname)
381 $context[$postname] = get_post($postname);
384 $context = isset($_SESSION[$ctx]) ? $_SESSION[$ctx] : null;
386 array_unshift($_SESSION['Context'], array('name' => $ctx,
388 'caller' => $_SERVER['PHP_SELF'],
393 Restores context after external page call and
394 returns array of data passed by external page.
396 function context_restore()
398 if ( count($_SESSION['Context'])) {
399 if ($_SERVER['PHP_SELF'] == $_SESSION['Context'][0]['caller']) {
400 $ctx = array_shift($_SESSION['Context']);
402 if (is_array($ctx['ctx'])) {
403 foreach($ctx['ctx'] as $name => $val)
405 $_POST[$name] = $val;
408 if ($ctx['name']!='')
409 $_SESSION[$ctx['name']] = $ctx['ctx'];
418 Return to caller page if the page was called from external context.
420 function context_return($ret)
422 if ( count($_SESSION['Context'])) {
423 $ctx = &$_SESSION['Context'][0];
425 meta_forward( $ctx['caller'] );
429 Clearing context stack after page cancel.
431 function context_reset()
433 $_SESSION['Context'] = array();
436 Context stack initialization
438 if (!isset($_SESSION['Context'])) {
442 Redirector for selector F4 calls.
443 $sel_editors is array of selname=>editor_page
445 function editor_redirect($sel_editors, $save_fun='') {
446 foreach ($sel_editors as $selname=>$editor)
447 if (isset($_POST['_'.$selname.'_editor'])) {
448 if (function_exists($save_fun))
450 unset($_POST['_'.$selname.'_editor']);
451 context_call($editor, array_keys($_POST));
455 Return procedure for selector F4 calls
457 function editor_return($vars, $restore_fun='') {
458 if (function_exists($restore_fun))
461 if ($ret = context_restore()) {
462 foreach ($vars as $postname=>$retname)
463 if (isset($ret[$retname])) {
464 $_POST[$postname] = $ret[$retname];
465 set_focus($postname);