1 | <?php |
---|
2 | /**************************************************************************\ |
---|
3 | * eGroupWare - HTML creation class * |
---|
4 | * http://www.eGroupWare.org * |
---|
5 | * Written and (c) by Ralf Becker <RalfBecker@outdoor-training.de> * |
---|
6 | * -------------------------------------------- * |
---|
7 | * This program is free software; you can redistribute it and/or modify it * |
---|
8 | * under the terms of the GNU General Public License as published by the * |
---|
9 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
10 | * option) any later version. * |
---|
11 | \**************************************************************************/ |
---|
12 | |
---|
13 | |
---|
14 | class html |
---|
15 | { |
---|
16 | var $user_agent,$ua_version; // 'mozilla','msie','konqueror' |
---|
17 | var $prefered_img_title; |
---|
18 | var $charset,$phpgwapi_js_url; |
---|
19 | var $need_footer = False; // do we need to be called at the end of the page |
---|
20 | |
---|
21 | function html() |
---|
22 | { |
---|
23 | // should be Ok for all HTML 4 compatible browsers |
---|
24 | if (!preg_match('/(Safari)\/([0-9.]+)/i',$_SERVER['HTTP_USER_AGENT'],$parts) && |
---|
25 | !preg_match('/compatible; ([a-z_]+)[\/ ]+([0-9.]+)/i',$_SERVER['HTTP_USER_AGENT'],$parts)) |
---|
26 | { |
---|
27 | preg_match('/^([a-z_]+)\/([0-9.]+)/i',$_SERVER['HTTP_USER_AGENT'],$parts); |
---|
28 | } |
---|
29 | list(,$this->user_agent,$this->ua_version) = $parts; |
---|
30 | $this->user_agent = strtolower($this->user_agent); |
---|
31 | |
---|
32 | $this->netscape4 = $this->user_agent == 'mozilla' && $this->ua_version < 5; |
---|
33 | $this->prefered_img_title = $this->netscape4 ? 'alt' : 'title'; |
---|
34 | //echo "<p>HTTP_USER_AGENT='$_SERVER[HTTP_USER_AGENT]', UserAgent: '$this->user_agent', Version: '$this->ua_version', img_title: '$this->prefered_img_title'</p>\n"; |
---|
35 | |
---|
36 | if ($GLOBALS['phpgw']->translation) |
---|
37 | { |
---|
38 | $this->charset = $GLOBALS['phpgw']->translation->charset(); |
---|
39 | } |
---|
40 | $this->phpgwapi_js_url = $GLOBALS['phpgw_info']['server']['webserver_url'].'/phpgwapi/js'; |
---|
41 | } |
---|
42 | |
---|
43 | /** |
---|
44 | * Created an input-field with an attached tigra color-picker |
---|
45 | * |
---|
46 | * Please note: it need to be called before the call to phpgw_header() !!! |
---|
47 | * |
---|
48 | * @param $name string the name of the input-field |
---|
49 | * @param $value string the actual value for the input-field, default '' |
---|
50 | * @param $title string tooltip/title for the picker-activation-icon |
---|
51 | */ |
---|
52 | function inputColor($name,$value='',$title='') |
---|
53 | { |
---|
54 | $id = str_replace(array('[',']'),array('_',''),$name).'_colorpicker'; |
---|
55 | $onclick = "if (this != '') { window.open(this+'&color='+encodeURIComponent(document.getElementById('$id').value),this.target,'width=240,height=187,scrollbars=no,resizable=no'); return false; } else { return true; }"; |
---|
56 | return '<input type="text" name="'.$name.'" id="'.$id.'" value="'.$this->htmlspecialchars($value).'" /> '. |
---|
57 | '<a href="'.$this->phpgwapi_js_url.'/colorpicker/select_color.html?id='.urlencode($id).'" target="_blank" onclick="'.$onclick.'">'. |
---|
58 | '<img src="'.$this->phpgwapi_js_url.'/colorpicker/ed_color_bg.gif'.'"'.($title ? ' title="'.$this->htmlspecialchars($title).'"' : '')." /></a>"; |
---|
59 | } |
---|
60 | |
---|
61 | /** |
---|
62 | * Handles tooltips via the wz_tooltip class from Walter Zorn |
---|
63 | * |
---|
64 | * Note: The wz_tooltip.js file gets automaticaly loaded at the end of the page |
---|
65 | * |
---|
66 | * @param $text string/boolean text or html for the tooltip, all chars allowed, they will be quoted approperiate |
---|
67 | * Or if False the content (innerHTML) of the element itself is used. |
---|
68 | * @param $do_lang boolean (default False) should the text be run though lang() |
---|
69 | * @param $options array param/value pairs, eg. 'TITLE' => 'I am the title'. Some common parameters: |
---|
70 | * title (string) gives extra title-row, width (int,'auto') , padding (int), above (bool), bgcolor (color), bgimg (URL) |
---|
71 | * For a complete list and description see http://www.walterzorn.com/tooltip/tooltip_e.htm |
---|
72 | * @return string to be included in any tag, like '<p'.$html->tooltip('Hello <b>Ralf</b>').'>Text with tooltip</p>' |
---|
73 | */ |
---|
74 | function tooltip($text,$do_lang=False,$options=False) |
---|
75 | { |
---|
76 | if (!$this->wz_tooltip_included) |
---|
77 | { |
---|
78 | if (!strstr('wz_tooltip',$GLOBALS['phpgw_info']['flags']['need_footer'])) |
---|
79 | { |
---|
80 | $GLOBALS['phpgw_info']['flags']['need_footer'] .= '<script language="JavaScript" type="text/javascript" src="'.$this->phpgwapi_js_url.'/wz_tooltip/wz_tooltip.js"></script>'."\n"; |
---|
81 | } |
---|
82 | $this->wz_tooltip_included = True; |
---|
83 | } |
---|
84 | if ($do_lang) $text = lang($text); |
---|
85 | |
---|
86 | $opt_out = ''; |
---|
87 | if (is_array($options)) |
---|
88 | { |
---|
89 | foreach($options as $option => $value) |
---|
90 | { |
---|
91 | $opt_out .= 'this.T_'.strtoupper($option).'='.(is_numeric($value)?$value:"'".str_replace("'","\\'",$value)."'").'; '; |
---|
92 | } |
---|
93 | } |
---|
94 | if ($text === False) return ' onmouseover="'.$opt_out.'return escape(this.innerHTML);"'; |
---|
95 | |
---|
96 | return ' onmouseover="'.$opt_out.'return escape(\''.str_replace(array("\n","\r","'",'"'),array('<br/>','',"\\'",'"'),$text).'\')"'; |
---|
97 | } |
---|
98 | |
---|
99 | function activate_links($content) |
---|
100 | { |
---|
101 | // Exclude everything which is already a link |
---|
102 | $NotAnchor = '(?<!"|href=|href\s=\s|href=\s|href\s=)'; |
---|
103 | |
---|
104 | // spamsaver emailaddress |
---|
105 | $result = preg_replace('/'.$NotAnchor.'mailto:([a-z0-9._-]+)@([a-z0-9_-]+)\.([a-z0-9._-]+)/i', |
---|
106 | '<a href="#" onclick="document.location=\'mai\'+\'lto:\\1\'+unescape(\'%40\')+\'\\2.\\3\'; return false;">\\1 AT \\2 DOT \\3</a>', |
---|
107 | $content); |
---|
108 | |
---|
109 | // First match things beginning with http:// (or other protocols) |
---|
110 | $Protocol = '(http|ftp|https):\/\/'; |
---|
111 | $Domain = '([\w]+.[\w]+)'; |
---|
112 | $Subdir = '([\w\-\.,@?^=%&;:\/~\+#]*[\w\-\@?^=%&\/~\+#])?'; |
---|
113 | $Expr = '/' . $NotAnchor . $Protocol . $Domain . $Subdir . '/i'; |
---|
114 | |
---|
115 | $result = preg_replace( $Expr, "<a href=\"$0\" target=\"_blank\">$2$3</a>", $result ); |
---|
116 | |
---|
117 | // Now match things beginning with www. |
---|
118 | $NotHTTP = '(?<!:\/\/)'; |
---|
119 | $Domain = 'www(.[\w]+)'; |
---|
120 | $Subdir = '([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?'; |
---|
121 | $Expr = '/' . $NotAnchor . $NotHTTP . $Domain . $Subdir . '/i'; |
---|
122 | |
---|
123 | return preg_replace( $Expr, "<a href=\"http://$0\" target=\"_blank\">$0</a>", $result ); |
---|
124 | } |
---|
125 | |
---|
126 | function htmlspecialchars($str) |
---|
127 | { |
---|
128 | // add @ by lkneschke to supress warning about unknown charset |
---|
129 | $str = @htmlspecialchars($str,ENT_COMPAT,$this->charset); |
---|
130 | |
---|
131 | // we need '&#' unchanged, so we translate it back |
---|
132 | $str = str_replace(array('&#','&nbsp;','&lt;','&gt;'),array('&#',' ','<','>'),$str); |
---|
133 | |
---|
134 | return $str; |
---|
135 | } |
---|
136 | |
---|
137 | /*! |
---|
138 | @function select |
---|
139 | @abstract allows to show and select one item from an array |
---|
140 | @param $name string with name of the submitted var which holds the key of the selected item form array |
---|
141 | @param $key key(s) of already selected item(s) from $arr, eg. '1' or '1,2' or array with keys |
---|
142 | @param $arr array with items to select, eg. $arr = array ( 'y' => 'yes','n' => 'no','m' => 'maybe'); |
---|
143 | @param $no_lang if !$no_lang send items through lang() |
---|
144 | @param $options additional options (e.g. 'width') |
---|
145 | @param $multiple number of lines for a multiselect, default 0 = no multiselect |
---|
146 | @returns string to set for a template or to echo into html page |
---|
147 | */ |
---|
148 | function select($name, $key, $arr=0,$no_lang=0,$options='',$multiple=0) |
---|
149 | { |
---|
150 | // should be in class common.sbox |
---|
151 | if (!is_array($arr)) |
---|
152 | { |
---|
153 | $arr = array('no','yes'); |
---|
154 | } |
---|
155 | if ((int)$multiple > 0) |
---|
156 | { |
---|
157 | $options .= ' multiple="1" size="'.(int)$multiple.'"'; |
---|
158 | if (substr($name,-2) != '[]') |
---|
159 | { |
---|
160 | $name .= '[]'; |
---|
161 | } |
---|
162 | } |
---|
163 | $out = "<select name=\"$name\" $options>\n"; |
---|
164 | |
---|
165 | if (!is_array($key)) |
---|
166 | { |
---|
167 | // explode on ',' only if multiple values expected and the key contains just numbers and commas |
---|
168 | $key = $multiple && preg_match('/^[,0-9]+$/',$key) ? explode(',',$key) : array($key); |
---|
169 | } |
---|
170 | foreach($arr as $k => $text) |
---|
171 | { |
---|
172 | $out .= '<option value="'.$this->htmlspecialchars($k).'"'; |
---|
173 | |
---|
174 | if(in_array($k,$key)) |
---|
175 | { |
---|
176 | $out .= ' selected="1"'; |
---|
177 | } |
---|
178 | $out .= ">" . $this->htmlspecialchars($no_lang || $text == '' ? $text : lang($text)) . "</option>\n"; |
---|
179 | } |
---|
180 | $out .= "</select>\n"; |
---|
181 | |
---|
182 | return $out; |
---|
183 | } |
---|
184 | |
---|
185 | function div($content,$options='',$class='',$style='') |
---|
186 | { |
---|
187 | if ($class) $options .= ' class="'.$class.'"'; |
---|
188 | if ($style) $options .= ' style="'.$style.'"'; |
---|
189 | |
---|
190 | return "<div $options>\n".($content ? "$content</div>\n" : ''); |
---|
191 | } |
---|
192 | |
---|
193 | function input_hidden($vars,$value='',$ignore_empty=True) |
---|
194 | { |
---|
195 | if (!is_array($vars)) |
---|
196 | { |
---|
197 | $vars = array( $vars => $value ); |
---|
198 | } |
---|
199 | foreach($vars as $name => $value) |
---|
200 | { |
---|
201 | if (is_array($value)) |
---|
202 | { |
---|
203 | $value = serialize($value); |
---|
204 | } |
---|
205 | if (!$ignore_empty || $value && !($name == 'filter' && $value == 'none')) // dont need to send all the empty vars |
---|
206 | { |
---|
207 | $html .= "<input type=\"hidden\" name=\"$name\" value=\"".$this->htmlspecialchars($value)."\" />\n"; |
---|
208 | } |
---|
209 | } |
---|
210 | return $html; |
---|
211 | } |
---|
212 | |
---|
213 | function textarea($name,$value='',$options='' ) |
---|
214 | { |
---|
215 | return "<textarea name=\"$name\" $options>".$this->htmlspecialchars($value)."</textarea>\n"; |
---|
216 | } |
---|
217 | |
---|
218 | function input($name,$value='',$type='',$options='' ) |
---|
219 | { |
---|
220 | if ($type) |
---|
221 | { |
---|
222 | $type = 'type="'.$type.'"'; |
---|
223 | } |
---|
224 | return "<input $type name=\"$name\" value=\"".$this->htmlspecialchars($value)."\" $options />\n"; |
---|
225 | } |
---|
226 | |
---|
227 | function submit_button($name,$lang,$onClick='',$no_lang=0,$options='',$image='',$app='phpgwapi') |
---|
228 | { |
---|
229 | // workaround for idots and IE button problem (wrong cursor-image) |
---|
230 | if ($this->user_agent == 'msie') |
---|
231 | { |
---|
232 | $options .= ' style="cursor: pointer; cursor: hand;"'; |
---|
233 | } |
---|
234 | if ($image != '') |
---|
235 | { |
---|
236 | $image = str_replace(array('.gif','.GIF','.png','.PNG'),'',$image); |
---|
237 | |
---|
238 | if (!($path = $GLOBALS['phpgw']->common->image($app,$image))) |
---|
239 | { |
---|
240 | $path = $image; // name may already contain absolut path |
---|
241 | } |
---|
242 | $image = ' src="'.$path.'"'; |
---|
243 | } |
---|
244 | if (!$no_lang) |
---|
245 | { |
---|
246 | $lang = lang($lang); |
---|
247 | } |
---|
248 | if (($accesskey = strstr($lang,'&')) && $accesskey[1] != ' ' && |
---|
249 | (($pos = strpos($accesskey,';')) === False || $pos > 5)) |
---|
250 | { |
---|
251 | $lang_u = str_replace('&'.$accesskey[1],'<u>'.$accesskey[1].'</u>',$lang); |
---|
252 | $lang = str_replace('&','',$lang); |
---|
253 | $options = 'accesskey="'.$accesskey[1].'" '.$options; |
---|
254 | } |
---|
255 | else |
---|
256 | { |
---|
257 | $accesskey = ''; |
---|
258 | $lang_u = $lang; |
---|
259 | } |
---|
260 | if ($onClick) $options .= " onclick=\"$onClick\""; |
---|
261 | |
---|
262 | // <button> is not working in all cases if ($this->user_agent == 'mozilla' && $this->ua_version < 5 || $image) |
---|
263 | { |
---|
264 | return $this->input($name,$lang,$image != '' ? 'image' : 'submit',$options.$image); |
---|
265 | } |
---|
266 | return '<button type="submit" name="'.$name.'" value="'.$lang.'" '.$options.' />'. |
---|
267 | ($image != '' ? "<img$image $this->prefered_img_title=\"$lang\"> " : ''). |
---|
268 | ($image == '' || $accesskey ? $lang_u : '').'</button>'; |
---|
269 | } |
---|
270 | |
---|
271 | /** |
---|
272 | * creates an absolut link + the query / get-variables |
---|
273 | * |
---|
274 | * Example link('/index.php?menuaction=infolog.uiinfolog.get_list',array('info_id' => 123)) |
---|
275 | * gives 'http://domain/phpgw-path/index.php?menuaction=infolog.uiinfolog.get_list&info_id=123' |
---|
276 | * @param $url phpgw-relative link, may include query / get-vars |
---|
277 | * @param $vars query or array ('name' => 'value', ...) with query |
---|
278 | * @return string absolut link already run through $phpgw->link |
---|
279 | */ |
---|
280 | function link($url,$vars='') |
---|
281 | { |
---|
282 | //echo "<p>html::link(url='$url',vars='"; print_r($vars); echo "')</p>\n"; |
---|
283 | if (!is_array($vars)) |
---|
284 | { |
---|
285 | parse_str($vars,$vars); |
---|
286 | } |
---|
287 | list($url,$v) = explode('?',$url); // url may contain additional vars |
---|
288 | if ($v) |
---|
289 | { |
---|
290 | parse_str($v,$v); |
---|
291 | $vars += $v; |
---|
292 | } |
---|
293 | return $GLOBALS['phpgw']->link($url,$vars); |
---|
294 | } |
---|
295 | |
---|
296 | function checkbox($name,$value='') |
---|
297 | { |
---|
298 | return "<input type=\"checkbox\" name=\"$name\" value=\"True\"" .($value ? ' checked="1"' : '') . " />\n"; |
---|
299 | } |
---|
300 | |
---|
301 | function form($content,$hidden_vars,$url,$url_vars='',$name='',$options='',$method='POST') |
---|
302 | { |
---|
303 | $html = "<form method=\"$method\" ".($name != '' ? "name=\"$name\" " : '')."action=\"".$this->link($url,$url_vars)."\" $options>\n"; |
---|
304 | $html .= $this->input_hidden($hidden_vars); |
---|
305 | |
---|
306 | if ($content) |
---|
307 | { |
---|
308 | $html .= $content; |
---|
309 | $html .= "</form>\n"; |
---|
310 | } |
---|
311 | return $html; |
---|
312 | } |
---|
313 | |
---|
314 | function form_1button($name,$lang,$hidden_vars,$url,$url_vars='',$form_name='',$method='POST') |
---|
315 | { |
---|
316 | return $this->form($this->submit_button($name,$lang),$hidden_vars,$url,$url_vars,$form_name,'',$method); |
---|
317 | } |
---|
318 | |
---|
319 | /** |
---|
320 | * creates table from array of rows |
---|
321 | * |
---|
322 | * abstracts the html stuff for the table creation |
---|
323 | * Example: $rows = array ( |
---|
324 | * '1' => array( |
---|
325 | * 1 => 'cell1', '.1' => 'colspan=3', |
---|
326 | * 2 => 'cell2', |
---|
327 | * 3 => 'cell3', '.3' => 'width="10%"' |
---|
328 | * ),'.1' => 'BGCOLOR="#0000FF"' ); |
---|
329 | * table($rows,'width="100%"') = '<table width="100%"><tr><td colspan=3>cell1</td><td>cell2</td><td width="10%">cell3</td></tr></table>' |
---|
330 | * @param $rows array with rows, each row is an array of the cols |
---|
331 | * @param $options options for the table-tag |
---|
332 | * @result string with html-code of the table |
---|
333 | */ |
---|
334 | function table($rows,$options = '',$no_table_tr=False) |
---|
335 | { |
---|
336 | $html = $no_table_tr ? '' : "<table $options>\n"; |
---|
337 | |
---|
338 | foreach($rows as $key => $row) |
---|
339 | { |
---|
340 | if (!is_array($row)) |
---|
341 | { |
---|
342 | continue; // parameter |
---|
343 | } |
---|
344 | $html .= $no_table_tr && $key == 1 ? '' : "\t<tr ".$rows['.'.$key].">\n"; |
---|
345 | |
---|
346 | foreach($row as $key => $cell) |
---|
347 | { |
---|
348 | if ($key[0] == '.') |
---|
349 | { |
---|
350 | continue; // parameter |
---|
351 | } |
---|
352 | $table_pos = strpos($cell,'<table'); |
---|
353 | $td_pos = strpos($cell,'<td'); |
---|
354 | if ($td_pos !== False && ($table_pos === False || $td_pos < $table_pos)) |
---|
355 | { |
---|
356 | $html .= $cell; |
---|
357 | } |
---|
358 | else |
---|
359 | { |
---|
360 | $html .= "\t\t<td ".$row['.'.$key].">$cell</td>\n"; |
---|
361 | } |
---|
362 | } |
---|
363 | $html .= "\t</tr>\n"; |
---|
364 | } |
---|
365 | $html .= "</table>\n"; |
---|
366 | |
---|
367 | if ($no_table_tr) |
---|
368 | { |
---|
369 | $html = substr($html,0,-16); |
---|
370 | } |
---|
371 | return $html; |
---|
372 | } |
---|
373 | |
---|
374 | function sbox_submit( $sbox,$no_script=0 ) |
---|
375 | { |
---|
376 | $html = str_replace('<select','<select onchange="this.form.submit()" ',$sbox); |
---|
377 | if ($no_script) |
---|
378 | { |
---|
379 | $html .= '<noscript>'.$this->submit_button('send','>').'</noscript>'; |
---|
380 | } |
---|
381 | return $html; |
---|
382 | } |
---|
383 | |
---|
384 | function progressbar( $percent,$title='',$options='',$width='',$color='',$height='' ) |
---|
385 | { |
---|
386 | $percent = (int) $percent; |
---|
387 | if (!$width) $width = '30px'; |
---|
388 | if (!$height)$height= '5px'; |
---|
389 | if (!$color) $color = '#D00000'; |
---|
390 | $title = $title ? $this->htmlspecialchars($title) : $percent.'%'; |
---|
391 | |
---|
392 | if ($this->netscape4) |
---|
393 | { |
---|
394 | return $title; |
---|
395 | } |
---|
396 | return '<div title="'.$title.'" '.$options. |
---|
397 | ' style="height: '.$height.'; width: '.$width.'; border: 1px solid black; padding: 1px;'. |
---|
398 | (stristr($options,'onclick="') ? ' cursor: pointer; cursor: hand;' : '').'">'."\n\t". |
---|
399 | '<div style="height: '.$height.'; width: '.$percent.'%; background: '.$color.';"></div>'."\n</div>\n"; |
---|
400 | } |
---|
401 | |
---|
402 | function image( $app,$name,$title='',$options='' ) |
---|
403 | { |
---|
404 | $name = str_replace(array('.gif','.GIF','.png','.PNG'),'',$name); |
---|
405 | |
---|
406 | if (!($path = $GLOBALS['phpgw']->common->image($app,$name))) |
---|
407 | { |
---|
408 | $path = $name; // name may already contain absolut path |
---|
409 | } |
---|
410 | if (!@is_readable(str_replace($GLOBALS['phpgw_info']['server']['webserver_url'],PHPGW_SERVER_ROOT,$path))) |
---|
411 | { |
---|
412 | // if the image-name is a percentage, use a progressbar |
---|
413 | if (substr($name,-1) == '%' && is_numeric($percent = substr($name,0,-1))) |
---|
414 | { |
---|
415 | return $this->progressbar($percent,$title); |
---|
416 | } |
---|
417 | return $title; |
---|
418 | } |
---|
419 | if ($title) |
---|
420 | { |
---|
421 | $options .= " $this->prefered_img_title=\"".$this->htmlspecialchars($title).'"'; |
---|
422 | } |
---|
423 | return "<img src=\"$path\" $options />"; |
---|
424 | } |
---|
425 | |
---|
426 | function a_href( $content,$url,$vars='',$options='') |
---|
427 | { |
---|
428 | if (!strstr($url,'/') && count(explode('.',$url)) == 3) |
---|
429 | { |
---|
430 | $url = "/index.php?menuaction=$url"; |
---|
431 | } |
---|
432 | if (is_array($url)) |
---|
433 | { |
---|
434 | $vars = $url; |
---|
435 | $url = '/index.php'; |
---|
436 | } |
---|
437 | //echo "<p>html::a_href('".htmlspecialchars($content)."','$url',".print_r($vars,True).") = ".$this->link($url,$vars)."</p>"; |
---|
438 | return '<a href="'.$this->link($url,$vars).'" '.$options.'>'.$content.'</a>'; |
---|
439 | } |
---|
440 | |
---|
441 | function bold($content) |
---|
442 | { |
---|
443 | return '<b>'.$content.'</b>'; |
---|
444 | } |
---|
445 | |
---|
446 | function italic($content) |
---|
447 | { |
---|
448 | return '<i>'.$content.'</i>'; |
---|
449 | } |
---|
450 | |
---|
451 | function hr($width,$options='') |
---|
452 | { |
---|
453 | if ($width) $options .= " width=\"$width\""; |
---|
454 | return "<hr $options />\n"; |
---|
455 | } |
---|
456 | |
---|
457 | /** |
---|
458 | * formats option-string for most of the above functions |
---|
459 | * |
---|
460 | * Example: formatOptions('100%,,1','width,height,border') = ' width="100%" border="1"' |
---|
461 | * @param $options mixed String (or Array) with option-values eg. '100%,,1' |
---|
462 | * @param $names mixed String (or Array) with the option-names eg. 'WIDTH,HEIGHT,BORDER' |
---|
463 | * @result string with options/attributes |
---|
464 | */ |
---|
465 | function formatOptions($options,$names) |
---|
466 | { |
---|
467 | if (!is_array($options)) $options = explode(',',$options); |
---|
468 | if (!is_array($names)) $names = explode(',',$names); |
---|
469 | |
---|
470 | foreach($options as $n => $val) |
---|
471 | { |
---|
472 | if ($val != '' && $names[$n] != '') |
---|
473 | { |
---|
474 | $html .= ' '.strtolower($names[$n]).'="'.$val.'"'; |
---|
475 | } |
---|
476 | } |
---|
477 | return $html; |
---|
478 | } |
---|
479 | |
---|
480 | /** |
---|
481 | * returns simple stylesheet (incl. <STYLE> tags) for nextmatch row-colors |
---|
482 | * @result the classes 'th' = nextmatch header, 'row_on'+'row_off' = alternating rows |
---|
483 | */ |
---|
484 | function themeStyles() |
---|
485 | { |
---|
486 | return $this->style($this->theme2css()); |
---|
487 | } |
---|
488 | |
---|
489 | /** |
---|
490 | * returns simple stylesheet for nextmatch row-colors |
---|
491 | * @result the classes 'th' = nextmatch header, 'row_on'+'row_off' = alternating rows |
---|
492 | */ |
---|
493 | function theme2css() |
---|
494 | { |
---|
495 | return ".th { background: ".$GLOBALS['phpgw_info']['theme']['th_bg']."; }\n". |
---|
496 | ".row_on,.th_bright { background: ".$GLOBALS['phpgw_info']['theme']['row_on']."; }\n". |
---|
497 | ".row_off { background: ".$GLOBALS['phpgw_info']['theme']['row_off']."; }\n"; |
---|
498 | } |
---|
499 | |
---|
500 | function style($styles) |
---|
501 | { |
---|
502 | return $styles ? "<style type=\"text/css\">\n<!--\n$styles\n-->\n</style>" : ''; |
---|
503 | } |
---|
504 | |
---|
505 | function label($content,$id='',$accesskey='',$options='') |
---|
506 | { |
---|
507 | if ($id != '') |
---|
508 | { |
---|
509 | $id = " for=\"$id\""; |
---|
510 | } |
---|
511 | if ($accesskey != '') |
---|
512 | { |
---|
513 | $accesskey = " accesskey=\"$accesskey\""; |
---|
514 | } |
---|
515 | return "<label$id$accesskey $options>$content</label>"; |
---|
516 | } |
---|
517 | } |
---|