#!/bin/bash
#-------------------------------------------------------------------
# This file is part of the wwwoffle-sql package
#
#  Version : 0.02  Released : 03/05/99
#
# Author : Peter Marbaise (pema@hippo.fido.de,2:2452/110.20)
#
#              GNU GENERAL PUBLIC LICENSE Version 2
#              (see LICENSE for the complete text)
#
#-------------------------------------------------------------------

exec perl -x "$0" "$@"     # w/o path
exec perl -S -x "$0" "$@"  # w/ path
echo cannot find $0        # failure
exit 1
#! perl
use lib '/usr/local/apache/share/htdocs/wwwoffle-sql/';
use wwwofflelib;


($dbh,$drh)=initdb();


print "---------------------------------------------------------------\n";
print "Seaching for $ARGV[0]\n";
print "---------------------------------------------------------------\n";
$sel_line="SELECT hosts.sid,hosts.id,hosts.name,hostpages.ref,hostpages.datum,";
$sel_line=$sel_line."hostpages.keywords,hostpages.usrkeywords,hostpages.size,hostpages.version";
$sel_line=$sel_line." from hosts,hostpages ";
$sel_line=$sel_line."WHERE hosts.id=hostpages.ID AND (";
$sel_line=$sel_line."hostpages.keywords like '%$ARGV[0]%' OR ";
$sel_line=$sel_line."hostpages.usrkeywords like '%$ARGV[0]%')";
$sel_line=$sel_line." order by hosts.name,hostpages.ref";
$csr=$dbh->prepare("$sel_line") or die "cant execute select";
$csr->execute;

$oldhost="";
while ( ($sid,$hostid,$host,$ref,$datum,$keywords,$usrkeywords,$size,$version)=$csr->fetchrow ) {

    if ( $oldhost ne $host ) {
        if ( $header == 1 ) {
            print"\n";
        }
        print "Host $host\n";
        $oldhost = $host;
        $header = 1;
    }
    $c = substr $keywords , 0, 1;
    if ( $c eq " " ) {
        $keywords = substr $keywords , 1, length($keywords);
    }
    $_=$keywords;
    s/ /+/g;
    $keywords=$_;
    $_=$datum;
    s/ /+/g;
    $datum=$_;
    print " - ";
    print "Page    : $host$ref\n";
    if ($version ne "") { print " - Version : $version\n"; }
    if ($size != 0 ) { print " - Size    : $size\n"; }
}
    print "\n";

print "---- generated with wwwoffle-sql scripts (c) Peter Marbaise ----\n";
print "Release : 0.02 03/05/99\n";
#$rc=$dbh->disconnect;
exit $rc;

# end of SEARCHKEY 
