*
* 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
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
/**
* \file htdocs/opensurvey/public/choix_date.php
* \ingroup opensurvey
* \brief Page to create a new survey (date selection)
*/
define("NOLOGIN",1); // This means this output page does not require to be logged.
define("NOCSRFCHECK",1); // We accept to go on this page from external web site.
require_once('../../main.inc.php');
require_once(DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php");
require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
require_once(DOL_DOCUMENT_ROOT."/opensurvey/fonctions.php");
$origin=GETPOST('origin','alpha');
/*
* Actions
*/
// Insert survey
if (GETPOST('confirmation') || GETPOST('confirmation_x'))
{
if (is_array($_SESSION['totalchoixjour']))
{
$nbofchoice=count($_SESSION["totalchoixjour"]);
for ($i = 0; $i < $nbofchoice; $i++)
{
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];
} else {
for ($j=0;$j<$_SESSION["nbrecaseshoraires"];$j++) {
if ($_SESSION["horaires$i"][$j]!="") {
$choixdate.=",";
$choixdate .= $_SESSION["totalchoixjour"][$i];
$choixdate.="@";
// On remplace la virgule et l'arobase pour ne pas avoir de problème par la suite
$choixdate .= str_replace(array(',', '@'), array(',', '@'), $_SESSION["horaires$i"][$j]);
}
}
}
}
}
else dol_print_error('','array not defined');
$_SESSION["toutchoix"]=substr("$choixdate",1);
ajouter_sondage($origin);
}
// Reset days
if (GETPOST('reset')) {
$nbofchoice=count($_SESSION["totalchoixjour"]);
for ($i = 0; $i < $nbofchoice; $i++) {
for ($j = 0; $j < $_SESSION["nbrecaseshoraires"]; $j++) {
unset($_SESSION["horaires$i"][$j]);
}
}
unset($_SESSION["totalchoixjour"]);
unset($_SESSION["nbrecaseshoraires"]);
}
/*
* View
*/
if (! isset($_SESSION['nom']) && ! isset($_SESSION['adresse']) && ! isset($_SESSION['commentaires']) && ! isset($_SESSION['mail']))
{
dol_print_error('',"You haven't filled the first section of the poll creation");
exit;
}
$arrayofjs=array();
$arrayofcss=array('/opensurvey/css/style.css');
llxHeaderSurvey($langs->trans("OpenSurvey"), "", 0, 0, $arrayofjs, $arrayofcss);
//nombre de cases par défaut
if (! isset($_SESSION["nbrecaseshoraires"]))
{
$_SESSION["nbrecaseshoraires"]=5;
}
elseif ((GETPOST('ajoutcases') || GETPOST('ajoutcases_x')) && $_SESSION["nbrecaseshoraires"] == 5)
{
$_SESSION["nbrecaseshoraires"]=10;
}
//valeurs de la date du jour actuel
$jourAJ=date("j");
$moisAJ=date("n");
$anneeAJ=date("Y");
// Initialisation des jour, mois et année
if (! isset($_SESSION['jour'])) $_SESSION['jour']= date('j');
if (! isset($_SESSION['mois'])) $_SESSION['mois']= date('n');
if (! isset($_SESSION['annee'])) $_SESSION['annee']= date('Y');
//mise a jour des valeurs de session si bouton retour a aujourd'hui
if ((!issetAndNoEmpty('anneeavant_x') && !issetAndNoEmpty('anneeapres_x') && !issetAndNoEmpty('moisavant_x') && !issetAndNoEmpty('moisapres_x') && !issetAndNoEmpty('choixjourajout')) && !issetAndNoEmpty('choixjourretrait') || (issetAndNoEmpty('retourmois') || issetAndNoEmpty('retourmois_x'))){
$_SESSION["jour"]=date("j");
$_SESSION["mois"]=date("n");
$_SESSION["annee"]=date("Y");
}
//mise a jour des valeurs de session si mois avant
if (issetAndNoEmpty('moisavant') || issetAndNoEmpty('moisavant_x')) {
if ($_SESSION["mois"] == 1) {
$_SESSION["mois"] = 12;
$_SESSION["annee"] = $_SESSION["annee"]-1;
} else {
$_SESSION["mois"] -= 1;
}
//On sauvegarde les heures deja entrées
if (issetAndNoEmpty('totalchoixjour', $_SESSION) === true)
{
$nbofchoice=count($_SESSION["totalchoixjour"]);
for ($i = 0; $i < $nbofchoice; $i++) {
//affichage des 5 cases horaires
for ($j = 0; $j < $_SESSION["nbrecaseshoraires"]; $j++) {
$_SESSION["horaires$i"][$j] = $_POST["horaires$i"][$j];
}
}
}
}
//mise a jour des valeurs de session si mois apres
if (issetAndNoEmpty('moisapres') || issetAndNoEmpty('moisapres_x')) {
if ($_SESSION["mois"] == 12) {
$_SESSION["mois"] = 1;
$_SESSION["annee"] += 1;
} else {
$_SESSION["mois"] += 1;
}
//On sauvegarde les heures deja entrées
if (issetAndNoEmpty('totalchoixjour', $_SESSION) === true)
{
$nbofchoice=count($_SESSION["totalchoixjour"]);
for ($i = 0; $i < $nbofchoice; $i++)
{
//affichage des 5 cases horaires
for ($j = 0; $j < $_SESSION["nbrecaseshoraires"]; $j++) {
$_SESSION["horaires$i"][$j] = $_POST["horaires$i"][$j];
}
}
}
}
//mise a jour des valeurs de session si annee avant
if (issetAndNoEmpty('anneeavant') || issetAndNoEmpty('anneeavant_x')) {
$_SESSION["annee"] -= 1;
//On sauvegarde les heures deja entrées
if (issetAndNoEmpty('totalchoixjour', $_SESSION) === true)
{
$nbofchoice=count($_SESSION["totalchoixjour"]);
for ($i = 0; $i < $nbofchoice; $i++) {
//affichage des 5 cases horaires
for ($j = 0; $j < $_SESSION["nbrecaseshoraires"]; $j++) {
$_SESSION["horaires$i"][$j] = $_POST["horaires$i"][$j];
}
}
}
}
//mise a jour des valeurs de session si annee apres
if (issetAndNoEmpty('anneeapres') || issetAndNoEmpty('anneeapres_x')) {
$_SESSION["annee"] += 1;
//On sauvegarde les heures deja entrées
if (issetAndNoEmpty('totalchoixjour', $_SESSION) === true)
{
$nbofchoice=count($_SESSION["totalchoixjour"]);
for ($i = 0; $i < $nbofchoice; $i++) {
//affichage des 5 cases horaires
for ($j = 0;$j < $_SESSION["nbrecaseshoraires"]; $j++) {
$_SESSION["horaires$i"][$j] = $_POST["horaires$i"][$j];
}
}
}
}
//valeurs du nombre de jour dans le mois et du premier jour du mois
$nbrejourmois = date("t", mktime(0, 0, 0, $_SESSION["mois"], 1, $_SESSION["annee"]));
$premierjourmois = date("N", mktime(0, 0, 0, $_SESSION["mois"], 1, $_SESSION["annee"])) - 1;
//le format du sondage est DATE
$_SESSION["formatsondage"] = "D";
$_SESSION["formatcanedit"] = $_SESSION["canedit"];
//traduction de la valeur du mois
if (is_integer($_SESSION["mois"]) && $_SESSION["mois"] > 0 && $_SESSION["mois"] < 13)
{
$motmois=dol_print_date(mktime(0, 0, 0, $_SESSION["mois"], 10), '%B');
}
else
{
$motmois=dol_print_date(dol_now(), '%B');
}
//Debut du formulaire et bandeaux de tete
print '