2 /**********************************************************************
3 Copyright (C) 2005-2008 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 function edit_link_cell($param, $title=false)
190 label_cell("<a href='" . $_SERVER['PHP_SELF']. "?" . "$param'"
191 .($title ? " title='$title'":'').">" . _("Edit") . "</a>", "nowrap");
194 function delete_link_cell($param, $title=false)
196 label_cell("<a href='" . $_SERVER['PHP_SELF']. "?" . "$param'"
197 .($title ? " title='$title'":'') .">" . _("Delete") . "</a>", "nowrap");
200 function edit_button($name, $value, $title=false, $icon=false)
202 // php silently changes dots,spaces,'[' and characters 128-159
203 // to underscore in POST names, to maintain compatibility with register_globals
204 if (user_graphic_links() && $icon)
206 global $path_to_root;
207 $name = htmlentities(strtr($name, array('.'=>'=2E',' '=>'=20','='=>'=3D','['=>'=5B')));
208 echo "<button type='submit' class='editbutton' name='$name' value='' /><img src='$path_to_root/themes/".user_theme().
209 "/images/$icon' width='14' height='14' border='0' ".($title ? "title='$title'" : "title='$value'")." />\n";
212 echo "<input type=\"submit\" class=\"editbutton\" name=\""
213 .htmlentities(strtr($name, array('.'=>'=2E',' '=>'=20','='=>'=3D','['=>'=5B')))
214 ."\" value=\"$value\""
215 .($title ? " title='$title'":'')." />\n";
218 function edit_button_cell($name, $value, $title=false, $icon=false)
221 edit_button($name, $value, $title, $icon);
225 //-----------------------------------------------------------------------------------
227 function start_row($param="")
230 echo "<tr $param>\n";
242 for ($i = 0; $i < $num; $i++)
246 $ajax_divs = array();
248 function div_start($id='', $trigger=null, $non_ajax=false)
252 if ($non_ajax) { // div for non-ajax elements
253 array_push($ajax_divs, array($id, null));
254 echo "<div style='display:none' class='js_only' ".($id !='' ? "id='$id'" : '').">";
255 } else { // ajax ready div
256 array_push($ajax_divs, array($id, $trigger===null ? $id : $trigger));
257 echo "<div ". ($id !='' ? "id='$id'" : '').">";
264 global $ajax_divs, $Ajax;
266 if (count($ajax_divs))
268 $div = array_pop($ajax_divs);
269 if ($div[1] !== null)
270 $Ajax->addUpdate($div[1], $div[0], ob_get_flush());
276 External page call with saving current context.
277 $call - url of external page
278 $ctx - optional. name of SESSION context object or array of names of POST
279 variables saved on call
281 function context_call($call, $ctx='')
285 foreach($ctx as $postname)
287 $context[$postname] = get_post($postname);
290 $context = isset($_SESSION[$ctx]) ? $_SESSION[$ctx] : null;
292 array_unshift($_SESSION['Context'], array('name' => $ctx,
294 'caller' => $_SERVER['PHP_SELF'],
299 Restores context after external page call and
300 returns array of data passed by external page.
302 function context_restore()
304 if ( count($_SESSION['Context'])) {
305 if ($_SERVER['PHP_SELF'] == $_SESSION['Context'][0]['caller']) {
306 $ctx = array_shift($_SESSION['Context']);
308 if (is_array($ctx['ctx'])) {
309 foreach($ctx['ctx'] as $name => $val)
311 $_POST[$name] = $val;
314 if ($ctx['name']!='')
315 $_SESSION[$ctx['name']] = $ctx['ctx'];
324 Return to caller page if the page was called from external context.
326 function context_return($ret)
328 if ( count($_SESSION['Context'])) {
329 $ctx = &$_SESSION['Context'][0];
331 meta_forward( $ctx['caller'] );
335 Clearing context stack after page cancel.
337 function context_reset()
339 $_SESSION['Context'] = array();
343 Context stack initialization
345 if (!isset($_SESSION['Context'])) {