:- ensure_loaded(common).
:- rdf_register_ns(ws, 'http://www.w3.org/2004/12/rules-ws/terms#').

%  This isn't really a part of Ontaria/Semwalker at all, but ... ummm
%  putting it here is the easiest thing for me!
%
%            -- sandro
%
%
% :- discontiguous title/2, org/3.

:- asserta(user:file_search_path(submissions, '/u/home/sandro/cvs/cvs.w3.org/WWW/2004/12/rules-ws/submissions')).

:- ensure_loaded(library(odbc)).
:- ensure_loaded(submissions('data.pl')).
:- ensure_loaded(submissions('titles.pl')).
:- ensure_loaded(submissions('rsvp.pl')).
:- ensure_loaded(html).

c1 :-
	open('/home/sandro/wbs-password', read, PWFile),
	read_term(PWFile, Password, []),
	odbc_connect('WBS', _, [alias(db), password(Password)]),
	close(PWFile).

:- c1.

accept(X) :-
	odbc_query(db, 'select b.who, c.QaireNo, b.rationale, c.value from ballots as b, ballotsperChoice as c where c.WGid=37327 and b.WGid=37327 and b.QaireNo=c.QaireNo and b.QNo=c.QNo and c.QaireNo != \'mt1\' and c.QNo = \'accept\' and c.choiceid=\'1\' and b.vorgid=c.vorgid', X1, []),
	decode_accept_level(X1, X).

presentq(X) :-
	odbc_query(db, 'select b.who, c.QaireNo, b.rationale, c.value from ballots as b, ballotsperChoice as c where c.WGid=37327 and b.WGid=37327 and b.QaireNo=c.QaireNo and b.QNo=c.QNo and c.QaireNo != \'mt1\' and c.QNo = \'present\' and c.choiceid=\'pres\' and b.vorgid=c.vorgid', X1, []),
	decode_accept_level(X1, X).

decode_accept_level(row(A,B,C,D1), row(A,B,C,D2)) :-
	accept_coding(D1, D2).

accept_coding('000001', 6).
accept_coding('000010', 5).
accept_coding('000100', 4).
accept_coding('001000', 3).
accept_coding('010000', 2).
accept_coding('100000', 1).

catq(Qno, X) :-
	odbc_query(db, 'select b.who, c.QaireNo, b.rationale, c.value from ballots as b, ballotsperChoice as c where c.WGid=37327 and b.WGid=37327 and b.QaireNo=c.QaireNo and b.QNo=c.QNo and c.QaireNo != \'mt1\' and c.QNo = \'~a\' and b.vorgid=c.vorgid'-[Qno], X, []).


reviewed(ReviewerNumber, PaperNumber, Answer) :-
	accept(row(Who, What, _, Answer)),
	reviewer_account(ReviewerNumber, Who),
	paper_str_number(What, PaperNumber).

present(ReviewerNumber, PaperNumber, Answer, Rationale) :-
	presentq(row(Who, What, Rationale, Answer)),
	reviewer_account(ReviewerNumber, Who),
	paper_str_number(What, PaperNumber).

present(ReviewerNumber, PaperNumber, Answer) :-
	presentq(row(Who, What, _, Answer)),
	reviewer_account(ReviewerNumber, Who),
	paper_str_number(What, PaperNumber).

paper_str_number(S, N) :-
	atom_concat('paper_', NA, S),
	atom_number(NA, N).

%  don't look too closely, this is quick-and-dirty code.   there are
%  much better ways to do the html and url stuff...

:- [time_conversions].
:- [write_to_atom].

goodmail(PaperNumber, Email, Name, _, MsgId) :-
	mail(PaperNumber, Email, Name, _, MsgId),
	\+bad(PaperNumber,_).
goodmail(PaperNumber, Email, Name, _, '') :-
	talk_presenter(PaperNumber, Email, Name).

domain(Email, Domain) :-
	concat_atom([_, Domain], '@', Email).

namekey(Full, Key) :-
	concat_atom(Parts, ' ', Full),
	reverse(Parts, Key).


pc_home_page :-
	absolute_file_name(submissions('Overview.html'), Filename),
	open(Filename, write, Out),
	pc_home_page(Out),
	close(Out).

% deprecated version
reviewer_view(ReviewerNumber) :-
	reviewer(ReviewerNumber, ReviewerName),
	H = [ h3('Reviewer: ', ReviewerName),
	      table(tr(th(colspan='1', 'Submitting Author'),
		       th(colspan='3', 'Links'),
		       th(colspan='2', 'Status')),
		    +forall(paper_reviewer(PaperNumber, ReviewerNumber),
			    +paper_view_1(ReviewerNumber, PaperNumber))
		   )
	    ],
	write_html(H).

reviewer_view(_Q, ReviewerNumber, H) :-
	reviewer(ReviewerNumber, ReviewerName),
	H = [ h3('Reviewer: ', ReviewerName),
	      table(tr(th(colspan='1', 'Submitting Author'),
		       th(colspan='3', 'Links'),
		       th(colspan='2', 'Status')),
		    +forall(paper_reviewer(PaperNumber, ReviewerNumber),
			    +paper_view_1(ReviewerNumber, PaperNumber))
		   )
	    ].

paper_view_1(ReviewerNumber, PaperNumber, H) :-
	mail(PaperNumber, _Email, Name, _, MsgId),
	write_to_atom(PLink, format('http://www.w3.org/2004/12/rules-ws/submissions/~a/submission', [PaperNumber])),
	concat_atom(['http://www.w3.org/mid/', MsgId], ELink),
	write_to_atom(SLink, format('http://www.w3.org/2002/09/wbs/37327/paper_~a/', [PaperNumber])),
	accept_status(ReviewerNumber, PaperNumber, Accept_status),
	present_status(ReviewerNumber, PaperNumber, Present_status),
	H = tr(td(Name),
	       td(a(href=PLink, paper)),
	       td(a(href=ELink, email)),
	       td(a(href=SLink, 'review form')),
	       td(Accept_status),
	       td(Present_status)
	       ).

paper_view_2(_Q, PaperNumber, H) :-
	% http://www.w3.org/2002/09/wbs/37327/paper_82/results
	goodmail(PaperNumber, Email, Name, _, MsgId),
	H = tr(td(Name),
	       td(Email),
	       td(a(href=['http://www.w3.org/2004/12/rules-ws/submissions/',
			  PaperNumber, '/submission'], paper)),
	       td(a(href=['http://www.w3.org/mid/', MsgId], email)),
	       td(a(href=['http://www.w3.org/2002/09/wbs/37327/paper_',
			  PaperNumber, '/results'], 'survey results')),
	       +findall(td(ReviewerName, ': ', Status),
			(   paper_reviewer(PaperNumber, ReviewerNumber),
			    reviewer(ReviewerNumber, ReviewerName),
			    (  reviewed(ReviewerNumber, PaperNumber, StatusCode)
			    -> decode99(StatusCode, Status)
			    ;  Status = ' not reviewed '
			    )
			))
	      ).

accept_status(ReviewerNumber, PaperNumber, Status) :-
	(   reviewed(ReviewerNumber, PaperNumber, StatusCode)
	->  decode99(StatusCode, Status)
	;   Status=' -- '
	).
present_status(ReviewerNumber, PaperNumber, Status) :-
	(   present(ReviewerNumber, PaperNumber, StatusCode)
	->  decode9x(StatusCode, Status)
	;   Status=' -- '
	).

decode99(1, span(class='rej', 'reject (important)')).
decode99(2, span(class='rej', 'reject (recommended)')).
decode99(3, span(class='help', 'find other')).
decode99(4, span(class='acc', 'accept (recommended)')).
decode99(5, span(class='acc', 'accept (important)')).
decode99(6, span(class='help', 'not answered')).

decode9x(1, span(class='prej', ' ')).
decode9x(2, span(class='prej', ' ')).
decode9x(3, span(class='pacc4', 'maybe...')).
decode9x(4, span(class='pacc4', 'present (recommended)')).
decode9x(5, span(class='pacc5', 'present (important)')).
decode9x(6, span(class='phelp', 'not answered')).

	
%			      format(Out, '<tr><td>~a</td><td>~a</td><td><a href="http://www.w3.org/2004/12/rules-ws/submissions/~a/submission">paper</a></td><td><a href="http://www.w3.org/mid/~a">email</a></td><td><a href="http://www.w3.org/2002/09/wbs/37327/paper_~a/">review form</a></td></tr>~n', [Name,Email,PaperNumber,MsgId,PaperNumber])


	       
pc_home_page(Out) :-
	head(Out),
	format(Out,'<h2 id="by_reviewer">3.  By Reviewer</h2>', []),
	forall(reviewer(ReviewerNumber, _),
	       reviewer_view(ReviewerNumber)
	      ),
	format(Out, '<p></p><h2 id="by_author">4.  By Author</h2><table>', []),
	findall(key(Key, goodmail(PaperNumber, Email, Name, _, MsgId)),
		(   goodmail(PaperNumber, Email, Name, _, MsgId),
		    namekey(Name, Key)
		),
		S),
	sort(S, SS),
	forall(member(key(_, goodmail(PaperNumber, Email, Name, _, MsgId)), SS),
	       (   reviewer_names(PaperNumber, ReviewerNames),
		   format(Out, '<tr><td>~a</td><td>~a</td><td><a href="http://www.w3.org/2004/12/rules-ws/submissions/~a/submission">paper</a></td><td><a href="http://www.w3.org/mid/~a">email</a></td><td>~a</td></tr>~n', [Name,Email,PaperNumber,MsgId,ReviewerNames])
	       )),
	format(Out, '</table>', []),
	length(SS, Count),
	format(Out, '<p>Total: ~a position papers</p>', [Count]),
	foot(Out).
			  

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	       

paper_reviewer_count(P, N) :-
	goodmail(P, _, _, _, _),
	findall(x, paper_reviewer(P, _), L),
	length(L, N).

reviewer_paper_count(R, C) :-
	reviewer(R, _),
	findall(x, paper_reviewer(_, R), L),
	length(L, C).

most_free_reviewer(R) :-
	findall(cr(C, R), reviewer_paper_count(R, C), L),
	sort(L, LS),
	member(cr(_, R), LS).

assign_reviewers :-
	forall((   paper_reviewer_count(P, N),
		   N < 2
	       ),
	       (   most_free_reviewer(R),
		   \+ avoid_reviewer(P, R),
		   \+ paper_reviewer(P, R),   % don't repeat the pairing
		   assert(paper_reviewer(P, R)),
		   format('~q.~n', [paper_reviewer(P, R)])
	       )).


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

set_up_all_forms :-
	forall(goodmail(I, _, _, _, _),
	       gen_lines(I)).

:- dynamic(id/1).

reviewer_names(PaperNumber, ReviewerNames) :-
	findall(ReviewerName,
		(   paper_reviewer(PaperNumber, ReviewerNumber),
		    reviewer(ReviewerNumber, ReviewerName)
		),
		Names),
	concat_atom(Names, ', ', ReviewerNames).

set_up_form(I) :-
	create_questionaire(I),
	set_title(I),
	set_intro(I).

get_id(Id) :-
	(   id(Id)
	->  true
	;   format('please do: assert(id(\'login:pw\'))~n', []),
	    fail
	).
	
% copy "sample_review" to a new questionaire, id "paper<N>"
create_questionaire(I) :-
	get_id(Id),
	qshell_format('echo \'wgid=37327&qaireno=paper_~a&uri=http%3A%2F%2Fwww.w3.org%2F2002%2F09%2Fwbs%2F37327%2Fsample_review%2F\' | lwp-request -s -d -C ~a -m POST http://www.w3.org/2002/09/wbs/37327/factory~n', [I, Id]).

% change the title
set_title(I) :-
	get_id(Id),
	get_time(Now),
	squished_isotime(Now, Date),
	goodmail(I, _, Author, _, _),
	reviewer_names(I, Reviewers),
	qshell_format('echo \'wgid=37327&qairedupd=~a&startdate=2005-03-20&closedate=2005-04-01&shortdesc=Paper Review, Author: ~a, Reviewers: ~a&voterBehalf=individual&resultsACL=group&emailNotif=&params %5BemailCC%5D=&seqno%3Aintro=10&seqno%3Acat=20&seqno%3Ausecases=30&seqno%3Acantechs=40&seqno%3AOther=50&seqno%3Aaccept=60&seqno%3Apresent=70&action=submit\' | lwp-request -s -d -C ~a -m POST http://www.w3.org/2002/09/wbs/37327/paper_~a/handler~n', [Date, Author, Reviewers, Id, I]).

set_intro(PaperNumber) :-
	get_id(Id),
	goodmail(PaperNumber, Email, Name, _, MsgId),
	reviewer_names(PaperNumber, ReviewerNames),
	write_to_atom(Intro, format('<p>&nbsp;</p><table><tr><th style="padding: 4px 1em">Author</th><td style="padding: 4px 1em; background: #ccc"><strong>~a</strong> &lt;~a&gt;</td></tr><tr><th style="padding: 4px 1em">Paper</th><td style="padding: 4px 1em;"><a href="http://www.w3.org/2004/12/rules-ws/submissions/~a/submission">paper itself</a>, <a href="http://www.w3.org/mid/~a">submission email</a></td></tr><tr><th style="padding: 4px 1em">Reviewers</th><td style="padding: 4px 1em;">~a</td></tr></table>~n', [Name,Email,PaperNumber,MsgId,ReviewerNames])),
	www_form_encode(Intro, IntroEncoded),
	qshell_format('echo \'shortdesc=Paper+Being+Reviewed&question=~a&action=submit\' | lwp-request -s -d -C ~a -m POST http://www.w3.org/2002/09/wbs/37327/paper_~a/q/intro/~n', [IntroEncoded,Id,PaperNumber]).


broken__q_delete(PaperNumber) :-
	get_id(Id),
	qshell_format('echo \'moved=&confirm=on&qaireno=paper_~a&wgid=37327&action=Delete\' | lwp-request -s -d -C ~a -m POST http://www.w3.org/2002/09/wbs/37327/factory~n', [PaperNumber,Id]).

	
% simple not-thread-safe version
qshell_format(Format, Args) :-
	sformat(String, Format, Args),
	string_to_atom(String, Atom),
	debug(shell, 'shell cmd: ~a', [Atom]),
	shell(Atom).


head(Out) :-
	absolute_file_name(submissions('Overview-Head.html'), Filename),
	open(Filename, read, O),
	copy_stream_data(O, Out),
	close(O).

foot(Out) :-
	absolute_file_name(submissions('Overview-Foot.html'), Filename),
	open(Filename, read, O),
	copy_stream_data(O, Out),
	close(O).


web_server_page(rwspc, rwspc).

rwspc(Q) :-
	telling(Out),
	memberchk(request_id(ReqId), Q),
	ensure_content_type_sent(ReqId, 'text/html'),
	pc_home_page(Out),
	debug(rwspc, 'done', []).

web_server_page(rwspcAllReviewers, rwspcAllReviewers).

rwspcAllReviewers(Q) :-
	std_head(Q, Head, 'All Reviewers'),
	Body =[
		p('Nearby: ',
		  a(href='http://www.w3.org/2004/12/rules-ws/submissions/', 'PC Home Page'), ' | ',
		  a(href='AllPapers', 'Papers by Acceptance'), ' | ',
		  a(href='AllPapers1', 'Single Table of Papers'), ' | ',
		  a(href='Categories', 'Use Cases Etc')
		 ),

	       h2(id='by_reviewer', 'By Reviewer'),
		
		+forall(reviewer(ReviewerNumber, _),
			+reviewer_view(Q, ReviewerNumber)
		       )
	      ],
	write_html(html(head(Head), body(Body))).

web_server_page(rwspcAllPapers, rwspc_papers).
web_server_page(rwspcAccepted, rwspcAccepted).
web_server_page(rwspcaccepted, rwspcAccepted).

rwspcAccepted(Q) :-
	std_head(Q, Head, 'Accepted Papers'),
	findall(key(Key, PaperNumber),
		(   accept_paper(PaperNumber),
		    goodmail(PaperNumber, _, Name, _, _),
		    namekey(Name, Key)
		),
		S),
	sort(S, SS),
	length(SS, Count),
	Totals = p('Total: ', int(Count), ' position papers accepted'),
	Body =[ h2('Accepted Papers'),
		p('See: ', a(href='http://www.w3.org/2004/12/rules-ws', 'Workshop Site')),
		table(tr(th(' '),
			 th(colspan=2, 'Submitting Author'),
			 th('Position Paper Title')
			),
		      +forall(member(key(_, PaperNumber), SS),
			      +paper_row_view(Q, PaperNumber, Index),
			      [count(Index)]
			     )
		     ),
		Totals
	      ],
	write_html(html(head(Head), body(Body))).

obfus(E, E2) :-
	concat_atom(Parts, '@', E),
	concat_atom(Parts, ' (at) ', E2).

paper_row_view(_Q, PaperNumber, Index, H) :-
	goodmail(PaperNumber, Email, Name, _, _MsgId),
	% reviewer_names(PaperNumber, ReviewerNames),
	obfus(Email, EmailObs),
	(  title(PaperNumber, Title)
	-> true
	;  Title='untitled'
	),
	H = tr(td(int(Index)),
	       td(Name),
	       td(EmailObs),
	       td(a(href=['http://www.w3.org/2004/12/rules-ws/paper/',
			  PaperNumber], Title)) %,
	       %td(a(href=['http://www.w3.org/mid/', MsgId], email)),
	       %td(ReviewerNames)
	      ).


web_server_page(rwspcCategories, rwspcCategories).

std_head(Q, Head, Title) :-
	memberchk(request_id(ReqId), Q),
	ensure_content_type_sent(ReqId, 'text/html'),
	Head = [title(Title),
		link(rel='stylesheet', href='http://www.w3.org/StyleSheets/base.css'),
		link(rel='stylesheet', href='http://www.w3.org/2004/12/rules-ws/style.css')
	       ].
	
rwspcCategories(Q) :-
	std_head(Q, Head, 'All Categories'),
	Body =[ h2('Categories'),
		p('Nearby: ',
		  a(href='http://www.w3.org/2004/12/rules-ws/submissions/', 'PC Home Page'), ' | ',
		  a(href='AllReviewers', 'By Reviewers'), ' | ', 
		  a(href='AllPapers', 'Papers by Acceptance'), ' | ',
		  a(href='AllPapers1', 'Single Table of Papers')
		 ),
		h3('Use Cases'),
		+category(Q, usecases),
		h3('Candidate Technologies'),
		+category(Q, cantechs),
		h3('Other'),
		+category(Q, 'Other')
	      ],
	write_html(html(head(Head), body(Body))).

category(Q, Qno, H) :-
	findall(r(Key, Text, Who, Num),
		(   catq(Qno, row(Who, What, _, Text)),
		    paper_str_number(What, Num),
		    goodmail(Num, _, _, _, _),
		    Text \= '',
		    upcase_atom(Text, Key)
		),
		L),
	sort(L, LS),
	H = [ table(+forall(member(r(_, Text, Who, Num), LS),
			    tr(td(Text),
			       td(+paper_word(Q, Num)),
			       td(Who))
			   ))
	    ].


paper_word(_Q, Num, H) :-
	goodmail(Num, _, Name, _, _),
	H=a(href=['paper/', Num], Name).


web_server_page(rwspcpaper, rwspcpaper).

rwspcpaper(Q) :-
	memberchk(path(Path), Q),
	concat_atom([_,_,PaperAtom], '/', Path),
	atom_number(PaperAtom, Num),
	goodmail(Num, _, Name, _, _),
	Title = ['Paper ', int(Num), ', from ', Name],
	std_head(Q, Head, Title),
	Body =[ h2(Title),
		table(+paper_row_view(Q, Num)),
		p('... more details would be good, eh?')
		],
	write_html(html(head(Head), body(Body))).

web_server_page(rwspc_papers, rwspc_papers).

rwspc_papers(Q) :-
	Title = 'Workshop Papers (By Acceptance Status)',
	std_head(Q, Head, Title),
	Body =[ h1(Title),
		p('Nearby: ',
		  a(href='http://www.w3.org/2004/12/rules-ws/submissions/', 'PC Home Page'), ' | ',
		  a(href='AllReviewers', 'By Reviewers'), ' | ',
		  a(href='AllPapers1', 'Single Table of Papers'), ' | ',
		  a(href='Categories', 'Use Cases Etc')
		 ),
		+paper_set(Q, 'Accepted By Both Reviewers'),
		+paper_set(Q, 'Reviewers Disagree'),
		+paper_set(Q, 'Rejected By Both Reviewers'),
		+paper_set(Q, 'Only One Review (Accept)'),
		+paper_set(Q, 'Only One Review (Reject)'),
		+paper_set(Q, 'Not Reviewed'),
	        +paper_set(Q, 'Other')
		],
	write_html(html(head(Head), body(Body))).


paper_set(Q, 'Other', H) :-
	H = [ h2('Other'),
	      table(+findall(key(x, +paper_view_2(Q, Num)),
			     ( 	 goodmail(Num, _, _, _, _),
				 \+ paper_instance(_, Num)
			     ),
			     [count(Count)]
			    )
		   ),
	      p(int(Count), ' papers in this category.')
	    ].
paper_set(Q, Title, H) :-
	H = [ h2(Title),
	      table(+findall(key(x, +paper_view_2(Q, Num)),
			     paper_instance(Title, Num),
			     [count(Count)]
			    )
		   ),
	      p(int(Count), ' papers in this category.')
	    ].

review_codes(PaperNumber, Codes) :-
	goodmail(PaperNumber, _, _, _, _),
	findall(StatusCode,
		reviewed(_ReviewerNumber, PaperNumber, StatusCode),
		Codes).
paper_instance('Accepted By Both Reviewers', PaperNumber) :-
	review_codes(PaperNumber, L),
	L = [N1, N2],
	accept_code(N1),
	accept_code(N2).
paper_instance('Reviewers Disagree', PaperNumber) :-
	review_codes(PaperNumber, L),
	L = [N1, N2],
	(  accept_code(N1), reject_code(N2)
	;  reject_code(N1), accept_code(N2)
	).
paper_instance('Rejected By Both Reviewers', PaperNumber) :-
	review_codes(PaperNumber, L),
	L = [N1, N2],
	reject_code(N1),
	reject_code(N2).
paper_instance('Only One Review (Accept)', PaperNumber) :-
	review_codes(PaperNumber, L),
	L = [N],
	accept_code(N).
paper_instance('Only One Review (Reject)', PaperNumber) :-
	review_codes(PaperNumber, L),
	L = [N],
	reject_code(N).
paper_instance('Not Reviewed', PaperNumber) :-
	review_codes(PaperNumber, L),
	L = [].
%paper_instance('Other', PaperNumber) :-
%	% negation loop!   :-)
%	\+ paper_instance(X, PaperNumber),
%	X \= 'Other'.


accept_code(4).
accept_code(5).
reject_code(1).
reject_code(2).

web_server_page(rwspcPresent1, rwspcPresent).

presentation_score(PaperNumber, Score, Count) :-
	findall(Score,
		(   present(_ReviewerNumber, PaperNumber, AScore, _),
		    (   AScore = 6
		    ->  Score = 3
		    ;   Score = AScore
		    )
		),
		L),
	sumlist(L, Sum),
	length(L, Count),
	(  Count = 0
	->  Score = 0
	;   Score is Sum / Count
	).

rwspcPresent(Q) :-
	std_head(Q, Head, 'All Papers, By Presentation Status'),
	findall(key(Key, Count, PaperNumber),
		(   goodmail(PaperNumber, _, _, _, _),
		    presentation_score(PaperNumber, Key, Count)
		),
		S),
	sort(S, SS),
	length(SS, Count),
	reverse(SS, SSR),
	Totals = p('Total: ', int(Count), ' position papers'),
	Body =[ h2('All Papers, By Presentation Status'),
		table(tr(th('Num'),
			 th(colspan='2', 'Submitting Author'),
			 th(colspan='3', 'Links'),
			 th('Avg Present Score'),
			 th('Number of Reviews')
			),
		      +forall(member(key(Score, ICount, PaperNumber), SSR),
			      +paper_view_3(Q, Score, ICount, PaperNumber, Index),
			      [count(Index)]
			     )
		     ),
		Totals
	      ],
	write_html(html(head(Head), body(Body))).

paper_view_3(_Q, Score, Count, PaperNumber, Index, H) :-
	goodmail(PaperNumber, Email, Name, _, MsgId),
	H = tr(td(int(Index)),
	       td(Name),
	       td(Email),
	       td(a(href=['http://www.w3.org/2004/12/rules-ws/submissions/',
			  PaperNumber, '/submission'], paper)),
	       td(a(href=['http://www.w3.org/mid/', MsgId], email)),
	       td(a(href=['http://www.w3.org/2002/09/wbs/37327/paper_',
			  PaperNumber, '/results'], 'survey results')),
	       td(float(Score, 2)),
	       td(int(Count))

%	       +findall(td(ReviewerName, ': ', Status),
%			(   paper_reviewer(PaperNumber, ReviewerNumber),
%			    reviewer(ReviewerNumber, ReviewerName),
%			    (  reviewed(ReviewerNumber, PaperNumber, StatusCode)
%			    -> decode99(StatusCode, Status)
%			    ;  Status = ' not reviewed '
%			    )
%			))
	      ).


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

web_server_page(rwspcPresent, rwspcPresent2).


presentation_score2(PaperNumber, Score) :-
	findall(k(Score, Rationale),
		(   present(_ReviewerNumber, PaperNumber, Score, Rationale),
		    Score \= 6
		),
		L),
	sort(L, LS),
	reverse(LS, Score).

rwspcPresent2(Q) :-
	std_head(Q, Head, 'All Papers, By Presentation Status'),
	findall(key(Key, PaperNumber),
		(   goodmail(PaperNumber, _, _, _, _),
		    presentation_score2(PaperNumber, Key)
		),
		S),
	sort(S, SS),
	length(SS, Count),
	reverse(SS, SSR),
	Totals = p('Total: ', int(Count), ' position papers'),
	Body =[ h2('All Papers, By Presentation Status'),
		table(tr(th('Num'),
			 th(colspan='1', 'Submitting Author'),
			 th(colspan='3', 'Links'),
			 th('Avg Present Score'),
			 th('Rationale(s)')
			),
		      +forall(member(key(ScoreBundle, PaperNumber), SSR),
			      +paper_view_4(Q, ScoreBundle, 2, PaperNumber, Index),
			      [count(Index)]
			     )
		     ),
		Totals
	      ], 
	write_html(html(head(Head), body(Body))).



paper_view_4(_Q, ScoreBundle, _Count, PaperNumber, Index, H) :-
	goodmail(PaperNumber, Email, Name, _, MsgId),
	% format(user_error, '~q~n', ScoreBundle),
	findall(X,
		member(k(X, _), ScoreBundle),
		ScoreList),
	concat_atom(ScoreList, ', ', ScoreAtom),
	findall(li(X),
		member(k(_, X), ScoreBundle),
		Rationales),
	H = tr(td(int(Index)),
	       td(Name, br([]), Email),
	       td(a(href=['http://www.w3.org/2004/12/rules-ws/submissions/',
			  PaperNumber, '/submission'], paper)),
	       td(a(href=['http://www.w3.org/mid/', MsgId], email)),
	       td(a(href=['http://www.w3.org/2002/09/wbs/37327/paper_',
			  PaperNumber, '/results'], 'survey results')),
	       td(ScoreAtom),
	       td(ul(Rationales))

%	       +findall(td(ReviewerName, ': ', Status),
%			(   paper_reviewer(PaperNumber, ReviewerNumber),
%			    reviewer(ReviewerNumber, ReviewerName),
%			    (  reviewed(ReviewerNumber, PaperNumber, StatusCode)
%			    -> decode99(StatusCode, Status)
%			    ;  Status = ' not reviewed '
%			    )
%			))
	      ).



web_server_page(rwspcProgram, rwspcProgram).

rwspcProgram(Q) :-
	std_head(Q, Head, 'Program'),
	Body =[ div(class=head,
		    
		    h1('Workshop Program'),
		    p('See: ', a(href='http://www.w3.org/2004/12/rules-ws', 'Workshop Site')),
		    p('See also the list of all ', a(href='accepted', 'accepted papers'), '.')
		    ),
	        h2('Day 1 (Wednesday, 27 April 2005)'),
		+day_table(1),
		h2('Day 2 (Thursday, 28 April 2005)'),
		+day_table(2),
		p('$Id: workshop_support.pl,v 1.10 2005/06/22 22:39:22 sandro Exp $')
	      ], 
	write_html(html(head(Head), body(Body))).

day_table(Day, H) :-
	H = [table(tr(th('Time'),
		     %th('End'),
		     th('Activity / Session')
		    ),
		  +forall(session(Day, Start, _End, Text),
			  tr(td(align=right, valign=top, Start),
			     % td(align=right, End),
			     td(Text))
			 )
		  ),
	     p([])
	    ].

session(1, '7:30', '8:30', 'breakfast (provided)').
session(1, '8:30', '10:30', +g1).
session(1, '10:30', '11:00', break).
session(1, '11:00', '12:30', +g2).
session(1, '12:30', '1:30', 'lunch (provided)').
session(1, '1:30', '4:00', +g3).
session(1, '4:00', '4:30', break).
session(1, '4:30', '6:00', +g4).
session(1, '6:00', '', 'End of Day (dinner not provided)').

session(2, '7:30', '8:30', 'breakfast (provided)').
session(2, '8:30', '10:00', +g5).
session(2, '10:30', '10:30', break).
session(2, '11:00', '12:00', +g6).
session(2, '12:30', '1:00', 'lunch (provided)').
session(2, '1:30', '4:00', +g7).
session(2, '3:00', '4:30', break).
session(2, '3:30', '4:00', +g8).
session(2, '4:30', '4:30', 'short break').
session(2, '4:45', '6:00', +g9).
session(2, '6:00', '', 'End of Workshop').

g1([+session_title('Getting Acquainted'),
    br([]),
    % em('Goals: to familiarize everyone with the goals of the workshop and the general problem space.'),
    ul(li('Welcome'),
       li('Introductions'),
       +pres(35),
       % li('Eric Miller: ', em('Rules and the Semantic Web')),
       +pres(200),
       +pres(34),
       +discussion(1)
      ), +notes(1)]).

%
% 
%

g2([+session_title('General Requirements'),
    br([]),
    ul(+pres(61),
       % +pres(15),
       +pres(112),
       +pres(201),
       +discussion(2)
      ), +notes(2)]).

g3([   +session_title('Candidate Technologies - Part 1'),
       ul(+pres(44),
       +pres(96),
	  +pres(124),
       +pres(94),
       +pres(81),
       +discussion(3)
      ), +notes(3)]).


g4([+session_title('Standards Work'),
    ul(li('Production Rules',
	  ul(+pres(53),
	     +pres(107))
	 ),
       +pres(85),
       +discussion(4)
      )
   , +notes(4)]).

g5([+session_title('Use Cases - Part 1'),
    ul(+pres(64),
       +pres(46),
       +pres(18),
       +pres(74),
       +pres(54),
       +pres(36),
       +discussion(5) )
   , +notes(5)] ).

g6([+session_title('Use Cases - Part 2'), %  inforsense, ritter, deceker, prt,
    ul(+pres(31),
       +pres(101),
       +pres(17),
       +pres(113),
       +discussion(6))
   , +notes(6) ]
   ).

g7([
     +session_title('Candidate Technologies - Part 2'),
     ul(  +pres(103),
	  +pres(98),
	  +pres(93),
	  +discussion(7)
      ), +notes(7) ]).

g8([+session_title('Use Cases - Part 3'),
     ul(+pres(68),
	+pres(59),
	+pres(28),
	+discussion(8)
       ), +notes(8)]).

g9([+session_title('Closing Panel: What''s Next'),
    ul(
       li(a(href='http://www.w3.org/2004/12/rules-ws/panel','Panel Presentations'), p(em('Note: panel members were asked during lunch to prepare a list of three key features of this work - they had little time to prepare these "presentations"')))
      ,+discussion(9)
      
      ), +notes(9)]).


session_title(X, strong(X)).

pres(PaperNumber, Topic, H) :-
	goodmail(PaperNumber, Email, Name, _, _MsgId),
	retractall(e(Email)),
	assert(e(Email)),
	atom_concat('mailto:', Email, _Emailto),
	PaperURI = ['http://www.w3.org/2004/12/rules-ws/paper/',
		    PaperNumber],
	(   org(PaperNumber, Org1, U)
	->  Org = [a(href=U, Org1) ]
	    % Org = [', ', Org1 ]
	;   Org = ''
	),
	(   slides(PaperNumber, URI)
	->  SlidesLink = a(href=URI, slides)
	;   SlidesLink = 'no slides available'
	),
	H=tr(td(Topic),
	     td(Name),
	     td(Org),
	     td(a(href=PaperURI, 'Position Paper')),
	     td(SlidesLink)
	    ).

pres(XPaperNumber, li(H)) :-
	(   XPaperNumber = STag - PaperNumber
	->  Tag = [em('(', STag, ')'), ' ']
	;   XPaperNumber = PaperNumber,
	    Tag = ''
	),
	goodmail(PaperNumber, Email, Name, _, _MsgId),
	retractall(e(Email)),
	assert(e(Email)),
	atom_concat('mailto:', Email, _Emailto),
	PaperURI = ['http://www.w3.org/2004/12/rules-ws/paper/',
		    PaperNumber],
	(   talk_title(PaperNumber, Title1)
	->  Title = [a(href=PaperURI, paper), ' (', em(Title1), ')']
	;   Title = [a(href=PaperURI, paper)]
	),
	(   org(PaperNumber, Org1, U)
	->  Org = [', ', a(href=U, Org1) ]
	;   Org = ''
	),
	(   slides_uri(PaperNumber, URI)
	->  Slides = a(href=URI, 'presentation')
	;   Slides = strong('(slides not available)')
	),
	H = [Tag, Name, Org, ': ', Slides, ', ', Title ].

pres(N, li(H)) :-
	H = [ '<unknown paper: ', int(N), '>' ] .


accept_paper(PaperNumber) :-
	review_codes(PaperNumber, L),
	L = [N1, N2],
	accept_code(N1),
	accept_code(N2).
accept_paper(PaperNumber) :-
	review_codes(PaperNumber, L),
	L = [N],
	accept_code(N).
accept_paper(82).   % manual override after discussion
accept_paper(124).
accept_paper(125).
accept_paper(126).
accept_paper(127).
accept_paper(128).

notify_accepted(PaperNumber) :-
	goodmail(PaperNumber, Email, Name, _, _MsgId),
	format('PAPERNUMBER=~a EMAIL=~q NAME=~q . send_the_mail.sh~n',
	       [PaperNumber, Email, Name]).

notify_accepted :-
	forall(accept_paper(PaperNumber),
	       notify_accepted(PaperNumber)
	      ).


template_accepted(PaperNumber) :-
	goodmail(PaperNumber, Email, Name, _, _MsgId),
	format('prim(~a, ~q-~q).~n%waitlist(~a, \'\'-\'\').~nhotel(~q-~q, ).~n~n',
	       [PaperNumber, Name, Email, PaperNumber, Name, Email]).

template_accepted :-
	forall(accept_paper(PaperNumber),
	       template_accepted(PaperNumber)
	      ).



list_accepted :-
	forall(accept_paper(PaperNumber),
	       format('~a ', [PaperNumber])
	      ).


	
web_server_page(rwspcAttendees, rwspcAttendees).
web_server_page(rwspcregistered, rwspc_registered).

rwspc_registered(Q) :-
	std_head(Q, Head, 'Attendee List'),
	Body =[ div(class=head,
		    h2('People Present at the Workshop'),
		    p('See: ', a(href='http://www.w3.org/2004/12/rules-ws', 'Workshop Site'))
		   ),
		%p('Note: We have not yet received replies to some invitations.  A waiting list of additional people associated with accepted papers is being used when cancellations occur.  Please send questions or corrections to ', a(href='mailto:team-rule-language-workshop-chairs@w3.org', 'team-rule-language-workshop-chairs@w3.org'), '.'),

		+att
	      ],
	write_html(html(head(Head), body(Body))).
	
		
% these are what --- disjoint subclasses of WorkshopPerson?
rwspcAttendees(Q) :-
	std_head(Q, Head, 'Attendees'),
	Body =[ div(class=head,
		    h1('Attendees')),
		h2('Confirmed Primary'),
		+att(prim),
		h2('Confirmed Secondary'),
		+att(secondary),
		h2('Confirmed Special Cases'),
		+att(special),
		h2('No Response to Primary Invitation'),
		table(+forall(nprim(PaperNumber, Person),
			      +person_view(PaperNumber, Person, Index1),
			      [count(Index1)]
			     )
		     ),
		h2('No Response to Secondary Invitation'),
		table(+forall(invwaitlist(PaperNumber, Person, _),
			      +person_view(PaperNumber, Person, Index1a),
			      [count(Index1a)]
			     )
		     ),
		h2('No Response to Special Case Invitation'),
		table(+forall(nspecial(PaperNumber, Person),
			      +person_view(PaperNumber, Person, Index1b),
			      [count(Index1b)]
			     )
		     ),
		h2('Declined Invitation'),
		table(+forall(xprim(PaperNumber, Person),
			      +person_view(PaperNumber, Person, Index2),
			      [count(Index2)]
			     )
		     ),
		h2('Wait List (unordered)'),
		table(+forall(waitlist(PaperNumber, Person, _),
			      +person_view(PaperNumber, Person, Index3),
			      [count(Index3)]
			     )
		     ),
		h2('By Paper'),
		table(+forall(accept_paper(PaperNumber),
			      +paper_person_view(PaperNumber)
			     )
		     )
	      ],
	write_html(html(head(Head), body(Body))).

person_view(PaperNumber, Person, Index, H) :-
	Person = Name-Email,
	H=tr(td(int(Index)), td(Name), td(Email), td(int(PaperNumber))).

person_viewx(Person, Index, H) :-
	Person = Name-Email,
	H=tr(td(int(Index)), td(Name), td(Email)).

paper_person_view(PaperNumber, H):-
	H=div(style='margin-left:2em;',
	      h3('Paper: ', int(PaperNumber)),
		h4('Confirmed'),
		table(+forall(prim(PaperNumber, Person),
			      +person_view(PaperNumber, Person, Index),
			      [count(Index)]
			     )
		     ),
		h4('No Response to Invitation'),
		table(+forall(nprim(PaperNumber, Person),
			      +person_view(PaperNumber, Person, Index1),
			      [count(Index1)]
			     )
		     ),
		h4('Declined Invitation'),
		table(+forall(xprim(PaperNumber, Person),
			      +person_view(PaperNumber, Person, Index2),
			      [count(Index2)]
			     )
		     ),
		h4('Wait List (unordered)'),
		table(+forall(waitlist(PaperNumber, Person, _),
			      +person_view(PaperNumber, Person, Index3),
			      [count(Index3)]
			     )
		     )
	     ).
		     

personkey(Name-_Email, Key) :-
	namekey(Name, Key).

att(F, H) :-
	findall(key(Key, Person),
		( call(F, _, Person),
		    personkey(Person, Key)
		),
		S),
	sort(S, SS),
	H = table(+forall(member(key(_, Person), SS),
			  +person_viewx(Person, Index),
			  [count(Index)]
			 )
		 ).


att(H) :-
	findall(key(Key, Person),
		( ( prim(_, Person)
		  ; secondary(_, Person)
		  ; special(_, Person)
		  ),
		  personkey(Person, Key)
		), 
		S),
	sort(S, SS),
	H = table(+forall(member(key(_, Person), SS),
			  +person_viewy(Person, Index),
			  [count(Index)]
			 )
		 ).


list_registered :-
	findall(key(Key, Person),
		( ( prim(_, Person)
		  ; secondary(_, Person)
		  ; special(_, Person)
		  ),
		  personkey(Person, Key)
		), 
		S),
	sort(S, SS),
	forall(member(key(Key, Person), SS),
	       (  Person=Regname-Email,
		   format('EMAIL=~q REGNAME=~q . send_the_mail_4.sh~n',
			  [Email, Regname])
	       )
	      ).

paper_view_5(PaperNum, H) :-
	PaperURI = ['http://www.w3.org/2004/12/rules-ws/paper/',
		    PaperNum],
	(  title(PaperNum, Title)
	-> true
	;  Title='untitled'
	),
	H=a(href=PaperURI, Title).


person_viewy(Person, Index, H) :-
	Person = Name-Email,
	obfus(Email, E2),
	H=tr(td(int(Index)), td(Name), td(E2),
	     td(+forall(reason(Person, Reason),
			Reason))).

reason(Person, Code) :-
	special(Code, Person).
reason(Person, PaperLink) :-
	(  prim(PaperNum, Person)
	;  secondary(PaperNum, Person)
	),
	PaperURI = ['http://www.w3.org/2004/12/rules-ws/paper/',
		    PaperNum],
	(  title(PaperNum, Title)
	-> true
	;  Title='untitled'
	),
	PaperLink=[a(href=PaperURI, Title), '  '].
	

%rdfq_provide(rdf:type, S, ws:'Person', _Q) :-
%    prim(_, Name-Email),
%    atom_concat(ws:'some_person/', Email, S).



web_server_page(rwspcSessionNotes, rwspcSessionNotes).

rwspcSessionNotes(Q) :-
	std_head(Q, Head, 'Workshop Session Notes'),
	Body =[ div(class=head,
		    
		    h1('Workshop Session Notes'),
		    p('See: ', a(href='http://www.w3.org/2004/12/rules-ws', 'Workshop Site'), ' and ', a(href='http://www.w3.org/2004/12/rules-ws/program', 'Program'))
		    ),
		+notes,
		p('$Id: workshop_support.pl,v 1.10 2005/06/22 22:39:22 sandro Exp $')
	      ], 
	write_html(html(head(Head), body(Body))).

notes(H) :-
	H = [+forall(session(_Day, _Start, _End, Text),
		     +if(Text = +Session, +session_notes(Session))
		    ),
	     p([])
	    ].

session_notes(Session, H) :-
	call(Session, List),
	List = [+session_title(Title) | Rest ],
	dig(Rest, PresList),
	atom_concat(g, SessionNum, Session),
	H = [h2(id=Session, 'Session ', SessionNum, ': ', Title),
	     table(+forall(member(P, PresList),
			   +tpres(P))
		  )
	    ].

dig([], []).
dig([+pres(N) | Rest], [N | R]) :- dig(Rest, R).
dig([T | Rest], R) :-
	T =.. [_functor | Args],
	dig(Args, R1),
	dig(Rest, R2),
	append(R1, R2, R).


talk_presenter(200, 'em@w3.org', 'Eric Miller').
talk_presenter(201, 'connolly@w3.org', 'Dan Connolly').
talk_title(200, 'Rules and the Semantic Web').
talk_title(201, 'W3C Process: A Means to an End').

npres(XPaperNumber, li(H)) :-
	(   XPaperNumber = STag - PaperNumber
	->  Tag = [em('(', STag, ')'), ' ']
	;   XPaperNumber = PaperNumber,
	    Tag = ''
	),
	goodmail(PaperNumber, Email, Name, _, _MsgId),
	retractall(e(Email)),
	assert(e(Email)),
	% atom_concat('mailto:', Email, _Emailto),
	PaperURI = ['http://www.w3.org/2004/12/rules-ws/paper/',
		    PaperNumber],
	(   talk_title(PaperNumber, Title1)
	->  Title = [em(a(href=PaperURI, Title1))]
	    % Title = [em(Title1)]
	;   Title = [em(a(href=PaperURI, 'Untitled'))]
	    % Title = ''
	),
	(   org(PaperNumber, Org1, U)
	->  Org = [', ', a(href=U, Org1) ]
	    % Org = [', ', Org1 ]
	;   Org = ''
	),
	H = [Tag, Name, Org, ': ', Title, ' ', Slides % ,%  ', ',
	     % '[',a(href=['http://www.w3.org/2002/09/wbs/37327/paper_',
	%		 PaperNumber, '/results'], 'survey results'), ']'
	    ].

slides_file(35, 'terrymoriarty.pdf').
slides_file(34, 'michaelkifer.pdf').
slides_file(61, 'edbarkmeyer.pdf').
slides_file(112, 'colleenmcclintock.pdf').
slides_file(44, 'josdebruijn.pdf').
slides_file(96, 'haroldboley.pdf').
slides_file(124, 'bengrosof.pdf').
slides_file(81, 'bijanparsia.pdf').
slides_file(53, 'paulvincent.pdf').
slides_file(107, 'danielselman.pdf').
slides_file(64, 'christinegolbreich.pdf').
slides_file(46, 'dougclark.pdf').
slides_file(74, 'chrismatheus.pdf').
slides_file(54, 'srinivaskrovvidy.pdf').
slides_file(36, 'davereynolds.pdf').
slides_file(31, 'harrychen.pdf').
slides_file(101, 'jeffreyritter.pdf').
slides_file(17, 'kurtgodden.pdf').
slides_file(113, 'marklinehan.pdf').
slides_file(103, 'pathayes.pdf').
slides_file(98, 'stefandecker.pdf').
slides_file(93, 'michaelsintek.pdf').
slides_file(68, 'garyhallmark.pdf').
slides_file(28, 'suzettestoutenberg.pdf').
slides_file(85, 'donaldchapin.pdf').

slides_uri(PaperNumber, URI) :-
	slides_file(PaperNumber, Filename),
	atom_concat('http://www.w3.org/2004/12/rules-ws/slides/', Filename, URI).
slides_uri(200, 'http://www.w3.org/2005/Talks/0427-rules-em/?n=0').
slides_uri(201, 'http://www.w3.org/2005/Talks/04w3c-process/all').
slides_uri(59, 'http://www.w3.org/2005/04/28-tlr-rules/').
slides_uri(94, 'http://www.w3.org/2005/Talks/0427-n3rules-tbl/all').
slides_uri(18, 'http://www.w3.org/2004/12/rules-ws/slides/philarcher/slide1.htm').

session_notes(1, 'Thomas Roessler (W3C) and others on IRC', 'irc-g1-pretty').
session_notes(2, 'Sandro Hawke (W3C) and others on IRC', 'irc-g2-pretty').
session_notes(3, 'Sandro Hawke (W3C) and others on IRC', 'irc-g3-pretty').
session_notes(4, 'Eric Miller (W3C) and others on IRC', 'irc-g4-pretty').
session_notes(5, 'Thomas Roessler (W3C) and others on IRC', 'irc-g5-pretty').
session_notes(6, 'Sandro Hawke (W3C) and others on IRC', 'irc-g6-pretty').
session_notes(7, 'Jos de Bruijn (DERI) and others on IRC', 'irc-g7-pretty').
session_notes(8, 'Thomas Roessler (W3C) and others on IRC', 'irc-g8-pretty').
session_notes(9, 'Thomas Roessler (W3C) and others on IRC', 'irc-g9-pretty').
session_notes(9, 'Sandro Hawke (W3C)', 'panel-hawke').
session_notes(4, 'Harold Boley (NRC)', 'stds-boley').
session_notes(5, 'Christian de Sainte Marie (ILOG)', 'uc1-csma').
session_notes(1, 'Benjamin Grosof (MIT)', 'grosof-1').
session_notes(2, 'Benjamin Grosof (MIT)', 'grosof-2').
session_notes(3, 'Benjamin Grosof (MIT)', 'grosof-3').
session_notes(4, 'Benjamin Grosof (MIT)', 'grosof-4').
session_notes(5, 'Benjamin Grosof (MIT)', 'grosof-5').
session_notes(6, 'Benjamin Grosof (MIT)', 'grosof-6').
session_notes(7, 'Benjamin Grosof (MIT)', 'grosof-7').
session_notes(8, 'Benjamin Grosof (MIT)', 'grosof-8').
session_notes(9, 'Benjamin Grosof (MIT)', 'grosof-9').

notes(N, []).
notes(N, H) :-
	Prefix = 'http://www.w3.org/2004/12/rules-ws/session-notes/',
	Minutes = 'http://www.w3.org/2004/12/rules-ws/report/minutes/',
	H = [h5(a(href=[Minutes, '#session_', N], minutes)),
	     h5('Contributed Session Notes: ',
	       ul(
	       +forall(session_notes(N, Name, Link),
		       li(a(href=[Prefix, Link], Name))))
	      )
	    ].


discussion(N, H) :-
	Prefix = 'http://www.w3.org/2004/12/rules-ws/session-notes/',
	Minutes = 'http://www.w3.org/2004/12/rules-ws/report/minutes',

	H =li('Discussion',
	       ul(
		  li(a(href=[Minutes, '#session_', N], minutes)),
		  +forall(session_notes(N, Name, Link),
			  li('Notes by ', a(href=[Prefix, Link], Name)))
		 )
	      ).


tpres(XPaperNumber, li(H)) :-
	(   XPaperNumber = STag - PaperNumber
	->  Tag = [em('(', STag, ')'), ' ']
	;   XPaperNumber = PaperNumber,
	    Tag = ''
	),
	goodmail(PaperNumber, Email, Name, _, _MsgId),
	retractall(e(Email)),
	assert(e(Email)),
	atom_concat('mailto:', Email, _Emailto),
	PaperURI = ['http://www.w3.org/2004/12/rules-ws/paper/',
		    PaperNumber],
	(   talk_title(PaperNumber, Title1)
	->  Title = [a(href=PaperURI, Title1)]
	;   Title = [a(href=PaperURI, paper)]
	),
	(   org(PaperNumber, Org1, U)
	->  Org = [a(href=U, Org1) ]
	;   Org = ''
	),
	(   slides_uri(PaperNumber, URI)
	->  Slides = a(href=URI, 'presentation')
	;   Slides = strong('(slides not available)')
	),
	H = tr(td(Name), td(Org), td(Slides), td(Title)).

