#! /srvtools/http/bin/perl
#############################################################################
#  
#   File:          PreviewMessage.pl
#
#   Author:        Jungmin Kim and Paul Coddington (paulc@npac.syr.edu)
#
#   Created:       03/05/95
#   Modified:      
#   Version: 
#
#   Input:         path name, file name,
#                  title, message (current message)
#                  hidden date, hidden name, hidden title, hidden message
#                  (message to be responded)
#                  user information
#   Output:        HTML text
#          
#
#   Description:   Print out the message entered to preview the message 
#                  before post it. both of current message and the 
#                  message to be responded are passed to main function
#               
#   Usage:         "http://.../Action.pl/preview:path:file:user"
#                  user should be "username:email_address".
#
#
#############################################################################

require "GetDate.pl";

sub PreviewMessage{
    local($path, $file, $title, $message, 
	  $hdate, $hname,  $htitle, $hmessage, $method, $user,
	  $initial, $hdate2, $hname2, $htitle2, $hmessage2,
	  $subdir) = @_;

    local ($temp, $temp2, $tmpuser, $html_message, $html_title, $date);

    $temp = $htitle;		# original title of message to be responded
    $temp =~ s/\<P\>/ /ig;
    $temp =~ s/\<BR\>/ /ig;
    $temp2 = $htitle2;		
    $temp2 =~ s/\<P\>/ /ig;
    $temp2 =~ s/\<BR\>/ /ig;

    #### save message and title to modify them
    $html_message = $message;
    $html_title = $title;

    #### replace HTML reserved characters
    $htitle =~ s/&/&amp;/g;
    $htitle =~ s/>/&gt;/g;
    $htitle =~ s/</&lt;/g;
    $htitle =~ s/\"/&quot;/g;
    $hmessage =~ s/&/&amp;/g;
    $hmessage =~ s/>/&gt;/g;
    $hmessage =~ s/</&lt;/g;
    $hmessage =~ s/\"/&quot;/g;
    $htitle2 =~ s/&/&amp;/g;
    $htitle2 =~ s/>/&gt;/g;
    $htitle2 =~ s/</&lt;/g;
    $htitle2 =~ s/\"/&quot;/g;
    $hmessage2 =~ s/&/&amp;/g;
    $hmessage2 =~ s/>/&gt;/g;
    $hmessage2 =~ s/</&lt;/g;
    $hmessage2 =~ s/\"/&quot;/g;
    $title =~ s/&/&amp;/g;
    $title =~ s/>/&gt;/g;
    $title =~ s/</&lt;/g;
    $title =~ s/\"/&quot;/g;
    $title =~ s/&/&amp;/g;
    $message =~ s/&/&amp;/g;
    $message =~ s/>/&gt;/g;
    $message =~ s/</&lt;/g;
    $message =~ s/\"/&quot;/g;
    $message =~ s/&/&amp;/g;
    
    $tmpuser = $user;
    $tmpuser =~ s/\+/ /g;
    ($username, $userid) = split(/\:/, $tmpuser);

    # *******************************************************************

    $pathname = $conference{$path};

    print "Content-type\: text/html\n\n";
    print "\n";
    print "<TITLE> Preview Message </TITLE>\n";
    # print "<H3> Preview your message \n";
    # print "to $pathname forum</H3>\n";
   
    # print "<HR>\n";
    print "<P>\n";

    print "<FORM METHOD=\"POST\" ";
    print "ACTION=\"$action\/$subdir\:postit\:$path\:$file\:$user\">\n";
    print "<FONT SIZE=\"+1\"><B>Choose one of the following\:</B></FONT>\n";
    print "<BR>\n";
    print "<INPUT TYPE=\"radio\" NAME=\"edit\" VALUE=\"no\" CHECKED>\n";
    print "<B>Post the message</B><BR>\n";
    print "<INPUT TYPE=\"radio\" NAME=\"edit\" VALUE=\"yes\">\n";
    print "<B>Edit the message</B><BR>\n";
    print "or\n";
    print "<B><A HREF=\"$action\/$subdir\:read\:$path\:$file\:$user#$file\">\n";
    print "Cancel</A> this post and return to the forum</B>\n";
    print "<P>\n";

    print "<B>\n";
    print "Then click on the \n";
    print "<INPUT TYPE=\"submit\" VALUE=\"SUBMIT\">\n";
    print "button to post or edit your message. \n";
    print "</B>\n";
    print "<P>\n";

    print "<HR>\n";

    if($method eq "comment") {
        print "<B>You are commenting on response\:</B> $file. $temp";
    }
    elsif($method eq "response") {
	if ($temp2) {  # Clicked on a response
          print "<B>You are responding to the topic\:</B> $initial. $temp2";
	}
	else { # CLicked on a topic
          print "<B>You are responding to the topic\:</B> $file. $temp";
	}
    }
    else {
	print "<B>You are creating a new topic.</B>\n";
    }

    #### replace all double CR and LF characters with <P>
    $html_title =~ s/(\r\n\r\n|\n\n|\r\r)/\<P\>\n/g;
    $html_message =~ s/(\r\n\r\n|\n\n|\r\r)/\<P\>\n/g;

    # ***************************************************** modified
    print "<BR>\n";
    print "<B> Your message is: </B><BR>\n";

        ### Print the header
	print "<HR>\n";
	# print "<BR>";
	print "<B>";
        # Number of this post.
	# print "$next\: "; #??
	print "$html_title\n";
	print "</B>";
	print "<FONT SIZE=\"-1\">";
        if ($userid) { # If there is an email address
	   print "from <A HREF=\"mailto:$userid\">$username</A>\n";
        }
        else {
	   print "from $username \n";
        }
	$date = &GetDate(0);
	print "on $date.\n";
	print "</FONT>";
	print "<P>\n";

	#### Print the message
	print $oldm;
        print "$html_message \n";
	print "<BR><HR>\n";
    
    # **************************************************************

    #### hidden fields
    print "<INPUT TYPE=\"hidden\" NAME=\"hdate\" VALUE=\"$hdate\">\n";
    print "<INPUT TYPE=\"hidden\" NAME=\"hname\" VALUE=\"$hname\">\n";
    print "<INPUT TYPE=\"hidden\" NAME=\"htitle\" VALUE=\"$htitle\">\n";
    print "<INPUT TYPE=\"hidden\" NAME=\"hmessage\" VALUE=\"$hmessage\">\n";
    print "<INPUT TYPE=\"hidden\" NAME=\"hdate2\" VALUE=\"$hdate2\">\n";
    print "<INPUT TYPE=\"hidden\" NAME=\"hname2\" VALUE=\"$hname2\">\n";
    print "<INPUT TYPE=\"hidden\" NAME=\"htitle2\" VALUE=\"$htitle2\">\n";
    print "<INPUT TYPE=\"hidden\" NAME=\"hmessage2\" VALUE=\"$hmessage2\">\n";
    print "<INPUT TYPE=\"hidden\" NAME=\"initial\" VALUE=\"$initial\">\n";
    print "<INPUT TYPE=\"hidden\" NAME=\"title\" VALUE=\"$title\">\n";
    print "<INPUT TYPE=\"hidden\" NAME=\"message\" VALUE=\"$message\">\n";
    print "<INPUT TYPE=\"hidden\" NAME=\"method\" VALUE=\"$method\">\n";
    
    print "</FORM>\n";

    # print "<P><HR><p>\n";

}
1;

