<?php
  function showInscriptionsProgressTotals()
  {
    global $connexion;
    //https://www.amcharts.com/demos/stacked-clustered-column-chart/
    //https://bl.ocks.org/mbostock/3887051
    //https://www.zingchart.com/docs/chart-types/bar-charts/

    $html = '';

    $html .= '
    <script>
    var chart = AmCharts.makeChart("chartdiv", {
      "type": "serial",
      "theme": "light",
    "dataProvider": [ ';


    ### 08-09 #################################################
    $html .= '
    {"year": 2009,';

      // on va chercher tout les comptes ISO-Actif de l'IR
      $requete = 'SELECT * FROM t_liste_ecoles_08,t_usager_grille WHERE u_e_id_fk = ID ORDER BY NOM ASC';
      $resultat = $connexion->query($requete);

      // Find how many schools completed the form fot that season
      $nbEcolesIR = 0;
      while ($ligne = $resultat->fetch_assoc())
      {
        if ($ligne['u_g_prisec'] == 'P' && verifierSi4BlocsCompletsP0809($ligne['u_id']) == 'oui')
        {
          $nbEcolesIR ++;
        }
        else if ($ligne['u_g_prisec'] == 'S' && verifierSi4BlocsCompletsS0809($ligne['u_id']) == 'oui')
        {
          $nbEcolesIR ++;
        }
      } // End School's loop

      $html .= '"nbEcoles": ' . $nbEcolesIR;

    $html .= '}, ';
    ###########################################################


    ### 09-10 #################################################
    $html .= '
    {"year": 2010,';

      // on va chercher tout les comptes ISO-Actif de l'IR
      $requete = 'SELECT * FROM t_liste_ecoles_08,t_usager_grille WHERE u_e_id_fk = ID ORDER BY NOM ASC';
      $resultat = $connexion->query($requete);

      // Find how many schools completed the form fot that season
      $nbEcolesIR = 0;
      while ($ligne = $resultat->fetch_assoc())
      {
        if ($ligne['u_g_prisec'] == 'P' && verifierSi4BlocsCompletsP0910($ligne['u_id']) == 'oui')
        {
          $nbEcolesIR ++;
        }
        else if ($ligne['u_g_prisec'] == 'S' && verifierSi4BlocsCompletsS0910($ligne['u_id']) == 'oui')
        {
          $nbEcolesIR ++;
        }
      } // End School's loop

      $html .= '"nbEcoles": ' . $nbEcolesIR;

    $html .= '}, ';
    ###########################################################


    ### 10-11 #################################################
    $html .= '
    {"year": 2011,';

      // on va chercher tout les comptes ISO-Actif de l'IR
      $requete = 'SELECT * FROM t_liste_ecoles_08,t_usager_grille WHERE u_e_id_fk = ID ORDER BY NOM ASC';
      $resultat = $connexion->query($requete);

      // Find how many schools completed the form fot that season
      $nbEcolesIR = 0;
      while ($ligne = $resultat->fetch_assoc())
      {
        if ($ligne['u_g_prisec'] == 'P' && verifierSi4BlocsCompletsP1011($ligne['u_id']) == 'oui')
        {
          $nbEcolesIR ++;
        }
        else if ($ligne['u_g_prisec'] == 'S' && verifierSi4BlocsCompletsS1011($ligne['u_id']) == 'oui')
        {
          $nbEcolesIR ++;
        }
      } // End School's loop

      $html .= '"nbEcoles": ' . $nbEcolesIR;

    $html .= '}, ';
    ###########################################################


    ### 11-12 #################################################
    $html .= '
    {"year": 2012,';

      // on va chercher tout les comptes ISO-Actif de l'IR
      $requete = 'SELECT * FROM t_liste_ecoles_08,t_usager_grille WHERE u_e_id_fk = ID ORDER BY NOM ASC';
      $resultat = $connexion->query($requete);

      // Find how many schools completed the form fot that season
      $nbEcolesIR = 0;
      while ($ligne = $resultat->fetch_assoc())
      {
        if ($ligne['u_g_prisec'] == 'P' && verifierSi4BlocsCompletsP1112($ligne['u_id']) == 'oui')
        {
          $nbEcolesIR ++;
        }
        else if ($ligne['u_g_prisec'] == 'S' && verifierSi4BlocsCompletsS1112($ligne['u_id']) == 'oui')
        {
          $nbEcolesIR ++;
        }
      } // End School's loop

      $html .= '"nbEcoles": ' . $nbEcolesIR;

    $html .= '}, ';
    ###########################################################


    ### 12-13 #################################################
    $html .= '
    {"year": 2013,';

      // on va chercher tout les comptes ISO-Actif de l'IR
      $requete = 'SELECT * FROM t_liste_ecoles_08,t_usager_grille WHERE u_e_id_fk = ID ORDER BY NOM ASC';
      $resultat = $connexion->query($requete);

      // Find how many schools completed the form fot that season
      $nbEcolesIR = 0;
      while ($ligne = $resultat->fetch_assoc())
      {
        if ($ligne['u_g_prisec'] == 'P' && verifierSi4BlocsCompletsP1213($ligne['u_id']) == 'oui')
        {
          $nbEcolesIR ++;
        }
        else if ($ligne['u_g_prisec'] == 'S' && verifierSi4BlocsCompletsS1213($ligne['u_id']) == 'oui')
        {
          $nbEcolesIR ++;
        }
      } // End School's loop

      $html .= '"nbEcoles": ' . $nbEcolesIR;

    $html .= '}, ';
    ###########################################################


    ### 13-14 #################################################
    $html .= '
    {"year": 2014,';

      // on va chercher tout les comptes ISO-Actif de l'IR
      $requete = 'SELECT * FROM t_liste_ecoles_08,isoactif_t_usager_ecole WHERE u_e_id_fk = ID ORDER BY NOM ASC';
      $resultat = $connexion->query($requete);

      // Find how many schools completed the form fot that season
      $nbEcolesIR = 0;
      while ($ligne = $resultat->fetch_assoc())
      {
        if (verifierSiFormComplet($ligne['u_id'],$ligne['u_g_prisec'],'_2013_2014') == 'oui')
        {
          $nbEcolesIR ++;
        }
      } // End School's loop

      $html .= '"nbEcoles": ' . $nbEcolesIR;

    $html .= '}, ';
    ###########################################################



    ### 14-15 #################################################
    $html .= '
    {"year": 2015,';

      // on va chercher tout les comptes ISO-Actif de l'IR
      $requete = 'SELECT * FROM t_liste_ecoles_08,isoactif_t_usager_ecole WHERE u_e_id_fk = ID ORDER BY NOM ASC';
      $resultat = $connexion->query($requete);

      // Find how many schools completed the form fot that season
      $nbEcolesIR = 0;
      while ($ligne = $resultat->fetch_assoc())
      {
        if (verifierSiFormComplet($ligne['u_id'],$ligne['u_g_prisec'],'_2014_2015') == 'oui')
        {
          $nbEcolesIR ++;
        }
      } // End School's loop

      $html .= '"nbEcoles": ' . $nbEcolesIR;

    $html .= '}, ';
    ###########################################################


    ### 15-16 #################################################
    $html .= '
    {"year": 2016,';

      // on va chercher tout les comptes ISO-Actif de l'IR
      $requete = 'SELECT * FROM t_liste_ecoles_08,isoactif_t_usager_ecole WHERE u_e_id_fk = ID ORDER BY NOM ASC';
      $resultat = $connexion->query($requete);

      // Find how many schools completed the form fot that season
      $nbEcolesIR = 0;
      while ($ligne = $resultat->fetch_assoc())
      {
        if (verifierSiFormComplet($ligne['u_id'],$ligne['u_g_prisec'],'_2015_2016') == 'oui')
        {
          $nbEcolesIR ++;
        }
      } // End School's loop

      $html .= '"nbEcoles": ' . $nbEcolesIR;

    $html .= '}, ';
    ###########################################################


    ### 16-17 #################################################
    $html .= '
    {"year": 2017,';

      // on va chercher tout les comptes ISO-Actif de l'IR
      $requete = 'SELECT * FROM t_liste_ecoles_08,isoactif_t_usager_ecole WHERE u_e_id_fk = ID ORDER BY NOM ASC';
      $resultat = $connexion->query($requete);

      // Find how many schools completed the form fot that season
      $nbEcolesIR = 0;
      while ($ligne = $resultat->fetch_assoc())
      {
        if (verifierSiFormComplet($ligne['u_id'],$ligne['u_g_prisec'],'_2016_2017') == 'oui')
        {
          $nbEcolesIR ++;
        }
      } // End School's loop

      $html .= '"nbEcoles": ' . $nbEcolesIR;

    $html .= '}, ';
    ###########################################################
    #
    #### 17-18 #################################################
    $html .= '
    {"year": 2018,';

      // on va chercher tout les comptes ISO-Actif de l'IR
      $requete = 'SELECT * FROM t_liste_ecoles_08,isoactif_t_usager_ecole WHERE u_e_id_fk = ID ORDER BY NOM ASC';
      $resultat = $connexion->query($requete);

      // Find how many schools completed the form fot that season
      $nbEcolesIR = 0;
      while ($ligne = $resultat->fetch_assoc())
      {
        if (verifierSiFormComplet($ligne['u_id'],$ligne['u_g_prisec'],'_2017_2018') == 'oui')
        {
          $nbEcolesIR ++;
        }
      } // End School's loop

      $html .= '"nbEcoles": ' . $nbEcolesIR;

    $html .= '}, ';
    ###########################################################

    $html .= ' ],
      "valueAxes": [ {
      "gridColor": "#FFFFFF",
      "gridAlpha": 0.2,
      "dashLength": 0
    } ],
    "gridAboveGraphs": true,
    "startDuration": 1,
    "graphs": [ {
      "balloonText": "[[category]]: <b>[[value]]</b>",
      "fillAlphas": 0.8,
      "lineAlpha": 0.2,
      "type": "column",
      "valueField": "nbEcoles"
    } ],
    "chartCursor": {
      "categoryBalloonEnabled": false,
      "cursorAlpha": 0,
      "zoomable": false
    },
    "categoryField": "year",
    "categoryAxis": {
      "gridPosition": "start",
      "gridAlpha": 0,
      "tickPosition": "start",
      "tickLength": 20
    }

    } );
    </script>';

    $html .= '<div id="chartdiv"></div>';

    return utf8_decode($html);
  }
?>
