dolibarr 23.0.4
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 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
37// Next should be define in the including php source file
38'
39@phan-var-force int $withproject
40@phan-var-force int $idcomment
41';
42
43require_once DOL_DOCUMENT_ROOT.'/core/class/comment.class.php';
44
45$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
46$comment = new Comment($db);
47
48/*
49 * Actions
50 */
51
52if ($action == 'addcomment') {
53 $description = GETPOST('comment_description', 'restricthtml');
54 if (!empty($description)) {
55 $comment->description = $description;
56 $comment->datec = dol_now();
57 $comment->fk_element = GETPOSTINT('id');
58 $comment->element_type = GETPOST('comment_element_type', 'alpha');
59 $comment->fk_user_author = $user->id;
60 $comment->entity = $conf->entity;
61 if ($comment->create($user) > 0) {
62 setEventMessages($langs->trans("CommentAdded"), null, 'mesgs');
63 header('Location: '.$varpage.'?id='.$id.($withproject ? '&withproject=1' : ''));
64 exit;
65 } else {
66 setEventMessages($comment->error, $comment->errors, 'errors');
67 $action = '';
68 }
69 }
70}
71if ($action === 'updatecomment') {
72 if ($comment->fetch($idcomment) >= 0) {
73 // Verify the comment belongs to the current object to prevent IDOR
74 if ($comment->fk_element != $id || $comment->element_type != $object->element) {
76 }
77 $comment->description = GETPOST('comment_description', 'restricthtml');
78 if ($comment->update($user) > 0) {
79 setEventMessages($langs->trans("CommentAdded"), null, 'mesgs');
80 header('Location: '.$varpage.'?id='.$id.($withproject ? '&withproject=1#comment' : ''));
81 exit;
82 } else {
83 setEventMessages($comment->error, $comment->errors, 'errors');
84 $action = '';
85 }
86 }
87}
88if ($action == 'deletecomment') {
89 if ($comment->fetch($idcomment) >= 0) {
90 // Verify the comment belongs to the current object to prevent IDOR
91 if ($comment->fk_element != $id || $comment->element_type != $object->element) {
93 }
94 if ($comment->delete($user) > 0) {
95 setEventMessages($langs->trans("CommentDeleted"), null, 'mesgs');
96 header('Location: '.$varpage.'?id='.$id.($withproject ? '&withproject=1' : ''));
97 exit;
98 } else {
99 setEventMessages($comment->error, $comment->errors, 'errors');
100 $action = '';
101 }
102 }
103}
$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.
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.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.