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