Support for users, roles, restrictions.
[cocanwiki.git] / scripts / delete_image.ml
1 (* COCANWIKI scripts.
2  * Written by Richard W.M. Jones <rich@merjis.com>.
3  * Copyright (C) 2004 Merjis Ltd.
4  * $Id: delete_image.ml,v 1.2 2004/09/07 13:40:10 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 image. *)
23     let sth = dbh#prepare_cached "update images
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 = "Image #" ^ string_of_int id ^ " has been deleted." in
33     let body = fun () ->
34       "Page: http://" ^ hostname ^ "/_images?deleted=1" in
35
36     email_notify ~body ~subject dbh hostid;
37     (* Done. *)
38     let buttons = [ ok_button "/_images" ] in
39     ok ~title:"Image deleted" ~buttons
40       q "Image was deleted successfully."
41   ) else
42     q#redirect ("http://" ^ hostname ^ "/_images")
43
44 let () =
45   register_script run