dolibarr  16.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 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 require '../../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
29 require_once DOL_DOCUMENT_ROOT."/core/lib/files.lib.php";
30 require_once DOL_DOCUMENT_ROOT."/core/class/doleditor.class.php";
31 require_once DOL_DOCUMENT_ROOT."/opensurvey/lib/opensurvey.lib.php";
32 
33 // Security check
34 if (!$user->rights->opensurvey->write) {
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');
48 foreach ($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
59 if (!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');
126 llxHeader('', $langs->trans("OpenSurvey"), '', "", 0, 0, $arrayofjs, $arrayofcss);
127 
128 print load_fiche_titre($langs->trans("CreatePoll").' (1 / 2)');
129 
130 // debut du formulaire
131 print '<form name="formulaire" action="" method="POST">'."\n";
132 print '<input type="hidden" name="token" value="'.newToken().'">';
133 
134 print dol_get_fiche_head();
135 
136 // Affichage des différents champs textes a remplir
137 print '<table class="border centpercent">'."\n";
138 
139 print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("PollTitle").'</td><td><input type="text" name="title" class="minwidth300" maxlength="80" value="'.$_SESSION["title"].'"></td>'."\n";
140 if (!$_SESSION["title"] && (GETPOST('creation_sondage_date') || GETPOST('creation_sondage_autre'))) {
141  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PollTitle")), null, 'errors');
142 }
143 
144 print '</tr>'."\n";
145 print '<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, '');
148 print '</td>'."\n";
149 print '</tr>'."\n";
150 
151 print '<tr><td class="fieldrequired">'.$langs->trans("ExpireDate").'</td><td>';
152 
153 print $form->selectDate($champdatefin ? $champdatefin : -1, 'champdatefin', '', '', '', "add", 1, 0);
154 
155 print '</tr>'."\n";
156 print '</table>'."\n";
157 
158 print dol_get_fiche_end();
159 
160 //focus javascript sur le premier champ
161 print '<script type="text/javascript">'."\n";
162 print 'document.formulaire.title.focus();'."\n";
163 print '</script>'."\n";
164 
165 print '<br>'."\n";
166 
167 // Check or not
168 
169 if ($_SESSION["mailsonde"]) {
170  $cochemail = "checked";
171 }
172 
173 print '<input type="checkbox" id="mailsonde" name="mailsonde" '.$cochemail.'> <label for="mailsonde">'.$langs->trans("ToReceiveEMailForEachVote").'</label><br>'."\n";
174 
175 if ($_SESSION['allow_comments']) {
176  $allow_comments = 'checked';
177 }
178 if (GETPOSTISSET('allow_comments')) {
179  $allow_comments = GETPOST('allow_comments') ? 'checked' : '';
180 }
181 print '<input type="checkbox" id="allow_comments" name="allow_comments" '.$allow_comments.'"> <label for="allow_comments">'.$langs->trans('CanComment').'</label><br>'."\n";
182 
183 if ($_SESSION['allow_spy']) {
184  $allow_spy = 'checked';
185 }
186 if (GETPOSTISSET('allow_spy')) {
187  $allow_spy = GETPOST('allow_spy') ? 'checked' : '';
188 }
189 print '<input type="checkbox" id="allow_spy" name="allow_spy" '.$allow_spy.'> <label for="allow_spy">'.$langs->trans('CanSeeOthersVote').'</label><br>'."\n";
190 
191 if (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 }
208 print '<br><br><br>'."\n";
209 print '</form>'."\n";
210 
211 // End of page
212 llxFooter();
213 $db->close();
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2514
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933
dol_mktime
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...
Definition: functions.lib.php:2757
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59
DolEditor
Class to manage a WYSIWYG editor.
Definition: doleditor.class.php:30