dolibarr  20.0.0-alpha
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  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <https://www.gnu.org/licenses/>.
16  * or see https://www.gnu.org/
17  *
18  * $elementype must be defined.
19  */
20 
27 require_once DOL_DOCUMENT_ROOT.'/core/class/comment.class.php';
28 
29 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
30 $comment = new Comment($db);
31 
32 /*
33  * Actions
34  */
35 
36 if ($action == 'addcomment') {
37  $description = GETPOST('comment_description', 'restricthtml');
38  if (!empty($description)) {
39  $comment->description = $description;
40  $comment->datec = dol_now();
41  $comment->fk_element = GETPOSTINT('id');
42  $comment->element_type = GETPOST('comment_element_type', 'alpha');
43  $comment->fk_user_author = $user->id;
44  $comment->entity = $conf->entity;
45  if ($comment->create($user) > 0) {
46  setEventMessages($langs->trans("CommentAdded"), null, 'mesgs');
47  header('Location: '.$varpage.'?id='.$id.($withproject ? '&withproject=1' : ''));
48  exit;
49  } else {
50  setEventMessages($comment->error, $comment->errors, 'errors');
51  $action = '';
52  }
53  }
54 }
55 if ($action === 'updatecomment') {
56  if ($comment->fetch($idcomment) >= 0) {
57  $comment->description = GETPOST('comment_description', 'restricthtml');
58  if ($comment->update($user) > 0) {
59  setEventMessages($langs->trans("CommentAdded"), null, 'mesgs');
60  header('Location: '.$varpage.'?id='.$id.($withproject ? '&withproject=1#comment' : ''));
61  exit;
62  } else {
63  setEventMessages($comment->error, $comment->errors, 'errors');
64  $action = '';
65  }
66  }
67 }
68 if ($action == 'deletecomment') {
69  if ($comment->fetch($idcomment) >= 0) {
70  if ($comment->delete($user) > 0) {
71  setEventMessages($langs->trans("CommentDeleted"), null, 'mesgs');
72  header('Location: '.$varpage.'?id='.$id.($withproject ? '&withproject=1' : ''));
73  exit;
74  } else {
75  setEventMessages($comment->error, $comment->errors, 'errors');
76  $action = '';
77  }
78  }
79 }
Class to manage comment.
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.