Gossamer Forum
Home : Products : DBMan : Customization :

Need Help with Spreadsheet mod

Quote Reply
Need Help with Spreadsheet mod
I decided to use DBMan because it has quite a community built around it. It seems like it slices and dices and even mows the lawn.

After making the spreadsheet3.txt mod (as located at http://www.jpdeni.com/dbman/Mods/spreadsheet3.txt ), I receive the following error:

"DBMan encountered an internal error. Please enable debugging to view."

I have already enabled debugging mode and yet the message doesn't change. I do not get any debugging info.

I added a line to the files html.pl, default.cfg and db.cgi to aid in trouble shooting as suggested at:
http://webmagic.hypermart.net/dbman/trouble1.txt

I have changed:
########################################
BEGIN {
open (STDERR, ">/path/to/somewhere/error.txt");
}
########################################

TO:
########################################
BEGIN {
open (STDERR, ">>/home/dss-www/htdocs/error.txt");
}
########################################

Where error.txt is derror.txt for default.cfg and herror.txt for html.pl

I touched to make the files and chmoded 777 *error.txt in the directory as stated in the path. I have ls -al to verify the permissions. I have verified that the files exist and have opened them in vi and made the first line to read null. In both browsers, I can access the file using http://blahblahblah though I do not receive any error data.

Since I have little to no error reporting, and because I am still a little daunted by dbman, I have decided to revert to my last working html.pl (as modified by UF_html mod) and start from scrath. I was pretty out of it when first I did the mod and probably made a mistake somewhere.

Maybe here is where I first screwed up. I don't quite understand what is meant by "in each of the header cells" in the clipped portion of code for the spreadsheet mod script as noted below?

######################################################
# Note: In each of the header cells, replace # with the field number
# of the field that is associated with that header -- in both places
# within each line.
print qq|
<TABLE><TR><TD><a href="$db_script_url?$new_url&sb=#&so=$so[#]">FieldName</a></TD>
<TD><a href="$db_script_url?$new_url&sb=#&so=$so[#]">FieldName</a></TD>
<TD><a href="$db_script_url?$new_url&sb=#&so=$so[#]">FieldName</a></TD>
<TD><a href="$db_script_url?$new_url&sb=#&so=$so[#]">FieldName</a></TD></TR>\n|;

for (0 .. $numhits - 1) {
print "<TR>";
&html_record (&array_to_hash($_, @hits));
print "</TR>\n";
}
print "</TABLE>";

######################################################

Can someone give me some direction here? Or can anyone point me to messages that discuss spreadsheet mod customization in greater detail? I have spent alot of time searching the Support forum before I posted the above message and I have spent much too much time looking for a place to start with this problem. I think I am missing something :-) Any help would be greatly appreciated.

BTW, I used the configarator and I have installed the UF_html mod. Everything was working fine until I tried to install the spreadsheet mod.

Thanks in advance,

-Thom
Quote Reply
Re: Need Help with Spreadsheet mod In reply to
You need to change the [#] to numbers of fields and how you want to sort them.

Regards,

Eliot Lee
Quote Reply
Re: Need Help with Spreadsheet mod In reply to
For the debugging you will want to use the same error.txt file for all your files.

BEGIN {
open (STDERR, ">>/home/dss-www/htdocs/error.txt");
}

when you run the script it is going to look in all referenced files such as your .cfg, .cgi, and html.pl files.

If the error is within another file, the error.txt will state the error and in which file the error is located.

Just be sure to refresh the file in your browser each time you run the script while checking for errors. This way you get the latest errors reported each time you make changes. This script will not catch all errors, but it does provide useful information with script errors.


Unoffical DBMan FAQ
http://webmagic.hypermart.net/dbman/
Quote Reply
Re: Need Help with Spreadsheet mod In reply to
Thom, did you ever figure this out? I'm getting the same error. I've checked permissions and reinstalled my old html.pl file to confirm that it works.

the implementation can be seen at: http://scrawford.netfirms.com (company list)

I've actually checked the code to see if i was missing the brackets, but nothing sticks out. Again, I tried a couple of times to make the mods, but get the same result both times. Any ideas? Here's the error code from the debugging: I've posted the raw code at (http://scrawford.netfirms.com/companyhtml.txt)

CGI ERROR
==========================================
Error Message : Error loading required libraries.
Check that they exist, permissions are set correctly and that they compile.
Reason: Missing right curly or square bracket at ./companyhtml.pl line 1472, at end of line
syntax error at ./companyhtml.pl line 1472, at EOF
Compilation failed in require at company.cfg line 53.
Compilation failed in require at db.cgi line 55.

Script Location : db.cgi
Perl Version : 5.006
Setup File : company.cfg

Form Variables
-------------------------------------------
db : company
signin_form : 1

Environment Variables
-------------------------------------------
DOCUMENT_ROOT : /d01/sec/s14/a0001nx3
GATEWAY_INTERFACE : CGI/1.1
HTTP_ACCEPT : image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/x-comet, application/vnd.ms-excel, application/msword, image/tiff, */*
HTTP_ACCEPT_ENCODING: gzip, deflate
HTTP_ACCEPT_LANGUAGE: en-us
HTTP_CONNECTION : Keep-Alive
HTTP_HOST : scrawford.netfirms.com
HTTP_REFERER : http://scrawford.netfirms.com/
HTTP_USER_AGENT : Mozilla/4.0 (compatible; MSIE 5.01; Windows 98)
PATH : /usr/local/bin:/usr/bin:/bin
QUERY_STRING : db=company&signin_form=1
REMOTE_ADDR : 216.190.8.66
REMOTE_PORT : 1405
REQUEST_METHOD : GET
REQUEST_URI : /cgi-bin/database/db.cgi?db=company&signin_form=1
SCRIPT_FILENAME : /d01/sec/s14/a0001nx3/cgi-bin/database/db.cgi
SCRIPT_NAME : /cgi-bin/database/db.cgi
SCRIPT_URI : http://scrawford.netfirms.com/cgi-bin/database/db.cgi
SCRIPT_URL : /cgi-bin/database/db.cgi
SERVER_ADMIN : support@netfirms.com
SERVER_NAME : scrawford.netfirms.com
SERVER_PORT : 80
SERVER_PROTOCOL : HTTP/1.1
SERVER_SOFTWARE : Apache/1.3.9 (Unix)


Quote Reply
Re: Need Help with Spreadsheet mod In reply to
Scott, I haven't worked on it since I left work Friday. Since I am not yet skilled enough to review the code and catch any typos I might have made while doing the mod, I am going to start from scratch Monday Morning.

I read some useful information at http://webmagic.hypermart.net/dbman/learn.htm

For some reason, I haven't been getting any debugging data.

I'll let you know if I come up with anything.

-Thom

Quote Reply
Re: Need Help with Spreadsheet mod In reply to
Right. That's pretty obvious from the comments in the code, but where are the following lines supposed to be placed in the code?

######################################################
# Note: In each of the header cells, replace # with the field number
# of the field that is associated with that header -- in both places
# within each line.
print qq|
<TABLE><TR><TD><a href="$db_script_url?$new_url&sb=#&so=$so[#]">FieldName</a></TD>
<TD><a href="$db_script_url?$new_url&sb=#&so=$so[#]">FieldName</a></TD>
<TD><a href="$db_script_url?$new_url&sb=#&so=$so[#]">FieldName</a></TD>
<TD><a href="$db_script_url?$new_url&sb=#&so=$so[#]">FieldName</a></TD></TR>\n|;

for (0 .. $numhits - 1) {
print "<TR>";
&html_record (&array_to_hash($_, @hits));
print "</TR>\n";
}
print "</TABLE>";

######################################################


Or is this code that already exist but just needs to be changed? It says "in each of the header fields". But where is that? How do I know what the header fields are?

I've searched the unmodified code for similar expressions such as $db_script_url?$new_url&sb= but have not found anything, so I am guessing that the code needs to be added.

It seems to me that they are going to be the top row of the table that is printed. And it seems to me that the # should be replaced by field number (starting with 0 i am assuming).

If this is the case, do I need to list every field including the key field (i'd rather not include that field) or can I just include the fields that I want to show?

In my failed attempt, I did add the code and make the seemingly appropriate changes, but to no avail. Am I missing something or is it more likely a typo?

Thanks Eliot,

-Thom

Quote Reply
Re: Need Help with Spreadsheet mod In reply to
I went over every line trying to find something wrong. I found a couple of things and made the changes, but nothing seemed to fix it.

Can someone look at this and tell me if I have missed something. Thanks.

BEGIN {
open (STDERR, ">>/home/dss-www/htdocs/error.txt");
}

# User-friendly html.pl
#
# Save this file as -- html.pl -- and use it instead of the script by the same name
# that comes with the DBMan archive. Be sure to read the notes that accompany the
# script which follow the copyright information.
#
# ----------------------
# DBMan
# ----------------------
# Database Administrator
#
# File: html.pl
# Description: This file contains all the HTML that the program generates.
# Author: Alex Krohn
# Email: alex@gossamer-threads.com
# Web: http://www.gossamer-threads.com/
# Version: 2.04
#
# 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.
# =====================================================================
#
#
# Notes on the "user-friendly html.pl":
#
# Look closely at the sections marked "HTML Globals," and "Page Layout" to
# set up your database to appear the way you would like it to.
# You can also edit the "Record Layout" section to create your own forms and
# page displays.
# In each of the rest of the subroutines, you will have several variables you can set
# to your liking:
# $page_title
# $submit_button -- only on pages with forms -- the text of the submit button
# $reset_button -- only on pages with forms -- the text of the reset button
# Also, the form definitions have been moved a little so it is easier to know what you
# can and cannot edit. To clarify things even more, each subroutine has the area where
# you can enter any text you want to for that page. Enter or edit your own text between
# # <-- Start page text -->
# print qq|
# and
# |;
# # <-- End page text -->
#
# If you have more than one DBMan database on your site and you would like to have all
# the pages coordinate, you can cut the "HTML Globals" and "Page Layout" sections from
# each of your html.pl scripts and place the sections in a separate file. Name the file
# format.pl
# and upload it into the same directory as the other DBMan scripts. Set the permissions
# to 644 [-rw-r--r--]. Uncomment (that is, delete the # at the beginning of the line)
# the next line in each of your html.pl scripts.
# require $db_script_path . "/format.pl";

##########################################################
## HTML Globals ##
##########################################################
# Put any globals you like in here for your html pages.
$html_title = 'Database Manager Demo';

# Add your email address. Be sure to leave the \ before the @
$admin_email = 'you\@server.com';

# Set your font preferences below

# font face for pages
$face = "font face=Verdana, Arial, Helvetica";
# size of normal text
$font = "$face size=2";
# an alternate color font
$font_color = "$font color=#003399";
# size of title text
$font_title = "$face size=4";
# color of error messages
$error_color = "font color=red";
# large font for error messages
$font_error = "$face size=4 color=red";

##########################################################
## Page Layout ##
##########################################################

sub html_page_top {
# --------------------------------------------------------
# This is where you define what all of your web pages will look like.
# You can change the background color, add a background image (be sure to use the
# complete URL to your background image and not a relative URL), define the color of
# normal text and links -- all just as you would do with a regular html page.
# Be sure to leave in the first line -- &html_print_headers -- and to put your html
# formatting between "print qq|" and "|;"

&html_print_headers;

print qq|
<html><head><title>$html_title: $page_title</title></head>
<body bgcolor="#DDDDDD">
<center>
<table border=1 bgcolor="#FFFFFF" cellpadding=5 cellspacing=3 width=500 align=center valign=top>
<tr><td colspan=2 bgcolor="navy">
<FONT FACE="MS Sans Serif, arial,helvetica" size=1 COLOR="#FFFFFF"><b>$html_title: $page_title</b></font></td></tr>
<tr><td><p><center><$font_title><b>$page_title</b></font></center>

|;

}

sub html_page_bottom {
# --------------------------------------------------------
# Here is where you finish off your web pages. If you have not paid for the script,
# be sure to leave the Gossamer Threads logo in place.
# The second "print qq" statement is where you end off any tables or other formatting
# that you started in the "page_top" subroutines. It makes it easier to see what
# to do if you maintain the indenting of lines.

print qq|
<table border=0 width=100%>
<tr>
<td align=left><$font>Copyright 1998
<A HREF="http://www.gossamer-threads.com">Gossamer Threads Inc.</A></font></td>
<td align=right>
<a href="http://www.gossamer-threads.com/scripts/dbman/">
<img src="http://www.gossamer-threads.com/images/powered.gif"
border=0 width=100 height=31 alt="Database Powered by Gossamer Threads Inc."></a>
</td></tr>
</table>
|;

print qq|
</td></tr></table></center></body></html>
|;
}

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;
}
}

sub html_footer {
# --------------------------------------------------------
# Print the menu.
#
# We only print options that the user have permissions for.
#

print qq!<P align=center><$font>!;
print qq!| <A HREF="$db_script_link_url">Home</A> !;
print qq!| <A HREF="$db_script_link_url&add_form=1">Add</A> ! if ($per_add);
print qq!| <A HREF="$db_script_link_url&view_search=1">View</A> ! if ($per_view);
print qq!| <A HREF="$db_script_link_url&delete_search=1">Delete</A> ! if ($per_del);
print qq!| <A HREF="$db_script_link_url&modify_search=1">Modify</A> ! if ($per_mod);
print qq!| <A HREF="$db_script_link_url&view_records=1&$db_key=*">List All</A> ! if ($per_view);
print qq!| <A HREF="$db_script_link_url&admin_display=1">Admin</A> ! if ($per_admin);
print qq!| <A HREF="$db_script_link_url&logoff=1">Log Off</A> !;
print qq!|</font></p>!;

}

sub html_search_options {
# --------------------------------------------------------
# Search options to be displayed at the bottom of search forms.
#
print qq~
<P>
<$font><STRONG>Search Options:</STRONG>

<INPUT TYPE="CHECKBOX" NAME="ma"> Match Any
<INPUT TYPE="CHECKBOX" NAME="cs"> Match Case
<INPUT TYPE="CHECKBOX" NAME="ww"> Whole Words
<INPUT TYPE="CHECKBOX" NAME="re"> Reg. Expression<BR>
<INPUT TYPE="TEXT" NAME="keyword" SIZE=15 MAXLENGTH=255> Keyword Search <FONT SIZE=-1> (will match against all fields)</FONT><BR>
<INPUT TYPE="TEXT" NAME="mh" VALUE="$db_max_hits" SIZE=3 MAXLENGTH=3> Max. Returned Hits<BR>
Sort By:
<SELECT NAME="sb">
<OPTION>---
~; for (my $i =0; $i <= $#db_cols; $i++) { print qq~<OPTION VALUE="$i">$db_cols[$i]</OPTION>\n~ if ($db_form_len{$db_cols[$i]} >= 0); } print qq~
</SELECT>
Sort Order:
<SELECT NAME="so">
<OPTION VALUE="ascend">Ascending
<OPTION VALUE="descend">Descending
</SELECT>


<strong>Search Tips:</strong>

- use '*' to match everything in a field)<BR>
- put a '>' or '<' at the beginning to to do range searches.<BR></font>
~;
}

##########################################################
## 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
# <FORM> and </FORM tags, merely the <INPUT> 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_color = 'Font face="Verdana, Arial, Helvetica" Size=2 Color=#003399';

print qq|
<TABLE WIDTH="450" CELLPADDING=0 CELLSPACING=0 BORDER=1 BGCOLOR="#FFFFCC">
<input type="hidden" NAME="key" VALUE="$rec{'key'}">
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="150"><$font_color>Change:</FONT></TD>
<TD VALIGN="TOP" WIDTH="475"> <INPUT TYPE="TEXT" NAME="Change" SIZE="20" VALUE="$rec{'Change'}" MAXLENGTH="25"></TD></TR>
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="150"><$font_color>Project:</FONT></TD>
<TD VALIGN="TOP" WIDTH="475"> |; print &build_select_field("Project",$rec{'Project'}); print qq|</TD></TR>
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="150"><$font_color>Time:</FONT></TD>
<TD VALIGN="TOP" WIDTH="475"> <INPUT TYPE="TEXT" NAME="Time" SIZE="20" VALUE="$rec{'Time'}" MAXLENGTH="25"></TD></TR>
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="150"><$font_color>Date:</FONT></TD>
<TD VALIGN="TOP" WIDTH="475"> <INPUT TYPE="TEXT" NAME="Date" SIZE="20" VALUE="$rec{'Date'}" MAXLENGTH="25"></TD></TR>
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="150"><$font_color>Description:</FONT></TD>
<TD VALIGN="TOP" WIDTH="475"> <TEXTAREA NAME="Description" ROWS="5" COLS="40" WRAP="VIRTUAL" MAXLENGTH="1000">$rec{'Description'}</TEXTAREA></TD></TR>
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="150"><$font_color>Status:</FONT></TD>
<TD VALIGN="TOP" WIDTH="475"> |; print &build_select_field("Status",$rec{'Status'}); print qq|</TD></TR>
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="150"><$font_color>On Call:</FONT></TD>
<TD VALIGN="TOP" WIDTH="475"> <INPUT TYPE="TEXT" NAME="On Call" SIZE="20" VALUE="$rec{'On Call'}" MAXLENGTH="50"></TD></TR>
</TABLE>
|;
}

#####################################################################
# 1-12-01 Replaced sub html_record with the following:

sub html_record {
my (%rec) = @_;

# Replace FieldName below with the names of the fields you want to
# display. Create as many table cells as you wish, one for each field.
print qq|
<TD>$rec{'Change'}</TD>
<TD>$rec{'Project'}</TD>
<TD>$rec{'Time'}</TD>
<TD>$rec{'Date'}</TD>
<TD>$rec{'Description'}</TD>
<TD>$rec{'Status'}</TD>
<TD>$rec{'On Call'}</TD>
|;
}

#####################################################################


##########################################################
## Home Page ##
##########################################################

sub html_home {
# --------------------------------------------------------
# The database manager home page.

$page_title = "Main Menu";
&html_page_top;

# < -- Start page text -- >
print qq|
<$face size="1"><b>
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|</b></font>
<P><$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.


<em>Enjoy!</em> and let me <a href="mailto:alex\@gossamer-threads.com">know</a> if you have any comments!
</font></p>
|;
# < -- End page text -->

&html_footer;
&html_page_bottom;
}



##########################################################
## 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.

$page_title = "Add a New Record";
&html_page_top;

$submit_button = "Add Record";
$reset_button = "Reset Form";

# < -- Start page text -- >
print qq|

|;
# < -- End page text -->

print qq|
<form action="$db_script_url" method="POST">
<input type=hidden name="db" value="$db_setup">
<input type=hidden name="uid" value="$db_uid">|;

&html_record_form (&get_defaults);

print qq|
<p><center>
<INPUT TYPE="SUBMIT" NAME="add_record" VALUE="$submit_button">
<INPUT TYPE="RESET" VALUE="$reset_button">
</center></p></form>
|;

&html_footer;
&html_page_bottom;
}

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.

$page_title = "Record Added";
&html_page_top;

# < -- Start page text -- >
print qq|
<P><$font>The following record was successfully added to the database:</FONT>
|;
# < -- End page text -->

print qq|
<TABLE><TR><TD>Change</TD>
<TD>Project</TD>
<TD>Time</TD>
<TD>Date</TD>
<TD>Description</TD>
<TD>Status</TD>
<TD>On Call</TD></TR>\n
<TR>|;
&html_record(&get_record($in{$db_key}));
print "</TR></TABLE>";

&html_footer;
&html_page_bottom;
}

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];

$page_title = "Unable to Add Record";
&html_page_top;

$submit_button = "Add Record";
$reset_button = "Reset Form";

# < -- Start page text -- >
print qq|
<$font>There were problems with the following fields:
<FONT COLOR="red"><B>$message</B></FONT>
<P>Please fix any errors and submit the record again.</p></font>
|;
# < -- End page text -->

print qq|
<form action="$db_script_url" method="POST">
<input type=hidden name="db" value="$db_setup">
<input type=hidden name="uid" value="$db_uid">|;

&html_record_form (%in);

print qq|
<p><center>
<INPUT TYPE="SUBMIT" NAME="add_record" VALUE="$submit_button">
<INPUT TYPE="RESET" VALUE="$reset_button">
</center></p></form>
|;

&html_footer;
&html_page_bottom;
}

##########################################################
## 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.
#

$page_title= "Search the Database";
&html_page_top;

$submit_button = "View Records";
$reset_button = "Reset Form";

# < -- Start page text -- >
print qq|

|;
# < -- End page text -->

print qq|
<form action="$db_script_url" method="GET">
<input type=hidden name="db" value="$db_setup">
<input type=hidden name="uid" value="$db_uid">
|;

&html_record_form();

&html_search_options;

print qq|
<p><center>
<INPUT TYPE="SUBMIT" NAME="view_records" VALUE="$submit_button">
<INPUT TYPE="RESET" VALUE="$reset_button">
</center></p></form>
|;

&html_footer;
&html_page_bottom;
}

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);

$page_title = "Search Results";
&html_page_top;

# < -- Start page text -- >
print qq|
<p><$font>
Your search returned <b>$db_total_hits</b> matches.</font>
|;
# < -- End page text -->

if ($db_next_hits) { print "
<$font>Pages: $db_next_hits</font>"; }

# Go through each hit and convert the array to hash and send to
# html_record for printing.
$new_url = $ENV{'QUERY_STRING'};
$new_url =~ s/\&sb=\d*//;
$new_url =~ s/\&so=\w*//;
for ($col=0; $col <=$#db_cols; ++$col) {
if ($in{'sb'} == $col) {
if ($in{'so'} eq 'descend') { $sb[$col] = 'ascend'; }
else { $so[$col] = 'descend'; }
}
else { $so[$col] = 'ascend'; }
}

# Note: In each of the header cells, replace # with the field number
# of the field that is associated with that header -- in both places
# within each line.
print qq|
<TABLE><TR><TD><a href="$db_script_url?$new_url&sb=0&so=$so0">FieldName</a></TD>
<TD><a href="$db_script_url?$new_url&sb=1&so=$so1">FieldName</a></TD>
<TD><a href="$db_script_url?$new_url&sb=2&so=$so2">FieldName</a></TD>
<TD><a href="$db_script_url?$new_url&sb=3&so=$so3">FieldName</a></TD>
<TD><a href="$db_script_url?$new_url&sb=4&so=$so4">FieldName</a></TD>
<TD><a href="$db_script_url?$new_url&sb=5&so=$so5">FieldName</a></TD>
<TD><a href="$db_script_url?$new_url&sb=6&so=$so6">FieldName</a></TD>
</TR>\n|;

for (0 .. $numhits - 1) {
print "<TR>";
&html_record (&array_to_hash($_, @hits));
print "</TR>\n";
}
print "</TABLE>";

if ($db_next_hits) { print "
<$font>Pages: $db_next_hits</font>"; }

&html_footer;
&html_page_bottom;

}

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];

$page_title = "Search Failed";
&html_page_top;

$submit_button = "View Records";
$reset_button = "Reset Form";

# < -- Start page text -- >
print qq|
<$font><P>There were problems with the search. Reason:
<$error_color><B>$message</B></FONT>
<BR>Please fix any errors and submit the record again.</p>
|;
# < -- End page text -->

print qq|
<form action="$db_script_url" method="GET">
<input type=hidden name="db" value="$db_setup">
<input type=hidden name="uid" value="$db_uid">
|;

&html_record_form(%in);

&html_search_options;

print qq|
<p><center>
<INPUT TYPE="SUBMIT" NAME="view_records" VALUE="$submit_button">
<INPUT TYPE="RESET" VALUE="$reset_button">
</center></p></form>
|;

&html_footer;
&html_page_bottom;
}

##########################################################
## 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.

$page_title = "Search the Database for Deletion";
&html_page_top;

$submit_button = "Search";
$reset_button = "Reset Form";

# < -- Start page text -- >
print qq|
<$font><P>Search the database for the records you wish to delete or
<A HREF="$db_script_link_url&delete_form=1&$db_key=*">list all</a>:</p>
|;
# < -- End page text -->

print qq|
<form action="$db_script_url" method="GET">
<input type=hidden name="db" value="$db_setup">
<input type=hidden name="uid" value="$db_uid">
|;

&html_record_form();

&html_search_options;

print qq|
<p><center>
<INPUT TYPE="SUBMIT" NAME="delete_form" VALUE="$submit_button">
<INPUT TYPE="RESET" VALUE="$reset_button">
</center></p></form>
|;

&html_footer;
&html_page_bottom;
}

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);

$page_title = "Delete Record(s)";
&html_page_top;

$submit_button = "Delete Checked Record(s)";
$reset_button = "Reset Form";

if ($status ne "ok") { # There was an error searching!
print qq|<P><$font_error>Error: $status</FONT></P>|;
&html_footer;
&html_page_bottom;
}

else {
# < -- Start page text -- >
print qq|
<p><$font>
Check which records you wish to delete and then press "Delete Records":

Your search returned <b>$db_total_hits</b> matches.</font>
|;
# < -- End page text -->

if ($db_next_hits) { print "
<$font>Pages: $db_next_hits</font>"; }

print qq|
<form action="$db_script_url" method="POST">
<input type=hidden name="db" value="$db_setup">
<input type=hidden name="uid" value="$db_uid">|;

# 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.

print "<P>";
$new_url = $ENV{'QUERY_STRING'};
$new_url =~ s/\&sb=\d*//;
$new_url =~ s/\&so=\w*//;
for ($col=0; $col <=$#db_cols; ++$col) {
if ($in{'sb'} == $col) {
if ($in{'so'} eq 'descend') { $sb[$col] = 'ascend'; }
else { $so[$col] = 'descend'; }
}
else { $so[$col] = 'ascend'; }
}

# Note: In each of the header cells, replace # with the field number
# of the field that is associated with that header -- in both places
# within each line.
print qq|
<TABLE><TR><TD> </TD>
<TD><a href="$db_script_url?$new_url&sb=0&so=$so0">FieldName</a></TD>
<TD><a href="$db_script_url?$new_url&sb=1&so=$so2">FieldName</a></TD>
<TD><a href="$db_script_url?$new_url&sb=3&so=$so3">FieldName</a></TD>
<TD><a href="$db_script_url?$new_url&sb=4&so=$so4">FieldName</a></TD>
<TD><a href="$db_script_url?$new_url&sb=5&so=$so5">FieldName</a></TD>
<TD><a href="$db_script_url?$new_url&sb=6&so=$so6">FieldName</a></TD></TR>\n|;

for (0 .. $numhits - 1) {
print "<TR>";
%tmp = &array_to_hash($_, @hits);
print qq|<TD><INPUT TYPE=CHECKBOX NAME="$tmp{$db_key}" VALUE="delete"></TD>|;
&html_record (%tmp);
print "</TR>\n";
}
print "</TABLE>";
print qq|
<p><center>
<INPUT TYPE="SUBMIT" name="delete_records" VALUE="$submit_button">
<INPUT TYPE="RESET" VALUE="$reset_button">
</center></p></form>
|;

if ($db_next_hits) { print "
<$font>Pages: $db_next_hits</font>"; }

&html_footer;
&html_page_bottom;
}
}

sub html_delete_success {
# --------------------------------------------------------
# This page let's the user know that the records were successfully
# deleted.

my $message = shift;

$page_title = "Record(s) Deleted";
&html_page_top;

# < -- Start page text -- >
print qq|
<$font>The following records were deleted from the database: '$message'.</font></p>
|;
# < -- End page text -->

&html_footer;
&html_page_bottom;
}

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];

$page_title = "Record(s) Not Deleted";
&html_page_top;

# < -- Start page text -- >
print qq|
<$font>The records with the following keys were not found in the database:
<$error_color>'$errstr'</FONT>.</font></p>
|;
# < -- End page text -->

&html_footer;
&html_page_bottom;
}

##########################################################
## 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.


$page_title = "Search the Database for Modifying";
&html_page_top;

$submit_button = "Search";
$reset_button = "Reset Form";

# < -- Start page text -- >
print qq|
<$font><P>Search the database for the records you wish to modify or
<A HREF="$db_script_link_url&modify_form=1&$db_key=*">list all</a>:</p>
|;
# < -- End page text -->

print qq|
<form action="$db_script_url" method="GET">
<input type=hidden name="db" value="$db_setup">
<input type=hidden name="uid" value="$db_uid">
|;

&html_record_form();

&html_search_options;

print qq|
<p><center>
<INPUT TYPE="SUBMIT" NAME="modify_form" VALUE="$submit_button">
<INPUT TYPE="RESET" VALUE="$reset_button">
</center></p></form>
|;

&html_footer;
&html_page_bottom;
}


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);


$page_title = "Modify Record";
&html_page_top;

$submit_button = "Modify Record";
$reset_button = "Reset Form";

if ($status ne "ok") { # Error searching database!
print qq|<P><$font_error>Error: $status</FONT>|;
&html_footer;
&html_page_bottom;
}
else {
# < -- Start page text -- >
print qq|
<p><$font>
Check which record you wish to modify and then press "Modify Records":

Your search returned <b>$db_total_hits</b> matches.</font>
|;
# < -- End page text -->

if ($db_next_hits) { print "
<$font>Pages: $db_next_hits</font>"; }

print qq|
<form action="$db_script_url" method="POST">
<input type=hidden name="db" value="$db_setup">
<input type=hidden name="uid" value="$db_uid">|;

# 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 "<P>";
$new_url = $ENV{'QUERY_STRING'};
$new_url =~ s/\&sb=\d*//;
$new_url =~ s/\&so=\w*//;
for ($col=0; $col <=$#db_cols; ++$col) {
if ($in{'sb'} == $col) {
if ($in{'so'} eq 'descend') { $sb[$col] = 'ascend'; }
else { $so[$col] = 'descend'; }
}
else { $so[$col] = 'ascend'; }

}
# Note: In each of the header cells, replace # with the field number
# of the field that is associated with that header -- in both places
# within each line.
print qq|
<TABLE><TR><TD> </TD>
<TD><a href="$db_script_url?$new_url&sb=0&so=$so0">FieldName</a></TD>
<TD><a href="$db_script_url?$new_url&sb=1&so=$so1">FieldName</a></TD>
<TD><a href="$db_script_url?$new_url&sb=2&so=$so2">FieldName</a></TD>
<TD><a href="$db_script_url?$new_url&sb=3&so=$so3">FieldName</a></TD>
<TD><a href="$db_script_url?$new_url&sb=4&so=$so4">FieldName</a></TD>
<TD><a href="$db_script_url?$new_url&sb=5&so=$so5">FieldName</a></TD>
<TD><a href="$db_script_url?$new_url&sb=6&so=$so6">FieldName</a></TD></TR>\n|;

for (0 .. $numhits - 1) {
print "<TR>";
%tmp = &array_to_hash($_, @hits);
print qq|<TD><INPUT TYPE=RADIO NAME="modify" VALUE="$tmp{$db_key}"></TD>|;
&html_record (%tmp);
print "</TR>\n";
}
print "</TABLE>";

print qq|
<p><center>
<input type="SUBMIT" name="modify_form_record" VALUE="$submit_button">
<INPUT TYPE="RESET" VALUE="$reset_button">
</center></p></form
|;

if ($db_next_hits) { print "
<$font>Pages: $db_next_hits</font>"; }

&html_footer;
&html_page_bottom;
}

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; }

$page_title = "Modify a Record";
&html_page_top;

$submit_button = "Modify Record";
$reset_button = "Reset Form";

# < -- Start page text -- >
print qq|

|;
# < -- End page text -->

print qq|
<form action="$db_script_url" method="POST">
<input type=hidden name="db" value="$db_setup">
<input type=hidden name="uid" value="$db_uid">|;

&html_record_form (%rec);

print qq|
<p><center>
<INPUT TYPE="SUBMIT" NAME="modify_record" VALUE="$submit_button">
<INPUT TYPE="RESET" VALUE="$reset_button">
</center></p></form>
|;

&html_footer;
&html_page_bottom;
}

sub html_modify_success {
# --------------------------------------------------------
# The user has successfully modified a record, and this page will
# display the modified record as a confirmation.

$page_title = "Record Modified";
&html_page_top;

# < -- Start page text -- >
print qq|
<$font>The following record was successfully modified:</font></p>
|;
# < -- End page text -->

print qq|
<TABLE><TR><TD>Change</TD>
<TD>Project</TD>
<TD>Time</TD>
<TD>Date</TD>
<TD>Description</TD>
<TD>Status</TD>
<TD>On Call</TD></TR>\n
<TR>|;
&html_record(&get_record($in{$db_key}));
print "</TR></TABLE>";

&html_footer;
&html_page_bottom;

}

sub html_modify_failure {
# --------------------------------------------------------
# There was an error modifying the record. $message contains
# the reason why.

my ($message) = $_[0];

$page_title = "Unable to Modify Record";
&html_page_top;

$submit_button = "Modify Record";
$reset_button = "Reset Form";

# < -- Start page text -- >
print qq|
<$font>There were problems modifying the record:
<$error_color><B>$message</B></FONT>
<BR>Please fix any errors and submit the record again.
</font></p>
|;
# < -- End page text -->

print qq|
<form action="$db_script_url" method="POST">
<input type=hidden name="db" value="$db_setup">
<input type=hidden name="uid" value="$db_uid">|;

&html_record_form (%in);

print qq|
<p><center>
<INPUT TYPE="SUBMIT" NAME="modify_record" VALUE="$submit_button">
<INPUT TYPE="RESET" VALUE="$reset_button">
</center></p></form>
|;

&html_footer;
&html_page_bottom;
}

##########################################################
## Authentication ##
##########################################################
sub html_login_form {
# --------------------------------------------------------
# The login screen.

$page_title = "Login";
&html_page_top;

$submit_button = "Logon";
$reset_button = "Cancel";

# < -- Start page text -- >
print qq|
<$font>Welcome! You need to have an active account to access $html_title. For
the demo, you can use userid/passwords: 'admin/admin', 'author/author', 'guest/guest'.
<p>
|;
# < -- End page text -->

print qq|
<form action="$db_script_url" method="POST">
<input type=hidden name="db" value="$db_setup">
<input type=hidden name="uid" value="$db_uid">

<table border=0>
<tr><td><$font_color><b>User ID:</b></FONT></td>
<td><input type="TEXT" name="userid"></td></tr>
<tr><td><$font_color><b>Password:</b></FONT></td>
<td><input type="PASSWORD" name="pw"></td></tr>
</table>
<p><center>
<INPUT TYPE="SUBMIT" name="login" VALUE="$submit_button">
<INPUT TYPE="SUBMIT" NAME="logoff" VALUE="$reset_button">
</center></p></form>
|;

if ($auth_signup) {
print qq|You can sign up for an account online right <a href="$db_script_url?db=$db_setup&signup_form=1">here</a>.|;
}

&html_page_bottom;
}

sub html_login_failure {
# --------------------------------------------------------
# There was an error loggin in. The error message is stored in $message.

my ($message) = $_[0];

$page_title = "Login Error";
&html_page_top;

$submit_button = "Logon";
$reset_button = "Cancel";

# < -- Start page text -- >
print qq|
<$font>Oops, there was a problem logging into the system:
<$error_color><b>$message</b></font>.


Please try logging in again, or contact the
<a href="mailto:$admin_email">system administrator.</a></font>
|;
# < -- End page text -->

print qq|
<form action="$db_script_url" method="POST">
<input type=hidden name="db" value="$db_setup">
<input type=hidden name="uid" value="$db_uid">
<p>
<table border=0>
<tr><td><$font_color><b>User ID:</b></FONT></td>
<td><input type="TEXT" name="userid" value="$in{'userid'}"></td></tr>
<tr><td><$font_color><b>Password:</b></FONT></td>
<td><input type="PASSWORD" name="pw" value="$in{'pw'}"></td></tr>
</table>
<p><center>
<input type="SUBMIT" name="login" VALUE="$submit_button">
<INPUT TYPE="SUBMIT" NAME="logoff" VALUE="$reset_button">
</center></p></form>
|;
if ($auth_signup) {
print qq|You can sign up for an account online right <a href="$db_script_url?db=$db_setup&signup_form=1">here</a>.|;
}
&html_page_bottom;
}

sub html_admin_display {
# --------------------------------------------------------
# The displays the list of current users.

my ($message, $user_list, $password, $permissions) = @_;

$page_title = "User Management";
&html_page_top;

$submit_button = "Update/Create User";

# < -- Start page text -- >
print qq|
<p><$font><$error_color><b>$message</b></font></font></p>
|;
# < -- End page text -->

print qq|
<form action="$db_script_url" method="POST">
<input type=hidden name="db" value="$db_setup">
<input type=hidden name="uid" value="$db_uid">
<input type=hidden name="admin_display" value="1">

<table border=0>
<tr><td align=right><$font>User List:</font></td>
<td>$user_list <input type=submit name=inquire value="Inquire"> <input type=submit name=delete value="Delete"></td></tr>
<tr><td align=right><$font>New Username:</font></td>
<td><input type="text" name="new_username" size="14"></td></tr>
<tr><td align=right><$font>Change Password:</font></td>
<td><input type="text" name="password" value="$password" size="14"></td></tr>
<tr><td colspan=2><$font>Permissions:

$permissions</font></td></tr>
</table>
<p><center>
<input type=submit value="$submit_button">
</center></p></form>
|;

&html_footer;
&html_page_bottom;
}

sub html_unauth {
# --------------------------------------------------------
# A user tried to do something he was not authorized for.

$page_title = "Unauthorized Action";
&html_page_top;

# < -- Start page text -- >
print qq|
<$font>The database program received a command that you are not authorized for.</font>
|;
# < -- End page text -->

&html_footer;
&html_page_bottom;
}

sub html_signup_form {
# --------------------------------------------------------
# This form is displayed for new users who want to create an account.
#
my $error = shift;

$page_title = "Create Account";
&html_page_top;

$submit_button = "Create";
$reset_button = "Cancel";

# < -- Start page text -- >
print qq|
<$font>To create your own account, simply enter in your desired username and
password.<p>
|;
# < -- End page text -->

if ($error) { print "<font color=red>$error</font></p>"; }

print qq|
<form action="$db_script_url" method="POST">
<input type=hidden name="db" value="$db_setup">
<input type=hidden name="uid" value="$db_uid">
<table border=0>
<tr><td><$font_color><b>User ID:</b></FONT></td>
<td><input type="TEXT" name="userid" value="$in{'userid'}"></td></tr>
<tr><td><$font_color><b>Password:</b></FONT></td>
<td><input type="PASSWORD" name="pw" value="$in{'pw'}"></td></tr>
</table>
<p><center>
<INPUT TYPE="SUBMIT" name="signup" VALUE="$submit_button">
<INPUT TYPE="SUBMIT" NAME="logoff" VALUE="$reset_button">
</center></p></form>
|;

&html_page_bottom;
}

sub html_signup_success {
# --------------------------------------------------------
# The user has successfully created a new account.

$page_title = "Account Created";
&html_page_top;

$submit_button = "Logon";
$reset_button = "Cancel";

# < -- Start page text -- >
print qq|
<$font>Your account has been set up! Use your username and password to log in.
|;
# < -- End page text -->

print qq|
<form action="$db_script_url" method="POST">
<input type=hidden name="db" value="$db_setup">
<input type=hidden name="uid" value="$db_uid">
<p>
<table border=0>
<tr><td><$font_color><b>User ID:</b></FONT></td>
<td><input type="TEXT" name="userid"></td></tr>
<tr><td><$font_color><b>Password:</b></FONT></td>
<td><input type="PASSWORD" name="pw"></td></tr>
</table>
<p><center>
<INPUT TYPE="SUBMIT" name="login" VALUE="$submit_button">
<INPUT TYPE="SUBMIT" NAME="logoff" VALUE="$reset_button">
</center></p></form>
|;

&html_page_bottom;
}

##########################################################
## Misc ##
##########################################################

sub html_unkown_action {
# --------------------------------------------------------
# The program received a command it did not recognize.

$page_title = "Unknown Action";
&html_page_top;

# < -- Start page text -- >
print qq|
<$font>The database program received a command that it did not understand.</font></p>
|;
# < -- End page text -->

&html_footer;
&html_page_bottom;
}
1;