dolibarr 21.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 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
36// Next should be define in the including php source file
37'
38@phan-var-force int $withproject
39@phan-var-force int $idcomment
40';
41
42require_once DOL_DOCUMENT_ROOT.'/core/class/comment.class.php';
43
44$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
45$comment = new Comment($db);
46
47/*
48 * Actions
49 */
50
51if ($action == 'addcomment') {
52 $description = GETPOST('comment_description', 'restricthtml');
53 if (!empty($description)) {
54 $comment->description = $description;
55 $comment->datec = dol_now();
56 $comment->fk_element = GETPOSTINT('id');
57 $comment->element_type = GETPOST('comment_element_type', 'alpha');
58 $comment->fk_user_author = $user->id;
59 $comment->entity = $conf->entity;
60 if ($comment->create($user) > 0) {
61 setEventMessages($langs->trans("CommentAdded"), null, 'mesgs');
62 header('Location: '.$varpage.'?id='.$id.($withproject ? '&withproject=1' : ''));
63 exit;
64 } else {
65 setEventMessages($comment->error, $comment->errors, 'errors');
66 $action = '';
67 }
68 }
69}
70if ($action === 'updatecomment') {
71 if ($comment->fetch($idcomment) >= 0) {
72 $comment->description = GETPOST('comment_description', 'restricthtml');
73 if ($comment->update($user) > 0) {
74 setEventMessages($langs->trans("CommentAdded"), null, 'mesgs');
75 header('Location: '.$varpage.'?id='.$id.($withproject ? '&withproject=1#comment' : ''));
76 exit;
77 } else {
78 setEventMessages($comment->error, $comment->errors, 'errors');
79 $action = '';
80 }
81 }
82}
83if ($action == 'deletecomment') {
84 if ($comment->fetch($idcomment) >= 0) {
85 if ($comment->delete($user) > 0) {
86 setEventMessages($langs->trans("CommentDeleted"), null, 'mesgs');
87 header('Location: '.$varpage.'?id='.$id.($withproject ? '&withproject=1' : ''));
88 exit;
89 } else {
90 setEventMessages($comment->error, $comment->errors, 'errors');
91 $action = '';
92 }
93 }
94}
$id
Definition account.php:48
Class to manage comment.
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.
dol_now($mode='auto')
Return date for now.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79