<?php

echo EDT_STATS1;
if ($nb_espedt>0) {
	echo '<p class="signal">'.EDT_STATS2.'</p> ';
}
$_SESSION['bctabs']='';
// récupération des divisions et groupes
$div = mysqli_query($bdd,"SELECT division FROM ".$prefix."_eleves WHERE categ = '1' GROUP BY division ORDER BY division ASC");
$groupes = mysqli_query($bdd,"SELECT groupe_nom FROM ".$prefix."_groupes");

// préparation des arrays
$tabAnnees = array();
$tabEtudeTotal = array();
$tabSeancesTotal = array();
$tabEtudeWeek = array();
$tabSeancesWeek = array();
$nb_weeks = array();

include('./db/proc/edt_stats_form_evol.php');
if(isset($_SESSION['nb_year'])) {
	$nbannees = substr($_SESSION['nb_year'],0,1);
}
else { $nbannees = 2; }

if($acadexist=="fnc") { $w1 = '07'; } 
else if($acadexist=="civ") { $w1 = '01'; } 
else { $w1 = '33'; }
if($acadexist=="fnc") { $w2 = "50"; } 
else if($acadexist=="civ") { $w2 = "52"; } 
else { $w2 = "27"; }

// Stats

//récupération des niveaux et couleurs par niveau
include('freq_stats_nivcolors.php'); 
include('edt_stats_arrays.php');
require_once('./include/basiccolors.php');

include('calweeknb.php');

echo '<h2>'.EDT_STATS3;
if(substr($_SESSION['nb_year'],1,1)=='p') {
	echo ($nbannees-1);
	$verifnb = ($nbannees-1);
}
else { echo $nbannees; $verifnb = $nbannees; }
echo YEARS.'</h2>';
if($no_annees==1||$verifnb!=count($tabAnnees)) {
	echo '<h3>'.NOSTATS1.'</h3>';
}
else {

	$bctab1 = '<table style="text-align:right;">
		<thead><tr><td colspan="5" style="text-align:center;">'.STATS_TIT1.'</td></tr><tr><th>'.YEAR.'</th><th>'.PERM.'</th><th>'.PERM.' '.PERWEEK.'</th><th>'.SEAN.'</th><th>'.SEAN.' '.PERWEEK.'</th></tr></thead><tbody>';
	$w=0;
	foreach($tabAnnees as $eachyear) {
		$bctab1 .= '<tr><td>'.$eachyear.'</td><td>'.$tabEtudeTotal[$w].'</td><td>'.$tabEtudeWeek[$w].'</td><td>'.$tabSeancesTotal[$w].'</td><td>'.$tabSeancesWeek[$w].'</td></tr>';
		$w++;
	}
	$bctab1 .= '</tr></tbody></table>';
	?>
	</article><article id="artleft" class="edtsep">
	<div id="wrapper" class="statcadre">
	<canvas id="chart_nbperyearperetcl" class="charts" width="600" height="300"></canvas>
	</div>
	<script type="text/javascript">
	(async function() {
	    
	    Chart.register(ChartDataLabels);
	    const labels = <?php echo json_encode($tabAnnees); ?>;
	    const data = {
	      labels: labels,
	      datasets: [ 
	        {
	            label: "<?php echo PERM;?> ",
	            data: <?php echo json_encode($tabEtudeTotal); ?>,
	            backgroundColor: '<?php echo $basicColors[0]; ?>',
	            borderColor: '<?php echo $basicColors[0]; ?>',
	            borderWidth: 1
	        },
	        {
	            label: "<?php echo SEAN;?> ",
	            data: <?php echo json_encode($tabSeancesTotal); ?>,
	            backgroundColor: '<?php echo $basicColors[1]; ?>',
	            borderColor: '<?php echo $basicColors[1]; ?>',
	            borderWidth: 1
	        } ]
	    };
	new Chart(
	    document.getElementById('chart_nbperyearperetcl'),
	    {
	    type: 'bar',
	    data: data,
	    options: {
	        plugins: {
	            title: {
	                display: true,
	                text: "<?php echo STATS_TIT1;?>"
	            },
	            legend: {
	    			display:false
	    		},
	            tooltip : {
	                mode: 'point',
	                intersect: false,
	              }  ,    
	            datalabels: {
	              display: true, // Affiche les étiquettes de données
	              color: '#878787', // Couleur du texte
	              align: 'center', // Alignement horizontal
	              anchor: 'center', // Alignement vertical
	              font: {
	                weight: 'bold', // Style de police
	              },
	              display: function(context) {
	                  return context.dataset.data[context.dataIndex] !== 0; // N'affiche pas si la valeur est égale à 0
	                },
	            },
	        },
	        responsive: true,
	        scales: {
	            yAxes: [{
	                ticks: {
	                    beginAtZero:true
	                }
	            }]
	        },
	      }
	    }
	);
	})();
	</script>
	
	<div id="wrapper" class="statcadre">
	<canvas id="chart_nbperyearperetclmo" class="charts" width="600" height="300"></canvas>
	</div>
	<script type="text/javascript">
	(async function() {
	    
	    Chart.register(ChartDataLabels);
	    const labels = <?php echo json_encode($tabAnnees); ?>;
	    const data = {
	      labels: labels,
	      datasets: [ 
	        {
	            label: "<?php echo PERM;?>",
	            data: <?php echo json_encode($tabEtudeWeek); ?>,
	            backgroundColor: '<?php echo $basicColors[0]; ?>',
	            borderColor: '<?php echo $basicColors[0]; ?>',
	            borderWidth: 1
	        },
	        {
	            label: "<?php echo SEAN;?>",
	            data: <?php echo json_encode($tabSeancesWeek); ?>,
	            backgroundColor: '<?php echo $basicColors[1]; ?>',
	            borderColor: '<?php echo $basicColors[1]; ?>',
	            borderWidth: 1
	        } ]
	    };
	new Chart(
	    document.getElementById('chart_nbperyearperetclmo'),
	    {
	    type: 'bar',
	    data: data,
	    options: {
	        plugins: {
	            title: {
	                display: true,
	                text: "<?php echo STATS_TIT2;?>"
	            },
	            legend: {
	    			display:false
	    		},
	            tooltip : {
	                mode: 'point',
	                intersect: false,
	              }  ,    
	            datalabels: {
	              display: true, // Affiche les étiquettes de données
	              color: '#878787', // Couleur du texte
	              align: 'center', // Alignement horizontal
	              anchor: 'center', // Alignement vertical
	              font: {
	                weight: 'bold', // Style de police
	              },
	              display: function(context) {
	                  return context.dataset.data[context.dataIndex] !== 0; // N'affiche pas si la valeur est égale à 0
	                },
	            },
	        },
	        responsive: true,
	        scales: {
	            yAxes: [{
	                ticks: {
	                    beginAtZero:true
	                }
	            }]
	        },
	      }
	    }
	);
	})();
	</script>

	<?php
	echo '<br> <br>'.$bctab1;
	$_SESSION['bctabs'] .= '<table></table>'.$bctab1;

	//séances par niveau par an :
	if(substr($_SESSION['nb_year'],1,1)=='a') { $nb_sans=0; } else { $nb_sans=1; }
	if($acadexist=="fnc"||$acadexist=="civ") {
		$_POST['fullyear'] = substr($day1,0,4);
	}
	else {
		$_POST['fullyear'] = (substr($day1,0,4)).(substr($day1,0,4)+1);
	}
	for($i=$nbannees;$i>$nb_sans;$i--) {
		$tabCodesSeq = array();
		$tabCodesSeqColors = array();
		if(substr($_SESSION['nb_year'],1,1)=='p'&&$i==1) { }
		else {
			if($i!=$nbannees) {
				if($acadexist=="fnc"||$acadexist=="civ") {
					$_POST['fullyear'] = ($_POST['fullyear']+1);
					$anneesco = $_POST['fullyear'];					
				}
				else {
					$_POST['fullyear'] = (substr($_POST['fullyear'],0,4)+1).(substr($_POST['fullyear'],0,4)+2);
					$anneesco = substr($_POST['fullyear'],0,4).'/'.substr($_POST['fullyear'],4,4);				
				}
			}
			if($acadexist=="fnc"||$acadexist=="civ") {
				$an2 = substr($anneesco,0,4);
			}
			else {
				$an2 = substr($anneesco,5,4);
			}
			$tabSeqperniv[$i] = array();
			$tabSeqpernivMoy[$i] = array();
			$nbseances_niv = mysqli_query($bdd,"SELECT event.uid, event.duration FROM ".$prefix."_edtevent event INNER JOIN ".$prefix."_edtbrik brik ON event.brik_id = brik.brik_id INNER JOIN ".$prefix."_userevent uevent ON event.uid = uevent.uid INNER JOIN ".$prefix."_espaces_event espevent ON event.uid = espevent.uid WHERE brik.seance = 1 AND brik.division <> '' AND event.week >= '".substr($anneesco,0,4).$w1."' AND event.week <= '".$an2.$w2."' AND uevent.user_id=0 AND espevent.espace_id ='0'");
			$nbseances = 0;
			foreach ($nbseances_niv as $eventdiv) {
				if($eventdiv['duration']==5) { $duree = 0.5; }
				else { $duree = substr($eventdiv['duration'],0,1).'.'.substr($eventdiv['duration'],1,1); }
				$nbseances += $duree;
			}
			array_push($tabSeqperniv[$i], $nbseances);
			array_push($tabSeqpernivMoy[$i], round(($nbseances/$nb_weeks[$i-1-$nb_sans]),1));
			foreach ($tabDebniveau as $divdeb) {
				$nivcolor = mysqli_query($bdd,"SELECT bgcolor FROM ".$prefix."_edtnivcolor WHERE niveau = '".$divdeb."'");
				$nivcolor_info = mysqli_fetch_assoc($nivcolor);
				$tabColor[$i] = $nivcolor_info['bgcolor'];
				if($acadexist=="fnc"||$acadexist=="civ") {
					$anneesco = $_POST['fullyear'];
				}
				else {
					$anneesco = substr($_POST['fullyear'],0,4).'/'.substr($_POST['fullyear'],4,4);
				}
				$nbseances_niv = mysqli_query($bdd,"SELECT event.uid, event.duration FROM ".$prefix."_edtevent event INNER JOIN ".$prefix."_edtbrik brik ON event.brik_id = brik.brik_id INNER JOIN ".$prefix."_userevent uevent ON event.uid = uevent.uid INNER JOIN ".$prefix."_espaces_event espevent ON event.uid = espevent.uid WHERE brik.seance = 1 AND event.week >= '".substr($anneesco,0,4).$w1."' AND event.week <= '".$an2.$w2."' AND brik.division LIKE '".$divdeb."%' AND uevent.user_id=0 AND espevent.espace_id ='0'");
				$nbseances = 0;
				foreach ($nbseances_niv as $eventdiv) {
					if($eventdiv['duration']==5) { $duree = 0.5; }
					else { $duree = substr($eventdiv['duration'],0,1).'.'.substr($eventdiv['duration'],1,1); }
					$nbseances += $duree;
				}
				array_push($tabSeqperniv[$i], $nbseances);
				array_push($tabSeqpernivMoy[$i], round(($nbseances/$nb_weeks[$i-1-$nb_sans]),1));
			}
			$tabNbPerDiv[$i] = array();
			$liste_division = mysqli_query($bdd,"SELECT division FROM ".$prefix."_freq GROUP BY division ORDER BY division ASC");
			foreach($liste_division as $listediv) {
				if($listediv['division']!="") {
					$nbseances_niv = mysqli_query($bdd,"SELECT event.uid, event.duration FROM ".$prefix."_edtevent event INNER JOIN ".$prefix."_edtbrik brik ON event.brik_id = brik.brik_id INNER JOIN ".$prefix."_userevent uevent ON event.uid = uevent.uid INNER JOIN ".$prefix."_espaces_event espevent ON event.uid = espevent.uid WHERE brik.seance = 1 AND event.week >= '".substr($anneesco,0,4).$w1."' AND event.week <= '".$an2.$w2."' AND brik.division = '".$listediv['division']."' AND uevent.user_id=0 AND espevent.espace_id ='0'");
					$nbseances = 0;
					foreach ($nbseances_niv as $eventdiv) {
						if($eventdiv['duration']==5) { $duree = 0.5; }
						else { $duree = substr($eventdiv['duration'],0,1).'.'.substr($eventdiv['duration'],1,1); }
						$nbseances += $duree;
					}
					array_push($tabNbPerDiv[$i], $nbseances);
				}
			}
			$tabNbPerDom[$i] = array();
			$liste_codes = mysqli_query($bdd,"SELECT brik.code, edtcode.code_id, edtcode.bgcolor_code FROM ".$prefix."_edtbrik brik INNER JOIN ".$prefix."_edtcode edtcode ON brik.code = edtcode.code INNER JOIN ".$prefix."_edtevent event ON event.brik_id = brik.brik_id WHERE event.week >= '".substr($tabAnnees[(count($tabAnnees)-1)],0,4).$w1."' GROUP BY brik.code ORDER BY edtcode.code_id ASC");
			foreach($liste_codes as $code) {
				$nbseances_niv = mysqli_query($bdd,"SELECT event.uid, event.duration FROM ".$prefix."_edtevent event INNER JOIN ".$prefix."_edtbrik brik ON event.brik_id = brik.brik_id INNER JOIN ".$prefix."_userevent uevent ON event.uid = uevent.uid INNER JOIN ".$prefix."_espaces_event espevent ON event.uid = espevent.uid WHERE event.week >= '".substr($anneesco,0,4).$w1."' AND event.week <= '".$an2.$w2."' AND brik.code = '".$code['code']."' AND uevent.user_id=0 AND espevent.espace_id ='0'");
				$nbseances = 0;
				foreach ($nbseances_niv as $eventdiv) {
					if($eventdiv['duration']==5) { $duree = 0.5; }
					else { $duree = substr($eventdiv['duration'],0,1).'.'.substr($eventdiv['duration'],1,1); }
					$nbseances += $duree;
				}
				$tabCodesSeq[]=$code['code'];
				$tabCodesSeqColors[]=$code['bgcolor_code'];
				array_push($tabNbPerDom[$i], $nbseances);
			}		
		}
	}
	$bctab2 = '<table style="text-align:right;">
	<thead><tr><td colspan="11" style="text-align:center;">'.STATS_TIT3.'</td></tr><tr><th>'.YEAR.'</th><th>'.TOTAL.'</th><th>'.TOTAL.' '.PERWEEK.'</th>';
	$nivi=0;
	foreach($tabDebniveau as $divdeb) {
		$bctab2 .= '<th>'.$tabNiveau[$nivi].'</th><th>'.$tabNiveau[$nivi].' '.PERWEEK.'</th>';
		$nivi++;
	}
	$bctab2 .= '</tr></thead><tbody>';
	$w=$nbannees;
	foreach(array_reverse($tabAnnees) as $eachyear) {
		$bctab2 .= '<tr><td>'.$eachyear.'</td>
		<td>'.$tabSeqperniv[$w][0].'</td><td>'.number_format((float)$tabSeqpernivMoy[$w][0],2,'.','').'</td>';
		$m=1;
		foreach($tabDebniveau as $divdeb) {
			$bctab2 .= '<td>'.$tabSeqperniv[$w][$m].'</td><td>'.number_format((float)$tabSeqpernivMoy[$w][$m],2,'.','').'</td>';
			$m++;
		}
		$w--;
	}	
	$bctab2 .= '</tbody></table>';
	$bctab3 = '<table style="text-align:right;">
	<thead><tr><td colspan="11" style="text-align:center;">'.STATS_TIT4.'</td></tr><tr><th>'.YEAR.'</th>';
	$nivi=0;
	foreach($liste_division as $listediv) {
		$bctab3 .= '<td>'.$listediv['division'].'</td>';
		$nivi++;
	}
	$bctab3 .= '</tr></thead><tbody>';
	$w=$nbannees;
	foreach(array_reverse($tabAnnees) as $eachyear) {
		$bctab3 .= '<tr><td>'.$eachyear.'</td>';
		$m=0;
		foreach($liste_division as $listediv) {
			$bctab3 .= '<td>'.$tabNbPerDiv[$w][$m].'</td>';
			$m++;
		}
		$w--;
	}	
	$bctab3 .= '</tbody></table>';
	$bctab4 = '<table style="text-align:right;">
	<thead><tr><td colspan="11" style="text-align:center;">'.STATS_TIT5.'</td></tr><tr><th>'.YEAR.'</th>';
	$nivi=0;
foreach($liste_codes as $code) {
		$bctab4 .= '<td>'.$code['code'].'</td>';
		$nivi++;
	}
	$bctab4 .= '</tr></thead><tbody>';
	$w=$nbannees;
	foreach(array_reverse($tabAnnees) as $eachyear) {
		$bctab4 .= '<tr><td>'.$eachyear.'</td>';
		$m=0;
		foreach($liste_codes as $code) {
			$bctab4 .= '<td>'.$tabNbPerDom[$w][$m].'</td>';
			$m++;
		}
		$w--;
	}	
	$bctab4 .= '</tbody></table>';
	echo '<br>&nbsp;<br>';
	?>
	<div id="wrapper" class="statcadre">
	<canvas id="chart_nbsperanperniv" class="charts" width="600" height="300"></canvas>
	</div>
	<script type="text/javascript">
	(async function() {
	    
	    Chart.register(ChartDataLabels);
	    const labels = <?php echo json_encode($taballNiveau); ?>;
	    const data = {
	      labels: labels,
	      datasets: [ 
	        <?php $j=1;
	        if(substr($_SESSION['nb_year'],1,1)=='p') { $j=2; }
	        for($i=$nbannees;$i>$nb_sans;$i--) { ?>
				{
					label: <?php echo json_encode($tabAnnees[$i-1-$nb_sans]); ?>,
					data: <?php echo json_encode($tabSeqperniv[$i]); ?>,
					backgroundColor: <?php echo json_encode($tabBgallcolor); ?>,
					borderColor: <?php echo json_encode($tabBgallcolor); ?>,
					borderWidth: 1
				} <?php if($j<=$nbannees) { echo ','; } $j++;} ?> ]
	    };
	new Chart(
	    document.getElementById('chart_nbsperanperniv'),
	    {
	    type: 'bar',
	    data: data,
	    options: {
	        plugins: {
	            title: {
	                display: true,
	                text: '<?php echo STATS_TIT6; ?> (<?php $j=1; if(substr($_SESSION['nb_year'],1,1)=='p') { $j=2; } for($i=$nbannees;$i>$nb_sans;$i--) { echo $tabAnnees[$i-1-$nb_sans]; if($j<$nbannees) { echo ' - '; } $j++; } ?>)'
	            },
	            legend: {
	    			display:false
	    		},
	            tooltip : {
	                mode: 'point',
	                intersect: false,
	              }  ,    
	            datalabels: {
	              display: true, // Affiche les étiquettes de données
	              color: function(context) {
			        var index = context.dataIndex;
			        var color = '#878787'; // Couleur par défaut

			        // Condition pour déterminer la couleur en fonction de l'index ou d'autres critères
			        if (index === 0) {
			            color = '#fff';
			        } 
			        return color; // Retourne la couleur déterminée
			    },
	              align: 'center', // Alignement horizontal
	              anchor: 'center', // Alignement vertical
	              font: {
	                weight: 'bold', // Style de police
	              },
	              display: function(context) {
	                  return context.dataset.data[context.dataIndex] !== 0; // N'affiche pas si la valeur est égale à 0
	                },
	            },
	        },
	        responsive: true,
	        scales: {
	            yAxes: [{
	                ticks: {
	                    beginAtZero:true
	                }
	            }]
	        },
	      }
	    }
	);
	})();
	</script>

	<div id="wrapper" class="statcadre">
	<canvas id="chart_moysperanperniv" class="charts" width="600" height="300"></canvas>
	</div>
	<script type="text/javascript">
	(async function() {
	    
	    Chart.register(ChartDataLabels);
	    const labels = <?php echo json_encode($taballNiveau); ?>;
	    const data = {
	      labels: labels,
	      datasets: [ 
	        <?php $j=1;
	        if(substr($_SESSION['nb_year'],1,1)=='p') { $j=2; }
	        for($i=$nbannees;$i>$nb_sans;$i--) { ?>
				{
					label: <?php echo json_encode($tabAnnees[$i-1-$nb_sans]); ?>,
					data: <?php echo json_encode($tabSeqpernivMoy[$i]); ?>,
					backgroundColor: <?php echo json_encode($tabBgallcolor); ?>,
					borderColor: <?php echo json_encode($tabBgallcolor); ?>,
					borderWidth: 1
				} <?php if($j<=$nbannees) { echo ','; } $j++;} ?> ]
	    };
	new Chart(
	    document.getElementById('chart_moysperanperniv'),
	    {
	    type: 'bar',
	    data: data,
	    options: {
	        plugins: {
	            title: {
	                display: true,
	                text: '<?php echo STATS_TIT7;?> (<?php $j=1; if(substr($_SESSION['nb_year'],1,1)=='p') { $j=2; } for($i=$nbannees;$i>$nb_sans;$i--) { echo $tabAnnees[$i-1-$nb_sans]; if($j<$nbannees) { echo ' - '; } $j++; } ?>)'
	            },
	            legend: {
	    			display:false
	    		},
	            tooltip : {
	                mode: 'point',
	                intersect: false,
	              }  ,    
	            datalabels: {
	              display: true, // Affiche les étiquettes de données
	              color: function(context) {
			        var index = context.dataIndex;
			        var color = '#878787'; // Couleur par défaut

			        // Condition pour déterminer la couleur en fonction de l'index ou d'autres critères
			        if (index === 0) {
			            color = '#fff';
			        } 
			        return color; // Retourne la couleur déterminée
			    },
	              align: 'center', // Alignement horizontal
	              anchor: 'center', // Alignement vertical
	              font: {
	                weight: 'bold', // Style de police
	              },
	              display: function(context) {
	                  return context.dataset.data[context.dataIndex] !== 0; // N'affiche pas si la valeur est égale à 0
	                },
	            },
	        },
	        responsive: true,
	        scales: {
	            yAxes: [{
	                ticks: {
	                    beginAtZero:true
	                }
	            }]
	        },
	      }
	    }
	);
	})();
	</script>
	<?php
	echo '<br> <br>'.$bctab2;
	$_SESSION['bctabs'] .= '<table></table>'.$bctab2;
	?>
	<div id="wrapper" class="statcadre">
	<canvas id="chart_nbperyearperdiv" class="charts" width="600" height="300"></canvas>
	</div>
	<script type="text/javascript">
	(async function() {
	    
	    Chart.register(ChartDataLabels);
	    const labels = <?php echo json_encode($tabDivisionsFreq); ?>;
	    const data = {
	      labels: labels,
	      datasets: [
			<?php $j=1;
			if(substr($_SESSION['nb_year'],1,1)=='p') { $j=2; }
			for($i=$nbannees;$i>$nb_sans;$i--) { ?>
			{
				label: <?php echo json_encode($tabAnnees[$i-1-$nb_sans]); ?>,
				data: <?php echo json_encode($tabNbPerDiv[$i]); ?>,
				backgroundColor: <?php echo json_encode($tabDivColorsFreq); ?>,
				borderColor: <?php echo json_encode($tabDivColorsFreq); ?>,
				borderWidth: 1
			} <?php if($j<=$nbannees) { echo ','; } $j++;} ?> ]
	    };
	new Chart(
	    document.getElementById('chart_nbperyearperdiv'),
	    {
	    type: 'bar',
	    data: data,
	    options: {
	        plugins: {
	            title: {
	                display: true,
	                text: '<?php echo STATS_TIT4;?> (<?php $j=1; if(substr($_SESSION['nb_year'],1,1)=='p') { $j=2; } for($i=$nbannees;$i>$nb_sans;$i--) { echo $tabAnnees[$i-1-$nb_sans]; if($j<$nbannees) { echo ' - '; } $j++; } ?>)'
	            },
	            legend: {
	    			display:false
	    		},
	            tooltip : {
	                mode: 'point',
	                intersect: false,
	              }  ,    
	            datalabels: {
	              display: true, // Affiche les étiquettes de données
	              color: '#878787', // Couleur du texte
	              align: 'center', // Alignement horizontal
	              anchor: 'center', // Alignement vertical
	              font: {
	                weight: 'bold', // Style de police
	              },
	              display: function(context) {
	                  return context.dataset.data[context.dataIndex] !== 0; // N'affiche pas si la valeur est égale à 0
	                },
	            },
	        },
	        responsive: true,
	        scales: {
	            yAxes: [{
	                ticks: {
	                    beginAtZero:true
	                }
	            }]
	        },
	      }
	    }
	);
	})();
	</script>
	<?php
	echo '<br> <br>'.$bctab3;
	$_SESSION['bctabs'] .= '<table></table>'.$bctab3;
	?>
	<div id="wrapper" class="statcadre">
	<canvas id="chart_nbperyearperdom" class="charts" width="600" height="300"></canvas>
	</div>
	<script type="text/javascript">
	(async function() {
	    
	    Chart.register(ChartDataLabels);
	    const labels = <?php echo json_encode($tabCodesSeq); ?>;
	    const data = {
	      labels: labels,
	      datasets: [
			<?php $j=1;
			if(substr($_SESSION['nb_year'],1,1)=='p') { $j=2; }
			for($i=$nbannees;$i>$nb_sans;$i--) { ?>
			{
				label: <?php echo json_encode($tabAnnees[$i-1-$nb_sans]); ?>,
				data: <?php echo json_encode($tabNbPerDom[$i]); ?>,
				backgroundColor: <?php echo json_encode($tabCodesSeqColors); ?>,
				borderColor: <?php echo json_encode($tabCodesSeqColors); ?>,
				borderWidth: 1
			} <?php if($j<=$nbannees) { echo ','; } $j++;} ?> ]
	    };
	new Chart(
	    document.getElementById('chart_nbperyearperdom'),
	    {
	    type: 'bar',
	    data: data,
	    options: {
	        plugins: {
	            title: {
	                display: true,
	                text: '<?php echo STATS_TIT5;?> (<?php $j=1; if(substr($_SESSION['nb_year'],1,1)=='p') { $j=2; } for($i=$nbannees;$i>$nb_sans;$i--) { echo $tabAnnees[$i-1-$nb_sans]; if($j<$nbannees) { echo ' - '; } $j++; } ?>)'
	            },
	            legend: {
	    			display:false
	    		},
	            tooltip : {
	                mode: 'point',
	                intersect: false,
	              }  ,    
	            datalabels: {
	              display: true, // Affiche les étiquettes de données
	              color: '#878787', // Couleur du texte
	              align: 'center', // Alignement horizontal
	              anchor: 'center', // Alignement vertical
	              font: {
	                weight: 'bold', // Style de police
	              },
	              display: function(context) {
	                  return context.dataset.data[context.dataIndex] !== 0; // N'affiche pas si la valeur est égale à 0
	                },
	            },
	        },
	        responsive: true,
	        scales: {
	            yAxes: [{
	                ticks: {
	                    beginAtZero:true
	                }
	            }]
	        },
	      }
	    }
	);
	})();
	</script>
<?php 
	echo '<br> <br>'.$bctab4;
	$_SESSION['bctabs'] .= '<table></table>'.$bctab4;
} 
echo '<br> <a onclick="submitods();" id="preview-ods"><i class="fa-solid fa-file-export" style="font-size:1.5em;"></i> '.STATS_DL1.'</a>';
if(isset($_POST['haveods'])) {
	include('stats_ods_loader.php');
}
echo '<form id="loadods" action="db/proc/stats/stats_ods_loader.php" method="post"><input type="hidden" name="haveods" value="1" /></form>';

echo '<script type="text/javascript">
function submitods(){
	$("#loadods").submit()
}
</script>';
?>