(* camlp4r ./pa_html.cmo *)
(* $Id: birthday.ml,v 4.11 2004/12/14 09:30:10 ddr Exp $ *)
(* Copyright (c) 1998-2005 INRIA *)
open Def;
open Config;
open Util;
open Gutil;
type date_event = [ DeBirth | DeDeath of death_reason ];
value print_anniversary_day conf base dead_people liste =
do {
Wserver.wprint "
\n";
List.iter
(fun (p, a, date_event, txt_of) ->
let is = index_of_sex p.sex in
do {
html_li conf;
Wserver.wprint "%s\n" (txt_of conf base p);
if not dead_people then Wserver.wprint " %d\n" a
else
let txt =
match date_event with
[ DeBirth -> transl_nth conf "born" is
| DeDeath Unspecified -> transl_nth conf "died" is
| DeDeath Killed -> transl_nth conf "killed (in action)" is
| DeDeath Murdered -> transl_nth conf "murdered" is
| DeDeath Executed ->
transl_nth conf "executed (legally killed)" is
| DeDeath Disappeared -> transl_nth conf "disappeared" is ]
in
Wserver.wprint ", %s %s %d\n" txt
(transl conf "in (year)") a;
})
liste;
Wserver.wprint "
\n";
}
;
value gen_print conf base mois f_scan dead_people =
let tab = Array.create 31 [] in
let title _ =
let lab =
if dead_people then transl conf "anniversaries"
else transl conf "birthdays"
in
Wserver.wprint "%s %s" (capitale lab)
(nominative (transl_nth conf "(month)" (mois - 1)))
in
do {
try
while True do {
let (p, txt_of) = f_scan () in
if not dead_people then
match (Adef.od_of_codate p.birth, p.death) with
[ (Some (Dgreg d _), NotDead | DontKnowIfDead) ->
if d.prec = Sure && d.day <> 0 && d.month <> 0 &&
d.month = mois && d.delta = 0 then
if authorized_age conf base p then
let j = d.day in
tab.(pred j) :=
[(p, d.year, DeBirth, txt_of) :: tab.(pred j)]
else ()
else ()
| _ -> () ]
else
match p.death with
[ NotDead | DontKnowIfDead -> ()
| _ ->
do {
match Adef.od_of_codate p.birth with
[ Some (Dgreg dt _) ->
if dt.prec = Sure && dt.day <> 0 && dt.month <> 0 &&
dt.month = mois && dt.delta = 0 then
if authorized_age conf base p then
let j = dt.day in
tab.(pred j) :=
[(p, dt.year, DeBirth, txt_of) :: tab.(pred j)]
else ()
else ()
| _ -> () ];
match p.death with
[ Death dr d ->
match Adef.date_of_cdate d with
[ Dgreg dt _ ->
if dt.prec = Sure && dt.day <> 0 && dt.month <> 0 &&
dt.month = mois && dt.delta = 0 then
if authorized_age conf base p then
let j = dt.day in
let a = dt.year in
tab.(pred j) :=
[(p, a, DeDeath dr, txt_of) :: tab.(pred j)]
else ()
else ()
| _ -> () ]
| _ -> () ];
} ]
}
with
[ Not_found -> () ];
header conf title;
print_link_to_welcome conf True;
Wserver.wprint "
\n";
for j = 1 to 31 do {
if tab.(pred j) <> [] then do {
html_li conf;
Wserver.wprint "%d\n" j;
let liste =
Sort.list (fun (p1, a1, _, _) (p2, a2, _, _) -> a1 <= a2)
tab.(pred j)
in
print_anniversary_day conf base dead_people liste;
}
else ()
};
Wserver.wprint "
\n";
trailer conf;
}
;
value print_anniversary_list conf base dead_people dt liste =
let a_ref = dt.year in
do {
Wserver.wprint "
\n";
List.iter
(fun (p, a, date_event, txt_of) ->
do {
html_li conf;
if dead_people then do {
Wserver.wprint "";
match date_event with
[ DeBirth -> Wserver.wprint "%s" (transl conf "birth")
| DeDeath _ -> Wserver.wprint "%s" (transl conf "death") ];
Wserver.wprint "\n";
Wserver.wprint "-> ";
Wserver.wprint "%s" (txt_of conf base p);
Wserver.wprint "\n%s %d" (transl conf "in (year)") a;
Wserver.wprint " (";
Wserver.wprint (ftransl conf "%d years ago")
(conf.today.year - a);
Wserver.wprint ")";
}
else do {
Wserver.wprint "\n%s" (txt_of conf base p);
match p.death with
[ NotDead ->
do {
Wserver.wprint " ";
match a_ref - a with
[ 0 -> Wserver.wprint "%s" (transl conf "birth")
| 1 -> Wserver.wprint "%s" (transl conf "one year old")
| n ->
Wserver.wprint "%d %s" n (transl conf "years old") ];
Wserver.wprint "";
}
| _ -> () ];
};
Wserver.wprint "\n";
})
liste;
Wserver.wprint "
\n";
}
;
value f_scan conf base =
let i = ref (-1) in
fun () ->
do {
incr i;
if i.val < base.data.persons.len then
(pget conf base (Adef.iper_of_int i.val),
referenced_person_title_text)
else raise Not_found
}
;
value print_birth conf base mois =
gen_print conf base mois (f_scan conf base) False
;
value print_dead conf base mois =
gen_print conf base mois (f_scan conf base) True
;
value print_birth_day conf base day_name verb wd dt list =
do {
Wserver.wprint "\n";
html_p conf;
match list with
[ [] ->
Wserver.wprint "%s %s.\n" (capitale (transl conf "no birthday"))
day_name
| _ ->
do {
Wserver.wprint "%s,\n" (capitale day_name);
Wserver.wprint "%s%s\n"
(std_color conf
("" ^
transl_decline conf "on (weekday day month year)"
(transl_nth conf "(week day)" wd ^ " " ^
Date.code_dmy conf dt) ^
""))
verb;
Wserver.wprint "%s\n"
(transl_a_of_b conf (transl conf "the birthday") "...");
print_anniversary_list conf base False dt list;
} ]
}
;
value propose_months conf mode =
tag "center" begin
tag "form" "method=get action=\"%s\"" conf.command begin
Util.hidden_env conf;
mode ();
tag "select" "name=v" begin
for i = 1 to 12 do {
Wserver.wprint "