New update comments is now available

This commit is contained in:
atm-ph 2019-10-30 15:45:04 +01:00
parent 8f5b0f5d4d
commit 2f68a73a2a
6 changed files with 107 additions and 29 deletions

View File

@ -57,6 +57,24 @@ if ($action == 'addcomment')
} }
} }
} }
if ($action === 'updatecomment')
{
if ($comment->fetch($idcomment) >= 0)
{
$comment->description = GETPOST('comment_description', 'none');
if ($comment->update($user) > 0)
{
setEventMessages($langs->trans("CommentAdded"), null, 'mesgs');
header('Location: '.$varpage.'?id='.$id.($withproject?'&withproject=1#comment':''));
exit;
}
else
{
setEventMessages($comment->error, $comment->errors, 'errors');
$action='';
}
}
}
if ($action == 'deletecomment') if ($action == 'deletecomment')
{ {
if ($comment->fetch($idcomment) >= 0) if ($comment->fetch($idcomment) >= 0)

View File

@ -62,6 +62,11 @@ class Comment extends CommonObject
*/ */
public $fk_user_author; public $fk_user_author;
/**
* @var int ID
*/
public $fk_user_modif;
/** /**
* @var int Entity * @var int Entity
*/ */
@ -94,17 +99,18 @@ class Comment extends CommonObject
*/ */
public function create($user, $notrigger = 0) public function create($user, $notrigger = 0)
{ {
global $conf, $langs; global $user;
$error=0; $error=0;
// Insert request // Insert request
$sql = "INSERT INTO ".MAIN_DB_PREFIX."comment ("; $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element." (";
$sql.= "description"; $sql.= "description";
$sql.= ", datec"; $sql.= ", datec";
$sql.= ", fk_element"; $sql.= ", fk_element";
$sql.= ", element_type"; $sql.= ", element_type";
$sql.= ", fk_user_author"; $sql.= ", fk_user_author";
$sql.= ", fk_user_modif";
$sql.= ", entity"; $sql.= ", entity";
$sql.= ", import_key"; $sql.= ", import_key";
$sql.= ") VALUES ("; $sql.= ") VALUES (";
@ -113,6 +119,7 @@ class Comment extends CommonObject
$sql.= ", '".(isset($this->fk_element)?$this->fk_element:"null")."'"; $sql.= ", '".(isset($this->fk_element)?$this->fk_element:"null")."'";
$sql.= ", '".$this->db->escape($this->element_type)."'"; $sql.= ", '".$this->db->escape($this->element_type)."'";
$sql.= ", '".(isset($this->fk_user_author)?$this->fk_user_author:"null")."'"; $sql.= ", '".(isset($this->fk_user_author)?$this->fk_user_author:"null")."'";
$sql.= ", ".$user->id."";
$sql.= ", ".(!empty($this->entity)?$this->entity:'1'); $sql.= ", ".(!empty($this->entity)?$this->entity:'1');
$sql.= ", ".(!empty($this->import_key)?"'".$this->db->escape($this->import_key)."'":"null"); $sql.= ", ".(!empty($this->import_key)?"'".$this->db->escape($this->import_key)."'":"null");
$sql.= ")"; $sql.= ")";
@ -128,7 +135,7 @@ class Comment extends CommonObject
if (! $error) if (! $error)
{ {
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."projet_task_comment"); $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
if (! $notrigger) if (! $notrigger)
{ {
@ -177,9 +184,10 @@ class Comment extends CommonObject
$sql.= " c.fk_element,"; $sql.= " c.fk_element,";
$sql.= " c.element_type,"; $sql.= " c.element_type,";
$sql.= " c.fk_user_author,"; $sql.= " c.fk_user_author,";
$sql.= " c.fk_user_modif,";
$sql.= " c.entity,"; $sql.= " c.entity,";
$sql.= " c.import_key"; $sql.= " c.import_key";
$sql.= " FROM ".MAIN_DB_PREFIX."comment as c"; $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as c";
$sql.= " WHERE c.rowid = ".$id; $sql.= " WHERE c.rowid = ".$id;
dol_syslog(get_class($this)."::fetch", LOG_DEBUG); dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
@ -196,8 +204,9 @@ class Comment extends CommonObject
$this->description = $obj->description; $this->description = $obj->description;
$this->element_type = $obj->element_type; $this->element_type = $obj->element_type;
$this->datec = $this->db->jdate($obj->datec); $this->datec = $this->db->jdate($obj->datec);
$this->tms = $obj->tms; $this->tms = $this->db->jdate($obj->tms);
$this->fk_user_author = $obj->fk_user_author; $this->fk_user_author = $obj->fk_user_author;
$this->fk_user_modif = $obj->fk_user_modif;
$this->fk_element = $obj->fk_element; $this->fk_element = $obj->fk_element;
$this->entity = $obj->entity; $this->entity = $obj->entity;
$this->import_key = $obj->import_key; $this->import_key = $obj->import_key;
@ -225,22 +234,21 @@ class Comment extends CommonObject
*/ */
public function update(User $user, $notrigger = 0) public function update(User $user, $notrigger = 0)
{ {
global $conf, $langs; global $user;
$error=0; $error=0;
// Clean parameters // Clean parameters
if (isset($this->fk_element)) $this->fk_project=(int) trim($this->fk_element); if (isset($this->fk_element)) $this->fk_project=(int) trim($this->fk_element);
if (isset($this->fk_user_author)) $this->fk_user_author=(int) trim($this->fk_user_author);
if (isset($this->description)) $this->description=trim($this->description); if (isset($this->description)) $this->description=trim($this->description);
// Update request // Update request
$sql = "UPDATE ".MAIN_DB_PREFIX."projet_task_comment SET"; $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET";
$sql.= " description=".(isset($this->description)?"'".$this->db->escape($this->description)."'":"null").","; $sql.= " description=".(isset($this->description)?"'".$this->db->escape($this->description)."'":"null").",";
$sql.= " datec=".($this->datec!=''?"'".$this->db->idate($this->datec)."'":'null').","; $sql.= " datec=".($this->datec!=''?"'".$this->db->idate($this->datec)."'":'null').",";
$sql.= " fk_element=".(isset($this->fk_element)?$this->fk_element:"null").","; $sql.= " fk_element=".(isset($this->fk_element)?$this->fk_element:"null").",";
$sql.= " element_type='".$this->db->escape($this->element_type)."',"; $sql.= " element_type='".$this->db->escape($this->element_type)."',";
$sql.= " fk_user_author=".(isset($this->fk_user_author)?$this->fk_user_author:"null").","; $sql.= " fk_user_modif=".$user->id.",";
$sql.= " entity=".(!empty($this->entity)?$this->entity:'1').","; $sql.= " entity=".(!empty($this->entity)?$this->entity:'1').",";
$sql.= " import_key=".(!empty($this->import_key)?"'".$this->db->escape($this->import_key)."'":"null"); $sql.= " import_key=".(!empty($this->import_key)?"'".$this->db->escape($this->import_key)."'":"null");
$sql.= " WHERE rowid=".$this->id; $sql.= " WHERE rowid=".$this->id;
@ -297,7 +305,7 @@ class Comment extends CommonObject
$this->db->begin(); $this->db->begin();
$sql = "DELETE FROM ".MAIN_DB_PREFIX."comment"; $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element;
$sql.= " WHERE rowid=".$this->id; $sql.= " WHERE rowid=".$this->id;
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
@ -345,7 +353,7 @@ class Comment extends CommonObject
if(!empty($element_type) && !empty($fk_element)) { if(!empty($element_type) && !empty($fk_element)) {
$sql = "SELECT"; $sql = "SELECT";
$sql.= " c.rowid"; $sql.= " c.rowid";
$sql.= " FROM ".MAIN_DB_PREFIX."comment as c"; $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as c";
$sql.= " WHERE c.fk_element = ".$fk_element; $sql.= " WHERE c.fk_element = ".$fk_element;
$sql.= " AND c.element_type = '".$db->escape($element_type)."'"; $sql.= " AND c.element_type = '".$db->escape($element_type)."'";
$sql.= " AND c.entity = ".$conf->entity; $sql.= " AND c.entity = ".$conf->entity;

View File

@ -36,6 +36,8 @@ print '<td width="25%"></td>';
print '<td width="25%"></td>'; print '<td width="25%"></td>';
print "</tr>\n"; print "</tr>\n";
if ($action !== 'editcomment')
{
print '<tr class="oddeven">'; print '<tr class="oddeven">';
// Description // Description
@ -51,6 +53,8 @@ print '</td>';
print '<td class="center">'; print '<td class="center">';
print '<input type="submit" class="button" value="'.$langs->trans("Add").'">'; print '<input type="submit" class="button" value="'.$langs->trans("Add").'">';
print '</td></tr>'; print '</td></tr>';
}
print '</table></form>'; print '</table></form>';
// List of comments // List of comments
@ -91,14 +95,51 @@ if (!empty($object->comments))
print '<div class="comment-cell comment-right">'; print '<div class="comment-cell comment-right">';
print '<div class="comment-table width100p">'; print '<div class="comment-table width100p">';
if ($action === 'editcomment' && $comment->id == $idcomment)
{
print '<form method="POST" action="'.$varpage.'?id='.$object->id.'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="updatecomment">';
print '<input type="hidden" name="id" value="'.$object->id.'">';
print '<input type="hidden" name="idcomment" value="'.$idcomment.'">';
print '<input type="hidden" name="withproject" value="'.$withproject.'">';
}
print '<div class="comment-description comment-cell">'; print '<div class="comment-description comment-cell">';
if ($action === 'editcomment' && $comment->id == $idcomment)
{
$doleditor = new DolEditor('comment_description', $comment->description, '', 80, 'dolibarr_notes', 'In', 0, true, true, ROWS_3, '100%');
print $doleditor->Create(1);
}
else
{
print $comment->description; print $comment->description;
}
print '</div>'; // End comment-description print '</div>'; // End comment-description
if ($action === 'editcomment' && $comment->id == $idcomment)
{
print '<input name="update" type="submit" class="button" value="'.$langs->trans("Update").'">';
print '<input name="cancel" type="submit" class="button" value="'.$langs->trans("Cancel").'">';
print '</form>';
}
else
{
if ($fk_user == $user->id || $user->admin == 1)
{
print '<a class="comment-edit comment-cell" href="'.$varpage.'?action=editcomment&id='.$id.'&withproject=1&idcomment='.$comment->id.'#comment" title="'.$langs->trans('Edit').'">';
print img_picto('', 'edit.png');
print '</a>';
}
if(($first && $fk_user == $user->id) || $user->admin == 1) { if(($first && $fk_user == $user->id) || $user->admin == 1) {
print '<a class="comment-delete comment-cell" href="'.$varpage.'?action=deletecomment&id='.$id.'&withproject=1&idcomment='.$comment->id.'" title="'.$langs->trans('Delete').'">'; print '<a class="comment-delete comment-cell" href="'.$varpage.'?action=deletecomment&id='.$id.'&withproject=1&idcomment='.$comment->id.'" title="'.$langs->trans('Delete').'">';
print img_picto('', 'delete.png'); print img_picto('', 'delete.png');
print '</a>'; print '</a>';
} }
}
print '</div>'; // End comment-table print '</div>'; // End comment-table
print '</div>'; // End comment-right print '</div>'; // End comment-right
print '</div>'; // End comment print '</div>'; // End comment

View File

@ -420,3 +420,5 @@ insert into llx_c_action_trigger (code,label,description,elementtype,rang) value
insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('MO_VALIDATE','MO validated','Executed when a MO is validated','bom',410); insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('MO_VALIDATE','MO validated','Executed when a MO is validated','bom',410);
insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('MO_PRODUCED','MO disabled','Executed when a MO is produced','bom',411); insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('MO_PRODUCED','MO disabled','Executed when a MO is produced','bom',411);
insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('MO_DELETE','MO deleted','Executed when a MO is deleted','bom',412); insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('MO_DELETE','MO deleted','Executed when a MO is deleted','bom',412);
ALTER TABLE llx_comment ADD COLUMN fk_user_modif integer DEFAULT NULL;

View File

@ -22,6 +22,7 @@ CREATE TABLE llx_comment (
tms timestamp, tms timestamp,
description text NOT NULL, description text NOT NULL,
fk_user_author integer DEFAULT NULL, fk_user_author integer DEFAULT NULL,
fk_user_modif integer DEFAULT NULL,
fk_element integer DEFAULT NULL, fk_element integer DEFAULT NULL,
element_type varchar(50) DEFAULT NULL, element_type varchar(50) DEFAULT NULL,
entity integer DEFAULT 1, entity integer DEFAULT 1,

View File

@ -4399,6 +4399,14 @@ pre#editfilecontentaceeditorid {
#comment .comment-delete:hover { #comment .comment-delete:hover {
background:rgba(250,20,20,0.8); background:rgba(250,20,20,0.8);
} }
#comment .comment-edit {
width: 100px;
text-align:center;
vertical-align:middle;
}
#comment .comment-edit:hover {
background:rgba(0,184,148,0.8);
}
#comment textarea { #comment textarea {
width: 100%; width: 100%;
} }