dolibarr 23.0.3
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 $toutchoix = '';
78 for ($i = 0; $i < $_SESSION["nbrecases"] + 1; $i++) {
79 $tmpchoice = $arrayofchoices[$i];
80 $tmptypecolumn = GETPOST('typecolonne'.$i, 'alphanohtml');
81 if (!empty($tmpchoice)) {
82 $toutchoix .= ',';
83 $toutchoix .= str_replace(array(",", "@"), " ", $tmpchoice).(empty($tmptypecolumn) ? '' : '@'.$tmptypecolumn);
84 }
85 }
86
87 $toutchoix = substr($toutchoix, 1);
88 $_SESSION["toutchoix"] = $toutchoix;
89
90 //test de remplissage des cases
91 $testremplissage = '';
92 for ($i = 0; $i < $_SESSION["nbrecases"]; $i++) {
93 if (isset($arrayofchoices[$i])) {
94 $testremplissage = "ok";
95 }
96 }
97
98 // Error if no field defined
99 if ($testremplissage != "ok" || (!$toutchoix)) {
100 setEventMessages($langs->trans("ErrorOpenSurveyOneChoice"), null, 'errors');
101 } else {
102 // format of survey AUTRE
103 $_SESSION["formatsondage"] = "A";
104
105 // Add into database
107 }
108}
109
110/*
111 * View
112 */
113
114$form = new Form($db);
115
116$arrayofjs = array();
117$arrayofcss = array('/opensurvey/css/style.css');
118llxHeader('', $langs->trans("OpenSurvey"), "", '', 0, 0, $arrayofjs, $arrayofcss);
119
120if (empty($_SESSION['title'])) {
121 dol_print_error(null, $langs->trans('ErrorOpenSurveyFillFirstSection'));
122 llxFooter();
123 exit;
124}
125
126
127//partie creation du sondage dans la base SQL
128//On prépare les données pour les inserer dans la base
129
130print '<form name="formulaire" id="surveyform" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";
131print '<input type="hidden" name="token" value="'.newToken().'">';
132
133print load_fiche_titre($langs->trans("CreatePoll").' (2 / 2)');
134
135
136print '<br>'.$langs->trans("PollOnChoice").'<br><br>'."\n";
137
138print '<div>'."\n";
139
140print '<table>'."\n";
141
142//affichage des cases texte de formulaire
143for ($i = 0; $i < $_SESSION["nbrecases"]; $i++) {
144 $j = $i + 1;
145 if (!isset($_SESSION["choix$i"])) {
146 $_SESSION["choix$i"] = '';
147 }
148 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.'">';
149 $tmparray = array('checkbox' => $langs->trans("CheckBox"), 'yesno' => $langs->trans("YesNoList"), 'foragainst' => $langs->trans("PourContreList"));
150
151 print ' &nbsp; '.$langs->trans("Type").' '.$form->selectarray("typecolonne".$i, $tmparray, $_SESSION["typecolonne".$i]);
152 print '</td></tr>'."\n";
153}
154
155print '</table>'."\n";
156
157//ajout de cases supplementaires
158print '<table><tr>'."\n";
159print '<td class="center">'.$langs->trans("5MoreChoices").'... ';
160if ($conf->use_javascript_ajax) {
161 print '<div id="addchoice" class="inline-block">';
162 print img_picto('', 'add', '', 0, 0, 0, '', 'valignmiddle btnTitle-icon cursorpointer');
163 print '</div>';
164
165 print '<input type="hidden" name="ajoutcases" id="ajoutcases" value="">';
166 print '<script>
167 // jQuery code to handle the div click event
168 $(document).ready(function() {
169 $("#addchoice").on("click", function() {
170 console.log("Click on adchoice");
171 $("#ajoutcases").val("ajoutcases");
172 $("#surveyform").submit();
173 });
174 });
175 </script>';
176} else {
177 print '<input type="image" name="ajoutcases" src="../img/add-16.png">';
178}
179print '</td><td>';
180print '</td>'."\n";
181print '</tr></table>'."\n";
182print'<br>'."\n";
183
184print '<input type="submit" class="button" name="confirmecreation" value="'.dol_escape_htmltag($langs->trans("CreatePoll")).'">'."\n";
185
186print '</form>'."\n";
187
188
189print '<a name="bas"></a>'."\n";
190print '<br><br><br>'."\n";
191
192print '</div>'."\n";
193
194// End of page
195llxFooter();
196$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 generation of HTML components Only common components must be here.
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, $allowothertags=array())
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...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
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...
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.