11 require_once(
"AWLUtilities.php");
137 function __construct( $intype, $inname, $attributes=
"", $current_value=
"" )
139 $this->ftype = $intype;
140 $this->fname = $inname;
141 $this->current = $current_value;
143 if ( isset($this->{
"new_$intype"}) && function_exists($this->{
"new_$intype"}) ) {
145 $this->{
"new_$intype"}( $attributes );
147 else if ( is_array($attributes) ) {
148 $this->attributes = $attributes;
153 $this->rendered =
"";
166 dbg_error_log(
"EntryField",
":Render: Name: %s, Type: %s, Current: %s", $this->fname, $this->ftype, $this->current );
168 switch ( $this->ftype ) {
171 $r .=
"select name=\"$this->fname\"%%attributes%%>";
172 reset( $this->attributes );
173 while( list($k,$v) = each( $this->attributes ) ) {
174 if ( substr($k, 0, 1) !=
'_' )
continue;
175 if ( $k ==
'_help' )
continue;
177 $r .=
"<option value=\"".htmlspecialchars($k).
"\"";
178 if (
"$this->current" ==
"$k" ) $r .=
" selected";
179 $r .=
">$v</option>" ;
185 $r .=
"select name=\"$this->fname\"%%attributes%%>";
186 reset( $this->attributes );
187 while( list($k,$v) = each( $this->attributes ) ) {
188 if ( substr($k, 0, 1) !=
'_' )
continue;
190 if ( $k ==
'help' || $k ==
"sql" || $k ==
"type" )
continue;
191 if ( $k ==
"null" ) $k =
"";
192 if ( $k ==
"zero" ) $k =
"0";
193 $r .=
"<option value=\"".htmlspecialchars($k).
"\"";
194 if (
"$this->current" ==
"$k" ) $r .=
" selected";
195 $r .=
">$v</option>" ;
197 if ( isset($this->attributes[
"_sql"]) ) {
198 $qry =
new PgQuery( $this->attributes[
"_sql"] );
201 $qry =
new PgQuery(
"SELECT code_id, code_value FROM codes WHERE code_type = ? ORDER BY code_seq, code_id", $this->attributes[
'_type'] );
210 if ( !isset($this->attributes[
'size']) || $this->attributes[
'size'] ==
"" ) $size =
" size=" . ($this->ftype ==
'date' ?
"12" :
"18");
211 $r .=
"input type=\"text\" name=\"$this->fname\"$size value=\"".$session->FormattedDate(htmlspecialchars($this->current)).
"\"%%attributes%%>";
217 $r .=
"input type=\"hidden\" name=\"$this->fname\" value=\"off\"><";
220 if ( $this->current ===
true || $this->current ==
't' || intval($this->current) == 1 || $this->current ==
'on' 221 || (isset($this->attributes[
'value']) && $this->current == $this->attributes[
'value'] ) )
222 $checked =
" checked";
223 $id =
"id_$this->fname" . ( $this->ftype ==
"radio" ?
"_".$this->attributes[
'value'] :
"");
224 if ( isset($this->attributes[
'_label']) ) {
225 $r .=
"label for=\"$id\"";
226 if ( isset($this->attributes[
'class']) )
227 $r .=
' class="'. $this->attributes[
'class'] .
'"';
230 $r .=
"input type=\"$this->ftype\" name=\"$this->fname\" id=\"$id\"$checked%%attributes%%>";
231 if ( isset($this->attributes[
'_label']) ) {
232 $r .=
" " . $this->attributes[
'_label'];
238 $r .=
"input type=\"button\" name=\"$this->fname\"%%attributes%%>";
242 $r .=
"input type=\"submit\" name=\"$this->fname\" value=\"".htmlspecialchars($this->current).
"\"%%attributes%%>";
246 $r .=
"textarea name=\"$this->fname\"%%attributes%%>$this->current</textarea>";
250 if ( !isset($this->attributes[
'size']) || $this->attributes[
'size'] ==
"" ) $size =
" size=25";
251 $r .=
"input type=\"file\" name=\"$this->fname\"$size value=\"".htmlspecialchars($this->current).
"\"%%attributes%%>";
255 $r .=
"input type=\"password\" name=\"$this->fname\" value=\"".htmlspecialchars($this->current).
"\"%%attributes%%>";
259 $r .=
"input type=\"text\" name=\"$this->fname\" value=\"".htmlspecialchars($this->current).
"\"%%attributes%%>";
264 reset( $this->attributes );
265 $attribute_values =
"";
266 while( list($k,$v) = each( $this->attributes ) ) {
267 if ( $k ==
'_readonly' ) $attribute_values .=
" readonly";
268 else if ( $k ==
'_disabled' ) $attribute_values .=
" disabled";
269 if ( substr($k, 0, 1) ==
'_' )
continue;
270 $attribute_values .=
" $k=\"".htmlspecialchars($v).
"\"";
272 $r = str_replace(
'%%attributes%%', $attribute_values, $r );
274 $this->rendered = $r;
284 $this->attributes = $attributes;
294 static function BuildOptionList( $qry, $current =
'', $location =
'options', $parameters =
false ) {
299 if ( isset($maxwidth) ) unset($maxwidth);
300 if ( is_array($parameters) ) {
301 if ( isset($parameters[
'maxwidth']) ) $maxwidth = max(4,intval($parameters[
'maxwidth']));
302 if ( isset($parameters[
'translate']) ) $translate =
true;
306 if ( $qry->rows() > 0 || $qry->Exec($location) ) {
307 while( $row = $qry->Fetch(
true) )
309 if (is_array($current)) {
310 $selected = ( ( in_array($row[0],$current,
true) || in_array($row[1],$current,
true)) ?
' selected="selected"' :
'' );
313 $selected = ( (
"$row[0]" ==
"$current" ||
"$row[1]" ==
"$current" ) ?
' selected="selected"' :
'' );
315 $display_value = $row[1];
316 if ( isset($translate) ) $display_value = translate( $display_value );
317 if ( isset($maxwidth) ) $display_value = substr( $display_value, 0, $maxwidth);
318 $nextrow =
"<option value=\"".htmlspecialchars($row[0]).
"\"$selected>".htmlspecialchars($display_value).
"</option>";
373 var $break_line_format;
379 var $table_line_format;
385 var $saved_line_format;
396 $this->action = $action;
397 $this->record = &$record;
398 $this->EditMode = $editing;
399 $this->break_line_format =
'<tr><th class="ph" colspan="2">%s</th></tr>'.
"\n";
400 $this->table_line_format =
'<tr><th class="prompt">%s</th><td class="entry">%s<span class="help">%s</span></td></tr>'.
"\n";
410 foreach( $record AS $k => $v ) {
411 $this->record->{
"$prefix$k"} = $v;
419 $this->break_line_format =
'<tr><th class="ph" colspan="2">%s</th></tr>'.
"\n";
420 $this->table_line_format =
'<tr><th class="prompt">%s</th><td class="entry">%s</td></tr>'.
"\n";
427 $this->break_line_format =
'<tr><th class="ph" colspan="2">%s</th></tr>'.
"\n";
428 $this->table_line_format =
'<tr><th class="prompt">%s</th><td class="entry">%s<span class="help">%s</span></td></tr>'.
"\n";
435 $this->break_line_format =
'<tr><th class="ph" colspan="3">%s</th></tr>'.
"\n";
436 $this->table_line_format =
'<tr><th class="prompt">%s</th><td class="entry">%s</td><td class="help">%s</td></tr>'.
"\n";
442 function SimpleForm( $new_format =
'<span class="prompt">%s:</span> <span class="entry">%s</span>' ) {
443 $this->break_line_format =
'%s'.
"\n";
444 $this->table_line_format = $new_format.
"\n";
451 function TempLineFormat( $new_format =
'<span class="prompt">%s:</span> <span class="entry">%s</span>' ) {
452 $this->saved_line_format = $this->table_line_format;
453 $this->table_line_format = $new_format .
"\n";
460 if ( isset($this->saved_line_format) ) {
461 $this->table_line_format = $this->saved_line_format;
471 if ( !is_array($extra_attributes) && $extra_attributes !=
'' ) {
472 list( $k, $v ) = explode(
'=', $extra_attributes );
473 $extra_attributes = array( $k => $v );
475 $extra_attributes[
'action'] = $this->action;
476 if ( !isset($extra_attributes[
'method']) ) $extra_attributes[
'method'] =
'post';
477 if ( strtolower($extra_attributes[
'method']) !=
'get' )
478 if ( !isset($extra_attributes[
'enctype']) ) $extra_attributes[
'enctype'] =
'multipart/form-data';
479 if ( !isset($extra_attributes[
'name']) ) $extra_attributes[
'name'] =
'form';
480 if ( !isset($extra_attributes[
'class']) ) $extra_attributes[
'class'] =
'formdata';
481 if ( !isset($extra_attributes[
'id']) ) $extra_attributes[
'id'] = $extra_attributes[
'name'];
484 reset( $extra_attributes );
485 $attribute_values =
"";
486 while( list($k,$v) = each( $extra_attributes ) ) {
487 $attribute_values .=
" $k=\"".htmlspecialchars($v).
"\"";
489 return "<form$attribute_values>\n";
506 return sprintf( $this->break_line_format, translate($text));
517 return sprintf(
'<input type="hidden" name="%s" value="%s" %s/>%s', $fname,
518 htmlspecialchars($fvalue), (isset($id) ?
'id="$id" ' :
''),
"\n" );
534 if ( !is_array($attributes) ) {
535 if ( strpos( $attributes,
'=' ) ===
false ) {
536 $attributes = array();
539 list( $k, $v ) = explode(
'=', $attributes );
540 $attributes = array( $k => $v );
545 if ( !isset($attributes[
'_help']) ) {
546 $attributes[
'_help'] =
"";
547 if ( isset($attributes[
'title']) )
548 $attributes[
'_help'] = $attributes[
'title'];
552 if ( !isset($attributes[
'class']) ) {
553 $attributes[
'class'] =
"f$ftype";
563 function DataEntryField( $format, $ftype=
'', $base_fname=
'', $attributes=
'', $prefix=
'' )
567 if ( ($base_fname ==
'' || $ftype ==
'') ) {
571 $fname = $prefix . $base_fname;
573 dbg_error_log(
"DataEntry",
":DataEntryField: fmt='%s', fname='%s', fvalue='%s'", $format, $fname, (isset($this->record->{$fname})?$this->record->{$fname}:
'value not set') );
574 if ( !$this->EditMode ) {
576 if ( !isset($this->record->{$fname}) && substr($fname,0,4) ==
'xxxx' && isset($this->record->{substr($fname,4)}) )
577 $fname = substr($fname,4);
578 if ( !isset($this->record->{$fname}) )
return '';
580 if ($ftype ==
"date" || $ftype ==
"timestamp")
581 return sprintf($format, $session->FormattedDate($this->record->{$fname}) );
582 dbg_error_log(
"DataEntry",
":DataEntryField: fmt='%s', fname='%s', fvalue='%s'", $format, $fname, (isset($this->record->{$fname})?$this->record->{$fname}:
'value not set') );
583 return sprintf($format, $this->record->{$fname} );
588 if ( preg_match(
"/^(.+)\[(.+)\]$/", $fname, $parts) ) {
591 @dbg_error_log(
"DataEntry",
":DataEntryField: fname=%s, p1=%s, p2=%s, POSTVAL=%s, \$this->record->{'%s'}['%s']=%s",
592 $fname, $p1, $p2, $_POST[$p1][$p2], $p1, $p2, $this->record->{
"$p1"}[
"$p2"] );
594 if ( isset($_POST[$p1]) ) {
595 if ( isset($_POST[$p1][$p2]) ) {
596 $currval = $_POST[$p1][$p2];
599 else if ( isset($this->record) && is_object($this->record)
600 && isset($this->record->{
"$p1"}[
"$p2"])
602 $currval = $this->record->{
"$p1"}[
"$p2"];
606 if ( isset($_POST[$fname]) ) {
607 $currval = $_POST[$fname];
609 else if ( isset($this->record) && is_object($this->record) && isset($this->record->{
"$base_fname"}) ) {
610 $currval = $this->record->{
"$base_fname"};
612 else if ( isset($this->record) && is_object($this->record) && isset($this->record->{
"$fname"}) ) {
613 $currval = $this->record->{
"$fname"};
616 if ( $ftype ==
"date" ) $currval = $session->FormattedDate($currval);
617 else if ( $ftype ==
"timestamp" ) $currval = $session->FormattedDate($currval, $ftype);
620 $field =
new EntryField( $ftype, $fname, $this->_ParseAttributes($ftype,$attributes), $currval );
621 return $field->Render();
631 $field =
new EntryField(
'submit', $fname, $this->_ParseAttributes(
'submit', $attributes), $fvalue );
632 return $field->Render();
639 function DataEntryLine( $prompt, $field_format, $ftype=
'', $fname=
'', $attributes=
'', $prefix =
'' )
641 $attributes = $this->_ParseAttributes( $ftype, $attributes );
642 return sprintf( $this->table_line_format, $prompt,
643 $this->DataEntryField( $field_format, $ftype, $fname, $attributes, $prefix ),
644 $attributes[
'_help'] );
652 function MultiEntryLine( $prompt_options, $prompt_name, $default_prompt, $format, $ftype=
'', $fname=
'', $attributes=
'', $prefix )
655 $prompt =
"<select name=\"$prompt_name\">";
657 reset($prompt_options);
658 while( list($k,$v) = each($prompt_options) ) {
659 $selected = ( ( $k == $default_prompt ) ?
' selected="selected"' :
'' );
660 $nextrow =
"<option value=\"$k\"$selected>$v</option>";
661 if ( preg_match(
'/&/', $nextrow) ) $nextrow = preg_replace(
'/&/',
'&', $nextrow);
664 $prompt .=
"</select>";
666 return $this->DataEntryLine( $prompt, $format, $ftype, $fname, $attributes, $prefix );
MultiEntryLine( $prompt_options, $prompt_name, $default_prompt, $format, $ftype='', $fname='', $attributes='', $prefix)
TempLineFormat( $new_format='< span class="prompt">%s:</span > < span class="entry">%s</span >')
__construct( $intype, $inname, $attributes="", $current_value="")
DataEntryField( $format, $ftype='', $base_fname='', $attributes='', $prefix='')
__construct( $action, &$record, $editing=false)
DataEntryLine( $prompt, $field_format, $ftype='', $fname='', $attributes='', $prefix='')
PopulateForm(&$record, $prefix="")
static BuildOptionList( $qry, $current='', $location='options', $parameters=false)
HiddenField($fname, $fvaluei, $fid=null)
SubmitButton( $fname, $fvalue, $attributes='')
SimpleForm( $new_format='< span class="prompt">%s:</span > < span class="entry">%s</span >')
_ParseAttributes( $ftype='', $attributes='')
StartForm( $extra_attributes='')