neuwies-kalender-generator-.../index.php

250 lines
11 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Copyright 2017 by George Ruinelli <george@ruinelli.ch>
Licence: GPL
Last Change: 10.02.2022
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<?php
include('common.php');
// Add the GET-Parameter "debug" for additional output
if(isset($_GET['debug'])) {
define('DEBUG', 1);
}
?>
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="shortcut icon" href="favicon.ico">
<title><? echo(NAME_OF_CHURCH); ?> Nächste Termine</title>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<?
$textStyle = "font-family: Arial; font-size: 11pt;";
$textStyleLarger = "font-family: Arial; font-size: 14pt;";
$titleStyle = "font-family: Arial Black; font-size: 14pt;";
$titleStyleLarger = "font-family: Arial Black; font-size: 16pt;";
?>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script src="javascript.js"></script>
</head>
<body style="background-color: #eee">
<div>
<h1>
<img src="logo_small.png" > &ndash; N&auml;chste Termine</h1>
<div style="margin: 20px">
<?
if(isset($_GET['date'])) {
$startDateForm = $_GET['date'];
}
else{
// http://php.net/manual/de/function.date.php
// select next sunday
// $startDateForm = $weekdays[date('N', strtotime('next sunday')) - 1] . date('. j. ', strtotime('next sunday')) . $monthNames[date('n', strtotime('next sunday')) - 1];
$startDateForm = date('d.m.Y', strtotime('next sunday'));
}
if(defined('DEBUG')) {
// echo("__" . date('n', strtotime('next sunday')) . "__");
// echo("__" . $monthNames[date('n', strtotime('next sunday')) - 1] . "__");
echo("<pre>startDateForm: $startDateForm</pre>\n");
}
$startDateCleaned = str_replace(" ", "", $startDateForm);
// $startDateCleaned = str_replace(".", " ", $startDateForm);
list($day, $month, $year) = explode(".", trim($startDateCleaned));
if(defined('DEBUG')) {
echo("<pre>startDateCleaned: $startDateCleaned</pre>\n");
echo("<pre>Day, Month, Year: $day, $month, $year</pre>\n");
}
if(isset($_GET['timeSpan'])) {
$timeSpan = $_GET['timeSpan'];
}
else{
$timeSpan = "1week";
}
if(defined('DEBUG')) {
echo("<pre>timeSpan: $timeSpan</pre>\n");
}
if($timeSpan == "1week"){
$timeSpanDays = 7;
$mode = "weeks";
}
elseif($timeSpan == "2weeks"){
$timeSpanDays = 14;
$mode = "weeks";
}
elseif($timeSpan == "3weeks"){
$timeSpanDays = 21;
$mode = "weeks";
}
elseif($timeSpan == "4weeks"){
$timeSpanDays = 28;
$mode = "weeks";
}
elseif($timeSpan == "16weeks"){
$timeSpanDays = 28*4;
$mode = "weeks";
}
elseif($timeSpan == "nextmonth" or $timeSpan == "afternextmonth"){
$mode = "months";
}
else{
die("Unbekannte Angabe für timeSpan!");
}
if(defined('DEBUG')) {
echo("<pre>mode: $mode</pre>\n");
}
if($mode == "weeks"){
$timeSpanSeconds = 3600 * 24 * $timeSpanDays;
// print_r($dateParts);
// echo("<br>" . $dateParts[1] . " " . $dateParts[2]);
// $startDate = strptime($dateParts[1] . " " . $dateParts[2], " %e. %m");
// $startDate = mktime(0, 0, 0, $monthDE[$dateParts[2]], $dateParts[1], date("Y"));
$startDate = mktime(0, 0, 0, $month, $day, $year);
// echo("<br>Start: $startDate<br>");
// echo("<br>Start: ". strftime("%c", $startDate) . "<br>");
$startDateIcs = strftime("%Y%m%dT000000Z", $startDate);
// echo("startDateIcs: ". $startDateIcs . "<br>");
$endDateIcs = strftime("%Y%m%dT235959Z", $startDate + $timeSpanSeconds);
// echo("endDateIcs: ". $endDateIcs . "<br><br>");
// $startDMY = strftime("%d.%m.%Y", $startDate);
$startDMY = strftime("%d. ", $startDate) . $monthNamesShort[(strftime("%m", $startDate)-1)*1] . strftime(". %Y", $startDate);
// $endDMY = strftime("%d.%m.%Y", $startDate + $timeSpanSeconds);
$endDMY = strftime("%d. ", $startDate + $timeSpanSeconds) . $monthNamesShort[(strftime("%m", $startDate + $timeSpanSeconds)-1)*1] . strftime(". %Y", $startDate + $timeSpanSeconds);
$startDayFormated = strftime("%e.", $startDate);
// $startMonthFormated = $monthNamesShort[(strftime("%m", $startDate)-1)*1] . ".";
$startMonthFormated = $monthNames[(strftime("%m", $startDate)-1)*1];
$startYearFormated = strftime("%Y", $startDate);
$endDayFormated = strftime("%e.", $startDate + $timeSpanSeconds);
// $endMonthFormated = $monthNamesShort[(strftime("%m", $startDate + $timeSpanSeconds)-1)*1] . ".";
$endMonthFormated = $monthNames[(strftime("%m", $startDate + $timeSpanSeconds)-1)*1];
$endYearFormated = strftime("%Y", $startDate + $timeSpanSeconds);
if ($startMonthFormated == $endMonthFormated) { # Start and end in same month
$formatedDateSpan = "$startDayFormated &ndash; $endDayFormated $endMonthFormated $endYearFormated";
}
else if (($startDayFormated != $endDayFormated) && ($startYearFormated == $endYearFormated)) { // Start and end not in same month but same year
$formatedDateSpan = "$startDayFormated $startMonthFormated &ndash; $endDayFormated $endMonthFormated $endYearFormated";
}
else { # Start and end not in same year
$formatedDateSpan = "$startDayFormated $startMonthFormated $startYearFormated &ndash; $endDayFormated $endMonthFormated $endYearFormated";
}
if(defined('DEBUG')) {
// echo("<pre>Month: -" . $dateParts[2] . "- => " . $monthDE[$dateParts[2]] . "</pre>\n");
echo("<pre>startDMY: $startDMY</pre>\n");
echo("<pre>mktime(0, 0, 0, $month, $day, $year);</pre>\n");
echo("<pre>endDMY: $endDMY</pre>\n");
}
}
else{ //months
$firstDayOfCurrentMonth = date("Y-m-01"); //2017-07-01
// $firstDayOfCurrentMonth = date("2016-12-1"); //test
// $firstDayOfCurrentMonth = date("2017-1-1"); //test
// $firstDayOfCurrentMonth = date("2017-2-1"); //test
if($timeSpan == "nextmonth"){
$firstOfMonth = strtotime ( '+1 month' , strtotime ( $firstDayOfCurrentMonth ) ) ;
}
else{ //after next month
$firstOfMonth = strtotime ( '+2 month' , strtotime ( $firstDayOfCurrentMonth ) ) ;
}
$lastDayOfMonth = strtotime ( '+1 month' , $firstOfMonth) - 1; //first day of next month minus 1 second
$startDateIcs = strftime("%Y%m%dT000000Z", $firstOfMonth);
$endDateIcs = strftime("%Y%m%dT235959Z", $lastDayOfMonth);
$monthNo = strftime("%m", $firstOfMonth);
$month = $monthNames[$monthNo-1];
$year = strftime("%Y", $firstOfMonth);
if(defined('DEBUG')) {
echo("<pre>startDateIcs: $startDateIcs ($firstOfMonth)</pre>");
echo("<pre>endDateIcs: $endDateIcs ($lastDayOfMonth)</pre>");
echo("<pre>firstOfMonth: $firstOfMonth ($monthNo)</pre>");
}
}
?>
<form action="index.php" method="get">
<input type=text class="date_input" name=date id=datepicker value="<? echo($startDateForm); ?>"
onchange="reloadPage(event.target.value, '<? echo($timeSpan); ?>');" size=10> <a href=".">Nächster Sonntag</a><br>
<label><input type="radio" name="timeSpan" value="1week" <? if($timeSpan == "1week"){ echo("checked=true"); } ?>
onclick="reloadPage('<? echo($startDateForm); ?>', '1week');">1 Woche</label><br>
<label><input type="radio" name="timeSpan" value="2weeks" <? if($timeSpan == "2weeks"){ echo("checked=true"); } ?>
onclick="reloadPage('<? echo($startDateForm); ?>', '2weeks');">2 Wochen</label><br>
<label><input type="radio" name="timeSpan" value="3weeks" <? if($timeSpan == "3weeks"){ echo("checked=true"); } ?>
onclick="reloadPage('<? echo($startDateForm); ?>', '3weeks');">3 Wochen</label><br>
<label><input type="radio" name="timeSpan" value="4weeks" <? if($timeSpan == "4weeks"){ echo("checked=true"); } ?>
onclick="reloadPage('<? echo($startDateForm); ?>', '4weeks');">4 Wochen</label><br>
<label><input type="radio" name="timeSpan" value="nextmonth" <? if($timeSpan == "nextmonth"){ echo("checked=true"); } ?>
onclick="reloadPage('<? echo($startDateForm); ?>', 'nextmonth');">Nächster Monat</label><br>
<label><input type="radio" name="timeSpan" value="afternextmonth" <? if($timeSpan == "afternextmonth"){ echo("checked=true"); } ?>
onclick="reloadPage('<? echo($startDateForm); ?>', 'afternextmonth');">Übernächster Monat</label>
<!-- <br> -->
<!-- <input type="submit" value="Lade Termine" style> -->
</form>
<hr>
<button style="width: 200px;" value="Program kopieren" onclick="selectElementContents( document.getElementById('Content') );">Programm kopieren</button>
<div id="Content" class="content">
<?
if($mode == "weeks"){
include('week.php');
}
else{ // months
include('month.php');
}
?>
</div>
<!-- <button style="width: 200px;" value="Program kopieren" onclick="selectElementContents( document.getElementById('Content') );">Programm kopieren</button> -->
<hr>
Quelle: <a href="<? echo(URL_TO_CALENDAR); ?>" target="_blank"><? echo(URL_TO_CALENDAR); ?></a><br>
Support: <a href="mailto:george[at]ruinelli.ch">george[at]ruinelli.ch</a>
</div>
</body>
</html>