From 9a067e00efe145b94d072ad195de6ee099c723ec Mon Sep 17 00:00:00 2001
From: Olivier PEREZ <olivier@olivierperez.fr>
Date: Fri, 26 Dec 2014 23:32:53 +0100
Subject: [PATCH] Fix creation of classic polls

---
 choix_autre.php | 187 ++++++++++++++++++++++++++----------------------
 choix_date.php  |  63 ++++++++--------
 2 files changed, 134 insertions(+), 116 deletions(-)

diff --git a/choix_autre.php b/choix_autre.php
index 368e6b5c..d66c2644 100644
--- a/choix_autre.php
+++ b/choix_autre.php
@@ -16,10 +16,20 @@
  * Auteurs de STUdS (projet initial) : Guilhem BORGHESI (borghesi@unistra.fr) et Raphaël DROZ
  * Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft)
  */
-namespace Framadate;
+use Framadate\Services\LogService;
+use Framadate\Services\PollService;
+use Framadate\Services\MailService;
+use Framadate\Utils;
+use Framadate\Choice;
 
 include_once __DIR__ . '/app/inc/init.php';
 
+/* Service */
+/*---------*/
+$logService = new LogService(LOG_FILE);
+$pollService = new PollService($connect, $logService);
+$mailService = new MailService($config['use_smtp']);
+
 if (file_exists('bandeaux_local.php')) {
     include_once('bandeaux_local.php');
 } else {
@@ -27,73 +37,82 @@ if (file_exists('bandeaux_local.php')) {
 }
 
 // Step 1/4 : error if $_SESSION from info_sondage are not valid
-if (empty($_SESSION['form']->titre) || empty($_SESSION['form']->nom) || (($config['use_smtp']) ? empty($_SESSION['form']->adresse) : false)) {
+if (empty($_SESSION['form']->title) || empty($_SESSION['form']->admin_name) || (($config['use_smtp']) ? empty($_SESSION['form']->admin_mail) : false)) {
 
-    Utils::print_header ( _("Error!") );
+    Utils::print_header(_("Error!"));
     bandeau_titre(_("Error!"));
 
     echo '
     <div class="alert alert-danger">
         <h3>' . _('You haven\'t filled the first section of the poll creation.') . ' !</h3>
         <p>' . _('Back to the homepage of') . ' <a href="' . Utils::get_server_name() . '"> ' . NOMAPPLICATION . '</a></p>
-    </div>'."\n";
+    </div>' . "\n";
 
     bandeau_pied();
 
 } else {
-    
+
     // Step 4 : Data prepare before insert in DB
     if (isset($_POST['confirmecreation'])) {
 
         $registredate = explode('/', $_POST['champdatefin']);
         if (is_array($registredate) == true && count($registredate) == 3) {
-            $time = mktime(0,0,0,$registredate[1],$registredate[0],$registredate[2]);
-            if ($time > time() + (24*60*60)) {
+            $time = mktime(0, 0, 0, $registredate[1], $registredate[0], $registredate[2]);
+            if ($time > time() + (24 * 60 * 60)) {
                 $_SESSION['form']->champdatefin = $time;
             }
         }
 
         // format du sondage AUTRE
-        $_SESSION['form']->formatsondage = 'A';
-        
+        $_SESSION['form']->format = 'A';
+
         // Insert poll in database
-        $admin_poll_id = ajouter_sondage(
-            $_SESSION['form']->titre,
-            $_SESSION['form']->commentaires,
-            $_SESSION['form']->nom,
-            $_SESSION['form']->adresse,
-            $_SESSION['form']->formatsondage,
-            $_SESSION['form']->editable,
-            $_SESSION['form']->champdatefin,
-            $_SESSION['form']->receiveNewVotes,
-            $_SESSION['form']->getChoices()
-        );
-        
+        $ids = $pollService->createPoll($_SESSION['form']);
+        $poll_id = $ids[0];
+        $admin_poll_id = $ids[1];
+
+
+        // Send confirmation by mail if enabled
+        if ($config['use_smtp'] === true) {
+            $message = _("This is the message you have to send to the people you want to poll. \nNow, you have to send this message to everyone you want to poll.");
+            $message .= "\n\n";
+            $message .= stripslashes(html_entity_decode($_SESSION['form']->admin_name, ENT_QUOTES, "UTF-8")) . ' ' . _('hast just created a poll called') . ' : "' . stripslashes(htmlspecialchars_decode($_SESSION['form']->title, ENT_QUOTES)) . "\".\n";
+            $message .= _('Thanks for filling the poll at the link above') . " :\n\n%s\n\n" . _('Thanks for your confidence.') . "\n" . NOMAPPLICATION;
+
+            $message_admin = _("This message should NOT be sent to the polled people. It is private for the poll's creator.\n\nYou can now modify it at the link above");
+            $message_admin .= " :\n\n" . "%s \n\n" . _('Thanks for your confidence.') . "\n" . NOMAPPLICATION;
+
+            $message = sprintf($message, Utils::getUrlSondage($poll_id));
+            $message_admin = sprintf($message_admin, Utils::getUrlSondage($admin_poll_id, true));
+
+            if ($mailService->isValidEmail($_SESSION['form']->admin_mail)) {
+                $mailService->send($_SESSION['form']->admin_mail, '[' . NOMAPPLICATION . '][' . _('Author\'s message') . '] ' . _('Poll') . ' : ' . stripslashes(htmlspecialchars_decode($_SESSION['form']->title, ENT_QUOTES)), $message_admin);
+                $mailService->send($_SESSION['form']->admin_mail, '[' . NOMAPPLICATION . '][' . _('For sending to the polled users') . '] ' . _('Poll') . ' : ' . stripslashes(htmlspecialchars_decode($_SESSION['form']->title, ENT_QUOTES)), $message);
+            }
+        }
+
         // Clean Form data in $_SESSION
         unset($_SESSION['form']);
 
         // Delete old polls
+        // TODO Create a PurgeService
         Utils::cleaningOldPolls($connect, 'admin/logs_studs.txt');
-        
+
         // Redirect to poll administration
         header('Location:' . Utils::getUrlSondage($admin_poll_id, true));
         exit;
 
-    }
-
-    // Step 3/4 : Confirm poll creation and choose a removal date
+    } // Step 3/4 : Confirm poll creation and choose a removal date
     else if (isset($_POST['fin_sondage_autre'])) {
-        Utils::print_header ( _('Removal date and confirmation (3 on 3)') );
+        Utils::print_header(_('Removal date and confirmation (3 on 3)'));
         bandeau_titre(_('Removal date and confirmation (3 on 3)'));
 
-        
+
         // Store choices in $_SESSION
         if (isset($_POST['choices'])) {
             $_SESSION['form']->clearChoices();
-            foreach ($_POST['choices'] as $c)
-            {
-                if (!empty($c))
-                {
+            foreach ($_POST['choices'] as $c) {
+                if (!empty($c)) {
                     $choice = new Choice(htmlentities(html_entity_decode($c, ENT_QUOTES, 'UTF-8'), ENT_QUOTES, 'UTF-8'));
                     $_SESSION['form']->addChoice($choice);
                 }
@@ -101,29 +120,29 @@ if (empty($_SESSION['form']->titre) || empty($_SESSION['form']->nom) || (($confi
         }
 
         // Expiration date is initialised with config parameter. Value will be modified in step 4 if user has defined an other date
-        $_SESSION['form']->champdatefin = time() + (86400 * $config['default_poll_duration']); //60 sec * 60 min * 24 hours * config
+        $_SESSION['form']->end_date = time() + (86400 * $config['default_poll_duration']); //60 sec * 60 min * 24 hours * config
 
         // Summary
         $summary = '<ol>';
         foreach ($_SESSION['form']->getChoices() as $choice) {
 
-            preg_match_all('/\[!\[(.*?)\]\((.*?)\)\]\((.*?)\)/', $choice->getName(), $md_a_img);  // Markdown [![alt](src)](href)
-            preg_match_all('/!\[(.*?)\]\((.*?)\)/', $choice->getName(), $md_img);                 // Markdown ![alt](src)
-            preg_match_all('/\[(.*?)\]\((.*?)\)/', $choice->getName(), $md_a);                    // Markdown [text](href)
-            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)
+            preg_match_all('/\[!\[(.*?)\]\((.*?)\)\]\((.*?)\)/', $choice->getName(), $md_a_img); // Markdown [![alt](src)](href)
+            preg_match_all('/!\[(.*?)\]\((.*?)\)/', $choice->getName(), $md_img); // Markdown ![alt](src)
+            preg_match_all('/\[(.*?)\]\((.*?)\)/', $choice->getName(), $md_a); // Markdown [text](href)
+            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)
 
-                $li_subject_text = (isset($md_a_img[1][0]) && $md_a_img[1][0]!='') ? stripslashes($md_a_img[1][0]) : _("Choice") .' '.($i+1);
-                $li_subject_html = '<a href="'.$md_a_img[3][0].'"><img src="'.$md_a_img[2][0].'" class="img-responsive" alt="'.$li_subject_text.'" /></a>';
+                $li_subject_text = (isset($md_a_img[1][0]) && $md_a_img[1][0] != '') ? stripslashes($md_a_img[1][0]) : _('Choice') . ' ' . ($i + 1);
+                $li_subject_html = '<a href="' . $md_a_img[3][0] . '"><img src="' . $md_a_img[2][0] . '" class="img-responsive" alt="' . $li_subject_text . '" /></a>';
 
-            } elseif (isset($md_img[2][0]) && $md_img[2][0]!='') { // ![alt](src)
+            } elseif (isset($md_img[2][0]) && $md_img[2][0] != '') { // ![alt](src)
 
-                $li_subject_text = (isset($md_img[1][0]) && $md_img[1][0]!='') ? stripslashes($md_img[1][0]) : _("Choice") .' '.($i+1);
-                $li_subject_html = '<img src="'.$md_img[2][0].'" class="img-responsive" alt="'.$li_subject_text.'" />';
+                $li_subject_text = (isset($md_img[1][0]) && $md_img[1][0] != '') ? stripslashes($md_img[1][0]) : _('Choice') . ' ' . ($i + 1);
+                $li_subject_html = '<img src="' . $md_img[2][0] . '" class="img-responsive" alt="' . $li_subject_text . '" />';
 
-            } elseif (isset($md_a[2][0]) && $md_a[2][0]!='') { // [text](href)
+            } elseif (isset($md_a[2][0]) && $md_a[2][0] != '') { // [text](href)
 
-                $li_subject_text = (isset($md_a[1][0]) && $md_a[1][0]!='') ? stripslashes($md_a[1][0]) : _("Choice") .' '.($i+1);
-                $li_subject_html = '<a href="'.$md_a[2][0].'">'.$li_subject_text.'</a>';
+                $li_subject_text = (isset($md_a[1][0]) && $md_a[1][0] != '') ? stripslashes($md_a[1][0]) : _('Choice') . ' ' . ($i + 1);
+                $li_subject_html = '<a href="' . $md_a[2][0] . '">' . $li_subject_text . '</a>';
 
             } else { // text only
 
@@ -132,54 +151,54 @@ if (empty($_SESSION['form']->titre) || empty($_SESSION['form']->nom) || (($confi
 
             }
 
-            $summary .= '<li>'.$li_subject_html.'</li>'."\n";
+            $summary .= '<li>' . $li_subject_html . '</li>' . "\n";
         }
         $summary .= '</ol>';
 
-        $end_date_str = utf8_encode(strftime('%d/%M/%Y', $_SESSION['form']->champdatefin));//textual date
+        $end_date_str = utf8_encode(strftime('%d/%M/%Y', $_SESSION['form']->end_date)); //textual date
 
         echo '
     <form name="formulaire" action="' . Utils::get_server_name() . 'choix_autre.php" method="POST" class="form-horizontal" role="form">
     <div class="row">
         <div class="col-md-8 col-md-offset-2">
             <div class="well summary">
-                <h4>'. _("List of your choices").'</h4>
-                '. $summary .'
+                <h4>' . _('List of your choices') . '</h4>
+                ' . $summary . '
             </div>
             <div class="alert alert-info">
-                <p>' . _('Your poll will be automatically removed after'). ' ' . $config['default_poll_duration'] . ' ' . _('days') . '.<br />' . _("You can fix another removal date for it.") .'</p>
+                <p>' . _('Your poll will be automatically removed after') . ' ' . $config['default_poll_duration'] . ' ' . _('days') . '.<br />' . _("You can fix another removal date for it.") . '</p>
                 <div class="form-group">
-                    <label for="champdatefin" class="col-sm-5 control-label">'. _("Removal date (optional)") .'</label>
+                    <label for="champdatefin" class="col-sm-5 control-label">' . _('Removal date (optional)') . '</label>
                     <div class="col-sm-6">
                         <div class="input-group date">
                             <span class="input-group-addon"><i class="glyphicon glyphicon-calendar text-info"></i></span>
-                            <input type="text" class="form-control" id="champdatefin" data-date-format="'. _("dd/mm/yyyy") .'" aria-describedby="dateformat" name="champdatefin" value="'. $end_date_str .'" size="10" maxlength="10" placeholder="'. _("dd/mm/yyyy") .'" />
+                            <input type="text" class="form-control" id="champdatefin" data-date-format="' . _("dd/mm/yyyy") . '" aria-describedby="dateformat" name="champdatefin" value="' . $end_date_str . '" size="10" maxlength="10" placeholder="' . _("dd/mm/yyyy") . '" />
                         </div>
                     </div>
-                    <span id="dateformat" class="sr-only">'. _("(dd/mm/yyyy)") .'</span>
+                    <span id="dateformat" class="sr-only">' . _("(dd/mm/yyyy)") . '</span>
                 </div>
             </div>
             <div class="alert alert-warning">
-                <p>'. _("Once you have confirmed the creation of your poll, you will be automatically redirected on the administration page of your poll."). '</p>';
-        if($config['use_smtp']==true){
+                <p>' . _("Once you have confirmed the creation of your poll, you will be automatically redirected on the administration page of your poll.") . '</p>';
+        if ($config['use_smtp'] == true) {
             echo '
-                <p>' . _("Then, you will receive quickly two emails: one contening the link of your poll for sending it to the voters, the other contening the link to the administration page of your poll.") .'</p>';
+                <p>' . _("Then, you will receive quickly two emails: one contening the link of your poll for sending it to the voters, the other contening the link to the administration page of your poll.") . '</p>';
         }
         echo '
             </div>
             <p class="text-right">
-                <button class="btn btn-default" onclick="javascript:window.history.back();" title="'. _('Back to step 2') . '">'. _('Back') . '</button>
-                <button name="confirmecreation" value="confirmecreation" type="submit" class="btn btn-success">'. _('Create the poll') . '</button>
+                <button class="btn btn-default" onclick="javascript:window.history.back();" title="' . _('Back to step 2') . '">' . _('Back') . '</button>
+                <button name="confirmecreation" value="confirmecreation" type="submit" class="btn btn-success">' . _('Create the poll') . '</button>
             </p>
         </div>
     </div>
-    </form>'."\n";
+    </form>' . "\n";
 
         bandeau_pied();
 
-    // Step 2/4 : Select choices of the poll
+        // Step 2/4 : Select choices of the poll
     } else {
-        Utils::print_header( _('Poll subjects (2 on 3)'));
+        Utils::print_header(_('Poll subjects (2 on 3)'));
         bandeau_titre(_('Poll subjects (2 on 3)'));
 
         echo '
@@ -188,12 +207,12 @@ if (empty($_SESSION['form']->titre) || empty($_SESSION['form']->nom) || (($confi
         <div class="col-md-8 col-md-offset-2">';
         echo '
             <div class="alert alert-info">
-                <p>'. _("To make a generic poll you need to propose at least two choices between differents subjects.") .'</p>
-                <p>'. _("You can add or remove additional choices with the buttons") .' <span class="glyphicon glyphicon-minus text-info"></span><span class="sr-only">'. _("Remove") .'</span> <span class="glyphicon glyphicon-plus text-success"></span><span class="sr-only">'. _("Add") .'</span></p>';
-        if($config['user_can_add_img_or_link']){
-            echo '    <p>'. _("It's possible to propose links or images by using "). '<a href="http://'.$lang.'.wikipedia.org/wiki/Markdown">'. _("the Markdown syntax") .'</a>.</p>';
+                <p>' . _("To make a generic poll you need to propose at least two choices between differents subjects.") . '</p>
+                <p>' . _("You can add or remove additional choices with the buttons") . ' <span class="glyphicon glyphicon-minus text-info"></span><span class="sr-only">' . _("Remove") . '</span> <span class="glyphicon glyphicon-plus text-success"></span><span class="sr-only">' . _("Add") . '</span></p>';
+        if ($config['user_can_add_img_or_link']) {
+            echo '    <p>' . _("It's possible to propose links or images by using ") . '<a href="http://' . $lang . '.wikipedia.org/wiki/Markdown">' . _("the Markdown syntax") . '</a>.</p>';
         }
-        echo '    </div>'."\n";
+        echo '    </div>' . "\n";
 
         // Fields choices : 5 by default
         $choices = $_SESSION['form']->getChoices();
@@ -202,27 +221,27 @@ if (empty($_SESSION['form']->titre) || empty($_SESSION['form']->nom) || (($confi
             $choice = isset($choices[$i]) ? $choices[$i] : new Choice();
             echo '
             <div class="form-group choice-field">
-                <label for="choice'.$i.'" class="col-sm-2 control-label">'. _('Choice') .' '.($i+1).'</label>
+                <label for="choice' . $i . '" class="col-sm-2 control-label">' . _('Choice') . ' ' . ($i + 1) . '</label>
                 <div class="col-sm-10 input-group">
-                    <input type="text" class="form-control" name="choices[]" size="40" value="'.$choice->getName().'" id="choice'.$i.'" />';
-                    if($config['user_can_add_img_or_link']){
-                        echo '<span class="input-group-addon btn-link md-a-img" title="'. _('Add a link or an image') .' - '. _('Choice') .' '.($i+1).'" ><span class="glyphicon glyphicon-picture"></span> <span class="glyphicon glyphicon-link"></span></span>';
-                    }
+                    <input type="text" class="form-control" name="choices[]" size="40" value="' . $choice->getName() . '" id="choice' . $i . '" />';
+            if ($config['user_can_add_img_or_link']) {
+                echo '<span class="input-group-addon btn-link md-a-img" title="' . _('Add a link or an image') . ' - ' . _('Choice') . ' ' . ($i + 1) . '" ><span class="glyphicon glyphicon-picture"></span> <span class="glyphicon glyphicon-link"></span></span>';
+            }
             echo '
             </div>
-            </div>'."\n";
+            </div>' . "\n";
         }
 
         echo '
             <div class="col-md-4">
                 <div class="btn-group btn-group">
-                    <button type="button" id="remove-a-choice" class="btn btn-default" title="'. _('Remove a choice') .'"><span class="glyphicon glyphicon-minus text-info"></span><span class="sr-only">'. _('Remove') .'</span></button>
-                    <button type="button" id="add-a-choice" class="btn btn-default" title="'. _('Add a choice') .'"><span class="glyphicon glyphicon-plus text-success"></span><span class="sr-only">'. _('Add') .'</span></button>
+                    <button type="button" id="remove-a-choice" class="btn btn-default" title="' . _('Remove a choice') . '"><span class="glyphicon glyphicon-minus text-info"></span><span class="sr-only">' . _('Remove') . '</span></button>
+                    <button type="button" id="add-a-choice" class="btn btn-default" title="' . _('Add a choice') . '"><span class="glyphicon glyphicon-plus text-success"></span><span class="sr-only">' . _('Add') . '</span></button>
                 </div>
             </div>
             <div class="col-md-8 text-right">
-                <a class="btn btn-default" href="'.Utils::get_server_name().'infos_sondage.php?choix_sondage=autre" title="'. _('Back to step 1') . '">'. _('Back') . '</a>
-                <button name="fin_sondage_autre" value="'._('Next').'" type="submit" class="btn btn-success disabled" title="'. _('Go to step 3') . '">'. _('Next') . '</button>
+                <a class="btn btn-default" href="' . Utils::get_server_name() . 'infos_sondage.php?choix_sondage=autre" title="' . _('Back to step 1') . '">' . _('Back') . '</a>
+                <button name="fin_sondage_autre" value="' . _('Next') . '" type="submit" class="btn btn-success disabled" title="' . _('Go to step 3') . '">' . _('Next') . '</button>
             </div>
         </div>
     </div>
@@ -230,32 +249,32 @@ if (empty($_SESSION['form']->titre) || empty($_SESSION['form']->nom) || (($confi
         <div class="modal-dialog">
             <div class="modal-content">
                 <div class="modal-header">
-                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">'. _('Close') . '</span></button>
-                    <p class="modal-title" id="md-a-imgModalLabel">'. _("Add a link or an image") .'</p>
+                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">' . _('Close') . '</span></button>
+                    <p class="modal-title" id="md-a-imgModalLabel">' . _("Add a link or an image") . '</p>
                 </div>
                 <div class="modal-body">
-                    <p class="alert alert-info">'. _("These fields are optional. You can add a link, an image or both.") .'</p>
+                    <p class="alert alert-info">' . _("These fields are optional. You can add a link, an image or both.") . '</p>
                     <div class="form-group">
-                        <label for="md-img"><span class="glyphicon glyphicon-picture"></span> '. _('URL of the image') . '</label>
+                        <label for="md-img"><span class="glyphicon glyphicon-picture"></span> ' . _('URL of the image') . '</label>
                         <input id="md-img" type="text" placeholder="http://…" class="form-control" size="40" />
                     </div>
                     <div class="form-group">
-                        <label for="md-a"><span class="glyphicon glyphicon-link"></span> '. _('Link') . '</label>
+                        <label for="md-a"><span class="glyphicon glyphicon-link"></span> ' . _('Link') . '</label>
                         <input id="md-a" type="text" placeholder="http://…" class="form-control" size="40" />
                     </div>
                     <div class="form-group">
-                        <label for="md-text">'. _('Alternative text') . '</label>
+                        <label for="md-text">' . _('Alternative text') . '</label>
                         <input id="md-text" type="text" class="form-control" size="40" />
                     </div>
                 </div>
                 <div class="modal-footer">
-                    <button type="button" class="btn btn-default" data-dismiss="modal">'. _('Cancel') . '</button>
-                    <button type="button" class="btn btn-primary">'. _('Add') . '</button>
+                    <button type="button" class="btn btn-default" data-dismiss="modal">' . _('Cancel') . '</button>
+                    <button type="button" class="btn btn-primary">' . _('Add') . '</button>
                 </div>
             </div>
         </div>
     </div>
-    </form>'."\n";
+    </form>' . "\n";
 
         bandeau_pied();
 
diff --git a/choix_date.php b/choix_date.php
index 6bf17e66..5a28339d 100644
--- a/choix_date.php
+++ b/choix_date.php
@@ -44,8 +44,8 @@ if (!isset($_SESSION['form']->title) || !isset($_SESSION['form']->admin_name) ||
 
     echo '
     <div class="alert alter-danger">
-        <h3>' . _("You haven't filled the first section of the poll creation.") . ' !</h3>
-        <p>' . _("Back to the homepage of ") . ' ' . '<a href="' . Utils::get_server_name() . '">' . NOMAPPLICATION . '</a>.</p>
+        <h3>' . _('You haven\'t filled the first section of the poll creation.') . ' !</h3>
+        <p>' . _('Back to the homepage of ') . ' ' . '<a href="' . Utils::get_server_name() . '">' . NOMAPPLICATION . '</a>.</p>
     </div>';
 
 
@@ -84,7 +84,7 @@ if (!isset($_SESSION['form']->title) || !isset($_SESSION['form']->admin_name) ||
         if ($config['use_smtp'] === true) {
             $message = _("This is the message you have to send to the people you want to poll. \nNow, you have to send this message to everyone you want to poll.");
             $message .= "\n\n";
-            $message .= stripslashes(html_entity_decode($_SESSION['form']->admin_name, ENT_QUOTES, "UTF-8")) . ' ' . _("hast just created a poll called") . ' : "' . stripslashes(htmlspecialchars_decode($_SESSION['form']->title, ENT_QUOTES)) . "\".\n";
+            $message .= stripslashes(html_entity_decode($_SESSION['form']->admin_name, ENT_QUOTES, 'UTF-8')) . ' ' . _("hast just created a poll called") . ' : "' . stripslashes(htmlspecialchars_decode($_SESSION['form']->title, ENT_QUOTES)) . "\".\n";
             $message .= _('Thanks for filling the poll at the link above') . " :\n\n%s\n\n" . _('Thanks for your confidence.') . "\n" . NOMAPPLICATION;
 
             $message_admin = _("This message should NOT be sent to the polled people. It is private for the poll's creator.\n\nYou can now modify it at the link above");
@@ -168,29 +168,28 @@ if (!isset($_SESSION['form']->title) || !isset($_SESSION['form']->admin_name) ||
     <form name="formulaire" action="' . Utils::get_server_name() . 'choix_date.php" method="POST" class="form-horizontal" role="form">
     <div class="row" id="selected-days">
         <div class="col-md-8 col-md-offset-2">
-            <h3>'. _("Confirm the creation of your poll") .'</h3>
+            <h3>'. _('Confirm the creation of your poll') .'</h3>
             <div class="well summary">
-                <h4>'. _("List of your choices").'</h4>
+                <h4>'. _('List of your choices').'</h4>
                 '. $summary .'
             </div>
             <div class="alert alert-info clearfix">
-                <p>' . _("Your poll will be automatically removed "). $config['default_poll_duration'] . ' ' . _("days") . ' ' ._("after the last date of your poll") . '.<br />' . _("You can fix another removal date for it.") .'</p>
+                <p>' . _('Your poll will be automatically removed '). $config['default_poll_duration'] . ' ' . _("days") . ' ' ._('after the last date of your poll') . '.<br />' . _('You can fix another removal date for it.') .'</p>
                 <div class="form-group">
-                    <label for="champdatefin" class="col-sm-5 control-label">'. _("Removal date") .'</label>
+                    <label for="champdatefin" class="col-sm-5 control-label">'. _('Removal date') .'</label>
                     <div class="col-sm-6">
                         <div class="input-group date">
                             <span class="input-group-addon"><i class="glyphicon glyphicon-calendar text-info"></i></span>
-                            <input type="text" class="form-control" id="champdatefin" data-date-format="'. _("dd/mm/yyyy") .'" aria-describedby="dateformat" name="champdatefin" value="'.strftime('%d/%m/%Y', $removal_date).'" size="10" maxlength="10" placeholder="'. _("dd/mm/yyyy") .'" />
+                            <input type="text" class="form-control" id="champdatefin" data-date-format="'. _("dd/mm/yyyy") .'" aria-describedby="dateformat" name="champdatefin" value="'.strftime('%d/%m/%Y', $removal_date).'" size="10" maxlength="10" placeholder="'. _('dd/mm/yyyy') .'" />
                         </div>
                     </div>
                     <span id="dateformat" class="sr-only">'. _("(dd/mm/yyyy)") .'</span>
                 </div>
             </div>
             <div class="alert alert-warning">
-                <p>'. _("Once you have confirmed the creation of your poll, you will be automatically redirected on the administration page of your poll."). '</p>';
+                <p>'. _('Once you have confirmed the creation of your poll, you will be automatically redirected on the administration page of your poll.'). '</p>';
         if($config['use_smtp']==true){
-            echo '
-                <p>' . _("Then, you will receive quickly two emails: one contening the link of your poll for sending it to the voters, the other contening the link to the administration page of your poll.") .'</p>';
+            echo '<p>' . _('Then, you will receive quickly two emails: one contening the link of your poll for sending it to the voters, the other contening the link to the administration page of your poll.') .'</p>';
         }
         echo '
             </div>
@@ -206,8 +205,8 @@ if (!isset($_SESSION['form']->title) || !isset($_SESSION['form']->admin_name) ||
 
     // Step 2/4 : Select dates of the poll
     } else {
-        Utils::print_header ( _("Poll dates (2 on 3)") );
-        bandeau_titre(_("Poll dates (2 on 3)"));
+        Utils::print_header ( _('Poll dates (2 on 3)') );
+        bandeau_titre(_('Poll dates (2 on 3)'));
 
         echo '
     <form name="formulaire" action="' . Utils::get_server_name() . 'choix_date.php" method="POST" class="form-horizontal" role="form">
@@ -215,34 +214,34 @@ if (!isset($_SESSION['form']->title) || !isset($_SESSION['form']->admin_name) ||
         <div class="col-md-10 col-md-offset-1">
             <h3>'. _("Choose the dates of your poll") .'</h3>
             <div class="alert alert-info">
-                <p>'. _("To schedule an event you need to propose at least two choices (two hours for one day or two days).").'</p>
-                <p>'. _("You can add or remove additionnal days and hours with the buttons") .' <span class="glyphicon glyphicon-minus text-info"></span><span class="sr-only">'. _("Remove") .'</span> <span class="glyphicon glyphicon-plus text-success"></span><span class="sr-only">'. _("Add") .'</span></p>
-                <p>'. _("For each selected day, you can choose, or not, meeting hours (e.g.: \"8h\", \"8:30\", \"8h-10h\", \"evening\", etc.)").'</p>
+                <p>'. _('To schedule an event you need to propose at least two choices (two hours for one day or two days).').'</p>
+                <p>'. _('You can add or remove additionnal days and hours with the buttons') .' <span class="glyphicon glyphicon-minus text-info"></span><span class="sr-only">'. _('Remove') .'</span> <span class="glyphicon glyphicon-plus text-success"></span><span class="sr-only">'. _('Add') .'</span></p>
+                <p>'. _('For each selected day, you can choose, or not, meeting hours (e.g.: "8h", "8:30", "8h-10h", "evening", etc.)').'</p>
             </div>';
 
         // Fields days : 3 by default
-        $nb_days = (isset($_SESSION["totalchoixjour"])) ? count($_SESSION["totalchoixjour"]) : 3;
+        $nb_days = (isset($_SESSION['totalchoixjour'])) ? count($_SESSION['totalchoixjour']) : 3;
         for ($i=0;$i<$nb_days;$i++) {
-            $day_value = isset($_SESSION["totalchoixjour"][$i]) ? strftime( "%d/%m/%Y", $_SESSION["totalchoixjour"][$i]) : '';
+            $day_value = isset($_SESSION['totalchoixjour'][$i]) ? strftime('%d/%m/%Y', $_SESSION['totalchoixjour'][$i]) : '';
             echo '
             <fieldset>
                 <div class="form-group">
                     <legend>
-                        <label class="sr-only" for="day'.$i.'">'. _("Day") .' '. ($i+1) .'</label>
+                        <label class="sr-only" for="day'.$i.'">'. _('Day') .' '. ($i+1) .'</label>
                         <div class="input-group date col-xs-7">
                             <span class="input-group-addon"><i class="glyphicon glyphicon-calendar text-info"></i></span>
-                            <input type="text" class="form-control" id="day'.$i.'" title="'. _("Day") .' '. ($i+1) .'" data-date-format="'. _("dd/mm/yyyy") .'" aria-describedby="dateformat'.$i.'" name="days[]" value="'.$day_value.'" size="10" maxlength="10" placeholder="'. _("dd/mm/yyyy") .'" />
+                            <input type="text" class="form-control" id="day'.$i.'" title="'. _("Day") .' '. ($i+1) .'" data-date-format="'. _('dd/mm/yyyy') .'" aria-describedby="dateformat'.$i.'" name="days[]" value="'.$day_value.'" size="10" maxlength="10" placeholder="'. _("dd/mm/yyyy") .'" />
                         </div>
-                        <span id="dateformat'.$i.'" class="sr-only">'. _("(dd/mm/yyyy)") .'</span>
+                        <span id="dateformat'.$i.'" class="sr-only">'. _('(dd/mm/yyyy)') .'</span>
                     </legend>'."\n";
 
             // Fields hours : 3 by default
-            for ($j=0;$j<max(count(isset($_SESSION["horaires".$i]) ? $_SESSION["horaires".$i] : 0),3);$j++) {
-                $hour_value = isset($_SESSION["horaires".$i][$j]) ? $_SESSION["horaires".$i][$j] : '';
+            for ($j=0;$j<max(count(isset($_SESSION['horaires'.$i]) ? $_SESSION['horaires'.$i] : 0),3);$j++) {
+                $hour_value = isset($_SESSION['horaires'.$i][$j]) ? $_SESSION['horaires'.$i][$j] : '';
                 echo '
                     <div class="col-sm-2">
-                        <label for="d'.$i.'-h'.$j.'" class="sr-only control-label">'. _("Time") .' '. ($j+1) .'</label>
-                        <input type="text" class="form-control hours" title="'.$day_value.' - '. _("Time") .' '. ($j+1) .'" placeholder="'. _("Time") .' '. ($j+1) .'" id="d'.$i.'-h'.$j.'" name="horaires'.$i.'[]" value="'.$hour_value.'" />
+                        <label for="d'.$i.'-h'.$j.'" class="sr-only control-label">'. _('Time') .' '. ($j+1) .'</label>
+                        <input type="text" class="form-control hours" title="'.$day_value.' - '. _('Time') .' '. ($j+1) .'" placeholder="'. _('Time') .' '. ($j+1) .'" id="d'.$i.'-h'.$j.'" name="horaires'.$i.'[]" value="'.$hour_value.'" />
                     </div>'."\n";
             }
             echo '
@@ -255,24 +254,24 @@ if (!isset($_SESSION['form']->title) || !isset($_SESSION['form']->admin_name) ||
             }
         echo '
             <div class="col-md-4">
-                <button type="button" id="copyhours" class="btn btn-default disabled" title="'. _("Copy hours of the first day") .'"><span class="glyphicon glyphicon-sort-by-attributes-alt text-info"></span><span class="sr-only">'. _("Copy hours of the first day") .'</span></button>
+                <button type="button" id="copyhours" class="btn btn-default disabled" title="'. _('Copy hours of the first day') .'"><span class="glyphicon glyphicon-sort-by-attributes-alt text-info"></span><span class="sr-only">'. _("Copy hours of the first day") .'</span></button>
                 <div class="btn-group btn-group">
-                    <button type="button" id="remove-a-day" class="btn btn-default disabled" title="'. _("Remove a day") .'"><span class="glyphicon glyphicon-minus text-info"></span><span class="sr-only">'. _("Remove a day") .'</span></button>
-                    <button type="button" id="add-a-day" class="btn btn-default" title="'. _("Add a day") .'"><span class="glyphicon glyphicon-plus text-success"></span><span class="sr-only">'. _("Add a day") .'</span></button>
+                    <button type="button" id="remove-a-day" class="btn btn-default disabled" title="'. _('Remove a day') .'"><span class="glyphicon glyphicon-minus text-info"></span><span class="sr-only">'. _("Remove a day") .'</span></button>
+                    <button type="button" id="add-a-day" class="btn btn-default" title="'. _('Add a day') .'"><span class="glyphicon glyphicon-plus text-success"></span><span class="sr-only">'. _("Add a day") .'</span></button>
                 </div>
             </div>
             <div class="col-md-8 text-right">
                 <div class="btn-group">
                     <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
-                        <span class="glyphicon glyphicon-remove text-danger"></span> '. _("Remove") . ' <span class="caret"></span>
+                        <span class="glyphicon glyphicon-remove text-danger"></span> '. _('Remove') . ' <span class="caret"></span>
                     </button>
                     <ul class="dropdown-menu" role="menu">
-                        <li><a id="resetdays" href="javascript:void(0)">'. _("Remove all days") .'</a></li>
-                        <li><a id="resethours" href="javascript:void(0)">'. _("Remove all hours") .'</a></li>
+                        <li><a id="resetdays" href="javascript:void(0)">'. _('Remove all days') .'</a></li>
+                        <li><a id="resethours" href="javascript:void(0)">'. _('Remove all hours') .'</a></li>
                     </ul>
                 </div>
                 <a class="btn btn-default" href="'.Utils::get_server_name().'infos_sondage.php?choix_sondage=date" title="'. _('Back to step 1') . '">'. _('Back') . '</a>
-                <button name="choixheures" value="'. _("Next") .'" type="submit" class="btn btn-success disabled" title="'. _('Go to step 3') . '">'. _("Next") .'</button>
+                <button name="choixheures" value="'. _('Next') .'" type="submit" class="btn btn-success disabled" title="'. _('Go to step 3') . '">'. _("Next") .'</button>
             </div>
         </div>
     </div>
-- 
GitLab