results.php 37 KB

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