#!/usr/bin/perl
use CGI::Carp qw(fatalsToBrowser);
$version="2.3 Pro build 2";
require "config/megatoplist.cfg";
################################################################################
#### Megatoplist                                                            ####
#### Version 2.3 Pro build 2 Date: 13.02.2005                               ####
#### Support: webmaster@topcgi.de                                           ####
#### Updates: http://www.topcgi.de                                          ####
#### Language: German - Deutsch                                             ####
#### for other language versions, vistit: http://www.topcgi.de              ####
####                                                                        ####
#### Copyright notice:                                                      ####
#### Dieses Programm ist keine Freeware und darf somit nicht an dritte      ####
#### weitergegeben werden. Weiter darf der Programmcode verÄndert werden.   ####
#### Es ist aber untersagt, die Copyrighthinweise zu entfernen.             ####
####                                                                        ####
####  This script is not freeware. Feel free to modify the source-code.     ####
####  It is not allowed to remove the advertising banner or the copyright   ####
####  notices.                                                              ####
################################################################################

if ($ENV{'REQUEST_METHOD'} eq 'POST') {
  read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
} else {
  $buffer = $ENV{'QUERY_STRING'};
}
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
  ($name, $value) = split(/=/, $pair);
  $name =~ tr/+/ /;
  $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  $value =~ tr/+/ /;
  $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  $value =~ s/\|//eg;
  $FORM{$name} = $value;
}
if    ($FORM{action} eq "new_member")       { &confirm_rules;}
elsif ($FORM{action} eq "rules_accept")     { &new_member_form;}
elsif ($FORM{action} eq "click_out")        { &checkip;        }
elsif ($FORM{action} eq "click_in")         { &check_gateway_option;  }
elsif ($FORM{action} eq "click_in_gateway") { &check_gateway;  }
elsif ($FORM{action} eq "edit_account")     { &edit_form;      }
elsif ($FORM{action} eq "vote")             { &vote_form;      }
elsif ($FORM{action} eq "vote_final")       { &checkip;        }
elsif ($FORM{action} eq "show_vote")        { &show_vote;      }
elsif ($FORM{action} eq "lostpassform")     { &lost_pass_form; }
elsif ($FORM{action} eq "regeln")           { &regeln;         }
elsif ($FORM{lost_password} eq "ja")        { &search_pass;    }
elsif ($FORM{ID})                           { &awm_click_out   }
else {
      &check_update;
      print "Location: $no_cgi_url/$dateiname.$dateiext\n\n";
      exit;
      }

sub check_gateway {
### delete old gateways
$maxgatetime = ($gateway_maxtime*60);
$zeit = time;
open (IP,"<config/log/session/session.log")||die("Konnte die Datei session.log nicht einlesen");
if ($use_flock eq "1") {flock (IP,1);}
@OLDGW =<IP>;
foreach $line (@OLDGW) {
    @TEMP_GW = split(/\|/,$line);
    if ((($TEMP_GW[1]+$maxgatetime)>$zeit)&&($TEMP_GW[0] ne $FORM{session}))
       {push @NEWGW,"$line";}
    if ($TEMP_GW[0] eq $FORM{session})
       {$usersession="$line"; }
    }
if ($use_flock eq "1") {flock (IP,8);}
close (IP);
open (NEWIP,">config/log/session/session.log")||die("Konnte die Datei session.log nicht beschreiben");
if ($use_flock eq "1") {flock (NEWIP,1);}
print NEWIP @NEWGW;
if ($use_flock eq "1") {flock (NEWIP,8);}
close (NEWIP);
### check actual gateway
if ($usersession ne"")
{
 @SESSIONDAT = split(/\|/,$usersession);
 $FORM{account}="$SESSIONDAT[2]";
 $FORM{action}="click_in";
 &checkip;
 }
else {
      print "Location: $no_cgi_url/$dateiname.$dateiext\n\n";
      exit;
     }
}

sub check_gateway_option {
if   ($gateway eq "on") {&create_gateway_session;}
else {&checkip;}
}

sub create_gateway_session {
  ### create session ID
  @BITS = ('a'..'Z', '0'..'9');
  $session_id="";
   for(0..9) {
    my $BITS = $BITS[ int(rand($#BITS + 1)) ];
    $session_id .="$BITS";
  }
  ### log gatewaysession in session.log
  $sessiontime = time();
  open (SESSIONLOG,">>config/log/session/session.log")||die("Konnte die Datei session.log nicht beschreiben");
  if ($use_flock eq "1") {flock (SESSIONLOG,1);}
  print SESSIONLOG "$session_id|$sessiontime|$FORM{account}|\n";
  if ($use_flock eq "1") {flock (SESSIONLOG,8);}
  close(SESSIONLOG);
  ### create gatewaypage and redirect user
  print "Content-type: text/html\n\n";
            open (DATEI,"<$cgi_root_path/config/insert/gateway.dat")||die("Konnte die Datei gateway.log nicht einlesen");
            if ($use_flock eq "1") {flock (DATEI,1);}
            @DATEN =<DATEI>;
            if ($use_flock eq "1") {flock (DATEI,8);}
            close (DATEI);
            foreach $line (@DATEN)
            { $line =~ s/\<URL\>/$cgi_root_url\/toplist.pl/gio;
              $line =~ s/\<SESSION\>/$session_id/gio;
            print $line;
            }
exit;
}

sub checkip {

$userip = $ENV{REMOTE_ADDR};
if($ENV{'HTTP_VIA'} || $ENV{'HTTP_X_FORWARDED_FOR'})
   {
   $found_proxy_server="on";
   ## Adminupdate check
   open (UPDATE, "<$cgi_root_path/config/adminproxy.txt");
   if ($use_flock eq "1") {flock (UPDATE,1);}
   $line =<UPDATE>;
   if ($use_flock eq "1") {flock (UPDATE,8);}
   close (UPDATE);
          if ($line eq "adminproxy_on"){
               $found_proxy_server="no";
               open (UPDATE, ">$cgi_root_path/config/adminproxy.txt");
               if ($use_flock eq "1") {flock (UPDATE,1);}
              print UPDATE "";
               if ($use_flock eq "1") {flock (UPDATE,8);}
               close (UPDATE);
               chmod 0777, "$cgi_root_path/config/adminproxy.txt";
               }
    }
else {$found_proxy_server="no";}
$zeit = time;
                                     ##### Festlegung wie alt die IP-Adressen sein duerfen
$minvotetime = ($minzeit_vote*60);
$clickintime =($minzeit_clickin*60);
$clickouttime=($minzeit_clickout*60);
$maxiptime = ($max_log_alter*3600);

                                     ##### alte IP-Eintraege loeschen
open (IP,"<config/log/ip.log")||die("Konnte die Datei ip.log nicht einlesen");
if ($use_flock eq "1") {flock (IP,1);}
@OLDIP =<IP>;
foreach $line (@OLDIP) {
    @TIME = split(/\|/,$line);
    if (($TIME[1]+$maxiptime)>$zeit){push @NEWIP,"$line";}
    }
if ($use_flock eq "1") {flock (IP,8);}
close (IP);
open (NEWIP,">config/log/ip.log")||die("Konnte die Datei session.log nicht beschreiben");
if ($use_flock eq "1") {flock (NEWIP,1);}
print NEWIP @NEWIP;
if ($use_flock eq "1") {flock (NEWIP,8);}
close (NEWIP);
#### IPCheck CLICK_IN
if  ($FORM{action} eq  "click_in"){
        ### log proxyserver click in (only redirect to toplist.html without update toplist to prevent serveroverload!)
        if (($found_proxy_server eq "on")&&($proxyfilter eq "on"))
        { ### proxylogbuch ein/aus
          if ($do_log_proxy ne "no"){
          open (PROXY_LOG,">>config/log/proxy.log")||die("Konnte die Datei proxy.log nicht einlesen");
          if ($use_flock eq "1") {flock (PROXY_LOG,1);}
          print PROXY_LOG "$userip|$zeit|$FORM{action}|$FORM{account}|$ENV{'HTTP_VIA'}|$ENV{'HTTP_X_FORWARDED_FOR'}\n";
          if ($use_flock eq "1") {flock (PROXY_LOG,8);}
          close(PROXY_LOG);
          }
                if ($click_option eq alternative_URL)
                  {
                    if ($click_in_url_alternative eq ""){print "Location: $no_cgi_url/$dateiname.$dateiext\n\n";}
                    else{print "Location: $click_in_url_alternative\n\n";}
                  }
              else{print "Location: $no_cgi_url/$dateiname.$dateiext\n\n";};
              exit;
        }
#### click in without proxyserver
else {
        $last_click_in_time=0;
        $click_in_gefunden=0;
        foreach $line (@NEWIP)
            {
             chomp ($line) if ($line =~ /\n/);
             @CLICK_IN_IP = split(/\|/,$line);
                 if (($CLICK_IN_IP[0] eq $userip)&&($CLICK_IN_IP[2] eq $FORM{action})&&($CLICK_IN_IP[3] eq $FORM{account}))
                    {$click_in_gefunden="1";
                    $last_click_in_time=$CLICK_IN_IP[1];
                    }
            }
 ### log doubleclick-in
          if (($click_in_gefunden eq "1")&&($zeit<($last_click_in_time+$clickintime))){
               ### klickin/out logbuch an aus
               if ($do_log_klick ne "no"){
               open (CLICK_LOG,">>config/log/click.log")||die("Konnte die Datei click.log nicht beschreiben");
               if ($use_flock eq "1") {flock (CLICK_LOG,1);}
               print CLICK_LOG "$userip|$zeit|$FORM{action}|$FORM{account}|\n";
               if ($use_flock eq "1") {flock (CLICK_LOG,8);}
               close(CLICK_LOG);
               }
               &check_update;
               if ($click_option eq alternative_URL)
                  {
                    if ($click_in_url_alternative eq ""){print "Location: $no_cgi_url/$dateiname.$dateiext\n\n";}
                    else{print "Location: $click_in_url_alternative\n\n";}
                   }
                else{print "Location: $no_cgi_url/$dateiname.$dateiext\n\n";}
              }
####
          else {
                open (CLICK_IN_LOG,">>config/log/ip.log")||die("Konnte die Datei ip.log nicht beschreiben");
                if ($use_flock eq "1") {flock (CLICK_IN_LOG,1);}
                print CLICK_IN_LOG "$userip|$zeit|$FORM{action}|$FORM{account}\n";
                if ($use_flock eq "1") {flock (CLICK_IN_LOG,8);}
                close(CLICK_IN_LOG);
                &check_update;
                &log_click_in;
                if ($click_option eq alternative_URL)
                      {
                        if ($click_in_url_alternative eq ""){print "Location: $no_cgi_url/$dateiname.$dateiext\n\n";}
                        else{print "Location: $click_in_url_alternative\n\n";}
                      }
                else{print "Location: $no_cgi_url/$dateiname.$dateiext\n\n";}
                exit;
               }
        }
 }
#### IPCheck CLICK_out
if  ($FORM{action} eq  "click_out"){
     ##### click out with a proxyserver (only redirect to userpage without update toplist to prevent serveroverload!)
     if (($found_proxy_server eq "on")&&($proxyfilter eq "on"))
        {
         ### Klick in/out Logbuch an/aus
         if($do_log_klick ne "no"){
         open (PROXY_LOG,">>config/log/proxy.log")||die("Konnte die Datei proxy.log nicht beschreiben");
         if ($use_flock eq "1") {flock (PROXY_LOG,1);}
         print PROXY_LOG "$userip|$zeit|$FORM{action}|$FORM{account}|$ENV{'HTTP_VIA'}|$ENV{'HTTP_X_FORWARDED_FOR'}\n";
         if ($use_flock eq "1") {flock (PROXY_LOG,8);}
         close(PROXY_LOG);
         }
                $datensatz=0;
                open (ALLEACCOUNTS, "<$userdatapath/user.dat")||die("Konnte die Datei user.dat nicht einlesen");
                if ($use_flock eq "1") {flock (ALLEACCOUNTS,1);}
                @ALLEACCOUNTS = <ALLEACCOUNTS>;
                foreach (@ALLEACCOUNTS){
                                         @USER = split(/\|/, $ALLEACCOUNTS[$datensatz]);
                                         if ($USER[4] eq  $FORM{account})
                                               {
                                                $redirect   = "$USER[11]";
                                                $awm_status = "$USER[32]";
                                                $awm_system = "$USER[33]";
                                                $awm_id     = "$USER[34]";
                                               }
                                          $datensatz++;
                                        }
                if ($use_flock eq "1") {flock (ALLEACCOUNTS,8);}
                close (ALLEACCOUNTS);


                 if ($awm_status eq "awm_check_on")
                    {
                     &awm_check;exit;
                    }
                   else {print "Location: $redirect \n\n";exit;}
         }
   ##### click out without a proxyserver
   else {
             $last_click_out_time=0;
             $click_out_gefunden=0;
        foreach $line (@NEWIP) {
             chomp ($line) if ($line =~ /\n/);
             @CLICK_out_IP = split(/\|/,$line);
             if (($CLICK_out_IP[0] eq $userip)&&($CLICK_out_IP[2] eq $FORM{action})&&($CLICK_out_IP[3] eq $FORM{account}))
                {
                 $last_click_out_time=$CLICK_out_IP[1];
                 $click_out_gefunden=1;
                }
             }
          ### log doubleclick-out
          if (($click_out_gefunden eq "1")&&($zeit<($last_click_out_time+$clickouttime))){
               &check_update;
               $datensatz=0;
                open (ALLEACCOUNTS, "<$userdatapath/user.dat")||die("Konnte die Datei user.dat nicht einlesen");
                if ($use_flock eq "1") {flock (ALLEACCOUNTS,1);}
                @ALLEACCOUNTS = <ALLEACCOUNTS>;
                foreach (@ALLEACCOUNTS){
                                         @USER = split(/\|/, $ALLEACCOUNTS[$datensatz]);
                                         if ($USER[4] eq  $FORM{account})
                                               {
                                                $redirect   = "$USER[11]";
                                                $awm_status = "$USER[32]";
                                                $awm_system = "$USER[33]";
                                                $awm_id     = "$USER[34]";
                                               }
                                          $datensatz++;
                                        }
                if ($use_flock eq "1") {flock (ALLEACCOUNTS,8);}
              close (ALLEACCOUNTS);
              ### Klick in/out Logbich an/aus
              if ($do_log_klick ne "no"){
              open (CLICK_LOG,">>config/log/click.log")||die("Konnte die Datei click.log nicht beschreiben");
              if ($use_flock eq "1") {flock (CLICK_LOG,1);}
              print CLICK_LOG "$userip|$zeit|$FORM{action}|$FORM{account}|\n";
              if ($use_flock eq "1") {flock (CLICK_LOG,8);}
              close(CLICK_LOG);
              }
                if ($awm_status eq "awm_check_on")
                     {
                      &awm_check;exit;
                     }
                else {print "Location: $redirect \n\n";exit;}
              }

          else {
                open (CLICK_out_LOG,">>config/log/ip.log")||die("Konnte die Datei ip.log nicht beschreiben");
                if ($use_flock eq "1") {flock (CLICK_out_LOG,1);}
                print CLICK_out_LOG "$userip|$zeit|$FORM{action}|$FORM{account}\n";
                if ($use_flock eq "1") {flock (CLICK_out_LOG,8);}
                close(CLICK_out_LOG);
                &check_update;
                &log_click_out;
                exit;
               }
        }
}

#### IPCheck Vote
if  ($FORM{action} eq  "vote_final"){
    if (($found_proxy_server eq "on")&&($proxyfilter eq "on"))
        {
        ### log proxyserver vote
        if ($found_proxy_server eq "on")
             { ### Proxylogbuch an/aus
               if ($do_log_proxy ne "no"){
                open (PROXY_LOG,">>config/log/proxy.log")||die("Konnte die Datei proxy.log nicht beschreiben");
                if ($use_flock eq "1") {flock (PROXY_LOG,1);}
                print PROXY_LOG "$userip|$zeit|$FORM{action}|$FORM{account}|$ENV{'HTTP_VIA'}|$ENV{'HTTP_X_FORWARDED_FOR'}\n";
                if ($use_flock eq "1") {flock (PROXY_LOG,8);}
                close(PROXY_LOG);
               }
               push @FEHLER , "<p align=\"center\"><font face\=\"$font\" size\=\"$error_font_size\" color\=$error_font_color>\n";
               push @FEHLER , "Sie k&ouml;nnen nicht &uuml;ber einen Proxy-Server bewerten!<br><br>Proxy-Server: $ENV{'HTTP_VIA'} $ENV{'HTTP_X_FORWARDED_FOR'}</font></p>\n";
               &error;
             }
         }
      ### vote without proxyserver
      else {
            $lastvote_time = "0";
            $votegefunden = "0";

             foreach $line (@NEWIP) {
             chomp ($line) if ($line =~ /\n/);
             @VOTEIP = split(/\|/,$line);
             if (($VOTEIP[0] eq $userip)&&($VOTEIP[2] eq $FORM{action})&&($VOTEIP[3] eq $FORM{account}))
                {$votegefunden++;
                 $lastvote_time=$VOTEIP[1];
                }
             }
     if (($votegefunden <=($maxvote_pro_account-1))&&( $zeit > ($lastvote_time+$minvotetime))){
          open (VOTELOG,">>config/log/ip.log")||die("Konnte die Datei ip.log nicht beschreiben");
          if ($use_flock eq "1") {flock (VOTELOG,1);}
          print VOTELOG "$userip|$zeit|$FORM{action}|$FORM{account}\n";
          if ($use_flock eq "1") {flock (VOTELOG,8);}
          close(VOTELOG);
          &vote_final;&check_update;
          }
      ### log doublevote
      if (($votegefunden <=($maxvote_pro_account-1))&&( $zeit < ($lastvote_time+$minvotetime))){
          ### Votelogbuch an/aus
          if ($do_log_vote ne "no"){
          open (VOTELOG,">>config/log/vote.log")||die("Konnte die Datei vote.log nicht beschreiben");
          if ($use_flock eq "1") {flock (VOTELOG,1);}
          print VOTELOG "$userip|$zeit|$FORM{action}|$FORM{account}\n";
          if ($use_flock eq "1") {flock (VOTELOG,8);}
          close(VOTELOG);
          }
          push @FEHLER , "<p align=\"center\"><font face\=\"$font\" size\=\"$error_font_size\" color\=\"$error_font_color\">\n";
          push @FEHLER , "Sie k&ouml;nnen diesen Account nur alle $minzeit_vote Minuten bewerten!</font></p>\n";
          &error;
          }
      ### log doublevote
      if ($votegefunden > ($maxvote_pro_account-1)) {
          ### Votelogbuch an/aus
          if ($do_log_vote ne "no"){
          open (VOTELOG,">>config/log/vote.log")||die("Konnte die Datei vote.log nicht beschreiben");
          if ($use_flock eq "1") {flock (VOTELOG,1);}
          print VOTELOG "$userip|$zeit|$FORM{action}|$FORM{account}\n";
          if ($use_flock eq "1") {flock (VOTELOG,8);}
          close(VOTELOG);
          }
          push @FEHLER , "<p align=\"center\"><font face\=$font size\=\"$error_font_size\" color\=\"$error_font_color\">\n";
          push @FEHLER , "Sie k&ouml;nnen  den  \"$FORM{account}\" Account maximal $maxvote_pro_account mal pro Sitzung bewerten!</font></p>\n";
          &error;
          }
       }
    }
 }

sub check_update {
         $zeit = time();
     if (!-e "$no_cgi_path/$dateiname.$dateiext")
        { &create_new_toplist; }
     if (!-e "$cgi_root_path/config/reset.txt")
        { open (RESET, ">$cgi_root_path/config/reset.txt")||die("Konnte die Datei reset.txt nicht erzeugen");
          if ($use_flock eq "1") {flock (RESET,1);}
          print RESET $zeit;
          if ($use_flock eq "1") {flock (RESET,8);}
          close (RESET);
        }
     if (!-e "$cgi_root_path/config/reset_all.txt")
        { open (RESETALL, ">$cgi_root_path/config/reset_all.txt")||die("Konnte die Datei reset_all.txt nicht erzeugen");
          if ($use_flock eq "1") {flock (RESETALL,1);}
          print RESETALL $zeit;
          if ($use_flock eq "1") {flock (RESETALL,8);}
          close (RESETALL);
        }
     if (!-e "$cgi_root_path/config/update.txt")
        { open (UPDATE, ">$cgi_root_path/config/update.txt")||die("Konnte die Datei update.txt nicht erzeugen");
          if ($use_flock eq "1") {flock (UPDATE,1);}
          print UPDATE $zeit;
          if ($use_flock eq "1") {flock (UPDATE,8);}
          close (UPDATE);
        }
     if (!-e "$cgi_root_path/config/backup.txt")
        { open (BACKUP, ">$cgi_root_path/config/backup.txt")||die("Konnte die Datei backup.txt nicht erzeugen");
          if ($use_flock eq "1") {flock (BACKUP,1);}
          print BACKUP $zeit;
          if ($use_flock eq "1") {flock (BACKUP,8);}
          close (BACKUP);
        }
      open (RESET, "<$cgi_root_path/config/reset.txt")||die("Konnte die Datei reset.txt nicht einlesen");
      if ($use_flock eq "1") {flock (RESET,1);}
      $last_reset = <RESET>;
      if ($use_flock eq "1") {flock (RESET,8);}
      close (RESET);
      open (RESETALL,"<$cgi_root_path/config/reset_all.txt"||die("Konnte die Datei reset_all.txt nicht einlesen"));
      if ($use_flock eq "1") {flock (RESETALL,1);}
      $last_reset_all = <RESETALL>;
      if ($use_flock eq "1") {flock (RESETALL,8);}
      close (RESETALL);
      open (UPDATE,"<$cgi_root_path/config/update.txt")||die("Konnte die Datei update.txt nicht einlesen");
      if ($use_flock eq "1") {flock (UPDATE,1);}
      $last_update =<UPDATE>;
      if ($use_flock eq "1") {flock (UPDATE,8);}
      close (UPDATE);
      open (BACKUP,"<$cgi_root_path/config/backup.txt")||die("Konnte die Datei backup.txt nicht einlesen");
      if ($use_flock eq "1") {flock (BACKUP,1);}
      $last_backup =<BACKUP>;
      if ($use_flock eq "1") {flock (BACKUP,8);}
      close (BACKUP);

 if ($zeit > $last_backup+($backup_day*86400))
    { open (BACKUP,">$cgi_root_path/config/backup.txt")||die("Konnte die Datei backup.txt nicht beschreiben");
      if ($use_flock eq "1") {flock (BACKUP,1);}
      print BACKUP $zeit;
      if ($use_flock eq "1") {flock (BACKUP,8);}
      close (BACKUP);
      &backup;
    }
 if ($zeit > $last_reset+($reset_time*86400))
     { open (RESET, ">$cgi_root_path/config/reset.txt")||die("Konnte die Datei reset.txt nicht beschreiben");
      if ($use_flock eq "1") {flock (RESET,1);}
      print RESET $zeit;
      if ($use_flock eq "1") {flock (RESET,8);}
      close (RESET);
      &reset_account;
      &create_new_toplist;
     }
     elsif ($zeit > $last_reset_all+($reset_all_time*86400))
     { open (RESETALL, ">$cgi_root_path/config/reset_all.txt")||die("Konnte die Datei reset_all.txt nicht beschreiben");
       if ($use_flock eq "1") {flock (RESETALL,1);}
       print RESETALL $zeit;
       if ($use_flock eq "1") {flock (RESETALL,8);}
       close (RESETALL);
       &reset_all_accounts;
       &create_new_toplist;
     }
     elsif ($zeit > $last_update+($update_time*60))
     { open (UPDATE, ">$cgi_root_path/config/update.txt")||die("Konnte die Datei update.txt nicht beschreiben");
       if ($use_flock eq "1") {flock (UPDATE,1);}
       print UPDATE $zeit;
       if ($use_flock eq "1") {flock (UPDATE,8);}
       close (UPDATE);
       &update_account;
       &create_new_toplist;
     }
}

sub create_new_toplist {
### Userdaten werden ausgelesen und sortiert

open (ACCOUNT, "<$userdatapath/user.dat")||die("Konnte die Datei user.dat nicht einlesen");
            if ($use_flock eq "1") {flock (ACCOUNT,1);}
            @ALLEDATEN = <ACCOUNT>;
            if ($use_flock eq "1") {flock (ACCOUNT,8);}
close (ACCOUNT);
@ALLEDATEN = sort {$b <=> $a} @ALLEDATEN;
### Userdaten werden ueberprueft
    $datensatz = "0";
    $user_found= "0";

foreach (@ALLEDATEN)
    {
     @TEMPARRY = split (/\|/,$ALLEDATEN[$datensatz] );
      ### Array zur Toplistenerstellung
      if (($TEMPARRY[0] >=$min_click) && ($TEMPARRY[18] ne "0") && ($user_found < $max_in_list))
          {
             push (@TOPUSER, join ("\|", @TEMPARRY));
             $user_found++;
          }
      ### Array aktive Mitglieder
       if (($TEMPARRY[0] >=$min_click) && ($TEMPARRY[18] ne "0"))
          {
             push (@AKTIV,$TEMPARRY[4]);
          }

     $datensatz++;
    }
$eingetragene_member=$datensatz++;
$active_member=@AKTIV;
### Berechnung der Seitenanzahl
$temp_page = ($user_found/$user_per_page);
if ($temp_page <= "1")
    {
     $lastpage = "1";
    }
else {
      if ($temp_page =~ /\./)
      {
       $temp_page++;$lastpage =int($temp_page);

      }
      else
      {
       $lastpage=$temp_page;
      }
     }
### Seiten werden erstellt
if ($show_previos_position eq "on")
    {
    open (OLDPOSITION, "<$cgi_root_path/config/position.txt")||die("Konnte die Datei position.txt nicht einlesen");
    if ($use_flock eq "1") {flock (OLDPOSITION,1);}
    @OLDPOSITION =<OLDPOSITION>;
    if ($use_flock eq "1") {flock (OLDPOSITION,8);}
    close (OLDPOSITION);
    }
$time = time(); ### Zur Berechnung der Durschnittshits
$topliste="";
$aktueller_user_in_tabelle="1";
$aktueller_user_auf_seite ="1";
$aktuelle_seite ="1";
$platz="1";
$tabelle_offen="0";
$datensatztopliste="0";
$oldposition="0";
&werbung_auslesen;
### Fehlermeldung falls keine User in der Datenbank fuer die Topliste
#if ((!@TOPUSER)||(@TOPUSER eq "")){
if ($user_found eq "0"){
               $user_found="1";
               $no_user_in_database_fix="on"; ### Activate the Toplisturl on site_description
               $maximale_banneranzahl="0";    ### Dont show any Banner in the Toplist
               $fehlermeldung_user="0|0|0|0|BANNERBLITZ|passwortistgeheim|niemand|niemand|123456\@iuhiuhiuh.de|Keine Topliste Verfügbar|<br>Momentan befindet sich leider kein User in unserer Datenbank, der die Kriterien erfüllt, um in dieser Liste zu erscheinen. Bitte besuchen Sie und später noch einmal.<br> |http://www.bannerblitz.de|http://www.bannerblitz.de/non-cgi/banner/userbanner/bannerblitz.gif|60|468|1012496530|0|0|1|10|10|0|0|0|0|0|0|0|0|0|10|show_normal_banner|awm_check_off|alterskontrolle|1027782003|1|1|1|1|info\@wefdetzggf.de|1|alex|http://www.bannerblitz.de|http://www.bannerblitz.de/non-cgi/banner/userbanner/bannerblitz.gif|1|1|1009547414|0|0|1|0|0|0|0|0|0|0|0|0|0|0|0|show_normal_banner|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|";
               push @TOPUSER,$fehlermeldung_user;
               }

foreach (@TOPUSER)
    { @USER = split (/\|/, $TOPUSER[$datensatztopliste]);
     ### Erstellung der neuen position.txt
              $pushposition = "$USER[4]|$platz|\n";
              push @NEWPOSITION ,$pushposition;
      ### Suchen der letzten Position
      foreach $line (@OLDPOSITION){
                                   @TEMP = split (/\|/,$line);
                                   if ($TEMP[0] eq $USER[4]) {$oldposition=$TEMP[1]};
                                  }
      if (($aktuelle_seite eq "1")&&($aktueller_user_auf_seite eq 1)){&open_page;}
      if ($aktueller_user_in_tabelle eq 1){&open_table;}


$topliste .="<tr><td width=\"$toplist_cell_width1\" bgcolor=\"$table_body_color\">\n";
$topliste .="<p align=\"center\"><font face=\"$font_face_toplistrank\" size=\"$font_size_toplistrank\" color=\"$font_color_toplistrank\">$platz</font>\n";
if ($show_previos_position eq "on")
    {
    $topliste .="<font face=\"$font_face_toplistrank\" size=\"$font_size_toplistpreviousrank\" color=\"$font_color_toplistrank\" align=\"center\"><br>($oldposition)</font>\n";
    }
$topliste .="</p></td><td width=\"$toplist_cell_width2\" bgcolor=\"$table_body_color\">\n";

if ($platz <= $maximale_banneranzahl)
    { $topliste .="<a href=\"$cgi_root_url/toplist.pl?action=click_out&account=$USER[4]\" target=\"$target\">\n";
      ### show the userbanner (7 ways :-D)
      if ($USER[31] eq "show_normal_banner")
          {$topliste .="<center><img target=\"$target\" style=\"border: $borderwidth_userbanner_toplist solid $bodercolor_userbanner_toplist\" src=\"$USER[12]\" width=\"$USER[14]\" height=\"$USER[13]\" alt=\"$USER[9]\"></center></a> \n";}
      if ($USER[31] eq "show_banner_not_validate")
          {
           if ($alternative_banner_admincheck eq "standard_banner")
              {
              $topliste .="<center><img target=\"$target\" style=\"border: $borderwidth_userbanner_toplist solid $bodercolor_userbanner_toplist\" src=\"$no_cgi_url/alternative_userbanner/not_validate.gif\" width=\"468\" height=\"60\" alt=\"Mitgliedsbanner ist noch nicht freigeschaltet\"></center></a> \n";
              }
           if ($alternative_banner_admincheck eq "user_defined_banner")
              {
              $topliste .="<center><img target=\"$target\" style=\"border: $borderwidth_userbanner_toplist solid $bodercolor_userbanner_toplist\" src=\"$alternative_banner_admincheck_url\" width=\"$alternative_banner_admincheck_width\" height=\"$alternative_banner_admincheck_height\" alt=\"Mitgliedsbanner ist noch nicht freigeschaltet\"></center></a> \n";
              }
          }
      if ($USER[31] eq "show_no_banner")
          {
           if ($alternative_banner_no_userbanner eq "standard_banner")
              {
              $topliste .="<center><img target=\"$target\" style=\"border: $borderwidth_userbanner_toplist solid $bodercolor_userbanner_toplist\" src=\"$no_cgi_url/alternative_userbanner/no_banner.gif\" width=\"468\" height=\"60\" alt=\"Dieses Mitglied hat kein Banner angegeben\"></center></a> \n";
              }
           if ($alternative_banner_no_userbanner eq "user_defined_banner")
              {
              $topliste .="<center><img target=\"$target\" style=\"border: $borderwidth_userbanner_toplist solid $bodercolor_userbanner_toplist\" src=\"$alternative_banner_no_userbanner_url\" width=\"$alternative_banner_no_userbanner_width\" height=\"$alternative_banner_no_userbanner_heigth\" alt=\"Dieses Mitglied hat kein Banner angegeben\"></center></a> \n";
              }
          }
      if ($USER[31] eq "show_not_allowed")
          {
           if ($alternative_banner_rules eq "standard_banner")
              {
              $topliste .="<center><img target=\"$target\" style=\"border: $borderwidth_userbanner_toplist solid $bodercolor_userbanner_toplist\" src=\"$no_cgi_url/alternative_userbanner/against_rules.gif\" width=\"468\" height=\"60\" alt=\"Das Mitgliedsbanner verst&ouml;ßt gegen die Regeln\"></center></a> \n";
              }
           if ($alternative_banner_rules eq "user_defined_banner")
              {
              $topliste .="<center><img target=\"$target\" style=\"border: $borderwidth_userbanner_toplist solid $bodercolor_userbanner_toplist\" src=\"$alternative_banner_rules_url\" width=\"$alternative_banner_rules_width\" height=\"$alternative_banner_rules_height\" alt=\"Das Mitgliedsbanner verst&ouml;ßt gegen die Regeln\"></center></a> \n";
              }
           }
    }
$topliste .="<center>";
if ($show_user_sitename_link eq "on")
    {
    ### Fix the Links if no User is in Database
    if ($no_user_in_database_fix eq "on")
       { $topliste .="<font face=\"$font\" size=\"$fontsize_user_sitename_link\">";
         $topliste .="<a target=\"$target\" href=\"$cgi_root_url/toplist.pl\" target=\"_self\" title=\"Topliste neu laden\"><b>$USER[9]</b></a><br>";
       }
    else
        {
         $topliste .="<font face=\"$font\" size=\"$fontsize_user_sitename_link\">";
         $topliste .="<a target=\"$target\" href=\"$cgi_root_url/toplist.pl?action=click_out&account=$USER[4]\" target=\"$target_userbanner_toplist\"><b>$USER[9]</b></a><br>";
        }

    }
if ($show_user_beschreibung eq "on")
    {
    $topliste .="<font face=\"$font\" size=\"$fontsize_user_beschreibung\" $font_color>$USER[10]</font>";
    }

$topliste .="</center></td><td width=\"$toplist_cell_width3\" bgcolor=\"$table_body_color\">\n";
$topliste .="<p align=\"center\"><font face=\"$font\" size=\"$fontsize_user_hitin\" $font_color>$USER[0]</font>\n";
if ($show_hitin_geamt eq "on")
    {
    $topliste .="<br><br><font face=\"$font\" size=\"$fontsize_user_hitin_gesamt\" $font_color>($USER[16])</font></p>\n";
    }
$topliste .="</td><td width=\"$toplist_cell_width4\" bgcolor=\"$table_body_color\">\n";
$topliste .="<p align=\"center\"><font face=\"$font\" size=\"$fontsize_user_hitin\" $font_color>$USER[1]</font>\n";
if ($show_hitin_geamt eq "on")
    {
    $topliste .="<br><br><font face=\"$font\" size=\"$fontsize_user_hitin_gesamt\" $font_color>($USER[17])</font></p>\n";
    }
$topliste .="</td></tr>\n";
if ($show_second_userline eq "on")
    {
####################################################################################
$topliste .=" <tr><td width=\"$toplist_cell_width1\" bgcolor=\"$table_body_color\">\n";
if ($show_user_bewertung_grafik eq "on")
    {
     if ($votegrafik eq "darkstars")
        {
       $star_dir="$no_cgi_url/stars/dark_background";$votegrafik_width="51";$votegrafik_height="10";
        }
     if ($votegrafik eq "lightstars")
        {
        $star_dir="$no_cgi_url/stars/light_background";$votegrafik_width="51";$votegrafik_height="10";
        }
     if ($votegrafik eq "other")
        {
        $star_dir="$no_cgi_url/stars/other";
        $votegrafik_width="$votegrafik_width_other";
        $votegrafik_height="$votegrafik_height_other";
        }
         if ($USER[19]<= 10)
            {$bild='5star.gif';
         if ($USER[19]<= 9)
            {$bild='4star.gif';}
         if ($USER[19]<= 8)
            {$bild='3star.gif';}
         if ($USER[19]<= 7)
            {$bild='2star.gif';}
         if ($USER[19]<= 6)
            {$bild='1star.gif';}
         if ($USER[19]<= 5)
            {$bild='0star.gif';}
              }
$topliste .=" <a href=\"$cgi_root_url/toplist.pl?action=show_vote\&account=$USER[4]\" target=\"_blank\">\n";
$topliste .=" <center><img border=\"0\" src=\"$star_dir/$bild\" alt=\"Bewertungsergebnisse $USER[9]\" width=\"$votegrafik_width\" height=\"$votegrafik_height\"></center></font>\n";
    }
$topliste .=" </td>\n";
$topliste .=" <td width=\"$toplist_cell_width2\" bgcolor=\"$table_body_color\"><font face=\"$font\" size=\"$fontsize_user_beschreibung\" $font_color>\n";
if ($show_vote_link eq "on")
    {
    $topliste .="<a title=\"Diese Seite bewerten\" href=\"$cgi_root_url/toplist.pl?action=vote&account=$USER[4]&bannerurl=$USER[12]&bannerbreite=$USER[14]&bannerhoehe=$USER[13]\" target=\"_blank\">Bewerten:</a> $USER[20]</font>\n";
    }
$topliste .=" </td>\n";
$topliste .=" <td width=\"$toplist_cell_width3\" bgcolor=\"$table_body_color\">\n";
if ($show_average eq "on")
    {
            $tage = ($time - $USER[15]) / 86400;
             if ($tage < "1") {$tage = 1;}
             $dschnitt_in = int ( $USER[16] / $tage);
             $dschnitt_out = int ( $USER[17] / $tage);
$topliste .=" <p align=\"center\"><font face=\"$font\" size=\"$fontsize_average\" $font_color>&Oslash; $dschnitt_in</font></p>\n";
    }
$topliste .=" </td>\n";
$topliste .=" <td width=\"$toplist_cell_width4\" bgcolor=\"$table_body_color\">\n";
$topliste .="<p align=\"center\"><font face=\"$font\" size=\"$fontsize_average\" $font_color>";
if ($show_average eq "on")
    {
$topliste .=" &Oslash; $dschnitt_out\n";
    }
$topliste .="</font></p></td>\n";
$topliste .=" </tr>\n";



    }

    if (($show_previos_position eq "on")&&($user_found eq $platz)){&save_new_position;}
    $aktueller_user_in_tabelle++;
    $aktueller_user_auf_seite++;
    $platz++;
    $datensatztopliste++;
    if ($aktueller_user_in_tabelle eq ($user_per_table+1))
          {&close_table; $aktueller_user_in_tabelle="1";}
    if ($aktueller_user_auf_seite eq ($user_per_page+1))
          {&close_table('seiten_menue_einfuegen');&close_page; }
    if ($platz eq $user_found+1)
          {&close_table('seiten_menue_einfuegen');&close_page;}
    }
}

sub open_page {
if ( $aktuelle_seite eq "1")
    {
         open (NEW,">$no_cgi_path/$dateiname\.$dateiext")||die("Konnte die Datei $dateiname\.$dateiext nicht erzeugen / beschreiben");
         if ($use_flock eq "1") {flock (NEW,1);}
    }
if ( $aktuelle_seite > "1")
    {
         open (NEW,">$no_cgi_path/$dateiname$aktuelle_seite\.$dateiext")||die("Konnte die Datei $dateiname$aktuelle_seite\.$dateiext nicht erzeugen / beschreiben");
         if ($use_flock eq "1") {flock (NEW,1);}

          }
$topliste .="<html><head><title>$title</title>\n";#### HTML Header wird geoeffnet
    if ($laufleiste) {
                 $topliste .= "<style>body \{scrollbar-arrow-color : $scrollbar_arrow_color\; ";### Farbige Scrollleiste
                 $topliste .= "scrollbar-base-color: $scrollbar_base_color \;  \}</style>";
                 }
                 #### Metatags werden eingefuegt
                 open (DATEI,"<$cgi_root_path/config/insert/metatag.dat")||die("Konnte die Datei metatag.dat nicht einlesen");
                 if ($use_flock eq "1") {flock (DATEI,1);}
                 @DATEN =<DATEI>;
                 if ($use_flock eq "1") {flock (DATEI,8);}
                 close (DATEI);
                 foreach $line (@DATEN)
                   {
                    $topliste .=$line;
                   }
                   ### HTML-Header wird geschlossen
                   ### Hintergrund an/aus
                   if ($background_show eq "on") {$background_code ="background=\"$background\"";}

$topliste .="</head>\n<body $background_code bgcolor\=\"$backcolor\" text\=\"$text_link_text\" link\=\"$text_link_link\" vlink\=\"$text_link_vlink\" alink\=\"$text_link_alink\">\n\n";
                ### Header wird eingefuegt
                open (DATEI,"<$cgi_root_path/config/insert/header.dat")||die("Konnte die Datei header.dat nicht einlesen");
                if ($use_flock eq "1") {flock (DATEI,1);}
                @DATEN =<DATEI>;
                if ($use_flock eq "1") {flock (DATEI,1);}
                close (DATEI);
                foreach $line (@DATEN)
                    {
                     $topliste .=$line;
                    }

#### Site of the moment  (show only the userbanner not the alternative banner)
if (($site_of_the_moment eq on)&&($aktuelle_seite eq "1")){
      $datensatz_sotm  = "0";
      $user_found_sotm = "0";
      foreach (@TOPUSER)
              {
               @SOTMTEMPARRY = split (/\|/,$TOPUSER[$datensatz_sotm] );
                if ($SOTMTEMPARRY[31] eq "show_normal_banner")
                    {push (@SOTMUSER, join ("\|", @SOTMTEMPARRY));
                     $user_found_sotm++;
                    }
                 $datensatz_sotm++;
              }
        srand;
        $sotm_user= int ((rand $user_found_sotm));
        @SOTM = split (/\|/,$SOTMUSER[$sotm_user]);
### Fix the Links if no User is in Database
if ($no_user_in_database_fix eq "on"){$sotm_user_link="http://www.bannerblitz.de";}
else {$sotm_user_link="$cgi_root_url/toplist.pl?action=click_out&account=$SOTM[4]";}
$sotm_cell_height=($SOTM[13]+10);
$topliste .="<div align=\"center\"><center>\n";
$topliste .="<table border=\"$tableborder_sotm\" ";
$topliste .="bordercolor=\"$toplist_border_color\" width=\"$tablewidth_sotm\" bgColor=\"$table_bg_color_sotm\" ";
$topliste .="cellPadding=\"$tablecellpadding_sotm\" cellSpacing=\"$tablecellspacing_sotm\">";
$topliste .="<tr><td bgcolor=\"$table_head_color_sotm\"><p align=center>\n";
$topliste .="<font align=\"center\" face=\"$font\" size=\"$font_size_table\" color=\"$font_color_sotm\">";
$topliste .="<b>$sotm_text</b></font></td></tr>";
$topliste .="<tr><td bgcolor=\"$table_body_color_sotm\" align=center height=\"$sotm_cell_height\">\n";
$topliste .="<p align=center><a href=\"$sotm_user_link\" target=\"_blank\">\n";
$topliste .="<img style=\"border: $borderwidth_userbanner_toplist solid $bodercolor_userbanner_toplist\" src=\"$SOTM[12]\" width=$SOTM[14] height=$SOTM[13] alt=\"$SOTM[9]\"></a></p>\n";
$topliste .="</td></tr></table><br></center></div>\n";
}

### Usermenue wird eingefuegt
if ($show_usermenue eq "on"){
$topliste .="<center><font face\=\"$font\" size\=\"$font_size\" color=\"$text_link_text\" ><a href=\"$webmasterhomepage\" target=\"_self\"><font face\=\"$font\" size\=\"$font_size\" color=\"$text_link_text\">[$button_home_text]</font></a>
             <a href=\"$cgi_root_url/toplist.pl?action=new_member\" target=\"_self\"><font face\=\"$font\" size\=\"$font_size\" color=\"$text_link_text\">[$button_anmelden_text]</font></a>
             <a href=\"$cgi_root_url/toplist.pl?action=edit_account\" target=\"_self\"><font face\=\"$font\" size\=\"$font_size\" color=\"$text_link_text\">[$button_userlogin_text]</font></a>
             <font face=\"Arial, Helvetica, sans-serif\" size=\"1\"><br>&nbsp;</font></center></font>";
}
### update und reset Informationen werden eingefuegt
&get_time;
if ($show_update_period eq "on"){
    if ($update_time > 1){$topliste .="<center><font face\=\"$font\" size\=\"$font_size\" color=\"$text_link_text\">Diese Liste wird alle $update_time Minuten aktualisiert.</font></center>";}
    else {$topliste .="<center><font face\=\"$font\" size\=\"$font_size\" color=\"$text_link_text\">Diese Liste wird alle 60 Sekunden aktualisiert.</font></center>";}
    }
if ($show_reset_period eq "on"){
    if ($reset_time > 1){$topliste .="<center><font face\=\"$font\" size\=\"$font_size\" color=\"$text_link_text\">Ein Reset erfolgt alle $reset_time Tage.</center></font>";}
    else {$topliste .="<center><font face\=\"$font\" size\=\"$font_size\" color=\"$text_link_text\">Ein Reset erfolgt jeden Tag. </font></center>";}
    }
if ($show_last_update eq "on"){
    $topliste .="<center><font face\=\"$font\" size\=\"$font_size\" color=\"$text_link_text\"> Letztes Update: $aktdate um $aktzeit.</font></center>\n";
    }
if ($show_next_update eq "on"){
    $topliste .="<center><font face\=\"$font\" size\=\"$font_size\" color=\"$text_link_text\"> N&auml;chstes Update: $nextupdatedate um $nextupdatetime.</font></center>\n";
    }
if ($show_next_reset eq "on"){
    $topliste .="<center><font face\=\"$font\" size\=\"$font_size\" color=\"$text_link_text\"> N&auml;chstes Reset: $nextresetdate um $nextresettime.</font></center>\n";
    }
### Eingetrage User werden angezeigt
if ($show_eingetragene_member eq "on"){
    $topliste .="<center><font face\=\"$font\" size\=\"$font_size\" color=\"$text_link_text\"> Eingetragene Mitglieder:<b> $eingetragene_member</b> </font></center>\n";
    }
### Aktive User werden angezeigt
if ($show_active_member eq "on"){
    $topliste .="<center><font face\=\"$font\" size\=\"$font_size\" color=\"$text_link_text\"> Aktive Mitglieder:<b> $active_member</b> </font></center>\n";
    }
#### Menue wird eingefuegt
&menue;
}

sub close_page {
   #### seiten_menue_einfuegen
           if (($aktueller_user_auf_seite eq ($user_per_page+1))||($platz eq $user_found+1))
                 {&menue;}



### Usermenue wird eingefuegt
if ($show_usermenue_down eq "on"){
$topliste .="<center><font face\=\"$font\" size\=\"$font_size\" color=\"$text_link_text\" ><a href=\"$webmasterhomepage\" target=\"_self\"><font face\=\"$font\" size\=\"$font_size\" color=\"$text_link_text\">[$button_home_text]</font></a>
             <a href=\"$cgi_root_url/toplist.pl?action=new_member\" target=\"_self\"><font face\=\"$font\" size\=\"$font_size\" color=\"$text_link_text\">[$button_anmelden_text]</font></a>
             <a href=\"$cgi_root_url/toplist.pl?action=edit_account\" target=\"_self\"><font face\=\"$font\" size\=\"$font_size\" color=\"$text_link_text\">[$button_userlogin_text]</font></a>
             <font face=\"Arial, Helvetica, sans-serif\" size=\"1\"><br>&nbsp;</font></center></font>";
}
if ($show_update_period_down eq "on"){
    if ($update_time > 1){$topliste .="<center><font face\=\"$font\" size\=\"$font_size\" color=\"$text_link_text\">Diese Liste wird alle $update_time Minuten aktualisiert. </font></center> ";}
    else {$topliste .="<center><font face\=\"$font\" size\=\"$font_size\" color=\"$text_link_text\">Diese Liste wird alle 60 Sekunden aktualisiert. </font></center>";}
    }
if ($show_reset_period_down eq "on"){
    if ($reset_time > 1){$topliste .="<center><font face\=\"$font\" size\=\"$font_size\" color=\"$text_link_text\">Ein Reset erfolgt alle $reset_time Tage.</center></font>";}
    else {$topliste .="<center><font face\=\"$font\" size\=\"$font_size\" color=\"$text_link_text\">Ein Reset erfolgt jeden Tag. </font></center>";}
    }
if ($show_last_update_down eq "on"){
    $topliste .="<center><font face\=\"$font\" size\=\"$font_size\" color=\"$text_link_text\"> Letztes Update: $aktdate um $aktzeit.</font></center>\n";
    }
if ($show_next_update_down eq "on"){
    $topliste .="<center><font face\=\"$font\" size\=\"$font_size\" color=\"$text_link_text\"> N&auml;chstes Update: $nextupdatedate um $nextupdatetime.</font></center>\n";
    }
if ($show_next_reset_down eq "on"){
    $topliste .="<center><font face\=\"$font\" size\=\"$font_size\" color=\"$text_link_text\"> N&auml;chstes Reset: $nextresetdate um $nextresettime.</font></center>\n";
    }
### Eingetrage User werden angezeigt
if ($show_eingetragene_member_down eq "on"){
    $topliste .="<center><font face\=\"$font\" size\=\"$font_size\" color=\"$text_link_text\"> Eingetragene Mitglieder:<b> $eingetragene_member</b> </font></center>\n";
    }
### Aktive User werden angezeigt
if ($show_active_member_down eq "on"){
    $topliste .="<center><font face\=\"$font\" size\=\"$font_size\" color=\"$text_link_text\"> Aktive Mitglieder:<b> $active_member</b> </font></center>\n";
    }
$topliste .="<font face=\"Arial, Helvetica, sans-serif\" size=\"1\"><br>&nbsp;</font>";

 #### Footer wird eingefuegt
 open (DATEI,"<$cgi_root_path/config/insert/footer.dat")||die("Konnte die Datei footer.dat nicht einlesen");
            if ($use_flock eq "1") {flock (DATEI,1);}
            @DATEN =<DATEI>;
            if ($use_flock eq "1") {flock (DATEI,8);}
            close (DATEI);
            foreach $line (@DATEN)
            {
            $topliste .="$line";
            }
 ### Html-Seite wird geschlossen
#$topliste .="<font face=\"Arial, Helvetica, sans-serif\" size=\"1\"><br>&nbsp;</font><center><font face=\"Arial\" size=\"2\" color=\"$text_link_text\">\n<b>Megatoplist V$version</b> &#169; by<a target=\"_blank\" href=\"http://www.topcgi.de\"><font face=\"Arial\" size=\"2\" color=\"$text_link_text\">Topcgi.de</font></a></font></center>";
$topliste .="</body></html>\n";
 ### aktuelle Seite wird geschrieben
 print NEW $topliste;
            if ($use_flock eq "1") {flock (NEW,8);}
         close (NEW);
        if ( $aktuelle_seite eq "1")
            {chmod 0777, "$no_cgi_path/$dateiname\.$dateiext";}
        if ( $aktuelle_seite > "1")
            { $chmod_path = "$no_cgi_path/$dateiname"."$aktuelle_seite\.$dateiext";
            chmod 0777, "$chmod_path";
            }

$aktuelle_seite++;
$aktueller_user_auf_seite ="1";
$aktueller_user_in_tabelle="1";
$topliste="";
    if ($platz < $user_found+1)
        {&open_page;}
}


sub menue {

if ($lastpage > 1){
    $topliste .="<font face=\"Arial, Helvetica, sans-serif\" size=\"1\">&nbsp;</font><center>\n";
        if  (($lastpage > 1)&&($aktuelle_seite ne 1))
            { $previous_page=($aktuelle_seite-1);
        if ($previous_page eq 1){$previous_page="";}
              $topliste .="<a title=\"vorherige Seite\" href=\"$no_cgi_url/$dateiname$previous_page.$dateiext\"><--</a>\n";
            }
for ($menue_link = 1;$menue_link<$lastpage+1;$menue_link++)
     {
       if ($menue_link eq 1)
            {
             $topliste .="<a title=\"TOP $user_per_page\" href=\"$no_cgi_url/$dateiname.$dateiext\">$menue_link</a> \n";
            }
      else {
            $top1= ((($menue_link-1)*$user_per_page)+1);
            $top2= (($top1+$user_per_page)-1);
            $topliste .="<a title=\"TOP $top1-$top2\" href=\"$no_cgi_url/$dateiname$menue_link.$dateiext\">$menue_link</a> \n";
            }
     }
if  (($lastpage > 1)&&($aktuelle_seite ne $lastpage))
     { $next_page=($aktuelle_seite+1);
      $topliste .="<a title=\"n&auml;chste Seite\" href=\"$no_cgi_url/$dateiname$next_page.$dateiext\">--></a>\n";
     }
$topliste .="</center><font face=\"Arial, Helvetica, sans-serif\" size=\"1\">&nbsp;</font>\n";
    }
    #### Zwischenraum zwischen Usermenue und Topliste falls kein Seitenmenue benoetigt wird.
else {$topliste .="<font face=\"Arial, Helvetica, sans-serif\" size=\"1\">&nbsp;</font>";}
}

sub open_table {
if ($tabelle_offen eq 0){
$topliste .="<div align=\"center\"><center>\n";
$topliste .= "<table width=\"$toplist_table_width\" border=\"$toplist_border_width\" bordercolor=\"$toplist_border_color\" cellspacing=\"$toplist_cellspacing\" cellpadding=\"$toplist_cellpadding\" bgColor=\"$table_bg_color\">\n";
$topliste .= "<tr>\n";
$topliste .= "<td width=\"$toplist_cell_width1\" bgcolor=\"$table_head_color\">\n";
$topliste .= "<p align=\"center\"><font face\=\"$font\" size\=\"$font_size_table\" color=\"$font_color_table_header\"><b>$platz_text</b></font></p>\n";
$topliste .= "</td>\n";
$topliste .= "<td width=\"$toplist_cell_width2\" bgcolor=\"$table_head_color\">\n";
$topliste .= "<p align=\"center\"><font face\=\"$font\" size\=\"$font_size_table\" color=\"$font_color_table_header\"><b>$Beschreibung_text</b></font></p></font>\n";
$topliste .= "</td>\n";
$topliste .= "<td width=\"$toplist_cell_width3\" bgcolor=\"$table_head_color\">\n";
$topliste .= "<p align=\"center\"><font face\=\"$font\" size\=\"$font_size_table\" color=\"$font_color_table_header\"><b>$Klick_in_text</b><br></font>\n";
if ($show_hitin_geamt eq "on")
    {
    $topliste .="<font face\=\"$font\" size\=\"1\" color=\"$font_color_table_header\">($Klick_in_gesamt_text)</font></p>\n";
    }
$topliste .= "</td>\n";
$topliste .= "<td width=\"$toplist_cell_width4\" bgcolor=\"$table_head_color\">\n";
$topliste .= "<p align=\"center\"><font face\=\"$font\" size\=\"$font_size_table\" color=\"$font_color_table_header\"><b>$Klick_out_text<br></b></font>\n";
if ($show_hitin_geamt eq "on")
    {
    $topliste .="<font face\=\"$font\" size\=\"1\" color=\"$font_color_table_header\">($Klick_out_gesamt_text)</font></p>\n";
    }
$topliste .= "</td>\n";
$topliste .= "</tr>\n";
$tabelle_offen = "1";
}
}

sub close_table {
 if ($tabelle_offen eq 1)
  {
  $topliste .="</tr></table></center></div>\n";
  &insert_werbung;
  $tabelle_offen="0";
  }
}

sub werbung_auslesen{

$werbung="0";
open (META,"<$userdatapath/insert/werbung/werbung.dat");
    if ($use_flock eq "1") {flock (META,1);}
    @WERBUNG = <META>;
    if ($use_flock eq "1") {flock (META,8);}
    close (META);
    foreach $line (@WERBUNG)
    {
    chomp ($line) if ($line =~ /\n/);
    }
open (META,"<$userdatapath/insert/werbung/standardwerbung.dat");
    if ($use_flock eq "1") {flock (META,1);}
    @STANDARDWERBUNG = <META>;
    if ($use_flock eq "1") {flock (META,8);}
    close (META);

}

sub insert_werbung {

if (-e "$userdatapath/insert/werbung/werbung_id_$WERBUNG[$werbung].dat")
    {
    open (META,"<$userdatapath/insert/werbung/werbung_id_$WERBUNG[$werbung].dat");
    if ($use_flock eq "1") {flock (META,1);}
    @AKTUELLE_WERBUNG = <META>;
    if ($use_flock eq "1") {flock (META,8);}
    close (META);
        foreach $line (@AKTUELLE_WERBUNG)
        {
        $topliste .="$line";
        }
    }
else { $topliste .= "@STANDARDWERBUNG";}
$werbung++;
}

sub get_time {
##### Uhrzeit des letzten Updates wird berechnet (mit Serveroffset)
if (($show_last_update eq "on")||($show_last_update_down eq "on")){
      $offsetzeit = time() + ($serveroffset * 3600);
      ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime ($offsetzeit);
      @months = ("space" , "Januar", "Februar", "M&auml;rz", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember");
      $mon++;$year = $year + 1900;$monformat = sprintf ("%2d", $mon);$monformat =~tr/ /0/;
      $mdayformat = sprintf ("%2d", $mday);$mdayformat =~tr/ /0/;$USDate = "$monformat-$mdayformat-$year";
      $EuroDate = "$mdayformat-$monformat-$year";$USDateerweitert = "$months[$mon] $mday, $year";
      $EuroDateerweitert = "$mday $months[$mon] $year";$min = sprintf ("%2d", $min);$min =~tr/ /0/;
      $hour = sprintf ("%2d", $hour);$hour =~tr/ /0/;$EuroTime = "$hour:$min Uhr";
      if ($hour < 12) {$ext = "AM";$USHour = "$hour";}if ($hour > 12) {$USHour = $hour - 12;$ext = "PM";}
      if ($hour == 12){$ext = "PM";$USHour = "12";}if ($hour == 0) {$USHour = "12";}
      $USHour = sprintf ("%2d", $USHour);$USHour =~tr/ /0/;$USTime = "$USHour:$min $ext";
      if ($timeformat eq "12") {$aktzeit = $USTime;} else {$aktzeit = $EuroTime;}
      if ($dateformat eq "US") {$aktdate = "$USDate";}elsif ($dateformat eq "USXL") {$aktdate = "$USDateerweitert";}
      elsif ($dateformat eq "EU") {$aktdate = "$EuroDate";}else {$aktdate = "$EuroDateerweitert";}
  }
##### Uhrzeit des naechsten Updates wird berechnet (mit Serveroffset)
if (($show_next_update eq "on")||($show_next_update_down eq "on")){
      $updatezeit = time() + ($serveroffset * 3600) +($update_time * 60);
      ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime ($updatezeit);
      @months = ("space" , "Januar", "Februar", "M&auml;rz", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember");
      $mon++;$year = $year + 1900;$monformat = sprintf ("%2d", $mon);$monformat =~tr/ /0/;
      $mdayformat = sprintf ("%2d", $mday);$mdayformat =~tr/ /0/;
      $USDate = "$monformat-$mdayformat-$year";$EuroDate = "$mdayformat-$monformat-$year";
      $USDateerweitert = "$months[$mon] $mday, $year";$EuroDateerweitert = "$mday $months[$mon] $year";
      $min = sprintf ("%2d", $min);$min =~tr/ /0/;$hour = sprintf ("%2d", $hour);$hour =~tr/ /0/;
      $EuroTime = "$hour:$min Uhr";if ($hour < 12) {$ext = "AM";$USHour = "$hour";}if ($hour > 12) {$USHour = $hour - 12;$ext = "PM";}
      if ($hour == 12){$ext = "PM";$USHour = "12";}          if ($hour == 0) {$USHour = "12";}
      $USHour = sprintf ("%2d", $USHour);$USHour =~tr/ /0/;$USTime = "$USHour:$min $ext";
      if ($timeformat eq "12") {$nextupdatetime = $USTime;}else {$nextupdatetime = $EuroTime;}
      if ($dateformat eq "US") {$nextupdatedate = "$USDate";}elsif ($dateformat eq "USXL") {$nextupdatedate = "$USDateerweitert";}
      elsif ($dateformat eq "EU") {$nextupdatedate = "$EuroDate";}else {$nextupdatedate = "$EuroDateerweitert";}
    }
###### Uhrzeit das naechste Reset wird berechnet (mit Serveroffeset)
if (($show_next_reset eq "on")||($show_next_reset_down eq "on")){
      $resetzeit = $last_reset + ($serveroffset * 3600) + ($reset_time*86400);
      ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime ($resetzeit);
      @months = ("space" , "Januar", "Februar", "M&auml;rz", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember");
      $mon++;$year = $year + 1900;$monformat = sprintf ("%2d", $mon);$monformat =~tr/ /0/;
      $mdayformat = sprintf ("%2d", $mday);$mdayformat =~tr/ /0/;
      $USDate = "$monformat-$mdayformat-$year";$EuroDate = "$mdayformat-$monformat-$year";
      $USDateerweitert = "$months[$mon] $mday, $year";$EuroDateerweitert = "$mday $months[$mon] $year";
      $min = sprintf ("%2d", $min);$min =~tr/ /0/;$hour = sprintf ("%2d", $hour);$hour =~tr/ /0/;
      $EuroTime = "$hour:$min Uhr";if ($hour < 12) {$ext = "AM";$USHour = "$hour";}if ($hour > 12) {$USHour = $hour - 12;$ext = "PM";}
      if ($hour == 12){$ext = "PM";$USHour = "12";}          if ($hour == 0) {$USHour = "12";}
      $USHour = sprintf ("%2d", $USHour);$USHour =~tr/ /0/;$USTime = "$USHour:$min $ext";
      if ($timeformat eq "12") {$nextresettime = $USTime;}else {$nextresettime = $EuroTime;}
      if ($dateformat eq "US") {$nextresetdate = "$USDate";}elsif ($dateformat eq "USXL") {$nextresetdate = "$USDateerweitert";}
      elsif ($dateformat eq "EU") {$nextresetdate = "$EuroDate";}else {$nextresetdate = "$EuroDateerweitert";}
    }
}

sub save_new_position {

    open (NEWPOSITION, ">$cgi_root_path/config/position.txt")||die("Konnte die Datei podition.txt nicht beschreiben");
    if ($use_flock eq "1") {flock (NEWPOSITION,1);}
    foreach $line (@NEWPOSITION)
    {
    print NEWPOSITION "$line";
    }
    if ($use_flock eq "1") {flock (NEWPOSITION,8);}
    close (NEWPOSITION);
    }



sub log_click_out {
                     $datensatz=0;

        open (ALLEACCOUNTS, "+<$userdatapath/user.dat")||die("Konnte die Datei user.dat nicht einlesen");
              if ($use_flock eq "1") {flock (ALLEACCOUNTS,1);}
                @ALLEACCOUNTS = <ALLEACCOUNTS>;

        foreach (@ALLEACCOUNTS)
           {
             @USER = split(/\|/, $ALLEACCOUNTS[$datensatz]);
             if ($USER[4] eq  $FORM{account})
               {
                 $USER[3]++;  $USER[17]++;
                 $redirect   = "$USER[11]";
                 $awm_status = "$USER[32]";
                 $awm_system = "$USER[33]";
                 $awm_id     = "$USER[34]";
                 $ALLEACCOUNTS[$datensatz] = join ("\|",@USER);
               }
               $datensatz++;
            }
        seek (ALLEACCOUNTS, 0, 0);
        print ALLEACCOUNTS @ALLEACCOUNTS;
        if ($use_flock eq "1") {flock (ALLEACCOUNTS,8);}
        close (ALLEACCOUNTS);

    if ($awm_status eq "awm_check_on")
       {
       &awm_check;
       }
    else {print "Location: $redirect \n\n";}

}

sub awm_check {
if ($awm_system eq "alterskontrolle")
   {


   &header;
print "<div align=\"center\">\n";
print "<center>\n";
print "<table width=\"600\" border=\"$toplist_border_width\" bordercolor=\"$toplist_border_color\" cellspacing=\"$toplist_cellspacing\" cellpadding=\"$toplist_cellpadding\" bgColor=\"$table_bg_color\">\n";
print "<tr>\n";
print "<td width=\"600\" bgcolor=\"$table_head_color\" colspan=\"2\">\n";
print "<center><font face\=\"$font\" size\=\"$font_size_table\" color=\"$font_color_table_header\"><b>Die Seite wird durch ein Jugendschutzsystem gesch&uuml;tzt!</b></font></td>\n";
print "</tr>\n";
print "<tr>\n";
print "<td width=\"600\" bgcolor=\"$table_body_color\"  height=\"25\" colspan=\"2\">\n";
print<<"TOR";
<!-- BEGIN ALTERSKONTROLLE.DE TOR CODE -->

<table border="0" width="100%" cellpadding="2">

  <table border="0" width="100%" cellpadding="2">
    <tr>
     <td width="100%">
     <p align="center"><font size="2" face="Arial"><br>
     Damit wir Ihr Alter feststellen können, geben Sie bitte Ihre Alterskontrolle - Zugangsdaten ein ! </font></p>
    <p><font face="Arial" size="2">Wenn Sie noch keine Zugangsdaten haben, können Sie sich
    <a href="http://www.alterskontrolle.de?wid=$webmasterID&sid=$siteID" target="_blank">hier in wenigen
     Minuten registrieren !</a></font><br>
&nbsp;</td>
</table>
<form method="POST" action="http://www.alterskontrolle.de/cgi-mod/tor2.cgi">
<input type="hidden" name="pname" value="ID">
<input type="hidden" name="pvalue" value="$awm_id">
<input type="hidden" name="id" value="$siteID">
<input type="hidden" name="wid" value="$webmasterID">
  <div align="center">
    <table cellspacing="0" cellpadding="0" bgcolor="#e5e5e9" border="0" ?>
      <tbody>
        <tr>
          <td><a
href="http://www.alterskontrolle.de/?wid=$webmasterID&sid=$siteID"
target="_blank"><img border="0"
src="http://www.alterskontrolle.de/images/tor.gif" width="348"
height="93"></a></td>
        </tr>
        <tr>
          <td valign="bottom" bgcolor="#E5E5E9">
            <table border="0" width="100%" cellspacing="4" cellpadding="0">
              <tr>
                <td><b><font face="Arial,Helvetica,sans-serif" size="2"
color="#000080">User-ID:</font></b></td>
                <td><input size="14" name="userid"></td>
                <td>
                  <p align="center"><img border="0"
src="http://www.alterskontrolle.de/images/infos.gif" width="80"
height="24"></td>
              </tr>
              <tr>
                <td><b><font face="Arial,Helvetica,sans-serif" size="2"
color="#000080">Passwort:</font></b></td>
                <td><input size="14" name="pw" type="password"></td>
                <td>
                  <p align="center"><input type="submit" value="START"
style="font-weight: bold; color: #000066"></td>
              </tr>
            </table>
          </td>
        </tr>
        <tr>
          <td align="middle" bgcolor="#000066">
            <table border="0" width="100%" cellspacing="0" cellpadding="4">
              <tr>
                <td width="100%" class="foot"><font
face="Arial,Helvetica,sans-serif" size="2"><font color="#E5E5E9">Diese
                  Seite wird durch</font> <a
href="http://www.alterskontrolle.de?wid=$webmasterID&sid=$siteID"
target="_blank" class="whitelink"><font
color="#E5E5E9">Alterskontrolle.de</font></a>
                  <font color="#E5E5E9">geschützt !</font></font></td>
              </tr>
            </table>
          </td>
        </tr>
      </tbody>
    </table>
  </div>
</form>

                <!-- END ALTERSKONTROLLE.DE TOR CODE -->
TOR
print "</td>\n";
print "</tr>\n";
print "</table>\n";
print "</center>\n";
print "</div>\n";
&footer;
   }

}

sub awm_click_out {


        open (ALLEACCOUNTS, "<$userdatapath/user.dat")||die("Konnte die Datei user.dat nicht einlesen");
              if ($use_flock eq "1") {flock (ALLEACCOUNTS,1);}
                @ALLEACCOUNTS = <ALLEACCOUNTS>;

        foreach (@ALLEACCOUNTS)
           {
             @USER = split(/\|/, $ALLEACCOUNTS[$datensatz]);
             if ($USER[34] eq  $FORM{ID})
               {
                 $redirect   = "$USER[11]";
               }
               $datensatz++;
            }

        if ($use_flock eq "1") {flock (ALLEACCOUNTS,8);}
        close (ALLEACCOUNTS);
print "Location: $redirect \n\n";
}

sub log_click_in {

        $datensatz=0;
              open (ALLEACCOUNTS, "+<$userdatapath/user.dat")||die("Konnte die Datei user.dat nicht einlesen");
              if ($use_flock eq "1") {flock (ALLEACCOUNTS,1);}
                   @ALLEACCOUNTS = <ALLEACCOUNTS>;

        foreach (@ALLEACCOUNTS)
           {
             @USER = split(/\|/, $ALLEACCOUNTS[$datensatz]);
             if ($USER[4] eq  $FORM{account})
               {
                 $USER[2]++; $USER[16]++;
                 $ALLEACCOUNTS[$datensatz] = join ("\|",@USER);
               }
               $datensatz++;
            }
        seek (ALLEACCOUNTS, 0, 0);
        print ALLEACCOUNTS @ALLEACCOUNTS;
        if ($use_flock eq "1") {flock (ALLEACCOUNTS,8);}
        close (ALLEACCOUNTS);



}

sub update_account {
             #  $datensatz=0;
#
#
#               open (ALLEACCOUNTS, "<$userdatapath/user.dat")||die("Konnte die Datei user.dat nicht einlesen");
#               if ($use_flock eq "1") {flock (ALLEACCOUNTS,1);}
#               @ALLEACCOUNTS = <ALLEACCOUNTS>;
#               if ($use_flock eq "1") {flock (ALLEACCOUNTS,8);}
#               close (ALLEACCOUNTS);
#         foreach (@ALLEACCOUNTS)
#            {
#              @USER = split(/\|/, $ALLEACCOUNTS[$datensatz]);
#              $USER[0] = $USER[0] + $USER[2];
#              $USER[1] = $USER[1] + $USER[3];
#              $USER[2] = 0;
#              $USER[3] = 0;
#              $v1 = $USER[21]* 10;
#              $v2 = $USER[22]* 20;
#              $v3 = $USER[23]* 30;
#              $v4 = $USER[24]* 40;
#              $v5 = $USER[25]* 50;
#              $v6 = $USER[26]* 60;
#              $v7 = $USER[27]* 70;
#              $v8 = $USER[28]* 80;
#              $v9 = $USER[29]* 90;
#              $v10 =$USER[30]* 100;
# if (($USER[20] eq "0")||($USER[20] eq "")||($USER[20] eq "\n"))
#    {$stimmen = "1";}
# else {$stimmen = $USER[20];}
#  $vote = (($v1+$v2+$v3+$v4+$v5+$v6+$v7+$v8+$v9+$v10) / $stimmen)/10;
#  $USER[19] = $vote;
#
#             $ALLEACCOUNTS[$datensatz] = join ("\|",@USER);
#             $datensatz++;
#             }
#
#
#         open (ALLEACCOUNTS, ">$userdatapath/user.dat")||die("Konnte die Datei user.dat nicht beschreiben");
#           if ($use_flock eq "1") {flock (ALLEACCOUNTS,1);}
#           print ALLEACCOUNTS @ALLEACCOUNTS;
#           if ($use_flock eq "1") {flock (ALLEACCOUNTS,8);}
#         close (ALLEACCOUNTS);
### neue updateroutine entfernt \n und leere Zeilen
open (ALLEACCOUNTS, "<$userdatapath/user.dat")||die("Konnte die Datei user.dat nicht einlesen");
if ($use_flock eq "1") {flock (ALLEACCOUNTS,1);}
@ALLEACCOUNTS = <ALLEACCOUNTS>;
if ($use_flock eq "1") {flock (ALLEACCOUNTS,8);}
close (ALLEACCOUNTS);
        foreach (@ALLEACCOUNTS)
           { if (($_ ne "")&&($_ ne "\n"))
             {
              @USER = split(/\|/, $_);
              $USER[0] = $USER[0] + $USER[2];
              $USER[1] = $USER[1] + $USER[3];
              $USER[2] = 0;
              $USER[3] = 0;
              $v1 = $USER[21]* 10;
              $v2 = $USER[22]* 20;
              $v3 = $USER[23]* 30;
              $v4 = $USER[24]* 40;
              $v5 = $USER[25]* 50;
              $v6 = $USER[26]* 60;
              $v7 = $USER[27]* 70;
              $v8 = $USER[28]* 80;
              $v9 = $USER[29]* 90;
              $v10 =$USER[30]* 100;
               if (($USER[20] eq "0")||($USER[20] eq "")||($USER[20] eq "\n"))
                   {$stimmen = "1";}
                   else {$stimmen = $USER[20];}
              $vote = (($v1+$v2+$v3+$v4+$v5+$v6+$v7+$v8+$v9+$v10) / $stimmen)/10;
              $USER[19] = $vote;
             push @UPDATE_ACCOUNT ,join ("\|",@USER);
              }
}
open (ALLEACCOUNTS, ">$userdatapath/user.dat")||die("Konnte die Datei user.dat nicht beschreiben");
if ($use_flock eq "1") {flock (ALLEACCOUNTS,1);}
print ALLEACCOUNTS @UPDATE_ACCOUNT;
if ($use_flock eq "1") {flock (ALLEACCOUNTS,8);}
close (ALLEACCOUNTS);
}

sub reset_account {
###neue resetroutine entfernt \n und leere Zeilen

              open (ALLEACCOUNTS, "<$userdatapath/user.dat")||die("Konnte die Datei user.dat nicht einlesen");
              if ($use_flock eq "1") {flock (ALLEACCOUNTS,1);}
              @ALLEACCOUNTS = <ALLEACCOUNTS>;
              if ($use_flock eq "1") {flock (ALLEACCOUNTS,8);}
              close (ALLEACCOUNTS);
   foreach (@ALLEACCOUNTS)
           {if (($_ ne "")&&($_ ne "\n"))
             {
              @USER = split(/\|/,$_);
              $USER[0] = 0;
              $USER[1] = 0;
              $USER[2] = 0;
              $USER[3] = 0;
              push @RESET_USER, join ("\|",@USER);
              }
          }
        open (ALLEACCOUNTS, ">$userdatapath/user.dat")||die("Konnte die Datei user.dat nicht beschreiben");
        if ($use_flock eq "1") {flock (ALLEACCOUNTS,1);}
        print ALLEACCOUNTS @RESET_USER;
        if ($use_flock eq "1") {flock (ALLEACCOUNTS,8);}
        close (ALLEACCOUNTS);
}

sub reset_all_accounts {
### neue Reset_all Routine entfernt \n und leere Zeilen!

              open (ALLEACCOUNTS, "<$userdatapath/user.dat")||die("Konnte die Datei user.dat nicht einlesen");
              if ($use_flock eq "1") {flock (ALLEACCOUNTS,1);}
              @ALLEACCOUNTS = <ALLEACCOUNTS>;
              if ($use_flock eq "1") {flock (ALLEACCOUNTS,8);}
              close (ALLEACCOUNTS);
   foreach (@ALLEACCOUNTS)
           {if (($_ ne "")&&($_ ne "\n"))
             {
              @USER = split(/\|/, $_);
              ### reset Klick in / out
              if ($reset_all_option_klick eq "on")
              {
               $USER[0]  = 0;
               $USER[1]  = 0;
               $USER[2]  = 0;
               $USER[3]  = 0;
              }
             ### reset Klick in / out all
              if ($reset_all_option_klick_all eq "on")
              {
               $USER[15] = time();
               $USER[16] = 0;
               $USER[17] = 0;
              }
             ### reset vote data
             if ($reset_all_option_vote eq "on")
             {
              $USER[19] = 0;
              $USER[20] = 0;
              $USER[21] = 0;
              $USER[22] = 0;
              $USER[23] = 0;
              $USER[24] = 0;
              $USER[25] = 0;
              $USER[26] = 0;
              $USER[27] = 0;
              $USER[28] = 0;
              $USER[29] = 0;
              $USER[30] = 0;
              }
            push @RESET_ALL_USER , join ("\|",@USER);
             }
            }
        open (ALLEACCOUNTS, ">$userdatapath/user.dat")||die("Konnte die Datei user.dat nicht beschreiben");
        if ($use_flock eq "1") {flock (ALLEACCOUNTS,1);}
        print ALLEACCOUNTS @RESET_ALL_USER;
        if ($use_flock eq "1") {flock (ALLEACCOUNTS,8);}
        close (ALLEACCOUNTS);


}

sub show_vote {

&header;
                $datensatz = "0";
                    open (ACCOUNT, "<$userdatapath/user.dat")||die("Konnte die Datei user.dat nicht einlesen");
                    if ($use_flock eq "1") {flock (ACCOUNT,1);}
                    @ALLEDATEN = <ACCOUNT>;
                    if ($use_flock eq "1") {flock (ACCOUNT,8);}
                    close (ACCOUNT);
                    foreach (@ALLEDATEN)
                    {
                    @ACCOUNTDATEN = split (/\|/, $ALLEDATEN[$datensatz]);
                    if ($ACCOUNTDATEN[4] eq $FORM{account})
                    {@ACCOUNT =@ACCOUNTDATEN;
 $voteanzahl = $ACCOUNT[20];
 $v1 = $ACCOUNT[21]* 10;
 $v2 = $ACCOUNT[22]* 20;
 $v3 = $ACCOUNT[23]* 30;
 $v4 = $ACCOUNT[24]* 40;
 $v5 = $ACCOUNT[25]* 50;
 $v6 = $ACCOUNT[26]* 60;
 $v7 = $ACCOUNT[27]* 70;
 $v8 = $ACCOUNT[28]* 80;
 $v9 = $ACCOUNT[29]* 90;
 $v10 = $ACCOUNT[30]* 100;
$stimmen = $voteanzahl;
if ($voteanzahl eq 0)
   {$voteanzahl = 1;$stimmen=0;}
 $vote_percent = ($v1+$v2+$v3+$v4+$v5+$v6+$v7+$v8+$v9+$v10) / $voteanzahl;
 $vote_percent = int $vote_percent;



}

                    $datensatz++;
                    }

print "<div align=\"center\">\n";
print "  <center>\n";
print "  <table width=\"451\" border=\"$toplist_border_width\" bordercolor=\"$toplist_border_color\" cellspacing=\"$toplist_cellspacing\" cellpadding=\"$toplist_cellpadding\" bgColor=\"$table_bg_color\">\n";
print "    <tr>\n";
print "      <td width=439 bgcolor=$table_head_color >\n";
print "        <p align=\"center\"><b><font face\=$font size\=$font_size_table color=\"$font_color_table_header\" size=3>Bewertung des &quot; $FORM{account} &quot;\n";
print "        Accounts</font></b></td>\n";
print "    </tr>\n";
print "    <tr>\n";
print "      <td width=\"431\" bgcolor=\"$table_body_color\" align=\"right\" height=\"25\">\n";
print "        <p align=\"center\">&nbsp;\n";
print "        </p>\n";
print "        \n";
print "        <div align=\"center\">\n";
print "          <center>\n";
print "          <table border=\"0\" cellspacing=\"0\" width=\"200\">\n";
print "            <tr>\n";
print "              <td width=\"100\" align=\"right\"><font face\=\"$font\" size\=\"$font_size_table\" $font_color >&nbsp;10 Punkte</font></td>\n";
print "              <td width=\"100\"><font face\=\"$font\" size\=\"$font_size_table\" $font_color >&nbsp;\= $ACCOUNT[30] mal</font></td>\n";
print "            </tr>\n";
print "            <tr>\n";
print "              <td width=\"100\" align=\"right\"><font face\=\"$font\" size\=\"$font_size_table\" $font_color >&nbsp;9 Punkte</font></td>\n";
print "              <td width=\"100\"><font face\=\"$font\" size\=\"$font_size_table\" $font_color >&nbsp;\= $ACCOUNT[29] mal</font></td>\n";
print "            </tr>\n";
print "            <tr>\n";
print "              <td width=\"100\" align=\"right\"><font face\=\"$font\" size\=\"$font_size_table\" $font_color >&nbsp;8 Punkte</font></td>\n";
print "              <td width=\"100\"><font face\=\"$font\" size\=\"$font_size_table\" $font_color >&nbsp;\= $ACCOUNT[28] mal</font></td>\n";
print "            </tr>\n";
print "            <tr>\n";
print "              <td width=\"100\" align=\"right\"><font face\=\"$font\" size\=\"$font_size_table\" $font_color >&nbsp;7 Punkte</font></td>\n";
print "              <td width=\"100\"><font face\=\"$font\" size\=\"$font_size_table\" $font_color >&nbsp;\= $ACCOUNT[27] mal</font></td>\n";
print "            </tr>\n";
print "            <tr>\n";
print "              <td width=\"100\" align=\"right\"><font face\=\"$font\" size\=\"$font_size_table\" $font_color >&nbsp;6 Punkte</font></td>\n";
print "              <td width=\"100\"><font face\=\"$font\" size\=\"$font_size_table\" $font_color >&nbsp;\= $ACCOUNT[26] mal</font></td>\n";
print "            </tr>\n";
print "            <tr>\n";
print "              <td width=\"100\" align=\"right\"><font face\=\"$font\" size\=\"$font_size_table\" $font_color >&nbsp;5 Punkte</font></td>\n";
print "              <td width=\"100\"><font face\=\"$font\" size\=\"$font_size_table\" $font_color >&nbsp;\= $ACCOUNT[25] mal</font></td>\n";
print "            </tr>\n";
print "            <tr>\n";
print "              <td width=\"100\" align=\"right\"><font face\=\"$font\" size\=\"$font_size_table\" $font_color >&nbsp;4 Punkte</font></td>\n";
print "              <td width=\"100\"><font face\=\"$font\" size\=\"$font_size_table\" $font_color >&nbsp;\= $ACCOUNT[24] mal</font></td>\n";
print "            </tr>\n";
print "            <tr>\n";
print "              <td width=\"100\" align=\"right\"><font face\=\"$font\" size\=\"$font_size_table\" $font_color >&nbsp;3 Punkte</font></td>\n";
print "              <td width=\"100\"><font face\=\"$font\" size\=\"$font_size_table\" $font_color >&nbsp;\= $ACCOUNT[23] mal</font></td>\n";
print "            </tr>\n";
print "            <tr>\n";
print "              <td width=\"100\" align=\"right\"><font face\=\"$font\" size\=\"$font_size_table\" $font_color >&nbsp;2 Punkte</font></td>\n";
print "              <td width=\"100\"><font face\=\"$font\" size\=\"$font_size_table\" $font_color >&nbsp;\= $ACCOUNT[22] mal</font></td>\n";
print "            </tr>\n";
print "            <tr>\n";
print "              <td width=\"100\" align=\"right\"><font face\=\"$font\" size\=\"$font_size_table\" $font_color >&nbsp;1 Punkt</font></td>\n";
print "              <td width=\"100\"><font face\=\"$font\" size\=\"$font_size_table\" $font_color >&nbsp;\= $ACCOUNT[21] mal</font></td>\n";
print "            </tr>\n";
print "          </table>\n";
print "          </center>\n";
print "        </div>\n";
print "        \n";
print "        <p align=\"center\"><font face\=\"$font\" size\=\"$font_size_table\" $font_color >Anzahl der Stimmen \= <b>$stimmen</b> </font>";
print "        \n";
print "        <p align=\"center\"><font face\=\"$font\" size\=\"$font_size_table\" $font_color >&nbsp;Gesamtergebnis \ = \<b>$vote_percent</b>%</font>";
print "        \n";
print "        <p align=\"center\">&nbsp;</td>\n";
print "    </tr>\n";
print "    <tr>      <td width=\"431\" bgcolor=\"$table_body_color\" align=\"right\" height=\"50\">\n";
print "        <p align=\"center\"><input TYPE=\"BUTTON\" VALUE=\"Schliessen\" onClick=window.close()></td>\n";
print "    </tr>\n";
print "  </table>\n";
print "  </center>\n";
print "</div>\n";
&footer;


}

sub header {

            print "Content-type: text/html\n\n";
            print "<html><head><title>$title</title>\n";
            if ($laufleiste) {
                print "<style>body \{scrollbar-arrow-color : $scrollbar_arrow_color\; ";
                print "scrollbar-base-color: $scrollbar_base_color \;  \}</style>";
                }
            open (DATEI,"<$cgi_root_path/config/insert/metatag.dat")||die("Konnte die Datei metatag.dat nicht einlesen");
            if ($use_flock eq "1") {flock (DATEI,1);}
            @DATEN =<DATEI>;
            if ($use_flock eq "1") {flock (DATEI,8);}
            close (DATEI);
            foreach $line (@DATEN)
            {
            print $line;
            }
            print "</head>\n";
            print "<body background\=\"$background\" bgcolor\=$backcolor text\=\"$text_link_text\" link\=\"$text_link_link\" vlink\=\"$text_link_vlink\" alink\=\"$text_link_alink\">\n";
            open (DATEI,"<$cgi_root_path/config/insert/header.dat")||die("Konnte die Datei header.dat nicht einlesen");
            if ($use_flock eq "1") {flock (DATEI,1);}
            @DATEN =<DATEI>;
            if ($use_flock eq "1") {flock (DATEI,8);}
            close (DATEI);
            foreach $line (@DATEN)
            {
            print $line;
            }
           }

sub footer {

            open (DATEI,"<$cgi_root_path/config/insert/footer.dat")||die("Konnte die Datei footer.dat nicht einlesen");
            if ($use_flock eq "1") {flock (DATEI,1);}
            @DATEN =<DATEI>;
            if ($use_flock eq "1") {flock (DATEI,8);}
            close (DATEI);
            foreach $line (@DATEN)
            {
            print $line;
            }
            #print "<br><br><center><font face=\"Arial\" size=\"2\" color=\"$text_link_text\"><b>Megatoplist V$version</b> &#169; by<a <font target=\"_blank\" href=\"http://www.topcgi.de\"><font face=\"Arial\" size=\"2\" color=\"$text_link_text\">Topcgi.de</font></a></font></center>\n";
            print "</body></html>\n";
            }

sub backup {

  open (BACKUP,"<$cgi_root_path/config/backup/backup.log")||die("Konnte die Datei backup.log nicht einlesen");
      if ($use_flock eq "1") {flock (BACKUP,1);}
      @BACKUPLOG =<BACKUP>;
      if ($use_flock eq "1") {flock (BACKUP,8);}
      close (BACKUP);

      #### Freie Backupnummer finden und Datei speichern
      $backupnumberneu="1001";
      while (-e "$cgi_root_path/config/backup/backup$backupnumberneu.dat")
            {
            $backupnumberneu++;
            }
    open (BACKUPLOG, ">>$cgi_root_path/config/backup/backup.log")||die("Konnte die Datei backup.log nicht beschreiben");
    if ($use_flock eq "1") {flock (BACKUPLOG,1);}
    print BACKUPLOG "$zeit|$cgi_root_path/config/backup/backup$backupnumberneu.dat|\n";
    if ($use_flock eq "1") {flock (BACKUPLOG,8);}
    close (BACKUPLOG);
    open (ACCOUNT, "<$userdatapath/user.dat")||die("Konnte die Datei user.dat nicht einlesen");
    if ($use_flock eq "1") {flock (ACCOUNT,1);}
    @ALLEDATEN = <ACCOUNT>;
    if ($use_flock eq "1") {flock (ACCOUNT,8);}
    close (ACCOUNT);

    open (NEWBACKUP, ">$cgi_root_path/config/backup/backup$backupnumberneu.dat")||die("Konnte die Datei backup$backupnumberneu.dat nicht beschreiben");
    if ($use_flock eq "1") {flock (NEWBACKUP,1);}
    foreach $line (@ALLEDATEN){
    print NEWBACKUP "$line";
    }
    if ($use_flock eq "1") {flock (NEWBACKUP,8);}
    close (NEWBACKUP);
    chmod 0777, "$cgi_root_path/config/backup/backup$backupnumberneu.dat";

    if ($backup_mail eq on){
    @MAIL = split(/\@/, $backup_mail_adress);
    open (MAIL,"|$mailpath -t");
    print MAIL "To: $MAIL[0]\@$MAIL[1]\n";
    print MAIL "From: $your_mail\n";
    print MAIL "Subject: Backup der $title erstellt \n";
    print MAIL "Content-type: text/plain\n\n";
    print MAIL "Hallo Webmaster\n\n";
    print MAIL "Ihre Topliste: $title wurde soeben gesichert.\n\n";
    print MAIL "Sie finden Ihr Backup in der Administrationskonsole unter:\n\n";
    print MAIL "$cgi_root_url/config/admin.pl\n\n";
    close (MAIL);
    }
}

sub new_member_form {
&header;
print "<div align=\"center\">\n";
print "  <center>\n";
print "  <table width=\"600\" border=\"$toplist_border_width\" bordercolor=\"$toplist_border_color\" cellspacing=\"$toplist_cellspacing\" cellpadding=\"$toplist_cellpadding\" bgColor=\"$table_bg_color\">\n";
print "    <tr>\n";
print "      <td width=\"600\" bgcolor=\"$table_head_color\" colspan=\"2\">\n";
print "        <p align=\"center\"><font face\=\"$font\" size\=\"$font_size_table\" color=\"$font_color_table_header\"><b><big>Neuen Account erstellen</big></b></font></td>\n";
print "    </tr>\n";
print "    <tr><form method=\"POST\" action=\"$new_member_url\">\n";
print "      <td width=\"220\" bgcolor=\"$table_body_color\" align=\"right\" height=\"25\"><font face\=\"$font\" size\=\"$font_size_table\" $font_color >Account Name</font></td>\n";
print "      <td width=\"380\" bgcolor=\"$table_body_color\" height=\"25\"><input type=\"text\" name=\"account\" size=\"33\"></td>\n";
print "    </tr>\n";
print "    <tr>\n";
print "      <td width=\"220\" bgcolor=\"$table_body_color\" align=\"right\" height=\"25\"><font face\=\"$font\" size\=\"$font_size_table\" $font_color >Passwort</font></td>\n";
print "      <td width=\"380\" bgcolor=\"$table_body_color\" height=\"25\"><input type=\"password\" name=\"passwort\" size=\"33\"></td>\n";
print "    </tr>\n";
print "    <tr>\n";
print "      <td width=\"220\" bgcolor=\"$table_body_color\" align=\"right\" height=\"25\"><font face\=\"$font\" size\=\"$font_size_table\" $font_color >Wiederhohlung Passwort</font></td>\n";
print "      <td width=\"380\" bgcolor=\"$table_body_color\" height=\"25\"><input type=\"password\" name=\"confirm_passwort\" size=\"33\"></td>\n";
print "    </tr>\n";
print "    <tr>\n";
print "      <td width=\"220\" bgcolor=\"$table_body_color\" align=\"right\" height=\"25\"><font  face\=\"$font\" size\=\"$font_size_table\" $font_color >Vorname</font></td>\n";
print "      <td width=\"380\" bgcolor=\"$table_body_color\" height=\"25\"><input type=\"text\" name=\"vorname\" size=\"33\"></td>\n";
print "    </tr>\n";
print "    <tr>\n";
print "      <td width=\"220\" bgcolor=\"$table_body_color\" align=\"right\" height=\"25\"><font face\=\"$font\" size\=\"$font_size_table\" $font_color >Nachname</font></td>\n";
print "      <td width=\"380\" bgcolor=\"$table_body_color\" height=\"25\"><input type=\"text\" name=\"nachname\" size=\"33\"></td>\n";
print "    </tr>\n";
print "    <tr>\n";
print "      <td width=\"220\" bgcolor=\"$table_body_color\" align=\"right\" height=\"25\"><font face\=\"$font\" size\=\"$font_size_table\" $font_color >Email</font></td>\n";
print "      <td width=\"380\" bgcolor=\"$table_body_color\" height=\"25\"><input type=\"text\" name=\"email\" size=\"33\"></td>\n";
print "    </tr>\n";
print "    <tr>\n";
print "      <td width=\"220\" bgcolor=\"$table_body_color\" align=\"right\" height=\"25\"><font face\=\"$font\" size\=\"$font_size_table\" $font_color >Seitenname</font></td>\n";
print "      <td width=\"380\" bgcolor=\"$table_body_color\" height=\"25\"><input type=\"text\" name=\"seitenname\" size=\"33\"></td>\n";
print "    </tr>\n";
print "    <tr>\n";
print "      <td width=\"220\" bgcolor=\"$table_body_color\" align=\"right\" height=\"62\"><font face\=\"$font\" size\=\"$font_size_table\" $font_color >Beschreibung</font></td>\n";
print "      <td width=\"380\" bgcolor=\"$table_body_color\" height=\"62\">\n";
print "                          <textarea rows=\"3\" name=\"beschreibung\" cols=\"28\"></textarea></td>\n";
print "    </tr>\n";
print "    <tr>\n";
print "      <td width=\"220\" bgcolor=\"$table_body_color\" align=\"right\" height=\"25\"><font face\=\"$font\" size\=$font_size_table\" $font_color >Seiten-Url</font></td>\n";
print "      <td width=\"380\" bgcolor=\"$table_body_color\" height=\"25\"><input type=\"text\" name=\"seitenurl\" size=\"33\" ></td>\n";
print "    </tr>\n";
print "    <tr>\n";
print "      <td width=\"220\" bgcolor=\"$table_body_color\" align=\"right\" height=\"25\"><font face\=\"$font\" size\=\"$font_size_table\" $font_color  >Banner-Url</font></td>\n";
print "      <td width=\"380\" bgcolor=\"$table_body_color\" height=\"25\"><input type=\"text\" name=\"bannerurl\" size=\"33\" ></td>\n";
print "    </tr>\n";
print "    <tr>\n";
print "      <td width=\"220\" bgcolor=\"$table_body_color\" align=\"right\" height=\"25\"><font face\=\"$font\" size\=\"$font_size_table\" $font_color  >Bannerbreite</font></td>\n";
print "      <td width=\"380\" bgcolor=\"$table_body_color\" height=\"25\"><input type=\"text\" name=\"bannerbreite\" size=\"33\"><font face\=\"$font\" size\=\"$font_size_table\" $font_color > (max. $user_banner_width Pixel)</td> \n";
print "    </tr>\n";
print "    <tr>\n";
print "      <td width=\"220\" bgcolor=\"$table_body_color\" align=\"right\" height=\"25\"><font face\=\"$font\" size\=\"$font_size_table\" $font_color >Bannerh&ouml;he</font></td>\n";
print "      <td width=\"380\" bgcolor=\"$table_body_color\" height=\"25\"><input type=\"text\" name=\"bannerhoehe\" size=\"33\"><font face\=\"$font\" size\=\"$font_size_table\" $font_color > (max. $user_banner_height Pixel) </td>\n";
print "    </tr>\n";
print "    <tr>\n";
print "      <td width=\"220\" bgcolor=\"$table_body_color\" align=\"right\" height=\"25\"><input type=\"hidden\" name=\"regeln\" value=\"ja\"></td>\n";
print "      <td width=\"380\" bgcolor=\"$table_body_color\" height=\"25\"><font face\=\"$font\" size\=\"$font_size_table\" $font_color  >&nbsp;</td>\n";
print "    </tr>\n";
print "    <tr>\n";
print "      <td width=\"220\" bgcolor=\"$table_body_color\" height=\"27\">&nbsp;</td>\n";
print "      <td width=\"380\" bgcolor=\"$table_body_color\" height=\"27\"><input type=\"hidden\" name=\"newuser\" value=\"ja\"><input type=\"submit\" value=\"Abschicken\">\&nbsp;\&nbsp;&nbsp;\n";
print "        <input type=\"reset\" value=\"&Auml;nderungen verwerfen\"></td>\n";
print "    </tr></form>\n";
print "  </table>\n";
print "  </center>\n";
print "</div>\n";
&footer;
    }
sub edit_form {
&header;
print "<div align=\"center\">\n";
print "<center>\n";
print "<table width=\"600\" border=\"$toplist_border_width\" bordercolor=\"$toplist_border_color\" cellspacing=\"$toplist_cellspacing\" cellpadding=\"$toplist_cellpadding\" bgColor=\"$table_bg_color\">\n";
print "<tr>\n";
print "<td width=\"600\" bgcolor=\"$table_head_color\" colspan=\"2 \">\n";
print "<p align=\"center\"><font face\=\"$font\" size\=\"$font_size_table\" color=\"$font_color_table_header\"><b><big>Login\: Account bearbeiten</big></b></font></td>\n";
print "</tr>\n";
print "<tr>\n";
print "<td width=\"600\" bgcolor=\"$table_body_color\" align=\"right\" height=\"25\" colspan=\"2\">&nbsp;</td>\n";
print "</tr>\n";
print "<tr><form method=\"POST\" action=\"$edit_member_url\">\n";
print "<td width=\"220\" bgcolor=\"$table_body_color\" align=\"right\" height=\"25\"><font face\=\"$font\" size\=\"$font_size_table\" $font_color  >Account Name</font></td>\n";
print "<td width=\"380\" bgcolor=\"$table_body_color\" height=\"25\"><input type=\"text\" name=\"editaccount\" size=\"33\"></td>\n";
print "</tr>\n";
print "<tr>\n";
print "<td width=\"220\" bgcolor=\"$table_body_color\" align=\"right\" height=\"25\"><font face\=\"$font\" size\=\"$font_size_table\" $font_color  >Passwort</font></td>\n";
print "<td width=\"380\" bgcolor=\"$table_body_color\" height=\"25\"><input type=\"password\" name=\"editpass\" size=\"33\"></td>\n";
print "</tr>\n";
print "<tr>\n";
print "<td width=\"600\" bgcolor=\"$table_body_color\" height=\"27\" colspan=\"2\">\n";
print "<p align=\"center\">\n";
print "<input type=\"hidden\" name=\"edit_account\" value=\"ja\">\n";
print "<center><input type=\"submit\" value=' login ' ></center>\n";
if ($email_on eq 1){
print "<br><br><center><a href=\"$cgi_root_url/toplist.pl\?action\=lostpassform\"><font face\=\"$font\" size\=\"$font_size_table\" $font_color >Passwort vergessen\?</font></a><center>\n";
}
print "</p></form>\n";
print "</td>\n";
print "</tr>\n";
print "</table>\n";
print "</center>\n";
print "</div>\n";
&footer;
}

sub vote_form {
&header;
print "<p>&nbsp;</p>\n";
print "<div align=\"center\">\n";
print "<center>\n";
print "<table width=\"560\" border=\"$toplist_border_width\" bordercolor=\"$toplist_border_color\" cellspacing=\"$toplist_cellspacing\" cellpadding=\"$toplist_cellpadding\" bgColor=\"$table_bg_color\">\n";
print "<tr>\n";
print "<td width=\"560\" bgcolor=\"$table_head_color\" >\n";
print "<p align=\"center\"><font face\=\"$font\" size\=\"$font_size_table\" color=\"$font_color_table_header\" ><b><big>\"$FORM{account}\" -&nbsp; Account bewerten<big></b></font></big></big></td>\n";
print "</tr>\n";
print "<tr>\n";
print "<td width=\"560\" bgcolor=\"$table_body_color\" align=\"right\">\n";
print "<p align=\"center\">&nbsp;</p>\n";
print "<p align=\"center\">\n";
print "<img border=\"0\" src=\"$FORM{bannerurl}\" alt=\"Userbanner des $FORM{account} Accounts\" width=\"$FORM{bannerbreite}\" height=\"$FORM{bannerhoehe}\"></p>\n";
print "<p align=\"center\">&nbsp;</td>\n";
print "</tr>\n";
print "<tr>\n";
print "<td width=\"560\" bgcolor=\"$table_body_color\" align=\"right\">\n";
print "<p align=\"center\">&nbsp;</p>\n";
print "<form method=\"GET\" action=\"$cgi_root_url/toplist.pl\">\n";
print "<input type=\"hidden\" name=\"action\" value=\"vote_final\">\n";
print "<input type=\"hidden\" name=\"account\" value=\"$FORM{account}\">\n";
print "<p align=\"center\"><select size=\"1\" name=\"bewertung\">\n";
print "<option selected value=\"30\">10 - SUPER</option>\n";
print "<option value=\"29\">9</option>\n";
print "<option value=\"28\">8</option>\n";
print "<option value=\"27\">7</option>\n";
print "<option value=\"26\">6 - mittel</option>\n";
print "<option value=\"25\">5</option>\n";
print "<option value=\"24\">4</option>\n";
print "<option value=\"23\">3</option>\n";
print "<option value=\"22\">2</option>\n";
print "<option value=\"21\">1 - schlecht</option>\n";
print "</select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type=\"submit\" value=\"Bewerten\" ></p>\n";
print "</form>\n";
print "<p align=\"center\">&nbsp;</td>\n";
print "</tr>\n";
print "</table>\n";
print "</center>\n";
print "</div>\n";
&footer;
}

sub vote_final {
                $datensatz = "0";
                   open (ACCOUNT, "<$userdatapath/user.dat")||die("Konnte die Datei user.dat nicht einlesen");
                   if ($use_flock eq "1") {flock (ACCOUNT,1);}
                   @ALLEDATEN = <ACCOUNT>;
                   if ($use_flock eq "1") {flock (ACCOUNT,8);}
                   close (ACCOUNT);
                   foreach (@ALLEDATEN)
                   {
                   @ACCOUNTDATEN = split (/\|/, $ALLEDATEN[$datensatz]);
                   if ($ACCOUNTDATEN[4] eq $FORM{account})
                   {$ACCOUNTDATEN[$FORM{bewertung}]++ ;
                    $ACCOUNTDATEN[20]++ ;
                    $vote_erfolgreich=1;}
                   $ALLEDATEN[$datensatz] = join ("\|",@ACCOUNTDATEN);
                   $datensatz++;
                   }
                        open (ACCOUNT, ">$userdatapath/user.dat")||die("Konnte die Datei user.dat nicht beschreiben");
                        if ($use_flock eq "1") {flock (ACCOUNT,1);}
                        print ACCOUNT @ALLEDATEN;
                        if ($use_flock eq "1") {flock (ACCOUNT,8);}
                        close (ACCOUNT);
 &show_vote;
}

sub lost_pass_form {
&header;
print "<div align=\"center\">\n";
print "<center>\n";
print "<table width=\"600\" border=\"$toplist_border_width\" bordercolor=\"$toplist_border_color\" cellspacing=\"$toplist_cellspacing\" cellpadding=\"$toplist_cellpadding\" bgColor=\"$table_bg_color\">\n";
print "<tr>\n";
print "<td width=\"600\" bgcolor=\"$table_head_color\" colspan=\"2\">\n";
print "<p align=\"center\"><font face\=\"$font\" size\=\"$font_size_table\" color=\"$font_color_table_header\"><b><big>Passwort vergessen \?</big></b></font></td>\n";
print "</tr>\n";
print "<tr>\n";
print "<td width=\"600\" bgcolor=\"$table_body_color\" align=\"right\" height=\"25\" colspan=\"2\">\n";
print "<center><font face\=\"$font\" size\=\"$font_size_table\" $font_color >Bitte geben Sie Ihren Accountnamen ein.</font></center>";
print "</td></tr>\n";
print "<tr><form method=\"GET\" action=\"$cgi_root_url/toplist.pl\">\n";
print "<input type=\"hidden\" name=\"lost_password\" value=\"ja\">\n";
print "<td width=\"220\" bgcolor=\"$table_body_color\" align=\"right\" height=\"25\"><font face\=\"$font\" size\=\"$font_size_table\" $font_color >Account Name</font></td>\n";
print "<td width=\"380\" bgcolor=\"$table_body_color\" height=\"25\"><input type=\"text\" name=\"account\" size=\"33\"></td>\n";
print "</tr>\n";
print "<tr>\n";
print "<td width=\"600\" bgcolor=\"$table_body_color\" height=\"27\" colspan=\"2\">\n";
print "<p align=\"center\">\n";
print "<input type=\"submit\" value=' login ' >\n";
print "</p></form>\n";
print "</td>\n";
print "</tr>\n";
print "</table>\n";
print "</center>\n";
print "</div>\n";
&footer;
}

sub search_pass {
$datensatz = "0";
                   open (ACCOUNT, "<$userdatapath/user.dat")||die("Konnte die Datei user.dat nicht einlesen");
                   if ($use_flock eq "1") {flock (ACCOUNT,1);}
                   @ALLEDATEN = <ACCOUNT>;
                   if ($use_flock eq "1") {flock (ACCOUNT,8);}
                   close (ACCOUNT);
                   foreach (@ALLEDATEN)
                   {
                   @ACCOUNTDATEN = split (/\|/, $ALLEDATEN[$datensatz]);
                   if ($ACCOUNTDATEN[4] eq $FORM{account})
                   {$ACCOUNTDATEN[$FORM{bewertung}]++ ;
                    $pass=$ACCOUNTDATEN[5];
                    $email=$ACCOUNTDATEN[8] ;
                    $suche_erfolgreich=1;}

                   $datensatz++;
                   }
if ($suche_erfolgreich eq 1){
@MAIL = split(/\@/, $email);
open (MAIL,"|$mailpath -t");
print MAIL "To: $MAIL[0]\@$MAIL[1]\n";
print MAIL "From: $your_mail\n";
print MAIL "Subject: Ihre Passwort fuer die $title \n";
print MAIL "Content-type: text/plain\n\n";
print MAIL "Sie haben Ihr Passwort bei uns angefordert.\n\n";
print MAIL "Folgende Zugangsdaten haben wir gefunden:\n\n";
print MAIL "Accountname: $FORM{account} \n";
print MAIL "Passwort: $pass\n\n";
print MAIL "Sie finden Ihren Eintrag unter:\n\n";
print MAIL "$cgi_root_url/toplist.pl\n\n";
print MAIL "Sollten Ihre Daten fehlerhaft sein koennen Sie diese hier aendern:\n\n";
print MAIL "$cgi_root_url/toplist.pl?action=edit_account\n\n";
close (MAIL);

&header;
print "<div align=\"center\">\n";
print "<center>\n";
print "<table width=\"600\" border=\"$toplist_border_width\" bordercolor=\"$toplist_border_color\" cellspacing=\"$toplist_cellspacing\" cellpadding=\"$toplist_cellpadding\" bgColor=\"$table_bg_color\">\n";
print "<tr>\n";
print "<td width=\"600\" bgcolor=\"$table_head_color\" colspan=\"2\">\n";
print "<center><font face\=\"$font\" size\=\"$font_size_table\" color=\"$font_color_table_header\"><b><big>Passwort wurde verschickt</big></b></font></td>\n";
print "</tr>\n";
print "<tr>\n";
print "<td width=\"600\" bgcolor=\"$table_body_color\" align=\"right\" height=\"25\" colspan=\"2\">\n";
print "<center><br><br><font face\=\"$font\" size\=\"$font_size_table\" $font_color ><b>Ihr Passwort wurde an folgende Email verschickt:</b></font><br><br>";
print "<font face\=\"$font\" size\=\"$font_size_table\" $font_color ><b><big>$email</big></b></font><br><br><br><br></td>\n";
print "</tr>\n";
print "</table>\n";
print "<br><br><p align=\"center\"><font face\=\"$font\" size\=\"$font_size_table\" $font_color><a href=\"$cgi_root_url/toplist.pl\">Zur&uuml;ck zur $title </a></font></p>\n";
print "</center>\n";
print "</div>\n";
&footer;
}
else {
&header;
print "<div align=\"center\">\n";
print "<center>\n";
print "<table width=\"600\" border=\"$toplist_border_width\" bordercolor=\"$toplist_border_color\" cellspacing=\"$toplist_cellspacing\" cellpadding=\"$toplist_cellpadding\" bgColor=\"$table_bg_color\">\n";
print "<tr>\n";
print "<td width=\"600\" bgcolor=\"$table_head_color\" colspan=\"2\">\n";
print "<center><font face\=\"$font\" size\=\"$font_size_table\" color=\"$font_color_table_header\"><b>Accountdaten nicht gefunden\!</b></font></td>\n";
print "</tr>\n";
print "<tr>\n";
print "<td width=\"600\" bgcolor=\"$table_body_color\" align=\"right\" height=\"25\" colspan=\"2\">\n";
print "<center><br><br><font $font size\=\"$error_font_size\" color\=\"$error_font_color\"><b>Leider haben wir Ihre Accountdaten nicht gefunden!</b></font><br>";
print "<font $font size\=\"$error_font_size\" color\=\"$error_font_color\"><b>Bitte &uuml;berpr&uuml;fen Sie Ihre Eingabe\!</b></font><br><br><br><br></td>\n";
print "</tr>\n";
print "</table>\n";
print "<br><br><p align=\"center\"><font size=\"4\" face=\"Arial\" ><a href=javascript:history.go(-1);><font face=\"Arial\" size=\"2\" color=\"$text_link_text\">Zur&uuml;ck</font></a></font></p>\n";
print "</center>\n";
print "</div>\n";
&footer;
}
}

sub confirm_rules {
&header;
print "<div align=\"center\">\n";
print "<center>\n";
print "<table width=\"600\" border=\"$toplist_border_width\" bordercolor=\"$toplist_border_color\" cellspacing=\"$toplist_cellspacing\" cellpadding=\"$toplist_cellpadding\" bgColor=\"$table_bg_color\">\n";
print "<tr>\n";
print "<td width=\"600\" bgcolor=\"$table_head_color\" colspan=\"2\" >\n";
print "<center><font face\=\"$font\" size\=\"$font_size_table\" color=\"$font_color_table_header\"><b>Regeln f&uuml;r den Beitritt in die $title</b></font></td>\n";
print "</tr>\n";
print "<tr>\n";
print "<td width=\"600\" bgcolor=\"$table_body_color\"  height=\"25\" colspan=\"2\">\n";
print "<font face\=\"$font\" size\=\"$font_size_table\" $font_color>\n";
open (DATEI,"<$cgi_root_path/config/insert/regeln.txt")||die("Konnte die Datei regeln.txt nicht einlesen");
            if ($use_flock eq "1") {flock (DATEI,1);}
            @DATEN =<DATEI>;
            if ($use_flock eq "1") {flock (DATEI,8);}
            close (DATEI);
            foreach $line (@DATEN)
            {
            print "$line" ;
            }
print "</font>\n";
####


print "<center>\n";
print "<table border=\"0\" cellpadding=\"3\" cellspacing=\"1\">\n";
print "<td>\n";
print "<form action=\"$cgi_root_url/toplist.pl\" method=\"POST\" name=\"yes\">";
print "<input type=\"hidden\" name=\"action\" value=\"rules_accept\"><input type=\"submit\" name=\"Submit\" value=\"Regeln akzeptieren\"></form>\n";
print "</td>\n";
print "<td>\&nbsp;\&nbsp;\&nbsp;</td>\n";
print "<td>\n";
print "<form action=\"$cgi_root_url/toplist.pl\" method=\"POST\"><input type=\"submit\" value=\"Regeln ablehnen\"></form>\n";
print "</td>\n";
print "</table>\n";
print "</center>\n";
###
if (!$wait_rules_accept){$wait_rules_accept = 10;}
print "<script language=\"javascript\">\n";
print "<!--\n";
print "var secs = $wait_rules_accept;\n";
print "var wait = secs * 1000;\n";
print "document.yes.Submit.disabled=true;\n";
print "        \n";
print "for(i=1;i<=secs;i++) {\n";
print " window.setTimeout(\"update(\" + i + \")\", i * 1000);\n";
print "}\n";
print "\n";
print "window.setTimeout(\"timer()\", wait);\n";
print "\n";
print "function update(num) {\n";
print " if(num == (wait/1000)) {\n";
print "  document.yes.Submit.value = \"Regeln akzeptieren\";\n";
print " }\n";
print " else {\n";
print "  printnr = (wait/1000)-num;\n";
print "  document.yes.Submit.value = \"Regeln akzeptieren ( \" + printnr + \" Sek. )\";\n";
print " }\n";
print "}\n";

print "function timer() {\n";
print " document.yes.Submit.disabled=false;\n";
print "}\n";
print "//-->\n";
print "</script>\n";
###
print "</td>\n";
print "</tr>\n";
print "</table>\n";
print "</center>\n";
print "</div>\n";
&footer;
}


sub regeln {

}

sub error {
    &header;
    print "<div align=\"center\">\n";
    print "<center>\n";
    print "<table width=\"600\" border=\"$toplist_border_width\" bordercolor=\"$toplist_border_color\" cellspacing=\"$toplist_cellspacing\" cellpadding=\"$toplist_cellpadding\" bgColor=\"$table_bg_color\">\n";
    print "<tr>\n";
    print "<td width=\"600\" bgcolor=\"$table_head_color\" colspan=\"2\" height=\"40\">\n";
    print "<p align=\"center\"><font face\=\"$font\" size\=\"$font_size_table\" color=\"$font_color_table_header\"><b><big>Folgende Fehler wurden gefunden</big></b></font></td>\n";
    print "</tr>\n";
    print "<tr><td width=\"600\" bgcolor=\"$table_body_color\"><p>&nbsp;</p>\n";
    print "@FEHLER";
    print "<p>&nbsp;</p></td></tr>";
    print "</table>\n";
    print "</center>\n";
    print "<p>\&nbsp;</p><center><input TYPE=BUTTON VALUE=Schliessen onClick=window.close()> <center>\n";
    print "</div>\n";
    &footer;

}
1;