create_survey.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <?php
  2. /* Copyright (C) 2013-2014 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
  4. * Copyright (C) 2015-2016 Alexandre Spangaro <aspangaro@open-dsi.fr>
  5. * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/opensurvey/wizard/create_survey.php
  22. * \ingroup opensurvey
  23. * \brief Page to create a new survey
  24. */
  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."/core/class/doleditor.class.php";
  30. require_once DOL_DOCUMENT_ROOT."/opensurvey/lib/opensurvey.lib.php";
  31. // Security check
  32. if (!$user->hasRight('opensurvey', 'write')) {
  33. accessforbidden();
  34. }
  35. $langs->load("opensurvey");
  36. $title = GETPOST('title');
  37. $description = GETPOST('description', 'restricthtml');
  38. $mailsonde = GETPOST('mailsonde');
  39. $creation_sondage_date = GETPOST('creation_sondage_date');
  40. $creation_sondage_autre = GETPOST('creation_sondage_autre');
  41. // We init some session variable to avoir warning
  42. $session_var = array('title', 'description', 'mailsonde');
  43. foreach ($session_var as $var) {
  44. if (isset($_SESSION[$var])) {
  45. $_SESSION[$var] = null;
  46. }
  47. }
  48. // On initialise également les autres variables
  49. $cocheplus = '';
  50. $cochemail = '';
  51. // Jump to correct page
  52. if (!empty($creation_sondage_date) || !empty($creation_sondage_autre)) {
  53. $_SESSION["title"] = $title;
  54. $_SESSION["description"] = $description;
  55. if (GETPOST('mailsonde') == 'on') {
  56. $_SESSION["mailsonde"] = true;
  57. } else {
  58. $_SESSION["mailsonde"] = false;
  59. }
  60. if (GETPOST('allow_comments') == 'on') {
  61. $_SESSION['allow_comments'] = true;
  62. } else {
  63. $_SESSION['allow_comments'] = false;
  64. }
  65. if (GETPOST('allow_spy') == 'on') {
  66. $_SESSION['allow_spy'] = true;
  67. } else {
  68. $_SESSION['allow_spy'] = false;
  69. }
  70. $testdate = false;
  71. $champdatefin = dol_mktime(0, 0, 0, GETPOST('champdatefinmonth'), GETPOST('champdatefinday'), GETPOST('champdatefinyear'));
  72. if ($champdatefin && ($champdatefin > 0)) { // A date was provided
  73. // Expire date is not before today
  74. if ($champdatefin >= dol_now()) {
  75. $testdate = true;
  76. $_SESSION['champdatefin'] = dol_print_date($champdatefin, 'dayrfc');
  77. } else {
  78. $testdate = true;
  79. $_SESSION['champdatefin'] = dol_print_date($champdatefin, 'dayrfc');
  80. //$testdate = false;
  81. //$_SESSION['champdatefin'] = dol_print_date($champdatefin,'dayrfc');
  82. setEventMessages('ExpireDate', null, 'warnings');
  83. }
  84. }
  85. if (!$testdate) {
  86. setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("ExpireDate")), null, 'errors');
  87. }
  88. if ($title && $testdate) {
  89. if (!empty($creation_sondage_date)) {
  90. header("Location: choix_date.php");
  91. exit();
  92. }
  93. if (!empty($creation_sondage_autre)) {
  94. header("Location: choix_autre.php");
  95. exit();
  96. }
  97. }
  98. }
  99. /*
  100. * View
  101. */
  102. $form = new Form($db);
  103. $arrayofjs = array();
  104. $arrayofcss = array('/opensurvey/css/style.css');
  105. llxHeader('', $langs->trans("OpenSurvey"), '', "", 0, 0, $arrayofjs, $arrayofcss);
  106. print load_fiche_titre($langs->trans("CreatePoll").' (1 / 2)');
  107. // debut du formulaire
  108. print '<form name="formulaire" action="" method="POST">'."\n";
  109. print '<input type="hidden" name="token" value="'.newToken().'">';
  110. print dol_get_fiche_head();
  111. // Affichage des différents champs textes a remplir
  112. print '<table class="border centpercent">'."\n";
  113. print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("PollTitle").'</td><td><input type="text" name="title" class="minwidth300" maxlength="80" value="'.$_SESSION["title"].'"></td>'."\n";
  114. if (!$_SESSION["title"] && (GETPOST('creation_sondage_date') || GETPOST('creation_sondage_autre'))) {
  115. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PollTitle")), null, 'errors');
  116. }
  117. print '</tr>'."\n";
  118. print '<tr><td>'.$langs->trans("Description").'</td><td>';
  119. $doleditor = new DolEditor('description', $_SESSION["description"], '', 120, 'dolibarr_notes', 'In', 1, 1, 1, ROWS_7, '90%');
  120. $doleditor->Create(0, '');
  121. print '</td>'."\n";
  122. print '</tr>'."\n";
  123. print '<tr><td class="fieldrequired">'.$langs->trans("ExpireDate").'</td><td>';
  124. print $form->selectDate($champdatefin ? $champdatefin : -1, 'champdatefin', '', '', '', "add", 1, 0);
  125. print '</tr>'."\n";
  126. print '</table>'."\n";
  127. print dol_get_fiche_end();
  128. //focus javascript sur le premier champ
  129. print '<script type="text/javascript">'."\n";
  130. print 'document.formulaire.title.focus();'."\n";
  131. print '</script>'."\n";
  132. print '<br>'."\n";
  133. // Check or not
  134. if ($_SESSION["mailsonde"]) {
  135. $cochemail = "checked";
  136. }
  137. print '<input type="checkbox" id="mailsonde" name="mailsonde" '.$cochemail.'> <label for="mailsonde">'.$langs->trans("ToReceiveEMailForEachVote").'</label><br>'."\n";
  138. if ($_SESSION['allow_comments']) {
  139. $allow_comments = 'checked';
  140. }
  141. if (GETPOSTISSET('allow_comments')) {
  142. $allow_comments = GETPOST('allow_comments') ? 'checked' : '';
  143. }
  144. print '<input type="checkbox" id="allow_comments" name="allow_comments" '.$allow_comments.'"> <label for="allow_comments">'.$langs->trans('CanComment').'</label><br>'."\n";
  145. if ($_SESSION['allow_spy']) {
  146. $allow_spy = 'checked';
  147. }
  148. if (GETPOSTISSET('allow_spy')) {
  149. $allow_spy = GETPOST('allow_spy') ? 'checked' : '';
  150. }
  151. print '<input type="checkbox" id="allow_spy" name="allow_spy" '.$allow_spy.'> <label for="allow_spy">'.$langs->trans('CanSeeOthersVote').'</label><br>'."\n";
  152. if (GETPOST('choix_sondage')) {
  153. if (GETPOST('choix_sondage') == 'date') {
  154. print '<input type="hidden" name="creation_sondage_date" value="date">';
  155. } else {
  156. print '<input type="hidden" name="creation_sondage_autre" value="autre">';
  157. }
  158. print '<input type="hidden" name="choix_sondage" value="'.GETPOST('choix_sondage').'">';
  159. print '<br><input type="submit" class="button" name="submit" value="'.$langs->trans("CreatePoll").' ('.(GETPOST('choix_sondage') == 'date' ? $langs->trans("TypeDate") : $langs->trans("TypeClassic")).')">';
  160. } else {
  161. // Show image to selecte between date survey or other survey
  162. print '<br><table>'."\n";
  163. print '<tr><td>'.$langs->trans("CreateSurveyDate").'</td><td></td> '."\n";
  164. print '<td><input type="image" name="creation_sondage_date" value="'.$langs->trans('CreateSurveyDate').'" src="../img/calendar-32.png"></td></tr>'."\n";
  165. print '<tr><td>'.$langs->trans("CreateSurveyStandard").'</td><td></td> '."\n";
  166. print '<td><input type="image" name="creation_sondage_autre" value="'.$langs->trans('CreateSurveyStandard').'" src="../img/chart-32.png"></td></tr>'."\n";
  167. print '</table>'."\n";
  168. }
  169. print '<br><br><br>'."\n";
  170. print '</form>'."\n";
  171. // End of page
  172. llxFooter();
  173. $db->close();