Index: openacs-4/contrib/obsolete-packages/postcard/www/add-picture-2-postgresql.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/obsolete-packages/postcard/www/add-picture-2-postgresql.xql,v
diff -u -r1.1 -r1.2
--- openacs-4/contrib/obsolete-packages/postcard/www/add-picture-2-postgresql.xql	7 May 2001 19:19:59 -0000	1.1
+++ openacs-4/contrib/obsolete-packages/postcard/www/add-picture-2-postgresql.xql	21 Aug 2001 22:22:29 -0000	1.2
@@ -2,15 +2,24 @@
 
 <queryset>
    <rdbms><type>postgresql</type><version>7.1</version></rdbms>
-
+ 
 <fullquery name="add_picture">      
       <querytext>
-    insert into postcard_images (card_image_id, image, mime_type, title, description)
-    values (postcard_image_seq.nextval,
-        [set __lob_id [db_string get_id "select empty_lob()"]],
-        :mime_type, :title, :description)
+
+	insert into postcard_images (card_image_id, mime_type,
+	title,	description)
+	values (:image_id,  :mime_type, :title, :description )
+
       </querytext>
 </fullquery>
 
- 
-</queryset>
+<fullquery name="upload_picture">      
+    <querytext>
+
+    update postcard_images
+    set lob = [set __lob_id [db_string get_lob_id "select empty_lob()"]]
+    where card_image_id = :image_id
+
+    </querytext>
+</fullquery>
+ </queryset>
Index: openacs-4/contrib/obsolete-packages/postcard/www/add-picture-2.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/obsolete-packages/postcard/www/add-picture-2.tcl,v
diff -u -r1.1 -r1.2
--- openacs-4/contrib/obsolete-packages/postcard/www/add-picture-2.tcl	20 Apr 2001 20:51:22 -0000	1.1
+++ openacs-4/contrib/obsolete-packages/postcard/www/add-picture-2.tcl	21 Aug 2001 22:22:29 -0000	1.2
@@ -8,19 +8,25 @@
     @cvs-id $Id$
 } {
     upload_file
+    {image_id:integer,notnull}
     {title:notnull}
     {description:notnull}
 }
 
-set user_id [ad_conn user_id]
+set user_id [ad_verify_and_get_user_id]
+
+ad_require_permission [ad_conn package_id] "postcard_create_image"
+
 set tmp_filename [ns_queryget upload_file.tmpfile]
-ad_require_permission [ad_conn package_id] admin
 
 set file_extension [string tolower [file extension $upload_file]]
 
+set file_size [file size $tmp_filename]
+
 # remove the first . from the file extension
 regsub "\." $file_extension "" file_extension
 
+
 set what_aolserver_told_us ""
 if { $file_extension == "jpeg" || $file_extension == "jpg" } {
     set mime_type "image/jpeg"
@@ -37,11 +43,24 @@
     set original_width ""
     set original_height ""
 }
+ 
+db_transaction {
 
-db_dml add_picture {
-    insert into postcard_images (card_image_id, image, mime_type, title, description)
-    values (postcard_image_seq.nextval, empty_blob(), :mime_type, :title, :description)
-    returning image into :1
-} -blob_files [list $tmp_filename]
+    db_dml add_picture {
+	insert into postcard_images (card_image_id, mime_type,
+	       title,	description)
+	values (:image_id, 
+	       :mime_type, :title, :description )
+    } -blob_files [list $tmp_filename]
 
+    db_dml upload_picture {
+	update postcard_images
+	set image = [set __lob_id [db_string get_lob_id "select empty_lob()"]]
+	where card_image_id = :image_id
+    } -blob_files [list $tmp_filename]
+}
+
 ad_returnredirect "."
+
+
+
Index: openacs-4/contrib/obsolete-packages/postcard/www/add-picture.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/obsolete-packages/postcard/www/add-picture.adp,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/contrib/obsolete-packages/postcard/www/add-picture.adp	21 Aug 2001 22:22:29 -0000	1.1
@@ -0,0 +1,25 @@
+<master>
+
+<center>
+<form enctype=multipart/form-data method=POST action=add-picture-2>
+Add a picture<br>
+<table border=1>
+ <tr>
+  <td>Select Image</td>
+  <td><input type=file name=upload_file size=20></td>
+ </tr>
+ <tr>
+  <td>Title</td>
+  <td><input type=text name=title size=30></td>
+ </tr>
+ <tr>
+  <td>Description</td>
+  <td><textarea name=description rows=5 cols=40></textarea></td>
+ </tr>
+
+ <input type=hidden name=image_id value="@image_id@">
+</table>
+<input type=submit>
+</form>
+</center>
+
Index: openacs-4/contrib/obsolete-packages/postcard/www/add-picture.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/obsolete-packages/postcard/www/add-picture.tcl,v
diff -u -r1.1 -r1.2
--- openacs-4/contrib/obsolete-packages/postcard/www/add-picture.tcl	20 Apr 2001 20:51:22 -0000	1.1
+++ openacs-4/contrib/obsolete-packages/postcard/www/add-picture.tcl	21 Aug 2001 22:22:29 -0000	1.2
@@ -9,36 +9,11 @@
 } {
 }
 
-ad_require_permission [ad_conn package_id] admin
+ad_require_permission [ad_conn package_id] "postcard_create_image"
 
-append page_content [ad_header "Add Comment"]
+set image_id [db_nextval postcard_image_sequence] 
 
-append page_content "
-<center>
-<form enctype=multipart/form-data method=POST action=add-picture-2>
-Add a picture<br>
-<table border=1>
- <tr>
-  <td>Select Image</td>
-  <td><input type=file name=upload_file size=20></td>
- </tr>
- <tr>
-  <td>Title</td>
-  <td><input type=text name=title size=30></td>
- </tr>
- <tr>
-  <td>Description</td>
-  <td><textarea name=description rows=5 cols=40></textarea></td>
- </tr>
-</table>
-<input type=submit>
-</form>
-</center>
-"
-append page_content [ad_footer]
+ad_return_template
 
 
-doc_return 200 text/html $page_content
 
-
-
Index: openacs-4/contrib/obsolete-packages/postcard/www/confirm.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/obsolete-packages/postcard/www/confirm.adp,v
diff -u -r1.1 -r1.2
--- openacs-4/contrib/obsolete-packages/postcard/www/confirm.adp	20 Apr 2001 20:51:22 -0000	1.1
+++ openacs-4/contrib/obsolete-packages/postcard/www/confirm.adp	21 Aug 2001 22:22:29 -0000	1.2
@@ -11,7 +11,9 @@
 <%= [export_form_vars sender] %>
 <%= [export_form_vars subject] %>
 <%= [export_form_vars message] %>
+<%= [export_form_vars card_id] %>
 
+
 <table>
   <tr>
      <td align=right>
Index: openacs-4/contrib/obsolete-packages/postcard/www/confirm.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/obsolete-packages/postcard/www/confirm.tcl,v
diff -u -r1.1 -r1.2
--- openacs-4/contrib/obsolete-packages/postcard/www/confirm.tcl	20 Apr 2001 20:51:22 -0000	1.1
+++ openacs-4/contrib/obsolete-packages/postcard/www/confirm.tcl	21 Aug 2001 22:22:29 -0000	1.2
@@ -7,6 +7,7 @@
   @creation-date 2000-10-23
   @cvs-id $Id$
 } {
+  card_id:integer,notnull
   image_id:integer,notnull
   sender:notnull
   recipient:notnull
@@ -22,5 +23,9 @@
 }
 
 # Insert a new postcard in the database, set card_id to the card id value
+ad_require_permission [ad_conn package_id] "postcard_create_card"
 
+set exported_vars [export_form_vars [list sender card_id recipient subject message card_id]]
+
 ad_return_template
+
Index: openacs-4/contrib/obsolete-packages/postcard/www/index.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/obsolete-packages/postcard/www/index.tcl,v
diff -u -r1.1 -r1.2
--- openacs-4/contrib/obsolete-packages/postcard/www/index.tcl	20 Apr 2001 20:51:22 -0000	1.1
+++ openacs-4/contrib/obsolete-packages/postcard/www/index.tcl	21 Aug 2001 22:22:29 -0000	1.2
@@ -4,13 +4,15 @@
   send a post card
 
   @author hqm@ai.mit.edu
+  @author k_vertigo@yahoo.com
   @creation-date 2000-10-23
   @cvs-id $Id$
 } -properties {
   message:onevalue
 }
 
-db_multirow images images {
+
+db_multirow images get_all_images {
     select card_image_id, mime_type, title, description
     from postcard_images
     order by card_image_id
Index: openacs-4/contrib/obsolete-packages/postcard/www/index.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/obsolete-packages/postcard/www/index.xql,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/contrib/obsolete-packages/postcard/www/index.xql	21 Aug 2001 22:22:29 -0000	1.1
@@ -0,0 +1,14 @@
+<?xml version="1.0"?>
+
+<queryset>
+
+<fullquery name="get_all_images">      
+      <querytext>
+    select card_image_id, mime_type, title, description
+    from postcard_images
+    order by card_image_id
+      </querytext>
+</fullquery>
+
+ 
+</queryset>
Index: openacs-4/contrib/obsolete-packages/postcard/www/postcard-picture-postgresql.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/obsolete-packages/postcard/www/postcard-picture-postgresql.xql,v
diff -u -r1.1 -r1.2
--- openacs-4/contrib/obsolete-packages/postcard/www/postcard-picture-postgresql.xql	7 May 2001 19:19:59 -0000	1.1
+++ openacs-4/contrib/obsolete-packages/postcard/www/postcard-picture-postgresql.xql	21 Aug 2001 22:22:29 -0000	1.2
@@ -3,13 +3,11 @@
 <queryset>
    <rdbms><type>postgresql</type><version>7.1</version></rdbms>
 
-<fullquery name="select_image">      
+<fullquery name="retrieve_image">      
       <querytext>
---      FIX ME LOB
-        select image
+        select lob
         from postcard_images
-        where card_image_id = $image_id
-
+        where card_image_id = :image_id
       </querytext>
 </fullquery>
 
Index: openacs-4/contrib/obsolete-packages/postcard/www/postcard-picture.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/obsolete-packages/postcard/www/postcard-picture.tcl,v
diff -u -r1.1 -r1.2
--- openacs-4/contrib/obsolete-packages/postcard/www/postcard-picture.tcl	20 Apr 2001 20:51:22 -0000	1.1
+++ openacs-4/contrib/obsolete-packages/postcard/www/postcard-picture.tcl	21 Aug 2001 22:22:29 -0000	1.2
@@ -7,7 +7,7 @@
     @creation-date 6 Nov 2000
     @cvs-id $Id$
 } {
-    {image_id:notnull}
+    {image_id:integer,notnull}
 } 
 
 
@@ -16,10 +16,11 @@
     from postcard_images
    where card_image_id = :image_id}]
 
-db_write_blob select_image "
-select image
+
+db_write_blob retrieve_image "
+select lob
     from postcard_images
-    where card_image_id = $image_id
+    where card_image_id = :image_id
 "
 
 
Index: openacs-4/contrib/obsolete-packages/postcard/www/send-card.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/obsolete-packages/postcard/www/send-card.tcl,v
diff -u -r1.1 -r1.2
--- openacs-4/contrib/obsolete-packages/postcard/www/send-card.tcl	20 Apr 2001 20:51:22 -0000	1.1
+++ openacs-4/contrib/obsolete-packages/postcard/www/send-card.tcl	21 Aug 2001 22:22:29 -0000	1.2
@@ -7,6 +7,7 @@
   @creation-date 2000-10-23
   @cvs-id $Id$
 } {
+  card_id:integer,notnull
   image_id:integer,notnull
   sender:notnull
   recipient:notnull
@@ -18,19 +19,26 @@
   url:onevalue
 }
 
-set card_id [db_nextval postcard_seq]
+ad_require_permission [ad_conn package_id] "postcard_create_card"
 
 set pickup_code [ns_crypt $card_id foobar]
 
-db_dml add_message {
-    insert into postcards (card_id, pickup_code, card_picture, recipient, sender, message)
-    values (:card_id, :pickup_code, :image_id, :recipient, :sender, :message)
-}
+db_transaction {
 
-db_0or1row select_card_id {
-    select max(card_id) as card_id from postcards
+    db_dml add_message {
+	insert into postcards (card_id, pickup_code, card_picture, recipient, sender, message)
+	values (:card_id, :pickup_code, :image_id, :recipient, :sender, :message)
+    }
+
+    db_0or1row select_card_id {
+	select max(card_id) as card_id from postcards
+    }
+
+} on_error { # most likely a double click
+    ad_returnredirect "."
 }
 
+
 set url "[util_current_location][ad_conn package_url]show-card?pickup_code=$pickup_code"
 
 
@@ -50,3 +58,5 @@
 "
 ns_sendmail $recipient $sender $subject $message
 
+
+
Index: openacs-4/contrib/obsolete-packages/postcard/www/show-card-postgresql.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/obsolete-packages/postcard/www/show-card-postgresql.xql,v
diff -u -r1.1 -r1.2
--- openacs-4/contrib/obsolete-packages/postcard/www/show-card-postgresql.xql	7 May 2001 19:19:59 -0000	1.1
+++ openacs-4/contrib/obsolete-packages/postcard/www/show-card-postgresql.xql	21 Aug 2001 22:22:29 -0000	1.2
@@ -7,7 +7,7 @@
       <querytext>
       
 	update postcards
-	set picked_up = current_time
+	set picked_up = now()
 	where pickup_code = :pickup_code
     
       </querytext>
Index: openacs-4/contrib/obsolete-packages/postcard/www/show-card.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/obsolete-packages/postcard/www/show-card.tcl,v
diff -u -r1.1 -r1.2
--- openacs-4/contrib/obsolete-packages/postcard/www/show-card.tcl	20 Apr 2001 20:51:22 -0000	1.1
+++ openacs-4/contrib/obsolete-packages/postcard/www/show-card.tcl	21 Aug 2001 22:22:29 -0000	1.2
@@ -16,12 +16,15 @@
 }
 
 # Get Record
-db_0or1row select_card_id {
+if ![db_0or1row select_card_id {
     select card_id, card_picture as image_id, recipient, sender, message, picked_up
     from postcards
     where pickup_code = :pickup_code
+}] { 
+    ns_log NOTICE "\n\n\n*****\n**** houston we have a problem"
 }
 
+
 # Set picked_up date
 if [empty_string_p $picked_up] {
     db_dml set_date {
Index: openacs-4/contrib/obsolete-packages/postcard/www/write-card.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/obsolete-packages/postcard/www/write-card.adp,v
diff -u -r1.1 -r1.2
--- openacs-4/contrib/obsolete-packages/postcard/www/write-card.adp	20 Apr 2001 20:51:22 -0000	1.1
+++ openacs-4/contrib/obsolete-packages/postcard/www/write-card.adp	21 Aug 2001 22:22:29 -0000	1.2
@@ -6,6 +6,7 @@
 <p>
 <form action=confirm method=post>
 <%= [export_form_vars image_id] %>
+<%= [export_form_vars card_id] %>
 
 <table>
   <tr>
Index: openacs-4/contrib/obsolete-packages/postcard/www/write-card.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/obsolete-packages/postcard/www/write-card.tcl,v
diff -u -r1.1 -r1.2
--- openacs-4/contrib/obsolete-packages/postcard/www/write-card.tcl	20 Apr 2001 20:51:22 -0000	1.1
+++ openacs-4/contrib/obsolete-packages/postcard/www/write-card.tcl	21 Aug 2001 22:22:29 -0000	1.2
@@ -13,4 +13,8 @@
   image_value:onevalue
 }
 
+ad_require_permission [ad_conn package_id] "postcard_create_card"
+
+set card_id [db_nextval postcard_sequence]
+
 ad_return_template
Index: openacs-4/packages/postcard/www/add-picture-2-postgresql.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/postcard/www/add-picture-2-postgresql.xql,v
diff -u -r1.1 -r1.2
--- openacs-4/packages/postcard/www/add-picture-2-postgresql.xql	7 May 2001 19:19:59 -0000	1.1
+++ openacs-4/packages/postcard/www/add-picture-2-postgresql.xql	21 Aug 2001 22:22:29 -0000	1.2
@@ -2,15 +2,24 @@
 
 <queryset>
    <rdbms><type>postgresql</type><version>7.1</version></rdbms>
-
+ 
 <fullquery name="add_picture">      
       <querytext>
-    insert into postcard_images (card_image_id, image, mime_type, title, description)
-    values (postcard_image_seq.nextval,
-        [set __lob_id [db_string get_id "select empty_lob()"]],
-        :mime_type, :title, :description)
+
+	insert into postcard_images (card_image_id, mime_type,
+	title,	description)
+	values (:image_id,  :mime_type, :title, :description )
+
       </querytext>
 </fullquery>
 
- 
-</queryset>
+<fullquery name="upload_picture">      
+    <querytext>
+
+    update postcard_images
+    set lob = [set __lob_id [db_string get_lob_id "select empty_lob()"]]
+    where card_image_id = :image_id
+
+    </querytext>
+</fullquery>
+ </queryset>
Index: openacs-4/packages/postcard/www/add-picture-2.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/postcard/www/add-picture-2.tcl,v
diff -u -r1.1 -r1.2
--- openacs-4/packages/postcard/www/add-picture-2.tcl	20 Apr 2001 20:51:22 -0000	1.1
+++ openacs-4/packages/postcard/www/add-picture-2.tcl	21 Aug 2001 22:22:29 -0000	1.2
@@ -8,19 +8,25 @@
     @cvs-id $Id$
 } {
     upload_file
+    {image_id:integer,notnull}
     {title:notnull}
     {description:notnull}
 }
 
-set user_id [ad_conn user_id]
+set user_id [ad_verify_and_get_user_id]
+
+ad_require_permission [ad_conn package_id] "postcard_create_image"
+
 set tmp_filename [ns_queryget upload_file.tmpfile]
-ad_require_permission [ad_conn package_id] admin
 
 set file_extension [string tolower [file extension $upload_file]]
 
+set file_size [file size $tmp_filename]
+
 # remove the first . from the file extension
 regsub "\." $file_extension "" file_extension
 
+
 set what_aolserver_told_us ""
 if { $file_extension == "jpeg" || $file_extension == "jpg" } {
     set mime_type "image/jpeg"
@@ -37,11 +43,24 @@
     set original_width ""
     set original_height ""
 }
+ 
+db_transaction {
 
-db_dml add_picture {
-    insert into postcard_images (card_image_id, image, mime_type, title, description)
-    values (postcard_image_seq.nextval, empty_blob(), :mime_type, :title, :description)
-    returning image into :1
-} -blob_files [list $tmp_filename]
+    db_dml add_picture {
+	insert into postcard_images (card_image_id, mime_type,
+	       title,	description)
+	values (:image_id, 
+	       :mime_type, :title, :description )
+    } -blob_files [list $tmp_filename]
 
+    db_dml upload_picture {
+	update postcard_images
+	set image = [set __lob_id [db_string get_lob_id "select empty_lob()"]]
+	where card_image_id = :image_id
+    } -blob_files [list $tmp_filename]
+}
+
 ad_returnredirect "."
+
+
+
Index: openacs-4/packages/postcard/www/add-picture.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/postcard/www/add-picture.adp,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/postcard/www/add-picture.adp	21 Aug 2001 22:22:29 -0000	1.1
@@ -0,0 +1,25 @@
+<master>
+
+<center>
+<form enctype=multipart/form-data method=POST action=add-picture-2>
+Add a picture<br>
+<table border=1>
+ <tr>
+  <td>Select Image</td>
+  <td><input type=file name=upload_file size=20></td>
+ </tr>
+ <tr>
+  <td>Title</td>
+  <td><input type=text name=title size=30></td>
+ </tr>
+ <tr>
+  <td>Description</td>
+  <td><textarea name=description rows=5 cols=40></textarea></td>
+ </tr>
+
+ <input type=hidden name=image_id value="@image_id@">
+</table>
+<input type=submit>
+</form>
+</center>
+
Index: openacs-4/packages/postcard/www/add-picture.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/postcard/www/add-picture.tcl,v
diff -u -r1.1 -r1.2
--- openacs-4/packages/postcard/www/add-picture.tcl	20 Apr 2001 20:51:22 -0000	1.1
+++ openacs-4/packages/postcard/www/add-picture.tcl	21 Aug 2001 22:22:29 -0000	1.2
@@ -9,36 +9,11 @@
 } {
 }
 
-ad_require_permission [ad_conn package_id] admin
+ad_require_permission [ad_conn package_id] "postcard_create_image"
 
-append page_content [ad_header "Add Comment"]
+set image_id [db_nextval postcard_image_sequence] 
 
-append page_content "
-<center>
-<form enctype=multipart/form-data method=POST action=add-picture-2>
-Add a picture<br>
-<table border=1>
- <tr>
-  <td>Select Image</td>
-  <td><input type=file name=upload_file size=20></td>
- </tr>
- <tr>
-  <td>Title</td>
-  <td><input type=text name=title size=30></td>
- </tr>
- <tr>
-  <td>Description</td>
-  <td><textarea name=description rows=5 cols=40></textarea></td>
- </tr>
-</table>
-<input type=submit>
-</form>
-</center>
-"
-append page_content [ad_footer]
+ad_return_template
 
 
-doc_return 200 text/html $page_content
 
-
-
Index: openacs-4/packages/postcard/www/confirm.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/postcard/www/confirm.adp,v
diff -u -r1.1 -r1.2
--- openacs-4/packages/postcard/www/confirm.adp	20 Apr 2001 20:51:22 -0000	1.1
+++ openacs-4/packages/postcard/www/confirm.adp	21 Aug 2001 22:22:29 -0000	1.2
@@ -11,7 +11,9 @@
 <%= [export_form_vars sender] %>
 <%= [export_form_vars subject] %>
 <%= [export_form_vars message] %>
+<%= [export_form_vars card_id] %>
 
+
 <table>
   <tr>
      <td align=right>
Index: openacs-4/packages/postcard/www/confirm.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/postcard/www/confirm.tcl,v
diff -u -r1.1 -r1.2
--- openacs-4/packages/postcard/www/confirm.tcl	20 Apr 2001 20:51:22 -0000	1.1
+++ openacs-4/packages/postcard/www/confirm.tcl	21 Aug 2001 22:22:29 -0000	1.2
@@ -7,6 +7,7 @@
   @creation-date 2000-10-23
   @cvs-id $Id$
 } {
+  card_id:integer,notnull
   image_id:integer,notnull
   sender:notnull
   recipient:notnull
@@ -22,5 +23,9 @@
 }
 
 # Insert a new postcard in the database, set card_id to the card id value
+ad_require_permission [ad_conn package_id] "postcard_create_card"
 
+set exported_vars [export_form_vars [list sender card_id recipient subject message card_id]]
+
 ad_return_template
+
Index: openacs-4/packages/postcard/www/index.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/postcard/www/index.tcl,v
diff -u -r1.1 -r1.2
--- openacs-4/packages/postcard/www/index.tcl	20 Apr 2001 20:51:22 -0000	1.1
+++ openacs-4/packages/postcard/www/index.tcl	21 Aug 2001 22:22:29 -0000	1.2
@@ -4,13 +4,15 @@
   send a post card
 
   @author hqm@ai.mit.edu
+  @author k_vertigo@yahoo.com
   @creation-date 2000-10-23
   @cvs-id $Id$
 } -properties {
   message:onevalue
 }
 
-db_multirow images images {
+
+db_multirow images get_all_images {
     select card_image_id, mime_type, title, description
     from postcard_images
     order by card_image_id
Index: openacs-4/packages/postcard/www/index.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/postcard/www/index.xql,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/postcard/www/index.xql	21 Aug 2001 22:22:29 -0000	1.1
@@ -0,0 +1,14 @@
+<?xml version="1.0"?>
+
+<queryset>
+
+<fullquery name="get_all_images">      
+      <querytext>
+    select card_image_id, mime_type, title, description
+    from postcard_images
+    order by card_image_id
+      </querytext>
+</fullquery>
+
+ 
+</queryset>
Index: openacs-4/packages/postcard/www/postcard-picture-postgresql.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/postcard/www/postcard-picture-postgresql.xql,v
diff -u -r1.1 -r1.2
--- openacs-4/packages/postcard/www/postcard-picture-postgresql.xql	7 May 2001 19:19:59 -0000	1.1
+++ openacs-4/packages/postcard/www/postcard-picture-postgresql.xql	21 Aug 2001 22:22:29 -0000	1.2
@@ -3,13 +3,11 @@
 <queryset>
    <rdbms><type>postgresql</type><version>7.1</version></rdbms>
 
-<fullquery name="select_image">      
+<fullquery name="retrieve_image">      
       <querytext>
---      FIX ME LOB
-        select image
+        select lob
         from postcard_images
-        where card_image_id = $image_id
-
+        where card_image_id = :image_id
       </querytext>
 </fullquery>
 
Index: openacs-4/packages/postcard/www/postcard-picture.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/postcard/www/postcard-picture.tcl,v
diff -u -r1.1 -r1.2
--- openacs-4/packages/postcard/www/postcard-picture.tcl	20 Apr 2001 20:51:22 -0000	1.1
+++ openacs-4/packages/postcard/www/postcard-picture.tcl	21 Aug 2001 22:22:29 -0000	1.2
@@ -7,7 +7,7 @@
     @creation-date 6 Nov 2000
     @cvs-id $Id$
 } {
-    {image_id:notnull}
+    {image_id:integer,notnull}
 } 
 
 
@@ -16,10 +16,11 @@
     from postcard_images
    where card_image_id = :image_id}]
 
-db_write_blob select_image "
-select image
+
+db_write_blob retrieve_image "
+select lob
     from postcard_images
-    where card_image_id = $image_id
+    where card_image_id = :image_id
 "
 
 
Index: openacs-4/packages/postcard/www/send-card.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/postcard/www/send-card.tcl,v
diff -u -r1.1 -r1.2
--- openacs-4/packages/postcard/www/send-card.tcl	20 Apr 2001 20:51:22 -0000	1.1
+++ openacs-4/packages/postcard/www/send-card.tcl	21 Aug 2001 22:22:29 -0000	1.2
@@ -7,6 +7,7 @@
   @creation-date 2000-10-23
   @cvs-id $Id$
 } {
+  card_id:integer,notnull
   image_id:integer,notnull
   sender:notnull
   recipient:notnull
@@ -18,19 +19,26 @@
   url:onevalue
 }
 
-set card_id [db_nextval postcard_seq]
+ad_require_permission [ad_conn package_id] "postcard_create_card"
 
 set pickup_code [ns_crypt $card_id foobar]
 
-db_dml add_message {
-    insert into postcards (card_id, pickup_code, card_picture, recipient, sender, message)
-    values (:card_id, :pickup_code, :image_id, :recipient, :sender, :message)
-}
+db_transaction {
 
-db_0or1row select_card_id {
-    select max(card_id) as card_id from postcards
+    db_dml add_message {
+	insert into postcards (card_id, pickup_code, card_picture, recipient, sender, message)
+	values (:card_id, :pickup_code, :image_id, :recipient, :sender, :message)
+    }
+
+    db_0or1row select_card_id {
+	select max(card_id) as card_id from postcards
+    }
+
+} on_error { # most likely a double click
+    ad_returnredirect "."
 }
 
+
 set url "[util_current_location][ad_conn package_url]show-card?pickup_code=$pickup_code"
 
 
@@ -50,3 +58,5 @@
 "
 ns_sendmail $recipient $sender $subject $message
 
+
+
Index: openacs-4/packages/postcard/www/show-card-postgresql.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/postcard/www/show-card-postgresql.xql,v
diff -u -r1.1 -r1.2
--- openacs-4/packages/postcard/www/show-card-postgresql.xql	7 May 2001 19:19:59 -0000	1.1
+++ openacs-4/packages/postcard/www/show-card-postgresql.xql	21 Aug 2001 22:22:29 -0000	1.2
@@ -7,7 +7,7 @@
       <querytext>
       
 	update postcards
-	set picked_up = current_time
+	set picked_up = now()
 	where pickup_code = :pickup_code
     
       </querytext>
Index: openacs-4/packages/postcard/www/show-card.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/postcard/www/show-card.tcl,v
diff -u -r1.1 -r1.2
--- openacs-4/packages/postcard/www/show-card.tcl	20 Apr 2001 20:51:22 -0000	1.1
+++ openacs-4/packages/postcard/www/show-card.tcl	21 Aug 2001 22:22:29 -0000	1.2
@@ -16,12 +16,15 @@
 }
 
 # Get Record
-db_0or1row select_card_id {
+if ![db_0or1row select_card_id {
     select card_id, card_picture as image_id, recipient, sender, message, picked_up
     from postcards
     where pickup_code = :pickup_code
+}] { 
+    ns_log NOTICE "\n\n\n*****\n**** houston we have a problem"
 }
 
+
 # Set picked_up date
 if [empty_string_p $picked_up] {
     db_dml set_date {
Index: openacs-4/packages/postcard/www/write-card.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/postcard/www/write-card.adp,v
diff -u -r1.1 -r1.2
--- openacs-4/packages/postcard/www/write-card.adp	20 Apr 2001 20:51:22 -0000	1.1
+++ openacs-4/packages/postcard/www/write-card.adp	21 Aug 2001 22:22:29 -0000	1.2
@@ -6,6 +6,7 @@
 <p>
 <form action=confirm method=post>
 <%= [export_form_vars image_id] %>
+<%= [export_form_vars card_id] %>
 
 <table>
   <tr>
Index: openacs-4/packages/postcard/www/write-card.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/postcard/www/write-card.tcl,v
diff -u -r1.1 -r1.2
--- openacs-4/packages/postcard/www/write-card.tcl	20 Apr 2001 20:51:22 -0000	1.1
+++ openacs-4/packages/postcard/www/write-card.tcl	21 Aug 2001 22:22:29 -0000	1.2
@@ -13,4 +13,8 @@
   image_value:onevalue
 }
 
+ad_require_permission [ad_conn package_id] "postcard_create_card"
+
+set card_id [db_nextval postcard_sequence]
+
 ad_return_template