constantonoff.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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', '0'); // Token is required even in GET mode
  42. }
  43. // Load Dolibarr environment
  44. require '../../main.inc.php';
  45. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  46. $action = GETPOST('action', 'aZ09'); // set or del
  47. $name = GETPOST('name', 'alpha');
  48. $entity = GETPOST('entity', 'int');
  49. $value = (GETPOST('value', 'aZ09') != '' ? GETPOST('value', 'aZ09') : 1);
  50. /*
  51. * View
  52. */
  53. // Ajout directives pour resoudre bug IE
  54. //header('Cache-Control: Public, must-revalidate');
  55. //header('Pragma: public');
  56. //top_htmlhead("", "", 1); // Replaced with top_httphead. An ajax page does not need html header.
  57. top_httphead();
  58. //print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
  59. // Registering the new value of constant
  60. if (!empty($action) && !empty($name)) {
  61. if ($user->admin) {
  62. if ($action == 'set') {
  63. dolibarr_set_const($db, $name, $value, 'chaine', 0, '', $entity);
  64. } elseif ($action == 'del') {
  65. dolibarr_del_const($db, $name, $entity);
  66. }
  67. }
  68. } else {
  69. http_response_code(403);
  70. }