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 ***********************************************************************/
13 Retrieve value of POST variable(s).
14 For $name passed as array $dflt is not used,
15 default values can be passed as values with non-numeric keys instead.
16 If some field have user formatted numeric value, pass float default value to
17 convert automatically to POSIX.
19 function get_post($name, $dflt='')
21 if (is_array($name)) {
23 foreach($name as $key => $dflt)
24 if (!is_numeric($key)) {
25 $ret[$key] = is_float($dflt) ? input_num($key, $dflt) : get_post($key, $dflt);
27 $ret[$dflt] = get_post($dflt, null);
31 return is_float($dflt) ? input_num($name, $dflt) :
32 ((!isset($_POST[$name]) || $_POST[$name] === '') ? $dflt : $_POST[$name]);
34 //---------------------------------------------------------------------------------
36 function start_form($multi=false, $dummy=false, $action="", $name="")
38 // $dummy - leaved for compatibility with 2.0 API
41 $name = "name='$name'";
43 $action = $_SERVER['PHP_SELF'];
46 echo "<form enctype='multipart/form-data' method='post' action='$action' $name>\n";
48 echo "<form method='post' action='$action' $name>\n";
52 //---------------------------------------------------------------------------------
54 function end_form($breaks=0)
58 echo "<input type=\"hidden\" name=\"_focus\" value=\"".get_post('_focus')."\">\n";
62 function start_table($extra="", $padding='2', $spacing='0')
64 echo "<center><table";
67 echo " cellpadding=$padding cellspacing=$spacing>\n";
70 function end_table($breaks=0)
72 echo "</table></center>\n";
77 function start_outer_table($extra="", $padding='2', $spacing='0', $br=false)
81 start_table($extra, $padding, $spacing);
82 echo "<tr valign=top><td>\n"; // outer table
85 function table_section($number=1, $width=false)
90 $width = ($width ? "width=$width" : "");
91 echo "</td><td class='tableseparator' $width>\n"; // outer table
96 function end_outer_table($breaks=0, $close_table=true)
104 // outer table spacer
106 function vertical_space($params='')
108 echo "</td></tr><tr><td valign=center $params>";
111 function meta_forward($forward_to, $params="")
114 echo "<meta http-equiv='Refresh' content='0; url=$forward_to?$params'>\n";
115 echo "<center><br>" . _("You should automatically be forwarded.");
116 echo " " . _("If this does not happen") . " " . "<a href='$forward_to?$params'>" . _("click here") . "</a> " . _("to continue") . ".<br><br></center>\n";
117 if ($params !='') $params = '?'.$params;
118 $Ajax->redirect($forward_to.$params);
122 //-----------------------------------------------------------------------------------
123 // Find and replace hotkey marker.
124 // if $clean == true marker is removed and clean label is returned
125 // (for use in wiki help system), otherwise result is array of label
126 // with underlined hotkey letter and access property string.
128 function access_string($label, $clean=false)
133 if (preg_match('/(.*)&([a-zA-Z0-9])(.*)/', $label, $slices))
135 $label = $clean ? $slices[1].$slices[2].$slices[3] :
136 $slices[1].'<u>'.$slices[2].'</u>'.$slices[3];
137 $access = " accesskey='".strtoupper($slices[2])."'";
140 $label = str_replace( '&&', '&', $label);
142 return $clean ? $label : array($label, $access);
145 function hyperlink_back($center=true)
149 echo "<p><a href='javascript:goBack();'>"._("Back")."</a></p>\n";
155 function hyperlink_no_params($target, $label, $center=true)
157 $id = default_focus();
158 $pars = access_string($label);
160 $target = $_SERVER['PHP_SELF'];
163 echo "<a href='$target' id='$id' $pars[1]>$pars[0]</a>\n";
168 function hyperlink_no_params_td($target, $label)
171 hyperlink_no_params($target, $label);
175 function viewer_link($label, $url='', $class='', $id='', $icon=null)
177 global $path_to_root;
180 $class = " class='$class'";
183 $class = " id='$id'";
187 $pars = access_string($label);
188 if (user_graphic_links() && $icon)
189 $pars[0] = set_icon($icon, $pars[0]);
190 $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>";
193 $preview_str = $label;
198 function menu_link($url, $label, $id=null)
201 $id = default_focus($id);
202 $pars = access_string($label);
203 return "<a href='$url' class='menu_option' id='$id' $pars[1]>$pars[0]</a>";
206 function submenu_option($title, $url, $id=null)
208 global $path_to_root;
209 display_note(menu_link($path_to_root . $url, $title, $id), 0, 1);
212 function submenu_view($title, $type, $number, $id=null)
214 display_note(get_trans_view_str($type, $number, $title, false, 'menu_option', $id), 0, 1);
217 function submenu_print($title, $type, $number, $id=null, $email=0, $extra=0)
219 display_note(print_document_link($number, $title, true, $type, false, 'menu_option', $id, $email, $extra), 0, 1);
221 //-----------------------------------------------------------------------------------
223 function hyperlink_params($target, $label, $params, $center=true)
225 $id = default_focus();
227 $pars = access_string($label);
229 $target = $_SERVER['PHP_SELF'];
232 echo "<a id='$id' href='$target?$params'$pars[1]>$pars[0]</a>\n";
237 function hyperlink_params_td($target, $label, $params)
240 hyperlink_params($target, $label, $params, false);
244 //-----------------------------------------------------------------------------------
246 function hyperlink_params_separate($target, $label, $params, $center=false)
248 $id = default_focus();
250 $pars = access_string($label);
253 echo "<a target='_blank' id='$id' href='$target?$params' $pars[1]>$pars[0]</a>\n";
258 function hyperlink_params_separate_td($target, $label, $params)
261 hyperlink_params_separate($target, $label, $params);
265 //--------------------------------------------------------------------------------------------------
267 function alt_table_row_color(&$k)
271 echo "<tr class='oddrow'>\n";
276 echo "<tr class='evenrow'>\n";
281 function table_section_title($msg, $colspan=2)
283 echo "<tr><td colspan=$colspan class='tableheader'>$msg</td></tr>\n";
286 function table_header($labels, $params='')
289 foreach ($labels as $label)
290 labelheader_cell($label, $params);
293 //-----------------------------------------------------------------------------------
295 function start_row($param="")
298 echo "<tr $param>\n";
310 for ($i = 0; $i < $num; $i++)
314 $ajax_divs = array();
316 function div_start($id='', $trigger=null, $non_ajax=false)
320 if ($non_ajax) { // div for non-ajax elements
321 array_push($ajax_divs, array($id, null));
322 echo "<div style='display:none' class='js_only' ".($id !='' ? "id='$id'" : '').">";
323 } else { // ajax ready div
324 array_push($ajax_divs, array($id, $trigger===null ? $id : $trigger));
325 echo "<div ". ($id !='' ? "id='$id'" : '').">";
332 global $ajax_divs, $Ajax;
334 if (count($ajax_divs))
336 $div = array_pop($ajax_divs);
337 if ($div[1] !== null)
338 $Ajax->addUpdate($div[1], $div[0], ob_get_flush());
343 /* Table editor interfaces. Key is editor type
344 0 => url of editor page
348 $popup_editors = array(
349 'customer' => array('/sales/manage/customers.php?debtor_no=',
350 113, _("Customers")),
351 'branch' => array('/sales/manage/customer_branches.php?SelectedBranch=',
353 'supplier' => array('/purchasing/manage/suppliers.php?supplier_id=',
354 113, _("Suppliers")),
355 'item' => array('/inventory/manage/items.php?stock_id=',
359 Bind editors for various selectors.
360 $type - type of editor
361 $input - name of related input field
362 $caller - optional function key code (available values F1-F12: 112-123,
365 function set_editor($type, $input, $caller=true)
367 global $path_to_root, $Editors, $popup_editors, $Pagehelp;
369 $key = $caller===true ? $popup_editors[$type][1] : $caller;
371 $Editors[$key] = array( $path_to_root . $popup_editors[$type][0], $input);
373 $help = 'F' . ($key - 111) . ' - ';
374 $help .= $popup_editors[$type][2];
377 //------------------------------------------------------------------------------
378 // Procedures below are now obsolete. Preserved for eventual future use.
381 External page call with saving current context.
382 $call - url of external page
383 $ctx - optional. name of SESSION context object or array of names of POST
384 variables saved on call
386 function context_call($call, $ctx='')
390 foreach($ctx as $postname)
392 $context[$postname] = get_post($postname);
395 $context = isset($_SESSION[$ctx]) ? $_SESSION[$ctx] : null;
397 array_unshift($_SESSION['Context'], array('name' => $ctx,
399 'caller' => $_SERVER['PHP_SELF'],
404 Restores context after external page call and
405 returns array of data passed by external page.
407 function context_restore()
409 if ( count($_SESSION['Context'])) {
410 if ($_SERVER['PHP_SELF'] == $_SESSION['Context'][0]['caller']) {
411 $ctx = array_shift($_SESSION['Context']);
413 if (is_array($ctx['ctx'])) {
414 foreach($ctx['ctx'] as $name => $val)
416 $_POST[$name] = $val;
419 if ($ctx['name']!='')
420 $_SESSION[$ctx['name']] = $ctx['ctx'];
429 Return to caller page if the page was called from external context.
431 function context_return($ret)
433 if ( count($_SESSION['Context'])) {
434 $ctx = &$_SESSION['Context'][0];
436 meta_forward( $ctx['caller'] );
440 Clearing context stack after page cancel.
442 function context_reset()
444 $_SESSION['Context'] = array();
447 Context stack initialization
449 if (!isset($_SESSION['Context'])) {
453 Redirector for selector F4 calls.
454 $sel_editors is array of selname=>editor_page
456 function editor_redirect($sel_editors, $save_fun='') {
457 foreach ($sel_editors as $selname=>$editor)
458 if (isset($_POST['_'.$selname.'_editor'])) {
459 if (function_exists($save_fun))
461 unset($_POST['_'.$selname.'_editor']);
462 context_call($editor, array_keys($_POST));
466 Return procedure for selector F4 calls
468 function editor_return($vars, $restore_fun='') {
469 if (function_exists($restore_fun))
472 if ($ret = context_restore()) {
473 foreach ($vars as $postname=>$retname)
474 if (isset($ret[$retname])) {
475 $_POST[$postname] = $ret[$retname];
476 set_focus($postname);
481 function confirm_dialog($submit, $msg) {
482 if (find_post($submit)) {
483 display_warning($msg);
485 submit_center_first('DialogConfirm', _("Proceed"), '', true);
486 submit_center_last('DialogCancel', _("Cancel"), '', 'cancel');
489 return get_post('DialogConfirm', 0);