summaryrefslogtreecommitdiffstats
path: root/frontends/php/include/html.inc.php
blob: 34641c23684e4dbc375bc505fa8dfee5c6d33d6c (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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
<?php
/*
** ZABBIX
** Copyright (C) 2000-2005 SIA Zabbix
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
?>
<?php
	function bold($str){
		if(is_array($str)){
			foreach($str as $key => $val)
				if(is_string($val)){
					$b = new CTag('strong','yes');
					$b->AddItem($val);
					$str[$key] = $b;
				}
		} 
		else if(is_string($str)) {
			$b = new CTag('strong','yes');
			$b->AddItem($str);
			$str = $b;
		}
	return $str;
	}

	function bfirst($str){
// mark first symbol of string as bold
		$res = bold($str[0]);
		for($i=1,$max=strlen($str); $i<$max; $i++)	$res .= $str[$i];
		$str = $res;
		return $str;	
	}

	function nbsp($str){
		return str_replace(" ",SPACE,$str);
	}

	function url1_param($parameter){
		if(isset($_REQUEST[$parameter])){
			return "$parameter=".$_REQUEST[$parameter];
		}
		else{
			return "";
		}
	}

	function prepare_url(&$var, $varname=null){
		$result = "";

		if(is_array($var)){
			foreach($var as $id => $par)
				$result .= prepare_url($par,isset($varname) ? $varname."[".$id."]": $id);
		}
		else{
			$result = '&'.$varname.'='.urlencode($var);
		}
		return $result;
	}

	function url_param($parameter,$request=true,$name=null){
		$result = '';
		if(!is_array($parameter)){
			if(!isset($name)){
				if(!$request)
					fatal_error('not request variable require url name [url_param]');
					
				$name = $parameter;
			}
		}
		
		if($request){
			$var =& $_REQUEST[$parameter];
		}
		else{
			$var =& $parameter;
		}
		
		if(isset($var)){
			$result = prepare_url($var,$name);
		}

	return $result;
	}
	
	function BR(){
		return new CTag('br','no');
	}
	
	function create_hat($caption,$items,$addicons=null,$id=null,$state=1){
	
		if(is_null($id)){
			list($usec, $sec) = explode(' ',microtime());	
			$id = 'hat_'.((int)($sec % 10)).((int)($usec * 1000));
		}

		$td_l = new CCol(SPACE);
		$td_l->AddOption('width','100%');

		$icons_row = array($td_l);
		if(!is_null($addicons)){
			if(!is_array($addicons)) $addicons = array($addicons);
			foreach($addicons as $value) $icons_row[] = $value;
		}

		$icon = new CDiv(SPACE,($state)?'arrowup':'arrowdown');
		$icon->AddAction('onclick',new CScript("javascript: change_hat_state(this,'".$id."');"));
		$icon->AddOption('title',S_SHOW.'/'.S_HIDE);

		$icons_row[] = $icon;

		$icon_tab = new CTable();
		$icon_tab->AddOption('width','100%');
		
		$icon_tab->AddRow($icons_row);
		
		$table = new CTable();
		$table->AddOption('width','100%');
		$table->SetCellPadding(0);
		$table->SetCellSpacing(0);
		$table->AddRow(get_table_header($caption,$icon_tab));

		$div = new CDiv($items);
		$div->AddOption('id',$id);
		if(!$state) $div->AddOption('style','display: none;');
		
		$table->AddRow($div);
	return $table;
	}
	
	function create_filter($col_l,$col_r,$items,$id='zbx_filter',$state=1){

		if(isset($_REQUEST['print'])) $state = 0;
		
		$table = new CTable();
		$table->AddOption('width','100%');
		$table->SetCellPadding(0);
		$table->SetCellSpacing(0);
		$table->AddOption('border',0);
		
		$icon = new CDiv(SPACE,($state)?'filteropened':'filterclosed');
		$icon->AddAction('onclick',new CScript("javascript: change_filter_state(this,'".$id."');"));
		$icon->AddOption('title',S_MAXIMIZE.'/'.S_MINIMIZE);
		$icon->AddAction('id','filter_icon');

		$td_icon = new CCol($icon);
		$td_icon->AddOption('valign','bottom');

		$icons_row = array($td_icon,SPACE);
		$icons_row[] = $col_l;

		$icon_tab = new CTable();
		$icon_tab->SetCellSpacing(0);
		$icon_tab->SetCellPadding(0);
		
		$icon_tab->AddRow($icons_row);
		
		$table->AddRow(get_thin_table_header($icon_tab,$col_r));

		$div = new CDiv($items);
		$div->AddOption('id',$id);
		if(!$state) $div->AddOption('style','display: none;');
		
		$tab = new CTable();
		$tab->AddRow($div);
		
//		$table->AddRow($tab);
		$table->AddRow($div);
	return $table;
	}
	
	function create_filter_hat($col_l,$col_r,$items,$id,$state=1){
		
		$table = new CTable(NULL,"filter");
		$table->SetCellSpacing(0);
		$table->SetCellPadding(1);



		$td_l = new CCol($icon_tab,"filter_l");
				
		$td_r = new CCol($col_r,"filter_r");
		$td_r->AddOption('align','right');
				
		$table->AddRow(array($td_l, $td_r));
	return $table;
	}
	
	
/* Function: 
 *	hide_form_items()
 *
 * Desc:
 *	Searches items/objects for Form tags like "<input"/Form classes like CForm, and makes it empty
 * 
 * Author: 
 *	Aly
 */
	function hide_form_items(&$obj){
		if(is_array($obj)){
			foreach($obj as $id => $item){
				hide_form_items($obj[$id]);			// Attention recursion;
			}
		}
		else if(is_object($obj)){
			if(str_in_array(strtolower(get_class($obj)),array('cform','ccheckbox','cselect','cbutton','cbuttonqmessage','cbuttondelete','cbuttoncancel'))){
				$obj=SPACE;
			}
			if(isset($obj->items) && !empty($obj->items)){
				foreach($obj->items as $id => $item){
					hide_form_items($obj->items[$id]); 		// Recursion
				}
			}
		}
		else{
			foreach(array('<form','<input','<select') as $item){
				if(strpos($obj,$item) !== FALSE) $obj = SPACE;
			}
		}
	}
	
	function get_thin_table_header($col1, $col2=SPACE){
		
		$table = new CTable(NULL,"filter");
//		$table->AddOption('border',1);
		$table->SetCellSpacing(0);
		$table->SetCellPadding(1);
		
		$td_r = new CCol($col2,"filter_r");
		$td_r->AddOption('align','right');
		
		$table->AddRow(array(new CCol($col1,"filter_l"), $td_r));
	return $table;
	}

	function	show_thin_table_header($col1, $col2=SPACE){
		$table = get_thin_table_header($col1, $col2);
		$table->Show();
	}

	function get_table_header($col1, $col2=SPACE){
		if(isset($_REQUEST['print'])){
			hide_form_items($col1);
			hide_form_items($col2);
		//if empty header than do not show it
			if(($col1 == SPACE) && ($col2 == SPACE)) return new CScript('');
		}
		
		$table = new CTable(NULL,"header");
//		$table->AddOption('border',1);
		$table->SetCellSpacing(0);
		$table->SetCellPadding(1);
		
		$td_r = new CCol($col2,"header_r");
		$td_r->AddOption('align','right');
		
		$table->AddRow(array(new CCol($col1,"header_l"), $td_r));
	return $table;
	}

	function	show_table_header($col1, $col2=SPACE)
	{
		$table = get_table_header($col1, $col2);
		$table->Show();
	}
?>