<HTML><BODY>
<?php
$to = "";
$res = "";
echo("<H1>Sending HTML form</H1>");
$res = "Calling from " . getenv("REMOTE_ADDR") . "\n"; /* $res: the message that will be sent by email
we want to keep the user's IP address*/
$first = TRUE; /* first data printed */
$comm_form = FALSE; /* the form is a command form */
$total = 0; /*if form is a command form, total of the order */
$currency = "currency";
/* parsing the results of the form. We don't know how many fields will be sent and the
field's names, except 4 hidden fields */
while ( list( $key, $val ) = each( $HTTP_POST_VARS ) ) {
/* detects the field form_id that will be used as subject of the mail */
if ( strcmp( strtoupper($key) , "FORM_ID") == 0 ) {
$subj = stripslashes($val);
}
/*detects the email address */
elseif ( strcmp( strtoupper($key) , "MAIL_FORM_TO") ==0 ) {
$to = stripslashes($val);
}
elseif ( strcmp( strtoupper($key) , "CURRENCY") ==0 ) {
$currency = stripslashes($val);
}
/* detects a command form and sets the flag on */
elseif ( (strcmp( strtoupper($key) , "COMM_FORM") ==0) & (strcmp( strtoupper($val) , "YES") ==0) )
$comm_form = TRUE;
else {
// if first field, then print a table header
if ($first) {
echo("<TABLE>");
$first = FALSE;
}
//strip slashes in the fields
$key = stripslashes($key);
$val = stripslashes($val);
if ($comm_form) {
// detecting an Item . Bug of strpos if you search an item at the beginning of the field
if ( is_int (strpos( strtoupper($key) , "QT_")) ) {
// if quantity > 0 then continue
if ($val <> "0") {
// keepin item number
$item = substr($key, 3);
$qt = (int) $val;
$line = "<TR><TD> $val x</TD><TD>Item $item </TD>";
$res = $res . "\n" . $val . " x\tItem " . $item;
// extracting next field
list( $key, $val ) = each( $HTTP_POST_VARS );
// verify if this is the expected field
//$pos = strpos( strtoupper($key) , "NR_");
if ( is_int (strpos( strtoupper($key) , "NR_"))) {
// keepin item number
$key = substr($key, 3);
if ($key != $item) {
//error
echo("<TD>Item nr different in QT_ and NR_<TD></TR>");
$res = $res . "Item nr different in QT_ and NR_";
}
else {
$price = (int) $val;
$sum = $qt * $val;
$total = $total + $sum;
$line = $line . "<TD>at $currency $price </TD><TD>= $currency $sum </TD></TR>";
echo($line);
$res = $res . "\t at " . $currency . " " . $val . "\t= " . $currency . " " . $sum;
}
}
}
else //jumping next field
{
list( $key, $val ) = each( $HTTP_POST_VARS );
}
}
else {
echo("<TR><TD> $key </TD><TD></TD><TD></TD><TD> $val </TD></TR>");
$res = $res . "\n" . $key . "\t\t" . $val;
}
}
else {
echo("<TR><TD> $key </TD><TD></TD><TD></TD><TD> $val </TD></TR>");
$res = $res . "\n" . $key . "\t\t" . $val;
}
}
}
if (!$first)
echo("</TABLE>");
if ($total > 0) {
echo("<H4>Total sum : $currency $total . Notice that postage cost may be charged!</H4>");
$res = $res . "\n\nTotal sum : " . $currency . " " . $total;
}
if ( strlen($to) == 0 )
echo("<H1>Error</h1><P>No email adress in hidden field MAIL_FORM_TO</P><P>Please inform the webmaster!</p>");
else {
echo("<P>This message has been sent to: <A HREF=\"mailto:");
echo($to);
echo("\">");
echo($to);
echo("</A></P>");
mail("$to", "$subj", "$res", "From: $to");
}
?>
</BODY>
</HTML>