summaryrefslogtreecommitdiffstats
path: root/frontends/php/include/js.inc.php
blob: 3e8b9e46505ce2ea02635d016f6a822aaf6cddf1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
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>';
}
?>