Merge pull request #12269 from atm-ph/new_edit_comment
New update comments is now available
This commit is contained in:
commit
906f30773d
@ -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 ($comment->fetch($idcomment) >= 0)
|
||||
|
||||
@ -62,6 +62,11 @@ class Comment extends CommonObject
|
||||
*/
|
||||
public $fk_user_author;
|
||||
|
||||
/**
|
||||
* @var int ID
|
||||
*/
|
||||
public $fk_user_modif;
|
||||
|
||||
/**
|
||||
* @var int Entity
|
||||
*/
|
||||
@ -94,17 +99,18 @@ class Comment extends CommonObject
|
||||
*/
|
||||
public function create($user, $notrigger = 0)
|
||||
{
|
||||
global $conf, $langs;
|
||||
global $user;
|
||||
|
||||
$error=0;
|
||||
|
||||
// Insert request
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."comment (";
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element." (";
|
||||
$sql.= "description";
|
||||
$sql.= ", datec";
|
||||
$sql.= ", fk_element";
|
||||
$sql.= ", element_type";
|
||||
$sql.= ", fk_user_author";
|
||||
$sql.= ", fk_user_modif";
|
||||
$sql.= ", entity";
|
||||
$sql.= ", import_key";
|
||||
$sql.= ") VALUES (";
|
||||
@ -113,6 +119,7 @@ class Comment extends CommonObject
|
||||
$sql.= ", '".(isset($this->fk_element)?$this->fk_element:"null")."'";
|
||||
$sql.= ", '".$this->db->escape($this->element_type)."'";
|
||||
$sql.= ", '".(isset($this->fk_user_author)?$this->fk_user_author:"null")."'";
|
||||
$sql.= ", ".$user->id."";
|
||||
$sql.= ", ".(!empty($this->entity)?$this->entity:'1');
|
||||
$sql.= ", ".(!empty($this->import_key)?"'".$this->db->escape($this->import_key)."'":"null");
|
||||
$sql.= ")";
|
||||
@ -128,7 +135,7 @@ class Comment extends CommonObject
|
||||
|
||||
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)
|
||||
{
|
||||
@ -177,9 +184,10 @@ class Comment extends CommonObject
|
||||
$sql.= " c.fk_element,";
|
||||
$sql.= " c.element_type,";
|
||||
$sql.= " c.fk_user_author,";
|
||||
$sql.= " c.fk_user_modif,";
|
||||
$sql.= " c.entity,";
|
||||
$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;
|
||||
|
||||
dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
|
||||
@ -196,8 +204,9 @@ class Comment extends CommonObject
|
||||
$this->description = $obj->description;
|
||||
$this->element_type = $obj->element_type;
|
||||
$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_modif = $obj->fk_user_modif;
|
||||
$this->fk_element = $obj->fk_element;
|
||||
$this->entity = $obj->entity;
|
||||
$this->import_key = $obj->import_key;
|
||||
@ -225,22 +234,21 @@ class Comment extends CommonObject
|
||||
*/
|
||||
public function update(User $user, $notrigger = 0)
|
||||
{
|
||||
global $conf, $langs;
|
||||
global $user;
|
||||
$error=0;
|
||||
|
||||
// Clean parameters
|
||||
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);
|
||||
|
||||
|
||||
// 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.= " datec=".($this->datec!=''?"'".$this->db->idate($this->datec)."'":'null').",";
|
||||
$sql.= " fk_element=".(isset($this->fk_element)?$this->fk_element:"null").",";
|
||||
$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.= " import_key=".(!empty($this->import_key)?"'".$this->db->escape($this->import_key)."'":"null");
|
||||
$sql.= " WHERE rowid=".$this->id;
|
||||
@ -297,7 +305,7 @@ class Comment extends CommonObject
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."comment";
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element;
|
||||
$sql.= " WHERE rowid=".$this->id;
|
||||
|
||||
$resql = $this->db->query($sql);
|
||||
@ -345,7 +353,7 @@ class Comment extends CommonObject
|
||||
if(!empty($element_type) && !empty($fk_element)) {
|
||||
$sql = "SELECT";
|
||||
$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.= " AND c.element_type = '".$db->escape($element_type)."'";
|
||||
$sql.= " AND c.entity = ".$conf->entity;
|
||||
|
||||
@ -36,21 +36,25 @@ print '<td width="25%"></td>';
|
||||
print '<td width="25%"></td>';
|
||||
print "</tr>\n";
|
||||
|
||||
print '<tr class="oddeven">';
|
||||
if ($action !== 'editcomment')
|
||||
{
|
||||
print '<tr class="oddeven">';
|
||||
|
||||
// Description
|
||||
print '<td colspan="3">';
|
||||
// Description
|
||||
print '<td colspan="3">';
|
||||
|
||||
$desc = GETPOST('comment_description');
|
||||
$desc = GETPOST('comment_description');
|
||||
|
||||
$doleditor = new DolEditor('comment_description', $desc, '', 80, 'dolibarr_notes', 'In', 0, true, true, ROWS_3, '100%');
|
||||
print $doleditor->Create(1);
|
||||
$doleditor = new DolEditor('comment_description', $desc, '', 80, 'dolibarr_notes', 'In', 0, true, true, ROWS_3, '100%');
|
||||
print $doleditor->Create(1);
|
||||
|
||||
print '</td>';
|
||||
print '</td>';
|
||||
|
||||
print '<td class="center">';
|
||||
print '<input type="submit" class="button" value="'.$langs->trans("Add").'">';
|
||||
print '</td></tr>';
|
||||
}
|
||||
|
||||
print '<td class="center">';
|
||||
print '<input type="submit" class="button" value="'.$langs->trans("Add").'">';
|
||||
print '</td></tr>';
|
||||
print '</table></form>';
|
||||
|
||||
// List of comments
|
||||
@ -91,15 +95,52 @@ if (!empty($object->comments))
|
||||
|
||||
print '<div class="comment-cell comment-right">';
|
||||
print '<div class="comment-table width100p">';
|
||||
print '<div class="comment-description comment-cell">';
|
||||
print $comment->description;
|
||||
|
||||
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">';
|
||||
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 '</div>'; // End comment-description
|
||||
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 img_picto('', 'delete.png');
|
||||
print '</a>';
|
||||
}
|
||||
print '</div>'; // End comment-table
|
||||
|
||||
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) {
|
||||
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 '</a>';
|
||||
}
|
||||
}
|
||||
|
||||
print '</div>'; // End comment-table
|
||||
print '</div>'; // End comment-right
|
||||
print '</div>'; // End comment
|
||||
|
||||
|
||||
@ -424,3 +424,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_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);
|
||||
|
||||
ALTER TABLE llx_comment ADD COLUMN fk_user_modif integer DEFAULT NULL;
|
||||
@ -22,6 +22,7 @@ CREATE TABLE llx_comment (
|
||||
tms timestamp,
|
||||
description text NOT NULL,
|
||||
fk_user_author integer DEFAULT NULL,
|
||||
fk_user_modif integer DEFAULT NULL,
|
||||
fk_element integer DEFAULT NULL,
|
||||
element_type varchar(50) DEFAULT NULL,
|
||||
entity integer DEFAULT 1,
|
||||
|
||||
@ -4415,6 +4415,14 @@ pre#editfilecontentaceeditorid {
|
||||
#comment .comment-delete:hover {
|
||||
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 {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user