datepicker_inline.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * JQuery data picker(inline version)
  4. *
  5. * @package event_calendar
  6. * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
  7. * @author Kevin Jardine <kevin@radagast.biz>
  8. * @copyright Radagast Solutions 2008 -2011
  9. * @link http://radagast.biz/
  10. *
  11. */
  12. if ($vars['group_guid']) {
  13. $link_bit = $vars['url']."event_calendar/group/{$vars['group_guid']}/%s/{$vars['mode']}";
  14. } else {
  15. $link_bit = $vars['url']."event_calendar/list/%s/{$vars['mode']}/{$vars['filter']}";
  16. }
  17. if ($vars['mode'] == 'week') {
  18. $selected_week = date('W',strtotime($vars['start_date'].' UTC'))+1;
  19. } else {
  20. $selected_week = '';
  21. }
  22. if ($vars['mode']) {
  23. $wrapper_class = "event-calendar-filter-period-".$vars['mode'];
  24. } else {
  25. $wrapper_class = "event-calendar-filter-period-month";
  26. }
  27. // TODO - figure out how to move this JavaScript
  28. ?>
  29. <script language="javascript">
  30. var selectedWeek = "<?php echo $selected_week; ?>";
  31. highlightWeek = function(d) {
  32. if (!selectedWeek) { return [true,''];}
  33. //var date = $(this).datepicker('getDate');
  34. var dayOfWeek = d.getUTCDay();
  35. var weekNumber = $.datepicker.iso8601Week(d);
  36. if (dayOfWeek == 6) {
  37. weekNumber += 1;
  38. }
  39. if (selectedWeek == weekNumber) {
  40. return [true,'week-highlight'];
  41. }
  42. return [true,''];
  43. }
  44. $(document).ready(function(){
  45. var done_loading = false;
  46. $("#<?php echo $vars['name']; ?>").datepicker({
  47. onChangeMonthYear: function(year, month, inst) {
  48. if(inst.onChangeToday){
  49. day=inst.selectedDay;
  50. }else{
  51. day=1;
  52. }
  53. if (done_loading) {
  54. // in this case the mode is forced to month
  55. document.location.href = "<?php echo $link_bit; ?>".replace('%s', year+'-'+month+'-1');
  56. }
  57. },
  58. onSelect: function(date) {
  59. // jump to the new page
  60. document.location.href = "<?php echo $link_bit; ?>".replace('%s', date.substring(0,10));
  61. },
  62. dateFormat: "yy-mm-dd",
  63. defaultDate: "<?php echo $vars['start_date'] .' - '.$vars['end_date']; ?>",
  64. beforeShowDay: highlightWeek
  65. });
  66. var start_date = $.datepicker.parseDate("yy-mm-dd", "<?php echo $vars['start_date']; ?>");
  67. var end_date = $.datepicker.parseDate("yy-mm-dd", "<?php echo $vars['end_date']; ?>");
  68. // not sure why this is necessary, but it seems to be
  69. if ("<?php echo $vars['mode'] ?>" == "month") {
  70. end_date += 1;
  71. }
  72. $("#<?php echo $vars['name']; ?>").datepicker("setDate", start_date, end_date);
  73. done_loading = true;
  74. });
  75. </script>
  76. <div style="position:relative;" id="<?php echo $vars['name']; ?>" class="<?php echo $wrapper_class; ?>" ></div>
  77. <p style="clear: both;"><!-- See day-by-day example for highlighting days code --></p>