Project

General

Profile

Download (6.99 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
/* DISABLE_PHP_LINT_CHECKING */
32

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

    
43
	function add_column($header, $cname, $width) {
44
//		$this->column[] = array('header' => $header, 'cname' => $cname, 'width' => $width)
45
		$this->headers[] = $header;
46
		$this->cname[] = $cname;
47
		$this->width[] = $width;
48
		$this->columns++;
49
	}
50

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

    
66
	function my_uri($uri) {
67
		$this->my_uri = $uri;
68
	}
69

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

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

    
103
	}
104
	private function display_rows() {
105
		global $g;
106
		$cur_row = 0;
107
		foreach ($this->content as $row) {
108
			echo "<tr>\n";
109
			for ($col = 0; $col < $this->columns - 1; $col++) {
110
				if ($col == 0) {
111
					$cl = 'listlr';
112
				} else {
113
					$cl = 'listr';
114
				}
115
				echo "  <td class=\"{$cl}\" onClick=\"fr_toggle({$cur_row})\" id=\"frd{$cur_row}\" ondblclick=\"document.location=\'{$this->edit_uri}?id={$cur_row}\'\">\n";
116
				if (is_array($row[$this->cname[$col]])) {
117
					foreach ($row[$this->cname[$col]] as $data) {
118
						echo "    {$data}<br/>\n";
119
					}
120
				} else {
121
					echo "    " . $row[$this->cname[$col]] . "\n";
122
				}
123
				echo "  </td>\n";
124
			}
125
			echo "  <td class=\"listbg\" onClick=\"fr_toggle({$cur_row})\" id=\"frd{$cur_row}\" ondblclick=\"document.location=\'{$this->edit_uri}?id={$cur_row}\'\">\n";
126
			echo "    <font color=\"#FFFFFF\">{$row[$this->cname[$this->columns - 1]]}</font>\n";
127
			echo "  </td>\n";
128
			echo "  <td class=\"list\" nowrap>\n";
129
			$this->display_buttons($cur_row);
130
			echo "  </td>\n";
131
			echo "</tr>\n";
132

    
133
			$cur_row++;
134
		}
135
	}
136
	private function display_footer() {
137
		global $g;
138
		echo "<tr>\n";
139
		echo "  <td class=\"list\" colspan=\"{$this->columns}\"></td>\n";
140
		echo "  <td class=\"list\">\n";
141
		echo "    <table border=\"0\" cellspacing=\"0\" cellpadding=\"1\">\n";
142
		echo "      <tr>\n";
143
		echo "        <td width=\"17\"></td>\n";
144
		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\"></a></td>\n";
145
		echo "      </tr>\n";
146
		echo "    </table>\n";
147
		echo "  </td>\n";
148
		echo "</tr>\n";
149
	}
150
	private function display_buttons($row) {
151
		echo "    <table border=\"0\" cellspacing=\"0\" cellpadding=\"1\">\n";
152
		echo "      <tr>\n";
153
		if ($this->buttons['move'])
154
			echo $this->display_button('move', $row);
155
		if ($this->buttons['edit'])
156
			echo $this->display_button('edit', $row);
157
		echo "      <tr>\n";
158
		if ($this->buttons['del'])
159
			echo $this->display_button('del', $row);
160
		if ($this->buttons['dup'])
161
			echo $this->display_button('dup', $row);
162
		echo "      </tr>\n";
163
		echo "    </table>\n";
164
	}
165
	private function display_button($button, $row) {
166
		global $g;
167
		echo "<td valign=\"middle\">";
168
		switch ($button) {
169
			case "move": {
170
				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)\">";
171
				break;
172
			}
173
			case "edit": {
174
				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\"></a>";
175
				break;
176
			}
177
			case "del": {
178
				echo "<a href=\"{$this->my_uri}?act=del&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\"></a>";
179
				break;
180
			}
181
			case "dup": {
182
				echo "<a href=\"{$this->edit_uri}?act=dup&id={$row}\"><img src=\"/themes/{$g['theme']}/images/icons/icon_plus.gif\" width=\"17\" height=\"17\" border=\"0\" title=\"Duplicate entry\"></a>";			
183
				break;
184
			}
185
		}
186
		echo "</td>";
187
	}
188

    
189
}
190
?>
    (1-1/1)