1 |
<?php |
2 |
|
3 |
/** |
4 |
* |
5 |
* This file contains the Default DataList child |
6 |
* that has its specific GUI layout/look/feel |
7 |
* |
8 |
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
9 |
* @package phpHtmlLib |
10 |
* |
11 |
*/ |
12 |
|
13 |
|
14 |
/** |
15 |
* This class is the Default phpHtmlLib GUI interface |
16 |
* child of the DataList class. This child simply does |
17 |
* the job of rendering the html/layout for a DataList. |
18 |
* You can use this as an example of how to build your |
19 |
* own look/feel for your DataList. |
20 |
* |
21 |
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
22 |
* @package phpHtmlLib |
23 |
* |
24 |
*/ |
25 |
class DefaultGUIDatalist extends DataList { |
26 |
|
27 |
function gui_init() { |
28 |
$container = container(); |
29 |
$container->add( $this->build_tool_link("first"), |
30 |
$this->build_tool_link("prev"), |
31 |
$this->build_tool_link("next"), |
32 |
$this->build_tool_link("last"), |
33 |
$this->build_tool_link("all"), |
34 |
$this->get_page_info() ); |
35 |
|
36 |
$this->_data_table = html_table($this->get_width(),0,0,0,"center"); |
37 |
$this->_data_table->set_class("datalist_border"); |
38 |
|
39 |
$this->_tool_td = html_td("datalist_title", "right", $container); |
40 |
$this->_tool_td->set_style("padding-top: 5px; padding-right: 5px;"); |
41 |
$this->_tool_td->set_tag_attribute("colspan", count($this->_columns)-1); |
42 |
|
43 |
$title = new TDtag(array("align" => "left", |
44 |
"class" => "datalist_title", |
45 |
"style" => "padding-left: 5px;"), |
46 |
$this->get_title() ); |
47 |
|
48 |
//add the header tr reference |
49 |
//it will get populated later |
50 |
$this->_header_tr = new TRtag; |
51 |
$this->_data_table->add( new TRtag(array(), $title, $this->_tool_td) ); |
52 |
$this->_data_table->add_reference($this->_header_tr); |
53 |
|
54 |
//initialize the first date row |
55 |
$this->_data_row = new TRtag; |
56 |
|
57 |
//enable search |
58 |
$this->search_enable(); |
59 |
$this->set_simple_search_modifier(); |
60 |
|
61 |
} |
62 |
|
63 |
function child_build_column_header($name, $col, $cnt) { |
64 |
$td = $this->build_column_header($name, $col, $cnt); |
65 |
$this->_header_tr->add( $td ); |
66 |
} |
67 |
|
68 |
function child_add_row_cell($obj, $col_name, $last_in_row_flag) { |
69 |
$td = $this->wrap_column_item($obj, $col_name); |
70 |
|
71 |
$this->_data_row->add( $td ); |
72 |
if ($last_in_row_flag) { |
73 |
$this->_data_table->add_row( $this->_data_row ); |
74 |
$this->_data_row = new TRtag; |
75 |
} |
76 |
} |
77 |
|
78 |
function child_get_gui() { |
79 |
return $this->_data_table; |
80 |
} |
81 |
|
82 |
/** |
83 |
* This function builds the object/text |
84 |
* to be used for a column header. It can |
85 |
* either be an href because its sortable, |
86 |
* or it can just be text, because its not |
87 |
* sortable. |
88 |
* |
89 |
* @param string $col_name - the column name |
90 |
* to build from |
91 |
* the headers. |
92 |
* @param array $col_data - the column's data. |
93 |
* @param int the column # we are working on. |
94 |
* @return mixed - either an Atag object or |
95 |
* raw text. |
96 |
*/ |
97 |
function build_column_header($col_name, $col_data, $col_num) { |
98 |
|
99 |
$td = new TDtag(array("class"=>"datalist_col_head", |
100 |
"width" => $col_data["size"])); |
101 |
|
102 |
if ($this->_columns[$col_name]["sortable"]) { |
103 |
$col_url = $this->build_column_url($col_name); |
104 |
|
105 |
$td->set_tag_attribute("title","Sort By ".$col_name); |
106 |
|
107 |
$td->push(html_a($col_url, $col_name,"form_link")); |
108 |
|
109 |
if ($this->_columns[$col_name]["data_name"] == $this->orderby()) { |
110 |
|
111 |
if ($this->reverseorder() == "false") { |
112 |
$alt_title = "Sorted in Ascending Order"; |
113 |
$img = html_img($this->get_image_path()."/picto_down.gif",11,11,'',$alt_title); |
114 |
$img->set_tag_attribute("style", "padding-left: 5px;margin-left:5px;vertical-align:middle;"); |
115 |
$td->push($img); |
116 |
} else { |
117 |
$alt_title = "Sorted in Descending Order"; |
118 |
$img = html_img($this->get_image_path()."/picto_up.gif",11,11,'',$alt_title); |
119 |
$img->set_tag_attribute("style", "padding-left: 5px;margin-left:5px;vertical-align:middle;"); |
120 |
$td->push($img); |
121 |
} |
122 |
} |
123 |
|
124 |
// we want to highlight the td on mouse over |
125 |
$td->set_tag_attribute("onMouseOver", |
126 |
"javascript:style.cursor='hand';this.className='datalist_col_head_hover';"); |
127 |
$td->set_tag_attribute("onMouseOut", |
128 |
"javascript:this.className='datalist_col_head'"); |
129 |
$td->set_tag_attribute("onMouseDown", |
130 |
"javascript:this.className='datalist_col_head_clicked'"); |
131 |
|
132 |
|
133 |
if ($this->get_form_method() == "POST") { |
134 |
$td->set_tag_attribute("onClick", $col_url); |
135 |
} |
136 |
else { |
137 |
$td->set_tag_attribute("onClick", "javascript:document.location='".$col_url."';"); |
138 |
} |
139 |
} else { |
140 |
$td->push($col_name); |
141 |
$td->set_tag_attribute("style", $style."padding-left:5px;padding-right:5px;white-space:nowrap;"); |
142 |
} |
143 |
|
144 |
return $td; |
145 |
} |
146 |
|
147 |
/** |
148 |
* This function ensures that the data we place |
149 |
* in a column is aligned according to what the |
150 |
* user wants. |
151 |
* |
152 |
* @param mixed - $obj - the data for the td. |
153 |
* @param string - $col_name - the name of the column header |
154 |
* for this row to render. |
155 |
* @param int - $odd_row - tells us if this cell lives in |
156 |
* an odd # row (for alternating row colors) |
157 |
* @param int - the column # we are working on. |
158 |
* @return TDtag object |
159 |
*/ |
160 |
function wrap_column_item($obj, $col_name) { |
161 |
|
162 |
//make sure its set to something. |
163 |
if ($obj == '') { |
164 |
$obj = " "; |
165 |
} |
166 |
|
167 |
//make sure we don't put a right border on the last |
168 |
//column we are working on. |
169 |
$style = "padding-left: 3px;padding-right:3px;border-top: 1px solid #dddddd;"; |
170 |
|
171 |
if ($this->_columns[$col_name]["data_name"] == $this->orderby()) { |
172 |
$style .= "background-color: #f4f4f4;"; |
173 |
} else { |
174 |
$style .= "background-color: #ffffff;"; |
175 |
} |
176 |
|
177 |
$align = $this->_columns[$col_name]["align"]; |
178 |
$td = new TDtag(array("align" => $align, |
179 |
"style" => $style, |
180 |
"class" => "font10")); |
181 |
|
182 |
if (is_object($obj) && $obj->_tag == "td") { |
183 |
return $obj; |
184 |
} else { |
185 |
$td->add( $obj ); |
186 |
} |
187 |
return $td; |
188 |
} |
189 |
|
190 |
/** |
191 |
* This builds the table that holds the search |
192 |
* capability. |
193 |
* |
194 |
* @return TABLEtag object. |
195 |
*/ |
196 |
function child_build_search_table() { |
197 |
//the search capability is enabled. |
198 |
//lets try and build the table. |
199 |
$td_attributes = array("style" => "padding-left: 5px;padding-bottom:4px;". |
200 |
"padding-right:40px;padding-top:4px;". |
201 |
"background-color: #eeeeee;", |
202 |
"align" => "left", |
203 |
"class" => "font10"); |
204 |
|
205 |
$table = html_table($this->get_width(),0,0,0,"center"); |
206 |
|
207 |
//test to see if they want to render the outer borders |
208 |
$table->set_tag_attribute("style", "border-left: 1px solid #a1a1a1;". |
209 |
"border-right: 1px solid #a1a1a1;"); |
210 |
|
211 |
$td = new TDtag($td_attributes); |
212 |
|
213 |
if ($this->search_type() == "advanced") { |
214 |
$td->push($this->_build_advanced_search_form()); |
215 |
} else { |
216 |
$td->push($this->_build_simple_search_form()); |
217 |
} |
218 |
$table->push_row($td); |
219 |
|
220 |
return container($this->_build_search_title(), $table); |
221 |
} |
222 |
|
223 |
/** |
224 |
* This function builds the search title table |
225 |
* |
226 |
* @return TABLEtag object |
227 |
*/ |
228 |
function _build_search_title() { |
229 |
//build the title stacked table |
230 |
$title = html_table($this->get_width(), 0, 0, 0, "center"); |
231 |
|
232 |
//test to see if they want to render the outer borders |
233 |
$title->set_tag_attribute("style","border: 1px solid #a1a1a1;"); |
234 |
$title->push_row(new TDtag(array("class" => "datalist_title", |
235 |
"style" => "color: ".$this->_title_fcolor.";". |
236 |
"background-color: ".$this->_title_color.";"), " Search")); |
237 |
|
238 |
return $title; |
239 |
} |
240 |
|
241 |
|
242 |
/** |
243 |
* This function builds the simple search TD |
244 |
* |
245 |
* @return ContainerWidget |
246 |
*/ |
247 |
function _build_simple_search_form() { |
248 |
|
249 |
//if there is only 1 item enabled for search |
250 |
//then the search looks simple. |
251 |
$fields = $this->_get_searchable_fields(); |
252 |
$cnt = count($fields); |
253 |
if ($cnt == 0) { |
254 |
return NULL; |
255 |
} |
256 |
|
257 |
$container = new ContainerWidget; |
258 |
|
259 |
if ($cnt == 1) { |
260 |
//user only has 1 field to show. |
261 |
list($name, $field) = each($fields); |
262 |
$container->push("Find ".$name." "); |
263 |
} else { |
264 |
//user has many fields to show. |
265 |
$container->push("Find ", |
266 |
form_select($this->_search_fieldVar, $fields, $this->search_field())); |
267 |
} |
268 |
|
269 |
if ($this->get_simple_search_modifier()) { |
270 |
//the user wants the search modifier turned on. |
271 |
$container->push($this->_build_simple_search_modifier()); |
272 |
} |
273 |
|
274 |
$container->push(form_text($this->_search_valueVar, $this->search_value_filter($this->search_value()), "20", "100", array("style"=>"vertical-align:middle;")), |
275 |
form_submit($this->get_form_name(), "Search", array("style"=>"vertical-align:middle;"))); |
276 |
|
277 |
if ($this->is_advanced_search_enabled()) { |
278 |
$span = html_span(html_a("ass","Advanced Search", "title")); |
279 |
$container->push(" ", $span); |
280 |
} |
281 |
|
282 |
if ($cnt == 1) { |
283 |
$container->push(form_hidden($this->_search_fieldVar, $field)); |
284 |
} |
285 |
|
286 |
return $container; |
287 |
} |
288 |
} |
289 |
|
290 |
/** |
291 |
* This class defines the css used by the |
292 |
* FooterNav Object. |
293 |
* |
294 |
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
295 |
* @package phpHtmlLib |
296 |
*/ |
297 |
class DefaultGUIDataListCSS extends CSSBuilder { |
298 |
|
299 |
function user_setup() { |
300 |
$this->add_entry(".datalist_col_head", "", |
301 |
array("font-family" => "arial, helvetica, sans-serif", |
302 |
"font-size" => "10pt", |
303 |
"font-weight" => "bold", |
304 |
"color" => "#000000", |
305 |
"background-color" => "#CCCCCC", |
306 |
"text-align" => "left", |
307 |
"white-space" => "nowrap", |
308 |
"height" => "20px", |
309 |
"vertical-align" => "middle", |
310 |
"border-left" => "1px solid white", |
311 |
"border-top" => "1px solid white", |
312 |
"border-right" => "1px solid gray", |
313 |
"border-bottom" => "1px solid gray", |
314 |
"padding-left" => "3px", |
315 |
"padding-right" => "3px") ); |
316 |
|
317 |
$this->add_entry(".datalist_col_head", "a.form_link:active,a.form_link:visited,a.form_link:link", |
318 |
array("color" => "#000000", |
319 |
"text-decoration" => "none")); |
320 |
|
321 |
$this->add_entry(".datalist_col_head_hover", "", |
322 |
array("font-family" => "arial, helvetica, sans-serif", |
323 |
"font-size" => "10pt", |
324 |
"font-weight" => "bold", |
325 |
"color" => "#000000", |
326 |
"background-color" => "#dcdcdc", |
327 |
"text-align" => "left", |
328 |
"white-space" => "nowrap", |
329 |
"height" => "20px", |
330 |
"vertical-align" => "middle", |
331 |
"border-left" => "1px solid white", |
332 |
"border-top" => "1px solid white", |
333 |
"border-right" => "1px solid gray", |
334 |
"border-bottom" => "1px solid gray", |
335 |
"padding-left" => "3px", |
336 |
"padding-right" => "3px") ); |
337 |
|
338 |
$this->add_entry(".datalist_col_head_clicked", "", |
339 |
array("font-family" => "arial, helvetica, sans-serif", |
340 |
"font-size" => "10pt", |
341 |
"font-weight" => "bold", |
342 |
"color" => "#000000", |
343 |
"background-color" => "#dddddd", |
344 |
"text-align" => "left", |
345 |
"white-space" => "nowrap", |
346 |
"height" => "20px", |
347 |
"vertical-align" => "middle", |
348 |
"border-left" => "1px solid white", |
349 |
"border-top" => "1px solid white", |
350 |
"border-right" => "1px solid gray", |
351 |
"border-bottom" => "1px solid gray", |
352 |
"padding-left" => "3px", |
353 |
"padding-right" => "3px") ); |
354 |
|
355 |
$this->add_entry( ".datalist_border", "", |
356 |
array("border" => "1px solid #999999")); |
357 |
|
358 |
$this->add_entry( ".datalist_title", "", |
359 |
array("font-family" => "arial", |
360 |
"font-size" => "10pt", |
361 |
"font-weight" => "bold", |
362 |
"color" => "#FFFFFF", |
363 |
"background-color" => "#999999", |
364 |
"white-space" =>"nowrap")); |
365 |
} |
366 |
} |
367 |
?> |