[ "$1" = "" ] && exit 
f=`date`
BASE=`pwd`
APPLDIR=$BASE/appl
DATADIR=$BASE/data
PATH=$PATH:$BASE/ihd/bin
export APPLDIR DATADIR PATH
#echo APPLDIR=$APPLDIR
#echo DATADIR=$DATADIR
#echo PATH=$PATH
DOMAIN=..
cd ..
WEBDIR=`pwd`
cd $BASE
BASEDIR=$WEBDIR
[ -d $BASEDIR ] || mkdir $BASEDIR
CGIDIR=$WEBDIR/cgi-bin
[ -d $CGIDIR ] || mkdir $CGIDIR
html=$BASEDIR/$1.htm
frm=$BASEDIR/$1
cgi=$CGIDIR/$1.cgi
gget=$CGIDIR/$1""get.cgi
list=$CGIDIR/$1""list.cgi
bsc=$CGIDIR/$1""bsc.cgi
shh=$APPLDIR/sh/$1
#echo  html=$html
#echo  cgi=$cgi
#echo  gget=$gget
#echo  list=$list
#echo  bsc=$bsc
#echo  shh=$shh

[ -d $APPLDIR/etc/$1 ] || mkdir $APPLDIR/etc/$1
fun=$APPLDIR/etc/$1/functions
jav=$APPLDIR/etc/$1/javascripts
sbm=$APPLDIR/etc/$1/submit
fla=$APPLDIR/etc/$1/flags
>$fun
>$jav
>$sbm
>$fla
#echo -n fun=$fun
#echo -n jav=$jav
#echo -n sbm=$sbm
#echo fla=$fla
t0=./tmp/t0
t1=./tmp/t1
t2=./tmp/t2
t3=./tmp/t3
t4=./tmp/t4
t5=$APPLDIR/$1/tf
ihmq forms h00:* h01: h02: h03: h04: d01: d02: d03: d04: d05: d06: d07: d08: d00: d09: d10: h08: h09: h10 |
awk -F: ' "'"$1"'" != $1 { next }
function trail(txt) { while (substr(txt,length(txt),1)==" ") txt=substr(txt,1,length(txt)-1); return (txt) }
{ print > "'"$t0"'" }
{ print $1":"$2":"$3":"$4":"$5":"$6":"$7":"$8":"$9":"$10":"$11":"$12":"$13":"$14":"$15 > "'"$t3"'" }
substr ($16,1,2)!="  " { printf "%s:%.2d:%s\n",$14,d[$14],trail($16) > "'"$fun"'" }
gra=="" {
ret=sprintf("%c",13)
	gra=split($17,jav,",")
	for (i=1;i<=gra;i++) print trail(jav[i]) > "'"$jav"'"
	gra=split($18,fla,",")
	for (i=1;i<=gra;i++) print trail(fla[i]) > "'"$fla"'"
	gra=split($19,subm,ret)
	for (i=1;i<=gra;i++) if(subm[i]!="")
	{
		 gr=split(subm[i],sbm,",")
		for (j=1;j<=gr;j++)
		 printf trail(sbm[j])":" > "'"$sbm"'"
		print "" > "'"$sbm"'"
	}
}
$14=="H" { d[$14]++ }
$14=="D" { d[$14]++ }
{ print $7 > "'"$t2"'" }
x=="" {printf "%s:%s:%s:%s:%s",$1,$2,$3,$4,$5 ;x=1}
x!="" && ($10=="1 " || $10=="  ") { r0=$10;print "" }
{ 
#for (i=r0+1;i<$10+0;i++) printf "%s","H                         :  :   :     :   :  :" 
#print r0+1,$10 >"/dev/tty"
printf "%s%s:%s:%s:%s:%s:%s:",$14,$7,$8,$9,$11,$15,$10
r0=$10
} ' > $t1
clspan=`awk -F: ' x+0 < NF { x=NF } END { print (x-1)/6 } ' $t1`
frname=`awk -F: ' { print $2 ; exit} ' $t1`
cp $t2 $t5
LL=`awk -F: ' { print $4 ;exit} ' $t3 `
PG=`awk -F: ' { print $5 ;exit} ' $t3 `
awk -F: ' $8+0 > 50 {
#print
r0=$11
r1=$9
r2="'"$APPLDIR"'/"r0"/"r0".t0"
r3=$12
#print r2
r4="./tmp/"r0""$8
r44=$8
#print r4
file="'"$DATADIR"'/"$11"/HEAD"
	fl=1
	x1=1
	while (( getline < r2 ) > 0)
	if(NF!=1) {
		if ($1==r3 )  x2=$2
		if ($1!=r3 && fl) x1+=$2
		else fl=0
		if(r44==0)
		{
			print
			print ":"r3":"$1":"x2":"x1	
		}
	}
	close(r2)
	#print "r0="file
	#print "r2="r2
	#print "r1="r1
	#print "x1="x1
	#print "x2="x2
	while (( getline < file ) > 0)
	print substr($0,1,r1)":"substr($0,x1,x2) > r4
	#command=sprintf ("sort -t: -k2 %s -o %s",r4,r4)
		#command | getline
		close(file)
	
} ' $t3
awk -F: ' BEGIN { dflag="";rf=0;clspan="'"$clspan"'"
clsp[112]=3; clsp[113]=5; clsp[114]=7; clsp[115]=9; clsp[116]=11
             clsp[223]=3; clsp[224]=5; clsp[225]=7; clsp[226]=9
                          clsp[334]=3; clsp[335]=5; clsp[336]=7
                                       clsp[445]=3; clsp[446]=5
                                                    clsp[556]=3
fun="'"$fun"'"
if(fun != "")
	while (( getline < fun ) > 0)
	{
		if($1=="D")
		{
			fncd[$2]=$3
			#print >"/dev/tty"
		}
		else if(NF>3) fnch[$2+0]=$3":"$4
		else fnch[$2+0]=$3
	}
alig["01"]="; text-align:right" }
NR==1 {
field=$1
print "<html>"
print "<head>"
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 "<meta http-equiv=\"Expires\" content=\"0\">"
print "<meta http-equiv=\"Last-Modified\" content=\"0\">"
print "<meta http-equiv=\"Cache-Control\" content=\"no-cache, mustrevalidate\">"
print "<meta http-equiv=\"Pragma\" content=\"no-cache\">"

printf "<title>%s</title>\n",trail($2)
print "</head>"
print "<body bgcolor=\"#D9CEF4\">"
print "<center>"
printf "<form name=\"%sform\" method=\"post\" onsubmit=\"return closeform()\" action=\"%s/cgi-bin/%s.cgi\">\n",$1,"'"$DOMAIN"'",$1
#print "<hr width=\"800\" color=\"#C0C0C0\">"
#print "<table border=\"1\" cellspacing=\"0\" cellpadding=\"0\">"
print "<table border=\"0\" cellpadding=\"0\" bordercolor=\"#999999\" cellspacing=\"0\" style=\"border-collapse: collapse\" width=\"0\">"
print "<tr>"
printf "<td><img src=\"../Forms/forms_up_left.gif\" width=\"13\" height=\"13\"></td>\n"
printf "<td colspan=%d background=\"../Forms/forms_up_vert.gif\"></td>\n",clspan*2
printf "<td><img src=\"../Forms/forms_up_right.gif\" width=\"13\" height=\"13\"></td>\n"
print "</tr>"
print "<tr>"
printf "<td background=\"../Forms/forms_left_bl.gif\"></td>\n"
printf "<td colspan=%d bgcolor=\"#003399\">\n",clspan*2
print "<p align=\"right\" style=\"margin-top: 0; margin-bottom: 0\"><font color=\"#FFFF00\">"
printf "<a href=\"../\"><img border=\"0\" src=\"%s/logol.gif\" align=\"left\" height=\"67\"></a>\n","'"$DOMAIN"'"
print "</font><b><font color=\"#FFFF00\" face=\"arial, helvetica\" size=\"5\">&nbsp;</font></b></p>"
print "<p align=\"center\" style=\"margin-top: 0; margin-bottom: 0\"><b>"
printf "<a href=\"%s/%s.htm\" style=\"text-decoration:none\"><font color=\"#FFFF00\">\n","'"$DOMAIN"'",$1
print "<font color=\"#FFFF00\" face=\"Arial\" size=\"5\">"
printf "&nbsp;%s&nbsp;</font><font color=\"#FFFF00\" face=\"arial, helvetica\" size=\"5\"></font></a></b></p>\n",trail($2)
print "</td>"
printf "<td background=\"../Forms/forms_right_bl.gif\"></td>\n"
print "</tr>"
print "<tr>"
printf "<td><img src=\"../Forms/forms_j_left.gif\" width=\"13\" height=\"23\"></td>\n"
printf "<td colspan=%d background=\"../Forms/forms_j_center.gif\"></td>\n",clspan*2
printf "<td><img src=\"../Forms/forms_j_right.gif\" width=\"13\" height=\"23\"></td>\n"
ant="  "
next
}
substr($1,1,1)=="D" {
if(dflag=="")
{
	dd=0
	dflag=1
	print "<tr height=\"13\">"
	printf "<td><img src=\"../Forms/forms_low_left.gif\" width=\"13\" height=\"13\"></td>\n"
	printf "<td colspan=%d background=\"../Forms/forms_low_vert.gif\"></td>\n",clspan*2
	printf "<td><img src=\"../Forms/forms_low_right.gif\" width=\"13\" height=\"13\"></td>\n"
	print "</tr>"
	printf "</table>\n"
	#print "<table border=\"1\" cellpadding=\"0\" bordercolor=\"#999999\">"
	print "<table border=\"0\" cellpadding=\"0\" bordercolor=\"#999999\" cellspacing=\"0\" style=\"border-collapse: collapse\" width=\"0\">"
}
doc0[dd]=$2
doc1[dd]=$3
doc2[dd]=$4
doc3[dd]=$5
doc4[dd]=$1
dd++
next
}
function tittle (tit)
{
print "<td bordercolor=\"#C0C0C0\" bgcolor=\"#003399\" align=\"center\">"
printf "<font face=\"Tahoma\" size=\"2\" color=\"#FFFFFF\"><b>%s</b></font>\n",toupper(tit)
print "</td>"
}
{
	
	rf1=(NF-1)/6
	if ($2!=15)
	{
		print "<tr>"
		printf "<td background=\"../Forms/forms_left_gr.gif\"></td>\n"
	}
	for (pp=0;pp<rf1;pp++)
	{
		f=pp*6
		f1[pp]=substr($(f+1),2)
		f2[pp]=$(f+2)
		f3[pp]=$(f+3)
		f4[pp]=trail($(f+4))
		f5[pp]=$(f+5)
		f6[pp]=clsp[(pp+1)""rf1""clspan]+0
		if (f6[pp]==0) f6[pp]=1
	}
	for (pp=0;pp<rf1;pp++)
	{
		if (f2[pp]==15) f6[pp+1] +=2
		singlef(f1[pp],f2[pp],f3[pp],f4[pp],f5[pp],f6[pp])
#		print NR,f1[pp],"pp=",pp,"rf1="(pp+1)""rf1""clspan,f6[pp]>"/dev/tty"
	}
	if ($2!=15)
	{
		print "</td>"
		printf "<td background=\"../Forms/forms_right_gr.gif\"></td>\n"
		print "</tr>"
	}
}
function trail(txt) { while (substr(txt,length(txt),1)==" ") txt=substr(txt,1,length(txt)-1); return (txt) }
function docline(name,type,len,file,lend)
{
#print "<p><td bordercolor=\"#FFFFFF\" bgcolor=\"#DCDCDC\" height=\"23\" colspan=\"3\">"
if (type ==15) printf "<td><input type=\"hidden\" name=\"DOC%s%s\">\n",field,name
else if (type==16) printf "<td><p><input type=\"button\" style=\"font-family: Arial; font-size: 8pt\" size=\"%s\" name=\"DOC%s%s\" %s %s %s></p>\n",len,field,name,alig[type],sprintf(fncd[substr(name,3)],substr(name,1,2)+0,substr(name,1,2)+0),sprintf(fncd[name],substr(name,1,2)+0,substr(name,1,2)+0)
else if (type==17) printf "<td><p><input type=\"checkbox\" style=\"font-family: Arial; font-size: 8pt\" size=\"%s\" name=\"DOC%s%s\" %s %s %s></p>\n",len,field,name,alig[type],sprintf(fncd[substr(name,3)],substr(name,1,2)+0,substr(name,1,2)+0),sprintf(fncd[name],substr(name,1,2)+0,substr(name,1,2)+0)
else if (type <50) printf "<td><p><input type=\"text\" style=\"font-family: Arial; font-size: 8pt %s %s\" size=\"%s\" name=\"DOC%s%s\" maxlength=\"%d\" %s %s></p>\n",BKG,alig[type], lend,field,name,len,trail(sprintf(fncd[substr(name,3)],substr(name,1,2)+0,substr(name,1,2)+0)),trail(sprintf(fncd[name],substr(name,1,2)+0,substr(name,1,2)+0))
else if (type <51)
{
	filer="sort -u '"$DATADIR/"'"file"/HEAD"
	#print "name="name"  field="field >"/dev/tty"
	printf "<td>\n<p><select name=\"DOC%s%s\" style=\"font-family: Arial; font-size: 8pt %s\" %s %s>\n",field,name,BKG,sprintf(fncd[substr(name,3)],substr(name,1,2)+0,substr(name,1,2)+0),sprintf(fncd[name],substr(name,1,2)+0,substr(name,1,2)+0)
	print "<option value=\"\">"
	#print "<option value=\" \">MOSTRAR"
	while (( filer | getline linex  ) > 0) 
	printf "<option value=\"%s\">%s\n",linex,trail(linex)
	close(filer)
	printf "</select></p>\n</td>\n"
}
else
{
	filer="sort ./tmp/"file""type"|sort -t: -u -k2"
	#print "filer="filer >"/dev/tty"
	#print "name="name"  field="field" fncd="fncd["00"] >"/dev/tty"
	printf "<td>\n<p><select name=\"DOC%s%s\" style=\"font-family: Arial; font-size: 8pt %s\" %s %s>\n",field,name,BKG,sprintf(fncd[substr(name,3)],substr(name,1,2)+0,substr(name,1,2)+0),sprintf(fncd[name],substr(name,1,2)+0,substr(name,1,2)+0)
	print "<option value=\"\">"
	#print "<option value=\" \">MOSTRAR"
	while (( filer | getline ) > 0) 
	printf "<option value=\"%s\">%s\n",trail($1),trail($2)
	close(filer)
	printf "</select></p>\n</td>\n"
}
print "</td>"
return (1)
}
function singlef(name,type,len,file,lend,colsp)
{
	if (len+0 ==0 )
	{
		printf "<td bordercolor=\"#FFFFFF\" bgcolor=\"#DCDCDC\" height=\"23\" colspan=\"%s\">&nbsp;</td>\n",2
		return
	}
if (type!=15)
{
	#print "<tr>"
	print "<td align=\"right\" bordercolor=\"#FFFFFF\" bgcolor=\"#DCDCDC\" height=\"23\">"
	printf "<b><font face=\"arial, helvetica\" size=\"-1\">&nbsp;%s:</b></font>\n",trail(name)
	print "</td>"
	#print "<td bordercolor=\"#FFFFFF\" bgcolor=\"#DCDCDC\" height=\"23\" colspan=\"3\">"
	printf "<td bordercolor=\"#FFFFFF\" bgcolor=\"#DCDCDC\" height=\"23\" colspan=\"%s\">\n",colsp
}
if (type ==20)
{
 printf "<input type=\"hidden\" name=\"%sH%.2d\">\n",field,rf
	 printf "<img name=\"%sH%.2d\" border=\"1\" width=\"%d\" height=\"%d\" alt=\"\" %s src=\"../Rostros.jpg\">\n",field,rf,lend,lend,fnch[rf++]
}
else if (type>9 && type <15) printf "<textarea cols=\"%s\"  name=\"%sH%.2d\" rows=\"%d\" %s>\n</textarea>\n",lend,field,rf,type-9,fnch[rf++]
else if(type==15)  printf "<input type=\"hidden\" name=\"%sH%.2d\">\n",field,rf++
else if (type==16) printf "<input type=\"button\" name=\"%sH%.2d\" style=\"font-family: Arial; font-size: 8pt\" size=\"%s\" %s %s>\n",field,rf,len,fnch[rf++],alig[type]
else if (type==17) printf "<input type=\"checkbox\" name=\"%sH%.2d\" style=\"font-family: Arial; font-size: 8pt\" size=\"%s\" %s %s>\n",field,rf,len,fnch[rf++],alig[type]
else if (type <50) printf "<input type=\"text\" name=\"%sH%.2d\" OnChange=\"chng(%d)\" style=\"font-family: Arial; font-size: 8pt %s\" size=\"%d\" maxlength=\"%d\" %s>\n",field,rf,rf,alig[type],lend,len,fnch[rf++]
else if (type <51)
{
	filer="sort -u '"$DATADIR/"'"file"/HEAD "
	printf "<select name=\"%sH%.2d\" style=\"font-family: Arial; font-size: 8pt\" OnChange=\"chng(%d)\">\n",field,rf,rf++
	print "<option value=\"\">"
	print "<option value=\" \">MOSTRAR"
	while (( filer | getline linex) > 0) 
	printf "<option value=\"%s\">%s\n",linex,trail(linex)
	close(filer)
	printf "</select>\n"
}
else
{
	filer="sort -t: -k2 ./tmp/"file""type
	#print "rovfiler="filer >"/dev/tty"
	printf "<select name=\"%sH%.2d\" style=\"font-family: Arial; font-size: 8pt\" OnChange=\"chng(%d)\" %s>\n",field,rf,rf,fnch[rf++]
	print "<option value=\"\">"
	print "<option value=\" \">MOSTRAR"
	while (( filer | getline) > 0) 
	printf "<option value=\"%s\">%s\n",trail($1),trail(substr($2,1,35))
	close(filer)
	printf "</select>\n"
}
if(type!=15)
{
	print "</td>"
	#print "</tr>"
}
else type=""
return (1)
}
END {
print "</tr>"
ff="'"$PG"'"*"'"$LL"'"
for (i=0;i<ff;i++)
{ for (j=0;j<dd;j++) printf "<input type=\"hidden\" name=\"%sD%.2d%.2d\">","'"$1"'",i,j
	print ""
}
if (dd!="")
{
if ("'"$PG"'"+0 >1) ddd=1
else ddd=0
printf "<td><img src=\"../Forms/forms_d_up_left.gif\" width=\"11\" height=\"11\"></td>\n"
printf "<td colspan=%d background=\"../Forms/forms_d_up_vert.gif\"></td>\n",dd+1+ddd
printf "<td><img src=\"../Forms/forms_d_up_right.gif\" width=\"11\" height=\"11\"></td></tr>\n"
printf "<tr id=\"titrow\"><td background=\"../Forms/forms_d_left_bl.gif\"></td>\n"
tittle("#")
for (j=0;j<dd;j++) if(doc0[j]!=15) tittle(trail(substr(doc4[j],2)))
else print "<td></td>"
if("'"$PG"'"+0 >1) tittle("")
printf "<td background=\"../Forms/forms_d_right_bl.gif\"></td>\n"
print "</tr>"
	for (i=0;i<"'"$LL"'"+0;i++)
	{
		if (i%2) BKG=";border:1px solid #7F9DB9;background-color:#E0E0E0"
		else BKG=";border:1px solid #7F9DB9;background-color:#FFFFFF"
		r1=1
		print "<tr>"
		printf "<td background=\"../Forms/forms_d_left_gr.gif\"></td>\n"
		printf "<td>\n<p><input type=\"text\" readonly ondblClick=\"insert(%d)\" value=\"%.2d\" name=\"T00\" align=\"center\" style=\"font-family: Arial; font-size: 8pt;width: 20; text-align:right\"></p>\n</td>\n",i,i+1
		for (j=0;j<dd;j++) docline(sprintf("%.2d%.2d",i,j),doc0[j],doc1[j],doc2[j],doc3[j])
		if("'"$PG"'"+0!=1)
		if(i==0) printf "<td><a REF=\"#\" OnMouseUp=\"slide1(-1)\">\n <img src=\"../Forms/forms_l_1.gif\" width=\"22\" height=\"22\"></td>\n"
		else if(i=="'"$LL"'"-1) printf "<td> <a REF=\"#\" OnMouseUp=\"slide1(1)\">\n<img src=\"../Forms/forms_l_4.gif\" width=\"22\" height=\"22\"></td>\n"
		else printf "<td> <a REF=\"#\" OnMouseUp=\"slide(%d)\">\n<img  name=\"sld_%d\" src=\"../Forms/forms_l_3.gif\" width=\"22\" height=\"22\"></td>\n",i,i
		printf "<td background=\"../Forms/forms_d_right_gr.gif\"></td>\n"
		print "</tr>"
	}
printf "<td><img src=\"../Forms/forms_d_low_left.gif\" width=\"11\" height=\"11\"></td>\n"
printf "<td colspan=%d background=\"../Forms/forms_d_low_vert.gif\"></td>\n",dd+1+ddd
printf "<td><img src=\"../Forms/forms_d_low_right.gif\" width=\"11\" height=\"11\"></td></tr>\n"
}
else 
{
	print "<tr height=\"13\">"
	printf "<td><img src=\"../Forms/forms_low_left.gif\" width=\"13\" height=\"13\"></td>\n"
	printf "<td colspan=%d background=\"../Forms/forms_low_vert.gif\"></td>\n",clspan*2
	printf "<td><img src=\"../Forms/forms_low_right.gif\" width=\"13\" height=\"13\"></td>\n"
	print "</tr>"
}
	printf "</table>\n"
sbm="'"$sbm"'"
print "<table border=\"0\" cellpadding=\"0\" bordercolor=\"#999999\">"
printf "<td align=center><font size=\"1\" face=\"Tahoma\"><b>&nbsp;</b><br></font>\n"
print "<input type=\"submit\" value=\"Consultar\" name=\"B1\" style=\"font-family: Arial; font-size: 8pt;float: left\" Onclick=\"cons(this)\">\n"
printf "<input type=\"submit\" value=\"Actualizar\" disabled name=\"B1\" style=\"font-family: Arial; font-size: 8pt;float: left\" Onclick=\"cons(this)\">\n"
if(sbm != "")
{
	while (( getline < sbm ) > 0)
	if($1!="")
	{
		printf "<td colspan=\"%d\" align=right>\n",td2
		if ($7!="")
		printf "<font size=\"1\" face=\"Tahoma\" color=\"#003399\"><b>%s:&nbsp;</b><br></font>\n",$7
		else printf "<font size=\"1\" face=\"Tahoma\" color=\"#003399\"><b>%s&nbsp;</b><br></font>\n",$7
		value=""
		size=""
		name="name=\"B1\""
		style="style=\"font-family: Arial; font-size: 8pt"
		if($2!="") name="name=\""$2"\""
		if($3!="") size="size=\""$3"\""
		if($4!="") style=style"; text-align:"$4"\""
		else style=style"\""
		if($5!="") value="value=\""$5"\""
		printf "<input type=\"%s\" %s %s %s %s %s></td>\n",$1,name,size,value,style,$6
	}
}
if (dd!="")
{
printf "<td align=center><font size=\"1\" face=\"Tahoma\" color=\"#1A1A1A\"><b>&nbsp;</b><br></font>\n"
print "<input type=\"button\" value=\"Scroll-up\" OnMouseUp=\"scrollup()\" name=\"B1\" style=\"font-family: Arial; font-size: 8pt; float: right\">\n<input type=\"button\" value=\"Scroll-Down\" OnMouseUp=\"scrolldown()\" name=\"B1\" style=\"font-family: Arial; font-size: 8pt;float: right\">\n</td>"
}
else print "</td>"
fla="'"$fla"'"
if(fla != "")
	while (( getline < fla ) > 0)
	if($1!="") printf "<input type=\"hidden\" name=\"%s\">\n",$1
print "</tr>"
print ""
print "</table>"
print "</body>"
print "<script language=\"Javascript\">"
printf "nhd=%d\n",rf
printf "nrd=%d\n",ff
printf "ncd=%d\n",dd
printf "lin=%d\n","'"$LL"'"
printf "tp=0\n"
printf "swapout()\n"
print "valact()"
#printf "document.%sform.elements[0].focus()\n","'"$1"'"
print "function valact()"
print "{"
printf "	if (document.%sform.elements[0].value!=\"\")\n","'"$1"'"
printf "	document.%sform.elements[%d].disabled = false\n","'"$1"'",rf+ff*dd+"'"$LL"'"*(dd+1)+1
printf "	else document.%sform.elements[%d].disabled = true\n","'"$1"'",rf+ff*dd+"'"$LL"'"*(dd+1)+1
print "}"
print "function swapout()"
print "{"
print "	lev=tp*ncd"
print "	ind=0"
print "	for(i=0;i<lin*(ncd+1);i++)"
printf "		if (i%%(ncd+1))\n"
printf "		{\n"
printf "			document.%sform.elements[nrd*ncd+nhd+i].value=document.%sform.elements[nhd+lev++].value\n","'"$1"'","'"$1"'"
printf "			if(document.%sform.elements[nrd*ncd+nhd+i].type==\"checkbox\")\n","'"$1"'"
printf "			if(document.%sform.elements[nrd*ncd+nhd+i].value==\"1\") document.%sform.elements[nrd*ncd+nhd+i].checked=true\n","'"$1"'","'"$1"'"
printf "			else document.%sform.elements[nrd*ncd+nhd+i].checked=false\n","'"$1"'"
printf "		}\n"
printf "		else document.%sform.elements[nrd*ncd+nhd+i].value= (tp+1+ind < 10 ? %c0%c : %c%c) + (tp+1+ind++)\n","'"$1"'",39,39,39,39
print "}"
print "function swapin()"
print "{"
print "	lev=tp*ncd"
printf "	for(i=0;i<lin*(ncd+1);i++) if (i%%(ncd+1)) document.%sform.elements[nhd+lev++].value=document.%sform.elements[nrd*ncd+nhd+i].value\n","'"$1"'","'"$1"'"
print "}"
print "function scrollup()"
print "{"
print "	swapin()"
printf "	tp -=%d\n","'"$LL"'"/2
print "	if (tp < 0) tp=nrd-lin"
print "	swapout()"
print "	exswap()"
print "}"
print "function scrolldown()"
print "{"
print "	swapin()"
printf "	tp +=%d\n","'"$LL"'"/2
print "	if (tp >nrd-lin) tp=0"
print "	swapout()"
print "	exswap()"
print "}"
print "</script>"
jav="'"$jav"'"
if(jav != "")
	while (( getline < jav ) > 0)
	if($1!="") printf "<script language=\"Javascript\" src=\"../js/%s.js\"> </script>\n",$1
printf "<script language=\"Javascript\" src=\"../js/brstype.js\"> </script>\n"
printf "<script language=\"Javascript\" src=\"../js/%s.js\"> </script>\n","'"$1"'"
printf "<script language=\"Javascript\" src=\"../js/slide.js\"> </script>\n"
	print "</form>"
print ""
} ' $t1 >$html
awk ' BEGIN {exit } END {
printf "<html>\n"
#print "<script type=\"text/javascript\">"
#print "history.go(-2)"
#print "</script>"
printf "<head>\n"
printf "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1252\">\n"
print "<meta name=\"GENERATOR\" content=\"Inhedo 4gt 1.0\">"
print "<meta name=\"ProgId\" content=\"Inhedo Form Generator\">"
printf "<META HTTP-EQUIV=\"refresh\" content=\"0;URL=../%s.htm\">\n","'"$1"'"
printf "</head>\n"
printf "</body>\n"
printf "</head>\n"
 } '  > $frm

[ -f $BASEDIR/js/$1.js ] || {
echo "function chng(x) {
if(x==0) valact()
}
//function exswap()
//{
	//return
//}
function cons(xx) { botonpres=xx.value }"
awk ' BEGIN { exit } END { 
printf "function closeform()\n"
printf "{\n"
printf "        swapin()\n"
printf "        fld=0\n"
printf "        if(botonpres==\"Consultar\")\n"
printf "        {\n"
printf "                for(i=0;i<nhd+ncd;i++) if( document.%sform.elements[i].value!=\"\") fld=1\n","'"$1"'"
printf "                if(fld==0) document.%sform.elements[0].value=\"\"\n","'"$1"'"
printf "                return true\n"
printf "        }\n"
printf "	return true\n"
printf "}\n"
} ' 
awk ' { printf $0"\n","'"$1"'","'"$1"'" } ' $BASEDIR/js/insert.js 
awk ' { printf $0"\n","'"$1"'","'"$1"'" } ' $BASEDIR/js/clear.js 
} >$BASEDIR/js/$1.js
#[ "$2" = "" ] &&  rm -f $t1 $t2 $t3 $t4 $t5
[ "$2" = "" ] && exit
awk -F: ' { } END {

print "#!/bin/sh"
print ""
print "# disable filename globbing"
print ""
print " echo Content-type: text/html"
print " echo"
print " BASE=`pwd`"
print "{"
printf "APPLDIR=$BASE/appl\n"
printf "DATADIR=$BASE/data\n"
print "PATH=$PATH:$BASE/ihd/bin:."
print "export PATH APPLDIR DATADIR"
print "T=/tmp/T$$"
print "T1=/tmp/T1$$"
print "T2=/tmp/T2$$"
#print "T=/tmp/TTT"
#print "T1=/tmp/TTT1"
#print "T2=/tmp/TTT2"
print "splash >$T"
printf "awk -F= %c BEGIN { ret=sprintf(\"%%c\",13) }\n",39
printf "$0==\"\" { next }\n"
printf "$1==\"T00\" { next }\n"
printf "substr($1,1,5)==\"%s\" && $2==\"\" { next }\n","'"$1"'"
printf "/DOC%s/ { next }\n","'"$1"'"
printf "{ wh=\"\" }\n"
printf "substr($1,1,5)==\"%s\" && index($0,ret) >0 {\n","'"$1"'"
printf "printf \"%%s\",$0\n"
printf "        while (wh==\"\")\n"
printf "        {\n"
printf "                if (getline <= 0) wh=1\n"
printf "                if(substr($1,1,5)==\"%s\") \n","'"$1"'"
printf "                if (index($0,ret)==0)  { printf \"\\n%%s\\n\",$0;wh=1 }\n"
printf "                else printf \"%%s\",$0\n"
printf "                else  printf \"%%s\",$0\n"
printf "        }\n"
printf "}\n"
printf "wh==\"\" && $2!=\"\" && $1!=\"T00\" %c $T > $T1\n",39
printf "QRY=`awk -F= %c $1== \"B1\" {print $2} %c $T1 `\n",39,39
print "if [ \"$QRY\" = Consultar ]"
print "then"
printf "	COMMAND=`awk -F= %c BEGIN { printf \"./ihd/bin/ihmq %s \" }\n",39,"'"$1"'"
print "	$1!=\"B1\" {"
print "	if (NR==1 && substr($1,length($1)-1) !=\"00\") printf \"H00^ \""
print "	if (substr($1,6,1)==\"D\") printf \"D%s^%s \",substr($1,length($1)-1),adv($2)"
print "	else printf \"H%s^%s \",substr($1,length($1)-1),adv($2)"
print "}"
print "function adv(txt) { while (substr(txt,1,1)==\" \") txt=substr(txt,2); return (txt) }"
print "END {"
print "if (NR==1) print \"H00^ \""
printf "print \"\" } %c $T1 `\n",39
print "$COMMAND | sort -t\\^ -k2 -k1 -u  >$T2"
printf "NF=`awk %c END { print NR } %c $T2`\n",39,39
print "if [ $NF = 1 ]"
print "then"
printf "		REG=`awk -F\"^\" %c { print $1 } %c $T2`\n",39,39
printf "		./%sget.cgi $REG\n","'"$1"'"
print "	else"
printf "	./%slist.cgi $T $T2\n","'"$1"'"
print "	fi"
print "fi"
print "if [ \"$QRY\" = Actualizar ]"
print "then"
printf "	COMMAND=`awk -F= %c END { printf \"./ihd/bin/ihmu %s %%s -N1\\n\",\"%c\"$T2\"%c\" } %c `\n",39,"'"$1"'",39,39,39
printf "	awk -F= %c\n",39
printf "\t/%sH/ { printf \"H%%s%%s\\n\",substr($1,length($1)-1),substr($0,10) }\n","'"$1"'"
printf "\t/%sD/ { printf \"D%%s%%s\\n\",substr($1,length($1)-3),substr($0,12) }\n","'"$1"'"
printf "	%c $T1 > $T2\n",39
printf "        awk -F= %c $1==\"%sH00\" { y=$2 }\n",39,"'"$1"'"
printf "                  $2==\"NEWFOTO>>>\" { x=$1 }\n"
printf "                  $1==\"FOTO\" {\n"
printf "                                split($2,ph,\".\")\n"
printf "                                shell=sprintf(\"rm -f ../IMAG/%s/%%s%%s.%%s;mv -f \\\"../upload/uploads/%%s\\\" ../IMAG/%s/%%s%%s.%%s\\n\",x,y,ph[2],$2,x,y,ph[2])\n","'"$1"'","'"$1"'"
printf "                                system(shell)\n"
printf "                                printf \"%%s%%s%%s.%%s\\n\",substr(x,6),x,y,ph[2] } %c $T1 >> $T2\n",39

print "echo -n \" \" >>$T2"
print "	$COMMAND "
printf "	cat ../%s\n","'"$1"'"
print "fi"
printf " } 2> ./error/%s.err\n","'"$1"'"
print "rm $T $T1 $T2"
} ' $t1 >$cgi

awk -F: '
$8 +0 >49 && $14=="H" {  TH[NR]=$9+0 }
$14=="D" { dnr++ }
$8 +0 >49 && $14=="D" {  TD[NR]=$9+0 }
END {
print " BASE=`pwd`"
printf "APPLDIR=$BASE/appl\n"
printf "DATADIR=$BASE/data\n"
print "PATH=$PATH:$BASE/ihd/bin:."
print "export PATH APPLDIR DATADIR"
printf "$APPLDIR/sh/%s $1 |\n","'"$1"'"
printf "awk -F\"^\" %c BEGIN {\n",39
for (i in TH) printf "TH[\"%.2d\"]=%s\n",i-1,TH[i]
for (i in TD) printf "TD[\"%.2d\"]=%s\n",i-1,TD[i]
printf "NH=%d\nND=%d\n",NR-dnr,dnr
print "}\n"
print "function trail(txt) { while (substr(txt,length(txt),1)==\" \") txt=substr(txt,1,length(txt)-1); return (txt) }"
print "FILENAME==ARGV[1] && NR==1 { for (i=1;i<=NH;i++) reg[sprintf(\"%.2d\",i-1)]=$i }"
print "FILENAME==ARGV[1] { for (i=NH+1;i<=NF;i++) doc[sprintf(\"%.2d\",NR-1)sprintf(\"%.2d\",i-1-NH)]=$i"
print "next }"
printf "/%sD/ {\n","'"$1"'"
print "m0=$0"
print "m1=\"\""
print "for (i=0;i<ND;i++)"
print "{"
printf "        x=index(m0,\"%sD\")\n","'"$1"'"
print "        y=index(substr(m0,2),\">\")"
print "        re=substr(m0,x+6,4)"
print "        m1=m1\"\"sprintf(\"%s value=\\\"%s\\\"%s\",substr(m0,1,y),trail(doc[re]),substr(m0,y+1,1))"
print "        m0=substr(m0,y+2)"
print "}"
print "print m1"
print "next"
print "}"
printf "/DOC%s/ { print ; next }\n","'"$1"'"
print "/textarea / {"
print "print "
printf "x=index($0,\"%sH\")\n","'"$1"'"
print "re=substr($0,x+6,2)"
print "printf trail(reg[re])"
print "next"
print "}"
print "/img name=/ {"
print "if (photo==\"\") print"
print "else"
print "{"
        print "name=substr($0,12,8)"
        print "y=index($0,\"../Ros\")"
        printf "printf \"%%s../IMAG/%s/%%s\\\">\\n\",substr($0,1,y-1),photo,photo\n","'"$1"'"
print "}"
        print "next"
print "}"
print "/input type=\\\"hidden/ {"
printf "x=index($0,\"%sH\")\n","'"$1"'"
print "y=index($0,\">\")"
print "re=substr($0,x+6,2)"
print "if (re==\"00\") rdonly=\"readonly\""
print "else rdonly=\"\""
print "printf \"%s value=\\\"%s\\\" %s %s\\n\",substr($0,1,y-1),trail(reg[re]),rdonly,substr($0,y)"
print "photo=trail(reg[re])"
print "next"
print "}"
print "/input type=\\\"checkbox/ {"
printf "x=index($0,\"%sH\")\n","'"$1"'"
print "y=index($0,\">\")"
print "re=substr($0,x+6,2)"
print "rdonly=\"\""
print "if (re==\"00\") rdonly=\"readonly\""
print "chkd=\"\""
print "if (reg[re]+0==1) chkd=\"checked\""
print "printf \"%s value=\\\"%s\\\" %s %s %s\\n\",substr($0,1,y-1),trail(reg[re]),rdonly,chkd,substr($0,y)"
print "next"
print "}"
print "/input type=\\\"text/ {"
printf "x=index($0,\"%sH\")\n","'"$1"'"
print "y=index($0,\">\")"
print "re=substr($0,x+6,2)"
print "if (re==\"00\") rdonly=\"readonly\""
print "else rdonly=\"\""
print "printf \"%s value=%c%s%c %s %s\\n\",substr($0,1,y-1),39,trail(reg[re]),39,rdonly,substr($0,y)"
print "next"
print "}"
printf "/select name=\\\"%sH/ { print\n","'"$1"'"
printf "x=index($0,\"%sH\")\n","'"$1"'"
print "indx=substr($0,x+6,2)"
print "re=trail(substr(reg[indx],1,TH[indx]))"
print "while (index($0,\"/select\") ==0 ) "
print "{"
print "	getline"
print "	y=index($0,\">\")"
print "	x=index($0,\"=\")"
print "	if(re==substr($0,x+2,TH[indx])) printf \"%s selected %s\\n\",substr($0,1,y-1),substr($0,y)"
print "	else"
print "	print"
print "}"
print "next } "
print "/Consultar/ {"
print "	y=index($0,\">\")"
print "	printf \"%s disabled %s\\n\",substr($0,1,y-1),substr($0,y)"
print "	next"
print "}"
print "{print}"
printf "%c - ../%s.htm\n",39,"'"$1"'"
} ' $t3 >$gget

awk -F= '
function trail(txt) { while (substr(txt,length(txt),1)==" ") txt=substr(txt,1,length(txt)-1); return (txt) }
BEGIN { 
	file="'"$t5"'"
printf "awk -F= %cBEGIN { \n",39
	while (( getline < file ) > 0) printf "T[\"%.2d\"]=\"%s\"\n",z++,trail(toupper($1))

print "	printf \"%s^\",T[\"00\"]"
printf "}\n"
printf "substr($1,1,6)==\"%sD\" && substr($1,1,8)!=\"%sD00\"  { next }\n","'"$1"'","'"$1"'"
printf "$2!=\"\" && substr($1,1,6)==\"%sH\" {\n","'"$1"'"
printf "        if(substr($1,length($1)-1)!=\"00\")\n"
printf "        {\n"
printf "                x=substr($1,length($1)-1)\n"
printf "                printf \"%%s^\",T[x]\n"
printf "        }\n"
printf "}\n"
printf "$2!=\"\" && substr($1,1,6)==\"%sD\" {\n","'"$1"'"
printf "                printf \"%%s^\",T[NR-1]\n"
printf "}\n"
printf "END {\n"
printf "	print \"\"\n"
printf "} %c $1 |\n",39
printf " awk -F\"^\" %c BEGIN {ttop(\"Consulta de Datos en %s\");bgcolor=\"#FFFFFF\"}\n",39,trail("'"$frname"'")
printf "NR==1 { for (i=1; i<NF; i++) labels($i)\n"
printf "print \"</tr>\"\n"
printf "next\n"
printf "}\n"
printf "{ for (i=1; i<NF; i++)if (i==1) boton($i)\n"
printf "else label($i)\n"
printf "print \"</tr>\"\n"
printf "if (NR%%2==0 ) bgcolor=\"#E1E1E1\"\n"
printf "else bgcolor=\"#FFFFFF\"\n"
printf "}\n"
printf "END { foot() } \n"
printf "function boton(value)\n"
printf "{\n"
printf "	print \"<td bgcolor=\\\"#E1E1E1\\\">\"\n"
print "printf \"<p><input type=\\\"submit\\\" style=\\\"width: 120\\\" value=\\\"%s\\\" name=\\\"T02\\\"></p>\\n\",value"
printf "print \"</td>\"\n"
printf "}\n"
printf "function label(value)\n"
printf "{\n"
print "printf \"<td bgcolor=\\\"%s\\\">\",bgcolor"
print "printf \"<p align=\\\"center\\\"><font face=\\\"Arial\\\" size=\\\"3\\\">&nbsp;%s&nbsp;</font></p>\\n\",value"
printf "print \"</td>\"\n"
printf "}\n"
printf "function labels(value)\n"
printf "{\n"
printf "print \"<td bordercolor=\\\"#C0C0C0\\\" bgcolor=\\\"#003399\\\" align=\\\"center\\\">\"\n"
print "printf \"<p align=\\\"center\\\"><b><font color=\\\"#FFFFFF\\\">%s</font></b></p>\\n\",value"
printf "print \"</td>\"\n"
printf "}\n"
printf "function ttop(value)\n"
printf "{\n"
printf "print \"<html>\"\n"
printf "print \"<head>\"\n"
printf "print \"<meta http-equiv=\\\"Content-Type\\\" content=\\\"text/html; charset=windows-1252\\\">\"\n"
printf "print \"<meta name=\\\"GENERATOR\\\" content=\\\"Inhedo 4gt 1.0\\\">\"\n"
printf "print \"<meta name=\\\"ProgId\\\" content=\\\"Inhedo Form Generator\\\">\"\n"
print "printf \"<title>%s</title>\\n\",value"
printf "print \"</head>\"\n"
printf "print \"<center>\"\n"
printf "print \"<body bgcolor=\\\"#D0D0DF\\\">\"\n"
printf "print \"<p align=\\\"center\\\"><img border=\\\"0\\\" src=\\\"%s/logol.gif\\\" width=\\\"200\\\" height=\\\"97\\\"></p>\"\n","'"$DOMAIN"'"
printf "printf \"<H1>%s</H1>\\n\"\n",trail("'"$frname"'")
printf "print \"<form method=\\\"post\\\" action=\\\"%s/cgi-bin/%sbsc.cgi\\\" name=billform>\"\n","'"$DOMAIN"'","'"$1"'"
printf "print \"<center>\"\n"
printf "print \"<table border=\\\"1\\\" cellspacing=\\\"0\\\" cellpadding=\\\"0\\\" bordercolor=\\\"#999999\\\" height=\\\"50\\\">\"\n"
printf "printf \"<input type=\\\"hidden\\\" value=\\\"Query\\\" name=\\\"B1\\\">\\n\"\n"
printf "print \"<tr>\"\n"
printf "print \"</center>\"\n"
printf "}\n"
printf "function foot()\n"
printf "{\n"
printf "print \"</table>\"\n"
printf "print \"</center>\"\n"
printf "print \"</form>\"\n"
print  "print \"<b>\"NR -1 \" Registros encontrados</b>\""
printf "print \"</body>\"\n"
printf "print \"</html>\"\n"
printf "} %c - $2\n",39
printf "awk %c BEGIN {\n",39
printf "print \"</body>\"\n"
printf "print \"</form>\"\n"
printf "print \"<form method=\\\"GET\\\" action=\\\"%s/%s.htm\\\">\"\n","'"$DOMAIN"'","'"$1"'"
printf "printf \"<p align=\\\"center\\\"><input type=\\\"submit\\\" value=\\\"Continuar\\\" name=\\\"B1\\\" style=\\\"width: 200; height: 50; font-weight: bold; font-size: 18pt\\\"></p>\\n\"\n"
printf "print \"</form>\"\n"
printf "print \"</body>\"\n"
printf "print \"</html>\"\n"
printf "exit } %c - $2\n",39
exit
} ' $t1 >$list

awk -F: ' BEGIN {
print "#!/bin/sh"
print ""
print "# disable filename globbing"
print ""
 print "echo Content-type: text/html"
 print "echo"
print " BASE=`pwd`"
printf "APPLDIR=$BASE/appl\n"
printf "DATADIR=$BASE/data\n"
print "PATH=$PATH:$BASE/ihd/bin:."
print "export PATH APPLDIR DATADIR"
print "T=/tmp/T$$"
print "splash >$T"
printf "REG=`awk -F= %c $1== \"T02\" {print $2} %c $T `\n",39,39
printf "	./%sget.cgi $REG\n","'"$1"'"
print "rm $T"
} ' $t1 >$bsc
$BASE/ihd/bin/dss $1 
chmod 755 $html $cgi $gget $list $bsc $shh
#chown www-data $html $cgi $gget $list $bsc $shh
#rm -f $t1 $t2 $t3 $t4 $t5
