1<?php 2/* Copyright (C) 2013-2014 Laurent Destailleur <eldy@users.sourceforge.net> 3 * Copyright (C) 2014 Marcos García <marcosgdf@gmail.com> 4 * Copyright (C) 2015-2016 Alexandre Spangaro <aspangaro@open-dsi.fr> 5 * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr> 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation; either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program. If not, see <https://www.gnu.org/licenses/>. 19 */ 20 21/** 22 * \file htdocs/opensurvey/wizard/create_survey.php 23 * \ingroup opensurvey 24 * \brief Page to create a new survey 25 */ 26 27require '../../main.inc.php'; 28require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php"; 29require_once DOL_DOCUMENT_ROOT."/core/lib/files.lib.php"; 30require_once DOL_DOCUMENT_ROOT."/core/class/doleditor.class.php"; 31require_once DOL_DOCUMENT_ROOT."/opensurvey/fonctions.php"; 32 33// Security check 34if (!$user->rights->opensurvey->write) { 35 accessforbidden(); 36} 37 38$langs->load("opensurvey"); 39 40$title = GETPOST('title'); 41$description = GETPOST('description', 'restricthtml'); 42$mailsonde = GETPOST('mailsonde'); 43$creation_sondage_date = GETPOST('creation_sondage_date'); 44$creation_sondage_autre = GETPOST('creation_sondage_autre'); 45 46// We init some session variable to avoir warning 47$session_var = array('title', 'description', 'mailsonde'); 48foreach ($session_var as $var) { 49 if (isset($_SESSION[$var])) { 50 $_SESSION[$var] = null; 51 } 52} 53 54// On initialise également les autres variables 55$cocheplus = ''; 56$cochemail = ''; 57 58// Jump to correct page 59if (!empty($creation_sondage_date) || !empty($creation_sondage_autre)) { 60 $_SESSION["title"] = $title; 61 $_SESSION["description"] = $description; 62 63 if (GETPOST('mailsonde') == 'on') { 64 $_SESSION["mailsonde"] = true; 65 } else { 66 $_SESSION["mailsonde"] = false; 67 } 68 69 if (GETPOST('allow_comments') == 'on') { 70 $_SESSION['allow_comments'] = true; 71 } else { 72 $_SESSION['allow_comments'] = false; 73 } 74 75 if (GETPOST('allow_spy') == 'on') { 76 $_SESSION['allow_spy'] = true; 77 } else { 78 $_SESSION['allow_spy'] = false; 79 } 80 81 $testdate = false; 82 $champdatefin = dol_mktime(0, 0, 0, GETPOST('champdatefinmonth'), GETPOST('champdatefinday'), GETPOST('champdatefinyear')); 83 84 if ($champdatefin && ($champdatefin > 0)) { // A date was provided 85 // Expire date is not before today 86 if ($champdatefin >= dol_now()) { 87 $testdate = true; 88 $_SESSION['champdatefin'] = dol_print_date($champdatefin, 'dayrfc'); 89 } else { 90 $testdate = true; 91 $_SESSION['champdatefin'] = dol_print_date($champdatefin, 'dayrfc'); 92 //$testdate = false; 93 //$_SESSION['champdatefin'] = dol_print_date($champdatefin,'dayrfc'); 94 setEventMessages('ExpireDate', null, 'warnings'); 95 } 96 } 97 98 if (!$testdate) { 99 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("ExpireDate")), null, 'errors'); 100 } 101 102 if ($title && $testdate) { 103 if (!empty($creation_sondage_date)) { 104 header("Location: choix_date.php"); 105 exit(); 106 } 107 108 if (!empty($creation_sondage_autre)) { 109 header("Location: choix_autre.php"); 110 exit(); 111 } 112 } 113} 114 115 116 117 118/* 119 * View 120 */ 121 122$form = new Form($db); 123 124$arrayofjs = array(); 125$arrayofcss = array('/opensurvey/css/style.css'); 126llxHeader('', $langs->trans("OpenSurvey"), '', "", 0, 0, $arrayofjs, $arrayofcss); 127 128print load_fiche_titre($langs->trans("CreatePoll").' (1 / 2)'); 129 130// debut du formulaire 131print '<form name="formulaire" action="" method="POST">'."\n"; 132print '<input type="hidden" name="token" value="'.newToken().'">'; 133 134print dol_get_fiche_head(); 135 136// Affichage des différents champs textes a remplir 137print '<table class="border centpercent">'."\n"; 138 139print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("PollTitle").'</td><td><input type="text" name="title" class="minwidth300" maxlength="80" value="'.$_SESSION["title"].'"></td>'."\n"; 140if (!$_SESSION["title"] && (GETPOST('creation_sondage_date') || GETPOST('creation_sondage_autre'))) { 141 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PollTitle")), null, 'errors'); 142} 143 144print '</tr>'."\n"; 145print '<tr><td>'.$langs->trans("Description").'</td><td>'; 146$doleditor = new DolEditor('description', $_SESSION["description"], '', 120, 'dolibarr_notes', 'In', 1, 1, 1, ROWS_7, '90%'); 147$doleditor->Create(0, ''); 148print '</td>'."\n"; 149print '</tr>'."\n"; 150 151print '<tr><td class="fieldrequired">'.$langs->trans("ExpireDate").'</td><td>'; 152 153print $form->selectDate($champdatefin ? $champdatefin : -1, 'champdatefin', '', '', '', "add", 1, 0); 154 155print '</tr>'."\n"; 156print '</table>'."\n"; 157 158print dol_get_fiche_end(); 159 160//focus javascript sur le premier champ 161print '<script type="text/javascript">'."\n"; 162print 'document.formulaire.title.focus();'."\n"; 163print '</script>'."\n"; 164 165print '<br>'."\n"; 166 167// Check or not 168 169if ($_SESSION["mailsonde"]) { 170 $cochemail = "checked"; 171} 172 173print '<input type="checkbox" id="mailsonde" name="mailsonde" '.$cochemail.'> <label for="mailsonde">'.$langs->trans("ToReceiveEMailForEachVote").'</label><br>'."\n"; 174 175if ($_SESSION['allow_comments']) { 176 $allow_comments = 'checked'; 177} 178if (GETPOSTISSET('allow_comments')) { 179 $allow_comments = GETPOST('allow_comments') ? 'checked' : ''; 180} 181print '<input type="checkbox" id="allow_comments" name="allow_comments" '.$allow_comments.'"> <label for="allow_comments">'.$langs->trans('CanComment').'</label><br>'."\n"; 182 183if ($_SESSION['allow_spy']) { 184 $allow_spy = 'checked'; 185} 186if (GETPOSTISSET('allow_spy')) { 187 $allow_spy = GETPOST('allow_spy') ? 'checked' : ''; 188} 189print '<input type="checkbox" id="allow_spy" name="allow_spy" '.$allow_spy.'> <label for="allow_spy">'.$langs->trans('CanSeeOthersVote').'</label><br>'."\n"; 190 191if (GETPOST('choix_sondage')) { 192 if (GETPOST('choix_sondage') == 'date') { 193 print '<input type="hidden" name="creation_sondage_date" value="date">'; 194 } else { 195 print '<input type="hidden" name="creation_sondage_autre" value="autre">'; 196 } 197 print '<input type="hidden" name="choix_sondage" value="'.GETPOST('choix_sondage').'">'; 198 print '<br><input type="submit" class="button" name="submit" value="'.$langs->trans("CreatePoll").' ('.(GETPOST('choix_sondage') == 'date' ? $langs->trans("TypeDate") : $langs->trans("TypeClassic")).')">'; 199} else { 200 // Show image to selecte between date survey or other survey 201 print '<br><table>'."\n"; 202 print '<tr><td>'.$langs->trans("CreateSurveyDate").'</td><td></td> '."\n"; 203 print '<td><input type="image" name="creation_sondage_date" value="'.$langs->trans('CreateSurveyDate').'" src="../img/calendar-32.png"></td></tr>'."\n"; 204 print '<tr><td>'.$langs->trans("CreateSurveyStandard").'</td><td></td> '."\n"; 205 print '<td><input type="image" name="creation_sondage_autre" value="'.$langs->trans('CreateSurveyStandard').'" src="../img/chart-32.png"></td></tr>'."\n"; 206 print '</table>'."\n"; 207} 208print '<br><br><br>'."\n"; 209print '</form>'."\n"; 210 211// End of page 212llxFooter(); 213$db->close(); 214