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