Inserted Copyright Notice and fixed graphic items
[fa-stable.git] / includes / ui / ui_controls.inc
1 <?php
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 //---------------------------------------------------------------------------------
13
14 function start_form($multi=false, $sid=false, $action="", $name="")
15 {
16         if ($name != "")
17                 $name = "name='$name'";
18         if ($action == "")
19                 $action = $_SERVER['PHP_SELF'];
20         if ($sid)
21         {
22                 if (strpos($action, "?"))
23                         $action .= "&" . SID;
24                 else
25                         $action .= "?" . SID;
26         }
27         if ($multi)
28                 echo "<form enctype='multipart/form-data' method='post' action='$action' $name>\n";
29         else
30                 echo "<form method='post' action='$action' $name>\n";
31
32 }
33
34 //---------------------------------------------------------------------------------
35
36 function end_form($breaks=0)
37 {
38         if ($breaks)
39                 br($breaks);
40         echo "<input type=\"hidden\" name=\"_focus\" value=\"".get_post('_focus')."\">\n";
41         echo "</form>\n";
42 }
43
44 function start_table($extra="", $padding='2', $spacing='0')
45 {
46         echo "<center><table";
47         if ($extra != "")
48                 echo " $extra";
49         echo " cellpadding=$padding cellspacing=$spacing>\n";
50 }
51
52 function end_table($breaks=0)
53 {
54         echo "</table></center>\n";
55         if ($breaks)
56                 br($breaks);
57 }
58
59 function meta_forward($forward_to, $params="")
60 {
61     global $Ajax;
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);
67         exit;
68 }
69
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.
75 //
76 function access_string($label, $clean=false)
77 {
78         $access = '';
79         $slices = array();
80
81         if (preg_match('/(.*)&([a-zA-Z0-9])(.*)/', $label, $slices))    
82         {
83                 $label = $clean ? $slices[1].$slices[2].$slices[3] :
84                         $slices[1].'<u>'.$slices[2].'</u>'.$slices[3];
85                 $access = " accesskey='".strtoupper($slices[2])."'";
86         }
87         
88         $label = str_replace( '&&', '&', $label);
89
90         return $clean ? $label : array($label, $access);
91 }
92
93 function hyperlink_back($center=true)
94 {
95         if ($center)
96                 echo "<center>";
97         //echo "<a href='javascript:goBack();'>"._("Back")."</a>\n";
98         echo "<p><a href='javascript:goBack();'>"._("Back")."</a></p>\n";
99         if ($center)
100                 echo "</center>";
101         echo "<br>";
102 }
103
104 function hyperlink_no_params($target, $label, $center=true)
105 {
106         $pars = access_string($label);
107         if ($center)
108                 echo "<br><center>";
109         echo "<a href='$target?=" . SID . "'$pars[1]>$pars[0]</a>\n";
110         if ($center)
111                 echo "</center>";
112 }
113
114 function hyperlink_no_params_td($target, $label)
115 {
116         echo "<td>";
117         hyperlink_no_params($target, $label);
118         echo "</td>\n";
119 }
120
121 //-----------------------------------------------------------------------------------
122
123 function hyperlink_params($target, $label, $params, $center=true)
124 {
125         $pars = access_string($label);
126         if ($center)
127                 echo "<br><center>";
128         echo "<a href='$target?$params'$pars[1]>$pars[0]</a>\n";
129         if ($center)
130                 echo "</center>";
131 }
132
133 function hyperlink_params_td($target, $label, $params)
134 {
135         echo "<td>";
136         hyperlink_params($target, $label, $params, false);
137         echo "</td>\n";
138 }
139
140 //-----------------------------------------------------------------------------------
141
142 function hyperlink_params_separate($target, $label, $params, $center=false)
143 {
144         $pars = access_string($label);
145         if ($center)
146                 echo "<br><center>";
147         echo "<a target='_blank' href='$target?$params" . SID . "'$pars[1]>$pars[0]</a>\n";
148         if ($center)
149                 echo "</center>";
150 }
151
152 function hyperlink_params_separate_td($target, $label, $params)
153 {
154         echo "<td>";
155         hyperlink_params_separate($target, $label, $params);
156         echo "</td>\n";
157 }
158
159 //--------------------------------------------------------------------------------------------------
160
161 function alt_table_row_color(&$k)
162 {
163         if ($k == 1)
164         {
165                 echo "<tr class='oddrow'>\n";
166                 $k = 0;
167         }
168         else
169         {
170                 echo "<tr class='evenrow'>\n";
171                 $k++;
172         }
173 }
174
175 function table_section_title($msg)
176 {
177         echo "<tr><td colspan=2 class='tableheader'>$msg</td><tr>\n";
178 }
179
180 function table_header($labels)
181 {
182         start_row();
183         foreach ($labels as $label)
184                 labelheader_cell($label);
185         end_row();
186 }
187
188 //-----------------------------------------------------------------------------------
189
190 function set_icon($icon, $title=false)
191 {
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";     
194 }
195
196 function button($name, $value, $title=false, $icon=false)
197 {
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)
201         {
202                 if ($value == _("Delete")) // Helper during implementation
203                         $icon = ICON_DELETE;
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";
207         }
208         else
209                 echo "<input type='submit' class='editbutton' name='"
210                         .htmlentities(strtr($name, array('.'=>'=2E',' '=>'=20','='=>'=3D','['=>'=5B')))
211                         ."' value='$value'"
212                         .($title ? " title='$title'":'')." />\n";
213 }
214
215 function button_cell($name, $value, $title=false, $icon=false)
216 {
217         echo "<td>";
218         button($name, $value, $title, $icon);
219         echo "</td>";
220 }
221
222 function delete_button_cell($name, $value, $title=false)
223 {
224         button_cell($name, $value, $title, ICON_DELETE);
225 }
226
227 function edit_button_cell($name, $value, $title=false)
228 {
229         button_cell($name, $value, $title, ICON_EDIT);
230 }
231
232 //-----------------------------------------------------------------------------------
233
234 function start_row($param="")
235 {
236         if ($param != "")
237                 echo "<tr $param>\n";
238         else
239                 echo "<tr>\n";
240 }
241
242 function end_row()
243 {
244         echo "</tr>\n";
245 }
246
247 function br($num=1)
248 {
249         for ($i = 0; $i < $num; $i++)
250                 echo "<br>";
251 }
252
253 $ajax_divs = array();
254
255 function div_start($id='', $trigger=null, $non_ajax=false)
256 {
257     global $ajax_divs;
258
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'" : '').">";
265                 ob_start();
266         }
267 }
268
269 function div_end()
270 {
271     global $ajax_divs, $Ajax;
272
273     if (count($ajax_divs))
274     {
275                 $div = array_pop($ajax_divs);
276                 if ($div[1] !== null)
277                         $Ajax->addUpdate($div[1], $div[0], ob_get_flush());
278                 echo "</div>";
279     }
280 }
281
282 /*
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
287 */
288 function context_call($call, $ctx='')
289 {
290         if (is_array($ctx)) 
291         {
292                 foreach($ctx as $postname)
293                 {
294                         $context[$postname] = get_post($postname);
295                 }
296         } else 
297                 $context = isset($_SESSION[$ctx]) ? $_SESSION[$ctx] : null;
298
299         array_unshift($_SESSION['Context'], array('name' => $ctx, 
300                 'ctx' => $context,
301                 'caller' => $_SERVER['PHP_SELF'],
302                 'ret' => array()));
303         meta_forward($call);
304 }
305 /*
306         Restores context after external page call and
307         returns array of data passed by external page.
308 */
309 function context_restore()
310 {
311         if ( count($_SESSION['Context'])) {
312                 if ($_SERVER['PHP_SELF'] == $_SESSION['Context'][0]['caller']) {
313                         $ctx = array_shift($_SESSION['Context']);
314                         if ($ctx) {
315                                 if (is_array($ctx['ctx'])) {
316                                         foreach($ctx['ctx'] as $name => $val) 
317                                         {
318                                                 $_POST[$name] = $val;
319                                         }
320                                 } else
321                                         if ($ctx['name']!='')
322                                                 $_SESSION[$ctx['name']] = $ctx['ctx'];
323                                 return $ctx['ret'];
324                         }
325                 }
326         }
327         return false;
328 }
329
330 /*
331         Return to caller page if the page was called from external context.
332 */
333 function context_return($ret)
334 {
335         if ( count($_SESSION['Context'])) {
336                 $ctx = &$_SESSION['Context'][0];
337                 $ctx['ret'] = $ret;
338                 meta_forward( $ctx['caller'] );
339         }
340 }
341 /*
342         Clearing context stack after page cancel.
343 */
344 function context_reset()
345 {
346         $_SESSION['Context'] = array();
347 }
348
349 /*
350         Context stack initialization
351 */
352 if (!isset($_SESSION['Context'])) {
353                 context_reset();
354 }
355
356 ?>