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
78 function end_outer_table($breaks=0, $close_table=true)
88 function vertical_space($params='')
90 echo "</td></tr><tr><td valign=center $params>";
93 function meta_forward($forward_to, $params="")
96 echo "<meta http-equiv='Refresh' content='0; url=$forward_to?$params'>\n";
97 echo "<center><br>" . _("You should automatically be forwarded.");
98 echo " " . _("If this does not happen") . " " . "<a href='$forward_to?$params'>" . _("click here") . "</a> " . _("to continue") . ".<br><br></center>\n";
99 if ($params !='') $params = '?'.$params;
100 $Ajax->redirect($forward_to.$params);
104 //-----------------------------------------------------------------------------------
105 // Find and replace hotkey marker.
106 // if $clean == true marker is removed and clean label is returned
107 // (for use in wiki help system), otherwise result is array of label
108 // with underlined hotkey letter and access property string.
110 function access_string($label, $clean=false)
115 if (preg_match('/(.*)&([a-zA-Z0-9])(.*)/', $label, $slices))
117 $label = $clean ? $slices[1].$slices[2].$slices[3] :
118 $slices[1].'<u>'.$slices[2].'</u>'.$slices[3];
119 $access = " accesskey='".strtoupper($slices[2])."'";
122 $label = str_replace( '&&', '&', $label);
124 return $clean ? $label : array($label, $access);
127 function hyperlink_back($center=true)
131 echo "<p><a href='javascript:goBack();'>"._("Back")."</a></p>\n";
137 function hyperlink_no_params($target, $label, $center=true)
139 $id = default_focus();
140 $pars = access_string($label);
142 $target = $_SERVER['PHP_SELF'];
145 echo "<a href='$target' $id='$id' $pars[1]>$pars[0]</a>\n";
150 function hyperlink_no_params_td($target, $label)
153 hyperlink_no_params($target, $label);
157 function viewer_link($label, $url='', $class='', $id='', $icon=null)
159 global $path_to_root;
162 $class = " class='$class'";
165 $class = " id='$id'";
169 $pars = access_string($label);
170 if (user_graphic_links() && $icon)
171 $pars[0] = set_icon($icon, $pars[0]);
172 $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>";
175 $preview_str = $label;
180 function menu_link($url, $label, $id=null)
183 $id = default_focus($id);
184 $pars = access_string($label);
185 return "<a href='$url' class='menu_option' id='$id' $pars[1]>$pars[0]</a>";
188 function submenu_option($title, $url, $id=null)
190 global $path_to_root;
191 display_note(menu_link($path_to_root . $url, $title, $id), 0, 1);
194 function submenu_view($title, $type, $number, $id=null)
196 display_note(get_trans_view_str($type, $number, $title, false, 'menu_option', $id), 0, 1);
199 function submenu_print($title, $type, $number, $id=null)
201 display_note(print_document_link($number, $title, true, $type, false, 'menu_option', $id), 0, 1);
203 //-----------------------------------------------------------------------------------
205 function hyperlink_params($target, $label, $params, $center=true)
207 $id = default_focus();
209 $pars = access_string($label);
211 $target = $_SERVER['PHP_SELF'];
214 echo "<a id='$id' href='$target?$params'$pars[1]>$pars[0]</a>\n";
219 function hyperlink_params_td($target, $label, $params)
222 hyperlink_params($target, $label, $params, false);
226 //-----------------------------------------------------------------------------------
228 function hyperlink_params_separate($target, $label, $params, $center=false)
230 $id = default_focus();
232 $pars = access_string($label);
235 echo "<a target='_blank' $id='$id' href='$target?$params' $pars[1]>$pars[0]</a>\n";
240 function hyperlink_params_separate_td($target, $label, $params)
243 hyperlink_params_separate($target, $label, $params);
247 //--------------------------------------------------------------------------------------------------
249 function alt_table_row_color(&$k)
253 echo "<tr class='oddrow'>\n";
258 echo "<tr class='evenrow'>\n";
263 function table_section_title($msg, $colspan=2)
265 echo "<tr><td colspan=$colspan class='tableheader'>$msg</td></tr>\n";
268 function table_header($labels, $params='')
271 foreach ($labels as $label)
272 labelheader_cell($label, $params);
275 //-----------------------------------------------------------------------------------
277 function start_row($param="")
280 echo "<tr $param>\n";
292 for ($i = 0; $i < $num; $i++)
296 $ajax_divs = array();
298 function div_start($id='', $trigger=null, $non_ajax=false)
302 if ($non_ajax) { // div for non-ajax elements
303 array_push($ajax_divs, array($id, null));
304 echo "<div style='display:none' class='js_only' ".($id !='' ? "id='$id'" : '').">";
305 } else { // ajax ready div
306 array_push($ajax_divs, array($id, $trigger===null ? $id : $trigger));
307 echo "<div ". ($id !='' ? "id='$id'" : '').">";
314 global $ajax_divs, $Ajax;
316 if (count($ajax_divs))
318 $div = array_pop($ajax_divs);
319 if ($div[1] !== null)
320 $Ajax->addUpdate($div[1], $div[0], ob_get_flush());
326 Bind editors for various selectors.
327 $type - type of editor
328 $input - array org_input => editor_input
329 $focus - focus after selection
331 function set_editor($type, $input, $focus=null)
333 global $path_to_root, $Editors;
334 // table of table editor interfaces.
335 // key is editor type, values contain:
336 // 0 => url of editor page
337 // 1 => array of names of parameters returned back from editor interface
340 if($focus === null) {
344 'customer' => array('/sales/manage/customers.php?debtor_no=',
345 113, _("F2 - Customers")),
346 'branch' => array('/sales/manage/customer_branches.php?SelectedBranch=',
347 114, _("F3 - Branches")),
348 'supplier' => array('/purchasing/manage/suppliers.php?supplier_id=',
349 113, _("F2 - Suppliers")),
350 'item' => array('/inventory/manage/items.php?stock_id=',
351 115, _("F4 - Items"))
354 $caller = $urls[$type][1];
355 $Editors[$caller] = array( $path_to_root . $urls[$type][0], $input, $focus);
357 // FIX status comments
360 //------------------------------------------------------------------------------
361 // Procedures below are now obsolete. Preserved for eventual future use.
364 External page call with saving current context.
365 $call - url of external page
366 $ctx - optional. name of SESSION context object or array of names of POST
367 variables saved on call
369 function context_call($call, $ctx='')
373 foreach($ctx as $postname)
375 $context[$postname] = get_post($postname);
378 $context = isset($_SESSION[$ctx]) ? $_SESSION[$ctx] : null;
380 array_unshift($_SESSION['Context'], array('name' => $ctx,
382 'caller' => $_SERVER['PHP_SELF'],
387 Restores context after external page call and
388 returns array of data passed by external page.
390 function context_restore()
392 if ( count($_SESSION['Context'])) {
393 if ($_SERVER['PHP_SELF'] == $_SESSION['Context'][0]['caller']) {
394 $ctx = array_shift($_SESSION['Context']);
396 if (is_array($ctx['ctx'])) {
397 foreach($ctx['ctx'] as $name => $val)
399 $_POST[$name] = $val;
402 if ($ctx['name']!='')
403 $_SESSION[$ctx['name']] = $ctx['ctx'];
412 Return to caller page if the page was called from external context.
414 function context_return($ret)
416 if ( count($_SESSION['Context'])) {
417 $ctx = &$_SESSION['Context'][0];
419 meta_forward( $ctx['caller'] );
423 Clearing context stack after page cancel.
425 function context_reset()
427 $_SESSION['Context'] = array();
430 Context stack initialization
432 if (!isset($_SESSION['Context'])) {
436 Redirector for selector F4 calls.
437 $sel_editors is array of selname=>editor_page
439 function editor_redirect($sel_editors, $save_fun='') {
440 foreach ($sel_editors as $selname=>$editor)
441 if (isset($_POST['_'.$selname.'_editor'])) {
442 if (function_exists($save_fun))
444 unset($_POST['_'.$selname.'_editor']);
445 context_call($editor, array_keys($_POST));
449 Return procedure for selector F4 calls
451 function editor_return($vars, $restore_fun='') {
452 if (function_exists($restore_fun))
455 if ($ret = context_restore()) {
456 foreach ($vars as $postname=>$retname)
457 if (isset($ret[$retname])) {
458 $_POST[$postname] = $ret[$retname];
459 set_focus($postname);