dolibarr 19.0.4
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 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
27// Load Dolibarr environment
28require '../../main.inc.php';
29require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
30require_once DOL_DOCUMENT_ROOT."/core/lib/files.lib.php";
31require_once DOL_DOCUMENT_ROOT."/core/class/doleditor.class.php";
32require_once DOL_DOCUMENT_ROOT."/opensurvey/lib/opensurvey.lib.php";
33
34// Security check
35if (!$user->hasRight('opensurvey', 'write')) {
37}
38
39$langs->load("opensurvey");
40
41$title = GETPOST('title');
42$description = GETPOST('description', 'restricthtml');
43$mailsonde = GETPOST('mailsonde');
44$creation_sondage_date = GETPOST('creation_sondage_date');
45$creation_sondage_autre = GETPOST('creation_sondage_autre');
46
47// We init some session variable to avoir warning
48$session_var = array('title', 'description', 'mailsonde');
49foreach ($session_var as $var) {
50 if (isset($_SESSION[$var])) {
51 $_SESSION[$var] = null;
52 }
53}
54
55// On initialise également les autres variables
56$cocheplus = '';
57$cochemail = '';
58
59// Jump to correct page
60if (!empty($creation_sondage_date) || !empty($creation_sondage_autre)) {
61 $_SESSION["title"] = $title;
62 $_SESSION["description"] = $description;
63
64 if (GETPOST('mailsonde') == 'on') {
65 $_SESSION["mailsonde"] = true;
66 } else {
67 $_SESSION["mailsonde"] = false;
68 }
69
70 if (GETPOST('allow_comments') == 'on') {
71 $_SESSION['allow_comments'] = true;
72 } else {
73 $_SESSION['allow_comments'] = false;
74 }
75
76 if (GETPOST('allow_spy') == 'on') {
77 $_SESSION['allow_spy'] = true;
78 } else {
79 $_SESSION['allow_spy'] = false;
80 }
81
82 $testdate = false;
83 $champdatefin = dol_mktime(0, 0, 0, GETPOST('champdatefinmonth'), GETPOST('champdatefinday'), GETPOST('champdatefinyear'));
84
85 if ($champdatefin && ($champdatefin > 0)) { // A date was provided
86 // Expire date is not before today
87 if ($champdatefin >= dol_now()) {
88 $testdate = true;
89 $_SESSION['champdatefin'] = dol_print_date($champdatefin, 'dayrfc');
90 } else {
91 $testdate = true;
92 $_SESSION['champdatefin'] = dol_print_date($champdatefin, 'dayrfc');
93 //$testdate = false;
94 //$_SESSION['champdatefin'] = dol_print_date($champdatefin,'dayrfc');
95 setEventMessages('ExpireDate', null, 'warnings');
96 }
97 }
98
99 if (!$testdate) {
100 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("ExpireDate")), null, 'errors');
101 }
102
103 if ($title && $testdate) {
104 if (!empty($creation_sondage_date)) {
105 header("Location: choix_date.php");
106 exit();
107 }
108
109 if (!empty($creation_sondage_autre)) {
110 header("Location: choix_autre.php");
111 exit();
112 }
113 }
114}
115
116
117
118
119/*
120 * View
121 */
122
123$form = new Form($db);
124
125$arrayofjs = array();
126$arrayofcss = array('/opensurvey/css/style.css');
127llxHeader('', $langs->trans("OpenSurvey"), '', "", 0, 0, $arrayofjs, $arrayofcss);
128
129print load_fiche_titre($langs->trans("CreatePoll").' (1 / 2)');
130
131// debut du formulaire
132print '<form name="formulaire" action="" method="POST">'."\n";
133print '<input type="hidden" name="token" value="'.newToken().'">';
134
135print dol_get_fiche_head();
136
137// Affichage des différents champs textes a remplir
138print '<table class="border centpercent">'."\n";
139
140print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("PollTitle").'</td><td><input type="text" name="title" class="minwidth300" maxlength="80" value="'.$_SESSION["title"].'"></td>'."\n";
141if (!$_SESSION["title"] && (GETPOST('creation_sondage_date') || GETPOST('creation_sondage_autre'))) {
142 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PollTitle")), null, 'errors');
143}
144
145print '</tr>'."\n";
146print '<tr><td>'.$langs->trans("Description").'</td><td>';
147$doleditor = new DolEditor('description', $_SESSION["description"], '', 120, 'dolibarr_notes', 'In', 1, 1, 1, ROWS_7, '90%');
148$doleditor->Create(0, '');
149print '</td>'."\n";
150print '</tr>'."\n";
151
152print '<tr><td class="fieldrequired">'.$langs->trans("ExpireDate").'</td><td>';
153
154print $form->selectDate($champdatefin ? $champdatefin : -1, 'champdatefin', '', '', '', "add", 1, 0);
155
156print '</tr>'."\n";
157print '</table>'."\n";
158
159print dol_get_fiche_end();
160
161//focus javascript sur le premier champ
162print '<script type="text/javascript">'."\n";
163print 'document.formulaire.title.focus();'."\n";
164print '</script>'."\n";
165
166print '<br>'."\n";
167
168// Check or not
169
170if ($_SESSION["mailsonde"]) {
171 $cochemail = "checked";
172}
173
174print '<input type="checkbox" id="mailsonde" name="mailsonde" '.$cochemail.'> <label for="mailsonde">'.$langs->trans("ToReceiveEMailForEachVote").'</label><br>'."\n";
175
176if ($_SESSION['allow_comments']) {
177 $allow_comments = 'checked';
178}
179if (GETPOSTISSET('allow_comments')) {
180 $allow_comments = GETPOST('allow_comments') ? 'checked' : '';
181}
182print '<input type="checkbox" id="allow_comments" name="allow_comments" '.$allow_comments.'"> <label for="allow_comments">'.$langs->trans('CanComment').'</label><br>'."\n";
183
184if ($_SESSION['allow_spy']) {
185 $allow_spy = 'checked';
186}
187if (GETPOSTISSET('allow_spy')) {
188 $allow_spy = GETPOST('allow_spy') ? 'checked' : '';
189}
190print '<input type="checkbox" id="allow_spy" name="allow_spy" '.$allow_spy.'> <label for="allow_spy">'.$langs->trans('CanSeeOthersVote').'</label><br>'."\n";
191
192if (GETPOST('choix_sondage')) {
193 if (GETPOST('choix_sondage') == 'date') {
194 print '<input type="hidden" name="creation_sondage_date" value="date">';
195 } else {
196 print '<input type="hidden" name="creation_sondage_autre" value="autre">';
197 }
198 print '<input type="hidden" name="choix_sondage" value="'.GETPOST('choix_sondage').'">';
199 print '<br><input type="submit" class="button" name="submit" value="'.$langs->trans("CreatePoll").' ('.(GETPOST('choix_sondage') == 'date' ? $langs->trans("TypeDate") : $langs->trans("TypeClassic")).')">';
200} else {
201 // Show image to selecte between date survey or other survey
202 print '<br><table>'."\n";
203 print '<tr><td>'.$langs->trans("CreateSurveyDate").'</td><td></td> '."\n";
204 print '<td><input type="image" name="creation_sondage_date" value="'.$langs->trans('CreateSurveyDate').'" src="../img/calendar-32.png"></td></tr>'."\n";
205 print '<tr><td>'.$langs->trans("CreateSurveyStandard").'</td><td></td> '."\n";
206 print '<td><input type="image" name="creation_sondage_autre" value="'.$langs->trans('CreateSurveyStandard').'" src="../img/chart-32.png"></td></tr>'."\n";
207 print '</table>'."\n";
208}
209print '<br><br><br>'."\n";
210print '</form>'."\n";
211
212// End of page
213llxFooter();
214$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
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 informations (by default a local PHP server timestamp) Re...
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.