Removed duplicate code

This commit is contained in:
Marcos García de La Fuente 2014-01-03 14:52:31 +01:00
parent 2e995fc20b
commit 7a1af8656a
3 changed files with 37 additions and 28 deletions

View File

@ -293,21 +293,12 @@ print '<form name="formulaire5" action="#" method="POST">'."\n";
print_fiche_titre($langs->trans("CommentsOfVoters"),'',''); print_fiche_titre($langs->trans("CommentsOfVoters"),'','');
// Comment list // Comment list
$sql = 'SELECT id_comment, usercomment, comment'; $comments = $object->getComments();
$sql.= ' FROM '.MAIN_DB_PREFIX.'opensurvey_comments';
$sql.= " WHERE id_sondage='".$db->escape($numsondage)."'"; if ($comments) {
$sql.= " ORDER BY id_comment"; foreach ($comments as $comment) {
$resql = $db->query($sql); print '<a href="'.dol_buildpath('/opensurvey/adminstuds.php',1).'?deletecomment='.$comment->id_comment.'&id='.$numsondageadmin.'"> '.img_picto('', 'delete.png').'</a> ';
$num_rows=$db->num_rows($resql); print $comment->usercomment.': '.dol_nl2br($comment->comment)." <br>";
if ($num_rows > 0)
{
$i = 0;
while ( $i < $num_rows)
{
$obj=$db->fetch_object($resql);
print '<a href="'.dol_buildpath('/opensurvey/adminstuds.php',1).'?deletecomment='.$obj->id_comment.'&id='.$numsondageadmin.'"> '.img_picto('', 'delete.png').'</a> ';
print $obj->usercomment.' : '.dol_nl2br($obj->comment)." <br>";
$i++;
} }
} }
else else
@ -320,7 +311,7 @@ print '<br>';
// Add comment // Add comment
print $langs->trans("AddACommentForPoll") . '<br>'; print $langs->trans("AddACommentForPoll") . '<br>';
print '<textarea name="comment" rows="2" cols="80"></textarea><br>'."\n"; print '<textarea name="comment" rows="2" cols="80"></textarea><br>'."\n";
print $langs->trans("Name") .' : <input type=text name="commentuser"><br>'."\n"; print $langs->trans("Name") .': <input type="text" name="commentuser" value="'.$user->getFullName($langs).'"><br>'."\n";
print '<input type="submit" class="button" name="ajoutcomment" value="'.dol_escape_htmltag($langs->trans("AddComment")).'"><br>'."\n"; print '<input type="submit" class="button" name="ajoutcomment" value="'.dol_escape_htmltag($langs->trans("AddComment")).'"><br>'."\n";
if (isset($erreur_commentaire_vide) && $erreur_commentaire_vide=="yes") { if (isset($erreur_commentaire_vide) && $erreur_commentaire_vide=="yes") {
print "<font color=#FF0000>" . $langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Name")) . "</font>"; print "<font color=#FF0000>" . $langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Name")) . "</font>";

View File

@ -517,5 +517,30 @@ class Opensurveysondage extends CommonObject
$this->canedit=0; $this->canedit=0;
} }
/**
* Returns all comments for the current opensurvey poll
*
* @return Object[]
*/
public function getComments() {
$sql = 'SELECT id_comment, usercomment, comment';
$sql.= ' FROM '.MAIN_DB_PREFIX.'opensurvey_comments';
$sql.= " WHERE id_sondage='".$this->db->escape($this->id_sondage)."'";
$sql.= " ORDER BY id_comment";
$resql = $this->db->query($sql);
$num_rows=$this->db->num_rows($resql);
$comments = array();
if ($num_rows > 0) {
while ($obj = $this->db->fetch_object($resql)) {
$comments[] = $obj;
}
}
return $comments;
}
} }
?> ?>

View File

@ -697,23 +697,16 @@ print '<br>';
// Comment list // Comment list
$sql = 'SELECT id_comment, usercomment, comment'; $comments = $object->getComments();
$sql.= ' FROM '.MAIN_DB_PREFIX.'opensurvey_comments';
$sql.= " WHERE id_sondage='".$db->escape($numsondage)."'"; if ($comments)
$sql.= " ORDER BY id_comment";
$resql = $db->query($sql);
$num_rows=$db->num_rows($resql);
if ($num_rows > 0)
{ {
$i = 0;
print "<br><b>" . $langs->trans("CommentsOfVoters") . " :</b><br>\n"; print "<br><b>" . $langs->trans("CommentsOfVoters") . " :</b><br>\n";
while ( $i < $num_rows)
{ foreach ($comments as $obj) {
$obj=$db->fetch_object($resql);
print '<div class="comment"><span class="usercomment">'; print '<div class="comment"><span class="usercomment">';
if (in_array($obj->usercomment, $listofvoters)) print '<a href="'.$_SERVER["PHP_SELF"].'?deletecomment='.$obj->id_comment.'&sondage='.$numsondage.'"> '.img_picto('', 'delete.png').'</a> '; if (in_array($obj->usercomment, $listofvoters)) print '<a href="'.$_SERVER["PHP_SELF"].'?deletecomment='.$obj->id_comment.'&sondage='.$numsondage.'"> '.img_picto('', 'delete.png').'</a> ';
print $obj->usercomment.' :</span> <span class="comment">'.dol_nl2br($obj->comment)."</span></div>"; print $obj->usercomment.' :</span> <span class="comment">'.dol_nl2br($obj->comment)."</span></div>";
$i++;
} }
} }