#! /usr/bin/perl


use WWWdb::HTML;

use Data::Dumper;
use CGI qw(:all);

$Data::Dumper::Indent = 1;         # mild pretty print

# print header();

if(0)
{
    $oHtmlTable = HTML::Table->new(Border => 20,
				   BgColor => "#f0f0f0");

# $oHtmlTable->Element(1, $oHtmlTableRow);
# $oHtmlTableRow->Element(1, $oHtmlTableCol);

    $oHtmlTable->Element(1,
		       HTML::TableRow->new(Border => 1,
					   BgColor => "red"));

    $oHtmlTable->Element(2, 2,
		       HTML::TableCol->new(Border  => 0,
					   BgColor => "green",
					   Colspan => 2,
					   Rowspan => 2));


    foreach (1..100)
{
    my $iSeq = int(rand() * 10 % 10);
    my $iCol = int(rand() * 10 % 10);
    my $iRow = int(rand() * 10 % 5) + 1;

    $oHtmlTable->Element($iRow, $iCol, $iSeq,
			 "$iRow.$iCol.$iSeq<BR>\n");

}

$oHtmlTable->Element(0, 0, 1,
		     "MaxRow=");
$oHtmlTable->Element(0, 0, 2,
		     $oHtmlTable->getMaxRow());
$oHtmlTable->Element(0, 0, 3,
		     "  MaxCol=");
$oHtmlTable->Element(0, 0, 4,
		     $oHtmlTable->getMaxCol());

$oHtmlTable->Element(0, 0)->setRowspan($oHtmlTable->getMaxRow())
    if defined $oHtmlTable->Element(0, 0);
$oHtmlTable->Element(1, 0)->setColspan($oHtmlTable->getMaxCol()-1)
    if defined $oHtmlTable->Element(1, 0);

print STDERR Dumper($oHtmlTable->Element(0));
#print STDERR Dumper($oHtmlTable);

print $oHtmlTable->HtmlCode();
}
else
{
    my $iBorder = 0;
    # Application-Table
    {
	$oHtmlTableApp  = HTML::Table->new(BorderPar  => $iBorder,
					   BgColorPar => "#d0d0d0",
					   WidthPar   => "100%",
					   HeightPar  => "100%");

	$oHtmlTableApp->Element(HTML::Table::APPEND, 0, 0,
				"Here is the Application" .
				"<BR>" x 0);

	$oHtmlTableApp->Element(HTML::Table::CURRENT,
                                0)->setHeightPar("80%");

	$oHtmlTableApp->Element(HTML::Table::APPEND, 0, 0,
				"Feld 1");
	$oHtmlTableApp->Element(HTML::Table::CURRENT, 1, 0,
			      CGI::textfield(-name => "Feld1",
					       -value => "Test"));
    }

    {
	$oHtmlTableMain = HTML::Table->new(BorderPar => $iBorder,
					   BgColorPar => "#e0e0e0",
					   WidthPar   => "100%",
					   HeightPar  => "80%");

	$oHtmlTableMain->Element(HTML::Table::APPEND, 1, 0,
				 "Table-Header");

	$oHtmlTableMain->Element(HTML::Table::CURRENT, 1, 1, "&nbsp; " x 100);
	$oHtmlTableMain->Element(HTML::Table::APPEND, 1, 0, "<HR>");

	$oHtmlTableMain->Element(HTML::Table::APPEND, 1, 0,
				 $oHtmlTableApp);

	$oHtmlTableMain->Element(HTML::Table::APPEND, 1, 0, "<HR>");
	$oHtmlTableMain->Element(HTML::Table::APPEND, 1, 0,
				 "Table-Footer");

    }

    {
	$oHtmlTableTop  = HTML::Table->new(BorderPar  => $iBorder,
					   BgColorPar => "#f0f0f0",
					   WidthPar   => "100%",
					   HeightPar  => "100%");

	$oHtmlTableTop->Element(HTML::Table::APPEND, 0, 0,
				"Form-Header");

	$oHtmlTableTop->Element(HTML::Table::APPEND, 0,
		    	         HTML::TableCol->new
	  			 (BgColorPar => "red",
				  WidthPar   => 100));

	$oHtmlTableTop->Element(HTML::Table::CURRENT, 0, 0,
				"Navigation");

	$oHtmlTableTop->Element(HTML::Table::CURRENT, 1, 1,
				$oHtmlTableMain);
  	$oHtmlTableTop->Element(HTML::Table::CURRENT,
                                HTML::Table::CURRENT)->setValignPar("Top");
  	$oHtmlTableTop->Element(HTML::Table::CURRENT,
                                HTML::Table::CURRENT)->setWidthPar("80%");

	$oHtmlTableTop->Element(HTML::Table::APPEND, 0, 0,
				"Form-Footer");

	foreach $oColElem ($oHtmlTableTop->Element(0, 0),
			   $oHtmlTableTop->Element(2, 0))
	{
	    if(defined $oColElem)
	    {
               $oColElem->setColspanPar($oHtmlTableTop->getMaxCol());
               $oColElem->setAlignPar("Center");
               $oColElem->setHeightPar("20");
	    }
	}
    }

    {
	$oHtmlForm  = HTML::Form->new
	    (BgColorHtml => "#c0c0c0",
	     AuthorHtml  => "K.Reger\@twc.de",
	     TitleHtml   => "Test for WWWdb-Html-Classes",
	     Method      => "POST",
	     Action      => "T.pl");

	$oHtmlForm->Element(0, $oHtmlTableTop);
    }

    $oHtmlForm->Dump();

    HTML::Form->ShowAttributes();
    HTML::Table->ShowAttributes();
    HTML::TableCol->ShowAttributes();
    HTML::TableRow->ShowAttributes();

    print $oHtmlForm->HtmlCode();

}
