#!/bin/sh

# disable filename globbing
{
echo Content-type: text/html
echo
BASE=`pwd`
APPLDIR=$BASE/appl
DATADIR=$BASE/data
PATH=$PATH:$BASE/ihd/bin:.
export PATH APPLDIR DATADIR
cd AGE
#QUERY_STRING="000060116+16.621.429-7+A+04/12/2018+20/12/2018"
TZ=America/Santiago
{
dat=`date +%F" "%T`
echo -n $dat"+"
echo -n "$QUERY_STRING""+" 
echo $REMOTE_USER
} | 
awk -F+ ' {
if( $4=="A") x= "ag[\""substr($2,1,9)"\"]=\""
if( $4=="V") x= "rz[\""substr($2,1,9)"\"]=\""
if( $4=="C") x= "cr[\""substr($2,1,9)"\"]=\""
x=x""$0"\""
print "H01"substr($2,1,5)
print "H02"$5
print "H03"substr($2,6)
print "H04"$3
print "H05"$6
print "H06"$4
print "H07"$1
print "H08"$9
print "H09"$7
print "H10"$8
print " "
print $0 >> "AGE"
print x >>"../../js/agenda.js"
} ' - > TIM$$


../ihd/bin/ihmu agend ../../AGE/TIM$$ -N1  >/dev/null
#rm TIM$$

echo | awk '
{
print "<html>"
print "<head>"
print "<body>"
print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1252\">"
print "<meta name=\"GENERATOR\" content=\"Inhedo 4gt 1.0\">"
print "<meta name=\"ProgId\" content=\"Inhedo Form Generator\">"
print "<script language=\"Javascript\">"
print "self.close()"
print "</script>"
print "</body>"
print "</head>"
} '
} 2>>error/agenda.err


