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