studs.php 23 KB

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