2f47901e6166213feaeb5c0d348de24a0d430262
[cocanwiki.git] / scripts / undelete_file_form.ml
1 (* COCANWIKI scripts.
2  * Written by Richard W.M. Jones <rich@merjis.com>.
3  * Copyright (C) 2004 Merjis Ltd.
4  * $Id: undelete_file_form.ml,v 1.1 2004/09/07 10:14:09 rich Exp $
5  *)
6
7 open Apache
8 open Registry
9 open Cgi
10 open Printf
11
12 open Cocanwiki
13
14 open Merjisforwiki
15
16 let template = get_template "undelete_file_form.html"
17
18 let run r (q : cgi) (dbh : Dbi.connection) (hostid, _) _ =
19   let id = int_of_string (q#param "id") in
20
21   let sth = dbh#prepare_cached "select name, name_deleted
22                                   from files
23                                  where hostid = ? and id = ?" in
24   sth#execute [`Int hostid; `Int id];
25
26   let name =
27     match sth#fetch1 () with
28         [ `String name; `Null]
29       | [ `Null; `String name] -> name
30       | _ -> assert false in
31
32   template#set "id" (string_of_int id);
33   template#set "name" name;
34
35   q#template template
36
37 let () =
38   register_script run