;;; products.mhtml: -*- Meta-HTML -*- 

;;;  Copyright (c) 1996 Universal Access Inc.
;;;  Author: Henry Minsky (hqm@ua.com) Sat Jul 27 14:09:04 1996.

;;; Define accessors for product database records

;;; The real pathname name of our database file
<set-var dbfile =
  <concat <get-var mhtml::include-prefix mhtml::relative-prefix>
	  /products.db>>

;;; For this demo, if the product database does not exist, we will
;;; just make a predefined one right now. This would not be done in a
;;; production environment, of course.
<when <not <get-file-properties <get-var dbfile>>>>
  Initializing cake product database...
  <include seed-database.mhtml>
  <if <get-file-properties "<get-var dbfile>">
      "done."
    "error, could not create database file!">
</when>

;;; Looks up a product using a product-id key
<define-tag get-product key>
  <set-var item::product-id=<get-var key>>
  <with-open-database db <get-var dbfile> mode=read>
    <database-load-record db <get-var key> package=item>
  </with-open-database>
</define-tag>

;;; Prints an HTML table of the product database
<define-tag display-products>
  <with-open-database pdb <get-var dbfile> mode=read>

    <table border=1>
      <tr>
	<th>Item</th>
	<th>Description</th>
	<th>Qty</th>
	<th>Price</th>
	<th>Next Delivery</th>
      </tr>

      <database-query pdb true 
	format=
	<prog
	  <tr>
	  <td><get-var key></td>
	  <td><a href="<get-var url>"><get-var title></a></td>
	  <td><get-var inventory></td>
	  <td><get-var price></td>
	  <td><get-var delivery></td>
	  </tr>>>

    </table>
  </with-open-database>
</define-tag>
