mymodule.js.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /* Copyright (C) ---Put here your own copyright and developer email---
  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. *
  17. * Library javascript to enable Browser notifications
  18. */
  19. if (!defined('NOREQUIREUSER')) {
  20. define('NOREQUIREUSER', '1');
  21. }
  22. if (!defined('NOREQUIREDB')) {
  23. define('NOREQUIREDB', '1');
  24. }
  25. if (!defined('NOREQUIRESOC')) {
  26. define('NOREQUIRESOC', '1');
  27. }
  28. if (!defined('NOREQUIRETRAN')) {
  29. define('NOREQUIRETRAN', '1');
  30. }
  31. if (!defined('NOCSRFCHECK')) {
  32. define('NOCSRFCHECK', 1);
  33. }
  34. if (!defined('NOTOKENRENEWAL')) {
  35. define('NOTOKENRENEWAL', 1);
  36. }
  37. if (!defined('NOLOGIN')) {
  38. define('NOLOGIN', 1);
  39. }
  40. if (!defined('NOREQUIREMENU')) {
  41. define('NOREQUIREMENU', 1);
  42. }
  43. if (!defined('NOREQUIREHTML')) {
  44. define('NOREQUIREHTML', 1);
  45. }
  46. if (!defined('NOREQUIREAJAX')) {
  47. define('NOREQUIREAJAX', '1');
  48. }
  49. /**
  50. * \file htdocs/modulebuilder/template/js/mymodule.js.php
  51. * \ingroup mymodule
  52. * \brief JavaScript file for module MyModule.
  53. */
  54. // Load Dolibarr environment
  55. $res = 0;
  56. // Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
  57. if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
  58. $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
  59. }
  60. // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
  61. $tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1;
  62. while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
  63. $i--; $j--;
  64. }
  65. if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) {
  66. $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
  67. }
  68. if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/../main.inc.php")) {
  69. $res = @include substr($tmp, 0, ($i + 1))."/../main.inc.php";
  70. }
  71. // Try main.inc.php using relative path
  72. if (!$res && file_exists("../../main.inc.php")) {
  73. $res = @include "../../main.inc.php";
  74. }
  75. if (!$res && file_exists("../../../main.inc.php")) {
  76. $res = @include "../../../main.inc.php";
  77. }
  78. if (!$res) {
  79. die("Include of main fails");
  80. }
  81. // Define js type
  82. header('Content-Type: application/javascript');
  83. // Important: Following code is to cache this file to avoid page request by browser at each Dolibarr page access.
  84. // You can use CTRL+F5 to refresh your browser cache.
  85. if (empty($dolibarr_nocache)) {
  86. header('Cache-Control: max-age=3600, public, must-revalidate');
  87. } else {
  88. header('Cache-Control: no-cache');
  89. }
  90. ?>
  91. /* Javascript library of module MyModule */