create_survey.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <?php
  2. /* Copyright (C) 2013-2014 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 <http://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/opensurvey/wizard/create_survey.php
  20. * \ingroup opensurvey
  21. * \brief Page to create a new survey
  22. */
  23. require_once('../../main.inc.php');
  24. require_once(DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php");
  25. require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
  26. require_once(DOL_DOCUMENT_ROOT."/core/class/doleditor.class.php");
  27. require_once(DOL_DOCUMENT_ROOT."/opensurvey/fonctions.php");
  28. // Security check
  29. if (!$user->rights->opensurvey->write) accessforbidden();
  30. $langs->load("opensurvey");
  31. // On teste toutes les variables pour supprimer l'ensemble des warnings PHP
  32. // On transforme en entites html les données afin éviter les failles XSS
  33. $post_var = array('titre', 'commentaires', 'mailsonde', 'creation_sondage_date', 'creation_sondage_autre');
  34. foreach ($post_var as $var)
  35. {
  36. $$var = GETPOST($var);
  37. }
  38. // On initialise egalement la session car sinon bonjour les warning :-)
  39. $session_var = array('titre', 'commentaires', 'mailsonde');
  40. foreach ($session_var as $var)
  41. {
  42. if (isset($_SESSION[$var])) $_SESSION[$var] = null;
  43. }
  44. // On initialise également les autres variables
  45. $cocheplus = '';
  46. $cochemail = '';
  47. // Jump to correct page
  48. if (GETPOST("creation_sondage_date") || GETPOST("creation_sondage_autre"))
  49. {
  50. $_SESSION["titre"] = $titre;
  51. $_SESSION["commentaires"] = $commentaires;
  52. if (GETPOST('mailsonde') == 'on') {
  53. $_SESSION["mailsonde"] = true;
  54. } else {
  55. $_SESSION["mailsonde"] = false;
  56. }
  57. if (GETPOST('allow_comments') == 'on') {
  58. $_SESSION['allow_comments'] = true;
  59. } else {
  60. $_SESSION['allow_comments'] = false;
  61. }
  62. if (GETPOST('allow_spy') == 'on') {
  63. $_SESSION['allow_spy'] = true;
  64. } else {
  65. $_SESSION['allow_spy'] = false;
  66. }
  67. $testdate = false;
  68. $champdatefin = dol_mktime(0,0,0,GETPOST('champdatefinmonth'),GETPOST('champdatefinday'),GETPOST('champdatefinyear'));
  69. if (GETPOST('champdatefin') && $champdatefin) // A date was provided
  70. {
  71. // Expire date is not before today
  72. if ($champdatefin - dol_now() > 0)
  73. {
  74. $testdate = true;
  75. $_SESSION['champdatefin'] = dol_print_date($champdatefin,'dayrfc');
  76. }
  77. else
  78. {
  79. $testdate = true;
  80. //setEventMessage($langs->trans('ExpiredDate'),'errors');
  81. }
  82. }
  83. if (! $testdate) {
  84. setEventMessage($langs->trans('ErrorFieldRequired',$langs->transnoentitiesnoconv("ExpireDate")), 'errors');
  85. }
  86. if ($titre && $testdate)
  87. {
  88. if (! empty($creation_sondage_date))
  89. {
  90. header("Location: choix_date.php");
  91. exit();
  92. }
  93. if (! empty($creation_sondage_autre))
  94. {
  95. header("Location: choix_autre.php");
  96. exit();
  97. }
  98. }
  99. }
  100. /*
  101. * View
  102. */
  103. $form = new Form($db);
  104. $arrayofjs=array();
  105. $arrayofcss=array('/opensurvey/css/style.css');
  106. llxHeader('', $langs->trans("OpenSurvey"), '', "", 0, 0, $arrayofjs, $arrayofcss);
  107. print_fiche_titre($langs->trans("CreatePoll").' (1 / 2)');
  108. //debut du formulaire
  109. print '<form name="formulaire" action="" method="POST">'."\n";
  110. //Affichage des différents champs textes a remplir
  111. print '<table class="border" width="100%">'."\n";
  112. print '<tr><td class="fieldrequired">'. $langs->trans("PollTitle") .'</td><td><input type="text" name="titre" size="40" maxlength="80" value="'.$_SESSION["titre"].'"></td>'."\n";
  113. if (! $_SESSION["titre"] && (GETPOST('creation_sondage_date') || GETPOST('creation_sondage_autre')))
  114. {
  115. setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("PollTitle")), 'errors');
  116. }
  117. print '</tr>'."\n";
  118. print '<tr><td>'. $langs->trans("Description") .'</td><td>';
  119. $doleditor=new DolEditor('commentaires', $_SESSION["commentaires"],'',120,'dolibarr_notes','In',1,1,1,ROWS_7,120);
  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->select_date($champdatefin?$champdatefin:-1,'champdatefin','','','',"add",1,0);
  125. print '</tr>'."\n";
  126. print '</table>'."\n";
  127. //focus javascript sur le premier champ
  128. print '<script type="text/javascript">'."\n";
  129. print 'document.formulaire.titre.focus();'."\n";
  130. print '</script>'."\n";
  131. print '<br>'."\n";
  132. // Check or not
  133. if ($_SESSION["mailsonde"]) $cochemail="checked";
  134. print '<input type="checkbox" name="mailsonde" '.$cochemail.'> '. $langs->trans("ToReceiveEMailForEachVote") .'<br>'."\n";
  135. if ($_SESSION['allow_comments']) $allow_comments = 'checked="checked"';
  136. if (isset($_POST['allow_comments'])) $allow_comments=GETPOST('allow_comments')?'checked="checked"':'';
  137. print '<input type="checkbox" name="allow_comments" '.$allow_comments.'"> '.$langs->trans('CanComment').'<br />'."\n";
  138. if ($_SESSION['allow_spy']) $allow_spy = 'checed="checked"';
  139. if (isset($_POST['allow_spy'])) $allow_spy=GETPOST('allow_spy')?'checked="checked"':'';
  140. print '<input type="checkbox" name="allow_spy" '.$allow_spy.'> '.$langs->trans('CanSeeOthersVote').'<br />'."\n";
  141. if (GETPOST('choix_sondage'))
  142. {
  143. if (GETPOST('choix_sondage') == 'date') print '<input type="hidden" name="creation_sondage_date" value="date">';
  144. else print '<input type="hidden" name="creation_sondage_autre" value="autre">';
  145. print '<input type="hidden" name="choix_sondage" value="'.GETPOST('choix_sondage').'">';
  146. print '<br><input type="submit" class="button" name="submit" value="'.$langs->trans("CreatePoll").' ('.(GETPOST('choix_sondage') == 'date'?$langs->trans("TypeDate"):$langs->trans("TypeClassic")).')">';
  147. }
  148. else
  149. {
  150. //affichage des boutons pour choisir sondage date ou autre
  151. print '<br><table>'."\n";
  152. print '<tr><td>'. $langs->trans("CreateSurveyDate") .'</td><td></td> '."\n";
  153. print '<td><input type="image" name="creation_sondage_date" value="'.$langs->trans('CreateSurveyDate').'" src="../img/calendar-32.png"></td></tr>'."\n";
  154. print '<tr><td>'. $langs->trans("CreateSurveyStandard") .'</td><td></td> '."\n";
  155. print '<td><input type="image" name="creation_sondage_autre" value="'.$langs->trans('CreateSurveyStandard').'" src="../img/chart-32.png"></td></tr>'."\n";
  156. print '</table>'."\n";
  157. }
  158. print '<br><br><br>'."\n";
  159. print '</form>'."\n";
  160. llxFooter();
  161. $db->close();