actions_comments.inc.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. {
  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 === 'updatecomment')
  55. {
  56. if ($comment->fetch($idcomment) >= 0)
  57. {
  58. $comment->description = GETPOST('comment_description', 'none');
  59. if ($comment->update($user) > 0)
  60. {
  61. setEventMessages($langs->trans("CommentAdded"), null, 'mesgs');
  62. header('Location: '.$varpage.'?id='.$id.($withproject ? '&withproject=1#comment' : ''));
  63. exit;
  64. }
  65. else
  66. {
  67. setEventMessages($comment->error, $comment->errors, 'errors');
  68. $action = '';
  69. }
  70. }
  71. }
  72. if ($action == 'deletecomment')
  73. {
  74. if ($comment->fetch($idcomment) >= 0)
  75. {
  76. if ($comment->delete($user) > 0)
  77. {
  78. setEventMessages($langs->trans("CommentDeleted"), null, 'mesgs');
  79. header('Location: '.$varpage.'?id='.$id.($withproject ? '&withproject=1' : ''));
  80. exit;
  81. }
  82. else
  83. {
  84. setEventMessages($comment->error, $comment->errors, 'errors');
  85. $action = '';
  86. }
  87. }
  88. }