Merged bugfixes upto [0000072] (version 2.0.3).
[fa-stable.git] / includes / ui / ui_controls.inc
1 <?php
2
3 //---------------------------------------------------------------------------------
4
5 function start_form($multi=false, $sid=false, $action="", $name="")
6 {
7         if ($name != "")
8                 $name = "name='$name'";
9         if ($action == "")
10                 $action = $_SERVER['PHP_SELF'];
11         if ($sid)
12         {
13                 if (strpos($action, "?"))
14                         $action .= "&" . SID;
15                 else
16                         $action .= "?" . SID;
17         }
18         if ($multi)
19                 echo "<form enctype='multipart/form-data' method='post' action='$action' $name>\n";
20         else
21                 echo "<form method='post' action='$action' $name>\n";
22
23 }
24
25 //---------------------------------------------------------------------------------
26
27 function end_form($breaks=0)
28 {
29         if ($breaks)
30                 br($breaks);
31         echo "<input type=\"hidden\" name=\"_focus\" value=\"".get_post('_focus')."\">\n";
32         echo "</form>\n";
33 }
34
35 function start_table($extra="", $padding='2', $spacing='0')
36 {
37         echo "<center><table";
38         if ($extra != "")
39                 echo " $extra";
40         echo " cellpadding=$padding cellspacing=$spacing>\n";
41 }
42
43 function end_table($breaks=0)
44 {
45         echo "</table></center>\n";
46         if ($breaks)
47                 br($breaks);
48 }
49
50 function meta_forward($forward_to, $params="")
51 {
52     global $Ajax;
53         echo "<meta http-equiv='Refresh' content='0; url=$forward_to?$params'>\n";
54         echo "<center><br>" . _("You should automatically be forwarded.");
55         echo " " . _("If this does not happen") . " " . "<a href='$forward_to?$params'>" . _("click here") . "</a> " . _("to continue") . ".<br><br></center>\n";
56         if ($params !='') $params = '?'.$params;
57         $Ajax->redirect($forward_to.$params);
58         exit;
59 }
60
61 //-----------------------------------------------------------------------------------
62
63 function hyperlink_back($center=true)
64 {
65         if ($center)
66                 echo "<center>";
67         //echo "<a href='javascript:goBack();'>"._("Back")."</a>\n";
68         echo "<p><a href='javascript:goBack();'>"._("Back")."</a></p>\n";
69         if ($center)
70                 echo "</center>";
71         echo "<br>";
72 }
73
74 function hyperlink_no_params($target, $label, $center=true)
75 {
76         if ($center)
77                 echo "<br><center>";
78         echo "<a href='$target?=" . SID . "'>$label</a>\n";
79         if ($center)
80                 echo "</center>";
81 }
82
83 function hyperlink_no_params_td($target, $label)
84 {
85         echo "<td>";
86         hyperlink_no_params($target, $label);
87         echo "</td>\n";
88 }
89
90 //-----------------------------------------------------------------------------------
91
92 function hyperlink_params($target, $label, $params, $center=true)
93 {
94         if ($center)
95                 echo "<br><center>";
96         echo "<a href='$target?$params'>$label</a>\n";
97         if ($center)
98                 echo "</center>";
99 }
100
101 function hyperlink_params_td($target, $label, $params)
102 {
103         echo "<td>";
104         hyperlink_params($target, $label, $params, false);
105         echo "</td>\n";
106 }
107
108 //-----------------------------------------------------------------------------------
109
110 function hyperlink_params_separate($target, $label, $params, $center=false)
111 {
112         if ($center)
113                 echo "<br><center>";
114         echo "<a target='_blank' href='$target?$params" . SID . "'>$label</a>\n";
115         if ($center)
116                 echo "</center>";
117 }
118
119 function hyperlink_params_separate_td($target, $label, $params)
120 {
121         echo "<td>";
122         hyperlink_params_separate($target, $label, $params);
123         echo "</td>\n";
124 }
125
126 //--------------------------------------------------------------------------------------------------
127
128 function alt_table_row_color(&$k)
129 {
130         if ($k == 1)
131         {
132                 echo "<tr class='oddrow'>\n";
133                 $k = 0;
134         }
135         else
136         {
137                 echo "<tr class='evenrow'>\n";
138                 $k++;
139         }
140 }
141
142 function table_section_title($msg)
143 {
144         echo "<tr><td colspan=2 class='tableheader'>$msg</td><tr>\n";
145 }
146
147 function table_header($labels)
148 {
149         start_row();
150         foreach ($labels as $label)
151                 labelheader_cell($label);
152         end_row();
153 }
154
155 function edit_link_cell($param, $title=false)
156 {
157     label_cell("<a href='" . $_SERVER['PHP_SELF']. "?" . "$param'"
158         .($title ? " title='$title'":'').">" . _("Edit") . "</a>", "nowrap");
159 }
160
161 function delete_link_cell($param, $title=false)
162 {
163     label_cell("<a href='" . $_SERVER['PHP_SELF']. "?" . "$param'"
164         .($title ? " title='$title'":'') .">" . _("Delete") . "</a>", "nowrap");
165 }
166
167 function edit_button($name, $value, $title=false)
168 {
169 // php silently changes dots,spaces,'[' and characters 128-159
170 // to underscore in POST names, to maintain compatibility with register_globals
171         echo "<input type=\"submit\" class=\"editbutton\" name=\""
172                 .htmlentities(strtr($name, array('.'=>'=2E',' '=>'=20','='=>'=3D','['=>'=5B')))
173                 ."\" value=\"$value\""
174                 .($title ? " title='$title'":'')." />\n";
175 }
176
177 function edit_button_cell($name, $value, $title=false)
178 {
179         echo "<td>";
180         edit_button($name, $value, $title);
181         echo "</td>";
182 }
183
184 //-----------------------------------------------------------------------------------
185
186 function start_row($param="")
187 {
188         if ($param != "")
189                 echo "<tr $param>\n";
190         else
191                 echo "<tr>\n";
192 }
193
194 function end_row()
195 {
196         echo "</tr>\n";
197 }
198
199 function br($num=1)
200 {
201         for ($i = 0; $i < $num; $i++)
202                 echo "<br>";
203 }
204
205 $ajax_divs = array();
206
207 function div_start($id='', $trigger=null, $non_ajax=false)
208 {
209     global $ajax_divs;
210
211         if ($non_ajax) { // div for non-ajax elements
212                 array_push($ajax_divs, array($id, null));
213                 echo "<div style='display:none' class='js_only' ".($id !='' ? "id='$id'" : '').">";
214         } else { // ajax ready div
215                 array_push($ajax_divs, array($id, $trigger===null ? $id : $trigger));
216                 echo "<div ". ($id !='' ? "id='$id'" : '').">";
217                 ob_start();
218         }
219 }
220
221 function div_end()
222 {
223     global $ajax_divs, $Ajax;
224
225     if (count($ajax_divs))
226     {
227                 $div = array_pop($ajax_divs);
228                 if ($div[1] !== null)
229                         $Ajax->addUpdate($div[1], $div[0], ob_get_flush());
230                 echo "</div>";
231     }
232 }
233
234 /*
235         External page call with saving current context.
236         $call - url of external page
237         $ctx - optional. name of SESSION context object or array of names of POST 
238                 variables saved on call
239 */
240 function context_call($call, $ctx='')
241 {
242         if (is_array($ctx)) 
243         {
244                 foreach($ctx as $postname)
245                 {
246                         $context[$postname] = get_post($postname);
247                 }
248         } else 
249                 $context = isset($_SESSION[$ctx]) ? $_SESSION[$ctx] : null;
250
251         array_unshift($_SESSION['Context'], array('name' => $ctx, 
252                 'ctx' => $context,
253                 'caller' => $_SERVER['PHP_SELF'],
254                 'ret' => array()));
255         meta_forward($call);
256 }
257 /*
258         Restores context after external page call and
259         returns array of data passed by external page.
260 */
261 function context_restore()
262 {
263         if ( count($_SESSION['Context'])) {
264                 if ($_SERVER['PHP_SELF'] == $_SESSION['Context'][0]['caller']) {
265                         $ctx = array_shift($_SESSION['Context']);
266                         if ($ctx) {
267                                 if (is_array($ctx['ctx'])) {
268                                         foreach($ctx['ctx'] as $name => $val) 
269                                         {
270                                                 $_POST[$name] = $val;
271                                         }
272                                 } else
273                                         if ($ctx['name']!='')
274                                                 $_SESSION[$ctx['name']] = $ctx['ctx'];
275                                 return $ctx['ret'];
276                         }
277                 }
278         }
279         return false;
280 }
281
282 /*
283         Return to caller page if the page was called from external context.
284 */
285 function context_return($ret)
286 {
287         if ( count($_SESSION['Context'])) {
288                 $ctx = &$_SESSION['Context'][0];
289                 $ctx['ret'] = $ret;
290                 meta_forward( $ctx['caller'] );
291         }
292 }
293 /*
294         Clearing context stack after page cancel.
295 */
296 function context_reset()
297 {
298         $_SESSION['Context'] = array();
299 }
300
301 /*
302         Context stack initialization
303 */
304 if (!isset($_SESSION['Context'])) {
305                 context_reset();
306 }
307
308 ?>