#! /usr/bin/perl

# two_table - simple CGI script to show how to pass a parameter

# PREAMBLE
use CGI;
use strict;

# PREAMBLE

# MAIN-BODY
my ($cgi) = new CGI;
my ($title) = "Table Picking Demo";

# parameter to look for in URL
my ($tbl_name) = $cgi->param ("tbl_name");

print $cgi->header ();
print $cgi->start_html (-title => $title);
print $cgi->h1 ($title);

# SELECTION
# If $tbl_name has a value, show the initial page
# Otherwise, display contents of the given table.

if (!$cgi->param ("tbl_name"))
{
	initial_page ();
}
else
{
	display_table ($cgi->param ("tbl_name"));
}
# SELECTION

print $cgi->end_html ();
# MAIN-BODY

exit (0);

# INITIAL_PAGE
sub initial_page
{
my ($url);

	print "Select a table by clicking on its name:<BR><BR>\n";
	printf "<A HREF=\"%s?tbl_name=table1\">table1</A><BR>\n",
				$cgi->script_name ();
	printf "<A HREF=\"%s?tbl_name=table2\">table2</A><BR>\n",
				$cgi->script_name ();
}
# INITIAL_PAGE

# INITIAL_PAGE-2
sub initial_page
{
my ($url);

	print "Select a table by clicking on its name:<BR><BR>\n";
	$url = $cgi->script_name () . "?tbl_name=table1";
	print $cgi->a ({-href => $url}, "table1") . "<BR>\n";;
	$url = $cgi->script_name () . "?tbl_name=table2";
	print $cgi->a ({-href => $url}, "table2") . "<BR>\n";;
}
# INITIAL_PAGE-2

# DISPLAY_TABLE
sub display_table
{
my ($tbl_name) = shift;

	print "Showing table $tbl_name<BR>\n";
}
# DISPLAY_TABLE
