dolibarr  17.0.4
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 $langs->trans("OpenSurveyHowTo").'<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 print '<div class="corps"> '."\n";
344 
345 // show title of survey
346 $titre = str_replace("\\", "", $object->title);
347 print '<strong>'.dol_htmlentities($titre).'</strong>';
348 
349 // show description of survey
350 if ($object->description) {
351  print '<br><br>'."\n";
352  print dol_htmlentitiesbr($object->description);
353  print '<br>'."\n";
354 }
355 
356 print '</div>'."\n";
357 
358 //The survey has expired, users can't vote or do any action
359 if (!$canbemodified) {
360  print '<br><center><div class="quatrevingtpercent center warning">'.$langs->trans('SurveyExpiredInfo').'</div></center>';
361  llxFooterSurvey();
362 
363  $db->close();
364  exit;
365 }
366 
367 print '<div class="cadre"> '."\n";
368 print '<br><br>'."\n";
369 
370 // Start to show survey result
371 print '<table class="resultats">'."\n";
372 
373 // Show choice titles
374 if ($object->format == "D") {
375  //display of survey topics
376  print '<tr>'."\n";
377  print '<td></td>'."\n";
378 
379  //display of years
380  $colspan = 1;
381  $nbofsujet = count($toutsujet);
382  for ($i = 0; $i < $nbofsujet; $i++) {
383  if (isset($toutsujet[$i + 1]) && date('Y', intval($toutsujet[$i])) == date('Y', intval($toutsujet[$i + 1]))) {
384  $colspan++;
385  } else {
386  print '<td colspan='.$colspan.' class="annee">'.date('Y', intval($toutsujet[$i])).'</td>'."\n";
387  $colspan = 1;
388  }
389  }
390 
391  print '</tr>'."\n";
392  print '<tr>'."\n";
393  print '<td></td>'."\n";
394 
395  //display of months
396  $colspan = 1;
397  for ($i = 0; $i < $nbofsujet; $i++) {
398  $cur = intval($toutsujet[$i]); // intval() est utiliser pour supprimer le suffixe @* qui déplaît logiquement à strftime()
399 
400  if (isset($toutsujet[$i + 1]) === false) {
401  $next = false;
402  } else {
403  $next = intval($toutsujet[$i + 1]);
404  }
405 
406  if ($next && dol_print_date($cur, "%B") == dol_print_date($next, "%B") && dol_print_date($cur, "%Y") == dol_print_date($next, "%Y")) {
407  $colspan++;
408  } else {
409  print '<td colspan='.$colspan.' class="mois">'.dol_print_date($cur, "%B").'</td>'."\n";
410  $colspan = 1;
411  }
412  }
413 
414  print '</tr>'."\n";
415  print '<tr>'."\n";
416  print '<td></td>'."\n";
417 
418  //display of days
419  $colspan = 1;
420  for ($i = 0; $i < $nbofsujet; $i++) {
421  $cur = intval($toutsujet[$i]);
422  if (isset($toutsujet[$i + 1]) === false) {
423  $next = false;
424  } else {
425  $next = intval($toutsujet[$i + 1]);
426  }
427  if ($next && dol_print_date($cur, "%a %d") == dol_print_date($next, "%a %d") && dol_print_date($cur, "%B") == dol_print_date($next, "%B")) {
428  $colspan++;
429  } else {
430  print '<td colspan="'.$colspan.'" class="jour">'.dol_print_date($cur, "%a %d").'</td>'."\n";
431  $colspan = 1;
432  }
433  }
434 
435  print '</tr>'."\n";
436 
437  //Display schedules
438  if (strpos($object->sujet, '@') !== false) {
439  print '<tr>'."\n";
440  print '<td></td>'."\n";
441 
442  for ($i = 0; isset($toutsujet[$i]); $i++) {
443  $heures = explode('@', $toutsujet[$i]);
444  if (isset($heures[1])) {
445  print '<td class="heure">'.dol_htmlentities($heures[1]).'</td>'."\n";
446  } else {
447  print '<td class="heure"></td>'."\n";
448  }
449  }
450 
451  print '</tr>'."\n";
452  }
453 } else {
454  //display of survey topics
455  print '<tr>'."\n";
456  print '<td></td>'."\n";
457 
458  for ($i = 0; isset($toutsujet[$i]); $i++) {
459  $tmp = explode('@', $toutsujet[$i]);
460  print '<td class="sujet">'.dol_escape_htmltag($tmp[0]).'</td>'."\n";
461  }
462 
463  print '</tr>'."\n";
464 }
465 
466 
467 // Loop on each answer
468 $sumfor = array();
469 $sumagainst = array();
470 $compteur = 0;
471 $sql = "SELECT id_users, nom as name, id_sondage, reponses";
472 $sql .= " FROM ".MAIN_DB_PREFIX."opensurvey_user_studs";
473 $sql .= " WHERE id_sondage = '".$db->escape($numsondage)."'";
474 $resql = $db->query($sql);
475 if (!$resql) {
476  dol_print_error($db);
477  exit;
478 }
479 $num = $db->num_rows($resql);
480 while ($compteur < $num) {
481  $obj = $db->fetch_object($resql);
482 
483  $ensemblereponses = $obj->reponses;
484 
485  // ligne d'un usager pré-authentifié
486  $mod_ok = (in_array($obj->name, $listofvoters));
487 
488  if (!$mod_ok && !$object->allow_spy) {
489  $compteur++;
490  continue;
491  }
492 
493  print '<tr>'."\n";
494 
495  // Name
496  print '<td class="nom">'.dol_htmlentities($obj->name).'</td>'."\n";
497 
498  // si la ligne n'est pas a changer, on affiche les données
499  if (!$testligneamodifier) {
500  for ($i = 0; $i < $nbcolonnes; $i++) {
501  $car = substr($ensemblereponses, $i, 1);
502  //print 'xx'.$i."-".$car.'-'.$listofanswers[$i]['format'].'zz';
503 
504  if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst'))) {
505  if (((string) $car) == "1") {
506  print '<td class="ok">OK</td>'."\n";
507  } else {
508  print '<td class="non">KO</td>'."\n";
509  }
510  // Total
511  if (!isset($sumfor[$i])) {
512  $sumfor[$i] = 0;
513  }
514  if (((string) $car) == "1") {
515  $sumfor[$i]++;
516  }
517  }
518  if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno') {
519  if (((string) $car) == "1") {
520  print '<td class="ok">'.$langs->trans("Yes").'</td>'."\n";
521  } elseif (((string) $car) == "0") {
522  print '<td class="non">'.$langs->trans("No").'</td>'."\n";
523  } else {
524  print '<td class="vide">&nbsp;</td>'."\n";
525  }
526  // Total
527  if (!isset($sumfor[$i])) {
528  $sumfor[$i] = 0;
529  }
530  if (!isset($sumagainst[$i])) {
531  $sumagainst[$i] = 0;
532  }
533  if (((string) $car) == "1") {
534  $sumfor[$i]++;
535  }
536  if (((string) $car) == "0") {
537  $sumagainst[$i]++;
538  }
539  }
540  if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst') {
541  if (((string) $car) == "1") {
542  print '<td class="ok">'.$langs->trans("For").'</td>'."\n";
543  } elseif (((string) $car) == "0") {
544  print '<td class="non">'.$langs->trans("Against").'</td>'."\n";
545  } else {
546  print '<td class="vide">&nbsp;</td>'."\n";
547  }
548  // Total
549  if (!isset($sumfor[$i])) {
550  $sumfor[$i] = 0;
551  }
552  if (!isset($sumagainst[$i])) {
553  $sumagainst[$i] = 0;
554  }
555  if (((string) $car) == "1") {
556  $sumfor[$i]++;
557  }
558  if (((string) $car) == "0") {
559  $sumagainst[$i]++;
560  }
561  }
562  }
563  } else {
564  //sinon on remplace les choix de l'utilisateur par une ligne de checkbox pour recuperer de nouvelles valeurs
565  if ($compteur == $ligneamodifier) {
566  for ($i = 0; $i < $nbcolonnes; $i++) {
567  $car = substr($ensemblereponses, $i, 1);
568  print '<td class="vide">';
569  if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst'))) {
570  print '<input type="checkbox" name="choix'.$i.'" value="1" ';
571  if ($car == '1') {
572  print 'checked';
573  }
574  print '>';
575  }
576  if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno') {
577  $arraychoice = array('2'=>'&nbsp;', '0'=>$langs->trans("No"), '1'=>$langs->trans("Yes"));
578  print $form->selectarray("choix".$i, $arraychoice, $car);
579  }
580  if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst') {
581  $arraychoice = array('2'=>'&nbsp;', '0'=>$langs->trans("Against"), '1'=>$langs->trans("For"));
582  print $form->selectarray("choix".$i, $arraychoice, $car);
583  }
584  print '</td>'."\n";
585  }
586  } else {
587  for ($i = 0; $i < $nbcolonnes; $i++) {
588  $car = substr($ensemblereponses, $i, 1);
589  if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst'))) {
590  if (((string) $car) == "1") {
591  print '<td class="ok">OK</td>'."\n";
592  } else {
593  print '<td class="non">KO</td>'."\n";
594  }
595  // Total
596  if (!isset($sumfor[$i])) {
597  $sumfor[$i] = 0;
598  }
599  if (((string) $car) == "1") {
600  $sumfor[$i]++;
601  }
602  }
603  if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno') {
604  if (((string) $car) == "1") {
605  print '<td class="ok">'.$langs->trans("For").'</td>'."\n";
606  } elseif (((string) $car) == "0") {
607  print '<td class="non">'.$langs->trans("Against").'</td>'."\n";
608  } else {
609  print '<td class="vide">&nbsp;</td>'."\n";
610  }
611  // Total
612  if (!isset($sumfor[$i])) {
613  $sumfor[$i] = 0;
614  }
615  if (!isset($sumagainst[$i])) {
616  $sumagainst[$i] = 0;
617  }
618  if (((string) $car) == "1") {
619  $sumfor[$i]++;
620  }
621  if (((string) $car) == "0") {
622  $sumagainst[$i]++;
623  }
624  }
625  if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst') {
626  if (((string) $car) == "1") {
627  print '<td class="ok">'.$langs->trans("For").'</td>'."\n";
628  } elseif (((string) $car) == "0") {
629  print '<td class="non">'.$langs->trans("Against").'</td>'."\n";
630  } else {
631  print '<td class="vide">&nbsp;</td>'."\n";
632  }
633  // Total
634  if (!isset($sumfor[$i])) {
635  $sumfor[$i] = 0;
636  }
637  if (!isset($sumagainst[$i])) {
638  $sumagainst[$i] = 0;
639  }
640  if (((string) $car) == "1") {
641  $sumfor[$i]++;
642  }
643  if (((string) $car) == "0") {
644  $sumagainst[$i]++;
645  }
646  }
647  }
648  }
649  }
650 
651  // Button edit at end of line
652  if ($compteur != $ligneamodifier && $mod_ok) {
653  print '<td class="casevide"><input type="submit" class="button smallpaddingimp" name="modifierligne'.$compteur.'" value="'.dol_escape_htmltag($langs->trans("Edit")).'"></td>'."\n";
654  }
655 
656  //demande de confirmation pour modification de ligne
657  for ($i = 0; $i < $nblines; $i++) {
658  if (GETPOSTISSET("modifierligne".$i)) {
659  if ($compteur == $i) {
660  print '<td class="casevide">';
661  print '<input type="hidden" name="idtomodify'.$compteur.'" value="'.$obj->id_users.'">';
662  print '<input type="submit" class="button button-save" name="validermodifier'.$compteur.'" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
663  print '</td>'."\n";
664  }
665  }
666  }
667 
668  $compteur++;
669  print '</tr>'."\n";
670 }
671 
672 // Add line to add new record
673 if ($ligneamodifier < 0 && (!isset($_SESSION['nom']))) {
674  print '<tr>'."\n";
675  print '<td class="nom">'."\n";
676  if (isset($_SESSION['nom'])) {
677  print '<input type=hidden name="nom" value="'.$_SESSION['nom'].'">'.$_SESSION['nom']."\n";
678  } else {
679  print '<input type="text" name="nom" placeholder="'.dol_escape_htmltag($langs->trans("Name")).'" maxlength="64" class=" minwidth175">'."\n";
680  }
681  print '</td>'."\n";
682 
683  // affichage des cases de formulaire checkbox pour un nouveau choix
684  for ($i = 0; $i < $nbcolonnes; $i++) {
685  print '<td class="vide">';
686  if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst'))) {
687  print '<input type="checkbox" name="choix'.$i.'" value="1"';
688  if (GETPOSTISSET('choix'.$i) && GETPOST('choix'.$i) == '1') {
689  print ' checked';
690  }
691  print '>';
692  }
693  if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno') {
694  $arraychoice = array('2'=>'&nbsp;', '0'=>$langs->trans("No"), '1'=>$langs->trans("Yes"));
695  print $form->selectarray("choix".$i, $arraychoice, GETPOST('choix'.$i));
696  }
697  if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst') {
698  $arraychoice = array('2'=>'&nbsp;', '0'=>$langs->trans("Against"), '1'=>$langs->trans("For"));
699  print $form->selectarray("choix".$i, $arraychoice, GETPOST('choix'.$i));
700  }
701  print '</td>'."\n";
702  }
703 
704  // Affichage du bouton de formulaire pour inscrire un nouvel utilisateur dans la base
705  print '<td><input type="image" class="borderimp" name="boutonp" value="'.$langs->trans("Vote").'" src="'.img_picto('', 'edit_add', '', false, 1).'"></td>'."\n";
706  print '</tr>'."\n";
707 }
708 
709 // Select value of best choice (for checkbox columns only)
710 $nbofcheckbox = 0;
711 for ($i = 0; $i < $nbcolonnes; $i++) {
712  if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst'))) {
713  $nbofcheckbox++;
714  }
715  if (isset($sumfor[$i])) {
716  if ($i == 0) {
717  $meilleurecolonne = $sumfor[$i];
718  }
719  if (!isset($meilleurecolonne) || $sumfor[$i] > $meilleurecolonne) {
720  $meilleurecolonne = $sumfor[$i];
721  }
722  }
723 }
724 
725 if ($object->allow_spy) {
726  // Show line total
727  print '<tr>'."\n";
728  print '<td class="center">'.$langs->trans("Total").'</td>'."\n";
729  for ($i = 0; $i < $nbcolonnes; $i++) {
730  $showsumfor = isset($sumfor[$i]) ? $sumfor[$i] : '';
731  $showsumagainst = isset($sumagainst[$i]) ? $sumagainst[$i] : '';
732  if (empty($showsumfor)) {
733  $showsumfor = 0;
734  }
735  if (empty($showsumagainst)) {
736  $showsumagainst = 0;
737  }
738 
739  print '<td>';
740  if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst'))) {
741  print $showsumfor;
742  }
743  if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno') {
744  print $langs->trans("Yes").': '.$showsumfor.'<br>'.$langs->trans("No").': '.$showsumagainst;
745  }
746  if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst') {
747  print $langs->trans("For").': '.$showsumfor.'<br>'.$langs->trans("Against").': '.$showsumagainst;
748  }
749  print '</td>'."\n";
750  }
751  print '</tr>';
752  // Show picto winner
753  if ($nbofcheckbox >= 2) {
754  print '<tr>'."\n";
755  print '<td class="somme"></td>'."\n";
756  for ($i = 0; $i < $nbcolonnes; $i++) {
757  //print 'xx'.(!empty($listofanswers[$i]['format'])).'-'.$sumfor[$i].'-'.$meilleurecolonne;
758  if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst')) && isset($sumfor[$i]) && isset($meilleurecolonne) && $sumfor[$i] == $meilleurecolonne) {
759  print '<td class="somme"><img src="'.dol_buildpath('/opensurvey/img/medaille.png', 1).'"></td>'."\n";
760  } else {
761  print '<td class="somme"></td>'."\n";
762  }
763  }
764  print '</tr>'."\n";
765  }
766 }
767 print '</table>'."\n";
768 print '</div>'."\n";
769 
770 if ($object->allow_spy) {
771  $toutsujet = explode(",", $object->sujet);
772  $toutsujet = str_replace("°", "'", $toutsujet);
773 
774  $compteursujet = 0;
775  $meilleursujet = '';
776 
777  for ($i = 0; $i < $nbcolonnes; $i++) {
778  if (isset($sumfor[$i]) && isset($meilleurecolonne) && $sumfor[$i] == $meilleurecolonne) {
779  $meilleursujet .= ($meilleursujet ? ", " : "");
780  if ($object->format == "D") {
781  $meilleursujetexport = $toutsujet[$i];
782  if (strpos($toutsujet[$i], '@') !== false) {
783  $toutsujetdate = explode("@", $toutsujet[$i]);
784  $meilleursujet .= dol_print_date($toutsujetdate[0], 'daytext').' ('.dol_print_date($toutsujetdate[0], '%A').') - '.$toutsujetdate[1];
785  } else {
786  $meilleursujet .= dol_print_date((empty($toutsujet[$i]) ? 0 : $toutsujet[$i]), 'daytext').' ('.dol_print_date((empty($toutsujet[$i]) ? 0 : $toutsujet[$i]), '%A').')';
787  }
788  } else {
789  $tmps = explode('@', $toutsujet[$i]);
790  $meilleursujet .= dol_htmlentities($tmps[0]);
791  }
792 
793  $compteursujet++;
794  }
795  }
796 
797  $meilleursujet = substr("$meilleursujet", 1);
798  $meilleursujet = str_replace("°", "'", $meilleursujet);
799 
800  // Show best choice
801  if ($nbofcheckbox >= 2) {
802  $vote_str = $langs->trans('votes');
803  print '<p class="affichageresultats">'."\n";
804 
805  if (isset($meilleurecolonne) && $compteursujet == "1") {
806  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";
807  } elseif (isset($meilleurecolonne)) {
808  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";
809  }
810 
811  print '</p><br>'."\n";
812  }
813 }
814 
815 print '<br>';
816 
817 
818 // Comment list
819 $comments = $object->getComments();
820 
821 if ($comments) {
822  print '<br><u><span class="bold opacitymedium">'.$langs->trans("CommentsOfVoters").':</span></u><br>'."\n";
823 
824  foreach ($comments as $obj) {
825  // ligne d'un usager pré-authentifié
826  //$mod_ok = (in_array($obj->name, $listofvoters));
827 
828  print '<div class="comment"><span class="usercomment">';
829  if (in_array($obj->usercomment, $listofvoters)) {
830  print '<a href="'.$_SERVER["PHP_SELF"].'?deletecomment='.$obj->id_comment.'&sondage='.$numsondage.'"> '.img_picto('', 'delete.png', '', false, 0, 0, '', 'nomarginleft').'</a> ';
831  }
832  //else print img_picto('', 'ellipsis-h', '', false, 0, 0, '', 'nomarginleft').' ';
833  print dol_htmlentities($obj->usercomment).':</span> <span class="comment">'.dol_nl2br(dol_htmlentities($obj->comment))."</span></div>";
834  }
835 }
836 
837 // Form to add comment
838 if ($object->allow_comments) {
839  print '<br><div class="addcomment"><span class="opacitymedium">'.$langs->trans("AddACommentForPoll")."</span><br>\n";
840 
841  print '<textarea name="comment" rows="'.ROWS_2.'" class="quatrevingtpercent">'.dol_escape_htmltag(GETPOST('comment', 'alphanohtml'), 0, 1).'</textarea><br>'."\n";
842  print $langs->trans("Name").': ';
843  print '<input type="text" name="commentuser" maxlength="64" value="'.dol_escape_htmltag(GETPOST('commentuser', 'alphanohtml')).'"> &nbsp; '."\n";
844  print '<input type="submit" class="button" name="ajoutcomment" value="'.dol_escape_htmltag($langs->trans("AddComment")).'"><br>'."\n";
845  print '</form>'."\n";
846 
847  print '</div>'."\n"; // div add comment
848 }
849 
850 print '<br><br>';
851 
852 print '<a name="bas"></a>'."\n";
853 
854 llxFooterSurvey();
855 
856 $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:47
if(isModEnabled('facture') &&!empty($user->rights->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') &&!empty($user->rights->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)) $resql
Social contributions to pay.
Definition: index.php:745
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:121
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
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.
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.
httponly_accessforbidden($message=1, $http_response_code=403, $stringalreadysanitized=0)
Show a message to say access is forbidden and stop program.