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($class=false, $extra="", $padding='2', $spacing='0')
64 echo "<center><table";
65 if ($class == TABLESTYLE_NOBORDER)
66 echo " class='tablestyle_noborder'";
67 elseif ($class == TABLESTYLE2)
68 echo " class='tablestyle2'";
69 elseif ($class == TABLESTYLE)
70 echo " class='tablestyle'";
73 echo " cellpadding=$padding cellspacing=$spacing>\n";
76 function end_table($breaks=0)
78 echo "</table></center>\n";
83 function start_outer_table($class=false, $extra="", $padding='2', $spacing='0', $br=false)
87 start_table($class, $extra, $padding, $spacing);
88 echo "<tr valign=top><td>\n"; // outer table
91 function table_section($number=1, $width=false)
96 $width = ($width ? "width=$width" : "");
97 //echo "</td><td class='tableseparator' $width>\n"; // outer table
98 echo "</td><td style='border-left:1px solid #cccccc;' $width>\n"; // outer table
100 echo "<table class='tablestyle_inner'>\n";
103 function end_outer_table($breaks=0, $close_table=true)
111 // outer table spacer
113 function vertical_space($params='')
115 echo "</td></tr><tr><td valign=center $params>";
118 function meta_forward($forward_to, $params="")
121 echo "<meta http-equiv='Refresh' content='0; url=$forward_to?$params'>\n";
122 echo "<center><br>" . _("You should automatically be forwarded.");
123 echo " " . _("If this does not happen") . " " . "<a href='$forward_to?$params'>" . _("click here") . "</a> " . _("to continue") . ".<br><br></center>\n";
124 if ($params !='') $params = '?'.$params;
125 $Ajax->redirect($forward_to.$params);
129 //-----------------------------------------------------------------------------------
130 // Find and replace hotkey marker.
131 // if $clean == true marker is removed and clean label is returned
132 // (for use in wiki help system), otherwise result is array of label
133 // with underlined hotkey letter and access property string.
135 function access_string($label, $clean=false)
140 if (preg_match('/(.*)&([a-zA-Z0-9])(.*)/', $label, $slices))
142 $label = $clean ? $slices[1].$slices[2].$slices[3] :
143 $slices[1].'<u>'.$slices[2].'</u>'.$slices[3];
144 $access = " accesskey='".strtoupper($slices[2])."'";
147 $label = str_replace( '&&', '&', $label);
149 return $clean ? $label : array($label, $access);
152 function hyperlink_back($center=true, $no_menu=true, $type_no=0, $trans_no=0)
154 global $path_to_root;
159 if ($no_menu && $trans_no != 0)
161 include_once($path_to_root."/admin/db/attachments_db.inc");
162 $id = has_attachment($type_no, $trans_no);
164 $width = ($id != 0 ? "30%" : "20%");
165 start_table(false, "width=$width");
170 echo "<td align=center><a href='$path_to_root/admin/attachments.php?vw=$id' target='blanc_'>"._("View Attachment")."</a></td>\n";
171 echo "<td align=center><a href='javascript:window.print();'>"._("Print")."</a></td>\n";
173 echo "<td align=center><a href='javascript:goBack();'>".($no_menu ? _("Close") : _("Back"))."</a></td>\n";
181 function hyperlink_no_params($target, $label, $center=true)
183 $id = default_focus();
184 $pars = access_string($label);
186 $target = $_SERVER['PHP_SELF'];
189 echo "<a href='$target' id='$id' $pars[1]>$pars[0]</a>\n";
194 function hyperlink_no_params_td($target, $label)
197 hyperlink_no_params($target, $label);
201 function viewer_link($label, $url='', $class='', $id='', $icon=null)
203 global $path_to_root;
206 $class = " class='$class'";
209 $class = " id='$id'";
213 $pars = access_string($label);
214 if (user_graphic_links() && $icon)
215 $pars[0] = set_icon($icon, $pars[0]);
216 $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>";
219 $preview_str = $label;
224 function menu_link($url, $label, $id=null)
227 $id = default_focus($id);
228 $pars = access_string($label);
229 return "<a href='$url' class='menu_option' id='$id' $pars[1]>$pars[0]</a>";
232 function submenu_option($title, $url, $id=null)
234 global $path_to_root;
235 display_note(menu_link($path_to_root . $url, $title, $id), 0, 1);
238 function submenu_view($title, $type, $number, $id=null)
240 display_note(get_trans_view_str($type, $number, $title, false, 'menu_option', $id), 0, 1);
243 function submenu_print($title, $type, $number, $id=null, $email=0, $extra=0)
245 display_note(print_document_link($number, $title, true, $type, false, 'menu_option', $id, $email, $extra), 0, 1);
247 //-----------------------------------------------------------------------------------
249 function hyperlink_params($target, $label, $params, $center=true)
251 $id = default_focus();
253 $pars = access_string($label);
255 $target = $_SERVER['PHP_SELF'];
258 echo "<a id='$id' href='$target?$params'$pars[1]>$pars[0]</a>\n";
263 function hyperlink_params_td($target, $label, $params)
266 hyperlink_params($target, $label, $params, false);
270 //-----------------------------------------------------------------------------------
272 function hyperlink_params_separate($target, $label, $params, $center=false)
274 $id = default_focus();
276 $pars = access_string($label);
279 echo "<a target='_blank' id='$id' href='$target?$params' $pars[1]>$pars[0]</a>\n";
284 function hyperlink_params_separate_td($target, $label, $params)
287 hyperlink_params_separate($target, $label, $params);
291 //--------------------------------------------------------------------------------------------------
293 function alt_table_row_color(&$k)
297 echo "<tr class='oddrow'>\n";
302 echo "<tr class='evenrow'>\n";
307 function table_section_title($msg, $colspan=2)
309 echo "<tr><td colspan=$colspan class='tableheader'>$msg</td></tr>\n";
312 function table_header($labels, $params='')
315 foreach ($labels as $label)
316 labelheader_cell($label, $params);
319 //-----------------------------------------------------------------------------------
321 function start_row($param="")
324 echo "<tr $param>\n";
336 for ($i = 0; $i < $num; $i++)
340 $ajax_divs = array();
342 function div_start($id='', $trigger=null, $non_ajax=false)
346 if ($non_ajax) { // div for non-ajax elements
347 array_push($ajax_divs, array($id, null));
348 echo "<div style='display:none' class='js_only' ".($id !='' ? "id='$id'" : '').">";
349 } else { // ajax ready div
350 array_push($ajax_divs, array($id, $trigger===null ? $id : $trigger));
351 echo "<div ". ($id !='' ? "id='$id'" : '').">";
358 global $ajax_divs, $Ajax;
360 if (count($ajax_divs))
362 $div = array_pop($ajax_divs);
363 if ($div[1] !== null)
364 $Ajax->addUpdate($div[1], $div[0], ob_get_flush());
369 //-----------------------------------------------------------------------------
371 // $name - prefix for widget internal elements:
372 // Nth tab submit name: {$name}_N
373 // div id: _{$name}_div
374 // sel (hidden) name: _{$name}_sel
375 // $tabs - array of tabs; string: tab title or array(tab_title, enabled_status)
377 function tabbed_content_start($name, $tabs, $dft='') {
380 $selname = '_'.$name.'_sel';
381 $div = '_'.$name.'_div';
385 $sel = find_submit($name.'_', '');
388 $Ajax->activate($name);
390 $sel = get_post($selname, $dft);
391 $_POST[$selname] = $sel;
394 $str = "<ul class='ajaxtabs' rel='$div'>\n";
395 foreach($tabs as $tab_no => $tab) {
397 $acc = access_string(is_array($tab) ? $tab[0] : $tab);
398 $disabled = (is_array($tab) && !$tab[1]) ? 'disabled ' : '';
400 ."<button type='submit' name='{$name}_".$tab_no
401 ."' class='".($tab_no===$sel ? 'current':'ajaxbutton')."' $acc[1] $disabled>"
402 ."<span>$acc[0]</span>"
408 $str .= "<div class='spaceBox'></div>\n";
409 $str .= "<input type='hidden' name='$selname' value='$sel'>\n";
410 $str .= "<div class='contentBox' id='$div'>\n";
414 function tabbed_content_end() {
415 echo "</div>"; // content box (don't change to div_end() unless div_start() is used above)
416 div_end(); // tabs widget
419 /* Table editor interfaces. Key is editor type
420 0 => url of editor page
424 $popup_editors = array(
425 'customer' => array('/sales/manage/customers.php?debtor_no=',
426 113, _("Customers")),
427 'branch' => array('/sales/manage/customer_branches.php?SelectedBranch=',
429 'supplier' => array('/purchasing/manage/suppliers.php?supplier_id=',
430 113, _("Suppliers")),
431 'item' => array('/inventory/manage/items.php?stock_id=',
435 Bind editors for various selectors.
436 $type - type of editor
437 $input - name of related input field
438 $caller - optional function key code (available values F1-F12: 112-123,
441 function set_editor($type, $input, $caller=true)
443 global $path_to_root, $Editors, $popup_editors, $Pagehelp;
445 $key = $caller===true ? $popup_editors[$type][1] : $caller;
447 $Editors[$key] = array( $path_to_root . $popup_editors[$type][0], $input);
449 $help = 'F' . ($key - 111) . ' - ';
450 $help .= $popup_editors[$type][2];
453 //------------------------------------------------------------------------------
454 // Procedures below are now obsolete. Preserved for eventual future use.
457 External page call with saving current context.
458 $call - url of external page
459 $ctx - optional. name of SESSION context object or array of names of POST
460 variables saved on call
462 function context_call($call, $ctx='')
466 foreach($ctx as $postname)
468 $context[$postname] = get_post($postname);
471 $context = isset($_SESSION[$ctx]) ? $_SESSION[$ctx] : null;
473 array_unshift($_SESSION['Context'], array('name' => $ctx,
475 'caller' => $_SERVER['PHP_SELF'],
480 Restores context after external page call and
481 returns array of data passed by external page.
483 function context_restore()
485 if ( count($_SESSION['Context'])) {
486 if ($_SERVER['PHP_SELF'] == $_SESSION['Context'][0]['caller']) {
487 $ctx = array_shift($_SESSION['Context']);
489 if (is_array($ctx['ctx'])) {
490 foreach($ctx['ctx'] as $name => $val)
492 $_POST[$name] = $val;
495 if ($ctx['name']!='')
496 $_SESSION[$ctx['name']] = $ctx['ctx'];
505 Return to caller page if the page was called from external context.
507 function context_return($ret)
509 if ( count($_SESSION['Context'])) {
510 $ctx = &$_SESSION['Context'][0];
512 meta_forward( $ctx['caller'] );
516 Clearing context stack after page cancel.
518 function context_reset()
520 $_SESSION['Context'] = array();
523 Context stack initialization
525 if (!isset($_SESSION['Context'])) {
529 Redirector for selector F4 calls.
530 $sel_editors is array of selname=>editor_page
532 function editor_redirect($sel_editors, $save_fun='') {
533 foreach ($sel_editors as $selname=>$editor)
534 if (isset($_POST['_'.$selname.'_editor'])) {
535 if (function_exists($save_fun))
537 unset($_POST['_'.$selname.'_editor']);
538 context_call($editor, array_keys($_POST));
542 Return procedure for selector F4 calls
544 function editor_return($vars, $restore_fun='') {
545 if (function_exists($restore_fun))
548 if ($ret = context_restore()) {
549 foreach ($vars as $postname=>$retname)
550 if (isset($ret[$retname])) {
551 $_POST[$postname] = $ret[$retname];
552 set_focus($postname);
557 function confirm_dialog($submit, $msg) {
558 if (find_post($submit)) {
559 display_warning($msg);
561 submit_center_first('DialogConfirm', _("Proceed"), '', true);
562 submit_center_last('DialogCancel', _("Cancel"), '', 'cancel');
565 return get_post('DialogConfirm', 0);