From e53043b232dfda2d36a91a150e476e8a51a945a1 Mon Sep 17 00:00:00 2001
From: Bob Le Bricodeur <Mr.Bricodage@gmail.com>
Date: Wed, 12 Nov 2014 16:35:13 +0100
Subject: [PATCH] $_SESSION["champdatefin"] modification (created in step 3 and
 only modified in needed in step 4) handle date format for windows platform

---
 choix_autre.php      | 15 ++++++++++-----
 creation_sondage.php |  5 +++--
 2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/choix_autre.php b/choix_autre.php
index 0ec091af..09cc5d4e 100644
--- a/choix_autre.php
+++ b/choix_autre.php
@@ -57,8 +57,6 @@ if (Utils::issetAndNoEmpty('titre', $_SESSION) === false || Utils::issetAndNoEmp
         $temp_results=substr($temp_results,1);
         $_SESSION["toutchoix"]=$temp_results;
 
-        // Expiration date → the configuration value is used if not filled or in bad format		
-        $_SESSION["champdatefin"]= time()+ (86400 * config_get('default_poll_duration')); //60 secondes * 60 minutes * 24 heures * config
 
         if (Utils::issetAndNoEmpty('champdatefin')) {
             $registredate = explode("/",$_POST["champdatefin"]);
@@ -69,7 +67,7 @@ if (Utils::issetAndNoEmpty('titre', $_SESSION) === false || Utils::issetAndNoEmp
                 }
             }
         }
-
+		
         //format du sondage AUTRE
         $_SESSION["formatsondage"]="A".$_SESSION["studsplus"];
 
@@ -93,9 +91,16 @@ if (Utils::issetAndNoEmpty('titre', $_SESSION) === false || Utils::issetAndNoEmp
         Utils::print_header ( _("Removal date and confirmation (3 on 3)") );
         bandeau_titre(_("Removal date and confirmation (3 on 3)"));
 
-        $removal_date=strftime(_("%A, den %e. %B %Y"), time()+15552000);
+		// Expiration date is initialised with config parameter. Value will be modified in step 4 if user has defined an other date		
+		$_SESSION["champdatefin"]= time()+ (86400 * config_get('default_poll_duration')); //60 secondes * 60 minutes * 24 heures * config		
 
-        // Sumary
+		$date_format = _("%A, den %e. %B %Y"); //locale replacement
+		if (strtoupper(substr(PHP_OS,0,3))=='WIN'){ //%e can't be used on Windows platform, use %#d instead
+			$date_format = preg_replace('#(?<!%)((?:%%)*)%e#','\1%#d', $date_format); //replace %e by %#d for windows
+		}
+		$removal_date="(".strftime($date_format, ($_SESSION["champdatefin"])).")";//textual date 
+		
+        // Summary
         $summary = '<ol>';
         for ($i=0;$i<count($_SESSION['choices']);$i++) {
 
diff --git a/creation_sondage.php b/creation_sondage.php
index 9e70e7bc..449999ea 100644
--- a/creation_sondage.php
+++ b/creation_sondage.php
@@ -45,8 +45,9 @@ function ajouter_sondage()
     $sondage=random(16);
     $sondage_admin=$sondage.random(8);
 
-    $date_fin = ($_SESSION["champdatefin"]) ? $_SESSION["champdatefin"] : $date_fin=time()+15552000;
-
+    //$date_fin = ($_SESSION["champdatefin"]) ? $_SESSION["champdatefin"] : $date_fin=time()+ (86400 * config_get('default_poll_duration'));
+	$date_fin = $_SESSION["champdatefin"]; //always provided by choix_autre.php
+	$_SESSION["champdatefin"]=""; //clean param cause 2 polls created by the same user in the same session can be affected by this param during the 2nd creation.
     $sql = 'INSERT INTO sondage
           (id_sondage, commentaires, mail_admin, nom_admin, titre, id_sondage_admin, date_fin, format, mailsonde)
           VALUES (
-- 
GitLab