Moved to merjis/tools/wiki.
[cocanwiki.git] / scripts / delete_file.ml
1 (* COCANWIKI scripts.
2  * Written by Richard W.M. Jones <rich@merjis.com>.
3  * Copyright (C) 2004 Merjis Ltd.
4  * $Id: delete_file.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 open Cocanwiki_ok
14 open Cocanwiki_emailnotify
15
16 open Merjisforwiki
17
18 let run r (q : cgi) (dbh : Dbi.connection) (hostid, hostname) _ =
19   let id = int_of_string (q#param "id") in
20
21   if q#param_true "yes" then (
22     (* Delete the file. *)
23     let sth = dbh#prepare_cached "update files
24                                      set name_deleted = name, name = null
25                                    where hostid = ? and id = ?
26                                      and name is not null" in
27     sth#execute [`Int hostid; `Int id];
28
29     dbh#commit ();
30
31     (* Email notify. *)
32     let subject = "File #" ^ string_of_int id ^ " has been deleted." in
33     let body = fun () ->
34       "Page: http://" ^ hostname ^ "/_files?deleted=1" in
35
36     email_notify ~body ~subject dbh hostid;
37
38     (* Done. *)
39     let buttons = [ ok_button "/_files" ] in
40     ok ~title:"File deleted" ~buttons
41       q "File was deleted successfully."
42   ) else
43     q#redirect ("http://" ^ hostname ^ "/_files")
44
45 let () =
46   register_script run