#! /bin/sh 
exec /home/clip/bin/ciao-shell-1.10 $0 $* # -*- mode: ciao; -*-

:- include(library(pillow)).
:- use_module(library(file_utils),[file_to_string/2]).

main(_) :-
    get_form_input(Input),
    get_form_value(Input,person_name,Name),
    response(Name,Response),
    file_to_string('html_template.html', Contents),
    html_template(Contents, HTML_terms, [response = Response]),
    output_html([cgi_reply|HTML_terms]).

response(Name, []) :- form_empty_value(Name), !.
response(Name, ['Phone number for ',bf(Name),' is ',Info, --]) :-
	phone(Name,Info), !.
response(Name, ['No phone number available for ',bf(Name), '.', --]).

%% Database
phone('CLIP',   '336-7448').
phone('Paco',   '554-5225').
phone('Daniel', '460-0569').

