~ubuntu-dev/ubuntu/lucid/zabbix/lucid-201002110857

« back to all changes in this revision

Viewing changes to frontends/php/js/common.js

  • Committer: Bazaar Package Importer
  • Author(s): Michael Ablassmeier
  • Date: 2007-07-02 09:06:51 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070702090651-8l6fl3fjw9rh6l2u
Tags: 1:1.4.1-2
Add patch from SVN in order to fix Incorrect processing of character '%'
in user parameters and remote commands.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
** ZABBIX
 
3
** Copyright (C) 2000-2005 SIA Zabbix
 
4
**
 
5
** This program is free software; you can redistribute it and/or modify
 
6
** it under the terms of the GNU General Public License as published by
 
7
** the Free Software Foundation; either version 2 of the License, or
 
8
** (at your option) any later version.
 
9
**
 
10
** This program is distributed in the hope that it will be useful,
 
11
** but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
** GNU General Public License for more details.
 
14
**
 
15
** You should have received a copy of the GNU General Public License
 
16
** along with this program; if not, write to the Free Software
 
17
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
18
**/
 
19
var IE = document.all?true:false;
 
20
var OP = window.opera?true:false;
 
21
 
 
22
 
 
23
function SDI(msg)
 
24
{
 
25
        alert("DEBUG INFO: " + msg);
 
26
}
 
27
 
 
28
function close_window()
 
29
{
 
30
        window.setTimeout("window.close()", 500); /* Solve bug for Internet Explorer */
 
31
        return false;
 
32
}
 
33
 
 
34
function add_variable(o_el, s_name, x_value, s_formname, o_document)
 
35
{
 
36
        var form;
 
37
 
 
38
        if(!o_document) o_document = document;
 
39
 
 
40
        if(s_formname)
 
41
        {
 
42
                if( !(form = o_document.forms[s_formname]) )
 
43
                         throw "Missed form with name '"+s_formname+"'.";
 
44
        }
 
45
        else if(o_el)
 
46
        {
 
47
                
 
48
                if( !(form = o_el.form) )
 
49
                        throw "Missed form in 'o_el' object";
 
50
        }
 
51
        else
 
52
        {
 
53
                if( !(form = this.form) )
 
54
                        throw "Missed form in 'this' object";
 
55
        }
 
56
 
 
57
        var o_variable = o_document.createElement('input');
 
58
 
 
59
        if( !o_variable )       throw "Can't create element";
 
60
 
 
61
        o_variable.type = 'hidden';
 
62
        o_variable.name = s_name;
 
63
        o_variable.value = x_value;
 
64
 
 
65
        form.appendChild(o_variable);
 
66
 
 
67
        return true;
 
68
}
 
69
 
 
70
function get_scroll_pos()
 
71
{
 
72
        var scrOfX = 0, scrOfY = 0;
 
73
        if( typeof( window.pageYOffset ) == 'number' )
 
74
        {       //Netscape compliant
 
75
                scrOfY = window.pageYOffset;
 
76
                scrOfX = window.pageXOffset;
 
77
        }
 
78
        else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) )
 
79
        {       //DOM compliant
 
80
                scrOfY = document.body.scrollTop;
 
81
                scrOfX = document.body.scrollLeft;
 
82
        }
 
83
        else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) )
 
84
        {       //IE6 standards compliant mode
 
85
                scrOfY = document.documentElement.scrollTop;
 
86
                scrOfX = document.documentElement.scrollLeft;
 
87
        }
 
88
        return [ scrOfX, scrOfY ];
 
89
}
 
90
function get_cursor_position(e)
 
91
{
 
92
        e = e || window.event;
 
93
        var cursor = {x:0, y:0};
 
94
        if (e.pageX || e.pageY) {
 
95
                cursor.x = e.pageX;
 
96
                cursor.y = e.pageY;
 
97
        } 
 
98
        else {
 
99
                var de = document.documentElement;
 
100
                var b = document.body;
 
101
                cursor.x = e.clientX + 
 
102
                (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
 
103
                cursor.y = e.clientY + 
 
104
                (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
 
105
        }
 
106
        return cursor;
 
107
}
 
108
 
 
109
function Redirect(url) {
 
110
        window.location = url;
 
111
        return false;
 
112
}       
 
113
 
 
114
function create_var(form_name, var_name, var_val, submit)
 
115
{
 
116
        var frmForm = document.forms[form_name];
 
117
 
 
118
        if(!frmForm) return false;
 
119
 
 
120
        var objVar = document.createElement('input');
 
121
 
 
122
        if(!objVar) return false;
 
123
 
 
124
        objVar.setAttribute('type',     'hidden');
 
125
        objVar.setAttribute('name',     var_name);
 
126
        objVar.setAttribute('value',    var_val);
 
127
 
 
128
        frmForm.appendChild(objVar);
 
129
        if(submit)
 
130
                frmForm.submit();
 
131
 
 
132
        return false;
 
133
}
 
134
 
 
135
function Confirm(msg){
 
136
        if(confirm(msg,'title'))
 
137
                return true;
 
138
        else
 
139
                return false;
 
140
}
 
141
 
 
142
function PopUp(url,width,height,form_name){
 
143
        if(!width) width = 600;
 
144
        if(!height) height = 450;
 
145
        if(!form_name) form_name = 'zbx_popup';
 
146
 
 
147
        var left = (screen.width-(width+150))/2; 
 
148
        var top = (screen.height-(height+150))/2;
 
149
        
 
150
        var popup = window.open(url,form_name,'width=' + width +',height=' + height + ',top='+ top +',left='+ left +
 
151
                        ',resizable=yes,scrollbars=yes,location=no,menubar=no');
 
152
 
 
153
        popup.focus();
 
154
        
 
155
        return false;
 
156
}
 
157
 
 
158
function CheckAll(form_name, chkMain, shkName){
 
159
        var frmForm = document.forms[form_name];
 
160
        var value = frmForm.elements[chkMain].checked;
 
161
        for (var i=0; i < frmForm.length; i++)
 
162
        {
 
163
                name = frmForm.elements[i].name.split('[')[0];
 
164
                if(frmForm.elements[i].type != 'checkbox') continue;
 
165
                if(name == chkMain) continue;
 
166
                if(shkName && shkName != name) continue;
 
167
                if(frmForm.elements[i].disabled == true) continue;
 
168
                frmForm.elements[i].checked = value;
 
169
        }
 
170
}
 
171
 
 
172
function GetSelectedText(obj)
 
173
{
 
174
        if (navigator.appName == "Microsoft Internet Explorer")
 
175
        {
 
176
                obj.focus();
 
177
                return document.selection.createRange().text;
 
178
        }
 
179
        else (obj.selectionStart)
 
180
        {
 
181
                if(obj.selectionStart != obj.selectionEnd) {
 
182
                        var s = obj.selectionStart;
 
183
                        var e = obj.selectionEnd;
 
184
                        return obj.value.substring(s, e);
 
185
                }
 
186
        }
 
187
        return obj.value;
 
188
}
 
189
 
 
190
function ScaleChartToParenElement(obj_name)
 
191
{
 
192
        var obj = document.getElementsByName(obj_name);
 
193
 
 
194
        if(obj.length <= 0) throw "Can't find objects with name [" + obj_name +"]";
 
195
 
 
196
        for(i = obj.length-1; i>=0; i--)
 
197
        {
 
198
                obj[i].src += "&width=" + (obj[i].parentNode.offsetWidth - obj[i].parentNode.offsetLeft - 10);
 
199
        }
 
200
}
 
201
 
 
202
function insert_sizeable_graph(url)
 
203
{
 
204
        var width;
 
205
 
 
206
        if(document.body.clientWidth)
 
207
                width = document.body.clientWidth;
 
208
        else if(document.width)
 
209
                width = document.width;
 
210
 
 
211
        if(width) url += "&amp;width=" + (width - 108);
 
212
 
 
213
        document.write("<IMG SRC=\"" + url + "\">");
 
214
}