actions_comments.inc.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. /**
  21. * \file htdocs/core/actions_comments.inc.php
  22. * \brief Code for actions on comments pages
  23. */
  24. require_once DOL_DOCUMENT_ROOT.'/core/class/comment.class.php';
  25. $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
  26. $comment = new Comment($db);
  27. /*
  28. * Actions
  29. */
  30. if ($action == 'addcomment')
  31. {
  32. $description = GETPOST('comment_description', 'none');
  33. if (!empty($description))
  34. {
  35. $comment->description = $description;
  36. $comment->datec = time();
  37. $comment->fk_element = GETPOST('id','int');
  38. $comment->element_type = GETPOST('comment_element_type','alpha');
  39. $comment->fk_user_author = $user->id;
  40. $comment->entity = $conf->entity;
  41. if ($comment->create($user) > 0)
  42. {
  43. setEventMessages($langs->trans("CommentAdded"), null, 'mesgs');
  44. header('Location: '.$varpage.'?id='.$id.($withproject?'&withproject=1':''));
  45. exit;
  46. }
  47. else
  48. {
  49. setEventMessages($comment->error, $comment->errors,'errors');
  50. $action='';
  51. }
  52. }
  53. }
  54. if ($action == 'deletecomment')
  55. {
  56. if ($comment->fetch($idcomment) >= 0)
  57. {
  58. if ($comment->delete($user) > 0)
  59. {
  60. setEventMessages($langs->trans("CommentDeleted"), null, 'mesgs');
  61. header('Location: '.$varpage.'?id='.$id.($withproject?'&withproject=1':''));
  62. exit;
  63. }
  64. else
  65. {
  66. setEventMessages($comment->error, $comment->errors,'errors');
  67. $action='';
  68. }
  69. }
  70. }