Personal tools

Postgres::Handler::HTML

From Deep Thought

Jump to: navigation, search

Postgres::Handler::HTML

NAME

Postgres::Handler::HTML - HTML Component for PostgreSQL data.

DESCRIPTION

Accessors for PostgreSQL data. Simplifies data access through a series of standard class methods.

SYNOPSIS

 #!/usr/bin/perl
 #
 # Connect to the postgres XYZ database owned by user1/mypass
 # Set the primary key field for the abc table to the field named pkid
 # Print the contents of the fldone field in the abc table where the pkid=123
 #
 use Postgres::Handler::HTML;
 our $STORE = Postgres::Handler::HTML->new(dbname=>'xyz', dbuser=>'user1', dbpass=>'mypass');
 $STORE->data('abc!PGHkeyfld'=>'pkid');
 $STORE->ShowThe('abc!fldone',123);
 exit(1);

REQUIRES

        Subclass of Postgres::Handler

        Postgres::Handler
                 +- CGI::Carp
                 +- CGI::Util
                 +- Class::Struct
                 +- DBI

METHODS

CheckBox()

Produce an HTML Checkbox for the specified boolean field, checked if the field is true.

Parameters

        TABLE   =>      name of table to get data from
        CBNAME  =>      name to put on the checkbox, defaults to VALUE
        VALUE   => field that contains the t/f use to set the checkmark
        LABEL   => what to put next to the checkbox as a label (defaults to field name)
        KEY         =>  value of the key used to lookup the data in the database
        CHECKED => set to '1' to check by default if KEY not found
        SCRIPT  => script tags (or class tags) to add to checkbox HTML
        NOLABEL => set to '1' to skip printing of label

Return

    0 = failure, sets error message, get with lasterror()
    1 = success

Pulldown()

Produce an HTML pulldown menu for the specified table/fields.

Parameters (required)

        TABLE       => name of table to get data from
        VALUE       => which field we stick into the option values

Parameters (optional)

        PDNAME      => name to put on the pulldown, defaults to VALUE
        SHOW        => which field we spit out on the selection menu, defaults to VALUE
        SELECT      => mark the one with this VALUE as selected
        ALLOWBLANK  => set to 1 to allow blank selection (noted as ---)
        ORDERBY         => special ordering, defaults to SHOW field
        WHERE       => filtering selection clause (without WHERE, i.e. pdclass='class1')
        SCRIPT          => event script, such as 'onChange="DoSumthin();"'
        PREADD          => address to hashref of Add-ons for begining of list
                        key     = the value
                                        content = show
        GROUP           => group the data

Example

    our $STORE = Postgres::Handler::HTML->new(dbname=>'xyz', dbuser=>'user1', dbpass=>'mypass');
    $STORE->Pulldown(TABLE=>'categories',VALUE=>'cat_name');

RadioButtons()

Produce an HTML Radio Button menu for the specified table/fields

Parameters

        TABLE                   =>       name of table to get data from
        RBNAME          =>       name to put on the pulldown, defaults to VALUE
        VALUE                   =>  which field we stick into the option values
        SHOW                    =>  which field we spit out on the menu, defaults to VALUE
        SELECT          =>  mark the one with this VALUE as selected
        ORDERBY         => special ordering, defaults to SHOW field
        WHERE                   => filtering selection clause (without WHERE, i.e. rbclass='class1')

ShowHeader()

Display header for retrieved records in an HTML table row

Parameters (required)

 One of these 2 required
 DATAREF        => reference to hash storing record 
 DISPCOLS       => reference to array of columns to show, defaults to hash key names

Parameters (optional)

 FULLNAME       => set to 1 to show full field name, otherwise we trunc up to first _
 SORT                   => set to 1 to sort keys

ShowRecord()

Display retrieved records in an HTML <table> row

Parameters

 DATAREF                => reference to hash storing record (required)

 DATAMODREF     => reference to hash storing data modifiers
                                                The field specified by the hash key is replaced
                                                with the data specified in the value.
                                                Use $Record{???} to place the record field ??? within 
                                                the substitution string.                                                

                                                If the modifier starts with ~eval(<blah>) then the modifier
                                                evaluates <blah> and returns it's result.  For example:
                                                $datmodref{THISFIELD} = '~eval(substr($Record{FIELD},0,10))';
                                                would display the first 10 characters of the field.

 DISPLAYREF     => reference to hash storing special cell formats for
                                                each data element. Key = element, value = <td> modifier

 DISPCOLS       => reference to array of columns to show, defaults to hash key names

 TRIMDATES      => set to 'minute' or 'day' to trim date fields
                                                date fields are any ending in 'LASTUPDATE' 
 WRAP                   => set to 1 to allow data wrapping
 SORT                   => set to 1 to sort keys
 ASFORM         => set to 1 to show data as input form fields
 NOTABLE                => set to 1 to drop all table html tags
 OUTPUT         => output file handle
 ROWMOD         => modifier to <tr> row definition
 CELLMOD                => modifier to each <td> Cell definition

ValOrZero()

Sets the named CGI parameters to 0 if they are not set, otherwise leaves the original value intact.

Set these CGI parameters to 0 if not defined. Used for checkbox form variables when we want to ensure the value is set to 0 (false) if they are not set via the CGI interface.

HTML checkboxes are NOT passed to the CGI module if they are not checked, so this function helps us out by forcing the assumption that the CGI parameters passed here should be 0 if the are not received.

Parameters

 [0] - the CGI variable
 [1] - an array of CGI parameters to be set

ShowThe()

Load the DB record and spit out the value of the specified field.

All parameters are positional (not named).

Parameters (required)

 <0> field name to be displayed in "table!field" format

 <1> key, lookup the record based on the Postgres::Handler key
          that has been set for this field.   Reference the
                         Postgres::Handler->Field method for more info.

Parameters (optional)

 [2] trim to this many characters

AUTHOR

Cyber Sprocket Labs (CSL) is and advanced internet technology consulting firm based in Charleston South Carolina. We provide custom software, database, and consulting services for small to mid-sized businesses.

For more information visit our website at www.cybersprocket.com

COPYRIGHT

(c) 2004 - 2008, Cyber Sprocket Labs

This script is covered by the GNU GENERAL PUBLIC LICENSE.

http://www.cybersprocket.com/wiki/index.php/GNU_General_Public_License

REVISION HISTORY

 v1.1 - May 2008
      Doc cleanup

 v1.0 - May 2008
      Attach to Postgres::Handler via use base() construct
      Cleaned up perldocs
      Build new distro so we can do routine updates

 v0.9 - January 2006
      GROUP option on Pulldown()
                Added some docs, minor code cleanup

 v0.8 - September 2005
                PREADD option on Pulldown()

 v0.7 - August 2005
      minor updates

 v0.6 - Jun 13 2005
      added script option to checkbox type
                added no label option to checkbox type

 v0.5 - Jun 09 2005
      moved under Postgres::Handler:: namespace
                initial CPAN release

 v0.4 - Apr 28 2005
                pod updates
                Updated CheckBox() w/ default 'checked' option
                Added ShowThe() method

 v0.1 - Dec/2004
      Initial private release


CPAN