| 1 |
<? |
| 2 |
/* |
| 3 |
## ----------------------------------------------------------------------------- |
| 4 |
## $Id: DataItem.php,v 1.3 2003/04/06 01:40:35 jonen Exp $ |
| 5 |
## ----------------------------------------------------------------------------- |
| 6 |
## $Log: DataItem.php,v $ |
| 7 |
## Revision 1.3 2003/04/06 01:40:35 jonen |
| 8 |
## + removed duplicated decode functions |
| 9 |
## |
| 10 |
## Revision 1.2 2003/04/04 23:58:33 jonen |
| 11 |
## + minor changes |
| 12 |
## |
| 13 |
## Revision 1.1 2003/04/04 00:32:57 jonen |
| 14 |
## + initial commit |
| 15 |
## |
| 16 |
## |
| 17 |
## |
| 18 |
## ----------------------------------------------------------------------------- |
| 19 |
*/ |
| 20 |
|
| 21 |
class DataItem extends InfoTable { |
| 22 |
|
| 23 |
/** |
| 24 |
* holds reference to source object. |
| 25 |
*/ |
| 26 |
var $_datasource = NULL; |
| 27 |
|
| 28 |
/** |
| 29 |
* container for arguments needed for e.g. setting the source object. |
| 30 |
*/ |
| 31 |
var $_options = array(); |
| 32 |
|
| 33 |
/** |
| 34 |
* container for hidden elements. |
| 35 |
*/ |
| 36 |
var $_hidden_elements = array(); |
| 37 |
|
| 38 |
function DataItem($title, $options = array()) { |
| 39 |
$this->_options = $options; |
| 40 |
|
| 41 |
$parent = get_parent_class($this); |
| 42 |
$this->$parent($title, $width="100%", "center"); |
| 43 |
|
| 44 |
// fetch data |
| 45 |
$this->data_prefetch(); |
| 46 |
} |
| 47 |
|
| 48 |
function render($indent_level=1, $output_debug=0) { |
| 49 |
// init data record entries |
| 50 |
$this->init_elements(); |
| 51 |
// add form container |
| 52 |
$this->get_form_container(); |
| 53 |
|
| 54 |
$table = html_table( $this->get_width(), 0, |
| 55 |
$this->get_cellspacing(), |
| 56 |
$this->get_cellpadding(), |
| 57 |
$this->get_align()); |
| 58 |
$table->set_class( "infotable" ); |
| 59 |
$table->add( $this->_build_title() ); |
| 60 |
|
| 61 |
$row = $this->_build_header(); |
| 62 |
if ($row != NULL) { |
| 63 |
$table->add_row( $row ); |
| 64 |
} |
| 65 |
|
| 66 |
//now go thru the rows of data |
| 67 |
//and add them |
| 68 |
foreach( $this->data as $row ) { |
| 69 |
if ((count($row) == 1) && is_object($row[0]) && (is_a($row[0], "TRtag") || |
| 70 |
is_a($row[0], "TDtag"))) { |
| 71 |
$table->add_row( $row[0] ); |
| 72 |
} else { |
| 73 |
$tr = new TRtag; |
| 74 |
$cnt = count( $row ); |
| 75 |
foreach( $row as $index => $data ) { |
| 76 |
$td = $this->_build_td("", "", $index+1, $cnt ); |
| 77 |
$td->add( $data ); |
| 78 |
$tr->add( $td ); |
| 79 |
} |
| 80 |
$table->add_row( $tr ); |
| 81 |
} |
| 82 |
} |
| 83 |
return $table->render($indent_level, $output_debug); |
| 84 |
} |
| 85 |
|
| 86 |
function set_data_source(&$source) { |
| 87 |
$this->_datasource = &$source; |
| 88 |
} |
| 89 |
|
| 90 |
function get_data_source() { |
| 91 |
$initial_locator = php::mkComponent( 'DataSource::Locator', array( adapter_type => 'phpHtmlLib' ) ); |
| 92 |
$proxy = php::mkComponent('DataSource::Generic', $initial_locator, $this->_options['data_locator_meta']); |
| 93 |
$source = $proxy->get_adapter(); |
| 94 |
$this->set_data_source( &$source ); |
| 95 |
} |
| 96 |
|
| 97 |
function _check_datasource($function_name) { |
| 98 |
if ( !is_object($this->_datasource) ) { |
| 99 |
user_error("DataList::".$function_name."() - DataListSource object is not set"); |
| 100 |
exit; |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
function data_prefetch() { |
| 105 |
$this->get_data_source(); |
| 106 |
$this->_check_datasource("data_prefetch"); |
| 107 |
|
| 108 |
$this->_datasource->do_query(); |
| 109 |
} |
| 110 |
|
| 111 |
function init_elements() { |
| 112 |
$result = $this->_datasource->_result; |
| 113 |
if (is_array($result)) { |
| 114 |
foreach($result as $key => $value) { |
| 115 |
if(!$value) { $value = _HTML_SPACE; } |
| 116 |
// if item is match by expression we will replace it with an link object |
| 117 |
if($this->_options['decode']) { |
| 118 |
$utils = php::mkComponent('WebExplorer::utils'); |
| 119 |
$hidden = $this->_hidden_elements; |
| 120 |
$options = $this->_options['decode_args']; |
| 121 |
|
| 122 |
/* |
| 123 |
if($utils->decode_item_expr($value, $hidden, $options)) { |
| 124 |
$this->add_element($key, $utils->decode_item_expr($value, $hidden, $options)); |
| 125 |
} |
| 126 |
elseif($utils->decode_item_array($value, $hidden, $options) ) { |
| 127 |
$this->add_element($key, $utils->decode_item_array($value, $hidden, $options)); |
| 128 |
} else { |
| 129 |
$this->add_element($key, $value); |
| 130 |
} |
| 131 |
*/ |
| 132 |
|
| 133 |
$utils->decode_item_expr($value, $hidden, $options); |
| 134 |
// if item is an Array we will replace it with an selection form object |
| 135 |
$utils->decode_item_array($value, $hidden, $options); |
| 136 |
$this->add_element($key, $value); |
| 137 |
|
| 138 |
} else { |
| 139 |
$this->add_element($key, $value); |
| 140 |
} |
| 141 |
|
| 142 |
|
| 143 |
} |
| 144 |
} |
| 145 |
} |
| 146 |
|
| 147 |
function add_element($label, $value) { |
| 148 |
$this->add_row(span_font10bold($label), $value); |
| 149 |
} |
| 150 |
|
| 151 |
function add_hidden_element($label, $value) { |
| 152 |
$this->_hidden_elements[$label] = $value; |
| 153 |
} |
| 154 |
|
| 155 |
function get_form_container() { |
| 156 |
$container = container(); |
| 157 |
// form open |
| 158 |
$container->add(form_open("item_fv", $_SERVER['PHP_SELF'], 'POST')); |
| 159 |
//hidden items |
| 160 |
if(is_array($this->_hidden_elements)) { |
| 161 |
foreach($this->_hidden_elements as $label => $value) { |
| 162 |
$container->add(form_hidden($label, $value)); |
| 163 |
} |
| 164 |
} |
| 165 |
// submit button |
| 166 |
$container->add(form_submit('ecdfe', "edit")); |
| 167 |
// close form |
| 168 |
$container->add(form_close()); |
| 169 |
|
| 170 |
// add container to InfoTable |
| 171 |
$this->add_row(_HTML_SPACE, $container); |
| 172 |
} |
| 173 |
|
| 174 |
|
| 175 |
} |
| 176 |
|
| 177 |
|
| 178 |
?> |