<?php
/* This little routine will produce a tab delimited file of the contents of the expertise and people
   tables from the injdirect database - that's the one that runs the Directory of Injury Personnel.
   The tab delimited file is sent as an application/octetstream file to force saving to file, to be used for
   producing some kind of mailout. 
	 We can't use CSV because someone decided to put "s in the data ;-( */

header("Content-disposition: filename=maillist.dat");
header("Content-type: application/octetstream");
header("Pragma: no-cache");
header("Expires: 0");
// doing some DOS-CRLF magic...
$client=getenv("HTTP_USER_AGENT");
if (ereg('[^(]*\((.*)\)[^)]*',$client,$regs)):
    $os = $regs[1];
    // this looks better under WinX
    if (eregi("Win",$os)):
      $crlf="\r\n";
    else:
      $crlf="\n";
    endif;			/* OS = WIN */
endif;			/* ereg $client */
$database = "xxxxxxxxx";
//<Build query here>
$sep="\t";

$result = mysql_db_query($database, $query);
if (mysql_errno() != 0):
 echo "ERRNUM: ".mysql_errno()." - ".mysql_error()."\n";
endif;

/* Dump a header line showing field order */
echo "title $sep surname $sep fname $sep position $sep section $sep division $sep orgname $sep mail1 $sep mail2 $sep city $sep ";
echo "state $sep postcode $sep phone $sep mobile $sep fax $sep email $sep exp1 $sep exp2 $sep exp3 $sep exp4 $sep exp5 $sep description";
echo $crlf;
while($row=mysql_fetch_array($result)){
extract($row);
echo stripslashes($title) . $sep;
echo stripslashes($surname) . $sep;
echo stripslashes($fname) . $sep;
echo stripslashes($position) . $sep;
echo stripslashes($section) . $sep;
echo stripslashes($division) . $sep;
echo stripslashes($orgname) . $sep;
echo stripslashes($mail1) . $sep;
echo stripslashes($mail2) . $sep;
echo $city . $sep;
echo $state . $sep;
echo $postcode . $sep;
echo $phone . $sep;
echo $mobile . $sep;
echo $fax . $sep;
echo $email . $sep;
echo $expertise[intval($exp1)] . $sep;
echo $expertise[intval($exp2)] . $sep;
echo $expertise[intval($exp3)] . $sep;
echo $expertise[intval($exp4)] . $sep;
echo $expertise[intval($exp5)] . $sep;
$description = stripslashes($description);
echo str_replace("\n", " ",$description);
echo $crlf;
}

?>
