choix_autre.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. /**
  19. * \file htdocs/opensurvey/wizard/choix_autre.php
  20. * \ingroup opensurvey
  21. * \brief Page to create a new survey (choice selection)
  22. */
  23. // Load Dolibarr environment
  24. require '../../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
  26. require_once DOL_DOCUMENT_ROOT."/core/lib/files.lib.php";
  27. require_once DOL_DOCUMENT_ROOT."/opensurvey/lib/opensurvey.lib.php";
  28. // Security check
  29. if (!$user->rights->opensurvey->write) {
  30. accessforbidden();
  31. }
  32. /*
  33. * Action
  34. */
  35. $arrayofchoices = GETPOST('choix', 'array');
  36. $arrayoftypecolumn = GETPOST('typecolonne', 'array');
  37. // Set session vars
  38. if (isset($_SESSION["nbrecases"])) {
  39. for ($i = 0; $i < $_SESSION["nbrecases"]; $i++) {
  40. if (isset($arrayofchoices[$i])) {
  41. $_SESSION["choix".$i] = $arrayofchoices[$i];
  42. }
  43. if (isset($arrayoftypecolumn[$i])) {
  44. $_SESSION["typecolonne".$i] = $arrayoftypecolumn[$i];
  45. }
  46. }
  47. } else { //nombre de cases par défaut
  48. $_SESSION["nbrecases"] = 5;
  49. }
  50. if (GETPOST("ajoutcases") || GETPOST("ajoutcases_x")) {
  51. $_SESSION["nbrecases"] = $_SESSION["nbrecases"] + 5;
  52. }
  53. // Create survey into database
  54. if (GETPOSTISSET("confirmecreation")) {
  55. //recuperation des données de champs textes
  56. $toutchoix = '';
  57. for ($i = 0; $i < $_SESSION["nbrecases"] + 1; $i++) {
  58. if (!empty($arrayofchoices[$i])) {
  59. $toutchoix .= ',';
  60. $toutchoix .= str_replace(array(",", "@"), " ", $arrayofchoices[$i]).(empty($arrayoftypecolumn[$i]) ? '' : '@'.$arrayoftypecolumn[$i]);
  61. }
  62. }
  63. $toutchoix = substr("$toutchoix", 1);
  64. $_SESSION["toutchoix"] = $toutchoix;
  65. //test de remplissage des cases
  66. $testremplissage = '';
  67. for ($i = 0; $i < $_SESSION["nbrecases"]; $i++) {
  68. if (isset($arrayofchoices[$i])) {
  69. $testremplissage = "ok";
  70. }
  71. }
  72. //message d'erreur si aucun champ renseigné
  73. if ($testremplissage != "ok" || (!$toutchoix)) {
  74. setEventMessages($langs->trans("ErrorOpenSurveyOneChoice"), null, 'errors');
  75. } else {
  76. //format du sondage AUTRE
  77. $_SESSION["formatsondage"] = "A";
  78. // Add into database
  79. ajouter_sondage();
  80. }
  81. }
  82. /*
  83. * View
  84. */
  85. $form = new Form($db);
  86. $arrayofjs = array();
  87. $arrayofcss = array('/opensurvey/css/style.css');
  88. llxHeader('', $langs->trans("OpenSurvey"), "", '', 0, 0, $arrayofjs, $arrayofcss);
  89. if (empty($_SESSION['title'])) {
  90. dol_print_error('', $langs->trans('ErrorOpenSurveyFillFirstSection'));
  91. llxFooter();
  92. exit;
  93. }
  94. //partie creation du sondage dans la base SQL
  95. //On prépare les données pour les inserer dans la base
  96. print '<form name="formulaire" action="#bas" method="POST">'."\n";
  97. print '<input type="hidden" name="token" value="'.newToken().'">';
  98. print load_fiche_titre($langs->trans("CreatePoll").' (2 / 2)');
  99. print '<br>'.$langs->trans("PollOnChoice").'<br><br>'."\n";
  100. print '<div class=corps>'."\n";
  101. print '<table>'."\n";
  102. //affichage des cases texte de formulaire
  103. for ($i = 0; $i < $_SESSION["nbrecases"]; $i++) {
  104. $j = $i + 1;
  105. if (isset($_SESSION["choix$i"]) === false) {
  106. $_SESSION["choix$i"] = '';
  107. }
  108. 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.'">';
  109. $tmparray = array('checkbox'=>$langs->trans("CheckBox"), 'yesno'=>$langs->trans("YesNoList"), 'foragainst'=>$langs->trans("PourContreList"));
  110. print ' &nbsp; '.$langs->trans("Type").' '.$form->selectarray("typecolonne[]", $tmparray, $_SESSION["typecolonne$i"]);
  111. print '</td></tr>'."\n";
  112. }
  113. print '</table>'."\n";
  114. //ajout de cases supplementaires
  115. print '<table><tr>'."\n";
  116. print '<td>'.$langs->trans("5MoreChoices").'</td><td><input type="image" name="ajoutcases" src="../img/add-16.png"></td>'."\n";
  117. print '</tr></table>'."\n";
  118. print'<br>'."\n";
  119. print '<table><tr>'."\n";
  120. print '<td></td><td><input type="submit" class="button" name="confirmecreation" value="'.dol_escape_htmltag($langs->trans("CreatePoll")).'"></td>'."\n";
  121. print '</tr></table>'."\n";
  122. //fin du formulaire et bandeau de pied
  123. print '</form>'."\n";
  124. print '<a name=bas></a>'."\n";
  125. print '<br><br><br>'."\n";
  126. print '</div>'."\n";
  127. // End of page
  128. llxFooter();
  129. $db->close();