dolibarr  13.0.2
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 {
38  $description = GETPOST('comment_description', 'restricthtml');
39  if (!empty($description))
40  {
41  $comment->description = $description;
42  $comment->datec = time();
43  $comment->fk_element = GETPOST('id', 'int');
44  $comment->element_type = GETPOST('comment_element_type', 'alpha');
45  $comment->fk_user_author = $user->id;
46  $comment->entity = $conf->entity;
47  if ($comment->create($user) > 0)
48  {
49  setEventMessages($langs->trans("CommentAdded"), null, 'mesgs');
50  header('Location: '.$varpage.'?id='.$id.($withproject ? '&withproject=1' : ''));
51  exit;
52  } else {
53  setEventMessages($comment->error, $comment->errors, 'errors');
54  $action = '';
55  }
56  }
57 }
58 if ($action === 'updatecomment')
59 {
60  if ($comment->fetch($idcomment) >= 0)
61  {
62  $comment->description = GETPOST('comment_description', 'restricthtml');
63  if ($comment->update($user) > 0)
64  {
65  setEventMessages($langs->trans("CommentAdded"), null, 'mesgs');
66  header('Location: '.$varpage.'?id='.$id.($withproject ? '&withproject=1#comment' : ''));
67  exit;
68  } else {
69  setEventMessages($comment->error, $comment->errors, 'errors');
70  $action = '';
71  }
72  }
73 }
74 if ($action == 'deletecomment')
75 {
76  if ($comment->fetch($idcomment) >= 0)
77  {
78  if ($comment->delete($user) > 0)
79  {
80  setEventMessages($langs->trans("CommentDeleted"), null, 'mesgs');
81  header('Location: '.$varpage.'?id='.$id.($withproject ? '&withproject=1' : ''));
82  exit;
83  } else {
84  setEventMessages($comment->error, $comment->errors, 'errors');
85  $action = '';
86  }
87  }
88 }
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= '')
Set event messages in dol_events session object.
print $_SERVER["PHP_SELF"]
Edit parameters.
Class to manage comment.