###############################################################################
# UB_Search.src                                                               #
###############################################################################
# UltraBoard 2000 by UltraScripts.com, Inc.                                   #
# Scripts written by Jacky Wing Wa Yung, WebMaster@UltraScripts.com           #
# Available from http://www.UltraBoard.org/                                   #
# =========================================================================== #
# COPYRIGHT NOTICE :                                                          #
#                                                                             #
# Copyright (c) 1999-2000 UltraScripts.com, Inc. All Rights Reserved.         #
#                                                                             #
# This program is being distributed as shareware. It may be used and modified #
# free for personal, government or non-profit. Any commercial use must be     #
# registered. However, modified versions cannot be sold or distributed. You   #
# cannot alter the copyright and "powered by" notices throughout the scripts. #
# These notices must be clearly visible to the end users.                     #
#                                                                             #
# WARRANTY DISCLAIMER:                                                        #
#                                                                             #
# 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.                                           #
###############################################################################

package Source;

use strict;

sub Search {

  my ($Categories) = &DB::Query (
    TABLE   => "Categories"   ,
    COLUMNS => ["ID", "TITLE"],
    SORT    => "POSITION"     ,
    BY      => "A-Z"
  );

  my ($Boards, $BoardsIndex) = &DB::Query (
    TABLE   => "Boards"       ,
    COLUMNS => ["ID", "TITLE", "STATUS", "CATEGORY"],
    SORT    => "POSITION"     ,
    BY      => "A-Z"
  );

# =========================================================================== #
# Printing Search Form

  &Standard::Require("UB_Search.src", "$UB::INTERFACES_PATH/$SYSTEM::DEFAULT_THEME/UB_Search.src");

  my ($Select, $Index) = &Standard::GetBoardsList($Categories, $Boards, $BoardsIndex, 1, "", "");

  my %FORM = (
    "SHOW.BOARDS.LIST"=> 1      ,
    "BOARDS.LIST"     => $Select,

    &Standard::ExtraVariables()
  );

  $FORM{"FORM.BID"}       = $UB::QUERY{'BID'};
  $FORM{"FORM.CID"}       = $UB::QUERY{'CID'};
  $FORM{"FORM.PID"}       = $UB::QUERY{'PID'};
  $FORM{"FORM.TID"}       = $UB::QUERY{'TID'};
  $FORM{"FORM.DAY_PRUNE"} = $UB::QUERY{'DayPrune'};
  $FORM{"FORM.PAGE"}      = $UB::QUERY{'P'};

  CATEGORY: for (my $c = 0; $c <= $#{ $Categories }; $c++) {
    my $Category = $Categories->[$c];

    if ( exists $Index->{ $Category->{'ID'} } ) {
      $FORM{'FORM_BOARDS'} .= "<option value=\"\">".$Category->{'TITLE'}."</option>";

      BOARD: for (my $b = 0; $b <= $#{ $Index->{ $Category->{'ID'} } }; $b++ ) {
        my $Board = $Boards->[ $BoardsIndex->{ $Index->{ $Category->{'ID'} }->[$b] } ];
        $FORM{'FORM_BOARDS'} .= "<option value=\"".$Board->{'ID'}."\">&nbsp;-&nbsp;&nbsp;".$Board->{'TITLE'}."</option>";
      }
    }
  }

  &Standard::PrintHTMLHeader();
  print &Search::Parse(\%FORM);
}

###############################################################################
1; # end of UB_Search.src file
###############################################################################