[2] | 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 (!eregi('(Safari)/([0-9.]+)',$_SERVER['HTTP_USER_AGENT'],$parts) && |
---|
| 25 | !eregi('compatible; ([a-z_]+)[/ ]+([0-9.]+)',$_SERVER['HTTP_USER_AGENT'],$parts)) |
---|
| 26 | { |
---|
| 27 | eregi('^([a-z_]+)/([0-9.]+)',$_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 | /*! |
---|
| 219 | @function htmlarea_avalible |
---|
| 220 | @author ralfbecker |
---|
| 221 | @abstract Checks if HTMLarea (or an other richtext editor) is availible for the used browser |
---|
| 222 | */ |
---|
| 223 | function htmlarea_availible() |
---|
| 224 | { |
---|
| 225 | switch($this->user_agent) |
---|
| 226 | { |
---|
| 227 | case 'msie': |
---|
| 228 | return $this->ua_version >= 5.5; |
---|
| 229 | case 'mozilla': |
---|
| 230 | return $this->ua_version >= 1.3; |
---|
| 231 | default: |
---|
| 232 | return False; |
---|
| 233 | } |
---|
| 234 | } |
---|
| 235 | |
---|
| 236 | /** |
---|
| 237 | * creates a textarea inputfield for the htmlarea js-widget (returns the necessary html and js) |
---|
| 238 | * |
---|
| 239 | * Please note: it need to be called before the call to phpgw_header() !!! |
---|
| 240 | * @author ralfbecker |
---|
| 241 | * @param $name string name and id of the input-field |
---|
| 242 | * @param $content string of the htmlarea (will be run through htmlspecialchars !!!), default '' |
---|
| 243 | * @param $style string inline styles, eg. dimension of textarea element |
---|
| 244 | * @param $base_href string set a base href to get relative image-pathes working |
---|
| 245 | * @param $plugins string plugins to load seperated by comma's, eg 'TableOperations,ContextMenu' |
---|
| 246 | * (htmlarea breaks when a plugin calls a nonexisiting lang file) |
---|
| 247 | * @return the necessary html for the textarea |
---|
| 248 | */ |
---|
| 249 | function htmlarea($name,$content='',$style='',$base_href='',$plugins='') |
---|
| 250 | { |
---|
| 251 | if (!$style) $style = 'width:100%; min-width:500px; height:300px;'; |
---|
| 252 | // check if htmlarea is availible for the browser and use a textarea if not |
---|
| 253 | if (!$this->htmlarea_availible()) |
---|
| 254 | { |
---|
| 255 | return $this->textarea($name,$content,'style="'.$style.'"'); |
---|
| 256 | } |
---|
| 257 | if (!$plugins) $plugins = 'ContextMenu,TableOperations,SpellChecker'; |
---|
| 258 | |
---|
| 259 | if (!is_object($GLOBALS['phpgw']->js)) |
---|
| 260 | { |
---|
| 261 | $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript'); |
---|
| 262 | } |
---|
| 263 | if (!strstr($GLOBALS['phpgw_info']['flags']['java_script'],'htmlarea')) |
---|
| 264 | { |
---|
| 265 | $GLOBALS['phpgw']->js->validate_file('htmlarea','htmlarea'); |
---|
| 266 | $GLOBALS['phpgw']->js->validate_file('htmlarea','dialog'); |
---|
| 267 | $lang = $GLOBALS['phpgw_info']['user']['preferences']['common']['lang']; |
---|
| 268 | if ($lang == 'en') // other lang-files are utf-8 only and incomplete (crashes htmlarea as of 3.0beta) |
---|
| 269 | { |
---|
| 270 | $GLOBALS['phpgw']->js->validate_file('htmlarea',"lang/$lang"); |
---|
| 271 | } |
---|
| 272 | else |
---|
| 273 | { |
---|
| 274 | $GLOBALS['phpgw_info']['flags']['java_script'] .= |
---|
| 275 | '<script type="text/javascript" src="'.ereg_replace('[?&]*click_history=[0-9a-f]*','', |
---|
| 276 | $GLOBALS['phpgw']->link('/phpgwapi/inc/htmlarea-lang.php',array('lang'=>$lang))).'"></script>'."\n"; |
---|
| 277 | } |
---|
| 278 | |
---|
| 279 | $GLOBALS['phpgw_info']['flags']['java_script_thirst'] .= |
---|
| 280 | '<style type="text/css">@import url(' . $this->phpgwapi_js_url . '/htmlarea/htmlarea.css);</style> |
---|
| 281 | <script type="text/javascript"> |
---|
| 282 | |
---|
| 283 | _editor_url = "'."$this->phpgwapi_js_url/htmlarea/".'"; |
---|
| 284 | // var htmlareaConfig = new HTMLArea.Config(); |
---|
| 285 | // htmlareaConfig.editorURL = '."'$this->phpgwapi_js_url/htmlarea/'; |
---|
| 286 | </script>\n"; |
---|
| 287 | |
---|
| 288 | // set a base href to get relative image-pathes working |
---|
| 289 | if ($base_href && $this->user_agent != 'msie') // HTMLarea does not work in IE with base href set !!! |
---|
| 290 | { |
---|
| 291 | $GLOBALS['phpgw_info']['flags']['java_script_thirst'] .= '<base href="'. |
---|
| 292 | ($base_href[0] != '/' && substr($base_href,0,4) != 'http' ? $GLOBALS['phpgw_info']['server']['webserver_url'].'/' : ''). |
---|
| 293 | $base_href.'" />'."\n"; |
---|
| 294 | } |
---|
| 295 | |
---|
| 296 | |
---|
| 297 | if (!empty($plugins)) |
---|
| 298 | { |
---|
| 299 | foreach(explode(',',$plugins) as $plg_name) |
---|
| 300 | { |
---|
| 301 | $plg_name = trim($plg_name); |
---|
| 302 | $plg_dir = PHPGW_SERVER_ROOT.'/phpgwapi/js/htmlarea/plugins/'.$plg_name; |
---|
| 303 | if (!@is_dir($plg_dir) || !@file_exists($plg_lang_script="$plg_dir/lang/lang.php") && !@file_exists($plg_lang_file="$plg_dir/lang/$lang.js")) |
---|
| 304 | { |
---|
| 305 | //echo "$plg_dir or $plg_lang_file not found !!!"; |
---|
| 306 | continue; // else htmlarea fails with js errors |
---|
| 307 | } |
---|
| 308 | $script_name = strtolower(preg_replace('/([A-Z][a-z]+)([A-Z][a-z]+)/','\\1-\\2',$plg_name)); |
---|
| 309 | $GLOBALS['phpgw']->js->validate_file('htmlarea',"plugins/$plg_name/$script_name"); |
---|
| 310 | if ($lang == 'en' || !@file_exists($plg_lang_script)) // other lang-files are utf-8 only and incomplete (crashes htmlarea as of 3.0beta) |
---|
| 311 | { |
---|
| 312 | $GLOBALS['phpgw']->js->validate_file('htmlarea',"plugins/$plg_name/lang/$lang"); |
---|
| 313 | } |
---|
| 314 | else |
---|
| 315 | { |
---|
| 316 | $GLOBALS['phpgw_info']['flags']['java_script'] .= |
---|
| 317 | '<script type="text/javascript" src="'.ereg_replace('[?&]*click_history=[0-9a-f]*','', |
---|
| 318 | $GLOBALS['phpgw']->link("/phpgwapi/js/htmlarea/plugins/$plg_name/lang/lang.php",array('lang'=>$lang))).'"></script>'."\n"; |
---|
| 319 | } |
---|
| 320 | //$load_plugin_string .= 'HTMLArea.loadPlugin("'.$plg_name.'");'."\n"; |
---|
| 321 | $register_plugin_string .= 'ret_editor = editor.registerPlugin("'.$plg_name.'");'."\n"; |
---|
| 322 | } |
---|
| 323 | } |
---|
| 324 | |
---|
| 325 | $GLOBALS['phpgw_info']['flags']['java_script'] .= |
---|
| 326 | '<script type="text/javascript"> |
---|
| 327 | |
---|
| 328 | /** Replacement for the replace-helperfunction to make it possible to include plugins. */ |
---|
| 329 | HTMLArea.replace = function(id, config) |
---|
| 330 | { |
---|
| 331 | var ta = HTMLArea.getElementById("textarea", id); |
---|
| 332 | |
---|
| 333 | if(ta) |
---|
| 334 | { |
---|
| 335 | editor = new HTMLArea(ta, config); |
---|
| 336 | '.$register_plugin_string.' |
---|
| 337 | ret_editor = editor.generate(); |
---|
| 338 | return ret_editor; |
---|
| 339 | } |
---|
| 340 | else |
---|
| 341 | { |
---|
| 342 | return null; |
---|
| 343 | } |
---|
| 344 | }; |
---|
| 345 | |
---|
| 346 | '.$load_plugin_string.' |
---|
| 347 | |
---|
| 348 | var htmlareaConfig = new HTMLArea.Config(); |
---|
| 349 | htmlareaConfig.editorURL = '."'$this->phpgwapi_js_url/htmlarea/';"; |
---|
| 350 | |
---|
| 351 | $GLOBALS['phpgw_info']['flags']['java_script'] .="</script>\n"; |
---|
| 352 | } |
---|
| 353 | $id = str_replace(array('[',']'),array('_',''),$name); // no brakets in the id allowed by js |
---|
| 354 | |
---|
| 355 | $GLOBALS['phpgw']->js->set_onload("HTMLArea.replace('$id',htmlareaConfig);"); |
---|
| 356 | |
---|
| 357 | if (!empty($style)) $style = " style=\"$style\""; |
---|
| 358 | |
---|
| 359 | return "<textarea name=\"$name\" id=\"$id\"$style>".$this->htmlspecialchars($content)."</textarea>\n"; |
---|
| 360 | } |
---|
| 361 | |
---|
| 362 | function input($name,$value='',$type='',$options='' ) |
---|
| 363 | { |
---|
| 364 | if ($type) |
---|
| 365 | { |
---|
| 366 | $type = 'type="'.$type.'"'; |
---|
| 367 | } |
---|
| 368 | return "<input $type name=\"$name\" value=\"".$this->htmlspecialchars($value)."\" $options />\n"; |
---|
| 369 | } |
---|
| 370 | |
---|
| 371 | function submit_button($name,$lang,$onClick='',$no_lang=0,$options='',$image='',$app='phpgwapi') |
---|
| 372 | { |
---|
| 373 | // workaround for idots and IE button problem (wrong cursor-image) |
---|
| 374 | if ($this->user_agent == 'msie') |
---|
| 375 | { |
---|
| 376 | $options .= ' style="cursor: pointer; cursor: hand;"'; |
---|
| 377 | } |
---|
| 378 | if ($image != '') |
---|
| 379 | { |
---|
| 380 | $image = str_replace(array('.gif','.GIF','.png','.PNG'),'',$image); |
---|
| 381 | |
---|
| 382 | if (!($path = $GLOBALS['phpgw']->common->image($app,$image))) |
---|
| 383 | { |
---|
| 384 | $path = $image; // name may already contain absolut path |
---|
| 385 | } |
---|
| 386 | $image = ' src="'.$path.'"'; |
---|
| 387 | } |
---|
| 388 | if (!$no_lang) |
---|
| 389 | { |
---|
| 390 | $lang = lang($lang); |
---|
| 391 | } |
---|
| 392 | if (($accesskey = strstr($lang,'&')) && $accesskey[1] != ' ' && |
---|
| 393 | (($pos = strpos($accesskey,';')) === False || $pos > 5)) |
---|
| 394 | { |
---|
| 395 | $lang_u = str_replace('&'.$accesskey[1],'<u>'.$accesskey[1].'</u>',$lang); |
---|
| 396 | $lang = str_replace('&','',$lang); |
---|
| 397 | $options = 'accesskey="'.$accesskey[1].'" '.$options; |
---|
| 398 | } |
---|
| 399 | else |
---|
| 400 | { |
---|
| 401 | $accesskey = ''; |
---|
| 402 | $lang_u = $lang; |
---|
| 403 | } |
---|
| 404 | if ($onClick) $options .= " onclick=\"$onClick\""; |
---|
| 405 | |
---|
| 406 | // <button> is not working in all cases if ($this->user_agent == 'mozilla' && $this->ua_version < 5 || $image) |
---|
| 407 | { |
---|
| 408 | return $this->input($name,$lang,$image != '' ? 'image' : 'submit',$options.$image); |
---|
| 409 | } |
---|
| 410 | return '<button type="submit" name="'.$name.'" value="'.$lang.'" '.$options.' />'. |
---|
| 411 | ($image != '' ? "<img$image $this->prefered_img_title=\"$lang\"> " : ''). |
---|
| 412 | ($image == '' || $accesskey ? $lang_u : '').'</button>'; |
---|
| 413 | } |
---|
| 414 | |
---|
| 415 | /** |
---|
| 416 | * creates an absolut link + the query / get-variables |
---|
| 417 | * |
---|
| 418 | * Example link('/index.php?menuaction=infolog.uiinfolog.get_list',array('info_id' => 123)) |
---|
| 419 | * gives 'http://domain/phpgw-path/index.php?menuaction=infolog.uiinfolog.get_list&info_id=123' |
---|
| 420 | * @param $url phpgw-relative link, may include query / get-vars |
---|
| 421 | * @param $vars query or array ('name' => 'value', ...) with query |
---|
| 422 | * @return string absolut link already run through $phpgw->link |
---|
| 423 | */ |
---|
| 424 | function link($url,$vars='') |
---|
| 425 | { |
---|
| 426 | //echo "<p>html::link(url='$url',vars='"; print_r($vars); echo "')</p>\n"; |
---|
| 427 | if (!is_array($vars)) |
---|
| 428 | { |
---|
| 429 | parse_str($vars,$vars); |
---|
| 430 | } |
---|
| 431 | list($url,$v) = explode('?',$url); // url may contain additional vars |
---|
| 432 | if ($v) |
---|
| 433 | { |
---|
| 434 | parse_str($v,$v); |
---|
| 435 | $vars += $v; |
---|
| 436 | } |
---|
| 437 | return $GLOBALS['phpgw']->link($url,$vars); |
---|
| 438 | } |
---|
| 439 | |
---|
| 440 | function checkbox($name,$value='') |
---|
| 441 | { |
---|
| 442 | return "<input type=\"checkbox\" name=\"$name\" value=\"True\"" .($value ? ' checked="1"' : '') . " />\n"; |
---|
| 443 | } |
---|
| 444 | |
---|
| 445 | function form($content,$hidden_vars,$url,$url_vars='',$name='',$options='',$method='POST') |
---|
| 446 | { |
---|
| 447 | $html = "<form method=\"$method\" ".($name != '' ? "name=\"$name\" " : '')."action=\"".$this->link($url,$url_vars)."\" $options>\n"; |
---|
| 448 | $html .= $this->input_hidden($hidden_vars); |
---|
| 449 | |
---|
| 450 | if ($content) |
---|
| 451 | { |
---|
| 452 | $html .= $content; |
---|
| 453 | $html .= "</form>\n"; |
---|
| 454 | } |
---|
| 455 | return $html; |
---|
| 456 | } |
---|
| 457 | |
---|
| 458 | function form_1button($name,$lang,$hidden_vars,$url,$url_vars='',$form_name='',$method='POST') |
---|
| 459 | { |
---|
| 460 | return $this->form($this->submit_button($name,$lang),$hidden_vars,$url,$url_vars,$form_name,'',$method); |
---|
| 461 | } |
---|
| 462 | |
---|
| 463 | /** |
---|
| 464 | * creates table from array of rows |
---|
| 465 | * |
---|
| 466 | * abstracts the html stuff for the table creation |
---|
| 467 | * Example: $rows = array ( |
---|
| 468 | * '1' => array( |
---|
| 469 | * 1 => 'cell1', '.1' => 'colspan=3', |
---|
| 470 | * 2 => 'cell2', |
---|
| 471 | * 3 => 'cell3', '.3' => 'width="10%"' |
---|
| 472 | * ),'.1' => 'BGCOLOR="#0000FF"' ); |
---|
| 473 | * table($rows,'width="100%"') = '<table width="100%"><tr><td colspan=3>cell1</td><td>cell2</td><td width="10%">cell3</td></tr></table>' |
---|
| 474 | * @param $rows array with rows, each row is an array of the cols |
---|
| 475 | * @param $options options for the table-tag |
---|
| 476 | * @result string with html-code of the table |
---|
| 477 | */ |
---|
| 478 | function table($rows,$options = '',$no_table_tr=False) |
---|
| 479 | { |
---|
| 480 | $html = $no_table_tr ? '' : "<table $options>\n"; |
---|
| 481 | |
---|
| 482 | foreach($rows as $key => $row) |
---|
| 483 | { |
---|
| 484 | if (!is_array($row)) |
---|
| 485 | { |
---|
| 486 | continue; // parameter |
---|
| 487 | } |
---|
| 488 | $html .= $no_table_tr && $key == 1 ? '' : "\t<tr ".$rows['.'.$key].">\n"; |
---|
| 489 | |
---|
| 490 | foreach($row as $key => $cell) |
---|
| 491 | { |
---|
| 492 | if ($key[0] == '.') |
---|
| 493 | { |
---|
| 494 | continue; // parameter |
---|
| 495 | } |
---|
| 496 | $table_pos = strpos($cell,'<table'); |
---|
| 497 | $td_pos = strpos($cell,'<td'); |
---|
| 498 | if ($td_pos !== False && ($table_pos === False || $td_pos < $table_pos)) |
---|
| 499 | { |
---|
| 500 | $html .= $cell; |
---|
| 501 | } |
---|
| 502 | else |
---|
| 503 | { |
---|
| 504 | $html .= "\t\t<td ".$row['.'.$key].">$cell</td>\n"; |
---|
| 505 | } |
---|
| 506 | } |
---|
| 507 | $html .= "\t</tr>\n"; |
---|
| 508 | } |
---|
| 509 | $html .= "</table>\n"; |
---|
| 510 | |
---|
| 511 | if ($no_table_tr) |
---|
| 512 | { |
---|
| 513 | $html = substr($html,0,-16); |
---|
| 514 | } |
---|
| 515 | return $html; |
---|
| 516 | } |
---|
| 517 | |
---|
| 518 | function sbox_submit( $sbox,$no_script=0 ) |
---|
| 519 | { |
---|
| 520 | $html = str_replace('<select','<select onchange="this.form.submit()" ',$sbox); |
---|
| 521 | if ($no_script) |
---|
| 522 | { |
---|
| 523 | $html .= '<noscript>'.$this->submit_button('send','>').'</noscript>'; |
---|
| 524 | } |
---|
| 525 | return $html; |
---|
| 526 | } |
---|
| 527 | |
---|
| 528 | function progressbar( $percent,$title='',$options='',$width='',$color='',$height='' ) |
---|
| 529 | { |
---|
| 530 | $percent = (int) $percent; |
---|
| 531 | if (!$width) $width = '30px'; |
---|
| 532 | if (!$height)$height= '5px'; |
---|
| 533 | if (!$color) $color = '#D00000'; |
---|
| 534 | $title = $title ? $this->htmlspecialchars($title) : $percent.'%'; |
---|
| 535 | |
---|
| 536 | if ($this->netscape4) |
---|
| 537 | { |
---|
| 538 | return $title; |
---|
| 539 | } |
---|
| 540 | return '<div title="'.$title.'" '.$options. |
---|
| 541 | ' style="height: '.$height.'; width: '.$width.'; border: 1px solid black; padding: 1px;'. |
---|
| 542 | (stristr($options,'onclick="') ? ' cursor: pointer; cursor: hand;' : '').'">'."\n\t". |
---|
| 543 | '<div style="height: '.$height.'; width: '.$percent.'%; background: '.$color.';"></div>'."\n</div>\n"; |
---|
| 544 | } |
---|
| 545 | |
---|
| 546 | function image( $app,$name,$title='',$options='' ) |
---|
| 547 | { |
---|
| 548 | $name = str_replace(array('.gif','.GIF','.png','.PNG'),'',$name); |
---|
| 549 | |
---|
| 550 | if (!($path = $GLOBALS['phpgw']->common->image($app,$name))) |
---|
| 551 | { |
---|
| 552 | $path = $name; // name may already contain absolut path |
---|
| 553 | } |
---|
| 554 | if (!@is_readable(str_replace($GLOBALS['phpgw_info']['server']['webserver_url'],PHPGW_SERVER_ROOT,$path))) |
---|
| 555 | { |
---|
| 556 | // if the image-name is a percentage, use a progressbar |
---|
| 557 | if (substr($name,-1) == '%' && is_numeric($percent = substr($name,0,-1))) |
---|
| 558 | { |
---|
| 559 | return $this->progressbar($percent,$title); |
---|
| 560 | } |
---|
| 561 | return $title; |
---|
| 562 | } |
---|
| 563 | if ($title) |
---|
| 564 | { |
---|
| 565 | $options .= " $this->prefered_img_title=\"".$this->htmlspecialchars($title).'"'; |
---|
| 566 | } |
---|
| 567 | return "<img src=\"$path\" $options />"; |
---|
| 568 | } |
---|
| 569 | |
---|
| 570 | function a_href( $content,$url,$vars='',$options='') |
---|
| 571 | { |
---|
| 572 | if (!strstr($url,'/') && count(explode('.',$url)) == 3) |
---|
| 573 | { |
---|
| 574 | $url = "/index.php?menuaction=$url"; |
---|
| 575 | } |
---|
| 576 | if (is_array($url)) |
---|
| 577 | { |
---|
| 578 | $vars = $url; |
---|
| 579 | $url = '/index.php'; |
---|
| 580 | } |
---|
| 581 | //echo "<p>html::a_href('".htmlspecialchars($content)."','$url',".print_r($vars,True).") = ".$this->link($url,$vars)."</p>"; |
---|
| 582 | return '<a href="'.$this->link($url,$vars).'" '.$options.'>'.$content.'</a>'; |
---|
| 583 | } |
---|
| 584 | |
---|
| 585 | function bold($content) |
---|
| 586 | { |
---|
| 587 | return '<b>'.$content.'</b>'; |
---|
| 588 | } |
---|
| 589 | |
---|
| 590 | function italic($content) |
---|
| 591 | { |
---|
| 592 | return '<i>'.$content.'</i>'; |
---|
| 593 | } |
---|
| 594 | |
---|
| 595 | function hr($width,$options='') |
---|
| 596 | { |
---|
| 597 | if ($width) $options .= " width=\"$width\""; |
---|
| 598 | return "<hr $options />\n"; |
---|
| 599 | } |
---|
| 600 | |
---|
| 601 | /** |
---|
| 602 | * formats option-string for most of the above functions |
---|
| 603 | * |
---|
| 604 | * Example: formatOptions('100%,,1','width,height,border') = ' width="100%" border="1"' |
---|
| 605 | * @param $options mixed String (or Array) with option-values eg. '100%,,1' |
---|
| 606 | * @param $names mixed String (or Array) with the option-names eg. 'WIDTH,HEIGHT,BORDER' |
---|
| 607 | * @result string with options/attributes |
---|
| 608 | */ |
---|
| 609 | function formatOptions($options,$names) |
---|
| 610 | { |
---|
| 611 | if (!is_array($options)) $options = explode(',',$options); |
---|
| 612 | if (!is_array($names)) $names = explode(',',$names); |
---|
| 613 | |
---|
| 614 | foreach($options as $n => $val) |
---|
| 615 | { |
---|
| 616 | if ($val != '' && $names[$n] != '') |
---|
| 617 | { |
---|
| 618 | $html .= ' '.strtolower($names[$n]).'="'.$val.'"'; |
---|
| 619 | } |
---|
| 620 | } |
---|
| 621 | return $html; |
---|
| 622 | } |
---|
| 623 | |
---|
| 624 | /** |
---|
| 625 | * returns simple stylesheet (incl. <STYLE> tags) for nextmatch row-colors |
---|
| 626 | * @result the classes 'th' = nextmatch header, 'row_on'+'row_off' = alternating rows |
---|
| 627 | */ |
---|
| 628 | function themeStyles() |
---|
| 629 | { |
---|
| 630 | return $this->style($this->theme2css()); |
---|
| 631 | } |
---|
| 632 | |
---|
| 633 | /** |
---|
| 634 | * returns simple stylesheet for nextmatch row-colors |
---|
| 635 | * @result the classes 'th' = nextmatch header, 'row_on'+'row_off' = alternating rows |
---|
| 636 | */ |
---|
| 637 | function theme2css() |
---|
| 638 | { |
---|
| 639 | return ".th { background: ".$GLOBALS['phpgw_info']['theme']['th_bg']."; }\n". |
---|
| 640 | ".row_on,.th_bright { background: ".$GLOBALS['phpgw_info']['theme']['row_on']."; }\n". |
---|
| 641 | ".row_off { background: ".$GLOBALS['phpgw_info']['theme']['row_off']."; }\n"; |
---|
| 642 | } |
---|
| 643 | |
---|
| 644 | function style($styles) |
---|
| 645 | { |
---|
| 646 | return $styles ? "<style type=\"text/css\">\n<!--\n$styles\n-->\n</style>" : ''; |
---|
| 647 | } |
---|
| 648 | |
---|
| 649 | function label($content,$id='',$accesskey='',$options='') |
---|
| 650 | { |
---|
| 651 | if ($id != '') |
---|
| 652 | { |
---|
| 653 | $id = " for=\"$id\""; |
---|
| 654 | } |
---|
| 655 | if ($accesskey != '') |
---|
| 656 | { |
---|
| 657 | $accesskey = " accesskey=\"$accesskey\""; |
---|
| 658 | } |
---|
| 659 | return "<label$id$accesskey $options>$content</label>"; |
---|
| 660 | } |
---|
| 661 | } |
---|