<?php
include("../config.php3");
include($BIB."bib_generic.php3");
include($BIB."bib_drapeaux.php3");

####################
# Administration script defaults
####################
# pas de timeout possible qql soit l'action effectuée
set_time_limit($TIME_LIMIT);

# le script continue une fois qu'il est lancé qql soit l'état de la connection après
ignore_user_abort(true);

$tabmois = array("janvier"=>"01","février"=>"02","mars"=>"03","avril"=>"04","mai"=>"05","juin"=>"06","juillet"=>"07","août"=>"08","septembre"=>"09","octobre"=>"10","novembre"=>"11","décembre"=>"12");

$tabCorrespondanceContainers = array("LIGUE 1"=>"L1",
									"LIGUE 2"=>"L2",
									"CHAMPIONNAT D'ANGLETERRE"=>"Etrangers",
									"CHAMPIONNAT D'ITALIE"=>"Etrangers",
									"CHAMPIONNAT D'ESPAGNE"=>"Etrangers",
									"CHAMPIONNAT D'ALLEMAGNE"=>"Etrangers"
									);
/*
foreach($TEAM_NAMES AS $Fuit)
{
	echo '"'.$Fuit.'"=>"'.$Fuit.'",<br>';
}*/
	

$tabFruitNames = array
(
	"Auxerre"=>"Auxerre",
	"Bastia"=>"Bastia",
	"Bordeaux"=>"Bordeaux",
	"Guingamp"=>"Guingamp",
	"Lens"=>"Lens",
	"Lille"=>"Lille",
	"Lyon"=>"Lyon",
	"Marseille"=>"Marseille",
	"Metz"=>"Metz",
	"Monaco"=>"Monaco",
	"Nantes"=>"Nantes",
	"Paris-SG"=>"Paris SG",
	"Rennes"=>"Rennes",
	"Saint-Etienne"=>"St Etienne",
	"Sedan"=>"Sedan",
	"Strasbourg"=>"Strasbourg",
	"Toulouse"=>"Toulouse",
	"Troyes"=>"Troyes",
	"Inter Bratislava"=>"Inter Bratislava",
	"France"=>"France",
	"Angleterre"=>"Angleterre",
	"Galatasaray"=>"Galatasaray",
	"Rosenborg"=>"Rosenborg",
	"Olympiakos"=>"Olympiakos",
	"G. Rangers"=>"G. Rangers",
	"Bayern Munich"=>"Bayern Munich",
	"Sturm Graz"=>"Sturm Graz",
	"Valence"=>"Valence",
	"Afrique du Sud"=>"Afrique du Sud",
	"Celtic Glasgow"=>"Celtic Glasgow",
	"Turquie"=>"Turquie",
	"Werder Brême"=>"Werder de Brême",
	"Spartak Moscou"=>"Spartak Moscou",
	"Cannes"=>"Cannes",
	"Valence CF"=>"Valence CF",
	"Le Havre"=>"Le Havre",
	"Nîmes"=>"Nîmes",
	"Nancy"=>"Nancy",
	"Cherbourg"=>"Cherbourg",
	"Châteauroux"=>"Chateauroux",
	"FC Porto"=>"FC Porto",
	"Rayo Vallecano"=>"Rayo Vallecano",
	"Allemagne"=>"Allemagne",
	"Amiens"=>"Amiens",
	"Wasquehal"=>"Wasquehal",
	"Niort"=>"Niort",
	"Clermont Foot"=>"Clermont Foot",
	"Sete"=>"Sete",
	"Milan AC"=>"Milan AC",
	"Arsenal"=>"Arsenal",
	"Deportivo La Corogne"=>"Deportivo",
	"FC Barcelone"=>"Barcelone FC",
	"Celta Vigo"=>"Celta Vigo",
	"Liverpool FC"=>"Liverpool",
	"Le Mans"=>"Le Mans",
	"Japon"=>"Japon",
	"Espagne"=>"Espagne",
	"Grenoble"=>"Grenoble",
	"Portugal"=>"Portugal",
	"Reims"=>"Reims",
	"Alavés"=>"Alavés",
	"Kaiserslautern"=>"Kaiserslautern",
	"Real Madrid"=>"Real Madrid",
	"Manchester United"=>"Manchester Utd",
	"Leeds Utd"=>"Leeds Utd",
	"Corée du Sud"=>"Corée du Sud",
	"Australie"=>"Australie",
	"Mexique"=>"Mexique",
	"Brésil"=>"Brésil",
	"Lorient"=>"Lorient",
	"Sochaux"=>"Sochaux",
	"Montpellier"=>"Montpellier",
	"Aston Villa"=>"Aston Villa",
	"KAA Gent"=>"KAA Gent",
	"Istres"=>"Istres",
	"Nice"=>"Nice",
	"Laval"=>"Laval",
	"Créteil"=>"Créteil",
	"Gueugnon"=>"Gueugnon",
	"Caen"=>"Caen",
	"Beauvais"=>"Beauvais",
	"AC Ajaccio"=>"Ajaccio",
	"Martigues"=>"Martigues",
	"Danemark"=>"Danemark",
	"Parme"=>"Parme",
	"FC Bâle"=>"FC Bâle",
	"Newcastle United"=>"Newcastle",
	"Brescia"=>"Brescia",
	"Blackburn Rovers"=>"Blackburn",
	"Southampton"=>"Southampton",
	"Bolton Wanderers"=>"Bolton W",
	"Chelsea"=>"Chelsea",
	"West Ham Utd"=>"West Ham",
	"Charlton"=>"Charlton",
	"Everton"=>"Everton",
	"Fulham"=>"Fulham",
	"Middlesbrough"=>"Middlesbrough",
	"Sunderland"=>"Sunderland",
	"Tottenham Hotspur"=>"Tottenham",
	"Atalanta Bergame"=>"Atalanta Bergame",
	"AS Rome"=>"AS Roma",
	"Bologne"=>"Bologne",
	"Chievo Verone"=>"Chievo Verona",
	"Inter Milan"=>"Inter Milan",
	"Juventus Turin"=>"Juventus",
	"Lazio Rome"=>"Lazio Rome",
	"Torino"=>"Torino",
	"Perugia"=>"Perugia",
	"Piacenza"=>"Piacenza",
	"Udinese"=>"Udinese",
	"Malaga"=>"Malaga",
	"Betis Séville"=>"Betis Séville",
	"Real Valladolid"=>"Real Valladolid",
	"Real Majorque"=>"Real Majorque",
	"Real Sociedad"=>"Real Sociedad",
	"Athletic Bilbao"=>"Ath. Bilbao",
	"Osasuna"=>"Osasuna",
	"Villarreal"=>"Villareal CF",
	"FC Séville"=>"FC Séville",
	"Espanyol Barcelone"=>"Esp. Barcelone",
	"Chili"=>"Chili",
	"Angers"=>"Angers",
	"Louhans-Cuiseaux"=>"Louhans-Cuiseaux",
	"Boavista"=>"Boavista",
	"Dinamo Kiev"=>"Dinamo Kiev",
	"Borussia Dortmund"=>"Dortmund",
	"Schalke 04"=>"Schalke 04",
	"Panathinaikos"=>"Panathinaikos",
	"PSV Eindhoven"=>"PSV Eindhoven",
	"Bayer Leverkusen"=>"Leverkusen",
	"Feyenoord"=>"Feyenoord",
	"Anderlecht"=>"Anderlecht",
	"Algérie"=>"Algérie",
	"Brest"=>"Brest",
	"Roumanie"=>"Roumanie",
	"Servette"=>"Servette",
	"AEK Athènes"=>"AEK Athènes",
	"Ecosse"=>"Ecosse",
	"Russie"=>"Russie",
	"Belgique"=>"Belgique",
	"Sénégal"=>"Sénégal",
	"Irlande"=>"Irlande",
	"Cameroun"=>"Cameroun",
	"Uruguay"=>"Uruguay",
	"Arabie Saoudite"=>"Arabie Saoudite",
	"Argentine"=>"Argentine",
	"Nigeria"=>"Nigeria",
	"Paraguay"=>"Paraguay",
	"Suède"=>"Suède",
	"Slovénie"=>"Slovénie",
	"Croatie"=>"Croatie",
	"Italie"=>"Italie",
	"Equateur"=>"Equateur",
	"Chine"=>"Chine",
	"Costa Rica"=>"Costa Rica",
	"Pologne"=>"Pologne",
	"Tunisie"=>"Tunisie",
	"Etats Unis"=>"Etats Unis",
	"Birmingham"=>"Birmingham",
	"Hajduk Split"=>"Hajduk Split",
	"Sporting CP"=>"Sporting CP",
	"Manchester City"=>"Manchester City",
	"Atletico Madrid"=>"Athl. Madrid",
	"Chypre"=>"Chypre",
	"Norvege"=>"Norvege",
	"Belarus"=>"Belarus",
	"Grece"=>"Grece",
	"Slovaquie"=>"Slovaquie",
	"Bulgarie"=>"Bulgarie",
	"Finlande"=>"Finlande",
	"Galles"=>"Galles",
	"Malte"=>"Malte",
	"Bosnie"=>"Bosnie",
	"Autriche"=>"Autriche",
	"Pays Bas"=>"Pays Bas",
	"FC Bruges"=>"FC Bruges",
	"Ajax Amsterdam"=>"Ajax Amsterdam",
	"V. Arnhem"=>"V. Arnhem",
	"Slavia Prague"=>"Slavia Prague",
	"Hongrie"=>"Hongrie",
	"Islande"=>"Islande",
	"Yougoslavie"=>"Yougoslavie",
	"Albanie"=>"Albanie",
	"Suisse"=>"Suisse",
	"Estonie"=>"Estonie",
	"Lituanie"=>"Lituanie",
	"Israël"=>"Israël",
	"Reggina"=>"Reggina",
	"R. Santander"=>"R. Santander",
	"Modena"=>"Modena",
	"Besiktas"=>"Besiktas",
	"Angoulême"=>"Angoulême",
	"Besançon"=>"Besançon",
	"West Bromwich Albion"=>"W. Br. Albion",
	"Valenciennes"=>"Valenciennes",
	"Empoli"=>"Empoli",
	"Dijon"=>"Dijon",
	"Hertha Berlin"=>"Hertha Berlin",
	"Rep. Tcheque"=>"Rep. Tcheque",
	"Como"=>"Como",
	"Valladolid"=>"Valladolid",
	"Ukraine"=>"Ukraine",
	"Georgie"=>"Georgie",
	"Egypte"=>"Egypte",
	"Paris St Germain"=>"Paris St Germain",
	"Recreativo Huelva"=>"Recreativo Huelva",
	"Colombie"=>"Colombie",
	"Nouvelle-Zélande"=>"Nouvelle-Zélande",
	"Luxembourg"=>"Luxembourg",
	"Moldavie"=>"Moldavie",
	"Belarus"=>"Belarus",
	"Rouen"=>"Rouen",
	"Leicester City"=>"Leicester City",
	"Wolverhampton"=>"Wolverhampton",
	"Portsmouth"=>"Portsmouth",
	"Ancona"=>"Ancona",
	"Austria Vienne"=>"Austria Vienne",
	"Benfica"=>"Benfica",
	"Loc. Moscou"=>"Loc. Moscou",
	"Murcie"=>"Murcie",
	"Partizan Belgrade"=>"Partizan Belgrade",
	"Real Saragosse"=>"Real Saragosse",
	"Sparta Prague"=>"Sparta Prague",
	"Torpedo Kutaisi"=>"Torpedo Kutaisi",
	"Albacete"=>"Albacete",
	"Lecce"=>"Lecce",
	"Sampdoria Gênes"=>"Sampdoria Gênes",
	"SC Heerenveen"=>"SC Heerenveen",
	"Sienne"=>"Siene",
	"VfL Wolfsburg"=>"VfL Wolfsburg",
	"SV Pasching"=>"SV Pasching",
	"Club Bruges"=>"Club Bruges",
	"Club Bruges"=>"Club Bruges",
	"CSKA Sofia"=>"CSKA Sofia",
	"Dinamo Zagreb"=>"Dinamo Zagreb",
	"FC Copenhague"=>"FC Copenhague",
	"Grass. Zürich"=>"Grass. Zürich",
	"Grazer AK"=>"Grazer AK",
	"MSK Zilina"=>"MSK Zilina",
	"Shakhtyor Donetsk"=>"Shakhtyor Donetsk",
	"Valdar Kopje"=>"Valdar Kopje",
	"Wisla Cracovie"=>"Wisla Cracovie",
	"MTK Budapest"=>"MTK Budapest",
	"Artmedia Petrzalka"=>"Artmedia Petrzalka",
	"Neuchâtel Xamax"=>"Neuchâtel Xamax",
	"Myllykosken Pallo-47"=>"Myllykosken Pallo-47",
	"Cementarnica 55"=>"Cementarnica 55",
	"Gaziantepspor"=>"Gaziantepspor",
	"FC Utrecht"=>"FC Utrecht",
	"Heart of Midlothian"=>"Heart of Midlothian",
	"Lettonie"=>"Lettonie",
	"VfB Stuttgart"=>"VfB Stuttgart",
	"Bayonne"=>"Bayonne",
	"Bourg-Péronnas"=>"Bourg-Péronnas",
	"Brive"=>"Brive",
	"Plabennec"=>"Plabennec",
	"Ajaccio GFCO"=>"Ajaccio GFCO",
	"Croix Savoie"=>"Croix Savoie",
	"Fontenay LCVF"=>"Fontenay LCVF",
	"Bröndby IF"=>"Bröndby IF",
	"Gençlerbirligi"=>"Gençlerbirligi",
	"Dniepr"=>"Dniepr",
	"Groclin Grodzisk"=>"Groclin Grodzisk",
	"Debreceni VSC"=>"Debreceni VSC",
	"Levski Sofia"=>"Levski Sofia",
	"Valerengen Oslo"=>"Valerengen Oslo",
	"FK Teplice"=>"FK Teplice",
	"Andorre"=>"Andorre",
	"Numancia"=>"Numancia",
	"Norwich City"=>"Norwich City",
	"Getafe"=>"Getafe",
	"Levante"=>"Levante",
	"Iles Féroé"=>"Iles Féroé",
	"CSKA Moscou"=>"CSKA Moscou",
	"Shelbourne"=>"Shelbourne",
	"AaB Aalborg"=>"AaB Aalborg",
	"Stabaeck"=>"Stabaeck",
	"Fiorentina"=>"Fiorentina",
	"Messina"=>"Messina",
	"Cagliari"=>"Cagliari",
	"Livorno"=>"Livorno",
	"Palerme"=>"Palerme",
	"Fenerbahçe"=>"Fenerbahçe",
	"Amica Wronski"=>"Amica Wronski",
	"AZ Alkmaar"=>"AZ Alkmaar",
	"Dinamo Tbilisi"=>"Dinamo Tbilisi",
	"Panionios"=>"Panionios",
	"Sporting CP"=>"Sporting CP",
	"TSV Alemannia"=>"TSV Alemannia",
	"Zenith St Petersbourg"=>"Zenith St Petersbourg",
	"Lyon-la-Duchère"=>"Lyon-la-Duchère",
	"Schiltigheim"=>"Schiltigheim",
	"Quevilly"=>"Quevilly",
	"Bois-Guillaume"=>"Bois-Guillaume",
	"Limoges"=>"Limoges",
	"Feignies"=>"Feignies",
	"La Roche-sur-Yon"=>"La Roche-sur-Yon",
	"Rhône-Vallée"=>"Rhône-Vallée",
	"Domerat"=>"Domerat",
	"Haguenau"=>"Haguenau",
	"Saint-Omer"=>"Saint-Omer",
	"Saumur"=>"Saumur",
	"Poire-sur-Vie"=>"Poire-sur-Vie",
	"Albi"=>"Albi",
	"Andrézieux"=>"Andrézieux",
	"Libourne/Saint-Seurin"=>"Libourne/Saint-Seurin",
	"Mont-de-Marsan"=>"Mont-de-Marsan",
	"Châteaubriand"=>"Châteaubriand",
	"Romorantin"=>"Romorantin",
	"Menton"=>"Menton",
	"Cournon"=>"Cournon",
	"Pau"=>"Pau",
	"Toulon"=>"Toulon",
	"Montagnarde"=>"Montagnarde",
	"Boulogne-sur-Mer"=>"Boulogne-sur-mer",
	"Blois"=>"Blois",
	"Vannes FC"=>"Vannes FC",
	"Côte d'Ivoire"=>"Côte d'Ivoire",
	"Wigan Athletic"=>"Wigan Athletic",
	"Hambourg SV"=>"Hambourg SV",
	"CFR Cluj"=>"CFR Cluj",
	"Serbie"=>"Serbie",
	"Irlande du Nord"=>"Irlande du Nord",
	"Beerschot Anvers"=>"Beerschot Anvers",
	"Willem II"=>"Willem II",
	"Vitoria FC"=>"Vitoria FC",
	"PaokFC"=>"PaokFC",
	"Tromso IL"=>"Tromso IL",
	"St. Bucarest"=>"St. Bucarest",
	"Viking FK"=>"Viking FK",
	"Halmstads BK"=>"Halmstads BK",
	"Etoile Rouge"=>"Etoile Rouge",
	"Dinamo Bucarest"=>"Dinamo Bucarest",
	"Rapid Bucarest"=>"Rapid Bucarest",
	"Litex Lovech"=>"Litex Lovech",
	"Calais"=>"Calais",
	"Vitré"=>"Vitré",
	"Colmar"=>"Colmar",
	"Ascoli"=>"Ascoli",
	"Iran"=>"Iran",
	"Angola"=>"Angola",
	"Trinité tobago"=>"Trinité tobago",
	"Ghana"=>"Ghana",
	"Togo"=>"Togo",
	"Mika Fc"=>"Mika Fc",
	"Young Boys Bern"=>"Young Boys Bern",
	"Dinamo"=>"Dinamo",
	"NK Domzale"=>"NK Domzale",
	"NK Orasje"=>"NK Orasje",
	"Spartak Trnava"=>"Spartak Trnava",
	"Karvan Evlakh"=>"Karvan Evlakh",
	"Levadia Tallinn"=>"Levadia Tallinn",
	"FC Haka"=>"FC Haka",
	"Zaglebie Lubin"=>"Zaglebie Lubin",
	"Dinamo Minsk"=>"Dinamo Minsk",
	"KF Tirana"=>"KF Tirana",
	"NK Varteks"=>"NK Varteks",
	"Jeunesse Esch"=>"Jeunesse Esch",
	"Skonto Riga"=>"Skonto Riga",
	"HJK Helsinki"=>"HJK Helsinki",
	"Drogheda Utd"=>"Drogheda Utd",
	"FK Vardar"=>"FK Vardar",
	"KSV Roeselare"=>"KSV Roeselare",
	"FK Sarajevo"=>"FK Sarajevo",
	"Rangers FC"=>"Rangers FC",
	"Bate Borisov"=>"Bate Borisov",
	"Nistru Otaci"=>"Nistru Otaci",
	"WIT Georgia"=>"WIT Georgia",
	"Artmedia Bratislava"=>"Artmedia Bratislava",
	"Ameri Tbilisi"=>"Ameri Tbilisi",
	"FC Banants"=>"FC Banants",
	"Sliema Wanderers"=>"Sliema Wanderers",
	"Rapid Bucuresti"=>"Rapid Bucuresti",
	"Derry City"=>"Derry City",
	"IFK Göteborg"=>"IFK Göteborg",
	"Zimbru Chisinau"=>"Zimbru Chisinau",
	"FK Karabakh"=>"FK Karabakh",
	"Makedonija Skopje"=>"Makedonija Skopje",
	"Lokomotiv Sofia"=>"Lokomotiv Sofia",
	"FC Basel"=>"FC Basel",
	"Tobol Kostanay"=>"Tobol Kostanay",
	"Etzella Ettelbrück"=>"Etzella Ettelbrück",
	"Atvidabergs FF"=>"Atvidabergs FF",
	"Skala Itrottarfelag"=>"Skala Itrottarfelag",
	"IK Start"=>"IK Start",
	"Portadown FC"=>"Portadown FC",
	"FBK Kaunas"=>"FBK Kaunas",
	"Glentoran FC"=>"Glentoran FC",
	"SK Brann"=>"SK Brann",
	"Rhyl FC"=>"Rhyl FC",
	"FK Suduva"=>"FK Suduva",
	"Brondby IF"=>"Brondby IF",
	"Valur Reykjavik"=>"Valur Reykjavik",
	"HNK Rijeka"=>"HNK Rijeka",
	"AS Omonia"=>"AS Omonia",
	"Hibernians FC"=>"Hibernians FC",
	"Dinamo Bucuresti"=>"Dinamo Bucuresti",
	"Tours FC"=>"Tours",
	"FC Farul Constanta"=>"FC Farul Constanta",
	"Ethnikos Achnas"=>"Ethnikos Achnas",
	"Larissa"=>"Larissa",
	"Kayserispor"=>"Kayserispor",
	"NK Maribor"=>"NK Maribor",
	"Maccabi Petach-Tikva"=>"Maccabi Petach-Tikva",
	"FC Moscou"=>"FC Moscou",
	"SV Ried"=>"SV Ried",
	"FC Tiraspol"=>"FC Tiraspol",
	"FC Dinaburg"=>"FC Dinaburg",
	"Odense"=>"Odense",
	"Lillestrom"=>"Lillestrom",
	"Kalmar FF"=>"Kalmar FF",
	"FC Twente"=>"FC Twente",
	"KS Elbasani"=>"KS Elbasani",
	"FK Ekranas"=>"FK Ekranas",
	"FC TVMK Tallin"=>"FC TVMK Tallin",
	"FH Hafnarfjördur"=>"FH Hafnarfjördur",
	"Liepajas Metalurgs"=>"Liepajas Metalurgs",
	"FK Aktobe"=>"FK Aktobe",
	"Myllykosken Pallo-47"=>"Myllykosken Pallo-47",
	"The New Saints FC"=>"The New Saints FC",
	"Cork City"=>"Cork City",
	"Apollon Limassol FC"=>"Apollon Limassol FC",
	"FC Sioni Bolnisi"=>"FC Sioni Bolnisi",
	"FK Bakou"=>"FK Bakou",
	"F91 Dudelange"=>"F91 Dudelange",
	"FK Rabotnicki"=>"FK Rabotnicki",
	"FC Shakhtyor Soligorsk"=>"FC Shakhtyor Soligorsk",
	"NK Siroki Brijeg"=>"NK Siroki Brijeg",
	"Birkirkara FC"=>"Birkirkara FC",
	"B36 Torshavn"=>"B36 Torshavn",
	"Linfield FC"=>"Linfield FC",
	"NK Gorica"=>"NK Gorica",
	"FC Pyunik"=>"FC Pyunik",
	"FC Sheriff"=>"FC Sheriff",
	"KS Dinamo Tirana"=>"KS Dinamo Tirana",
	"Crvena Zvezda"=>"Crvena Zvezda",
	"Debrecen"=>"Debrecen",
	"Hearts"=>"Hearts",
	"Boleslav"=>"Boleslav",
	"Valerenga"=>"Valerenga",
	"Ekranas"=>"Ekranas",
	"Rabotnicki Skopje"=>"Rabotnicki Skopje",
	"VSC Debrecen"=>"VSC Debrecen",
	"MFK Ruzomberok"=>"MFK Ruzomberok",
	"Djurgardens IF"=>"Djurgardens IF",
	"RB Salzburg"=>"RB Salzburg",
	"FC Zürich"=>"FC Zürich",
	"FL Mlada Boleslav"=>"FL Mlada Boleslav",
	"Macédoine"=>"Macédoine",
	"Kazakhstan"=>"Kazakhstan",
	"Sheffield united"=>"Sheffield united",
	"Reading"=>"Reading",
	"Watford"=>"Watford",
	"OFK Belgrade"=>"OFK Belgrade",
	"Beitar Jerusalem"=>"Beitar Jerusalem",
	"Zaragoza"=>"Zaragoza",
	"Racing Santander"=>"Racing Santander",
	"Recreativo Huelva "=>"Recreativo Huelva ",
	"Gimnastic"=>"Gimnastic",
	"PSV Eindhoven"=>"PSV Eindhoven",
	"Eintracht Francfort"=>"Eintracht Francfort",
	"Sporting Braga"=>"Sporting Braga",
	"Hapoël Tel-Aviv"=>"Hapoël Tel-Aviv",
	"Catane"=>"Catania",
	"VfL Bochum"=>"Bochum",
	"Mayence"=>"Mayence",
	"Wolfsburg"=>"Wolfsburg",
	"Nuremberg"=>"Nuremberg",
	"Stuttgart"=>"Stuttgart",
	"Arminia Bielefeld"=>"Arminia Bielefeld",
	"Energie Cottbus"=>"Energie Cottbus",
	"Borussia M'Gladbach"=>"Mönchengladbach",
	"Hanovre 96"=>"Hanovre 96",
	"Aachen"=>"Aachen",
	"Vannes OC"=>"Vannes OC",
	"Montceau"=>"Montceau",
	"Maccabi Haïfa"=>"Maccabi Haïfa",
	"Azerbaïdjan"=>"Azerbaïdjan",
	"Liechtenstein"=>"Liechtenstein",
	"San Marin"=>"San Marin",
	"Arménie"=>"Arménie",
	"Goias"=>"Goias",
	"Figueirense"=>"Figueirense",
	"Atlético Minerio Belo Horizont"=>"Atlético Minerio Belo Horizont",
	"Atlético Paranaense"=>"Atlético Paranaense",
	"Botafogo"=>"Botafogo",
	"Gremio Porto Alegre"=>"Gremio Porto Alegre",
	"Santos"=>"Santos",
	"Corinthians"=>"Corinthians",
	"Palmeiras"=>"Palmeiras",
	"Cruzeiro"=>"Cruzeiro",
	"Sport Recife"=>"Sport Recife",
	"Flamengo"=>"Flamengo",
	"Juventude"=>"Juventude",
	"América"=>"América",
	"Parana"=>"Parana",
	"São Paulo"=>"São Paulo",
	"Internacional"=>"Internacional",
	"Náutico"=>"Náutico",
	"Vasco de Gama"=>"Vasco de Gama",
	"Fluminense"=>"Fluminense",
	"Madagascar"=>"Madagascar",
	"Gabon"=>"Gabon",
	"Burundi"=>"Burundi",
	"Botswana"=>"Botswana",
	"Mauritanie"=>"Mauritanie",
	"Niger"=>"Niger",
	"Lesotho"=>"Lesotho",
	"Ouganda"=>"Ouganda",
	"Maurice"=>"Maurice",
	"Seychelles"=>"Seychelles",
	"Soudan"=>"Soudan",
	"Guinée équatoriale"=>"Guinée équatoriale",
	"Libéria"=>"Libéria",
	"Rwanda"=>"Rwanda",
	"Erythrée"=>"Erythrée",
	"Kenya"=>"Kenya",
	"Swaziland"=>"Swaziland",
	"Mozambique"=>"Mozambique",
	"Burkina Faso"=>"Burkina Faso",
	"Tanzanie"=>"Tanzanie",
	"Cap-Vert"=>"Cap-Vert",
	"Gambie"=>"Gambie",
	"Guinée"=>"Guinée",
	"Mali"=>"Mali",
	"Sierra Leone"=>"Sierra Leone",
	"Bénin"=>"Bénin",
	"Namibie"=>"Namibie",
	"R D Congo"=>"R D Congo",
	"Libye"=>"Libye",
	"Ethiopie"=>"Ethiopie",
	"Zambie"=>"Zambie",
	"Tchad"=>"Tchad",
	"Congo"=>"Congo",
	"Malawi"=>"Malawi",
	"Maroc"=>"Maroc",
	"Bolivie"=>"Bolivie",
	"Irak"=>"Irak",
	"Indonésie"=>"Indonésie",
	"Jamaique"=>"Jamaique",
	"Malaisie"=>"Malaisie",
	"Emirats Arabes Unis"=>"Emirats Arabes Unis",
	"Vietnam"=>"Vietnam",
	"Oman"=>"Oman",
	"R D P Corée"=>"R D P Corée",
	"Qatar"=>"Qatar",
	"Turkménistan"=>"Turkménistan",
	"Macao"=>"Macao",
	"Guam"=>"Guam",
	"Hong Kong"=>"Hong Kong",
	"Singapore"=>"Singapore",
	"Palestine"=>"Palestine",
	"Bahrein"=>"Bahrein",
	"Thailande"=>"Thailande",
	"Venezuela"=>"Venezuela",
	"Perou"=>"Perou",
	"FC Tobol Kostanay"=>"FC Tobol Kostanay",
	"FK Macedonia Skopje"=>"FK Macedonia Skopje",
	"Dacia Chisinau"=>"Dacia Chisinau",
	"Chernomorets Odessa"=>"Chernomorets Odessa",
	"Zalaegerszegi"=>"Zalaegerszegi",
	"Rapid Vienne"=>"Rapid Vienne",
	"FC Sarajevo"=>"FC Sarajevo",
	"Honka Espoo"=>"Honka Espoo",
	"Trabzonspor"=>"Trabzonspor",
	"Vetra Vilnius"=>"Vetra Vilnius",
	"Hajduk Kula"=>"Hajduk Kula",
	"Gloria Bistrita"=>"Gloria Bistrita",
	"Slovan Liberec"=>"Slovan Liberec",
	"Cherno More Varna"=>"Cherno More Varna",
	"Saint Gall"=>"Saint Gall",
	"Shakter Soligorsk"=>"Shakter Soligorsk",
	"Hammarby IF"=>"Hammarby IF",
	"Rubin Kazan"=>"Rubin Kazan",
	"Cliftonville FC"=>"Cliftonville FC",
	"Slovan Bratislava"=>"Slovan Bratislava",
	"Otelul Galati"=>"Otelul Galati",
	"Vllaznia Shkoder"=>"Vllaznia Shkoder",
	"Legia Varsovie"=>"Legia Varsovie",
	"FC Utrecht"=>"FC Utrecht",
	"Uniao Leiria"=>"Uniao Leiria",
	"OFI Crète"=>"OFI Crète",
	"SK Tirana"=>"SK Tirana",
	"Marsaxlokk"=>"Marsaxlokk",
	"Pyunik Erevan"=>"Pyunik Erevan",
	"Sheriff Tiraspol"=>"Sheriff Tiraspol",
	"Ranger's"=>"Ranger's",
	"FC Pobeda"=>"FC Pobeda",
	"FK Zeta Golubovci"=>"FK Zeta Golubovci",
	"FBK Kaunas"=>"FBK Kaunas",
	"Khazar Lenkoran"=>"Khazar Lenkoran",
	"HB Torshavn"=>"HB Torshavn",
	"Apoel Nicosie"=>"Apoel Nicosie",
	"FC Bate Borisov"=>"FC Bate Borisov",
	"Olimpi Rustavi"=>"Olimpi Rustavi",
	"FC Zhenis Astana"=>"FC Zhenis Astana",
	"Total Network Solutions"=>"Total Network Solutions",
	"Ventspils"=>"Ventspils",
	"Elfsborg Boras"=>"Elfsborg Boras",
	"Derby"=>"Derby",
	"Hansa Rostock"=>"Hansa Rostock",
	"Karlsruhe SC"=>"Karlsruher SC",
	"Duisburg"=>"Duisburg",
	"Almeria"=>"Alméria",
	"Genoa"=>"Genoa",
	"Naples"=>"Naples",
	"Chakhtior Donetsk FC"=>"Chakhtior Donetsk FC",
	"Tampere United"=>"Tampere United",
	"Panionios NFC"=>"Panionios NFC",
	"Belenenses"=>"Belenenses",
	"Liège Standard"=>"Liège Standard",
	"FC Sion"=>"FC Sion",
	"Aberdeen"=>"Aberdeen",
	"Helsingborgs IF"=>"Helsingborgs IF",
	"Mlada Boleslav"=>"Mlada Boleslav",
	"Aris Salonique"=>"Aris Salonique",
	"Falkirk"=>"Falkirk",
	"Inverness CT"=>"Inverness CT",
	"Gretna"=>"Gretna",
	"St Mirren"=>"St Mirren",
	"Kilmarnock"=>"Kilmarnock",
	"Motherwell"=>"Motherwell",
	"Dundee United"=>"Dundee United",
	"Heracles"=>"Heracles",
	"Excelsior"=>"Excelsior",
	"Roda JC"=>"Roda JC",
	"NEC Nimègue"=>"NEC Nimègue",
	"VVV Venlo"=>"VVV Venlo",
	"De Graafschap"=>"De Graafschap",
	"NAC Breda"=>"NAC Breda",
	"Vitesse Arnhem"=>"Vitesse Arnhem",
	"FC Groningen"=>"FC Groningen",
	"Sparta Rotterdam"=>"Sparta Rotterdam",
	"Frejus"=>"Frejus",
	"Marignane"=>"Marignane",
	"Arles"=>"Arles",
	"Selongey"=>"Selongey",
	"Raon l'Etape"=>"Raon l'Etape",
	"Viry Chatillon"=>"Viry Chatillon",
	"Avranches"=>"Avranches",
	"Le Poiré sue Vie"=>"Le Poiré sue Vie",
	"Coulaines"=>"Coulaines",
	"Vesoul"=>"Vesoul",
	"Luzenac"=>"Luzenac",
	"Montluçon"=>"Montluçon",
	"Carquefou"=>"Carquefou",
	"Epinal"=>"Epinal",
	"Paris FC"=>"Paris FC",
	"Maubeuge"=>"Maubeuge",
	"Avion"=>"Avion",
	"Montenegro"=>"Montenegro",
	"Ipatinga"=>"Ipatinga",
	"Portuguesa"=>"Portuguesa",
	"Coritiba"=>"Coritiba",
	"Terek Grozny"=>"Terek Grozny",
	"Dinamo Moscou"=>"Dinamo Moscou",
	"Krylia Sovetov"=>"Krylia Sovetov",
	"Rubin Kazan"=>"Rubin Kazan",
	"Spartak Naltchik"=>"Spartak Naltchik",
	"Shinnik Yaroslavl"=>"Shinnik Yaroslavl",
	"Saturn"=>"Saturn",
	"Amkar Perm"=>"Amkar Perm",
	"Tomsk"=>"Tomsk",
	"Vladivostok"=>"Vladivostok",
	"FC Khimki"=>"FC Khimki",
	"Stoke City"=>"Stoke City",
	"Hull City"=>"Hull City",
	"FC Cologne"=>"FC Cologne",
	"Hoffenheim"=>"Hoffenheim",
	"Sporting Gijon"=>"Gijon",
	"Anorthosis"=>"Anorthosis",
	"Metalist Kharkov"=>"Metalist Kharkov",
	"Lech Poznan"=>"Lech Poznan"
);

?>
<html>
<head></head>
<link rel="stylesheet" href="admin.css">
<body rightmargin=0>
<div align=center class=trTitle>Récupération de match depuis l'équipe.fr</div>
<br>
<?php
$journees_defaut = 1;

if($journees)
	$journees_defaut = $journees;




if($Add == "x")
{
	//on ajoute la categorie
	main_db_query("INSERT INTO Categories (Container,Name,EndTime,ShowTime, Image) VALUES ('".$ContainerId."','".$Name."','".$EndTime."','".$ShowTime."', '".$Image."')");
	$CategoryId = db_insert_id();
	
	$i=1;
	
	$Team1= "Team1_".$i;
	$Team2= "Team2_".$i;
	$match_showtime= "match_showtime_".$i;
	$match_endtime= "match_endtime_".$i;
	
	while(strlen($$Team1) > 1)
	{
		main_db_query("INSERT INTO Matchs (Team1,Team2,Rate1,Rate2,Date,ShowTime,Category) VALUES ('".$$Team1."','".$$Team2."','".$Taux1."','".$Taux2."','".$$match_endtime."','".$$match_showtime."','".$CategoryId."')");
		$max_tmp = db_fetch_array(main_db_query("SELECT MAX(MatchId) as MaxId FROM Matchs"));
		$the_MatchId = $max_tmp[MaxId];
		main_db_query("INSERT INTO MatchsStats (MatchId, Win1, Win2, NullGame) VALUES ('$the_MatchId', '0', '0', '0')");
		echo "Match :".$$Team1." vs ".$$Team2." du ".$$match_endtime." a été injecté !<br>";
		
		$i++;
		
		$Team1= "Team1_".$i;
		$Team2= "Team2_".$i;
		$match_showtime= "match_showtime_".$i;
		$match_endtime= "match_endtime_".$i;
	}
	
	if($nextJournee)
	{
		//on parse à l'url de la journée suivante
		$patternURL = "#(http://[^/]*/)([A-Za-z0-9/-]*)([A-Za-z])([0-9]+).html#";
		if(preg_match ($patternURL ,$url,$trouve))
		{
			$url = $trouve[1].$trouve[2].$trouve[3].(intval($trouve[4])+1).".html";		
			$NextPageOk = 1;
			$ok = 1;
		}
		else
		{
			$NextPageOk = -1;
		}
	}
	
	
}
	

	

?>
	
<?php
if($NextPageOk == 1)
{
	echo "<h1>JOURNEE SUIVANTE</h1>";
}
elseif($NextPageOk == -1)
{
	echo "<h1>Page suivante non trouvée</h1";
}
?>
<!-- 
FORMULAIRE DE DECLARATION DE LA PAGE SOURCE 
-->
<form method=post>
>> <a href="http://www.lequipe.fr/Football/" target="_blank">Aller sur l'équipe.fr</a>
<br><br>
<b>Url de la page Calendrier et Résultats l'equipe.fr </b>: <input type=text name=url value="<?php echo $url;?>" size=100>
<br><i>exemple : http://www.lequipe.fr/Football/FootballResultat17881.html</i>
<br><i>pour enchainer les journées éviter les urls du type : http://www.lequipe.fr/Football/RES_D1.html</i>
<br>
<br>
<?php 
if($nextJournee)
	$checked = "CHECKED";
?>
<input type=checkbox name=nextJournee <?php echo $checked;?>> <b>Enchainer la journée suivante</b>
<br>
<input type="submit" name="ok" value="Parser la page">
</form>

<hr>

<!-- 
FORMULAIRE DE VALIDATION DE MATCH RECUPERES
-->
<form method=post>
<?php
if($ok)
{	
	$titre = 0;
	$date_time = "";
	$mapage_array = file($url);
	$ParseOk = 0;
	foreach ( $mapage_array AS $maligne)
	{
		$maligne =  utf8_decode($maligne);
		
		
		if(preg_match ( "#<h1>(.*)</h1>#" , $maligne,$trouve ))
		{
			$CONTAINER = $trouve[1];
		}
		if(preg_match ( "#<h2>(.*)</h2>#" , $maligne,$trouve ))
		{
			$CATEGORIE = $trouve[1];
		}
		
		
		
		//on trouve la zone ou sont affichés les matchs
		if(eregi ( "class=\"resultats ld" , $maligne ) )
		{
			
			echo "<table cellpadding=10 cellspacing=10>";
			
			$i = 1;
			$col = 0;
			$date_time = "";
			//On parse ligne par ligne (une ligne commence par un <tr...>
			$pattern_split = "/<tr([[:space:]]class=\"alternate[1-2]\"){0,1}>/";
			$Les_lignes_match = preg_split($pattern_split,$maligne);				
			foreach ( $Les_lignes_match AS $match)
			{
				
				
				$failed = 0;
				
				//SI la ligne est de type affichage de date
				//on recupere la date du/des match si elle est sur cette ligne
				$patternJour = "#<th colspan=\"6\">(.*)</th></tr>#";
				if(preg_match ($patternJour ,$match,$trouve))
				{						
					preg_match ("#(.*) (.*) (.*) (.*)#" ,$trouve[1],$date);
					$new_date_time = $date[4]."-".$tabmois[$date[3]]."-".sprintf("%02s",str_replace("er","",$date[2]));
					if($date_time != $new_date_time)
					{
						$date_time = $new_date_time;						
					}
					
				}
				
				//Si la ligne est de type affichage de match
				//on recupere les infos du match : heure / equipe domicile / score / equipe visiteur
				$pattern_ultime = "#<td class=\"heure\">(.*)</td>(<td class=\"lieu\">(.*)</td> ){0,1}<td class=\"domicile\"><a class=\"lien\" href=\"(.*)\">(<strong>){0,1}([éèàùêâàûîôö[:alnum:][:space:]-\']*)(</strong>){0,1}(&nbsp;){0,1}(\([0-9]*\)){0,1}</a></td><td class=\"score\">(<a href=\"(.*)\">)*(.*)(</a>)*</td><td class=\"visiteur\"><a class=\"lien\" href=\"(.*)\">(<b>){0,1}([éèàùêâàûîôö[:alnum:][:space:]-\']*)(</b>){0,1}</a>(&nbsp;){0,1}(\([0-9]*\)){0,1}</td><td class=\"archive\">(<a href=\"(.*)\"><img src=\"(.*)\" alt=\"confrontations\" />(.*)</a>|&nbsp;)+</td></tr>#";
				if(preg_match ($pattern_ultime ,$match,$trouve))
				{
					
					$domicile = trim($trouve[6]);			
					$score = $trouve[12];	
					$visiteur = trim($trouve[16]);
				}
				else
				{
					$failed = 1;
				}
				
				//Si on a bien recuperé des info sur la ligne on les affiche dans le formulaire de validation
				if(!$failed)
				{
					
					
					$ParseOk = 1;
					if($col == 0)
						echo "<tr>";
					
										
					if($trouve[1] != "")
					{
						$heure = str_replace("h",":",$trouve[1]);
						$heure = str_replace("&nbsp;","",$heure);
						$heure .= ":00";
					}
					//on recupere la 1ere date
					if($i==1)
					{
						$FIRSTMATCH_DATE = $date_time." ".$heure;						
						
						$SHOWTIME = date("Y-m-d H:i:s",strtotime($FIRSTMATCH_DATE)-(15*24*60*60));
						
					}
					
					echo "<td>";
					echo "\n<h3>Match ".$i."</h3>";
					echo "\n<table cellpadding=0 cellspacing=0>";					
					//echo "\n<tr><td><b>Equipe Domicile :</b></td><td><input type='text' name='equipe1_".$i."' value='".$domicile."'></td></tr>";	
					echo "<tr><td><b>Equipe  :</b><br>(".$domicile.")</td><td>";
					echo "<select name=\"Team1_".$i."\" size=1>";
					$found = 0;
					asort($TEAM_NAMES);
					while(list($k,$v)=each($TEAM_NAMES))
					{
						if ($tabFruitNames[$domicile] == $v)
						{
							echo "<option selected>".$v;
							$found = 1;
						}
						else
						{
							echo "<option>".$v;
						}
					}
					echo "</select>";
					if($found == 0)
						echo "&nbsp;<font color=#FF0000><b>!!</b></font>";
					echo "</td></tr>";
					echo "<tr><td><b>Equipe 2 :</b><br>(".$visiteur.")</td><td>";
					echo "<select name=\"Team2_".$i."\" size=1>";
					$found = 0;
					reset($TEAM_NAMES);
					while(list($k,$v)=each($TEAM_NAMES))
					{
						if ($tabFruitNames[$visiteur] == $v)
						{
							echo "<option selected>".$v;
							$found = 1;
						}
						else
						{
							echo "<option>".$v;
						}
					}
					echo "</select>";
					if($found == 0)
						echo "&nbsp;<font color=#FF0000><b>!!</b></font>";
					echo "</td></tr>";
					
					//echo "\n<tr><td><b>Equipe Visiteur :</b></td><td><input type='text' name='equipe2_".$i."' value='".$visiteur."'></td></tr>";
					echo "\n<tr><td><b>Date d'affichage :</b> </td><td><input type='text' name='match_showtime_".$i."' value='".$SHOWTIME."'></td></tr>";
					echo "\n<tr><td><b>Date limite :</b> </td><td><input type='text' name='match_endtime_".$i."' value='".$date_time." ".$heure."'></td></tr>";
					echo "\n</table>";
					echo "\n</td>";
					$i++;
					
					//On ferme la catégorie à l'heure de début du dernier match 
					$ENDTIME = $date_time." ".$heure;
					
					if($col == 2)
					{
						echo "</tr>";
						$col = 0;
					}
					else
					{
						$col++;
					}					
				}
				else
				{
					//echo "<hr><br><b>Failed</b>".$match;
				}
			}

			
		}
	}
}
if($ParseOk)
{
?>
	<tr>
		<td colspan=3 align=center>
			<hr><h3>Sélection Container et catégorie</h3>
		</td>
	</tr>
	<tr>		
		<td valign=top >
			<b>Container :</b><br>
			<select name="ContainerId">
			<?php
				
				$squery = "SELECT * FROM Containers WHERE EndTime>'$current_european_date'";
				$containers = main_db_query($squery);
				while($container = db_fetch_array($containers))
				{
					if ($container[Name]==$tabCorrespondanceContainers[$CONTAINER])
					{
						echo "<option value=$container[Id] selected>".$container[Name];
					}
					else
					{
						echo "<option value=$container[Id]>".$container[Name];
					}
				}
			?>
			</select>
			
		</td>
		
		<td valign=top >
			<b>Categorie :</b><br>
			<?php
			if(preg_match ( "#CHAMPIONNAT D'(.*)#" , $CONTAINER,$trouve ))
			{
				$CATEGORIE = ucfirst(strtolower($trouve[1]))." - ".$CATEGORIE;	
			}
			elseif(preg_match ( "#CHAMPIONNAT DE (.*)#" , $CONTAINER,$trouve ))
			{
				$CATEGORIE = ucfirst(strtolower($trouve[1]))." - ".$CATEGORIE;	
			}
			elseif(preg_match ( "#CHAMPIONNAT DU (.*)#" , $CONTAINER,$trouve ))
			{
				$CATEGORIE = ucfirst(strtolower($trouve[1]))." - ".$CATEGORIE;	
			}
			elseif(preg_match ( "#CHAMPIONNAT DES (.*)#" , $CONTAINER,$trouve ))
			{
				$CATEGORIE = ucfirst(strtolower($trouve[1]))." - ".$CATEGORIE;	
			}
			elseif(preg_match ( "#LIGUE 1#" , $CONTAINER,$trouve ))
			{
				$CATEGORIE = "Ligue 1 - ".$CATEGORIE;	
			}
			elseif(preg_match ( "#LIGUE 2#" , $CONTAINER,$trouve ))
			{
				$CATEGORIE = "Ligue 2 - ".$CATEGORIE;	
			}
			?>			
			<input type="text" name="Name" value="<?php echo $CATEGORIE ?>" size=30>
			<br>
			Showtime : <input type="text" name="ShowTime" value="<?php echo $SHOWTIME ?>" size=20>
			<br>
			Endtime : <input type="text" name="EndTime" value="<?php echo $ENDTIME ?>" size=20>
		
		</td>
		
		<td valign=top >
			<b>Image :</b><br>
			<select name="Image">
			<?php
				# contenu du répertoire
				$iconesDir = "IconesCategories/";
				$fichiers = dir($GAME_DIR."Images/".$iconesDir);				
				$i=0;
				while ($fichier=$fichiers->read())
				{
					if ($fichier!="." && $fichier!="..")
					{
						$liste[$i]=$fichier;
						$i++;
					}
				}
				$imax=$i;
				sort($liste);
				$found = 0;
				for ($i=0;$i<$imax;$i++)
				{
					echo "<option value=".$iconesDir.$liste[$i];
					if (($iconesDir.$liste[$i])==$Image)
					{
						echo " selected";
						$found = 1;
					}
					echo ">".$iconesDir.$liste[$i];
					echo "</option>";
				}
			?>
			</select>
			<?php
			if($found == 0)
				echo "&nbsp;<font color=#FF0000><b>!!</b></font>";
			?>
		</td>

	</tr>	
	<tr>
		<td colspan=3>
			<hr>
		</td>
	</tr>
	<tr>
		<td colspan=4 align=center>	
			
			<input type="hidden" name="nextJournee" size=2 value="<?php echo $nextJournee;?>">
			<input type="hidden" name="url" size=2 value="<?php echo $url;?>">
			<input type="hidden" name="Taux1" size=2 value="10">
			<input type="hidden" name="Taux2" size=2 value="2">
			<input type="hidden" name="Add" value="x">
			<input type="submit" name="valider" value="Valider la journée">
		</td>
	</tr>
</form>
</table>
<?php
}
?>
</body>
</html>