dolibarr 21.0.0-beta
studs.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2013-2015 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
4 * Copyright (C) 2024 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(0, $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) || $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;
258for ($i = 0; $i < $nblines; $i++) {
259 if (GETPOSTISSET('modifierligne'.$i)) {
260 $ligneamodifier = $i;
261 $testligneamodifier = true;
262 }
263
264 //test to see if a line is to be modified
265 if (GETPOSTISSET('validermodifier'.$i)) {
266 $modifier = $i;
267 $testmodifier = true;
268 }
269}
270
271if ($testmodifier) {
272 $nouveauchoix = '';
273 for ($i = 0; $i < $nbcolonnes; $i++) {
274 if (GETPOSTISSET("choix".$i) && GETPOST("choix".$i) == '1') {
275 $nouveauchoix .= "1";
276 } elseif (GETPOSTISSET("choix".$i) && GETPOST("choix".$i) == '2') {
277 $nouveauchoix .= "2";
278 } else {
279 $nouveauchoix .= "0";
280 }
281 }
282
283 if (!$canbemodified) {
284 httponly_accessforbidden('ErrorForbidden');
285 }
286
287 $idtomodify = GETPOST("idtomodify".$modifier);
288 $sql = 'UPDATE '.MAIN_DB_PREFIX."opensurvey_user_studs";
289 $sql .= " SET reponses = '".$db->escape($nouveauchoix)."'";
290 $sql .= " WHERE id_users = '".$db->escape($idtomodify)."'";
291
292 $resql = $db->query($sql);
293 if (!$resql) {
294 dol_print_error($db);
295 }
296}
297
298// Delete comment
299$idcomment = GETPOSTINT('deletecomment');
300if ($idcomment) {
301 if (!$canbemodified) {
302 httponly_accessforbidden('ErrorForbidden');
303 }
304
305 $resql = $object->deleteComment($idcomment);
306}
307
308
309
310/*
311 * View
312 */
313
314$form = new Form($db);
315
316$arrayofjs = array();
317$arrayofcss = array('/opensurvey/css/style.css');
318
319llxHeaderSurvey($object->title, "", 0, 0, $arrayofjs, $arrayofcss, $numsondage);
320
321if (empty($object->ref)) { // For survey, id is a hex string
322 $langs->load("errors");
323 print $langs->trans("ErrorRecordNotFound");
324
326
327 $db->close();
328 exit();
329}
330
331// Define format of choices
332$toutsujet = explode(",", $object->sujet);
333$listofanswers = array();
334foreach ($toutsujet as $value) {
335 $tmp = explode('@', $value);
336 $listofanswers[] = array('label' => $tmp[0], 'format' => (!empty($tmp[1]) ? $tmp[1] : 'checkbox'));
337}
338$toutsujet = str_replace("°", "'", $toutsujet);
339
340
341print '<div class="survey_intro">';
342print '<div class="survey_invitation">'.$langs->trans("YouAreInivitedToVote").'</div>';
343print '<span class="opacitymedium">'.$langs->trans("OpenSurveyHowTo").'</span><br>';
344if (empty($object->allow_spy)) {
345 print '<span class="opacitymedium">'.$langs->trans("YourVoteIsPrivate").'</span><br>';
346} else {
347 print $form->textwithpicto('<span class="opacitymedium">'.$langs->trans("YourVoteIsPublic").'</span>', $langs->trans("CanSeeOthersVote")).'<br>';
348}
349print '</div>';
350print '<br>';
351
352if (empty($object->description)) {
353 print '<div class="corps">'."\n";
354} else {
355 print '<br>'."\n";
356}
357
358// show title of survey
359$titre = str_replace("\\", "", $object->title);
360print '<div class="survey_title">'.img_picto('', 'poll', 'class="size15x paddingright"').' <strong>'.dol_htmlentities($titre).'</strong></div>';
361
362if (!empty($object->description)) {
363 print '<br><div class="corps">'."\n";
364}
365
366// show description of survey
367if ($object->description) {
368 print dol_htmlentitiesbr($object->description);
369}
370
371print '</div>'."\n";
372
373//The survey has expired, users can't vote or do any action
374if (!$canbemodified) {
375 print '<br><center><div class="quatrevingtpercent center warning">'.$langs->trans('SurveyExpiredInfo').'</div></center>';
377
378 $db->close();
379 exit;
380}
381
382print '<div class="cadre"> '."\n";
383print '<br><br>'."\n";
384
385// Start to show survey result
386print '<div class="div-table-responsive">';
387print '<table class="resultats">'."\n";
388
389// Show choice titles
390if ($object->format == "D") {
391 //display of survey topics
392 print '<tr>'."\n";
393 print '<td></td>'."\n";
394
395 //display of years
396 $colspan = 1;
397 $nbofsujet = count($toutsujet);
398 for ($i = 0; $i < $nbofsujet; $i++) {
399 if (isset($toutsujet[$i + 1]) && date('Y', intval($toutsujet[$i])) == date('Y', intval($toutsujet[$i + 1]))) {
400 $colspan++;
401 } else {
402 print '<td colspan='.$colspan.' class="annee">'.date('Y', intval($toutsujet[$i])).'</td>'."\n";
403 $colspan = 1;
404 }
405 }
406
407 print '</tr>'."\n";
408 print '<tr>'."\n";
409 print '<td></td>'."\n";
410
411 //display of months
412 $colspan = 1;
413 for ($i = 0; $i < $nbofsujet; $i++) {
414 $cur = intval($toutsujet[$i]); // intval() est utiliser pour supprimer le suffixe @* qui déplaît logiquement à strftime()
415
416 if (!isset($toutsujet[$i + 1])) {
417 $next = false;
418 } else {
419 $next = intval($toutsujet[$i + 1]);
420 }
421
422 if ($next && dol_print_date($cur, "%B") == dol_print_date($next, "%B") && dol_print_date($cur, "%Y") == dol_print_date($next, "%Y")) {
423 $colspan++;
424 } else {
425 print '<td colspan='.$colspan.' class="mois">'.dol_print_date($cur, "%B").'</td>'."\n";
426 $colspan = 1;
427 }
428 }
429
430 print '</tr>'."\n";
431 print '<tr>'."\n";
432 print '<td></td>'."\n";
433
434 //display of days
435 $colspan = 1;
436 for ($i = 0; $i < $nbofsujet; $i++) {
437 $cur = intval($toutsujet[$i]);
438 if (!isset($toutsujet[$i + 1])) {
439 $next = false;
440 } else {
441 $next = intval($toutsujet[$i + 1]);
442 }
443 if ($next && dol_print_date($cur, "%a %d") == dol_print_date($next, "%a %d") && dol_print_date($cur, "%B") == dol_print_date($next, "%B")) {
444 $colspan++;
445 } else {
446 print '<td colspan="'.$colspan.'" class="jour">'.dol_print_date($cur, "%a %d").'</td>'."\n";
447 $colspan = 1;
448 }
449 }
450
451 print '</tr>'."\n";
452
453 //Display schedules
454 if (strpos($object->sujet, '@') !== false) {
455 print '<tr>'."\n";
456 print '<td></td>'."\n";
457
458 for ($i = 0; isset($toutsujet[$i]); $i++) {
459 $heures = explode('@', $toutsujet[$i]);
460 if (isset($heures[1])) {
461 print '<td class="heure">'.dol_htmlentities($heures[1]).'</td>'."\n";
462 } else {
463 print '<td class="heure"></td>'."\n";
464 }
465 }
466
467 print '</tr>'."\n";
468 }
469} else {
470 //display of survey topics
471 print '<tr>'."\n";
472 print '<td></td>'."\n";
473
474 for ($i = 0; isset($toutsujet[$i]); $i++) {
475 $tmp = explode('@', $toutsujet[$i]);
476 print '<td class="sujet">'.dol_escape_htmltag($tmp[0]).'</td>'."\n";
477 }
478
479 print '</tr>'."\n";
480}
481
482
483// Loop on each answer
484$currentusername = '';
485$sumfor = array();
486$sumagainst = array();
487$compteur = 0;
488$sql = "SELECT id_users, nom as name, id_sondage, reponses";
489$sql .= " FROM ".MAIN_DB_PREFIX."opensurvey_user_studs";
490$sql .= " WHERE id_sondage = '".$db->escape($numsondage)."'";
491$resql = $db->query($sql);
492if (!$resql) {
493 dol_print_error($db);
494 exit;
495}
496$num = $db->num_rows($resql);
497while ($compteur < $num) {
498 $obj = $db->fetch_object($resql);
499
500 $ensemblereponses = $obj->reponses;
501
502 // ligne d'un usager pré-authentifié
503 $mod_ok = (in_array($obj->name, $listofvoters));
504
505 if (!$mod_ok && !$object->allow_spy) {
506 $compteur++;
507 continue;
508 }
509
510 print '<tr>'."\n";
511
512 // Name
513 print '<td class="nom">'.img_picto($obj->name, 'user', 'class="pictofixedwidth"').dol_htmlentities($obj->name).'</td>'."\n";
514
515 // si la ligne n'est pas a changer, on affiche les données
516 if (!$testligneamodifier) {
517 for ($i = 0; $i < $nbcolonnes; $i++) {
518 $car = substr($ensemblereponses, $i, 1);
519 //print 'xx'.$i."-".$car.'-'.$listofanswers[$i]['format'].'zz';
520
521 if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst'))) {
522 if (((string) $car) == "1") {
523 print '<td class="ok">OK</td>'."\n";
524 } else {
525 print '<td class="non">KO</td>'."\n";
526 }
527 // Total
528 if (!isset($sumfor[$i])) {
529 $sumfor[$i] = 0;
530 }
531 if (((string) $car) == "1") {
532 $sumfor[$i]++;
533 }
534 }
535 if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno') {
536 if (((string) $car) == "1") {
537 print '<td class="ok">'.$langs->trans("Yes").'</td>'."\n";
538 } elseif (((string) $car) == "0") {
539 print '<td class="non">'.$langs->trans("No").'</td>'."\n";
540 } else {
541 print '<td class="vide">&nbsp;</td>'."\n";
542 }
543 // Total
544 if (!isset($sumfor[$i])) {
545 $sumfor[$i] = 0;
546 }
547 if (!isset($sumagainst[$i])) {
548 $sumagainst[$i] = 0;
549 }
550 if (((string) $car) == "1") {
551 $sumfor[$i]++;
552 }
553 if (((string) $car) == "0") {
554 $sumagainst[$i]++;
555 }
556 }
557 if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst') {
558 if (((string) $car) == "1") {
559 print '<td class="ok">'.$langs->trans("For").'</td>'."\n";
560 } elseif (((string) $car) == "0") {
561 print '<td class="non">'.$langs->trans("Against").'</td>'."\n";
562 } else {
563 print '<td class="vide">&nbsp;</td>'."\n";
564 }
565 // Total
566 if (!isset($sumfor[$i])) {
567 $sumfor[$i] = 0;
568 }
569 if (!isset($sumagainst[$i])) {
570 $sumagainst[$i] = 0;
571 }
572 if (((string) $car) == "1") {
573 $sumfor[$i]++;
574 }
575 if (((string) $car) == "0") {
576 $sumagainst[$i]++;
577 }
578 }
579 }
580 } else {
581 // Else, replace the user's choices with a line of checkboxes for entry
582 if ($compteur == $ligneamodifier) {
583 for ($i = 0; $i < $nbcolonnes; $i++) {
584 $car = substr($ensemblereponses, $i, 1);
585 print '<td class="vide">';
586 if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst'))) {
587 print '<input type="checkbox" name="choix'.$i.'" value="1" ';
588 if ($car == '1') {
589 print 'checked';
590 }
591 print '>';
592 }
593 if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno') {
594 $arraychoice = array('2' => '&nbsp;', '0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
595 print $form->selectarray("choix".$i, $arraychoice, $car);
596 }
597 if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst') {
598 $arraychoice = array('2' => '&nbsp;', '0' => $langs->trans("Against"), '1' => $langs->trans("For"));
599 print $form->selectarray("choix".$i, $arraychoice, $car);
600 }
601 print '</td>'."\n";
602 }
603 } else {
604 for ($i = 0; $i < $nbcolonnes; $i++) {
605 $car = substr($ensemblereponses, $i, 1);
606 if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst'))) {
607 if (((string) $car) == "1") {
608 print '<td class="ok">OK</td>'."\n";
609 } else {
610 print '<td class="non">KO</td>'."\n";
611 }
612 // Total
613 if (!isset($sumfor[$i])) {
614 $sumfor[$i] = 0;
615 }
616 if (((string) $car) == "1") {
617 $sumfor[$i]++;
618 }
619 }
620 if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno') {
621 if (((string) $car) == "1") {
622 print '<td class="ok">'.$langs->trans("For").'</td>'."\n";
623 } elseif (((string) $car) == "0") {
624 print '<td class="non">'.$langs->trans("Against").'</td>'."\n";
625 } else {
626 print '<td class="vide">&nbsp;</td>'."\n";
627 }
628 // Total
629 if (!isset($sumfor[$i])) {
630 $sumfor[$i] = 0;
631 }
632 if (!isset($sumagainst[$i])) {
633 $sumagainst[$i] = 0;
634 }
635 if (((string) $car) == "1") {
636 $sumfor[$i]++;
637 }
638 if (((string) $car) == "0") {
639 $sumagainst[$i]++;
640 }
641 }
642 if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst') {
643 if (((string) $car) == "1") {
644 print '<td class="ok">'.$langs->trans("For").'</td>'."\n";
645 } elseif (((string) $car) == "0") {
646 print '<td class="non">'.$langs->trans("Against").'</td>'."\n";
647 } else {
648 print '<td class="vide">&nbsp;</td>'."\n";
649 }
650 // Total
651 if (!isset($sumfor[$i])) {
652 $sumfor[$i] = 0;
653 }
654 if (!isset($sumagainst[$i])) {
655 $sumagainst[$i] = 0;
656 }
657 if (((string) $car) == "1") {
658 $sumfor[$i]++;
659 }
660 if (((string) $car) == "0") {
661 $sumagainst[$i]++;
662 }
663 }
664 }
665 }
666 }
667
668 // Button edit at end of line
669 if ($compteur != $ligneamodifier && $mod_ok) {
670 $currentusername = $obj->name;
671 print '<td class="casevide"><input type="submit" class="button small" name="modifierligne'.$compteur.'" value="'.dol_escape_htmltag($langs->trans("Edit")).'"></td>'."\n";
672 }
673
674 //demande de confirmation pour modification de ligne
675 for ($i = 0; $i < $nblines; $i++) {
676 if (GETPOSTISSET("modifierligne".$i)) {
677 if ($compteur == $i) {
678 print '<td class="casevide">';
679 print '<input type="hidden" name="idtomodify'.$compteur.'" value="'.$obj->id_users.'">';
680 print '<input type="submit" class="button button-save small" name="validermodifier'.$compteur.'" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
681 print '</td>'."\n";
682 }
683 }
684 }
685
686 $compteur++;
687 print '</tr>'."\n";
688}
689
690// Add line to add new record
691if ($ligneamodifier < 0 && (!isset($_SESSION['nom']))) {
692 print '<tr>'."\n";
693 print '<td class="nom">'."\n";
694 if (isset($_SESSION['nom'])) {
695 print '<input type=hidden name="nom" value="'.$_SESSION['nom'].'">'.$_SESSION['nom']."\n";
696 } else {
697 print '<input type="text" name="nom" placeholder="'.dol_escape_htmltag($langs->trans("Name")).'" maxlength="64" class=" minwidth175" value="">'."\n";
698 }
699 print '</td>'."\n";
700
701 // show cell form checkbox for a new choice
702 for ($i = 0; $i < $nbcolonnes; $i++) {
703 print '<td class="vide">';
704 if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst'))) {
705 print '<input type="checkbox" name="choix'.$i.'" value="1"';
706 if (GETPOSTISSET('choix'.$i) && GETPOST('choix'.$i) == '1') {
707 print ' checked';
708 }
709 print '>';
710 }
711 if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno') {
712 $arraychoice = array('2' => '&nbsp;', '0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
713 print $form->selectarray("choix".$i, $arraychoice, GETPOST('choix'.$i));
714 }
715 if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst') {
716 $arraychoice = array('2' => '&nbsp;', '0' => $langs->trans("Against"), '1' => $langs->trans("For"));
717 print $form->selectarray("choix".$i, $arraychoice, GETPOST('choix'.$i));
718 }
719 print '</td>'."\n";
720 }
721
722 // Show button to add a new line into database
723 print '<td><input type="image" class="borderimp" name="boutonp" value="'.$langs->trans("Vote").'" src="'.img_picto('', 'edit_add', '', 0, 1).'"></td>'."\n";
724 print '</tr>'."\n";
725}
726
727// Select value of best choice (for checkbox columns only)
728$nbofcheckbox = 0;
729for ($i = 0; $i < $nbcolonnes; $i++) {
730 if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst'))) {
731 $nbofcheckbox++;
732 }
733 if (isset($sumfor[$i])) {
734 if ($i == 0) {
735 $meilleurecolonne = $sumfor[$i];
736 }
737 if (!isset($meilleurecolonne) || $sumfor[$i] > $meilleurecolonne) {
738 $meilleurecolonne = $sumfor[$i];
739 }
740 }
741}
742
743if ($object->allow_spy) {
744 // Show line total
745 print '<tr>'."\n";
746 print '<td class="center">'.$langs->trans("Total").'</td>'."\n";
747 for ($i = 0; $i < $nbcolonnes; $i++) {
748 $showsumfor = isset($sumfor[$i]) ? $sumfor[$i] : '';
749 $showsumagainst = isset($sumagainst[$i]) ? $sumagainst[$i] : '';
750 if (empty($showsumfor)) {
751 $showsumfor = 0;
752 }
753 if (empty($showsumagainst)) {
754 $showsumagainst = 0;
755 }
756
757 print '<td>';
758 if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst'))) {
759 print $showsumfor;
760 }
761 if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno') {
762 print $langs->trans("Yes").': '.$showsumfor.'<br>'.$langs->trans("No").': '.$showsumagainst;
763 }
764 if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst') {
765 print $langs->trans("For").': '.$showsumfor.'<br>'.$langs->trans("Against").': '.$showsumagainst;
766 }
767 print '</td>'."\n";
768 }
769 print '</tr>';
770 // Show picto winner
771 if ($nbofcheckbox >= 2) {
772 print '<tr>'."\n";
773 print '<td class="somme"></td>'."\n";
774 for ($i = 0; $i < $nbcolonnes; $i++) {
775 //print 'xx'.(!empty($listofanswers[$i]['format'])).'-'.$sumfor[$i].'-'.$meilleurecolonne;
776 if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst')) && isset($sumfor[$i]) && isset($meilleurecolonne) && $sumfor[$i] == $meilleurecolonne) {
777 print '<td class="somme"><img src="'.dol_buildpath('/opensurvey/img/medaille.png', 1).'"></td>'."\n";
778 } else {
779 print '<td class="somme"></td>'."\n";
780 }
781 }
782 print '</tr>'."\n";
783 }
784}
785print '</table>'."\n";
786print '</div>'."\n";
787
788print '</div>'."\n";
789
790if ($object->allow_spy) {
791 $toutsujet = explode(",", $object->sujet);
792 $toutsujet = str_replace("°", "'", $toutsujet);
793
794 $compteursujet = 0;
795 $meilleursujet = '';
796
797 for ($i = 0; $i < $nbcolonnes; $i++) {
798 if (isset($sumfor[$i]) && isset($meilleurecolonne) && $sumfor[$i] == $meilleurecolonne) {
799 $meilleursujet .= ($meilleursujet ? ", " : "");
800 if ($object->format == "D") {
801 if (strpos($toutsujet[$i], '@') !== false) {
802 $toutsujetdate = explode("@", $toutsujet[$i]);
803 $meilleursujet .= dol_print_date($toutsujetdate[0], 'daytext').' ('.dol_print_date($toutsujetdate[0], '%A').') - '.$toutsujetdate[1];
804 } else {
805 $meilleursujet .= dol_print_date((empty($toutsujet[$i]) ? 0 : $toutsujet[$i]), 'daytext').' ('.dol_print_date((empty($toutsujet[$i]) ? 0 : $toutsujet[$i]), '%A').')';
806 }
807 } else {
808 $tmps = explode('@', $toutsujet[$i]);
809 $meilleursujet .= dol_htmlentities($tmps[0]);
810 }
811
812 $compteursujet++;
813 }
814 }
815
816 //$meilleursujet = substr($meilleursujet, 1);
817 $meilleursujet = str_replace("°", "'", $meilleursujet);
818
819 // Show best choice
820 if ($nbofcheckbox >= 2) {
821 $vote_str = $langs->trans('votes');
822 print '<p class="affichageresultats">'."\n";
823
824 if (isset($meilleurecolonne) && $compteursujet == "1") {
825 print '<img src="'.dol_buildpath('/opensurvey/img/medaille.png', 1).'"> '.$langs->trans('TheBestChoice').": <b>".$meilleursujet."</b> - <b>".$meilleurecolonne."</b> ".$vote_str.".\n";
826 } elseif (isset($meilleurecolonne)) {
827 print '<img src="'.dol_buildpath('/opensurvey/img/medaille.png', 1).'"> '.$langs->trans('TheBestChoices').": <b>".$meilleursujet."</b> - <b>".$meilleurecolonne."</b> ".$vote_str.".\n";
828 }
829
830 print '</p><br>'."\n";
831 }
832}
833
834print '<br>';
835
836
837// Comment list
838$comments = $object->getComments();
839
840if ($comments) {
841 print '<br>'.img_picto('', 'note', 'class="pictofixedwidth"').'<span class="bold opacitymedium">'.$langs->trans("CommentsOfVoters").':</span><br>'."\n";
842
843 foreach ($comments as $obj) {
844 // ligne d'un usager pré-authentifié
845 //$mod_ok = (in_array($obj->name, $listofvoters));
846
847 print '<div class="comment"><span class="usercomment">';
848 if (in_array($obj->usercomment, $listofvoters)) {
849 print '<a href="'.$_SERVER["PHP_SELF"].'?deletecomment='.$obj->id_comment.'&sondage='.$numsondage.'"> '.img_picto('', 'delete.png', '', 0, 0, 0, '', 'nomarginleft').'</a> ';
850 }
851 //else print img_picto('', 'ellipsis-h', '', 0, 0, 0, '', 'nomarginleft').' ';
852 print img_picto('', 'user', 'class="pictofixedwidth"').dol_htmlentities($obj->usercomment).':</span> <span class="comment">'.dol_nl2br(dol_htmlentities($obj->comment))."</span></div>";
853 }
854}
855
856// Form to add comment
857if ($object->allow_comments && $currentusername) {
858 print '<br><div class="addcomment"><span class="opacitymedium">'.$langs->trans("AddACommentForPoll")."</span><br>\n";
859
860 print '<textarea name="comment" rows="'.ROWS_2.'" class="quatrevingtpercent">'.dol_escape_htmltag(GETPOST('comment', 'alphanohtml'), 0, 1).'</textarea><br>'."\n";
861 print $langs->trans("Name").': ';
862 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";
863 print '<input type="submit" class="button smallpaddingimp" name="ajoutcomment" value="'.dol_escape_htmltag($langs->trans("AddComment")).'"><br>'."\n";
864 print '</form>'."\n";
865
866 print '</div>'."\n"; // div add comment
867}
868
869print '<br><br>';
870
871print '<a name="bas"></a>'."\n";
872
874
875$db->close();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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...
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.