4 |
## $Id$ |
## $Id$ |
5 |
## ----------------------------------------------------------------------------- |
## ----------------------------------------------------------------------------- |
6 |
## $Log$ |
## $Log$ |
7 |
|
## Revision 1.3 2003/04/04 23:58:02 jonen |
8 |
|
## + saving of items sould now work with new 'GenericSource' structure |
9 |
|
## |
10 |
|
## Revision 1.2 2003/04/04 00:43:22 jonen |
11 |
|
## + complete rework |
12 |
|
## |
13 |
## Revision 1.1 2003/03/27 01:18:06 jonen |
## Revision 1.1 2003/03/27 01:18:06 jonen |
14 |
## + inital commit (was orginal 'DataItem.php') |
## + inital commit (was orginal 'DataItem.php') |
15 |
## |
## |
42 |
|
|
43 |
class EditDataItem extends StandardFormContent { |
class EditDataItem extends StandardFormContent { |
44 |
|
|
45 |
|
/** |
46 |
|
* holds reference to source object. |
47 |
|
*/ |
48 |
|
var $_datasource = NULL; |
49 |
|
|
50 |
|
/** |
51 |
|
* container for arguments needed for e.g. setting the source object. |
52 |
|
*/ |
53 |
var $_options = array(); |
var $_options = array(); |
54 |
|
|
55 |
var $_confirm_msg = "Die Daten wurden erfolgreich gespeichert!"; |
var $_confirm_msg = "Die Daten wurden erfolgreich gespeichert!"; |
56 |
|
|
57 |
function EditDataItem($options = array()) { |
function EditDataItem($title, $options = array()) { |
58 |
$this->_options = $options; |
$this->_options = $options; |
59 |
|
// prefetch data |
60 |
|
$this->data_prefetch(); |
61 |
|
|
62 |
$parent = get_parent_class($this); |
$parent = get_parent_class($this); |
63 |
$this->$parent($this->_options['caption'], $PHP_SELF, 600); |
$this->$parent($title, $PHP_SELF, 600); |
64 |
} |
} |
65 |
|
|
66 |
function set_data_source(&$source) { |
function set_data_source(&$source) { |
67 |
$this->_source = &$source; |
$this->_datasource = &$source; |
68 |
} |
} |
69 |
|
|
70 |
function get_data_source() { |
function get_data_source() { |
74 |
$this->set_data_source( &$source ); |
$this->set_data_source( &$source ); |
75 |
} |
} |
76 |
|
|
77 |
|
function _check_datasource($function_name) { |
78 |
|
if ( !is_object($this->_datasource) ) { |
79 |
|
user_error("DataList::".$function_name."() - DataListSource object is not set"); |
80 |
|
exit; |
81 |
|
} |
82 |
|
} |
83 |
|
|
84 |
|
function data_prefetch() { |
85 |
|
$this->get_data_source(); |
86 |
|
$this->_check_datasource("data_prefetch"); |
87 |
|
|
88 |
|
$this->_datasource->do_query(); |
89 |
|
} |
90 |
|
|
91 |
/** |
/** |
92 |
* This method gets called EVERY time the object is |
* This method gets called EVERY time the object is |
98 |
//we want an confirmation page for this form. |
//we want an confirmation page for this form. |
99 |
$this->set_confirm(); |
$this->set_confirm(); |
100 |
|
|
101 |
foreach($this->_source->_result as $key => $value) { |
foreach($this->_datasource->_result as $key => $value) { |
102 |
if($value) { |
if($value) { |
103 |
$validation = TRUE; |
$validation = TRUE; |
104 |
} else { |
} else { |
122 |
//and set the initial values of some of the |
//and set the initial values of some of the |
123 |
//form fields. |
//form fields. |
124 |
|
|
125 |
foreach($this->_source->_result as $key => $value) { |
foreach($this->_datasource->_result as $key => $value) { |
126 |
if(!$this->decode_item_expr($value, $this->_options) && !$this->decode_item_array($value, $this->_options)) { |
if(!$this->decode_item_expr($value, $this->_options) && !$this->decode_item_array($value, $this->_options)) { |
127 |
$this->set_element_value($key, $value); |
$this->set_element_value($key, $value); |
128 |
} |
} |
129 |
} |
} |
130 |
|
|
131 |
|
/* OLD !! |
132 |
$post_vars = array_join_merge($_GET, $_POST); |
$post_vars = array_join_merge($_GET, $_POST); |
133 |
foreach ($post_vars as $var => $val) { |
foreach ($post_vars as $var => $val) { |
134 |
$this->set_hidden_element_value($var, $val); |
$this->set_hidden_element_value($var, $val); |
135 |
} |
} |
136 |
|
*/ |
137 |
|
|
138 |
} |
} |
139 |
|
|
145 |
function &_dataitem() { |
function &_dataitem() { |
146 |
$table = &html_table($this->_width,0,2); |
$table = &html_table($this->_width,0,2); |
147 |
|
|
148 |
foreach($this->_source->_result as $key => $value) { |
foreach($this->_datasource->_result as $key => $value) { |
149 |
// if item is match by expression we will replace it with an link object |
// if item is match by expression we will replace it with an link object |
150 |
if($this->decode_item_expr($value, $this->_options) && $this->_options['inheritance']) { |
if($this->_options['decode']) { |
151 |
$table->add_row($key, $this->decode_item_expr($value, $this->_options)); |
if($this->decode_item_expr($value)) { |
152 |
} |
$table->add_row($key, $this->decode_item_expr($value)); |
153 |
// if item is an Array we will replace it with an selection form object |
} |
154 |
elseif($this->decode_item_array($value, $this->_options) && $this->_options['inheritance']) { |
// if item is an Array we will replace it with an selection form object |
155 |
$table->add_row($key, $this->decode_item_array($value, $this->_options)); |
elseif($this->decode_item_array($value) ) { |
156 |
} |
$table->add_row($key, $this->decode_item_array($value)); |
157 |
else { |
} else { |
158 |
|
$table->add_row($this->element_label($key), $this->element_form($key)); |
159 |
|
} |
160 |
|
} else { |
161 |
$table->add_row($this->element_label($key), $this->element_form($key)); |
$table->add_row($this->element_label($key), $this->element_form($key)); |
162 |
} |
} |
163 |
} |
} |
213 |
$td = new TDtag(array("colspan" => 2, |
$td = new TDtag(array("colspan" => 2, |
214 |
"class" => "contentnovertical", |
"class" => "contentnovertical", |
215 |
"align" => "center"), |
"align" => "center"), |
216 |
$this->add_action("Confirm"), |
form_submit('ecdfe', "Confirm"), |
217 |
_HTML_SPACE, |
_HTML_SPACE, |
218 |
$this->add_action("Edit")); |
$this->add_action("Edit")); |
219 |
|
|
237 |
*/ |
*/ |
238 |
function confirm_action() { |
function confirm_action() { |
239 |
|
|
240 |
foreach($this->_source->_result as $label => $value_old) { |
foreach($this->_datasource->_result as $label => $value_old) { |
241 |
|
if(!$this->decode_item_expr($value_old) && !$this->decode_item_array($value_old)) { |
242 |
$value_new = $this->_elements[$label]->get_value(); |
$value_new = $this->_elements[$label]->get_value(); |
243 |
$item[$label] = $value_new; |
$data[$label] = $value_new; |
244 |
|
} |
245 |
} |
} |
246 |
$error = $this->_source->set($item); |
// write new data to datasource |
247 |
|
$this->_options['data_locator_meta']['action'] = "write"; |
248 |
|
$this->_options['data_locator_meta']['data'] = $data; |
249 |
|
// TODO: 'data_prefetch()' will never return ANYTHING! |
250 |
|
// Implement some error-handling there or somewhere. |
251 |
|
$error = $this->data_prefetch(); |
252 |
|
|
253 |
|
//$error = $this->_datasource->set($item); |
254 |
if(!$error) { |
if(!$error) { |
255 |
|
// fetch fresh data |
256 |
|
$this->_options['data_locator_meta']['action'] = "read"; |
257 |
|
// unset previous initialed 'data' var |
258 |
|
$this->_options['data_locator_meta']['data'] = NULL; |
259 |
|
$this->data_prefetch(); |
260 |
|
|
261 |
$this->set_action_message($this->_confirm_msg); |
$this->set_action_message($this->_confirm_msg); |
262 |
return TRUE; |
return TRUE; |
263 |
} else { |
} else { |
265 |
} |
} |
266 |
} |
} |
267 |
|
|
268 |
|
/** |
269 |
|
* This function is used to build the standard |
270 |
|
* buttons for a form. |
271 |
|
* |
272 |
|
* @return ButtonPanel |
273 |
|
*/ |
274 |
|
function form_content_buttons() { |
275 |
|
$div = new DIVtag( array("style" => "background-color: #eeeeee;". |
276 |
|
"padding-top:5px;padding-bottom:5px", |
277 |
|
"align"=>"center", "nowrap"), |
278 |
|
form_submit('ecdfe', "Save"), |
279 |
|
_HTML_SPACE, |
280 |
|
//$this->add_cancel() |
281 |
|
form_submit('ecdfc', "Cancel") |
282 |
|
); |
283 |
|
return $div; |
284 |
|
} |
285 |
|
|
286 |
|
|
287 |
|
|
288 |
function decode_item_array($item, $options=array()) { |
|
289 |
|
function decode_item_array($item) { |
290 |
|
$options = $this->_options['decode_args']; |
291 |
if( is_array($item) ) { |
if( is_array($item) ) { |
292 |
//$cur_row_index = $this->_datasource->get_cur_data_index(); |
//$cur_row_index = $this->_datasource->get_cur_data_index(); |
293 |
//$parent_guid = $this->_datasource->_data[$cur_row_index]['guid']; |
//$parent_guid = $this->_datasource->_data[$cur_row_index]['guid']; |
302 |
if(is_array($list) ) { |
if(is_array($list) ) { |
303 |
$container = container( |
$container = container( |
304 |
form_open( $item[0], $_SERVER["PHP_SELF"], "POST" ), |
form_open( $item[0], $_SERVER["PHP_SELF"], "POST" ), |
305 |
form_open("meta", $meta), |
form_hidden("ecdm", $meta), |
306 |
form_select("ident", $list), |
form_select("ecdid", $list), |
307 |
form_submit("submit","view" ), |
form_submit("submit","view" ) |
|
form_close() |
|
308 |
); |
); |
309 |
foreach($this->_hidden_items as $label => $value) { |
foreach($this->_hidden_elements as $label => $value) { |
310 |
$container->add(form_hidden($label, $value)); |
$container->add(form_hidden($label, $value)); |
311 |
} |
} |
312 |
|
$container->add(form_close() ); |
313 |
$item = $container; |
$item = $container; |
314 |
} |
} |
315 |
} else { |
} else { |
318 |
$tmp = split($options['seperator'], $value); |
$tmp = split($options['seperator'], $value); |
319 |
$ident = $tmp['1']; |
$ident = $tmp['1']; |
320 |
$meta = $tmp['2']; |
$meta = $tmp['2']; |
321 |
foreach($this->_hidden_items as $label => $value) { |
foreach($this->_hidden_elements as $label => $object) { |
322 |
|
$value = $this->_hidden_elements[$label]->get_value(); |
323 |
$tmp_array[] = $label . "=" . $value; |
$tmp_array[] = $label . "=" . $value; |
324 |
} |
} |
325 |
$str_hidden = join("&", $tmp_array); |
$str_hidden = join("&", $tmp_array); |
326 |
$container->add("->", html_a($_SERVER["PHP_SELF"] . "?ident=" . $ident . "&meta=" . $meta . $str_hidden, $key . " view"), html_br()); |
$container->add("->", html_a($_SERVER["PHP_SELF"] . "?ecdid=" . $ident . "&ecdm=" . $meta . "&" . $str_hidden, $key . " view"), html_br()); |
327 |
} |
} |
328 |
$item = $container; |
$item = $container; |
329 |
} |
} |
331 |
} |
} |
332 |
} |
} |
333 |
|
|
334 |
function decode_item_expr($item, $options=array()) { |
|
335 |
|
function decode_item_expr($item) { |
336 |
|
$options = $this->_options['decode_args']; |
337 |
if(substr($item, 0, 2) == "o_") { |
if(substr($item, 0, 2) == "o_") { |
338 |
$tmp = split($options['seperator'], $item); |
$tmp = split($options['seperator'], $item); |
339 |
$ident = $tmp['1']; |
$ident = $tmp['1']; |
340 |
$meta = $tmp['2']; |
$meta = $tmp['2']; |
341 |
foreach($this->_hidden_items as $label => $value) { |
foreach($this->_hidden_elements as $label => $object) { |
342 |
|
$value = $this->_hidden_elements[$label]->get_value(); |
343 |
$tmp_array[] = $label . "=" . $value; |
$tmp_array[] = $label . "=" . $value; |
344 |
} |
} |
345 |
$str_hidden = join("&", $tmp_array); |
$str_hidden = join("&", $tmp_array); |
346 |
$item = html_a($_SERVER["PHP_SELF"] . "?ident=" . $guid . "&meta=" . $meta . $str_hidden, "view"); |
$item = html_a($_SERVER["PHP_SELF"] . "?ecdid=" . $ident . "&ecdm=" . $meta . "&" . $str_hidden, "view"); |
347 |
return $item; |
return $item; |
348 |
} |
} |
349 |
} |
} |