2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU Affero General Public License,
5 AGPL, as published by the Free Software Foundation, either version
6 3 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/agpl-3.0.html>.
11 ***********************************************************************/
12 //---------------------------------------------------------------------------------
14 function start_form($multi=false, $sid=false, $action="", $name="")
17 $name = "name='$name'";
19 $action = $_SERVER['PHP_SELF'];
22 if (strpos($action, "?"))
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')
62 start_table($extra, $padding, $spacing);
63 echo "<tr valign=top><td>\n"; // outer table
66 function table_section($number=1, $width=false)
71 $width = ($width ? "width=$width" : "");
72 echo "</td><td class='tableseparator' $width>\n"; // outer table
77 function end_outer_table($breaks=0, $close_table=true)
85 function vertical_space()
87 echo "</td></tr><tr><td valign=center>"; // outer table
89 function meta_forward($forward_to, $params="")
92 echo "<meta http-equiv='Refresh' content='0; url=$forward_to?$params'>\n";
93 echo "<center><br>" . _("You should automatically be forwarded.");
94 echo " " . _("If this does not happen") . " " . "<a href='$forward_to?$params'>" . _("click here") . "</a> " . _("to continue") . ".<br><br></center>\n";
95 if ($params !='') $params = '?'.$params;
96 $Ajax->redirect($forward_to.$params);
100 //-----------------------------------------------------------------------------------
101 // Find and replace hotkey marker.
102 // if $clean == true marker is removed and clean label is returned
103 // (for use in wiki help system), otherwise result is array of label
104 // with underlined hotkey letter and access property string.
106 function access_string($label, $clean=false)
111 if (preg_match('/(.*)&([a-zA-Z0-9])(.*)/', $label, $slices))
113 $label = $clean ? $slices[1].$slices[2].$slices[3] :
114 $slices[1].'<u>'.$slices[2].'</u>'.$slices[3];
115 $access = " accesskey='".strtoupper($slices[2])."'";
118 $label = str_replace( '&&', '&', $label);
120 return $clean ? $label : array($label, $access);
123 function hyperlink_back($center=true)
127 //echo "<a href='javascript:goBack();'>"._("Back")."</a>\n";
128 echo "<p><a href='javascript:goBack();'>"._("Back")."</a></p>\n";
134 function hyperlink_no_params($target, $label, $center=true)
136 $pars = access_string($label);
139 echo "<a href='$target?=" . SID . "'$pars[1]>$pars[0]</a>\n";
144 function hyperlink_no_params_td($target, $label)
147 hyperlink_no_params($target, $label);
151 //-----------------------------------------------------------------------------------
153 function hyperlink_params($target, $label, $params, $center=true)
155 $pars = access_string($label);
158 echo "<a href='$target?$params'$pars[1]>$pars[0]</a>\n";
163 function hyperlink_params_td($target, $label, $params)
166 hyperlink_params($target, $label, $params, false);
170 //-----------------------------------------------------------------------------------
172 function hyperlink_params_separate($target, $label, $params, $center=false)
174 $pars = access_string($label);
177 echo "<a target='_blank' href='$target?$params" . SID . "'$pars[1]>$pars[0]</a>\n";
182 function hyperlink_params_separate_td($target, $label, $params)
185 hyperlink_params_separate($target, $label, $params);
189 //--------------------------------------------------------------------------------------------------
191 function alt_table_row_color(&$k)
195 echo "<tr class='oddrow'>\n";
200 echo "<tr class='evenrow'>\n";
205 function table_section_title($msg, $colspan=2)
207 echo "<tr><td colspan=$colspan class='tableheader'>$msg</td></tr>\n";
210 function table_header($labels)
213 foreach ($labels as $label)
214 labelheader_cell($label);
217 //-----------------------------------------------------------------------------------
219 function start_row($param="")
222 echo "<tr $param>\n";
234 for ($i = 0; $i < $num; $i++)
238 $ajax_divs = array();
240 function div_start($id='', $trigger=null, $non_ajax=false)
244 if ($non_ajax) { // div for non-ajax elements
245 array_push($ajax_divs, array($id, null));
246 echo "<div style='display:none' class='js_only' ".($id !='' ? "id='$id'" : '').">";
247 } else { // ajax ready div
248 array_push($ajax_divs, array($id, $trigger===null ? $id : $trigger));
249 echo "<div ". ($id !='' ? "id='$id'" : '').">";
256 global $ajax_divs, $Ajax;
258 if (count($ajax_divs))
260 $div = array_pop($ajax_divs);
261 if ($div[1] !== null)
262 $Ajax->addUpdate($div[1], $div[0], ob_get_flush());
268 External page call with saving current context.
269 $call - url of external page
270 $ctx - optional. name of SESSION context object or array of names of POST
271 variables saved on call
273 function context_call($call, $ctx='')
277 foreach($ctx as $postname)
279 $context[$postname] = get_post($postname);
282 $context = isset($_SESSION[$ctx]) ? $_SESSION[$ctx] : null;
284 array_unshift($_SESSION['Context'], array('name' => $ctx,
286 'caller' => $_SERVER['PHP_SELF'],
291 Restores context after external page call and
292 returns array of data passed by external page.
294 function context_restore()
296 if ( count($_SESSION['Context'])) {
297 if ($_SERVER['PHP_SELF'] == $_SESSION['Context'][0]['caller']) {
298 $ctx = array_shift($_SESSION['Context']);
300 if (is_array($ctx['ctx'])) {
301 foreach($ctx['ctx'] as $name => $val)
303 $_POST[$name] = $val;
306 if ($ctx['name']!='')
307 $_SESSION[$ctx['name']] = $ctx['ctx'];
316 Return to caller page if the page was called from external context.
318 function context_return($ret)
320 if ( count($_SESSION['Context'])) {
321 $ctx = &$_SESSION['Context'][0];
323 meta_forward( $ctx['caller'] );
327 Clearing context stack after page cancel.
329 function context_reset()
331 $_SESSION['Context'] = array();
335 Context stack initialization
337 if (!isset($_SESSION['Context'])) {
341 Redirector for selector F4 calls.
342 $sel_editors is array of selname=>editor_page
344 function editor_redirect($sel_editors, $save_fun='') {
345 foreach ($sel_editors as $selname=>$editor)
346 if (isset($_POST['_'.$selname.'_editor'])) {
347 if (function_exists($save_fun))
349 unset($_POST['_'.$selname.'_editor']);
350 context_call($editor, array_keys($_POST));
354 Return procedure for selector F4 calls
356 function editor_return($vars, $restore_fun='') {
357 if (function_exists($restore_fun))
360 if ($ret = context_restore()) {
361 foreach ($vars as $postname=>$retname)
362 if (isset($ret[$retname])) {
363 $_POST[$postname] = $ret[$retname];
364 set_focus($postname);