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