/[cvs]/nfo/php/libs/org.netfrag.patches/phphtmllib/widgets/DataItem.php
ViewVC logotype

Contents of /nfo/php/libs/org.netfrag.patches/phphtmllib/widgets/DataItem.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations)
Fri Apr 4 23:58:33 2003 UTC (21 years, 5 months ago) by jonen
Branch: MAIN
Changes since 1.1: +8 -5 lines
+ minor changes

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

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed