#*********************************************************************************************
#                                 Fait par JGP SOLDAT
#                               Maintenu par Kana-chan
#                             Pour l'Alliance Francophone 
#                             Version 4.00, le 21 mai 2007 
#*********************************************************************************************

use Socket;
use Encode qw(decode encode);

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

@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];
$mois1=$mois+1;
if ($mois1 < 10) { $mois1 = "0".$mois1; }
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";

$test=0;
if ($test==1) { print("\ntest message\n\n"); }
print("\nTraitement des donnees\n");

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

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

open (messageHTML, '>:utf8', "$destWWW/message.html");

print messageHTML ("<!DOCTYPE html>\n");
print messageHTML ("<html>\n");
print messageHTML ("<head>\n");
print messageHTML ("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF8\">\n");
print messageHTML ("<title>Alliance Francophone (Folding At Home)</title>\n");
print messageHTML ("<meta name=\"Author\" lang=\"fr, en-us\" content=\"JGP SOLDAT\">\n");
print messageHTML ("<meta name=\"Description\" content=\"Statistiques des performances de l'Alliance Francophone chez Folding\@home\">\n");
print messageHTML ("<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");
print messageHTML ("<meta name=\"Identifier-URL\" content=\"".$homeWWW."\">\n");
print messageHTML ("<meta name=\"Publisher\" content=\"JGP SOLDAT\">\n");
print messageHTML ("<link rel=\"stylesheet\" href=\"./site/StatStyle.css\" type=\"text/css\">\n");
print messageHTML ("<style>\n");
print messageHTML (".corps th {background-color:".$couleur_fond[$jour2]."}\n");
print messageHTML ("</style>\n");
print messageHTML ("</head>\n");

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

print messageHTML ("<table class=\"corps\">\n");

$c=$b;
while ($c > 0 and $c > ($b-28)) {
  if (open(fileMESS, '<:utf8', "message/message-".$c."-sp.txt")) {
    @mess=<fileMESS>;
    close (fileMESS);

    open(message2, "message_score.res");
    @mess_score = <message2>;
    close(message2);

    if ($test==1) { print("Contenu = ".@mess."\n\n"); }
    print messageHTML "<tr><td>";
    print messageHTML @mess;
    if (length($mess_score[0]) >= 2) {
      if ($test==1) { print("Contenu = ".@mess_score."\n\n"); }
      print messageHTML @mess_score;
    }
    print messageHTML "</td></tr>";
  }
  if ($test==1) { print("Ouverture de ...message/message-".$c.".txt\n"); }
  if (open(fileMESS, '<:utf8', "message/message-".$c.".txt")) {@mess=<fileMESS>;} else { $mess[0]="&#160;"; print("Ne trouve pas le fichier message/message-".$c.".txt.\n"); }
  close (fileMESS);
  #@mess=~ s/\%0D\%0A/\<br\>\<br\>/g;
  if ($test==1) { print("Contenu = ".@mess."\n\n"); }
  print messageHTML "<tr><td>";
  print messageHTML @mess;
  print messageHTML "</td></tr>";
  $c--;
}
print messageHTML ("</table>\n");

print messageHTML ("</div>\n</div>\n<div id =\"footer\">\n");
print messageHTML ("<div class=\"row_latest\">\n<div class=\"latest\">\n<div class=\"latest_text\">");
print messageHTML ("<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 messageHTML ("</div>\n</div>\n</div>\n</div>\n</div>\n");

print messageHTML ("</body>\n");
print messageHTML ("</html>\n");

close (messageHTML);
print("Fermeture du fichier message.html\n");
print("Fin du traitement\n");
exit;
1;
