#!/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
$start=$ENV{QUERY_STRING};

# Get Info
open (F,"<$basepath/webrings.lst");
flock(F,$LOCK_EX);
@data=<F>;
flock(F,$LOCK_UN);
close (F);
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/rwgetrlist.cgi?$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/rwgetrlist.cgi?$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))
	{
		$cnt=$i+1;
		chop($data[$i]);
		($data[$i],$ccc)=split("\t",$data[$i]);
		open (F,"<$basepath/$data[$i].wrd");
		flock(F,$LOCK_EX);
		@dta=<F>;
		flock(F,$LOCK_UN);
		close (F);
		($name,$email,$description,$wurl,$webringname)=split("\t",$dta[0]);
		$fullrn=$webringname;
		$fullrn=~s/_/ /g;
		$fullrn=qq~<a href="$wurl" target="_blank">$fullrn</a>~ if $wurl;
		$total=@dta-1;
		push(@result,qq~<tr><td width="100%" bgcolor="#CECE00"><font face="Arial" size="2" color="#000000"><center>$cnt. WEBRING: $fullrn ($total sites)</center></font></td></tr><tr><td width="100%"><font face="Arial" size="2"><b>Owner Name:</b> $name<br><b>Owner e-mail:</b> $email<br><b>Description:</b><br> $description</font></td></tr>\n~);
		$i++;
	}
}
else
{
	$i=$start*10;
	$last=$i+10;
	while($i<$last)
	{
		$cnt=$i+1;
		chop($data[$i]);
		($data[$i],$ccc)=split("\t",$data[$i]);
		open (F,"<$basepath/$data[$i].wrd");
		flock(F,$LOCK_EX);
		@dta=<F>;
		flock(F,$LOCK_UN);
		close (F);
		($name,$email,$description,$wurl,$webringname)=split("\t",$dta[0]);
		$fullrn=$webringname;
		$fullrn=~s/_/ /g;
		$fullrn=qq~<a href="$wurl" target="_blank">$fullrn</a>~ if $wurl;
		$total=@dta-1;
		push(@result,qq~<tr><td width="100%" bgcolor="#CECE00"><font face="Arial" size="2" color="#000000"><center>$cnt. WEBRING: $fullrn ($total sites)</center></font></td></tr><tr><td width="100%"><font face="Arial" size="2"><b>Owner Name:</b> $name<br><b>Owner e-mail:</b> $email<br><b>Description:</b><br> $description</font></td></tr>\n~);
		$i++;
	}
}
if (!@result)
{
	push(@result,"<tr><td>No WebRings</td></tr>\n");
}

# Print Result
open (F,"<$rwpath/template/ringlist.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;
