WernerScheduler.borg
WernerScheduler.borg
{
` ----------------------------
` GLOBAL VARIABLES
` ----------------------------
FREE:0;
VUB:1;
JETTE:2;
TRAVEL:3;
AWAY:4;
HOME:5;
NAME:"W.E.R.N.E.R."; `Persons Name
MAINURL:"/Werner"; `URL to subscribe to
START:9; `start hour
STOP:24; `stop hour
EMPTYFIELD:""; `the empty field in the schedule
` ----------------------------
` DATA STORAGE
` ----------------------------
makeappointement(color,str):: clone();
makeday(dag,maand,jaar)::
{
uren[STOP-START]:makeappointement(FREE,EMPTYFIELD);
setappointement(from,to,app)::
{
while(from1]:=app;
from:=from+1
})
};
clone()
};
day_equals(a,d):: (((a.dag)=(d.dag)) & ((a.maand)=(d.maand)) & ((a.jaar)=(d.jaar)));
day_greater(a,d)::
{
if ((a.jaar)>(d.jaar), true,
if ((a.jaar)=(d.jaar),
if ((a.maand)>(d.maand), true,
if ((a.maand)=(d.maand),
(a.dag)>(d.dag),
false)),
false))
};
nextday(day)::
{
d:(day.dag)+1;
m:day.maand;
j:day.jaar;
if (d>monthtab[m],
{d:=1;
m:=m+1});
if (m>12,
{m:=1;
j:=k+1});
makeday(d,m,j)
};
days:[];
save_sched()::saveexp(days,agentself,"schedule.exp");
load_sched()::
{
display("loading the last known schedule",eoln);
newdays:loadexp(agentself,"hborg/schedule.exp");
if(is_void(newdays),
{display("failed",eoln); false},
{days:=newdays; true})
};
findday(d)::
{
D:void;
for(i:1,i<=size(days),i:=i+1,
if (day_equals(d,days[i]), D:=days[i]));
D
};
checkcalendar()::
{
`check wether the current day is in the list or not...
`remove all old days
currentdate:date();
today:makeday(currentdate[1],currentdate[2],currentdate[3]);
x:nrofdays:1;
found:false;
while(xvoid,
{
nrofdays:=nrofdays+1;
found := found | day_equals(today,days[x])
});
x:=x+1
});
`calculate the size of the new array
if (!found, nrofdays:=nrofdays+1);
if (nrofdays<14, nrofdays:=14);
`allocate the new array, and say how to write
tays[nrofdays]:void;
writingat:1;
todayinserted:false;
lastwritten:void;
write(d)::
{
if ((!todayinserted) & (!found) & day_greater(d,today),
{tays[writingat]:=today;
todayinserted:=true;
writingat:=writingat+1});
tays[writingat]:=d;
lastwritten:=d;
writingat:=writingat+1
};
`copy all existing days
for(readingat:1,readingat1,
{
d:days[readingat];
if (!is_void(d),write(d))
});
`insert today if necesary
if ((!todayinserted) & (!found),
{write(today);
todayinserted:=true});
`insert next days till end of matrix
while(writingat<=nrofdays,
write(nextday(lastwritten)));
`reasign days
days:=tays
};
` ----------------------------
` HTML OUTPUT
` ----------------------------
pagetext:"";
cleartext()::pagetext:="";
flushtext(to)::{to->display(pagetext); cleartext()};
disp(txt)::pagetext := pagetext + text(txt);
href(anker,txt)::"+anker+'"'+">"+txt+"";
appointement_html(obj,url)::
{
if ((obj.color)=FREE,"",
if ((obj.color)=JETTE," | ",
if ((obj.color)=VUB," | ",
if ((obj.color)=AWAY," | ",
if ((obj.color)=HOME," | ",
if ((obj.color)=TRAVEL," | ",<"td bgcolor=#000000>"))))))+
href(url,".")+(obj.str)+" | "
};
day_url_html(day)::"get"+MAINURL+"?DAY="+text(day.dag)+"&MONTH="+text(day.maand)+"&YEAR="+text(day.jaar);
day_html(day)::
{
header:text(day.dag)+"/"+text(day.maand)+"/"+text(day.jaar);
href(day_url_html(day),header)
};
printheader()::
{
disp("Hello "
+NAME+"I'm agent "+text(agentname));
disp("
Please feel free to debug me :-)
")
};
printcalendar()::
{
disp("");
disp("Uur | ");
x:1;
while(x<=size(days),
{
day:days[x];
disp(""+day_html(day)+" | ");
x := x + 1
});
disp("
"+eoln);
uur:1;
while(uur<=(STOP-START),
{
disp("");
disp(href("get"+MAINURL+"?FROM="+text(START-1+uur),text(START-1+uur)+" - "+text(START+uur)));
disp(" | ");
x : 1;
while(x<=size(days),
{
day:days[x];
uren:day.uren;
appointement:uren[uur];
url:day_url_html(day)+"&FROM="+text(START-1+uur);
disp(appointement_html(appointement,url));
x := x + 1
});
uur := uur + 1;
disp("
")
});
disp("
")
};
printform(formdata)::
{
txt(t):: if (is_void(t), "",
if (is_number(t), text(t), t));
disp("