Retourner à la liste des tutos

Partie statistique NEB Luka


Page /statistique.php

HTML
<!DOCTYPE html>
<?php
$root = realpath($_SERVER["DOCUMENT_ROOT"]);
include("$root/includes/login_include.php");
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="description" content="Statistiques" />
    <meta name="keywords" content="ecole, lycee, serveur, donnees, neb, notation, course, natation, eleves" />
    <title>Statistiques</title>
    <link rel="stylesheet" href="/styles/style.css" />
    <link rel="icon" type="png" href="images/sys/favicon.ico" />
    <style>
    #menu .menuStatistiquesBTN
    {
    border-bottom: 2px solid rgb(206, 173, 0);
    }
    </style>

</head>

<body>

<div id="topBar"> <!--=========== Bar de menu en haut =========-->

    <img src="/images/sys/logos/nebLogo1_B_original.png" alt="logo NEB" class="topBarLogoImg"/> <!-- logo en haut a gauche de la topBar -->

    <?php
    session_start();
    $root = realpath($_SERVER["DOCUMENT_ROOT"]);
    include("$root/includes/nav.php");
    ?>
</div> <!-- FIN (topBar) -->
<div id="leftBar">
                <BR /><BR />
                <img src="images/sys/statistiques2.png" style="max-width: 180px;">

    </div>
<br /><br /><br /><br /><br /><br />
<div id="block">
    <a href="/index.php" id="boutonNormal">Retour</a><br /><br />

    <div id="blockFiltreStatistiques">
<form method='post' action='go/statistiques.php'>
<span class='cadrePourFiltreStatistiques'>
Section
<INPUT type="checkbox" name="sectionCb" value="1">

<SELECT name="sectionLst">
<OPTION value='0'>Tle
<OPTION value='1'>1ère
<OPTION value='2'>2ndes
<OPTION value='3'>3°
<OPTION value='4'>4°
<OPTION value='5'>5°
<OPTION value='6'>6°
</SELECT>
</span>
<span class='cadrePourFiltreStatistiques'>
Classe
<INPUT type="checkbox" name="classeCb" value="1">
<SELECT name="classeLst">
<?php
$classes=[]; // classe est un tableau (on le voit grace aux crochets)

include("$root/includes/bddConnect.php");
$requette=$bdd->query("SELECT * FROM eleves WHERE 1");
while($val=$requette->fetch())  //tant qu on a encore des élèves à traiter
{
if(!(in_array($val[4], $classes)))
{
array_push($classes, $val[4]);

}
}
array_multisort($classes, SORT_STRING | SORT_NUMERIC);
foreach($classes as &$classe)
{
echo "<option value='$classe'>".str_replace('0', '', $classe);
}
?>
</SELECT>
</span>
<span class='cadrePourFiltreStatistiques'>
Sexe
<INPUT type="checkbox" name="sexeCb" value="1">
<SELECT name="sexeLst">
<OPTION value='1'>Fille
<OPTION value='0'>Garçon
<option value='2'>Les deux
</SELECT>
</span>
<input type="submit" value="valider"/>
</form>
</div>
    <br />
    <div id="blockPourImgStatistiques">
        <img src="images/sys/statistiques.png">
    </div>
</div>
</body>
<?php
$root = realpath($_SERVER["DOCUMENT_ROOT"]);
include("$root/includes/footer.php");
?>
</html>


Page /go/statistiques.php

PHP
<?php
$root = realpath($_SERVER["DOCUMENT_ROOT"]);
include("$root/includes/login_include.php");
?>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <meta name="description" content="Statistiques" />
        <meta name="keywords" content="ecole, lycee, serveur, donnees, neb, notation, course, natation, eleves" />
        <title>Statistiques</title>
        <link rel="stylesheet" href="/styles/style.css" />
        <link rel="icon" type="png" href="images/sys/favicon.ico" />
        <style>
            #menu .menuStatistiquesBTN
            {
                border-bottom: 2px solid rgb(206, 173, 0);
            }
        </style>


    </head>

    <body>




    <div id="topBar"> <!--=========== Bar de menu en haut =========-->

            <img src="/images/sys/logos/nebLogo1_B_original.png" alt="logo NEB" class="topBarLogoImg"/> <!-- logo en haut a gauche de la topBar -->

        <?php
            $root = realpath($_SERVER["DOCUMENT_ROOT"]);
            include("$root/includes/nav.php");
        ?>
        </div> <!-- FIN (topBar) -->
        <div id="leftBar">
        <BR /><BR />
            <img src="/images/sys/statistiques2.png" style="max-width: 180px;">


        </div>
        <br /><br /><br /><br /><br /><br />
        <div id="block">
            <a href="/statistiques.php" id="boutonNormal">Retour</a><br /><br />

            <?php
$checkSection=htmlspecialchars($_POST['sectionCb']);
$checkClasse=htmlspecialchars($_POST['classeCb']);
$checkSexe=htmlspecialchars($_POST['sexeCb']);

$lstSection=htmlspecialchars($_POST['sectionLst']);
$lstClasse=htmlspecialchars($_POST['classeLst']);
$lstSexe=htmlspecialchars($_POST['sexeLst']);

            // ======= mise en mémoire de la section selectionee ========
            if($lstSection == "0"){
                $section = "Terminales";
            }elseif($lstSection == "1"){
                $section=  "Premières";
            }elseif($lstSection == "2"){
                $section=  "Secondes";
            }elseif($lstSection == "3"){
                $section=  "Troisièmes";
            }elseif($lstSection == "4"){
                $section=  "Quatrièmes";
            }elseif($lstSection == "5"){
                $section=  "Cinquièmes";
            }elseif($lstSection == "6"){
                $section=  "Sixièmes";
            }

            // ======= mise en mémoire du sexe selectione ========
            if($lstSexe == "0"){
                $sexe = "masculin";
            }elseif($lstSexe == "1"){
                $sexe = "féminin";
            }else{
                $sexe = "Mixtes";
            }

$notes=[];

if($checkSection == "1" and $checkClasse == "1"){ // ===== si CLASSE et SECTION selectionnés cela est problematique =====
echo "<br /><br /><br /><div id='erreur'>Vous ne pouvez pas choisir le filtre 'Section' et 'Classe' en même temps</div>"; // ===== box erreur ======
}else{
                include("$root/includes/bddConnect.php"); // ===== importation de la page de connexion a la BDD =========



                                // ========== si SECTION seule est selectionée ================
                if(($checkSection == "1" and $checkClasse != "1" and $checkSexe != "1") or ($checkSection == "1" and $checkClasse != "1" and $checkSexe == "1" and $lstSexe == "2"))
                {
                echo "<h2>Statistiques sur la section ".$section."</h2>";

                         $requette=$bdd->query("SELECT id_eleve, note FROM notes WHERE TRUE");
                     while($val=$requette->fetch()) // W1
                     {
                                    $idDeEleve = $val['0'];

                                    $requetteInterne=$bdd->query("SELECT classe FROM eleves WHERE id='$idDeEleve'");
                     while($valInterne=$requetteInterne->fetch()){ // W2

                     if($valInterne['0'][0] == $lstSection)
                     {
                     array_push($notes, $val['1']);
                     }
                     } // fin W2 --- (fin while du fetch interne)
                     } // fin W1 --- (fin while du fetch)

                } // (fin if section seule)


                                // =============== si SECTION + SEXE selectionnés ==============
                                elseif($checkSection == "1" and $checkClasse != "1" and $checkSexe == "1")
                                {
                                    echo "<h2>Statistiques sur la section ".$section." de sexe ".$sexe."</h2>";

                                        $requette=$bdd->query("SELECT id_eleve, note FROM notes WHERE TRUE"); // ===== on recupere l'Id de l'élève et sa note (pour toutes les notes de la base) =====
                                        while($val=$requette->fetch()) // W1
                                        {
                                                    $idDeEleve = $val['0'];

                                                    $requetteInterne=$bdd->query("SELECT * FROM eleves WHERE id='$idDeEleve'");
                                                    while($valInterne=$requetteInterne->fetch()){ // W2
                                                        // echo "[ ".$valInterne['0'][0]." ]";
                                                        if($valInterne['4'][0] == $lstSection and $valInterne['3'] == $lstSexe)
                                                        {
                                                                    array_push($notes, $val['1']);
                                                        }
                                                    } // fin W2 --- (fin while du fetch interne)
                                        } // fin W1 --- (fin while du fetch)

                                } // (fin if section + sexe)

                                // ========== si CLASSE seule est selectionée ================
                                elseif(($checkSection != "1" and $checkClasse == "1" and $checkSexe != "1") or ($checkSection != "1" and $checkClasse == "1" and $checkSexe == "1" and $lstSexe == "2"))
                                {
                                    echo "<h2>Statistiques sur la classe de ".str_replace("0T", "T",$lstClasse).".</h2>";

                                    $requette=$bdd->query("SELECT id_eleve, note FROM notes WHERE TRUE");
                                    while($val=$requette->fetch()) // W1
                                    {
                                        $idDeEleve = $val['0'];

                                        $requetteInterne=$bdd->query("SELECT classe FROM eleves WHERE id='$idDeEleve'");
                                        while($valInterne=$requetteInterne->fetch()){ // W2

                                            if($valInterne['0'] == $lstClasse)
                                            {
                                                array_push($notes, $val['1']);
                                            }
                                        } // fin W2 --- (fin while du fetch interne)
                                    } // fin W1 --- (fin while du fetch)

                                } // (fin if CLASSE seule)

                                // =============== si CLASSE + SEXE selectionnés ==============
                                elseif($checkSection != "1" and $checkClasse == "1" and $checkSexe == "1")
                                {
                                    echo "<h2>Statistiques sur la classe de ".str_replace("0T", "T",$lstClasse)." de sexe ".$sexe."</h2>";

                                    $requette=$bdd->query("SELECT id_eleve, note FROM notes WHERE TRUE"); // ===== on recupere l'Id de l'élève et sa note (pour toutes les notes de la base) =====
                                    while($val=$requette->fetch()) // W1
                                    {
                                        $idDeEleve = $val['0'];

                                        $requetteInterne=$bdd->query("SELECT * FROM eleves WHERE id='$idDeEleve'");
                                        while($valInterne=$requetteInterne->fetch()){ // W2
                                            if($valInterne['4'] == $lstClasse and $valInterne['3'] == $lstSexe)
                                            {
                                                array_push($notes, $val['1']);
                                            }
                                        } // fin W2 --- (fin while du fetch interne)
                                    } // fin W1 --- (fin while du fetch)

                                } // (fin if classe + sexe)

                                // ========== si SEXE seule est selectionée ================
                                elseif($checkSection != "1" and $checkClasse != "1" and $checkSexe == "1")
                                {
                                    echo "<h2>Statistiques sur tous les élèves du collège et du lycée de sexe ".$sexe."</h2>";

                                    $requette=$bdd->query("SELECT id_eleve, note FROM notes WHERE TRUE");
                                    while($val=$requette->fetch()) // W1
                                    {
                                        $idDeEleve = $val['0'];

                                        $requetteInterne=$bdd->query("SELECT sex FROM eleves WHERE id='$idDeEleve'");
                                        while($valInterne=$requetteInterne->fetch()){ // W2

                                            if($valInterne['0'] == $lstSexe)
                                            {
                                                array_push($notes, $val['1']);
                                            }
                                        } // fin W2 --- (fin while du fetch interne)
                                    } // fin W1 --- (fin while du fetch)
                                    if($lstSexe == "2")
                                    {
                                        $requette=$bdd->query("SELECT note FROM notes WHERE TRUE");
                                        while($val=$requette->fetch())
                                        {
                                            array_push($notes, $val['0']);
                                        }
                                    }
                                } // (fin if CLASSE seule)

                echo "<table class='tableauStatistiques'>";
                echo "<tr><td style='background-color: rgb(200,100,100);'>Min</td><td>".round(min($notes),2)."</td></tr>";
                echo "<tr><td style='background-color: rgb(100,200,100);'>Max</td><td>".round(max($notes),2)."</td></tr>";
                echo "<tr><td style='background-color: rgb(200,200,100);'>Moyenne</td><td>".round(array_sum($notes)/count($notes),2)."</td></tr>";
                echo "</table>";
} // (fin if pas d'erreur de cochage)



?>

</div>


</body>
    <?php
    $root = realpath($_SERVER["DOCUMENT_ROOT"]);
    include("$root/includes/footer.php");
    ?>
</html>