###############################################################################
#                       AUTH-EXTRA-HTML.PL
#
# This script was written by Selena Sol & Gunther Birznieks. 
# Date Created: 5-10-96
# Date Last Modified: 12-01-98
# Last modified by Michael E. Schechter (mschechter@earthlink.net)
#
#   You may copy this under the terms of the GNU General Public
#   License or the Artistic License which is distributed with
#   copies of Perl v5.x for UNIX.
# 
# Selena Sol may be contacted at selena@extropia.com
#
# Purpose: This script contains all the cosmetic HTML output
# routines related to the authentication routines.  Basically,
# each routine prints out an HTML page to provide information
# or prompt user for input for registration purposes.
#
# Main Procedures:
#   All the routines are ancillary to the auth-extra-lib.pl 
#   file.
#
# Special Notes: Nearly all the routines below accept
# some sort of parameter.  These parameters are only for
# printing out extra information.  They are not doing any
# significant processing.
#
# Modifications by MES:  Mostly cleaning up the script to make
# it easier, at least for me, to read.  Added cookie support to
# the authorization routines, so added appropriate HTML to
# utilize them.  Added public access button information.  Added
# instructions for using the user_help.pl add-on script that I
# wrote, in order to provide online help to users.
###############################################################################

###############################################################################
# Subroutine: PrintLogonPage()
#
#  This routine outputs the logon HTML page along with
#  a bad logon message if one exists.  Hidden form tags
#  are generated automatically if we are passing previous
#  form data from the main script.
###############################################################################

sub PrintLogonPage {
	local($bad_logon_message, $main_script, *in) = @_;
	local($form_tags,$register_tag,$search_tag,$public_access_tag,$cookie_tag);
	$register_tag = "";
	$search_tag = "";
	$public_access_tag = "";
	$cookie_tag = "";
	if ($auth_allow_register) {
		$register_tag = "<input type=\"submit\" name=\"auth_register_screen_op\" ";
		$register_tag .= "value=\"Register for Account\"><p>\n";
	}
	if ($auth_allow_search) {
		$search_tag = "<input type=\"submit\" name=\"auth_search_screen_op\" ";
		$search_tag .= "value=\"Search for Account\"><p>\n";
	}
	if ($allow_public_access) {
		$public_access_tag = "<b>Click the Public Access button for read-only access.</b><p>";
		$public_access_tag .= "<center><input type=\"submit\" name=\"public_access_op\" ";
		$public_access_tag .= "value=\"Public Access\"></center><hr>\n";
	}
	if ($use_cookies) {
		$cookie_tag = "<input type=\"checkbox\" name=\"save_info\" value=\"on\">";
		$cookie_tag .= "<font size=\"1\"><b>Save Login Information</b></font>";
	}
	$form_tags = &PrintCurrentFormVars(*in);
	print "Content-type: text/html\n\n";
	print "<html><head><title>Submit Logon</title>";
	if ($auth_use_help) {
		print qq!
		<script language="JavaScript">
		<\!--
		function openNew(url) {
			window.open(url, "fc_info", "scrollbars,height=225,width=400");
		}
		//-->
		</script>\n!;
	}
	print "</head><body$bodytag>\n$basefont_tag\n<center>";
	print "<h3>Enter Your Logon Information</h3><p>";
	if ($auth_use_help) {
		print qq!
		<a href=javascript:openNew('$auth_help_script?config_file=$auth_help_setup&help_topic=90')><b>H&nbsp;E&nbsp;L&nbsp;P</b></a>!;
	}
	print "<hr><font size=\"2\">$bad_logon_message";
	print "<form method=\"post\" action=$main_script>\n$form_tags\n";
	print "$public_access_tag</font><table>";
	print "<tr><td><b><font size=\"2\">Username</font></b></td>\n";
	print "<td><input type=\"text\" name=\"auth_user_name\"></td>\n</tr>";
	print "<tr><td><b><font size=\"2\">Password</font></b></td>\n";
	print "<td><input type=\"password\" name=\"auth_password\"></td></tr>\n";
	print "</table>$cookie_tag<p>\n<input type=\"submit\" name=\"auth_logon_op\" ";
	print "value=\"Logon to System\"><p>\n";
	print "$register_tag\n$search_tag\n<hr></center></form></body></html>";
}

###############################################################################
# Subroutine: PrintSearchPage()
#
#  This routine outputs the Search HTML page if one exists.  
#  Hidden form tags are generated automatically if we are 
#  passing previous form data from the main script.
###############################################################################

sub PrintSearchPage {
	local($main_script,*in) = @_;
	local($form_tags);
	$form_tags = &PrintCurrentFormVars(*in);
	print "Content-type: text/html\n\n";
	print "<html><head><title>Search For An Account</title>";
	if ($auth_use_help) {
		print qq!
			<script language="JavaScript">
			<\!--
			function openNew(url) {
				window.open(url, "fc_info", "scrollbars,height=225,width=400");
			}
			//-->
			</script>!;
	}
	print qq!
		</head><body$bodytag>$basefont_tag<center>
		<h3>Search For Matching Username</h3><p>!;
	if ($auth_use_help) {
		print qq!
			<a href=javascript:openNew('$auth_help_script?config_file=$auth_help_setup&help_topic=92')><B>H&nbsp;E&nbsp;L&nbsp;P</B></A>!;
	}
	print qq!
		<hr></center><blockquote><b>Enter Your Email Address To Search For A
		Matching Username</b></blockquote>
		<form method="post" action=$main_script>$form_tags<center><table>
		<tr><td><b><font size="2">Email</font></b></td>
		<td><input type="text" name=auth_email></td></tr></table><p>
		<input type="submit" name="auth_search_op" value="Submit Search"><p>
		<input type="submit" name="auth_logon_screen_op" value="Return to Logon Screen">
		<p></center></form></body></html>!;
}

###############################################################################
# Subroutine: HTMLPrintSearchResults()
#
#   This routine outputs the results of the search for 
#   usernames using an email address
###############################################################################

sub HTMLPrintSearchResults {
	local($main_script, $form_tags, $user_list) = @_;
	print "Content-type: text/html\n\n";
	print qq!
		<html><head><title>User Found</title></head>
		<body$bodytag>$basefont_tag<center>
		<h3>User Was Found In The Search</h3><hr>
		<h3>List Of Users</h3><b>$user_list</b>
		<form method="post" action=$main_script>$form_tags
		<input type="submit" name="auth_logon_screen_op" value="Return to Logon Screen">
		</center></form></body></html>!;
}

###############################################################################
# Subroutine: HTMLPrintNoSearchResults()
#
#   This routine prints the HTML related to not having
#   found any results from the search on email address.
###############################################################################

sub HTMLPrintNoSearchResults {
	local($main_script, $form_tags) = @_;
	print "Content-type: text/html\n\n";
	print qq!
		<html><head><title>No Users Found</title></head>
		<body$bodytag>$basefont_tag<center>
		<h3>Sorry, No Users Found</h3></center><hr><blockquote>
		<b>Sorry, no users were found that matched your email address.</b></blockquote>
		<center><form method="post" ACTION=$main_script>$form_tags
		<input type="submit" name="auth_search_screen_op" value="Return to Search Screen"><p>
		<input type="submit" name="auth_logon_screen_op" value="Return to Logon Screen">
		</center></form></body></html>!;
}

###############################################################################
# Subroutine: PrintRegisterPage()
#
#  This routine outputs the Register HTML page.  Hidden form 
#  tags are generated automatically if we are passing previous
#  form data from the main script.
###############################################################################

sub PrintRegisterPage {
	local($main_script,*in) = @_;
	local($more_form_input,$password_input, $x, $form_tags, $password_message);
	$form_tags = &PrintCurrentFormVars(*in);
	$more_form_input = "";
	for ($x = 0; $x <= @auth_extra_fields - 1; $x++) {
		$more_form_input .= "<tr><td align=right><b><font size=\"2\">$auth_extra_desc[$x]</font>";
		$more_form_input .= "</b></td><td>";
		$more_form_input .= "<input type=\"text\" name=$auth_extra_fields[$x]></td></tr>";
	}
	$password_input = "";
	unless ($auth_generate_password) {
		$password_input = "<tr><td align=right><b><font size=\"2\">Password</font>";
		$password_input .= "</b></td><td><input type=password name=auth_password1>";
		$password_input .= "</td></tr>\n<tr><td align=right><b><font size=\"2\">";
		$password_input .= "Password Again</font></b></td><td>";
		$password_input .= "<input type=password name=auth_password2></td></tr>\n";
	}
	$password_message = "";
	if ($auth_generate_password) {
		$password_message = "Your password will be automatically generated";
		if ($auth_email_register) {
			$password_message .= " and sent to you via your E-Mail address.";
		} else {
			$password_message .= ".";
		}
	}
    print "Content-type: text/html\n\n";
	print "<html><head><title>Register For An Account</title>";
	if ($auth_use_help) {
		print qq!
			<script language="JavaScript">
			<\!--
			function openNew(url) {
				window.open(url, "fc_info", "scrollbars,height=225,width=400");
			}
			//-->
			</script>!;
	}
	print "</head><body$bodytag>$basefont_tag<center>";
	print "<h3>Enter The Registration Information</h3><p>";
	if ($auth_use_help) {
		print qq!
			<a href=javascript:openNew('$auth_help_script?config_file=$auth_help_setup&help_topic=91')><b>H&nbsp;E&nbsp;L&nbsp;P</b></a>!;
	}
	print qq!
		<hr><form method="post" action=$main_script>$form_tags
		<table><tr><td align=right><b><font size="2">User Name</font></b></td>
		<td><input type=Username name=auth_user_name></td></tr>
		$password_input
		$more_form_input</table>!;
	if ($use_cookies) {
		print "<input type=\"checkbox\" name=\"save_info\" value=\"on\">",
			  "<font size=\"1\"><b> Save Login Information</b></font>";
	}
	print qq!
		<p><input type="submit" name="auth_register_op" value="Submit Information"><p>
		<input type="submit" name="auth_logon_screen_op" value="Return to Logon Screen"><p>
		</center></form>$password_message</body></html>!;
}

###############################################################################
# Subroutine: HTMLPrintRegisterSuccess()
#
#  This routine prints the HTML for a successful user
#  registration.
###############################################################################

sub HTMLPrintRegisterSuccess {
	local($main_script, $form_tags) = @_;
	print "Content-type: text/html\n\n";
	print qq!
		<html><head><title>Registration Added</title></head>
		<body$bodytag>$basefont_tag<center>
		<h3>You have been added to the user database.</h3></center><hr>
		<form method="post" action=$main_script>$form_tags<blockquote>
		<b>$auth_register_message</b></blockquote><center>
		<input type="submit" name="auth_logon_screen_op" value="Return to Logon Screen")
		</center></form></body></html>!;
}

###############################################################################
# Subroutine: HTMLPrintRegisterPassword()
#
#  This routine prints the HTML for a successful user
#  registration when password generation is on and 
#  $auth_email_register is off.
###############################################################################

sub HTMLPrintRegisterPassword {
	local($main_script, $message, $form_tags) = @_;
	print "Content-type: text/html\n\n";
	print qq!
		<html><head><title>Registration Added</title></head>
		<body$bodytag>$basefont_tag<center>
		<h3>You have been added to the user database.</h3></center><hr>
		<form method="post" action=$main_script>$form_tags<blockquote>
		<b>$auth_register_message<p>$message</b></blockquote><center>
		<input type="submit" name="auth_logon_screen_op" value="Return to Logon Screen")
		</center></form></body></html>!;
}

###############################################################################
# Subroutine: HTMLPrintRegisterFoundDuplicate()
#
#  This routine prints the HTML for a failed user
#  registration because of finding a duplicate username
###############################################################################

sub HTMLPrintRegisterFoundDuplicate {
	local($main_script, $form_tags) = @_;
	print "Content-type: text/html\n\n";
	print qq!
		<html><head><title>Problem with Registration</title></head>
		<body$bodytag>$basefont_tag<center>
		<h3>Problem with Registration</h3></center><hr>
		<form method="post" action=$main_script>$form_tags<blockquote><b>
		Sorry, your username is already in the database.  Please try again.</b>
		</blockquote><center>
		<input type="submit" name="auth_register_screen_op" value="Return to Registration Screen")
		</center></form></body></html>!;
}

###############################################################################
# Subroutine: HTMLPrintRegisterNoPasswordMatch()
#
#  This routine prints the HTML for a failed user
#  registration because the two passwords did not match
###############################################################################

sub HTMLPrintRegisterNoPasswordMatch {
	local($main_script, $form_tags) = @_;
	print "Content-type: text/html\n\n";
	print qq!
		<html><head><title>Problem with Registration</title></HEAD>
		<body$bodytag>$basefont_tag\n<center>
		<h3>Problem with Registration</h3></center><hr>
		<form method="post" action=$main_script>$form_tags
		<blockquote><b>Sorry, the two passwords you typed do not match.</b>
		</blockquote><center>
		<input type="submit" name="auth_register_screen_op" value="Return to Registration Screen")
		</center></form></body></html>!;
}

###############################################################################
# Subroutine: HTMLPrintRegisterNoValidValues()
#
#  This routine prints the HTML for a failed user
#  registration because of finding a missing value or
#  a value that has a PIPE in it.
###############################################################################

sub HTMLPrintRegisterNoValidValues {
	local ($main_script, $form_tags) = @_;
	print "Content-type: text/html\n\n";
	print qq!
		<html><head><title>Problem with Registration</title></head>
		<body$bodytag>$basefont_tag<center>
		<h3>Problem with Registration</h3></center>
		<hr><form method="post" action=$main_script>$form_tags
		<blockquote><b>Sorry, you need to enter a valid value for every field.</b>
		</blockquote><center>
		<input type="submit" name="auth_register_screen_op" value="Return to Registration Screen">
		</center></form></body></html>!;
}
1;
