Skip to content
Snippets Groups Projects
Commit e24fb9f4 authored by Laurent Destailleur's avatar Laurent Destailleur
Browse files

Removed all old code. All orignal code has been rewritten now.

parent 473fbf2c
No related branches found
No related tags found
No related merge requests found
......@@ -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 '<input type="hidden" name="sondage" value="'.$numsondageadmin.'">';
print '<div class="cadre"> '."\n";
print '<br>'."\n";
//debut de l'affichage de résultats
// Start to show survey result
print '<table class="resultats">'."\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 '<td class="casevide"><input type="submit" class="button" name="modifierligne'.$compteur.'" value="'.dol_escape_htmltag($langs->trans("Edit")).'"></td>'."\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 '<p class=affichageresultats>'."\n";
print '<p class="affichageresultats">'."\n";
if (isset($meilleurecolonne) && $compteursujet == "1") {
print "<img src=\"".dol_buildpath('/opensurvey/img/medaille.png',1)."\"> " . $langs->trans('TheBestChoice') . " : <b>$meilleursujet </b>" . $langs->trans("with") . " <b>$meilleurecolonne </b>" . $vote_str . ".<br>\n";
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)) {
print "<img src=\"".dol_buildpath('/opensurvey/img/medaille.png',1)."\"> " . $langs->trans('TheBestChoices') . " : <b>$meilleursujet </b>" . $langs->trans("with") . " <b>$meilleurecolonne </b>" . $vote_str . ".<br>\n";
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></p><br>'."\n";
}
print '</form>'."\n";
print '<a name="bas"></a>'."\n";
llxFooterSurvey();
$db->close();
......
......@@ -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("@","<br>",$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 '<div class="survey_invitation">'.$langs->trans("YouAreInivitedToVote").'</div>';
print $langs->trans("OpenSurveyHowTo").'<br><br>';
......@@ -283,7 +266,8 @@ print '<strong>'.$titre.'</strong><br>'."\n";
print $langs->trans("InitiatorOfPoll") .' : '.$object->nom_admin.'<br>'."\n";
//affichage des commentaires du sondage
if ($object->commentaires) {
if ($object->commentaires)
{
print '<br>'.$langs->trans("Description") .' :<br>'."\n";
$commentaires=dol_nl2br($object->commentaires);
print $commentaires;
......@@ -294,19 +278,14 @@ print '</div>'."\n";
print '<form name="formulaire" action="studs.php?sondage='.$numsondage.'"'.'#bas" method="POST" onkeypress="javascript:process_keypress(event)">'."\n";
print '<input type="hidden" name="sondage" value="' . $numsondage . '"/>';
// Todo : add CSRF protection
print '<div class="cadre"> '."\n";
print '<br><br>'."\n";
// Debut de l'affichage des resultats du sondage
// Start to show survey result
print '<table class="resultats">'."\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 '<tr>'."\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 '<td class="nom">'.$nombase.'</td>'."\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 '<td class="vide">';
if (empty($listofanswers[$i]['format']) || ! in_array($listofanswers[$i]['format'],array('yesno','foragainst')))
{
print '<input type="checkbox" name="choix'.$i.'" value="1" ';
if (((string) $car) == '1') print 'checked="checked"';
print '>';
}
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);
}
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";
}
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 '<td class="ok">OK</td>'."\n";
else print '<td class="non">KO</td>'."\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 '<td class="ok">'.$langs->trans("For").'</td>'."\n";
if (((string) $car) == "1") print '<td class="ok">'.$langs->trans("For").'</td>'."\n";
else if (((string) $car) == "0") print '<td class="non">'.$langs->trans("Against").'</td>'."\n";
else print '<td class="vide">&nbsp;</td>'."\n";
else print '<td class="vide">&nbsp;</td>'."\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 '<td class="vide">';
if (empty($listofanswers[$i]['format']) || ! in_array($listofanswers[$i]['format'],array('yesno','foragainst')))
{
print '<input type="checkbox" name="choix'.$i.'" value="1" ';
if ($car == '1') print 'checked="checked"';
print '>';
}
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);
}
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";
}
}
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 '<td class="ok">OK</td>'."\n";
else print '<td class="non">KO</td>'."\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 '<td class="ok">'.$langs->trans("For").'</td>'."\n";
else if (((string) $car) == "0") print '<td class="non">'.$langs->trans("Against").'</td>'."\n";
else print '<td class="vide">&nbsp;</td>'."\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 '<td class="ok">'.$langs->trans("For").'</td>'."\n";
else if (((string) $car) == "0") print '<td class="non">'.$langs->trans("Against").'</td>'."\n";
else print '<td class="vide">&nbsp;</td>'."\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 '<td class="casevide"><input type="submit" class="button" name="modifierligne'.$compteur.'" value="'.dol_escape_htmltag($langs->trans("Edit")).'"></td>'."\n";
}
//demande de confirmation pour modification de ligne
for ($i=0;$i<$nblignes;$i++) {
if (isset($_POST["modifierligne$i"])) {
if ($compteur == $i) {
print '<td class="casevide"><input type="submit" class="button" name="validermodifier'.$compteur.'" value="'.dol_escape_htmltag($langs->trans("Save")).'"></td>'."\n";
for ($i=0; $i<$nblignes; $i++)
{
if (isset($_POST["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" name="validermodifier'.$compteur.'" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
print '</td>'."\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 '<td><input type="image" name="boutonp" value="' . $langs->trans('Vote') . '" src="'.dol_buildpath('/opensurvey/img/add-24.png',1).'"></td>'."\n";
print '<td><input type="image" name="boutonp" value="'.$langs->trans("Vote").'" src="'.dol_buildpath('/opensurvey/img/add-24.png',1).'"></td>'."\n";
print '</tr>'."\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 '<tr '.$bc[false].'>'."\n";
print '<tr>'."\n";
print '<td align="center">'. $langs->trans("Total") .'</td>'."\n";
for ($i = 0; $i < $nbcolonnes; $i++)
{
......@@ -587,7 +627,7 @@ for ($i = 0; $i < $nbcolonnes; $i++)
print '</td>'."\n";
}
print '</tr>';
// Show picto winnner
// Show picto winner
if ($nbofcheckbox >= 2)
{
print '<tr>'."\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 '<td class="somme"><img src="'.dol_buildpath('/opensurvey/img/medaille.png',1).'"></td>'."\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 '<p class="affichageresultats">'."\n";
if ($compteursujet == "1" && isset($meilleurecolonne)) {
print '<img src="images/medaille.png" alt="Meilleur choix"> ' . $langs->trans('TheBestChoice') . ": <b>$meilleursujet</b> " . $langs->trans('with') . " <b>$meilleurecolonne </b>" . $vote_str . ".\n";
if (isset($meilleurecolonne) && $compteursujet == "1") {
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)) {
print '<img src="images/medaille.png" alt="Meilleur choix"> ' . $langs->trans('TheBestChoices') . ": <b>$meilleursujet</b> " . $langs->trans('with') . " <b>$meilleurecolonne </b>" . $vote_str . ".\n";
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>';
print '</p><br>'."\n";
}
print '<br>';
......@@ -685,8 +727,8 @@ print $langs->trans("Name") .' : ';
print '<input type="text" name="commentuser" maxlength="64" /> &nbsp; '."\n";
print '<input type="submit" class="button" name="ajoutcomment" value="'.dol_escape_htmltag($langs->trans("AddComment")).'"><br>'."\n";
print '</form>'."\n";
// Focus javascript sur la case de texte du formulaire
print '</div>'."\n";
print '</div>'."\n"; // div add comment
print '<br><br>';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment