<?php
include( 'menu.inc' );
include( 'func.inc' );

$t = getmsg( 20, $lang );
if( empty( $xid )){
	if( !head( $t[1], '', $xid, $xpar )) exit;
	echo "<font $_fontbulk>\n";
	echo "<p>$t[2]</p>\n";
	eval( "\$x = \"$t[3]\";" );
	echo "<p>".add_xid( $x, $xid )."</p>\n";
	foot();
	exit;
}

if( !$id = mysql_query( "select xfn, xln, xem from session where x_id = $xid" )) {
	echo "Error 1: ".mysql_errno().": ".mysql_error();
	exit;
};
if( $row = mysql_fetch_array( $id )) {
	$name = $row[ 'xfn' ].' '.$row[ 'xln' ];
	$em = "\"$name\" <".$row[ 'xem' ].">";
}

if( !$id = mysql_query( " select title, titlabb, link from metatext
	where proj_id = $pid and status = 'act'" )) {
	echo "Error 2: ".mysql_errno().": ".mysql_error();
	exit;
};

if( !$row = mysql_fetch_array( $id )) {
	echo "Error 3: no_rows_selected";
	exit;
}
$ti = $row[ "title" ];
$ta = $row[ "titlabb" ];
$lnk = lnkxid( $row[ 'link' ], $xid );

eval( "\$x = \"$t[0]\";" );
if( !head( $x, '', $xid, $xpar )) exit;
echo "<font $_fontbulk>\n";

$mid = $xpar[ 'mid' ];
if( $action == 'send' ){
	echo "<p>$t[4]</p>\n<p><a href='$lnk'><b>$t[5]</b></a></p></font>\n";
} else {
	eval( "\$x = \"$t[6]\";" );
	echo "<p>$x</p>\n";
}

if( !$id = mysql_query( " select subj, text, ctext
	from par_mail where proj_id = $pid and memb_id = $mid" )) {
	echo "Error 4: ".mysql_errno().": ".mysql_error();
	exit;
};

if(( $i = mysql_num_rows( $id )) == 0 ){
	eval( "\$x = \"$t[7]\";" );
	echo "<p>$x</p>\n<p><a href='$lnk'><b>$t[5]</b></a></p></font>\n";
	foot();
	exit;
}

$lst = strtolower( $ta )."@$domain";
$hdr = "From: $em\nReply-To: $lst\n";
while( $row = mysql_fetch_array( $id )) {
	$txt .= "\n".$row[ "text" ].$row[ "ctext" ]."\n";
	$chd = eregi_replace( "\"", "&quot;", $row[ "subj" ]);
}

if( $i > 1 ) eval( "\$chd = \"$t[8]\";" );

if( $action == 'send' ){
	if( empty( $hd )) $hd = $chd;
	$hd = trim( stripslashes( strip_tags( $hd )));
	mail( $lst, $hd, $txt, $hdr );
	if( !mysql_query( "delete from par_mail
		where proj_id = $pid and memb_id = $mid" )){
		echo "Error 5: ".mysql_errno().": ".mysql_error();
		exit;
	}
}
else {
	echo "<form action='$PHP_SELF?xid=$xid&pid=$pid' method='post'>\n";
	echo "<center><input type='submit' value='$t[9]'><br><br>\n";
	echo "<input type='hidden' name='action' value='send'>\n";
	echo "<table bgcolor='#FFFFFF'><tr><td><font face='courier new' size=3>\n";
	echo "<font size=2>$t[10]: </font>";
	echo "<input type='text' name='hd' value=\"$chd\" size=60>\n";
	echo "<pre>$hdr$txt</pre></font></td></tr></table></center></form>\n</font>\n";
}
foot();
?>
