#!/usr/bin/perl
###########################################################################
#    WWWThreads  - Interactive Discussion Forum
#    Rick Baker scream@screamingweb.com 
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program 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 this program; if not, write to the Free Software
#    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
###########################################################################
  use lib '/home/simplew2/domains/forum.sportruck.com/public_html/cgi-bin';
  use wwwthreads qw(%config $dbh);

  use strict;


# ---------------------
# Give them the search page 
  wwwthreads::send_header("Search");
  wwwthreads::table_header("Search");

  print qq~
    <table border=0 width=100% cellspacing=0 bgcolor=$wwwthreads::config{'tddark'}>
    <tr><td> 
    Fill out the information below to search through the forums.
    </p>
    <form method= POST action = "$wwwthreads::config{'cgiurl'}/dosearch.pl">
    <p>
    </td></tr><tr><td bgcolor=$wwwthreads::config{'tdlight'}>
    Forum to Search<br>
  ~;


# ---------------
# Grab the forums
  wwwthreads::db_connect();
  my $query =qq!
    SELECT Title,Keyword
    FROM   Boards
  !;

  my $sth = $dbh -> prepare($query) or die "Query syntax error: $DBI::errstr. Query: $query";
  $sth -> execute() or die "Can't execute query. Reason: $DBI::errstr";

  my $forums = $sth -> rows;


# -----------------------------------
# Assign the forums to the select box
  print "<select name = Forum>";
  for (my $i=0;$i<$forums;$i++) {

    my ($Title,$Keyword) = $sth -> fetchrow_array;  
    print "<option value=\"$Keyword\">$Title</option>";

  }

  print "<option value=\"All_Forums\">All Forums</option>";
  print "</select>";

  print qq~
    <p>
    Words to search for<br>
    <input type=text name = Words size=30>
    <p>
    Search options<br>
    <select name = Match>
    <option value="Whole">Match entire word</option>
    <option value="Substrings">Match Substrings</option>
    </select>
    <p>
    Number of Results to show per page<br>
    <input type=text name = Limit value = 25 size=3>
    <p>
    <input type=submit value=submit>
    </form>
    </td></tr></table>
  ~;


# -------------
# Send a footer
  $sth -> finish;
  wwwthreads::send_footer;
