actions_comments.inc.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. /**
  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. $description = GETPOST('comment_description', 'restricthtml');
  32. if (!empty($description)) {
  33. $comment->description = $description;
  34. $comment->datec = dol_now();
  35. $comment->fk_element = GETPOST('id', 'int');
  36. $comment->element_type = GETPOST('comment_element_type', 'alpha');
  37. $comment->fk_user_author = $user->id;
  38. $comment->entity = $conf->entity;
  39. if ($comment->create($user) > 0) {
  40. setEventMessages($langs->trans("CommentAdded"), null, 'mesgs');
  41. header('Location: '.$varpage.'?id='.$id.($withproject ? '&withproject=1' : ''));
  42. exit;
  43. } else {
  44. setEventMessages($comment->error, $comment->errors, 'errors');
  45. $action = '';
  46. }
  47. }
  48. }
  49. if ($action === 'updatecomment') {
  50. if ($comment->fetch($idcomment) >= 0) {
  51. $comment->description = GETPOST('comment_description', 'restricthtml');
  52. if ($comment->update($user) > 0) {
  53. setEventMessages($langs->trans("CommentAdded"), null, 'mesgs');
  54. header('Location: '.$varpage.'?id='.$id.($withproject ? '&withproject=1#comment' : ''));
  55. exit;
  56. } else {
  57. setEventMessages($comment->error, $comment->errors, 'errors');
  58. $action = '';
  59. }
  60. }
  61. }
  62. if ($action == 'deletecomment') {
  63. if ($comment->fetch($idcomment) >= 0) {
  64. if ($comment->delete($user) > 0) {
  65. setEventMessages($langs->trans("CommentDeleted"), null, 'mesgs');
  66. header('Location: '.$varpage.'?id='.$id.($withproject ? '&withproject=1' : ''));
  67. exit;
  68. } else {
  69. setEventMessages($comment->error, $comment->errors, 'errors');
  70. $action = '';
  71. }
  72. }
  73. }