Add STATUS.txt file
[framadate-sandstorm.git] / adminstuds.php
blobcded6fe95e4cf776751449de593b73ff7b1a72b3
1 <?php
2 /**
3 * This software is governed by the CeCILL-B license. If a copy of this license
4 * is not distributed with this file, you can obtain one at
5 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.txt
7 * Authors of STUdS (initial project): Guilhem BORGHESI (borghesi@unistra.fr) and Raphaël DROZ
8 * Authors of Framadate/OpenSondate: Framasoft (https://github.com/framasoft)
10 * =============================
12 * Ce logiciel est régi par la licence CeCILL-B. Si une copie de cette licence
13 * ne se trouve pas avec ce fichier vous pouvez l'obtenir sur
14 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-fr.txt
16 * Auteurs de STUdS (projet initial) : Guilhem BORGHESI (borghesi@unistra.fr) et Raphaël DROZ
17 * Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft)
19 namespace Framadate;
21 session_start();
23 //setlocale(LC_TIME, "fr_FR");
24 include_once __DIR__ . '/app/inc/init.php';
26 if (file_exists('bandeaux_local.php')) {
27 include_once('bandeaux_local.php');
28 } else {
29 include_once('bandeaux.php');
32 // Initialisation des variables
33 $numsondageadmin = false;
34 $sondage = false;
36 // recuperation du numero de sondage admin (24 car.) dans l'URL
37 if (Utils::issetAndNoEmpty('sondage', $_GET) && is_string($_GET['sondage']) && strlen($_GET['sondage']) === 24) {
38 $numsondageadmin=$_GET["sondage"];
39 //on découpe le résultat pour avoir le numéro de sondage (16 car.)
40 $numsondage=substr($numsondageadmin, 0, 16);
43 if (preg_match(";[\w\d]{24};i", $numsondageadmin)) {
44 $sql = 'SELECT * FROM sondage WHERE id_sondage_admin = '.$connect->Param('numsondageadmin');
45 $sql = $connect->Prepare($sql);
46 $sondage = $connect->Execute($sql, array($numsondageadmin));
48 if ($sondage !== false) {
49 $sql = 'SELECT * FROM sujet_studs WHERE id_sondage = '.$connect->Param('numsondage');
50 $sql = $connect->Prepare($sql);
51 $sujets = $connect->Execute($sql, array($numsondage));
53 $sql = 'SELECT * FROM user_studs WHERE id_sondage = '.$connect->Param('numsondage').' order by id_users';
54 $sql = $connect->Prepare($sql);
55 $user_studs = $connect->Execute($sql, array($numsondage));
59 //verification de l'existence du sondage, s'il n'existe pas on met une page d'erreur
60 if (!$sondage || $sondage->RecordCount() != 1){
61 Utils::print_header( _("Error!"));
63 bandeau_titre(_("Error!"));
65 echo '
66 <div class="alert alert-warning">
67 <h2>' . _("This poll doesn't exist !") . '</h2>
68 <p>' . _('Back to the homepage of ') . ' <a href="' . Utils::get_server_name() . '"> ' . NOMAPPLICATION . '</a></p>
69 </div>'."\n";
71 bandeau_pied();
73 die();
76 $dsujet=$sujets->FetchObject(false);
77 $dsondage=$sondage->FetchObject(false);
79 // Send email (only once during the session) to alert admin of the change he made. ==> two modifications (comment, title, description, ...) on differents polls in the same session will generate only one mail.
80 $email_admin = $dsondage->mail_admin;
81 $poll_title = $dsondage->titre;
82 $smtp_allowed = $config['use_smtp'];
83 function send_mail_admin() {
84 global $email_admin;
85 global $poll_title;
86 global $numsondageadmin;
87 global $smtp_allowed;
88 if($smtp_allowed==true){
89 if(!isset($_SESSION["mail_admin_sent"])) {
90 Utils::sendEmail( $email_admin,
91 _("[ADMINISTRATOR] New settings for your poll") . ' ' . stripslashes( $poll_title ),
92 _("You have changed the settings of your poll. \nYou can modify this poll with this link") .
93 " :\n\n" . Utils::getUrlSondage($numsondageadmin, true) . "\n\n" .
94 _("Thanks for your trust.") . "\n" . NOMAPPLICATION
96 $_SESSION["mail_admin_sent"]=true;
102 //si la valeur du nouveau titre est valide et que le bouton est activé
103 if (isset($_POST["boutonnouveautitre"])) {
104 if (Utils::issetAndNoEmpty('nouveautitre') === false) {
105 $err |= TITLE_EMPTY;
106 } else {
107 //Update SQL database with new title
108 $nouveautitre = htmlentities(html_entity_decode($_POST['nouveautitre'], ENT_QUOTES, 'UTF-8'), ENT_QUOTES, 'UTF-8');
109 $sql = 'UPDATE sondage SET titre = '.$connect->Param('nouveautitre').' WHERE id_sondage = '.$connect->Param('numsondage');
110 $sql = $connect->Prepare($sql);
112 //Email sent to the admin
113 if ($connect->Execute($sql, array($nouveautitre, $numsondage))) {
114 send_mail_admin();
119 // si le bouton est activé, quelque soit la valeur du champ textarea
120 if (isset($_POST["boutonnouveauxcommentaires"])) {
121 if (Utils::issetAndNoEmpty('nouveautitre') === false) {
122 $err |= COMMENT_EMPTY;
123 } else {
124 $commentaires = htmlentities(html_entity_decode($_POST['nouveauxcommentaires'], ENT_QUOTES, 'UTF-8'), ENT_QUOTES, 'UTF-8');
126 //Update SQL database with new description
127 $sql = 'UPDATE sondage SET commentaires = '.$connect->Param('commentaires').' WHERE id_sondage = '.$connect->Param('numsondage');
128 $sql = $connect->Prepare($sql);
130 //Email sent to the admin
131 if ($connect->Execute($sql, array($commentaires, $numsondage))) {
132 send_mail_admin();
137 //si la valeur de la nouvelle adresse est valide et que le bouton est activé
138 if (isset($_POST["boutonnouvelleadresse"])) {
139 if (Utils::issetAndNoEmpty('nouvelleadresse') === false || Utils::isValidEmail($_POST["nouvelleadresse"]) === false) {
140 $err |= INVALID_EMAIL;
141 } else {
142 $nouvelleadresse = htmlentities(html_entity_decode($_POST['nouvelleadresse'], ENT_QUOTES, 'UTF-8'), ENT_QUOTES, 'UTF-8');
144 //Update SQL database with new email
145 $sql = 'UPDATE sondage SET mail_admin = '.$connect->Param('nouvelleadresse').' WHERE id_sondage = '.$connect->Param('numsondage');
146 $sql = $connect->Prepare($sql);
148 //Email sent to the admin
149 if ($connect->Execute($sql, array($nouvelleadresse, $numsondage))) {
150 send_mail_admin();
155 //New poll rules
156 if (isset($_POST["btn_poll_rules"])) {
157 echo '<!-- '; print_r($_POST); echo ' -->';
158 if($_POST['poll_rules'] == '+') {
159 $new_poll_rules = substr($dsondage->format, 0, 1).'+';
160 } elseif($_POST['poll_rules'] == '-') {
161 $new_poll_rules = substr($dsondage->format, 0, 1).'-';
162 } else {
163 $new_poll_rules = substr($dsondage->format, 0, 1);
166 //Update SQL database with new rules
167 $sql = 'UPDATE sondage SET format = '.$connect->Param('new_poll_rules').' WHERE id_sondage = '.$connect->Param('numsondage');
168 $sql = $connect->Prepare($sql);
170 //Email sent to the admin
171 if ($connect->Execute($sql, array($new_poll_rules, $numsondage))) {
172 send_mail_admin();
176 // reload
177 $dsujet=$sujets->FetchObject(false);
178 $dsondage=$sondage->FetchObject(false);
180 if (isset($_POST["ajoutsujet"])) {
181 Utils::print_header( _("Add a column") .' - ' . stripslashes( $dsondage->titre ));
183 bandeau_titre(_("Make your polls"));
185 //on recupere les données et les sujets du sondage
187 echo '
188 <div class="row">
189 <div class="col-md-6 col-md-offset-3">
190 <form name="formulaire" class="form-horizontal" action="' . Utils::getUrlSondage($numsondageadmin, true) . '" method="POST">
191 <h2>' . _("Column's adding") . '</h2>'."\n";
193 if (substr($dsondage->format, 0, 1)=="A"){
194 echo '
195 <div class="form-group">
196 <label for="nouvellecolonne" class="col-md-6">' . _("Add a column") .' :</label>
197 <div class="col-md-6">
198 <input type="text" id="nouvellecolonne" name="nouvellecolonne" class="form-control" />
199 </div>
200 </div>'."\n";
201 } else {
202 //ajout d'une date avec creneau horaire
203 echo '
204 <p>'. _("You can add a new scheduling date to your poll.").'<br />'._("If you just want to add a new hour to an existant date, put the same date and choose a new hour.") .'</p>
206 <div class="form-group">
207 <label for="newdate" class="col-md-4">'. _("Day") .'</label>
208 <div class="col-md-8">
209 <div class="input-group date">
210 <span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
211 <input type="text" id="newdate" data-date-format="'. _("dd/mm/yyyy") .'" aria-describedby="dateformat" name="newdate" class="form-control" placeholder="'. _("dd/mm/yyyy") .'" />
212 </div>
213 <span id="dateformat" class="sr-only">'. _("(dd/mm/yyyy)") .'</span>
214 </div>
215 </div>
216 <div class="form-group">
217 <label for="newhour" class="col-md-4">'. _("Time") .'</label>
218 <div class="col-md-8">
219 <input type="text" id="newhour" name="newhour" class="form-control" />
220 </div>
221 </div>';
223 echo '
224 <p class="text-center">
225 <button class="btn btn-default" type="submit" value="retoursondage" name="retoursondage">'. _('Back to the poll'). '</button>
226 <button type="submit" name="ajoutercolonne" class="btn btn-success">'. _('Add a column'). '</button>
227 </p>
228 </form>
229 </div>
230 </div>';
232 bandeau_pied();
234 die();
237 if (isset($_POST["suppressionsondage"])) {
238 Utils::print_header( _("Confirm removal of your poll") .' - ' . stripslashes( $dsondage->titre ));
240 bandeau_titre(_("Confirm removal of your poll"));
242 echo '
243 <form name="formulaire" action="' . Utils::getUrlSondage($numsondageadmin, true) . '" method="POST">
244 <div class="alert alert-warning text-center">
245 <h2>' . _("Confirm removal of your poll") . '</h2>
246 <p><button class="btn btn-default" type="submit" value="" name="annullesuppression">'._("Keep this poll!").'</button>
247 <button type="submit" name="confirmesuppression" value="" class="btn btn-danger">'._("Remove this poll!").'</button></p>
248 </div>
249 </form>';
251 bandeau_pied();
253 die();
256 // Remove all the comments
257 if (isset($_POST["removecomments"])) {
258 $sql = 'DELETE FROM comments WHERE id_sondage='.$connect->Param('numsondage');
259 $sql = $connect->Prepare($sql);
260 $cleaning = $connect->Execute($sql, array($numsondage));
263 // Remove all the votes
264 if (isset($_POST["removevotes"])) {
265 $sql = 'DELETE FROM user_studs WHERE id_sondage='.$connect->Param('numsondage');
266 $sql = $connect->Prepare($sql);
267 $cleaning = $connect->Execute($sql, array($numsondage));
270 //action si bouton confirmation de suppression est activé
271 if (isset($_POST["confirmesuppression"])) {
272 $nbuser=$user_studs->RecordCount();
273 $date=date('H:i:s d/m/Y:');
275 if (Utils::remove_sondage($connect, $numsondage)) {
276 // on ecrit dans le fichier de logs la suppression du sondage
277 error_log($date . " SUPPRESSION: $dsondage->id_sondage\t$dsondage->format\t$dsondage->nom_admin\t$dsondage->mail_admin\n", 3, 'admin/logs_studs.txt');
279 // Email sent
280 send_mail_admin();
281 //affichage de l'ecran de confirmation de suppression de sondage
282 Utils::print_header(_("Your poll has been removed!"));
284 bandeau_titre(_("Make your polls"));
286 echo '
287 <div class="alert alert-success text-center">
288 <h2>' . _("Your poll has been removed!") . '</h2>
289 <p>' . _('Back to the homepage of ') . ' <a href="' . Utils::get_server_name() . '"> ' . NOMAPPLICATION . '</a></p>
290 </div>
291 </form>'."\n";
293 bandeau_pied();
295 die();
299 // quand on ajoute un commentaire utilisateur
300 if (isset($_POST['ajoutcomment'])) {
301 if (Utils::issetAndNoEmpty('commentuser') === false) {
302 $err |= COMMENT_USER_EMPTY;
303 } else {
304 $comment_user = htmlentities(html_entity_decode($_POST["commentuser"], ENT_QUOTES, 'UTF-8'), ENT_QUOTES, 'UTF-8');
307 if(Utils::issetAndNoEmpty('comment') === false) {
308 $err |= COMMENT_EMPTY;
311 if (Utils::issetAndNoEmpty('comment') && !Utils::is_error(COMMENT_EMPTY) && !Utils::is_error(NO_POLL) && !Utils::is_error(COMMENT_USER_EMPTY)) {
312 $comment = htmlentities(html_entity_decode($_POST["comment"], ENT_QUOTES, 'UTF-8'), ENT_QUOTES, 'UTF-8');
314 // Check for doublons
315 $comment_doublon = false;
316 $req = 'SELECT * FROM comments WHERE id_sondage='.$connect->Param('numsondage').' ORDER BY id_comment';
317 $sql = $connect->Prepare($req);
318 $comment_user_doublon = $connect->Execute($sql, array($numsondage));
319 if ($comment_user_doublon->RecordCount() != 0) {
320 while ( $dcomment_user_doublon=$comment_user_doublon->FetchNextObject(false)) {
321 if($dcomment_user_doublon->comment == $comment && $dcomment_user_doublon->usercomment == $comment_user) {
322 $comment_doublon = true;
327 if(!$comment_doublon) {
328 $req = 'INSERT INTO comments (id_sondage, comment, usercomment) VALUES ('.
329 $connect->Param('id_sondage').','.
330 $connect->Param('comment').','.
331 $connect->Param('comment_user').')';
332 $sql = $connect->Prepare($req);
334 $comments = $connect->Execute($sql, array($numsondage, $comment, $comment_user));
335 if ($comments === false) {
336 $err |= COMMENT_INSERT_FAILED;
342 $nbcolonnes = substr_count($dsujet->sujet, ',') + 1;
343 $nblignes = $user_studs->RecordCount();
345 //si il n'y a pas suppression alors on peut afficher normalement le tableau
347 //action si le bouton participer est cliqué
348 if (isset($_POST["boutonp"])) {
349 //si on a un nom dans la case texte
350 if (Utils::issetAndNoEmpty('nom')){
351 $nouveauchoix = '';
352 $erreur_prenom = false;
354 for ($i=0;$i<$nbcolonnes;$i++){
355 // radio checked 1 = Yes, 2 = Ifneedbe, 0 = No
356 if (isset($_POST["choix$i"])) {
357 switch ($_POST["choix$i"]) {
358 case 1: $nouveauchoix .= "1";break;
359 case 2: $nouveauchoix .= "2";break;
360 default: $nouveauchoix .= "0";break;
365 $nom = htmlentities(html_entity_decode($_POST["nom"], ENT_QUOTES, 'UTF-8'), ENT_QUOTES, 'UTF-8');
367 while($user = $user_studs->FetchNextObject(false)) {
368 if ($nom == $user->nom){
369 $erreur_prenom="yes";
373 // Ecriture des choix de l'utilisateur dans la base
374 if (!$erreur_prenom) {
375 $sql = 'INSERT INTO user_studs (nom, id_sondage, reponses) VALUES ('.
376 $connect->Param('nom').','.
377 $connect->Param('numsondage').','.
378 $connect->Param('nouveauchoix').')';
380 $sql = $connect->Prepare($sql);
381 $connect->Execute($sql, array($nom, $numsondage, $nouveauchoix));
387 //action quand on ajoute une colonne au format AUTRE
388 if (isset($_POST["ajoutercolonne"]) && Utils::issetAndNoEmpty('nouvellecolonne') && (substr($dsondage->format, 0, 1) == "A" )) {
389 $nouveauxsujets=$dsujet->sujet;
391 //on rajoute la valeur a la fin de tous les sujets deja entrés
392 $nouveauxsujets.=",";
393 $nouveauxsujets.=str_replace(","," ",$_POST["nouvellecolonne"]);
394 $nouveauxsujets = htmlentities(html_entity_decode($nouveauxsujets, ENT_QUOTES, 'UTF-8'), ENT_QUOTES, 'UTF-8');
396 //mise a jour avec les nouveaux sujets dans la base
397 $sql = 'UPDATE sujet_studs SET sujet = '.$connect->Param('nouveauxsujets').' WHERE id_sondage = '.$connect->Param('numsondage');
398 $sql = $connect->Prepare($sql);
399 if ($connect->Execute($sql, array($nouveauxsujets, $numsondage))) {
400 send_mail_admin();
404 $erreur_ajout_date = false;
405 //action quand on ajoute une colonne au format DATE
406 if (isset($_POST["ajoutercolonne"]) && (substr($dsondage->format, 0, 1) == "D")) {
407 $nouveauxsujets=$dsujet->sujet;
409 if (isset($_POST["newdate"]) && $_POST["newdate"] != "") {
410 $nouvelledate=mktime(0, 0, 0, substr($_POST["newdate"],3,2), substr($_POST["newdate"],0,2), substr($_POST["newdate"],6,4));
412 if (isset($_POST["newhour"]) && $_POST["newhour"]!=""){
413 $nouvelledate.="@";
414 $nouvelledate.=$_POST["newhour"];
417 //on rajoute la valeur dans les valeurs
418 $datesbase = explode(",",$dsujet->sujet);
419 $taillebase = sizeof($datesbase);
421 //recherche de l'endroit de l'insertion de la nouvelle date dans les dates deja entrées dans le tableau
422 if ($nouvelledate < $datesbase[0]) {
423 $cleinsertion = 0;
424 } elseif ($nouvelledate > $datesbase[$taillebase-1]) {
425 $cleinsertion = count($datesbase);
426 } else {
427 for ($i = 0; $i < count($datesbase); $i++) {
428 $j = $i + 1;
429 if ($nouvelledate > $datesbase[$i] && $nouvelledate < $datesbase[$j]) {
430 $cleinsertion = $j;
435 array_splice($datesbase, $cleinsertion, 0, $nouvelledate);
436 $cle = array_search($nouvelledate, $datesbase);
437 $dateinsertion = '';
438 for ($i = 0; $i < count($datesbase); $i++) {
439 $dateinsertion.=",";
440 $dateinsertion.=$datesbase[$i];
443 $dateinsertion = substr("$dateinsertion", 1);
445 //mise a jour avec les nouveaux sujets dans la base
447 $sql = 'UPDATE sujet_studs SET sujet = '.$connect->Param('dateinsertion').' WHERE id_sondage = '.$connect->Param('numsondage');
448 $sql = $connect->Prepare($sql);
449 $connect->Execute($sql, array($dateinsertion, $numsondage));
451 /* Doesn't work → 30/11/-0001
452 if ($nouvelledate > strtotime($dsondage->date_fin)) {
453 $date_fin=$nouvelledate+200000;
454 $sql = 'UPDATE sondage SET date_fin = '.$connect->Param('date_fin').' WHERE id_sondage = '.$connect->Param('numsondage');
455 $sql = $connect->Prepare($sql);
456 $connect->Execute($sql, array($date_fin, $numsondage));
459 //mise a jour des reponses actuelles correspondant au sujet ajouté
460 $sql = 'UPDATE user_studs SET reponses = '.$connect->Param('reponses').' WHERE nom = '.$connect->Param('nom').' AND id_users='.$connect->Param('id_users');
461 $sql = $connect->Prepare($sql);
462 while ($data = $user_studs->FetchNextObject(false)) {
463 $ensemblereponses=$data->reponses;
464 $newcar = '';
466 //parcours de toutes les réponses actuelles
467 for ($j = 0; $j < $nbcolonnes; $j++) {
468 $car=substr($ensemblereponses,$j,1);
470 //si les reponses ne concerne pas la colonne ajoutée, on concatene
471 if ($j==$cle) {
472 $newcar.="0";
475 $newcar.=$car;
478 //mise a jour des reponses utilisateurs dans la base
479 if (isset($erreur_ajout_date) && !$erreur_ajout_date){
480 $connect->Execute($sql, array($newcar, $data->nom, $data->id_users));
484 //Email sent to the admin
485 send_mail_admin();
487 } else {
488 $erreur_ajout_date = true;
493 //suppression de ligne dans la base
494 for ($i = 0; $i < $nblignes; $i++) {
495 if (isset($_POST["effaceligne$i"])) {
496 $compteur=0;
497 $sql = 'DELETE FROM user_studs WHERE nom = '.$connect->Param('nom').' AND id_users = '.$connect->Param('id_users');
498 $sql = $connect->Prepare($sql);
500 while ($data=$user_studs->FetchNextObject(false)) {
501 if ($compteur==$i){
502 $connect->Execute($sql, array($data->nom, $data->id_users));
505 $compteur++;
511 //suppression d'un commentaire utilisateur
512 $sql = 'SELECT * FROM comments WHERE id_sondage='.$connect->Param('numsondage').' ORDER BY id_comment';
513 $sql = $connect->Prepare($sql);
514 $comment_user = $connect->Execute($sql, array($numsondage));
515 $i = 0;
516 while ($dcomment = $comment_user->FetchNextObject(false)) {
517 if (isset($_POST['suppressioncomment'.$i])) {
518 $sql = 'DELETE FROM comments WHERE id_comment = '.$connect->Param('id_comment');
519 $sql = $connect->Prepare($sql);
520 $connect->Execute($sql, array($dcomment->id_comment));
523 $i++;
527 //on teste pour voir si une ligne doit etre modifiée
528 $testmodifier = false;
529 $testligneamodifier = false;
531 for ($i = 0; $i < $nblignes; $i++) {
532 if (isset($_POST["modifierligne$i"])) {
533 $ligneamodifier=$i;
534 $testligneamodifier="true";
537 //test pour voir si une ligne est a modifier
538 if (isset($_POST["validermodifier$i"])) {
539 $modifier=$i;
540 $testmodifier="true";
545 //si le test est valide alors on affiche des checkbox pour entrer de nouvelles valeurs
546 if ($testmodifier) {
547 $nouveauchoix = '';
548 for ($i = 0; $i < $nbcolonnes; $i++) {
549 // radio checked 1 = Yes, 2 = Ifneedbe, 0 = No
550 if (isset($_POST["choix$i"])) {
551 switch ($_POST["choix$i"]) {
552 case 1: $nouveauchoix .= "1";break;
553 case 2: $nouveauchoix .= "2";break;
554 default: $nouveauchoix .= "0";break;
559 $compteur=0;
561 while ($data=$user_studs->FetchNextObject(false)) {
562 //mise a jour des données de l'utilisateur dans la base SQL
563 if ($compteur==$modifier) {
564 $sql = 'UPDATE user_studs SET reponses = '.$connect->Param('reponses').' WHERE nom = '.$connect->Param('nom').' AND id_users = '.$connect->Param('id_users');
565 $sql = $connect->Prepare($sql);
566 $connect->Execute($sql, array($nouveauchoix, $data->nom, $data->id_users));
569 $compteur++;
574 //suppression de colonnes dans la base
575 for ($i = 0; $i < $nbcolonnes; $i++) {
576 if ((isset($_POST["effacecolonne$i"])) && $nbcolonnes > 1){
577 $toutsujet = explode(",",$dsujet->sujet);
578 //sort($toutsujet, SORT_NUMERIC);
579 $j = 0;
580 $nouveauxsujets = '';
582 //parcours de tous les sujets actuels
583 while (isset($toutsujet[$j])) {
584 //si le sujet n'est pas celui qui a été effacé alors on concatene
585 if ($i != $j) {
586 $nouveauxsujets .= ',';
587 $nouveauxsujets .= $toutsujet[$j];
590 $j++;
593 //on enleve la virgule au début
594 $nouveauxsujets = substr("$nouveauxsujets", 1);
596 //nettoyage des reponses actuelles correspondant au sujet effacé
597 $compteur = 0;
598 $sql = 'UPDATE user_studs SET reponses = '.$connect->Param('reponses').' WHERE nom = '.$connect->Param('nom').' AND id_users = '.$connect->Param('id_users');
599 $sql = $connect->Prepare($sql);
601 while ($data = $user_studs->FetchNextObject(false)) {
602 $newcar = '';
603 $ensemblereponses = $data->reponses;
605 //parcours de toutes les réponses actuelles
606 for ($j = 0; $j < $nbcolonnes; $j++) {
607 $car=substr($ensemblereponses, $j, 1);
608 //si les reponses ne concerne pas la colonne effacée, on concatene
609 if ($i != $j) {
610 $newcar .= $car;
614 $compteur++;
616 //mise a jour des reponses utilisateurs dans la base
617 $connect->Execute($sql, array($newcar, $data->nom, $data->id_users));
620 //mise a jour des sujets dans la base
621 $sql = 'UPDATE sujet_studs SET sujet = '.$connect->Param('nouveauxsujets').' WHERE id_sondage = '.$connect->Param('numsondage');
622 $sql = $connect->Prepare($sql);
623 $connect->Execute($sql, array($nouveauxsujets, $numsondage));
628 //recuperation des donnes de la base
629 $sql = 'SELECT * FROM sondage WHERE id_sondage_admin = '.$connect->Param('numsondageadmin');
630 $sql = $connect->Prepare($sql);
631 $sondage = $connect->Execute($sql, array($numsondageadmin));
633 if ($sondage !== false) {
634 $sql = 'SELECT * FROM sujet_studs WHERE id_sondage = '.$connect->Param('numsondage');
635 $sql = $connect->Prepare($sql);
636 $sujets = $connect->Execute($sql, array($numsondage));
638 $sql = 'SELECT * FROM user_studs WHERE id_sondage = '.$connect->Param('numsondage').' order by id_users';
639 $sql = $connect->Prepare($sql);
640 $user_studs = $connect->Execute($sql, array($numsondage));
641 } else {
643 Utils::print_header(_("Error!"));
644 bandeau_titre(_("Error!"));
646 echo '
647 <div class="alert alert-warning">
648 <h2>' . _("This poll doesn't exist !") . '</h2>
649 <p>' . _('Back to the homepage of ') . ' <a href="' . Utils::get_server_name() . '"> ' . NOMAPPLICATION . '</a></p>
650 </div>'."\n";
652 bandeau_pied();
654 die();
657 // Errors
658 $errors = '';
659 if ((isset($_POST["boutonp"])) && $_POST["nom"] == "") {
660 $errors .= '<li>' . _("Enter a name") . '</li>';
662 if (isset($erreur_prenom) && $erreur_prenom) {
663 $errors .= '<li>' . _("The name you've chosen already exist in this poll!") . '</li>';
665 if (isset($erreur_injection) && $erreur_injection) {
666 $errors .= '<li>' . _("Characters \" ' < et > are not permitted") . '</li>';
668 if (isset($erreur_ajout_date) && $erreur_ajout_date) {
669 $errors .= '<li>' . _("The date is not correct !") . '</li>';
672 //Poll title, description and email values
673 $title = (isset($_POST["boutonnouveautitre"]) && Utils::issetAndNoEmpty('nouveautitre')) ? htmlentities(html_entity_decode($_POST['nouveautitre'], ENT_QUOTES, 'UTF-8'), ENT_QUOTES, 'UTF-8') : stripslashes( $dsondage->titre );
674 $description = (isset($_POST["nouveauxcommentaires"])) ? stripslashes(htmlentities(html_entity_decode($_POST['nouveauxcommentaires'], ENT_QUOTES, 'UTF-8'), ENT_QUOTES, 'UTF-8')) : stripslashes( $dsondage->commentaires );
675 $email_admin = (isset($_POST["boutonnouvelleadresse"]) && Utils::issetAndNoEmpty('nouvelleadresse')) ? htmlentities(html_entity_decode($_POST['nouvelleadresse'], ENT_QUOTES, 'UTF-8'), ENT_QUOTES, 'UTF-8') : stripslashes( $dsondage->mail_admin );
677 //Poll format (locked A-/D-, open A/D, editable A+/D+)
678 $poll_rules = (isset($_POST["poll_rules"]) && Utils::issetAndNoEmpty('btn_poll_rules')) ? $_POST["poll_rules"] : substr($dsondage->format, 1, 1);
679 $poll_rules_opt1 = '';$poll_rules_opt2 = '';$poll_rules_opt3 = '';
680 if($poll_rules == '+') {
681 $poll_rules_text = '<span class="glyphicon glyphicon-edit"></span> '. _("Votes are editable");
682 $poll_rules_opt3 = 'selected';
683 } elseif($poll_rules == '-') {
684 $poll_rules_text = '<span class="glyphicon glyphicon-lock"></span> '. _("Votes and comments are locked");
685 $poll_rules_opt1 = 'selected';
686 } else {
687 $poll_rules_text = '<span class="glyphicon glyphicon-check"></span> '. _("Votes and comments are open");
688 $poll_rules_opt2 = 'selected';
691 if ($errors!='') {
692 Utils::print_header(_("Error!"));
693 bandeau_titre(_("Error!"));
695 echo '<div class="alert alert-danger"><ul class="list-unstyled">'.$errors.'</ul></div>'."\n";
697 } else {
698 Utils::print_header(_('Poll administration').' - '.$title);
699 bandeau_titre(_('Poll administration').' - '.$title);
701 // session_unset();
704 echo '
705 <form name="formulaire4" action="' . Utils::getUrlSondage($numsondageadmin, true) . '" method="POST">
706 <div class="jumbotron bg-danger">
707 <div class="row">
708 <div class="col-md-7" id="title-form">
709 <h3>'.$title.'<button class="btn btn-link btn-sm btn-edit" title="'. _('Edit the title') .'"> <span class="glyphicon glyphicon-pencil"></span><span class="sr-only">' . _('Edit') . '</span></button></h3>
710 <div class="hidden js-title">
711 <label class="sr-only" for="newtitle">'. _("Title") .'</label>
712 <div class="input-group">
713 <input type="text" class="form-control" id="newtitle" name="nouveautitre" size="40" value="'.$title.'" />
714 <span class="input-group-btn">
715 <button type="submit" class="btn btn-success" name="boutonnouveautitre" value="1" title="'. _('Save the new title') .'"><span class="glyphicon glyphicon-ok"></span><span class="sr-only">' . _('Save') . '</span></button>
716 <button class="btn btn-link btn-cancel" title="'. _('Cancel the title edit') .'"><span class="glyphicon glyphicon-remove"></span><span class="sr-only">' . _('Cancel') . '</span></button>
717 </span>
718 </div>
719 </div>
720 </div>
721 <div class="col-md-5">
722 <div class="btn-group pull-right">
723 <button onclick="javascript:print(); return false;" class="btn btn-default"><span class="glyphicon glyphicon-print"></span> ' . _('Print') . '</button>
724 <button onclick="window.location.href=\'' . Utils::get_server_name() . 'exportcsv.php?numsondage=' . $numsondage . '\';return false;" class="btn btn-default"><span class="glyphicon glyphicon-download-alt"></span> ' . _('Export to CSV') . '</button>
725 <button type="button" class="btn btn-danger dropdown-toggle" data-toggle="dropdown">
726 <span class="glyphicon glyphicon-trash"></span> <span class="sr-only">' . _("Remove") . '</span> <span class="caret"></span>
727 </button>
728 <ul class="dropdown-menu" role="menu">
729 <li><button class="btn btn-link" type="submit" name="removevotes">' . _('Remove all the votes') . '</button></li>
730 <li><button class="btn btn-link" type="submit" name="removecomments">' . _('Remove all the comments') . '</button></li>
731 <li class="divider" role="presentation"></li>
732 <li><button class="btn btn-link" type="submit" id="suppressionsondage" name="suppressionsondage" value="" >'. _("Remove the poll") .'</button></li>
733 </ul>
734 </div>
735 </div>
736 </div>
737 <div class="row">
738 <div class="col-md-5">
739 <div class="form-group" >
740 <div id="author-form">
741 <h4 class="control-label">'. _("Initiator of the poll") .'</h4>
742 <p> '.stripslashes($dsondage->nom_admin).'</p>
743 </div>
744 <div id="email-form">
745 <p>'.$email_admin.'<button class="btn btn-link btn-sm btn-edit" title="'. _('Edit the email adress') .'"><span class="glyphicon glyphicon-pencil"></span><span class="sr-only">' . _('Edit') . '</span></button></p>
746 <div class="hidden js-email">
747 <label class="sr-only" for="newemail">'. _("Email adress") .'</label>
748 <div class="input-group">
749 <input type="text" class="form-control" id="newemail" name="nouvelleadresse" size="40" value="'.$email_admin.'" />
750 <span class="input-group-btn">
751 <button type="submit" name="boutonnouvelleadresse" value="1" class="btn btn-success" title="'. _('Save the email address ') .'"><span class="glyphicon glyphicon-ok"></span><span class="sr-only">' . _('Save') . '</span></button>
752 <button class="btn btn-link btn-cancel" title="'. _('Cancel the email address edit') .'"><span class="glyphicon glyphicon-remove"></span><span class="sr-only">' . _('Cancel') . '</span></button>
753 </span>
754 </div>
755 </div>
756 </div>
757 </div>
758 </div>
759 <div class="form-group col-md-7" id="description-form">
760 <h4 class="control-label">'._("Description") .'</h4><button class="btn btn-link btn-sm btn-edit" title="'. _('Edit the description') .'"><span class="glyphicon glyphicon-pencil"></span><span class="sr-only">' . _('Edit') . '</span></button><br />
761 <p class="well">'.$description.'</p>
762 <div class="hidden js-desc text-right">
763 <label class="sr-only" for="newdescription">'._("Description") .'</label>
764 <textarea class="form-control" id="newdescription" name="nouveauxcommentaires" rows="2" cols="40">'.$description.'</textarea>
765 <button type="submit" id="btn-new-desc" name="boutonnouveauxcommentaires" value="1" class="btn btn-sm btn-success" title="'. _("Save the description") .'">'. _("Save") .'</button>
766 <button class="btn btn-default btn-sm btn-cancel" title="'. _('Cancel the description edit') .'">'. _('Cancel') .'</button>
767 </div>
768 </div>
769 </div>
770 <div class="row">
771 <div class="form-group col-md-5">
772 <label for="public-link"><a class="public-link" href="' . Utils::getUrlSondage($dsondage->id_sondage) . '">'._("Public link of the poll") .' <span class="btn-link glyphicon glyphicon-link"></span></a></label>
773 <input class="form-control" id="public-link" type="text" readonly="readonly" value="' . Utils::getUrlSondage($dsondage->id_sondage) . '" />
774 </div>
775 <div class="form-group col-md-5">
776 <label for="admin-link"><a class="admin-link" href="' . Utils::getUrlSondage($numsondageadmin, true) . '">'._("Admin link of the poll") .' <span class="btn-link glyphicon glyphicon-link"></span></a></label>
777 <input class="form-control" id="admin-link" type="text" readonly="readonly" value="' . Utils::getUrlSondage($numsondageadmin, true) . '" />
778 </div>
779 <div class="form-group col-md-2">
780 <h4 class="control-label">'. _("Expiration's date") .'</h4>
781 <p>'.date("d/m/Y",strtotime($dsondage->date_fin)).'</p>
782 </div>
783 </div>
784 <div class="row">
785 <div class="col-md-5 col-md-offset-7" >
786 <div id="poll-rules-form">
787 <p class="pull-right">'.$poll_rules_text.'<button class="btn btn-link btn-sm btn-edit" title="'. _('Edit the poll rules') .'"><span class="glyphicon glyphicon-pencil"></span><span class="sr-only">' . _('Edit') . '</span></button></p>
788 <div class="hidden js-poll-rules">
789 <label class="sr-only" for="newrules">'. _("Poll rules") .'</label>
790 <div class="input-group">
791 <select class="form-control" id="newrules" name="poll_rules">
792 <option value="-" '.$poll_rules_opt1.'>'. _("Votes and comments are locked") .'</option>
793 <option value="0" '.$poll_rules_opt2.'>'. _("Votes and comments are open") .'</option>
794 <option value="+" '.$poll_rules_opt3.'>'. _("Votes are editable") .'</option>
795 </select>
796 <span class="input-group-btn">
797 <button type="submit" name="btn_poll_rules" value="1" class="btn btn-success" title="'. _('Save the new rules') .'"><span class="glyphicon glyphicon-ok"></span><span class="sr-only">' . _('Save') . '</span></button>
798 <button class="btn btn-link btn-cancel" title="'. _('Cancel the rules edit') .'"><span class="glyphicon glyphicon-remove"></span><span class="sr-only">' . _('Cancel') . '</span></button>
799 </span>
800 </div>
801 </div>
802 </div>
803 </div>
804 </div>
805 </div>
806 </form>'."\n"; // .jumbotron
808 //on recupere les données et les sujets du sondage
809 $dsujet=$sujets->FetchObject(false);
810 $dsondage=$sondage->FetchObject(false);
812 //reformatage des données des sujets du sondage
813 $toutsujet=explode(",",$dsujet->sujet);
814 $toutsujet=str_replace("°","'",$toutsujet);
815 $nbcolonnes=substr_count($dsujet->sujet,',')+1;
817 // Table headers
818 $thead = '<thead>';
820 // Button in the first td to avoid remove col on "Return" keypress)
821 $tr_add_remove_col = '<tr><td role="presentation"><button type="submit" class="invisible" name="boutonp" ></button></td>';
823 $border = array(); // bordure pour distinguer les mois
824 $td_headers = array(); // for a11y, headers="M1 D4 H5" on each td
825 $radio_title = array(); // date for
827 // Dates poll
828 if (substr($dsondage->format, 0, 1)=="D") {
830 $tr_months = '<tr><th role="presentation"></th>';
831 $tr_days = '<tr><th role="presentation"></th>';
832 $tr_hours = '<tr><th role="presentation"></th>';
834 // Headers
835 $colspan_month = 1;
836 $colspan_day = 1;
838 for ($i = 0; $i < count($toutsujet); $i++) {
840 // Current date
841 $current = $toutsujet[$i];//format date@hour. ex : 2020292820@10:00
842 $horoCur = explode("@",$current); //horoCur[0] = date, horoCur[1] = hour
843 if (isset($toutsujet[$i+1])){
844 $next = $toutsujet[$i+1];
845 $horoNext = explode("@",$next);
847 $border[$i] = false;
848 $radio_title[$i] = strftime($date_format['txt_short'],$horoCur[0]);
850 // Months
851 $td_headers[$i] = 'M'.($i+1-$colspan_month);
853 if (isset($toutsujet[$i+1]) && strftime("%B", $horoCur[0]) == strftime("%B", $horoNext[0]) && strftime("%Y", $horoCur[0]) == strftime("%Y", $horoNext[0])){
854 $colspan_month++;
855 } else {
856 $border[$i] = true;
857 $tr_months .= '<th colspan="'.$colspan_month.'" class="bg-primary month" id="M'.($i+1-$colspan_month).'">'.strftime("%B",$horoCur[0]).' '.strftime("%Y", $horoCur[0]).'</th>';
858 $colspan_month=1;
861 // Days
862 $td_headers[$i] .= ' D'.($i+1-$colspan_day);
864 if (isset($toutsujet[$i+1]) && strftime($date_format['txt_day'],$horoCur[0])==strftime($date_format['txt_day'],$horoNext[0]) && strftime("%B",$horoCur[0])==strftime("%B",$horoNext[0])){
865 $colspan_day++;
866 } else {
867 $rbd = ($border[$i]) ? ' rbd' : '';
868 $tr_days .= '<th colspan="'.$colspan_day.'" class="bg-primary day'.$rbd.'" id="D'.($i+1-$colspan_day).'">'.strftime($date_format['txt_day'],$horoCur[0]).'</th>';
869 $colspan_day=1;
872 // Hours
873 $rbd = ($border[$i]) ? ' rbd' : '';
874 if (isset($horoCur[1]) && $horoCur[1] !== '') {
875 $tr_hours .= '<th class="bg-info'.$rbd.'" id="H'.$i.'" title="'.$horoCur[1].'">'.$horoCur[1].'</th>';
876 $radio_title[$i] .= ' - '.$horoCur[1];
877 $td_headers[$i] .= ' H'.$i;
878 } else {
879 $tr_hours .= '<th class="bg-info'.$rbd.'"></th>';
882 // Remove col
883 $tr_add_remove_col .= (count($toutsujet) > 1 ) ? '<td headers="'.$td_headers[$i].'"><button type="submit" name="effacecolonne'.$i.'" class="btn btn-link btn-sm" title="' . _('Remove the column') . ' ' .$radio_title[$i]. '"><span class="glyphicon glyphicon-remove text-danger"></span><span class="sr-only">'. _("Remove") .'</span></button></td>' : '<td role="presentation"></td>';
887 $border[count($border)-1] = false; // suppression de la bordure droite du dernier mois
889 $tr_months .= '<th></th></tr>';
890 $tr_days .= '<th></th></tr>';
891 $tr_hours .= '<th></th></tr>';
893 // Add col
894 $tr_add_remove_col .= '<td><button type="submit" name="ajoutsujet" class="btn btn-link btn-sm" title="'. _('Add a column') . '"><span class="glyphicon glyphicon-plus text-success"></span><span class="sr-only">'. _("Add a column") .'</span></button></td></tr>';
896 $thead = "\n".$tr_add_remove_col."\n".$tr_months."\n".$tr_days."\n".$tr_hours."\n";
898 // Subjects poll
899 } else {
900 $toutsujet=str_replace("@","<br />",$toutsujet);
902 $tr_subjects = '<tr><th role="presentation"></th>';
904 for ($i = 0; isset($toutsujet[$i]); $i++) {
906 $td_headers[$i]='';$radio_title[$i]=''; // init before concatenate
908 // Subjects
909 preg_match_all('/\[!\[(.*?)\]\((.*?)\)\]\((.*?)\)/',$toutsujet[$i],$md_a_img); // Markdown [![alt](src)](href)
910 preg_match_all('/!\[(.*?)\]\((.*?)\)/',$toutsujet[$i],$md_img); // Markdown ![alt](src)
911 preg_match_all('/\[(.*?)\]\((.*?)\)/',$toutsujet[$i],$md_a); // Markdown [text](href)
912 if (isset($md_a_img[2][0]) && $md_a_img[2][0]!='' && isset($md_a_img[3][0]) && $md_a_img[3][0]!='') { // [![alt](src)](href)
914 $th_subject_text = (isset($md_a_img[1][0]) && $md_a_img[1][0]!='') ? stripslashes($md_a_img[1][0]) : _("Choice") .' '.($i+1);
915 $th_subject_html = '<a href="'.$md_a_img[3][0].'"><img src="'.$md_a_img[2][0].'" class="img-responsive" alt="'.$th_subject_text.'" /></a>';
917 } elseif (isset($md_img[2][0]) && $md_img[2][0]!='') { // ![alt](src)
919 $th_subject_text = (isset($md_img[1][0]) && $md_img[1][0]!='') ? stripslashes($md_img[1][0]) : _("Choice") .' '.($i+1);
920 $th_subject_html = '<img src="'.$md_img[2][0].'" class="img-responsive" alt="'.$th_subject_text.'" />';
922 } elseif (isset($md_a[2][0]) && $md_a[2][0]!='') { // [text](href)
924 $th_subject_text = (isset($md_a[1][0]) && $md_a[1][0]!='') ? stripslashes($md_a[1][0]) : _("Choice") .' '.($i+1);
925 $th_subject_html = '<a href="'.$md_a[2][0].'">'.$th_subject_text.'</a>';
927 } else { // text only
929 $th_subject_text = stripslashes($toutsujet[$i]);
930 $th_subject_html = $th_subject_text;
933 $tr_subjects .= '<th class="bg-info" id="S'.$i.'" title="'.$th_subject_text.'">'.$th_subject_html.'</th>';
935 $border[$i] = false;
936 $td_headers[$i] .= 'S'.$i;
937 $radio_title[$i] .= $th_subject_text;
939 // Remove col
940 $tr_add_remove_col .= '<td headers="'.$td_headers[$i].'"><button type="submit" name="effacecolonne'.$i.'" class="btn btn-link btn-sm" title="' . _('Remove the column') . ' '. $radio_title[$i] .'"><span class="glyphicon glyphicon-remove text-danger"></span><span class="sr-only">' . _('Remove') .'</span></button></td>';
943 // Add col
944 $tr_add_remove_col .= '<td><button type="submit" name="ajoutsujet" class="btn btn-link btn-sm" title="'. _('Add a column') . '"><span class="glyphicon glyphicon-plus text-success"></span><span class="sr-only">'. _("Add a column") .'</span></button></td></tr>';
946 $thead = $tr_add_remove_col.$tr_subjects.'<th></th></tr>';
949 // Print headers
950 echo '
951 <form name="formulaire" action="' . Utils::getUrlSondage($numsondageadmin, true) . '" method="POST">
953 <div class="alert alert-info">
954 <p>' . _('As poll administrator, you can change all the lines of this poll with this button ').'<span class="glyphicon glyphicon-pencil"></span><span class="sr-only">' . _('Edit') . '</span>,
955 ' . _(' remove a column or a line with ') . '<span class="glyphicon glyphicon-remove text-danger"></span><span class="sr-only">' . _('Remove') . '</span>
956 ' . _('and add a new column with '). '<span class="glyphicon glyphicon-plus text-success"></span><span class="sr-only">'. _('Add a column') . '</span></p>
957 <p>' . _('Finally, you can change the informations of this poll like the title, the comments or your email address.') . '</p>
958 <p aria-hidden="true"><b>' . _('Legend:'). '</b> <span class="glyphicon glyphicon-ok"></span> =' . _('Yes') . ', <b>(<span class="glyphicon glyphicon-ok"></span>)</b> = ' . _('Ifneedbe') . ', <span class="glyphicon glyphicon-ban-circle"></span> = ' . _('No') . '</p>
959 </div>
961 <div class="hidden row scroll-buttons" aria-hidden="true">
962 <div class="btn-group pull-right">
963 <button class="btn btn-sm btn-link scroll-left" title="' . _('Scroll to the left') . '">
964 <span class="glyphicon glyphicon-chevron-left"></span>
965 </button>
966 <button class="btn btn-sm btn-link scroll-right" title="' . _('Scroll to the right') . '">
967 <span class="glyphicon glyphicon-chevron-right"></span>
968 </button>
969 </div>
970 </div>
972 <h3>'._('Votes of the poll ').'</h3>
973 <div id="tableContainer" class="tableContainer">
974 <table class="results">
975 <caption class="sr-only">'._('Votes of the poll ').$title.'</caption>
976 <thead>'. $thead . '</thead>
977 <tbody>';
979 // Print poll results
980 $somme[] = 0;
981 $compteur = 0;
983 while ($data = $user_studs->FetchNextObject(false)) {
985 $ensemblereponses = $data->reponses;
987 // Print name
988 $nombase=str_replace("°","'",$data->nom);
989 echo '<tr>
990 <th class="bg-info">'.stripslashes($nombase).'</th>'."\n";
992 // si la ligne n'est pas a changer, on affiche les données
993 if (!$testligneamodifier) {
994 for ($k = 0; $k < $nbcolonnes; $k++) {
995 $rbd = ($border[$k]) ? ' rbd' : '';
996 $car = substr($ensemblereponses, $k, 1);
997 switch ($car) {
998 case "1": echo '<td class="bg-success text-success'.$rbd.'" headers="'.$td_headers[$k].'"><span class="glyphicon glyphicon-ok"></span><span class="sr-only"> ' . _('Yes') . '</span></td>'."\n";
999 if (isset($somme[$k]) === false) {
1000 $somme[$k] = 0;
1002 $somme[$k]++; break;
1003 case "2": echo '<td class="bg-warning text-warning'.$rbd.'" headers="'.$td_headers[$k].'">(<span class="glyphicon glyphicon-ok"></span>)<span class="sr-only"> ' . _('Yes') . _(', ifneedbe') . '</span></td>'."\n"; break;
1004 default: echo '<td class="bg-danger'.$rbd.'" headers="'.$td_headers[$k].'"><span class="sr-only">' . _('No') . '</span></td>'."\n";break;
1007 } else { // sinon on remplace les choix de l'utilisateur par une ligne de radio pour recuperer de nouvelles valeurs
1008 // si c'est bien la ligne a modifier on met les radios
1009 if ($compteur == "$ligneamodifier") {
1010 for ($j = 0; $j < $nbcolonnes; $j++) {
1012 $car = substr($ensemblereponses, $j, 1);
1014 // variable pour afficher la valeur cochée
1015 $car_html[0]='value="0"';$car_html[1]='value="1"';$car_html[2]='value="2"';
1016 switch ($car) {
1017 case "1": $car_html[1]='value="1" checked';break;
1018 case "2": $car_html[2]='value="2" checked';break;
1019 default: $car_html[0]='value="0" checked';break;
1022 echo '
1023 <td class="bg-info" headers="'.$td_headers[$j].'">
1024 <ul class="list-unstyled choice">
1025 <li class="yes">
1026 <input type="radio" id="y-choice-'.$j.'" name="choix'.$j.'" '.$car_html[1].' />
1027 <label class="btn btn-default btn-xs" for="y-choice-'.$j.'" title="' . _('Vote "yes" for ') . $radio_title[$j] . '">
1028 <span class="glyphicon glyphicon-ok"></span><span class="sr-only">' . _('Yes') . '</span>
1029 </label>
1030 </li>
1031 <li class="ifneedbe">
1032 <input type="radio" id="i-choice-'.$j.'" name="choix'.$j.'" '.$car_html[2].' />
1033 <label class="btn btn-default btn-xs" for="i-choice-'.$j.'" title="' . _('Vote "ifneedbe" for ') . $radio_title[$j] . '">
1034 (<span class="glyphicon glyphicon-ok"></span>)<span class="sr-only">' . _('Ifneedbe') . '</span>
1035 </label>
1036 </li>
1037 <li class="no">
1038 <input type="radio" id="n-choice-'.$j.'" name="choix'.$j.'" '.$car_html[0].'/>
1039 <label class="btn btn-default btn-xs" for="n-choice-'.$j.'" title="' . _('Vote "no" for ') . $radio_title[$j] . '">
1040 <span class="glyphicon glyphicon-ban-circle"></span><span class="sr-only">' . _('No') . '</span>
1041 </label>
1042 </li>
1043 </ul>
1044 </td>'."\n";
1047 } else { //sinon on affiche les lignes normales
1048 for ($k = 0; $k < $nbcolonnes; $k++) {
1049 $rbd = ($border[$k]) ? ' rbd' : '';
1050 $car = substr($ensemblereponses, $k, 1);
1051 switch ($car) {
1052 case "1": echo '<td class="bg-success text-success'.$rbd.'" headers="'.$td_headers[$k].'"><span class="glyphicon glyphicon-ok"></span><span class="sr-only"> ' . _('Yes') . '</span></td>'."\n";
1053 if (isset($somme[$k]) === false) {
1054 $somme[$k] = 0;
1056 $somme[$k]++; break;
1057 case "2": echo '<td class="bg-warning text-warning'.$rbd.'" headers="'.$td_headers[$k].'">(<span class="glyphicon glyphicon-ok"></span>)<span class="sr-only"> ' . _('Yes') . _(', ifneedbe') . '</span></td>'."\n"; break;
1058 default: echo '<td class="bg-danger'.$rbd.'" headers="'.$td_headers[$k].'"><span class="sr-only">' . _('No') . '</span></td>'."\n";break;
1064 //a la fin de chaque ligne se trouve les boutons modifier
1065 if (!$testligneamodifier=="true") {
1066 echo '
1067 <td>
1068 <button type="submit" class="btn btn-link btn-sm" name="modifierligne'.$compteur.'" title="'. _('Edit the line:') .' '.stripslashes($nombase).'">
1069 <span class="glyphicon glyphicon-pencil"></span><span class="sr-only">' . _('Edit') . '</span>
1070 </button>
1071 <button type="submit" name="effaceligne'.$compteur.'" title="'. _('Remove the line:') .' '.stripslashes($nombase).'" class="btn btn-link btn-sm">
1072 <span class="glyphicon glyphicon-remove text-danger"></span><span class="sr-only">' . _('Remove') . '</span>
1073 </button>
1074 </td>'."\n";
1077 //demande de confirmation pour modification de ligne
1078 for ($i = 0; $i < $nblignes; $i++) {
1079 if (isset($_POST["modifierligne$i"])) {
1080 if ($compteur == $i) {
1081 echo '<td style="padding:5px"><button type="submit" class="btn btn-success btn-xs" name="validermodifier'.$compteur.'" title="'. _('Save the choices') .' '.stripslashes($nombase).'">'. _('Save') .'</button></td>'."\n";
1086 $compteur++;
1087 echo '</tr>'."\n";
1090 if (!$testligneamodifier=="true") {
1091 //affichage de la case vide de texte pour un nouvel utilisateur
1092 echo '<tr id="vote-form">
1093 <td class="bg-info" style="padding:5px">
1094 <div class="input-group input-group-sm">
1095 <span class="input-group-addon"><span class="glyphicon glyphicon-user"></span></span>
1096 <input type="text" id="nom" name="nom" class="form-control" title="'. _('Your name') .'" placeholder="'. _('Your name') .'" />
1097 </div>
1098 </td>'."\n";
1100 //une ligne de checkbox pour le choix du nouvel utilisateur
1101 for ($i = 0; $i < $nbcolonnes; $i++) {
1102 echo '
1103 <td class="bg-info" headers="'.$td_headers[$i].'">
1104 <ul class="list-unstyled choice">
1105 <li class="yes">
1106 <input type="radio" id="y-choice-'.$i.'" name="choix'.$i.'" value="1" />
1107 <label class="btn btn-default btn-xs" for="y-choice-'.$i.'" title="' . _('Vote "yes" for ') . $radio_title[$i] . '">
1108 <span class="glyphicon glyphicon-ok"></span><span class="sr-only">' . _('Yes') . '</span>
1109 </label>
1110 </li>
1111 <li class="ifneedbe">
1112 <input type="radio" id="i-choice-'.$i.'" name="choix'.$i.'" value="2" />
1113 <label class="btn btn-default btn-xs" for="i-choice-'.$i.'" title="' . _('Vote "ifneedbe" for ') . $radio_title[$i] . '">
1114 (<span class="glyphicon glyphicon-ok"></span>)<span class="sr-only">' . _('Ifneedbe') . '</span>
1115 </label>
1116 </li>
1117 <li class="no">
1118 <input type="radio" id="n-choice-'.$i.'" name="choix'.$i.'" value="0" checked/>
1119 <label class="btn btn-default btn-xs" for="n-choice-'.$i.'" title="' . _('Vote "no" for ') . $radio_title[$i] . '">
1120 <span class="glyphicon glyphicon-ban-circle"></span><span class="sr-only">' . _('No') . '</span>
1121 </label>
1122 </li>
1123 </ul>
1124 </td>'."\n";
1127 // Affichage du bouton de formulaire pour inscrire un nouvel utilisateur dans la base
1128 echo '<td><button type="submit" class="btn btn-success btn-sm" name="boutonp" title="'. _('Save the choices') .'">'. _('Save') .'</button></td>
1129 </tr>'."\n";
1133 // Addition and Best choice
1134 //affichage de la ligne contenant les sommes de chaque colonne
1135 $tr_addition = '<tr id="addition"><td>'. _("Addition") .'</td>';
1136 $meilleurecolonne = max($somme);
1137 $compteursujet = 0;
1138 $meilleursujet = '<ul style="list-style:none">';
1139 for ($i = 0; $i < $nbcolonnes; $i++) {
1140 if (isset($somme[$i]) && $somme[$i] > 0 ) {
1141 if (in_array($i, array_keys($somme, max($somme)))){
1143 $tr_addition .= '<td><span class="glyphicon glyphicon-star text-warning"></span><span>'.$somme[$i].'</span></td>';
1145 $meilleursujet.= '<li><b>'.$radio_title[$i].'</b></li>';
1146 $compteursujet++;
1148 } else {
1149 $tr_addition .= '<td>'.$somme[$i].'</td>';
1151 } else {
1152 $tr_addition .= '<td></td>';
1155 $tr_addition .= '<td></td></tr>';
1157 //recuperation des valeurs des sujets et adaptation pour affichage
1158 $toutsujet = explode(",", $dsujet->sujet);
1160 $meilleursujet = str_replace("°", "'", $meilleursujet).'</ul>';
1161 $vote_str = ($meilleurecolonne > 1) ? $vote_str = _('votes') : _('vote');
1163 // Print Addition and Best choice
1164 echo $tr_addition.'
1165 </tbody>
1166 </table>
1167 </div>
1168 <div class="row">'."\n";
1170 if ($compteursujet == 1) {
1171 echo '
1172 <div class="col-sm-12"><h3>' . _("Best choice") . '</h3></div>
1173 <div class="col-sm-6 col-sm-offset-3 alert alert-success">
1174 <p><span class="glyphicon glyphicon-star text-warning"></span> ' . _("The best choice at this time is:") . '</p>
1175 ' . $meilleursujet . '
1176 <p>' . _("with") . ' <b>' . $meilleurecolonne . '</b> ' . $vote_str . '.</p>
1177 </div>'."\n";
1178 } elseif ($compteursujet > 1) {
1179 echo '
1180 <div class="col-sm-12"><h3>' . _("Best choices") . '</h3></div>
1181 <div class="col-sm-6 col-sm-offset-3 alert alert-success">
1182 <p><span class="glyphicon glyphicon-star text-warning"></span> ' . _("The bests choices at this time are:") . '</p>
1183 ' . $meilleursujet . '
1184 <p>' . _("with") . ' <b>' . $meilleurecolonne . '</b> ' . $vote_str . '.</p>
1185 </div>'."\n";
1188 echo '
1189 </div>
1190 <hr role="presentation" />'."\n";
1191 // Commments
1192 $sql = 'SELECT * FROM comments WHERE id_sondage='.$connect->Param('numsondage').' ORDER BY id_comment';
1193 $sql = $connect->Prepare($sql);
1194 $comment_user = $connect->Execute($sql, array($numsondage));
1196 if ($comment_user->RecordCount() != 0) {
1197 echo '<div><h3>' . _("Comments of polled people") . '</h3>'."\n";
1199 $i = 0;
1200 while ( $dcomment=$comment_user->FetchNextObject(false)) {
1201 echo '
1202 <div class="comment">
1203 <button type="submit" name="suppressioncomment'.$i.'" class="btn btn-link" title="' . _('Remove the comment') . '"><span class="glyphicon glyphicon-remove text-danger"></span><span class="sr-only">' . _('Remove') . '</span></button>
1204 <b>'.stripslashes($dcomment->usercomment). ' :</b>
1205 <span class="comment">' . stripslashes(nl2br($dcomment->comment)) . '</span>
1206 </div>';
1207 $i++;
1209 echo '</div>';
1211 echo '
1212 <div class="hidden-print alert alert-info">
1213 <div class="col-md-6 col-md-offset-3">
1214 <fieldset id="add-comment"><legend>' . _("Add a comment in the poll") . '</legend>
1215 <div class="form-group">
1216 <p><label for="commentuser">'. _("Your name") .'</label><input type=text name="commentuser" class="form-control" id="commentuser" /></p>
1217 </div>
1218 <div class="form-group">
1219 <p><label for="comment">'. _("Your comment") .'</label><br />
1220 <textarea name="comment" id="comment" class="form-control" rows="2" cols="40"></textarea></p>
1221 </div>
1222 <p class="text-center"><input type="submit" name="ajoutcomment" value="'. _("Send the comment") .'" class="btn btn-success"></p>
1223 </fieldset>
1224 </div>
1225 <div class="clearfix"></div>
1226 </div>
1227 </form>';
1229 bandeau_pied();