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