Project

General

Profile

Download (7.38 KB) Statistics
| Branch: | Tag: | Revision:
1 50d86c13 Bill Marquette
<?php
2
/* $Id$ */
3
/*
4 f3ec0487 Phil Davis
	part of pfSense (https://www.pfsense.org/)
5 50d86c13 Bill Marquette
6 f3ec0487 Phil Davis
	Copyright (C) 2008 Bill Marquette <bill.marquette@gmail.com>.
7
	All rights reserved.
8 50d86c13 Bill Marquette
9 f3ec0487 Phil Davis
	Redistribution and use in source and binary forms, with or without
10
	modification, are permitted provided that the following conditions are met:
11 50d86c13 Bill Marquette
12 f3ec0487 Phil Davis
	1. Redistributions of source code must retain the above copyright notice,
13
	   this list of conditions and the following disclaimer.
14 50d86c13 Bill Marquette
15 f3ec0487 Phil Davis
	2. Redistributions in binary form must reproduce the above copyright
16
	   notice, this list of conditions and the following disclaimer in the
17
	   documentation and/or other materials provided with the distribution.
18 50d86c13 Bill Marquette
19 f3ec0487 Phil Davis
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
20
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
23
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
	POSSIBILITY OF SUCH DAMAGE.
29 50d86c13 Bill Marquette
*/
30
31 13d193c2 Scott Ullrich
/*
32
	pfSense_MODULE:	guiutils
33
*/
34
35 50d86c13 Bill Marquette
36
class MainTable {
37
	private $headers = array();
38
//	private $columns = array();
39
	private $columns = 0;
40
	private $rows = 0;
41
	private $content = array();
42
	private $edit_uri = '';
43
	private $my_uri = '';
44
	private $buttons = array('move' => false, 'edit' => false, 'del' => false, 'dup' => false);
45
46
	function add_column($header, $cname, $width) {
47
//		$this->column[] = array('header' => $header, 'cname' => $cname, 'width' => $width)
48
		$this->headers[] = $header;
49
		$this->cname[] = $cname;
50
		$this->width[] = $width;
51
		$this->columns++;
52
	}
53
54
	function add_content_array($rows) {
55 f3ec0487 Phil Davis
		foreach ($rows as $row) {
56 50d86c13 Bill Marquette
			$this->content[] = $row;
57
			$this->rows++;
58
		}
59
	}
60
	function add_button($name) {
61
		if (isset($this->buttons[$name])) {
62
			$this->buttons[$name] = true;
63
		}
64
	}
65
	function edit_uri($uri) {
66
		$this->edit_uri = $uri;
67
	}
68
69
	function my_uri($uri) {
70
		$this->my_uri = $uri;
71
	}
72
73
	function display() {
74
		echo "<!-- begin content table -->\n";
75 f326b978 Colin Fleming
		echo "<table class=\"tabcont\" width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" summary=\"display\">\n";
76 50d86c13 Bill Marquette
		echo "  <!-- begin content table header -->\n";
77
		echo $this->display_header();
78
		echo "  <!-- end content table header -->\n";
79
		echo "  <!-- begin content table rows -->\n";
80
		echo $this->display_rows();
81
		echo "  <!-- end content table rows -->\n";
82
		echo "  <!-- begin content table footer -->\n";
83
		echo $this->display_footer();
84
		echo "  <!-- end content table footer -->\n";
85
		echo "</table>\n";
86
		echo "<!-- end content table -->\n";
87
	}
88
89
	private function display_header() {
90
		global $g;
91
		echo "<tr>\n";
92
		for ($col = 0; $col < $this->columns - 1; $col++) {
93
			echo "  <td width=\"{$this->width[$col]}%\" class=\"listhdrr\">{$this->headers[$col]}</td>\n";
94
		}
95
		echo "  <td width=\"{$this->width[$this->columns - 1]}%\" class=\"listhdr\">{$this->headers[$this->columns - 1]}</td>\n";
96
		echo "  <td width=\"10%\" class=\"list\">\n";
97 f326b978 Colin Fleming
		echo "    <table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" summary=\"display header\">\n";
98 50d86c13 Bill Marquette
		echo "      <tr>\n";
99
		echo "        <td width=\"17\"></td>\n";
100 f326b978 Colin Fleming
		echo "         <td valign=\"middle\"><a href=\"{$this->edit_uri}\"><img src=\"/themes/{$g['theme']}/images/icons/icon_plus.gif\" width=\"17\" height=\"17\" border=\"0\" alt=\"plus\" /></a></td>\n";
101 50d86c13 Bill Marquette
		echo "      </tr>\n";
102
		echo "    </table>\n";
103
		echo "  </td>\n";
104
		echo "</tr>\n";
105
106
	}
107
	private function display_rows() {
108
		global $g;
109
		$cur_row = 0;
110 ddddf255 jim-p
		$encode_cols = array("name", "descr");
111 50d86c13 Bill Marquette
		foreach ($this->content as $row) {
112
			echo "<tr>\n";
113
			for ($col = 0; $col < $this->columns - 1; $col++) {
114
				if ($col == 0) {
115
					$cl = 'listlr';
116
				} else {
117
					$cl = 'listr';
118
				}
119 f326b978 Colin Fleming
				echo "  <td class=\"{$cl}\" onclick=\"fr_toggle({$cur_row})\" id=\"frd{$cur_row}\" ondblclick=\"document.location='{$this->edit_uri}?id={$cur_row}'\">\n";
120 50d86c13 Bill Marquette
				if (is_array($row[$this->cname[$col]])) {
121
					foreach ($row[$this->cname[$col]] as $data) {
122 ddddf255 jim-p
						if (in_array($this->cname[$col], $encode_cols)) {
123
							$data = htmlspecialchars($data);
124
						}
125 8cd558b6 ayvis
						echo "    {$data}<br />\n";
126 50d86c13 Bill Marquette
					}
127
				} else {
128 ddddf255 jim-p
					if (in_array($this->cname[$col], $encode_cols)) {
129
						$row[$this->cname[$col]] = htmlspecialchars($row[$this->cname[$col]]);
130
					}
131 50d86c13 Bill Marquette
					echo "    " . $row[$this->cname[$col]] . "\n";
132
				}
133
				echo "  </td>\n";
134
			}
135 d1d6d0d3 Colin Fleming
			echo "  <td class=\"listbg\" onclick=\"fr_toggle({$cur_row})\" id=\"frd{$cur_row}\" ondblclick=\"document.location='{$this->edit_uri}?id={$cur_row}'\">\n";
136 ddddf255 jim-p
			echo "    <font color=\"#FFFFFF\">" . htmlspecialchars($row[$this->cname[$this->columns - 1]]) . "</font>\n";
137 50d86c13 Bill Marquette
			echo "  </td>\n";
138 f326b978 Colin Fleming
			echo "  <td class=\"list nowrap\">\n";
139 50d86c13 Bill Marquette
			$this->display_buttons($cur_row);
140
			echo "  </td>\n";
141
			echo "</tr>\n";
142
143
			$cur_row++;
144
		}
145
	}
146
	private function display_footer() {
147
		global $g;
148
		echo "<tr>\n";
149
		echo "  <td class=\"list\" colspan=\"{$this->columns}\"></td>\n";
150
		echo "  <td class=\"list\">\n";
151 f326b978 Colin Fleming
		echo "    <table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" summary=\"display footer\">\n";
152 50d86c13 Bill Marquette
		echo "      <tr>\n";
153
		echo "        <td width=\"17\"></td>\n";
154 f326b978 Colin Fleming
		echo "        <td valign=\"middle\"><a href=\"{$this->edit_uri}\"><img src=\"/themes/{$g['theme']}/images/icons/icon_plus.gif\" width=\"17\" height=\"17\" border=\"0\" alt=\"plus\" /></a></td>\n";
155 50d86c13 Bill Marquette
		echo "      </tr>\n";
156
		echo "    </table>\n";
157
		echo "  </td>\n";
158
		echo "</tr>\n";
159
	}
160
	private function display_buttons($row) {
161 f326b978 Colin Fleming
		echo "    <table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" summary=\"display buttons\">\n";
162 50d86c13 Bill Marquette
		echo "      <tr>\n";
163 f3ec0487 Phil Davis
		if ($this->buttons['move']) {
164 50d86c13 Bill Marquette
			echo $this->display_button('move', $row);
165 f3ec0487 Phil Davis
		}
166
		if ($this->buttons['edit']) {
167 50d86c13 Bill Marquette
			echo $this->display_button('edit', $row);
168 f3ec0487 Phil Davis
		}
169 f326b978 Colin Fleming
		echo "      </tr>\n";
170 50d86c13 Bill Marquette
		echo "      <tr>\n";
171 f3ec0487 Phil Davis
		if ($this->buttons['del']) {
172 50d86c13 Bill Marquette
			echo $this->display_button('del', $row);
173 f3ec0487 Phil Davis
		}
174
		if ($this->buttons['dup']) {
175 50d86c13 Bill Marquette
			echo $this->display_button('dup', $row);
176 f3ec0487 Phil Davis
		}
177 50d86c13 Bill Marquette
		echo "      </tr>\n";
178
		echo "    </table>\n";
179
	}
180
	private function display_button($button, $row) {
181
		global $g;
182
		echo "<td valign=\"middle\">";
183
		switch ($button) {
184
			case "move": {
185 f326b978 Colin Fleming
				echo "<input name=\"move_{$row}\" type=\"image\" src=\"./themes/{$g['theme']}/images/icons/icon_left.gif\" width=\"17\" height=\"17\" title=\"Move selected entries before this entry\" onmouseover=\"fr_insline({$row}, true)\" onmouseout=\"fr_insline({$row}, false)\" />";
186 50d86c13 Bill Marquette
				break;
187
			}
188
			case "edit": {
189 f326b978 Colin Fleming
				echo "<a href=\"{$this->edit_uri}?id={$row}\"><img src=\"/themes/{$g['theme']}/images/icons/icon_e.gif\" width=\"17\" height=\"17\" border=\"0\" title=\"Edit entry\" alt=\"edit\" /></a>";
190 50d86c13 Bill Marquette
				break;
191
			}
192
			case "del": {
193 d1d6d0d3 Colin Fleming
				echo "<a href=\"{$this->my_uri}?act=del&amp;id={$row}\" onclick=\"return confirm('Do you really want to delete this entry?')\"><img src=\"/themes/{$g['theme']}/images/icons/icon_x.gif\" width=\"17\" height=\"17\" border=\"0\" title=\"Delete entry\" alt=\"delete\" /></a>";
194 50d86c13 Bill Marquette
				break;
195
			}
196
			case "dup": {
197 f326b978 Colin Fleming
				echo "<a href=\"{$this->edit_uri}?act=dup&amp;id={$row}\"><img src=\"/themes/{$g['theme']}/images/icons/icon_plus.gif\" width=\"17\" height=\"17\" border=\"0\" title=\"Duplicate entry\" alt=\"duplicate\" /></a>";
198 50d86c13 Bill Marquette
				break;
199
			}
200
		}
201
		echo "</td>";
202
	}
203
204
}
205 13d193c2 Scott Ullrich
206
?>