dolibarr  13.0.2
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/fonctions.php";
32 
33 // Security check
34 if (!$user->rights->opensurvey->write) accessforbidden();
35 
36 $langs->load("opensurvey");
37 
38 $title = GETPOST('title');
39 $description = GETPOST('description', 'restricthtml');
40 $mailsonde = GETPOST('mailsonde');
41 $creation_sondage_date = GETPOST('creation_sondage_date');
42 $creation_sondage_autre = GETPOST('creation_sondage_autre');
43 
44 // We init some session variable to avoir warning
45 $session_var = array('title', 'description', 'mailsonde');
46 foreach ($session_var as $var)
47 {
48  if (isset($_SESSION[$var])) $_SESSION[$var] = null;
49 }
50 
51 // On initialise également les autres variables
52 $cocheplus = '';
53 $cochemail = '';
54 
55 // Jump to correct page
56 if (!empty($creation_sondage_date) || !empty($creation_sondage_autre))
57 {
58  $_SESSION["title"] = $title;
59  $_SESSION["description"] = $description;
60 
61  if (GETPOST('mailsonde') == 'on') {
62  $_SESSION["mailsonde"] = true;
63  } else {
64  $_SESSION["mailsonde"] = false;
65  }
66 
67  if (GETPOST('allow_comments') == 'on') {
68  $_SESSION['allow_comments'] = true;
69  } else {
70  $_SESSION['allow_comments'] = false;
71  }
72 
73  if (GETPOST('allow_spy') == 'on') {
74  $_SESSION['allow_spy'] = true;
75  } else {
76  $_SESSION['allow_spy'] = false;
77  }
78 
79  $testdate = false;
80  $champdatefin = dol_mktime(0, 0, 0, GETPOST('champdatefinmonth'), GETPOST('champdatefinday'), GETPOST('champdatefinyear'));
81 
82  if ($champdatefin && ($champdatefin > 0)) // A date was provided
83  {
84  // Expire date is not before today
85  if ($champdatefin >= dol_now())
86  {
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  {
104  if (!empty($creation_sondage_date))
105  {
106  header("Location: choix_date.php");
107  exit();
108  }
109 
110  if (!empty($creation_sondage_autre))
111  {
112  header("Location: choix_autre.php");
113  exit();
114  }
115  }
116 }
117 
118 
119 
120 
121 /*
122  * View
123  */
124 
125 $form = new Form($db);
126 
127 $arrayofjs = array();
128 $arrayofcss = array('/opensurvey/css/style.css');
129 llxHeader('', $langs->trans("OpenSurvey"), '', "", 0, 0, $arrayofjs, $arrayofcss);
130 
131 print load_fiche_titre($langs->trans("CreatePoll").' (1 / 2)');
132 
133 // debut du formulaire
134 print '<form name="formulaire" action="" method="POST">'."\n";
135 print '<input type="hidden" name="token" value="'.newToken().'">';
136 
138 
139 // Affichage des différents champs textes a remplir
140 print '<table class="border centpercent">'."\n";
141 
142 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";
143 if (!$_SESSION["title"] && (GETPOST('creation_sondage_date') || GETPOST('creation_sondage_autre')))
144 {
145  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PollTitle")), null, 'errors');
146 }
147 
148 print '</tr>'."\n";
149 print '<tr><td>'.$langs->trans("Description").'</td><td>';
150 $doleditor = new DolEditor('description', $_SESSION["description"], '', 120, 'dolibarr_notes', 'In', 1, 1, 1, ROWS_7, '90%');
151 $doleditor->Create(0, '');
152 print '</td>'."\n";
153 print '</tr>'."\n";
154 
155 print '<tr><td class="fieldrequired">'.$langs->trans("ExpireDate").'</td><td>';
156 
157 print $form->selectDate($champdatefin ? $champdatefin : -1, 'champdatefin', '', '', '', "add", 1, 0);
158 
159 print '</tr>'."\n";
160 print '</table>'."\n";
161 
163 
164 //focus javascript sur le premier champ
165 print '<script type="text/javascript">'."\n";
166 print 'document.formulaire.title.focus();'."\n";
167 print '</script>'."\n";
168 
169 print '<br>'."\n";
170 
171 // Check or not
172 
173 if ($_SESSION["mailsonde"]) $cochemail = "checked";
174 
175 print '<input type="checkbox" name="mailsonde" '.$cochemail.'> '.$langs->trans("ToReceiveEMailForEachVote").'<br>'."\n";
176 
177 if ($_SESSION['allow_comments']) $allow_comments = 'checked';
178 if (GETPOSTISSET('allow_comments')) $allow_comments = GETPOST('allow_comments') ? 'checked' : '';
179 print '<input type="checkbox" name="allow_comments" '.$allow_comments.'"> '.$langs->trans('CanComment').'<br>'."\n";
180 
181 if ($_SESSION['allow_spy']) $allow_spy = 'checked';
182 if (GETPOSTISSET('allow_spy')) $allow_spy = GETPOST('allow_spy') ? 'checked' : '';
183 print '<input type="checkbox" name="allow_spy" '.$allow_spy.'> '.$langs->trans('CanSeeOthersVote').'<br>'."\n";
184 
185 if (GETPOST('choix_sondage'))
186 {
187  if (GETPOST('choix_sondage') == 'date') print '<input type="hidden" name="creation_sondage_date" value="date">';
188  else print '<input type="hidden" name="creation_sondage_autre" value="autre">';
189  print '<input type="hidden" name="choix_sondage" value="'.GETPOST('choix_sondage').'">';
190  print '<br><input type="submit" class="button" name="submit" value="'.$langs->trans("CreatePoll").' ('.(GETPOST('choix_sondage') == 'date' ? $langs->trans("TypeDate") : $langs->trans("TypeClassic")).')">';
191 } else {
192  // Show image to selecte between date survey or other survey
193  print '<br><table>'."\n";
194  print '<tr><td>'.$langs->trans("CreateSurveyDate").'</td><td></td> '."\n";
195  print '<td><input type="image" name="creation_sondage_date" value="'.$langs->trans('CreateSurveyDate').'" src="../img/calendar-32.png"></td></tr>'."\n";
196  print '<tr><td>'.$langs->trans("CreateSurveyStandard").'</td><td></td> '."\n";
197  print '<td><input type="image" name="creation_sondage_autre" value="'.$langs->trans('CreateSurveyStandard').'" src="../img/chart-32.png"></td></tr>'."\n";
198  print '</table>'."\n";
199 }
200 print '<br><br><br>'."\n";
201 print '</form>'."\n";
202 
203 // End of page
204 llxFooter();
205 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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...
dol_now($mode= 'auto')
Return date for now.
llxHeader()
Empty header.
Definition: wrapper.php:45
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
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 ...
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
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_get_fiche_end($notab=0)
Return tab footer of a card.
Class to manage a WYSIWYG editor.
llxFooter()
Empty footer.
Definition: wrapper.php:59