4
** Copyright (C) 2000-2005 SIA Zabbix
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.
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.
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.
20
require_once "include/classes/clink.inc.php";
25
function insert_show_color_picker_javascript()
27
global $SHOW_COLOR_PICKER_SCRIPT_ISERTTED;
29
if($SHOW_COLOR_PICKER_SCRIPT_ISERTTED) return;
30
$SHOW_COLOR_PICKER_SCRIPT_ISERTTED = true;
32
<script language="JavaScript" type="text/javascript">
35
var color_table = <?php
38
$table .= '<table cellspacing="0" cellpadding="1">';
41
foreach(array('0','3','6','8','9','A','C','E','F') as $c)
43
$color = $c.$c.$c.$c.$c.$c;
44
$table .= '<td>'.unpack_object(new CColorCell(null, $color, 'set_color(\\\''.$color.'\\\')')).'</td>';
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)
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')
70
foreach($colors as $c)
73
foreach($brigs as $br)
79
$color = $r.$r.$g.$g.$b.$b;
81
$table .= '<td>'.unpack_object(new CColorCell(null, $color, 'set_color(\\\''.$color.'\\\')')).'</td>';
86
$cancel = '<a href="javascript:hide_color_picker()">'.S_CANCEL.'</a>';
87
echo '\''.$table.$cancel.'\'';
93
var left = obj.offsetLeft;
94
var top = obj.offsetTop;;
95
while (obj = obj.offsetParent)
97
left += obj.offsetLeft
103
var color_picker = null;
107
function hide_color_picker()
109
if(!color_picker) return;
111
color_picker.style.visibility="hidden"
112
color_picker.style.left = "-" + ((color_picker.style.width) ? color_picker.style.width : 100) + "px";
118
function show_color_picker(name)
120
if(!color_picker) return;
122
curr_lbl = document.getElementById('lbl_' + name);
123
curr_txt = document.getElementById(name);
125
var pos = GetPos(curr_lbl);
127
color_picker.x = pos[0];
128
color_picker.y = pos[1];
130
color_picker.style.left = color_picker.x + "px";
131
color_picker.style.top = color_picker.y + "px";
133
color_picker.style.visibility = "visible";
136
function create_color_picker()
138
if(color_picker) return;
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);
148
function set_color(color)
150
if(curr_lbl) curr_lbl.style.background = curr_lbl.style.color = '#' + color;
151
if(curr_txt) curr_txt.value = color;
156
function set_color_by_name(name, color)
158
curr_lbl = document.getElementById('lbl_' + name);
159
curr_txt = document.getElementById(name);
164
if (window.addEventListener)
166
window.addEventListener("load", create_color_picker, false);
168
else if (window.attachEvent)
170
window.attachEvent("onload", create_color_picker);
172
else if (document.getElementById)
174
window.onload = create_color_picker;
182
class CColorCell extends CLink
184
function CColorCell($name, $value, $action=null)
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);
193
function SetAction($action=null)
195
if(!isset($action)) return false;
197
return $this->SetUrl('javascript:'.$action);
201
class CColor extends CObject
204
function CColor($name,$value)
208
$lbl = new CColorCell('lbl_'.$name, $value, 'show_color_picker(\''.$name.'\')');
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));
216
insert_show_color_picker_javascript();