dolibarr  16.0.5
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/lib/opensurvey.lib.php";
29 
30 // Security check
31 if (!$user->rights->opensurvey->write) {
33 }
34 
35 
36 
37 /*
38  * Action
39  */
40 
41 $arrayofchoices = GETPOST('choix', 'array');
42 $arrayoftypecolumn = GETPOST('typecolonne', 'array');
43 
44 // Set session vars
45 if (isset($_SESSION["nbrecases"])) {
46  for ($i = 0; $i < $_SESSION["nbrecases"]; $i++) {
47  if (isset($arrayofchoices[$i])) {
48  $_SESSION["choix".$i] = $arrayofchoices[$i];
49  }
50  if (isset($arrayoftypecolumn[$i])) {
51  $_SESSION["typecolonne".$i] = $arrayoftypecolumn[$i];
52  }
53  }
54 } else { //nombre de cases par défaut
55  $_SESSION["nbrecases"] = 5;
56 }
57 
58 if (GETPOST("ajoutcases") || GETPOST("ajoutcases_x")) {
59  $_SESSION["nbrecases"] = $_SESSION["nbrecases"] + 5;
60 }
61 
62 // Create survey into database
63 if (GETPOSTISSET("confirmecreation")) {
64  //recuperation des données de champs textes
65  $toutchoix = '';
66  for ($i = 0; $i < $_SESSION["nbrecases"] + 1; $i++) {
67  if (!empty($arrayofchoices[$i])) {
68  $toutchoix .= ',';
69  $toutchoix .= str_replace(array(",", "@"), " ", $arrayofchoices[$i]).(empty($arrayoftypecolumn[$i]) ? '' : '@'.$arrayoftypecolumn[$i]);
70  }
71  }
72 
73  $toutchoix = substr("$toutchoix", 1);
74  $_SESSION["toutchoix"] = $toutchoix;
75 
76  //test de remplissage des cases
77  $testremplissage = '';
78  for ($i = 0; $i < $_SESSION["nbrecases"]; $i++) {
79  if (isset($arrayofchoices[$i])) {
80  $testremplissage = "ok";
81  }
82  }
83 
84  //message d'erreur si aucun champ renseigné
85  if ($testremplissage != "ok" || (!$toutchoix)) {
86  setEventMessages($langs->trans("ErrorOpenSurveyOneChoice"), null, 'errors');
87  } else {
88  //format du sondage AUTRE
89  $_SESSION["formatsondage"] = "A";
90 
91  // Add into database
92  ajouter_sondage();
93  }
94 }
95 
96 /*
97  * View
98  */
99 
100 $form = new Form($db);
101 
102 $arrayofjs = array();
103 $arrayofcss = array('/opensurvey/css/style.css');
104 llxHeader('', $langs->trans("OpenSurvey"), "", '', 0, 0, $arrayofjs, $arrayofcss);
105 
106 if (empty($_SESSION['title'])) {
107  dol_print_error('', $langs->trans('ErrorOpenSurveyFillFirstSection'));
108  llxFooter();
109  exit;
110 }
111 
112 
113 //partie creation du sondage dans la base SQL
114 //On prépare les données pour les inserer dans la base
115 
116 print '<form name="formulaire" action="#bas" method="POST">'."\n";
117 print '<input type="hidden" name="token" value="'.newToken().'">';
118 
119 print load_fiche_titre($langs->trans("CreatePoll").' (2 / 2)');
120 
121 
122 print '<br>'.$langs->trans("PollOnChoice").'<br><br>'."\n";
123 
124 print '<div class=corps>'."\n";
125 print '<table>'."\n";
126 
127 //affichage des cases texte de formulaire
128 for ($i = 0; $i < $_SESSION["nbrecases"]; $i++) {
129  $j = $i + 1;
130  if (isset($_SESSION["choix$i"]) === false) {
131  $_SESSION["choix$i"] = '';
132  }
133  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.'">';
134  $tmparray = array('checkbox'=>$langs->trans("CheckBox"), 'yesno'=>$langs->trans("YesNoList"), 'foragainst'=>$langs->trans("PourContreList"));
135  print ' &nbsp; '.$langs->trans("Type").' '.$form->selectarray("typecolonne[]", $tmparray, $_SESSION["typecolonne$i"]);
136  print '</td></tr>'."\n";
137 }
138 
139 print '</table>'."\n";
140 
141 //ajout de cases supplementaires
142 print '<table><tr>'."\n";
143 print '<td>'.$langs->trans("5MoreChoices").'</td><td><input type="image" name="ajoutcases" src="../img/add-16.png"></td>'."\n";
144 print '</tr></table>'."\n";
145 print'<br>'."\n";
146 
147 print '<table><tr>'."\n";
148 print '<td></td><td><input type="submit" class="button" name="confirmecreation" value="'.dol_escape_htmltag($langs->trans("CreatePoll")).'"></td>'."\n";
149 print '</tr></table>'."\n";
150 
151 //fin du formulaire et bandeau de pied
152 print '</form>'."\n";
153 
154 
155 print '<a name=bas></a>'."\n";
156 print '<br><br><br>'."\n";
157 print '</div>'."\n";
158 
159 // End of page
160 llxFooter();
161 $db->close();
dol_escape_htmltag
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
Definition: functions.lib.php:1468
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
accessforbidden
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 ...
Definition: security.lib.php:933
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59