list.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * scientia
  4. *
  5. * Copyright 2023 - 2024 Johannes Keßler
  6. *
  7. * https://www.bananas-playground.net/projekt/scientia/
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see http://www.gnu.org/licenses/gpl-3.0.
  21. */
  22. $TemplateData['entries'] = array();
  23. require_once 'lib/entry.class.php';
  24. $Entry = new Entry($DB);
  25. $searchTerm = '';
  26. if(isset($_POST['submitForm']) && isset($_POST['searchInput'])) {
  27. if(Summoner::validate($_POST['searchInput'])) {
  28. $searchTerm = trim($_POST['searchInput']);
  29. }
  30. }
  31. // why?
  32. // mysql knows the dates and validates them. There is no 2020-02-31
  33. // the single date infos come from index.php
  34. $_groupByFormat = $_year;
  35. $breadcrumb = array('Y');
  36. $_intervalStart = '';
  37. $_intervalEnd = '';
  38. if(!empty($_requestDateProvided)) {
  39. if($_requestDateProvided === 'Y-m-d') {
  40. $queryLimit = "";
  41. $_groupByFormat = $_year.'-'.$_month.'-'.$_day;
  42. $_intervalStart = $_groupByFormat;
  43. $_intervalEnd = $_groupByFormat;
  44. $breadcrumb = array('Y','m','d');
  45. }
  46. elseif ($_requestDateProvided === 'Y-m') {
  47. $queryLimit = "";
  48. $_groupByFormat = $_year.'-'.$_month;
  49. $_intervalStart = $_groupByFormat.'-01';
  50. $_tDate = new DateTime( $_intervalStart );
  51. $_monthDays = $_tDate->format( 't' );
  52. $_intervalEnd = $_groupByFormat.'-'.$_monthDays;
  53. $breadcrumb = array('Y','m');
  54. }
  55. elseif ($_requestDateProvided === 'Y') {
  56. $_intervalStart = $_groupByFormat.'-01-01';
  57. $_intervalEnd = $_groupByFormat.'-12-31';
  58. }
  59. } else {
  60. $_requestDateProvided = 'Y';
  61. }
  62. $entries = $Entry->list($searchTerm, $_intervalStart, $_intervalEnd);
  63. foreach($entries as $k=>$entry) {
  64. $_d = new DateTime($entry['date']);
  65. $_breadcrumb = array();
  66. foreach($breadcrumb as $_b) {
  67. $_breadcrumb[] = $_d->format($_b);
  68. }
  69. $TemplateData['entries'][$_d->format($_requestDateProvided)]['breadcrumb'] = $_breadcrumb;
  70. $TemplateData['entries'][$_d->format($_requestDateProvided)]['e'][$entry['ident']] = $entry;
  71. $TemplateData['entries'][$_d->format($_requestDateProvided)]['e'][$entry['ident']]['link'] = str_replace('-','/',$entry['date']).'/'.$entry['ident'];
  72. }