#!/usr/bin/perl
######################################################################
# RingWorld v1.7                                                     #
#--------------------------------------------------------------------#
# Copyright 1999-2001 TRXX Programming Group                         #
# Programming by Michael "TRXX" Sissine                              #
# All Rights Reserved                                                #
# http://www.trxx.co.uk                                              #
# trxx@trxx.co.uk                                                    #
######################################################################
# Variables Section
open (F, "<rworld.cfg");
@commands=<F>;
close (F);
foreach (@commands)
{
	eval $_;
}

######################################################################
# Main Section                                                       #
######################################################################
# Get data
($farg,$sarg)=split("&",$ENV{QUERY_STRING});
($webring)=$farg=~/=(.+)/;
($start)=$sarg=~/=(.+)/;

# Get info
if (-e "$basepath/$webring.wrd")
{
open (F,"<$basepath/$webring.wrd");
flock(F,$LOCK_EX);
@data=<F>;
flock(F,$LOCK_UN);
close (F);
($name,$email,$description,$wurl,$webringname)=split("\t",shift(@data));
$fullrn=$webringname;
$fullrn=~s/_/ /g;
$fullrn=qq~<a href="$wurl" target="_blank">$fullrn</a>~ if $wurl;
foreach (@data)
{
	chop;
	($nm,$tit,$uurl,$desc,$iflg)=split("\t",$_);
	push(@ndata,"$tit\t$uurl\t$desc") unless ($iflg);
}
@data=@ndata;
push (@footer,"<table width=\"100%\" border=0><tr>");
$icount=scalar(@data);
if (scalar (@data)>10)
{
	if ($start>0)
	{
		$pstart=$start-1;
		push(@footer,"<td width=\"15%\" align=\"center\"><a href=\"$cgi/rwgetlst.cgi?n=$webring&s=$pstart\"><img src=\"$ringworld/images/rwprev.gif\" border=0></a></td>");
	}
	else {push(@footer,"<td width=\"15%\" align=\"center\"></td>");}
	push(@footer,"<td width=\"70%\" align=\"center\"><img src=\"$ringworld/images/rwline.gif\"></td>");
	if ($start*10+10<scalar(@data))
	{
		$nstart=$start+1;
		push(@footer,"<td width=\"15%\" align=\"center\"><a href=\"$cgi/rwgetlst.cgi?n=$webring&s=$nstart\"><img src=\"$ringworld/images/rwnext.gif\" border=0></a></td>");
	}
	else {push(@footer,"<td width=\"15%\" align=\"center\"></td>");}
}
else {push(@footer,"<td width=\"100%\" align=\"center\"><img src=\"$ringworld/images/rwline.gif\"></td>");}
push (@footer,"</tr></table>");
if ($start*10+10>scalar(@data))
{
	$i=$start*10;
	while($i<scalar(@data))
	{
		($title,$uurl,$desc)=split("\t",$data[$i]);
		push(@result,"<li><a href=\"$uurl\"><font face=\"Arial\" size=\"2\">$title</font></a><br><font face=\"Arial\" size=\"2\">$desc</font></li>\n");
		$i++;
	}
}
else
{
	$i=$start*10;
	$last=$i+10;
	while($i<$last)
	{
		($title,$uurl,$desc)=split("\t",$data[$i]);
		push(@result,"<li><a href=\"$uurl\"><font face=\"Arial\" size=\"2\">$title</font></a><br><font face=\"Arial\" size=\"2\">$desc</font></li>\n");
		$i++;
	}
}
if (!@result)
{
	push(@result,"<li>Empty WebRing</li>");
}
}
else
{
	push(@result,"<li>Sorry webring <b>$webring</b> is not longer exist</li>");
	push(@footer,"<table width=\"100%\" border=0><tr><td width=\"100%\" align=\"center\"><img src=\"$ringworld/images/rwline.gif\"></td></tr></table>");
}
# Print Results
open (F,"<$rwpath/template/sitelist.tpl");
@html=<F>;
close (F);
$html=join("\n",@html);
print "HTTP/1.0 200 Found\n" if ($sysid eq "Windows");
print "content-type: text/html\n\n";
eval $html;
