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 meta_forward($forward_to, $params="")
62 echo "<meta http-equiv='Refresh' content='0; url=$forward_to?$params'>\n";
63 echo "<center><br>" . _("You should automatically be forwarded.");
64 echo " " . _("If this does not happen") . " " . "<a href='$forward_to?$params'>" . _("click here") . "</a> " . _("to continue") . ".<br><br></center>\n";
65 if ($params !='') $params = '?'.$params;
66 $Ajax->redirect($forward_to.$params);
70 //-----------------------------------------------------------------------------------
71 // Find and replace hotkey marker.
72 // if $clean == true marker is removed and clean label is returned
73 // (for use in wiki help system), otherwise result is array of label
74 // with underlined hotkey letter and access property string.
76 function access_string($label, $clean=false)
81 if (preg_match('/(.*)&([a-zA-Z0-9])(.*)/', $label, $slices))
83 $label = $clean ? $slices[1].$slices[2].$slices[3] :
84 $slices[1].'<u>'.$slices[2].'</u>'.$slices[3];
85 $access = " accesskey='".strtoupper($slices[2])."'";
88 $label = str_replace( '&&', '&', $label);
90 return $clean ? $label : array($label, $access);
93 function hyperlink_back($center=true)
97 //echo "<a href='javascript:goBack();'>"._("Back")."</a>\n";
98 echo "<p><a href='javascript:goBack();'>"._("Back")."</a></p>\n";
104 function hyperlink_no_params($target, $label, $center=true)
106 $pars = access_string($label);
109 echo "<a href='$target?=" . SID . "'$pars[1]>$pars[0]</a>\n";
114 function hyperlink_no_params_td($target, $label)
117 hyperlink_no_params($target, $label);
121 //-----------------------------------------------------------------------------------
123 function hyperlink_params($target, $label, $params, $center=true)
125 $pars = access_string($label);
128 echo "<a href='$target?$params'$pars[1]>$pars[0]</a>\n";
133 function hyperlink_params_td($target, $label, $params)
136 hyperlink_params($target, $label, $params, false);
140 //-----------------------------------------------------------------------------------
142 function hyperlink_params_separate($target, $label, $params, $center=false)
144 $pars = access_string($label);
147 echo "<a target='_blank' href='$target?$params" . SID . "'$pars[1]>$pars[0]</a>\n";
152 function hyperlink_params_separate_td($target, $label, $params)
155 hyperlink_params_separate($target, $label, $params);
159 //--------------------------------------------------------------------------------------------------
161 function alt_table_row_color(&$k)
165 echo "<tr class='oddrow'>\n";
170 echo "<tr class='evenrow'>\n";
175 function table_section_title($msg)
177 echo "<tr><td colspan=2 class='tableheader'>$msg</td><tr>\n";
180 function table_header($labels)
183 foreach ($labels as $label)
184 labelheader_cell($label);
187 //-----------------------------------------------------------------------------------
189 function start_row($param="")
192 echo "<tr $param>\n";
204 for ($i = 0; $i < $num; $i++)
208 $ajax_divs = array();
210 function div_start($id='', $trigger=null, $non_ajax=false)
214 if ($non_ajax) { // div for non-ajax elements
215 array_push($ajax_divs, array($id, null));
216 echo "<div style='display:none' class='js_only' ".($id !='' ? "id='$id'" : '').">";
217 } else { // ajax ready div
218 array_push($ajax_divs, array($id, $trigger===null ? $id : $trigger));
219 echo "<div ". ($id !='' ? "id='$id'" : '').">";
226 global $ajax_divs, $Ajax;
228 if (count($ajax_divs))
230 $div = array_pop($ajax_divs);
231 if ($div[1] !== null)
232 $Ajax->addUpdate($div[1], $div[0], ob_get_flush());
238 External page call with saving current context.
239 $call - url of external page
240 $ctx - optional. name of SESSION context object or array of names of POST
241 variables saved on call
243 function context_call($call, $ctx='')
247 foreach($ctx as $postname)
249 $context[$postname] = get_post($postname);
252 $context = isset($_SESSION[$ctx]) ? $_SESSION[$ctx] : null;
254 array_unshift($_SESSION['Context'], array('name' => $ctx,
256 'caller' => $_SERVER['PHP_SELF'],
261 Restores context after external page call and
262 returns array of data passed by external page.
264 function context_restore()
266 if ( count($_SESSION['Context'])) {
267 if ($_SERVER['PHP_SELF'] == $_SESSION['Context'][0]['caller']) {
268 $ctx = array_shift($_SESSION['Context']);
270 if (is_array($ctx['ctx'])) {
271 foreach($ctx['ctx'] as $name => $val)
273 $_POST[$name] = $val;
276 if ($ctx['name']!='')
277 $_SESSION[$ctx['name']] = $ctx['ctx'];
286 Return to caller page if the page was called from external context.
288 function context_return($ret)
290 if ( count($_SESSION['Context'])) {
291 $ctx = &$_SESSION['Context'][0];
293 meta_forward( $ctx['caller'] );
297 Clearing context stack after page cancel.
299 function context_reset()
301 $_SESSION['Context'] = array();
305 Context stack initialization
307 if (!isset($_SESSION['Context'])) {