results.php 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173
  1. <?php
  2. /* Copyright (C) 2013-2020 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
  4. * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/opensurvey/results.php
  21. * \ingroup opensurvey
  22. * \brief Page to preview votes of a survey
  23. */
  24. // Load Dolibarr environment
  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/lib/opensurvey.lib.php";
  30. // Security check
  31. if (empty($user->rights->opensurvey->read)) {
  32. accessforbidden();
  33. }
  34. // Init vars
  35. $action = GETPOST('action', 'aZ09');
  36. $numsondage = GETPOST("id", 'alphanohtml');
  37. $object = new Opensurveysondage($db);
  38. $result = $object->fetch(0, $numsondage);
  39. if ($result <= 0) {
  40. dol_print_error('', 'Failed to get survey id '.$numsondage);
  41. }
  42. $nblines = $object->fetch_lines();
  43. /*
  44. * Actions
  45. */
  46. // Return to the results
  47. if (GETPOST('cancel')) {
  48. header('Location: results.php?id='.(GETPOSTISSET('id_sondage') ? GETPOST('id_sondage', 'aZ09') : GETPOST('id', 'alphanohtml')));
  49. exit;
  50. }
  51. $nbcolonnes = substr_count($object->sujet, ',') + 1;
  52. // Add vote
  53. if (GETPOST("boutonp") || GETPOST("boutonp.x") || GETPOST("boutonp_x")) { // boutonp for chrome, boutonp.x for firefox
  54. if (GETPOST('nom')) {
  55. $erreur_prenom = false;
  56. $nouveauchoix = '';
  57. for ($i = 0; $i < $nbcolonnes; $i++) {
  58. if (GETPOSTISSET("choix$i") && GETPOST("choix$i") == '1') {
  59. $nouveauchoix .= "1";
  60. } elseif (GETPOSTISSET("choix$i") && GETPOST("choix$i") == '2') {
  61. $nouveauchoix .= "2";
  62. } else { // sinon c'est 0
  63. $nouveauchoix .= "0";
  64. }
  65. }
  66. $nom = substr(GETPOST("nom", 'alphanohtml'), 0, 64);
  67. // Check if vote already exists
  68. $sql = 'SELECT id_users, nom as name';
  69. $sql .= ' FROM '.MAIN_DB_PREFIX.'opensurvey_user_studs';
  70. $sql .= " WHERE id_sondage='".$db->escape($numsondage)."' AND nom = '".$db->escape($nom)."'";
  71. $sql .= ' ORDER BY id_users';
  72. $resql = $db->query($sql);
  73. $num_rows = $db->num_rows($resql);
  74. if ($num_rows > 0) {
  75. setEventMessages($langs->trans("VoteNameAlreadyExists"), null, 'errors');
  76. $error++;
  77. } else {
  78. $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'opensurvey_user_studs (nom, id_sondage, reponses)';
  79. $sql .= " VALUES ('".$db->escape($nom)."', '".$db->escape($numsondage)."','".$db->escape($nouveauchoix)."')";
  80. $resql = $db->query($sql);
  81. if (!$resql) {
  82. dol_print_error($db);
  83. }
  84. }
  85. }
  86. }
  87. // Update vote
  88. $testmodifier = false;
  89. $testligneamodifier = false;
  90. $ligneamodifier = -1;
  91. for ($i = 0; $i < $nblines; $i++) {
  92. if (GETPOSTISSET('modifierligne'.$i)) {
  93. $ligneamodifier = $i;
  94. $testligneamodifier = true;
  95. }
  96. //test pour voir si une ligne est a modifier
  97. if (GETPOSTISSET('validermodifier'.$i)) {
  98. $modifier = $i;
  99. $testmodifier = true;
  100. }
  101. }
  102. if ($testmodifier) {
  103. // Security check
  104. if (!$user->rights->opensurvey->write) {
  105. accessforbidden();
  106. }
  107. $nouveauchoix = '';
  108. for ($i = 0; $i < $nbcolonnes; $i++) {
  109. if (GETPOSTISSET("choix$i") && GETPOST("choix$i") == '1') {
  110. $nouveauchoix .= "1";
  111. } elseif (GETPOSTISSET("choix$i") && GETPOST("choix$i") == '2') {
  112. $nouveauchoix .= "2";
  113. } else { // sinon c'est 0
  114. $nouveauchoix .= "0";
  115. }
  116. }
  117. $idtomodify = GETPOST("idtomodify".$modifier);
  118. $sql = 'UPDATE '.MAIN_DB_PREFIX."opensurvey_user_studs";
  119. $sql .= " SET reponses = '".$db->escape($nouveauchoix)."'";
  120. $sql .= " WHERE id_users = '".$db->escape($idtomodify)."'";
  121. $resql = $db->query($sql);
  122. if (!$resql) {
  123. dol_print_error($db);
  124. }
  125. }
  126. // Add column (not for date)
  127. if (GETPOST("ajoutercolonne") && GETPOST('nouvellecolonne') && $object->format == "A") {
  128. // Security check
  129. if (!$user->rights->opensurvey->write) {
  130. accessforbidden();
  131. }
  132. $nouveauxsujets = $object->sujet;
  133. //on rajoute la valeur a la fin de tous les sujets deja entrés
  134. $nouveauxsujets .= ',';
  135. $nouveauxsujets .= str_replace(array(",", "@"), " ", GETPOST("nouvellecolonne")).(!GETPOST("typecolonne") ? '' : '@'.GETPOST("typecolonne"));
  136. //mise a jour avec les nouveaux sujets dans la base
  137. $sql = 'UPDATE '.MAIN_DB_PREFIX."opensurvey_sondage";
  138. $sql .= " SET sujet = '".$db->escape($nouveauxsujets)."'";
  139. $sql .= " WHERE id_sondage = '".$db->escape($numsondage)."'";
  140. $resql = $db->query($sql);
  141. if (!$resql) {
  142. dol_print_error($db);
  143. } else {
  144. header('Location: results.php?id='.$object->id_sondage);
  145. }
  146. }
  147. // Add column (with format date)
  148. if (GETPOSTISSET("ajoutercolonne") && $object->format == "D") {
  149. // Security check
  150. if (!$user->rights->opensurvey->write) {
  151. accessforbidden();
  152. }
  153. $nouveauxsujets = $object->sujet;
  154. if (GETPOSTISSET("nouveaujour") && GETPOST("nouveaujour") != "vide" &&
  155. GETPOSTISSET("nouveaumois") && GETPOST("nouveaumois") != "vide" &&
  156. GETPOSTISSET("nouvelleannee") && GETPOST("nouvelleannee") != "vide") {
  157. $nouvelledate = dol_mktime(0, 0, 0, GETPOST("nouveaumois"), GETPOST("nouveaujour"), GETPOST("nouvelleannee"));
  158. if (GETPOSTISSET("nouvelleheuredebut") && GETPOST("nouvelleheuredebut") != "vide") {
  159. $nouvelledate .= "@";
  160. $nouvelledate .= GETPOST("nouvelleheuredebut");
  161. $nouvelledate .= "h";
  162. if (GETPOST("nouvelleminutedebut") != "vide") {
  163. $nouvelledate .= GETPOST("nouvelleminutedebut");
  164. }
  165. }
  166. if (GETPOSTISSET("nouvelleheurefin") && GETPOST("nouvelleheurefin") != "vide") {
  167. $nouvelledate .= "-";
  168. $nouvelledate .= GETPOST("nouvelleheurefin");
  169. $nouvelledate .= "h";
  170. if (GETPOST("nouvelleminutefin") != "vide") {
  171. $nouvelledate .= GETPOST("nouvelleminutefin");
  172. }
  173. }
  174. if (GETPOST("nouvelleheuredebut") == "vide" || (GETPOSTISSET("nouvelleheuredebut") && GETPOSTISSET("nouvelleheurefin")
  175. && (GETPOST("nouvelleheuredebut") < GETPOST("nouvelleheurefin") || (GETPOST("nouvelleheuredebut") == GETPOST("nouvelleheurefin")
  176. && (GETPOST("nouvelleminutedebut") < GETPOST("nouvelleminutefin")))))) {
  177. $erreur_ajout_date = false;
  178. } else {
  179. $erreur_ajout_date = "yes";
  180. }
  181. //on rajoute la valeur dans les valeurs
  182. $datesbase = explode(",", $object->sujet);
  183. $taillebase = count($datesbase);
  184. //recherche de l'endroit de l'insertion de la nouvelle date dans les dates deja entrées dans le tableau
  185. if ($nouvelledate < $datesbase[0]) {
  186. $cleinsertion = 0;
  187. } elseif ($nouvelledate > $datesbase[$taillebase - 1]) {
  188. $cleinsertion = count($datesbase);
  189. } else {
  190. $nbdatesbase = count($datesbase);
  191. for ($i = 0; $i < $nbdatesbase; $i++) {
  192. $j = $i + 1;
  193. if ($nouvelledate > $datesbase[$i] && $nouvelledate < $datesbase[$j]) {
  194. $cleinsertion = $j;
  195. }
  196. }
  197. }
  198. array_splice($datesbase, $cleinsertion, 0, $nouvelledate);
  199. $cle = array_search($nouvelledate, $datesbase);
  200. $dateinsertion = '';
  201. $nbofdates = count($datesbase);
  202. for ($i = 0; $i < $nbofdates; $i++) {
  203. $dateinsertion .= ",";
  204. $dateinsertion .= $datesbase[$i];
  205. }
  206. $dateinsertion = substr("$dateinsertion", 1);
  207. // update with new topics into database
  208. if (isset($erreur_ajout_date) && empty($erreur_ajout_date)) {
  209. $sql = 'UPDATE '.MAIN_DB_PREFIX."opensurvey_sondage";
  210. $sql .= " SET sujet = '".$db->escape($dateinsertion)."'";
  211. $sql .= " WHERE id_sondage = '".$db->escape($numsondage)."'";
  212. $resql = $db->query($sql);
  213. if (!$resql) {
  214. dol_print_error($db);
  215. } else {
  216. header('Location: results.php?id='.$object->id_sondage);
  217. }
  218. }
  219. if ($cleinsertion >= 0) {
  220. $sql = 'SELECT s.reponses';
  221. $sql .= " FROM ".MAIN_DB_PREFIX."opensurvey_user_studs as s";
  222. $sql .= " WHERE id_sondage = '".$db->escape($numsondage)."'";
  223. $resql = $db->query($sql);
  224. if (!$resql) {
  225. dol_print_error($db);
  226. } else {
  227. $num = $db->num_rows($resql);
  228. $compteur = 0;
  229. while ($compteur < $num) {
  230. $obj = $db->fetch_object($resql);
  231. $sql = 'UPDATE '.MAIN_DB_PREFIX."opensurvey_user_studs";
  232. if ($cleinsertion == 0) {
  233. $sql .= " SET reponses = '0".$db->escape($obj->reponses)."'";
  234. } else {
  235. $reponsesadd = str_split($obj->reponses);
  236. $lengthresponses = count($reponsesadd);
  237. for ($cpt = $lengthresponses; $cpt > $cleinsertion; $cpt--) {
  238. $reponsesadd[$cpt] = $reponsesadd[$cpt-1];
  239. }
  240. $reponsesadd[$cleinsertion] = '0';
  241. $reponsesadd = implode($reponsesadd);
  242. $sql .= " SET reponses = '".$db->escape($reponsesadd)."'";
  243. }
  244. $sql .= " WHERE id_sondage = '".$db->escape($numsondage)."'";
  245. $resql = $db->query($sql);
  246. if (!$resql) {
  247. dol_print_error($db);
  248. }
  249. $compteur++;
  250. }
  251. }
  252. }
  253. $adresseadmin = $object->mail_admin;
  254. } else {
  255. $erreur_ajout_date = "yes";
  256. }
  257. }
  258. // Delete line
  259. for ($i = 0; $i < $nblines; $i++) {
  260. if (GETPOST("effaceligne".$i) || GETPOST("effaceligne".$i."_x") || GETPOST("effaceligne".$i.".x")) { // effacelignei for chrome, effacelignei_x for firefox
  261. // Security check
  262. if (!$user->rights->opensurvey->write) {
  263. accessforbidden();
  264. }
  265. $compteur = 0;
  266. // Loop on each answer
  267. $compteur = 0;
  268. $sql = "SELECT id_users, nom as name, id_sondage, reponses";
  269. $sql .= " FROM ".MAIN_DB_PREFIX."opensurvey_user_studs";
  270. $sql .= " WHERE id_sondage = '".$db->escape($numsondage)."'";
  271. $resql = $db->query($sql);
  272. if (!$resql) {
  273. dol_print_error($db);
  274. }
  275. $num = $db->num_rows($resql);
  276. while ($compteur < $num) {
  277. $obj = $db->fetch_object($resql);
  278. if ($compteur == $i) {
  279. $sql2 = 'DELETE FROM '.MAIN_DB_PREFIX.'opensurvey_user_studs';
  280. $sql2 .= " WHERE id_users = ".((int) $obj->id_users);
  281. $resql2 = $db->query($sql2);
  282. }
  283. $compteur++;
  284. }
  285. }
  286. }
  287. // Delete column
  288. for ($i = 0; $i < $nbcolonnes; $i++) {
  289. if ((GETPOST("effacecolonne".$i) || GETPOST("effacecolonne".$i."_x") || GETPOST("effacecolonne".$i.".x"))
  290. && $nbcolonnes > 1) { // effacecolonnei for chrome, effacecolonnei_x for firefox
  291. // Security check
  292. if (!$user->rights->opensurvey->write) {
  293. accessforbidden();
  294. }
  295. $db->begin();
  296. $toutsujet = explode(",", $object->sujet);
  297. $j = 0;
  298. $nouveauxsujets = '';
  299. //parcours de tous les sujets actuels
  300. while (isset($toutsujet[$j])) {
  301. //si le sujet n'est pas celui qui a été effacé alors on concatene
  302. if ($i != $j) {
  303. if (!empty($nouveauxsujets)) {
  304. $nouveauxsujets .= ',';
  305. }
  306. $nouveauxsujets .= $toutsujet[$j];
  307. }
  308. $j++;
  309. }
  310. // Mise a jour des sujets dans la base
  311. $sql = 'UPDATE '.MAIN_DB_PREFIX."opensurvey_sondage";
  312. $sql .= " SET sujet = '".$db->escape($nouveauxsujets)."' WHERE id_sondage = '".$db->escape($numsondage)."'";
  313. $resql = $db->query($sql);
  314. if (!$resql) {
  315. dol_print_error($db);
  316. }
  317. // Clean current answer to remove deleted columns
  318. $compteur = 0;
  319. $sql = "SELECT id_users, nom as name, id_sondage, reponses";
  320. $sql .= " FROM ".MAIN_DB_PREFIX."opensurvey_user_studs";
  321. $sql .= " WHERE id_sondage = '".$db->escape($numsondage)."'";
  322. dol_syslog('sql='.$sql);
  323. $resql = $db->query($sql);
  324. if (!$resql) {
  325. dol_print_error($db);
  326. exit;
  327. }
  328. $num = $db->num_rows($resql);
  329. while ($compteur < $num) {
  330. $obj = $db->fetch_object($resql);
  331. $newcar = '';
  332. $ensemblereponses = $obj->reponses;
  333. // parcours de toutes les réponses actuelles
  334. for ($j = 0; $j < $nbcolonnes; $j++) {
  335. $car = substr($ensemblereponses, $j, 1);
  336. //si les reponses ne concerne pas la colonne effacée, on concatene
  337. if ($i != $j) {
  338. $newcar .= $car;
  339. }
  340. }
  341. // mise a jour des reponses utilisateurs dans la base
  342. $sql2 = 'UPDATE '.MAIN_DB_PREFIX.'opensurvey_user_studs';
  343. $sql2 .= " SET reponses = '".$db->escape($newcar)."'";
  344. $sql2 .= " WHERE id_users = '".$db->escape($obj->id_users)."'";
  345. //print $sql2;
  346. dol_syslog('sql='.$sql2);
  347. $resql2 = $db->query($sql2);
  348. $compteur++;
  349. }
  350. $db->commit();
  351. }
  352. }
  353. /*
  354. * View
  355. */
  356. $form = new Form($db);
  357. if ($object->fk_user_creat) {
  358. $userstatic = new User($db);
  359. $userstatic->fetch($object->fk_user_creat);
  360. }
  361. $result = $object->fetch(0, $numsondage);
  362. if ($result <= 0) {
  363. dol_print_error($db, $object->error);
  364. exit;
  365. }
  366. $title = $object->title." - ".$langs->trans('Card');
  367. $helpurl = '';
  368. $arrayofjs = array();
  369. $arrayofcss = array('/opensurvey/css/style.css');
  370. llxHeader('', $title, $helpurl, 0, 0, 0, $arrayofjs, $arrayofcss);
  371. // Define format of choices
  372. $toutsujet = explode(",", $object->sujet);
  373. $listofanswers = array();
  374. foreach ($toutsujet as $value) {
  375. $tmp = explode('@', $value);
  376. $listofanswers[] = array('label'=>$tmp[0], 'format'=>(!empty($tmp[1]) ? $tmp[1] : 'checkbox'));
  377. }
  378. $toutsujet = str_replace("@", "<br>", $toutsujet);
  379. $toutsujet = str_replace("°", "'", $toutsujet);
  380. print '<form name="formulaire4" action="#" method="POST">'."\n";
  381. print '<input type="hidden" name="token" value="'.newToken().'">';
  382. print '<input type="hidden" name="id" value="'.GETPOST('id').'">';
  383. $head = opensurvey_prepare_head($object);
  384. print dol_get_fiche_head($head, 'preview', $langs->trans("Survey"), -1, 'poll');
  385. $morehtmlref = '';
  386. $linkback = '<a href="'.DOL_URL_ROOT.'/opensurvey/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  387. dol_banner_tab($object, 'id', $linkback, 1, 'id_sondage', 'id_sondage', $morehtmlref);
  388. print '<div class="fichecenter">';
  389. print '<div class="fichehalfleft">';
  390. print '<div class="underbanner clearboth"></div>';
  391. print '<table class="border tableforfield centpercent">';
  392. // Type
  393. $type = ($object->format == "A") ? 'classic' : 'date';
  394. print '<tr><td class="titlefield">'.$langs->trans("Type").'</td><td>';
  395. print img_picto('', dol_buildpath('/opensurvey/img/'.($type == 'classic' ? 'chart-32.png' : 'calendar-32.png'), 1), 'width="16"', 1);
  396. print ' '.$langs->trans($type == 'classic' ? "TypeClassic" : "TypeDate").'</td></tr>';
  397. // Title
  398. print '<tr><td>';
  399. $adresseadmin = $object->mail_admin;
  400. print $langs->trans("Title").'</td><td>';
  401. if ($action == 'edit') {
  402. print '<input type="text" name="nouveautitre" size="40" value="'.dol_escape_htmltag($object->title).'">';
  403. } else {
  404. print dol_htmlentities($object->title);
  405. }
  406. print '</td></tr>';
  407. // Description
  408. print '<tr><td class="tdtop">'.$langs->trans("Description").'</td><td class="wordbreak">';
  409. if ($action == 'edit') {
  410. $doleditor = new DolEditor('nouveauxcommentaires', $object->description, '', 120, 'dolibarr_notes', 'In', 1, 1, 1, ROWS_7, '90%');
  411. $doleditor->Create(0, '');
  412. } else {
  413. print (dol_textishtml($object->description) ? $object->description : dol_nl2br($object->description, 1, true));
  414. }
  415. print '</td></tr>';
  416. // EMail
  417. //If linked user, then emails are going to be sent to users' email
  418. if (!$object->fk_user_creat) {
  419. print '<tr><td>'.$langs->trans("EMail").'</td><td>';
  420. if ($action == 'edit') {
  421. print '<input type="text" name="nouvelleadresse" class="minwith200" value="'.$object->mail_admin.'">';
  422. } else {
  423. print dol_print_email($object->mail_admin, 0, 0, 1, 0, 1, 1);
  424. }
  425. print '</td></tr>';
  426. }
  427. print '</table>';
  428. print '</div>';
  429. print '<div class="fichehalfright">';
  430. print '<div class="underbanner clearboth"></div>';
  431. print '<table class="border tableforfield centpercent">';
  432. // Expire date
  433. print '<tr><td>'.$langs->trans('ExpireDate').'</td><td>';
  434. if ($action == 'edit') {
  435. print $form->selectDate($expiredate ? $expiredate : $object->date_fin, 'expire', 0, 0, 0, '', 1, 0);
  436. } else {
  437. print dol_print_date($object->date_fin, 'day');
  438. if ($object->date_fin && $object->date_fin < dol_now() && $object->status == Opensurveysondage::STATUS_VALIDATED) {
  439. print img_warning($langs->trans("Expired"));
  440. }
  441. }
  442. print '</td></tr>';
  443. // Author
  444. print '<tr><td>';
  445. print $langs->trans("Author").'</td><td>';
  446. if ($object->fk_user_creat) {
  447. print $userstatic->getLoginUrl(-1);
  448. } else {
  449. print dol_htmlentities($object->nom_admin);
  450. }
  451. print '</td></tr>';
  452. // Link
  453. print '<tr><td>'.$langs->trans("UrlForSurvey", '').'</td><td>';
  454. // Define $urlwithroot
  455. $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
  456. $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
  457. //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
  458. $url = $urlwithouturlroot.dol_buildpath('/public/opensurvey/studs.php', 1).'?sondage='.$object->id_sondage;
  459. $urllink = '<input type="text" class="quatrevingtpercent" '.($action == 'edit' ? 'disabled' : '').' id="opensurveyurl" name="opensurveyurl" value="'.$url.'">';
  460. print $urllink;
  461. if ($action != 'edit') {
  462. print ajax_autoselect("opensurveyurl", $url, 'image');
  463. }
  464. print '</td></tr>';
  465. print '</table>';
  466. print '</div>';
  467. print '</div>';
  468. print '<div class="clearboth"></div>';
  469. print dol_get_fiche_end();
  470. print '</form>'."\n";
  471. // Buttons
  472. print '<div class="tabsAction">';
  473. print '<a class="butAction" href="exportcsv.php?id='.urlencode($numsondage).'">'.$langs->trans("ExportSpreadsheet").' (.CSV)</a>';
  474. print '</div>';
  475. // Show form to add a new field/column
  476. if (GETPOST('ajoutsujet')) {
  477. // Security check
  478. if (!$user->rights->opensurvey->write) {
  479. accessforbidden();
  480. }
  481. print '<form name="formulaire" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";
  482. print '<input type="hidden" name="token" value="'.newToken().'">';
  483. print '<input type="hidden" name="backtopage" value="'.GETPOST('backtopage', 'alpha').'">';
  484. print '<input type="hidden" name="id" value="'.GETPOST('id', 'alpha').'">';
  485. print '<input type="hidden" name="ajoutsujet" value="1">';
  486. print '<div class="center">'."\n";
  487. print "<br><br>\n";
  488. // Add new column
  489. if ($object->format == "A") {
  490. print $langs->trans("AddNewColumn").':<br><br>';
  491. print $langs->trans("Title").' <input type="text" name="nouvellecolonne" size="40"><br>';
  492. $tmparray = array('checkbox'=>$langs->trans("CheckBox"), 'yesno'=>$langs->trans("YesNoList"), 'foragainst'=>$langs->trans("PourContreList"));
  493. print $langs->trans("Type").' '.$form->selectarray("typecolonne", $tmparray, GETPOST('typecolonne')).'<br><br>';
  494. print '<input type="submit" class="button" name="ajoutercolonne" value="'.dol_escape_htmltag($langs->trans("Add")).'">';
  495. print '<input type="hidden" name="id_sondage" value="'.dol_escape_htmltag($object->id_sondage).'">';
  496. print ' &nbsp; &nbsp; ';
  497. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  498. print '<br><br>'."\n";
  499. } else {
  500. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  501. $formother = new FormOther($db);
  502. //ajout d'une date avec creneau horaire
  503. print $langs->trans("AddADate").':<br><br>'."\n";
  504. print '<select name="nouveaujour"> '."\n";
  505. print '<OPTION VALUE="vide">&nbsp;</OPTION>'."\n";
  506. for ($i = 1; $i < 32; $i++) {
  507. print '<OPTION VALUE="'.$i.'">'.$i.'</OPTION>'."\n";
  508. }
  509. print '</select>'."\n";
  510. print $formother->select_month('', 'nouveaumois', 1);
  511. print '&nbsp;';
  512. print $formother->selectyear('', 'nouvelleannee', 1, 0, 5, 0, 1);
  513. print '<br><br>'.$langs->trans("AddStartHour").': <br><br>'."\n";
  514. print '<select name="nouvelleheuredebut"> '."\n";
  515. print '<OPTION VALUE="vide">&nbsp;</OPTION>'."\n";
  516. for ($i = 0; $i < 24; $i++) {
  517. print '<OPTION VALUE="'.$i.'">'.$i.' H</OPTION>'."\n";
  518. }
  519. print '</select>'."\n";
  520. print '<select name="nouvelleminutedebut"> '."\n";
  521. print '<OPTION VALUE="vide">&nbsp;</OPTION>'."\n";
  522. print '<OPTION VALUE="00">00</OPTION>'."\n";
  523. print '<OPTION VALUE="15">15</OPTION>'."\n";
  524. print '<OPTION VALUE="30">30</OPTION>'."\n";
  525. print '<OPTION VALUE="45">45</OPTION>'."\n";
  526. print '</select>'."\n";
  527. print '<br><br>'.$langs->trans("AddEndHour").': <br><br>'."\n";
  528. print '<select name="nouvelleheurefin"> '."\n";
  529. print '<OPTION VALUE="vide">&nbsp;</OPTION>'."\n";
  530. for ($i = 0; $i < 24; $i++) {
  531. print '<OPTION VALUE="'.$i.'">'.$i.' H</OPTION>'."\n";
  532. }
  533. print '</SELECT>'."\n";
  534. print '<select name="nouvelleminutefin"> '."\n";
  535. print '<OPTION VALUE="vide">&nbsp;</OPTION>'."\n";
  536. print '<OPTION VALUE="00">00</OPTION>'."\n";
  537. print '<OPTION VALUE="15">15</OPTION>'."\n";
  538. print '<OPTION VALUE="30">30</OPTION>'."\n";
  539. print '<OPTION VALUE="45">45</OPTION>'."\n";
  540. print '</select>'."\n";
  541. print '<br><br>';
  542. print' <input type="submit" class="button" name="ajoutercolonne" value="'.dol_escape_htmltag($langs->trans("Add")).'">'."\n";
  543. print '&nbsp; &nbsp;';
  544. print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
  545. }
  546. print '</form>'."\n";
  547. print '<br><br><br><br>'."\n";
  548. print '</div>'."\n";
  549. exit;
  550. }
  551. if ($user->rights->opensurvey->write) {
  552. print '<span class="opacitymedium">';
  553. $s = $langs->trans("PollAdminDesc", '{s1}', $langs->trans("Add"));
  554. print str_replace('{s1}', img_picto('', 'delete'), $s);
  555. print '</span><br>';
  556. }
  557. $nbcolonnes = substr_count($object->sujet, ',') + 1;
  558. print '<form name="formulaire" action="" method="POST">'."\n";
  559. print '<input type="hidden" name="token" value="'.newToken().'">';
  560. print '<input type="hidden" name="page_y" value="">';
  561. print '<div class="cadre div-table-responsive-no-min"> '."\n";
  562. // Start to show survey result
  563. print '<table class="resultats">'."\n";
  564. //reformatage des données des sujets du sondage
  565. $toutsujet = explode(",", $object->sujet);
  566. $toutsujet = str_replace("°", "'", $toutsujet);
  567. print '<tr>'."\n";
  568. print '<td></td>'."\n";
  569. print '<td></td>'."\n";
  570. // loop to show the delete link
  571. if ($user->rights->opensurvey->write) {
  572. for ($i = 0; isset($toutsujet[$i]); $i++) {
  573. print '<td class=somme><input type="image" name="effacecolonne'.$i.'" src="'.img_picto('', 'delete.png', '', false, 1).'"></td>'."\n";
  574. }
  575. }
  576. print '</tr>'."\n";
  577. // Show choice titles
  578. if ($object->format == "D") {
  579. //affichage des sujets du sondage
  580. print '<tr>'."\n";
  581. print '<td></td>'."\n";
  582. print '<td></td>'."\n";
  583. //affichage des années
  584. $colspan = 1;
  585. $nbofsujet = count($toutsujet);
  586. for ($i = 0; $i < $nbofsujet; $i++) {
  587. if (isset($toutsujet[$i + 1]) && date('Y', intval($toutsujet[$i])) == date('Y', intval($toutsujet[$i + 1]))) {
  588. $colspan++;
  589. } else {
  590. print '<td colspan='.$colspan.' class="annee">'.date('Y', intval($toutsujet[$i])).'</td>'."\n";
  591. $colspan = 1;
  592. }
  593. }
  594. if ($user->rights->opensurvey->write) {
  595. print '<td class="annee">';
  596. print '<a href="'.$_SERVER["PHP_SELF"].'?ajoutsujet=1&id='.$object->id_sondage.'">'.$langs->trans("Add").'</a></td>'."\n";
  597. }
  598. print '</tr>'."\n";
  599. print '<tr>'."\n";
  600. print '<td></td>'."\n";
  601. print '<td></td>'."\n";
  602. //affichage des mois
  603. $colspan = 1;
  604. for ($i = 0; $i < $nbofsujet; $i++) {
  605. $cur = intval($toutsujet[$i]); // intval() est utiliser pour supprimer le suffixe @* qui déplaît logiquement à strftime()
  606. if (isset($toutsujet[$i + 1]) === false) {
  607. $next = false;
  608. } else {
  609. $next = intval($toutsujet[$i + 1]);
  610. }
  611. if ($next && dol_print_date($cur, "%B") == dol_print_date($next, "%B") && dol_print_date($cur, "%Y") == dol_print_date($next, "%Y")) {
  612. $colspan++;
  613. } else {
  614. print '<td colspan='.$colspan.' class="mois">'.dol_print_date($cur, "%B").'</td>'."\n";
  615. $colspan = 1;
  616. }
  617. }
  618. if ($user->rights->opensurvey->write) {
  619. print '<td class="mois"><a href="'.$_SERVER["PHP_SELF"].'?ajoutsujet=1&id='.$object->id_sondage.'">'.$langs->trans("Add").'</a></td>'."\n";
  620. }
  621. print '</tr>'."\n";
  622. print '<tr>'."\n";
  623. print '<td></td>'."\n";
  624. print '<td></td>'."\n";
  625. //affichage des jours
  626. $colspan = 1;
  627. for ($i = 0; $i < $nbofsujet; $i++) {
  628. $cur = intval($toutsujet[$i]);
  629. if (isset($toutsujet[$i + 1]) === false) {
  630. $next = false;
  631. } else {
  632. $next = intval($toutsujet[$i + 1]);
  633. }
  634. if ($next && dol_print_date($cur, "%a %d") == dol_print_date($next, "%a %d") && dol_print_date($cur, "%B") == dol_print_date($next, "%B")) {
  635. $colspan++;
  636. } else {
  637. print '<td colspan='.$colspan.' class="jour">'.dol_print_date($cur, "%a %d").'</td>'."\n";
  638. $colspan = 1;
  639. }
  640. }
  641. if ($user->rights->opensurvey->write) {
  642. print '<td class="jour"><a href="'.$_SERVER["PHP_SELF"].'?ajoutsujet=1&id='.$object->id_sondage.'">'.$langs->trans("Add").'</a></td>'."\n";
  643. }
  644. print '</tr>'."\n";
  645. //affichage des horaires
  646. if (strpos($object->sujet, '@') !== false) {
  647. print '<tr>'."\n";
  648. print '<td></td>'."\n";
  649. print '<td></td>'."\n";
  650. for ($i = 0; isset($toutsujet[$i]); $i++) {
  651. $heures = explode('@', $toutsujet[$i]);
  652. if (isset($heures[1])) {
  653. print '<td class="heure">'.dol_htmlentities($heures[1]).'</td>'."\n";
  654. } else {
  655. print '<td class="heure"></td>'."\n";
  656. }
  657. }
  658. if ($user->rights->opensurvey->write) {
  659. print '<td class="heure"><a href="'.$_SERVER["PHP_SELF"].'?ajoutsujet=1&id='.$object->id_sondage.'">'.$langs->trans("Add").'</a></td>'."\n";
  660. }
  661. print '</tr>'."\n";
  662. }
  663. } else {
  664. // Show titles
  665. print '<tr>'."\n";
  666. print '<td></td>'."\n";
  667. print '<td></td>'."\n";
  668. for ($i = 0; isset($toutsujet[$i]); $i++) {
  669. $tmp = explode('@', $toutsujet[$i]);
  670. print '<td class="sujet">'.dol_htmlentities($tmp[0]).'</td>'."\n";
  671. }
  672. print '<td class="sujet"><a href="'.$_SERVER["PHP_SELF"].'?id='.$numsondage.'&ajoutsujet=1&backtopage='.urlencode($_SERVER["PHP_SELF"]).'"><span class="fa fa-plus-circle valignmiddle btnTitle-icon"></span></a></td>'."\n";
  673. print '</tr>'."\n";
  674. }
  675. // Loop on each answer
  676. $sumfor = array();
  677. $sumagainst = array();
  678. $compteur = 0;
  679. $sql = "SELECT id_users, nom as name, id_sondage, reponses";
  680. $sql .= " FROM ".MAIN_DB_PREFIX."opensurvey_user_studs";
  681. $sql .= " WHERE id_sondage = '".$db->escape($numsondage)."'";
  682. dol_syslog('sql='.$sql);
  683. $resql = $db->query($sql);
  684. if (!$resql) {
  685. dol_print_error($db);
  686. exit;
  687. }
  688. $num = $db->num_rows($resql);
  689. while ($compteur < $num) {
  690. $obj = $db->fetch_object($resql);
  691. $ensemblereponses = $obj->reponses;
  692. print '<tr><td>'."\n";
  693. if ($user->rights->opensurvey->write) {
  694. print '<input type="image" class="reposition" name="effaceligne'.$compteur.'" src="'.img_picto('', 'delete.png', '', false, 1).'">'."\n";
  695. }
  696. // Name
  697. print '</td><td class="nom">'.dol_htmlentities($obj->name).'</td>'."\n";
  698. // si la ligne n'est pas a changer, on affiche les données
  699. if (!$testligneamodifier) {
  700. for ($i = 0; $i < $nbcolonnes; $i++) {
  701. $car = substr($ensemblereponses, $i, 1);
  702. //print 'xx'.$i."-".$car.'-'.$listofanswers[$i]['format'].'zz';
  703. if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst'))) {
  704. if (((string) $car) == "1") {
  705. print '<td class="ok">OK</td>'."\n";
  706. } else {
  707. print '<td class="non">KO</td>'."\n";
  708. }
  709. // Total
  710. if (!isset($sumfor[$i])) {
  711. $sumfor[$i] = 0;
  712. }
  713. if (((string) $car) == "1") {
  714. $sumfor[$i]++;
  715. }
  716. }
  717. if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno') {
  718. if (((string) $car) == "1") {
  719. print '<td class="ok">'.$langs->trans("Yes").'</td>'."\n";
  720. } elseif (((string) $car) == "0") {
  721. print '<td class="non">'.$langs->trans("No").'</td>'."\n";
  722. } else {
  723. print '<td class="vide">&nbsp;</td>'."\n";
  724. }
  725. // Total
  726. if (!isset($sumfor[$i])) {
  727. $sumfor[$i] = 0;
  728. }
  729. if (!isset($sumagainst[$i])) {
  730. $sumagainst[$i] = 0;
  731. }
  732. if (((string) $car) == "1") {
  733. $sumfor[$i]++;
  734. }
  735. if (((string) $car) == "0") {
  736. $sumagainst[$i]++;
  737. }
  738. }
  739. if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst') {
  740. if (((string) $car) == "1") {
  741. print '<td class="ok">'.$langs->trans("For").'</td>'."\n";
  742. } elseif (((string) $car) == "0") {
  743. print '<td class="non">'.$langs->trans("Against").'</td>'."\n";
  744. } else {
  745. print '<td class="vide">&nbsp;</td>'."\n";
  746. }
  747. // Total
  748. if (!isset($sumfor[$i])) {
  749. $sumfor[$i] = 0;
  750. }
  751. if (!isset($sumagainst[$i])) {
  752. $sumagainst[$i] = 0;
  753. }
  754. if (((string) $car) == "1") {
  755. $sumfor[$i]++;
  756. }
  757. if (((string) $car) == "0") {
  758. $sumagainst[$i]++;
  759. }
  760. }
  761. }
  762. } else {
  763. //sinon on remplace les choix de l'utilisateur par une ligne de checkbox pour recuperer de nouvelles valeurs
  764. if ($compteur == $ligneamodifier) {
  765. for ($i = 0; $i < $nbcolonnes; $i++) {
  766. $car = substr($ensemblereponses, $i, 1);
  767. print '<td class="vide">';
  768. if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst'))) {
  769. print '<input type="checkbox" name="choix'.$i.'" value="1" ';
  770. if ($car == '1') {
  771. print 'checked';
  772. }
  773. print '>';
  774. }
  775. if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno') {
  776. $arraychoice = array('2'=>'&nbsp;', '0'=>$langs->trans("No"), '1'=>$langs->trans("Yes"));
  777. print $form->selectarray("choix".$i, $arraychoice, $car);
  778. }
  779. if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst') {
  780. $arraychoice = array('2'=>'&nbsp;', '0'=>$langs->trans("Against"), '1'=>$langs->trans("For"));
  781. print $form->selectarray("choix".$i, $arraychoice, $car);
  782. }
  783. print '</td>'."\n";
  784. }
  785. } else {
  786. for ($i = 0; $i < $nbcolonnes; $i++) {
  787. $car = substr($ensemblereponses, $i, 1);
  788. if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst'))) {
  789. if (((string) $car) == "1") {
  790. print '<td class="ok">OK</td>'."\n";
  791. } else {
  792. print '<td class="non">KO</td>'."\n";
  793. }
  794. // Total
  795. if (!isset($sumfor[$i])) {
  796. $sumfor[$i] = 0;
  797. }
  798. if (((string) $car) == "1") {
  799. $sumfor[$i]++;
  800. }
  801. }
  802. if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno') {
  803. if (((string) $car) == "1") {
  804. print '<td class="ok">'.$langs->trans("For").'</td>'."\n";
  805. } elseif (((string) $car) == "0") {
  806. print '<td class="non">'.$langs->trans("Against").'</td>'."\n";
  807. } else {
  808. print '<td class="vide">&nbsp;</td>'."\n";
  809. }
  810. // Total
  811. if (!isset($sumfor[$i])) {
  812. $sumfor[$i] = 0;
  813. }
  814. if (!isset($sumagainst[$i])) {
  815. $sumagainst[$i] = 0;
  816. }
  817. if (((string) $car) == "1") {
  818. $sumfor[$i]++;
  819. }
  820. if (((string) $car) == "0") {
  821. $sumagainst[$i]++;
  822. }
  823. }
  824. if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst') {
  825. if (((string) $car) == "1") {
  826. print '<td class="ok">'.$langs->trans("For").'</td>'."\n";
  827. } elseif (((string) $car) == "0") {
  828. print '<td class="non">'.$langs->trans("Against").'</td>'."\n";
  829. } else {
  830. print '<td class="vide">&nbsp;</td>'."\n";
  831. }
  832. // Total
  833. if (!isset($sumfor[$i])) {
  834. $sumfor[$i] = 0;
  835. }
  836. if (!isset($sumagainst[$i])) {
  837. $sumagainst[$i] = 0;
  838. }
  839. if (((string) $car) == "1") {
  840. $sumfor[$i]++;
  841. }
  842. if (((string) $car) == "0") {
  843. $sumagainst[$i]++;
  844. }
  845. }
  846. }
  847. }
  848. }
  849. // Button edit at end of line
  850. if ($compteur != $ligneamodifier && ($user->rights->opensurvey->write)) {
  851. print '<td class="casevide"><input type="submit" class="button reposition" name="modifierligne'.$compteur.'" value="'.dol_escape_htmltag($langs->trans("Edit")).'"></td>'."\n";
  852. }
  853. //demande de confirmation pour modification de ligne
  854. for ($i = 0; $i < $nblines; $i++) {
  855. if (GETPOSTISSET("modifierligne".$i)) {
  856. if ($compteur == $i) {
  857. print '<td class="casevide">';
  858. print '<input type="hidden" name="idtomodify'.$compteur.'" value="'.$obj->id_users.'">';
  859. print '<input type="submit" class="button button-save reposition" name="validermodifier'.$compteur.'" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  860. print '</td>'."\n";
  861. }
  862. }
  863. }
  864. $compteur++;
  865. print '</tr>'."\n";
  866. }
  867. // Add line to add new record
  868. if (empty($testligneamodifier)) {
  869. print '<tr>'."\n";
  870. print '<td></td>'."\n";
  871. print '<td class="nom">'."\n";
  872. print '<input type="text" class="maxwidthonsmartphone" placeholder="'.dol_escape_htmltag($langs->trans("Name")).'" name="nom" maxlength="64">'."\n";
  873. print '</td>'."\n";
  874. for ($i = 0; $i < $nbcolonnes; $i++) {
  875. print '<td class="vide">';
  876. if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst'))) {
  877. print '<input type="checkbox" name="choix'.$i.'" value="1"';
  878. if (GETPOSTISSET('choix'.$i) && GETPOST('choix'.$i) == '1') {
  879. print ' checked';
  880. }
  881. print '>';
  882. }
  883. if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno') {
  884. $arraychoice = array('2'=>'&nbsp;', '0'=>$langs->trans("No"), '1'=>$langs->trans("Yes"));
  885. print $form->selectarray("choix".$i, $arraychoice);
  886. }
  887. if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst') {
  888. $arraychoice = array('2'=>'&nbsp;', '0'=>$langs->trans("Against"), '1'=>$langs->trans("For"));
  889. print $form->selectarray("choix".$i, $arraychoice);
  890. }
  891. print '</td>'."\n";
  892. }
  893. // Affichage du bouton de formulaire pour inscrire un nouvel utilisateur dans la base
  894. print '<td><input type="image" name="boutonp" class="borderimp" value="'.$langs->trans("Vote").'" src="'.img_picto('', 'edit_add', '', false, 1).'"></td>'."\n";
  895. print '</tr>'."\n";
  896. }
  897. // Select value of best choice (for checkbox columns only)
  898. $nbofcheckbox = 0;
  899. for ($i = 0; $i < $nbcolonnes + 1; $i++) {
  900. if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst'))) {
  901. $nbofcheckbox++;
  902. }
  903. if (isset($sumfor[$i])) {
  904. if ($i == 0) {
  905. $meilleurecolonne = $sumfor[$i];
  906. }
  907. if (isset($sumfor[$i]) && $sumfor[$i] > $meilleurecolonne) {
  908. $meilleurecolonne = $sumfor[$i];
  909. }
  910. }
  911. }
  912. // Show line total
  913. print '<tr>'."\n";
  914. print '<td></td>'."\n";
  915. print '<td class="center">'.$langs->trans("Total").'</td>'."\n";
  916. for ($i = 0; $i < $nbcolonnes; $i++) {
  917. $showsumfor = isset($sumfor[$i]) ? $sumfor[$i] : '';
  918. $showsumagainst = isset($sumagainst[$i]) ? $sumagainst[$i] : '';
  919. if (empty($showsumfor)) {
  920. $showsumfor = 0;
  921. }
  922. if (empty($showsumagainst)) {
  923. $showsumagainst = 0;
  924. }
  925. print '<td>';
  926. if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst'))) {
  927. print $showsumfor;
  928. }
  929. if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno') {
  930. print $langs->trans("Yes").': '.$showsumfor.'<br>'.$langs->trans("No").': '.$showsumagainst;
  931. }
  932. if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst') {
  933. print $langs->trans("For").': '.$showsumfor.'<br>'.$langs->trans("Against").': '.$showsumagainst;
  934. }
  935. print '</td>'."\n";
  936. }
  937. print '</tr>';
  938. // Show picto winner
  939. if ($nbofcheckbox >= 2) {
  940. print '<tr>'."\n";
  941. print '<td></td>'."\n";
  942. print '<td></td>'."\n";
  943. for ($i = 0; $i < $nbcolonnes; $i++) {
  944. if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst')) && isset($sumfor[$i]) && isset($meilleurecolonne) && $sumfor[$i] == $meilleurecolonne) {
  945. print '<td class="somme"><img src="'.dol_buildpath('/opensurvey/img/medaille.png', 1).'"></td>'."\n";
  946. } else {
  947. print '<td class="somme"></td>'."\n";
  948. }
  949. }
  950. print '</tr>'."\n";
  951. }
  952. // S'il a oublié de remplir un nom
  953. if (GETPOSTISSET("boutonp") && GETPOST("nom") == "") {
  954. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Name")), null, 'errors');
  955. }
  956. if (isset($erreur_prenom) && $erreur_prenom) {
  957. setEventMessages($langs->trans('VoteNameAlreadyExists'), null, 'errors');
  958. }
  959. if (isset($erreur_ajout_date) && $erreur_ajout_date) {
  960. setEventMessages($langs->trans("ErrorWrongDate"), null, 'errors');
  961. }
  962. //fin du tableau
  963. print '</table>'."\n";
  964. print '</div>'."\n";
  965. $toutsujet = explode(",", $object->sujet); // With old versions, this field was not set
  966. $compteursujet = 0;
  967. $meilleursujet = '';
  968. for ($i = 0; $i < $nbcolonnes; $i++) {
  969. if (isset($sumfor[$i]) === true && isset($meilleurecolonne) === true && $sumfor[$i] == $meilleurecolonne) {
  970. $meilleursujet .= ($meilleursujet ? ", " : "");
  971. if ($object->format == "D") {
  972. $meilleursujetexport = $toutsujet[$i];
  973. //var_dump($toutsujet);
  974. if (strpos($toutsujet[$i], '@') !== false) {
  975. $toutsujetdate = explode("@", $toutsujet[$i]);
  976. $meilleursujet .= dol_print_date($toutsujetdate[0], 'daytext').($toutsujetdate[0] ? ' ('.dol_print_date($toutsujetdate[0], '%A').')' : '').' - '.$toutsujetdate[1];
  977. } else {
  978. $meilleursujet .= dol_print_date((empty($toutsujet[$i]) ? 0 : $toutsujet[$i]), 'daytext').' ('.dol_print_date((empty($toutsujet[$i]) ? 0 : $toutsujet[$i]), '%A').')';
  979. }
  980. } else {
  981. $tmps = explode('@', $toutsujet[$i]);
  982. $meilleursujet .= dol_htmlentities($tmps[0]);
  983. }
  984. $compteursujet++;
  985. }
  986. }
  987. $meilleursujet = substr($meilleursujet, 1);
  988. $meilleursujet = str_replace("°", "'", $meilleursujet);
  989. // Show best choice
  990. if ($nbofcheckbox >= 2) {
  991. $vote_str = $langs->trans('votes');
  992. print '<p class="affichageresultats">'."\n";
  993. if (isset($meilleurecolonne) && $compteursujet == "1") {
  994. print "<img src=\"".DOL_URL_ROOT.'/opensurvey/img/medaille.png'."\"> ".$langs->trans('TheBestChoice').": <b>".$meilleursujet." </b>".$langs->trans("with")." <b>".$meilleurecolonne."</b> ".$vote_str.".\n";
  995. } elseif (isset($meilleurecolonne)) {
  996. print "<img src=\"".DOL_URL_ROOT.'/opensurvey/img/medaille.png'."\"> ".$langs->trans('TheBestChoices').": <b>".$meilleursujet." </b>".$langs->trans("with")." <b>".$meilleurecolonne."</b> ".$vote_str.".\n";
  997. }
  998. print '<br></p><br>'."\n";
  999. }
  1000. print '</form>'."\n";
  1001. print '<a name="bas"></a>'."\n";
  1002. llxFooter();
  1003. $db->close();