dolibarr  19.0.0-dev
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 
25 if (!defined('NOLOGIN')) {
26  define("NOLOGIN", 1); // This means this output page does not require to be logged.
27 }
28 if (!defined('NOCSRFCHECK')) {
29  define("NOCSRFCHECK", 1); // We accept to go on this page from external web site.
30 }
31 if (!defined('NOBROWSERNOTIF')) {
32  define('NOBROWSERNOTIF', '1');
33 }
34 if (!defined('NOIPCHECK')) {
35  define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
36 }
37 
38 // Load Dolibarr environment
39 require '../../main.inc.php';
40 require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
41 require_once DOL_DOCUMENT_ROOT."/core/lib/files.lib.php";
42 require_once DOL_DOCUMENT_ROOT."/opensurvey/class/opensurveysondage.class.php";
43 require_once DOL_DOCUMENT_ROOT."/opensurvey/lib/opensurvey.lib.php";
44 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
45 
46 
47 // Init vars
48 $action = GETPOST('action', 'aZ09');
49 $numsondage = '';
50 if (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
63 if (empty($conf->opensurvey->enabled)) {
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
77 if (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
139 if (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;
250 for ($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 
263 if ($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 = GETPOST('deletecomment', 'int');
292 if ($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 
311 llxHeaderSurvey($object->title, "", 0, 0, $arrayofjs, $arrayofcss, $numsondage);
312 
313 if (empty($object->ref)) { // For survey, id is a hex string
314  $langs->load("errors");
315  print $langs->trans("ErrorRecordNotFound");
316 
317  llxFooterSurvey();
318 
319  $db->close();
320  exit();
321 }
322 
323 // Define format of choices
324 $toutsujet = explode(",", $object->sujet);
325 $listofanswers = array();
326 foreach ($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 
333 
334 print '<div class="survey_invitation">'.$langs->trans("YouAreInivitedToVote").'</div>';
335 print '<span class="opacitymedium">'.$langs->trans("OpenSurveyHowTo").'</span><br>';
336 if (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 }
341 print '<br>';
342 
343 if (empty($object->description)) {
344  print '<div class="corps"> '."\n";
345 }
346 
347 // show title of survey
348 $titre = str_replace("\\", "", $object->title);
349 print '<strong>'.dol_htmlentities($titre).'</strong><br>';
350 
351 if (!empty($object->description)) {
352  print '<br><div class="corps"> '."\n";
353 }
354 
355 // show description of survey
356 if ($object->description) {
357  print dol_htmlentitiesbr($object->description);
358 }
359 
360 print '</div>'."\n";
361 
362 //The survey has expired, users can't vote or do any action
363 if (!$canbemodified) {
364  print '<br><center><div class="quatrevingtpercent center warning">'.$langs->trans('SurveyExpiredInfo').'</div></center>';
365  llxFooterSurvey();
366 
367  $db->close();
368  exit;
369 }
370 
371 print '<div class="cadre"> '."\n";
372 print '<br><br>'."\n";
373 
374 // Start to show survey result
375 print '<table class="resultats">'."\n";
376 
377 // Show choice titles
378 if ($object->format == "D") {
379  //display of survey topics
380  print '<tr>'."\n";
381  print '<td></td>'."\n";
382 
383  //display of years
384  $colspan = 1;
385  $nbofsujet = count($toutsujet);
386  for ($i = 0; $i < $nbofsujet; $i++) {
387  if (isset($toutsujet[$i + 1]) && date('Y', intval($toutsujet[$i])) == date('Y', intval($toutsujet[$i + 1]))) {
388  $colspan++;
389  } else {
390  print '<td colspan='.$colspan.' class="annee">'.date('Y', intval($toutsujet[$i])).'</td>'."\n";
391  $colspan = 1;
392  }
393  }
394 
395  print '</tr>'."\n";
396  print '<tr>'."\n";
397  print '<td></td>'."\n";
398 
399  //display of months
400  $colspan = 1;
401  for ($i = 0; $i < $nbofsujet; $i++) {
402  $cur = intval($toutsujet[$i]); // intval() est utiliser pour supprimer le suffixe @* qui déplaît logiquement à strftime()
403 
404  if (isset($toutsujet[$i + 1]) === false) {
405  $next = false;
406  } else {
407  $next = intval($toutsujet[$i + 1]);
408  }
409 
410  if ($next && dol_print_date($cur, "%B") == dol_print_date($next, "%B") && dol_print_date($cur, "%Y") == dol_print_date($next, "%Y")) {
411  $colspan++;
412  } else {
413  print '<td colspan='.$colspan.' class="mois">'.dol_print_date($cur, "%B").'</td>'."\n";
414  $colspan = 1;
415  }
416  }
417 
418  print '</tr>'."\n";
419  print '<tr>'."\n";
420  print '<td></td>'."\n";
421 
422  //display of days
423  $colspan = 1;
424  for ($i = 0; $i < $nbofsujet; $i++) {
425  $cur = intval($toutsujet[$i]);
426  if (isset($toutsujet[$i + 1]) === false) {
427  $next = false;
428  } else {
429  $next = intval($toutsujet[$i + 1]);
430  }
431  if ($next && dol_print_date($cur, "%a %d") == dol_print_date($next, "%a %d") && dol_print_date($cur, "%B") == dol_print_date($next, "%B")) {
432  $colspan++;
433  } else {
434  print '<td colspan="'.$colspan.'" class="jour">'.dol_print_date($cur, "%a %d").'</td>'."\n";
435  $colspan = 1;
436  }
437  }
438 
439  print '</tr>'."\n";
440 
441  //Display schedules
442  if (strpos($object->sujet, '@') !== false) {
443  print '<tr>'."\n";
444  print '<td></td>'."\n";
445 
446  for ($i = 0; isset($toutsujet[$i]); $i++) {
447  $heures = explode('@', $toutsujet[$i]);
448  if (isset($heures[1])) {
449  print '<td class="heure">'.dol_htmlentities($heures[1]).'</td>'."\n";
450  } else {
451  print '<td class="heure"></td>'."\n";
452  }
453  }
454 
455  print '</tr>'."\n";
456  }
457 } else {
458  //display of survey topics
459  print '<tr>'."\n";
460  print '<td></td>'."\n";
461 
462  for ($i = 0; isset($toutsujet[$i]); $i++) {
463  $tmp = explode('@', $toutsujet[$i]);
464  print '<td class="sujet">'.dol_escape_htmltag($tmp[0]).'</td>'."\n";
465  }
466 
467  print '</tr>'."\n";
468 }
469 
470 
471 // Loop on each answer
472 $currentusername = '';
473 $sumfor = array();
474 $sumagainst = array();
475 $compteur = 0;
476 $sql = "SELECT id_users, nom as name, id_sondage, reponses";
477 $sql .= " FROM ".MAIN_DB_PREFIX."opensurvey_user_studs";
478 $sql .= " WHERE id_sondage = '".$db->escape($numsondage)."'";
479 $resql = $db->query($sql);
480 if (!$resql) {
481  dol_print_error($db);
482  exit;
483 }
484 $num = $db->num_rows($resql);
485 while ($compteur < $num) {
486  $obj = $db->fetch_object($resql);
487 
488  $ensemblereponses = $obj->reponses;
489 
490  // ligne d'un usager pré-authentifié
491  $mod_ok = (in_array($obj->name, $listofvoters));
492 
493  if (!$mod_ok && !$object->allow_spy) {
494  $compteur++;
495  continue;
496  }
497 
498  print '<tr>'."\n";
499 
500  // Name
501  print '<td class="nom">'.dol_htmlentities($obj->name).'</td>'."\n";
502 
503  // si la ligne n'est pas a changer, on affiche les données
504  if (!$testligneamodifier) {
505  for ($i = 0; $i < $nbcolonnes; $i++) {
506  $car = substr($ensemblereponses, $i, 1);
507  //print 'xx'.$i."-".$car.'-'.$listofanswers[$i]['format'].'zz';
508 
509  if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst'))) {
510  if (((string) $car) == "1") {
511  print '<td class="ok">OK</td>'."\n";
512  } else {
513  print '<td class="non">KO</td>'."\n";
514  }
515  // Total
516  if (!isset($sumfor[$i])) {
517  $sumfor[$i] = 0;
518  }
519  if (((string) $car) == "1") {
520  $sumfor[$i]++;
521  }
522  }
523  if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno') {
524  if (((string) $car) == "1") {
525  print '<td class="ok">'.$langs->trans("Yes").'</td>'."\n";
526  } elseif (((string) $car) == "0") {
527  print '<td class="non">'.$langs->trans("No").'</td>'."\n";
528  } else {
529  print '<td class="vide">&nbsp;</td>'."\n";
530  }
531  // Total
532  if (!isset($sumfor[$i])) {
533  $sumfor[$i] = 0;
534  }
535  if (!isset($sumagainst[$i])) {
536  $sumagainst[$i] = 0;
537  }
538  if (((string) $car) == "1") {
539  $sumfor[$i]++;
540  }
541  if (((string) $car) == "0") {
542  $sumagainst[$i]++;
543  }
544  }
545  if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst') {
546  if (((string) $car) == "1") {
547  print '<td class="ok">'.$langs->trans("For").'</td>'."\n";
548  } elseif (((string) $car) == "0") {
549  print '<td class="non">'.$langs->trans("Against").'</td>'."\n";
550  } else {
551  print '<td class="vide">&nbsp;</td>'."\n";
552  }
553  // Total
554  if (!isset($sumfor[$i])) {
555  $sumfor[$i] = 0;
556  }
557  if (!isset($sumagainst[$i])) {
558  $sumagainst[$i] = 0;
559  }
560  if (((string) $car) == "1") {
561  $sumfor[$i]++;
562  }
563  if (((string) $car) == "0") {
564  $sumagainst[$i]++;
565  }
566  }
567  }
568  } else {
569  //sinon on remplace les choix de l'utilisateur par une ligne de checkbox pour saisie
570  if ($compteur == $ligneamodifier) {
571  for ($i = 0; $i < $nbcolonnes; $i++) {
572  $car = substr($ensemblereponses, $i, 1);
573  print '<td class="vide">';
574  if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst'))) {
575  print '<input type="checkbox" name="choix'.$i.'" value="1" ';
576  if ($car == '1') {
577  print 'checked';
578  }
579  print '>';
580  }
581  if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno') {
582  $arraychoice = array('2'=>'&nbsp;', '0'=>$langs->trans("No"), '1'=>$langs->trans("Yes"));
583  print $form->selectarray("choix".$i, $arraychoice, $car);
584  }
585  if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst') {
586  $arraychoice = array('2'=>'&nbsp;', '0'=>$langs->trans("Against"), '1'=>$langs->trans("For"));
587  print $form->selectarray("choix".$i, $arraychoice, $car);
588  }
589  print '</td>'."\n";
590  }
591  } else {
592  for ($i = 0; $i < $nbcolonnes; $i++) {
593  $car = substr($ensemblereponses, $i, 1);
594  if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst'))) {
595  if (((string) $car) == "1") {
596  print '<td class="ok">OK</td>'."\n";
597  } else {
598  print '<td class="non">KO</td>'."\n";
599  }
600  // Total
601  if (!isset($sumfor[$i])) {
602  $sumfor[$i] = 0;
603  }
604  if (((string) $car) == "1") {
605  $sumfor[$i]++;
606  }
607  }
608  if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno') {
609  if (((string) $car) == "1") {
610  print '<td class="ok">'.$langs->trans("For").'</td>'."\n";
611  } elseif (((string) $car) == "0") {
612  print '<td class="non">'.$langs->trans("Against").'</td>'."\n";
613  } else {
614  print '<td class="vide">&nbsp;</td>'."\n";
615  }
616  // Total
617  if (!isset($sumfor[$i])) {
618  $sumfor[$i] = 0;
619  }
620  if (!isset($sumagainst[$i])) {
621  $sumagainst[$i] = 0;
622  }
623  if (((string) $car) == "1") {
624  $sumfor[$i]++;
625  }
626  if (((string) $car) == "0") {
627  $sumagainst[$i]++;
628  }
629  }
630  if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst') {
631  if (((string) $car) == "1") {
632  print '<td class="ok">'.$langs->trans("For").'</td>'."\n";
633  } elseif (((string) $car) == "0") {
634  print '<td class="non">'.$langs->trans("Against").'</td>'."\n";
635  } else {
636  print '<td class="vide">&nbsp;</td>'."\n";
637  }
638  // Total
639  if (!isset($sumfor[$i])) {
640  $sumfor[$i] = 0;
641  }
642  if (!isset($sumagainst[$i])) {
643  $sumagainst[$i] = 0;
644  }
645  if (((string) $car) == "1") {
646  $sumfor[$i]++;
647  }
648  if (((string) $car) == "0") {
649  $sumagainst[$i]++;
650  }
651  }
652  }
653  }
654  }
655 
656  // Button edit at end of line
657  if ($compteur != $ligneamodifier && $mod_ok) {
658  $currentusername = $obj->name;
659  print '<td class="casevide"><input type="submit" class="button small" name="modifierligne'.$compteur.'" value="'.dol_escape_htmltag($langs->trans("Edit")).'"></td>'."\n";
660  }
661 
662  //demande de confirmation pour modification de ligne
663  for ($i = 0; $i < $nblines; $i++) {
664  if (GETPOSTISSET("modifierligne".$i)) {
665  if ($compteur == $i) {
666  print '<td class="casevide">';
667  print '<input type="hidden" name="idtomodify'.$compteur.'" value="'.$obj->id_users.'">';
668  print '<input type="submit" class="button button-save small" name="validermodifier'.$compteur.'" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
669  print '</td>'."\n";
670  }
671  }
672  }
673 
674  $compteur++;
675  print '</tr>'."\n";
676 }
677 
678 // Add line to add new record
679 if ($ligneamodifier < 0 && (!isset($_SESSION['nom']))) {
680  print '<tr>'."\n";
681  print '<td class="nom">'."\n";
682  if (isset($_SESSION['nom'])) {
683  print '<input type=hidden name="nom" value="'.$_SESSION['nom'].'">'.$_SESSION['nom']."\n";
684  } else {
685  print '<input type="text" name="nom" placeholder="'.dol_escape_htmltag($langs->trans("Name")).'" maxlength="64" class=" minwidth175" value="">'."\n";
686  }
687  print '</td>'."\n";
688 
689  // affichage des cases de formulaire checkbox pour un nouveau choix
690  for ($i = 0; $i < $nbcolonnes; $i++) {
691  print '<td class="vide">';
692  if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst'))) {
693  print '<input type="checkbox" name="choix'.$i.'" value="1"';
694  if (GETPOSTISSET('choix'.$i) && GETPOST('choix'.$i) == '1') {
695  print ' checked';
696  }
697  print '>';
698  }
699  if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno') {
700  $arraychoice = array('2'=>'&nbsp;', '0'=>$langs->trans("No"), '1'=>$langs->trans("Yes"));
701  print $form->selectarray("choix".$i, $arraychoice, GETPOST('choix'.$i));
702  }
703  if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst') {
704  $arraychoice = array('2'=>'&nbsp;', '0'=>$langs->trans("Against"), '1'=>$langs->trans("For"));
705  print $form->selectarray("choix".$i, $arraychoice, GETPOST('choix'.$i));
706  }
707  print '</td>'."\n";
708  }
709 
710  // Show button to add a new line into database
711  print '<td><input type="image" class="borderimp" name="boutonp" value="'.$langs->trans("Vote").'" src="'.img_picto('', 'edit_add', '', false, 1).'"></td>'."\n";
712  print '</tr>'."\n";
713 }
714 
715 // Select value of best choice (for checkbox columns only)
716 $nbofcheckbox = 0;
717 for ($i = 0; $i < $nbcolonnes; $i++) {
718  if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst'))) {
719  $nbofcheckbox++;
720  }
721  if (isset($sumfor[$i])) {
722  if ($i == 0) {
723  $meilleurecolonne = $sumfor[$i];
724  }
725  if (!isset($meilleurecolonne) || $sumfor[$i] > $meilleurecolonne) {
726  $meilleurecolonne = $sumfor[$i];
727  }
728  }
729 }
730 
731 if ($object->allow_spy) {
732  // Show line total
733  print '<tr>'."\n";
734  print '<td class="center">'.$langs->trans("Total").'</td>'."\n";
735  for ($i = 0; $i < $nbcolonnes; $i++) {
736  $showsumfor = isset($sumfor[$i]) ? $sumfor[$i] : '';
737  $showsumagainst = isset($sumagainst[$i]) ? $sumagainst[$i] : '';
738  if (empty($showsumfor)) {
739  $showsumfor = 0;
740  }
741  if (empty($showsumagainst)) {
742  $showsumagainst = 0;
743  }
744 
745  print '<td>';
746  if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst'))) {
747  print $showsumfor;
748  }
749  if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno') {
750  print $langs->trans("Yes").': '.$showsumfor.'<br>'.$langs->trans("No").': '.$showsumagainst;
751  }
752  if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst') {
753  print $langs->trans("For").': '.$showsumfor.'<br>'.$langs->trans("Against").': '.$showsumagainst;
754  }
755  print '</td>'."\n";
756  }
757  print '</tr>';
758  // Show picto winner
759  if ($nbofcheckbox >= 2) {
760  print '<tr>'."\n";
761  print '<td class="somme"></td>'."\n";
762  for ($i = 0; $i < $nbcolonnes; $i++) {
763  //print 'xx'.(!empty($listofanswers[$i]['format'])).'-'.$sumfor[$i].'-'.$meilleurecolonne;
764  if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst')) && isset($sumfor[$i]) && isset($meilleurecolonne) && $sumfor[$i] == $meilleurecolonne) {
765  print '<td class="somme"><img src="'.dol_buildpath('/opensurvey/img/medaille.png', 1).'"></td>'."\n";
766  } else {
767  print '<td class="somme"></td>'."\n";
768  }
769  }
770  print '</tr>'."\n";
771  }
772 }
773 print '</table>'."\n";
774 print '</div>'."\n";
775 
776 if ($object->allow_spy) {
777  $toutsujet = explode(",", $object->sujet);
778  $toutsujet = str_replace("°", "'", $toutsujet);
779 
780  $compteursujet = 0;
781  $meilleursujet = '';
782 
783  for ($i = 0; $i < $nbcolonnes; $i++) {
784  if (isset($sumfor[$i]) && isset($meilleurecolonne) && $sumfor[$i] == $meilleurecolonne) {
785  $meilleursujet .= ($meilleursujet ? ", " : "");
786  if ($object->format == "D") {
787  $meilleursujetexport = $toutsujet[$i];
788  if (strpos($toutsujet[$i], '@') !== false) {
789  $toutsujetdate = explode("@", $toutsujet[$i]);
790  $meilleursujet .= dol_print_date($toutsujetdate[0], 'daytext').' ('.dol_print_date($toutsujetdate[0], '%A').') - '.$toutsujetdate[1];
791  } else {
792  $meilleursujet .= dol_print_date((empty($toutsujet[$i]) ? 0 : $toutsujet[$i]), 'daytext').' ('.dol_print_date((empty($toutsujet[$i]) ? 0 : $toutsujet[$i]), '%A').')';
793  }
794  } else {
795  $tmps = explode('@', $toutsujet[$i]);
796  $meilleursujet .= dol_htmlentities($tmps[0]);
797  }
798 
799  $compteursujet++;
800  }
801  }
802 
803  $meilleursujet = substr("$meilleursujet", 1);
804  $meilleursujet = str_replace("°", "'", $meilleursujet);
805 
806  // Show best choice
807  if ($nbofcheckbox >= 2) {
808  $vote_str = $langs->trans('votes');
809  print '<p class="affichageresultats">'."\n";
810 
811  if (isset($meilleurecolonne) && $compteursujet == "1") {
812  print '<img src="'.dol_buildpath('/opensurvey/img/medaille.png', 1).'"> '.$langs->trans('TheBestChoice').": <b>".$meilleursujet."</b> ".$langs->trans('with')." <b>".$meilleurecolonne."</b>".$vote_str.".\n";
813  } elseif (isset($meilleurecolonne)) {
814  print '<img src="'.dol_buildpath('/opensurvey/img/medaille.png', 1).'"> '.$langs->trans('TheBestChoices').": <b>".$meilleursujet."</b> ".$langs->trans('with')." <b>".$meilleurecolonne."</b>".$vote_str.".\n";
815  }
816 
817  print '</p><br>'."\n";
818  }
819 }
820 
821 print '<br>';
822 
823 
824 // Comment list
825 $comments = $object->getComments();
826 
827 if ($comments) {
828  print '<br><u><span class="bold opacitymedium">'.$langs->trans("CommentsOfVoters").':</span></u><br>'."\n";
829 
830  foreach ($comments as $obj) {
831  // ligne d'un usager pré-authentifié
832  //$mod_ok = (in_array($obj->name, $listofvoters));
833 
834  print '<div class="comment"><span class="usercomment">';
835  if (in_array($obj->usercomment, $listofvoters)) {
836  print '<a href="'.$_SERVER["PHP_SELF"].'?deletecomment='.$obj->id_comment.'&sondage='.$numsondage.'"> '.img_picto('', 'delete.png', '', false, 0, 0, '', 'nomarginleft').'</a> ';
837  }
838  //else print img_picto('', 'ellipsis-h', '', false, 0, 0, '', 'nomarginleft').' ';
839  print dol_htmlentities($obj->usercomment).':</span> <span class="comment">'.dol_nl2br(dol_htmlentities($obj->comment))."</span></div>";
840  }
841 }
842 
843 // Form to add comment
844 if ($object->allow_comments && $currentusername) {
845  print '<br><div class="addcomment"><span class="opacitymedium">'.$langs->trans("AddACommentForPoll")."</span><br>\n";
846 
847  print '<textarea name="comment" rows="'.ROWS_2.'" class="quatrevingtpercent">'.dol_escape_htmltag(GETPOST('comment', 'alphanohtml'), 0, 1).'</textarea><br>'."\n";
848  print $langs->trans("Name").': ';
849  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";
850  print '<input type="submit" class="button smallpaddingimp" name="ajoutcomment" value="'.dol_escape_htmltag($langs->trans("AddComment")).'"><br>'."\n";
851  print '</form>'."\n";
852 
853  print '</div>'."\n"; // div add comment
854 }
855 
856 print '<br><br>';
857 
858 print '<a name="bas"></a>'."\n";
859 
860 llxFooterSurvey();
861 
862 $db->close();
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.
Definition: user.class.php:48
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition: date.lib.php:122
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
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...
httponly_accessforbidden($message=1, $http_response_code=403, $stringalreadysanitized=0)
Show a message to say access is forbidden and stop program.