2 * Written by Richard W.M. Jones <rich@merjis.com>.
3 * Copyright (C) 2004 Merjis Ltd.
4 * $Id: undelete_image.ml,v 1.2 2004/09/07 13:40:10 rich Exp $
15 open Cocanwiki_template
18 let run r (q : cgi) (dbh : Dbi.connection) (hostid, hostname, _) _ =
19 let id = int_of_string (q#param "id") in
21 if q#param_true "yes" then (
22 (* Get the name of the image. *)
23 let sth = dbh#prepare_cached "select name_deleted from images
24 where hostid = ? and id = ?" in
25 sth#execute [`Int hostid; `Int id];
27 let name = sth#fetch1string () in
29 (* First delete any more recent versions of this image. *)
30 let sth = dbh#prepare_cached "update images
31 set name_deleted = name, name = null
32 where hostid = ? and name = ?" in
33 sth#execute [`Int hostid; `String name];
35 (* Now copy the old row, changing name_deleted back to name so the image
38 let sth = dbh#prepare_cached "insert into images
39 (hostid, name, image, width, height,
40 alt, title, longdesc, class,
41 mime_type, thumbnail, tn_width,
42 tn_height, tn_mime_type, upload_date)
43 select hostid, name_deleted, image,
44 width, height, alt, title, longdesc,
45 class, mime_type, thumbnail,
46 tn_width, tn_height, tn_mime_type,
49 where hostid = ? and id = ?" in
50 sth#execute [`Int hostid; `Int id];
55 let buttons = [ ok_button "/_images" ] in
56 ok ~title:"Image restored" ~buttons
57 q "Image was restored successfully."
59 q#redirect ("http://" ^ hostname ^ "/_images")