diff --git a/htdocs/core/actions_comments.inc.php b/htdocs/core/actions_comments.inc.php index a84edb0150a..1c679c88825 100644 --- a/htdocs/core/actions_comments.inc.php +++ b/htdocs/core/actions_comments.inc.php @@ -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) diff --git a/htdocs/core/class/comment.class.php b/htdocs/core/class/comment.class.php index 3f4b486f547..18c20b0b07c 100644 --- a/htdocs/core/class/comment.class.php +++ b/htdocs/core/class/comment.class.php @@ -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; diff --git a/htdocs/core/tpl/bloc_comment.tpl.php b/htdocs/core/tpl/bloc_comment.tpl.php index fba0810e7cd..d7b5e5d7532 100644 --- a/htdocs/core/tpl/bloc_comment.tpl.php +++ b/htdocs/core/tpl/bloc_comment.tpl.php @@ -36,21 +36,25 @@ print ''; print ''; print "\n"; -print ''; +if ($action !== 'editcomment') +{ + print ''; -// Description -print ''; + // Description + print ''; -$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 ''; + print ''; + + print ''; + print ''; + print ''; +} -print ''; -print ''; -print ''; print ''; // List of comments @@ -91,15 +95,52 @@ if (!empty($object->comments)) print '
'; print '
'; - print '
'; - print $comment->description; + + if ($action === 'editcomment' && $comment->id == $idcomment) + { + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + } + + print '
'; + 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 '
'; // End comment-description - if(($first && $fk_user == $user->id) || $user->admin == 1) { - print ''; - print img_picto('', 'delete.png'); - print ''; - } - print '
'; // End comment-table + + if ($action === 'editcomment' && $comment->id == $idcomment) + { + print ''; + print ''; + + print ''; + } + else + { + if ($fk_user == $user->id || $user->admin == 1) + { + print ''; + print img_picto('', 'edit.png'); + print ''; + } + if(($first && $fk_user == $user->id) || $user->admin == 1) { + print ''; + print img_picto('', 'delete.png'); + print ''; + } + } + + print '
'; // End comment-table print '
'; // End comment-right print ''; // End comment diff --git a/htdocs/install/mysql/migration/10.0.0-11.0.0.sql b/htdocs/install/mysql/migration/10.0.0-11.0.0.sql index 59cd6473e57..fd529105822 100644 --- a/htdocs/install/mysql/migration/10.0.0-11.0.0.sql +++ b/htdocs/install/mysql/migration/10.0.0-11.0.0.sql @@ -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; \ No newline at end of file diff --git a/htdocs/install/mysql/tables/llx_comment.sql b/htdocs/install/mysql/tables/llx_comment.sql index d881c84c0e3..22b2c40b9f1 100644 --- a/htdocs/install/mysql/tables/llx_comment.sql +++ b/htdocs/install/mysql/tables/llx_comment.sql @@ -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, diff --git a/htdocs/theme/eldy/global.inc.php b/htdocs/theme/eldy/global.inc.php index 4a3b73b1d20..6db99927fb1 100644 --- a/htdocs/theme/eldy/global.inc.php +++ b/htdocs/theme/eldy/global.inc.php @@ -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%; }