(* COCANWIKI scripts. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. * $Id: delete_image.ml,v 1.3 2004/09/07 14:58:34 rich Exp $ *) open Apache open Registry open Cgi open Printf open Cocanwiki open Cocanwiki_ok open Cocanwiki_emailnotify let run r (q : cgi) (dbh : Dbi.connection) (hostid, hostname, _) _ = let id = int_of_string (q#param "id") in if q#param_true "yes" then ( (* Delete the image. *) let sth = dbh#prepare_cached "update images set name_deleted = name, name = null where hostid = ? and id = ? and name is not null" in sth#execute [`Int hostid; `Int id]; dbh#commit (); (* Email notify. *) let subject = "Image #" ^ string_of_int id ^ " has been deleted." in let body = fun () -> "Page: http://" ^ hostname ^ "/_images?deleted=1" in email_notify ~body ~subject dbh hostid; (* Done. *) let buttons = [ ok_button "/_images" ] in ok ~title:"Image deleted" ~buttons q "Image was deleted successfully." ) else q#redirect ("http://" ^ hostname ^ "/_images") let () = register_script run