From 41ab5a0ce2e4473f1a68641e7d36837a4469cd0e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 26 Jul 2014 19:02:32 +0200 Subject: [PATCH] Fix: date was not saved if not in future. --- .../class/opensurveysondage.class.php | 11 +++- htdocs/opensurvey/wizard/choix_date.php | 61 ++++++++++--------- htdocs/opensurvey/wizard/create_survey.php | 6 +- 3 files changed, 45 insertions(+), 33 deletions(-) diff --git a/htdocs/opensurvey/class/opensurveysondage.class.php b/htdocs/opensurvey/class/opensurveysondage.class.php index 37c04e50a29..c20c4ebca0d 100644 --- a/htdocs/opensurvey/class/opensurveysondage.class.php +++ b/htdocs/opensurvey/class/opensurveysondage.class.php @@ -1,6 +1,6 @@ - * Copyright (C) 2014 Marcos García +/* Copyright (C) 2013-2014 Laurent Destailleur + * Copyright (C) 2014 Marcos García * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -100,7 +100,12 @@ class Opensurveysondage extends CommonObject $this->cleanParameters(); // Check parameters - // Put here code to add control on parameters values + if (! $this->date_fin > 0) + { + $this->error='BadValueForEndDate'; + dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR); + return -1; + } // Insert request $sql = "INSERT INTO ".MAIN_DB_PREFIX."opensurvey_sondage("; diff --git a/htdocs/opensurvey/wizard/choix_date.php b/htdocs/opensurvey/wizard/choix_date.php index 6e10e10778a..e835c274e7d 100644 --- a/htdocs/opensurvey/wizard/choix_date.php +++ b/htdocs/opensurvey/wizard/choix_date.php @@ -30,10 +30,9 @@ require_once(DOL_DOCUMENT_ROOT."/opensurvey/fonctions.php"); // Security check if (!$user->rights->opensurvey->write) accessforbidden(); -//le format du sondage est DATE +// Survey type is DATE $_SESSION["formatsondage"] = "D"; -//traitement de l'entrée des heures dans les cases texte $erreur = false; /* @@ -44,15 +43,16 @@ $erreur = false; if (GETPOST('confirmation')) { - //On sauvegarde les heures deja entrées - if (issetAndNoEmpty('totalchoixjour', $_SESSION) === true && issetAndNoEmpty('nbrecaseshoraires', $_SESSION) === true) + // We save hours entered + if (issetAndNoEmpty('totalchoixjour', $_SESSION) === true && issetAndNoEmpty('nbrecaseshoraires', $_SESSION) === true) { $nbofchoice=count($_SESSION["totalchoixjour"]); - - for ($i = 0; $i < $nbofchoice; $i++) { - //affichage des 5 cases horaires - for ($j = 0; $j < $_SESSION["nbrecaseshoraires"]; $j++) { - + + for ($i = 0; $i < $nbofchoice; $i++) + { + // Show hours choices + for ($j = 0; $j < $_SESSION["nbrecaseshoraires"]; $j++) + { $_SESSION["horaires$i"][$j] = $_POST["horaires$i"][$j]; $case = $j + 1; @@ -128,7 +128,7 @@ if (GETPOST('confirmation')) $errheure[$i][$j]=true; $erreur=true; } - + if (issetAndNoEmpty('horaires'.$i, $_SESSION) === false || issetAndNoEmpty($j, $_SESSION['horaires'.$i]) === false) { if (issetAndNoEmpty('horaires'.$i, $_SESSION) === true) { $_SESSION["horaires$i"][$j] = ''; @@ -138,7 +138,7 @@ if (GETPOST('confirmation')) } } } - + if ($_SESSION["horaires$i"][0] == "" && $_SESSION["horaires$i"][1] == "" && $_SESSION["horaires$i"][2] == "" && $_SESSION["horaires$i"][3] == "" && $_SESSION["horaires$i"][4] == "") { $choixdate.=","; $choixdate .= $_SESSION["totalchoixjour"][$i]; @@ -154,7 +154,7 @@ if (GETPOST('confirmation')) } } } - + if (isset($errheure)) { setEventMessage($langs->trans("ErrorBadFormat"), 'errors'); } @@ -165,17 +165,22 @@ if (GETPOST('confirmation')) setEventMessage($langs->trans("MoreChoices"), 'errors'); $erreur=true; } - - if (!$erreur) { + + // Add survey into database + if (!$erreur) + { $_SESSION["toutchoix"]=substr("$choixdate",1); + ajouter_sondage(); } } // Reset days -if (GETPOST('reset')) { +if (GETPOST('reset')) +{ $nbofchoice=count($_SESSION["totalchoixjour"]); - for ($i = 0; $i < $nbofchoice; $i++) { + for ($i = 0; $i < $nbofchoice; $i++) + { for ($j = 0; $j < $_SESSION["nbrecaseshoraires"]; $j++) { unset($_SESSION["horaires$i"][$j]); } @@ -238,7 +243,7 @@ if (issetAndNoEmpty('moisavant_x') || issetAndNoEmpty('moisavant')) { } //On sauvegarde les heures deja entrées - if (issetAndNoEmpty('totalchoixjour', $_SESSION) === true) + if (issetAndNoEmpty('totalchoixjour', $_SESSION) === true) { $nbofchoice=count($_SESSION["totalchoixjour"]); for ($i = 0; $i < $nbofchoice; $i++) { @@ -260,10 +265,10 @@ if (issetAndNoEmpty('moisapres_x') || issetAndNoEmpty('moisapres')) { } //On sauvegarde les heures deja entrées - if (issetAndNoEmpty('totalchoixjour', $_SESSION) === true) + if (issetAndNoEmpty('totalchoixjour', $_SESSION) === true) { $nbofchoice=count($_SESSION["totalchoixjour"]); - for ($i = 0; $i < $nbofchoice; $i++) + for ($i = 0; $i < $nbofchoice; $i++) { //affichage des 5 cases horaires for ($j = 0; $j < $_SESSION["nbrecaseshoraires"]; $j++) { @@ -278,7 +283,7 @@ if (issetAndNoEmpty('anneeavant_x') || issetAndNoEmpty('anneeavant')) { $_SESSION["annee"] -= 1; //On sauvegarde les heures deja entrées - if (issetAndNoEmpty('totalchoixjour', $_SESSION) === true) + if (issetAndNoEmpty('totalchoixjour', $_SESSION) === true) { $nbofchoice=count($_SESSION["totalchoixjour"]); for ($i = 0; $i < $nbofchoice; $i++) { @@ -295,7 +300,7 @@ if (issetAndNoEmpty('anneeapres_x') || issetAndNoEmpty('anneeapres')) { $_SESSION["annee"] += 1; //On sauvegarde les heures deja entrées - if (issetAndNoEmpty('totalchoixjour', $_SESSION) === true) + if (issetAndNoEmpty('totalchoixjour', $_SESSION) === true) { $nbofchoice=count($_SESSION["totalchoixjour"]); for ($i = 0; $i < $nbofchoice; $i++) { @@ -361,7 +366,7 @@ if (issetAndNoEmpty('choixjourajout')) { // Test pour éviter les doublons dans la variable qui contient toutes les dates $journeuf = true; - if (issetAndNoEmpty('totalchoixjour', $_SESSION) === true && issetAndNoEmpty('choixjourajout') === true) + if (issetAndNoEmpty('totalchoixjour', $_SESSION) === true && issetAndNoEmpty('choixjourajout') === true) { $nbofchoice=count($_SESSION["totalchoixjour"]); for ($i = 0; $i < $nbofchoice; $i++) { @@ -411,9 +416,9 @@ if (issetAndNoEmpty('choixjourretrait')) { } } - for ($i = 0; $i < $nbofchoice; $i++) + for ($i = 0; $i < $nbofchoice; $i++) { - if ($_SESSION["totalchoixjour"][$i] == mktime(0, 0, 0, $_SESSION["mois"], $_POST["choixjourretrait"][0], $_SESSION["annee"])) + if ($_SESSION["totalchoixjour"][$i] == mktime(0, 0, 0, $_SESSION["mois"], $_POST["choixjourretrait"][0], $_SESSION["annee"])) { for ($j = $i; $j < $nbofchoice; $j++) { $k = $j+1; @@ -458,9 +463,9 @@ for ($i = 0; $i < $nbrejourmois + $premierjourmois; $i++) { if ($i < $premierjourmois) { print ''."\n"; } else { - if (issetAndNoEmpty('totalchoixjour', $_SESSION) === true) + if (issetAndNoEmpty('totalchoixjour', $_SESSION) === true) { - $nbofchoice=count($_SESSION["totalchoixjour"]); + $nbofchoice=count($_SESSION["totalchoixjour"]); for ($j = 0; $j < $nbofchoice; $j++) { //affichage des boutons ROUGES if (date("j", $_SESSION["totalchoixjour"][$j]) == $numerojour && date("n", $_SESSION["totalchoixjour"][$j]) == $_SESSION["mois"] && date("Y", $_SESSION["totalchoixjour"][$j]) == $_SESSION["annee"]) { @@ -513,7 +518,7 @@ if (issetAndNoEmpty('totalchoixjour', $_SESSION) || $erreur) //affichage de la liste des jours choisis $nbofchoice=count($_SESSION["totalchoixjour"]); - + for ($i=0; $i<$nbofchoice; $i++) { print ''."\n"; @@ -525,7 +530,7 @@ if (issetAndNoEmpty('totalchoixjour', $_SESSION) || $erreur) if (isset($errheure[$i][$j]) && $errheure[$i][$j]) { print ''."\n"; } else { //sinon la case est vide normalement - + print ''."\n"; } } diff --git a/htdocs/opensurvey/wizard/create_survey.php b/htdocs/opensurvey/wizard/create_survey.php index b63536247f5..cacc0ad8155 100644 --- a/htdocs/opensurvey/wizard/create_survey.php +++ b/htdocs/opensurvey/wizard/create_survey.php @@ -79,10 +79,10 @@ if (GETPOST("creation_sondage_date") || GETPOST("creation_sondage_autre")) $testdate = false; $champdatefin = dol_mktime(0,0,0,GETPOST('champdatefinmonth'),GETPOST('champdatefinday'),GETPOST('champdatefinyear')); - if (GETPOST('champdatefin') && $champdatefin) // A date was provided + if (GETPOST('champdatefin') && ($champdatefin > 0)) // A date was provided { // Expire date is not before today - if ($champdatefin - dol_now() > 0) + if ($champdatefin >= dol_now()) { $testdate = true; $_SESSION['champdatefin'] = dol_print_date($champdatefin,'dayrfc'); @@ -90,6 +90,8 @@ if (GETPOST("creation_sondage_date") || GETPOST("creation_sondage_autre")) else { $testdate = true; + //$testdate = false; + //$_SESSION['champdatefin'] = dol_print_date($champdatefin,'dayrfc'); //setEventMessage($langs->trans('ExpiredDate'),'errors'); } }