1 |
jonen |
1.1 |
<?php |
2 |
|
|
/** |
3 |
|
|
* This file holds the ListAction object, which |
4 |
|
|
* can be used to handle an action from a post |
5 |
|
|
* of the checkbox data from the DefaultGUIDataList |
6 |
|
|
* |
7 |
|
|
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
8 |
|
|
* @package phpHtmlLib |
9 |
|
|
*/ |
10 |
|
|
|
11 |
|
|
/** |
12 |
|
|
* A class for showing a list of items |
13 |
|
|
* to preform an action on |
14 |
|
|
* |
15 |
|
|
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
16 |
|
|
* @package phpHtmlLib |
17 |
|
|
*/ |
18 |
|
|
class ListAction extends DataList { |
19 |
|
|
|
20 |
|
|
/** |
21 |
|
|
* The string that describes |
22 |
|
|
* the action |
23 |
|
|
* ie. 'delete' |
24 |
|
|
*/ |
25 |
|
|
var $_action_name = 'delete'; |
26 |
|
|
|
27 |
|
|
|
28 |
|
|
/** |
29 |
|
|
* name/description of the type of |
30 |
|
|
* data we are working on |
31 |
|
|
* ie 'users', 'files' |
32 |
|
|
*/ |
33 |
|
|
var $_item_name = ''; |
34 |
|
|
|
35 |
|
|
/** |
36 |
|
|
* The overall alignment |
37 |
|
|
* |
38 |
|
|
* DEFAULT: "center" |
39 |
|
|
*/ |
40 |
|
|
var $_align = "center"; |
41 |
|
|
|
42 |
|
|
|
43 |
|
|
/** |
44 |
|
|
* A flag to tell us to save all |
45 |
|
|
* vars passed |
46 |
|
|
*/ |
47 |
|
|
var $_save_all_vars = TRUE; |
48 |
|
|
|
49 |
|
|
/** |
50 |
|
|
* This sets the url for the |
51 |
|
|
* cancel action to post to |
52 |
|
|
*/ |
53 |
|
|
var $_cancel_url = "index.php"; |
54 |
|
|
|
55 |
|
|
|
56 |
|
|
/** |
57 |
|
|
* The name of the array variable |
58 |
|
|
* that the data was posted to us |
59 |
|
|
* |
60 |
|
|
*/ |
61 |
|
|
var $_data_post_name = "checkbox"; |
62 |
|
|
|
63 |
|
|
|
64 |
|
|
/****************************************/ |
65 |
|
|
/* The required DataList child methods */ |
66 |
|
|
/****************************************/ |
67 |
|
|
|
68 |
|
|
/** |
69 |
|
|
* Initialize the gui layout |
70 |
|
|
* |
71 |
|
|
*/ |
72 |
|
|
function gui_init() { |
73 |
|
|
|
74 |
|
|
$this->set_form_render(TRUE); |
75 |
|
|
$this->search_disable(); |
76 |
|
|
|
77 |
|
|
$this->_data_table = html_table($this->get_width(),0,0,0, |
78 |
|
|
$this->_align); |
79 |
|
|
$this->_data_table->set_class("datalist_border"); |
80 |
|
|
|
81 |
|
|
//add the header tr reference |
82 |
|
|
//it will get populated later |
83 |
|
|
$this->_header_tr = new TRtag; |
84 |
|
|
|
85 |
|
|
//initialize the first date row |
86 |
|
|
$this->_data_row = new TRtag; |
87 |
|
|
|
88 |
|
|
if (!is_array($_REQUEST[$this->_data_post_name]) || |
89 |
|
|
$data_post_count <= 0) { |
90 |
|
|
// The user didn't select anything to delete. |
91 |
|
|
$err_string = "Please select at least one ". $this->_item_name. " to delete."; |
92 |
|
|
$dialog = messagebox_ok("Error", $err_string, "index.php?tab_selected=$tab_selected&showall=$showall", |
93 |
|
|
array(), "50%"); |
94 |
|
|
return $dialog; |
95 |
|
|
} |
96 |
|
|
} |
97 |
|
|
|
98 |
|
|
function child_get_gui() { |
99 |
|
|
$this->_build_hidden_vars(); |
100 |
|
|
$wrapper = $this->_build_delete_confirm(); |
101 |
|
|
$wrapper->add($this->_data_table); |
102 |
|
|
return $wrapper; |
103 |
|
|
//return container( $this->_data_table ); |
104 |
|
|
} |
105 |
|
|
|
106 |
|
|
function child_build_column_header($name, $col, $cnt) { |
107 |
|
|
$td = $this->build_column_header($name, $col, $cnt); |
108 |
|
|
$this->_header_tr->add( $td ); |
109 |
|
|
} |
110 |
|
|
|
111 |
|
|
|
112 |
|
|
function child_add_row_cell($obj, $col_name, $last_in_row_flag, $row_data) { |
113 |
|
|
//show the normal data |
114 |
|
|
$td = $this->wrap_column_item($obj, $col_name); |
115 |
|
|
$this->_data_row->add( $td ); |
116 |
|
|
|
117 |
|
|
if ($last_in_row_flag) { |
118 |
|
|
$this->_data_table->add_row( $this->_data_row ); |
119 |
|
|
$this->_data_row = new TRtag; |
120 |
|
|
} |
121 |
|
|
} |
122 |
|
|
|
123 |
|
|
|
124 |
|
|
/** |
125 |
|
|
* This builds the hidden form fields |
126 |
|
|
* of the data that was originally sent |
127 |
|
|
* to us |
128 |
|
|
* |
129 |
|
|
* @return Container |
130 |
|
|
*/ |
131 |
|
|
function _build_hidden_vars() { |
132 |
|
|
$save_vars = array(); |
133 |
|
|
$x=0; |
134 |
|
|
if ($_REQUEST[$this->_data_post_name]) { |
135 |
|
|
foreach ( $_REQUEST[$this->_data_post_name] as $value ) { |
136 |
|
|
$save_vars[$this->_data_post_name."[".$x."]"] = $value; |
137 |
|
|
$x++; |
138 |
|
|
} |
139 |
|
|
$this->set_save_vars( $save_vars ); |
140 |
|
|
} |
141 |
|
|
} |
142 |
|
|
|
143 |
|
|
|
144 |
|
|
/** |
145 |
|
|
* This function builds the object/text |
146 |
|
|
* to be used for a column header. It can |
147 |
|
|
* either be an href because its sortable, |
148 |
|
|
* or it can just be text, because its not |
149 |
|
|
* sortable. |
150 |
|
|
* |
151 |
|
|
* @param string $col_name - the column name |
152 |
|
|
* to build from |
153 |
|
|
* the headers. |
154 |
|
|
* @param array $col_data - the column's data. |
155 |
|
|
* @param int the column # we are working on. |
156 |
|
|
* @return mixed - either an Atag object or |
157 |
|
|
* raw text. |
158 |
|
|
*/ |
159 |
|
|
function build_column_header($col_name, $col_data, $col_num) { |
160 |
|
|
|
161 |
|
|
$td = new TDtag(array("class"=>"datalist_col_head", |
162 |
|
|
"width" => $col_data["size"])); |
163 |
|
|
|
164 |
|
|
if ($this->_columns[$col_name]["sortable"]) { |
165 |
|
|
$col_url = $this->build_column_url($col_name); |
166 |
|
|
|
167 |
|
|
$td->set_tag_attribute("title","Sort By ".$col_name); |
168 |
|
|
|
169 |
|
|
$td->push(html_a($col_url, $col_name,"form_link")); |
170 |
|
|
|
171 |
|
|
if ($this->_columns[$col_name]["data_name"] == $this->orderby()) { |
172 |
|
|
|
173 |
|
|
if ($this->reverseorder() == "false") { |
174 |
|
|
$alt_title = "Sorted in Ascending Order"; |
175 |
|
|
$img = html_img($this->get_image_path()."/picto_down.gif",11,11,'',$alt_title); |
176 |
|
|
$img->set_tag_attribute("style", "padding-left: 5px;margin-left:5px;vertical-align:middle;"); |
177 |
|
|
$td->push($img); |
178 |
|
|
} else { |
179 |
|
|
$alt_title = "Sorted in Descending Order"; |
180 |
|
|
$img = html_img($this->get_image_path()."/picto_up.gif",11,11,'',$alt_title); |
181 |
|
|
$img->set_tag_attribute("style", "padding-left: 5px;margin-left:5px;vertical-align:middle;"); |
182 |
|
|
$td->push($img); |
183 |
|
|
} |
184 |
|
|
} |
185 |
|
|
|
186 |
|
|
// we want to highlight the td on mouse over |
187 |
|
|
$td->set_tag_attribute("onMouseOver", |
188 |
|
|
"javascript:style.cursor='hand';this.className='datalist_col_head_hover';"); |
189 |
|
|
$td->set_tag_attribute("onMouseOut", |
190 |
|
|
"javascript:this.className='datalist_col_head'"); |
191 |
|
|
$td->set_tag_attribute("onMouseDown", |
192 |
|
|
"javascript:this.className='datalist_col_head_clicked'"); |
193 |
|
|
|
194 |
|
|
|
195 |
|
|
if ($this->get_form_method() == "POST") { |
196 |
|
|
$td->set_tag_attribute("onClick", $col_url); |
197 |
|
|
} |
198 |
|
|
else { |
199 |
|
|
$td->set_tag_attribute("onClick", "javascript:document.location='".$col_url."';"); |
200 |
|
|
} |
201 |
|
|
} else { |
202 |
|
|
$td->push($col_name); |
203 |
|
|
$td->set_tag_attribute("style", $style."padding-left:5px;padding-right:5px;white-space:nowrap;"); |
204 |
|
|
} |
205 |
|
|
|
206 |
|
|
return $td; |
207 |
|
|
} |
208 |
|
|
|
209 |
|
|
/** |
210 |
|
|
* This function ensures that the data we place |
211 |
|
|
* in a column is aligned according to what the |
212 |
|
|
* user wants. |
213 |
|
|
* |
214 |
|
|
* @param mixed - $obj - the data for the td. |
215 |
|
|
* @param string - $col_name - the name of the column header |
216 |
|
|
* for this row to render. |
217 |
|
|
* @param int - $odd_row - tells us if this cell lives in |
218 |
|
|
* an odd # row (for alternating row colors) |
219 |
|
|
* @param int - the column # we are working on. |
220 |
|
|
* @return TDtag object |
221 |
|
|
*/ |
222 |
|
|
function wrap_column_item($obj, $col_name) { |
223 |
|
|
|
224 |
|
|
//make sure its set to something. |
225 |
|
|
if ($obj == '') { |
226 |
|
|
$obj = " "; |
227 |
|
|
} |
228 |
|
|
|
229 |
|
|
//make sure we don't put a right border on the last |
230 |
|
|
//column we are working on. |
231 |
|
|
//$style = "padding-left: 3px;padding-right:3px;border-top: 1px solid #dddddd;"; |
232 |
|
|
|
233 |
|
|
|
234 |
|
|
if ($this->_columns[$col_name]["data_name"] == $this->orderby()) { |
235 |
|
|
$style = "background-color: #f4f4f4;"; |
236 |
|
|
} else { |
237 |
|
|
$style = "background-color: #ffffff;"; |
238 |
|
|
} |
239 |
|
|
|
240 |
|
|
$align = $this->_columns[$col_name]["align"]; |
241 |
|
|
$td = new TDtag(array("align" => $align, |
242 |
|
|
"style" => $style, |
243 |
|
|
"class" => "datalist_data_cell")); |
244 |
|
|
|
245 |
|
|
if (is_object($obj) && $obj->_tag == "td") { |
246 |
|
|
return $obj; |
247 |
|
|
} else { |
248 |
|
|
$td->add( $obj ); |
249 |
|
|
} |
250 |
|
|
return $td; |
251 |
|
|
} |
252 |
|
|
|
253 |
|
|
|
254 |
|
|
|
255 |
|
|
/****************************************/ |
256 |
|
|
/* The Methods specific to the logic */ |
257 |
|
|
/* of handling the action. */ |
258 |
|
|
/****************************************/ |
259 |
|
|
|
260 |
|
|
|
261 |
|
|
|
262 |
|
|
/** |
263 |
|
|
* Build any additional custom options |
264 |
|
|
* such as checkboxes, radiobuttons |
265 |
|
|
* for special options for the action. |
266 |
|
|
*/ |
267 |
|
|
function build_options() { |
268 |
|
|
return NULL; |
269 |
|
|
} |
270 |
|
|
|
271 |
|
|
|
272 |
|
|
/** |
273 |
|
|
* This method is used to build the portion |
274 |
|
|
* of the DB query that limits the list of |
275 |
|
|
* items to show based on what was submitted |
276 |
|
|
* from the original DataList action |
277 |
|
|
* |
278 |
|
|
* @param string - the field |
279 |
|
|
* @return string |
280 |
|
|
*/ |
281 |
|
|
function build_in_clause($field) { |
282 |
|
|
|
283 |
|
|
if (!$_REQUEST[$this->_data_post_name]) { |
284 |
|
|
return NULL; |
285 |
|
|
} else { |
286 |
|
|
$clause = $field." in ("; |
287 |
|
|
foreach ($_REQUEST[$this->_data_post_name] as $value ) { |
288 |
|
|
$query .= "'".$value."',"; |
289 |
|
|
} |
290 |
|
|
|
291 |
|
|
$query = substr($query, 0, strlen($query)-1); |
292 |
|
|
$clause .= $query .") "; |
293 |
|
|
return $clause; |
294 |
|
|
} |
295 |
|
|
} |
296 |
|
|
|
297 |
|
|
|
298 |
|
|
/** |
299 |
|
|
* This function builds the actual form |
300 |
|
|
*/ |
301 |
|
|
function _build_delete_confirm() { |
302 |
|
|
|
303 |
|
|
$showall = $_REQUEST["showall"]; |
304 |
|
|
$data_post_count = count($_REQUEST[$this->_data_post_name]); |
305 |
|
|
|
306 |
|
|
$container = container(); |
307 |
|
|
|
308 |
|
|
|
309 |
|
|
|
310 |
|
|
// handle plural case |
311 |
|
|
if ($data_post_count > 1) $plural = "s"; |
312 |
|
|
else $plural = ""; |
313 |
|
|
|
314 |
|
|
$table = new InfoTable(ucfirst($this->_action_name) . " Confirmation", $this->get_width()); |
315 |
|
|
|
316 |
|
|
$content = html_table("100%"); |
317 |
|
|
//$content->set_default_col_attributes(array("class"=>"f10-1")); |
318 |
|
|
|
319 |
|
|
$td = new TDTag(array("class"=>"f10-1","align"=>"center")); |
320 |
|
|
$td->push(html_br(), |
321 |
|
|
html_b("Are you sure you want to ".$this->_action_name." the following " . $this->_item_name . $plural . "?"), |
322 |
|
|
html_br(),html_br()); |
323 |
|
|
|
324 |
|
|
$content->add_row($td); |
325 |
|
|
|
326 |
|
|
// add any additional options |
327 |
|
|
if ($options = $this->build_options()) $content->add_row($options); |
328 |
|
|
|
329 |
|
|
// buttons |
330 |
|
|
$buttons = new ButtonPanel(1, "center"); |
331 |
|
|
$buttons->pushButton(form_button("yes","Yes", array("type"=>"submit","style"=>"width: 90px;"))); |
332 |
|
|
|
333 |
|
|
$cancel_url = $this->get_cancel_url(); |
334 |
|
|
$form_name = $this->get_form_name(); |
335 |
|
|
$cancel_action = "document.".$form_name.".action='".$cancel_url."'; document.".$form_name.".method='POST'; document.".$form_name.".submit();"; |
336 |
|
|
|
337 |
|
|
$buttons->pushButton(form_button("no","No", |
338 |
|
|
array("type"=>"button", |
339 |
|
|
"style"=>"width: 90px;", |
340 |
|
|
"onClick"=>$cancel_action))); |
341 |
|
|
$content->push_row($buttons); |
342 |
|
|
|
343 |
|
|
$td = new TDTag(array("class"=>"f10-1","align"=>"center","style"=>_CSS_BORDER_TOP)); |
344 |
|
|
$td->add(_HTML_SPACE); |
345 |
|
|
$content->add_row($td); |
346 |
|
|
|
347 |
|
|
$content->add_row(_HTML_SPACE); |
348 |
|
|
|
349 |
|
|
$table->add_row($content); |
350 |
|
|
|
351 |
|
|
$container->add( $table ); |
352 |
|
|
|
353 |
|
|
$container->add(form_hidden("confirmed", "yes")); |
354 |
|
|
|
355 |
|
|
//do this hack to make the cancel button not bust |
356 |
|
|
//the next page. |
357 |
|
|
if ($_SERVER["REQUEST_METHOD"] == "POST") { |
358 |
|
|
unset($_POST["checkbox"]); |
359 |
|
|
} else { |
360 |
|
|
unset($_GET["checkbox"]); |
361 |
|
|
} |
362 |
|
|
|
363 |
|
|
return $container; |
364 |
|
|
} |
365 |
|
|
|
366 |
|
|
|
367 |
|
|
|
368 |
|
|
/****************************************/ |
369 |
|
|
/* The utility/param methods */ |
370 |
|
|
/****************************************/ |
371 |
|
|
|
372 |
|
|
|
373 |
|
|
|
374 |
|
|
/** |
375 |
|
|
* this function is used to set the overall alignment |
376 |
|
|
* of the widget |
377 |
|
|
* |
378 |
|
|
* @param string - the align value |
379 |
|
|
*/ |
380 |
|
|
function set_align($align) { |
381 |
|
|
$this->_align = $align; |
382 |
|
|
} |
383 |
|
|
|
384 |
|
|
|
385 |
|
|
/** |
386 |
|
|
* Set the name of the deleted items |
387 |
|
|
* used for display purposes only |
388 |
|
|
*/ |
389 |
|
|
function set_item_name($item) { |
390 |
|
|
$this->_item_name = $item; |
391 |
|
|
} |
392 |
|
|
|
393 |
|
|
/** |
394 |
|
|
* Set the name of the action |
395 |
|
|
* used for display purposes only |
396 |
|
|
*/ |
397 |
|
|
function set_action_name($item) { |
398 |
|
|
$this->_action_name = $item; |
399 |
|
|
} |
400 |
|
|
|
401 |
|
|
/** |
402 |
|
|
* This method sets the flag that |
403 |
|
|
* tells us to automatically add |
404 |
|
|
* hidden form fields for all |
405 |
|
|
* the GET/POST vars passed in to us. |
406 |
|
|
* |
407 |
|
|
*/ |
408 |
|
|
function set_save_vars_Flag($flag=TRUE) { |
409 |
|
|
$this->_save_all_vars = TRUE; |
410 |
|
|
} |
411 |
|
|
|
412 |
|
|
/** |
413 |
|
|
* This sets the url to post to |
414 |
|
|
* when a cancel/no action is clicked |
415 |
|
|
* |
416 |
|
|
* @param string - the url |
417 |
|
|
*/ |
418 |
|
|
function set_cancel_url( $url ) { |
419 |
|
|
$this->_cancel_url = $url; |
420 |
|
|
} |
421 |
|
|
|
422 |
|
|
/** |
423 |
|
|
* this returns the current cancel url |
424 |
|
|
* |
425 |
|
|
* @return string - the url |
426 |
|
|
*/ |
427 |
|
|
function get_cancel_url() { |
428 |
|
|
return $this->_cancel_url; |
429 |
|
|
} |
430 |
|
|
|
431 |
|
|
|
432 |
|
|
|
433 |
|
|
} |
434 |
|
|
?> |