#!/usr/local/qddb/bin/qtclsh
# 
# Copyright (C) 1996 Herrin Software Development, Inc.
# All rights reserved.
#
# This file is part of Qddb Guest Book.
#
# Qddb Guest Book is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License Version 2
# as published by the Free Software Foundation.
#
# Qddb Guest Book is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Qddb Guest Book; see the file LICENSE.  If not, write to:
#
#	Herrin Software Development, Inc. 
#	R&D Division
#	41 South Highland Ave. 
#	Prestonsburg, KY 41653 
#

lappend auto_path $qddb_library/hx

#
# Note that the "email" and "homepage" attributes
# must exist in your GuestBook/Schema since this
# script treats them specially.
#


# The page_* variables are for customizing your
# guestbook pages.

set page_title "Businesses database"
set page_opening "Welcome to the Business Data submission form"
set page_message \
"Please note that the information you provide will be visible
by everyone.   If you would just like
to let us know you were here, send e-mail to 
<a href=\"mailto:webmaster@knotwork.com\">webmaster@knotwork.com</a>.
<p>
<b>Thanks for visiting our site!</b>
"

# ---- YOU SHOULDN'T HAVE TO CHANGE MUCH BELOW THIS LINE
# (But of course you can if you want:-)


# The following two variables need to be customized to your
# site
source ./init.tcl

set env(QDDBDIRS) $dir
set mypath "$cgidir/business"

source postform.tcl
# allow privnote entry, but not searching or display

GuestBookEntryPostForm ;# append privnote or other private entries

set s [qddb_schema open $DBname]
Hx:Init $s

if {[string compare $env(REQUEST_METHOD) GET] == 0} {
	puts -nonewline \
"Content-type: text/html

<html>
<head><title>$page_title</title></head>
$body
<h2>$page_opening</h2>
<p>
$page_message
<p>
<br>
$page_signature
<hr size=3 width=95% align=center>

<form method=POST ACTION=${mypath}?$env(QUERY_STRING)>
<pre>
[Hx:DefinedEntryForm $s $postform]
<br>
<input type=submit value=\"Enter record!\"> <input type=reset value=\"Clear entry\">

</pre>
</form>

</body>
</html>
"
} elseif {[string compare $env(REQUEST_METHOD) POST] == 0} {
	source $dir/utils.tcl
	set l1 [Hx:GetPostedData]
	set t [qddb_tuple new $s]
	set v [qddb_view define $t {}]
	qddb_instance setval $v entrydate "now"
	foreach i $l1 {
		set attr [lindex $i 0]
		set attrval [lindex $i 1]
		if {[string length [string trim $attrval]] == 0} {
			continue
		}
		set vals($attr) $attrval
		qddb_instance setval $v $attr $attrval
	}
	if {![info exists vals(Business)] || ![info exists vals(EMail)]} {
		Usage
		exit 0
	}
	qddb_tuple write $t
	puts -nonewline \
"Content-type: text/html

<html>
<head><title>$page_title</title></head>
$body
<h2>Thanks for signing our guest book!</h2>
</body>
</html>
"
}
exit 0
