#*********************************************************************************************
#                                 Fait par JGP SOLDAT
#                               Maintenu par Kana-chan
#                             Pour l'Alliance Francophone
#                             Version 4.00, le 21 mai 2007  
#                           Première version 27 janvier 2001
#
#                     (Programme de création de la page score3.html)
#
#*********************************************************************************************

use Socket;
use DBI;
use Encode qw(decode encode);
use URI::Escape qw(uri_escape uri_unescape);

$maintenu = "<a href=\"/code/fahCode.7z\" target=\"_blank\">Kana-chan</a> avec l'aimable participation de Dylav de Zebulon.fr";
$ip_interne = ".";
$destWWW = "/var/www/html";
$homeWWW = "/"; #"https://fah.chezmks.fr";

$test = 0;
$test1 = 0;
$test_uid = 0;

sub place {
  local ($tot, $val, $record) = @_;
  return (($tot-$val+$record)-1);
}

sub format_number {
  local ($number) = @_;
  my $number_str = "".$number."";
  my $cpt_pl = length($number_str)-1;
  my $cpt_nb = 1;
  while ( $cpt_pl >= 0 ) {
    if ( $cpt_nb == 3 ) {
      if ( $cpt_pl > 0 and substr($number_str, $cpt_pl-1, 1) ne "-" ) {
        substr($number_str, $cpt_pl, 1) = "&#160;".substr($number_str, $cpt_pl, 1);
        $cpt_nb = 0;
      }
    }
    $cpt_nb++;
    $cpt_pl--;
  }
  return $number_str;
}

# Parametres de connection a la base de donnees
$bd    = '/tmp/memory/fah.db';
$identifiant = '';      # identifiant
$motdepasse  = '';

# Connection a la base de donnees mysql
print("Connexion a la base de donnees $bd\n");
$db = DBI->connect(
        "DBI:SQLite:dbname=$bd",
        $identifiant, $motdepasse, {RaiseError => 1}
      ) or die "Connection impossible a la base de donnees $bd !\n $! \n $@\n$DBI::errstr";

open(file, "pos.res"); $b1 = <file>; close(file);
open(file, "pos2.res"); $b = <file>; close(file);

if ($test == 1) { print("Test meilleur.pl\n"); }
print("Traitement des donnees\n\n");

$ip_fah = "https://foldingathome.org/";
$ip6 = "https://www.alliancefrancophone.org";
$version = "7.10";

$donner = "pos_Alliance, pos_general, nom, score, wu, rec";

if ($test == 1) { 
  print("Lecture des membres de l'Alliance Francophone pour la journee. REC = ".$b1."\n");
}

$ErrNum = 0;
%tri_uid = 0;
if ($test_uid == 1) { print("SELECT nom,id FROM uid\n"); }
$do = $db->prepare("SELECT nom,id FROM uid");
$ErrNum = $do->execute() or die $DBI::errstr;
while ($ErrNum >= 0 and my @data = $do->fetchrow_array()) {
  $name = $data[0];
  $tri_uid{$name} = $data[1];
  if ($test_uid == 1) { print($name." ==> [".$tri_uid{$name}."]\n"); }
}

$membre = 0;
$vert = 0;
if ($test == 1) { print("SELECT nom,score,pos_general FROM Alliance WHERE rec =".$b1); }
$do = $db->prepare("SELECT nom,score,pos_general FROM Alliance WHERE rec = ".$b1);
$ErrNum = $do->execute() or die $DBI::errstr;
while ($ErrNum >= 0 and my @data = $do->fetchrow_array()) {
  $tri_nom[$membre] = $data[0];
  $tri_score{$tri_nom[$membre]} = int($data[1]);
  $tri_pos{$tri_nom[$membre]} = $data[2];
  $Test{$tri_nom[$membre]} = 1;
  if ($test1 == 1) { print ($tri_nom[$membre]." = ".$tri_score{$tri_nom[$membre]}."\n"); }
  $membre++;
}

if ($test == 1) { print ("Membre dans l'Alliance Francophone = ".$membre."\n"); }

open(file, '>:utf8', "$destWWW/meilleur.html");
@mois = ('janvier','f&eacute;vrier','mars','avril','mai','juin','juillet','ao&ucirc;t','septembre','octobre','novembre','d&eacute;cembre');
@jour = ('dimanche','lundi','mardi','mercredi','jeudi','vendredi','samedi');

($sec,$min,$heure,$jour,$mois,$annee,$jour2) = (localtime(time))[0,1,2,3,4,5,6];
if ($sec < 10) { $sec = "0".$sec; }
if ($min < 10) { $min = "0".$min; }
if ($heure < 10) { $heure = "0".$heure; }
if ($jour < 10) { $jour = "0".$jour; }
$annee += "1900";

($GMsec,$GMmin,$GMheure,$GMjour,$GMmois,$GMannee,$GMjour2) = (gmtime(time))[0,1,2,3,4,5,6];
if ($GMsec < 10) { $GMsec = "0$GMsec"; }
if ($GMmin < 10) { $GMmin = "0$GMmin"; }
if ($GMheure < 10) { $GMheure = "0$GMheure"; }
if ($GMjour < 10) { $GMjour = "0$GMjour"; }
$GMannee += "1900";

# $url_javascript = "http://fah-web.stanford.edu/cgi-bin/main.py?qtype=userpage&username=";
$url_javascript = "https://stats.foldingathome.org/donor/";

@couleur_fond = ('#8CD4F6', '#C2B998', '#C1A0B9', '#C4C7C4', '#DAC7C3', '#A2BFE4', '#AADFAA'); ### 2020-04-07 ###

$t0 = 0;
$t1 = 0;
$t2 = 0;
$t3 = 0;
$t4 = 0;

# --- section <head> -----------------------------------------------------

print file ("<!DOCTYPE html>\n");                       ### 2020-04-07 ###
print file ("<html>\n");                                ### 2020-04-07 ###
print file ("<head>\n");                                ### 2020-04-07 ###
print file ("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF8\">\n"); ### 2020-04-07 ###
print file ("<title>Le classement des meilleurs producteurs chez Folding\@home</title>\n"); ### 2020-04-07 ###
print file ("<meta name=\"Author\" lang=\"fr, en-us\" content=\"JGP SOLDAT\">\n"); ### 2020-04-07 ###
print file ("<meta name=\"Description\" content=\"Statistiques des performances de l'Alliance Francophone\">\n"); ### 2020-04-07 ###
print file ("<meta name=\"Keywords\" LANG=\"fr\" content=\"JGP SOLDAT, calcul distribué, Folding\@home, Foldingathome, Stanford, Forum, Alliance Francophone, Québec, Quebec, France, français, francais, Folding at Home\">\n"); ### 2020-04-07 ###
print file ("<meta name=\"Identifier-URL\" content=\"".$homeWWW."\">\n"); ### 2020-04-07 ###
print file ("<meta name=\"Publisher\" content=\"JGP SOLDAT\">\n"); ### 2020-04-07 ###
print file ("<link rel=\"stylesheet\" href=\"./site/StatStyle.css\" type=\"text/css\">\n"); ### 2020-04-07 ###
print file ("<style>\n");                               ### 2020-04-07 ###
print file (".corps th {background-color:".$couleur_fond[$jour2]."}\n"); ### 2020-04-07 ###
print file ("</style>\n");                              ### 2020-04-07 ###
print file ("<script type=\"text/javascript\" src=\"https://code.jquery.com/jquery-3.5.0.js\"></script>\n");
print file ("<script language=\"javascript\"><!--\n");
print file ("function seoc(nom) {\n");
print file ("\$.get('https://folding.extremeoverclocking.com/xml/user_summary.php?un='+nom+'&t=51', function(responseXml) {\n");
print file ("var xml = \$(responseXml);\n");
print file ("var userid = \$('UserID', xml).text();\n");
print file ("var url = 'https://folding.extremeoverclocking.com/user_summary.php?u='+userid;\n");
print file ("var args = '';\n");
print file ("window.open(url, nom+' chez EOC', args);\n");
print file ("});\n");
print file ("}\n");
print file ("function fah(nom, userid) {\n");
print file ("var url = '$url_javascript';\n");
print file ("url = url + userid;\n");
print file ("var args = '';\n");
print file ("window.open(url, nom+' chez Folding', args);\n");
print file ("}\n");
print file ("// --></script>\n");
print file ("</head>\n");                               ### 2020-04-07 ###

# --- section <body> -----------------------------------------------------

print file ("<body>\n");                                ### 2020-04-07 ###
print file ("<div id=\"container\">\n");                ### 2020-04-07 ###
print file ("<div id=\"header\">\n");                   ### 2020-04-07 ###
print file ("<div id=\"logo\">\n");                     ### 2020-04-07 ###
print file ("<div class=\"wrapper\">\n");               ### 2020-04-07 ###
print file ("<a href=\"".$ip6."\"><img style=\"width:1050px\" src=\"./site/images_site/logo_1050.png\" title=\"Statistiques de l'Alliance Francophone - Folding\@home\"></a>\n"); ### 2020-04-07 ###
print file ("</div>\n");                                ### 2020-04-07 ###
print file ("</div>\n");                                ### 2020-04-07 ###
print file ("</div>\n");                                ### 2020-04-07 ###
print file ("<div id=\"main\">\n");                     ### 2020-04-07 ###
print file ("<div id=\"navbar\">\n");
print file ("<ul class=\"nav\">\n");
print file ("<!--li><a href=\"https://www.alliancefrancophone.org/\">Accueil de l'Alliance</a></li-->\n");
print file ("<li><a href=\"../index.html\">Accueil des stats</a></li>\n");
print file ("<li><a href=\"../Alliance.html\">Classement membres de l'AF</a></li>\n");
print file ("<li><a href=\"../miniteam.html\">Classement mini-teams</a></li>\n");
print file ("<li><a href=\"./site/TeamsStats.html\">Statistiques</a></li>\n");
print file ("<li><a href=\"./site/TeamsPays.html\">Mini-teams pays</a></li>\n");
print file ("<li><a href=\"./site/TeamsActives.html\">Mini-teams actives</a></li>\n");
print file ("<li><a href=\"./site/TeamsSommeil.html\">Mini-teams en sommeil</a></li>\n");
print file ("<li><a href=\"https://forum.alliancefrancophone.org/\">Forum de l'Alliance</a></li>\n");
print file ("</ul>\n");
print file ("</div>\n");
print file ("<div id=\"content\">\n");
print file ("<a id=\"top\" name=\"top\"></a>\n");       ### 2020-04-07 ###
print file ("<div class=\"parag\"><h4>Les 100 meilleurs plieurs chez<br>&nbsp;</h4></div>\n"); ### 2020-04-07 ###
print file ("<div class=\"parag\"><a href=\"".$ip_fah."\" target=\"_blank\"><img src=\"./images/folding5.gif\"></a></div>\n"); ### 2020-04-07 ###
print file ("<br><br><p class=\"MAJ\">Mis &agrave; jour le ".$jour[$jour2]." ".$jour." ".$mois[$mois]." ".$annee." &agrave; "); ### 2020-04-07 ###
print file ("$heure:$min, heure de Paris ($GMheure:$GMmin GMT)</p>\n"); ### 2020-04-07 ###

$actuelle = 9;
$b1 = $b-$actuelle;
if ($b1 < 0) {
  $b1 = 0;
}

$num = 0;
if ($test == 1) { 
  print("Traitement de la position ".$b1." a la position ".$b."\n");
}
$membre = 0;
$vert = 0;
$donner = "pos_general, numeroteam, score, wu, rec";
if ($test == 1) { print("SELECT pos_general,name,team FROM meilleur WHERE rec = ".$b."\n"); }
$do = $db->prepare("SELECT pos_general,name,team FROM meilleur WHERE rec = ".$b);
$ErrNum = $do->execute() or die $DBI::errstr;
while ($ErrNum >= 0 and my @data = $do->fetchrow_array()) {
  $tri[$data[0]] = $data[1];
  $tri1[$data[0]] = $data[2];
  $membre++;
}

$max1 = 0;
$mon1 = 0;
$max2 = 0;
$mon2 = 0;
$max3 = 0;
$mon3 = 0;
$num = 0;
$num1 = 0;
$allo = 0;
$nouv = 0;
if ($test == 1) { print("Meilleur a traiter = ".$membre."\n"); }
while ($num < $membre) {
  if ($num1 >= 200) { print file ("\n</table>"); $num1=0; }
  if ($num1 == 0)
  {

# --- entête du tableau --------------------------------------------------

   print file ("<table class=\"corps\">\n");            ### 2020-04-07 ###
   print file ("<tr>\n");                               ### 2020-04-07 ###
   print file ("<th rowspan=\"2\">Pos</th>\n");         ### 2020-04-07 ###
   print file ("<th rowspan=\"2\">Noms</th>\n");        ### 2020-04-07 ###
   print file ("<th rowspan=\"2\">Points</th>\n");      ### 2020-04-07 ###
   print file ("<th rowspan=\"2\">WU</th>\n");          ### 2020-04-07 ###
   print file ("<th colspan=\"8\">Production</th>\n");  ### 2020-04-07 ###
   print file ("<th colspan=\"8\">+/- Folding</th>\n"); ### 2020-04-07 ###
   print file ("</tr>\n");                              ### 2020-04-07 ###
   print file ("<tr>\n");                               ### 2020-04-07 ###
   print file ("<th>&nbsp;J&nbsp;</th><th>J-1</th><th>J-2</th><th>J-3</th><th>J-4</th><th>J-5</th><th>J-6</th><th>Semaine</th>\n"); ### 2020-04-07 ###
   print file ("<th>&nbsp;J&nbsp;</th><th>J-1</th><th>J-2</th><th>J-3</th><th>J-4</th><th>J-5</th><th>J-6</th><th>Semaine</th>\n"); ### 2020-04-07 ###
   print file ("</tr>\n");                              ### 2020-04-07 ###
  }
  $num++;
  
  $cpt = 0;
  while ($cpt < $actuelle+1) {
    $credit[$cpt] = -1;
    $posg[$cpt] = 0;
    $cpt++;
  }

  $ccc = 0;
  if ($test == 1) { print($num." ".$tri[$num]."\n"); }
  if ($test == 1) { print("SELECT rec,name,pos_general,credit,total,team FROM meilleur WHERE name = '".$tri[$num]."' AND rec BETWEEN ".$b1." AND ".$b." AND team = '".$tri1[$num]."'\n"); }
  $do = $db->prepare("SELECT rec,name,pos_general,credit,total,team FROM meilleur WHERE name = '".$tri[$num]."' AND rec BETWEEN ".$b1." AND ".$b." AND team = '".$tri1[$num]."'");
  $ErrNum = $do->execute() or die $DBI::errstr;
  while ($ErrNum >= 0 and my @data = $do->fetchrow_array()) {
    $ccc++; 
    $rec = place($actuelle+1, $b, $data[0]);
    $name[$rec] = $data[1];
    $nom[$rec] = $name[$rec];
    $nom1[$num] = $nom[$rec];
    $nom[$rec] =~ s/&#39;/'/g;
    $posg[$rec] = $data[2];
    $credit[$rec] = int($data[3]);
    $total[$rec] = int($data[4]);
    $team1[$rec] = $data[5];
    if ($test == 1) { print($credit[$rec]." "); }
    if ($ccc%5 == 0 and $test == 1 ) { print("\n"); }
  }
  
  if ($ccc%5 != 0 and $test == 1 ) { print("\n"); }
  if ($test == 1) { print("\n"); }
  
  $memoire = 0; 
  if ($credit[0] == -1) { $credit[0] =0; $memoire = 0; } else { $memoire = $credit[0]; }
  if ($credit[1] == -1) { $credit[1] = $memoire; } else { $memoire = $credit[1]; }
  if ($credit[2] == -1) { $credit[2] = $memoire; } else { $memoire = $credit[2]; }
  if ($credit[3] == -1) { $credit[3] = $memoire; } else { $memoire = $credit[3]; }
  if ($credit[4] == -1) { $credit[4] = $memoire; } else { $memoire = $credit[4]; }
  if ($credit[5] == -1) { $credit[5] = $memoire; } else { $memoire = $credit[5]; }
  if ($credit[6] == -1) { $credit[6] = $memoire; } else { $memoire = $credit[6]; }
  if ($credit[7] == -1) { $credit[7] = $memoire; } else { $memoire = $credit[7]; }
  if ($credit[8] == -1) { $credit[8] = $memoire; } else { $memoire = $credit[8]; }
  if ($ccc > 1) { $u1 = $credit[$actuelle]-$credit[$actuelle-1]; } else { $u1 = 0; }  
  if ($ccc > 2) { $u2 = $credit[$actuelle-1]-$credit[$actuelle-2]; } else { $u2 = 0; }
  if ($ccc > 3) { $u3 = $credit[$actuelle-2]-$credit[$actuelle-3]; } else { $u3 = 0; }
  if ($ccc > 4) { $u4 = $credit[$actuelle-3]-$credit[$actuelle-4]; } else { $u4 = 0; }
  if ($ccc > 5) { $u5 = $credit[$actuelle-4]-$credit[$actuelle-5]; } else { $u5 = 0; }
  if ($ccc > 6) { $u6 = $credit[$actuelle-5]-$credit[$actuelle-6]; } else { $u6 = 0; }
  if ($ccc > 7) { $u7 = $credit[$actuelle-6]-$credit[$actuelle-7]; } else { $u7 = 0; }
  $u8 = $u1+$u2+$u3+$u4+$u5+$u6+$u7;

  $f_u1 = format_number($u1);
  $f_u2 = format_number($u2);
  $f_u3 = format_number($u3);
  $f_u4 = format_number($u4);
  $f_u5 = format_number($u5);
  $f_u6 = format_number($u6);
  $f_u7 = format_number($u7);
  $f_u8 = format_number($u8);

  $tri2[$num] = $u1;
  if ($u1 > $max1) { $max3 = $max2; $mon3 = $mon2; $max2 = $max1; $mon2 = $mon1; $max1 = $u1; $mon1 = $num; }
  elsif ($u1 > $max2 and $u1 < $max1) { $max3 = $max2; $mon3 = $mon2; $max2 = $u1; $mon2 = $num; }
  elsif ($u1 > $max3 and $u1 < $max2 and $u1 < $max1) { $max3 = $u1; $mon3 = $num; }

  $p8 = 0;
  if ($posg[$actuelle-1] > 0) { $p1 = $posg[$actuelle-1]-$posg[$actuelle]; $p8 = $p8+$p1; }
  else { $p1 = "???"; $posg[$actuelle-1] = $posg[$actuelle]; } 
  if ($posg[$actuelle-2] > 0) { $p2 = $posg[$actuelle-2]-$posg[$actuelle-1]; $p8 = $p8+$p2; }
  else { $p2 = "???"; $posg[$actuelle-2] = $posg[$actuelle-1]; }
  if ($posg[$actuelle-3] > 0) { $p3 = $posg[$actuelle-3]-$posg[$actuelle-2]; $p8 = $p8+$p3; }
  else { $p3 = "???"; $posg[$actuelle-3] = $posg[$actuelle-2]; }
  if ($posg[$actuelle-4] > 0) { $p4 = $posg[$actuelle-4]-$posg[$actuelle-3]; $p8 = $p8+$p4; }
  else { $p4 = "???"; $posg[$actuelle-4] = $posg[$actuelle-3]; }
  if ($posg[$actuelle-5] > 0) { $p5 = $posg[$actuelle-5]-$posg[$actuelle-4]; $p8 = $p8+$p5; }
  else { $p5 = "???"; $posg[$actuelle-5] = $posg[$actuelle-4]; }
  if ($posg[$actuelle-6] > 0) { $p6 = $posg[$actuelle-6]-$posg[$actuelle-5]; $p8 = $p8+$p6; }
  else { $p6 = "???"; $posg[$actuelle-6] = $posg[$actuelle-5]; }
  if ($posg[$actuelle-7] > 0) { $p7 = $posg[$actuelle-7]-$posg[$actuelle-6]; $p8 = $p8+$p7; }
  else { $p7 = "???"; $posg[$actuelle-7] = $posg[$actuelle-6]; }

  $f_p1 = format_number($p1);
  $f_p2 = format_number($p2);
  $f_p3 = format_number($p3);
  $f_p4 = format_number($p4);
  $f_p5 = format_number($p5);
  $f_p6 = format_number($p6);
  $f_p7 = format_number($p7);
  $f_p8 = format_number($p8);

  $f_posg_actuelle = format_number($posg[$actuelle]);
  
# --- ligne membre -------------------------------------------------------
  
  print file ("<tr>\n");                                          ### 2020-04-07 ###
  print file ("<td class=\"right\">");
  my $nom_uri = uri_unescape($nom[$rec]);
  
  #print("$xyz ==> $xyz_chr ==> $xyz_chr_uri\n");
  if ($tri_uid{$nom_uri} ne "" and $tri_uid{$nom_uri} ne "-1") {
    print file ("<a href=\"javascript:fah('".$nom_uri."',".$tri_uid{$nom_uri}.")\">".$f_posg_actuelle."</a>");
  } else {
    print file ($f_posg_actuelle);
  }
  print file ("</td>\n<td>"); ### 2020-04-07 ###

  if ($tri_uid{$nom_uri} ne "" and $tri_uid{$nom_uri} ne "-1") {
    print file ("<a href=\"javascript:seoc('".$nom_uri."')\">".$nom[$actuelle]."</a>"); ### 2020-04-07 ###
  } else {
    print file ($nom[$actuelle]);
  }

  if ( $u1+$u2+$u3+$u4+$u5+$u6+$u7 <= 0 and $ccc > 1 ) {
    print file ("&nbsp;<img src=\"./images/jgp_bye.gif\">");
  } elsif ($credit[$actuelle-1] == 0 or $posg[$actuelle-1] == 0) {
    print file ("&nbsp;<img src=\"./images/jgp_new.gif\">");
  }
  print file ("</td>\n");                           ### 2020-04-07 ###
  
  $f_credit_actuelle = format_number($credit[$actuelle]);
  print file ("<td class=\"right\">".$f_credit_actuelle."</td>\n"); ### 2020-04-07 ###
  
  $f_total_actuelle = format_number($total[$actuelle]);
  print file ("<td class=\"right\">".$f_total_actuelle."</td>\n"); ### 2020-04-07 ###
  
  print file ("<td class=\"right\">".$f_u1."</td>\n");  ### 2020-04-07 ###
  print file ("<td class=\"right\">".$f_u2."</td>\n");  ### 2020-04-07 ###
  print file ("<td class=\"right\">".$f_u3."</td>\n");  ### 2020-04-07 ###
  print file ("<td class=\"right\">".$f_u4."</td>\n");  ### 2020-04-07 ###
  print file ("<td class=\"right\">".$f_u5."</td>\n");  ### 2020-04-07 ###
  print file ("<td class=\"right\">".$f_u6."</td>\n");  ### 2020-04-07 ###
  print file ("<td class=\"right\">".$f_u7."</td>\n");  ### 2020-04-07 ###
  print file ("<td class=\"right\">".$f_u8."</td>\n");  ### 2020-04-07 ###
  print file ("<td class=\"right\">".$f_p1."</td>\n");  ### 2020-04-07 ###
  print file ("<td class=\"right\">".$f_p2."</td>\n");  ### 2020-04-07 ###
  print file ("<td class=\"right\">".$f_p3."</td>\n");  ### 2020-04-07 ###
  print file ("<td class=\"right\">".$f_p4."</td>\n");  ### 2020-04-07 ###
  print file ("<td class=\"right\">".$f_p5."</td>\n");  ### 2020-04-07 ###
  print file ("<td class=\"right\">".$f_p6."</td>\n");  ### 2020-04-07 ###
  print file ("<td class=\"right\">".$f_p7."</td>\n");  ### 2020-04-07 ###
  print file ("<td class=\"right\">".$f_p8."</td>\n");  ### 2020-04-07 ###
  print file ("</tr>\n");                               ### 2020-04-07 ###
  $num1++;
}
print file ("</table>\n");                              ### 2020-04-07 ###

# --- podium -------------------------------------------------------------

print file ("<br>\n");                                                ### 2020-04-07 ###
print file ("<table class=\"podium\"><tr>\n");                        ### 2020-04-07 ###
print file ("<td></td><td><em><u>Le podium du jour</u></em></td>\n"); ### 2020-04-07 ###
print file ("</tr><tr>\n");                                           ### 2020-04-07 ###

if ($tri2[$mon1] != 0) {
  $f_tri2_num = format_number($tri2[$mon1]);
  if ($test == 1) { print("Meilleur 1 = ".$nom1[$mon1]." avec ".$max1." points.\n"); }
  print file ("<td><img src=\"./images/premier.gif\"></td>\n");     ### 2020-04-07 ###
  print file ("<td><strong>".$nom1[$mon1]."</strong></td>\n");      ### 2020-04-07 ###
  print file ("<td class=\"right\">".$f_tri2_num." points</td>\n"); ### 2020-04-07 ###
  print file ("</tr><tr>\n");                                       ### 2020-04-07 ###
}

if ($tri2[$mon2] != 0) {
  $f_tri2_num = format_number($tri2[$mon2]);
  if ($test == 1) { print("Meilleur 2 = ".$nom1[$mon2]." avec ".$max2." points.\n"); }
  print file ("<td><img src=\"./images/deuxieme.gif\"></td>\n");    ### 2020-04-07 ###
  print file ("<td><strong>".$nom1[$mon2]."</strong></td>\n");      ### 2020-04-07 ###
  print file ("<td class=\"right\">".$f_tri2_num." points</td>\n"); ### 2020-04-07 ###
  print file ("</tr><tr>\n");                                       ### 2020-04-07 ###
}

if ($tri2[$mon3] != 0) {
  $f_tri2_num = format_number($tri2[$mon3]);
  if ($test == 1) { print("Meilleur 3 = ".$nom1[$mon3]." avec ".$max3." points.\n"); }
  print file ("<td><img src=\"./images/trois.gif\"></td>\n");       ### 2020-04-07 ###
  print file ("<td><strong>".$nom1[$mon3]."</strong></td>\n");      ### 2020-04-07 ###
  print file ("<td class=\"right\">".$f_tri2_num." points</td>\n"); ### 2020-04-07 ###
  print file ("</tr></table>\n");                                   ### 2020-04-07 ###
}

# --- bas de page --------------------------------------------------------
print file ("</div>\n</div>\n<div id =\"footer\">\n");
print file ("<div class=\"row_latest\">\n<div class=\"latest\">\n<div class=\"latest_text\">");
print file ("<p><a href=\"http://folding.fleucorp.net/installation.htm\" target=\"_blank\">Élaboré par JGP SOLDAT</a>&nbsp;-&nbsp;Maintenu par <a href=\"/code/fahCode.7z\" target=\"_blank\">Kana-chan</a> avec l'aimable participation de Dylav de Zebulon.fr&nbsp;-&nbsp;Version 7.10<a href=\"/\" class=\"top_button\">HOME</a><a href=\"#top\" class=\"top_button\">HAUT</a></p>\n");
print file ("</div>\n</div>\n</div>\n</div>\n</div>\n");

print file ("</body>\n");                               ### 2020-04-07 ###
print file ("</html>\n");                               ### 2020-04-07 ###

close(file);
print("Fin du traitement\n");

$db->disconnect();

if ($test == 0) {
  open(file, "$destWWW/meilleur.html");
  @copy = <file>;
  close(file);
  open(file, ">vieux/meilleur-".$b.".html");
  print file (@copy);
  close(file);
}
exit;
1;
