datepicker.js.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. /* Copyright (C) 2011 Regis Houssin <regis.houssin@capnetworks.com>
  3. * Copyright (C) 2011 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 <http://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/core/js/datepicker.js.php
  20. * \brief File that include javascript functions for datepickers
  21. */
  22. //if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); // Not disabled cause need to load personalized language
  23. //if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1');
  24. if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
  25. //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); // Not disabled cause need to do translations
  26. if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK',1);
  27. if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL',1);
  28. if (! defined('NOLOGIN')) define('NOLOGIN',1);
  29. if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU',1);
  30. if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML',1);
  31. if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
  32. session_cache_limiter(FALSE);
  33. require_once '../../main.inc.php';
  34. // Define javascript type
  35. top_httphead('text/javascript; charset=UTF-8');
  36. // Important: Following code is to avoid page request by browser and PHP CPU at each Dolibarr page access.
  37. if (empty($dolibarr_nocache)) header('Cache-Control: max-age=3600, public, must-revalidate');
  38. else header('Cache-Control: no-cache');
  39. // Define tradMonths javascript array (we define this in datepicker AND in parent page to avoid errors with IE8)
  40. $tradMonths=array(
  41. dol_escape_js($langs->transnoentitiesnoconv("January")),
  42. dol_escape_js($langs->transnoentitiesnoconv("February")),
  43. dol_escape_js($langs->transnoentitiesnoconv("March")),
  44. dol_escape_js($langs->transnoentitiesnoconv("April")),
  45. dol_escape_js($langs->transnoentitiesnoconv("May")),
  46. dol_escape_js($langs->transnoentitiesnoconv("June")),
  47. dol_escape_js($langs->transnoentitiesnoconv("July")),
  48. dol_escape_js($langs->transnoentitiesnoconv("August")),
  49. dol_escape_js($langs->transnoentitiesnoconv("September")),
  50. dol_escape_js($langs->transnoentitiesnoconv("October")),
  51. dol_escape_js($langs->transnoentitiesnoconv("November")),
  52. dol_escape_js($langs->transnoentitiesnoconv("December"))
  53. );
  54. $tradMonthsShort=array(
  55. $langs->trans("JanuaryMin"),
  56. $langs->trans("FebruaryMin"),
  57. $langs->trans("MarchMin"),
  58. $langs->trans("AprilMin"),
  59. $langs->trans("MayMin"),
  60. $langs->trans("JuneMin"),
  61. $langs->trans("JulyMin"),
  62. $langs->trans("AugustMin"),
  63. $langs->trans("SeptemberMin"),
  64. $langs->trans("OctoberMin"),
  65. $langs->trans("NovemberMin"),
  66. $langs->trans("DecemberMin")
  67. );
  68. $tradDays=array(
  69. $langs->trans("Sunday"),
  70. $langs->trans("Monday"),
  71. $langs->trans("Tuesday"),
  72. $langs->trans("Wednesday"),
  73. $langs->trans("Thursday"),
  74. $langs->trans("Friday"),
  75. $langs->trans("Saturday")
  76. );
  77. $tradDaysShort=array(
  78. $langs->trans("ShortSunday"),
  79. $langs->trans("ShortMonday"),
  80. $langs->trans("ShortTuesday"),
  81. $langs->trans("ShortWednesday"),
  82. $langs->trans("ShortThursday"),
  83. $langs->trans("ShortFriday"),
  84. $langs->trans("ShortSaturday")
  85. );
  86. $tradDaysMin=array(
  87. $langs->trans("SundayMin"),
  88. $langs->trans("MondayMin"),
  89. $langs->trans("TuesdayMin"),
  90. $langs->trans("WednesdayMin"),
  91. $langs->trans("ThursdayMin"),
  92. $langs->trans("FridayMin"),
  93. $langs->trans("SaturdayMin")
  94. );
  95. ?>
  96. // For eldy and jQuery date picker
  97. var tradMonths = <?php echo json_encode($tradMonths) ?>;
  98. var tradMonthsShort = <?php echo json_encode($tradMonthsShort) ?>;
  99. var tradDays = <?php echo json_encode($tradDays) ?>;
  100. var tradDaysShort = <?php echo json_encode($tradDaysShort) ?>;
  101. var tradDaysMin = <?php echo json_encode($tradDaysMin) ?>;
  102. // For JQuery date picker
  103. $(document).ready(function() {
  104. $.datepicker.setDefaults({
  105. autoSize: true,
  106. changeMonth: true,
  107. changeYear: true,
  108. altField: '#timestamp',
  109. altFormat: '@' // Gives a timestamp dateformat
  110. });
  111. });
  112. jQuery(function($){
  113. $.datepicker.regional['<?php echo $langs->defaultlang ?>'] = {
  114. closeText: '<?php echo $langs->trans("Close2") ?>',
  115. prevText: '<?php echo $langs->trans("Previous") ?>',
  116. nextText: '<?php echo $langs->trans("Next") ?>',
  117. currentText: '<?php echo $langs->trans("Now") ?>',
  118. monthNames: tradMonths,
  119. monthNamesShort: tradMonthsShort,
  120. dayNames: tradDays,
  121. dayNamesShort: tradDaysShort,
  122. dayNamesMin: tradDaysMin,
  123. weekHeader: '<?php echo $langs->trans("Week"); ?>',
  124. dateFormat: '<?php echo $langs->trans("FormatDateShortJQuery"); ?>',
  125. firstDay: <?php echo (isset($conf->global->MAIN_START_WEEK)?$conf->global->MAIN_START_WEEK:'1'); ?>,
  126. isRTL: <?php echo ($langs->trans("DIRECTION")=='rtl'?'true':'false'); ?>,
  127. showMonthAfterYear: false, // TODO add specific to country
  128. yearSuffix: '' // TODO add specific to country
  129. };
  130. $.datepicker.setDefaults($.datepicker.regional['<?php echo $langs->defaultlang ?>']);
  131. });
  132. <?php
  133. if (is_object($db)) $db->close();