studs.php 24 KB

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