#!../eu/peu
constant progname="Aanmelden Budodag"
ifdef CGI_BIN
putenv("PEUINC=../eu/include")
include FCGI.E
elsedef
include ../teams/FSERVER.E
enddef
include readf.e
include ../teams/FORMDEF.E
global sequence derror={"Foutje bestaat niet !",
"Geen activiteit gegeven !",
"Geen naam gegeven",
"Niet geboren ?",
"Geen correct eMail adres gegeven !"
},
dcomment={"Programma foutje",
"",
"",
"Jaar mag '80 of 80 of 1980 zijn",
"eMail moet min. @ en . bevatten"}
include ../teams/FORMINS.E
sequence respbuf,respcmd,header=""
procedure response_to()
write_client("<pre>"&respbuf&"</pre>")
cmdbuf={}
end procedure
function split_post(sequence file)
sequence input,output={},output1={},output2={}
for i=1 to length(file) do
input=sreadf(file[i],'=')
if sequence(input) and length(input)>1
then output1=append(output1,input[1])
output2=append(output2,input[2])
end if
end for
if length(output1)!=0 then output={output1,output2} end if
return output
end function
function is_email_juist(sequence text)
integer atpos= find('@',text)
if atpos
then return find('.',text[atpos..])
else return 0
end if
end function
sequence year=fdate(),short_year=value(year[-2..$]) short_year=short_year[2]
year=value(year[-4..$]) year=year[2]
sequence persoon={{},{},{}}
sequence selectie_text={"Kata Trainig","3-Sporten Trainig","Model-Skills Trainig"}
sequence selectie={0,0,0}
integer NOMAILFLAG
sequence errors
procedure lees_page()
sequence post=split_post(split(POSTCMD,'\n'))
integer i=1
errors={1}
if length(post)!=0
then
while i<= length(post[1]) do
if post[1][i]<200
then errors={}
selectie[post[1][i]-100]=post[2][i]
elsif post[1][i]=202
then if sequence(post[2][i]) and length(post[2][i])!=0
then persoon[post[1][i]-201]=post[2][i]
else errors=append(errors,post[1][i]-200)
end if
elsif post[1][i]=203
then if sequence(post[2][i])
then if length(post[2][i])=3
then post[2][i]=post[2][i][2..3]
end if
post[2][i]=value(post[2][i])
if post[2][i][1]
then errors=append(errors,post[1][i]-200)
else post[2][i]=post[2][i][2]
end if
elsif post[2][i]<100
then if post[2][i]>=short_year
then post[2][i]+=1900
else post[2][i]+=2000
end if
end if
if find(post[1][i]-200,errors)=0
then if post[2][i]<=year
then persoon[post[1][i]-201]=sprintf("%u",post[2][i])
else errors=append(errors,post[1][i]-200)
end if
end if
elsif post[1][i]=204
then if sequence(post[2][i]) and length(post[2][i])!=0
then
if is_email_juist(post[2][i])
then persoon[post[1][i]-201]=post[2][i]
else errors=append(errors,post[1][i]-200)
end if
else errors=append(errors,post[1][i]-200)
end if
else
NOMAILFLAG=post[2][i]
end if
i+=1
end while
else
write_client("<h1>no data</h1>")
end if
end procedure
procedure inschrijfing()
lees_page()
if length(errors)
then d_error(errors,{})
elsif NOMAILFLAG
then
write_client("<p><h2>er word geen mail gemaakt</h2>")
else write_client("<p><h2>U krijgt een bevestigings mail</h2>")
NOMAILFLAG=1
add_hide(300,sprintf("%4.4i",NOMAILFLAG))
end if
end procedure
procedure aanmelding()
write_client("oh wat mooi")
add_form("_ta")
add_table(0,2,90,1)
add_row(108,2,100,3,0)
add_text(108,1,"Ik wil mij opgeven voor (meerde keuzen mogelijk)")
add_row(108,2,30,0,0)
add_check(109,'k',101,selectie_text[1],selectie[1],selectie_text[1])
add_col(108,2,30,0,0)
add_check(109,'s',102,selectie_text[2],selectie[2],selectie_text[2])
add_col(108,2,30,0,0)
add_check(109,'m',103,selectie_text[3],selectie[3],selectie_text[3])
add_row(108,1,30,0,0)
add_text(108,1,"Mijn naam is : ") add_input_text(1000,'n',25,202,persoon[1])
add_col(108,2,30,0,0)
add_text(108,1," geboorte jaar : ") add_input_text(1000,'n',4,203,persoon[2])
add_col(108,2,30,0,0)
add_text(108,1," mijn eMail is : ") add_input_text(1000,'n',30,204,persoon[3])
add_row(0,2,0,3,0)
write_client("<dev id=\"error\">")
add_hide(300,sprintf("%4.4i",NOMAILFLAG))
write_client(" ")
write_client("</dev>")
add_row(108,2,100,3,0)
d_oke_reset_niets()
write_client("</table>")
write_client("</form>")
end procedure
integer main_pageID=routine_id("aanmelding")
procedure open_inschrijving()
if respcmd="nomail"
then NOMAILFLAG=1
else NOMAILFLAG=0
end if
new_page(progname,"?MF.CSS","silver")
program(progname,"0.0",0,main_pageID)
end procedure
function command_decoder()
constant onbekend="<center><h1>Onbekende opdracht</h1><br><h2>Commando = "
integer index
while length(cmdbuf) do
index=find('?',cmdbuf)
if index then
respcmd=cmdbuf[1..index-1] respbuf=cmdbuf[index+1..]
else
respcmd=cmdbuf respbuf=""
end if
if find('_',respcmd) then
if respcmd="_n" then write_client(header&"error| ") write_client(" ") cmdbuf={}
elsif respcmd="_ta" then write_client(header&"error| ") inschrijfing() cmdbuf={}
else respbuf=onbekend&respcmd&"</h2></center>"
write_client(header&"foo|") response_to() cmdbuf={}
end if
else
if respcmd="4" or lower(respcmd)="quit"
then
return 0
elsif respcmd="index"
then
open_inschrijving()
cmdbuf={}
else
open_inschrijving()
cmdbuf={}
end if
end if
end while
return 1
end function
ifdef CGI_BIN
if command_from_client() then
if nph_flag
then header=""
else header="Content-type: text/plain\n\n"
end if
if command_decoder()
then close_page()
else quitserver()
end if
end if
elsedef
netserver()
while 1 do
command_from_client()
if command_decoder()
then close_page()
else quitserver() exit
end if
end while
enddef