dolibarr 22.0.5
create_survey.php
Go to the documentation of this file.
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-2024 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28// Load Dolibarr environment
29require '../../main.inc.php';
30require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
31require_once DOL_DOCUMENT_ROOT."/core/lib/files.lib.php";
32require_once DOL_DOCUMENT_ROOT."/core/class/doleditor.class.php";
33require_once DOL_DOCUMENT_ROOT."/opensurvey/lib/opensurvey.lib.php";
34
43// Security check
44if (!$user->hasRight('opensurvey', 'write')) {
46}
47
48$langs->load("opensurvey");
49
50$title = GETPOST('title');
51$description = GETPOST('description', 'restricthtml');
52$mailsonde = GETPOST('mailsonde');
53$creation_sondage_date = GETPOST('creation_sondage_date');
54$creation_sondage_autre = GETPOST('creation_sondage_autre');
55
56// We init some session variable to avoir warning
57$session_var = array('title', 'description', 'mailsonde');
58foreach ($session_var as $var) {
59 if (isset($_SESSION[$var])) {
60 $_SESSION[$var] = null;
61 }
62}
63
64// On initialise également les autres variables
65$cocheplus = '';
66$cochemail = '';
67$champdatefin = 0;
68
69// Jump to correct page
70if (!empty($creation_sondage_date) || !empty($creation_sondage_autre)) {
71 $error = 0;
72
73 $_SESSION["title"] = $title;
74 $_SESSION["description"] = $description;
75
76 if (GETPOST('mailsonde') == 'on') {
77 $_SESSION["mailsonde"] = true;
78 } else {
79 $_SESSION["mailsonde"] = false;
80 }
81
82 if (GETPOST('allow_comments') == 'on') {
83 $_SESSION['allow_comments'] = true;
84 } else {
85 $_SESSION['allow_comments'] = false;
86 }
87
88 if (GETPOST('allow_spy') == 'on') {
89 $_SESSION['allow_spy'] = true;
90 } else {
91 $_SESSION['allow_spy'] = false;
92 }
93
94 $testdate = false;
95 $champdatefin = (int) dol_mktime(23, 59, 59, GETPOSTINT('champdatefinmonth'), GETPOSTINT('champdatefinday'), GETPOSTINT('champdatefinyear'));
96
97 if ($champdatefin > 0) { // A date was provided
98 // Expire date is not before today
99 if ($champdatefin >= dol_now()) {
100 $testdate = true;
101 $_SESSION['champdatefin'] = dol_print_date($champdatefin, 'dayrfc');
102 } else {
103 $error++;
104 $testdate = true;
105 $_SESSION['champdatefin'] = dol_print_date($champdatefin, 'dayrfc');
106 //$testdate = false;
107 //$_SESSION['champdatefin'] = dol_print_date($champdatefin,'dayrfc');
108 setEventMessages($langs->trans('ErrorDateMustBeInFuture'), null, 'errors');
109 }
110 }
111
112 if (!$testdate) {
113 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("ExpireDate")), null, 'errors');
114 }
115
116 if (!$error && $title && $testdate) {
117 if (!empty($creation_sondage_date)) {
118 header("Location: choix_date.php");
119 exit();
120 }
121
122 if (!empty($creation_sondage_autre)) {
123 header("Location: choix_autre.php");
124 exit();
125 }
126 }
127}
128
129
130
131
132/*
133 * View
134 */
135
136$form = new Form($db);
137
138$arrayofjs = array();
139$arrayofcss = array('/opensurvey/css/style.css');
140llxHeader('', $langs->trans("OpenSurvey"), '', "", 0, 0, $arrayofjs, $arrayofcss);
141
142print load_fiche_titre($langs->trans("CreatePoll").' (1 / 2)', '', 'poll');
143
144
145print '<form name="formulaire" action="" method="POST">'."\n";
146print '<input type="hidden" name="token" value="'.newToken().'">';
147
148print dol_get_fiche_head();
149
150print '<table class="border centpercent">'."\n";
151
152print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("PollTitle").'</td>';
153
154print '<td><input type="text" name="title" class="minwidth300" maxlength="80" value="'.$_SESSION["title"].'" autofocus></td>'."\n";
155if (!$_SESSION["title"] && (GETPOST('creation_sondage_date') || GETPOST('creation_sondage_autre'))) {
156 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PollTitle")), null, 'errors');
157}
158
159print '</tr>'."\n";
160print '<tr><td>'.$langs->trans("Description").'</td><td>';
161$doleditor = new DolEditor('description', $_SESSION["description"], '', 120, 'dolibarr_notes', 'In', true, 1, 1, ROWS_7, '90%');
162$doleditor->Create(0, '');
163print '</td>'."\n";
164print '</tr>'."\n";
165
166print '<tr><td class="fieldrequired">'.$langs->trans("ExpireDate").'</td><td>';
167
168print $form->selectDate($champdatefin ? $champdatefin : -1, 'champdatefin', 0, 0, 0, "add", 1, 0);
169
170print '</tr>'."\n";
171print '</table>'."\n";
172
173print dol_get_fiche_end();
174
175print '<br>'."\n";
176
177// Check or not
178
179if ($_SESSION["mailsonde"]) {
180 $cochemail = "checked";
181}
182
183print '<input type="checkbox" id="mailsonde" name="mailsonde" '.$cochemail.'> <label for="mailsonde">'.$langs->trans("ToReceiveEMailForEachVote").'</label><br>'."\n";
184
185$allow_comments = '';
186if ($_SESSION['allow_comments']) {
187 $allow_comments = 'checked';
188}
189if (GETPOSTISSET('allow_comments')) {
190 $allow_comments = GETPOST('allow_comments') ? 'checked' : '';
191}
192print '<input type="checkbox" id="allow_comments" name="allow_comments" '.$allow_comments.'"> <label for="allow_comments">'.$langs->trans('CanComment').'</label><br>'."\n";
193
194$allow_spy = '';
195if ($_SESSION['allow_spy']) {
196 $allow_spy = 'checked';
197}
198if (GETPOSTISSET('allow_spy')) {
199 $allow_spy = GETPOST('allow_spy') ? 'checked' : '';
200}
201print '<input type="checkbox" id="allow_spy" name="allow_spy" '.$allow_spy.'> <label for="allow_spy">'.$langs->trans('CanSeeOthersVote').'</label><br>'."\n";
202
203if (GETPOST('choix_sondage')) {
204 if (GETPOST('choix_sondage') == 'date') {
205 print '<input type="hidden" name="creation_sondage_date" value="date">';
206 } else {
207 print '<input type="hidden" name="creation_sondage_autre" value="autre">';
208 }
209 print '<input type="hidden" name="choix_sondage" value="'.GETPOST('choix_sondage').'">';
210 print '<br><input type="submit" class="button" name="submit" value="'.$langs->trans("CreatePoll").' ('.(GETPOST('choix_sondage') == 'date' ? $langs->trans("TypeDate") : $langs->trans("TypeClassic")).')">';
211} else {
212 // Show image to select between date survey or other survey
213 print '<br><table>'."\n";
214 print '<tr><td>'.$langs->trans("CreateSurveyDate").'</td><td></td> '."\n";
215 print '<td><input type="image" name="creation_sondage_date" value="'.$langs->trans('CreateSurveyDate').'" src="../img/calendar-32.png"></td></tr>'."\n";
216 print '<tr><td>'.$langs->trans("CreateSurveyStandard").'</td><td></td> '."\n";
217 print '<td><input type="image" name="creation_sondage_autre" value="'.$langs->trans('CreateSurveyStandard').'" src="../img/chart-32.png"></td></tr>'."\n";
218 print '</table>'."\n";
219}
220print '<br><br><br>'."\n";
221print '</form>'."\n";
222
223// End of page
224llxFooter();
225$db->close();
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage a WYSIWYG editor.
Class to manage generation of HTML components Only common components must be here.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_now($mode='auto')
Return date for now.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.