Menu hotkeys system implementation.
[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 // Find and replace hotkey marker.
63 // if $clean == true marker is removed and clean label is returned 
64 // (for use in wiki help system), otherwise result is array of label 
65 // with underlined hotkey letter and access property string.
66 //
67 function access_string($label, $clean=false)
68 {
69         $access = '';
70         $slices = array();
71
72         if (preg_match('/(.*)&([a-zA-Z0-9])(.*)/', $label, $slices))    
73         {
74                 $label = $clean ? $slices[1].$slices[2].$slices[3] :
75                         $slices[1].'<u>'.$slices[2].'</u>'.$slices[3];
76                 $access = " accesskey='".strtoupper($slices[2])."'";
77         }
78         
79         $label = str_replace( '&&', '&', $label);
80
81         return $clean ? $label : array($label, $access);
82 }
83
84 function hyperlink_back($center=true)
85 {
86         if ($center)
87                 echo "<center>";
88         //echo "<a href='javascript:goBack();'>"._("Back")."</a>\n";
89         echo "<p><a href='javascript:goBack();'>"._("Back")."</a></p>\n";
90         if ($center)
91                 echo "</center>";
92         echo "<br>";
93 }
94
95 function hyperlink_no_params($target, $label, $center=true)
96 {
97         $pars = access_string($label);
98         if ($center)
99                 echo "<br><center>";
100         echo "<a href='$target?=" . SID . "'$pars[1]>$pars[0]</a>\n";
101         if ($center)
102                 echo "</center>";
103 }
104
105 function hyperlink_no_params_td($target, $label)
106 {
107         echo "<td>";
108         hyperlink_no_params($target, $label);
109         echo "</td>\n";
110 }
111
112 //-----------------------------------------------------------------------------------
113
114 function hyperlink_params($target, $label, $params, $center=true)
115 {
116         $pars = access_string($label);
117         if ($center)
118                 echo "<br><center>";
119         echo "<a href='$target?$params'$pars[1]>$pars[0]</a>\n";
120         if ($center)
121                 echo "</center>";
122 }
123
124 function hyperlink_params_td($target, $label, $params)
125 {
126         echo "<td>";
127         hyperlink_params($target, $label, $params, false);
128         echo "</td>\n";
129 }
130
131 //-----------------------------------------------------------------------------------
132
133 function hyperlink_params_separate($target, $label, $params, $center=false)
134 {
135         $pars = access_string($label);
136         if ($center)
137                 echo "<br><center>";
138         echo "<a target='_blank' href='$target?$params" . SID . "'$pars[1]>$pars[0]</a>\n";
139         if ($center)
140                 echo "</center>";
141 }
142
143 function hyperlink_params_separate_td($target, $label, $params)
144 {
145         echo "<td>";
146         hyperlink_params_separate($target, $label, $params);
147         echo "</td>\n";
148 }
149
150 //--------------------------------------------------------------------------------------------------
151
152 function alt_table_row_color(&$k)
153 {
154         if ($k == 1)
155         {
156                 echo "<tr class='oddrow'>\n";
157                 $k = 0;
158         }
159         else
160         {
161                 echo "<tr class='evenrow'>\n";
162                 $k++;
163         }
164 }
165
166 function table_section_title($msg)
167 {
168         echo "<tr><td colspan=2 class='tableheader'>$msg</td><tr>\n";
169 }
170
171 function table_header($labels)
172 {
173         start_row();
174         foreach ($labels as $label)
175                 labelheader_cell($label);
176         end_row();
177 }
178
179 function edit_link_cell($param, $title=false)
180 {
181     label_cell("<a href='" . $_SERVER['PHP_SELF']. "?" . "$param'"
182         .($title ? " title='$title'":'').">" . _("Edit") . "</a>", "nowrap");
183 }
184
185 function delete_link_cell($param, $title=false)
186 {
187     label_cell("<a href='" . $_SERVER['PHP_SELF']. "?" . "$param'"
188         .($title ? " title='$title'":'') .">" . _("Delete") . "</a>", "nowrap");
189 }
190
191 function edit_button($name, $value, $title=false)
192 {
193 // php silently changes dots,spaces,'[' and characters 128-159
194 // to underscore in POST names, to maintain compatibility with register_globals
195         echo "<input type=\"submit\" class=\"editbutton\" name=\""
196                 .htmlentities(strtr($name, array('.'=>'=2E',' '=>'=20','='=>'=3D','['=>'=5B')))
197                 ."\" value=\"$value\""
198                 .($title ? " title='$title'":'')." />\n";
199 }
200
201 function edit_button_cell($name, $value, $title=false)
202 {
203         echo "<td>";
204         edit_button($name, $value, $title);
205         echo "</td>";
206 }
207
208 //-----------------------------------------------------------------------------------
209
210 function start_row($param="")
211 {
212         if ($param != "")
213                 echo "<tr $param>\n";
214         else
215                 echo "<tr>\n";
216 }
217
218 function end_row()
219 {
220         echo "</tr>\n";
221 }
222
223 function br($num=1)
224 {
225         for ($i = 0; $i < $num; $i++)
226                 echo "<br>";
227 }
228
229 $ajax_divs = array();
230
231 function div_start($id='', $trigger=null, $non_ajax=false)
232 {
233     global $ajax_divs;
234
235         if ($non_ajax) { // div for non-ajax elements
236                 array_push($ajax_divs, array($id, null));
237                 echo "<div style='display:none' class='js_only' ".($id !='' ? "id='$id'" : '').">";
238         } else { // ajax ready div
239                 array_push($ajax_divs, array($id, $trigger===null ? $id : $trigger));
240                 echo "<div ". ($id !='' ? "id='$id'" : '').">";
241                 ob_start();
242         }
243 }
244
245 function div_end()
246 {
247     global $ajax_divs, $Ajax;
248
249     if (count($ajax_divs))
250     {
251                 $div = array_pop($ajax_divs);
252                 if ($div[1] !== null)
253                         $Ajax->addUpdate($div[1], $div[0], ob_get_flush());
254                 echo "</div>";
255     }
256 }
257
258 /*
259         External page call with saving current context.
260         $call - url of external page
261         $ctx - optional. name of SESSION context object or array of names of POST 
262                 variables saved on call
263 */
264 function context_call($call, $ctx='')
265 {
266         if (is_array($ctx)) 
267         {
268                 foreach($ctx as $postname)
269                 {
270                         $context[$postname] = get_post($postname);
271                 }
272         } else 
273                 $context = isset($_SESSION[$ctx]) ? $_SESSION[$ctx] : null;
274
275         array_unshift($_SESSION['Context'], array('name' => $ctx, 
276                 'ctx' => $context,
277                 'caller' => $_SERVER['PHP_SELF'],
278                 'ret' => array()));
279         meta_forward($call);
280 }
281 /*
282         Restores context after external page call and
283         returns array of data passed by external page.
284 */
285 function context_restore()
286 {
287         if ( count($_SESSION['Context'])) {
288                 if ($_SERVER['PHP_SELF'] == $_SESSION['Context'][0]['caller']) {
289                         $ctx = array_shift($_SESSION['Context']);
290                         if ($ctx) {
291                                 if (is_array($ctx['ctx'])) {
292                                         foreach($ctx['ctx'] as $name => $val) 
293                                         {
294                                                 $_POST[$name] = $val;
295                                         }
296                                 } else
297                                         if ($ctx['name']!='')
298                                                 $_SESSION[$ctx['name']] = $ctx['ctx'];
299                                 return $ctx['ret'];
300                         }
301                 }
302         }
303         return false;
304 }
305
306 /*
307         Return to caller page if the page was called from external context.
308 */
309 function context_return($ret)
310 {
311         if ( count($_SESSION['Context'])) {
312                 $ctx = &$_SESSION['Context'][0];
313                 $ctx['ret'] = $ret;
314                 meta_forward( $ctx['caller'] );
315         }
316 }
317 /*
318         Clearing context stack after page cancel.
319 */
320 function context_reset()
321 {
322         $_SESSION['Context'] = array();
323 }
324
325 /*
326         Context stack initialization
327 */
328 if (!isset($_SESSION['Context'])) {
329                 context_reset();
330 }
331
332 ?>