diff --git a/htdocs/opensurvey/card.php b/htdocs/opensurvey/card.php index ca43feb70a2..474d7db85f4 100644 --- a/htdocs/opensurvey/card.php +++ b/htdocs/opensurvey/card.php @@ -142,8 +142,7 @@ if ($idcomment) // Security check if (!$user->rights->opensurvey->write) accessforbidden(); - $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'opensurvey_comments WHERE id_comment = '.$idcomment; - $resql = $db->query($sql); + $resql = $object->deleteComment($idcomment); } if ($action == 'edit') { diff --git a/htdocs/opensurvey/class/opensurveysondage.class.php b/htdocs/opensurvey/class/opensurveysondage.class.php index 5d532fead5b..45c58688969 100644 --- a/htdocs/opensurvey/class/opensurveysondage.class.php +++ b/htdocs/opensurvey/class/opensurveysondage.class.php @@ -478,6 +478,23 @@ class Opensurveysondage extends CommonObject return true; } + /** + * Deletes a comment of the poll + * + * @param int $id_comment Id of the comment + * @return boolean False in case of the query fails, true if it was successful + */ + public function deleteComment($id_comment) { + $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'opensurvey_comments WHERE id_comment = '.$id_comment.' AND id_sondage = '.$this->id_sondage; + $resql = $this->db->query($sql); + + if (!$resql) { + return false; + } + + return true; + } + /** * Cleans all the class variables before doing an update or an insert * diff --git a/htdocs/opensurvey/public/studs.php b/htdocs/opensurvey/public/studs.php index a8274ddeb79..6042aafd37b 100644 --- a/htdocs/opensurvey/public/studs.php +++ b/htdocs/opensurvey/public/studs.php @@ -205,8 +205,7 @@ if ($testmodifier) $idcomment=GETPOST('deletecomment','int'); if ($idcomment) { - $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'opensurvey_comments WHERE id_comment = '.$idcomment; - $resql = $db->query($sql); + $resql = $object->deleteComment($idcomment); }