dolibarr 21.0.0-alpha
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 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26// Load Dolibarr environment
27require '../../main.inc.php';
28require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
29require_once DOL_DOCUMENT_ROOT."/core/lib/files.lib.php";
30require_once DOL_DOCUMENT_ROOT."/opensurvey/lib/opensurvey.lib.php";
31
32// Security check
33if (!$user->hasRight('opensurvey', 'write')) {
35}
36
37
38
39/*
40 * Action
41 */
42
43$arrayofchoices = GETPOST('choix', 'array');
44$arrayoftypecolumn = GETPOST('typecolonne', 'array');
45
46// Set session vars
47if (isset($_SESSION["nbrecases"])) {
48 for ($i = 0; $i < $_SESSION["nbrecases"]; $i++) {
49 if (isset($arrayofchoices[$i])) {
50 $_SESSION["choix".$i] = $arrayofchoices[$i];
51 }
52 if (isset($arrayoftypecolumn[$i])) {
53 $_SESSION["typecolonne".$i] = $arrayoftypecolumn[$i];
54 }
55 }
56} else { //nombre de cases par défaut
57 $_SESSION["nbrecases"] = 5;
58}
59
60if (GETPOST("ajoutcases") || GETPOST("ajoutcases_x")) {
61 $_SESSION["nbrecases"] += 5;
62}
63
64// Create survey into database
65if (GETPOSTISSET("confirmecreation")) {
66 //recuperation des données de champs textes
67 $toutchoix = '';
68 for ($i = 0; $i < $_SESSION["nbrecases"] + 1; $i++) {
69 if (!empty($arrayofchoices[$i])) {
70 $toutchoix .= ',';
71 $toutchoix .= str_replace(array(",", "@"), " ", $arrayofchoices[$i]).(empty($arrayoftypecolumn[$i]) ? '' : '@'.$arrayoftypecolumn[$i]);
72 }
73 }
74
75 $toutchoix = substr("$toutchoix", 1);
76 $_SESSION["toutchoix"] = $toutchoix;
77
78 //test de remplissage des cases
79 $testremplissage = '';
80 for ($i = 0; $i < $_SESSION["nbrecases"]; $i++) {
81 if (isset($arrayofchoices[$i])) {
82 $testremplissage = "ok";
83 }
84 }
85
86 //message d'erreur si aucun champ renseigné
87 if ($testremplissage != "ok" || (!$toutchoix)) {
88 setEventMessages($langs->trans("ErrorOpenSurveyOneChoice"), null, 'errors');
89 } else {
90 //format du sondage AUTRE
91 $_SESSION["formatsondage"] = "A";
92
93 // Add into database
95 }
96}
97
98/*
99 * View
100 */
101
102$form = new Form($db);
103
104$arrayofjs = array();
105$arrayofcss = array('/opensurvey/css/style.css');
106llxHeader('', $langs->trans("OpenSurvey"), "", '', 0, 0, $arrayofjs, $arrayofcss);
107
108if (empty($_SESSION['title'])) {
109 dol_print_error(null, $langs->trans('ErrorOpenSurveyFillFirstSection'));
110 llxFooter();
111 exit;
112}
113
114
115//partie creation du sondage dans la base SQL
116//On prépare les données pour les inserer dans la base
117
118print '<form name="formulaire" action="#bas" method="POST">'."\n";
119print '<input type="hidden" name="token" value="'.newToken().'">';
120
121print load_fiche_titre($langs->trans("CreatePoll").' (2 / 2)');
122
123
124print '<br>'.$langs->trans("PollOnChoice").'<br><br>'."\n";
125
126print '<div class=corps>'."\n";
127print '<table>'."\n";
128
129//affichage des cases texte de formulaire
130for ($i = 0; $i < $_SESSION["nbrecases"]; $i++) {
131 $j = $i + 1;
132 if (!isset($_SESSION["choix$i"])) {
133 $_SESSION["choix$i"] = '';
134 }
135 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.'">';
136 $tmparray = array('checkbox' => $langs->trans("CheckBox"), 'yesno' => $langs->trans("YesNoList"), 'foragainst' => $langs->trans("PourContreList"));
137 print ' &nbsp; '.$langs->trans("Type").' '.$form->selectarray("typecolonne[]", $tmparray, $_SESSION["typecolonne$i"]);
138 print '</td></tr>'."\n";
139}
140
141print '</table>'."\n";
142
143//ajout de cases supplementaires
144print '<table><tr>'."\n";
145print '<td>'.$langs->trans("5MoreChoices").'</td><td><input type="image" name="ajoutcases" src="../img/add-16.png"></td>'."\n";
146print '</tr></table>'."\n";
147print'<br>'."\n";
148
149print '<table><tr>'."\n";
150print '<td></td><td><input type="submit" class="button" name="confirmecreation" value="'.dol_escape_htmltag($langs->trans("CreatePoll")).'"></td>'."\n";
151print '</tr></table>'."\n";
152
153//fin du formulaire et bandeau de pied
154print '</form>'."\n";
155
156
157print '<a name="bas"></a>'."\n";
158print '<br><br><br>'."\n";
159print '</div>'."\n";
160
161// End of page
162llxFooter();
163$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:70
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.
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...
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.