Back to index

awl  0.53
Public Member Functions | Static Public Member Functions | Public Attributes
EntryForm Class Reference

List of all members.

Public Member Functions

 EntryForm ($action, &$record, $editing=false)
 

@-


 PopulateForm (&$record, $prefix="")
 Initialise some more of the forms fields, possibly with a prefix.
 NoHelp ()
 Set the line format to have no help display.
 HelpInLine ()
 Set the line format to have help displayed in the same cell as the entry field.
 HelpInCell ()
 Set the line format to have help displayed in it's own separate cell.
 SimpleForm ($new_format= '< span class="prompt">%s:</span > &nbsp;< span class="entry">%s</span >')
 Set the line format to an extremely simple CSS based prompt / field layout.
 TempLineFormat ($new_format= '< span class="prompt">%s:</span > &nbsp;< span class="entry">%s</span >')
 Set the line format to a temporary one that we can revert from.
 RevertLineFormat ()
 Revert the line format to what was in place before the last TempLineFormat call.
 StartForm ($extra_attributes='')
 Start the actual HTML form.
 EndForm ()
 Return the HTML fragment to end the form.
 BreakLine ($text= '')
 A utility function for a heading line within a data entry table.
 HiddenField ($fname, $fvaluei, $fid=null)
 A utility function for a hidden field within a data entry table.
 DataEntryField ($format, $ftype='', $base_fname='', $attributes='', $prefix='')
 A utility function for a data entry line within a table.
 SubmitButton ($fname, $fvalue, $attributes= '')
 A utility function for a submit button within a data entry table.
 DataEntryLine ($prompt, $field_format, $ftype='', $fname='', $attributes='', $prefix= '')
 A utility function for a data entry line within a table.
 MultiEntryLine ($prompt_options, $prompt_name, $default_prompt, $format, $ftype='', $fname='', $attributes='', $prefix)
 A utility function for a data entry line, where the prompt is a drop-down.

Static Public Member Functions

 _ParseAttributes ($ftype= '', $attributes= '')
 Internal function for parsing the type extra on a field.

Public Attributes

 $action
 $record
 $EditMode
 $name
 $class
 $break_line_format
 $table_line_format
 $saved_line_format

Detailed Description

Definition at line 334 of file DataEntry.php.


Member Function Documentation

EntryForm::_ParseAttributes ( ftype = '',
attributes = '' 
) [static]

Internal function for parsing the type extra on a field.

If the '_help' attribute is not set it will be assigned the value of the 'title' attribute, if there is one.

If the 'class' attribute is not set it will be assigned to 'flookup', 'fselect', etc, according to the field type.

Returns:
string The parsed type extra.

Definition at line 532 of file DataEntry.php.

                                                              {

    if ( !is_array($attributes) ) {
      if ( strpos( $attributes, '=' ) === false ) {
        $attributes = array();
      }
      else {
        list( $k, $v ) = explode( '=', $attributes );
        $attributes = array( $k => $v );
      }
    }

    // Default the help to the title, or to blank
    if ( !isset($attributes['_help']) ) {
      $attributes['_help'] = "";
      if ( isset($attributes['title']) )
        $attributes['_help'] = $attributes['title'];
    }

    // Default the style to fdate, ftext, fcheckbox etc.
    if ( !isset($attributes['class']) ) {
      $attributes['class'] = "f$ftype";
    }

    return $attributes;
  }
EntryForm::BreakLine ( text = '')

A utility function for a heading line within a data entry table.

Returns:
string The HTML fragment to end the form.

Definition at line 504 of file DataEntry.php.

  {
    return sprintf( $this->break_line_format, translate($text));
  }
EntryForm::DataEntryField ( format,
ftype = '',
base_fname = '',
attributes = '',
prefix = '' 
)

A utility function for a data entry line within a table.

Returns:
string The HTML fragment to display the data entry field

For some forms we prefix the field name with xxxx so it doesn't collide with the real DB field name.

If it is a date, then format it according to the current user's date format type

Definition at line 563 of file DataEntry.php.

  {
    global $session;

    if ( ($base_fname == '' || $ftype == '') ) {
      // Displaying never-editable values
      return $format;
    }
    $fname = $prefix . $base_fname;

    dbg_error_log( "DataEntry", ":DataEntryField: fmt='%s', fname='%s', fvalue='%s'", $format, $fname, (isset($this->record->{$fname})?$this->record->{$fname}:'value not set') );
    if ( !$this->EditMode ) {
      if ( !isset($this->record->{$fname}) && substr($fname,0,4) == 'xxxx' && isset($this->record->{substr($fname,4)}) )
        $fname = substr($fname,4);
      if ( !isset($this->record->{$fname}) ) return '';
      if ($ftype == "date" || $ftype == "timestamp")
        return sprintf($format, $session->FormattedDate($this->record->{$fname}) );
      dbg_error_log( "DataEntry", ":DataEntryField: fmt='%s', fname='%s', fvalue='%s'", $format, $fname, (isset($this->record->{$fname})?$this->record->{$fname}:'value not set') );
      return sprintf($format, $this->record->{$fname} );
    }

    $currval = '';
    // Get the default value, preferably from $_POST
    if ( preg_match("/^(.+)\[(.+)\]$/", $fname, $parts) ) {
      $p1 = $parts[1];
      $p2 = $parts[2];
      @dbg_error_log( "DataEntry", ":DataEntryField: fname=%s, p1=%s, p2=%s, POSTVAL=%s, \$this->record->{'%s'}['%s']=%s",
                                                  $fname, $p1, $p2, $_POST[$p1][$p2], $p1, $p2, $this->record->{"$p1"}["$p2"] );
      // @todo This could be changed to handle more dimensions on submitted variable names
      if ( isset($_POST[$p1]) ) {
        if ( isset($_POST[$p1][$p2]) ) {
          $currval = $_POST[$p1][$p2];
        }
      }
      else if ( isset($this->record) && is_object($this->record)
                && isset($this->record->{"$p1"}["$p2"])
              ) {
        $currval = $this->record->{"$p1"}["$p2"];
      }
    }
    else {
      if ( isset($_POST[$fname]) ) {
        $currval = $_POST[$fname];
      }
      else if ( isset($this->record) && is_object($this->record) && isset($this->record->{"$base_fname"}) ) {
        $currval = $this->record->{"$base_fname"};
      }
      else if ( isset($this->record) && is_object($this->record) && isset($this->record->{"$fname"}) ) {
        $currval = $this->record->{"$fname"};
      }
    }
    if ( $ftype == "date" ) $currval = $session->FormattedDate($currval);
    else if ( $ftype == "timestamp" ) $currval = $session->FormattedDate($currval, $ftype);

    // Now build the entry field and render it
    $field = new EntryField( $ftype, $fname, $this->_ParseAttributes($ftype,$attributes), $currval );
    return $field->Render();
  }
EntryForm::DataEntryLine ( prompt,
field_format,
ftype = '',
fname = '',
attributes = '',
prefix = '' 
)

A utility function for a data entry line within a table.

Returns:
string The HTML fragment to display the prompt and field.

Definition at line 639 of file DataEntry.php.

  {
    $attributes = $this->_ParseAttributes( $ftype, $attributes );
    return sprintf( $this->table_line_format, $prompt,
                $this->DataEntryField( $field_format, $ftype, $fname, $attributes, $prefix ),
                $attributes['_help'] );
  }

Return the HTML fragment to end the form.

Returns:
string The HTML fragment to end the form.

Definition at line 496 of file DataEntry.php.

                      {
    return "</form>\n";
  }
EntryForm::EntryForm ( action,
&$  record,
editing = false 
)

@-

Initialise a new data-entry form.

Parameters:
string$actionThe action when the form is submitted.
objectref$recordA reference to the database object we are displaying / editing.
boolean$editmodeWhether we are editing.

Definition at line 394 of file DataEntry.php.

  {
    $this->action   = $action;
    $this->record   = &$record;
    $this->EditMode = $editing;
    $this->break_line_format = '<tr><th class="ph" colspan="2">%s</th></tr>'."\n";
    $this->table_line_format = '<tr><th class="prompt">%s</th><td class="entry">%s<span class="help">%s</span></td></tr>'."\n";
  }

Set the line format to have help displayed in it's own separate cell.

Definition at line 434 of file DataEntry.php.

                         {
    $this->break_line_format = '<tr><th class="ph" colspan="3">%s</th></tr>'."\n";
    $this->table_line_format = '<tr><th class="prompt">%s</th><td class="entry">%s</td><td class="help">%s</td></tr>'."\n";
  }

Set the line format to have help displayed in the same cell as the entry field.

Definition at line 426 of file DataEntry.php.

                         {
    $this->break_line_format = '<tr><th class="ph" colspan="2">%s</th></tr>'."\n";
    $this->table_line_format = '<tr><th class="prompt">%s</th><td class="entry">%s<span class="help">%s</span></td></tr>'."\n";
  }
EntryForm::HiddenField ( fname,
fvaluei,
fid = null 
)

A utility function for a hidden field within a data entry table.

Parameters:
string$fnameThe name of the field.
string$fvalueThe value of the field.
Returns:
string The HTML fragment for the hidden field.

Definition at line 516 of file DataEntry.php.

                                                    {
    return sprintf( '<input type="hidden" name="%s" value="%s" %s/>%s', $fname,
                               htmlspecialchars($fvalue), (isset($id) ? 'id="$id" ' : ''), "\n" );
  }
EntryForm::MultiEntryLine ( prompt_options,
prompt_name,
default_prompt,
format,
ftype = '',
fname = '',
attributes = '',
prefix 
)

A utility function for a data entry line, where the prompt is a drop-down.

Returns:
string The HTML fragment for the drop-down prompt and associated entry field.

Definition at line 652 of file DataEntry.php.

  {

    $prompt = "<select name=\"$prompt_name\">";

    reset($prompt_options);
    while( list($k,$v) = each($prompt_options) ) {
      $selected = ( ( $k == $default_prompt ) ? ' selected="selected"' : '' );
      $nextrow = "<option value=\"$k\"$selected>$v</option>";
      if ( preg_match('/&/', $nextrow) ) $nextrow = preg_replace( '/&/', '&amp;', $nextrow);
      $prompt .= $nextrow;
    }
    $prompt .= "</select>";

    return $this->DataEntryLine( $prompt, $format, $ftype, $fname, $attributes, $prefix );
  }

Set the line format to have no help display.

Definition at line 418 of file DataEntry.php.

                     {
    $this->break_line_format = '<tr><th class="ph" colspan="2">%s</th></tr>'."\n";
    $this->table_line_format = '<tr><th class="prompt">%s</th><td class="entry">%s</td></tr>'."\n";
  }
EntryForm::PopulateForm ( &$  record,
prefix = "" 
)

Initialise some more of the forms fields, possibly with a prefix.

Parameters:
objectref$recordA reference to the database object we are displaying / editing.
string$prefixA prefix to prepend to the field name.

Definition at line 408 of file DataEntry.php.

  {
    foreach( $record AS $k => $v ) {
      $this->record->{"$prefix$k"} = $v;
    }
  }

Revert the line format to what was in place before the last TempLineFormat call.

Definition at line 459 of file DataEntry.php.

                               {
    if ( isset($this->saved_line_format) ) {
      $this->table_line_format = $this->saved_line_format;
    }
  }
EntryForm::SimpleForm ( new_format = '<span class="prompt">%s:</span>&nbsp;<span class="entry">%s</span>')

Set the line format to an extremely simple CSS based prompt / field layout.

Definition at line 442 of file DataEntry.php.

                                                             :</span>&nbsp;<span class="entry">%s</span>' ) {
    $this->break_line_format = '%s'."\n";
    $this->table_line_format = $new_format."\n";
  }
EntryForm::StartForm ( extra_attributes = '')

Start the actual HTML form.

Return the fragment to do this.

Parameters:
array$extra_attributesExtra key/value pairs for the FORM tag.
Returns:
string The HTML fragment for the start of the form.

Definition at line 470 of file DataEntry.php.

                                             {
    if ( !is_array($extra_attributes) && $extra_attributes != '' ) {
      list( $k, $v ) = explode( '=', $extra_attributes );
      $extra_attributes = array( $k => $v );
    }
    $extra_attributes['action']  = $this->action;
    if ( !isset($extra_attributes['method']) )  $extra_attributes['method']  = 'post';
    if ( strtolower($extra_attributes['method']) != 'get' )
      if ( !isset($extra_attributes['enctype']) ) $extra_attributes['enctype'] = 'multipart/form-data';
    if ( !isset($extra_attributes['name']) )    $extra_attributes['name']    = 'form';
    if ( !isset($extra_attributes['class']) )   $extra_attributes['class']   = 'formdata';
    if ( !isset($extra_attributes['id']) )      $extra_attributes['id']      = $extra_attributes['name'];

    // Now process the generic attributes
    reset( $extra_attributes );
    $attribute_values = "";
    while( list($k,$v) = each( $extra_attributes ) ) {
      $attribute_values .= " $k=\"".htmlspecialchars($v)."\"";
    }
    return "<form$attribute_values>\n";
  }
EntryForm::SubmitButton ( fname,
fvalue,
attributes = '' 
)

A utility function for a submit button within a data entry table.

Returns:
string The HTML fragment to display a submit button for the form.

Definition at line 629 of file DataEntry.php.

  {
    $field = new EntryField( 'submit', $fname, $this->_ParseAttributes('submit', $attributes), $fvalue );
    return $field->Render();
  }
EntryForm::TempLineFormat ( new_format = '<span class="prompt">%s:</span>&nbsp;<span class="entry">%s</span>')

Set the line format to a temporary one that we can revert from.

Parameters:
string$new_formatThe (optional) new format we will temporarily use.

Definition at line 451 of file DataEntry.php.

                                                                 :</span>&nbsp;<span class="entry">%s</span>' ) {
    $this->saved_line_format = $this->table_line_format;
    $this->table_line_format = $new_format ."\n";
  }

Member Data Documentation

Definition at line 343 of file DataEntry.php.

Definition at line 373 of file DataEntry.php.

Definition at line 367 of file DataEntry.php.

Definition at line 355 of file DataEntry.php.

Definition at line 361 of file DataEntry.php.

Definition at line 349 of file DataEntry.php.

Definition at line 385 of file DataEntry.php.

Definition at line 379 of file DataEntry.php.


The documentation for this class was generated from the following file: