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)
71 echo "</td><td class='tableseparator'>\n"; // outer table
76 function end_outer_table($breaks=0)
83 function meta_forward($forward_to, $params="")
86 echo "<meta http-equiv='Refresh' content='0; url=$forward_to?$params'>\n";
87 echo "<center><br>" . _("You should automatically be forwarded.");
88 echo " " . _("If this does not happen") . " " . "<a href='$forward_to?$params'>" . _("click here") . "</a> " . _("to continue") . ".<br><br></center>\n";
89 if ($params !='') $params = '?'.$params;
90 $Ajax->redirect($forward_to.$params);
94 //-----------------------------------------------------------------------------------
95 // Find and replace hotkey marker.
96 // if $clean == true marker is removed and clean label is returned
97 // (for use in wiki help system), otherwise result is array of label
98 // with underlined hotkey letter and access property string.
100 function access_string($label, $clean=false)
105 if (preg_match('/(.*)&([a-zA-Z0-9])(.*)/', $label, $slices))
107 $label = $clean ? $slices[1].$slices[2].$slices[3] :
108 $slices[1].'<u>'.$slices[2].'</u>'.$slices[3];
109 $access = " accesskey='".strtoupper($slices[2])."'";
112 $label = str_replace( '&&', '&', $label);
114 return $clean ? $label : array($label, $access);
117 function hyperlink_back($center=true)
121 //echo "<a href='javascript:goBack();'>"._("Back")."</a>\n";
122 echo "<p><a href='javascript:goBack();'>"._("Back")."</a></p>\n";
128 function hyperlink_no_params($target, $label, $center=true)
130 $pars = access_string($label);
133 echo "<a href='$target?=" . SID . "'$pars[1]>$pars[0]</a>\n";
138 function hyperlink_no_params_td($target, $label)
141 hyperlink_no_params($target, $label);
145 //-----------------------------------------------------------------------------------
147 function hyperlink_params($target, $label, $params, $center=true)
149 $pars = access_string($label);
152 echo "<a href='$target?$params'$pars[1]>$pars[0]</a>\n";
157 function hyperlink_params_td($target, $label, $params)
160 hyperlink_params($target, $label, $params, false);
164 //-----------------------------------------------------------------------------------
166 function hyperlink_params_separate($target, $label, $params, $center=false)
168 $pars = access_string($label);
171 echo "<a target='_blank' href='$target?$params" . SID . "'$pars[1]>$pars[0]</a>\n";
176 function hyperlink_params_separate_td($target, $label, $params)
179 hyperlink_params_separate($target, $label, $params);
183 //--------------------------------------------------------------------------------------------------
185 function alt_table_row_color(&$k)
189 echo "<tr class='oddrow'>\n";
194 echo "<tr class='evenrow'>\n";
199 function table_section_title($msg, $colspan=2)
201 echo "<tr><td colspan=$colspan class='tableheader'>$msg</td></tr>\n";
204 function table_header($labels)
207 foreach ($labels as $label)
208 labelheader_cell($label);
211 //-----------------------------------------------------------------------------------
213 function start_row($param="")
216 echo "<tr $param>\n";
228 for ($i = 0; $i < $num; $i++)
232 $ajax_divs = array();
234 function div_start($id='', $trigger=null, $non_ajax=false)
238 if ($non_ajax) { // div for non-ajax elements
239 array_push($ajax_divs, array($id, null));
240 echo "<div style='display:none' class='js_only' ".($id !='' ? "id='$id'" : '').">";
241 } else { // ajax ready div
242 array_push($ajax_divs, array($id, $trigger===null ? $id : $trigger));
243 echo "<div ". ($id !='' ? "id='$id'" : '').">";
250 global $ajax_divs, $Ajax;
252 if (count($ajax_divs))
254 $div = array_pop($ajax_divs);
255 if ($div[1] !== null)
256 $Ajax->addUpdate($div[1], $div[0], ob_get_flush());
262 External page call with saving current context.
263 $call - url of external page
264 $ctx - optional. name of SESSION context object or array of names of POST
265 variables saved on call
267 function context_call($call, $ctx='')
271 foreach($ctx as $postname)
273 $context[$postname] = get_post($postname);
276 $context = isset($_SESSION[$ctx]) ? $_SESSION[$ctx] : null;
278 array_unshift($_SESSION['Context'], array('name' => $ctx,
280 'caller' => $_SERVER['PHP_SELF'],
285 Restores context after external page call and
286 returns array of data passed by external page.
288 function context_restore()
290 if ( count($_SESSION['Context'])) {
291 if ($_SERVER['PHP_SELF'] == $_SESSION['Context'][0]['caller']) {
292 $ctx = array_shift($_SESSION['Context']);
294 if (is_array($ctx['ctx'])) {
295 foreach($ctx['ctx'] as $name => $val)
297 $_POST[$name] = $val;
300 if ($ctx['name']!='')
301 $_SESSION[$ctx['name']] = $ctx['ctx'];
310 Return to caller page if the page was called from external context.
312 function context_return($ret)
314 if ( count($_SESSION['Context'])) {
315 $ctx = &$_SESSION['Context'][0];
317 meta_forward( $ctx['caller'] );
321 Clearing context stack after page cancel.
323 function context_reset()
325 $_SESSION['Context'] = array();
329 Context stack initialization
331 if (!isset($_SESSION['Context'])) {