dolibarr  13.0.2
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 require '../../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
27 require_once DOL_DOCUMENT_ROOT."/core/lib/files.lib.php";
28 require_once DOL_DOCUMENT_ROOT."/opensurvey/fonctions.php";
29 
30 // Security check
31 if (!$user->rights->opensurvey->write) accessforbidden();
32 
33 
34 
35 /*
36  * Action
37  */
38 
39 $arrayofchoices = GETPOST('choix', 'array');
40 $arrayoftypecolumn = GETPOST('typecolonne', 'array');
41 
42 // Set session vars
43 if (isset($_SESSION["nbrecases"])) {
44  for ($i = 0; $i < $_SESSION["nbrecases"]; $i++) {
45  if (isset($arrayofchoices[$i])) {
46  $_SESSION["choix".$i] = $arrayofchoices[$i];
47  }
48  if (isset($arrayoftypecolumn[$i])) {
49  $_SESSION["typecolonne".$i] = $arrayoftypecolumn[$i];
50  }
51  }
52 } else { //nombre de cases par défaut
53  $_SESSION["nbrecases"] = 5;
54 }
55 
56 if (GETPOST("ajoutcases") || GETPOST("ajoutcases_x"))
57 {
58  $_SESSION["nbrecases"] = $_SESSION["nbrecases"] + 5;
59 }
60 
61 // Create survey into database
62 if (GETPOSTISSET("confirmecreation"))
63 {
64  //recuperation des données de champs textes
65  $toutchoix = '';
66  for ($i = 0; $i < $_SESSION["nbrecases"] + 1; $i++)
67  {
68  if (!empty($arrayofchoices[$i]))
69  {
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  {
82  if (isset($arrayofchoices[$i]))
83  {
84  $testremplissage = "ok";
85  }
86  }
87 
88  //message d'erreur si aucun champ renseigné
89  if ($testremplissage != "ok" || (!$toutchoix)) {
90  setEventMessages($langs->trans("ErrorOpenSurveyOneChoice"), null, 'errors');
91  } else {
92  //format du sondage AUTRE
93  $_SESSION["formatsondage"] = "A";
94 
95  // Add into database
97  }
98 }
99 
100 /*
101  * View
102  */
103 
104 $form = new Form($db);
105 
106 $arrayofjs = array();
107 $arrayofcss = array('/opensurvey/css/style.css');
108 llxHeader('', $langs->trans("OpenSurvey"), "", '', 0, 0, $arrayofjs, $arrayofcss);
109 
110 if (empty($_SESSION['title']))
111 {
112  dol_print_error('', $langs->trans('ErrorOpenSurveyFillFirstSection'));
113  llxFooter();
114  exit;
115 }
116 
117 
118 //partie creation du sondage dans la base SQL
119 //On prépare les données pour les inserer dans la base
120 
121 print '<form name="formulaire" action="#bas" method="POST">'."\n";
122 print '<input type="hidden" name="token" value="'.newToken().'">';
123 
124 print load_fiche_titre($langs->trans("CreatePoll").' (2 / 2)');
125 
126 
127 print '<br>'.$langs->trans("PollOnChoice").'<br><br>'."\n";
128 
129 print '<div class=corps>'."\n";
130 print '<table>'."\n";
131 
132 //affichage des cases texte de formulaire
133 for ($i = 0; $i < $_SESSION["nbrecases"]; $i++) {
134  $j = $i + 1;
135  if (isset($_SESSION["choix$i"]) === false) {
136  $_SESSION["choix$i"] = '';
137  }
138  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.'">';
139  $tmparray = array('checkbox'=>$langs->trans("CheckBox"), 'yesno'=>$langs->trans("YesNoList"), 'foragainst'=>$langs->trans("PourContreList"));
140  print ' &nbsp; '.$langs->trans("Type").' '.$form->selectarray("typecolonne[]", $tmparray, $_SESSION["typecolonne$i"]);
141  print '</td></tr>'."\n";
142 }
143 
144 print '</table>'."\n";
145 
146 //ajout de cases supplementaires
147 print '<table><tr>'."\n";
148 print '<td>'.$langs->trans("5MoreChoices").'</td><td><input type="image" name="ajoutcases" src="../img/add-16.png"></td>'."\n";
149 print '</tr></table>'."\n";
150 print'<br>'."\n";
151 
152 print '<table><tr>'."\n";
153 print '<td></td><td><input type="submit" class="button" name="confirmecreation" value="'.dol_escape_htmltag($langs->trans("CreatePoll")).'"></td>'."\n";
154 print '</tr></table>'."\n";
155 
156 //fin du formulaire et bandeau de pied
157 print '</form>'."\n";
158 
159 
160 print '<a name=bas></a>'."\n";
161 print '<br><br><br>'."\n";
162 print '</div>'."\n";
163 
164 // End of page
165 llxFooter();
166 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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 ...
print
Draft customers invoices.
Definition: index.php:89
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
ajouter_sondage()
Add a poll.
Definition: fonctions.php:226
llxFooter()
Empty footer.
Definition: wrapper.php:59
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $keepmoretags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...