diff options
| author | artem <artem@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2007-08-02 10:54:51 +0000 |
|---|---|---|
| committer | artem <artem@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2007-08-02 10:54:51 +0000 |
| commit | 70544b9e784123d3955a03851bfc86e1ca52feb5 (patch) | |
| tree | 0f1884f877812f33409406e219c9189528f4b6cf /frontends/php/include/js.inc.php | |
| parent | 11f5ce6cef37a10e7777fdbd5f22932a91b4952e (diff) | |
- merged rev. 4499:4500 of branches/1.4.2/ (Artem) [js function moved from config.inc.php to js.inc.php. Added showhint.js]
git-svn-id: svn://svn.zabbix.com/trunk@4501 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'frontends/php/include/js.inc.php')
| -rw-r--r-- | frontends/php/include/js.inc.php | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/frontends/php/include/js.inc.php b/frontends/php/include/js.inc.php new file mode 100644 index 00000000..b76353f9 --- /dev/null +++ b/frontends/php/include/js.inc.php @@ -0,0 +1,140 @@ +<?php + +/* function: + * zbx_jsvalue + * + * description: + * convert PHP variable to string version + * of JavaScrip style + * + * author: Eugene Grigorjev + */ +function zbx_jsvalue($value) +{ + if(!is_array($value)) + { + if(is_object($value)) return unpack_object($value); + if(is_string($value)) return '\''.str_replace('\'','\\\'', /* ' => \' */ + str_replace("\n", '\n', /* LF => \n */ + str_replace("\\", "\\\\", /* \ => \\ */ + str_replace("\r", '', /* CR => remove */ + ($value))))).'\''; + if(is_null($value)) return 'null'; + return strval($value); + } + + if(count($value) == 0) return '[]'; + + foreach($value as $id => $v) + { + if(!isset($is_object) && is_string($id)) $is_object = true; + + $value[$id] = (isset($is_object) ? '\''.$id.'\' : ' : '').zbx_jsvalue($v); + } + + if(isset($is_object)) + return '{'.implode(',',$value).'}'; + else + return '['.implode(',',$value).']'; +} + +/* function: + * zbx_add_post_js + * + * description: + * add JavaScript for calling after page loaging. + * + * author: Eugene Grigorjev + */ +function zbx_add_post_js($script) +{ + global $ZBX_PAGE_POST_JS; + + $ZBX_PAGE_POST_JS[] = $script; +} + +function insert_sizeable_graph($url){ + + echo '<script language="JavaScript" type="text/javascript"> + <!-- + insert_sizeable_graph('.zbx_jsvalue($url).'); + --> + </script>'; +} + + +function get_dynamic_chart($img_src,$width=0){ + if(is_int($width) && $width > 0) $img_src.= url_param($width, false, 'width'); + $result = ' + <script language="JavaScript" type="text/javascript"> + <!-- + var width = "'.((!(is_int($width) && $width > 0)) ? $width : '').'"; + var img_src = "'.$img_src.'"; + + if(width!=""){ + var scr_width = 0; + if(document.body.clientWidth) + scr_width = document.body.clientWidth; + else + scr_width = document.width; + + width = "&width=" + (scr_width - 100 + parseInt(width)); + } + + document.write(\'<img alt="chart" src=" + img_src + width + " />\'); + --> + </script>'; +return $result; +} + +function insert_showhint_javascript(){ + if(defined('SHOW_HINT_SCRIPT_INSERTTED')) return; + define('SHOW_HINT_SCRIPT_INSERTTED', 1); + + echo '<script type"text/javascript" src="js/showhint.js"></script>'; +} + +function Redirect($url,$timeout=null){ + zbx_flush_post_cookies(); + + echo '<script language="JavaScript" type="text/javascript">'; + if( is_numeric($timeout) ) { + echo 'setTimeout(\'window.location="'.$url.'"\','.($timeout*1000).')'; + } + else { + echo 'window.location = "'.$url.'";'; + } + echo '</script>'; +} + +function play_sound($filename){ + + echo '<script language="javascript" type="text/javascript"> + + if (IE){ + document.writeln(\'<bgsound src="'.$filename.'" loop="0" />\'); + } + else{ + document.writeln(\'<embed src="'.$filename.'" autostart="true" width="0" height="0" loop="0" />\'); + document.writeln(\'<noembed><bgsound src="'.$filename.'" loop="0" /></noembed>\'); + } + </script>'; +} + + +function SetFocus($frm_name, $fld_name){ + echo '<script language="javascript" type="text/javascript"> + <!-- + document.forms["'.$frm_name.'"].elements["'.$fld_name.'"].focus(); + //--> + </script>'; +} + +function Alert($msg){ + echo '<script language="javascript" type="text/javascript"> + <!-- + alert("'.$msg.'"); + //--> + </script>'; +} +?>
\ No newline at end of file |
