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