#!/usr/bin/perl -T
use lib 'lib';

############################> Ringlink <############################
#                                                                  #
#  $Id: rand.pl,v 1.45 2009/01/03 08:39:54 gunnarh Exp $           #
#                                                                  #
#  Ringlink is a CGI Perl program that provides the tools          #
#  necessary to run and administer rings of websites.              #
#                                                                  #
#  Copyright © 2000-2009 Gunnar Hjalmarsson                        #
#  Ringlink homepage: http://www.ringlink.org/                     #
#                                                                  #
#  Ringlink is free software; you can redistribute it and/or       #
#  modify it under the terms of the GNU General Public License as  #
#  published by the Free Software Foundation; either version 2 of  #
#  the License, or (at your option) any later version.             #
#                                                                  #
#  Ringlink 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. See the    #
#  GNU General Public License for more details.                    #
#                                                                  #
#  You should have received a copy of the GNU General Public       #
#  License along with this program; if not, write to the Free      #
#  Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,  #
#  MA  02111-1307  USA                                             #
#                                                                  #
####################################################################

use CGI::Carp 'fatalsToBrowser';
BEGIN	{ CGI::Carp -> VERSION(1.20) }
use strict;

use rlmain 3.3;

rlmain::execstart;
rlmain::inittests;
my $activesite = 0;
my $i = 0;
my $browser = rlmain::browser();
for (@rlmain::activesites)	{
  if ($_ =~ /^\Q$rlmain::data{'siteid'}\E\t/)	{
    $activesite = 1;
    splice (@rlmain::activesites, $i, 1) if scalar @rlmain::activesites > 1;
    rlmain::addgenhits ($rlmain::data{'siteid'}) if $browser;
    last;
  }
  $i ++;
}
rlmain::naverror if !$activesite && $rlmain::data{'siteid'};
my @sitevalues = split (/\t/, splice (@rlmain::activesites, int (rand (scalar @rlmain::activesites)), 1));
for (@rlmain::sitenames)	{
  ${$rlmain::refs{$_}} = shift (@sitevalues);
}
rlmain::addrechits ($rlmain::siteid) if $browser;
rlmain::redirect ($rlmain::entryURL);

