Location: PHPKode > projects > Pnyx : des lections virtuelles! > pnyx1.0.1/adm_stat.php
<?php

	#########################################################################################
	# Gestion des statistiques de Pnyx														#
	# Auteur : V. Blais																		#
	# Création : 2007-06-05																	#
	# Modification : 2008-08-28																#
	# 																						#
	# Pnyx - une application Web (PHP/MySQL) d'élections virtuelles conçue pour	des	élèves	#
	# du primaire et du secondaire, dans lequel ils sont amenés à faire des	propositions	#
	# en ligne et voter pour leur favorite, sous la supervision d'un enseignant.			#
	#																						#
    # Copyright (C) <2008 - 2009>															#
	# <Service national du RÉCIT de l'univers social de la Commission scolaire de la		#
	# Pointe-de-l'Île>																		#
	#																						#
	# This program is free software; you can redistribute it and/or modify it under the 	#
	# terms of the GNU General Public License as published by the Free Software Foundation.	#
	# This program is distributed in the hope that it will be useful, but WITHOUT ANY 		#
	# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 		#
	# PARTICULAR PURPOSE.  See the GNU General Public License for more details.				#
	# You should have received a copy of the GNU General Public License along with this 	#
	# program as the file LICENSE.txt; if not, please see 									#
	# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.									#
	# 																						#
	# Service national du RÉCIT de l'univers social											#
	# http://www.recitus.qc.ca																#
	# Contact e-mail : steve-hide@address.com												#
	#########################################################################################

  require "entete_php.php";
	#gen_variables_session();
  
  	#vérifier si l'usager peut accéder à cette page
  	acces_admin("adm_stat.php");
  
  	if ($projet_admin != 0){
		$projet = $projet_admin;
		#variables pour l'affichage du titre
  	$titre = "Statistiques (projet archivé)";
	}else{
		$projet = $HTTP_SESSION_VARS['SESSION']['projet'];
		#variables pour l'affichage du titre
  	$titre = "Statistiques";
	}	

################################### REQUETES BDD #########################################	
  if ($projet != 0){

    //requete nombre d'élève du projet en cours
    $requete_sql = "SELECT *
					FROM projet
					WHERE projet_id = $projet
					";
    $reponse_actif = bd_executer_sql($requete_sql);
    $ligne_actif = mysql_fetch_array($reponse_actif);
	
	$requete_sql = "SELECT eleve_id
					FROM eleve
					WHERE projet_id = $projet
					";
    $reponse_eleve = bd_executer_sql($requete_sql);
    $nb_eleve = mysql_num_rows($reponse_eleve);
	
	$requete_sql = "SELECT eleve_id
					FROM eleve
					WHERE projet_id = $projet
					AND vote = 1
					";
	
	$reponse_vote = bd_executer_sql($requete_sql);
    $nb_votes = mysql_num_rows($reponse_vote);
	
	$requete_sql = "SELECT eleve_id
					FROM eleve
					WHERE projet_id = $projet
					AND candidat = 1
					";
    $reponse_cand = bd_executer_sql($requete_sql);
    $nb_cand = mysql_num_rows($reponse_cand);
	
	$requete_sql = "SELECT eleve_id
					FROM eleve
					WHERE projet_id = $projet
					AND candidat = 0
					";
    $reponse_elec = bd_executer_sql($requete_sql);
    $nb_elec = mysql_num_rows($reponse_elec);

    $requete_sql = "SELECT eleve_id
					FROM eleve
					WHERE projet_id = $projet
					AND valide = 1
					";
    $reponse_eleve = bd_executer_sql($requete_sql);
    $nb_eleve_val = mysql_num_rows($reponse_eleve);
	
	$requete_sql = "SELECT eleve_id
					FROM fiche
					WHERE projet_id = $projet
					AND valide = 1
					";
    $reponse_fiche = bd_executer_sql($requete_sql);
    $nb_fiche_val = mysql_num_rows($reponse_fiche);
	
	$requete_sql = "SELECT eleve_id
					FROM fiche
					WHERE projet_id = $projet
					AND valide = 0
					AND date_soumis != \"0000-00-00\"
					AND date_soumis != \"\"
					";
    $reponse_fiches = bd_executer_sql($requete_sql);
    $nb_fiche_soumis = mysql_num_rows($reponse_fiches);
	
	/*$requete_sql = "SELECT eleve_id
            FROM eleve
            WHERE projet_id = $projet
            ";*/
   
	
    
  }

################################### FIN REQUETES BDD #########################################

	#affichage graphique
	require "entete.php";

    $message = $HTTP_SESSION_VARS['SESSION']['message'];

    echo "<br /><h3 align=\"center\"><font color='#FF0000'>$message</font></h3>";
    $HTTP_SESSION_VARS['SESSION']['message']="";



  if ($projet == 0){
?>
    <p>Il n'y a aucun projet en cours.</p>
<?
  } else {
?>
	<p>&nbsp;&nbsp;&nbsp;Nom du projet : <a href="adm_enregistrement.php?id_projet=<?= $projet ?>"><?= $ligne_actif['nom'] ?></a></p>
    <?
	if ($projet_admin != 0){
?>
	<div align='right'><a href="adm_enregistrement2.php?type_action=retour_projCour">Revenir au projet actif</a></div>
<?
	}
?>
    
<div id="panneauxOnglet1" class="panneauxOnglet">
  	<ul class="ongletGroupe">
    <li id="onglet1" class="onglets" onclick="selectionPanneaux('1','2')" onmouseover="overOnglet('1')" onmouseout="outOnglet('1')">Élèves</li>
    <li id="onglet2" class="onglets" onclick="selectionPanneaux('2','2')" onmouseover="overOnglet('2')" onmouseout="outOnglet('2')">Vote</li>
  	</ul>
	
	<div class="panneauxGroupe">
<?
################################################ ONGLET ÉLÈVES #################################################
?>
<div id="panelContenu1" class="panneaux">	
<p><strong>Statistiques concernant les &eacute;l&egrave;ves participants :</strong></p>
    <table cellpadding="0" cellspacing="0" width="600">
    <tr>
      <td valign="top">Nombre total d'&eacute;l&egrave;ves :</td>
        <td valign="top"><?= $nb_eleve ?></td>
    </tr>
    <tr>
      <td valign="top">Nombre d'&eacute;l&egrave;ves validés :</td>
        <td valign="top"><?= $nb_eleve_val ?></td>
    </tr>
	<tr>
      <td valign="top">Nombre d'&eacute;l&egrave;ves non validés :</td>
        <td valign="top"><? $nb_nval = $nb_eleve - $nb_eleve_val;
				echo $nb_nval; ?></td>
    </tr>
	<tr>
      <td valign="top">Nombre de candidats :</td>
        <td valign="top"><?= $nb_cand ?></td>
    </tr>
	<tr>
      <td valign="top">Nombre d'&eacute;lecteurs :</td>
        <td valign="top"><?= $nb_elec ?></td>
    </tr>
    <tr>
      <td valign="top">Nombre de fiches de candidature en ligne :</td>
        <td valign="top"><?= $nb_fiche_val ?></td>
    </tr>
	<tr>
      <td valign="top">Nombre de fiches de candidature soumises &agrave; un responsable :</td>
        <td valign="top"><?= $nb_fiche_soumis ?></td>
    </tr>
	<tr>
      <td valign="top">Nombre d'&eacute;l&egrave;ves ayant voté :</td>
        <td valign="top"><?= $nb_votes ?></td>
    </tr>
	<tr>
      <td valign="top">Nombre d'&eacute;l&egrave;ves n'ayant pas voté :</td>
        <td valign="top"><? $nb_nvotes = $nb_eleve - $nb_votes;
				echo $nb_nvotes; ?></td>
    </tr>
    <tr>
    <td colspan="2"><p>&nbsp;</p></td>
    </tr>
    </table>
    </div>
<?
################################################ ONGLET VOTES ############################################################
?>
<div id="panelContenu2" class="panneaux">
<?
	if ($nb_votes == 0){
?>
		<p>Il n'y a aucun vote pour l'instant. Les r&eacute;sultats s'afficheront ici durant la p&eacute;riode de vote.</p>
<?
	} else {
	
		$requete_sql = "SELECT DISTINCT RE.nom, RE.region_id
						FROM ((((eleve AS E LEFT JOIN groupe AS G ON E.groupe_id = G.groupe_id)
											LEFT JOIN responsable AS R ON G.resp_id = R.resp_id)
											LEFT JOIN ecole AS EC ON R.ecole_id = EC.ecole_id)
											LEFT JOIN commission_scolaire AS CS ON EC.comscol_id = CS.comscol_id)
											LEFT JOIN region AS RE ON CS.region_id = RE.region_id
  						WHERE E.projet_id = $projet
						AND E.valide = 1
						ORDER BY RE.nom 
						";
	$reponse_region = bd_executer_sql($requete_sql);
	$tab_region = array();
	$i = 0;
	  
	while ($region = mysql_fetch_array($reponse_region)){
		$tab_region[$i] = $region['nom'];
		$i++;
	}
?>
    <p><strong>Légende</strong></p>
    <table cellpadding="0" cellspacing="0" width="600" align="center" >
	<tr>   
   <?
	$nb = count($tab_region);
	for ($j = 0; $j < $nb; $j++){ 
	$leg = $j+1;
	?>
	  
	  <td>&nbsp;<? echo $leg." = ".$tab_region[$j]; ?>&nbsp;</td>
<?
		if ($j == $nb || $j == 3 || $j == 7 || $j == 11 || $j == 15){
		 echo "</tr>";
		 if ($j != nb){
			echo "<tr>";
		}
		}
	
	}
?> 
	</table>
	<p>&nbsp;</p>
	
    <table cellpadding="0" cellspacing="0" width="600" align="center" border="1">
	<tr>
	<td><strong>&nbsp;</strong></td>   
   <?
	$val = count($tab_region)+1;
	for ($a = 1; $a < $val; $a++){ 
	?>
	  <td align="center">&nbsp;<strong><?= $a?></strong>&nbsp;</td>
<?
	}
?> 
	<td align="center"><strong>Total</strong></td>
	</tr>
<?
		$requete_sql = "SELECT E.fiche_id, F.slogan
            			FROM election E, fiche F
            			WHERE E.projet_id = $projet
						AND E.fiche_id = F.fiche_id
            			";
    	$reponse_prop = bd_executer_sql($requete_sql);
		
		$total_region = array();
		    	
		while ($props = mysql_fetch_array($reponse_prop)){
			
			$total_prop = 0;
			$titre = substr($props['slogan'], 0, 29)."...";
			echo "<tr><td><a href=\"gen_fiche.php?id_prop=".$props['fiche_id']."\">".$titre."</a></td>";
			
			$nb = count($tab_region);
			for ($b = 0; $b < $nb; $b++){
				
				$requete_sql = "SELECT DISTINCT RE.region_id
						FROM ((((eleve AS E LEFT JOIN groupe AS G ON E.groupe_id = G.groupe_id)
											LEFT JOIN responsable AS R ON G.resp_id = R.resp_id)
											LEFT JOIN ecole AS EC ON R.ecole_id = EC.ecole_id)
											LEFT JOIN commission_scolaire AS CS ON EC.comscol_id = CS.comscol_id)
											LEFT JOIN region AS RE ON CS.region_id = RE.region_id
  						WHERE E.projet_id = $projet
						AND E.valide = 1
						AND RE.nom = \"$tab_region[$b]\"
						ORDER BY RE.nom 
						";
				$reponse_regionID = bd_executer_sql($requete_sql);
				$ligne_regionID = mysql_fetch_array($reponse_regionID);
				
				$requete_sql = "SELECT E.fiche_vote
								FROM ((((eleve AS E LEFT JOIN groupe AS G ON E.groupe_id = G.groupe_id)
								LEFT JOIN responsable AS R ON G.resp_id = R.resp_id)
								LEFT JOIN ecole AS EC ON R.ecole_id = EC.ecole_id)
								LEFT JOIN commission_scolaire AS CS ON EC.comscol_id = CS.comscol_id)
								LEFT JOIN region AS RE ON CS.region_id = RE.region_id
								WHERE E.projet_id = $projet
								AND E.fiche_vote = \"$props[fiche_id]\"
								AND RE.region_id = " . $ligne_regionID['region_id'] . "
								";
				$reponse_vregion = bd_executer_sql($requete_sql);
				$nb_votereg = mysql_num_rows($reponse_vregion);
				$total_prop += $nb_votereg;
				if(array_key_exists($b, $total_region)){
					$total_region[$b] += $nb_votereg;
				}
				else{
					$total_region[$b] = $nb_votereg;
				}
				
#				echo $requete_sql."<br />";
				
				echo "<td align=\"center\">".$nb_votereg."</td>";
			}
			echo "<td align=\"center\">".$total_prop."</td></tr>";
		}
?>	
	</tr>
	<tr>
	<td><strong>Total</strong></td>
<?
	$nb = count($tab_region);
	for ($j = 0; $j < $nb; $j++){
		echo "<td align=\"center\">".$total_region[$j] ."</td>";
	}
?>
	<td align="center">&nbsp;</td>
	</tr>
	</table>
<?
  }
  }
?>
</div>
</div>
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<?
require "pied_page.php";
?>
Return current item: Pnyx : des lections virtuelles!