Web Mailer

$val) {
$data[$key] = $a[$key];
}
return $data;
}

function xmlentities($string) {
return str_replace ( array(‘&’, ‘”‘, “‘”, ‘<', '>‘), array(‘&’, ‘"’, ‘'’, ‘<‘, ‘>’), $string);
}

$t = date(“U”);

$formhomedir = preg_replace(‘/.*\/home\/content/’,”,$_SERVER[‘DOCUMENT_ROOT’]);
$formhomedir = explode(‘/’,$formhomedir);
$formhome=”/home/content”.$formhomedir[0].”/”.$formhomedir[1].”/”.$formhomedir[2].”/”.$formhomedir[3].”/”.$formhomedir[4].”/data/”;

$file_order = “.default”;
$file_format = “.text”;
$file_interval = “.15m”;
$field_order = “”;

if (isset($query_vars[‘form_order’])) {
if ($query_vars[‘form_order’] != “alpha”) {
$field_order=$query_vars[‘form_order’];
$file_order=”.custom”;
$query_vars = customsort($query_vars,$field_order);
}
else {
switch ($query_vars[‘form_order’]) {
case “alpha”:
uksort($query_vars,’strnatcasecmp’);
$file_order=”.alpha”;
break;
default:
$file_order=”.default”;
break;
}
}
}

if (isset($query_vars[‘form_format’])) {
switch ($query_vars[‘form_format’]) {
case “csv”:
$file_format = “.csv”;
break;
case “html”:
$file_format = “.html”;
break;
case “xml”:
$file_format = “.xml”;
break;
case “text”:
case “default”:
default:
$file_format = “.text”;
break;
}
}

if (isset($query_vars[‘form_delivery’])) {
switch ($query_vars[‘form_delivery’]) {
case “hourly”:
$file_interval = “.60m”;
break;
case “hourly_digest”:
$file_interval = “.60mc”;
break;
case “daily”:
$file_interval = “.24h”;
break;
case “daily_digest”:
$file_interval = “.24hc”;
break;
case “digest”:
$file_interval = “.15mc”;
break;
case “default”:
default:
$file_interval = “.15m”;
break;
}
}

$file = $formhome.”form_”.$t.$file_order.$file_format.$file_interval;
$fp = fopen($file,”w”);

switch ($file_format) {
case “.csv”:
$csvkeys = “”;
$csvvals= “”;
$firsttime = “”;
while (list ($key, $val) = each ($query_vars)) {
if ( ($key == “form_order”) ||
($key == “form_format”) ||
($key == “form_delivery”) ||
($key == “redirect”) ) {
}
else {
if ($csvkeys != “”) {
$firsttime=”,”;
}
$tmpkey=escapeshellcmd($key);
$csvkeys = $csvkeys.$firsttime.”‘”.$tmpkey.”‘”;
$tmpval=escapeshellcmd($val);
$csvvals = $csvvals.$firsttime.”‘”.$tmpval.”‘”;
}
}
fputs($fp,”$csvkeys\n”);
fputs($fp,”$csvvals\n”);
break;
case “.html”:
fputs($fp,”

\n”);
break;
case “.xml”:
fputs($fp,”

\n”);
break;
}

while (list ($key, $val) = each ($query_vars)) {
if ($key == “redirect”) {
$landing_page = $val;
}
if ( ($key == “form_order”) ||
($key == “form_format”) ||
($key == “form_delivery”) ||
($key == “redirect”) ) {

}
else {
switch ($file_format) {
case “.html”:
fputs($fp,”\t

\n”);
fputs($fp,”\t\t

\n”);
fputs($fp,”\t\t

\n”);
fputs($fp,”\t

\n”);

break;
case “.csv”:
// content is already output
break;
case “.xml”:
fputs($fp,”\t\n”);
fputs($fp,”\t\t“.xmlentities($key).”\n”);
fputs($fp,”\t\t“.xmlentities($val).”\n”);
fputs($fp,”\t
\n”);
break;
case “.text”:
default:
fputs($fp,$key.”: “.$val.”\n”);
break;
}
}
}

switch ($file_format) {
case “.html”:
fputs($fp,”

$key $val

\n”);
break;
case “.xml”:
fputs($fp,”

\n”);
break;
}

fclose($fp);

if ($landing_page != “”) {
header(“Location: http://”.$_SERVER[“HTTP_HOST”].”/$landing_page”);
}
else {
header(“Location: http://”.$_SERVER[“HTTP_HOST”].”/”);
}

?>