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 |
// if item is an Array we will replace it with an link or contained form object |
167 |
elseif( is_array($obj) ) { |
168 |
$cur_row_index = $this->_datasource->get_cur_data_index(); |
169 |
$parent_guid = $this->_datasource->_data[$cur_row_index]['guid']; |
170 |
foreach($obj as $key => $value) { |
171 |
if(is_numeric($key)) { |
172 |
$guid = $value['guid']; |
173 |
$list[$key] = $guid; |
174 |
} |
175 |
} |
176 |
if(is_array($list) ) { |
177 |
$container = container( |
178 |
form_open($obj[guid], $_SERVER["PHP_SELF"] ), |
179 |
form_select("guid", $list), |
180 |
form_hidden("ap", "oview"), |
181 |
form_hidden("parent", $parent_guid), |
182 |
form_submit("submit","view" ), |
183 |
form_close() |
184 |
); |
185 |
$obj = $container; |
186 |
} else { |
187 |
$obj = html_a($_SERVER["PHP_SELF"] . "?ap=oview&guid=" . $obj['guid'] . "&parent=" . $parent_guid, "view"); |
188 |
} |
189 |
} |
190 |
|
191 |
|
192 |
//make sure we don't put a right border on the last |
193 |
//column we are working on. |
194 |
$style = "padding-left: 3px;padding-right:3px;border-top: 1px solid #dddddd;"; |
195 |
|
196 |
if ($this->_columns[$col_name]["data_name"] == $this->orderby()) { |
197 |
$style .= "background-color: #f4f4f4;"; |
198 |
} else { |
199 |
$style .= "background-color: #ffffff;"; |
200 |
} |
201 |
|
202 |
$align = $this->_columns[$col_name]["align"]; |
203 |
$td = new TDtag(array("align" => $align, |
204 |
"style" => $style, |
205 |
"class" => "font10")); |
206 |
|
207 |
if (is_object($obj) && $obj->_tag == "td") { |
208 |
return $obj; |
209 |
} else { |
210 |
$td->add( $obj ); |
211 |
} |
212 |
return $td; |
213 |
} |
214 |
|
215 |
/** |
216 |
* This builds the table that holds the search |
217 |
* capability. |
218 |
* |
219 |
* @return TABLEtag object. |
220 |
*/ |
221 |
function child_build_search_table() { |
222 |
//the search capability is enabled. |
223 |
//lets try and build the table. |
224 |
$td_attributes = array("style" => "padding-left: 5px;padding-bottom:4px;". |
225 |
"padding-right:40px;padding-top:4px;". |
226 |
"background-color: #eeeeee;", |
227 |
"align" => "left", |
228 |
"class" => "font10"); |
229 |
|
230 |
$table = html_table($this->get_width(),0,0,0,"center"); |
231 |
|
232 |
//test to see if they want to render the outer borders |
233 |
$table->set_tag_attribute("style", "border-left: 1px solid #a1a1a1;". |
234 |
"border-right: 1px solid #a1a1a1;"); |
235 |
|
236 |
$td = new TDtag($td_attributes); |
237 |
|
238 |
if ($this->search_type() == "advanced") { |
239 |
$td->push($this->_build_advanced_search_form()); |
240 |
} else { |
241 |
$td->push($this->_build_simple_search_form()); |
242 |
} |
243 |
$table->push_row($td); |
244 |
|
245 |
return container($this->_build_search_title(), $table); |
246 |
} |
247 |
|
248 |
/** |
249 |
* This function builds the search title table |
250 |
* |
251 |
* @return TABLEtag object |
252 |
*/ |
253 |
function _build_search_title() { |
254 |
//build the title stacked table |
255 |
$title = html_table($this->get_width(), 0, 0, 0, "center"); |
256 |
|
257 |
//test to see if they want to render the outer borders |
258 |
$title->set_tag_attribute("style","border: 1px solid #a1a1a1;"); |
259 |
$title->push_row(new TDtag(array("class" => "datalist_title", |
260 |
"style" => "color: ".$this->_title_fcolor.";". |
261 |
"background-color: ".$this->_title_color.";"), " Search")); |
262 |
|
263 |
return $title; |
264 |
} |
265 |
|
266 |
|
267 |
/** |
268 |
* This function builds the simple search TD |
269 |
* |
270 |
* @return ContainerWidget |
271 |
*/ |
272 |
function _build_simple_search_form() { |
273 |
|
274 |
//if there is only 1 item enabled for search |
275 |
//then the search looks simple. |
276 |
$fields = $this->_get_searchable_fields(); |
277 |
$cnt = count($fields); |
278 |
if ($cnt == 0) { |
279 |
return NULL; |
280 |
} |
281 |
|
282 |
$container = new ContainerWidget; |
283 |
|
284 |
if ($cnt == 1) { |
285 |
//user only has 1 field to show. |
286 |
list($name, $field) = each($fields); |
287 |
$container->push("Find ".$name." "); |
288 |
} else { |
289 |
//user has many fields to show. |
290 |
$container->push("Find ", |
291 |
form_select($this->_search_fieldVar, $fields, $this->search_field())); |
292 |
} |
293 |
|
294 |
if ($this->get_simple_search_modifier()) { |
295 |
//the user wants the search modifier turned on. |
296 |
$container->push($this->_build_simple_search_modifier()); |
297 |
} |
298 |
|
299 |
$container->push(form_text($this->_search_valueVar, $this->search_value_filter($this->search_value()), "20", "100", array("style"=>"vertical-align:middle;")), |
300 |
form_submit($this->get_form_name(), "Search", array("style"=>"vertical-align:middle;"))); |
301 |
|
302 |
if ($this->is_advanced_search_enabled()) { |
303 |
$span = html_span(html_a("ass","Advanced Search", "title")); |
304 |
$container->push(" ", $span); |
305 |
} |
306 |
|
307 |
if ($cnt == 1) { |
308 |
$container->push(form_hidden($this->_search_fieldVar, $field)); |
309 |
} |
310 |
|
311 |
$hidden_fields = $this->get_hidden_fields(); |
312 |
if(is_array($hidden_fields)) { |
313 |
foreach($hidden_fields as $key => $value) { |
314 |
$container->push(form_hidden($key, $value)); |
315 |
} |
316 |
} |
317 |
|
318 |
$container->push(form_close() ); |
319 |
|
320 |
return $container; |
321 |
} |
322 |
|
323 |
|
324 |
function get_hidden_fields() { |
325 |
user_error("DefaulGUIDataList::get_hidden_fields() - ". |
326 |
"child class must override this method ". |
327 |
"this function should return a hash for hidden fields, if not needed just return" ); |
328 |
} |
329 |
|
330 |
} |
331 |
|
332 |
/** |
333 |
* This class defines the css used by the |
334 |
* FooterNav Object. |
335 |
* |
336 |
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
337 |
* @package phpHtmlLib |
338 |
*/ |
339 |
class DefaultGUIDataListCSS extends CSSBuilder { |
340 |
|
341 |
function user_setup() { |
342 |
$this->add_entry(".datalist_col_head", "", |
343 |
array("font-family" => "arial, helvetica, sans-serif", |
344 |
"font-size" => "10pt", |
345 |
"font-weight" => "bold", |
346 |
"color" => "#000000", |
347 |
"background-color" => "#CCCCCC", |
348 |
"text-align" => "left", |
349 |
"white-space" => "nowrap", |
350 |
"height" => "20px", |
351 |
"vertical-align" => "middle", |
352 |
"border-left" => "1px solid white", |
353 |
"border-top" => "1px solid white", |
354 |
"border-right" => "1px solid gray", |
355 |
"border-bottom" => "1px solid gray", |
356 |
"padding-left" => "3px", |
357 |
"padding-right" => "3px") ); |
358 |
|
359 |
$this->add_entry(".datalist_col_head", "a.form_link:active,a.form_link:visited,a.form_link:link", |
360 |
array("color" => "#000000", |
361 |
"text-decoration" => "none")); |
362 |
|
363 |
$this->add_entry(".datalist_col_head_hover", "", |
364 |
array("font-family" => "arial, helvetica, sans-serif", |
365 |
"font-size" => "10pt", |
366 |
"font-weight" => "bold", |
367 |
"color" => "#000000", |
368 |
"background-color" => "#dcdcdc", |
369 |
"text-align" => "left", |
370 |
"white-space" => "nowrap", |
371 |
"height" => "20px", |
372 |
"vertical-align" => "middle", |
373 |
"border-left" => "1px solid white", |
374 |
"border-top" => "1px solid white", |
375 |
"border-right" => "1px solid gray", |
376 |
"border-bottom" => "1px solid gray", |
377 |
"padding-left" => "3px", |
378 |
"padding-right" => "3px") ); |
379 |
|
380 |
$this->add_entry(".datalist_col_head_clicked", "", |
381 |
array("font-family" => "arial, helvetica, sans-serif", |
382 |
"font-size" => "10pt", |
383 |
"font-weight" => "bold", |
384 |
"color" => "#000000", |
385 |
"background-color" => "#dddddd", |
386 |
"text-align" => "left", |
387 |
"white-space" => "nowrap", |
388 |
"height" => "20px", |
389 |
"vertical-align" => "middle", |
390 |
"border-left" => "1px solid white", |
391 |
"border-top" => "1px solid white", |
392 |
"border-right" => "1px solid gray", |
393 |
"border-bottom" => "1px solid gray", |
394 |
"padding-left" => "3px", |
395 |
"padding-right" => "3px") ); |
396 |
|
397 |
$this->add_entry( ".datalist_border", "", |
398 |
array("border" => "1px solid #999999")); |
399 |
|
400 |
$this->add_entry( ".datalist_title", "", |
401 |
array("font-family" => "arial", |
402 |
"font-size" => "10pt", |
403 |
"font-weight" => "bold", |
404 |
"color" => "#FFFFFF", |
405 |
"background-color" => "#999999", |
406 |
"white-space" =>"nowrap")); |
407 |
} |
408 |
} |
409 |
?> |