;;; modify-products.mhtml: -*- Meta-HTML -*-  Acme Cake Shop.
;;;
;;;  Copyright (c) 1996 Universal Access Inc.
;;;  Author: Art Medlar, Henry Minsky Fri Jul 26 18:19:12 PDT 1996

<set-var page-title="Acme Cakes Product Database">
<set-var page-color="#FFFFFF">
<include header.mhtml>

<h3>Edit Product Description</h3>

;;; Normally, we just look for a posted variable called
;;; KEY, and display the product with that key from
;;; the product database.
;;;
;;; If, however, there is a posted variable named  "MODIFY", then
;;; we actually do a database transaction to modify the record.
;;; In this case we assume that all field values for the product
;;; are posted in the POSTED package, so we can just
;;; save the entire POSTED package into that product id.

<when <package-vars posted>>
  <when <string-eq <get-var posted::cancel> "Cancel">>
    <redirect show-products.mhtml>
  </when>

  <with-open-database pdb <get-var dbfile> mode=write-create>
    <when <string-eq <get-var posted::delete> "Delete">>
      <database-delete-record pdb <get-var posted::key>>
      <b>Deleted Product ID <get-var posted::key></b>
    </when>

    ;;; If we are modifying the record, then all its fields
    ;;; are in the posted package, so save the posted package out
    ;;; as a database record.
    <when <get-var posted::modify>>
      <set-var ok =
	<database-save-package pdb <get-var posted::key> posted strip=true>>
    </when>
  </with-open-database>
</when>

<display-product-form <get-var posted::key>>
<b><a href="show-products.mhtml">View Product Database</a></b>

<include footer.mhtml>
