dfprocess.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
  3. * Copyright (C) 2005-2013 Regis Houssin <regis.houssin@inodbox.com>
  4. * Copyright (C) 2007-2020 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2014-2015 Marcos García <marcosgdf@gmail.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/projet/ajax/projects.php
  22. * \brief File to return Ajax response on product list request
  23. */
  24. if (!defined('NOTOKENRENEWAL')) {
  25. define('NOTOKENRENEWAL', 1); // Disables token renewal
  26. }
  27. if (!defined('NOREQUIREMENU')) {
  28. define('NOREQUIREMENU', '1');
  29. }
  30. if (!defined('NOREQUIREHTML')) {
  31. define('NOREQUIREHTML', '1');
  32. }
  33. if (!defined('NOREQUIREAJAX')) {
  34. define('NOREQUIREAJAX', '1');
  35. }
  36. if (!defined('NOREQUIRESOC')) {
  37. define('NOREQUIRESOC', '1');
  38. }
  39. if (!defined('NOCSRFCHECK')) {
  40. define('NOCSRFCHECK', '1');
  41. }
  42. if (empty($_GET['keysearch']) && !defined('NOREQUIREHTML')) {
  43. define('NOREQUIREHTML', '1');
  44. }
  45. require '../../../main.inc.php';
  46. dol_include_once('/documentfollower/class/documentfollowerprocess.class.php');
  47. dol_include_once('/documentfollower/class/dfprocessajaxhandler.class.php');
  48. /*
  49. * View
  50. */
  51. dol_syslog("Call ajax custom/documentfollower/ajax/dfprocess.php");
  52. top_httphead('application/json');
  53. $ref = GETPOST('ref', 'aZ09');
  54. $id = GETPOST('id', 'aZ09');
  55. $operation = GETPOST('type', 'int');
  56. $level = GETPOST('level', 'int');
  57. $description = GETPOST('description', 'aZ09');
  58. // missing parameters
  59. if (empty($id) || empty($ref)) {
  60. http_response_code(400);
  61. return;
  62. }
  63. // object by ref
  64. $object = new DocumentFollowerProcess($db);
  65. if ($object->fetch(null, $ref) < 1) {
  66. http_response_code(404);
  67. return;
  68. }
  69. // encoded ID not equals with the parameter ID
  70. if (hash('sha512', $object->id) !== $id) {
  71. http_response_code(500);
  72. return;
  73. }
  74. $ajaxResult = [];
  75. try {
  76. if (empty($level)) {
  77. $level = null;
  78. }
  79. (new DfProcessAjaxHandler($object, $operation, $level, $description))->process();
  80. $ajaxResult = [
  81. 'success' => [
  82. 'message' => 'Sikeres mentés'
  83. ]
  84. ];
  85. } catch (\Exception $e) {
  86. $ajaxResult['error'] = [
  87. 'message' => 'Hiba történt a feldolgozás során'
  88. ];
  89. }
  90. $db->close();
  91. echo json_encode($ajaxResult);