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