#!/usr/bin/perl -w

##
## WRITE_MESSAGE
##
## Warren Sack
## February 2005
##
##

use CGI;

##
## load_params
##
sub load_params
{
    my(@params) = @_;
    my($param,$param_value);
    foreach $param (@params) {
	$param_value = $request->param(lc($param));
	if (not($param_value)) { $param_value = $request->param(uc($param)); }
	if ($param_value) { 
	    $params{lc($param)} = $param_value;
	}
    }
    if ( defined($params{'subject'}) ) {
	$params{'subject'} = 'RE: '.$params{'subject'};	
    }
    foreach $param (keys %params) {
	$param_value = $params{$param};
	$hidden_params .= '<INPUT TYPE="hidden" NAME="'.lc($param).'" VALUE="'.$param_value.'">'."\n";
    }
}


$request = new CGI;
$hidden_params = '';
%params = ();
## read parameters
&load_params('url','cgi_url','archive','smid','id','subject','news_group','language_locale');



##
## create_write_message_page
##
sub create_write_message_page
{
    my($html,$previous_field,$title,$email_address,$send_message,$subject);

    if ( defined($params{'id'}) ) {
	$previous_field = '<TR align="left">
			<TD class=headerfieldtext><B>PREVIOUS:&nbsp;</B></TD>
			<TD class=headertext><A href="http://'.$params{'url'}.'/Agonistics/'.$params{'archive'}.'/Interface/Messages/'.$params{'smid'}.'.html">&#91;'.$params{'smid'}.'&#93; </A>'.$params{'id'}.'</TD>
		</TR>';
    }
    else { $previous_field = ''; }
    print "Content-Type: text/html; charset=utf-8\n\n";
    ## write (and then print) the html for a message form to be filled 
    ## out by the sender of a message
    if ( $params{'language_locale'} =~ /^EN/ ) { 
	$title = "write message"; 
	$send_message = 'SEND MESSAGE';
	if ( $params{'subject'} ) { $subject = $params{'subject'}; }
	else {
	    $subject = '<INPUT class=formstyle name="subject" value="type the subject here">';
	}
	$email_address = 'your email address';
	$message_text = 'type your message here';
    }
    elsif ( $params{'language_locale'} =~ /^FR/ ) { 
	$title = "&eacute;crire un message"; 
	$send_message = 'ENVOYER';
	if ( $params{'subject'} ) { $subject = $params{'subject'}; }
	else {
	    $subject = '<INPUT class=formstyle name="subject" value="le sujet du message">';
	}
	$email_address = 'votre adresse';
	$message_text = 'votre message ici';	
    }
    elsif ( $params{'language_locale'} =~ /^DE/ ) { 
	$title = 'nachricht schreiben';
	$send_message = 'SENDEN';
	if ( $params{'subject'} ) { $subject = $params{'subject'}; }
	else {
	    $subject = '<INPUT class=formstyle name="subject" value="das Thema einer Nachrichten">';
	}
	$email_address = 'Ihre email Adresse';
	$message_text = 'der Text der Nachricht';
    }

    $html = '<HTML>

    <HEAD>

         <META HTTP-EQUIV="Content-Type" content="text/html; charset=utf-8">

        <TITLE>agonistics / '.$title.'</TITLE>

        <LINK type="text/css" rel="stylesheet" href="http://'.$params{'url'}.'/Agonistics/'.$params{'archive'}.'/Interface/Messages/message_style.css">
       

    </HEAD>

    <BODY>
    
        <SCRIPT>window.resizeTo((screen.availWidth/2),(screen.availHeight/2));</SCRIPT>

        <TABLE>


     <FORM METHOD="POST" ACTION="http://'.$params{'cgi_url'}.'/Agonistics/send_message.pl?'.$params.'" ENCTYPE="multipart/form-data">

           '.$hidden_params.'

            <TBODY>

		<TR align="left">
			<TD class=headerfieldtext><B>SUBJECT:&nbsp;</B></TD>
			<TD class=headertext>'.$subject.'</TD>
		</TR>
		<TR align="left">
			<TD class=headerfieldtext><B>SENDER:&nbsp;</B></TD>
                        <TD class=headertext>
                           <INPUT class=formstyle name="sender" value="'.$email_address.'">
                        </TD>
		</TR>
		<TR align="left">
			<TD class=headerfieldtext><B>NEWSGROUPS:&nbsp;</B></TD>
			<TD class=headertext>'.$params{'news_group'}.'</TD>
		</TR>
		<TR align="left">
			<TD class=headerfieldtext><B>DATE:&nbsp;</B></TD>
			<TD class=headertext>'.gmtime.'</TD>
		</TR>'
                .$previous_field.'

                <TR align="left">             
                        <TD class=headerfieldtext>
		           <INPUT name="send_message" class=buttonstyle type="SUBMIT" value="'.$send_message.'">
		        </TD>
                        <TD>&nbsp;</TD>
                </TR>

                <TR align="left">
                        <TD class=text colspan="2">
                           <TEXTAREA class=messagebodyinputstyle rows=10 cols=35 name="message_body">'.$message_text.'</TEXTAREA>
                        </TD>
                </TR>


          </TBODY>
	 </TABLE>

       </FORM>
    </BODY>

    </HTML>';
    print $html;
}

&create_write_message_page();
