ajax.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. /* For license terms, see /license.txt */
  3. require_once __DIR__.'/../../main/inc/global.inc.php';
  4. $action = isset($_REQUEST['a']) ? $_REQUEST['a'] : '';
  5. $calendarId = isset($_REQUEST['id']) ? $_REQUEST['id'] : 0;
  6. $plugin = LearningCalendarPlugin::create();
  7. $item = $plugin->getCalendar($calendarId);
  8. $plugin->protectCalendar($item);
  9. switch ($action) {
  10. case 'toggle_day':
  11. $startDate = isset($_REQUEST['start_date']) ? $_REQUEST['start_date'] : '';
  12. if (empty($startDate)) {
  13. exit;
  14. }
  15. $endDate = isset($_REQUEST['end_date']) ? $_REQUEST['end_date'] : '';
  16. if ($startDate == $endDate) {
  17. // One day
  18. $plugin->toogleDayType($calendarId, $startDate);
  19. } else {
  20. // A list of days
  21. $startDateTime = new DateTime($startDate);
  22. $endDateTime = new DateTime($endDate);
  23. $diff = $startDateTime->diff($endDateTime);
  24. $countDays = $diff->format('%a');
  25. $dayList[] = $startDate;
  26. for ($i = 0; $i < $countDays; $i++) {
  27. $startDateTime->modify('+1 day');
  28. $dayList[] = $startDateTime->format('Y-m-d');
  29. }
  30. foreach ($dayList as $day) {
  31. $plugin->toogleDayType($calendarId, $day);
  32. }
  33. }
  34. break;
  35. case 'get_events':
  36. $list = $plugin->getEvents($calendarId);
  37. echo json_encode($list);
  38. break;
  39. }