diff --git a/htdocs/opensurvey/adminstuds.php b/htdocs/opensurvey/adminstuds.php index 0d84caeeb7b196fd759e51118769543b80ecafd4..2700ea5c51854f5ac7b7de3db0aaea0721000ca2 100644 --- a/htdocs/opensurvey/adminstuds.php +++ b/htdocs/opensurvey/adminstuds.php @@ -44,6 +44,13 @@ if (GETPOST('id')) { $object=new Opensurveysondage($db); +$result=$object->fetch(0, $numsondageadmin); +if ($result <= 0) +{ + dol_print_error($db,$object->error); + exit; +} + $expiredate=dol_mktime(0, 0, 0, GETPOST('expiremonth'), GETPOST('expireday'), GETPOST('expireyear')); @@ -74,12 +81,6 @@ if ($action == 'update') $action = 'edit'; } - if (! $error) - { - $res=$object->fetch(0,$numsondageadmin); - if ($res < 0) dol_print_error($db,$object->error); - } - if (! $error) { $object->titre = GETPOST('nouveautitre'); @@ -120,10 +121,8 @@ if (GETPOST('ajoutcomment')) $comment = GETPOST("comment"); $comment_user = GETPOST('commentuser'); - $sql = "INSERT INTO ".MAIN_DB_PREFIX."opensurvey_comments (id_sondage, comment, usercomment)"; - $sql.= " VALUES ('".$db->escape($object->id_sondage)."','".$db->escape($comment)."','".$db->escape($comment_user)."')"; - $resql = $db->query($sql); - dol_syslog("sql=".$sql); + $resql = $object->addComment($comment, $comment_user); + if (! $resql) { $err |= COMMENT_INSERT_FAILED; @@ -146,13 +145,6 @@ if ($idcomment) $form=new Form($db); -$result=$object->fetch(0, $numsondageadmin); -if ($result <= 0) -{ - dol_print_error($db,$object->error); - exit; -} - $arrayofjs=array(); $arrayofcss=array('/opensurvey/css/style.css'); llxHeader('',$object->titre, 0, 0, 0, 0, $arrayofjs, $arrayofcss); diff --git a/htdocs/opensurvey/class/opensurveysondage.class.php b/htdocs/opensurvey/class/opensurveysondage.class.php index 870fd17ce76d05ddb524a65c2e9ab88f62173d5d..6db64139971677f5471de23736d96a09dd19394a 100644 --- a/htdocs/opensurvey/class/opensurveysondage.class.php +++ b/htdocs/opensurvey/class/opensurveysondage.class.php @@ -542,5 +542,26 @@ class Opensurveysondage extends CommonObject return $comments; } + + /** + * Adds a comment to the poll + * + * @param string $comment Comment content + * @param string $comment_user Comment author + * @return boolean False in case of the query fails, true if it was successful + */ + public function addComment($comment, $comment_user) { + + $sql = "INSERT INTO ".MAIN_DB_PREFIX."opensurvey_comments (id_sondage, comment, usercomment)"; + $sql.= " VALUES ('".$this->db->escape($this->id_sondage)."','".$this->db->escape($comment)."','".$this->db->escape($comment_user)."')"; + $resql = $this->db->query($sql); + dol_syslog("sql=".$sql); + + if (!$resql) { + return false; + } + + return true; + } } ?> diff --git a/htdocs/opensurvey/public/studs.php b/htdocs/opensurvey/public/studs.php index e2241482ac4aa8afdb5275e2d42076b75d82ce0b..2c84dead099f7bb4e98d1229cc52a8b10475b8cd 100644 --- a/htdocs/opensurvey/public/studs.php +++ b/htdocs/opensurvey/public/studs.php @@ -84,10 +84,8 @@ if (GETPOST('ajoutcomment')) $comment = GETPOST("comment"); $comment_user = GETPOST('commentuser'); - $sql = "INSERT INTO ".MAIN_DB_PREFIX."opensurvey_comments (id_sondage, comment, usercomment)"; - $sql.= " VALUES ('".$db->escape($numsondage)."','".$db->escape($comment)."','".$db->escape($comment_user)."')"; - $resql = $db->query($sql); - dol_syslog("sql=".$sql); + $resql = $object->addComment($comment, $comment_user); + if (! $resql) dol_print_error($db); } } @@ -227,15 +225,6 @@ 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');