constantonoff.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /* Copyright (C) 2011-2015 Regis Houssin <regis.houssin@inodbox.com>
  3. * Copyright (C) 2021 Laurent Destailleur <eldy@users.sourceforge.net>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/core/ajax/constantonoff.php
  20. * \brief File to set or del an on/off constant
  21. */
  22. if (!defined('NOTOKENRENEWAL')) {
  23. define('NOTOKENRENEWAL', '1'); // Disables token renewal
  24. }
  25. if (!defined('NOREQUIREMENU')) {
  26. define('NOREQUIREMENU', '1');
  27. }
  28. if (!defined('NOREQUIREHTML')) {
  29. define('NOREQUIREHTML', '1');
  30. }
  31. if (!defined('NOREQUIREAJAX')) {
  32. define('NOREQUIREAJAX', '1');
  33. }
  34. if (!defined('NOREQUIRESOC')) {
  35. define('NOREQUIRESOC', '1');
  36. }
  37. if (!defined('NOREQUIRETRAN')) {
  38. define('NOREQUIRETRAN', '1');
  39. }
  40. if (!defined('CSRFCHECK_WITH_TOKEN')) {
  41. define('CSRFCHECK_WITH_TOKEN', '1'); // Token is required even in GET mode
  42. }
  43. require '../../main.inc.php';
  44. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  45. $action = GETPOST('action', 'aZ09'); // set or del
  46. $name = GETPOST('name', 'alpha');
  47. $entity = GETPOST('entity', 'int');
  48. $value = ((GETPOST('value', 'int') || GETPOST('value', 'int') == '0') ? GETPOST('value', 'int') : 1);
  49. /*
  50. * View
  51. */
  52. // Ajout directives pour resoudre bug IE
  53. //header('Cache-Control: Public, must-revalidate');
  54. //header('Pragma: public');
  55. //top_htmlhead("", "", 1); // Replaced with top_httphead. An ajax page does not need html header.
  56. top_httphead();
  57. //print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
  58. // Registering the new value of constant
  59. if (!empty($action) && !empty($name)) {
  60. if ($user->admin) {
  61. if ($action == 'set') {
  62. dolibarr_set_const($db, $name, $value, 'chaine', 0, '', $entity);
  63. } elseif ($action == 'del') {
  64. dolibarr_del_const($db, $name, $entity);
  65. }
  66. }
  67. } else {
  68. http_response_code(403);
  69. }