diff --git a/htdocs/opensurvey/adminstuds_preview.php b/htdocs/opensurvey/adminstuds_preview.php index d85dc37297b..c93221a2af2 100755 --- a/htdocs/opensurvey/adminstuds_preview.php +++ b/htdocs/opensurvey/adminstuds_preview.php @@ -39,7 +39,9 @@ $numsondageadmin=GETPOST("sondage"); $numsondage=substr($numsondageadmin, 0, 16); $object=new Opensurveysondage($db); -$object->fetch(0,$numsondageadmin); +$result=$object->fetch(0,$numsondage); +if ($result <= 0) dol_print_error('','Failed to get survey id '.$numsondage); + $nblignes=count($object->fetch_lines()); @@ -587,7 +589,7 @@ print ''; print '
'."\n"; print '
'."\n"; -//debut de l'affichage de résultats +// Start to show survey result print ''."\n"; //reformatage des données des sujets du sondage @@ -863,14 +865,14 @@ while ($compteur < $num) } } - //a la fin de chaque ligne se trouve les boutons modifier + // Button edit at end of line if ($compteur != $ligneamodifier) { print ''."\n"; } //demande de confirmation pour modification de ligne - for ($i = 0; $i < $nblignes; $i++) + for ($i=0; $i<$nblignes; $i++) { if (isset($_POST["modifierligne".$i])) { @@ -935,10 +937,12 @@ for ($i=0; $i < $nbcolonnes + 1; $i++) $nbofcheckbox++; if (isset($sumfor[$i])) { - if ($i == 0) { + if ($i == 0) + { $meilleurecolonne = $sumfor[$i]; } - if (isset($sumfor[$i]) && $sumfor[$i] > $meilleurecolonne){ + if (isset($sumfor[$i]) && $sumfor[$i] > $meilleurecolonne) + { $meilleurecolonne = $sumfor[$i]; } } @@ -1015,7 +1019,7 @@ $toutsujet = explode(",", $object->sujet); $compteursujet = 0; $meilleursujet = ''; for ($i = 0; $i < $nbcolonnes; $i++) { - if (isset($sumfor[$i]) === true && isset($meilleurecolonne) === true && $sumfor[$i] == $meilleurecolonne){ + if (isset($sumfor[$i]) === true && isset($meilleurecolonne) === true && $sumfor[$i] == $meilleurecolonne) { $meilleursujet.=", "; if ($object->format == "D" || $object->format == "D+") { @@ -1038,7 +1042,6 @@ for ($i = 0; $i < $nbcolonnes; $i++) { } } -//adaptation pour affichage des valeurs $meilleursujet = substr("$meilleursujet", 1); $meilleursujet = str_replace("°", "'", $meilleursujet); @@ -1046,18 +1049,20 @@ $meilleursujet = str_replace("°", "'", $meilleursujet); if ($nbofcheckbox >= 2) { $vote_str = $langs->trans('votes'); - print '

'."\n"; + print '

'."\n"; if (isset($meilleurecolonne) && $compteursujet == "1") { - print " " . $langs->trans('TheBestChoice') . " : $meilleursujet " . $langs->trans("with") . " $meilleurecolonne " . $vote_str . ".
\n"; + print " " . $langs->trans('TheBestChoice') . " : $meilleursujet " . $langs->trans("with") . " $meilleurecolonne " . $vote_str . ".\n"; } elseif (isset($meilleurecolonne)) { - print " " . $langs->trans('TheBestChoices') . " : $meilleursujet " . $langs->trans("with") . " $meilleurecolonne " . $vote_str . ".
\n"; + print " " . $langs->trans('TheBestChoices') . " : $meilleursujet " . $langs->trans("with") . " $meilleurecolonne " . $vote_str . ".\n"; } - print '


'."\n"; + print '


'."\n"; } print ''."\n"; +print ''."\n"; + llxFooterSurvey(); $db->close(); diff --git a/htdocs/opensurvey/public/studs.php b/htdocs/opensurvey/public/studs.php index 9a20b14031b..d1df65c8eea 100755 --- a/htdocs/opensurvey/public/studs.php +++ b/htdocs/opensurvey/public/studs.php @@ -51,15 +51,15 @@ $object=new Opensurveysondage($db); $result=$object->fetch(0,$numsondage); if ($result <= 0) dol_print_error('','Failed to get survey id '.$numsondage); - -$nbcolonnes = substr_count($object->sujet, ',') + 1; - +$nblignes=count($object->fetch_lines()); /* * Actions */ +$nbcolonnes = substr_count($object->sujet, ',') + 1; + $listofvoters=explode(',',$_SESSION["savevoter"]); // Add comment @@ -162,22 +162,22 @@ if (isset($_POST["boutonp"]) || isset($_POST["boutonp_x"])) // Update vote -$sql = 'SELECT * FROM '.MAIN_DB_PREFIX.'opensurvey_user_studs WHERE id_sondage='.$connect->Param('numsondage').' ORDER BY id_users'; -$sql = $connect->Prepare($sql); -$user_studs = $connect->Execute($sql, array($numsondage)); -$nblignes = $user_studs->RecordCount(); $testmodifier = false; +$testligneamodifier = false; $ligneamodifier = -1; for ($i=0; $i<$nblignes; $i++) { - if (isset($_POST['modifierligne'.$i])) { - $ligneamodifier = $i; + if (isset($_POST['modifierligne'.$i])) + { + $ligneamodifier=$i; + $testligneamodifier=true; } //test pour voir si une ligne est a modifier - if (isset($_POST['validermodifier'.$i])) { - $modifier = $i; - $testmodifier = true; + if (isset($_POST['validermodifier'.$i])) + { + $modifier=$i; + $testmodifier=true; } } @@ -200,33 +200,16 @@ if ($testmodifier) $nouveauchoix.="0"; } } + + $idtomodify=$_POST["idtomodify".$modifier]; + $sql = 'UPDATE '.MAIN_DB_PREFIX."opensurvey_user_studs"; + $sql.= " SET reponses = '".$db->escape($nouveauchoix)."'"; + $sql.= " WHERE id_users = '".$db->escape($idtomodify)."'"; - $compteur=0; - while ($data = $user_studs->FetchNextObject(false) ) - { - if ($compteur == $modifier) - { - $sql = 'UPDATE '.MAIN_DB_PREFIX."opensurvey_user_studs"; - $sql.= " SET reponses = '".$db->escape($nouveauchoix)."'"; - $sql.= " WHERE nom = '".$db->escape($data->nom)."' AND id_users = '".$db->escape($data->id_users)."'"; - $resql = $db->query($sql); - if ($resql <= 0) - { - dol_print_error($db); - exit; - } - - if ($object->mailsonde=="yes") - { - // TODO Use CMailFile - //$headers="From: ".NOMAPPLICATION." <".ADRESSEMAILADMIN.">\r\nContent-Type: text/plain; charset=\"UTF-8\"\nContent-Transfer-Encoding: 8bit"; - //mail ("$object->mail_admin", "[".NOMAPPLICATION."] " . _("Poll's participation") . " : $object->titre", "\"$data->nom\""."" . _("has filled a line.\nYou can find your poll at the link") . " :\n\n".getUrlSondage($numsondage)." \n\n" . _("Thanks for your confidence.") . "\n".NOMAPPLICATION,$headers); - } - } - - $compteur++; - } -} + dol_syslog("sql=".$sql); + $resql = $db->query($sql); + if (! $resql) dol_print_error($db); +} // Delete comment $idcomment=GETPOST('deletecomment','int'); @@ -245,30 +228,30 @@ if ($idcomment) $form=new Form($db); $object=new OpenSurveySondage($db); +$result=$object->fetch(0,$numsondage); +if ($result <= 0) +{ + print $langs->trans("ErrorRecordNotFound"); + llxFooterSurvey(); + exit; +} + $arrayofjs=array(); $arrayofcss=array('/opensurvey/css/style.css'); llxHeaderSurvey($object->titre, "", 0, 0, $arrayofjs, $arrayofcss); - -$res=$object->fetch(0,$numsondage); - -if ($res <= 0) -{ - print $langs->trans("ErrorPollDoesNotExists",$numsondage); - llxFooterSurvey(); - exit; -} + // Define format of choices $toutsujet=explode(",",$object->sujet); +$listofanswers=array(); +foreach ($toutsujet as $value) +{ + $tmp=explode('@',$value); + $listofanswers[]=array('label'=>$tmp[0],'format'=>($tmp[1]?$tmp[1]:'checkbox')); +} +$toutsujet=str_replace("@","
",$toutsujet); $toutsujet=str_replace("°","'",$toutsujet); -$listofanswers=array(); -foreach ($toutsujet as $value) -{ - $tmp=explode('@',$value); - $listofanswers[]=array('label'=>$tmp[0],'format'=>($tmp[1]?$tmp[1]:'checkbox')); -} - print '
'.$langs->trans("YouAreInivitedToVote").'
'; print $langs->trans("OpenSurveyHowTo").'

'; @@ -283,7 +266,8 @@ print ''.$titre.'
'."\n"; print $langs->trans("InitiatorOfPoll") .' : '.$object->nom_admin.'
'."\n"; //affichage des commentaires du sondage -if ($object->commentaires) { +if ($object->commentaires) +{ print '
'.$langs->trans("Description") .' :
'."\n"; $commentaires=dol_nl2br($object->commentaires); print $commentaires; @@ -294,19 +278,14 @@ print ''."\n"; print ''."\n"; print ''; -// Todo : add CSRF protection + print '
'."\n"; print '

'."\n"; -// Debut de l'affichage des resultats du sondage +// Start to show survey result print '
'."\n"; -//recuperation des utilisateurs du sondage -$sql = 'SELECT * FROM '.MAIN_DB_PREFIX.'opensurvey_user_studs WHERE id_sondage='.$connect->Param('numsondage').' ORDER BY id_users'; -$sql = $connect->Prepare($sql); -$user_studs = $connect->Execute($sql, array($numsondage)); - -//si le sondage est un sondage de date +// Show choice titles if ($object->format=="D"||$object->format=="D+") { //affichage des sujets du sondage @@ -410,15 +389,22 @@ else $sumfor = array(); $sumagainst = array(); $compteur = 0; - -$sql = 'SELECT * FROM '.MAIN_DB_PREFIX.'opensurvey_user_studs WHERE id_sondage='.$connect->Param('numsondage').' ORDER BY id_users'; -$sql = $connect->Prepare($sql); -$user_studs = $connect->Execute($sql, array($numsondage)); - -while ($data = $user_studs->FetchNextObject(false)) +$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) { - $ensemblereponses = $data->reponses; - $nombase=str_replace("°","'",$data->nom); + dol_print_error($db); + exit; +} +$num=$db->num_rows($resql); +while ($compteur < $num) +{ + $obj=$db->fetch_object($resql); + + $ensemblereponses = $obj->reponses; print ''."\n"; @@ -426,41 +412,23 @@ while ($data = $user_studs->FetchNextObject(false)) $mod_ok = ($object->canedit || (! empty($nombase) && in_array($nombase, $listofvoters))); // Name + $nombase=str_replace("°","'",$obj->nom); print ''."\n"; - // pour chaque colonne - for ($i=0; $i < $nbcolonnes; $i++) + // si la ligne n'est pas a changer, on affiche les données + if (! $testligneamodifier) { - $car = substr($ensemblereponses, $i, 1); - if ($compteur == $ligneamodifier) - { - 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 ''."\n"; else print ''."\n"; // Total - if (isset($sumfor[$i]) === false) $sumfor[$i] = 0; + if (! isset($sumfor[$i])) $sumfor[$i] = 0; if (((string) $car) == "1") $sumfor[$i]++; } if (! empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno') @@ -476,9 +444,9 @@ while ($data = $user_studs->FetchNextObject(false)) } if (! empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst') { - if (((string) $car) == "1") print ''."\n"; + if (((string) $car) == "1") print ''."\n"; else if (((string) $car) == "0") print ''."\n"; - else print ''."\n"; + else print ''."\n"; // Total if (! isset($sumfor[$i])) $sumfor[$i] = 0; if (! isset($sumagainst[$i])) $sumagainst[$i] = 0; @@ -487,18 +455,90 @@ while ($data = $user_studs->FetchNextObject(false)) } } } + 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 ''."\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 ''."\n"; + else print ''."\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 ''."\n"; + else if (((string) $car) == "0") print ''."\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 ''."\n"; + else if (((string) $car) == "0") print ''."\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 + // 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 ''."\n"; + for ($i=0; $i<$nblignes; $i++) + { + if (isset($_POST["modifierligne".$i])) + { + if ($compteur == $i) + { + print ''."\n"; } } } @@ -547,7 +587,7 @@ if ($ligneamodifier < 0 && (! isset($_SESSION['nom']))) } // Affichage du bouton de formulaire pour inscrire un nouvel utilisateur dans la base - print ''."\n"; + print ''."\n"; print ''."\n"; } @@ -555,7 +595,7 @@ if ($ligneamodifier < 0 && (! isset($_SESSION['nom']))) $nbofcheckbox=0; for ($i=0; $i < $nbcolonnes; $i++) { - if (! empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] != 'checkbox') continue; + if (empty($listofanswers[$i]['format']) || ! in_array($listofanswers[$i]['format'],array('yesno','foragainst'))) $nbofcheckbox++; if (isset($sumfor[$i])) { @@ -571,7 +611,7 @@ for ($i=0; $i < $nbcolonnes; $i++) } // Show line total -print ''."\n"; +print ''."\n"; print ''."\n"; for ($i = 0; $i < $nbcolonnes; $i++) { @@ -587,7 +627,7 @@ for ($i = 0; $i < $nbcolonnes; $i++) print ''."\n"; } print ''; -// Show picto winnner +// Show picto winner if ($nbofcheckbox >= 2) { print ''."\n"; @@ -595,7 +635,7 @@ if ($nbofcheckbox >= 2) for ($i=0; $i < $nbcolonnes; $i++) { //print 'xx'.(! empty($listofanswers[$i]['format'])).'-'.$sumfor[$i].'-'.$meilleurecolonne; - if (! empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'checkbox' && isset($sumfor[$i]) && isset($meilleurecolonne) && $sumfor[$i] == $meilleurecolonne) + if (empty($listofanswers[$i]['format']) || ! in_array($listofanswers[$i]['format'],array('yesno','foragainst')) && isset($sumfor[$i]) && isset($meilleurecolonne) && $sumfor[$i] == $meilleurecolonne) { print ''."\n"; } else { @@ -625,7 +665,9 @@ for ($i = 0; $i < $nbcolonnes; $i++) { } else { $meilleursujet .= dol_print_date($toutsujet[$i],'daytext'). ' ('.dol_print_date($toutsujet[$i],'%A').')'; } - } else { + } + else + { $tmps=explode('@',$toutsujet[$i]); $meilleursujet .= $tmps[0]; } @@ -644,13 +686,13 @@ if ($nbofcheckbox >= 2) $vote_str = $langs->trans('votes'); print '

'."\n"; - if ($compteursujet == "1" && isset($meilleurecolonne)) { - print 'Meilleur choix ' . $langs->trans('TheBestChoice') . ": $meilleursujet " . $langs->trans('with') . " $meilleurecolonne " . $vote_str . ".\n"; + if (isset($meilleurecolonne) && $compteursujet == "1") { + print ' ' . $langs->trans('TheBestChoice') . ": $meilleursujet " . $langs->trans('with') . " $meilleurecolonne " . $vote_str . ".\n"; } elseif (isset($meilleurecolonne)) { - print 'Meilleur choix ' . $langs->trans('TheBestChoices') . ": $meilleursujet " . $langs->trans('with') . " $meilleurecolonne " . $vote_str . ".\n"; + print ' ' . $langs->trans('TheBestChoices') . ": $meilleursujet " . $langs->trans('with') . " $meilleurecolonne " . $vote_str . ".\n"; } - print '


'; + print '


'."\n"; } print '
'; @@ -685,8 +727,8 @@ print $langs->trans("Name") .' : '; print '   '."\n"; print '
'."\n"; print ''."\n"; -// Focus javascript sur la case de texte du formulaire -print ''."\n"; + +print ''."\n"; // div add comment print '

';
'.$nombase.''; - 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 'OKKO'.$langs->trans("For").''.$langs->trans("For").''.$langs->trans("Against").'  '; + 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 'OKKO'.$langs->trans("For").''.$langs->trans("Against").' '.$langs->trans("For").''.$langs->trans("Against").' '; + print ''; + print ''; + print '
'. $langs->trans("Total") .'