#
# ----------------------
# 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 = 'Database Manager Demo';
##########################################################
## 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
#
tags, merely the 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="Verdana, Arial, Helvetica" Size=2 Color=#003399';
###MULTIPAGE MOD:
################ Global Items to Print on Top of All Pages ##################
print qq|
|;
###MULTIPAGE MOD:
################ Page One ###############
if ($in{'PageStatus'} eq "1") {
print qq|
|;
###MULTIPAGE MOD: Sets status for next page: 1 if modifying; 2 if adding.
if ($in{'add_form'}) {print qq|
|;}
else
{print qq|
|;}
}
if (($in{'PageStatus'} eq "1") || ($in{'modify_search'} eq "1") || ($in{'view_search'} eq "1") || ($in{'delete_search'} eq "1")){
print qq|
Field 1:
Field 2:
Field 3:
Field 4:
Field 5:
Field 6:
Field 7:
Field 8:
Field 9:
Field 10:
Field 21:
Field 22:
Field 23:
Field 24:
Field 25:
Field 26:
Field 27:
Field 28:
Field 29:
Field 30:
|;
}
###MULTIPAGE MOD:
################ Global Items to Print on bottom of All Pages ##################
###MULTIPAGE MOD: This prints the "continue" button when necessary - most are used to seeing the button in the footer or elsewhere
if (($in{'modify_form'}) || ($in{'modify_form_record'})) {print qq|
|;}
if ($in{'add_form'}) {print qq|
|;}
}
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.
my (%rec) = @_; # Load any defaults to put in the VALUE field.
($db_auto_generate and print &build_html_record(%rec) and return);
my $font_color = 'Font face="Verdana, Arial, Helvetica" Size=2 Color=#003399';
my $font = 'Font face="Verdana, Arial, Helvetica" Size=2';
###MULTIPAGE MOD:
print qq|
Field 1: $rec{'Page1Field1'}
Field 2: $rec{'Page1Field2'}
Field 3: $rec{'Page1Field3'}
Field 4: $rec{'Page1Field4'}
Field 5: $rec{'Page1Field5'}
Field 6: $rec{'Page1Field6'}
Field 7: $rec{'Page1Field7'}
Field 8: $rec{'Page1Field8'}
Field 9: $rec{'Page1Field9'}
Field 10: $rec{'Page1Field10'}
Field 11: $rec{'Page2Field1'}
Field 12: $rec{'Page2Field2'}
Field 13: $rec{'Page2Field3'}
Field 14: $rec{'Page2Field4'}
Field 15: $rec{'Page2Field5'}
Field 16: $rec{'Page2Field6'}
Field 17: $rec{'Page2Field7'}
Field 18: $rec{'Page2Field8'}
Field 19: $rec{'Page2Field9'}
Field 20: $rec{'Page2Field10'}
Field 21: $rec{'Page3Field1'}
Field 22: $rec{'Page3Field2'}
Field 23: $rec{'Page3Field3'}
Field 24: $rec{'Page3Field4'}
Field 25: $rec{'Page3Field5'}
Field 26: $rec{'Page3Field6'}
Field 27: $rec{'Page3Field7'}
Field 28: $rec{'Page3Field8'}
Field 29: $rec{'Page3Field9'}
Field 30: $rec{'Page3Field10'}
|;
}
##########################################################
## Home Page ##
##########################################################
sub html_home {
# --------------------------------------------------------
# The database manager home page.
&html_print_headers;
print qq|
$html_title: Main Menu.
$html_title: Main Menu
<$font_title>
Main Menu
Permissions: |;
print " View " if ($per_view);
print " Add " if ($per_add);
print " Delete " if ($per_del);
print " Modify " if ($per_mod);
print " Admin " if ($per_admin);
print " None " if (!($per_view || $per_add || $per_del || per_mod));
print qq|
<$font>
This database has been set up so any user can view any other users information, but you can
only modify and delete your own records. If you have admin access, you can of course do anything
you like.
|;
}
sub html_footer {
# --------------------------------------------------------
# Print the menu and the footer and logo. It would be nice if you left
# the logo in. ;)
#
# We only print options that the user have permissions for.
###MULTIPAGE MOD: Had to turn off the search pages for modifying & deleting - couldn't get them to work properly. Will have to "list all" for these functions -- sorry about that...
my $font = 'Font face="Verdana, Arial, Helvetica" Size=2';
print qq!
<$font>!;
print qq!| Home !;
print qq!| Add ! if ($per_add);
print qq!| View ! 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!| Log Off |!;
print qq!
!;
# Print the Footer -- note: a link (doesn't have to be the graphic) is required unless you purchase
# a license. See: http://gossamer-threads.com/scripts/register/ for more info.
print qq!
!;
}
sub html_search_options {
# --------------------------------------------------------
# Search options to be displayed at the bottom of search forms.
print qq~
Search Options:
Match Any
Match Case
Whole Words
Reg. Expression
Keyword Search (will match against all fields)
Max. Returned Hits
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.
|;
}
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;
###MULTIPAGE MOD: this keeps add_success from displaying the page just entered and instead takes the user to the next appropriate page, while briefly display a "please wait" message.
print qq|
$html_title: Record Added.
|;
}
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.
|;
}
##########################################################
## 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 Database.
|;
}
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);
&html_print_headers;
print qq|
$html_title: Search Results.
$html_title: Search Results
<$font>
Your search returned $db_total_hits matches.
|;
if ($db_next_hits) {
print " <$font>Pages: $db_next_hits";
}
# Go through each hit and convert the array to hash and send to
# html_record for printing.
for (0 .. $numhits - 1) {
print "
|;
}
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.
|;
}
##########################################################
## 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.
|;
}
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).
|;
}
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.
|;
}
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.
|;
###MULTIPAGE MOD: this keeps modify_success from displaying the page just entered and instead takes the user to the next appropriate page. Also displays a brief "please wait" message which I think is kinda cool.
if ($in{'PageStatus'} eq "1") {print qq|
|;}
if ($in{'PageStatus'} eq "2") {print qq|
|;}
if ($in{'PageStatus'} eq "3") {print qq|
|;}
if ($in{'PageStatus'} eq "Done") {print qq|
|;}
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.
|;
}
##########################################################
## Authentication ##
##########################################################
sub html_login_form {
# --------------------------------------------------------
# The login screen.
&html_print_headers;
print qq|
$html_title: Login.
|;
}
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.
|;
}
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.
|;
}
sub html_unauth {
# --------------------------------------------------------
# A user tried to do something he was not authorized for.
&html_print_headers;
print qq|
$html_title: Error! Unauthorized Action.
$html_title: Error! Unauthorized Action.
<$font_title>
Error: Unauthorized Action
<$font>
The database program received a command that you are not authorized for.
|; &html_footer; print qq|
|;
}
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.
|;
}
sub html_signup_success {
# --------------------------------------------------------
# The user has successfully created a new account.
&html_print_headers;
print qq|
$html_title: Account Created.
|;
}
##########################################################
## Misc ##
##########################################################
sub html_unkown_action {
# --------------------------------------------------------
# The program received a command it did not recognize.
&html_print_headers;
print qq|
$html_title: Error! Unknown Action.
$html_title: Error! Unkown Action.
<$font_title>
Error: Unknown Action
<$font>
The database program received a command that it did not understand.
|; &html_footer; print qq|
|;
}
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;