Project

General

Profile

Download (7.23 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
        part of pfSense (http://www.pfsense.com/)
5

    
6
        Copyright (C) 2008 Bill Marquette <bill.marquette@gmail.com>.
7
        All rights reserved.
8

    
9
        Redistribution and use in source and binary forms, with or without
10
        modification, are permitted provided that the following conditions are met:
11

    
12
        1. Redistributions of source code must retain the above copyright notice,
13
           this list of conditions and the following disclaimer.
14

    
15
        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

    
19
        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
*/
30

    
31
/*
32
	pfSense_MODULE:	guiutils
33
*/
34

    
35
/* DISABLE_PHP_LINT_CHECKING */
36

    
37
class MainTable {
38
	private $headers = array();
39
//	private $columns = array();
40
	private $columns = 0;
41
	private $rows = 0;
42
	private $content = array();
43
	private $edit_uri = '';
44
	private $my_uri = '';
45
	private $buttons = array('move' => false, 'edit' => false, 'del' => false, 'dup' => false);
46

    
47
	function add_column($header, $cname, $width) {
48
//		$this->column[] = array('header' => $header, 'cname' => $cname, 'width' => $width)
49
		$this->headers[] = $header;
50
		$this->cname[] = $cname;
51
		$this->width[] = $width;
52
		$this->columns++;
53
	}
54

    
55
	function add_content_array($rows) {
56
		foreach($rows as $row) {
57
			$this->content[] = $row;
58
			$this->rows++;
59
		}
60
	}
61
	function add_button($name) {
62
		if (isset($this->buttons[$name])) {
63
			$this->buttons[$name] = true;
64
		}
65
	}
66
	function edit_uri($uri) {
67
		$this->edit_uri = $uri;
68
	}
69

    
70
	function my_uri($uri) {
71
		$this->my_uri = $uri;
72
	}
73

    
74
	function display() {
75
		echo "<!-- begin content table -->\n";
76
		echo "<table class=\"tabcont\" width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" summary=\"display\">\n";
77
		echo "  <!-- begin content table header -->\n";
78
		echo $this->display_header();
79
		echo "  <!-- end content table header -->\n";
80
		echo "  <!-- begin content table rows -->\n";
81
		echo $this->display_rows();
82
		echo "  <!-- end content table rows -->\n";
83
		echo "  <!-- begin content table footer -->\n";
84
		echo $this->display_footer();
85
		echo "  <!-- end content table footer -->\n";
86
		echo "</table>\n";
87
		echo "<!-- end content table -->\n";
88
	}
89

    
90
	private function display_header() {
91
		global $g;
92
		echo "<tr>\n";
93
		for ($col = 0; $col < $this->columns - 1; $col++) {
94
			echo "  <td width=\"{$this->width[$col]}%\" class=\"listhdrr\">{$this->headers[$col]}</td>\n";
95
		}
96
		echo "  <td width=\"{$this->width[$this->columns - 1]}%\" class=\"listhdr\">{$this->headers[$this->columns - 1]}</td>\n";
97
		echo "  <td width=\"10%\" class=\"list\">\n";
98
		echo "    <table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" summary=\"display header\">\n";
99
		echo "      <tr>\n";
100
		echo "        <td width=\"17\"></td>\n";
101
		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";
102
		echo "      </tr>\n";
103
		echo "    </table>\n";
104
		echo "  </td>\n";
105
		echo "</tr>\n";
106

    
107
	}
108
	private function display_rows() {
109
		global $g;
110
		$cur_row = 0;
111
		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
				echo "  <td class=\"{$cl}\" onclick=\"fr_toggle({$cur_row})\" id=\"frd{$cur_row}\" ondblclick=\"document.location='{$this->edit_uri}?id={$cur_row}'\">\n";
120
				if (is_array($row[$this->cname[$col]])) {
121
					foreach ($row[$this->cname[$col]] as $data) {
122
						echo "    {$data}<br/>\n";
123
					}
124
				} else {
125
					echo "    " . $row[$this->cname[$col]] . "\n";
126
				}
127
				echo "  </td>\n";
128
			}
129
			echo "  <td class=\"listbg\" onclick=\"fr_toggle({$cur_row})\" id=\"frd{$cur_row}\" ondblclick=\"document.location=\'{$this->edit_uri}?id={$cur_row}\'\">\n";
130
			echo "    <font color=\"#FFFFFF\">{$row[$this->cname[$this->columns - 1]]}</font>\n";
131
			echo "  </td>\n";
132
			echo "  <td class=\"list nowrap\">\n";
133
			$this->display_buttons($cur_row);
134
			echo "  </td>\n";
135
			echo "</tr>\n";
136

    
137
			$cur_row++;
138
		}
139
	}
140
	private function display_footer() {
141
		global $g;
142
		echo "<tr>\n";
143
		echo "  <td class=\"list\" colspan=\"{$this->columns}\"></td>\n";
144
		echo "  <td class=\"list\">\n";
145
		echo "    <table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" summary=\"display footer\">\n";
146
		echo "      <tr>\n";
147
		echo "        <td width=\"17\"></td>\n";
148
		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";
149
		echo "      </tr>\n";
150
		echo "    </table>\n";
151
		echo "  </td>\n";
152
		echo "</tr>\n";
153
	}
154
	private function display_buttons($row) {
155
		echo "    <table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" summary=\"display buttons\">\n";
156
		echo "      <tr>\n";
157
		if ($this->buttons['move'])
158
			echo $this->display_button('move', $row);
159
		if ($this->buttons['edit'])
160
			echo $this->display_button('edit', $row);
161
		echo "      </tr>\n";
162
		echo "      <tr>\n";
163
		if ($this->buttons['del'])
164
			echo $this->display_button('del', $row);
165
		if ($this->buttons['dup'])
166
			echo $this->display_button('dup', $row);
167
		echo "      </tr>\n";
168
		echo "    </table>\n";
169
	}
170
	private function display_button($button, $row) {
171
		global $g;
172
		echo "<td valign=\"middle\">";
173
		switch ($button) {
174
			case "move": {
175
				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)\" />";
176
				break;
177
			}
178
			case "edit": {
179
				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>";
180
				break;
181
			}
182
			case "del": {
183
				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>";
184
				break;
185
			}
186
			case "dup": {
187
				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>";
188
				break;
189
			}
190
		}
191
		echo "</td>";
192
	}
193

    
194
}
195

    
196
?>
    (1-1/1)