#!/usr/bin/perl -T
# top.pl - top level entry point for a HyperNews site.
# Copyright HyperNews.org, 1998

# Add current directory to load path.
$0 = $ENV{SCRIPT_FILENAME} if $0 =~ m{^/dev};
$0 =~ m{^(.*)/[^/]+$ }x;   $hnbin = $1 || '.';
unshift(@INC, $hnbin, "$hnbin/.scripts"); 

require "Admin/hnrc";

&feval('&Public()');

sub Public {

    require "urc.pl";
    require "member-lib.pl";
    require 'hnview-lib.pl';
    require "formlib.pl";

    my %form = &GetFormArgs();

    # Check for authentication.
    &checkAuthenticated($form{UserID}, $form{Password}, 
			$form{remoteUser}, $form{adminPassword});

    &checkAuthenticated();
    my $isAdmin = $authenticated && &isAdmin($remoteUser);


    $URL = $ENV{'PATH_INFO'};

    my $thisURL = &URLencode($ENV{REQUEST_URI} || 
			     "$editResponseURL$URL");
    my $thisUserID = "userid=$remoteUser" if $remoteUser;
    my $redirectURL = "$loginURL?$thisUserID&url=$thisURL";

    # Need to check whether URL is for SECURED or Admin.
    if ($manualSecurity == 1 && !$authenticated && $hnReadSF > 1) {
	# Try logging in first.  Need to avoid login loop.
	&printRedirect($redirectURL);
    }

    &access1($hnReadSF, 4, '', $remoteUser, 
		 "User <strong> $remoteUser </strong> is not permitted
 to access this system.<p>",
		 $authenticated);

 
    my $whoami = &sustring($remoteUser);
    if ($whoami) { $whoami = "You are authenticated as: $whoami <P>"; }

    my $adminEmail = &addressOf($hnAdmin[0]) || $hnAdmin[0];

    $gifsOK = $ENV{'HTTP_ACCEPT'} =~ m,(image/gif)|(\*/\*),;
    &HNMsg("ACCEPT: $ENV{HTTP_ACCEPT}") if $debug;


    my $setup_long_form_URL;
    if ($ENV{'SCRIPT_NAME'} =~ m{\.cgi$ }x) {
      $setup_long_form_URL = "$hnAdminURL/setup-form.cgi";
    }
    else {
      $setup_long_form_URL = "$hnAdminURL/setup-form.pl";
    }


    &print_HTML_HEAD("Welcome to $hnSystemName");

    print qq{
<H2>Welcome to $hnSystemName</H2>

 This site uses the <A
 HREF="http://www.hypernews.org"><B>HyperNews</B></A> system, version
 $hnversion. See the <A
 HREF="http://www.hypernews.org/HyperNews/get/hypernews.html">
 HyperNews Home Page</A> for lists of forums at other HyperNews sites.
<P>

};

    my $test_text = qq{
You are welcome to try out HyperNews on the 
<A HREF="$hntestURL">HyperNews.org Test Forum</a>.
} if $hntestURL;


    print qq{
Here are some brief instructions on how to use HyperNews.  Please see
the more detailed instructions if you have questions.  Email <a
HREF="mailto:$adminEmail"><B>$adminEmail</B></A> if you have problems
using this HyperNews site.   $test_text <P>

$whoami
};

    print "<TABLE>\n";

    if ($instructionsURL) {
      print qq{
<TR><TD VALIGN=TOP>
};

      &commandLink("$instructionsURL#Reading", $targetBlank,
		   "Help for $hnSystemName $hnversion",
		   "help.gif", 
               $commandIconXsize, $commandIconYsize,
		   "Help for $hnSystemName $hnversion");

    print qq{
</TD>
<TD>
Get more detailed help. <P>
</TD></TR>
};
    }

    if ($searchURL) {
      print qq{
<TR><TD VALIGN=TOP>
};

      &commandLink($searchURL, $targetBlank,
		   "Search $hnSystemName",
		   "search.gif", 
               $commandIconXsize, $commandIconYsize,
		   "Search $hnSystemName");

      print qq{
</TD>
<TD>
Search the contents of all the public HyperNews groups at UMDNJ.<p>
</TD></TR>
};
    }


    if ($viewMembers) {
	$viewMsg = "list members, ";
    }

    if (!$authenticateInquiries) {
	$inquireMsg = "display more info about individual members,";
    }

    if (!$authenticated && $joinSF && $joinSF < 3 || $isAdmin) {
       $registerMsg = "<A HREF=\"$editMemberURL\">
register as a new member</A>,";
    }

    if ($joinSF && !$externalSecurity) {

	print qq{
<TR><TD VALIGN=TOP>
};

	&commandLink("$viewMembersURL", $targetBlank,
		     "View list of $hnSystemName members",
		     "members.gif", 
		     $commandIconXsize, $commandIconYsize,
		     "Members");

	print qq{
</TD>
<TD>
With this button you can
$viewMsg 
$inquireMsg 
$registerMsg or 
update your member info. 
Membership applies to all forums at this site.
<P>
</TD></TR>
};
    }

  
    if (($editArticleSF && ($editArticleSF < 3)) || $isAdmin) {
	print qq{
<TR><TD VALIGN=TOP>
};

	&commandLink("$editArticleURL", $targetBlank,
		     "Create or update a forum",
		     "", 
		     $commandIconXsize, $commandIconYsize,
		     "Edit Forum");


	print qq{
</TD>
<TD>
    Create or update a forum.  
  (<A HREF=\"http://www.hypernews.org/HyperNews/get/hypernews/base-articles.html\">more instructions</A>)

<P>
</TD></TR>
};
    };




    print qq{
<TR><TD COLSPAN=2>
<B>When reading a forum or message, use the following buttons.</B>
</TD></TR>
};

    print qq{
<TR><TD VALIGN=TOP>
<IMG SRC=\"$hniconsURL/add.gif\" BORDER=0>
</TD><TD>

Add a message to the forum.  To add a reply to a message, first
make sure you are reading the message, then click on the Add Message button.
};

    print qq{
<TR><TD VALIGN=TOP> 
<IMG SRC=\"$hniconsURL/email.gif\" BORDER=0>
</TD><TD>

Subscribe to a forum or message.  You will get
email when a message or reply is added.  Also use this
button to Unsubscribe.
</TD></TR>
};



    print qq{
<TR><TD VALIGN=TOP> 
<img src="$hniconsURL/Inline1.gif" alt="[ Inline 1 ]"> 
<BR>
<img src="$hniconsURL/InlineAll.gif" alt="[ Inline All ]">
</TD><TD>

In inline mode, the contents of the messages will be displayed on your
screen one after another.  If you inline only one level, the reply
messages will be shown in outline mode.  
</TD></TR>
};

    print qq{
<TR><TD VALIGN=TOP> 
<img src="$hniconsURL/Outline1.gif" alt="[ Outline 1 ]"> 
<BR>
<img src="$hniconsURL/Outline2.gif" alt="[ Outline 2 ]"> 
<BR>
<img src="$hniconsURL/Outline3.gif" alt="[ Outline 3 ]"> 
<BR>
<img src="$hniconsURL/OutlineAll.gif" alt="[ Outline All ]">
</TD><TD>
In outline mode, only message titles are shown, in which case you select
the message whose content you wish to read.
</TD></TR>
};

    print qq{
<TR><TD VALIGN=TOP> 
<img src="$hniconsURL/prev.gif" alt="[ Previous ]">
<BR>
<img src="$hniconsURL/next.gif" alt="[ Next ]">
<BR>
<img src="$hniconsURL/in.gif" alt="[ More ]">
</TD><TD>
Navigate the thread of message within one window.
</TD></TR>
};

    print qq{
<TR><TD VALIGN=TOP> 
<img src="$hniconsURL/frames.gif" alt="[ Frames ]">
</TD><TD>
Creates a multi-frame view of the forum that may be easier for you to
navigate.  
</TD></TR>
};

    if ($isAdmin) {
      print qq{
<TR><TD VALIGN=TOP> 
<IMG SRC=\"$hniconsURL/hnicon.gif\" BORDER=0>
</TD><TD>

<A HREF="$setup_long_form_URL">Setup HyperNews</A>

</TD></TR>
};
    };

    print qq{
</TABLE>
};


    if (($autoGenerateChildForumList && $displayChildren)
	|| @childForums) {
	print qq{
<P> Every page has a list of other forums that are available.  Related
forums may be listed that are at a lower level, higher level, or at
the same level.  Forums at a lower level are generally about subtopics.  
Below is a list of the top-most forums at this site.  <P> 
};
      };


    print qq{


<H1>Other discussion groups</H1>

<form method=POST action="http://www.ForumOne.com/cgi-prosody/srch">
<table>
<tr>
<td> <A href="http://www.ForumOne.com/"><IMG
    src="http://www.ForumOne.com/f1logo2.gif"
    border=0 height=101 width=93 align=top alt=""></A> </td>

<td> <A href="http://www.ForumOne.com/">
Forum One</a> offers a searchable
index of thousands of web-based discussion forums. 

<input name="DATABASE" type=hidden value="f1">
<input name="SEARCH_TYPE" type=hidden value="SIMPLE">
<input name="TERM_1">&nbsp;&nbsp;&nbsp;
<input type="submit" value="Search">
</td>
</tr></table>
</form>

};


    &printEnd();
}


sub commandLink {
  # Print a command link.
  my ($commandURL, $target, $msg, $gif, $width, $height, $alt, $align) = @_;
  my $alignment = ($align ?  'ALIGN="absmiddle"' : '');
  my $anchor = "<A HREF=\"$commandURL\" $target
 onMouseOver=\"return window.help('$msg');\"
 onMouseOut=\"return window.help('');\">";
  if ($gifsOK) {
    # Netscape 2.0 needs the width and height with the javascript.
    print "
$anchor
 <IMG SRC=\"$hniconsURL/$gif\" BORDER=0  
 WIDTH=$width HEIGHT=$height
 ALT=\"$alt\"
 $alignment></A>\n";
      }
  else {
    # The $TD$B is not always right.
    print "$TD$B
$anchor
 $alt</A>$endB$endTD \n";
  }
}

