NAME

CGI::List - Easily generate HTML Lists From a DataBase

VERSION

Version 0.05

SYNOPSIS

Easily create html lists whit auto order, auto pagination, grouping and conditional formats.

Perhaps a little code snippet.

    use CGI::List;

    #We need a DBH Handle
    $dbh = DBI->connect(.....);

    #Create List Object
    $list = CGI::List->new(
	dbh => $dbh,
        sql => {
            select => "foo, bar ",
            from => "table1",
            limit => "20",
            where => "some_column1=? AND some_column2=?",
            params=>["Value1","Value2"],
            order_by => "foo DESC",
       },
    );

    #Print 
    print $list->print();

FEATURES

* Auto Order
* Auto Pagination
* CSS based. Contact developer for CSS examples 
* Column totals(Only SUM, COUNT and AVG are supported)
* Conditional formats for rows
* Conditional Formats for cells
* Auto detect column names
* 2 row formats for better visualization
* Row grouping
* Http Link and highlight on rows based in rows keys
* Opener action for pop up windows
* And more

METHODS

new()

This method creates a new $list object, which you then use to generate and process your list.

    my $list = CGI::List->new();

	The following is a description of each option, in alphabetical order:

	name => 'list_name'
            If you use a multi lists pages you need to specify a name for each list
	on_errors => 'print',
	    If you have SQL errors you can print(default), warn or die
        debug => 0 | 1, default 0
            If is set to 1 this print the query executed on SQL errors
	caption => 'list title'
	    This create a list title with the caption html tag
	auto_order => 1 | 0,   default 1
	    Enable, disable auto order mechanism on the list
	pagination => 1 | 0, default 1
	    Enable or disable auto pagination on the list
	nav_pages => $number, default 4
	    Number of pages you can see on pagination
        Number_Format => {THOUSANDS_SEP=>",",DECIMAL_POINT=>".",MON_THOUSANDS_SEP=>",","MON_DECIMAL_POINT"=>".","INT_CURR_SYMBOL"=>'$'};
            On SUM otions you can format the result to price ($1,234.00), whit this parameters THOUSANDS_SEP, DECIMAL_POINT, MON_THOUSANDS_SEP, MON_DECIMAL_POINT, INT_CURR_SYMBOL.

        table => {}
            Propiedades de la tabla, default {width => "100%",class => "cg_table",align => "center",cellpadding=>"0",cellspacing=>"0"}
        labels => {
		       page_of => 'Page _PAGE_ of _OF_',
		       no_data   => 'No records found',
		       link_up   => '↑',
		       link_down => '↓',
		       next_page => '»',
		       previous_page => '«',
		       number_of_rows => "_NUMBER_ rows",
		      };
            This are the text printed on the list, you can traslate to other language

print()

This function renders the list into HTML, and returns a string containing the list.

print $list->print;

group()

This method Create groups of data:

$list->group(key=>'key_field',fields=>[qw/key_field other_field other_field/]);

group_total()

This method calculate row totals on each group:

$list->group_total(key=>'key_field',type=>"MATH",operation=>'SUM',label=>"%% some text",format=>'price');
Operation support only SUM, AVG, and COUNT, the format parameter are optional

total()

This method calculate row totals:

$list->total(key=>'key_field',type=>"MATH",operation=>'SUM',label=>"%% some text",format=>'price');
Operation suport only SUM, AVG, and COUNT, the format parameter are optional

row_format()

This function specify a format of row depending on their value

$list->row_format(name=>"field_name",condition=>"'%%' eq 'urgent'",params=>{class=>"cg_row_urgent"});

%% is the cell value, on this example you need to create 2 css class cg_row_urgent and cg_row_urgent_hover for the hover action

cell_format();

This function specify a format of cell depending on their value

$list->cell_format(name=>"field_name",condition=>"'%%' eq 'urgent'",params=>{class=>"cg_cell_urgent"});

%% is the cell value, on this example you need to create 2 css class cg_cell_urgent and cg_cell_urgent_hover for the hover action

columns_width()

This function specify the width of each column

$list->columns_width(["100","200","300"]);

On this example you have a 3 columns query and 100, 200, 300 are the width of each column

columns_align()

This function specify the horizontal align of each column

$list->columns_align(["left","center","right"]);

On this example you have a 3 columns query and left, center, right are the alignment of each column data

columns_headers_align()

This function specify the horizontal align of each column header

$list->columns_headers_align(["left","center","right"]);

On this example you have a 3 columns query and left, center, right are the alignment of each column header data

Examples

This example provides an list of data with auto order, auto pagination and action on each row click

    my $list = CGI::List->new( 
                  dbh => $dbh,
                  name => "pays_list",
                  sql => {
                      select => "p.pay_id, p.date, pr.name, " .
                          "IF(p.is_cancel,'Cancel','Active') AS 'status'",
                      from => "pays p INNER JOIN partners pr ON p.pay_id=pr.pay_id ",
                      limit => "20",
                      where => "some_column=? AND some_column=?",
                      params=>["Value1","Value2"],
                      order_by => "p.date DESC",
                     },
                  link => {
                       key => "pay_id",
                       hidde_key_col => 1,
                       location => "pays.pl",
                       transit_params => {some_param_to_be_present_everywere=>"value"},
                      },
                 );
	$list->print();

AUTHOR

David Romero Garcia, <romdav at gmail.com>

COLABORATORS

Juan C. Sanchez-DelBarrio

BUGS

Please report any bugs or feature requests to bug-cgi-list at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CGI-List. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc CGI::List

You can also look for information at:

http://www.cgi-list.com. http://groups.google.com/group/cgilist.

ACKNOWLEDGEMENTS

COPYRIGHT & LICENSE

Copyright 2007 David Romero García, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 1171:

Non-ASCII character seen before =encoding in 'García,'. Assuming UTF-8