dolibarr 24.0.1
actions_comments.inc.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2011-2015 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 * or see https://www.gnu.org/
19 *
20 * $elementype must be defined.
21 */
22
41// Next should be define in the including php source file
42'
43@phan-var-force ?string $action
44@phan-var-force int $withproject
45@phan-var-force int $idcomment
46@phan-var-force int $id
47';
48
49require_once DOL_DOCUMENT_ROOT.'/core/class/comment.class.php';
50
51$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
52$comment = new Comment($db);
53
54/*
55 * Actions
56 */
57
58if ($action == 'addcomment') {
59 $description = GETPOST('comment_description', 'restricthtml');
60 if (!empty($description)) {
61 $comment->description = $description;
62 $comment->datec = dol_now();
63 $comment->fk_element = GETPOSTINT('id');
64 $comment->element_type = GETPOST('comment_element_type', 'alpha');
65 $comment->fk_user_author = $user->id;
66 $comment->entity = $conf->entity;
67 if ($comment->create($user) > 0) {
68 setEventMessages($langs->trans("CommentAdded"), null, 'mesgs');
69 header('Location: '.$varpage.'?id='.$id.($withproject ? '&withproject=1' : ''));
70 exit;
71 } else {
72 setEventMessages($comment->error, $comment->errors, 'errors');
73 $action = '';
74 }
75 }
76}
77if ($action === 'updatecomment') {
78 if ($comment->fetch($idcomment) >= 0) {
79 // Verify the comment belongs to the current object to prevent IDOR
80 if ($comment->fk_element != $id || $comment->element_type != $object->element) {
82 }
83 $comment->description = GETPOST('comment_description', 'restricthtml');
84 if ($comment->update($user) > 0) {
85 setEventMessages($langs->trans("CommentAdded"), null, 'mesgs');
86 header('Location: '.$varpage.'?id='.$id.($withproject ? '&withproject=1#comment' : ''));
87 exit;
88 } else {
89 setEventMessages($comment->error, $comment->errors, 'errors');
90 $action = '';
91 }
92 }
93}
94if ($action == 'deletecomment') {
95 if ($comment->fetch($idcomment) >= 0) {
96 // Verify the comment belongs to the current object to prevent IDOR
97 if ($comment->fk_element != $id || $comment->element_type != $object->element) {
99 }
100 if ($comment->delete($user) > 0) {
101 setEventMessages($langs->trans("CommentDeleted"), null, 'mesgs');
102 header('Location: '.$varpage.'?id='.$id.($withproject ? '&withproject=1' : ''));
103 exit;
104 } else {
105 setEventMessages($comment->error, $comment->errors, 'errors');
106 $action = '';
107 }
108 }
109}
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
Class to manage comment.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_now($mode='gmt')
Return date for now.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.