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

« back to all changes in this revision

Viewing changes to frontends/php/include/classes/ccolor.inc.php

  • 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
<?php
 
2
/* 
 
3
** ZABBIX
 
4
** Copyright (C) 2000-2005 SIA Zabbix
 
5
**
 
6
** This program is free software; you can redistribute it and/or modify
 
7
** it under the terms of the GNU General Public License as published by
 
8
** the Free Software Foundation; either version 2 of the License, or
 
9
** (at your option) any later version.
 
10
**
 
11
** This program is distributed in the hope that it will be useful,
 
12
** but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
** GNU General Public License for more details.
 
15
**
 
16
** You should have received a copy of the GNU General Public License
 
17
** along with this program; if not, write to the Free Software
 
18
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
19
**/
 
20
        require_once "include/classes/clink.inc.php";
 
21
 
 
22
?>
 
23
<?php
 
24
 
 
25
        function insert_show_color_picker_javascript()
 
26
        {
 
27
                global $SHOW_COLOR_PICKER_SCRIPT_ISERTTED;
 
28
 
 
29
                if($SHOW_COLOR_PICKER_SCRIPT_ISERTTED) return;
 
30
                $SHOW_COLOR_PICKER_SCRIPT_ISERTTED = true;
 
31
?>
 
32
<script language="JavaScript" type="text/javascript">
 
33
<!--
 
34
 
 
35
var color_table = <?php
 
36
        $table = '';
 
37
 
 
38
        $table .= '<table cellspacing="0" cellpadding="1">';
 
39
        $table .= '<tr>';
 
40
        /* gray colors */
 
41
        foreach(array('0','3','6','8','9','A','C','E','F') as $c)
 
42
        {
 
43
                $color = $c.$c.$c.$c.$c.$c;
 
44
                $table .= '<td>'.unpack_object(new CColorCell(null, $color, 'set_color(\\\''.$color.'\\\')')).'</td>';
 
45
        }
 
46
        $table .= '</tr>';
 
47
        
 
48
        /* other colors */
 
49
        $colors = array(
 
50
                array('r' => 0, 'g' => 0, 'b' => 1),
 
51
                array('r' => 0, 'g' => 1, 'b' => 0),
 
52
                array('r' => 1, 'g' => 0, 'b' => 0),
 
53
                array('r' => 0, 'g' => 1, 'b' => 1),
 
54
                array('r' => 1, 'g' => 0, 'b' => 1),
 
55
                array('r' => 1, 'g' => 1, 'b' => 0)
 
56
                );
 
57
        
 
58
        $brigs  = array(
 
59
                array(0 => '0', 1 => '3'),
 
60
                array(0 => '0', 1 => '6'),
 
61
                array(0 => '0', 1 => '9'),
 
62
                array(0 => '0', 1 => 'C'),
 
63
                array(0 => '0', 1 => 'F'),
 
64
                array(0 => '3', 1 => 'F'),
 
65
                array(0 => '6', 1 => 'F'),
 
66
                array(0 => '9', 1 => 'F'),
 
67
                array(0 => 'C', 1 => 'F')
 
68
                );
 
69
 
 
70
        foreach($colors as $c)
 
71
        {
 
72
                $table .= '<tr>';
 
73
                foreach($brigs as $br)
 
74
                {
 
75
                        $r = $br[$c['r']];
 
76
                        $g = $br[$c['g']];
 
77
                        $b = $br[$c['b']];
 
78
                        
 
79
                        $color = $r.$r.$g.$g.$b.$b;
 
80
 
 
81
                        $table .= '<td>'.unpack_object(new CColorCell(null, $color, 'set_color(\\\''.$color.'\\\')')).'</td>';
 
82
                }
 
83
                $table .= '</tr>';
 
84
        }
 
85
        $table .= '</table>';
 
86
        $cancel = '<a href="javascript:hide_color_picker()">'.S_CANCEL.'</a>';
 
87
        echo '\''.$table.$cancel.'\'';
 
88
        unset($table);
 
89
?>
 
90
 
 
91
function GetPos(obj)
 
92
{
 
93
        var left = obj.offsetLeft;
 
94
        var top  = obj.offsetTop;;
 
95
        while (obj = obj.offsetParent)
 
96
        {
 
97
                left    += obj.offsetLeft
 
98
                top     += obj.offsetTop
 
99
        }
 
100
        return [left,top];
 
101
}
 
102
 
 
103
var color_picker = null;
 
104
var curr_lbl = null;
 
105
var curr_txt = null;
 
106
 
 
107
function hide_color_picker()
 
108
{
 
109
        if(!color_picker) return;
 
110
 
 
111
        color_picker.style.visibility="hidden"
 
112
        color_picker.style.left = "-" + ((color_picker.style.width) ? color_picker.style.width : 100) + "px";
 
113
 
 
114
        curr_lbl = null;
 
115
        curr_txt = null;
 
116
}
 
117
 
 
118
function show_color_picker(name)
 
119
{
 
120
        if(!color_picker) return;
 
121
 
 
122
        curr_lbl = document.getElementById('lbl_' + name);
 
123
        curr_txt = document.getElementById(name);
 
124
        
 
125
        var pos = GetPos(curr_lbl);
 
126
 
 
127
        color_picker.x  = pos[0];
 
128
        color_picker.y  = pos[1];
 
129
 
 
130
        color_picker.style.left = color_picker.x + "px";
 
131
        color_picker.style.top  = color_picker.y + "px";
 
132
 
 
133
        color_picker.style.visibility = "visible";
 
134
}
 
135
 
 
136
function create_color_picker()
 
137
{
 
138
        if(color_picker) return;
 
139
 
 
140
        color_picker = document.createElement("div");
 
141
        color_picker.setAttribute("id", "color_picker");
 
142
        color_picker.innerHTML = color_table;
 
143
        document.body.appendChild(color_picker);
 
144
 
 
145
        hide_color_picker();
 
146
}
 
147
 
 
148
function set_color(color)
 
149
{
 
150
        if(curr_lbl)    curr_lbl.style.background = curr_lbl.style.color = '#' + color;
 
151
        if(curr_txt)    curr_txt.value = color;
 
152
 
 
153
        hide_color_picker();
 
154
}
 
155
 
 
156
function set_color_by_name(name, color)
 
157
{
 
158
        curr_lbl = document.getElementById('lbl_' + name);
 
159
        curr_txt = document.getElementById(name);
 
160
        
 
161
        set_color(color);
 
162
}
 
163
 
 
164
if (window.addEventListener)
 
165
{
 
166
        window.addEventListener("load", create_color_picker, false);
 
167
}
 
168
else if (window.attachEvent)
 
169
{
 
170
        window.attachEvent("onload", create_color_picker);
 
171
}
 
172
else if (document.getElementById)
 
173
{
 
174
        window.onload   = create_color_picker;
 
175
}
 
176
 
 
177
//-->
 
178
</script>
 
179
<?php
 
180
        }
 
181
 
 
182
        class CColorCell extends CLink
 
183
        {
 
184
                function        CColorCell($name, $value, $action=null)
 
185
                {
 
186
                        parent::CLink(SPACE.SPACE.SPACE, null);
 
187
                        $this->SetName($name);
 
188
                        $this->AddOption('id', $name);
 
189
                        $this->AddOption('title', '#'.$value);
 
190
                        $this->AddOption('style', 'text-decoration: none; outline: 1px solid black; background-color: #'.$value);
 
191
                        $this->SetAction($action);
 
192
                }
 
193
                function        SetAction($action=null)
 
194
                {
 
195
                        if(!isset($action)) return false;
 
196
                        
 
197
                        return $this->SetUrl('javascript:'.$action);
 
198
                }
 
199
        }
 
200
 
 
201
        class CColor extends CObject
 
202
        {
 
203
/* public */
 
204
                function CColor($name,$value)
 
205
                {
 
206
                        parent::CObject();
 
207
 
 
208
                        $lbl = new CColorCell('lbl_'.$name, $value, 'show_color_picker(\''.$name.'\')');
 
209
 
 
210
                        $txt = new CTextBox($name,$value,7);
 
211
                        $txt->AddOption('id', $name);
 
212
                        $txt->AddAction('onChange', 'set_color_by_name(\''.$name.'\',this.value)');
 
213
                        $txt->AddOption('style', 'margin: 0px');
 
214
                        $this->AddItem(array($txt, $lbl));
 
215
                        
 
216
                        insert_show_color_picker_javascript();
 
217
                }
 
218
        }
 
219
?>