| 4 |
## $Id$ |
## $Id$ |
| 5 |
## ----------------------------------------------------------------------------- |
## ----------------------------------------------------------------------------- |
| 6 |
## $Log$ |
## $Log$ |
| 7 |
|
## Revision 1.7 2003/05/10 18:04:45 jonen |
| 8 |
|
## + added values needed for 'create/add new' links |
| 9 |
|
## |
| 10 |
|
## Revision 1.6 2003/04/11 00:48:03 joko |
| 11 |
|
## minor fix: calling parent constructor explicitely by name now, transparency seems not be automagically compatible with inheritance in php ,-) (non-orthogonal) |
| 12 |
|
## |
| 13 |
|
## Revision 1.5 2003/04/09 09:59:30 joko |
| 14 |
|
## fixes regarding modification of decode-function-behavior |
| 15 |
|
## |
| 16 |
|
## Revision 1.4 2003/04/06 01:41:33 jonen |
| 17 |
|
## - removed duplicated decode functions |
| 18 |
|
## |
| 19 |
|
## Revision 1.3 2003/04/04 23:58:02 jonen |
| 20 |
|
## + saving of items sould now work with new 'GenericSource' structure |
| 21 |
|
## |
| 22 |
|
## Revision 1.2 2003/04/04 00:43:22 jonen |
| 23 |
|
## + complete rework |
| 24 |
|
## |
| 25 |
## Revision 1.1 2003/03/27 01:18:06 jonen |
## Revision 1.1 2003/03/27 01:18:06 jonen |
| 26 |
## + inital commit (was orginal 'DataItem.php') |
## + inital commit (was orginal 'DataItem.php') |
| 27 |
## |
## |
| 54 |
|
|
| 55 |
class EditDataItem extends StandardFormContent { |
class EditDataItem extends StandardFormContent { |
| 56 |
|
|
| 57 |
|
/** |
| 58 |
|
* holds reference to source object. |
| 59 |
|
*/ |
| 60 |
|
var $_datasource = NULL; |
| 61 |
|
|
| 62 |
|
/** |
| 63 |
|
* container for arguments needed for e.g. setting the source object. |
| 64 |
|
*/ |
| 65 |
var $_options = array(); |
var $_options = array(); |
| 66 |
|
|
| 67 |
var $_confirm_msg = "Die Daten wurden erfolgreich gespeichert!"; |
var $_confirm_msg = "Die Daten wurden erfolgreich gespeichert!"; |
| 68 |
|
|
| 69 |
function EditDataItem($options = array()) { |
function EditDataItem($title, $options = array()) { |
| 70 |
$this->_options = $options; |
$this->_options = $options; |
| 71 |
|
// prefetch data |
| 72 |
|
$this->data_prefetch(); |
| 73 |
|
|
| 74 |
|
// doesn't work if EditDataItem gets inherited |
| 75 |
|
//$parent = get_parent_class($this); |
| 76 |
|
//$this->$parent($title, $PHP_SELF, 600); |
| 77 |
|
|
| 78 |
|
$this->StandardFormContent($title, $PHP_SELF, 600); |
| 79 |
|
|
|
$parent = get_parent_class($this); |
|
|
$this->$parent($this->_options['caption'], $PHP_SELF, 600); |
|
| 80 |
} |
} |
| 81 |
|
|
| 82 |
function set_data_source(&$source) { |
function set_data_source(&$source) { |
| 83 |
$this->_source = &$source; |
$this->_datasource = &$source; |
| 84 |
} |
} |
| 85 |
|
|
| 86 |
function get_data_source() { |
function get_data_source() { |
| 90 |
$this->set_data_source( &$source ); |
$this->set_data_source( &$source ); |
| 91 |
} |
} |
| 92 |
|
|
| 93 |
|
function _check_datasource($function_name) { |
| 94 |
|
if ( !is_object($this->_datasource) ) { |
| 95 |
|
user_error("DataList::".$function_name."() - DataListSource object is not set"); |
| 96 |
|
exit; |
| 97 |
|
} |
| 98 |
|
} |
| 99 |
|
|
| 100 |
|
function data_prefetch() { |
| 101 |
|
$this->get_data_source(); |
| 102 |
|
$this->_check_datasource("data_prefetch"); |
| 103 |
|
|
| 104 |
|
$this->_datasource->do_query(); |
| 105 |
|
} |
| 106 |
|
|
| 107 |
/** |
/** |
| 108 |
* This method gets called EVERY time the object is |
* This method gets called EVERY time the object is |
| 114 |
//we want an confirmation page for this form. |
//we want an confirmation page for this form. |
| 115 |
$this->set_confirm(); |
$this->set_confirm(); |
| 116 |
|
|
| 117 |
foreach($this->_source->_result as $key => $value) { |
$utils = php::mkComponent('WebExplorer::utils'); |
| 118 |
|
$hidden = $this->get_hidden_elements(); |
| 119 |
|
$options = $this->_options['decode_args']; |
| 120 |
|
|
| 121 |
|
foreach($this->_datasource->_result as $key => $value) { |
| 122 |
if($value) { |
if($value) { |
| 123 |
$validation = TRUE; |
$validation = TRUE; |
| 124 |
} else { |
} else { |
| 125 |
$validation = FALSE; |
$validation = FALSE; |
| 126 |
} |
} |
| 127 |
if(!$this->decode_item_expr($value, $this->_options) && !$this->decode_item_array($value, $this->_options)) { |
if(!$utils->decode_item_expr($value, $hidden, $options) && !$utils->decode_item_array($value, $hidden, $options)) { |
| 128 |
$this->add_element( new FEText($key, $validation, "350px") ); |
$this->add_element( new FEText($key, $validation, "350px") ); |
| 129 |
} |
} |
| 130 |
} |
} |
| 142 |
//and set the initial values of some of the |
//and set the initial values of some of the |
| 143 |
//form fields. |
//form fields. |
| 144 |
|
|
| 145 |
foreach($this->_source->_result as $key => $value) { |
$utils = php::mkComponent('WebExplorer::utils'); |
| 146 |
if(!$this->decode_item_expr($value, $this->_options) && !$this->decode_item_array($value, $this->_options)) { |
$hidden = $this->get_hidden_elements(); |
| 147 |
|
$options = $this->_options['decode_args']; |
| 148 |
|
|
| 149 |
|
foreach($this->_datasource->_result as $key => $value) { |
| 150 |
|
if(!$utils->decode_item_expr($value, $hidden, $options) && !$utils->decode_item_array($value, $hidden, $options)) { |
| 151 |
$this->set_element_value($key, $value); |
$this->set_element_value($key, $value); |
| 152 |
} |
} |
| 153 |
} |
} |
| 154 |
|
|
| 155 |
|
/* OLD !! |
| 156 |
$post_vars = array_join_merge($_GET, $_POST); |
$post_vars = array_join_merge($_GET, $_POST); |
| 157 |
foreach ($post_vars as $var => $val) { |
foreach ($post_vars as $var => $val) { |
| 158 |
$this->set_hidden_element_value($var, $val); |
$this->set_hidden_element_value($var, $val); |
| 159 |
} |
} |
| 160 |
|
*/ |
| 161 |
|
|
| 162 |
} |
} |
| 163 |
|
|
| 169 |
function &_dataitem() { |
function &_dataitem() { |
| 170 |
$table = &html_table($this->_width,0,2); |
$table = &html_table($this->_width,0,2); |
| 171 |
|
|
| 172 |
foreach($this->_source->_result as $key => $value) { |
foreach($this->_datasource->_result as $key => $value) { |
| 173 |
// 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 |
| 174 |
if($this->decode_item_expr($value, $this->_options) && $this->_options['inheritance']) { |
if($this->_options['decode']) { |
| 175 |
$table->add_row($key, $this->decode_item_expr($value, $this->_options)); |
$utils = php::mkComponent('WebExplorer::utils'); |
| 176 |
} |
$hidden = $this->get_hidden_elements(); |
| 177 |
// if item is an Array we will replace it with an selection form object |
$options = $this->_options['decode_args']; |
| 178 |
elseif($this->decode_item_array($value, $this->_options) && $this->_options['inheritance']) { |
$options[label] = $key; |
| 179 |
$table->add_row($key, $this->decode_item_array($value, $this->_options)); |
$options[parent_guid] = $this->_options['parent']['guid']; |
| 180 |
} |
$options[parent_class] = $this->_options['parent']['class']; |
| 181 |
else { |
if($utils->decode_item_expr($value, $hidden, $options)) { |
| 182 |
|
$table->add_row($key, $value); |
| 183 |
|
} |
| 184 |
|
// if item is an Array we will replace it with an selection form object |
| 185 |
|
elseif($utils->decode_item_array($value, $hidden, $options) ) { |
| 186 |
|
$table->add_row($key, $value); |
| 187 |
|
} else { |
| 188 |
|
$table->add_row($this->element_label($key), $this->element_form($key)); |
| 189 |
|
} |
| 190 |
|
} else { |
| 191 |
$table->add_row($this->element_label($key), $this->element_form($key)); |
$table->add_row($this->element_label($key), $this->element_form($key)); |
| 192 |
} |
} |
| 193 |
} |
} |
| 243 |
$td = new TDtag(array("colspan" => 2, |
$td = new TDtag(array("colspan" => 2, |
| 244 |
"class" => "contentnovertical", |
"class" => "contentnovertical", |
| 245 |
"align" => "center"), |
"align" => "center"), |
| 246 |
$this->add_action("Confirm"), |
form_submit('ecdfe', "Confirm"), |
| 247 |
_HTML_SPACE, |
_HTML_SPACE, |
| 248 |
$this->add_action("Edit")); |
$this->add_action("Edit")); |
| 249 |
|
|
| 267 |
*/ |
*/ |
| 268 |
function confirm_action() { |
function confirm_action() { |
| 269 |
|
|
| 270 |
foreach($this->_source->_result as $label => $value_old) { |
$utils = php::mkComponent('WebExplorer::utils'); |
| 271 |
|
$hidden = $this->get_hidden_elements(); |
| 272 |
|
$options = $this->_options['decode_args']; |
| 273 |
|
|
| 274 |
|
foreach($this->_datasource->_result as $label => $value_old) { |
| 275 |
|
if(!$utils->decode_item_expr($value_old, $hidden, $options) && !$utils->decode_item_array($value_old, $hidden, $options)) { |
| 276 |
$value_new = $this->_elements[$label]->get_value(); |
$value_new = $this->_elements[$label]->get_value(); |
| 277 |
$item[$label] = $value_new; |
$data[$label] = $value_new; |
| 278 |
|
} |
| 279 |
} |
} |
| 280 |
$error = $this->_source->set($item); |
// write new data to datasource |
| 281 |
|
$this->_options['data_locator_meta']['action'] = "write"; |
| 282 |
|
$this->_options['data_locator_meta']['data'] = $data; |
| 283 |
|
// TODO: 'data_prefetch()' will never return ANYTHING! |
| 284 |
|
// Implement some error-handling there or somewhere. |
| 285 |
|
$error = $this->data_prefetch(); |
| 286 |
|
|
| 287 |
|
//$error = $this->_datasource->set($item); |
| 288 |
if(!$error) { |
if(!$error) { |
| 289 |
|
// fetch fresh data |
| 290 |
|
$this->_options['data_locator_meta']['action'] = "read"; |
| 291 |
|
// unset previous initialed 'data' var |
| 292 |
|
$this->_options['data_locator_meta']['data'] = NULL; |
| 293 |
|
$this->data_prefetch(); |
| 294 |
|
|
| 295 |
$this->set_action_message($this->_confirm_msg); |
$this->set_action_message($this->_confirm_msg); |
| 296 |
return TRUE; |
return TRUE; |
| 297 |
} else { |
} else { |
| 299 |
} |
} |
| 300 |
} |
} |
| 301 |
|
|
| 302 |
|
/** |
| 303 |
function decode_item_array($item, $options=array()) { |
* This function is used to build the standard |
| 304 |
if( is_array($item) ) { |
* buttons for a form. |
| 305 |
//$cur_row_index = $this->_datasource->get_cur_data_index(); |
* |
| 306 |
//$parent_guid = $this->_datasource->_data[$cur_row_index]['guid']; |
* @return ButtonPanel |
| 307 |
// build list for selection form |
*/ |
| 308 |
if($options['form']) { |
function form_content_buttons() { |
| 309 |
foreach($item as $key => $value) { |
$div = new DIVtag( array("style" => "background-color: #eeeeee;". |
| 310 |
$tmp = split($options['seperator'], $value); |
"padding-top:5px;padding-bottom:5px", |
| 311 |
$ident = $tmp['1']; |
"align"=>"center", "nowrap"), |
| 312 |
$meta = $tmp['2']; |
form_submit('ecdfe', "Save"), |
| 313 |
$list[$key] = $ident; |
_HTML_SPACE, |
| 314 |
} |
//$this->add_cancel() |
| 315 |
if(is_array($list) ) { |
form_submit('ecdfc', "Cancel") |
| 316 |
$container = container( |
); |
| 317 |
form_open( $item[0], $_SERVER["PHP_SELF"], "POST" ), |
return $div; |
|
form_open("meta", $meta), |
|
|
form_select("ident", $list), |
|
|
form_submit("submit","view" ), |
|
|
form_close() |
|
|
); |
|
|
foreach($this->_hidden_items as $label => $value) { |
|
|
$container->add(form_hidden($label, $value)); |
|
|
} |
|
|
$item = $container; |
|
|
} |
|
|
} else { |
|
|
$container = container(); |
|
|
foreach($item as $key => $value) { |
|
|
$tmp = split($options['seperator'], $value); |
|
|
$ident = $tmp['1']; |
|
|
$meta = $tmp['2']; |
|
|
foreach($this->_hidden_items as $label => $value) { |
|
|
$tmp_array[] = $label . "=" . $value; |
|
|
} |
|
|
$str_hidden = join("&", $tmp_array); |
|
|
$container->add("->", html_a($_SERVER["PHP_SELF"] . "?ident=" . $ident . "&meta=" . $meta . $str_hidden, $key . " view"), html_br()); |
|
|
} |
|
|
$item = $container; |
|
|
} |
|
|
return $item; |
|
| 318 |
} |
} |
|
} |
|
| 319 |
|
|
| 320 |
function decode_item_expr($item, $options=array()) { |
|
| 321 |
if(substr($item, 0, 2) == "o_") { |
function get_hidden_elements() { |
| 322 |
$tmp = split($options['seperator'], $item); |
foreach($this->_hidden_elements as $label => $object) { |
| 323 |
$ident = $tmp['1']; |
$value = $this->_hidden_elements[$label]->get_value(); |
| 324 |
$meta = $tmp['2']; |
$tmp_array[$label] = $value; |
|
foreach($this->_hidden_items as $label => $value) { |
|
|
$tmp_array[] = $label . "=" . $value; |
|
|
} |
|
|
$str_hidden = join("&", $tmp_array); |
|
|
$item = html_a($_SERVER["PHP_SELF"] . "?ident=" . $guid . "&meta=" . $meta . $str_hidden, "view"); |
|
|
return $item; |
|
| 325 |
} |
} |
| 326 |
|
return $tmp_array; |
| 327 |
} |
} |
| 328 |
|
|
|
|
|
| 329 |
} |
} |
| 330 |
|
|
| 331 |
|
|