dolibarr 24.0.0-beta
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
40// Next should be define in the including php source file
41'
42@phan-var-force ?string $action
43@phan-var-force int $withproject
44@phan-var-force int $idcomment
45@phan-var-force int $id
46';
47
48require_once DOL_DOCUMENT_ROOT.'/core/class/comment.class.php';
49
50$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
51$comment = new Comment($db);
52
53/*
54 * Actions
55 */
56
57if ($action == 'addcomment') {
58 $description = GETPOST('comment_description', 'restricthtml');
59 if (!empty($description)) {
60 $comment->description = $description;
61 $comment->datec = dol_now();
62 $comment->fk_element = GETPOSTINT('id');
63 $comment->element_type = GETPOST('comment_element_type', 'alpha');
64 $comment->fk_user_author = $user->id;
65 $comment->entity = $conf->entity;
66 if ($comment->create($user) > 0) {
67 setEventMessages($langs->trans("CommentAdded"), null, 'mesgs');
68 header('Location: '.$varpage.'?id='.$id.($withproject ? '&withproject=1' : ''));
69 exit;
70 } else {
71 setEventMessages($comment->error, $comment->errors, 'errors');
72 $action = '';
73 }
74 }
75}
76if ($action === 'updatecomment') {
77 if ($comment->fetch($idcomment) >= 0) {
78 $comment->description = GETPOST('comment_description', 'restricthtml');
79 if ($comment->update($user) > 0) {
80 setEventMessages($langs->trans("CommentAdded"), null, 'mesgs');
81 header('Location: '.$varpage.'?id='.$id.($withproject ? '&withproject=1#comment' : ''));
82 exit;
83 } else {
84 setEventMessages($comment->error, $comment->errors, 'errors');
85 $action = '';
86 }
87 }
88}
89if ($action == 'deletecomment') {
90 if ($comment->fetch($idcomment) >= 0) {
91 if ($comment->delete($user) > 0) {
92 setEventMessages($langs->trans("CommentDeleted"), null, 'mesgs');
93 header('Location: '.$varpage.'?id='.$id.($withproject ? '&withproject=1' : ''));
94 exit;
95 } else {
96 setEventMessages($comment->error, $comment->errors, 'errors');
97 $action = '';
98 }
99 }
100}
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
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.
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.