Commit | Line | Data |
---|---|---|
ca8aa8e9 DO |
1 | <?php |
2 | ||
d3535346 DO |
3 | define ('TAGNAME_REGEXP', '/^[\p{L}0-9]([. _~-]?[\p{L}0-9])*$/u'); |
4 | define ('AUTOTAGNAME_REGEXP', '/^\$[\p{L}0-9]([. _~-]?[\p{L}0-9])*$/u'); | |
5 | ||
ca8aa8e9 DO |
6 | // Let's have it here, so extensions can add their own images. |
7 | $image = array(); | |
8 | $image['logo']['path'] = 'pix/defaultlogo.png'; | |
9 | $image['logo']['width'] = 210; | |
10 | $image['logo']['height'] = 40; | |
11 | $image['rackspace']['path'] = 'pix/racks.png'; | |
12 | $image['rackspace']['width'] = 218; | |
13 | $image['rackspace']['height'] = 200; | |
14 | $image['objects']['path'] = 'pix/server.png'; | |
15 | $image['objects']['width'] = 218; | |
16 | $image['objects']['height'] = 200; | |
17 | $image['depot']['path'] = 'pix/server.png'; | |
18 | $image['depot']['width'] = 218; | |
19 | $image['depot']['height'] = 200; | |
20 | $image['files']['path'] = 'pix/files.png'; | |
21 | $image['files']['width'] = 218; | |
22 | $image['files']['height'] = 200; | |
23 | $image['ipv4space']['path'] = 'pix/addressspace.png'; | |
24 | $image['ipv4space']['width'] = 218; | |
25 | $image['ipv4space']['height'] = 200; | |
26 | $image['ipv6space']['path'] = 'pix/addressspacev6.png'; | |
27 | $image['ipv6space']['width'] = 218; | |
28 | $image['ipv6space']['height'] = 200; | |
29 | $image['ipv4slb']['path'] = 'pix/slb.png'; | |
30 | $image['ipv4slb']['width'] = 218; | |
31 | $image['ipv4slb']['height'] = 200; | |
32 | $image['config']['path'] = 'pix/configuration.png'; | |
33 | $image['config']['width'] = 218; | |
34 | $image['config']['height'] = 200; | |
35 | $image['reports']['path'] = 'pix/report.png'; | |
36 | $image['reports']['width'] = 218; | |
37 | $image['reports']['height'] = 200; | |
38 | $image['8021q']['path'] = 'pix/8021q.png'; | |
39 | $image['8021q']['width'] = 218; | |
40 | $image['8021q']['height'] = 200; | |
41 | $image['objectlog']['path'] = 'pix/crystal-mimetypes-shellscript-218x200.png'; | |
42 | $image['objectlog']['width'] = 218; | |
43 | $image['objectlog']['height'] = 200; | |
44 | $image['virtual']['path'] = 'pix/virtualresources.png'; | |
45 | $image['virtual']['width'] = 218; | |
46 | $image['virtual']['height'] = 200; | |
47 | $image['download']['path'] = 'pix/download.png'; | |
48 | $image['download']['width'] = 16; | |
49 | $image['download']['height'] = 16; | |
50 | $image['DOWNLOAD']['path'] = 'pix/download-big.png'; | |
51 | $image['DOWNLOAD']['width'] = 32; | |
52 | $image['DOWNLOAD']['height'] = 32; | |
53 | $image['plug']['path'] = 'pix/tango-network-wired.png'; | |
54 | $image['plug']['width'] = 16; | |
55 | $image['plug']['height'] = 16; | |
56 | $image['cut']['path'] = 'pix/tango-edit-cut-16x16.png'; | |
57 | $image['cut']['width'] = 16; | |
58 | $image['cut']['height'] = 16; | |
59 | $image['Cut']['path'] = 'pix/tango-edit-cut-22x22.png'; | |
60 | $image['Cut']['width'] = 22; | |
61 | $image['Cut']['height'] = 22; | |
75a01117 DO |
62 | $image['Cut gray']['path'] = 'pix/tango-edit-cut-22x22-gray.png'; |
63 | $image['Cut gray']['width'] = 22; | |
64 | $image['Cut gray']['height'] = 22; | |
ca8aa8e9 DO |
65 | $image['CUT']['path'] = 'pix/tango-edit-cut-32x32.png'; |
66 | $image['CUT']['width'] = 32; | |
67 | $image['CUT']['height'] = 32; | |
68 | $image['add']['path'] = 'pix/tango-list-add.png'; | |
69 | $image['add']['width'] = 16; | |
70 | $image['add']['height'] = 16; | |
71 | $image['ADD']['path'] = 'pix/tango-list-add-big.png'; | |
72 | $image['ADD']['width'] = 32; | |
73 | $image['ADD']['height'] = 32; | |
74 | $image['delete']['path'] = 'pix/tango-list-remove.png'; | |
75 | $image['delete']['width'] = 16; | |
76 | $image['delete']['height'] = 16; | |
77 | $image['DELETE']['path'] = 'pix/tango-list-remove-32x32.png'; | |
78 | $image['DELETE']['width'] = 32; | |
79 | $image['DELETE']['height'] = 32; | |
80 | $image['destroy']['path'] = 'pix/tango-user-trash-16x16.png'; | |
81 | $image['destroy']['width'] = 16; | |
82 | $image['destroy']['height'] = 16; | |
83 | $image['nodestroy']['path'] = 'pix/tango-user-trash-16x16-gray.png'; | |
84 | $image['nodestroy']['width'] = 16; | |
85 | $image['nodestroy']['height'] = 16; | |
86 | $image['NODESTROY']['path'] = 'pix/tango-user-trash-32x32-gray.png'; | |
87 | $image['NODESTROY']['width'] = 32; | |
88 | $image['NODESTROY']['height'] = 32; | |
89 | $image['DESTROY']['path'] = 'pix/tango-user-trash-32x32.png'; | |
90 | $image['DESTROY']['width'] = 32; | |
91 | $image['DESTROY']['height'] = 32; | |
92 | $image['nodelete']['path'] = 'pix/tango-list-remove-shadow.png'; | |
93 | $image['nodelete']['width'] = 16; | |
94 | $image['nodelete']['height'] = 16; | |
95 | $image['inservice']['path'] = 'pix/tango-emblem-system.png'; | |
96 | $image['inservice']['width'] = 16; | |
97 | $image['inservice']['height'] = 16; | |
98 | $image['notinservice']['path'] = 'pix/tango-dialog-error.png'; | |
99 | $image['notinservice']['width'] = 16; | |
100 | $image['notinservice']['height'] = 16; | |
101 | $image['find']['path'] = 'pix/tango-system-search.png'; | |
102 | $image['find']['width'] = 16; | |
103 | $image['find']['height'] = 16; | |
104 | $image['next']['path'] = 'pix/tango-go-next.png'; | |
105 | $image['next']['width'] = 32; | |
106 | $image['next']['height'] = 32; | |
107 | $image['prev']['path'] = 'pix/tango-go-previous.png'; | |
108 | $image['prev']['width'] = 32; | |
109 | $image['prev']['height'] = 32; | |
110 | $image['COMMIT']['path'] = 'pix/tango-go-prev-next-32x32.png'; | |
111 | $image['COMMIT']['width'] = 32; | |
112 | $image['COMMIT']['height'] = 32; | |
113 | $image['COMMIT gray']['path'] = 'pix/tango-go-prev-next-gray-32x32.png'; | |
114 | $image['COMMIT gray']['width'] = 32; | |
115 | $image['COMMIT gray']['height'] = 32; | |
116 | $image['RECALC']['path'] = 'pix/tango-view-refresh-32x32.png'; | |
117 | $image['RECALC']['width'] = 32; | |
118 | $image['RECALC']['height'] = 32; | |
119 | $image['clear']['path'] = 'pix/tango-edit-clear.png'; | |
120 | $image['clear']['width'] = 16; | |
121 | $image['clear']['height'] = 16; | |
122 | $image['CLEAR']['path'] = 'pix/tango-edit-clear-big.png'; | |
123 | $image['CLEAR']['width'] = 32; | |
124 | $image['CLEAR']['height'] = 32; | |
125 | $image['CLEAR gray']['path'] = 'pix/tango-edit-clear-gray-32x32.png'; | |
126 | $image['CLEAR gray']['width'] = 32; | |
127 | $image['CLEAR gray']['height'] = 32; | |
128 | $image['save']['path'] = 'pix/tango-document-save-16x16.png'; | |
129 | $image['save']['width'] = 16; | |
130 | $image['save']['height'] = 16; | |
131 | $image['SAVE']['path'] = 'pix/tango-document-save-32x32.png'; | |
132 | $image['SAVE']['width'] = 32; | |
133 | $image['SAVE']['height'] = 32; | |
134 | $image['NOSAVE']['path'] = 'pix/tango-document-save-32x32-gray.png'; | |
135 | $image['NOSAVE']['width'] = 32; | |
136 | $image['NOSAVE']['height'] = 32; | |
137 | $image['create']['path'] = 'pix/tango-document-new.png'; | |
138 | $image['create']['width'] = 16; | |
139 | $image['create']['height'] = 16; | |
140 | $image['CREATE']['path'] = 'pix/tango-document-new-big.png'; | |
141 | $image['CREATE']['width'] = 32; | |
142 | $image['CREATE']['height'] = 32; | |
143 | $image['DENIED']['path'] = 'pix/tango-dialog-error-big.png'; | |
144 | $image['DENIED']['width'] = 32; | |
145 | $image['DENIED']['height'] = 32; | |
146 | $image['node-collapsed']['path'] = 'pix/node-collapsed.png'; | |
147 | $image['node-collapsed']['width'] = 16; | |
148 | $image['node-collapsed']['height'] = 16; | |
149 | $image['node-expanded']['path'] = 'pix/node-expanded.png'; | |
150 | $image['node-expanded']['width'] = 16; | |
151 | $image['node-expanded']['height'] = 16; | |
152 | $image['node-expanded-static']['path'] = 'pix/node-expanded-static.png'; | |
153 | $image['node-expanded-static']['width'] = 16; | |
154 | $image['node-expanded-static']['height'] = 16; | |
155 | $image['dragons']['path'] = 'pix/mitsudragon.png'; | |
156 | $image['dragons']['width'] = 195; | |
157 | $image['dragons']['height'] = 33; | |
158 | $image['LB']['path'] = 'pix/loadbalancer.png'; | |
159 | $image['LB']['width'] = 32; | |
160 | $image['LB']['height'] = 32; | |
161 | $image['RS pool']['path'] = 'pix/serverpool.png'; | |
162 | $image['RS pool']['width'] = 48; | |
163 | $image['RS pool']['height'] = 16; | |
164 | $image['VS']['path'] = 'pix/servicesign.png'; | |
165 | $image['VS']['width'] = 39; | |
166 | $image['VS']['height'] = 62; | |
167 | $image['router']['path'] = 'pix/router.png'; | |
168 | $image['router']['width'] = 32; | |
169 | $image['router']['height'] = 32; | |
170 | $image['object']['path'] = 'pix/bracket-16x16.png'; | |
171 | $image['object']['width'] = 16; | |
172 | $image['object']['height'] = 16; | |
173 | $image['OBJECT']['path'] = 'pix/bracket-32x32.png'; | |
174 | $image['OBJECT']['width'] = 32; | |
175 | $image['OBJECT']['height'] = 32; | |
176 | $image['attach']['path'] = 'pix/tango-mail-attachment-16x16.png'; | |
177 | $image['attach']['width'] = 16; | |
178 | $image['attach']['height'] = 16; | |
179 | $image['Attach']['path'] = 'pix/tango-mail-attachment-22x22.png'; | |
180 | $image['Attach']['width'] = 22; | |
181 | $image['Attach']['height'] = 22; | |
182 | $image['ATTACH']['path'] = 'pix/tango-mail-attachment-32x32.png'; | |
183 | $image['ATTACH']['width'] = 32; | |
184 | $image['ATTACH']['height'] = 32; | |
185 | $image['favorite']['path'] = 'pix/tango-emblem-favorite.png'; | |
186 | $image['favorite']['width'] = 16; | |
187 | $image['favorite']['height'] = 16; | |
188 | $image['computer']['path'] = 'pix/tango-computer.png'; | |
189 | $image['computer']['width'] = 16; | |
190 | $image['computer']['height'] = 16; | |
191 | $image['empty file']['path'] = 'pix/crystal-file-empty-32x32.png'; | |
192 | $image['empty file']['width'] = 32; | |
193 | $image['empty file']['height'] = 32; | |
194 | $image['text file']['path'] = 'pix/crystal-file-text-32x32.png'; | |
195 | $image['text file']['width'] = 32; | |
196 | $image['text file']['height'] = 32; | |
197 | $image['image file']['path'] = 'pix/crystal-file-image-32x32.png'; | |
198 | $image['image file']['width'] = 32; | |
199 | $image['image file']['height'] = 32; | |
200 | $image['text']['path'] = 'pix/tango-text-x-generic-16x16.png'; | |
201 | $image['text']['width'] = 16; | |
202 | $image['text']['height'] = 16; | |
203 | $image['NET']['path'] = 'pix/crystal-network_local-32x32.png'; | |
204 | $image['NET']['width'] = 32; | |
205 | $image['NET']['height'] = 32; | |
206 | $image['net']['path'] = 'pix/crystal-network_local-16x16.png'; | |
207 | $image['net']['width'] = 16; | |
208 | $image['net']['height'] = 16; | |
209 | $image['USER']['path'] = 'pix/crystal-edit-user-32x32.png'; | |
210 | $image['USER']['width'] = 32; | |
211 | $image['USER']['height'] = 32; | |
212 | $image['setfilter']['path'] = 'pix/pgadmin3-viewfiltereddata.png'; | |
213 | $image['setfilter']['width'] = 32; | |
214 | $image['setfilter']['height'] = 32; | |
215 | $image['setfilter gray']['path'] = 'pix/pgadmin3-viewfiltereddata-grayscale.png'; | |
216 | $image['setfilter gray']['width'] = 32; | |
217 | $image['setfilter gray']['height'] = 32; | |
218 | $image['resetfilter']['path'] = 'pix/pgadmin3-viewdata.png'; | |
219 | $image['resetfilter']['width'] = 32; | |
220 | $image['resetfilter']['height'] = 32; | |
221 | $image['resetfilter gray']['path'] = 'pix/pgadmin3-viewdata-grayscale.png'; | |
222 | $image['resetfilter gray']['width'] = 32; | |
223 | $image['resetfilter gray']['height'] = 32; | |
224 | $image['knight']['path'] = 'pix/smiley_knight.png'; | |
225 | $image['knight']['width'] = 72; | |
226 | $image['knight']['height'] = 33; | |
227 | $image['Zoom']['path'] = 'pix/tango-system-search-22x22.png'; | |
228 | $image['Zoom']['width'] = 22; | |
229 | $image['Zoom']['height'] = 22; | |
230 | $image['Zooming']['path'] = 'pix/tango-view-fullscreen-22x22.png'; | |
231 | $image['Zooming']['width'] = 22; | |
232 | $image['Zooming']['height'] = 22; | |
233 | $image['UNLOCK']['path'] = 'pix/crystal-actions-unlock-32x32.png'; | |
234 | $image['UNLOCK']['width'] = 32; | |
235 | $image['UNLOCK']['height'] = 32; | |
236 | $image['CLOCK']['path'] = 'pix/tango-appointment-32x32.png'; | |
237 | $image['CLOCK']['width'] = 32; | |
238 | $image['CLOCK']['height'] = 32; | |
239 | $image['DQUEUE done']['path'] = 'pix/crystal-ok-32x32.png'; | |
240 | $image['DQUEUE done']['width'] = 32; | |
241 | $image['DQUEUE done']['height'] = 32; | |
242 | $image['DQUEUE sync_aging']['path'] = 'pix/tango-appointment-32x32.png'; | |
243 | $image['DQUEUE sync_aging']['width'] = 32; | |
244 | $image['DQUEUE sync_aging']['height'] = 32; | |
245 | $image['DQUEUE resync_aging']['path'] = 'pix/tango-appointment-32x32.png'; | |
246 | $image['DQUEUE resync_aging']['width'] = 32; | |
247 | $image['DQUEUE resync_aging']['height'] = 32; | |
248 | $image['DQUEUE sync_ready']['path'] = 'pix/tango-emblem-system-32x32.png'; | |
249 | $image['DQUEUE sync_ready']['width'] = 32; | |
250 | $image['DQUEUE sync_ready']['height'] = 32; | |
251 | $image['DQUEUE resync_ready']['path'] = 'pix/tango-emblem-important-32x32.png'; | |
252 | $image['DQUEUE resync_ready']['width'] = 32; | |
253 | $image['DQUEUE resync_ready']['height'] = 32; | |
254 | $image['DQUEUE failed']['path'] = 'pix/tango-emblem-unreadable-32x32.png'; | |
255 | $image['DQUEUE failed']['width'] = 32; | |
256 | $image['DQUEUE failed']['height'] = 32; | |
257 | $image['DQUEUE disabled']['path'] = 'pix/tango-emblem-readonly-32x32.png'; | |
258 | $image['DQUEUE disabled']['width'] = 32; | |
259 | $image['DQUEUE disabled']['height'] = 32; | |
260 | $image['COPY']['path'] = 'pix/tango-edit-copy-32x32.png'; | |
261 | $image['COPY']['width'] = 32; | |
262 | $image['COPY']['height'] = 32; | |
263 | $image['html']['path'] = 'pix/tango-text-html.png'; | |
264 | $image['html']['width'] = 16; | |
265 | $image['html']['height'] = 16; | |
266 | ||
267 | function printSelect ($optionList, $select_attrs = array(), $selected_id = NULL) | |
268 | { | |
269 | echo getSelect ($optionList, $select_attrs, $selected_id); | |
270 | } | |
271 | ||
272 | // Input array keys are OPTION VALUEs and input array values are OPTION text. | |
c4ad9ac0 | 273 | function getSelect ($optionList, $select_attrs = array(), $selected_id = NULL, $treat_single_special = TRUE) |
ca8aa8e9 DO |
274 | { |
275 | $ret = ''; | |
276 | if (!array_key_exists ('name', $select_attrs)) | |
277 | return ''; | |
278 | // handle two corner cases in a specific way | |
279 | if (count ($optionList) == 0) | |
280 | return '(none)'; | |
c4ad9ac0 | 281 | if (count ($optionList) == 1 && $treat_single_special) |
ca8aa8e9 DO |
282 | { |
283 | foreach ($optionList as $key => $value) { break; } | |
284 | return "<input type=hidden name=${select_attrs['name']} id=${select_attrs['name']} value=${key}>" . $value; | |
285 | } | |
286 | if (!array_key_exists ('id', $select_attrs)) | |
287 | $select_attrs['id'] = $select_attrs['name']; | |
288 | $ret .= '<select'; | |
289 | foreach ($select_attrs as $attr_name => $attr_value) | |
290 | $ret .= " ${attr_name}=${attr_value}"; | |
291 | $ret .= '>'; | |
292 | foreach ($optionList as $dict_key => $dict_value) | |
293 | $ret .= "<option value='${dict_key}'" . ($dict_key == $selected_id ? ' selected' : '') . ">${dict_value}</option>"; | |
294 | $ret .= '</select>'; | |
295 | return $ret; | |
296 | } | |
297 | ||
298 | function printNiftySelect ($groupList, $select_attrs = array(), $selected_id = NULL, $autocomplete = false) | |
299 | { | |
300 | echo getNiftySelect ($groupList, $select_attrs, $selected_id); | |
301 | } | |
302 | ||
303 | // Input is a cooked list of OPTGROUPs, each with own sub-list of OPTIONs in the same | |
304 | // format as printSelect() expects. | |
7232ef01 AD |
305 | // If tree is true, hierarchical drop-boxes are used, otherwise optgroups are used. |
306 | function getNiftySelect ($groupList, $select_attrs, $selected_id = NULL, $tree = false) | |
ca8aa8e9 DO |
307 | { |
308 | // special treatment for ungrouped data | |
309 | if (count ($groupList) == 1 and isset ($groupList['other'])) | |
310 | return getSelect ($groupList['other'], $select_attrs, $selected_id); | |
311 | if (!array_key_exists ('name', $select_attrs)) | |
312 | return ''; | |
313 | if (!array_key_exists ('id', $select_attrs)) | |
314 | $select_attrs['id'] = $select_attrs['name']; | |
7232ef01 | 315 | if ($tree) |
ca8aa8e9 | 316 | { |
2f06f6be DO |
317 | # it is safe to call many times for the same file |
318 | addJS ('js/jquery.optionTree.js'); | |
7232ef01 AD |
319 | $ret = "<input type=hidden name=${select_attrs['name']}>\n"; |
320 | $ret .= "<script type='text/javascript'>\n"; | |
321 | $ret .= "\$(function() {\n"; | |
322 | $ret .= " var option_tree = {\n"; | |
323 | foreach ($groupList as $groupname => $groupdata) | |
324 | { | |
325 | $ret .= " '${groupname}': {"; | |
326 | foreach ($groupdata as $dict_key => $dict_value) | |
327 | $ret .= "\"${dict_value}\":'${dict_key}', "; | |
328 | $ret .= "},\n"; | |
329 | } | |
330 | $ret .= " };\n"; | |
30dce055 | 331 | $ret .= " var options = {empty_value: '', choose: 'select...'};\n"; |
7232ef01 AD |
332 | $ret .= " \$('input[name=${select_attrs['name']}]').optionTree(option_tree, options);\n"; |
333 | $ret .= "});\n"; | |
334 | $ret .= "</script>\n"; | |
335 | } | |
336 | else | |
337 | { | |
338 | $ret = '<select'; | |
339 | foreach ($select_attrs as $attr_name => $attr_value) | |
340 | $ret .= " ${attr_name}=${attr_value}"; | |
341 | $ret .= ">\n"; | |
342 | foreach ($groupList as $groupname => $groupdata) | |
343 | { | |
344 | $ret .= "<optgroup label='${groupname}'>\n"; | |
345 | foreach ($groupdata as $dict_key => $dict_value) | |
346 | $ret .= "<option value='${dict_key}'" . ($dict_key == $selected_id ? ' selected' : '') . ">${dict_value}</option>\n"; | |
347 | $ret .= "</optgroup>\n"; | |
348 | } | |
349 | $ret .= "</select>\n"; | |
ca8aa8e9 | 350 | } |
ca8aa8e9 DO |
351 | return $ret; |
352 | } | |
353 | ||
16d86b28 DO |
354 | function getOptionTree ($tree_name, $tree_options, $tree_config = array()) |
355 | { | |
356 | function serializeJSArray ($tree_options) | |
357 | { | |
358 | $self = __FUNCTION__; | |
359 | $tmp = array(); | |
360 | foreach ($tree_options as $option_label => $option_value) | |
361 | $tmp[] = "\"${option_label}\": " . (is_array ($option_value) ? $self ($option_value) : "${option_value}"); | |
362 | return '{' . implode (', ', $tmp) . "}\n"; | |
363 | } | |
364 | ||
365 | $default_config = array | |
366 | ( | |
367 | 'choose' => 'select...', | |
368 | 'empty_value' => '', | |
369 | ); | |
370 | foreach ($tree_config as $cfgoption_name => $cfgoption_value) | |
371 | $default_config[$cfgoption_name] = $cfgoption_value; | |
372 | # it is safe to call many times for the same file | |
373 | addJS ('js/jquery.optionTree.js'); | |
374 | $ret = "<input type=hidden name=${tree_name}>\n"; | |
375 | $ret .= "<script type='text/javascript'>\n"; | |
376 | $ret .= "\$(function() {\n"; | |
377 | $ret .= " var option_tree = " . serializeJSArray ($tree_options) . ";\n"; | |
378 | $ret .= " var options = " . serializeJSArray ($default_config) . ";\n"; | |
379 | $ret .= " \$('input[name=${tree_name}]').optionTree(option_tree, options);\n"; | |
380 | $ret .= "});\n"; | |
381 | $ret .= "</script>\n"; | |
382 | return $ret; | |
383 | } | |
384 | ||
ca8aa8e9 DO |
385 | function printImageHREF ($tag, $title = '', $do_input = FALSE, $tabindex = 0) |
386 | { | |
387 | echo getImageHREF ($tag, $title, $do_input, $tabindex); | |
388 | } | |
389 | ||
390 | // this would be better called mkIMG(), make "IMG" HTML element | |
391 | function getImageHREF ($tag, $title = '', $do_input = FALSE, $tabindex = 0) | |
392 | { | |
393 | global $image; | |
394 | if (!isset ($image[$tag])) | |
395 | $tag = 'error'; | |
396 | $img = $image[$tag]; | |
19f22ad8 | 397 | $img['path'] = '?module=chrome&uri=' . $img['path']; |
ca8aa8e9 DO |
398 | if ($do_input == TRUE) |
399 | return | |
400 | "<input type=image name=submit class=icon " . | |
401 | "src='${img['path']}' " . | |
402 | "border=0 " . | |
403 | ($tabindex ? "tabindex=${tabindex}" : '') . | |
404 | (!strlen ($title) ? '' : " title='${title}'") . // JT: Add title to input hrefs too | |
405 | ">"; | |
406 | else | |
407 | return | |
408 | "<img " . | |
409 | "src='${img['path']}' " . | |
410 | "width=${img['width']} " . | |
411 | "height=${img['height']} " . | |
412 | "border=0 " . | |
413 | (!strlen ($title) ? '' : "title='${title}'") . | |
414 | ">"; | |
415 | } | |
416 | ||
967e3845 DO |
417 | function dos2unix ($text) |
418 | { | |
419 | return str_replace ("\r\n", "\n", $text); | |
420 | } | |
421 | ||
422 | function escapeString ($value, $do_db_escape = FALSE) | |
423 | { | |
424 | $ret = htmlspecialchars ($value, ENT_QUOTES, 'UTF-8'); | |
425 | if ($do_db_escape) | |
426 | { | |
427 | global $dbxlink; | |
428 | $ret = substr ($dbxlink->quote ($ret), 1, -1); | |
429 | } | |
430 | return $ret; | |
431 | } | |
432 | ||
433 | function transformRequestData() | |
434 | { | |
435 | global $sic; | |
436 | // Magic quotes feature is deprecated, but just in case the local system | |
437 | // still has it activated, reverse its effect. | |
dbd20c7e AA |
438 | $do_magic_quotes = (function_exists ('get_magic_quotes_gpc') and get_magic_quotes_gpc()); |
439 | $seen_keys = array(); | |
440 | ||
967e3845 DO |
441 | // Escape any globals before we ever try to use them, but keep a copy of originals. |
442 | $sic = array(); | |
4675424f AA |
443 | // walk through merged GET and POST instead of REQUEST array because it |
444 | // can contain cookies with data which could not be decoded from UTF-8 | |
4675424f | 445 | foreach (array_merge($_GET, $_POST) as $key => $value) |
967e3845 | 446 | { |
5a7dc9e7 AA |
447 | if (is_array ($value)) |
448 | $_REQUEST[$key] = $value; | |
449 | else | |
450 | { | |
451 | $value = dos2unix ($value); | |
452 | if ($do_magic_quotes) | |
453 | $value = stripslashes ($value); | |
454 | $_REQUEST[$key] = escapeString ($value); | |
455 | } | |
456 | $sic[$key] = $value; | |
dbd20c7e | 457 | $seen_keys[$key] = 1; |
967e3845 DO |
458 | } |
459 | ||
dbd20c7e AA |
460 | // delete cookie information from the $_REQUEST array |
461 | foreach (array_keys ($_REQUEST) as $key) | |
462 | if (! isset ($seen_keys[$key])) | |
463 | unset ($_REQUEST[$key]); | |
464 | ||
967e3845 DO |
465 | if (isset ($_SERVER['PHP_AUTH_USER'])) |
466 | $_SERVER['PHP_AUTH_USER'] = escapeString ($_SERVER['PHP_AUTH_USER']); | |
467 | if (isset ($_SERVER['REMOTE_USER'])) | |
468 | $_SERVER['REMOTE_USER'] = escapeString ($_SERVER['REMOTE_USER']); | |
469 | } | |
470 | ||
ca6698d8 AA |
471 | // JS scripts should be included through this function. |
472 | // They automatically appear in the <head> of your page. | |
473 | // $data is a JS filename, or JS code w/o tags around, if $inline = TRUE | |
474 | // Scripts are included in the order of adding within the same group, and groups are sorted alphabetically. | |
475 | function addJS ($data, $inline = FALSE, $group = 'default') | |
476 | { | |
477 | static $javascript = array(); | |
478 | static $seen_filenames = array(); | |
479 | ||
480 | if (! isset ($data)) | |
481 | { | |
482 | ksort ($javascript); | |
483 | return $javascript; | |
484 | } | |
485 | // Add jquery.js and racktables.js the first time a Javascript file is added. | |
486 | if (empty($javascript)) | |
487 | { | |
488 | $javascript = array | |
489 | ( | |
490 | 'a_core' => array | |
491 | ( | |
492 | array('type' => 'file', 'script' => 'js/jquery-1.4.4.min.js'), | |
493 | array('type' => 'file', 'script' => 'js/racktables.js'), | |
494 | ), | |
495 | ); | |
496 | ||
497 | // initialize core js filelist | |
498 | foreach ($javascript as $group_name => $group_array) | |
499 | foreach ($group_array as $item) | |
500 | if ($item['type'] == 'file') | |
501 | $seen_filenames[$item['script']] = 1; | |
502 | } | |
503 | ||
504 | if ($inline) | |
505 | $javascript[$group][] = array | |
506 | ( | |
507 | 'type' => 'inline', | |
508 | 'script' => $data, | |
509 | ); | |
510 | elseif (! isset ($seen_filenames[$data])) | |
511 | { | |
512 | $javascript[$group][] = array | |
513 | ( | |
514 | 'type' => 'file', | |
515 | 'script' => $data, | |
516 | ); | |
517 | $seen_filenames[$data] = 1; | |
518 | } | |
519 | } | |
520 | ||
521 | // CSS styles should be included through this function. | |
522 | // They automatically appear in the <head> of your page. | |
523 | // $data is a CSS filename, or CSS code w/o tags around, if $inline = TRUE | |
524 | // Styles are included in the order of adding. | |
525 | function addCSS ($data, $inline = FALSE) | |
526 | { | |
527 | static $styles = array(); | |
528 | static $seen_filenames = array(); | |
529 | ||
530 | if (! isset ($data)) | |
531 | return $styles; | |
532 | if ($inline) | |
533 | $styles[] = array | |
534 | ( | |
535 | 'type' => 'inline', | |
536 | 'style' => $data, | |
537 | ); | |
538 | elseif (! isset ($seen_filenames[$data])) | |
539 | { | |
540 | $styles[] = array | |
541 | ( | |
542 | 'type' => 'file', | |
543 | 'style' => $data, | |
544 | ); | |
545 | $seen_filenames[$data] = 1; | |
546 | } | |
547 | } | |
548 | ||
549 | // print part of HTML HEAD block | |
550 | function printPageHeaders () | |
551 | { | |
552 | global $pageheaders; | |
553 | ksort ($pageheaders); | |
554 | foreach ($pageheaders as $s) | |
555 | echo $s . "\n"; | |
556 | ||
557 | // add CSS styles | |
558 | foreach (addCSS (NULL) as $item) | |
559 | if ($item['type'] == 'inline') | |
560 | echo '<style type="text/css">' . "\n" . trim ($item['style'], "\r\n") . "\n</style>\n"; | |
561 | elseif ($item['type'] == 'file') | |
562 | echo "<link rel=stylesheet type='text/css' href='?module=chrome&uri=${item['style']}' />\n"; | |
563 | ||
564 | // add JS scripts | |
565 | foreach (addJS (NULL) as $group_name => $js_list) | |
566 | foreach ($js_list as $item) | |
567 | if ($item['type'] == 'inline') | |
568 | echo '<script type="text/javascript">' . "\n" . trim ($item['script'], "\r\n") . "\n</script>\n"; | |
569 | elseif ($item['type'] == 'file') | |
570 | echo "<script type='text/javascript' src='?module=chrome&uri=${item['script']}'></script>\n"; | |
571 | } | |
572 | ||
d3535346 DO |
573 | function validTagName ($s, $allow_autotag = FALSE) |
574 | { | |
575 | if (1 == preg_match (TAGNAME_REGEXP, $s)) | |
576 | return TRUE; | |
577 | if ($allow_autotag and 1 == preg_match (AUTOTAGNAME_REGEXP, $s)) | |
578 | return TRUE; | |
579 | return FALSE; | |
580 | } | |
581 | ||
221327e3 DO |
582 | function serializeTags ($chain, $baseurl = '') |
583 | { | |
584 | $tmp = array(); | |
585 | foreach ($chain as $taginfo) | |
30bb83bd | 586 | { |
d3ee17b7 AA |
587 | if ($baseurl == '') |
588 | $tmp[] = $taginfo['tag']; | |
30bb83bd | 589 | else |
d3ee17b7 | 590 | { |
30bb83bd | 591 | $title = ''; |
d3ee17b7 AA |
592 | if (isset ($taginfo['user']) and isset ($taginfo['time'])) |
593 | $title = 'title="' . htmlspecialchars ($taginfo['user'] . ', ' . formatAge ($taginfo['time']), ENT_QUOTES) . '"'; | |
594 | $tmp[] = "<a $title href='${baseurl}cft[]=${taginfo['id']}'>" . $taginfo['tag'] . "</a>"; | |
595 | } | |
30bb83bd | 596 | } |
221327e3 DO |
597 | return implode (', ', $tmp); |
598 | } | |
599 | ||
2030a7f2 AA |
600 | function startPortlet ($title = '') |
601 | { | |
602 | echo "<div class=portlet><h2>${title}</h2>"; | |
603 | } | |
604 | ||
605 | function finishPortlet () | |
606 | { | |
607 | echo "</div>\n"; | |
608 | } | |
609 | ||
ca8aa8e9 | 610 | ?> |