###############################################################################
# UB_Forward.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 Forward {
  my ($ERROR) = @_;
  return if ((!$SYSTEM::SENDMAIL) || (!$GENERAL::FORWARD));

# =========================================================================== #
# Checking Permission

  (
    my ($Board) = &DB::BinarySelect (
      TABLE   => "Boards",
      COLUMNS => ["ID", "TITLE", "CATEGORY", "STATUS"],
      KEY     => $UB::QUERY{'BID'}
    )
  ) || &HTML::Error(MESSAGE => $DB::Error);

  (
    my ($Category) = &DB::BinarySelect (
      TABLE   => "Categories",
      COLUMNS => ["ID", "TITLE"],
      KEY     => $Board->{'CATEGORY'}
    )
  ) || &HTML::Error(MESSAGE => $DB::Error);

  (
    my ($Topic) = &DB::BinarySelect (
      TABLE   => "B".$Board->{'ID'},
      COLUMNS => ["ID", "READ_ONLY"],
      KEY     => $UB::QUERY{'TID'}
    )
  ) || &HTML::Error (CODE => "POST_NOT_FOUND");

  if ( ( ($UB::MEMBER{'LOGIN'} == 1) && ($UB::MEMBER{'LEVEL'} ne "70") && ($UB::MEMBER{'LEVEL'} ne "100") ) || ($UB::MEMBER{'LOGIN'} == 0)) {
    if ($Board->{'STATUS'} == 50) {
      &Standard::FileOpen(*DATA, "r", "$SYSTEM::DB_PATH/B".$Board->{'ID'}."/READ-LEVEL-00.dat");
        my $READ_LEVEL_00 = join ("", <DATA>);
      close (DATA);

      if ($READ_LEVEL_00 ne "*") {
        if ($UB::MEMBER{'LOGIN'} == 1) {
          &Login unless &Standard::GetBoardPermission ($Board->{'ID'}, "READ", $UB::MEMBER{'LEVEL'}, $UB::MEMBER{'GROUP'});
        } else {
          &Login;
        }
      }
    } elsif ($Board->{'STATUS'} == 30) {
      &HTML::Error(CODE => "BOARD_INACTIVATE");
    } elsif ($Board->{'STATUS'} != 70) {
      &HTML::Error(CODE => "BOARD_INACTIVATE");
    }
  }

# =========================================================================== #
# Printing Forward Form

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

  &Standard::FileOpen(*HEADER, "r", "$SYSTEM::DB_PATH/B".$Board->{'ID'}."/header.inc");
    my $HEADER = join ("", <HEADER>);
  close (HEADER);

  &Standard::FileOpen(*FOOTER, "r", "$SYSTEM::DB_PATH/B".$Board->{'ID'}."/footer.inc");
    my $FOOTER = join ("", <FOOTER>);
  close (FOOTER);

  my $BoardOption = &Standard::GetBoardsList("", "", "", 1, "", $Board->{'ID'});

  my %FORM = (
    "CATEGORY.ID"       => $Category->{'ID'}      ,
    "CATEGORY.TITLE"    => $Category->{'TITLE'}   ,

    "BOARD.ID"          => $Board->{'ID'}         ,
    "BOARD.TITLE"       => $Board->{'TITLE'}      ,
    "BOARD.UB_CODES"    => $Board->{'UB_CODES'}   ,
    "BOARD.HTML_TAGS"   => $Board->{'HTML_TAGS'}  ,
    "BOARD.FILE_ATTACH" => $Board->{'FILE_ATTACH'},

    "BOARD.HEADER"      => $HEADER                ,
    "BOARD.FOOTER"      => $FOOTER                ,

    "TOPIC.ID"          => $UB::QUERY{'TID'}      ,

    "SHOW.BOARDS.LIST"  => 1                      ,
    "BOARDS.LIST"       => $BoardOption           ,

    "ADDRESS"           => "<a href=\"$SYSTEM::UB_URL/UltraBoard.$SYSTEM::EXT?action=Category&CID=".$Category->{'ID'}."&SID=".$UB::MEMBER{'SESSION'}."\" style=\"color:$UB::STYLE{'NORMAL_TEXT_COLOR'}\">".$Category-> {'TITLE'}."</a>".
                           " / ".
                           "<a href=\"$SYSTEM::UB_URL/UltraBoard.$SYSTEM::EXT?action=Headlines&BID=".$Board->{'ID'}."&SID=".$UB::MEMBER{'SESSION'}."\" style=\"color:$UB::STYLE{'NORMAL_TEXT_COLOR'}\">".$Board-> {'TITLE'}."</a>",

    &Standard::ExtraVariables()
  );

  $FORM{'FORM.YOUR.NICKNAME'}    = $UB::QUERY{'FORM_YOUR_NICKNAME'}    || $UB::MEMBER{'NICKNAME'} || $UB::COOKIES{'NICKNAME'}; #|| $UB::CGI->cookie('NICKNAME');
  $FORM{'FORM.YOUR.EMAIL'}       = $UB::QUERY{'FORM_YOUR_EMAIL'}       || $UB::MEMBER{'EMAIL'}    || $UB::COOKIES{'EMAIL'}   ; #|| $UB::CGI->cookie('EMAIL');
  $FORM{'FORM.FRIEND.NICKNAME'}  = $UB::QUERY{'FORM_FRIEND_NICKNAME'};
  $FORM{'FORM.FRIEND.EMAIL'}     = $UB::QUERY{'FORM_FRIEND_EMAIL'};

  $FORM{'FORM.SUBJECT'}     = $UB::QUERY{'FORM_SUBJECT'}     || "";
  $FORM{'FORM.MESSAGE'}     = $UB::QUERY{'FORM_MESSAGE'}     || "";

  $FORM{'TOPIC.URL'}        = "$SYSTEM::UB_URL/UltraBoard.$SYSTEM::EXT?action=Read&BID=$UB::QUERY{'BID'}&TID=$UB::QUERY{'TID'}";

  $FORM{'ERROR.MESSAGE'}    = ((exists $Forward::DYNAMIC{"LANGUAGE.".$ERROR}) ? $Forward::DYNAMIC{"LANGUAGE.".$ERROR} : $ERROR);

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

sub Login {
  print "Location: $SYSTEM::UB_URL/UltraBoard.$SYSTEM::EXT?action=Login&refer=Forward&BID=".$UB::QUERY{'BID'}."&TID=".$UB::QUERY{'TID'}."\n\n";
}

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