dolibarr 25.0.0-alpha
studs.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 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
5 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.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
27if (!defined('NOLOGIN')) {
28 define("NOLOGIN", 1); // This means this output page does not require to be logged.
29}
30if (!defined('NOCSRFCHECK')) {
31 define("NOCSRFCHECK", 1); // We accept to go on this page from external web site.
32}
33if (!defined('NOBROWSERNOTIF')) {
34 define('NOBROWSERNOTIF', '1');
35}
36if (!defined('NOIPCHECK')) {
37 define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
38}
39
40// Load Dolibarr environment
41require '../../main.inc.php';
48require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
49require_once DOL_DOCUMENT_ROOT."/core/lib/files.lib.php";
50require_once DOL_DOCUMENT_ROOT."/opensurvey/class/opensurveysondage.class.php";
51require_once DOL_DOCUMENT_ROOT."/opensurvey/lib/opensurvey.lib.php";
52require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
53
54// Init vars
55$action = GETPOST('action', 'aZ09');
56$numsondage = '';
57if (GETPOST('sondage')) {
58 $numsondage = GETPOST('sondage', 'alpha');
59}
60
61$object = new Opensurveysondage($db);
62$result = $object->fetch('', $numsondage);
63
64$nblines = $object->fetch_lines();
65
66//If the survey has not yet finished, then it can be modified
67$canbemodified = ((empty($object->date_fin) || dol_get_last_hour($object->date_fin) > dol_now()) && $object->status != Opensurveysondage::STATUS_CLOSED);
68
69// Security check
70if (!isModEnabled('opensurvey')) {
71 httponly_accessforbidden('Module Opensurvey not enabled');
72}
73
74
75/*
76 * Actions
77 */
78
79$nbcolonnes = substr_count($object->sujet, ',') + 1;
80
81$listofvoters = explode(',', $_SESSION["savevoter"] ?? '');
82
83$error = 0;
84
85// Add comment
86if (GETPOST('ajoutcomment', 'alpha')) {
87 if (!$canbemodified || empty($object->allow_comments)) {
88 // Comments are refused when the survey is expired/closed or when the survey does not allow comments
89 // (the comment form is hidden in that case, so a comment here can only come from a forged POST).
90 httponly_accessforbidden('ErrorForbidden');
91 }
92
93 $comment = GETPOST("comment", 'alphanohtml');
94 $comment_user = GETPOST('commentuser', 'alphanohtml');
95
96 if (!$comment) {
97 $error++;
98 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Comment")), null, 'errors');
99 }
100 if (!$comment_user) {
101 $error++;
102 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Name")), null, 'errors');
103 }
104
105 if (!in_array($comment_user, $listofvoters)) {
106 setEventMessages($langs->trans("UserMustBeSameThanUserUsedToVote"), null, 'errors');
107 $error++;
108 }
109
110 $user_ip = getUserRemoteIP();
111 $nb_post_max = getDolGlobalInt("MAIN_SECURITY_MAX_POST_ON_PUBLIC_PAGES_BY_IP_ADDRESS", 200);
112 $now = dol_now();
113 $minmonthpost = dol_time_plus_duree($now, -1, "m");
114 // Calculate nb of post for IP
115 $nb_post_ip = 0;
116 if ($nb_post_max > 0) { // Calculate only if there is a limit to check
117 $sql = "SELECT COUNT(id_comment) as nb_comments";
118 $sql .= " FROM ".MAIN_DB_PREFIX."opensurvey_comments";
119 $sql .= " WHERE ip = '".$db->escape($user_ip)."'";
120 $sql .= " AND date_creation > '".$db->idate($minmonthpost)."'";
121 $resql = $db->query($sql);
122 if ($resql) {
123 $num = $db->num_rows($resql);
124 $i = 0;
125 while ($i < $num) {
126 $i++;
127 $obj = $db->fetch_object($resql);
128 $nb_post_ip = $obj->nb_comments;
129 }
130 }
131 }
132
133 if ($nb_post_max > 0 && $nb_post_ip >= $nb_post_max) {
134 setEventMessages($langs->trans("AlreadyTooMuchPostOnThisIPAdress"), null, 'errors');
135 $error++;
136 }
137
138 if (!$error) {
139 $resql = $object->addComment($comment, $comment_user, $user_ip);
140
141 if (!$resql) {
142 dol_print_error($db);
143 }
144 }
145}
146
147// Add vote
148if (GETPOST("boutonp") || GETPOST("boutonp.x") || GETPOST("boutonp_x")) { // boutonp for chrome, boutonp_x for firefox
149 if (!$canbemodified) {
150 httponly_accessforbidden('ErrorForbidden');
151 }
152
153 // If the name is entered correctly
154 if (GETPOST('nom', 'alphanohtml')) {
155 $nouveauchoix = '';
156 for ($i = 0; $i < $nbcolonnes; $i++) {
157 if (GETPOSTISSET("choix".$i) && GETPOST("choix".$i) == '1') {
158 $nouveauchoix .= "1";
159 } elseif (GETPOSTISSET("choix".$i) && GETPOST("choix".$i) == '2') {
160 $nouveauchoix .= "2";
161 } else {
162 $nouveauchoix .= "0";
163 }
164 }
165
166 $user_ip = getUserRemoteIP();
167 $nb_post_max = getDolGlobalInt("MAIN_SECURITY_MAX_POST_ON_PUBLIC_PAGES_BY_IP_ADDRESS", 200);
168 $now = dol_now();
169 $minmonthpost = dol_time_plus_duree($now, -1, "m");
170 // Calculate nb of post for IP
171 $nb_post_ip = 0;
172 if ($nb_post_max > 0) { // Calculate only if there is a limit to check
173 $sql = "SELECT COUNT(id_users) as nb_records";
174 $sql .= " FROM ".MAIN_DB_PREFIX."opensurvey_user_studs";
175 $sql .= " WHERE ip = '".$db->escape($user_ip)."'";
176 $sql .= " AND date_creation > '".$db->idate($minmonthpost)."'";
177 $resql = $db->query($sql);
178 if ($resql) {
179 $num = $db->num_rows($resql);
180 $i = 0;
181 while ($i < $num) {
182 $i++;
183 $obj = $db->fetch_object($resql);
184 $nb_post_ip = $obj->nb_records;
185 }
186 }
187 }
188
189
190 $nom = substr(GETPOST("nom", 'alphanohtml'), 0, 64);
191
192 // Check if vote already exists
193 $sql = 'SELECT id_users, nom as name';
194 $sql .= ' FROM '.MAIN_DB_PREFIX.'opensurvey_user_studs';
195 $sql .= " WHERE id_sondage = '".$db->escape($numsondage)."' AND nom = '".$db->escape($nom)."' ORDER BY id_users";
196 $resql = $db->query($sql);
197 if (!$resql) {
198 dol_print_error($db);
199 }
200
201 $num_rows = $db->num_rows($resql);
202
203 if ($num_rows > 0) {
204 setEventMessages($langs->trans("VoteNameAlreadyExists"), null, 'errors');
205 $error++;
206 } elseif ($nb_post_max > 0 && $nb_post_ip >= $nb_post_max) {
207 setEventMessages($langs->trans("AlreadyTooMuchPostOnThisIPAdress"), null, 'errors');
208 $error++;
209 } else {
210 $now = dol_now();
211 $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'opensurvey_user_studs (nom, id_sondage, reponses, ip, date_creation)';
212 $sql .= " VALUES ('".$db->escape($nom)."', '".$db->escape($numsondage)."','".$db->escape($nouveauchoix)."', '".$db->escape($user_ip)."', '".$db->idate($now)."')";
213 $resql = $db->query($sql);
214
215 if ($resql) {
216 // Add voter to session
217 $_SESSION["savevoter"] = $nom.','.(empty($_SESSION["savevoter"]) ? '' : $_SESSION["savevoter"]); // Save voter
218 $listofvoters = explode(',', $_SESSION["savevoter"]);
219
220 if ($object->mailsonde) {
221 if ($object->fk_user_creat) {
222 $userstatic = new User($db);
223 $userstatic->fetch($object->fk_user_creat);
224
225 $email = $userstatic->email;
226 } else {
227 $email = $object->mail_admin;
228 }
229
230 //Linked user may not have an email set
231 if ($email) {
232 include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
233
234 $application = ($conf->global->MAIN_APPLICATION_TITLE ? $conf->global->MAIN_APPLICATION_TITLE : 'Dolibarr ERP/CRM');
235
236 $link = getUrlSondage($numsondage, true);
237 $link = '<a href="'.$link.'">'.$link.'</a>';
238 $body = str_replace('\n', '<br>', $langs->transnoentities('EmailSomeoneVoted', $nom, $link));
239 //var_dump($body);exit;
240
241 $cmailfile = new CMailFile("[".$application."] ".$langs->trans("Poll").': '.$object->title, $email, $conf->global->MAIN_MAIL_EMAIL_FROM, $body, null, null, null, '', '', 0, -1);
242 $result = $cmailfile->sendfile();
243 }
244 }
245 } else {
246 dol_print_error($db);
247 }
248 }
249 } else {
250 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Name")), null, 'errors');
251 }
252}
253
254
255// Update vote
256$testmodifier = false;
257$testligneamodifier = false;
258$ligneamodifier = -1;
259$modifier = -1;
260for ($i = 0; $i < $nblines; $i++) {
261 if (GETPOSTISSET('modifierligne'.$i)) {
262 $ligneamodifier = $i;
263 $testligneamodifier = true;
264 }
265
266 //test to see if a line is to be modified
267 if (GETPOSTISSET('validermodifier'.$i)) {
268 $modifier = $i;
269 $testmodifier = true;
270 }
271}
272
273if ($testmodifier) {
274 $nouveauchoix = '';
275 for ($i = 0; $i < $nbcolonnes; $i++) {
276 if (GETPOSTISSET("choix".$i) && GETPOST("choix".$i) == '1') {
277 $nouveauchoix .= "1";
278 } elseif (GETPOSTISSET("choix".$i) && GETPOST("choix".$i) == '2') {
279 $nouveauchoix .= "2";
280 } else {
281 $nouveauchoix .= "0";
282 }
283 }
284
285 if (!$canbemodified) {
286 httponly_accessforbidden('ErrorForbidden');
287 }
288
289 $idtomodify = GETPOST("idtomodify".$modifier);
290 $sql = 'UPDATE '.MAIN_DB_PREFIX."opensurvey_user_studs";
291 $sql .= " SET reponses = '".$db->escape($nouveauchoix)."'";
292 $sql .= " WHERE id_users = '".$db->escape($idtomodify)."'";
293
294 $resql = $db->query($sql);
295 if (!$resql) {
296 dol_print_error($db);
297 }
298}
299
300// Delete comment
301$idcomment = GETPOSTINT('deletecomment');
302if ($idcomment) {
303 if (!$canbemodified) {
304 httponly_accessforbidden('ErrorForbidden');
305 }
306
307 $resql = $object->deleteComment($idcomment);
308}
309
310
311
312/*
313 * View
314 */
315
316$form = new Form($db);
317
318$arrayofjs = array();
319$arrayofcss = array('/opensurvey/css/style.css');
320
321llxHeaderSurvey($object->title, "", 0, 0, $arrayofjs, $arrayofcss, $numsondage);
322
323if (empty($object->ref)) { // For survey, id is a hex string
324 $langs->load("errors");
325 print $langs->trans("ErrorRecordNotFound");
326
328
329 $db->close();
330 exit();
331}
332
333// Define format of choices
334$toutsujet = explode(",", $object->sujet);
335$listofanswers = array();
336foreach ($toutsujet as $value) {
337 $tmp = explode('@', $value);
338 $listofanswers[] = array('label' => $tmp[0], 'format' => (!empty($tmp[1]) ? $tmp[1] : 'checkbox'));
339}
340$toutsujet = str_replace("°", "'", $toutsujet);
341
342
343print '<div class="survey_intro">';
344print '<div class="survey_invitation">'.$langs->trans("YouAreInivitedToVote").'</div>';
345print '<div class="small">';
346print '<span class="opacitymedium">'.$langs->trans("OpenSurveyHowTo").'</span><br>';
347if (empty($object->allow_spy)) {
348 print '<span class="opacitymedium">'.$langs->trans("YourVoteIsPrivate").'</span><br>';
349} else {
350 print $form->textwithpicto('<span class="opacitymedium">'.$langs->trans("YourVoteIsPublic").'</span>', $langs->trans("CanSeeOthersVote")).'<br>';
351}
352print '</div>';
353print '</div>';
354print '<br>';
355
356if (empty($object->description)) {
357 print '<div class="corps">'."\n";
358} else {
359 print '<br>'."\n";
360}
361
362// show title of survey
363$titre = str_replace("\\", "", $object->title);
364print '<div class="survey_title">'.img_picto('', 'poll', 'class="size15x paddingright"').' <strong>'.dol_htmlentities($titre).'</strong></div>';
365
366if (!empty($object->description)) {
367 print '<br><div class="corps">'."\n";
368}
369
370// show description of survey
371if ($object->description) {
372 print dol_htmlentitiesbr($object->description);
373}
374
375print '</div>'."\n";
376
377//The survey has expired, users can't vote or do any action
378if (!$canbemodified) {
379 print '<br><center><div class="center warning">'.$langs->trans('SurveyExpiredInfo').'</div></center>';
381
382 $db->close();
383 exit;
384}
385
386print '<div class="cadre"> '."\n";
387print '<br><br>'."\n";
388
389// Start to show survey result
390print '<div class="div-table-responsive">';
391print '<table class="resultats">'."\n";
392
393// Show choice titles
394if ($object->format == "D") {
395 //display of survey topics
396 print '<tr>'."\n";
397 print '<td></td>'."\n";
398
399 //display of years
400 $colspan = 1;
401 $nbofsujet = count($toutsujet);
402 for ($i = 0; $i < $nbofsujet; $i++) {
403 if (isset($toutsujet[$i + 1]) && date('Y', intval($toutsujet[$i])) == date('Y', intval($toutsujet[$i + 1]))) {
404 $colspan++;
405 } else {
406 print '<td colspan='.$colspan.' class="annee">'.date('Y', intval($toutsujet[$i])).'</td>'."\n";
407 $colspan = 1;
408 }
409 }
410
411 print '</tr>'."\n";
412 print '<tr>'."\n";
413 print '<td></td>'."\n";
414
415 //display of months
416 $colspan = 1;
417 for ($i = 0; $i < $nbofsujet; $i++) {
418 $cur = intval($toutsujet[$i]); // intval() is used to remove the @* suffix which logically belongs to strftime()
419 if (!isset($toutsujet[$i + 1])) {
420 $next = false;
421 } else {
422 $next = intval($toutsujet[$i + 1]);
423 }
424
425 if ($next && dol_print_date($cur, "%B") == dol_print_date($next, "%B") && dol_print_date($cur, "%Y") == dol_print_date($next, "%Y")) {
426 $colspan++;
427 } else {
428 print '<td colspan='.$colspan.' class="mois">'.dol_print_date($cur, "%B").'</td>'."\n";
429 $colspan = 1;
430 }
431 }
432
433 print '</tr>'."\n";
434 print '<tr>'."\n";
435 print '<td></td>'."\n";
436
437 //display of days
438 $colspan = 1;
439 for ($i = 0; $i < $nbofsujet; $i++) {
440 $cur = intval($toutsujet[$i]);
441 if (!isset($toutsujet[$i + 1])) {
442 $next = false;
443 } else {
444 $next = intval($toutsujet[$i + 1]);
445 }
446 if ($next && dol_print_date($cur, "%a %d") == dol_print_date($next, "%a %d") && dol_print_date($cur, "%B") == dol_print_date($next, "%B")) {
447 $colspan++;
448 } else {
449 print '<td colspan="'.$colspan.'" class="jour">'.dol_print_date($cur, "%a %d").'</td>'."\n";
450 $colspan = 1;
451 }
452 }
453
454 print '</tr>'."\n";
455
456 //Display schedules
457 if (strpos($object->sujet, '@') !== false) {
458 print '<tr>'."\n";
459 print '<td></td>'."\n";
460
461 for ($i = 0; isset($toutsujet[$i]); $i++) {
462 $heures = explode('@', $toutsujet[$i]);
463 if (isset($heures[1])) {
464 print '<td class="heure">'.dol_htmlentities($heures[1]).'</td>'."\n";
465 } else {
466 print '<td class="heure"></td>'."\n";
467 }
468 }
469
470 print '</tr>'."\n";
471 }
472} else {
473 //display of survey topics
474 print '<tr>'."\n";
475 print '<td></td>'."\n";
476
477 for ($i = 0; isset($toutsujet[$i]); $i++) {
478 $tmp = explode('@', $toutsujet[$i]);
479 print '<td class="sujet">'.dol_escape_htmltag($tmp[0]).'</td>'."\n";
480 }
481
482 print '</tr>'."\n";
483}
484
485
486// Loop on each answer
487$currentusername = '';
488$sumfor = array();
489$sumagainst = array();
490$compteur = 0;
491$sql = "SELECT id_users, nom as name, id_sondage, reponses";
492$sql .= " FROM ".MAIN_DB_PREFIX."opensurvey_user_studs";
493$sql .= " WHERE id_sondage = '".$db->escape($numsondage)."'";
494$resql = $db->query($sql);
495if (!$resql) {
496 dol_print_error($db);
497 exit;
498}
499$num = $db->num_rows($resql);
500while ($compteur < $num) {
501 $obj = $db->fetch_object($resql);
502
503 $ensemblereponses = $obj->reponses;
504
505 // Set if line of pre-authentified user
506 $mod_ok = (in_array($obj->name, $listofvoters));
507
508 if (!$mod_ok && !$object->allow_spy) {
509 $compteur++;
510 continue;
511 }
512
513 print '<tr>'."\n";
514
515 // Name
516 print '<td class="nom">'.img_picto($obj->name, 'user', 'class="pictofixedwidth"').dol_htmlentities($obj->name).'</td>'."\n";
517
518 // If the line does not need modification, show the data
519 if (!$testligneamodifier) {
520 for ($i = 0; $i < $nbcolonnes; $i++) {
521 $car = substr($ensemblereponses, $i, 1);
522 //print 'xx'.$i."-".$car.'-'.$listofanswers[$i]['format'].'zz';
523
524 if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst'))) {
525 if (((string) $car) == "1") {
526 print '<td class="ok">OK</td>'."\n";
527 } else {
528 print '<td class="non">KO</td>'."\n";
529 }
530 // Total
531 if (!isset($sumfor[$i])) {
532 $sumfor[$i] = 0;
533 }
534 if (((string) $car) == "1") {
535 $sumfor[$i]++;
536 }
537 }
538 if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno') {
539 if (((string) $car) == "1") {
540 print '<td class="ok">'.$langs->trans("Yes").'</td>'."\n";
541 } elseif (((string) $car) == "0") {
542 print '<td class="non">'.$langs->trans("No").'</td>'."\n";
543 } else {
544 print '<td class="vide">&nbsp;</td>'."\n";
545 }
546 // Total
547 if (!isset($sumfor[$i])) {
548 $sumfor[$i] = 0;
549 }
550 if (!isset($sumagainst[$i])) {
551 $sumagainst[$i] = 0;
552 }
553 if (((string) $car) == "1") {
554 $sumfor[$i]++;
555 }
556 if (((string) $car) == "0") {
557 $sumagainst[$i]++;
558 }
559 }
560 if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst') {
561 if (((string) $car) == "1") {
562 print '<td class="ok">'.$langs->trans("For").'</td>'."\n";
563 } elseif (((string) $car) == "0") {
564 print '<td class="non">'.$langs->trans("Against").'</td>'."\n";
565 } else {
566 print '<td class="vide">&nbsp;</td>'."\n";
567 }
568 // Total
569 if (!isset($sumfor[$i])) {
570 $sumfor[$i] = 0;
571 }
572 if (!isset($sumagainst[$i])) {
573 $sumagainst[$i] = 0;
574 }
575 if (((string) $car) == "1") {
576 $sumfor[$i]++;
577 }
578 if (((string) $car) == "0") {
579 $sumagainst[$i]++;
580 }
581 }
582 }
583 } else {
584 // Else, replace the user's choices with a line of checkboxes for entry
585 if ($compteur == $ligneamodifier) {
586 for ($i = 0; $i < $nbcolonnes; $i++) {
587 $car = substr($ensemblereponses, $i, 1);
588 print '<td class="vide">';
589 if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst'))) {
590 print '<input type="checkbox" name="choix'.$i.'" value="1" ';
591 if ($car == '1') {
592 print 'checked';
593 }
594 print '>';
595 }
596 if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno') {
597 $arraychoice = array('2' => '&nbsp;', '0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
598 print $form->selectarray("choix".$i, $arraychoice, $car);
599 }
600 if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst') {
601 $arraychoice = array('2' => '&nbsp;', '0' => $langs->trans("Against"), '1' => $langs->trans("For"));
602 print $form->selectarray("choix".$i, $arraychoice, $car);
603 }
604 print '</td>'."\n";
605 }
606 } else {
607 for ($i = 0; $i < $nbcolonnes; $i++) {
608 $car = substr($ensemblereponses, $i, 1);
609 if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst'))) {
610 if (((string) $car) == "1") {
611 print '<td class="ok">OK</td>'."\n";
612 } else {
613 print '<td class="non">KO</td>'."\n";
614 }
615 // Total
616 if (!isset($sumfor[$i])) {
617 $sumfor[$i] = 0;
618 }
619 if (((string) $car) == "1") {
620 $sumfor[$i]++;
621 }
622 }
623 if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno') {
624 if (((string) $car) == "1") {
625 print '<td class="ok">'.$langs->trans("For").'</td>'."\n";
626 } elseif (((string) $car) == "0") {
627 print '<td class="non">'.$langs->trans("Against").'</td>'."\n";
628 } else {
629 print '<td class="vide">&nbsp;</td>'."\n";
630 }
631 // Total
632 if (!isset($sumfor[$i])) {
633 $sumfor[$i] = 0;
634 }
635 if (!isset($sumagainst[$i])) {
636 $sumagainst[$i] = 0;
637 }
638 if (((string) $car) == "1") {
639 $sumfor[$i]++;
640 }
641 if (((string) $car) == "0") {
642 $sumagainst[$i]++;
643 }
644 }
645 if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst') {
646 if (((string) $car) == "1") {
647 print '<td class="ok">'.$langs->trans("For").'</td>'."\n";
648 } elseif (((string) $car) == "0") {
649 print '<td class="non">'.$langs->trans("Against").'</td>'."\n";
650 } else {
651 print '<td class="vide">&nbsp;</td>'."\n";
652 }
653 // Total
654 if (!isset($sumfor[$i])) {
655 $sumfor[$i] = 0;
656 }
657 if (!isset($sumagainst[$i])) {
658 $sumagainst[$i] = 0;
659 }
660 if (((string) $car) == "1") {
661 $sumfor[$i]++;
662 }
663 if (((string) $car) == "0") {
664 $sumagainst[$i]++;
665 }
666 }
667 }
668 }
669 }
670
671 // Button edit at end of line
672 if ($compteur != $ligneamodifier && $mod_ok) {
673 $currentusername = $obj->name;
674 print '<td class="casevide"><input type="submit" class="button small" name="modifierligne'.$compteur.'" value="'.dol_escape_htmltag($langs->trans("Edit")).'"></td>'."\n";
675 }
676
677 // Ask for confirmation to modify the line
678 for ($i = 0; $i < $nblines; $i++) {
679 if (GETPOSTISSET("modifierligne".$i)) {
680 if ($compteur == $i) {
681 print '<td class="casevide">';
682 print '<input type="hidden" name="idtomodify'.$compteur.'" value="'.$obj->id_users.'">';
683 print '<input type="submit" class="button button-save small" name="validermodifier'.$compteur.'" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
684 print '</td>'."\n";
685 }
686 }
687 }
688
689 $compteur++;
690 print '</tr>'."\n";
691}
692
693// Add line to add new record
694if ($ligneamodifier < 0 && (!isset($_SESSION['nom']))) {
695 print '<tr>'."\n";
696 print '<td class="nom">'."\n";
697 if (isset($_SESSION['nom'])) {
698 print '<input type=hidden name="nom" value="'.$_SESSION['nom'].'">'.$_SESSION['nom']."\n";
699 } else {
700 print '<input type="text" name="nom" placeholder="'.dol_escape_htmltag($langs->trans("Name")).'" maxlength="64" class=" minwidth175" value="">'."\n";
701 }
702 print '</td>'."\n";
703
704 // show cell form checkbox for a new choice
705 for ($i = 0; $i < $nbcolonnes; $i++) {
706 print '<td class="vide">';
707 if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst'))) {
708 print '<input type="checkbox" name="choix'.$i.'" value="1"';
709 if (GETPOSTISSET('choix'.$i) && GETPOST('choix'.$i) == '1') {
710 print ' checked';
711 }
712 print '>';
713 }
714 if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno') {
715 $arraychoice = array('2' => '&nbsp;', '0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
716 print $form->selectarray("choix".$i, $arraychoice, GETPOST('choix'.$i));
717 }
718 if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst') {
719 $arraychoice = array('2' => '&nbsp;', '0' => $langs->trans("Against"), '1' => $langs->trans("For"));
720 print $form->selectarray("choix".$i, $arraychoice, GETPOST('choix'.$i));
721 }
722 print '</td>'."\n";
723 }
724
725 // Show button to add a new line into database
726 print '<td><input type="image" class="borderimp classfortooltip" title="'.dolPrintHTML($langs->trans("AddTheVote")).'" name="boutonp" value="'.$langs->trans("Vote").'" src="'.img_picto('', 'edit_add', '', 0, 1).'"></td>'."\n";
727 print '</tr>'."\n";
728}
729
730// Select value of best choice (for checkbox columns only)
731$nbofcheckbox = 0;
732$meilleurecolonne = null;
733for ($i = 0; $i < $nbcolonnes; $i++) {
734 if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst'))) {
735 $nbofcheckbox++;
736 }
737 if (isset($sumfor[$i])) {
738 if ($i == 0) {
739 $meilleurecolonne = $sumfor[$i];
740 }
741 if (!isset($meilleurecolonne) || $sumfor[$i] > $meilleurecolonne) {
742 $meilleurecolonne = $sumfor[$i];
743 }
744 }
745}
746
747if ($object->allow_spy) {
748 // Show line total
749 print '<tr>'."\n";
750 print '<td class="center">'.$langs->trans("Total").'</td>'."\n";
751 for ($i = 0; $i < $nbcolonnes; $i++) {
752 $showsumfor = isset($sumfor[$i]) ? $sumfor[$i] : '';
753 $showsumagainst = isset($sumagainst[$i]) ? $sumagainst[$i] : '';
754 if (empty($showsumfor)) {
755 $showsumfor = 0;
756 }
757 if (empty($showsumagainst)) {
758 $showsumagainst = 0;
759 }
760
761 print '<td>';
762 if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst'))) {
763 print $showsumfor;
764 }
765 if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno') {
766 print $langs->trans("Yes").': '.$showsumfor.'<br>'.$langs->trans("No").': '.$showsumagainst;
767 }
768 if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst') {
769 print $langs->trans("For").': '.$showsumfor.'<br>'.$langs->trans("Against").': '.$showsumagainst;
770 }
771 print '</td>'."\n";
772 }
773 print '</tr>';
774 // Show picto winner
775 if ($nbofcheckbox >= 2) {
776 print '<tr>'."\n";
777 print '<td class="somme"></td>'."\n";
778 for ($i = 0; $i < $nbcolonnes; $i++) {
779 //print 'xx'.(!empty($listofanswers[$i]['format'])).'-'.$sumfor[$i].'-'.$meilleurecolonne;
780 if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst')) && isset($sumfor[$i]) && isset($meilleurecolonne) && $sumfor[$i] == $meilleurecolonne) {
781 print '<td class="somme"><img src="'.dol_buildpath('/opensurvey/img/medaille.png', 1).'"></td>'."\n";
782 } else {
783 print '<td class="somme"></td>'."\n";
784 }
785 }
786 print '</tr>'."\n";
787 }
788}
789print '</table>'."\n";
790print '</div>'."\n";
791
792print '</div>'."\n";
793
794if ($object->allow_spy) {
795 $toutsujet = explode(",", $object->sujet);
796 $toutsujet = str_replace("°", "'", $toutsujet);
797
798 $compteursujet = 0;
799 $meilleursujet = '';
800
801 for ($i = 0; $i < $nbcolonnes; $i++) {
802 if (isset($sumfor[$i]) && isset($meilleurecolonne) && $sumfor[$i] == $meilleurecolonne) {
803 $meilleursujet .= ($meilleursujet ? ", " : "");
804 if ($object->format == "D") {
805 if (strpos($toutsujet[$i], '@') !== false) {
806 $toutsujetdate = explode("@", $toutsujet[$i]);
807 $meilleursujet .= dol_print_date($toutsujetdate[0], 'daytext').' ('.dol_print_date($toutsujetdate[0], '%A').') - '.$toutsujetdate[1];
808 } else {
809 $meilleursujet .= dol_print_date((empty($toutsujet[$i]) ? 0 : $toutsujet[$i]), 'daytext').' ('.dol_print_date((empty($toutsujet[$i]) ? 0 : $toutsujet[$i]), '%A').')';
810 }
811 } else {
812 $tmps = explode('@', $toutsujet[$i]);
813 $meilleursujet .= dol_htmlentities($tmps[0]);
814 }
815
816 $compteursujet++;
817 }
818 }
819
820 //$meilleursujet = substr($meilleursujet, 1);
821 $meilleursujet = str_replace("°", "'", $meilleursujet);
822
823 // Show best choice
824 if ($nbofcheckbox >= 2) {
825 $vote_str = $langs->trans('votes');
826 print '<p class="affichageresultats">'."\n";
827
828 if (isset($meilleurecolonne) && $compteursujet == "1") {
829 print '<img src="'.dol_buildpath('/opensurvey/img/medaille.png', 1).'"> '.$langs->trans('TheBestChoice').": <b>".$meilleursujet."</b> - <b>".$meilleurecolonne."</b> ".$vote_str.".\n";
830 } elseif (isset($meilleurecolonne)) {
831 print '<img src="'.dol_buildpath('/opensurvey/img/medaille.png', 1).'"> '.$langs->trans('TheBestChoices').": <b>".$meilleursujet."</b> - <b>".$meilleurecolonne."</b> ".$vote_str.".\n";
832 }
833
834 print '</p><br>'."\n";
835 }
836}
837
838print '<br>';
839
840
841// Comment list
842$comments = $object->getComments();
843
844if ($comments) {
845 print '<br>'.img_picto('', 'note', 'class="pictofixedwidth"').'<span class="bold opacitymedium">'.$langs->trans("CommentsOfVoters").':</span><br>'."\n";
846
847 foreach ($comments as $obj) {
848 // Set if line of pre-authentified user
849 //$mod_ok = (in_array($obj->name, $listofvoters));
850
851 print '<div class="comment"><span class="usercomment">';
852 if (in_array($obj->usercomment, $listofvoters)) {
853 print '<a href="'.$_SERVER["PHP_SELF"].'?deletecomment='.$obj->id_comment.'&sondage='.$numsondage.'"> '.img_picto('', 'delete', '', 0, 0, 0, '', 'nomarginleft').'</a> ';
854 }
855 //else print img_picto('', 'ellipsis-h', '', 0, 0, 0, '', 'nomarginleft').' ';
856 print img_picto('', 'user', 'class="pictofixedwidth"').dol_htmlentities($obj->usercomment).':</span> <span class="comment">'.dol_nl2br(dol_htmlentities($obj->comment))."</span></div>";
857 }
858}
859
860// Form to add comment
861if ($object->allow_comments && $currentusername) {
862 print '<br><div class="addcomment"><span class="opacitymedium">'.$langs->trans("AddACommentForPoll")."</span><br>\n";
863
864 print '<textarea name="comment" rows="'.ROWS_2.'" class="quatrevingtpercent">'.dol_escape_htmltag(GETPOST('comment', 'alphanohtml'), 0, 1).'</textarea><br>'."\n";
865 print $langs->trans("Name").': ';
866 print '<input type="text" name="commentuser" maxlength="64" value="'.dol_escape_htmltag(GETPOSTISSET('commentuser') ? GETPOST('commentuser', 'alphanohtml') : (empty($_SESSION['nom']) ? $currentusername : $_SESSION['nom'])).'"> &nbsp; '."\n";
867 print '<input type="submit" class="button smallpaddingimp" name="ajoutcomment" value="'.dol_escape_htmltag($langs->trans("AddComment")).'"><br>'."\n";
868 print '</form>'."\n";
869
870 print '</div>'."\n"; // div add comment
871}
872
873print '<br><br>';
874
875print '<a name="bas"></a>'."\n";
876
878
879$db->close();
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
Class to manage generation of HTML components Only common components must be here.
Put here description of your class.
Class to manage Dolibarr users.
dol_get_last_hour($date, $gm='tzserver')
Return GMT time for last hour of a given GMT date (it replaces hours, min and second part to 23:59:59...
Definition date.lib.php:662
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition date.lib.php:126
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dol_now($mode='gmt')
Return date for now.
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
dol_htmlentities($string, $flags=ENT_QUOTES|ENT_SUBSTITUTE, $encoding='UTF-8', $double_encode=false)
Replace htmlentities functions.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getUserRemoteIP($trusted=0)
Return the real IP of remote user.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
isModEnabled($module)
Is Dolibarr module enabled.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Definition html.lib.php:181
llxFooterSurvey()
Show footer for new member.
getUrlSondage($id, $admin=false)
Function for generating URLs for surveys.
llxHeaderSurvey($title, $head="", $disablejs=0, $disablehead=0, $arrayofjs=[], $arrayofcss=[], $numsondage='')
Show header for new member.
print $langs trans('Date')." left Ref Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right Paid right PaymentTypeShortLIQ right SELECT p pos_change as p datep as date
Definition receipt.php:492
httponly_accessforbidden($message='1', $http_response_code=403, $stringalreadysanitized=0)
Show a message to say access is forbidden and stop program.