Приглашаем посетить
Фет (fet.lit-info.ru)

CHAT-HTML

###########################################################
#                   CHAT-HTML.PL
#
# This script was written by Gunther Birznieks.
# Date Created: 4-18-96
#
#   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.
#
# Purpose:
#   Prints out the various HTML screens for the Chat
#   Script
# 
#############################################################


############################################################
#
# subroutine: PrintChatEntrance
#
# This routine prints the first chat screen people see.
# It includes an error message when it is printed again
# if not all the required information is entered 
# correctly.
#
############################################################


sub PrintChatEntrance {
local($setup,$chat_error) = @_;
local ($chat_room_options);

$setup = "" if ($setup eq "chat");

# 
# The chat room options
# are derived from the 
# available chat rooms in the
# array of chat rooms in the
# chat.setup script
$chat_room_options = "";
for (0..@chat_rooms - 1) {
$chat_room_options .=
  "<OPTION VALUE=$chat_room_variable[$_]>" .
  "$chat_rooms[$_]\n";
}

if ($chat_room_options eq "") {
    $chat_room_options = 
        "<OPTION>Chat Room Not Set Up\n";
}

print <<__END_OF_ENTRANCE__;
<HTML>
<HEAD>
<TITLE>Chat Page</TITLE>
</HEAD>
<BODY>
<H1>Welcome To The Chat Page</H1>
<H2>$chat_error</H2>
<FORM METHOD=POST ACTION=chat.cgi>
<INPUT TYPE=HIDDEN NAME=setup VALUE=$setup>
<HR>
<STRONG>Enter Information Below:</STRONG><p>

<TABLE BORDER=1>
<TR>
<TD ALIGHT=RIGHT>User Name:</TD>
<TD><INPUT NAME=chat_username></TD>
</TR>
<TR>
<TD ALIGHT=RIGHT>Your Email Address(*):</TD>
<TD><INPUT NAME=chat_email></TD>
</TR>
<TR>
<TD ALIGHT=RIGHT>Your Home Page (*):</TD>
<TD><INPUT NAME=chat_http></TD>
</TR>
<TR>
<TD ALIGHT=RIGHT>How Many Old Messages To Display:</TD>
<TD><INPUT NAME=how_many_old VALUE="10"></TD>
</TR>
<TR>
<TD ALIGHT=RIGHT>Automatic Refresh Rate (Seconds):</TD>
<TD><INPUT NAME=refresh_rate VALUE="0"></TD>
</TR>
<TR>
<TD ALIGHT=RIGHT>Use Frames?:</TD>
<TD><INPUT TYPE=checkbox NAME=frames></TD>
</TR>
<TR>
<TD ALIGHT=RIGHT>Chat Room</TD>
<TD><SELECT NAME=chat_room>
$chat_room_options
</SELECT>
</TD>
</TR>
</TABLE>
<P>
<INPUT TYPE=SUBMIT NAME=enter_chat
VALUE="Enter The Chat Room">

<P>
<STRONG>Special Notes:</STRONG><P>
(*) Indicates Optional Information<P>
Choose <STRONG>how many old messages</STRONG> to display if you want to
display some older messages along with the new ones whenever you refresh
the chat message list.
<P>
Additionally, if you use Netscape 2.0 or another browser that supports
the HTML <STRONG>Refresh</STRONG> tag, then you can state the number of
seconds you want to pass before the chat message list is automatically
refreshed for you. This lets you display new messages automatically.
<P>
If you are using Netscape 2.0 or another browser that supports
<STRONG>Frames</STRONG>, it is highly suggested that you turn frames ON.
This allows the messages to be displayed in one frame, while you submit
your own chat messages in another one on the same screen.

 <HR> 
</FORM>
</BODY>
</HTML>
__END_OF_ENTRANCE__


} # end of PrintChatEntrance


############################################################
#
# subroutine: PrintChatScreen
#
# Prints the main chat screen.  This includes the form
# for chatting.
#
# Parameters:
#   $chat_buffer = all the chat messages
#   $refresh-rate = refresh rate for use with the META
#                   operator
#   $session = session id
#   $chat_room = chat room name
#   $setup = setup file.
#   $frames = "on" for Printing Main Frame HTML
#   $fmsgs = "on" for printing Messages Frame
#   $fsubmit = "on" for printing chat Messages Frame
#
############################################################

sub PrintChatScreen {
local($chat_buffer, 
      $refresh_rate, $session,
      $chat_room, $setup,
      $frames, $fmsgs, $fsubmit) = @_;

local($chat_message_header, $more_url,
      $more_hidden, $chat_refresh);

$setup = "" if ($setup eq "chat");

#
# $more_url contains setup information
# that needs to get passed from screen to
# screen and is used with the META Tag.
#
# $more_hidden is the same thing but is
# used as a hidden variable in the form
# posted below.
#
$more_url = "";
$more_hidden = "";
if ($setup ne "") {
    $more_url = "&setup=$setup";
    $more_hidden = "<INPUT TYPE=HIDDEN NAME=setup " .
                   "VALUE=$setup>";
}
$more_url = "session=$session" . 
               "&chat_room=$chat_room" .
		$more_url;


# When we generate a meta tag, we need to
# make sure the hidden variables get passed to
# the URL since we can not post using the
# META operator
#
if ($refresh_rate > 0) {
    $chat_refresh =
      qq!<META HTTP-EQUIV="Refresh" ! .
      qq!CONTENT="$refresh_rate; ! .
      qq!URL=chat.cgi?$more_url!;

    if ($frames ne "on" && $fmsgs eq "on") {
        $chat_refresh .= "&fmsgs=on";
    }
    $chat_refresh .= qq!">!;
} else {
    $chat_refresh = "";
}


if ($frames ne "on" && $fsubmit eq "on") {
    $chat_refresh = "";
}

if ($frames eq "on") {
    print <<__END_OF_MAIN_FRAME__;
<HTML>
<HEAD>
<TITLE>$chat_room_name</TITLE>
</HEAD>

<FRAMESET ROWS="*,210">
   <FRAME NAME="_fmsgs" SRC=chat.cgi?fmsgs=on&$more_url>
   <FRAME NAME="_fsubmit" SRC=chat.cgi?fsubmit=on&$more_url>
</FRAMESET>
</HTML>
__END_OF_MAIN_FRAME__
}

if ($frames ne "on") {
print <<__END_OF_HTML_HEADER__;
<HTML>
$chat_refresh
<HEAD>
<TITLE>$chat_room_name</TITLE>
</HEAD>
<BODY>
__END_OF_HTML_HEADER__
}

if ($fsubmit eq "on") {

$form_header = <<__END_FORM_HDR__;
<FORM METHOD=POST ACTION=chat.cgi TARGET="_fmsgs">
__END_FORM_HDR__
} else {
$form_header = <<__END_FORM_HDR__;
<FORM METHOD=POST ACTION=chat.cgi>
__END_FORM_HDR__
}



if ($fsubmit eq "on") {
    $form_header .= qq!<INPUT TYPE=HIDDEN NAME=fmsgs! .
                    qq! VALUE=on>!;
}

if ($fmsgs eq "on") {
    $form_header = "";
}

$chat_message_header = "";
if ($fmsgs ne "on") {
    $chat_message_header = "<H2>Chat Messages:</H2>";
}

if (($frames ne "on" &&
     $fsubmit ne "on") ||
    $fmsgs eq "on") {
    print <<__END_OF_CHAT_HEADER__;
<H1>Welcome To $chat_room_name Chat</H1>
__END_OF_CHAT_HEADER__
}

#
# SUBMIT CHAT FORM
#

    if ($fsubmit eq "on" ||
        ($frames ne "on" && $fmsgs ne "on")) {
	print <<__END_OF_CHAT_SUBMIT__;
$form_header

<INPUT TYPE=HIDDEN NAME=session VALUE=$session>
<INPUT TYPE=HIDDEN NAME=chat_room VALUE=$chat_room>
$more_hidden
<STRONG>Enter Chat Message Below:</STRONG>
<BR>
<TEXTAREA NAME=chat_message
ROWS=3 COLS=40 WRAP=physical></TEXTAREA>
<BR>
Which User To Send To:
<INPUT TYPE=TEXT NAME=chat_to_user
VALUE="ALL">
<BR>
<INPUT TYPE=SUBMIT NAME=submit_message
VALUE="Send Message">
<INPUT TYPE=SUBMIT NAME=refresh_chat
VALUE="New Messages">
<INPUT TYPE=SUBMIT NAME=logoff
VALUE="Log Off">
<INPUT TYPE=SUBMIT NAME=occupants
VALUE="View Occupants">
<INPUT TYPE=RESET
VALUE="Clear Form">
</FORM>
__END_OF_CHAT_SUBMIT__

if ($fsubmit ne "on") {
    print "<HR>\n";
}
}


if (($frames ne "on" &&
     $fsubmit ne "on") ||
    $fmsgs eq "on") {
    print <<__END_OF_CHAT_MSGS__;
$chat_message_header
$chat_buffer
__END_OF_CHAT_MSGS__

if ($fmsgs ne "on") {
    print "<HR>\n";
}
}


    if ($frames ne "on") {
	print <<__END_OF_CHAT_FOOTER__;
</BODY>
</HTML>
__END_OF_CHAT_FOOTER__
}


} # end of PrintChatScreen

############################################################
#
# subroutine: PrintChatError
#
# This routine outputs an error page if something
# happened incorrectly in the chat room.
#
############################################################

sub PrintChatError {
local($error) = @_;

print <<__END_OF_ERROR__;
<HTML><HEAD>
<TITLE>Problem In Chat Occurred</TITLE>
</HEAD>
<BODY>
<h1>Problem In Chat Occurred</h1>
<HR>
<blockquote>
$error
</blockquote>
<HR>
</BODY></HTML>
__END_OF_ERROR__

} # End of PrintChatError

# We also have to end the required library
# with a function call of 1 
1;