14 function Field( $type, $name, $prompt, $seq = 50, $default = "", $current = "", $inextra = "" ) {
18 $this->prompt
= $prompt;
19 $this->default = $default;
20 $this->current
= $current;
22 if ( isset($this->{"new_$type"}) && function_exists($this->{"new_$type"}) ) {
23 $this->{"new_$type"}( $inextra );
25 else if ( is_array($inextra) ) {
26 $this->attributes
= $inextra;
35 function new_lookup( $inextra ) {
36 $this->attributes
= $inextra;
39 function BuildHTML( $stub = "fh_" ) {
41 error_log( "$sysname DBG: Building HTML for field $this->name" );
42 if ( substr($this->type
, 0,4) == "btn_" ) {
43 $type = substr($this->type
, 4);
44 $h = "<tr><td class=\"fprompt\"> </td><td class=\"fdata\"><input type=\"$type\" name=\"$stub$this->name\" value=\"".$this->prompt
."\"></td></tr>\n";
47 $h = "<tr><th class=fprompt>$this->prompt</th>";
49 switch ( $this->type
) {
51 $r .= "select name=\"$this->name\"%%attributes%%>";
52 reset( $this->attributes
);
53 while( list($k,$v) = each( $this->attributes
) ) {
54 if ( substr($k, 0, 1) != '_' ) continue;
56 $r .= "<option value=\"".htmlentities($k)."\"";
57 if ( "$this->current" == "$k" ) $r .= " selected";
58 $r .= ">$v</option>\n" ;
64 $r .= "select name=\"$this->name\"%%attributes%%>";
65 if ( isset($this->attributes
["_sql"]) ) {
66 $qry = new PgQuery( $this->attributes
["_sql"] );
69 $qry = new PgQuery( "SELECT lookup_id, lookup_description FROM lookups WHERE lookup_type = ? ORDER BY lookup_type, lookup_seq, lookup_id", $this->attributes
['_type'] );
71 error_log( "$sysname DBG: lookup $this->name via: $qry->querystring" );
72 $r .= $qry->BuildOptionList( $this->current
, "rndr:$this->name" );
77 $r .= "select multiple name=\"$this->name" . "[]\"%%attributes%%>";
78 if ( isset($this->attributes
["_sql"]) ) {
79 $qry = new PgQuery( $this->attributes
["_sql"] );
82 $qry = new PgQuery( "SELECT lookup_id, lookup_description FROM lookups WHERE lookup_type = ? ORDER BY lookup_type, lookup_seq, lookup_id", $this->attributes
['_type'] );
84 error_log( "$sysname DBG: lookup $this->name via: $qry->querystring" );
85 $r .= $qry->BuildOptionList( $this->current
, "rndr:$this->name" );
91 $fmt .= "<label><input type=\"radio-set\" name=\"$this->name\" value=\"%s\"%s%%attributes%%> %s </label>";
92 if ( isset($this->attributes
["_values"]) ) {
93 foreach( $this->attributes
["_values"] as $k => $v ) {
94 $selected = ($this->current
== $k ?
" selected" : "" );
95 $r .= sprintf( $fmt, $k, $selected, $v );
99 if ( isset($this->attributes
["_sql"]) ) {
100 $qry = new PgQuery( $this->attributes
["_sql"] );
103 $qry = new PgQuery( "SELECT lookup_id, lookup_description FROM lookups WHERE lookup_type = ? ORDER BY lookup_type, lookup_seq, lookup_id", $this->attributes
['_type'] );
105 error_log( "$sysname DBG: lookup $this->name via: $qry->querystring" );
106 $r .= $qry->BuildRadioSet( $fmt, $this->current
, "rndr:$this->name" );
111 if ( !isset($this->attributes
['size']) ||
$this->attributes
['size'] == "" ) $size = " size=12";
112 $r .= "input type=\"text\" name=\"$this->name\"$size value=\"".htmlentities($this->current
)."\"%%attributes%%>\n";
116 $r .= "textarea type=\"$this->type\" name=\"$this->name\" %%attributes%%>$this->current</textarea>\n";
120 $r .= "input type=\"$this->type\" name=\"$this->name\" value=\"".htmlentities($this->current
)."\"%%attributes%%>\n";
124 // Now process the generic attributes
125 if ( is_array($this->attributes
) ||
is_object($this->attributes
) ) {
126 reset( $this->attributes
);
127 $attribute_values = "";
128 while( list($k,$v) = each( $this->attributes
) ) {
129 if ( substr($k, 0, 1) == '_' ) continue;
130 $attribute_values .= " $k=\"".htmlentities($v)."\"";
132 $r = str_replace( '%%attributes%%', $attribute_values, $r );
135 $h .= "<td class=fdata>$r</td></tr>\n";
145 var $phase = 'display';
154 function Form( $name = "fh", $rec = false ) {
156 $this->record
= $rec;
157 $this->fields
= array();
160 function AddField( $type, $name, $prompt, $seq = 50, $default = "", $extra = "" ) {
161 if ( is_object($this->record
) ) {
162 $current = $this->record
->{$name};
167 if ( isset($this->fields
[$name]) ) {
168 $this->fields
[$name]->type
= $type;
169 $this->fields
[$name]->seq
= $seq;
170 $this->fields
[$name]->name
= $name;
171 $this->fields
[$name]->prompt
= $prompt;
172 $this->fields
[$name]->default = $default;
173 $this->fields
[$name]->current
= $current;
174 $this->fields
[$name]->attributes
= $extra;
177 $this->fields
[$name] = new Field( $type, $name, $prompt, $seq, $default, $current, $extra );
181 function AddButton( $type, $name, $label, $seq = 50 ) {
185 $this->fields
[$name] = new Field( $type, $name, $prompt, $seq );
188 function BuildHTML( ) {
190 $fst = sprintf( "<form action=\"%s\" target=\"%s\" method=\"%s\">\n", $this->action
, $this->target
, $this->method
);
193 while( list($k,$v) = each($this->fields
) ) {
194 $fst .= $v->BuildHTML();
196 $fst .= "</table></form>";