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