# # ---------------------- # DBMan # ---------------------- # Database Administrator # # File: html.pl # Description: This file contains all the HTML that the program generates. # Author: Alex Krohn # Web: http://www.gossamer-threads.com/ # Version: 2.05 # CVS Revision: $Id: html.pl,v 1.3 2000/07/08 18:14:40 alex Exp $ # # COPYRIGHT NOTICE: # # Copyright 1997 Gossamer Threads Inc. All Rights Reserved. # # This program is being distributed as shareware. It may be used and # modified free of charge for personal, academic, government or non-profit # use, so long as this copyright notice and the header above remain intact. # Any commercial use should be registered. Please also send me an email, # and let me know where you are using this script. By using this program # you agree to indemnify Gossamer Threads Inc. from any liability. # # Selling the code for this program without prior written consent is # expressly forbidden. Obtain permission before redistributing this # program over the Internet or in any other medium. In all cases # copyright and header must remain intact. # # Please check the README file for full details on registration. # ===================================================================== ########################################################## ## HTML Globals ## ########################################################## # Put any globals you like in here for your html pages. $html_title = 'HSH Main Registry'; ########################################################## ## Record Layout ## ########################################################## sub html_record_form { # -------------------------------------------------------- # The form fields that will be displayed each time a record is # edited (including searching). You don't want to put the #
and
tags for each field. # The values to be displayed are in %rec and should be incorporated # into your form. You can use &build_select_field, &build_checkbox_field # and &build_radio_field to generate the respective input boxes. Text and # Textarea inputs can be inserted as is. If you turn on form auto # generation, the program will build the forms for you (all though they may # not be as nice). See the README for more info. my (%rec) = @_; # ($db_auto_generate and print &build_html_record_form(%rec) and return); my $font = 'Font face="Helvetica" Size=2 Color=#000000'; print qq|
<$font>ID#:
<$font>Name:
<$font>Breed:
<$font>Year Born:
<$font>Gender:
<$font>Base Color:
<$font>Pattern:   |; print &build_select_field("Pattern","$rec{'Pattern'}"); print qq|
<$font>Sire:
<$font>Dam:
<$font>Owner:
|; } sub html_record { # -------------------------------------------------------- # How a record will be displayed. This is used primarily in # returning search results and how it is formatted. The record to # be displayed will be in the %rec hash. # This is the "short display" -- the list of records that are returned # from a search. my (%rec) = @_; # create link to full display $record_number = $rec{'ID'}; $long_url = $ENV{'QUERY_STRING'}; $long_url =~ s/\&nh=\d+//; $long_url =~ s/\&mh=\d+//; $long_url = "$db_script_url?$long_url&nh=$record_number&mh=1"; my $font_color = 'Font face="helvetica" style=font-size:11px'; my $font = 'Font face="helvetica" style=font-size:11px'; print qq| <$font>$rec{'ID'} <$font_color>$rec{'Horse Name'} <$font_color>$rec{'Horse Breed'} <$font_color>$rec{'Gender'} <$font_color>$rec{'Base Color'} $rec{'Pattern'} <$font_color>$rec{'Year'} <$font_color>$rec{'Current Owner'} |; # <-- End of short display formatting -- > print ""; # do not remove this! It is necessary to make the records display properly } ##################################################################### # Add the following subroutine to html.pl sub html_record_long { #---------------------------------------------------------------- my (%rec) = @_; if ($db_total_hits > 1) { # create links to previous and next records $next_url = $ENV{'QUERY_STRING'}; $next_url =~ s/\&nh=\d+//; $next_hit = $nh + 1; $prev_hit = $nh - 1; if ($prev_hit) { $previous = qq~<$font>Previous~; } else { $previous = " "; } if ($next_hit <= $db_total_hits) { $next = qq~<$font>Next~; } else { $next = " "; } # create link back to short display $list_url = $next_url; $list_url =~ s/\&mh=\d+//; $mh = $db_max_hits; $lh = int(($nh-1)/$mh) + 1; $list = qq~<$font>Back to record list~; # print out the links print qq|
$previous $next
$list
<$font>Record $rec{'ID'} of $db_total_hits
|; } # Below is where you define your form. # <-- Start of record display --> my (%rec) = @_; # Load any defaults to put in the VALUE field. my $font_color = 'Font face="helvetica" style="font-size:11px" style="letter-spacing:1px"'; my $font = 'Font face="helvetica" style="font-size:11px" style="letter-spacing:1px"'; print qq|
Basic Information
ID: $rec{'ID'}
Name: $rec{'Horse Name'}
<$font_color>Breed: $rec{'Horse Breed'}
<$font_color>Gender: $rec{'Gender'}
<$font_color>Color: $rec{'Base Color'}
<$font_color>Pattern: $rec{'Pattern'}
<$font_color>Year Born: $rec{'Year'}

Ownership Information
Current Owner: $rec{'Current Owner'}
Past Owners: $rec{'Past Owners'}
Owned Since: $rec{'Owned Since'}

Training Information
<$font_color>Uses: $rec{'Uses'}
<$font_color>Trained In: $rec{'Trained In'}
<$font_color>Training Comments: $rec{'Training Comments'}

Lineage
<$font_color>Sire: $rec{'Sire'}
<$font_color>Sire Lineage: $rec{'Sire Lineage'}
<$font_color>Sire Title: $rec{'Sire Title'}
<$font_color>Sire Acheivements: $rec{'Sire Acheivements'}
<$font_color>
<$font_color>Dam: $rec{'Dam'}
<$font_color>Dam Lineage: $rec{'Dam Lineage'}
<$font_color>Dam Title: $rec{'Dam Title'}
<$font_color>Dam Acheivements: $rec{'Dam Acheivements'}

Showing/Racing History
<$font_color>Points: $rec{'Points'}
<$font_color>Title: $rec{'Title'}
<$font_color>Acheivements: $rec{'Acheivements'}

Additional Comments
<$font_color>Description: $rec{'Description'}

|; # <-- End of record display --> }########################################################## ## Home Page ## ########################################################## sub html_home { # -------------------------------------------------------- # The database manager home page. &html_print_headers; print qq| $html_title: Main Menu.
Main Menu
|; &html_header; print qq| |; } sub html_header { # -------------------------------------------------------- my $font_color = 'Font face="helvetica" style="font-size:11px" style="letter-spacing:1px"'; my $font = 'Font face="helvetica" style="font-size:11px" style="letter-spacing:1px"'; print qq!<$font>!; print qq! Home !; print qq!>> Add ! if ($per_add); print qq!>> Search ! if ($per_view); print qq!>> Delete ! if ($per_del); print qq!>> Modify ! if ($per_mod); print qq!>> List All ! if ($per_view); print qq!>> Admin ! if ($per_admin); print qq!>> Uses Abbreviations !; print qq!>> Log Off !; print qq!>> Gossamer Threads !; print qq!!; } sub html_search_options { # -------------------------------------------------------- # Search options to be displayed at the bottom of search forms. # print qq~

Search Options:

Show records per page.
Sort By: Sort Order:

Search Tips:
- use '*' to match everything in a field)
- put a '>' or '<' at the beginning to to do range searches.
~; } ########################################################## ## Adding ## ########################################################## sub html_add_form { # -------------------------------------------------------- # The add form page where the user fills out all the details # on the new record he would like to add. You should use # &html_record_form to print out the form as it makes # updating much easier. Feel free to edit &get_defaults # to change the default values. &html_print_headers; print qq| $html_title: Add a New Record.
Add a New Record
|; &html_header; print qq|

<$font> <
<$font>ID#:
<$font>Name:
<$font>Breed:
<$font>Year Born:
<$font>Gender:
<$font>Base Color:
<$font>Pattern:   |; print &build_select_field("Pattern","$rec{'Pattern'}"); print qq|
<$font>Sire:
<$font>Sire Lineage:
<$font>Sire Title:  |; print &build_select_field("Sire Title","$rec{'Sire Title'}"); print qq|
<$font>Dam:
<$font>Dam Lineage:
<$font>Dam Title:   |; print &build_select_field("Dam Title","$rec{'Dam Title'}"); print qq|
<$font>Owner:
<$font>Date Added:
<$font>Uses:
<$font>Description:

|; } sub html_add_success { # -------------------------------------------------------- # The page that is returned upon a successful addition to # the database. You should use &get_record and &html_record # to verify that the record was inserted properly and to make # updating easier. &html_print_headers; print qq| $html_title: Record Added.
Record Added
|; &html_header; print qq|

<$font>

The following record was successfully added to the database: |; &html_record_long(&get_record($in{$db_key})); print qq|

|; } sub html_add_failure { # -------------------------------------------------------- # The page that is returned if the addition failed. An error message # is passed in explaining what happened in $message and the form is # reprinted out saving the input (by passing in %in to html_record_form). my ($message) = $_[0]; &html_print_headers; print qq| $html_title: Error! Unable to Add Record.
Error: Unable to add record.
|; &html_header; print qq|

<$font> There were problems with the following fields: $message

Please fix any errors and submit the record again.

|; &html_record_form (%in); print qq|

|; } ########################################################## ## Viewing ## ########################################################## sub html_view_search { # -------------------------------------------------------- # This page is displayed when a user requests to search the # database for viewing. # Note: all searches must use GET method. # &html_print_headers; print qq| $html_title: Search the Registry
Search the Registry
|; &html_header; print qq|

<$font>

|; if ($in{'advanced'}) { &html_advanced_search_form(); } else { &html_record_form(); } print qq| |; &html_search_options; print qq|

|; } sub html_view_success { # -------------------------------------------------------- # This page displays the results of a successful search. # You can use the following variables when displaying your # results: # # $numhits - the number of hits in this batch of results. # $maxhits - the max number of hits displayed. # $db_total_hits - the total number of hits. # $db_next_hits - html for displaying the next set of results. # my (@hits) = @_; my ($numhits) = ($#hits+1) / ($#db_cols+1); my ($maxhits); $in{'mh'} ? ($maxhits = $in{'mh'}) : ($maxhits = $db_max_hits); $in{'nh'} ? ($nh = $in{'nh'}) : ($nh = 1); &html_print_headers; print qq| $html_title: Search Results.
Search Results
|; &html_header; print qq|

|; # Go through each hit and convert the array to hash and send to # html_record for printing. if ($maxhits == 1) { &html_record_long(&array_to_hash(0, @hits)); } else { print qq|

<$font>Your search returned $db_total_hits matches.|; if ($db_next_hits) { print "
<$font>Pages: $db_next_hits"; } $rec_count = 1; print ""; print qq|
\n|; for (0 .. $numhits - 1) { print ""; &html_record (&array_to_hash($_, @hits)); print "\n"; } print "
IDHorse NameBreedGenderColorAgeOwner
"; print ""; if ($db_next_hits) { print "
<$font>Pages: $db_next_hits";} } ; print qq| |; } sub html_view_failure { # -------------------------------------------------------- # The search for viewing failed. The reason is stored in $message # and a new search form is printed out. my ($message) = $_[0]; &html_print_headers; print qq| $html_title: Search Failed.
Search Failed!
|; &html_header; print qq|

<$font>

There were problems with the search. Reason: $message
Please fix any errors and submit the record again.

|; &html_record_form(%in); print qq| |; &html_search_options; print qq|

|; } ########################################################## ## Deleting ## ########################################################## sub html_delete_search { # -------------------------------------------------------- # The page is displayed when a user wants to delete records. First # the user has to search the database to pick which records to delete. # That's handled by this form. &html_print_headers; print qq| $html_title: Search the Database for Deletion.
Find a record to delete
|; &html_header; print qq|

<$font>

Search the database for the records you wish to delete or list all:

|; &html_record_form(); print qq| |; &html_search_options; print qq|

|; } sub html_delete_form { # -------------------------------------------------------- # The user has searched the database for deletion and must now # pick which records to delete from the records returned. This page # should produce a checkbox with name=ID value=delete for each record. # We have to do a little work to convert the array @hits that contains # the search results to a hash for printing. my ($status, @hits) = &query("mod"); my ($numhits) = ($#hits+1) / ($#db_cols+1); my ($maxhits); $in{'mh'} ? ($maxhits = $in{'mh'}) : ($maxhits = $db_max_hits); my (%tmp); &html_print_headers; print qq| $html_title: Delete Record(s).
Search Results
|; &html_header; print qq|

|; if ($status ne "ok") { # There was an error searching! print qq|

<$font_error>Error: $status

|; } else { print qq|
|; # Go through each hit and convert the array to hash and send to # html_record for printing. Also add a checkbox with name=key and value=delete. if (($db_total_hits == 1) || ($maxhits == 1)) { print qq|

<$font> If you would like to delete this record, check the box and then press "Delete Records":|; %tmp = &array_to_hash(0, @hits); print qq||; &html_record_long(&array_to_hash(0, @hits)); print qq|
|; } else { print qq|

<$font> Check which records you wish to delete and then press "Delete Records":
Your search returned $db_total_hits matches. |; if ($db_next_hits) { print "
<$font>Pages: $db_next_hits"; } $rec_count = 1; print ""; print qq|
\n|; for (0 .. $numhits - 1) { print ""; %tmp = &array_to_hash($_, @hits); print qq||; &html_record (%tmp); print "\n"; } print "
IDHorse NameBreedGenderColorAgeOwner
"; print ""; if ($db_next_hits) { print "
<$font>Pages: $db_next_hits"; } } print qq|

|; } &html_footer; print qq| |; } sub html_delete_success { # -------------------------------------------------------- # This page let's the user know that the records were successfully # deleted. my $message = shift; &html_print_headers; print qq| $html_title: Record(s) Deleted.
Record Deleted
|; &html_header; print qq|

<$font> The following records were deleted from the database: '$message'.

|; } sub html_delete_failure { # -------------------------------------------------------- # This page let's the user know that some/all of the records were # not deleted (because they were not found in the database). # $errstr contains a list of records not deleted. my ($errstr) = $_[0]; &html_print_headers; print qq| $html_title: Error: Record(s) Not Deleted.
Error! Record(s) not deleted
|; &html_header; print qq|

<$font> The records with the following keys were not found in the database: '$errstr'.

|; } ########################################################## ## Modifying ## ########################################################## sub html_modify_search { # -------------------------------------------------------- # The page is displayed when a user wants to modify a record. First # the user has to search the database to pick which record to modify. # That's handled by this form. &html_print_headers; print qq| $html_title: Search the Database for Modifying.
Find a record to modify
|; &html_header; print qq|

<$font>

Search the database for the records you wish to modify or list all:

<$font>ID#:
<$font>Name:
<$font>Breed:
<$font>Year Born:
<$font>Gender:
<$font>Current Owner:
|; &html_search_options; print qq|

|; } sub html_modify_form { # -------------------------------------------------------- # The user has searched the database for modification and must now # pick which record to modify from the records returned. This page # should produce a radio button with name=modify value=ID for each record. # We have to do a little work to convert the array @hits that contains # the search results to a hash for printing. my (%tmp); my ($status, @hits) = &query("mod"); my ($numhits) = ($#hits+1) / ($#db_cols+1); if (($numhits == 1) and !$in{'nh'}) { $in{'modify'} = $hits[$db_key_pos]; &html_modify_form_record(); return; } my ($maxhits); $in{'mh'} ? ($maxhits = $in{'mh'}) : ($maxhits = $db_max_hits); &html_print_headers; print qq! $html_title: Modify Record.
Search Results
|; &html_header; print qq|

!; if ($status ne "ok") { # Error searching database! print qq|

<$font_error>Error: $status|; } else { print qq|

|; # Go through each hit and convert the array to hash and send to # html_record for printing. Also add a radio button with name=modify # and value=key. print qq|

<$font> Check which record you wish to modify and then press "Modify Records":
Your search returned $db_total_hits matches. |; if ($db_next_hits) { print "
<$font>Pages: $db_next_hits"; } $rec_count = 1; print ""; print qq|
\n|; for (0 .. $numhits - 1) { print ""; %tmp = &array_to_hash($_, @hits); print qq||; &html_record (%tmp); print "\n"; } print "
IDHorse NameBreedGenderAgeOwner
"; print ""; if ($db_next_hits) { print "
<$font>Pages: $db_next_hits"; } } print qq|

|; &html_footer; print qq| |; } sub html_modify_form_record { # -------------------------------------------------------- # The user has picked a record to modify and it should appear # filled in here stored in %rec. If we can't find the record, # the user is sent to modify_failure. my (%rec) = &get_record($in{'modify'}); if (!%rec) { &html_modify_failure("unable to find record/no record specified: $in{'modify'}"); return; } &html_print_headers; print qq| $html_title: Modify a Record.
Modify a record
|; &html_header; print qq|

<$font>

<$font>ID#:
<$font>Name:
<$font>Breed:
<$font>Year Born:
<$font>Gender:
<$font>Base Color:
<$font>Pattern: |; print &build_select_field("Pattern","$rec{'Pattern'}"); print qq|
<$font>Sire:
<$font>Sire Lineage:   |; print &build_select_field("Sire Title","$rec{'Sire Title'}"); print qq|
<$font>Sire Title:
<$font>Sire Acheivements:
<$font>Dam:
<$font>Dam Lineage:
<$font>Dam Title:   |; print &build_select_field("Dam Title","$rec{'Dam Title'}"); print qq|
<$font>Dam Acheivements:
<$font>Owner:
<$font>Points:
<$font>Title:   |; print &build_select_field("Title","$rec{'Title'}"); print qq|
<$font>Acheivements:
<$font>Trained In:
<$font>Training Comments:
<$font>Date Added:
<$font>Uses:
<$font>Description:

|; } sub html_modify_success { # -------------------------------------------------------- # The user has successfully modified a record, and this page will # display the modified record as a confirmation. &html_print_headers; print qq| $html_title: Record Modified.
Record modified
|; &html_header; print qq|

<$font> The following record was successfully modified:

|; &html_record_long(&get_record($in{$db_key})); print qq| |; } sub html_modify_failure { # -------------------------------------------------------- # There was an error modifying the record. $message contains # the reason why. my ($message) = $_[0]; &html_print_headers; print qq| $html_title: Error! Unable to Modify Record.
Error! Unable to modify record
|; &html_header; print qq|

<$font> There were problems modifying the record: $message
Please fix any errors and submit the record again.

|; &html_record_form (%in); print qq|

|; } ########################################################## ## Authentication ## ########################################################## sub html_login_form { # -------------------------------------------------------- # The login screen. &html_print_headers; print qq| $html_title: Login.
Login
|; &html_header; print qq|

<$font>Welcome! To login, use the username Member and the password Member!

User ID:
Password:

|; } sub html_login_failure { # -------------------------------------------------------- # There was an error loggin in. The error message is stored in $message. my ($message) = $_[0]; &html_print_headers; print qq| $html_title: Login Error.
Login error
|; &html_header; print qq|

<$font>Oops, there was a problem logging into the system: $message.

Please try logging in again, or contact the system administrator.

User ID:
Password:

|; } sub html_admin_display { # -------------------------------------------------------- # The displays the list of current users. my ($message, $user_list, $password, $permissions) = @_; &html_print_headers; print qq| $html_title: User Management.
$html_title: User Management

<$font_title> User Management

<$font>$message

<$font>User List: $user_list
<$font>New Username:
<$font>Change Password:
<$font>Permissions:
$permissions

|; } sub html_unauth { # -------------------------------------------------------- # A user tried to do something he was not authorized for. &html_print_headers; print qq| $html_title: Error! Unauthorized Action.
Error! Unauthorized action
|; &html_header; print qq|

<$font> Try again in a few minutes. If you still get this error, email Anne.

|; } sub html_signup_form { # -------------------------------------------------------- # This form is displayed for new users who want to create an account. # my $error = shift; &html_print_headers; print qq| $html_title: Create Account.
$html_title: Create Account

<$font_title> Create Account

<$font>To create your own account, simply enter in your desired username and password.

|; if ($error) { print "$error

"; } print qq|
User ID:
Password:

|; } sub html_signup_success { # -------------------------------------------------------- # The user has successfully created a new account. &html_print_headers; print qq| $html_title: Account Created.
$html_title: Account Created

<$font_title> Account Created

<$font>Your account has been set up! Use your username and password to log in.

User ID:
Password:

|; } ########################################################## ## Misc ## ########################################################## sub html_unkown_action { # -------------------------------------------------------- # The program received a command it did not recognize. &html_print_headers; print qq| $html_title: Error! Unknown Action.
Error! Unknown action
|; &html_header; print qq|

<$font> Try again in a few minutes. If you still receive this error email Anne.

|; } sub html_print_headers { # -------------------------------------------------------- # Print out the headers if they haven't already been printed. if (!$html_headers_printed) { print "Content-type: text/html\n\n"; $html_headers_printed = 1; } } 1;