// <--- Common Functions --->
// Function handles missing required fields
function output_missing ($aryMissing) {
// Print out html
include($GLOBALS["incHeader"]);
include($GLOBALS["incMissing"]);
echo "Fehler im Formular:
\n";
for ($p = 0 ; $p < count($aryMissing) ; $p++) {
echo "".$aryMissing[$p]."
\n";
} // endwhile
echo "
Bitte geh zurück und berichtige die oben genanten Fehler.
";
include($GLOBALS["incFooter"]);
} // endfunc
// Function handles bad address
function output_bad_address ($address) {
// Print out html
include($GLOBALS["incHeader"]);
include($GLOBALS["incBadEmail"]);
echo "Fehlerhafte Mailadresse: ".$address."\n";
echo "Bitte gehe zurück und berichtige Die Mail Adresse.
";
include($GLOBALS["incFooter"]);
} // endfunc
// Function handles opening screen
function output_welcome ($selfname) {
// Print out html
include($GLOBALS["incHeader"]);
include($GLOBALS["incWelcome"]);
echo "\n";
include($GLOBALS["incFooter"]);
} // endfunc
// Function handles thanks screen
function output_thanks ($selfname, $again = 0, $text = "Please Submit Again
") {
// Print out html
include($GLOBALS["incHeader"]);
include($GLOBALS["incThanks"]);
if ( $again ) {
echo $text;
echo "\n";
} else // endif
include($GLOBALS["incFooter"]);
} // endfunc
// Function sets unset or blank variables
// to their configuration defaults
function default_ifempty ($key,$value) {
if (empty ($value)) {
// determine the corresponding default name for KEY
$defname = "def".ucfirst(strtolower($key));
if (!empty ($GLOBALS["$defname"])) {
$value = $GLOBALS["$defname"];
} // endif
} // endif
return $value;
} // endfunc
// Function does a simple check for a valid email address format
function bad_address ($email) {
if (!eregi("^[^@[:space:]]+@([[:alnum:]\-]+\.)+[[:alnum:]][[:alnum:]][[:alnum:]]?$", $email)) {
return 1;
} else {
return 0;
} // endif
} // endfunc
// Function checks for existence of required fields
function check_required ($strRequired,&$aryMissing) {
// Set up for return counter
$j = 0;
// Check for empty required
if (!empty ($strRequired)) {
// Create array for required fields
$aryRequired = explode(",", $strRequired);
// Traverse array for required fields
for ($i=0 ; $i < count($aryRequired) ; $i++) {
// Test if a required field is missing
$curr_field = $aryRequired[$i];
$glob_field = $_POST[$curr_field];
if (empty($glob_field)) {
$aryMissing[$j] = $aryRequired[$i];
$j++;
} // endif
} // endfor
} // endif
return $j;
} // endfunc
// Function replaces variables into templates
function build_body ($bbody = "") {
reset($_POST);
if (!empty($bbody)) {
// Fill in variables into the template
while (list($header, $value) = each($_POST)) {
$bbody = ereg_replace("%".$header."%", $value, $bbody);
} // endwhile
} else {
// Simply add variables line by line
$bbody = "";
sort($_POST);
while (list($header, $value) = each($_POST)) {
$bbody = $bbody."\n$header: $value";
} // endwhile
} // endif
return $bbody;
} // endfunc
// Function sends mail to user
function send_mail ($to, $email, $subject, $body, $extras) {
// Build extra headers
$headers = "From:".$email."\n";
if (! empty ($extras)) {
$headers = $headers.$extras;
} // endfrom
// Send mail
mail ( $to, stripslashes($subject), stripslashes($body), $headers);
} // endfunc
// Function formats mail headers and sends mail(s).
function mail_it () {
global $to, $subject, $email, $autoemail, $autosubject,
$sendextras, $autoextras, $template, $autoreply,
$autoprefix ;
$subject = addslashes ($subject);
$autosubject = addslashes ($autosubject);
$template = addslashes ($template);
$autoreply = addslashes ($autoreply);
// Send the message.
if (!empty ($template)) {
$mainbody = build_body ($template);
} else {
$mainbody = build_body ();
}
if (!empty ($to)) {
send_mail ($to, $_POST['email'], $subject, $mainbody, $sendextras);
}
// Send the autoreply.
if ( (!empty($autoreply)) and (!bad_address($_POST['email'])) ) {
$autobody = build_body ($autoreply);
$autoto = $_POST['email'];
if (empty($autosubject)) {
if (!empty ($autoprefix)) {
$autosubject = $autoprefix.$subject;
} else {
$autosubject = "Auto-Reply: ".$subject;
} // endif
}
if (!empty ($autoemail)) {
$autofrom = $autoemail;
} else {
$autofrom = $to;
}
send_mail ($autoto, $autofrom, $autosubject, $autobody, $autoextras);
} // endif (auto reply)
return $mainbody;
} // endfunc
// Function logs the email to a table
function log_it ($email, $subject, $body) {
// Set up access to needed global values
global $db_hostname, $db_user, $db_password, $db_database, $db_table, $logbodies, $debug;
// Open a connection to the DBMS
$lnk = mysql_connect($db_hostname,$db_user,$db_password);
// Log mail to database
if ($lnk) {
$host = getenv("REMOTE_HOST");
$host ? "" : $host = gethostbyaddr(getenv($REMOTE_ADDR));
if ($logbodies) {
$db_query = "INSERT INTO ".$db_table." (t_stamp,host,recipient,subject,body) VALUES (null,'$host','$email','$subject','$body')";
} else {
$db_query = "INSERT INTO ".$db_table." (t_stamp,host,recipient,subject) VALUES (null,'$host','$email','$subject')";
} // endif
$result = mysql_db_query ($db_database,$db_query,$lnk);
if ((!($result)) && ($debug == 1)) {
echo mysql_errno().": ".mysql_error();
echo "
".$db_query."
";
}
} else {
if ($debug == 1) {
echo mysql_errno().": ".mysql_error();
}
} // endif
return $result;
} // endfunc
?>