dolibarr 21.0.0-beta
choix_autre.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2013-2015 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
4 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
5 * Copyright (C) 2024 Frédéric France <frederic.france@free.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."/opensurvey/lib/opensurvey.lib.php";
32
41// Security check
42if (!$user->hasRight('opensurvey', 'write')) {
44}
45
46
47
48/*
49 * Action
50 */
51
52$arrayofchoices = GETPOST('choix', 'array');
53$arrayoftypecolumn = GETPOST('typecolonne', 'array');
54
55// Set session vars
56if (isset($_SESSION["nbrecases"])) {
57 for ($i = 0; $i < $_SESSION["nbrecases"]; $i++) {
58 if (isset($arrayofchoices[$i])) {
59 $_SESSION["choix".$i] = $arrayofchoices[$i];
60 }
61 if (isset($arrayoftypecolumn[$i])) {
62 $_SESSION["typecolonne".$i] = $arrayoftypecolumn[$i];
63 }
64 }
65} else { //nombre de cases par défaut
66 $_SESSION["nbrecases"] = 5;
67}
68
69if (GETPOST("ajoutcases") || GETPOST("ajoutcases_x")) {
70 if ($_SESSION["nbrecases"] < 100) {
71 $_SESSION["nbrecases"] += 5;
72 }
73}
74
75// Create survey into database
76if (GETPOSTISSET("confirmecreation")) {
77 //recuperation des données de champs textes
78 $toutchoix = '';
79 for ($i = 0; $i < $_SESSION["nbrecases"] + 1; $i++) {
80 if (!empty($arrayofchoices[$i])) {
81 $toutchoix .= ',';
82 $toutchoix .= str_replace(array(",", "@"), " ", $arrayofchoices[$i]).(empty($arrayoftypecolumn[$i]) ? '' : '@'.$arrayoftypecolumn[$i]);
83 }
84 }
85
86 $toutchoix = substr("$toutchoix", 1);
87 $_SESSION["toutchoix"] = $toutchoix;
88
89 //test de remplissage des cases
90 $testremplissage = '';
91 for ($i = 0; $i < $_SESSION["nbrecases"]; $i++) {
92 if (isset($arrayofchoices[$i])) {
93 $testremplissage = "ok";
94 }
95 }
96
97 //message d'erreur si aucun champ renseigné
98 if ($testremplissage != "ok" || (!$toutchoix)) {
99 setEventMessages($langs->trans("ErrorOpenSurveyOneChoice"), null, 'errors');
100 } else {
101 //format du sondage AUTRE
102 $_SESSION["formatsondage"] = "A";
103
104 // Add into database
106 }
107}
108
109/*
110 * View
111 */
112
113$form = new Form($db);
114
115$arrayofjs = array();
116$arrayofcss = array('/opensurvey/css/style.css');
117llxHeader('', $langs->trans("OpenSurvey"), "", '', 0, 0, $arrayofjs, $arrayofcss);
118
119if (empty($_SESSION['title'])) {
120 dol_print_error(null, $langs->trans('ErrorOpenSurveyFillFirstSection'));
121 llxFooter();
122 exit;
123}
124
125
126//partie creation du sondage dans la base SQL
127//On prépare les données pour les inserer dans la base
128
129print '<form name="formulaire" id="surveyform" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";
130print '<input type="hidden" name="token" value="'.newToken().'">';
131
132print load_fiche_titre($langs->trans("CreatePoll").' (2 / 2)');
133
134
135print '<br>'.$langs->trans("PollOnChoice").'<br><br>'."\n";
136
137print '<div>'."\n";
138
139print '<table>'."\n";
140
141//affichage des cases texte de formulaire
142for ($i = 0; $i < $_SESSION["nbrecases"]; $i++) {
143 $j = $i + 1;
144 if (!isset($_SESSION["choix$i"])) {
145 $_SESSION["choix$i"] = '';
146 }
147 print '<tr><td>'.$langs->trans("TitleChoice").' '.$j.': </td><td><input type="text" name="choix[]" size="40" maxlength="40" value="'.dol_escape_htmltag($_SESSION["choix$i"]).'" id="choix'.$i.'">';
148 $tmparray = array('checkbox' => $langs->trans("CheckBox"), 'yesno' => $langs->trans("YesNoList"), 'foragainst' => $langs->trans("PourContreList"));
149
150 print ' &nbsp; '.$langs->trans("Type").' '.$form->selectarray("typecolonne[]", $tmparray, $_SESSION["typecolonne".$i]);
151 print '</td></tr>'."\n";
152}
153
154print '</table>'."\n";
155
156//ajout de cases supplementaires
157print '<table><tr>'."\n";
158print '<td class="center">'.$langs->trans("5MoreChoices").'... ';
159if ($conf->use_javascript_ajax) {
160 print '<div id="addchoice" class="inline-block">';
161 print img_picto('', 'add', '', 0, 0, 0, '', 'valignmiddle btnTitle-icon cursorpointer');
162 print '</div>';
163
164 print '<input type="hidden" name="ajoutcases" id="ajoutcases" value="">';
165 print '<script>
166 // jQuery code to handle the div click event
167 $(document).ready(function() {
168 $("#addchoice").on("click", function() {
169 $("#ajoutcases").val("ajoutcases");
170 $("#surveyform").submit();
171 });
172 });
173 </script>';
174} else {
175 print '<input type="image" name="ajoutcases" src="../img/add-16.png">';
176}
177print '</td><td>';
178print '</td>'."\n";
179print '</tr></table>'."\n";
180print'<br>'."\n";
181
182print '<input type="submit" class="button" name="confirmecreation" value="'.dol_escape_htmltag($langs->trans("CreatePoll")).'">'."\n";
183
184print '</form>'."\n";
185
186
187print '<a name="bas"></a>'."\n";
188print '<br><br><br>'."\n";
189
190print '</div>'."\n";
191
192// End of page
193llxFooter();
194$db->close();
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:71
Class to manage generation of HTML components Only common components must be here.
llxFooter()
Footer empty.
Definition document.php:107
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.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
ajouter_sondage()
Add a poll.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.