dolibarr 24.0.0-beta
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
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) {
88 httponly_accessforbidden('ErrorForbidden');
89 }
90
91 $comment = GETPOST("comment", 'alphanohtml');
92 $comment_user = GETPOST('commentuser', 'alphanohtml');
93
94 if (!$comment) {
95 $error++;
96 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Comment")), null, 'errors');
97 }
98 if (!$comment_user) {
99 $error++;
100 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Name")), null, 'errors');
101 }
102
103 if (!in_array($comment_user, $listofvoters)) {
104 setEventMessages($langs->trans("UserMustBeSameThanUserUsedToVote"), null, 'errors');
105 $error++;
106 }
107
108 $user_ip = getUserRemoteIP();
109 $nb_post_max = getDolGlobalInt("MAIN_SECURITY_MAX_POST_ON_PUBLIC_PAGES_BY_IP_ADDRESS", 200);
110 $now = dol_now();
111 $minmonthpost = dol_time_plus_duree($now, -1, "m");
112 // Calculate nb of post for IP
113 $nb_post_ip = 0;
114 if ($nb_post_max > 0) { // Calculate only if there is a limit to check
115 $sql = "SELECT COUNT(id_comment) as nb_comments";
116 $sql .= " FROM ".MAIN_DB_PREFIX."opensurvey_comments";
117 $sql .= " WHERE ip = '".$db->escape($user_ip)."'";
118 $sql .= " AND date_creation > '".$db->idate($minmonthpost)."'";
119 $resql = $db->query($sql);
120 if ($resql) {
121 $num = $db->num_rows($resql);
122 $i = 0;
123 while ($i < $num) {
124 $i++;
125 $obj = $db->fetch_object($resql);
126 $nb_post_ip = $obj->nb_comments;
127 }
128 }
129 }
130
131 if ($nb_post_max > 0 && $nb_post_ip >= $nb_post_max) {
132 setEventMessages($langs->trans("AlreadyTooMuchPostOnThisIPAdress"), null, 'errors');
133 $error++;
134 }
135
136 if (!$error) {
137 $resql = $object->addComment($comment, $comment_user, $user_ip);
138
139 if (!$resql) {
141 }
142 }
143}
144
145// Add vote
146if (GETPOST("boutonp") || GETPOST("boutonp.x") || GETPOST("boutonp_x")) { // boutonp for chrome, boutonp_x for firefox
147 if (!$canbemodified) {
148 httponly_accessforbidden('ErrorForbidden');
149 }
150
151 //Si le nom est bien entré
152 if (GETPOST('nom', 'alphanohtml')) {
153 $nouveauchoix = '';
154 for ($i = 0; $i < $nbcolonnes; $i++) {
155 if (GETPOSTISSET("choix".$i) && GETPOST("choix".$i) == '1') {
156 $nouveauchoix .= "1";
157 } elseif (GETPOSTISSET("choix".$i) && GETPOST("choix".$i) == '2') {
158 $nouveauchoix .= "2";
159 } else {
160 $nouveauchoix .= "0";
161 }
162 }
163
164 $user_ip = getUserRemoteIP();
165 $nb_post_max = getDolGlobalInt("MAIN_SECURITY_MAX_POST_ON_PUBLIC_PAGES_BY_IP_ADDRESS", 200);
166 $now = dol_now();
167 $minmonthpost = dol_time_plus_duree($now, -1, "m");
168 // Calculate nb of post for IP
169 $nb_post_ip = 0;
170 if ($nb_post_max > 0) { // Calculate only if there is a limit to check
171 $sql = "SELECT COUNT(id_users) as nb_records";
172 $sql .= " FROM ".MAIN_DB_PREFIX."opensurvey_user_studs";
173 $sql .= " WHERE ip = '".$db->escape($user_ip)."'";
174 $sql .= " AND date_creation > '".$db->idate($minmonthpost)."'";
175 $resql = $db->query($sql);
176 if ($resql) {
177 $num = $db->num_rows($resql);
178 $i = 0;
179 while ($i < $num) {
180 $i++;
181 $obj = $db->fetch_object($resql);
182 $nb_post_ip = $obj->nb_records;
183 }
184 }
185 }
186
187
188 $nom = substr(GETPOST("nom", 'alphanohtml'), 0, 64);
189
190 // Check if vote already exists
191 $sql = 'SELECT id_users, nom as name';
192 $sql .= ' FROM '.MAIN_DB_PREFIX.'opensurvey_user_studs';
193 $sql .= " WHERE id_sondage = '".$db->escape($numsondage)."' AND nom = '".$db->escape($nom)."' ORDER BY id_users";
194 $resql = $db->query($sql);
195 if (!$resql) {
197 }
198
199 $num_rows = $db->num_rows($resql);
200
201 if ($num_rows > 0) {
202 setEventMessages($langs->trans("VoteNameAlreadyExists"), null, 'errors');
203 $error++;
204 } elseif ($nb_post_max > 0 && $nb_post_ip >= $nb_post_max) {
205 setEventMessages($langs->trans("AlreadyTooMuchPostOnThisIPAdress"), null, 'errors');
206 $error++;
207 } else {
208 $now = dol_now();
209 $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'opensurvey_user_studs (nom, id_sondage, reponses, ip, date_creation)';
210 $sql .= " VALUES ('".$db->escape($nom)."', '".$db->escape($numsondage)."','".$db->escape($nouveauchoix)."', '".$db->escape($user_ip)."', '".$db->idate($now)."')";
211 $resql = $db->query($sql);
212
213 if ($resql) {
214 // Add voter to session
215 $_SESSION["savevoter"] = $nom.','.(empty($_SESSION["savevoter"]) ? '' : $_SESSION["savevoter"]); // Save voter
216 $listofvoters = explode(',', $_SESSION["savevoter"]);
217
218 if ($object->mailsonde) {
219 if ($object->fk_user_creat) {
220 $userstatic = new User($db);
221 $userstatic->fetch($object->fk_user_creat);
222
223 $email = $userstatic->email;
224 } else {
225 $email = $object->mail_admin;
226 }
227
228 //Linked user may not have an email set
229 if ($email) {
230 include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
231
232 $application = ($conf->global->MAIN_APPLICATION_TITLE ? $conf->global->MAIN_APPLICATION_TITLE : 'Dolibarr ERP/CRM');
233
234 $link = getUrlSondage($numsondage, true);
235 $link = '<a href="'.$link.'">'.$link.'</a>';
236 $body = str_replace('\n', '<br>', $langs->transnoentities('EmailSomeoneVoted', $nom, $link));
237 //var_dump($body);exit;
238
239 $cmailfile = new CMailFile("[".$application."] ".$langs->trans("Poll").': '.$object->title, $email, $conf->global->MAIN_MAIL_EMAIL_FROM, $body, null, null, null, '', '', 0, -1);
240 $result = $cmailfile->sendfile();
241 }
242 }
243 } else {
245 }
246 }
247 } else {
248 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Name")), null, 'errors');
249 }
250}
251
252
253// Update vote
254$testmodifier = false;
255$testligneamodifier = false;
256$ligneamodifier = -1;
257$modifier = -1;
258for ($i = 0; $i < $nblines; $i++) {
259 if (GETPOSTISSET('modifierligne'.$i)) {
260 $ligneamodifier = $i;
261 $testligneamodifier = true;
262 }
263
264 //test to see if a line is to be modified
265 if (GETPOSTISSET('validermodifier'.$i)) {
266 $modifier = $i;
267 $testmodifier = true;
268 }
269}
270
271if ($testmodifier) {
272 $nouveauchoix = '';
273 for ($i = 0; $i < $nbcolonnes; $i++) {
274 if (GETPOSTISSET("choix".$i) && GETPOST("choix".$i) == '1') {
275 $nouveauchoix .= "1";
276 } elseif (GETPOSTISSET("choix".$i) && GETPOST("choix".$i) == '2') {
277 $nouveauchoix .= "2";
278 } else {
279 $nouveauchoix .= "0";
280 }
281 }
282
283 if (!$canbemodified) {
284 httponly_accessforbidden('ErrorForbidden');
285 }
286
287 $idtomodify = GETPOST("idtomodify".$modifier);
288 $sql = 'UPDATE '.MAIN_DB_PREFIX."opensurvey_user_studs";
289 $sql .= " SET reponses = '".$db->escape($nouveauchoix)."'";
290 $sql .= " WHERE id_users = '".$db->escape($idtomodify)."'";
291
292 $resql = $db->query($sql);
293 if (!$resql) {
295 }
296}
297
298// Delete comment
299$idcomment = GETPOSTINT('deletecomment');
300if ($idcomment) {
301 if (!$canbemodified) {
302 httponly_accessforbidden('ErrorForbidden');
303 }
304
305 $resql = $object->deleteComment($idcomment);
306}
307
308
309
310/*
311 * View
312 */
313
314$form = new Form($db);
315
316$arrayofjs = array();
317$arrayofcss = array('/opensurvey/css/style.css');
318
319llxHeaderSurvey($object->title, "", 0, 0, $arrayofjs, $arrayofcss, $numsondage);
320
321if (empty($object->ref)) { // For survey, id is a hex string
322 $langs->load("errors");
323 print $langs->trans("ErrorRecordNotFound");
324
326
327 $db->close();
328 exit();
329}
330
331// Define format of choices
332$toutsujet = explode(",", $object->sujet);
333$listofanswers = array();
334foreach ($toutsujet as $value) {
335 $tmp = explode('@', $value);
336 $listofanswers[] = array('label' => $tmp[0], 'format' => (!empty($tmp[1]) ? $tmp[1] : 'checkbox'));
337}
338$toutsujet = str_replace("°", "'", $toutsujet);
339
340
341print '<div class="survey_intro">';
342print '<div class="survey_invitation">'.$langs->trans("YouAreInivitedToVote").'</div>';
343print '<div class="small">';
344print '<span class="opacitymedium">'.$langs->trans("OpenSurveyHowTo").'</span><br>';
345if (empty($object->allow_spy)) {
346 print '<span class="opacitymedium">'.$langs->trans("YourVoteIsPrivate").'</span><br>';
347} else {
348 print $form->textwithpicto('<span class="opacitymedium">'.$langs->trans("YourVoteIsPublic").'</span>', $langs->trans("CanSeeOthersVote")).'<br>';
349}
350print '</div>';
351print '</div>';
352print '<br>';
353
354if (empty($object->description)) {
355 print '<div class="corps">'."\n";
356} else {
357 print '<br>'."\n";
358}
359
360// show title of survey
361$titre = str_replace("\\", "", $object->title);
362print '<div class="survey_title">'.img_picto('', 'poll', 'class="size15x paddingright"').' <strong>'.dol_htmlentities($titre).'</strong></div>';
363
364if (!empty($object->description)) {
365 print '<br><div class="corps">'."\n";
366}
367
368// show description of survey
369if ($object->description) {
370 print dol_htmlentitiesbr($object->description);
371}
372
373print '</div>'."\n";
374
375//The survey has expired, users can't vote or do any action
376if (!$canbemodified) {
377 print '<br><center><div class="center warning">'.$langs->trans('SurveyExpiredInfo').'</div></center>';
379
380 $db->close();
381 exit;
382}
383
384print '<div class="cadre"> '."\n";
385print '<br><br>'."\n";
386
387// Start to show survey result
388print '<div class="div-table-responsive">';
389print '<table class="resultats">'."\n";
390
391// Show choice titles
392if ($object->format == "D") {
393 //display of survey topics
394 print '<tr>'."\n";
395 print '<td></td>'."\n";
396
397 //display of years
398 $colspan = 1;
399 $nbofsujet = count($toutsujet);
400 for ($i = 0; $i < $nbofsujet; $i++) {
401 if (isset($toutsujet[$i + 1]) && date('Y', intval($toutsujet[$i])) == date('Y', intval($toutsujet[$i + 1]))) {
402 $colspan++;
403 } else {
404 print '<td colspan='.$colspan.' class="annee">'.date('Y', intval($toutsujet[$i])).'</td>'."\n";
405 $colspan = 1;
406 }
407 }
408
409 print '</tr>'."\n";
410 print '<tr>'."\n";
411 print '<td></td>'."\n";
412
413 //display of months
414 $colspan = 1;
415 for ($i = 0; $i < $nbofsujet; $i++) {
416 $cur = intval($toutsujet[$i]); // intval() est utiliser pour supprimer le suffixe @* qui déplaît logiquement à strftime()
417
418 if (!isset($toutsujet[$i + 1])) {
419 $next = false;
420 } else {
421 $next = intval($toutsujet[$i + 1]);
422 }
423
424 if ($next && dol_print_date($cur, "%B") == dol_print_date($next, "%B") && dol_print_date($cur, "%Y") == dol_print_date($next, "%Y")) {
425 $colspan++;
426 } else {
427 print '<td colspan='.$colspan.' class="mois">'.dol_print_date($cur, "%B").'</td>'."\n";
428 $colspan = 1;
429 }
430 }
431
432 print '</tr>'."\n";
433 print '<tr>'."\n";
434 print '<td></td>'."\n";
435
436 //display of days
437 $colspan = 1;
438 for ($i = 0; $i < $nbofsujet; $i++) {
439 $cur = intval($toutsujet[$i]);
440 if (!isset($toutsujet[$i + 1])) {
441 $next = false;
442 } else {
443 $next = intval($toutsujet[$i + 1]);
444 }
445 if ($next && dol_print_date($cur, "%a %d") == dol_print_date($next, "%a %d") && dol_print_date($cur, "%B") == dol_print_date($next, "%B")) {
446 $colspan++;
447 } else {
448 print '<td colspan="'.$colspan.'" class="jour">'.dol_print_date($cur, "%a %d").'</td>'."\n";
449 $colspan = 1;
450 }
451 }
452
453 print '</tr>'."\n";
454
455 //Display schedules
456 if (strpos($object->sujet, '@') !== false) {
457 print '<tr>'."\n";
458 print '<td></td>'."\n";
459
460 for ($i = 0; isset($toutsujet[$i]); $i++) {
461 $heures = explode('@', $toutsujet[$i]);
462 if (isset($heures[1])) {
463 print '<td class="heure">'.dol_htmlentities($heures[1]).'</td>'."\n";
464 } else {
465 print '<td class="heure"></td>'."\n";
466 }
467 }
468
469 print '</tr>'."\n";
470 }
471} else {
472 //display of survey topics
473 print '<tr>'."\n";
474 print '<td></td>'."\n";
475
476 for ($i = 0; isset($toutsujet[$i]); $i++) {
477 $tmp = explode('@', $toutsujet[$i]);
478 print '<td class="sujet">'.dol_escape_htmltag($tmp[0]).'</td>'."\n";
479 }
480
481 print '</tr>'."\n";
482}
483
484
485// Loop on each answer
486$currentusername = '';
487$sumfor = array();
488$sumagainst = array();
489$compteur = 0;
490$sql = "SELECT id_users, nom as name, id_sondage, reponses";
491$sql .= " FROM ".MAIN_DB_PREFIX."opensurvey_user_studs";
492$sql .= " WHERE id_sondage = '".$db->escape($numsondage)."'";
493$resql = $db->query($sql);
494if (!$resql) {
496 exit;
497}
498$num = $db->num_rows($resql);
499while ($compteur < $num) {
500 $obj = $db->fetch_object($resql);
501
502 $ensemblereponses = $obj->reponses;
503
504 // Set if line of pre-authentified user
505 $mod_ok = (in_array($obj->name, $listofvoters));
506
507 if (!$mod_ok && !$object->allow_spy) {
508 $compteur++;
509 continue;
510 }
511
512 print '<tr>'."\n";
513
514 // Name
515 print '<td class="nom">'.img_picto($obj->name, 'user', 'class="pictofixedwidth"').dol_htmlentities($obj->name).'</td>'."\n";
516
517 // If the line does not need modification, show the data
518 if (!$testligneamodifier) {
519 for ($i = 0; $i < $nbcolonnes; $i++) {
520 $car = substr($ensemblereponses, $i, 1);
521 //print 'xx'.$i."-".$car.'-'.$listofanswers[$i]['format'].'zz';
522
523 if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst'))) {
524 if (((string) $car) == "1") {
525 print '<td class="ok">OK</td>'."\n";
526 } else {
527 print '<td class="non">KO</td>'."\n";
528 }
529 // Total
530 if (!isset($sumfor[$i])) {
531 $sumfor[$i] = 0;
532 }
533 if (((string) $car) == "1") {
534 $sumfor[$i]++;
535 }
536 }
537 if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno') {
538 if (((string) $car) == "1") {
539 print '<td class="ok">'.$langs->trans("Yes").'</td>'."\n";
540 } elseif (((string) $car) == "0") {
541 print '<td class="non">'.$langs->trans("No").'</td>'."\n";
542 } else {
543 print '<td class="vide">&nbsp;</td>'."\n";
544 }
545 // Total
546 if (!isset($sumfor[$i])) {
547 $sumfor[$i] = 0;
548 }
549 if (!isset($sumagainst[$i])) {
550 $sumagainst[$i] = 0;
551 }
552 if (((string) $car) == "1") {
553 $sumfor[$i]++;
554 }
555 if (((string) $car) == "0") {
556 $sumagainst[$i]++;
557 }
558 }
559 if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst') {
560 if (((string) $car) == "1") {
561 print '<td class="ok">'.$langs->trans("For").'</td>'."\n";
562 } elseif (((string) $car) == "0") {
563 print '<td class="non">'.$langs->trans("Against").'</td>'."\n";
564 } else {
565 print '<td class="vide">&nbsp;</td>'."\n";
566 }
567 // Total
568 if (!isset($sumfor[$i])) {
569 $sumfor[$i] = 0;
570 }
571 if (!isset($sumagainst[$i])) {
572 $sumagainst[$i] = 0;
573 }
574 if (((string) $car) == "1") {
575 $sumfor[$i]++;
576 }
577 if (((string) $car) == "0") {
578 $sumagainst[$i]++;
579 }
580 }
581 }
582 } else {
583 // Else, replace the user's choices with a line of checkboxes for entry
584 if ($compteur == $ligneamodifier) {
585 for ($i = 0; $i < $nbcolonnes; $i++) {
586 $car = substr($ensemblereponses, $i, 1);
587 print '<td class="vide">';
588 if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst'))) {
589 print '<input type="checkbox" name="choix'.$i.'" value="1" ';
590 if ($car == '1') {
591 print 'checked';
592 }
593 print '>';
594 }
595 if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno') {
596 $arraychoice = array('2' => '&nbsp;', '0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
597 print $form->selectarray("choix".$i, $arraychoice, $car);
598 }
599 if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst') {
600 $arraychoice = array('2' => '&nbsp;', '0' => $langs->trans("Against"), '1' => $langs->trans("For"));
601 print $form->selectarray("choix".$i, $arraychoice, $car);
602 }
603 print '</td>'."\n";
604 }
605 } else {
606 for ($i = 0; $i < $nbcolonnes; $i++) {
607 $car = substr($ensemblereponses, $i, 1);
608 if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst'))) {
609 if (((string) $car) == "1") {
610 print '<td class="ok">OK</td>'."\n";
611 } else {
612 print '<td class="non">KO</td>'."\n";
613 }
614 // Total
615 if (!isset($sumfor[$i])) {
616 $sumfor[$i] = 0;
617 }
618 if (((string) $car) == "1") {
619 $sumfor[$i]++;
620 }
621 }
622 if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno') {
623 if (((string) $car) == "1") {
624 print '<td class="ok">'.$langs->trans("For").'</td>'."\n";
625 } elseif (((string) $car) == "0") {
626 print '<td class="non">'.$langs->trans("Against").'</td>'."\n";
627 } else {
628 print '<td class="vide">&nbsp;</td>'."\n";
629 }
630 // Total
631 if (!isset($sumfor[$i])) {
632 $sumfor[$i] = 0;
633 }
634 if (!isset($sumagainst[$i])) {
635 $sumagainst[$i] = 0;
636 }
637 if (((string) $car) == "1") {
638 $sumfor[$i]++;
639 }
640 if (((string) $car) == "0") {
641 $sumagainst[$i]++;
642 }
643 }
644 if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst') {
645 if (((string) $car) == "1") {
646 print '<td class="ok">'.$langs->trans("For").'</td>'."\n";
647 } elseif (((string) $car) == "0") {
648 print '<td class="non">'.$langs->trans("Against").'</td>'."\n";
649 } else {
650 print '<td class="vide">&nbsp;</td>'."\n";
651 }
652 // Total
653 if (!isset($sumfor[$i])) {
654 $sumfor[$i] = 0;
655 }
656 if (!isset($sumagainst[$i])) {
657 $sumagainst[$i] = 0;
658 }
659 if (((string) $car) == "1") {
660 $sumfor[$i]++;
661 }
662 if (((string) $car) == "0") {
663 $sumagainst[$i]++;
664 }
665 }
666 }
667 }
668 }
669
670 // Button edit at end of line
671 if ($compteur != $ligneamodifier && $mod_ok) {
672 $currentusername = $obj->name;
673 print '<td class="casevide"><input type="submit" class="button small" name="modifierligne'.$compteur.'" value="'.dol_escape_htmltag($langs->trans("Edit")).'"></td>'."\n";
674 }
675
676 // Ask for confirmation to modify the line
677 for ($i = 0; $i < $nblines; $i++) {
678 if (GETPOSTISSET("modifierligne".$i)) {
679 if ($compteur == $i) {
680 print '<td class="casevide">';
681 print '<input type="hidden" name="idtomodify'.$compteur.'" value="'.$obj->id_users.'">';
682 print '<input type="submit" class="button button-save small" name="validermodifier'.$compteur.'" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
683 print '</td>'."\n";
684 }
685 }
686 }
687
688 $compteur++;
689 print '</tr>'."\n";
690}
691
692// Add line to add new record
693if ($ligneamodifier < 0 && (!isset($_SESSION['nom']))) {
694 print '<tr>'."\n";
695 print '<td class="nom">'."\n";
696 if (isset($_SESSION['nom'])) {
697 print '<input type=hidden name="nom" value="'.$_SESSION['nom'].'">'.$_SESSION['nom']."\n";
698 } else {
699 print '<input type="text" name="nom" placeholder="'.dol_escape_htmltag($langs->trans("Name")).'" maxlength="64" class=" minwidth175" value="">'."\n";
700 }
701 print '</td>'."\n";
702
703 // show cell form checkbox for a new choice
704 for ($i = 0; $i < $nbcolonnes; $i++) {
705 print '<td class="vide">';
706 if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst'))) {
707 print '<input type="checkbox" name="choix'.$i.'" value="1"';
708 if (GETPOSTISSET('choix'.$i) && GETPOST('choix'.$i) == '1') {
709 print ' checked';
710 }
711 print '>';
712 }
713 if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno') {
714 $arraychoice = array('2' => '&nbsp;', '0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
715 print $form->selectarray("choix".$i, $arraychoice, GETPOST('choix'.$i));
716 }
717 if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst') {
718 $arraychoice = array('2' => '&nbsp;', '0' => $langs->trans("Against"), '1' => $langs->trans("For"));
719 print $form->selectarray("choix".$i, $arraychoice, GETPOST('choix'.$i));
720 }
721 print '</td>'."\n";
722 }
723
724 // Show button to add a new line into database
725 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";
726 print '</tr>'."\n";
727}
728
729// Select value of best choice (for checkbox columns only)
730$nbofcheckbox = 0;
731$meilleurecolonne = null;
732for ($i = 0; $i < $nbcolonnes; $i++) {
733 if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst'))) {
734 $nbofcheckbox++;
735 }
736 if (isset($sumfor[$i])) {
737 if ($i == 0) {
738 $meilleurecolonne = $sumfor[$i];
739 }
740 if (!isset($meilleurecolonne) || $sumfor[$i] > $meilleurecolonne) {
741 $meilleurecolonne = $sumfor[$i];
742 }
743 }
744}
745
746if ($object->allow_spy) {
747 // Show line total
748 print '<tr>'."\n";
749 print '<td class="center">'.$langs->trans("Total").'</td>'."\n";
750 for ($i = 0; $i < $nbcolonnes; $i++) {
751 $showsumfor = isset($sumfor[$i]) ? $sumfor[$i] : '';
752 $showsumagainst = isset($sumagainst[$i]) ? $sumagainst[$i] : '';
753 if (empty($showsumfor)) {
754 $showsumfor = 0;
755 }
756 if (empty($showsumagainst)) {
757 $showsumagainst = 0;
758 }
759
760 print '<td>';
761 if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst'))) {
762 print $showsumfor;
763 }
764 if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno') {
765 print $langs->trans("Yes").': '.$showsumfor.'<br>'.$langs->trans("No").': '.$showsumagainst;
766 }
767 if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst') {
768 print $langs->trans("For").': '.$showsumfor.'<br>'.$langs->trans("Against").': '.$showsumagainst;
769 }
770 print '</td>'."\n";
771 }
772 print '</tr>';
773 // Show picto winner
774 if ($nbofcheckbox >= 2) {
775 print '<tr>'."\n";
776 print '<td class="somme"></td>'."\n";
777 for ($i = 0; $i < $nbcolonnes; $i++) {
778 //print 'xx'.(!empty($listofanswers[$i]['format'])).'-'.$sumfor[$i].'-'.$meilleurecolonne;
779 if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst')) && isset($sumfor[$i]) && isset($meilleurecolonne) && $sumfor[$i] == $meilleurecolonne) {
780 print '<td class="somme"><img src="'.dol_buildpath('/opensurvey/img/medaille.png', 1).'"></td>'."\n";
781 } else {
782 print '<td class="somme"></td>'."\n";
783 }
784 }
785 print '</tr>'."\n";
786 }
787}
788print '</table>'."\n";
789print '</div>'."\n";
790
791print '</div>'."\n";
792
793if ($object->allow_spy) {
794 $toutsujet = explode(",", $object->sujet);
795 $toutsujet = str_replace("°", "'", $toutsujet);
796
797 $compteursujet = 0;
798 $meilleursujet = '';
799
800 for ($i = 0; $i < $nbcolonnes; $i++) {
801 if (isset($sumfor[$i]) && isset($meilleurecolonne) && $sumfor[$i] == $meilleurecolonne) {
802 $meilleursujet .= ($meilleursujet ? ", " : "");
803 if ($object->format == "D") {
804 if (strpos($toutsujet[$i], '@') !== false) {
805 $toutsujetdate = explode("@", $toutsujet[$i]);
806 $meilleursujet .= dol_print_date($toutsujetdate[0], 'daytext').' ('.dol_print_date($toutsujetdate[0], '%A').') - '.$toutsujetdate[1];
807 } else {
808 $meilleursujet .= dol_print_date((empty($toutsujet[$i]) ? 0 : $toutsujet[$i]), 'daytext').' ('.dol_print_date((empty($toutsujet[$i]) ? 0 : $toutsujet[$i]), '%A').')';
809 }
810 } else {
811 $tmps = explode('@', $toutsujet[$i]);
812 $meilleursujet .= dol_htmlentities($tmps[0]);
813 }
814
815 $compteursujet++;
816 }
817 }
818
819 //$meilleursujet = substr($meilleursujet, 1);
820 $meilleursujet = str_replace("°", "'", $meilleursujet);
821
822 // Show best choice
823 if ($nbofcheckbox >= 2) {
824 $vote_str = $langs->trans('votes');
825 print '<p class="affichageresultats">'."\n";
826
827 if (isset($meilleurecolonne) && $compteursujet == "1") {
828 print '<img src="'.dol_buildpath('/opensurvey/img/medaille.png', 1).'"> '.$langs->trans('TheBestChoice').": <b>".$meilleursujet."</b> - <b>".$meilleurecolonne."</b> ".$vote_str.".\n";
829 } elseif (isset($meilleurecolonne)) {
830 print '<img src="'.dol_buildpath('/opensurvey/img/medaille.png', 1).'"> '.$langs->trans('TheBestChoices').": <b>".$meilleursujet."</b> - <b>".$meilleurecolonne."</b> ".$vote_str.".\n";
831 }
832
833 print '</p><br>'."\n";
834 }
835}
836
837print '<br>';
838
839
840// Comment list
841$comments = $object->getComments();
842
843if ($comments) {
844 print '<br>'.img_picto('', 'note', 'class="pictofixedwidth"').'<span class="bold opacitymedium">'.$langs->trans("CommentsOfVoters").':</span><br>'."\n";
845
846 foreach ($comments as $obj) {
847 // Set if line of pre-authentified user
848 //$mod_ok = (in_array($obj->name, $listofvoters));
849
850 print '<div class="comment"><span class="usercomment">';
851 if (in_array($obj->usercomment, $listofvoters)) {
852 print '<a href="'.$_SERVER["PHP_SELF"].'?deletecomment='.$obj->id_comment.'&sondage='.$numsondage.'"> '.img_picto('', 'delete', '', 0, 0, 0, '', 'nomarginleft').'</a> ';
853 }
854 //else print img_picto('', 'ellipsis-h', '', 0, 0, 0, '', 'nomarginleft').' ';
855 print img_picto('', 'user', 'class="pictofixedwidth"').dol_htmlentities($obj->usercomment).':</span> <span class="comment">'.dol_nl2br(dol_htmlentities($obj->comment))."</span></div>";
856 }
857}
858
859// Form to add comment
860if ($object->allow_comments && $currentusername) {
861 print '<br><div class="addcomment"><span class="opacitymedium">'.$langs->trans("AddACommentForPoll")."</span><br>\n";
862
863 print '<textarea name="comment" rows="'.ROWS_2.'" class="quatrevingtpercent">'.dol_escape_htmltag(GETPOST('comment', 'alphanohtml'), 0, 1).'</textarea><br>'."\n";
864 print $langs->trans("Name").': ';
865 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";
866 print '<input type="submit" class="button smallpaddingimp" name="ajoutcomment" value="'.dol_escape_htmltag($langs->trans("AddComment")).'"><br>'."\n";
867 print '</form>'."\n";
868
869 print '</div>'."\n"; // div add comment
870}
871
872print '<br><br>';
873
874print '<a name="bas"></a>'."\n";
875
877
878$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:650
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:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_now($mode='gmt')
Return date for now.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.
dol_htmlentities($string, $flags=ENT_QUOTES|ENT_SUBSTITUTE, $encoding='UTF-8', $double_encode=false)
Replace htmlentities functions.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
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:487
httponly_accessforbidden($message='1', $http_response_code=403, $stringalreadysanitized=0)
Show a message to say access is forbidden and stop program.