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