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