summaryrefslogtreecommitdiffstats
path: root/frontends/php/include/classes/ctable.inc.php
blob: 69b10f71ed83986e3b559c8914084adc8aa4fc72 (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
<?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
	class CCol extends CTag
	{
/* public */
		function CCol($item=NULL,$class=NULL)
		{
			parent::CTag("td","yes");
			$this->AddItem($item);
			$this->SetClass($class);
		}
		function SetAlign($value)
		{
			if(!is_string($value))
			{
				return $this->error("Incorrect value for SetAlign [$value]"); 
			}
			return $this->AddOption("align",$value);
		}
		function SetRowSpan($value)
		{
			if(!is_int($value) && !is_numeric($value))
			{
				return $this->error("Incorrect value for SetRowSpan [$value]"); 
			}
			return $this->AddOption("rowspan",strval($value));
		}
		function SetColSpan($value)
		{
			if(!is_int($value) && !is_numeric($value))
			{
				return $this->error("Incorrect value for SetColSpan[$value]"); 
			}
			return $this->AddOption("colspan",strval($value));
		}
	}
	
	class CRow extends CTag
	{	
/* public */
		function CRow($item=NULL,$class=NULL)
		{
			parent::CTag("tr","yes");
			$this->AddItem($item);
			$this->SetClass($class);
		}
		function SetAlign($value)
		{
			if(!is_string($value))
			{
				return $this->error("Incorrect value for SetAlign [$value]"); 
			}
			return $this->AddOption("align",$value);
		}
		function AddItem($item=NULL)
		{
			if(is_null($item))
				return 0;
                        elseif(is_a($item,'ccol'))
			{
                        	return parent::AddItem($item);
			}
			elseif(is_array($item))
			{
				$ret = 0;
				foreach($item as $el)
				{
                        		if(is_a($el,'ccol'))
					{
                		        	$ret |= parent::AddItem($el);
					} elseif(!is_null($el)) {
						$ret |= parent::AddItem(new CCol($el));
					}
				}
				return $ret;
			}
			return parent::AddItem(new CCol($item));
		}
	}

	class CTable extends CTag
	{
/* protected */
		var $oddRowClass;
		var $evenRowClass;
		var $header;
		var $footer;
/* public */
		function CTable($message=NULL,$class=NULL)
		{
			parent::CTag("table","yes");
			$this->SetClass($class);
			$this->message = $message;
				
			$this->oddRowClass = NULL;
			$this->evenRowClass = NULL;
			$this->header = NULL;
			$this->footer = NULL;;
		}
		function SetHeader($value=NULL,$class=NULL)
		{
			if(is_null($value)){
				$this->header = NULL;
			}elseif(is_a($value,'crow'))
			{
				if(isset($class))
					$value->SetClass($class);
				$this->header = $value;
			}else{
				$this->header = new CRow($value,$class);
			}
			return true;
		}
		function SetFooter($value=NULL,$class=NULL)
		{
			if(is_null($value)){
				$this->footer = NULL;
			}elseif(is_a($value,'ccol'))
			{
				if(isset($this->header) && $value->GetOption('colspan')==NULL)
					$value->SetColSpan(count($this->header->items));

				$this->footer = new CRow($value,$class);
			}elseif(is_a($value,'crow'))
			{
				if(isset($class))
					$value->SetClass($class);
				$this->footer = $value;
			}else{
				$this->footer = new CRow($value,$class);
			}
		}
		function SetOddRowClass($value=NULL)
		{
			if(!is_string($value) && !is_null($value))
			{
				return $this->error("Incorrect value for SetOddRowClass [$value]"); 
			}
			$this->oddRowClass = $value;
		}
		function SetEvenRowClass($value=NULL)
		{
			if(!is_string($value) && !is_null($value))
			{
				return $this->error("Incorrect value for SetEvenRowClass [$value]"); 
			}
			$this->evenRowClass = $value;
		}
		function SetAlign($value)
		{
			if(!is_string($value))
			{
				return $this->error("Incorrect value for SetAlign [$value]"); 
			}
			return $this->AddOption("align",$value);
		}
		function SetCellPadding($value)
		{
			if(!is_int($value) && !is_numeric($value))
			{
				return $this->error("Incorrect value for SetCellpadding [$value]"); 
			}
			return $this->AddOption("cellpadding",strval($value));
		}
		function SetCellSpacing($value)
		{
			if(!is_int($value) && !is_numeric($value))
			{
				return $this->error("Incorrect value for SetCellSpacing [$value]"); 
			}
			return $this->AddOption("cellspacing",strval($value));
		}
		function AddRow($item,$rowClass=NULL)
		{
			if(is_null($item)){
				return 0;
			}elseif(is_a($item,'ccol'))
			{
				if(isset($this->header) && $item->GetOption('colspan')==NULL)
					$item->SetColSpan(count($this->header->items));

				return $this->AddItem(new CRow($item,$rowClass));
			}elseif(is_a($item,'crow'))
			{
				if(isset($rowClass))
					$item->SetClass($rowClass);

				return $this->AddItem($item);
			}else{
				return $this->AddItem(new CRow($item,$rowClass));
			}
		}
/* protected */
		function ShowHeader()
		{
			if(isset($this->header))
				$this->header->Show();
		}

		function GetNumRows()
		{
			return $this->GetItemsCount();
		}

		function ShowTagBody()
		{
			$this->ShowHeader();

			if(count($this->items)==0)
			{
				if(isset($this->message)) 
					$this->AddRow(new CCol($this->message,'message'),$this->evenRowClass);
			} 

			parent::ShowTagBody();

			if(is_a($this->footer,'crow'))
				$this->footer->Show();
		}
		function AddItem($value)
		{
			$cname="crow";
                        if(!is_a($value,$cname))
			{
				return $this->error("Incorrect value for AddItem [$value]"); 
			}

			if($value->GetOption('class')==NULL)
			{
				$value->SetClass(
					((count($this->items)+1)%2==1) ?
					 $this->evenRowClass : $this->oddRowClass
				);
			}

                        return parent::AddItem($value);
		}
/*		function Show()
		{
			ob_start();
			parent::Show();
			ob_end_flush();
		}
*/
	}
?>