2011-05-15 01:32:47 +02:00
< ? php
//==========================================================================
//
//Université de Strasbourg - Direction Informatique
//Auteur : Guilhem BORGHESI
//Création : Février 2008
//
//borghesi@unistra.fr
//
//Ce logiciel est régi par la licence CeCILL-B soumise au droit français et
//respectant les principes de diffusion des logiciels libres. Vous pouvez
//utiliser, modifier et/ou redistribuer ce programme sous les conditions
//de la licence CeCILL-B telle que diffusée par le CEA, le CNRS et l'INRIA
//sur le site "http://www.cecill.info".
//
//Le fait que vous puissiez accéder à cet en-tête signifie que vous avez
//pris connaissance de la licence CeCILL-B, et que vous en avez accepté les
//termes. Vous pouvez trouver une copie de la licence dans le fichier LICENCE.
//
//==========================================================================
//
//Université de Strasbourg - Direction Informatique
//Author : Guilhem BORGHESI
//Creation : Feb 2008
//
//borghesi@unistra.fr
//
//This software is governed by the CeCILL-B license under French law and
//abiding by the rules of distribution of free software. You can use,
//modify and/ or redistribute the software under the terms of the CeCILL-B
//license as circulated by CEA, CNRS and INRIA at the following URL
//"http://www.cecill.info".
//
//The fact that you are presently reading this means that you have had
//knowledge of the CeCILL-B license and that you accept its terms. You can
//find a copy of this license in the file LICENSE.
//
//==========================================================================
session_start ();
2011-05-15 03:56:54 +02:00
if ( file_exists ( 'bandeaux_local.php' )) {
include_once ( 'bandeaux_local.php' );
} else {
include_once ( 'bandeaux.php' );
}
2011-05-15 01:32:47 +02:00
include_once ( 'fonctions.php' );
// Le fichier studs.php sert a afficher les résultats d'un sondage à un simple utilisateur.
// C'est également l'interface pour ajouter une valeur à un sondage deja créé.
$numsondage = false ;
//On récupère le numéro de sondage par le lien web.
2011-05-21 18:46:44 +02:00
if ( issetAndNoEmpty ( 'sondage' , $_GET ) === true ) {
$numsondage = $_GET [ " sondage " ];
2011-05-15 01:32:47 +02:00
$_SESSION [ " numsondage " ] = $numsondage ;
2011-05-15 03:56:54 +02:00
}
2011-05-21 18:46:44 +02:00
if ( issetAndNoEmpty ( 'sondage' ) === true ) {
$numsondage = $_POST [ " sondage " ];
2011-05-15 01:32:47 +02:00
$_SESSION [ " numsondage " ] = $numsondage ;
2011-05-21 18:46:44 +02:00
} elseif ( issetAndNoEmpty ( 'sondage' , $_COOKIE ) === true ) {
$numsondage = $_COOKIE [ " sondage " ];
} elseif ( issetAndNoEmpty ( 'numsondage' , $_SESSION ) === true ) {
$numsondage = $_SESSION [ " numsondage " ];
2011-05-15 01:32:47 +02:00
}
2011-05-21 18:46:44 +02:00
if ( $numsondage !== false ) {
2011-05-15 01:32:47 +02:00
$dsondage = get_sondage_from_id ( $numsondage );
2011-05-21 18:46:44 +02:00
if ( $dsondage === false ) {
2011-05-15 01:32:47 +02:00
$err |= NO_POLL ;
2011-05-15 03:56:54 +02:00
}
} else {
2011-05-15 01:32:47 +02:00
$err |= NO_POLL_ID ;
2011-05-15 03:56:54 +02:00
}
2011-05-15 01:32:47 +02:00
//output a CSV and die()
2011-05-21 18:46:44 +02:00
if ( issetAndNoEmpty ( 'export' , $_GET ) && $dsondage !== false ) {
2011-05-15 03:56:54 +02:00
if ( $_GET [ 'export' ] == 'csv' ) {
2011-05-15 01:32:47 +02:00
require_once ( 'exportcsv.php' );
2011-05-15 03:56:54 +02:00
}
2011-05-21 18:46:44 +02:00
if ( $_GET [ 'export' ] == 'ics' && $dsondage -> is_date ) {
2011-05-15 01:32:47 +02:00
require_once ( 'exportics.php' );
2011-05-15 03:56:54 +02:00
}
2011-05-15 01:32:47 +02:00
die ();
2011-05-15 03:56:54 +02:00
}
2011-05-15 01:32:47 +02:00
// quand on ajoute un commentaire utilisateur
2011-05-21 18:46:44 +02:00
if ( isset ( $_POST [ 'ajoutcomment' ]) || isset ( $_POST [ 'ajoutcomment_x' ])) {
2011-06-27 00:34:04 +02:00
if ( isset ( $_SESSION [ 'nom' ]) && issetAndNoEmpty ( 'commentuser' ) === false ) {
2011-05-21 18:46:44 +02:00
// Si le nom vient de la session, on le de-htmlentities
$comment_user = html_entity_decode ( $_SESSION [ 'nom' ], ENT_QUOTES , 'UTF-8' );
} elseif ( issetAndNoEmpty ( 'commentuser' )) {
$comment_user = $_POST [ " commentuser " ];
2011-05-15 03:56:54 +02:00
} elseif ( isset ( $_POST [ " commentuser " ])) {
2011-05-15 01:32:47 +02:00
$err |= COMMENT_USER_EMPTY ;
2011-05-15 03:56:54 +02:00
} else {
2011-05-15 01:32:47 +02:00
$comment_user = _ ( 'anonyme' );
2011-05-15 03:56:54 +02:00
}
2011-05-21 18:46:44 +02:00
if ( issetAndNoEmpty ( 'comment' ) === false ) {
2011-05-15 01:32:47 +02:00
$err |= COMMENT_EMPTY ;
2011-05-15 03:56:54 +02:00
}
2011-05-15 01:32:47 +02:00
2011-05-21 18:46:44 +02:00
if ( isset ( $_POST [ " comment " ]) && ! is_error ( COMMENT_EMPTY ) && ! is_error ( NO_POLL ) && ! is_error ( COMMENT_USER_EMPTY )) {
// protection contre les XSS : htmlentities
$comment = htmlentities ( $_POST [ 'comment' ], ENT_QUOTES , 'UTF-8' );
$comment_user = htmlentities ( $comment_user , ENT_QUOTES , 'UTF-8' );
$sql = 'INSERT INTO comments (id_sondage, comment, usercomment) VALUES (' .
$connect -> Param ( 'id_sondage' ) . ',' .
$connect -> Param ( 'comment' ) . ',' .
$connect -> Param ( 'comment_user' ) . ')' ;
$sql = $connect -> Prepare ( $sql );
$comments = $connect -> Execute ( $sql , array ( $numsondage , $comment , $comment_user ));
if ( $comments === false ) {
2011-05-15 03:56:54 +02:00
$err |= COMMENT_INSERT_FAILED ;
}
2011-05-15 01:32:47 +02:00
}
}
// Action quand on clique le bouton participer
2011-05-21 18:46:44 +02:00
$sql = 'SELECT * FROM user_studs WHERE id_sondage=' . $connect -> Param ( 'numsondage' ) . ' ORDER BY id_users' ;
$sql = $connect -> Prepare ( $sql );
$user_studs = $connect -> Execute ( $sql , array ( $numsondage ));
$nbcolonnes = substr_count ( $dsondage -> sujet , ',' ) + 1 ;
if ( ! is_error ( NO_POLL ) && ( isset ( $_POST [ " boutonp " ]) || isset ( $_POST [ " boutonp_x " ]))) {
2011-05-15 01:32:47 +02:00
//Si le nom est bien entré
2011-05-21 18:46:44 +02:00
if ( issetAndNoEmpty ( 'nom' ) === false ) {
2011-05-15 01:32:47 +02:00
$err |= NAME_EMPTY ;
2011-05-15 03:56:54 +02:00
}
2011-05-21 18:46:44 +02:00
if ( ! is_error ( NAME_EMPTY ) && ( ! isset ( $_SERVER [ 'REMOTE_USER' ]) || $_POST [ " nom " ] == $_SESSION [ " nom " ])) {
$nouveauchoix = '' ;
2011-05-15 03:56:54 +02:00
for ( $i = 0 ; $i < $nbcolonnes ; $i ++ ) {
2011-05-15 01:32:47 +02:00
// Si la checkbox est enclenchée alors la valeur est 1
2011-05-15 03:56:54 +02:00
if ( isset ( $_POST [ " choix $i " ]) && $_POST [ " choix $i " ] == '1' ) {
$nouveauchoix .= " 1 " ;
} else { // sinon c'est 0
$nouveauchoix .= " 0 " ;
2011-05-15 01:32:47 +02:00
}
}
2011-05-21 18:46:44 +02:00
$nom = substr ( $_POST [ " nom " ], 0 , 64 );
// protection contre les XSS : htmlentities
$nom = htmlentities ( $nom , ENT_QUOTES , 'UTF-8' );
2011-05-15 01:32:47 +02:00
while ( $user = $user_studs -> FetchNextObject ( false )) {
2011-05-21 18:46:44 +02:00
if ( $nom == $user -> nom ) {
2011-05-15 03:56:54 +02:00
$err |= NAME_TAKEN ;
}
2011-05-15 01:32:47 +02:00
}
// Ecriture des choix de l'utilisateur dans la base
2011-05-21 18:46:44 +02:00
if ( ! is_error ( NAME_TAKEN ) && ! is_error ( NAME_EMPTY )) {
$sql = 'INSERT INTO user_studs (nom,id_sondage,reponses) VALUES (' .
$connect -> Param ( 'nom' ) . ', ' .
$connect -> Param ( 'numsondage' ) . ', ' .
$connect -> Param ( 'nouveauchoix' ) . ')' ;
$sql = $connect -> Prepare ( $sql );
// Todo : Il faudrait lever une erreur en cas d'erreur d'insertion
$connect -> Execute ( $sql , array ( $nom , $numsondage , $nouveauchoix ));
2011-05-15 03:56:54 +02:00
if ( $dsondage -> mailsonde || /* compatibility for non boolean DB */ $dsondage -> mailsonde == " yes " || $dsondage -> mailsonde == " true " ) {
$headers = " From: " . NOMAPPLICATION . " < " . ADRESSEMAILADMIN . " > \r \n Content-Type: text/plain; charset= \" UTF-8 \" \n Content-Transfer-Encoding: 8bit " ;
2012-01-09 01:26:44 +01:00
sendEmail ( " $dsondage->mail_admin " ,
2011-07-04 22:24:38 +02:00
" [ " . NOMAPPLICATION . " ] " . _ ( " Poll's participation " ) . " : " . html_entity_decode ( $dsondage -> titre , ENT_QUOTES , 'UTF-8' ) . " " ,
html_entity_decode ( " \" $nom\ " " , ENT_QUOTES, 'UTF-8').
2011-05-15 03:56:54 +02:00
_ ( " has filled a line. \n You can find your poll at the link " ) . " : \n \n " .
2011-05-21 18:46:44 +02:00
getUrlSondage ( $numsondage ) . " \n \n " .
2011-05-15 03:56:54 +02:00
_ ( " Thanks for your confidence. " ) . " \n " . NOMAPPLICATION ,
2012-01-09 01:26:44 +01:00
$headers );
2011-05-15 01:32:47 +02:00
}
}
2011-05-15 03:56:54 +02:00
} else {
2011-05-15 01:32:47 +02:00
$err |= NAME_EMPTY ;
2011-05-15 03:56:54 +02:00
}
2011-05-15 01:32:47 +02:00
}
2011-05-20 02:52:22 +02:00
print_header ( true , $dsondage -> titre );
2011-05-15 01:32:47 +02:00
echo '<body>' . " \n " ;
2011-06-23 16:52:10 +02:00
framanav ();
2011-05-15 01:32:47 +02:00
logo ();
bandeau_tete ();
bandeau_titre ( _ ( " Make your polls " ));
sous_bandeau ();
2011-06-23 01:21:56 +02:00
#print_r($_SESSION);
2011-05-15 01:32:47 +02:00
if ( $err != 0 ) {
bandeau_titre ( _ ( " Error! " ));
echo '<div class="error"><ul>' . " \n " ;
2011-05-15 03:56:54 +02:00
if ( is_error ( NAME_EMPTY )) {
2011-05-15 01:32:47 +02:00
echo '<li class="error">' . _ ( " Enter a name ! " ) . " </li> \n " ;
2011-05-15 03:56:54 +02:00
}
if ( is_error ( NAME_TAKEN )) {
2011-05-15 01:32:47 +02:00
echo '<li class="error">' .
2011-05-15 03:56:54 +02:00
_ ( " The name you've chosen already exist in this poll! " ) .
" </li> \n " ;
}
if ( is_error ( COMMENT_EMPTY ) || is_error ( COMMENT_USER_EMPTY )) {
2011-05-15 01:32:47 +02:00
echo '<li class="error">' .
2011-05-15 03:56:54 +02:00
_ ( " Enter a name and a comment! " ) .
" </li> \n " ;
}
if ( is_error ( COMMENT_INSERT_FAILED ) ) {
2011-05-15 01:32:47 +02:00
echo '<li class="error">' .
2011-05-15 03:56:54 +02:00
_ ( " Failed to insert the comment! " ) .
" </li> \n " ;
}
2011-05-15 01:32:47 +02:00
echo '</ul></div>' ;
2011-06-23 01:21:56 +02:00
2011-05-15 01:32:47 +02:00
if ( is_error ( NO_POLL_ID ) || is_error ( NO_POLL )) {
echo '<div class=corpscentre>' . " \n " ;
print " <H2> " . _ ( " This poll doesn't exist ! " ) . " </H2> " . " \n " ;
2011-05-15 03:56:54 +02:00
print _ ( " Back to the homepage of " ) . ' <a href="index.php"> ' . NOMAPPLICATION . '</a>.' . " \n " ;
2011-05-15 01:32:47 +02:00
echo '<br><br><br><br>' . " \n " ;
echo '</div>' . " \n " ;
bandeau_pied ();
echo '</body>' . " \n " ;
echo '</html>' . " \n " ;
die ();
}
2011-05-15 03:56:54 +02:00
}
2011-05-15 01:32:47 +02:00
2011-06-23 01:21:56 +02:00
echo '<div class="corps">' ; //ajout pyg cohérence graphique
echo '<div class="imprimer""><a href="javascript:print()" class="button white medium">Imprimer</a></div>' ;
2011-05-15 01:32:47 +02:00
echo '<div class="presentationdate"> ' . " \n " ;
//affichage du titre du sondage
2011-05-15 03:56:54 +02:00
$titre = str_replace ( " \\ " , " " , $dsondage -> titre );
2011-06-23 01:21:56 +02:00
echo '<H2>' . stripslashes ( $titre ) . '</H2>' . " \n " ;
2011-05-15 01:32:47 +02:00
//affichage du nom de l'auteur du sondage
2011-06-23 01:21:56 +02:00
echo _ ( " Initiator of the poll " ) . ' : ' . stripslashes ( $dsondage -> nom_admin ) . '<br>' . " \n " ;
2011-06-27 00:37:17 +02:00
echo 'Adresse : <code>' . getUrlSondage ( $dsondage -> id_sondage ) . '</code><br>' . " \n " ;;
2011-06-23 01:21:56 +02:00
2011-05-15 01:32:47 +02:00
//affichage des commentaires du sondage
2011-05-15 03:56:54 +02:00
if ( $dsondage -> commentaires ) {
echo _ ( " Comments " ) . ' :<br>' . " \n " ;
2011-05-21 18:46:44 +02:00
$commentaires = $dsondage -> commentaires ;
2011-05-22 02:39:49 +02:00
$commentaires = nl2br ( str_replace ( " \\ " , " " , $commentaires ));
2011-05-15 03:56:54 +02:00
echo $commentaires ;
echo '<br>' . " \n " ;
}
2011-05-15 01:32:47 +02:00
2011-05-15 03:56:54 +02:00
echo '<br>' . " \n " ;
echo '</div>' . " \n " ;
2011-05-15 01:32:47 +02:00
2011-06-27 00:39:58 +02:00
echo '<form name="formulaire" action="' . getUrlSondage ( $dsondage -> id_sondage ) . '"' . '#bas" method="POST" onkeypress="javascript:process_keypress(event)">' . " \n " ;
2011-05-15 01:32:47 +02:00
echo '<input type="hidden" name="sondage" value="' . $numsondage . '"/>' ;
2011-05-21 18:46:44 +02:00
// Todo : add CSRF protection
2011-06-27 01:34:06 +02:00
echo '<div class="cadre"><div class="information">' . " \n " ;
2011-05-15 03:56:54 +02:00
echo _ ( " If you want to vote in this poll, you have to give your name, choose the values that fit best for you<br>(without paying attention to the choices of the other voters) and validate with the plus button at the end of the line. " ) . " \n " ;
2011-06-27 01:34:06 +02:00
echo '</div>' . " \n " ;
2011-05-15 01:32:47 +02:00
// Debut de l'affichage des resultats du sondage
2011-07-04 21:33:58 +02:00
echo '<table class="resultats">' . " \n " . '<thead>' ;
2011-05-15 01:32:47 +02:00
//On récupere les données et les sujets du sondage
2011-05-21 18:46:44 +02:00
$nblignes = $user_studs -> RecordCount ();
2011-05-15 01:32:47 +02:00
2011-05-15 03:56:54 +02:00
//on teste pour voir si une ligne doit etre modifiée
2011-05-15 01:32:47 +02:00
$testmodifier = false ;
$ligneamodifier = - 1 ;
2011-05-15 03:56:54 +02:00
for ( $i = 0 ; $i < $nblignes ; $i ++ ) {
if ( isset ( $_POST [ " modifierligne $i " ]) || isset ( $_POST [ 'modifierligne' . $i . '_x' ])) {
2011-05-21 18:46:44 +02:00
$ligneamodifier = $i ;
2011-05-15 03:56:54 +02:00
}
//test pour voir si une ligne est a modifier
2011-05-21 18:46:44 +02:00
if ( isset ( $_POST [ 'validermodifier' . $i ]) || isset ( $_POST [ 'validermodifier' . $i . '_x' ])) {
$modifier = $i ;
$testmodifier = true ;
2011-05-15 03:56:54 +02:00
}
}
2011-05-15 01:32:47 +02:00
2011-05-15 03:56:54 +02:00
//si le test est valide alors on affiche des checkbox pour entrer de nouvelles valeurs
if ( $testmodifier ) {
2011-05-21 18:46:44 +02:00
$nouveauchoix = '' ;
2011-05-15 03:56:54 +02:00
for ( $i = 0 ; $i < $nbcolonnes ; $i ++ ) {
//recuperation des nouveaux choix de l'utilisateur
if ( isset ( $_POST [ " choix $i " ]) && $_POST [ " choix $i " ] == 1 ) {
$nouveauchoix .= " 1 " ;
} else {
$nouveauchoix .= " 0 " ;
}
}
$compteur = 0 ;
2011-05-21 18:46:44 +02:00
while ( $data = $user_studs -> FetchNextObject ( false ) ) {
2011-05-15 03:56:54 +02:00
//mise a jour des données de l'utilisateur dans la base SQL
2011-05-21 18:46:44 +02:00
if ( $compteur == $modifier ) {
$sql = 'UPDATE user_studs SET reponses=' . $connect -> Param ( 'nouveauchoix' ) . ' WHERE nom=' . $connect -> Param ( 'nom' ) . ' AND id_users=' . $connect -> Param ( 'id_users' );
$sql = $connect -> Prepare ( $sql );
$connect -> Execute ( $sql , array ( $nouveauchoix , $data -> nom , $data -> id_users ));
2011-05-15 03:56:54 +02:00
if ( $dsondage -> mailsonde == " yes " ) {
$headers = " From: " . NOMAPPLICATION . " < " . ADRESSEMAILADMIN . " > \r \n Content-Type: text/plain; charset= \" UTF-8 \" \n Content-Transfer-Encoding: 8bit " ;
2012-01-09 01:26:44 +01:00
sendEmail ( " $dsondage->mail_admin " , " [ " . NOMAPPLICATION . " ] " . _ ( " Poll's participation " ) . " : " . html_entity_decode ( $dsondage -> titre , ENT_QUOTES , 'UTF-8' ), " \" " . html_entity_decode ( $data -> nom , ENT_QUOTES , 'UTF-8' ) . " \" " . " " . _ ( " has filled a line. \n You can find your poll at the link " ) . " : \n \n " . getUrlSondage ( $numsondage ) . " \n \n " . _ ( " Thanks for your confidence. " ) . " \n " . NOMAPPLICATION , $headers );
2011-05-15 03:56:54 +02:00
}
}
$compteur ++ ;
}
}
//recuperation des utilisateurs du sondage
2011-05-21 18:46:44 +02:00
$sql = 'SELECT * FROM user_studs WHERE id_sondage=' . $connect -> Param ( 'numsondage' ) . ' ORDER BY id_users' ;
$sql = $connect -> Prepare ( $sql );
$user_studs = $connect -> Execute ( $sql , array ( $numsondage ));
2011-05-15 01:32:47 +02:00
//reformatage des données des sujets du sondage
2011-05-21 18:46:44 +02:00
$toutsujet = explode ( " , " , $dsondage -> sujet );
2011-05-15 01:32:47 +02:00
//si le sondage est un sondage de date
2011-05-15 03:56:54 +02:00
if ( $dsondage -> format == " D " || $dsondage -> format == " D+ " ) {
//affichage des sujets du sondage
echo '<tr>' . " \n " ;
echo '<td></td>' . " \n " ;
//affichage des années
$colspan = 1 ;
for ( $i = 0 ; $i < count ( $toutsujet ); $i ++ ) {
2011-05-21 18:46:44 +02:00
if ( isset ( $toutsujet [ $i + 1 ]) && date ( 'Y' , intval ( $toutsujet [ $i ])) == date ( 'Y' , intval ( $toutsujet [ $i + 1 ]))) {
2011-05-15 03:56:54 +02:00
$colspan ++ ;
} else {
echo '<td colspan=' . $colspan . ' class="annee">' . date ( 'Y' , intval ( $toutsujet [ $i ])) . '</td>' . " \n " ;
$colspan = 1 ;
}
}
echo '</tr>' . " \n " ;
echo '<tr>' . " \n " ;
echo '<td></td>' . " \n " ;
//affichage des mois
$colspan = 1 ;
for ( $i = 0 ; $i < count ( $toutsujet ); $i ++ ) {
// intval() est utiliser pour supprimer le suffixe @* qui déplaît logiquement à strftime()
$cur = intval ( $toutsujet [ $i ]);
2011-05-21 18:46:44 +02:00
if ( isset ( $toutsujet [ $i + 1 ]) === false ) {
$next = false ;
} else {
$next = intval ( $toutsujet [ $i + 1 ]);
}
if ( $next && strftime ( " %B " , $cur ) == strftime ( " %B " , $next ) && date ( 'Y' , $cur ) == date ( 'Y' , $next )) {
2011-05-15 03:56:54 +02:00
$colspan ++ ;
} else {
if ( $_SESSION [ " langue " ] == " EN " ) { // because strftime doesn't support english suffix (like st,nd,rd,th)
echo '<td colspan=' . $colspan . ' class="mois">' . date ( " F " , $cur ) . '</td>' . " \n " ;
} else {
echo '<td colspan=' . $colspan . ' class="mois">' . strftime ( " %B " , $cur ) . '</td>' . " \n " ;
}
$colspan = 1 ;
}
}
echo '</tr>' . " \n " ;
echo '<tr>' . " \n " ;
echo '<td></td>' . " \n " ;
//affichage des jours
$colspan = 1 ;
for ( $i = 0 ; $i < count ( $toutsujet ); $i ++ ) {
$cur = intval ( $toutsujet [ $i ]);
2011-05-21 18:46:44 +02:00
if ( isset ( $toutsujet [ $i + 1 ]) === false ) {
$next = false ;
} else {
$next = intval ( $toutsujet [ $i + 1 ]);
}
if ( $next && strftime ( " %a %e " , $cur ) == strftime ( " %a %e " , $next ) && strftime ( " %B " , $cur ) == strftime ( " %B " , $next )) {
2011-05-15 03:56:54 +02:00
$colspan ++ ;
} else {
if ( $_SESSION [ " langue " ] == " EN " ) {
echo '<td colspan=' . $colspan . ' class="jour">' . date ( " D jS " , $cur ) . '</td>' . " \n " ;
} else {
echo '<td colspan=' . $colspan . ' class="jour">' . strftime ( " %a %e " , $cur ) . '</td>' . " \n " ;
}
$colspan = 1 ;
}
}
echo '</tr>' . " \n " ;
//affichage des horaires
if ( strpos ( $dsondage -> sujet , '@' ) !== false ) {
echo '<tr>' . " \n " ;
echo '<td></td>' . " \n " ;
2011-05-21 18:46:44 +02:00
for ( $i = 0 ; isset ( $toutsujet [ $i ]); $i ++ ) {
2011-05-15 03:56:54 +02:00
$heures = explode ( " @ " , $toutsujet [ $i ]);
2011-05-21 18:46:44 +02:00
if ( isset ( $heures [ 1 ]) === true ) {
2011-06-23 01:21:56 +02:00
echo '<td class="heure">' . stripslashes ( $heures [ 1 ]) . '</td>' . " \n " ;
2011-05-21 18:46:44 +02:00
} else {
echo '<td class="heure"></td>' . " \n " ;
}
2011-05-15 03:56:54 +02:00
}
echo '</tr>' . " \n " ;
}
} else {
$toutsujet = str_replace ( " ° " , " ' " , $toutsujet );
//affichage des sujets du sondage
echo '<tr>' . " \n " ;
echo '<td></td>' . " \n " ;
2011-05-21 18:46:44 +02:00
for ( $i = 0 ; isset ( $toutsujet [ $i ]); $i ++ ) {
2011-06-23 01:21:56 +02:00
echo '<td class="sujet">' . stripslashes ( $toutsujet [ $i ]) . '</td>' . " \n " ;
2011-05-15 03:56:54 +02:00
}
echo '</tr>' . " \n " ;
2011-05-15 01:32:47 +02:00
}
2011-07-04 21:33:58 +02:00
echo '</thead>' . " \n " . '<tbody>' . " \n " ;
2011-05-15 01:32:47 +02:00
//Usager pré-authentifié dans la liste?
2011-05-21 18:46:44 +02:00
$user_mod = false ;
2011-05-15 03:56:54 +02:00
2011-05-15 01:32:47 +02:00
//affichage des resultats actuels
$somme = array ();
2011-05-15 03:56:54 +02:00
$compteur = 0 ;
2011-05-21 18:46:44 +02:00
while ( $data = $user_studs -> FetchNextObject ( false )) {
2011-05-15 03:56:54 +02:00
echo '<tr>' . " \n " ;
echo '<td class="nom">' ;
// Le nom de l'utilisateur
$nombase = str_replace ( " ° " , " ' " , $data -> nom );
2011-06-23 01:21:56 +02:00
echo stripslashes ( $nombase ) . '</td>' . " \n " ;
2011-05-15 03:56:54 +02:00
// Les réponses qu'il a choisit
2011-05-21 18:46:44 +02:00
$ensemblereponses = $data -> reponses ;
2011-05-15 03:56:54 +02:00
// ligne d'un usager pré-authentifié
$mod_ok = ! isset ( $_SERVER [ 'REMOTE_USER' ]) || ( $nombase == $_SESSION [ 'nom' ]);
$user_mod |= $mod_ok ;
// pour chaque colonne
for ( $k = 0 ; $k < $nbcolonnes ; $k ++ ) {
// on remplace les choix de l'utilisateur par une ligne de checkbox pour recuperer de nouvelles valeurs
if ( $compteur == $ligneamodifier ) {
echo '<td class="vide"><input type="checkbox" name="choix' . $k . '" value="1" ' ;
if ( substr ( $ensemblereponses , $k , 1 ) == '1' ) {
echo 'checked="checked"' ;
}
echo ' /></td>' . " \n " ;
} else {
2011-05-21 18:46:44 +02:00
$car = substr ( $ensemblereponses , $k , 1 );
if ( $car == " 1 " ) {
2011-05-15 03:56:54 +02:00
echo '<td class="ok">OK</td>' . " \n " ;
2011-05-21 18:46:44 +02:00
if ( isset ( $somme [ $k ]) === false ) {
$somme [ $k ] = 0 ;
}
2011-05-15 03:56:54 +02:00
$somme [ $k ] ++ ;
} else {
echo '<td class="non"></td>' . " \n " ;
}
}
}
//a la fin de chaque ligne se trouve les boutons modifier
if ( $compteur != $ligneamodifier && ( $dsondage -> format == " A+ " || $dsondage -> format == " D+ " ) && $mod_ok ) {
echo '<td class=casevide><input type="image" name="modifierligne' . $compteur . '" value="Modifier" src="images/info.png"></td>' . " \n " ;
}
//demande de confirmation pour modification de ligne
for ( $i = 0 ; $i < $nblignes ; $i ++ ) {
2011-05-21 18:46:44 +02:00
if ( isset ( $_POST [ " modifierligne $i " ]) || isset ( $_POST [ 'modifierligne' . $i . '_x' ])) {
if ( $compteur == $i ) {
2011-05-15 03:56:54 +02:00
echo '<td class="casevide"><input type="image" name="validermodifier' . $compteur . '" value="Valider la modification" src="images/accept.png" ></td>' . " \n " ;
}
}
}
$compteur ++ ;
echo '</tr>' . " \n " ;
}
2011-05-15 01:32:47 +02:00
// affichage de la ligne pour un nouvel utilisateur
2011-05-15 03:56:54 +02:00
if ( ! isset ( $_SERVER [ 'REMOTE_USER' ]) || ! $user_mod ) {
2011-06-27 01:34:06 +02:00
echo '<tr class="ajout_reponse">' . " \n " ;
2011-05-15 03:56:54 +02:00
echo '<td class="nom">' . " \n " ;
2011-05-21 18:46:44 +02:00
if ( isset ( $_SESSION [ 'nom' ])) {
2011-06-27 00:26:31 +02:00
$nom = stripslashes ( $_SESSION [ 'nom' ]);
2011-05-15 03:56:54 +02:00
} else {
2011-06-27 00:26:31 +02:00
$nom = '' ;
2011-05-15 03:56:54 +02:00
}
2011-06-27 00:26:31 +02:00
echo '<input type=text name="nom" maxlength="64" value="' . $nom . '">' . " \n " ;
2011-05-15 03:56:54 +02:00
echo '</td>' . " \n " ;
// affichage des cases de formulaire checkbox pour un nouveau choix
for ( $i = 0 ; $i < $nbcolonnes ; $i ++ ) {
echo '<td class="vide"><input type="checkbox" name="choix' . $i . '" value="1"' ;
if ( isset ( $_POST [ 'choix' . $i ]) && $_POST [ 'choix' . $i ] == '1' && is_error ( NAME_EMPTY ) ) {
echo ' checked="checked"' ;
}
echo '></td>' . " \n " ;
}
// Affichage du bouton de formulaire pour inscrire un nouvel utilisateur dans la base
echo '<td><input type="image" name="boutonp" value="' . _ ( 'Participate' ) . '" src="images/add-24.png"></td>' . " \n " ;
echo '</tr>' . " \n " ;
}
2011-05-15 01:32:47 +02:00
//determination de la meilleure date
// On cherche la meilleure colonne
2011-05-21 18:46:44 +02:00
for ( $i = 0 ; $i < $nbcolonnes ; $i ++ ) {
if ( isset ( $somme [ $i ]) === true ) {
if ( $i == " 0 " ) {
$meilleurecolonne = $somme [ $i ];
}
if ( isset ( $meilleurecolonne ) === false || $somme [ $i ] > $meilleurecolonne ) {
$meilleurecolonne = $somme [ $i ];
}
2011-05-15 03:56:54 +02:00
}
}
2011-05-15 01:32:47 +02:00
2011-07-04 21:33:58 +02:00
echo '</tbody>' . " \n " . '<tfoot>' . " \n " ;
2011-05-15 01:32:47 +02:00
// Affichage des différentes sommes des colonnes existantes
2011-05-15 03:56:54 +02:00
echo '<tr>' . " \n " ;
echo '<td align="right">' . _ ( " Addition " ) . '</td>' . " \n " ;
2011-05-21 18:46:44 +02:00
for ( $i = 0 ; $i < $nbcolonnes ; $i ++ ) {
if ( isset ( $somme [ $i ]) === true ) {
$affichesomme = $somme [ $i ];
if ( $affichesomme == " " ) {
$affichesomme = '0' ;
}
} else {
$affichesomme = '0' ;
2011-05-15 03:56:54 +02:00
}
echo '<td class="somme">' . $affichesomme . '</td>' . " \n " ;
}
echo '</tr>' . " \n " ;
echo '<tr>' . " \n " ;
echo '<td class="somme"></td>' . " \n " ;
2011-05-21 18:46:44 +02:00
for ( $i = 0 ; $i < $nbcolonnes ; $i ++ ) {
if ( isset ( $somme [ $i ]) && isset ( $meilleurecolonne ) && $somme [ $i ] == $meilleurecolonne ) {
2011-05-15 03:56:54 +02:00
echo '<td class="somme"><img src="images/medaille.png" alt="' . _ ( 'Best choice' ) . '"></td>' . " \n " ;
} else {
echo '<td class="somme"></td>' . " \n " ;
}
}
echo '</tr>' . " \n " ;
2011-07-04 21:33:58 +02:00
echo '</tfoot>' . " \n " ;
2011-05-15 03:56:54 +02:00
echo '</table>' . " \n " ;
echo '</div>' . " \n " ;
2011-05-15 01:32:47 +02:00
// reformatage des données de la base pour les sujets
2011-05-15 03:56:54 +02:00
$toutsujet = explode ( " , " , $dsondage -> sujet );
$toutsujet = str_replace ( " ° " , " ' " , $toutsujet );
2011-05-15 01:32:47 +02:00
// On compare le nombre de résultat avec le meilleur et si le résultat est égal
// on concatene le resultat dans $meilleursujet
2011-05-15 03:56:54 +02:00
$compteursujet = 0 ;
2011-05-21 18:46:44 +02:00
$meilleursujet = '' ;
for ( $i = 0 ; $i < $nbcolonnes ; $i ++ ) {
if ( isset ( $somme [ $i ]) && isset ( $meilleurecolonne ) && $somme [ $i ] == $meilleurecolonne ) {
2011-05-15 03:56:54 +02:00
$meilleursujet .= " , " ;
if ( $dsondage -> format == " D " || $dsondage -> format == " D+ " ) {
2011-05-21 18:46:44 +02:00
$meilleursujetexport = $toutsujet [ $i ];
2011-05-15 03:56:54 +02:00
if ( strpos ( $toutsujet [ $i ], '@' ) !== false ) {
$toutsujetdate = explode ( " @ " , $toutsujet [ $i ]);
if ( $_SESSION [ " langue " ] == " EN " ) {
$meilleursujet .= date ( " l, F jS Y " , $toutsujetdate [ 0 ]) . " " . _ ( " for " ) . " " . $toutsujetdate [ 1 ];
} else {
$meilleursujet .= strftime ( _ ( " %A, den %e. %B %Y " ), $toutsujetdate [ 0 ]) . ' ' . _ ( " for " ) . ' ' . $toutsujetdate [ 1 ];
}
} else {
if ( $_SESSION [ " langue " ] == " EN " ) {
$meilleursujet .= date ( " l, F jS Y " , $toutsujet [ $i ]);
} else {
$meilleursujet .= strftime ( _ ( " %A, den %e. %B %Y " ), $toutsujet [ $i ]);
}
}
} else {
2011-05-21 18:46:44 +02:00
$meilleursujet .= $toutsujet [ $i ];
2011-05-15 03:56:54 +02:00
}
$compteursujet ++ ;
}
}
2011-05-15 01:32:47 +02:00
2011-05-21 18:46:44 +02:00
$meilleursujet = substr ( " $meilleursujet " , 1 );
2011-05-15 01:32:47 +02:00
$vote_str = _ ( 'vote' );
2011-05-15 03:56:54 +02:00
2011-05-21 18:46:44 +02:00
if ( isset ( $meilleurecolonne ) && $meilleurecolonne > 1 ) {
2011-05-15 01:32:47 +02:00
$vote_str = _ ( 'votes' );
2011-05-15 03:56:54 +02:00
}
echo '<p class="affichageresultats">' . " \n " ;
// Affichage du meilleur choix
2011-05-21 18:46:44 +02:00
if ( $compteursujet == " 1 " && isset ( $meilleurecolonne )) {
2011-06-23 01:21:56 +02:00
print '<img src="images/medaille.png" alt="Meilleur choix"> ' . _ ( 'The best choice at this time is:' ) . " <b> " . stripslashes ( $meilleursujet ) . " </b> " . _ ( 'with' ) . " <b> $meilleurecolonne </b> " . $vote_str . " . \n " ;
2011-05-21 18:46:44 +02:00
} elseif ( isset ( $meilleurecolonne )) {
2011-06-23 01:21:56 +02:00
print '<img src="images/medaille.png" alt="Meilleur choix"> ' . _ ( 'The bests choices at this time are:' ) . " <b> " . stripslashes ( $meilleursujet ) . " </b> " . _ ( 'with' ) . " <b> $meilleurecolonne </b> " . $vote_str . " . \n " ;
2011-05-15 03:56:54 +02:00
}
echo '</p>' ;
//affichage des commentaires des utilisateurs existants
2011-05-21 18:46:44 +02:00
$sql = 'select * from comments where id_sondage=' . $connect -> Param ( 'numsondage' ) . ' order by id_comment' ;
$sql = $connect -> Prepare ( $sql );
$comment_user = $connect -> Execute ( $sql , array ( $numsondage ));
2011-05-15 03:56:54 +02:00
if ( $comment_user -> RecordCount () != 0 ) {
print " <br><b> " . _ ( " Comments of polled people " ) . " :</b><br> \n " ;
2011-05-21 18:46:44 +02:00
while ( $dcomment = $comment_user -> FetchNextObject ( false )) {
2011-06-23 01:21:56 +02:00
print '<div class="comment"><span class="usercomment">' . stripslashes ( $dcomment -> usercomment ) . ' :</span> <span class="comment">' . stripslashes ( nl2br ( $dcomment -> comment )) . '</span></div>' ;
2011-05-15 03:56:54 +02:00
}
}
2011-05-15 01:32:47 +02:00
2011-05-15 03:56:54 +02:00
//affichage de la case permettant de rajouter un commentaire par les utilisateurs
print '<div class="addcomment">' . '<p>' . _ ( " Add a comment in the poll: " ) . '</p>' . " \n " ;
2011-05-15 01:32:47 +02:00
2011-05-21 18:46:44 +02:00
if ( isset ( $_SESSION [ 'nom' ]) === false ) {
2011-06-27 00:34:04 +02:00
$nom = '' ;
} else {
$nom = stripslashes ( $_SESSION [ 'nom' ]);
}
echo _ ( " Name " ) . ' : ' ;
echo '<input type="text" name="commentuser" maxlength="64" value="' . $nom . '" /><br>' . " \n " ;
2011-05-15 03:56:54 +02:00
2011-05-15 01:32:47 +02:00
echo '<textarea name="comment" rows="2" cols="40"></textarea>' . " \n " ;
echo '<input type="image" name="ajoutcomment" value="Ajouter un commentaire" src="images/accept.png" alt="Valider"><br>' . " \n " ;
echo '</form>' . " \n " ;
// Focus javascript sur la case de texte du formulaire
echo '<script type="text/javascript">' . " \n " . 'document.formulaire.commentuser.focus();' . " \n " . '</script>' . " \n " ;
echo '</div>' . " \n " ;
echo '<ul class="exports">' ;
2011-05-15 03:56:54 +02:00
echo '<li><img alt="' . _ ( 'Export to CSV' ) . '" src="images/csv.png"/>' . '<a class="affichageexport" href="exportcsv.php?numsondage=' . $numsondage . '">' . _ ( " Export: Spreadsheet " ) . ' (.CSV)' . '</a></li>' ;
2011-05-15 01:32:47 +02:00
2011-05-15 03:56:54 +02:00
if ( ( $dsondage -> format == 'D' || $dsondage -> format == 'D+' ) && $compteursujet == " 1 " && $meilleurecolonne && file_exists ( 'iCalcreator/iCalcreator.class.php' ) && false /* TODO: later */ ) {
echo '<li><img alt="' . _ ( 'Export iCal' ) . '" src="images/ical.png">' . '<a class="affichageexport" href="exportics.php?numsondage=' . $numsondage . '">' . _ ( " Agenda " ) . ' (.ICS)' . '</a></li>' ;
}
2011-05-15 01:32:47 +02:00
2011-05-15 03:56:54 +02:00
echo '</ul>' ;
echo '<a name="bas"></a>' . " \n " ;
2011-06-23 01:21:56 +02:00
echo '</div>' ; // ajout pyg cohérence graphique
2011-05-15 03:56:54 +02:00
bandeau_pied_mobile ();
// Affichage du bandeau de pied
echo '</body>' . " \n " ;
2011-07-04 22:08:39 +02:00
echo '</html>' . " \n " ;