dolibarr  7.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  *
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 <http://www.gnu.org/licenses/>.
16  * or see http://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', 'none');
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  }
53  else
54  {
55  setEventMessages($comment->error, $comment->errors,'errors');
56  $action='';
57  }
58  }
59 }
60 if ($action == 'deletecomment')
61 {
62  if ($comment->fetch($idcomment) >= 0)
63  {
64  if ($comment->delete($user) > 0)
65  {
66  setEventMessages($langs->trans("CommentDeleted"), null, 'mesgs');
67  header('Location: '.$varpage.'?id='.$id.($withproject?'&withproject=1':''));
68  exit;
69  }
70  else
71  {
72  setEventMessages($comment->error, $comment->errors,'errors');
73  $action='';
74  }
75  }
76 }
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage comment.