forked from Wavyzz/dolibarr
Unified comment addition in OpenSurveySondage::addComment and removed duplicate code
This commit is contained in:
@@ -44,6 +44,13 @@ if (GETPOST('id')) {
|
|||||||
|
|
||||||
$object=new Opensurveysondage($db);
|
$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'));
|
$expiredate=dol_mktime(0, 0, 0, GETPOST('expiremonth'), GETPOST('expireday'), GETPOST('expireyear'));
|
||||||
|
|
||||||
|
|
||||||
@@ -74,12 +81,6 @@ if ($action == 'update')
|
|||||||
$action = 'edit';
|
$action = 'edit';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $error)
|
|
||||||
{
|
|
||||||
$res=$object->fetch(0,$numsondageadmin);
|
|
||||||
if ($res < 0) dol_print_error($db,$object->error);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
$object->titre = GETPOST('nouveautitre');
|
$object->titre = GETPOST('nouveautitre');
|
||||||
@@ -120,10 +121,8 @@ if (GETPOST('ajoutcomment'))
|
|||||||
$comment = GETPOST("comment");
|
$comment = GETPOST("comment");
|
||||||
$comment_user = GETPOST('commentuser');
|
$comment_user = GETPOST('commentuser');
|
||||||
|
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."opensurvey_comments (id_sondage, comment, usercomment)";
|
$resql = $object->addComment($comment, $comment_user);
|
||||||
$sql.= " VALUES ('".$db->escape($object->id_sondage)."','".$db->escape($comment)."','".$db->escape($comment_user)."')";
|
|
||||||
$resql = $db->query($sql);
|
|
||||||
dol_syslog("sql=".$sql);
|
|
||||||
if (! $resql)
|
if (! $resql)
|
||||||
{
|
{
|
||||||
$err |= COMMENT_INSERT_FAILED;
|
$err |= COMMENT_INSERT_FAILED;
|
||||||
@@ -146,13 +145,6 @@ if ($idcomment)
|
|||||||
|
|
||||||
$form=new Form($db);
|
$form=new Form($db);
|
||||||
|
|
||||||
$result=$object->fetch(0, $numsondageadmin);
|
|
||||||
if ($result <= 0)
|
|
||||||
{
|
|
||||||
dol_print_error($db,$object->error);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
$arrayofjs=array();
|
$arrayofjs=array();
|
||||||
$arrayofcss=array('/opensurvey/css/style.css');
|
$arrayofcss=array('/opensurvey/css/style.css');
|
||||||
llxHeader('',$object->titre, 0, 0, 0, 0, $arrayofjs, $arrayofcss);
|
llxHeader('',$object->titre, 0, 0, 0, 0, $arrayofjs, $arrayofcss);
|
||||||
|
|||||||
@@ -542,5 +542,26 @@ class Opensurveysondage extends CommonObject
|
|||||||
|
|
||||||
return $comments;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|||||||
@@ -84,10 +84,8 @@ if (GETPOST('ajoutcomment'))
|
|||||||
$comment = GETPOST("comment");
|
$comment = GETPOST("comment");
|
||||||
$comment_user = GETPOST('commentuser');
|
$comment_user = GETPOST('commentuser');
|
||||||
|
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."opensurvey_comments (id_sondage, comment, usercomment)";
|
$resql = $object->addComment($comment, $comment_user);
|
||||||
$sql.= " VALUES ('".$db->escape($numsondage)."','".$db->escape($comment)."','".$db->escape($comment_user)."')";
|
|
||||||
$resql = $db->query($sql);
|
|
||||||
dol_syslog("sql=".$sql);
|
|
||||||
if (! $resql) dol_print_error($db);
|
if (! $resql) dol_print_error($db);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -227,15 +225,6 @@ if ($idcomment)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
$form=new Form($db);
|
$form=new Form($db);
|
||||||
$object=new OpenSurveySondage($db);
|
|
||||||
|
|
||||||
$result=$object->fetch(0,$numsondage);
|
|
||||||
if ($result <= 0)
|
|
||||||
{
|
|
||||||
print $langs->trans("ErrorRecordNotFound");
|
|
||||||
llxFooterSurvey();
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
$arrayofjs=array();
|
$arrayofjs=array();
|
||||||
$arrayofcss=array('/opensurvey/css/style.css');
|
$arrayofcss=array('/opensurvey/css/style.css');
|
||||||
|
|||||||
Reference in New Issue
Block a user