Back to index

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

List of all members.

Public Member Functions

 EntryField ($intype, $inname, $attributes="", $current_value="")
 

@-


 Render ()
 Render an EntryField into HTML.
 new_lookup ($attributes)
 Function called indirectly when a new EntryField of type 'lookup' is created.

Static Public Member Functions

static BuildOptionList ($qry, $current= '', $location= 'options', $parameters=false)
 Build an option list from the query.

Public Attributes

 $fname
 $ftype
 $current
 $attributes
 $rendered

Detailed Description

Definition at line 38 of file DataEntry.php.


Member Function Documentation

static EntryField::BuildOptionList ( qry,
current = '',
location = 'options',
parameters = false 
) [static]

Build an option list from the query.

Parameters:
string$currentDefault selection of drop down box (optional)
string$locationfor debugging purposes
array$parametersan array further parameters, including 'maxwidth' => 20 to set a maximum width
Returns:
string Select box HTML

Definition at line 294 of file DataEntry.php.

                                                                                                     {
    global $debuggroups;
    $result = '';
    $translate = false;

    if ( isset($maxwidth) ) unset($maxwidth);
    if ( is_array($parameters) ) {
      if ( isset($parameters['maxwidth']) ) $maxwidth = max(4,intval($parameters['maxwidth']));
      if ( isset($parameters['translate']) ) $translate = true;
    }

    // The query may not have already been executed
    if ( $qry->rows() > 0 || $qry->Exec($location) ) {
      while( $row = $qry->Fetch(true) )
      {
        if (is_array($current)) {
          $selected = ( ( in_array($row[0],$current,true) || in_array($row[1],$current,true)) ? ' selected="selected"' : '' );
        }
        else {
          $selected = ( ( "$row[0]" == "$current" || "$row[1]" == "$current" ) ? ' selected="selected"' : '' );
        }
        $display_value = $row[1];
        if ( isset($translate) ) $display_value = translate( $display_value );
        if ( isset($maxwidth) ) $display_value = substr( $display_value, 0, $maxwidth);
        $nextrow = "<option value=\"".htmlspecialchars($row[0])."\"$selected>".htmlspecialchars($display_value)."</option>";
        $result .= $nextrow;
      }
    }
    return $result;
   }

Here is the caller graph for this function:

EntryField::EntryField ( intype,
inname,
attributes = "",
current_value = "" 
)

@-

Initialise an EntryField, used for data entry.

The following types of fields are possible:

  • select - Will display a select list of the keys/values in $attributes where the key starts with an underscore. The key will have the '_' removed before being used as the key in the list. All the $attributes with keys not beginning with '_' will be used in the normal manner as HTML attributes within the <select ...> tag.
  • lookup - Will display a select list of values from the database. If $attributes defines a '_sql' attibute then that will be used to make the list, otherwise the database values will be from the 'codes' table as in "SELECT code_id, code_value FROM codes WHERE code_type = '_type' ORDER BY code_seq, code_id" using the value of $attributes['_type'] as the code_type.
  • date - Will be a text field, expecting a date value which might be javascript validated at some point in the future.
  • checkbox - Will display a checkbox for an on-off value.
  • textarea - Will display an HTML textarea.
  • file - Will display a file browse / enter field.
  • button - Will display a button field.
  • password - Password entry. This will display entered data as asterisks.

The $attributes array is useful to set specific HTML attributes within the HTML tag used for the entry field however $attribute keys named starting with an underscore ('_') affect the field operation rather than the HTML. For the 'select' field type, these are simply used as the keys / values for the selection (with the '_' removed), but other cases are more complex:

  • _help - While this will be ignored by the EntryField::Render() method the _help should be assigned (or will be assigned the same value as the 'title' attribute) and will (depending on the data-entry line format in force) be displayed as help for the field by the EntryForm::DataEntryLine() method.
  • _sql - When used in a 'lookup' field this controls the SQL to return keys/values for the list. The actual SQL should return two columns, the first will be used for the key and the second for the displayed value.
  • _type - When used in a 'lookup' field this defines the codes type used.
  • _null - When used in a 'lookup' field this will control the description for an option using a '' key value which will precede the list of values from the database.
  • _zero - When used in a 'lookup' field this will control the description for an option using a '0' key value which will precede the list of values from the database.
  • _label - When used in a 'radio' or 'checkbox' field this will wrap the field with an HTML label tag as <label ...><input field...>$attributes['_label']</label>
  • -
Parameters:
text$intypeThe type of field: select | lookup | date | checkbox | textarea | file | button | password (anything else is dealt with as "text")
text$innameThe name of the field.
text$attributesAn associative array of extra attributes to be applied to the field. Optional, but generally important. Some $attribute keys have special meaning, while others are simply added as HTML attributes to the field.
text$current_valueThe current value to use to initialise the field. Optional.

Definition at line 137 of file DataEntry.php.

  {
    $this->ftype = $intype;
    $this->fname = $inname;
    $this->current = $current_value;

    if ( isset($this->{"new_$intype"}) && function_exists($this->{"new_$intype"}) ) {
      // Optionally call a function within this object called "new_<intype>" for setup
      $this->{"new_$intype"}( $attributes );
    }
    else if ( is_array($attributes) ) {
      $this->attributes = $attributes;
    }
    else {
    }

    $this->rendered = "";
  }
EntryField::new_lookup ( attributes)

Function called indirectly when a new EntryField of type 'lookup' is created.

Parameters:
array$attributesThe attributes array that was passed in to the new EntryField() constructor.

Definition at line 283 of file DataEntry.php.

                                     {
    $this->attributes = $attributes;
  }

Render an EntryField into HTML.

See also:
EntryField::EntryField(), EntryForm::DataEntryLine()
Returns:
text An HTML fragment for the data-entry field.

Definition at line 162 of file DataEntry.php.

                    {
    global $session;

    $r = "<";
    dbg_error_log( "EntryField", ":Render: Name: %s, Type: %s, Current: %s", $this->fname, $this->ftype, $this->current );
    $size = "";
    switch ( $this->ftype ) {

      case "select":
        $r .= "select name=\"$this->fname\"%%attributes%%>";
        reset( $this->attributes );
        while( list($k,$v) = each( $this->attributes ) ) {
          if ( substr($k, 0, 1) != '_' ) continue;
          if ( $k == '_help' ) continue;
          $k = substr($k,1);
          $r .= "<option value=\"".htmlspecialchars($k)."\"";
          if ( "$this->current" == "$k" ) $r .= " selected";
          $r .= ">$v</option>" ;
        }
        $r .= "</select>";
        break;

      case "lookup":
        $r .= "select name=\"$this->fname\"%%attributes%%>";
        reset( $this->attributes );
        while( list($k,$v) = each( $this->attributes ) ) {
          if ( substr($k, 0, 1) != '_' ) continue;
          $k = substr($k,1);
          if ( $k == 'help' || $k == "sql" || $k == "type" ) continue;
          if ( $k == "null" ) $k = "";
          if ( $k == "zero" ) $k = "0";
          $r .= "<option value=\"".htmlspecialchars($k)."\"";
          if ( "$this->current" == "$k" ) $r .= " selected";
          $r .= ">$v</option>" ;
        }
        if ( isset($this->attributes["_sql"]) ) {
          $qry = new PgQuery( $this->attributes["_sql"] );
        }
        else {
          $qry = new PgQuery( "SELECT code_id, code_value FROM codes WHERE code_type = ? ORDER BY code_seq, code_id", $this->attributes['_type'] );
        }
        $r .= EntryField::BuildOptionList( $qry, $this->current, "rndr:$this->fname", array('translate'=>1) );
        $r .= "</select>";
        break;

      case "date":
      case "timestamp":
        $size = '';
        if ( !isset($this->attributes['size']) || $this->attributes['size'] == "" ) $size = " size=" . ($this->ftype == 'date' ? "12" : "18");
        $r .= "input type=\"text\" name=\"$this->fname\"$size value=\"".$session->FormattedDate(htmlspecialchars($this->current))."\"%%attributes%%>";
        break;

      case "checkbox":
        // We send a hidden field with a false value, which will be overridden by the real
        // field with a true value (if true) or not overridden (if false).
        $r .= "input type=\"hidden\" name=\"$this->fname\" value=\"off\"><";
      case "radio":
        $checked = "";
        if ( $this->current === true || $this->current == 't' || intval($this->current) == 1 || $this->current == 'on'
              || (isset($this->attributes['value']) && $this->current == $this->attributes['value'] ) )
          $checked = " checked";
        $id = "id_$this->fname" . ( $this->ftype == "radio" ? "_".$this->attributes['value'] : "");
        if ( isset($this->attributes['_label']) ) {
          $r .= "label for=\"$id\"";
          if ( isset($this->attributes['class']) )
            $r .= ' class="'. $this->attributes['class'] . '"';
          $r .= "><";
        }
        $r .= "input type=\"$this->ftype\" name=\"$this->fname\" id=\"$id\"$checked%%attributes%%>";
        if ( isset($this->attributes['_label']) ) {
          $r .= " " . $this->attributes['_label'];
          $r .= "</label>";
        }
        break;

      case "button":
        $r .= "input type=\"button\" name=\"$this->fname\"%%attributes%%>";
        break;

      case "submit":
        $r .= "input type=\"submit\" name=\"$this->fname\" value=\"".htmlspecialchars($this->current)."\"%%attributes%%>";
        break;

      case "textarea":
        $r .= "textarea name=\"$this->fname\"%%attributes%%>$this->current</textarea>";
        break;

      case "file":
        if ( !isset($this->attributes['size']) || $this->attributes['size'] == "" ) $size = " size=25";
        $r .= "input type=\"file\" name=\"$this->fname\"$size value=\"".htmlspecialchars($this->current)."\"%%attributes%%>";
        break;

      case "password":
        $r .= "input type=\"password\" name=\"$this->fname\" value=\"".htmlspecialchars($this->current)."\"%%attributes%%>";
        break;

      default:
        $r .= "input type=\"text\" name=\"$this->fname\" value=\"".htmlspecialchars($this->current)."\"%%attributes%%>";
        break;
    }

    // Now process the generic attributes
    reset( $this->attributes );
    $attribute_values = "";
    while( list($k,$v) = each( $this->attributes ) ) {
      if ( $k == '_readonly' ) $attribute_values .= " readonly";
      else if ( $k == '_disabled' ) $attribute_values .= " disabled";
      if ( substr($k, 0, 1) == '_' ) continue;
      $attribute_values .= " $k=\"".htmlspecialchars($v)."\"";
    }
    $r = str_replace( '%%attributes%%', $attribute_values, $r );

    $this->rendered = $r;
    return $r;
  }

Here is the call graph for this function:


Member Data Documentation

Definition at line 69 of file DataEntry.php.

Definition at line 63 of file DataEntry.php.

Definition at line 47 of file DataEntry.php.

Definition at line 53 of file DataEntry.php.

Definition at line 75 of file DataEntry.php.


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