Serial columns now 64 bits.
[cocanwiki.git] / scripts / edit_image_form.ml
1 (* COCANWIKI - a wiki written in Objective CAML.
2  * Written by Richard W.M. Jones <rich@merjis.com>.
3  * Copyright (C) 2004 Merjis Ltd.
4  * $Id: edit_image_form.ml,v 1.1 2004/11/01 17:05:14 rich Exp $
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; see the file COPYING.  If not, write to
18  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  *)
21
22 open Apache
23 open Registry
24 open Cgi
25 open Printf
26
27 open Cocanwiki
28 open Cocanwiki_template
29 open Cocanwiki_date
30
31 let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ =
32   let template = get_template dbh hostid "edit_image_form.html" in
33
34   let id = int_of_string (q#param "id") in
35
36   let sth = dbh#prepare_cached "select name, alt, coalesce (title, ''),
37                                        coalesce (longdesc, ''),
38                                        coalesce (class, ''),
39                                        mime_type,
40                                        coalesce (tn_width, 0),
41                                        coalesce (tn_height, 0),
42                                        upload_date
43                                   from images
44                                  where hostid = ? and id = ?" in
45   sth#execute [`Int hostid; `Int id];
46
47   let name, alt, title, longdesc, clazz, mime_type, tn_width, tn_height,
48     upload_date =
49     match sth#fetch1 () with
50         [ `String name; `String alt; `String title; `String longdesc;
51           `String clazz; `String mime_type; `Int tn_width; `Int tn_height;
52           `Timestamp upload_date ] ->
53           name, alt, title, longdesc, clazz, mime_type, tn_width, tn_height,
54           upload_date
55       | _ -> assert false in
56
57   template#set "id" (string_of_int id);
58   template#set "name" name;
59   template#set "alt" alt;
60   template#set "title" title;
61   template#set "longdesc" longdesc;
62   template#set "class" clazz;
63   template#set "mime_type" mime_type;
64   template#set "tn_width" (string_of_int tn_width);
65   template#set "tn_height" (string_of_int tn_height);
66   template#set "upload_date" (printable_date upload_date);
67
68   q#template template
69
70 let () =
71   register_script ~restrict:[CanEdit] run