From b1b95dabf1c1e96f7dc2d24b579e983ec072af89 Mon Sep 17 00:00:00 2001 From: rich Date: Fri, 17 Sep 2004 16:03:34 +0000 Subject: [PATCH] Display contacts. Updated deps. --- scripts/.depend | 4 ++ scripts/Makefile | 4 +- scripts/contact_show.ml | 65 +++++++++++++++++++++++++++++ scripts/contacts.ml | 58 ++++++++++++++++++++++++++ templates/contact_show.html | 99 +++++++++++++++++++++++++++++++++++++++++++++ templates/contacts.html | 63 +++++++++++++++++++++++++++++ 6 files changed, 292 insertions(+), 1 deletion(-) create mode 100644 scripts/contact_show.ml create mode 100644 scripts/contacts.ml create mode 100644 templates/contact_show.html create mode 100644 templates/contacts.html diff --git a/scripts/.depend b/scripts/.depend index 335073e..39ea508 100644 --- a/scripts/.depend +++ b/scripts/.depend @@ -18,6 +18,10 @@ cocanwiki_template.cmx: cocanwiki_files.cmx cocanwiki_version.cmx \ cocanwiki_template.cmi contact.cmo: cocanwiki.cmo cocanwiki_ok.cmo cocanwiki_template.cmi contact.cmx: cocanwiki.cmx cocanwiki_ok.cmx cocanwiki_template.cmx +contact_show.cmo: cocanwiki.cmo cocanwiki_template.cmi +contact_show.cmx: cocanwiki.cmx cocanwiki_template.cmx +contacts.cmo: cocanwiki.cmo cocanwiki_template.cmi +contacts.cmx: cocanwiki.cmx cocanwiki_template.cmx create.cmo: cocanwiki.cmo cocanwiki_emailnotify.cmo cocanwiki_ok.cmo \ wikilib.cmi create.cmx: cocanwiki.cmx cocanwiki_emailnotify.cmx cocanwiki_ok.cmx \ diff --git a/scripts/Makefile b/scripts/Makefile index ec9ebb5..2ac30f9 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -1,5 +1,5 @@ # Makefile for COCANWIKI. -# $Id: Makefile,v 1.11 2004/09/17 12:35:38 rich Exp $ +# $Id: Makefile,v 1.12 2004/09/17 16:03:34 rich Exp $ include ../Makefile.config @@ -23,6 +23,8 @@ LIB_OBJS := \ OBJS := 00-TEMPLATE.cmo \ contact.cmo \ + contact_show.cmo \ + contacts.cmo \ create.cmo \ create_form.cmo \ delete_file.cmo \ diff --git a/scripts/contact_show.ml b/scripts/contact_show.ml new file mode 100644 index 0000000..d65c99c --- /dev/null +++ b/scripts/contact_show.ml @@ -0,0 +1,65 @@ +(* COCANWIKI - a wiki written in Objective CAML. + * Written by Richard W.M. Jones . + * Copyright (C) 2004 Merjis Ltd. + * $Id: contact_show.ml,v 1.1 2004/09/17 16:03:34 rich Exp $ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + *) + +open Apache +open Registry +open Cgi +open Printf + +open Cocanwiki +open Cocanwiki_template + +let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ = + let template = get_template dbh hostid "contact_show.html" in + + let id = int_of_string (q#param "id") in + template#set "id" (string_of_int id); + + (* Pull out all the details out of the database. *) + let sth = dbh#prepare_cached + "select name, subject + from contacts where hostid = ? and id = ?" in + sth#execute [`Int hostid; `Int id]; + + let name, subject = + match sth#fetch1 () with + [ `String name; `String subject ] -> name, subject + | _ -> assert false in + + template#set "name" name; + template#set "subject" subject; + + (* Get the emails. *) + let sth = dbh#prepare_cached + "select email from contact_emails where contactid = ? + order by 1" in + sth#execute [`Int id]; + + let table = sth#map (function [`String email] -> + [ "email", Template.VarString email ] + | _ -> assert false) in + + template#table "emails" table; + + q#template template + +let () = + register_script ~restrict:[CanManageContacts] run diff --git a/scripts/contacts.ml b/scripts/contacts.ml new file mode 100644 index 0000000..22adc38 --- /dev/null +++ b/scripts/contacts.ml @@ -0,0 +1,58 @@ +(* COCANWIKI - a wiki written in Objective CAML. + * Written by Richard W.M. Jones . + * Copyright (C) 2004 Merjis Ltd. + * $Id: contacts.ml,v 1.1 2004/09/17 16:03:34 rich Exp $ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + *) + +open Apache +open Registry +open Cgi +open Printf + +open Cocanwiki +open Cocanwiki_template + +let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ = + let template = get_template dbh hostid "contacts.html" in + + (* Pull out all the contacts from the database. *) + let sth = dbh#prepare_cached + "select c.id, c.name, c.subject, + (select count(*) from contact_emails + where contactid = c.id) + from contacts c + where c.hostid = ? + order by c.name, c.id" in + sth#execute [`Int hostid]; + + let table = + sth#map + (function + [`Int id; `String name; `String subject; `Int count] -> + [ "id", Template.VarString (string_of_int id); + "name", Template.VarString name; + "subject", Template.VarString subject; + "count", Template.VarString (string_of_int count) ] + | _ -> assert false) in + + template#table "contacts" table; + + q#template template + +let () = + register_script ~restrict:[CanManageContacts] run diff --git a/templates/contact_show.html b/templates/contact_show.html new file mode 100644 index 0000000..3381b83 --- /dev/null +++ b/templates/contact_show.html @@ -0,0 +1,99 @@ + + + +Contact form: ::name_html:: + + + + + +

Contact form: ::name_html::

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Contact ID: ::id_html::
Name: ::name_html::
Subject line for email: ::subject_html::
Emails: +::table(emails):: +::email_html::
+::end:: +
Actions: + +
HTML snippet: +

+Copy and paste this example snippet into +your page to enable the form. +

+ +
+<html>
+<form method="post" action="/_contact">
+<input type="hidden" name="id" value="::id::"/>
+<table class="left_table">
+<tr> <th> Name: </th>
+     <td> <input name="Name" size="50" /> </td> </tr>
+<tr> <th> Tel.: </th>
+     <td> <input name="Phone" size="50" /> </td> </tr>
+<tr> <th> Notes: </th>
+     <td> <textarea name="Notes" rows="5" cols="60"></textarea> </td> </tr>
+<tr> <th></th>
+     <td> <input type="submit" value="Send form"/> </td> </tr>
+</table>
+</form>
+</html>
+
+ +
+ + + + + +
+ + + + + \ No newline at end of file diff --git a/templates/contacts.html b/templates/contacts.html new file mode 100644 index 0000000..5aafbe2 --- /dev/null +++ b/templates/contacts.html @@ -0,0 +1,63 @@ + + + +Contact forms + + + + + +

Contact forms

+ + + +
+ + + + + + + + +::table(contacts):: + + + + + + + +::end:: + + + +
Contact ID Name Subject line # addresses
::id:: ::name_html:: ::subject_html:: ::count_html::
+ +
+
+ + + + + +
+ + + + + \ No newline at end of file -- 1.8.3.1