Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.69 KB | None | 0 0
  1. <?php
  2.  
  3.     $matrix = [];
  4.  
  5. $req = $bdd->query("SELECT nom, id_theme_question_q, priorite
  6.     FROM theme_q
  7.     INNER JOIN theme_r ON theme_r.id_site = theme_q.id_site and id_theme_q_r = id_theme_question_q
  8.     where theme_q.id_site in ($site_selection)
  9.     and i2c IS NOT NULL
  10.     group by nom, id_theme_question_q, priorite
  11.     order by priorite");
  12. while ($donnees = $req->fetch())
  13. {
  14.     $nom = $donnees['nom'];
  15.     $id_theme_question_q = $donnees['id_theme_question_q'];
  16.  
  17.     $tot = 0;
  18.     $moyenneTotal ='';
  19.     $matrix2 = [];
  20.     /*$reqSite = $bdd->query("SELECT *, AVG(i2c) AS i2c
  21.         FROM chapitre_q
  22.         INNER JOIN chapitre_r ON chapitre_r.id_site = chapitre_q.id_site and id_chapitre_q_r = id_chapitre_question_q
  23.         where chapitre_q.id_site in ($site_selection)
  24.         and chapitre_q.id_theme = $id_theme_question_q
  25.         and vague = $vague_max
  26.         and i2c IS NOT NULL
  27.         group by chapitre_q.id_chapitre_question_q");*/
  28.    $reqSite = $bdd->query("SELECT  chapitre_q.id_chapitre_q, chapitre_q.id_site, chapitre_q.id_formulaires, chapitre_q.nom, chapitre_q.id_theme, chapitre_q.id_chapitre_question_q, chapitre_q.priorite, chapitre_q.coef_chapitre, AVG(i2c) AS i2c
  29.        FROM chapitre_q
  30.        INNER JOIN chapitre_r ON chapitre_r.id_site = chapitre_q.id_site and id_chapitre_q_r = id_chapitre_question_q
  31.        where chapitre_q.id_site in ($site_selection)
  32.        and chapitre_q.id_theme = $id_theme_question_q
  33.        and vague = $vague_max
  34.        and i2c IS NOT NULL
  35.        group by chapitre_q.id_chapitre_q, chapitre_q.id_site, chapitre_q.id_formulaires, chapitre_q.nom, chapitre_q.id_theme, chapitre_q.id_chapitre_question_q, chapitre_q.priorite, chapitre_q.coef_chapitre");
  36.     while ($donnees = $reqSite->fetch())
  37.     {
  38.         $resultat = [];
  39.         $tot += 1;
  40.         $nom_site = $donnees['nom'];
  41.         $id_site = $donnees['id_site'];
  42.         $i2c = $donnees['i2c'];
  43.         $i2c = round($i2c);
  44.  
  45.  
  46.         if ($i2c >= $passage_2_client) {
  47.             $progress_bar= 'trait-vert.png';
  48.             $width = $i2c.'%';
  49.         } else if ($i2c < $passage_1_client && $i2c!=0) {
  50.             $progress_bar= 'trait-rouge.png';
  51.             $width = $i2c.'%';
  52.         } else if ($i2c == 0){
  53.             $progress_bar= 'trait-rouge.png';
  54.             $width = '1%';
  55.         } else {
  56.             $progress_bar= 'trait-orange.png';
  57.             $width = $i2c.'%';
  58.         }
  59.  
  60.         $id_chapitre_question_q = $donnees['id_chapitre_question_q'];
  61.  
  62.         $resultat = [
  63.             'name' => $nom_site,
  64.             'i2c' => $i2c,
  65.             'progress-bar' => $progress_bar,
  66.             'width' => $width
  67.         ];
  68.  
  69. // VAGUE - 1
  70.             $num_vague_moinsun = $vague_max -1;
  71.             $moyenneIntMoinsUn = '';
  72.  
  73.  
  74.             if ($num_vague_moinsun > 0) {
  75.  
  76.                 $reqProgression = $bdd->query("SELECT AVG(i2c) AS i2c
  77.                     FROM chapitre_r
  78.                     where id_chapitre_q_r = $id_chapitre_question_q
  79.                     and chapitre_r.id_site in ($site_selection)
  80.                     and vague = $num_vague_moinsun
  81.                     ");
  82.  
  83.                 while ($donnees = $reqProgression->fetch())
  84.                 {
  85.                     $moyenneIntMoinsUn = $donnees['i2c'];
  86.  
  87.  
  88.                     if (isset($moyenneIntMoinsUn) and $moyenneIntMoinsUn > $i2c) {$resultat['evolution'] ="fleche-moin.png";}
  89.                     if (isset($moyenneIntMoinsUn) and $moyenneIntMoinsUn < $i2c) {$resultat['evolution'] ="fleche-plus.png";}
  90.                     if (isset($moyenneIntMoinsUn) and $moyenneIntMoinsUn == $i2c) {$resultat['evolution'] ="fleche-egal.png";}
  91.  
  92.                 }
  93.  
  94.             }
  95.             $matrix2[] = $resultat;
  96.         }
  97.  
  98.         $tot = 0;
  99.         $moyenneTotal ='';
  100.         $matrix3 =[];
  101.         $reqSite = $bdd->query("SELECT nom_site, i2c, theme_r.id_site
  102.             FROM site
  103.             INNER JOIN theme_r ON theme_r.id_site = site.id_site
  104.             where theme_r.id_site in ($site_selection)
  105.             and id_theme_q_r = $id_theme_question_q
  106.             and vague = $vague_max
  107.             and i2c IS NOT NULL
  108.             order by nom_site");
  109.         while ($donnees = $reqSite->fetch())
  110.         {
  111.             $tot += 1;
  112.             $nom_site = $donnees['nom_site'];
  113.             $id_site = $donnees['id_site'];
  114.             $i2c = $donnees['i2c'];
  115.             $moyenneTotal += $i2c;
  116.         }
  117.         $moyenneTotal/$tot;
  118.         $moyenne_couleur = round($moyenneTotal/$tot);
  119.         $matrix3['name'] = $nom;
  120.         if($tot  == 0){
  121.             $matrix3['background-color'] = '#808080';
  122.             $matrix3['i2c'] = 'NC';
  123.         } else {
  124.             if ($moyenne_couleur  >= $passage_2_client) {
  125.                 $matrix3['background-color'] = '#599200';
  126.             } else if ($moyenne_couleur < $passage_1_client) {
  127.                 $matrix3['background-color'] = '#d1291d';
  128.             } else  {
  129.                 $matrix3['background-color'] = '#ed6e00';
  130.             }
  131.             $matrix3['i2c'] = $moyenne_couleur."%";
  132.         }
  133.  
  134.         $matrix[] = [
  135.             'box' => $matrix3,
  136.             'lignes' => $matrix2
  137.         ];
  138.  
  139.     }
  140.  
  141.     foreach ($matrix as $line) {
  142.         // echo json_encode($line);
  143.         echo '<div class="table-row-cat">';
  144.             echo "<div class='chapitre' style='background-color:".$line['box']['background-color']."'>";
  145.                 echo '<div class="nom">'.$line['box']['name'].'</div>';
  146.                 echo '<div class="i2c">'.$line['box']['i2c'].'</div>';
  147.             echo '</div>';
  148.             echo '<table class="sous-chapitre">';
  149.                 foreach ($line['lignes'] as $site) {
  150.                     echo '<tr class="ligne">';
  151.                         echo '<td class="nom">'.$site['name'].'</td>';
  152.                         echo '<td>';
  153.                             echo '<div class="bar">';
  154.                                 echo '<div class="bar-progress">';
  155.                                     echo '<img src="/img/rapport/'.$site['progress-bar'].'" height="12" width="'.$site['width'].'">';
  156.                                 echo '</div>';
  157.                             echo '</div>';
  158.                         echo '</td>';
  159.                         echo "<td><div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></td>";
  160.                         echo '<td class="cent">'.$site['i2c'].'%</td>';
  161.                         echo "<td><div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></td>";
  162.                         echo '<td class="">';
  163.                         if (isset($site['evolution'])) {
  164.                             echo "<img src='/img/extranet/rapport/".$site['evolution']."'>";
  165.                         }
  166.                         echo '</td>';
  167.                     echo '</tr>';
  168.                 }
  169.             echo '</table>';
  170.         echo '</div>';
  171.         echo '<br><br><br>';
  172.     }
  173.     ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement