Fix: date was not saved if not in future.

This commit is contained in:
Laurent Destailleur 2014-07-26 19:02:32 +02:00
parent db091896a5
commit 41ab5a0ce2
3 changed files with 45 additions and 33 deletions

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2013 Laurent Destailleur <eldy@users.sourceforge.net> /* Copyright (C) 2013-2014 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2014 Marcos García <marcosgdf@gmail.com> * Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -100,7 +100,12 @@ class Opensurveysondage extends CommonObject
$this->cleanParameters(); $this->cleanParameters();
// Check parameters // 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 // Insert request
$sql = "INSERT INTO ".MAIN_DB_PREFIX."opensurvey_sondage("; $sql = "INSERT INTO ".MAIN_DB_PREFIX."opensurvey_sondage(";

View File

@ -30,10 +30,9 @@ require_once(DOL_DOCUMENT_ROOT."/opensurvey/fonctions.php");
// Security check // Security check
if (!$user->rights->opensurvey->write) accessforbidden(); if (!$user->rights->opensurvey->write) accessforbidden();
//le format du sondage est DATE // Survey type is DATE
$_SESSION["formatsondage"] = "D"; $_SESSION["formatsondage"] = "D";
//traitement de l'entrée des heures dans les cases texte
$erreur = false; $erreur = false;
/* /*
@ -44,15 +43,16 @@ $erreur = false;
if (GETPOST('confirmation')) if (GETPOST('confirmation'))
{ {
//On sauvegarde les heures deja entrées // We save hours entered
if (issetAndNoEmpty('totalchoixjour', $_SESSION) === true && issetAndNoEmpty('nbrecaseshoraires', $_SESSION) === true) if (issetAndNoEmpty('totalchoixjour', $_SESSION) === true && issetAndNoEmpty('nbrecaseshoraires', $_SESSION) === true)
{ {
$nbofchoice=count($_SESSION["totalchoixjour"]); $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++) { // Show hours choices
for ($j = 0; $j < $_SESSION["nbrecaseshoraires"]; $j++)
{
$_SESSION["horaires$i"][$j] = $_POST["horaires$i"][$j]; $_SESSION["horaires$i"][$j] = $_POST["horaires$i"][$j];
$case = $j + 1; $case = $j + 1;
@ -166,16 +166,21 @@ if (GETPOST('confirmation'))
$erreur=true; $erreur=true;
} }
if (!$erreur) { // Add survey into database
if (!$erreur)
{
$_SESSION["toutchoix"]=substr("$choixdate",1); $_SESSION["toutchoix"]=substr("$choixdate",1);
ajouter_sondage(); ajouter_sondage();
} }
} }
// Reset days // Reset days
if (GETPOST('reset')) { if (GETPOST('reset'))
{
$nbofchoice=count($_SESSION["totalchoixjour"]); $nbofchoice=count($_SESSION["totalchoixjour"]);
for ($i = 0; $i < $nbofchoice; $i++) { for ($i = 0; $i < $nbofchoice; $i++)
{
for ($j = 0; $j < $_SESSION["nbrecaseshoraires"]; $j++) { for ($j = 0; $j < $_SESSION["nbrecaseshoraires"]; $j++) {
unset($_SESSION["horaires$i"][$j]); unset($_SESSION["horaires$i"][$j]);
} }

View File

@ -79,10 +79,10 @@ if (GETPOST("creation_sondage_date") || GETPOST("creation_sondage_autre"))
$testdate = false; $testdate = false;
$champdatefin = dol_mktime(0,0,0,GETPOST('champdatefinmonth'),GETPOST('champdatefinday'),GETPOST('champdatefinyear')); $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 // Expire date is not before today
if ($champdatefin - dol_now() > 0) if ($champdatefin >= dol_now())
{ {
$testdate = true; $testdate = true;
$_SESSION['champdatefin'] = dol_print_date($champdatefin,'dayrfc'); $_SESSION['champdatefin'] = dol_print_date($champdatefin,'dayrfc');
@ -90,6 +90,8 @@ if (GETPOST("creation_sondage_date") || GETPOST("creation_sondage_autre"))
else else
{ {
$testdate = true; $testdate = true;
//$testdate = false;
//$_SESSION['champdatefin'] = dol_print_date($champdatefin,'dayrfc');
//setEventMessage($langs->trans('ExpiredDate'),'errors'); //setEventMessage($langs->trans('ExpiredDate'),'errors');
} }
} }