time-zones.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <?php
  2. include "../ucenter/user.php";
  3. include "../../../lang/lang.php";
  4. ?>
  5. <!DOCTYPE html>
  6. <html>
  7. <head>
  8. <meta charset="utf-8" />
  9. <link href="../lib/main.css" rel="stylesheet" />
  10. <script src="../lib/main.js"></script>
  11. <script>
  12. function getCookie(name) {
  13. var start = document.cookie.indexOf(name + "=");
  14. var len = start + name.length + 1;
  15. if (!start && name != document.cookie.substring(0, name.length)) {
  16. return null;
  17. }
  18. if (start == -1) return null;
  19. var end = document.cookie.indexOf(";", len);
  20. if (end == -1) end = document.cookie.length;
  21. return decodeURI(document.cookie.substring(len, end));
  22. }
  23. document.addEventListener("DOMContentLoaded", function () {
  24. var initialTimeZone = "local";
  25. var timeZoneSelectorEl = document.getElementById("time-zone-selector");
  26. var loadingEl = document.getElementById("loading");
  27. var calendarEl = document.getElementById("calendar");
  28. var calendar = new FullCalendar.Calendar(calendarEl, {
  29. timeZone: initialTimeZone,
  30. locale: getCookie("language"),
  31. headerToolbar: {
  32. left: "prev,next today",
  33. center: "title",
  34. right: "dayGridMonth,timeGridWeek,timeGridDay,listWeek",
  35. },
  36. //initialDate: "2020-12-12",
  37. navLinks: true, // can click day/week names to navigate views
  38. editable: true,
  39. selectable: true,
  40. dayMaxEvents: true, // allow "more" link when too many events
  41. events: {
  42. url: "php/get_events.php",
  43. failure: function () {
  44. document.getElementById("script-warning").style.display = "inline"; // show
  45. },
  46. },
  47. eventClick: function (info) {
  48. info.jsEvent.preventDefault(); // don't let the browser navigate
  49. if (info.event.url) {
  50. window.open(info.event.url);
  51. }
  52. },
  53. loading: function (bool) {
  54. if (bool) {
  55. loadingEl.style.display = "inline"; // show
  56. } else {
  57. loadingEl.style.display = "none"; // hide
  58. }
  59. },
  60. eventTimeFormat: { hour: "numeric", minute: "2-digit" },
  61. dateClick: function (arg) {
  62. console.log("dateClick", calendar.formatIso(arg.date));
  63. },
  64. select: function (arg) {
  65. console.log("select", calendar.formatIso(arg.start), calendar.formatIso(arg.end));
  66. },
  67. });
  68. calendar.render();
  69. // load the list of available timezones, build the <select> options
  70. // it's HIGHLY recommended to use a different library for network requests, not this internal util func
  71. FullCalendar.requestJson(
  72. "GET",
  73. "php/get-time-zones.php",
  74. {},
  75. function (timeZones) {
  76. timeZones.forEach(function (timeZone) {
  77. var optionEl;
  78. if (timeZone !== "UTC") {
  79. // UTC is already in the list
  80. optionEl = document.createElement("option");
  81. optionEl.value = timeZone;
  82. optionEl.innerText = timeZone;
  83. timeZoneSelectorEl.appendChild(optionEl);
  84. }
  85. });
  86. },
  87. function () {
  88. // TODO: handle error
  89. }
  90. );
  91. // when the timezone selector changes, dynamically change the calendar option
  92. timeZoneSelectorEl.addEventListener("change", function () {
  93. calendar.setOption("timeZone", this.value);
  94. });
  95. });
  96. </script>
  97. <style>
  98. body {
  99. margin: 0;
  100. padding: 0;
  101. font-family: Arial, Helvetica Neue, Helvetica, sans-serif;
  102. font-size: 14px;
  103. }
  104. #top {
  105. background: #eee;
  106. border-bottom: 1px solid #ddd;
  107. padding: 0 10px;
  108. line-height: 40px;
  109. font-size: 12px;
  110. }
  111. .left {
  112. float: left;
  113. }
  114. .right {
  115. float: right;
  116. }
  117. .clear {
  118. clear: both;
  119. }
  120. #script-warning,
  121. #loading {
  122. display: none;
  123. }
  124. #script-warning {
  125. font-weight: bold;
  126. color: red;
  127. }
  128. #calendar {
  129. max-width: 1100px;
  130. margin: 40px auto;
  131. padding: 0 10px;
  132. }
  133. .tzo {
  134. color: #000;
  135. }
  136. </style>
  137. </head>
  138. <body>
  139. <div id="top">
  140. <div class="left">
  141. Timezone:
  142. <select id="time-zone-selector">
  143. <option value="local" selected>local</option>
  144. <option value="UTC">UTC</option>
  145. </select>
  146. </div>
  147. <div class="right">
  148. <span id="loading">loading...</span>
  149. <span id="script-warning"><code>php/get-events.php</code> must be running.</span>
  150. </div>
  151. <div class="clear"></div>
  152. </div>
  153. <div id="calendar"></div>
  154. </body>
  155. </html>