dolibarr/htdocs/public/opensurvey/studs.php

798 lines
24 KiB
PHP
Raw Normal View History

<?php
/* Copyright (C) 2013-2015 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/public/opensurvey/studs.php
* \ingroup opensurvey
* \brief Page to list surveys
*/
2021-02-26 18:58:34 +01:00
if (!defined('NOLOGIN')) {
define("NOLOGIN", 1); // This means this output page does not require to be logged.
}
if (!defined('NOCSRFCHECK')) {
define("NOCSRFCHECK", 1); // We accept to go on this page from external web site.
}
if (!defined('NOBROWSERNOTIF')) {
define('NOBROWSERNOTIF', '1');
}
if (!defined('NOIPCHECK')) {
define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
}
2018-07-26 11:57:25 +02:00
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
require_once DOL_DOCUMENT_ROOT."/core/lib/files.lib.php";
require_once DOL_DOCUMENT_ROOT."/opensurvey/class/opensurveysondage.class.php";
require_once DOL_DOCUMENT_ROOT."/opensurvey/lib/opensurvey.lib.php";
// Init vars
$action = GETPOST('action', 'aZ09');
$numsondage = '';
2021-02-26 18:58:34 +01:00
if (GETPOST('sondage')) {
$numsondage = GETPOST('sondage', 'alpha');
2013-06-05 16:24:32 +02:00
}
$object = new Opensurveysondage($db);
$result = $object->fetch(0, $numsondage);
$nblines = $object->fetch_lines();
2014-01-05 21:54:12 +01:00
//If the survey has not yet finished, then it can be modified
$canbemodified = ((empty($object->date_fin) || $object->date_fin > dol_now()) && $object->status != Opensurveysondage::STATUS_CLOSED);
2014-01-05 21:54:12 +01:00
2017-05-23 15:51:39 +02:00
// Security check
2021-02-26 18:58:34 +01:00
if (empty($conf->opensurvey->enabled)) {
accessforbidden('', 0, 0, 1);
}
2017-05-23 15:51:39 +02:00
/*
* Actions
*/
$nbcolonnes = substr_count($object->sujet, ',') + 1;
$listofvoters = explode(',', $_SESSION["savevoter"]);
// Add comment
2021-02-26 18:58:34 +01:00
if (GETPOST('ajoutcomment', 'alpha')) {
if (!$canbemodified) {
accessforbidden('', 0, 0, 1);
}
2014-03-05 11:52:51 +01:00
$error = 0;
2022-02-24 18:29:24 +01:00
$comment = GETPOST("comment", 'alphanohtml');
$comment_user = GETPOST('commentuser', 'alphanohtml');
2021-02-26 18:58:34 +01:00
if (!$comment) {
$error++;
2015-10-17 17:09:34 +02:00
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Comment")), null, 'errors');
}
2021-02-26 18:58:34 +01:00
if (!$comment_user) {
$error++;
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Name")), null, 'errors');
}
2021-02-26 18:58:34 +01:00
if (!in_array($comment_user, $listofvoters)) {
setEventMessages($langs->trans("UserMustBeSameThanUserUsedToVote"), null, 'errors');
$error++;
}
2021-02-26 18:58:34 +01:00
if (!$error) {
$resql = $object->addComment($comment, $comment_user);
2014-03-05 11:52:51 +01:00
2021-02-26 18:58:34 +01:00
if (!$resql) {
dol_print_error($db);
}
}
}
// Add vote
2021-02-26 18:58:34 +01:00
if (GETPOST("boutonp") || GETPOST("boutonp.x") || GETPOST("boutonp_x")) { // boutonp for chrome, boutonp_x for firefox
if (!$canbemodified) {
accessforbidden('', 0, 0, 1);
}
2014-03-05 11:52:51 +01:00
//Si le nom est bien entré
if (GETPOST('nom', 'alphanohtml')) {
$nouveauchoix = '';
2021-02-26 18:58:34 +01:00
for ($i = 0; $i < $nbcolonnes; $i++) {
2020-11-30 14:47:07 +01:00
if (GETPOSTISSET("choix$i") && GETPOST("choix$i") == '1') {
$nouveauchoix .= "1";
2020-11-30 14:47:07 +01:00
} elseif (GETPOSTISSET("choix$i") && GETPOST("choix$i") == '2') {
$nouveauchoix .= "2";
2020-11-30 14:47:07 +01:00
} else {
$nouveauchoix .= "0";
}
}
$nom = substr(GETPOST("nom", 'alphanohtml'), 0, 64);
2017-06-18 12:48:58 +02:00
// Check if vote already exists
$sql = 'SELECT id_users, nom as name';
$sql .= ' FROM '.MAIN_DB_PREFIX.'opensurvey_user_studs';
$sql .= " WHERE id_sondage='".$db->escape($numsondage)."' AND nom = '".$db->escape($nom)."' ORDER BY id_users";
$resql = $db->query($sql);
2021-02-26 18:58:34 +01:00
if (!$resql) {
dol_print_error($db);
}
2017-06-18 12:48:58 +02:00
$num_rows = $db->num_rows($resql);
2021-02-26 18:58:34 +01:00
if ($num_rows > 0) {
2015-12-20 10:36:20 +01:00
setEventMessages($langs->trans("VoteNameAlreadyExists"), null, 'errors');
$error++;
2020-05-21 15:05:19 +02:00
} else {
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'opensurvey_user_studs (nom, id_sondage, reponses)';
$sql .= " VALUES ('".$db->escape($nom)."', '".$db->escape($numsondage)."','".$db->escape($nouveauchoix)."')";
$resql = $db->query($sql);
2021-02-26 18:58:34 +01:00
if ($resql) {
// Add voter to session
$_SESSION["savevoter"] = $nom.','.(empty($_SESSION["savevoter"]) ? '' : $_SESSION["savevoter"]); // Save voter
$listofvoters = explode(',', $_SESSION["savevoter"]);
2021-02-26 18:58:34 +01:00
if ($object->mailsonde) {
if ($object->fk_user_creat) {
$userstatic = new User($db);
$userstatic->fetch($object->fk_user_creat);
2014-03-05 11:52:51 +01:00
$email = $userstatic->email;
} else {
$email = $object->mail_admin;
}
2014-03-05 11:52:51 +01:00
//Linked user may not have an email set
if ($email) {
include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
2014-03-05 11:52:51 +01:00
2018-12-11 10:52:59 +01:00
$application = ($conf->global->MAIN_APPLICATION_TITLE ? $conf->global->MAIN_APPLICATION_TITLE : 'Dolibarr ERP/CRM');
2014-03-05 11:52:51 +01:00
$link = getUrlSondage($numsondage, true);
$link = '<a href="'.$link.'">'.$link.'</a>';
$body = str_replace('\n', '<br>', $langs->transnoentities('EmailSomeoneVoted', $nom, $link));
2018-12-11 10:52:59 +01:00
//var_dump($body);exit;
$cmailfile = new CMailFile("[".$application."] ".$langs->trans("Poll").': '.$object->title, $email, $conf->global->MAIN_MAIL_EMAIL_FROM, $body, null, null, null, '', '', 0, -1);
$result = $cmailfile->sendfile();
}
}
2021-02-26 18:58:34 +01:00
} else {
dol_print_error($db);
}
}
2020-05-21 15:05:19 +02:00
} else {
2015-10-17 17:09:34 +02:00
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Name")), null, 'errors');
}
}
// Update vote
2013-06-05 16:24:32 +02:00
$testmodifier = false;
$testligneamodifier = false;
$ligneamodifier = -1;
2021-02-26 18:58:34 +01:00
for ($i = 0; $i < $nblines; $i++) {
if (GETPOSTISSET('modifierligne'.$i)) {
$ligneamodifier = $i;
$testligneamodifier = true;
2013-06-05 16:24:32 +02:00
}
2015-12-20 10:36:20 +01:00
//test to see if a line is to be modified
2021-02-26 18:58:34 +01:00
if (GETPOSTISSET('validermodifier'.$i)) {
$modifier = $i;
$testmodifier = true;
2013-06-05 16:24:32 +02:00
}
}
2021-02-26 18:58:34 +01:00
if ($testmodifier) {
2013-06-05 16:24:32 +02:00
$nouveauchoix = '';
2021-02-26 18:58:34 +01:00
for ($i = 0; $i < $nbcolonnes; $i++) {
2020-11-30 14:47:07 +01:00
if (GETPOSTISSET("choix".$i) && GETPOST("choix".$i) == '1') {
$nouveauchoix .= "1";
2020-11-30 14:47:07 +01:00
} elseif (GETPOSTISSET("choix".$i) && GETPOST("choix".$i) == '2') {
$nouveauchoix .= "2";
2020-11-30 14:47:07 +01:00
} else {
$nouveauchoix .= "0";
2013-06-05 16:24:32 +02:00
}
}
2014-03-05 11:52:51 +01:00
2021-02-26 18:58:34 +01:00
if (!$canbemodified) {
accessforbidden('', 0, 0, 1);
}
2013-06-05 16:24:32 +02:00
2021-03-24 19:53:31 +01:00
$idtomodify = GETPOST("idtomodify".$modifier);
2013-06-05 16:24:32 +02:00
$sql = 'UPDATE '.MAIN_DB_PREFIX."opensurvey_user_studs";
$sql .= " SET reponses = '".$db->escape($nouveauchoix)."'";
$sql .= " WHERE id_users = '".$db->escape($idtomodify)."'";
2013-06-05 16:24:32 +02:00
$resql = $db->query($sql);
2021-02-26 18:58:34 +01:00
if (!$resql) {
dol_print_error($db);
}
}
2013-06-05 16:24:32 +02:00
// Delete comment
$idcomment = GETPOST('deletecomment', 'int');
2021-02-26 18:58:34 +01:00
if ($idcomment) {
if (!$canbemodified) {
accessforbidden('', 0, 0, 1);
}
2014-03-05 11:52:51 +01:00
$resql = $object->deleteComment($idcomment);
2013-06-05 16:24:32 +02:00
}
/*
* View
*/
$form = new Form($db);
$arrayofjs = array();
$arrayofcss = array('/opensurvey/css/style.css');
2020-03-20 21:16:52 +01:00
llxHeaderSurvey($object->title, "", 0, 0, $arrayofjs, $arrayofcss, $numsondage);
2013-06-05 16:24:32 +02:00
2021-02-26 18:58:34 +01:00
if (empty($object->ref)) { // For survey, id is a hex string
$langs->load("errors");
print $langs->trans("ErrorRecordNotFound");
2016-09-12 02:47:36 +02:00
llxFooterSurvey();
2016-09-12 02:47:36 +02:00
$db->close();
exit();
2016-09-12 02:47:36 +02:00
}
2013-06-05 16:24:32 +02:00
// Define format of choices
$toutsujet = explode(",", $object->sujet);
$listofanswers = array();
2021-02-26 18:58:34 +01:00
foreach ($toutsujet as $value) {
$tmp = explode('@', $value);
$listofanswers[] = array('label'=>$tmp[0], 'format'=>($tmp[1] ? $tmp[1] : 'checkbox'));
}
$toutsujet = str_replace("°", "'", $toutsujet);
2020-03-20 21:16:52 +01:00
print '<div class="survey_invitation">'.$langs->trans("YouAreInivitedToVote").'</div>';
print $langs->trans("OpenSurveyHowTo").'<br>';
if (empty($object->allow_spy)) {
print '<span class="opacitymedium">'.$langs->trans("YourVoteIsPrivate").'</span><br>';
} else {
print $form->textwithpicto('<span class="opacitymedium">'.$langs->trans("YourVoteIsPublic").'</span>', $langs->trans("CanSeeOthersVote")).'<br>';
}
print '<br>';
print '<div class="corps"> '."\n";
// show title of survey
$titre = str_replace("\\", "", $object->title);
2022-03-09 11:02:35 +01:00
print '<strong>'.dol_htmlentities($titre).'</strong>';
// show description of survey
2021-02-26 18:58:34 +01:00
if ($object->description) {
2022-03-09 11:02:35 +01:00
print '<br><br>'."\n";
print dol_htmlentitiesbr($object->description);
print '<br>'."\n";
}
print '</div>'."\n";
2014-01-05 21:54:12 +01:00
//The survey has expired, users can't vote or do any action
if (!$canbemodified) {
2021-10-19 16:26:43 +02:00
print '<br><center><div class="quatrevingtpercent center warning">'.$langs->trans('SurveyExpiredInfo').'</div></center>';
2014-01-05 21:54:12 +01:00
llxFooterSurvey();
$db->close();
2017-02-08 12:52:31 +01:00
exit;
2014-01-05 21:54:12 +01:00
}
print '<div class="cadre"> '."\n";
print '<br><br>'."\n";
// Start to show survey result
print '<table class="resultats">'."\n";
// Show choice titles
2021-02-26 18:58:34 +01:00
if ($object->format == "D") {
2015-12-20 10:36:20 +01:00
//display of survey topics
print '<tr>'."\n";
print '<td></td>'."\n";
2015-12-20 10:36:20 +01:00
//display of years
$colspan = 1;
$nbofsujet = count($toutsujet);
2021-02-26 18:58:34 +01:00
for ($i = 0; $i < $nbofsujet; $i++) {
if (isset($toutsujet[$i + 1]) && date('Y', intval($toutsujet[$i])) == date('Y', intval($toutsujet[$i + 1]))) {
$colspan++;
} else {
print '<td colspan='.$colspan.' class="annee">'.date('Y', intval($toutsujet[$i])).'</td>'."\n";
$colspan = 1;
}
}
print '</tr>'."\n";
print '<tr>'."\n";
print '<td></td>'."\n";
2015-12-20 10:36:20 +01:00
//display of months
$colspan = 1;
for ($i = 0; $i < $nbofsujet; $i++) {
$cur = intval($toutsujet[$i]); // intval() est utiliser pour supprimer le suffixe @* qui déplaît logiquement à strftime()
if (isset($toutsujet[$i + 1]) === false) {
$next = false;
} else {
$next = intval($toutsujet[$i + 1]);
}
if ($next && dol_print_date($cur, "%B") == dol_print_date($next, "%B") && dol_print_date($cur, "%Y") == dol_print_date($next, "%Y")) {
$colspan++;
} else {
print '<td colspan='.$colspan.' class="mois">'.dol_print_date($cur, "%B").'</td>'."\n";
$colspan = 1;
}
}
print '</tr>'."\n";
print '<tr>'."\n";
print '<td></td>'."\n";
2015-12-20 10:36:20 +01:00
//display of days
$colspan = 1;
for ($i = 0; $i < $nbofsujet; $i++) {
$cur = intval($toutsujet[$i]);
if (isset($toutsujet[$i + 1]) === false) {
$next = false;
} else {
$next = intval($toutsujet[$i + 1]);
}
if ($next && dol_print_date($cur, "%a %e") == dol_print_date($next, "%a %e") && dol_print_date($cur, "%B") == dol_print_date($next, "%B")) {
$colspan++;
} else {
print '<td colspan="'.$colspan.'" class="jour">'.dol_print_date($cur, "%a %e").'</td>'."\n";
$colspan = 1;
}
}
print '</tr>'."\n";
2015-12-20 10:36:20 +01:00
//Display schedules
if (strpos($object->sujet, '@') !== false) {
print '<tr>'."\n";
print '<td></td>'."\n";
for ($i = 0; isset($toutsujet[$i]); $i++) {
$heures = explode('@', $toutsujet[$i]);
if (isset($heures[1])) {
print '<td class="heure">'.dol_htmlentities($heures[1]).'</td>'."\n";
} else {
print '<td class="heure"></td>'."\n";
}
}
print '</tr>'."\n";
}
2020-05-21 15:05:19 +02:00
} else {
2015-12-20 10:36:20 +01:00
//display of survey topics
print '<tr>'."\n";
print '<td></td>'."\n";
2021-02-26 18:58:34 +01:00
for ($i = 0; isset($toutsujet[$i]); $i++) {
$tmp = explode('@', $toutsujet[$i]);
2020-09-19 04:18:51 +02:00
print '<td class="sujet">'.dol_escape_htmltag($tmp[0]).'</td>'."\n";
}
print '</tr>'."\n";
}
// Loop on each answer
$sumfor = array();
$sumagainst = array();
$compteur = 0;
$sql = "SELECT id_users, nom as name, id_sondage, reponses";
$sql .= " FROM ".MAIN_DB_PREFIX."opensurvey_user_studs";
$sql .= " WHERE id_sondage = '".$db->escape($numsondage)."'";
$resql = $db->query($sql);
2021-02-26 18:58:34 +01:00
if (!$resql) {
dol_print_error($db);
exit;
}
$num = $db->num_rows($resql);
2021-02-26 18:58:34 +01:00
while ($compteur < $num) {
$obj = $db->fetch_object($resql);
$ensemblereponses = $obj->reponses;
// ligne d'un usager pré-authentifié
$mod_ok = (in_array($obj->name, $listofvoters));
if (!$mod_ok && !$object->allow_spy) {
$compteur++;
continue;
}
print '<tr>'."\n";
// Name
print '<td class="nom">'.dol_htmlentities($obj->name).'</td>'."\n";
// si la ligne n'est pas a changer, on affiche les données
2021-02-26 18:58:34 +01:00
if (!$testligneamodifier) {
for ($i = 0; $i < $nbcolonnes; $i++) {
$car = substr($ensemblereponses, $i, 1);
//print 'xx'.$i."-".$car.'-'.$listofanswers[$i]['format'].'zz';
2021-02-26 18:58:34 +01:00
if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst'))) {
if (((string) $car) == "1") {
print '<td class="ok">OK</td>'."\n";
} else {
print '<td class="non">KO</td>'."\n";
}
// Total
2021-02-26 18:58:34 +01:00
if (!isset($sumfor[$i])) {
$sumfor[$i] = 0;
}
if (((string) $car) == "1") {
$sumfor[$i]++;
}
}
2021-02-26 18:58:34 +01:00
if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno') {
if (((string) $car) == "1") {
print '<td class="ok">'.$langs->trans("Yes").'</td>'."\n";
} elseif (((string) $car) == "0") {
print '<td class="non">'.$langs->trans("No").'</td>'."\n";
} else {
print '<td class="vide">&nbsp;</td>'."\n";
}
// Total
2021-02-26 18:58:34 +01:00
if (!isset($sumfor[$i])) {
$sumfor[$i] = 0;
}
if (!isset($sumagainst[$i])) {
$sumagainst[$i] = 0;
}
if (((string) $car) == "1") {
$sumfor[$i]++;
}
if (((string) $car) == "0") {
$sumagainst[$i]++;
}
}
2021-02-26 18:58:34 +01:00
if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst') {
if (((string) $car) == "1") {
print '<td class="ok">'.$langs->trans("For").'</td>'."\n";
} elseif (((string) $car) == "0") {
print '<td class="non">'.$langs->trans("Against").'</td>'."\n";
} else {
print '<td class="vide">&nbsp;</td>'."\n";
}
// Total
2021-02-26 18:58:34 +01:00
if (!isset($sumfor[$i])) {
$sumfor[$i] = 0;
}
if (!isset($sumagainst[$i])) {
$sumagainst[$i] = 0;
}
if (((string) $car) == "1") {
$sumfor[$i]++;
}
if (((string) $car) == "0") {
$sumagainst[$i]++;
}
}
}
2020-05-21 15:05:19 +02:00
} else {
//sinon on remplace les choix de l'utilisateur par une ligne de checkbox pour recuperer de nouvelles valeurs
2021-02-26 18:58:34 +01:00
if ($compteur == $ligneamodifier) {
for ($i = 0; $i < $nbcolonnes; $i++) {
$car = substr($ensemblereponses, $i, 1);
print '<td class="vide">';
2021-02-26 18:58:34 +01:00
if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst'))) {
print '<input type="checkbox" name="choix'.$i.'" value="1" ';
2021-02-26 18:58:34 +01:00
if ($car == '1') {
print 'checked';
}
print '>';
}
2021-02-26 18:58:34 +01:00
if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno') {
$arraychoice = array('2'=>'&nbsp;', '0'=>$langs->trans("No"), '1'=>$langs->trans("Yes"));
print $form->selectarray("choix".$i, $arraychoice, $car);
}
2021-02-26 18:58:34 +01:00
if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst') {
$arraychoice = array('2'=>'&nbsp;', '0'=>$langs->trans("Against"), '1'=>$langs->trans("For"));
print $form->selectarray("choix".$i, $arraychoice, $car);
}
print '</td>'."\n";
}
2020-05-21 15:05:19 +02:00
} else {
2021-02-26 18:58:34 +01:00
for ($i = 0; $i < $nbcolonnes; $i++) {
$car = substr($ensemblereponses, $i, 1);
2021-02-26 18:58:34 +01:00
if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst'))) {
if (((string) $car) == "1") {
print '<td class="ok">OK</td>'."\n";
} else {
print '<td class="non">KO</td>'."\n";
}
// Total
2021-02-26 18:58:34 +01:00
if (!isset($sumfor[$i])) {
$sumfor[$i] = 0;
}
if (((string) $car) == "1") {
$sumfor[$i]++;
}
}
2021-02-26 18:58:34 +01:00
if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno') {
if (((string) $car) == "1") {
print '<td class="ok">'.$langs->trans("For").'</td>'."\n";
} elseif (((string) $car) == "0") {
print '<td class="non">'.$langs->trans("Against").'</td>'."\n";
} else {
print '<td class="vide">&nbsp;</td>'."\n";
}
// Total
2021-02-26 18:58:34 +01:00
if (!isset($sumfor[$i])) {
$sumfor[$i] = 0;
}
if (!isset($sumagainst[$i])) {
$sumagainst[$i] = 0;
}
if (((string) $car) == "1") {
$sumfor[$i]++;
}
if (((string) $car) == "0") {
$sumagainst[$i]++;
}
}
2021-02-26 18:58:34 +01:00
if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst') {
if (((string) $car) == "1") {
print '<td class="ok">'.$langs->trans("For").'</td>'."\n";
} elseif (((string) $car) == "0") {
print '<td class="non">'.$langs->trans("Against").'</td>'."\n";
} else {
print '<td class="vide">&nbsp;</td>'."\n";
}
// Total
2021-02-26 18:58:34 +01:00
if (!isset($sumfor[$i])) {
$sumfor[$i] = 0;
}
if (!isset($sumagainst[$i])) {
$sumagainst[$i] = 0;
}
if (((string) $car) == "1") {
$sumfor[$i]++;
}
if (((string) $car) == "0") {
$sumagainst[$i]++;
}
}
}
}
}
// Button edit at end of line
2021-02-26 18:58:34 +01:00
if ($compteur != $ligneamodifier && $mod_ok) {
2020-12-09 12:32:21 +01:00
print '<td class="casevide"><input type="submit" class="button smallpaddingimp" name="modifierligne'.$compteur.'" value="'.dol_escape_htmltag($langs->trans("Edit")).'"></td>'."\n";
}
//demande de confirmation pour modification de ligne
2021-02-26 18:58:34 +01:00
for ($i = 0; $i < $nblines; $i++) {
if (GETPOSTISSET("modifierligne".$i)) {
if ($compteur == $i) {
print '<td class="casevide">';
print '<input type="hidden" name="idtomodify'.$compteur.'" value="'.$obj->id_users.'">';
print '<input type="submit" class="button button-save" name="validermodifier'.$compteur.'" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
print '</td>'."\n";
}
}
}
$compteur++;
print '</tr>'."\n";
}
// Add line to add new record
2021-02-26 18:58:34 +01:00
if ($ligneamodifier < 0 && (!isset($_SESSION['nom']))) {
print '<tr>'."\n";
print '<td class="nom">'."\n";
2021-02-26 18:58:34 +01:00
if (isset($_SESSION['nom'])) {
print '<input type=hidden name="nom" value="'.$_SESSION['nom'].'">'.$_SESSION['nom']."\n";
} else {
2021-06-13 01:27:04 +02:00
print '<input type="text" name="nom" placeholder="'.dol_escape_htmltag($langs->trans("Name")).'" maxlength="64" class=" minwidth175">'."\n";
}
print '</td>'."\n";
// affichage des cases de formulaire checkbox pour un nouveau choix
2021-02-26 18:58:34 +01:00
for ($i = 0; $i < $nbcolonnes; $i++) {
print '<td class="vide">';
2021-02-26 18:58:34 +01:00
if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst'))) {
print '<input type="checkbox" name="choix'.$i.'" value="1"';
2020-11-30 14:47:07 +01:00
if (GETPOSTISSET('choix'.$i) && GETPOST('choix'.$i) == '1') {
print ' checked';
}
print '>';
}
2021-02-26 18:58:34 +01:00
if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno') {
$arraychoice = array('2'=>'&nbsp;', '0'=>$langs->trans("No"), '1'=>$langs->trans("Yes"));
print $form->selectarray("choix".$i, $arraychoice, GETPOST('choix'.$i));
}
2021-02-26 18:58:34 +01:00
if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst') {
$arraychoice = array('2'=>'&nbsp;', '0'=>$langs->trans("Against"), '1'=>$langs->trans("For"));
print $form->selectarray("choix".$i, $arraychoice, GETPOST('choix'.$i));
}
print '</td>'."\n";
}
// Affichage du bouton de formulaire pour inscrire un nouvel utilisateur dans la base
print '<td><input type="image" class="borderimp" name="boutonp" value="'.$langs->trans("Vote").'" src="'.img_picto('', 'edit_add', '', false, 1).'"></td>'."\n";
print '</tr>'."\n";
}
// Select value of best choice (for checkbox columns only)
$nbofcheckbox = 0;
2021-02-26 18:58:34 +01:00
for ($i = 0; $i < $nbcolonnes; $i++) {
if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst'))) {
$nbofcheckbox++;
}
if (isset($sumfor[$i])) {
if ($i == 0) {
$meilleurecolonne = $sumfor[$i];
}
2021-02-26 18:58:34 +01:00
if (!isset($meilleurecolonne) || $sumfor[$i] > $meilleurecolonne) {
$meilleurecolonne = $sumfor[$i];
}
}
}
if ($object->allow_spy) {
// Show line total
print '<tr>'."\n";
print '<td class="center">'.$langs->trans("Total").'</td>'."\n";
2021-02-26 18:58:34 +01:00
for ($i = 0; $i < $nbcolonnes; $i++) {
$showsumfor = isset($sumfor[$i]) ? $sumfor[$i] : '';
$showsumagainst = isset($sumagainst[$i]) ? $sumagainst[$i] : '';
2021-02-26 18:58:34 +01:00
if (empty($showsumfor)) {
$showsumfor = 0;
}
if (empty($showsumagainst)) {
$showsumagainst = 0;
}
print '<td>';
2021-02-26 18:58:34 +01:00
if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst'))) {
print $showsumfor;
}
if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno') {
print $langs->trans("Yes").': '.$showsumfor.'<br>'.$langs->trans("No").': '.$showsumagainst;
}
if (!empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst') {
print $langs->trans("For").': '.$showsumfor.'<br>'.$langs->trans("Against").': '.$showsumagainst;
}
print '</td>'."\n";
}
print '</tr>';
// Show picto winner
2021-02-26 18:58:34 +01:00
if ($nbofcheckbox >= 2) {
print '<tr>'."\n";
print '<td class="somme"></td>'."\n";
2021-02-26 18:58:34 +01:00
for ($i = 0; $i < $nbcolonnes; $i++) {
//print 'xx'.(! empty($listofanswers[$i]['format'])).'-'.$sumfor[$i].'-'.$meilleurecolonne;
2021-02-26 18:58:34 +01:00
if (empty($listofanswers[$i]['format']) || !in_array($listofanswers[$i]['format'], array('yesno', 'foragainst')) && isset($sumfor[$i]) && isset($meilleurecolonne) && $sumfor[$i] == $meilleurecolonne) {
print '<td class="somme"><img src="'.dol_buildpath('/opensurvey/img/medaille.png', 1).'"></td>'."\n";
} else {
print '<td class="somme"></td>'."\n";
}
}
print '</tr>'."\n";
}
}
print '</table>'."\n";
print '</div>'."\n";
if ($object->allow_spy) {
$toutsujet = explode(",", $object->sujet);
$toutsujet = str_replace("°", "'", $toutsujet);
$compteursujet = 0;
$meilleursujet = '';
for ($i = 0; $i < $nbcolonnes; $i++) {
if (isset($sumfor[$i]) && isset($meilleurecolonne) && $sumfor[$i] == $meilleurecolonne) {
2022-04-01 19:30:22 +02:00
$meilleursujet .= ($meilleursujet ? ", " : "");
if ($object->format == "D") {
$meilleursujetexport = $toutsujet[$i];
if (strpos($toutsujet[$i], '@') !== false) {
$toutsujetdate = explode("@", $toutsujet[$i]);
2020-04-26 23:06:52 +02:00
$meilleursujet .= dol_print_date($toutsujetdate[0], 'daytext').' ('.dol_print_date($toutsujetdate[0], '%A').') - '.$toutsujetdate[1];
} else {
2022-04-01 19:30:22 +02:00
$meilleursujet .= dol_print_date((empty($toutsujet[$i]) ? 0 : $toutsujet[$i]), 'daytext').' ('.dol_print_date((empty($toutsujet[$i]) ? 0 : $toutsujet[$i]), '%A').')';
}
2020-05-21 15:05:19 +02:00
} else {
$tmps = explode('@', $toutsujet[$i]);
$meilleursujet .= dol_htmlentities($tmps[0]);
2013-06-05 16:24:32 +02:00
}
$compteursujet++;
}
}
$meilleursujet = substr("$meilleursujet", 1);
$meilleursujet = str_replace("°", "'", $meilleursujet);
// Show best choice
2021-02-26 18:58:34 +01:00
if ($nbofcheckbox >= 2) {
$vote_str = $langs->trans('votes');
print '<p class="affichageresultats">'."\n";
if (isset($meilleurecolonne) && $compteursujet == "1") {
2022-04-01 19:30:22 +02:00
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";
} elseif (isset($meilleurecolonne)) {
2022-04-01 19:30:22 +02:00
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";
}
print '</p><br>'."\n";
}
}
print '<br>';
2013-06-05 16:24:32 +02:00
// Comment list
2014-01-03 14:52:31 +01:00
$comments = $object->getComments();
2021-02-26 18:58:34 +01:00
if ($comments) {
print '<br><u><span class="bold opacitymedium">'.$langs->trans("CommentsOfVoters").':</span></u><br>'."\n";
2014-03-05 11:52:51 +01:00
2014-01-03 14:52:31 +01:00
foreach ($comments as $obj) {
// ligne d'un usager pré-authentifié
//$mod_ok = (in_array($obj->name, $listofvoters));
2013-06-05 16:24:32 +02:00
print '<div class="comment"><span class="usercomment">';
2021-02-26 18:58:34 +01:00
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> ';
}
//else print img_picto('', 'ellipsis-h', '', false, 0, 0, '', 'nomarginleft').' ';
2014-01-05 20:30:53 +01:00
print dol_htmlentities($obj->usercomment).':</span> <span class="comment">'.dol_nl2br(dol_htmlentities($obj->comment))."</span></div>";
2013-06-05 16:24:32 +02:00
}
}
// Form to add comment
2014-01-03 17:44:42 +01:00
if ($object->allow_comments) {
2020-12-09 12:23:37 +01:00
print '<br><div class="addcomment"><span class="opacitymedium">'.$langs->trans("AddACommentForPoll")."</span><br>\n";
2022-02-24 18:29:24 +01:00
print '<textarea name="comment" rows="'.ROWS_2.'" class="quatrevingtpercent">'.dol_escape_htmltag(GETPOST('comment', 'alphanohtml'), 0, 1).'</textarea><br>'."\n";
print $langs->trans("Name").': ';
2022-02-24 18:29:24 +01:00
print '<input type="text" name="commentuser" maxlength="64" value="'.dol_escape_htmltag(GETPOST('commentuser', 'alphanohtml')).'"> &nbsp; '."\n";
2014-01-03 17:44:42 +01:00
print '<input type="submit" class="button" name="ajoutcomment" value="'.dol_escape_htmltag($langs->trans("AddComment")).'"><br>'."\n";
print '</form>'."\n";
print '</div>'."\n"; // div add comment
2014-01-03 17:44:42 +01:00
}
2013-06-05 16:24:32 +02:00
print '<br><br>';
print '<a name="bas"></a>'."\n";
llxFooterSurvey();
$db->close();