#!/bin/sh

[ ! -d tmp ] && mkdir tmp
[ ! -d county ] && mkdir county
[ ! -d ../../gafoia ] && mkdir ../../gafoia
wrk="tmp/getcounty.$$.wrk"; export wrk

cat county.db |
while read dbx
do
cono="$( echo "${dbx}" | cut -d "~" -f 1 )"; export cono
coname="$( echo "${dbx}" | cut -d "~" -f 2 | tr " " "_" )"; export coname
echo "${coname} ${cono}"

name="Dwayne Rowland"; export name
phone="478 461-4955"; export phone
email="Dwayne@WorldVote.com"; export email
addressfx="dwayne.add"; export addressfx
dte="$( date "+%b %e %Y" )"; export dte
agent="$( cat county/${coname}.agent )"; export agent
agentaddressfx="county/${coname}.add"; export agentaddressfx
reasonfx="reason.txt"; export reasonfx

{
cat mkfoia.head 2>&1
cat foia.txt |
sed -e "
s~\&~(AMP)~g
s~(NAME)~${name}~g
s~(PHONE)~${phone}~g
s~(EMAIL)~${email}~g
/(ADDRESS)/r ${addressfx}
/(ADDRESS)/d
s~(DATE)~${dte}~g
s~(AGENT)~${agent}~g
/(AGENTADDRESS)/r ${agentaddressfx}
/(AGENTADDRESS)/d
/(REASON)/r ${reasonfx}
/(REASON)/d
s~(AMP)~\&~g
" |
tr "\n" "+" |
sed -e "
s~+~<br>\\
~g
"
cat mkfoia.foot 2>&1
} >county/${coname}.htm
cp county/${coname}.htm ../../gafoia

done
