25 if (!defined(
'NOLOGIN')) {
28 if (!defined(
'NOCSRFCHECK')) {
29 define(
"NOCSRFCHECK", 1);
31 if (!defined(
'NOBROWSERNOTIF')) {
32 define(
'NOBROWSERNOTIF',
'1');
34 if (!defined(
'NOIPCHECK')) {
35 define(
'NOIPCHECK',
'1');
38 require
'../../main.inc.php';
39 require_once DOL_DOCUMENT_ROOT.
"/core/lib/admin.lib.php";
40 require_once DOL_DOCUMENT_ROOT.
"/core/lib/files.lib.php";
41 require_once DOL_DOCUMENT_ROOT.
"/opensurvey/class/opensurveysondage.class.php";
42 require_once DOL_DOCUMENT_ROOT.
"/opensurvey/lib/opensurvey.lib.php";
46 $action =
GETPOST(
'action',
'aZ09');
49 $numsondage =
GETPOST(
'sondage',
'alpha');
53 $result = $object->fetch(0, $numsondage);
55 $nblines = $object->fetch_lines();
61 if (empty($conf->opensurvey->enabled)) {
70 $nbcolonnes = substr_count($object->sujet,
',') + 1;
72 $listofvoters = explode(
',', $_SESSION[
"savevoter"]);
75 if (
GETPOST(
'ajoutcomment',
'alpha')) {
76 if (!$canbemodified) {
82 $comment =
GETPOST(
"comment",
'alphanohtml');
83 $comment_user =
GETPOST(
'commentuser',
'alphanohtml');
87 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Comment")),
null,
'errors');
91 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Name")),
null,
'errors');
94 if (!in_array($comment_user, $listofvoters)) {
95 setEventMessages($langs->trans(
"UserMustBeSameThanUserUsedToVote"),
null,
'errors');
100 $resql = $object->addComment($comment, $comment_user);
110 if (!$canbemodified) {
115 if (
GETPOST(
'nom',
'alphanohtml')) {
117 for ($i = 0; $i < $nbcolonnes; $i++) {
119 $nouveauchoix .=
"1";
121 $nouveauchoix .=
"2";
123 $nouveauchoix .=
"0";
127 $nom = substr(
GETPOST(
"nom",
'alphanohtml'), 0, 64);
130 $sql =
'SELECT id_users, nom as name';
131 $sql .=
' FROM '.MAIN_DB_PREFIX.
'opensurvey_user_studs';
132 $sql .=
" WHERE id_sondage='".$db->escape($numsondage).
"' AND nom = '".$db->escape($nom).
"' ORDER BY id_users";
133 $resql = $db->query($sql);
138 $num_rows = $db->num_rows(
$resql);
143 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.
'opensurvey_user_studs (nom, id_sondage, reponses)';
144 $sql .=
" VALUES ('".$db->escape($nom).
"', '".$db->escape($numsondage).
"','".$db->escape($nouveauchoix).
"')";
145 $resql = $db->query($sql);
149 $_SESSION[
"savevoter"] = $nom.
','.(empty($_SESSION[
"savevoter"]) ?
'' : $_SESSION[
"savevoter"]);
150 $listofvoters = explode(
',', $_SESSION[
"savevoter"]);
152 if ($object->mailsonde) {
153 if ($object->fk_user_creat) {
154 $userstatic =
new User($db);
155 $userstatic->fetch($object->fk_user_creat);
157 $email = $userstatic->email;
159 $email = $object->mail_admin;
164 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
166 $application = ($conf->global->MAIN_APPLICATION_TITLE ? $conf->global->MAIN_APPLICATION_TITLE :
'Dolibarr ERP/CRM');
168 $link = getUrlSondage($numsondage,
true);
169 $link =
'<a href="'.$link.
'">'.$link.
'</a>';
170 $body = str_replace(
'\n',
'<br>', $langs->transnoentities(
'EmailSomeoneVoted', $nom, $link));
173 $cmailfile =
new CMailFile(
"[".$application.
"] ".$langs->trans(
"Poll").
': '.$object->title, $email, $conf->global->MAIN_MAIL_EMAIL_FROM, $body,
null,
null,
null,
'',
'', 0, -1);
174 $result = $cmailfile->sendfile();
182 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Name")),
null,
'errors');
188 $testmodifier =
false;
189 $testligneamodifier =
false;
190 $ligneamodifier = -1;
191 for ($i = 0; $i < $nblines; $i++) {
193 $ligneamodifier = $i;
194 $testligneamodifier =
true;
200 $testmodifier =
true;
206 for ($i = 0; $i < $nbcolonnes; $i++) {
208 $nouveauchoix .=
"1";
210 $nouveauchoix .=
"2";
212 $nouveauchoix .=
"0";
216 if (!$canbemodified) {
220 $idtomodify =
GETPOST(
"idtomodify".$modifier);
221 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"opensurvey_user_studs";
222 $sql .=
" SET reponses = '".$db->escape($nouveauchoix).
"'";
223 $sql .=
" WHERE id_users = '".$db->escape($idtomodify).
"'";
225 $resql = $db->query($sql);
232 $idcomment =
GETPOST(
'deletecomment',
'int');
234 if (!$canbemodified) {
238 $resql = $object->deleteComment($idcomment);
249 $arrayofjs = array();
250 $arrayofcss = array(
'/opensurvey/css/style.css');
252 llxHeaderSurvey($object->title,
"", 0, 0, $arrayofjs, $arrayofcss, $numsondage);
254 if (empty($object->ref)) {
255 $langs->load(
"errors");
256 print $langs->trans(
"ErrorRecordNotFound");
265 $toutsujet = explode(
",", $object->sujet);
266 $listofanswers = array();
267 foreach ($toutsujet as $value) {
268 $tmp = explode(
'@', $value);
269 $listofanswers[] = array(
'label'=>$tmp[0],
'format'=>($tmp[1] ? $tmp[1] :
'checkbox'));
271 $toutsujet = str_replace(
"°",
"'", $toutsujet);
275 print
'<div class="survey_invitation">'.$langs->trans(
"YouAreInivitedToVote").
'</div>';
276 print $langs->trans(
"OpenSurveyHowTo").
'<br>';
277 if (empty($object->allow_spy)) {
278 print
'<span class="opacitymedium">'.$langs->trans(
"YourVoteIsPrivate").
'</span><br>';
280 print
$form->textwithpicto(
'<span class="opacitymedium">'.$langs->trans(
"YourVoteIsPublic").
'</span>', $langs->trans(
"CanSeeOthersVote")).
'<br>';
284 print
'<div class="corps"> '.
"\n";
287 $titre = str_replace(
"\\",
"", $object->title);
288 print
'<strong>'.dol_htmlentities($titre).
'</strong>';
291 if ($object->description) {
292 print
'<br><br>'.
"\n";
300 if (!$canbemodified) {
301 print
'<br><center><div class="quatrevingtpercent center warning">'.$langs->trans(
'SurveyExpiredInfo').
'</div></center>';
308 print
'<div class="cadre"> '.
"\n";
309 print
'<br><br>'.
"\n";
312 print
'<table class="resultats">'.
"\n";
315 if ($object->format ==
"D") {
318 print
'<td></td>'.
"\n";
322 $nbofsujet = count($toutsujet);
323 for ($i = 0; $i < $nbofsujet; $i++) {
324 if (isset($toutsujet[$i + 1]) && date(
'Y', intval($toutsujet[$i])) == date(
'Y', intval($toutsujet[$i + 1]))) {
327 print
'<td colspan='.$colspan.
' class="annee">'.date(
'Y', intval($toutsujet[$i])).
'</td>'.
"\n";
334 print
'<td></td>'.
"\n";
338 for ($i = 0; $i < $nbofsujet; $i++) {
339 $cur = intval($toutsujet[$i]);
341 if (isset($toutsujet[$i + 1]) ===
false) {
344 $next = intval($toutsujet[$i + 1]);
350 print
'<td colspan='.$colspan.
' class="mois">'.
dol_print_date($cur,
"%B").
'</td>'.
"\n";
357 print
'<td></td>'.
"\n";
361 for ($i = 0; $i < $nbofsujet; $i++) {
362 $cur = intval($toutsujet[$i]);
363 if (isset($toutsujet[$i + 1]) ===
false) {
366 $next = intval($toutsujet[$i + 1]);
371 print
'<td colspan="'.$colspan.
'" class="jour">'.
dol_print_date($cur,
"%a %e").
'</td>'.
"\n";
379 if (strpos($object->sujet,
'@') !==
false) {
381 print
'<td></td>'.
"\n";
383 for ($i = 0; isset($toutsujet[$i]); $i++) {
384 $heures = explode(
'@', $toutsujet[$i]);
385 if (isset($heures[1])) {
386 print
'<td class="heure">'.dol_htmlentities($heures[1]).
'</td>'.
"\n";
388 print
'<td class="heure"></td>'.
"\n";
397 print
'<td></td>'.
"\n";
399 for ($i = 0; isset($toutsujet[$i]); $i++) {
400 $tmp = explode(
'@', $toutsujet[$i]);
401 print
'<td class="sujet">'.dol_escape_htmltag($tmp[0]).
'</td>'.
"\n";
410 $sumagainst = array();
412 $sql =
"SELECT id_users, nom as name, id_sondage, reponses";
413 $sql .=
" FROM ".MAIN_DB_PREFIX.
"opensurvey_user_studs";
414 $sql .=
" WHERE id_sondage = '".$db->escape($numsondage).
"'";
415 $resql = $db->query($sql);
420 $num = $db->num_rows(
$resql);
421 while ($compteur < $num) {
422 $obj = $db->fetch_object(
$resql);
424 $ensemblereponses = $obj->reponses;
427 $mod_ok = (in_array($obj->name, $listofvoters));
429 if (!$mod_ok && !$object->allow_spy) {
437 print
'<td class="nom">'.dol_htmlentities($obj->name).
'</td>'.
"\n";
440 if (!$testligneamodifier) {
441 for ($i = 0; $i < $nbcolonnes; $i++) {
442 $car = substr($ensemblereponses, $i, 1);
445 if (empty($listofanswers[$i][
'format']) || !in_array($listofanswers[$i][
'format'], array(
'yesno',
'foragainst'))) {
446 if (((
string) $car) ==
"1") {
447 print
'<td class="ok">OK</td>'.
"\n";
449 print
'<td class="non">KO</td>'.
"\n";
452 if (!isset($sumfor[$i])) {
455 if (((
string) $car) ==
"1") {
459 if (!empty($listofanswers[$i][
'format']) && $listofanswers[$i][
'format'] ==
'yesno') {
460 if (((
string) $car) ==
"1") {
461 print
'<td class="ok">'.$langs->trans(
"Yes").
'</td>'.
"\n";
462 } elseif (((
string) $car) ==
"0") {
463 print
'<td class="non">'.$langs->trans(
"No").
'</td>'.
"\n";
465 print
'<td class="vide"> </td>'.
"\n";
468 if (!isset($sumfor[$i])) {
471 if (!isset($sumagainst[$i])) {
474 if (((
string) $car) ==
"1") {
477 if (((
string) $car) ==
"0") {
481 if (!empty($listofanswers[$i][
'format']) && $listofanswers[$i][
'format'] ==
'foragainst') {
482 if (((
string) $car) ==
"1") {
483 print
'<td class="ok">'.$langs->trans(
"For").
'</td>'.
"\n";
484 } elseif (((
string) $car) ==
"0") {
485 print
'<td class="non">'.$langs->trans(
"Against").
'</td>'.
"\n";
487 print
'<td class="vide"> </td>'.
"\n";
490 if (!isset($sumfor[$i])) {
493 if (!isset($sumagainst[$i])) {
496 if (((
string) $car) ==
"1") {
499 if (((
string) $car) ==
"0") {
506 if ($compteur == $ligneamodifier) {
507 for ($i = 0; $i < $nbcolonnes; $i++) {
508 $car = substr($ensemblereponses, $i, 1);
509 print
'<td class="vide">';
510 if (empty($listofanswers[$i][
'format']) || !in_array($listofanswers[$i][
'format'], array(
'yesno',
'foragainst'))) {
511 print
'<input type="checkbox" name="choix'.$i.
'" value="1" ';
517 if (!empty($listofanswers[$i][
'format']) && $listofanswers[$i][
'format'] ==
'yesno') {
518 $arraychoice = array(
'2'=>
' ',
'0'=>$langs->trans(
"No"),
'1'=>$langs->trans(
"Yes"));
519 print
$form->selectarray(
"choix".$i, $arraychoice, $car);
521 if (!empty($listofanswers[$i][
'format']) && $listofanswers[$i][
'format'] ==
'foragainst') {
522 $arraychoice = array(
'2'=>
' ',
'0'=>$langs->trans(
"Against"),
'1'=>$langs->trans(
"For"));
523 print
$form->selectarray(
"choix".$i, $arraychoice, $car);
528 for ($i = 0; $i < $nbcolonnes; $i++) {
529 $car = substr($ensemblereponses, $i, 1);
530 if (empty($listofanswers[$i][
'format']) || !in_array($listofanswers[$i][
'format'], array(
'yesno',
'foragainst'))) {
531 if (((
string) $car) ==
"1") {
532 print
'<td class="ok">OK</td>'.
"\n";
534 print
'<td class="non">KO</td>'.
"\n";
537 if (!isset($sumfor[$i])) {
540 if (((
string) $car) ==
"1") {
544 if (!empty($listofanswers[$i][
'format']) && $listofanswers[$i][
'format'] ==
'yesno') {
545 if (((
string) $car) ==
"1") {
546 print
'<td class="ok">'.$langs->trans(
"For").
'</td>'.
"\n";
547 } elseif (((
string) $car) ==
"0") {
548 print
'<td class="non">'.$langs->trans(
"Against").
'</td>'.
"\n";
550 print
'<td class="vide"> </td>'.
"\n";
553 if (!isset($sumfor[$i])) {
556 if (!isset($sumagainst[$i])) {
559 if (((
string) $car) ==
"1") {
562 if (((
string) $car) ==
"0") {
566 if (!empty($listofanswers[$i][
'format']) && $listofanswers[$i][
'format'] ==
'foragainst') {
567 if (((
string) $car) ==
"1") {
568 print
'<td class="ok">'.$langs->trans(
"For").
'</td>'.
"\n";
569 } elseif (((
string) $car) ==
"0") {
570 print
'<td class="non">'.$langs->trans(
"Against").
'</td>'.
"\n";
572 print
'<td class="vide"> </td>'.
"\n";
575 if (!isset($sumfor[$i])) {
578 if (!isset($sumagainst[$i])) {
581 if (((
string) $car) ==
"1") {
584 if (((
string) $car) ==
"0") {
593 if ($compteur != $ligneamodifier && $mod_ok) {
594 print
'<td class="casevide"><input type="submit" class="button smallpaddingimp" name="modifierligne'.$compteur.
'" value="'.
dol_escape_htmltag($langs->trans(
"Edit")).
'"></td>'.
"\n";
598 for ($i = 0; $i < $nblines; $i++) {
600 if ($compteur == $i) {
601 print
'<td class="casevide">';
602 print
'<input type="hidden" name="idtomodify'.$compteur.
'" value="'.$obj->id_users.
'">';
603 print
'<input type="submit" class="button button-save" name="validermodifier'.$compteur.
'" value="'.
dol_escape_htmltag($langs->trans(
"Save")).
'">';
614 if ($ligneamodifier < 0 && (!isset($_SESSION[
'nom']))) {
616 print
'<td class="nom">'.
"\n";
617 if (isset($_SESSION[
'nom'])) {
618 print
'<input type=hidden name="nom" value="'.$_SESSION[
'nom'].
'">'.$_SESSION[
'nom'].
"\n";
620 print
'<input type="text" name="nom" placeholder="'.dol_escape_htmltag($langs->trans(
"Name")).
'" maxlength="64" class=" minwidth175">'.
"\n";
625 for ($i = 0; $i < $nbcolonnes; $i++) {
626 print
'<td class="vide">';
627 if (empty($listofanswers[$i][
'format']) || !in_array($listofanswers[$i][
'format'], array(
'yesno',
'foragainst'))) {
628 print
'<input type="checkbox" name="choix'.$i.
'" value="1"';
634 if (!empty($listofanswers[$i][
'format']) && $listofanswers[$i][
'format'] ==
'yesno') {
635 $arraychoice = array(
'2'=>
' ',
'0'=>$langs->trans(
"No"),
'1'=>$langs->trans(
"Yes"));
636 print
$form->selectarray(
"choix".$i, $arraychoice,
GETPOST(
'choix'.$i));
638 if (!empty($listofanswers[$i][
'format']) && $listofanswers[$i][
'format'] ==
'foragainst') {
639 $arraychoice = array(
'2'=>
' ',
'0'=>$langs->trans(
"Against"),
'1'=>$langs->trans(
"For"));
640 print
$form->selectarray(
"choix".$i, $arraychoice,
GETPOST(
'choix'.$i));
646 print
'<td><input type="image" class="borderimp" name="boutonp" value="'.$langs->trans(
"Vote").
'" src="'.
img_picto(
'',
'edit_add',
'',
false, 1).
'"></td>'.
"\n";
652 for ($i = 0; $i < $nbcolonnes; $i++) {
653 if (empty($listofanswers[$i][
'format']) || !in_array($listofanswers[$i][
'format'], array(
'yesno',
'foragainst'))) {
656 if (isset($sumfor[$i])) {
658 $meilleurecolonne = $sumfor[$i];
660 if (!isset($meilleurecolonne) || $sumfor[$i] > $meilleurecolonne) {
661 $meilleurecolonne = $sumfor[$i];
666 if ($object->allow_spy) {
669 print
'<td class="center">'.$langs->trans(
"Total").
'</td>'.
"\n";
670 for ($i = 0; $i < $nbcolonnes; $i++) {
671 $showsumfor = isset($sumfor[$i]) ? $sumfor[$i] :
'';
672 $showsumagainst = isset($sumagainst[$i]) ? $sumagainst[$i] :
'';
673 if (empty($showsumfor)) {
676 if (empty($showsumagainst)) {
681 if (empty($listofanswers[$i][
'format']) || !in_array($listofanswers[$i][
'format'], array(
'yesno',
'foragainst'))) {
684 if (!empty($listofanswers[$i][
'format']) && $listofanswers[$i][
'format'] ==
'yesno') {
685 print $langs->trans(
"Yes").
': '.$showsumfor.
'<br>'.$langs->trans(
"No").
': '.$showsumagainst;
687 if (!empty($listofanswers[$i][
'format']) && $listofanswers[$i][
'format'] ==
'foragainst') {
688 print $langs->trans(
"For").
': '.$showsumfor.
'<br>'.$langs->trans(
"Against").
': '.$showsumagainst;
694 if ($nbofcheckbox >= 2) {
696 print
'<td class="somme"></td>'.
"\n";
697 for ($i = 0; $i < $nbcolonnes; $i++) {
699 if (empty($listofanswers[$i][
'format']) || !in_array($listofanswers[$i][
'format'], array(
'yesno',
'foragainst')) && isset($sumfor[$i]) && isset($meilleurecolonne) && $sumfor[$i] == $meilleurecolonne) {
700 print
'<td class="somme"><img src="'.dol_buildpath(
'/opensurvey/img/medaille.png', 1).
'"></td>'.
"\n";
702 print
'<td class="somme"></td>'.
"\n";
708 print
'</table>'.
"\n";
711 if ($object->allow_spy) {
712 $toutsujet = explode(
",", $object->sujet);
713 $toutsujet = str_replace(
"°",
"'", $toutsujet);
718 for ($i = 0; $i < $nbcolonnes; $i++) {
719 if (isset($sumfor[$i]) && isset($meilleurecolonne) && $sumfor[$i] == $meilleurecolonne) {
720 $meilleursujet .= ($meilleursujet ?
", " :
"");
721 if ($object->format ==
"D") {
722 $meilleursujetexport = $toutsujet[$i];
723 if (strpos($toutsujet[$i],
'@') !==
false) {
724 $toutsujetdate = explode(
"@", $toutsujet[$i]);
727 $meilleursujet .=
dol_print_date((empty($toutsujet[$i]) ? 0 : $toutsujet[$i]),
'daytext').
' ('.
dol_print_date((empty($toutsujet[$i]) ? 0 : $toutsujet[$i]),
'%A').
')';
730 $tmps = explode(
'@', $toutsujet[$i]);
738 $meilleursujet = substr(
"$meilleursujet", 1);
739 $meilleursujet = str_replace(
"°",
"'", $meilleursujet);
742 if ($nbofcheckbox >= 2) {
743 $vote_str = $langs->trans(
'votes');
744 print
'<p class="affichageresultats">'.
"\n";
746 if (isset($meilleurecolonne) && $compteursujet ==
"1") {
747 print
'<img src="'.dol_buildpath(
'/opensurvey/img/medaille.png', 1).
'"> '.$langs->trans(
'TheBestChoice').
": <b>".$meilleursujet.
"</b> ".$langs->trans(
'with').
" <b>".$meilleurecolonne.
"</b>".$vote_str.
".\n";
748 } elseif (isset($meilleurecolonne)) {
749 print
'<img src="'.dol_buildpath(
'/opensurvey/img/medaille.png', 1).
'"> '.$langs->trans(
'TheBestChoices').
": <b>".$meilleursujet.
"</b> ".$langs->trans(
'with').
" <b>".$meilleurecolonne.
"</b>".$vote_str.
".\n";
752 print
'</p><br>'.
"\n";
760 $comments = $object->getComments();
763 print
'<br><u><span class="bold opacitymedium">'.$langs->trans(
"CommentsOfVoters").
':</span></u><br>'.
"\n";
765 foreach ($comments as $obj) {
769 print
'<div class="comment"><span class="usercomment">';
770 if (in_array($obj->usercomment, $listofvoters)) {
771 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?deletecomment='.$obj->id_comment.
'&sondage='.$numsondage.
'"> '.
img_picto(
'',
'delete.png',
'',
false, 0, 0,
'',
'nomarginleft').
'</a> ';
779 if ($object->allow_comments) {
780 print
'<br><div class="addcomment"><span class="opacitymedium">'.$langs->trans(
"AddACommentForPoll").
"</span><br>\n";
782 print
'<textarea name="comment" rows="'.ROWS_2.
'" class="quatrevingtpercent">'.
dol_escape_htmltag(
GETPOST(
'comment',
'alphanohtml'), 0, 1).
'</textarea><br>'.
"\n";
783 print $langs->trans(
"Name").
': ';
784 print
'<input type="text" name="commentuser" maxlength="64" value="'.dol_escape_htmltag(
GETPOST(
'commentuser',
'alphanohtml')).
'"> '.
"\n";
785 print
'<input type="submit" class="button" name="ajoutcomment" value="'.dol_escape_htmltag($langs->trans(
"AddComment")).
'"><br>'.
"\n";
786 print
'</form>'.
"\n";
793 print
'<a name="bas"></a>'.
"\n";