dolibarr  13.0.2
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')) define("NOLOGIN", 1); // This means this output page does not require to be logged.
26 if (!defined('NOCSRFCHECK')) define("NOCSRFCHECK", 1); // We accept to go on this page from external web site.
27 if (!defined('NOBROWSERNOTIF')) define('NOBROWSERNOTIF', '1');
28 if (!defined('NOIPCHECK')) define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
29 
30 require '../../main.inc.php';
31 require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
32 require_once DOL_DOCUMENT_ROOT."/core/lib/files.lib.php";
33 require_once DOL_DOCUMENT_ROOT."/opensurvey/class/opensurveysondage.class.php";
34 require_once DOL_DOCUMENT_ROOT."/opensurvey/fonctions.php";
35 
36 
37 // Init vars
38 $action = GETPOST('action', 'aZ09');
39 $numsondage = '';
40 if (GETPOST('sondage'))
41 {
42  $numsondage = GETPOST('sondage', 'alpha');
43 }
44 
45 $object = new Opensurveysondage($db);
46 $result = $object->fetch(0, $numsondage);
47 
48 $nblines = $object->fetch_lines();
49 
50 //If the survey has not yet finished, then it can be modified
51 $canbemodified = ((empty($object->date_fin) || $object->date_fin > dol_now()) && $object->status != Opensurveysondage::STATUS_CLOSED);
52 
53 // Security check
54 if (empty($conf->opensurvey->enabled)) accessforbidden('', 0, 0, 1);
55 
56 
57 /*
58  * Actions
59  */
60 
61 $nbcolonnes = substr_count($object->sujet, ',') + 1;
62 
63 $listofvoters = explode(',', $_SESSION["savevoter"]);
64 
65 // Add comment
66 if (GETPOST('ajoutcomment', 'alpha'))
67 {
68  if (!$canbemodified) accessforbidden('', 0, 0, 1);
69 
70  $error = 0;
71 
72  $comment = GETPOST("comment", 'restricthtml');
73  $comment_user = GETPOST('commentuser', 'nohtml');
74 
75  if (!$comment)
76  {
77  $error++;
78  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Comment")), null, 'errors');
79  }
80  if (!$comment_user)
81  {
82  $error++;
83  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Name")), null, 'errors');
84  }
85 
86  if (!in_array($comment_user, $listofvoters))
87  {
88  setEventMessages($langs->trans("UserMustBeSameThanUserUsedToVote"), null, 'errors');
89  $error++;
90  }
91 
92  if (!$error)
93  {
94  $resql = $object->addComment($comment, $comment_user);
95 
96  if (!$resql) dol_print_error($db);
97  }
98 }
99 
100 // Add vote
101 if (GETPOST("boutonp") || GETPOST("boutonp.x") || GETPOST("boutonp_x")) // boutonp for chrome, boutonp_x for firefox
102 {
103  if (!$canbemodified) accessforbidden('', 0, 0, 1);
104 
105  //Si le nom est bien entré
106  if (GETPOST('nom', 'nohtml'))
107  {
108  $nouveauchoix = '';
109  for ($i = 0; $i < $nbcolonnes; $i++)
110  {
111  if (GETPOSTISSET("choix$i") && GETPOST("choix$i") == '1') {
112  $nouveauchoix .= "1";
113  } elseif (GETPOSTISSET("choix$i") && GETPOST("choix$i") == '2') {
114  $nouveauchoix .= "2";
115  } else {
116  $nouveauchoix .= "0";
117  }
118  }
119 
120  $nom = substr(GETPOST("nom", 'nohtml'), 0, 64);
121 
122  // Check if vote already exists
123  $sql = 'SELECT id_users, nom as name';
124  $sql .= ' FROM '.MAIN_DB_PREFIX.'opensurvey_user_studs';
125  $sql .= " WHERE id_sondage='".$db->escape($numsondage)."' AND nom = '".$db->escape($nom)."' ORDER BY id_users";
126  $resql = $db->query($sql);
127  if (!$resql) dol_print_error($db);
128 
129  $num_rows = $db->num_rows($resql);
130  if ($num_rows > 0)
131  {
132  setEventMessages($langs->trans("VoteNameAlreadyExists"), null, 'errors');
133  $error++;
134  } else {
135  $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'opensurvey_user_studs (nom, id_sondage, reponses)';
136  $sql .= " VALUES ('".$db->escape($nom)."', '".$db->escape($numsondage)."','".$db->escape($nouveauchoix)."')";
137  $resql = $db->query($sql);
138 
139  if ($resql)
140  {
141  // Add voter to session
142  $_SESSION["savevoter"] = $nom.','.(empty($_SESSION["savevoter"]) ? '' : $_SESSION["savevoter"]); // Save voter
143  $listofvoters = explode(',', $_SESSION["savevoter"]);
144 
145  if ($object->mailsonde)
146  {
147  if ($object->fk_user_creat) {
148  $userstatic = new User($db);
149  $userstatic->fetch($object->fk_user_creat);
150 
151  $email = $userstatic->email;
152  } else {
153  $email = $object->mail_admin;
154  }
155 
156  //Linked user may not have an email set
157  if ($email) {
158  include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
159 
160  $application = ($conf->global->MAIN_APPLICATION_TITLE ? $conf->global->MAIN_APPLICATION_TITLE : 'Dolibarr ERP/CRM');
161 
162  $body = str_replace('\n', '<br>', $langs->transnoentities('EmailSomeoneVoted', $nom, getUrlSondage($numsondage, true)));
163  //var_dump($body);exit;
164 
165  $cmailfile = new CMailFile("[".$application."] ".$langs->trans("Poll").': '.$object->title, $email, $conf->global->MAIN_MAIL_EMAIL_FROM, $body, null, null, null, '', '', 0, -1);
166  $result = $cmailfile->sendfile();
167  }
168  }
169  } else dol_print_error($db);
170  }
171  } else {
172  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Name")), null, 'errors');
173  }
174 }
175 
176 
177 // Update vote
178 $testmodifier = false;
179 $testligneamodifier = false;
180 $ligneamodifier = -1;
181 for ($i = 0; $i < $nblines; $i++)
182 {
183  if (GETPOSTISSET('modifierligne'.$i))
184  {
185  $ligneamodifier = $i;
186  $testligneamodifier = true;
187  }
188 
189  //test to see if a line is to be modified
190  if (GETPOSTISSET('validermodifier'.$i))
191  {
192  $modifier = $i;
193  $testmodifier = true;
194  }
195 }
196 
197 if ($testmodifier)
198 {
199  //var_dump($_POST);exit;
200  $nouveauchoix = '';
201  for ($i = 0; $i < $nbcolonnes; $i++)
202  {
203  //var_dump($_POST["choix$i"]);
204  if (GETPOSTISSET("choix".$i) && GETPOST("choix".$i) == '1') {
205  $nouveauchoix .= "1";
206  } elseif (GETPOSTISSET("choix".$i) && GETPOST("choix".$i) == '2') {
207  $nouveauchoix .= "2";
208  } else {
209  $nouveauchoix .= "0";
210  }
211  }
212 
213  if (!$canbemodified) accessforbidden('', 0, 0, 1);
214 
215  $idtomodify = $_POST["idtomodify".$modifier];
216  $sql = 'UPDATE '.MAIN_DB_PREFIX."opensurvey_user_studs";
217  $sql .= " SET reponses = '".$db->escape($nouveauchoix)."'";
218  $sql .= " WHERE id_users = '".$db->escape($idtomodify)."'";
219 
220  $resql = $db->query($sql);
221  if (!$resql) dol_print_error($db);
222 }
223 
224 // Delete comment
225 $idcomment = GETPOST('deletecomment', 'int');
226 if ($idcomment)
227 {
228  if (!$canbemodified) accessforbidden('', 0, 0, 1);
229 
230  $resql = $object->deleteComment($idcomment);
231 }
232 
233 
234 
235 /*
236  * View
237  */
238 
239 $form = new Form($db);
240 
241 $arrayofjs = array();
242 $arrayofcss = array('/opensurvey/css/style.css');
243 
244 llxHeaderSurvey($object->title, "", 0, 0, $arrayofjs, $arrayofcss, $numsondage);
245 
246 if (empty($object->ref)) // For survey, id is a hex string
247 {
248  $langs->load("errors");
249  print $langs->trans("ErrorRecordNotFound");
250 
251  llxFooterSurvey();
252 
253  $db->close();
254  exit();
255 }
256 
257 // Define format of choices
258 $toutsujet = explode(",", $object->sujet);
259 $listofanswers = array();
260 foreach ($toutsujet as $value)
261 {
262  $tmp = explode('@', $value);
263  $listofanswers[] = array('label'=>$tmp[0], 'format'=>($tmp[1] ? $tmp[1] : 'checkbox'));
264 }
265 $toutsujet = str_replace("°", "'", $toutsujet);
266 
267 
268 
269 print '<div class="survey_invitation">'.$langs->trans("YouAreInivitedToVote").'</div>';
270 print $langs->trans("OpenSurveyHowTo").'<br><br>';
271 
272 print '<div class="corps"> '."\n";
273 
274 // show title of survey
275 $titre = str_replace("\\", "", $object->title);
276 print '<strong>'.dol_htmlentities($titre).'</strong><br><br>'."\n";
277 
278 // show description of survey
279 if ($object->description)
280 {
281  print dol_htmlentitiesbr($object->description);
282  print '<br>'."\n";
283 }
284 
285 print '</div>'."\n";
286 
287 //The survey has expired, users can't vote or do any action
288 if (!$canbemodified) {
289  print '<div style="text-align: center"><p>'.$langs->trans('SurveyExpiredInfo').'</p></div>';
290  llxFooterSurvey();
291 
292  $db->close();
293  exit;
294 }
295 
296 print '<div class="cadre"> '."\n";
297 print '<br><br>'."\n";
298 
299 // Start to show survey result
300 print '<table class="resultats">'."\n";
301 
302 // Show choice titles
303 if ($object->format == "D")
304 {
305  //display of survey topics
306  print '<tr>'."\n";
307  print '<td></td>'."\n";
308 
309  //display of years
310  $colspan = 1;
311  $nbofsujet = count($toutsujet);
312  for ($i = 0; $i < $nbofsujet; $i++)
313  {
314  if (isset($toutsujet[$i + 1]) && date('Y', intval($toutsujet[$i])) == date('Y', intval($toutsujet[$i + 1]))) {
315  $colspan++;
316  } else {
317  print '<td colspan='.$colspan.' class="annee">'.date('Y', intval($toutsujet[$i])).'</td>'."\n";
318  $colspan = 1;
319  }
320  }
321 
322  print '</tr>'."\n";
323  print '<tr>'."\n";
324  print '<td></td>'."\n";
325 
326  //display of months
327  $colspan = 1;
328  for ($i = 0; $i < $nbofsujet; $i++) {
329  $cur = intval($toutsujet[$i]); // intval() est utiliser pour supprimer le suffixe @* qui déplaît logiquement à strftime()
330 
331  if (isset($toutsujet[$i + 1]) === false) {
332  $next = false;
333  } else {
334  $next = intval($toutsujet[$i + 1]);
335  }
336 
337  if ($next && dol_print_date($cur, "%B") == dol_print_date($next, "%B") && dol_print_date($cur, "%Y") == dol_print_date($next, "%Y")) {
338  $colspan++;
339  } else {
340  print '<td colspan='.$colspan.' class="mois">'.dol_print_date($cur, "%B").'</td>'."\n";
341  $colspan = 1;
342  }
343  }
344 
345  print '</tr>'."\n";
346  print '<tr>'."\n";
347  print '<td></td>'."\n";
348 
349  //display of days
350  $colspan = 1;
351  for ($i = 0; $i < $nbofsujet; $i++) {
352  $cur = intval($toutsujet[$i]);
353  if (isset($toutsujet[$i + 1]) === false) {
354  $next = false;
355  } else {
356  $next = intval($toutsujet[$i + 1]);
357  }
358  if ($next && dol_print_date($cur, "%a %e") == dol_print_date($next, "%a %e") && dol_print_date($cur, "%B") == dol_print_date($next, "%B")) {
359  $colspan++;
360  } else {
361  print '<td colspan="'.$colspan.'" class="jour">'.dol_print_date($cur, "%a %e").'</td>'."\n";
362  $colspan = 1;
363  }
364  }
365 
366  print '</tr>'."\n";
367 
368  //Display schedules
369  if (strpos($object->sujet, '@') !== false) {
370  print '<tr>'."\n";
371  print '<td></td>'."\n";
372 
373  for ($i = 0; isset($toutsujet[$i]); $i++) {
374  $heures = explode('@', $toutsujet[$i]);
375  if (isset($heures[1])) {
376  print '<td class="heure">'.dol_htmlentities($heures[1]).'</td>'."\n";
377  } else {
378  print '<td class="heure"></td>'."\n";
379  }
380  }
381 
382  print '</tr>'."\n";
383  }
384 } else {
385  //display of survey topics
386  print '<tr>'."\n";
387  print '<td></td>'."\n";
388 
389  for ($i = 0; isset($toutsujet[$i]); $i++)
390  {
391  $tmp = explode('@', $toutsujet[$i]);
392  print '<td class="sujet">'.dol_escape_htmltag($tmp[0]).'</td>'."\n";
393  }
394 
395  print '</tr>'."\n";
396 }
397 
398 
399 // Loop on each answer
400 $sumfor = array();
401 $sumagainst = array();
402 $compteur = 0;
403 $sql = "SELECT id_users, nom as name, id_sondage, reponses";
404 $sql .= " FROM ".MAIN_DB_PREFIX."opensurvey_user_studs";
405 $sql .= " WHERE id_sondage = '".$db->escape($numsondage)."'";
406 $resql = $db->query($sql);
407 if (!$resql)
408 {
409  dol_print_error($db);
410  exit;
411 }
412 $num = $db->num_rows($resql);
413 while ($compteur < $num)
414 {
415  $obj = $db->fetch_object($resql);
416 
417  $ensemblereponses = $obj->reponses;
418 
419  // ligne d'un usager pré-authentifié
420  $mod_ok = (in_array($obj->name, $listofvoters));
421 
422  if (!$mod_ok && !$object->allow_spy) {
423  $compteur++;
424  continue;
425  }
426 
427  print '<tr>'."\n";
428 
429  // Name
430  print '<td class="nom">'.dol_htmlentities($obj->name).'</td>'."\n";
431 
432  // si la ligne n'est pas a changer, on affiche les données
433  if (!$testligneamodifier)
434  {
435  for ($i = 0; $i < $nbcolonnes; $i++)
436  {
437  $car = substr($ensemblereponses, $i, 1);
438  //print 'xx'.$i."-".$car.'-'.$listofanswers[$i]['format'].'zz';
439 
440  if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst')))
441  {
442  if (((string) $car) == "1") print '<td class="ok">OK</td>'."\n";
443  else print '<td class="non">KO</td>'."\n";
444  // Total
445  if (!isset($sumfor[$i])) $sumfor[$i] = 0;
446  if (((string) $car) == "1") $sumfor[$i]++;
447  }
448  if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno')
449  {
450  if (((string) $car) == "1") print '<td class="ok">'.$langs->trans("Yes").'</td>'."\n";
451  elseif (((string) $car) == "0") print '<td class="non">'.$langs->trans("No").'</td>'."\n";
452  else print '<td class="vide">&nbsp;</td>'."\n";
453  // Total
454  if (!isset($sumfor[$i])) $sumfor[$i] = 0;
455  if (!isset($sumagainst[$i])) $sumagainst[$i] = 0;
456  if (((string) $car) == "1") $sumfor[$i]++;
457  if (((string) $car) == "0") $sumagainst[$i]++;
458  }
459  if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst')
460  {
461  if (((string) $car) == "1") print '<td class="ok">'.$langs->trans("For").'</td>'."\n";
462  elseif (((string) $car) == "0") print '<td class="non">'.$langs->trans("Against").'</td>'."\n";
463  else print '<td class="vide">&nbsp;</td>'."\n";
464  // Total
465  if (!isset($sumfor[$i])) $sumfor[$i] = 0;
466  if (!isset($sumagainst[$i])) $sumagainst[$i] = 0;
467  if (((string) $car) == "1") $sumfor[$i]++;
468  if (((string) $car) == "0") $sumagainst[$i]++;
469  }
470  }
471  } else {
472  //sinon on remplace les choix de l'utilisateur par une ligne de checkbox pour recuperer de nouvelles valeurs
473  if ($compteur == $ligneamodifier)
474  {
475  for ($i = 0; $i < $nbcolonnes; $i++)
476  {
477  $car = substr($ensemblereponses, $i, 1);
478  print '<td class="vide">';
479  if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst')))
480  {
481  print '<input type="checkbox" name="choix'.$i.'" value="1" ';
482  if ($car == '1') print 'checked';
483  print '>';
484  }
485  if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno')
486  {
487  $arraychoice = array('2'=>'&nbsp;', '0'=>$langs->trans("No"), '1'=>$langs->trans("Yes"));
488  print $form->selectarray("choix".$i, $arraychoice, $car);
489  }
490  if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst')
491  {
492  $arraychoice = array('2'=>'&nbsp;', '0'=>$langs->trans("Against"), '1'=>$langs->trans("For"));
493  print $form->selectarray("choix".$i, $arraychoice, $car);
494  }
495  print '</td>'."\n";
496  }
497  } else {
498  for ($i = 0; $i < $nbcolonnes; $i++)
499  {
500  $car = substr($ensemblereponses, $i, 1);
501  if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst')))
502  {
503  if (((string) $car) == "1") print '<td class="ok">OK</td>'."\n";
504  else print '<td class="non">KO</td>'."\n";
505  // Total
506  if (!isset($sumfor[$i])) $sumfor[$i] = 0;
507  if (((string) $car) == "1") $sumfor[$i]++;
508  }
509  if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno')
510  {
511  if (((string) $car) == "1") print '<td class="ok">'.$langs->trans("For").'</td>'."\n";
512  elseif (((string) $car) == "0") print '<td class="non">'.$langs->trans("Against").'</td>'."\n";
513  else print '<td class="vide">&nbsp;</td>'."\n";
514  // Total
515  if (!isset($sumfor[$i])) $sumfor[$i] = 0;
516  if (!isset($sumagainst[$i])) $sumagainst[$i] = 0;
517  if (((string) $car) == "1") $sumfor[$i]++;
518  if (((string) $car) == "0") $sumagainst[$i]++;
519  }
520  if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst')
521  {
522  if (((string) $car) == "1") print '<td class="ok">'.$langs->trans("For").'</td>'."\n";
523  elseif (((string) $car) == "0") print '<td class="non">'.$langs->trans("Against").'</td>'."\n";
524  else print '<td class="vide">&nbsp;</td>'."\n";
525  // Total
526  if (!isset($sumfor[$i])) $sumfor[$i] = 0;
527  if (!isset($sumagainst[$i])) $sumagainst[$i] = 0;
528  if (((string) $car) == "1") $sumfor[$i]++;
529  if (((string) $car) == "0") $sumagainst[$i]++;
530  }
531  }
532  }
533  }
534 
535  // Button edit at end of line
536  if ($compteur != $ligneamodifier && $mod_ok)
537  {
538  print '<td class="casevide"><input type="submit" class="button smallpaddingimp" name="modifierligne'.$compteur.'" value="'.dol_escape_htmltag($langs->trans("Edit")).'"></td>'."\n";
539  }
540 
541  //demande de confirmation pour modification de ligne
542  for ($i = 0; $i < $nblines; $i++)
543  {
544  if (GETPOSTISSET("modifierligne".$i))
545  {
546  if ($compteur == $i)
547  {
548  print '<td class="casevide">';
549  print '<input type="hidden" name="idtomodify'.$compteur.'" value="'.$obj->id_users.'">';
550  print '<input type="submit" class="button button-save" name="validermodifier'.$compteur.'" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
551  print '</td>'."\n";
552  }
553  }
554  }
555 
556  $compteur++;
557  print '</tr>'."\n";
558 }
559 
560 // Add line to add new record
561 if ($ligneamodifier < 0 && (!isset($_SESSION['nom'])))
562 {
563  print '<tr>'."\n";
564  print '<td class="nom">'."\n";
565  if (isset($_SESSION['nom']))
566  {
567  print '<input type=hidden name="nom" value="'.$_SESSION['nom'].'">'.$_SESSION['nom']."\n";
568  } else {
569  print '<input type="text" name="nom" placeholder="'.dol_escape_htmltag($langs->trans("Name")).'" maxlength="64" size="24">'."\n";
570  }
571  print '</td>'."\n";
572 
573  // affichage des cases de formulaire checkbox pour un nouveau choix
574  for ($i = 0; $i < $nbcolonnes; $i++)
575  {
576  print '<td class="vide">';
577  if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst')))
578  {
579  print '<input type="checkbox" name="choix'.$i.'" value="1"';
580  if (GETPOSTISSET('choix'.$i) && GETPOST('choix'.$i) == '1') {
581  print ' checked';
582  }
583  print '>';
584  }
585  if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno')
586  {
587  $arraychoice = array('2'=>'&nbsp;', '0'=>$langs->trans("No"), '1'=>$langs->trans("Yes"));
588  print $form->selectarray("choix".$i, $arraychoice, GETPOST('choix'.$i));
589  }
590  if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst')
591  {
592  $arraychoice = array('2'=>'&nbsp;', '0'=>$langs->trans("Against"), '1'=>$langs->trans("For"));
593  print $form->selectarray("choix".$i, $arraychoice, GETPOST('choix'.$i));
594  }
595  print '</td>'."\n";
596  }
597 
598  // Affichage du bouton de formulaire pour inscrire un nouvel utilisateur dans la base
599  print '<td><input type="image" class="borderimp" name="boutonp" value="'.$langs->trans("Vote").'" src="'.img_picto('', 'edit_add', '', false, 1).'"></td>'."\n";
600  print '</tr>'."\n";
601 }
602 
603 // Select value of best choice (for checkbox columns only)
604 $nbofcheckbox = 0;
605 for ($i = 0; $i < $nbcolonnes; $i++)
606 {
607  if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst')))
608  $nbofcheckbox++;
609  if (isset($sumfor[$i]))
610  {
611  if ($i == 0)
612  {
613  $meilleurecolonne = $sumfor[$i];
614  }
615  if (!isset($meilleurecolonne) || $sumfor[$i] > $meilleurecolonne)
616  {
617  $meilleurecolonne = $sumfor[$i];
618  }
619  }
620 }
621 
622 if ($object->allow_spy) {
623  // Show line total
624  print '<tr>'."\n";
625  print '<td class="center">'.$langs->trans("Total").'</td>'."\n";
626  for ($i = 0; $i < $nbcolonnes; $i++)
627  {
628  $showsumfor = isset($sumfor[$i]) ? $sumfor[$i] : '';
629  $showsumagainst = isset($sumagainst[$i]) ? $sumagainst[$i] : '';
630  if (empty($showsumfor)) $showsumfor = 0;
631  if (empty($showsumagainst)) $showsumagainst = 0;
632 
633  print '<td>';
634  if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst'))) print $showsumfor;
635  if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno') print $langs->trans("Yes").': '.$showsumfor.'<br>'.$langs->trans("No").': '.$showsumagainst;
636  if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst') print $langs->trans("For").': '.$showsumfor.'<br>'.$langs->trans("Against").': '.$showsumagainst;
637  print '</td>'."\n";
638  }
639  print '</tr>';
640  // Show picto winner
641  if ($nbofcheckbox >= 2)
642  {
643  print '<tr>'."\n";
644  print '<td class="somme"></td>'."\n";
645  for ($i = 0; $i < $nbcolonnes; $i++)
646  {
647  //print 'xx'.(! empty($listofanswers[$i]['format'])).'-'.$sumfor[$i].'-'.$meilleurecolonne;
648  if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst')) && isset($sumfor[$i]) && isset($meilleurecolonne) && $sumfor[$i] == $meilleurecolonne)
649  {
650  print '<td class="somme"><img src="'.dol_buildpath('/opensurvey/img/medaille.png', 1).'"></td>'."\n";
651  } else {
652  print '<td class="somme"></td>'."\n";
653  }
654  }
655  print '</tr>'."\n";
656  }
657 }
658 print '</table>'."\n";
659 print '</div>'."\n";
660 
661 if ($object->allow_spy) {
662  $toutsujet = explode(",", $object->sujet);
663  $toutsujet = str_replace("°", "'", $toutsujet);
664 
665  $compteursujet = 0;
666  $meilleursujet = '';
667 
668  for ($i = 0; $i < $nbcolonnes; $i++) {
669  if (isset($sumfor[$i]) && isset($meilleurecolonne) && $sumfor[$i] == $meilleurecolonne) {
670  $meilleursujet .= ", ";
671  if ($object->format == "D") {
672  $meilleursujetexport = $toutsujet[$i];
673 
674  if (strpos($toutsujet[$i], '@') !== false) {
675  $toutsujetdate = explode("@", $toutsujet[$i]);
676  $meilleursujet .= dol_print_date($toutsujetdate[0], 'daytext').' ('.dol_print_date($toutsujetdate[0], '%A').') - '.$toutsujetdate[1];
677  } else {
678  $meilleursujet .= dol_print_date($toutsujet[$i], 'daytext').' ('.dol_print_date($toutsujet[$i], '%A').')';
679  }
680  } else {
681  $tmps = explode('@', $toutsujet[$i]);
682  $meilleursujet .= dol_htmlentities($tmps[0]);
683  }
684 
685  $compteursujet++;
686  }
687  }
688 
689  $meilleursujet = substr("$meilleursujet", 1);
690  $meilleursujet = str_replace("°", "'", $meilleursujet);
691 
692 
693  // Show best choice
694  if ($nbofcheckbox >= 2)
695  {
696  $vote_str = $langs->trans('votes');
697  print '<p class="affichageresultats">'."\n";
698 
699  if (isset($meilleurecolonne) && $compteursujet == "1") {
700  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";
701  } elseif (isset($meilleurecolonne)) {
702  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";
703  }
704 
705  print '</p><br>'."\n";
706  }
707 }
708 
709 print '<br>';
710 
711 
712 // Comment list
713 $comments = $object->getComments();
714 
715 if ($comments)
716 {
717  print '<br><u><span class="bold opacitymedium">'.$langs->trans("CommentsOfVoters").':</span></u><br>'."\n";
718 
719  foreach ($comments as $obj) {
720  // ligne d'un usager pré-authentifié
721  //$mod_ok = (in_array($obj->name, $listofvoters));
722 
723  print '<div class="comment"><span class="usercomment">';
724  if (in_array($obj->usercomment, $listofvoters)) print '<a href="'.$_SERVER["PHP_SELF"].'?deletecomment='.$obj->id_comment.'&sondage='.$numsondage.'"> '.img_picto('', 'delete.png', '', false, 0, 0, '', 'nomarginleft').'</a> ';
725  //else print img_picto('', 'ellipsis-h', '', false, 0, 0, '', 'nomarginleft').' ';
726  print dol_htmlentities($obj->usercomment).':</span> <span class="comment">'.dol_nl2br(dol_htmlentities($obj->comment))."</span></div>";
727  }
728 }
729 
730 // Form to add comment
731 if ($object->allow_comments) {
732  print '<br><div class="addcomment"><span class="opacitymedium">'.$langs->trans("AddACommentForPoll")."</span><br>\n";
733 
734  print '<textarea name="comment" rows="'.ROWS_2.'" class="quatrevingtpercent">'.dol_escape_htmltag(GETPOST('comment', 'restricthtml'), 0, 1).'</textarea><br>'."\n";
735  print $langs->trans("Name").': ';
736  print '<input type="text" name="commentuser" maxlength="64" value="'.GETPOST('commentuser', 'nohtml').'"> &nbsp; '."\n";
737  print '<input type="submit" class="button" name="ajoutcomment" value="'.dol_escape_htmltag($langs->trans("AddComment")).'"><br>'."\n";
738  print '</form>'."\n";
739 
740  print '</div>'."\n"; // div add comment
741 }
742 
743 print '<br><br>';
744 
745 print '<a name="bas"></a>'."\n";
746 
748 
749 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_now($mode= 'auto')
Return date for now.
Class to manage Dolibarr users.
Definition: user.class.php:44
getUrlSondage($id, $admin=false)
Fonction permettant de générer les URL pour les sondage.
Definition: fonctions.php:192
dol_htmlentities($string, $flags=null, $encoding= 'UTF-8', $double_encode=false)
Replace htmlentities functions.
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...
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
llxFooterSurvey()
Show footer for new member.
Definition: fonctions.php:131
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,$sendto,$replyto,$message,$filepath,$mimetype,$filename,$cc,$ccc,$deliveryreceipt,$msgishtml,$errors_to,$css,$trackid,$moreinheader,$sendcontext,$replyto); $mailfile-&gt;sendfile();.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
if(!GETPOST('transkey', 'alphanohtml')&&!GETPOST('transphrase', 'alphanohtml')) else
View.
Definition: notice.php:44
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Put here description of your class.
print
Draft customers invoices.
Definition: index.php:89
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
print $_SERVER["PHP_SELF"] n
Edit parameters.
Definition: categories.php:101
llxHeaderSurvey($title, $head="", $disablejs=0, $disablehead=0, $arrayofjs= '', $arrayofcss= '', $numsondage= '')
Show header for new member.
Definition: fonctions.php:73
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $keepmoretags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...