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