
% :- ensure_loaded(library('http/http_client')).
:- ensure_loaded('my_http_client').

submitted_sources_filename('submitted_sources.pl').

handle_submit(Request, ReqId) :-
	(   member(method(post), Request)
	->  do_submit(Request, ReqId)
	;   submit(ReqId)
	).

do_submit(Request, ReqId) :-
	http_read_data(Request, Data, []),
	Data = [uri=URI, email=EMail],
	submitted_sources_filename(Filename),
	open(Filename, append, File, [lock(write)]),
	get_time(Time),
	set_prolog_flag(float_format, '%.12g'),
	format(File, '~q.~n', [submitted_source(URI, EMail, Time)]),
	log_term(submitted_sources, submitted_source(URI, EMail, Time)),
	close(File),
	submit_done(ReqId).

submit_done(ReqId) :-
	write_page(ReqId, submit_done_body, '').

submit_done_body(H) :-
	H = [
		h1(class='semWalkerTitle2', 'Add A Data Source'),
		p('Added.'),
		p('Depending on various factors, the site may be harvested within a few seconds, or it might take a few days.'),
		p('Return to site ', a(href=".", 'home page'), '.')
		].

submit(ReqId) :-
	write_page(ReqId, submit_body, '').

submit_body(H) :-
	H = [
		h1(class='semWalkerTitle2', 'Add A Data Source'),
		a(href="help", help),
		p('Use this form to request that some web data source be always included.   To remove a source, use a robots.txt file'),
		form(method='post', action='submit',
		     p('URI: '),
		     input(name=uri, size='72', type=text, value='http://'),
		     p('Your e-mail address (optional, kept private) in case we would like to contact you about your site:'),
		     input(name=email, size='72', type=text),
		     input(type=submit, value='Submit')
		    ),
		p('Question, comments, problem: send email to ', a(href='mailto:sandro@w3.org?cc=www-archive@w3.org?subject=Ontaria', 'sandro@w3.org CC: www-archive@w3.org'), '.')
		].

