#!/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

if {![info exists env(QUERY_STRING)]} {
  set env(QUERY_STRING) ""
}

# The page_* variables are for customizing your
# guestbook pages.
set page_title "Search Inventory Database"
set page_opening "Welcome to the Inventory Database search form!"
set page_message \
"Please enter any search criteria you like using the standard
Qddb syntax.    \".*\" in any field will bring up all the 
records that have a value in that field.
If you don't know Qddb's simple search syntax, you can read
about it in the
<a href=http://www.hsdi.com/qddb/manual/node15.html>Guide to Qddb</a>.
If you have any problems with this search engine, please send
a mail message to
<a href=\"mailto:webmaster@www.knotwork.com\">
webmaster@www.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:-)

source ./init.tcl
set mypath "$cgidir/inventorysearch"  ;# full path of this file (http://../)
set env(QDDBDIRS) $dir

source $dir/postform.tcl
if {[string length $env(QUERY_STRING)] != 0} {
	regsub -all "\{\}" $env(QUERY_STRING) " " env(QUERY_STRING)
	set l $env(QUERY_STRING)
	set firstrow [lindex $l 0]
	set lastrow [lindex $l 1]
	set search [lindex [lrange $l 2 end] 0] ;# strip off a list level
}

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

if {[string compare $env(REQUEST_METHOD) GET] == 0} {
    source $dir/searchform.tcl
    GuestBookSearchForm		
} elseif {[string compare $env(REQUEST_METHOD) POST] == 0} {
    source $dir/search.tcl
    GuestBookSearch
}
exit 0
