studs.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768
  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. /**
  19. * \file htdocs/public/opensurvey/studs.php
  20. * \ingroup opensurvey
  21. * \brief Page to list surveys
  22. */
  23. define("NOLOGIN", 1); // This means this output page does not require to be logged.
  24. define("NOCSRFCHECK", 1); // We accept to go on this page from external web site.
  25. require '../../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
  27. require_once DOL_DOCUMENT_ROOT."/core/lib/files.lib.php";
  28. require_once DOL_DOCUMENT_ROOT."/opensurvey/class/opensurveysondage.class.php";
  29. require_once DOL_DOCUMENT_ROOT."/opensurvey/fonctions.php";
  30. // Init vars
  31. $action = GETPOST('action', 'aZ09');
  32. $numsondage = '';
  33. if (GETPOST('sondage'))
  34. {
  35. $numsondage = GETPOST('sondage', 'alpha');
  36. }
  37. $object = new Opensurveysondage($db);
  38. $result = $object->fetch(0, $numsondage);
  39. $nblines = $object->fetch_lines();
  40. //If the survey has not yet finished, then it can be modified
  41. $canbemodified = ((empty($object->date_fin) || $object->date_fin > dol_now()) && $object->status != Opensurveysondage::STATUS_CLOSED);
  42. // Security check
  43. if (empty($conf->opensurvey->enabled)) accessforbidden('', 0, 0, 1);
  44. /*
  45. * Actions
  46. */
  47. $nbcolonnes = substr_count($object->sujet, ',') + 1;
  48. $listofvoters = explode(',', $_SESSION["savevoter"]);
  49. // Add comment
  50. if (GETPOST('ajoutcomment', 'alpha'))
  51. {
  52. if (!$canbemodified) accessforbidden('', 0, 0, 1);
  53. $error = 0;
  54. $comment = GETPOST("comment", 'none');
  55. $comment_user = GETPOST('commentuser', 'nohtml');
  56. if (!$comment)
  57. {
  58. $error++;
  59. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Comment")), null, 'errors');
  60. }
  61. if (!$comment_user)
  62. {
  63. $error++;
  64. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("User")), null, 'errors');
  65. }
  66. if (!in_array($comment_user, $listofvoters))
  67. {
  68. setEventMessages($langs->trans("UserMustBeSameThanUserUsedToVote"), null, 'errors');
  69. $error++;
  70. }
  71. if (!$error)
  72. {
  73. $resql = $object->addComment($comment, $comment_user);
  74. if (!$resql) dol_print_error($db);
  75. }
  76. }
  77. // Add vote
  78. if (GETPOST("boutonp") || GETPOST("boutonp.x") || GETPOST("boutonp_x")) // boutonp for chrome, boutonp_x for firefox
  79. {
  80. if (!$canbemodified) accessforbidden('', 0, 0, 1);
  81. //Si le nom est bien entré
  82. if (GETPOST('nom', 'nohtml'))
  83. {
  84. $nouveauchoix = '';
  85. for ($i = 0; $i < $nbcolonnes; $i++)
  86. {
  87. if (isset($_POST["choix$i"]) && $_POST["choix$i"] == '1')
  88. {
  89. $nouveauchoix .= "1";
  90. }
  91. elseif (isset($_POST["choix$i"]) && $_POST["choix$i"] == '2')
  92. {
  93. $nouveauchoix .= "2";
  94. }
  95. else { // sinon c'est 0
  96. $nouveauchoix .= "0";
  97. }
  98. }
  99. $nom = substr(GETPOST("nom", 'nohtml'), 0, 64);
  100. // Check if vote already exists
  101. $sql = 'SELECT id_users, nom as name';
  102. $sql .= ' FROM '.MAIN_DB_PREFIX.'opensurvey_user_studs';
  103. $sql .= " WHERE id_sondage='".$db->escape($numsondage)."' AND nom = '".$db->escape($nom)."' ORDER BY id_users";
  104. $resql = $db->query($sql);
  105. if (!$resql) dol_print_error($db);
  106. $num_rows = $db->num_rows($resql);
  107. if ($num_rows > 0)
  108. {
  109. setEventMessages($langs->trans("VoteNameAlreadyExists"), null, 'errors');
  110. $error++;
  111. }
  112. else
  113. {
  114. $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'opensurvey_user_studs (nom, id_sondage, reponses)';
  115. $sql .= " VALUES ('".$db->escape($nom)."', '".$db->escape($numsondage)."','".$db->escape($nouveauchoix)."')";
  116. $resql = $db->query($sql);
  117. if ($resql)
  118. {
  119. // Add voter to session
  120. $_SESSION["savevoter"] = $nom.','.(empty($_SESSION["savevoter"]) ? '' : $_SESSION["savevoter"]); // Save voter
  121. $listofvoters = explode(',', $_SESSION["savevoter"]);
  122. if ($object->mailsonde)
  123. {
  124. if ($object->fk_user_creat) {
  125. $userstatic = new User($db);
  126. $userstatic->fetch($object->fk_user_creat);
  127. $email = $userstatic->email;
  128. } else {
  129. $email = $object->mail_admin;
  130. }
  131. //Linked user may not have an email set
  132. if ($email) {
  133. include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
  134. $application = ($conf->global->MAIN_APPLICATION_TITLE ? $conf->global->MAIN_APPLICATION_TITLE : 'Dolibarr ERP/CRM');
  135. $body = str_replace('\n', '<br>', $langs->transnoentities('EmailSomeoneVoted', $nom, getUrlSondage($numsondage, true)));
  136. //var_dump($body);exit;
  137. $cmailfile = new CMailFile("[".$application."] ".$langs->trans("Poll").': '.$object->titre, $email, $conf->global->MAIN_MAIL_EMAIL_FROM, $body, null, null, null, '', '', 0, -1);
  138. $result = $cmailfile->sendfile();
  139. }
  140. }
  141. }
  142. else dol_print_error($db);
  143. }
  144. }
  145. else
  146. {
  147. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Name")), null, 'errors');
  148. }
  149. }
  150. // Update vote
  151. $testmodifier = false;
  152. $testligneamodifier = false;
  153. $ligneamodifier = -1;
  154. for ($i = 0; $i < $nblines; $i++)
  155. {
  156. if (isset($_POST['modifierligne'.$i]))
  157. {
  158. $ligneamodifier = $i;
  159. $testligneamodifier = true;
  160. }
  161. //test to see if a line is to be modified
  162. if (isset($_POST['validermodifier'.$i]))
  163. {
  164. $modifier = $i;
  165. $testmodifier = true;
  166. }
  167. }
  168. if ($testmodifier)
  169. {
  170. //var_dump($_POST);exit;
  171. $nouveauchoix = '';
  172. for ($i = 0; $i < $nbcolonnes; $i++)
  173. {
  174. //var_dump($_POST["choix$i"]);
  175. if (isset($_POST["choix".$i]) && $_POST["choix".$i] == '1')
  176. {
  177. $nouveauchoix .= "1";
  178. }
  179. elseif (isset($_POST["choix".$i]) && $_POST["choix".$i] == '2')
  180. {
  181. $nouveauchoix .= "2";
  182. }
  183. else { // sinon c'est 0
  184. $nouveauchoix .= "0";
  185. }
  186. }
  187. if (!$canbemodified) accessforbidden('', 0, 0, 1);
  188. $idtomodify = $_POST["idtomodify".$modifier];
  189. $sql = 'UPDATE '.MAIN_DB_PREFIX."opensurvey_user_studs";
  190. $sql .= " SET reponses = '".$db->escape($nouveauchoix)."'";
  191. $sql .= " WHERE id_users = '".$db->escape($idtomodify)."'";
  192. $resql = $db->query($sql);
  193. if (!$resql) dol_print_error($db);
  194. }
  195. // Delete comment
  196. $idcomment = GETPOST('deletecomment', 'int');
  197. if ($idcomment)
  198. {
  199. if (!$canbemodified) accessforbidden('', 0, 0, 1);
  200. $resql = $object->deleteComment($idcomment);
  201. }
  202. /*
  203. * View
  204. */
  205. $form = new Form($db);
  206. $arrayofjs = array();
  207. $arrayofcss = array('/opensurvey/css/style.css');
  208. llxHeaderSurvey($object->titre, "", 0, 0, $arrayofjs, $arrayofcss, $numsondage);
  209. if (empty($object->ref)) // For survey, id is a hex string
  210. {
  211. $langs->load("errors");
  212. print $langs->trans("ErrorRecordNotFound");
  213. llxFooterSurvey();
  214. $db->close();
  215. exit();
  216. }
  217. // Define format of choices
  218. $toutsujet = explode(",", $object->sujet);
  219. $listofanswers = array();
  220. foreach ($toutsujet as $value)
  221. {
  222. $tmp = explode('@', $value);
  223. $listofanswers[] = array('label'=>$tmp[0], 'format'=>($tmp[1] ? $tmp[1] : 'checkbox'));
  224. }
  225. $toutsujet = str_replace("°", "'", $toutsujet);
  226. print '<div class="survey_invitation">'.$langs->trans("YouAreInivitedToVote").'</div>';
  227. print $langs->trans("OpenSurveyHowTo").'<br><br>';
  228. print '<div class="corps"> '."\n";
  229. //affichage du titre du sondage
  230. $titre = str_replace("\\", "", $object->titre);
  231. print '<strong>'.dol_htmlentities($titre).'</strong><br><br>'."\n";
  232. //affichage des commentaires du sondage
  233. if ($object->commentaires)
  234. {
  235. print dol_htmlentitiesbr($object->commentaires);
  236. print '<br>'."\n";
  237. }
  238. print '</div>'."\n";
  239. //The survey has expired, users can't vote or do any action
  240. if (!$canbemodified) {
  241. print '<div style="text-align: center"><p>'.$langs->trans('SurveyExpiredInfo').'</p></div>';
  242. llxFooterSurvey();
  243. $db->close();
  244. exit;
  245. }
  246. print '<div class="cadre"> '."\n";
  247. print '<br><br>'."\n";
  248. // Start to show survey result
  249. print '<table class="resultats">'."\n";
  250. // Show choice titles
  251. if ($object->format == "D")
  252. {
  253. //display of survey topics
  254. print '<tr>'."\n";
  255. print '<td></td>'."\n";
  256. //display of years
  257. $colspan = 1;
  258. $nbofsujet = count($toutsujet);
  259. for ($i = 0; $i < $nbofsujet; $i++)
  260. {
  261. if (isset($toutsujet[$i + 1]) && date('Y', intval($toutsujet[$i])) == date('Y', intval($toutsujet[$i + 1]))) {
  262. $colspan++;
  263. } else {
  264. print '<td colspan='.$colspan.' class="annee">'.date('Y', intval($toutsujet[$i])).'</td>'."\n";
  265. $colspan = 1;
  266. }
  267. }
  268. print '</tr>'."\n";
  269. print '<tr>'."\n";
  270. print '<td></td>'."\n";
  271. //display of months
  272. $colspan = 1;
  273. for ($i = 0; $i < $nbofsujet; $i++) {
  274. $cur = intval($toutsujet[$i]); // intval() est utiliser pour supprimer le suffixe @* qui déplaît logiquement à strftime()
  275. if (isset($toutsujet[$i + 1]) === false) {
  276. $next = false;
  277. } else {
  278. $next = intval($toutsujet[$i + 1]);
  279. }
  280. if ($next && dol_print_date($cur, "%B") == dol_print_date($next, "%B") && dol_print_date($cur, "%Y") == dol_print_date($next, "%Y")) {
  281. $colspan++;
  282. } else {
  283. print '<td colspan='.$colspan.' class="mois">'.dol_print_date($cur, "%B").'</td>'."\n";
  284. $colspan = 1;
  285. }
  286. }
  287. print '</tr>'."\n";
  288. print '<tr>'."\n";
  289. print '<td></td>'."\n";
  290. //display of days
  291. $colspan = 1;
  292. for ($i = 0; $i < $nbofsujet; $i++) {
  293. $cur = intval($toutsujet[$i]);
  294. if (isset($toutsujet[$i + 1]) === false) {
  295. $next = false;
  296. } else {
  297. $next = intval($toutsujet[$i + 1]);
  298. }
  299. if ($next && dol_print_date($cur, "%a %e") == dol_print_date($next, "%a %e") && dol_print_date($cur, "%B") == dol_print_date($next, "%B")) {
  300. $colspan++;
  301. } else {
  302. print '<td colspan="'.$colspan.'" class="jour">'.dol_print_date($cur, "%a %e").'</td>'."\n";
  303. $colspan = 1;
  304. }
  305. }
  306. print '</tr>'."\n";
  307. //Display schedules
  308. if (strpos($object->sujet, '@') !== false) {
  309. print '<tr>'."\n";
  310. print '<td></td>'."\n";
  311. for ($i = 0; isset($toutsujet[$i]); $i++) {
  312. $heures = explode('@', $toutsujet[$i]);
  313. if (isset($heures[1])) {
  314. print '<td class="heure">'.dol_htmlentities($heures[1]).'</td>'."\n";
  315. } else {
  316. print '<td class="heure"></td>'."\n";
  317. }
  318. }
  319. print '</tr>'."\n";
  320. }
  321. }
  322. else
  323. {
  324. //display of survey topics
  325. print '<tr>'."\n";
  326. print '<td></td>'."\n";
  327. for ($i = 0; isset($toutsujet[$i]); $i++)
  328. {
  329. $tmp = explode('@', $toutsujet[$i]);
  330. print '<td class="sujet">'.$tmp[0].'</td>'."\n";
  331. }
  332. print '</tr>'."\n";
  333. }
  334. // Loop on each answer
  335. $sumfor = array();
  336. $sumagainst = array();
  337. $compteur = 0;
  338. $sql = "SELECT id_users, nom as name, id_sondage, reponses";
  339. $sql .= " FROM ".MAIN_DB_PREFIX."opensurvey_user_studs";
  340. $sql .= " WHERE id_sondage = '".$db->escape($numsondage)."'";
  341. $resql = $db->query($sql);
  342. if (!$resql)
  343. {
  344. dol_print_error($db);
  345. exit;
  346. }
  347. $num = $db->num_rows($resql);
  348. while ($compteur < $num)
  349. {
  350. $obj = $db->fetch_object($resql);
  351. $ensemblereponses = $obj->reponses;
  352. // ligne d'un usager pré-authentifié
  353. $mod_ok = (in_array($obj->name, $listofvoters));
  354. if (!$mod_ok && !$object->allow_spy) {
  355. $compteur++;
  356. continue;
  357. }
  358. print '<tr>'."\n";
  359. // Name
  360. print '<td class="nom">'.dol_htmlentities($obj->name).'</td>'."\n";
  361. // si la ligne n'est pas a changer, on affiche les données
  362. if (!$testligneamodifier)
  363. {
  364. for ($i = 0; $i < $nbcolonnes; $i++)
  365. {
  366. $car = substr($ensemblereponses, $i, 1);
  367. //print 'xx'.$i."-".$car.'-'.$listofanswers[$i]['format'].'zz';
  368. if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst')))
  369. {
  370. if (((string) $car) == "1") print '<td class="ok">OK</td>'."\n";
  371. else print '<td class="non">KO</td>'."\n";
  372. // Total
  373. if (!isset($sumfor[$i])) $sumfor[$i] = 0;
  374. if (((string) $car) == "1") $sumfor[$i]++;
  375. }
  376. if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno')
  377. {
  378. if (((string) $car) == "1") print '<td class="ok">'.$langs->trans("Yes").'</td>'."\n";
  379. elseif (((string) $car) == "0") print '<td class="non">'.$langs->trans("No").'</td>'."\n";
  380. else print '<td class="vide">&nbsp;</td>'."\n";
  381. // Total
  382. if (!isset($sumfor[$i])) $sumfor[$i] = 0;
  383. if (!isset($sumagainst[$i])) $sumagainst[$i] = 0;
  384. if (((string) $car) == "1") $sumfor[$i]++;
  385. if (((string) $car) == "0") $sumagainst[$i]++;
  386. }
  387. if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst')
  388. {
  389. if (((string) $car) == "1") print '<td class="ok">'.$langs->trans("For").'</td>'."\n";
  390. elseif (((string) $car) == "0") print '<td class="non">'.$langs->trans("Against").'</td>'."\n";
  391. else print '<td class="vide">&nbsp;</td>'."\n";
  392. // Total
  393. if (!isset($sumfor[$i])) $sumfor[$i] = 0;
  394. if (!isset($sumagainst[$i])) $sumagainst[$i] = 0;
  395. if (((string) $car) == "1") $sumfor[$i]++;
  396. if (((string) $car) == "0") $sumagainst[$i]++;
  397. }
  398. }
  399. }
  400. else
  401. {
  402. //sinon on remplace les choix de l'utilisateur par une ligne de checkbox pour recuperer de nouvelles valeurs
  403. if ($compteur == $ligneamodifier)
  404. {
  405. for ($i = 0; $i < $nbcolonnes; $i++)
  406. {
  407. $car = substr($ensemblereponses, $i, 1);
  408. print '<td class="vide">';
  409. if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst')))
  410. {
  411. print '<input type="checkbox" name="choix'.$i.'" value="1" ';
  412. if ($car == '1') print 'checked';
  413. print '>';
  414. }
  415. if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno')
  416. {
  417. $arraychoice = array('2'=>'&nbsp;', '0'=>$langs->trans("No"), '1'=>$langs->trans("Yes"));
  418. print $form->selectarray("choix".$i, $arraychoice, $car);
  419. }
  420. if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst')
  421. {
  422. $arraychoice = array('2'=>'&nbsp;', '0'=>$langs->trans("Against"), '1'=>$langs->trans("For"));
  423. print $form->selectarray("choix".$i, $arraychoice, $car);
  424. }
  425. print '</td>'."\n";
  426. }
  427. }
  428. else
  429. {
  430. for ($i = 0; $i < $nbcolonnes; $i++)
  431. {
  432. $car = substr($ensemblereponses, $i, 1);
  433. if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst')))
  434. {
  435. if (((string) $car) == "1") print '<td class="ok">OK</td>'."\n";
  436. else print '<td class="non">KO</td>'."\n";
  437. // Total
  438. if (!isset($sumfor[$i])) $sumfor[$i] = 0;
  439. if (((string) $car) == "1") $sumfor[$i]++;
  440. }
  441. if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno')
  442. {
  443. if (((string) $car) == "1") print '<td class="ok">'.$langs->trans("For").'</td>'."\n";
  444. elseif (((string) $car) == "0") print '<td class="non">'.$langs->trans("Against").'</td>'."\n";
  445. else print '<td class="vide">&nbsp;</td>'."\n";
  446. // Total
  447. if (!isset($sumfor[$i])) $sumfor[$i] = 0;
  448. if (!isset($sumagainst[$i])) $sumagainst[$i] = 0;
  449. if (((string) $car) == "1") $sumfor[$i]++;
  450. if (((string) $car) == "0") $sumagainst[$i]++;
  451. }
  452. if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst')
  453. {
  454. if (((string) $car) == "1") print '<td class="ok">'.$langs->trans("For").'</td>'."\n";
  455. elseif (((string) $car) == "0") print '<td class="non">'.$langs->trans("Against").'</td>'."\n";
  456. else print '<td class="vide">&nbsp;</td>'."\n";
  457. // Total
  458. if (!isset($sumfor[$i])) $sumfor[$i] = 0;
  459. if (!isset($sumagainst[$i])) $sumagainst[$i] = 0;
  460. if (((string) $car) == "1") $sumfor[$i]++;
  461. if (((string) $car) == "0") $sumagainst[$i]++;
  462. }
  463. }
  464. }
  465. }
  466. // Button edit at end of line
  467. if ($compteur != $ligneamodifier && $mod_ok)
  468. {
  469. print '<td class="casevide"><input type="submit" class="button" name="modifierligne'.$compteur.'" value="'.dol_escape_htmltag($langs->trans("Edit")).'"></td>'."\n";
  470. }
  471. //demande de confirmation pour modification de ligne
  472. for ($i = 0; $i < $nblines; $i++)
  473. {
  474. if (isset($_POST["modifierligne".$i]))
  475. {
  476. if ($compteur == $i)
  477. {
  478. print '<td class="casevide">';
  479. print '<input type="hidden" name="idtomodify'.$compteur.'" value="'.$obj->id_users.'">';
  480. print '<input type="submit" class="button" name="validermodifier'.$compteur.'" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  481. print '</td>'."\n";
  482. }
  483. }
  484. }
  485. $compteur++;
  486. print '</tr>'."\n";
  487. }
  488. // Add line to add new record
  489. if ($ligneamodifier < 0 && (!isset($_SESSION['nom'])))
  490. {
  491. print '<tr>'."\n";
  492. print '<td class="nom">'."\n";
  493. if (isset($_SESSION['nom']))
  494. {
  495. print '<input type=hidden name="nom" value="'.$_SESSION['nom'].'">'.$_SESSION['nom']."\n";
  496. } else {
  497. print '<input type="text" name="nom" placeholder="'.dol_escape_htmltag($langs->trans("Name")).'" maxlength="64" size="24">'."\n";
  498. }
  499. print '</td>'."\n";
  500. // affichage des cases de formulaire checkbox pour un nouveau choix
  501. for ($i = 0; $i < $nbcolonnes; $i++)
  502. {
  503. print '<td class="vide">';
  504. if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst')))
  505. {
  506. print '<input type="checkbox" name="choix'.$i.'" value="1"';
  507. if (isset($_POST['choix'.$i]) && $_POST['choix'.$i] == '1')
  508. {
  509. print ' checked';
  510. }
  511. print '>';
  512. }
  513. if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno')
  514. {
  515. $arraychoice = array('2'=>'&nbsp;', '0'=>$langs->trans("No"), '1'=>$langs->trans("Yes"));
  516. print $form->selectarray("choix".$i, $arraychoice, GETPOST('choix'.$i));
  517. }
  518. if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst')
  519. {
  520. $arraychoice = array('2'=>'&nbsp;', '0'=>$langs->trans("Against"), '1'=>$langs->trans("For"));
  521. print $form->selectarray("choix".$i, $arraychoice, GETPOST('choix'.$i));
  522. }
  523. print '</td>'."\n";
  524. }
  525. // Affichage du bouton de formulaire pour inscrire un nouvel utilisateur dans la base
  526. print '<td><input type="image" name="boutonp" value="'.$langs->trans("Vote").'" src="'.dol_buildpath('/opensurvey/img/add-24.png', 1).'"></td>'."\n";
  527. print '</tr>'."\n";
  528. }
  529. // Select value of best choice (for checkbox columns only)
  530. $nbofcheckbox = 0;
  531. for ($i = 0; $i < $nbcolonnes; $i++)
  532. {
  533. if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst')))
  534. $nbofcheckbox++;
  535. if (isset($sumfor[$i]))
  536. {
  537. if ($i == 0)
  538. {
  539. $meilleurecolonne = $sumfor[$i];
  540. }
  541. if (!isset($meilleurecolonne) || $sumfor[$i] > $meilleurecolonne)
  542. {
  543. $meilleurecolonne = $sumfor[$i];
  544. }
  545. }
  546. }
  547. if ($object->allow_spy) {
  548. // Show line total
  549. print '<tr>'."\n";
  550. print '<td class="center">'.$langs->trans("Total").'</td>'."\n";
  551. for ($i = 0; $i < $nbcolonnes; $i++)
  552. {
  553. $showsumfor = isset($sumfor[$i]) ? $sumfor[$i] : '';
  554. $showsumagainst = isset($sumagainst[$i]) ? $sumagainst[$i] : '';
  555. if (empty($showsumfor)) $showsumfor = 0;
  556. if (empty($showsumagainst)) $showsumagainst = 0;
  557. print '<td>';
  558. if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst'))) print $showsumfor;
  559. if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno') print $langs->trans("Yes").': '.$showsumfor.'<br>'.$langs->trans("No").': '.$showsumagainst;
  560. if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst') print $langs->trans("For").': '.$showsumfor.'<br>'.$langs->trans("Against").': '.$showsumagainst;
  561. print '</td>'."\n";
  562. }
  563. print '</tr>';
  564. // Show picto winner
  565. if ($nbofcheckbox >= 2)
  566. {
  567. print '<tr>'."\n";
  568. print '<td class="somme"></td>'."\n";
  569. for ($i = 0; $i < $nbcolonnes; $i++)
  570. {
  571. //print 'xx'.(! empty($listofanswers[$i]['format'])).'-'.$sumfor[$i].'-'.$meilleurecolonne;
  572. if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst')) && isset($sumfor[$i]) && isset($meilleurecolonne) && $sumfor[$i] == $meilleurecolonne)
  573. {
  574. print '<td class="somme"><img src="'.dol_buildpath('/opensurvey/img/medaille.png', 1).'"></td>'."\n";
  575. } else {
  576. print '<td class="somme"></td>'."\n";
  577. }
  578. }
  579. print '</tr>'."\n";
  580. }
  581. }
  582. print '</table>'."\n";
  583. print '</div>'."\n";
  584. if ($object->allow_spy) {
  585. $toutsujet = explode(",", $object->sujet);
  586. $toutsujet = str_replace("°", "'", $toutsujet);
  587. $compteursujet = 0;
  588. $meilleursujet = '';
  589. for ($i = 0; $i < $nbcolonnes; $i++) {
  590. if (isset($sumfor[$i]) && isset($meilleurecolonne) && $sumfor[$i] == $meilleurecolonne) {
  591. $meilleursujet .= ", ";
  592. if ($object->format == "D") {
  593. $meilleursujetexport = $toutsujet[$i];
  594. if (strpos($toutsujet[$i], '@') !== false) {
  595. $toutsujetdate = explode("@", $toutsujet[$i]);
  596. $meilleursujet .= dol_print_date($toutsujetdate[0], 'daytext').' ('.dol_print_date($toutsujetdate[0], '%A').') - '.$toutsujetdate[1];
  597. } else {
  598. $meilleursujet .= dol_print_date($toutsujet[$i], 'daytext').' ('.dol_print_date($toutsujet[$i], '%A').')';
  599. }
  600. }
  601. else
  602. {
  603. $tmps = explode('@', $toutsujet[$i]);
  604. $meilleursujet .= dol_htmlentities($tmps[0]);
  605. }
  606. $compteursujet++;
  607. }
  608. }
  609. $meilleursujet = substr("$meilleursujet", 1);
  610. $meilleursujet = str_replace("°", "'", $meilleursujet);
  611. // Show best choice
  612. if ($nbofcheckbox >= 2)
  613. {
  614. $vote_str = $langs->trans('votes');
  615. print '<p class="affichageresultats">'."\n";
  616. if (isset($meilleurecolonne) && $compteursujet == "1") {
  617. 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";
  618. } elseif (isset($meilleurecolonne)) {
  619. 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";
  620. }
  621. print '</p><br>'."\n";
  622. }
  623. }
  624. print '<br>';
  625. // Comment list
  626. $comments = $object->getComments();
  627. if ($comments)
  628. {
  629. print "<br><b>".$langs->trans("CommentsOfVoters").":</b><br>\n";
  630. foreach ($comments as $obj) {
  631. // ligne d'un usager pré-authentifié
  632. //$mod_ok = (in_array($obj->name, $listofvoters));
  633. print '<div class="comment"><span class="usercomment">';
  634. 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> ';
  635. //else print img_picto('', 'ellipsis-h', '', false, 0, 0, '', 'nomarginleft').' ';
  636. print dol_htmlentities($obj->usercomment).':</span> <span class="comment">'.dol_nl2br(dol_htmlentities($obj->comment))."</span></div>";
  637. }
  638. }
  639. // Form to add comment
  640. if ($object->allow_comments) {
  641. print '<div class="addcomment">'.$langs->trans("AddACommentForPoll")."<br>\n";
  642. print '<textarea name="comment" rows="'.ROWS_2.'" class="quatrevingtpercent">'.dol_escape_htmltag(GETPOST('comment', 'none'), 0, 1).'</textarea><br>'."\n";
  643. print $langs->trans("Name").': ';
  644. print '<input type="text" name="commentuser" maxlength="64" value="'.GETPOST('commentuser', 'nohtml').'"> &nbsp; '."\n";
  645. print '<input type="submit" class="button" name="ajoutcomment" value="'.dol_escape_htmltag($langs->trans("AddComment")).'"><br>'."\n";
  646. print '</form>'."\n";
  647. print '</div>'."\n"; // div add comment
  648. }
  649. print '<br><br>';
  650. print '<a name="bas"></a>'."\n";
  651. llxFooterSurvey();
  652. $db->close();