diff --git a/htdocs/opensurvey/public/studs.php b/htdocs/opensurvey/public/studs.php index 4ac633e52f8..96aa63104eb 100644 --- a/htdocs/opensurvey/public/studs.php +++ b/htdocs/opensurvey/public/studs.php @@ -361,43 +361,112 @@ else // Loop on each answer -if ($object->allow_spy) { - $sumfor = array(); - $sumagainst = array(); - $compteur = 0; - $sql ="SELECT id_users, nom, id_sondage, reponses"; - $sql.=" FROM ".MAIN_DB_PREFIX."opensurvey_user_studs"; - $sql.=" WHERE id_sondage = '".$db->escape($numsondage)."'"; - dol_syslog('sql='.$sql); - $resql=$db->query($sql); - if (! $resql) - { - dol_print_error($db); - exit; +$sumfor = array(); +$sumagainst = array(); +$compteur = 0; +$sql ="SELECT id_users, nom, id_sondage, reponses"; +$sql.=" FROM ".MAIN_DB_PREFIX."opensurvey_user_studs"; +$sql.=" WHERE id_sondage = '".$db->escape($numsondage)."'"; +dol_syslog('sql='.$sql); +$resql=$db->query($sql); +if (! $resql) +{ + dol_print_error($db); + exit; +} +$num=$db->num_rows($resql); +while ($compteur < $num) +{ + $obj=$db->fetch_object($resql); + + $ensemblereponses = $obj->reponses; + + // ligne d'un usager pré-authentifié + $mod_ok = (in_array($obj->nom, $listofvoters)); + + if (!$mod_ok && !$object->allow_spy) { + $compteur++; + continue; } - $num=$db->num_rows($resql); - while ($compteur < $num) + + print ''."\n"; + + // Name + print ''.htmlentities($obj->nom).''."\n"; + + // si la ligne n'est pas a changer, on affiche les données + if (! $testligneamodifier) { - $obj=$db->fetch_object($resql); + for ($i = 0; $i < $nbcolonnes; $i++) + { + $car = substr($ensemblereponses, $i, 1); + //print 'xx'.$i."-".$car.'-'.$listofanswers[$i]['format'].'zz'; - $ensemblereponses = $obj->reponses; - - print ''."\n"; - - // ligne d'un usager pré-authentifié - $mod_ok = (! empty($nombase) && in_array($nombase, $listofvoters)); - - // Name - print ''.htmlentities($obj->nom).''."\n"; - - // si la ligne n'est pas a changer, on affiche les données - if (! $testligneamodifier) + if (empty($listofanswers[$i]['format']) || ! in_array($listofanswers[$i]['format'],array('yesno','foragainst'))) + { + if (((string) $car) == "1") print 'OK'."\n"; + else print 'KO'."\n"; + // Total + if (! isset($sumfor[$i])) $sumfor[$i] = 0; + if (((string) $car) == "1") $sumfor[$i]++; + } + if (! empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno') + { + if (((string) $car) == "1") print ''.$langs->trans("Yes").''."\n"; + else if (((string) $car) == "0") print ''.$langs->trans("No").''."\n"; + else print ' '."\n"; + // Total + 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]++; + } + if (! empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst') + { + if (((string) $car) == "1") print ''.$langs->trans("For").''."\n"; + else if (((string) $car) == "0") print ''.$langs->trans("Against").''."\n"; + else print ' '."\n"; + // Total + 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]++; + } + } + } + else + { + //sinon on remplace les choix de l'utilisateur par une ligne de checkbox pour recuperer de nouvelles valeurs + if ($compteur == $ligneamodifier) + { + for ($i = 0; $i < $nbcolonnes; $i++) + { + $car = substr($ensemblereponses, $i, 1); + print ''; + if (empty($listofanswers[$i]['format']) || ! in_array($listofanswers[$i]['format'],array('yesno','foragainst'))) + { + print ''; + } + if (! empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno') + { + $arraychoice=array('2'=>' ','0'=>$langs->trans("No"),'1'=>$langs->trans("Yes")); + print $form->selectarray("choix".$i, $arraychoice, $car); + } + if (! empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst') + { + $arraychoice=array('2'=>' ','0'=>$langs->trans("Against"),'1'=>$langs->trans("For")); + print $form->selectarray("choix".$i, $arraychoice, $car); + } + print ''."\n"; + } + } + else { for ($i = 0; $i < $nbcolonnes; $i++) { $car = substr($ensemblereponses, $i, 1); - //print 'xx'.$i."-".$car.'-'.$listofanswers[$i]['format'].'zz'; - if (empty($listofanswers[$i]['format']) || ! in_array($listofanswers[$i]['format'],array('yesno','foragainst'))) { if (((string) $car) == "1") print 'OK'."\n"; @@ -408,8 +477,8 @@ if ($object->allow_spy) { } if (! empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno') { - if (((string) $car) == "1") print ''.$langs->trans("Yes").''."\n"; - else if (((string) $car) == "0") print ''.$langs->trans("No").''."\n"; + if (((string) $car) == "1") print ''.$langs->trans("For").''."\n"; + else if (((string) $car) == "0") print ''.$langs->trans("Against").''."\n"; else print ' '."\n"; // Total if (! isset($sumfor[$i])) $sumfor[$i] = 0; @@ -430,97 +499,31 @@ if ($object->allow_spy) { } } } - else - { - //sinon on remplace les choix de l'utilisateur par une ligne de checkbox pour recuperer de nouvelles valeurs - if ($compteur == $ligneamodifier) - { - for ($i = 0; $i < $nbcolonnes; $i++) - { - $car = substr($ensemblereponses, $i, 1); - print ''; - if (empty($listofanswers[$i]['format']) || ! in_array($listofanswers[$i]['format'],array('yesno','foragainst'))) - { - print ''; - } - if (! empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno') - { - $arraychoice=array('2'=>' ','0'=>$langs->trans("No"),'1'=>$langs->trans("Yes")); - print $form->selectarray("choix".$i, $arraychoice, $car); - } - if (! empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst') - { - $arraychoice=array('2'=>' ','0'=>$langs->trans("Against"),'1'=>$langs->trans("For")); - print $form->selectarray("choix".$i, $arraychoice, $car); - } - print ''."\n"; - } - } - else - { - for ($i = 0; $i < $nbcolonnes; $i++) - { - $car = substr($ensemblereponses, $i, 1); - if (empty($listofanswers[$i]['format']) || ! in_array($listofanswers[$i]['format'],array('yesno','foragainst'))) - { - if (((string) $car) == "1") print 'OK'."\n"; - else print 'KO'."\n"; - // Total - if (! isset($sumfor[$i])) $sumfor[$i] = 0; - if (((string) $car) == "1") $sumfor[$i]++; - } - if (! empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno') - { - if (((string) $car) == "1") print ''.$langs->trans("For").''."\n"; - else if (((string) $car) == "0") print ''.$langs->trans("Against").''."\n"; - else print ' '."\n"; - // Total - 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]++; - } - if (! empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst') - { - if (((string) $car) == "1") print ''.$langs->trans("For").''."\n"; - else if (((string) $car) == "0") print ''.$langs->trans("Against").''."\n"; - else print ' '."\n"; - // Total - 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 - if ($compteur != $ligneamodifier && $mod_ok) - { - print ''."\n"; - } - - //demande de confirmation pour modification de ligne - for ($i=0; $i<$nblignes; $i++) - { - if (isset($_POST["modifierligne".$i])) - { - if ($compteur == $i) - { - print ''; - print ''; - print ''; - print ''."\n"; - } - } - } - - $compteur++; - print ''."\n"; } + + // Button edit at end of line + if ($compteur != $ligneamodifier && $mod_ok) + { + print ''."\n"; + } + + //demande de confirmation pour modification de ligne + for ($i=0; $i<$nblignes; $i++) + { + if (isset($_POST["modifierligne".$i])) + { + if ($compteur == $i) + { + print ''; + print ''; + print ''; + print ''."\n"; + } + } + } + + $compteur++; + print ''."\n"; } // Add line to add new record