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);
188 //-----------------------------------------------------------------------------------
190 function set_icon($icon, $title=false)
192 global $path_to_root;
193 return "<img src='$path_to_root/themes/".user_theme()."/images/$icon' width='14' height='14' border='0'".($title ? " title='$title'" : "")." />\n";
196 function button($name, $value, $title=false, $icon=false)
198 // php silently changes dots,spaces,'[' and characters 128-159
199 // to underscore in POST names, to maintain compatibility with register_globals
200 if (user_graphic_links() && $icon)
202 if ($value == _("Delete")) // Helper during implementation
204 echo "<button type='submit' class='editbutton' name='".
205 htmlentities(strtr($name, array('.'=>'=2E',' '=>'=20','='=>'=3D','['=>'=5B'))).
206 "' value=''" . ($title ? " title='$title'":" title='$value'")." />".set_icon($icon)."\n";
209 echo "<input type='submit' class='editbutton' name='"
210 .htmlentities(strtr($name, array('.'=>'=2E',' '=>'=20','='=>'=3D','['=>'=5B')))
212 .($title ? " title='$title'":'')." />\n";
215 function button_cell($name, $value, $title=false, $icon=false)
218 button($name, $value, $title, $icon);
222 function delete_button_cell($name, $value, $title=false)
224 button_cell($name, $value, $title, ICON_DELETE);
227 function edit_button_cell($name, $value, $title=false)
229 button_cell($name, $value, $title, ICON_EDIT);
232 //-----------------------------------------------------------------------------------
234 function start_row($param="")
237 echo "<tr $param>\n";
249 for ($i = 0; $i < $num; $i++)
253 $ajax_divs = array();
255 function div_start($id='', $trigger=null, $non_ajax=false)
259 if ($non_ajax) { // div for non-ajax elements
260 array_push($ajax_divs, array($id, null));
261 echo "<div style='display:none' class='js_only' ".($id !='' ? "id='$id'" : '').">";
262 } else { // ajax ready div
263 array_push($ajax_divs, array($id, $trigger===null ? $id : $trigger));
264 echo "<div ". ($id !='' ? "id='$id'" : '').">";
271 global $ajax_divs, $Ajax;
273 if (count($ajax_divs))
275 $div = array_pop($ajax_divs);
276 if ($div[1] !== null)
277 $Ajax->addUpdate($div[1], $div[0], ob_get_flush());
283 External page call with saving current context.
284 $call - url of external page
285 $ctx - optional. name of SESSION context object or array of names of POST
286 variables saved on call
288 function context_call($call, $ctx='')
292 foreach($ctx as $postname)
294 $context[$postname] = get_post($postname);
297 $context = isset($_SESSION[$ctx]) ? $_SESSION[$ctx] : null;
299 array_unshift($_SESSION['Context'], array('name' => $ctx,
301 'caller' => $_SERVER['PHP_SELF'],
306 Restores context after external page call and
307 returns array of data passed by external page.
309 function context_restore()
311 if ( count($_SESSION['Context'])) {
312 if ($_SERVER['PHP_SELF'] == $_SESSION['Context'][0]['caller']) {
313 $ctx = array_shift($_SESSION['Context']);
315 if (is_array($ctx['ctx'])) {
316 foreach($ctx['ctx'] as $name => $val)
318 $_POST[$name] = $val;
321 if ($ctx['name']!='')
322 $_SESSION[$ctx['name']] = $ctx['ctx'];
331 Return to caller page if the page was called from external context.
333 function context_return($ret)
335 if ( count($_SESSION['Context'])) {
336 $ctx = &$_SESSION['Context'][0];
338 meta_forward( $ctx['caller'] );
342 Clearing context stack after page cancel.
344 function context_reset()
346 $_SESSION['Context'] = array();
350 Context stack initialization
352 if (!isset($_SESSION['Context'])) {