Leitgedanken/outlook.php_20200212
2022-11-21 09:47:28 +01:00

847 lines
26 KiB
Plaintext

<?php
## Die Datei ist als ANSI abgespeichert und kein encoding wurde vorgenommen. Das könnte in Zeile 708ff erfolgen
## Somit ist der Export für SOGo (Jochen geeignet), aber nicht für Outlook, welches UTF8 benötigt
/*
# Fuer debugging
error_reporting(E_ALL);
ini_set('display_errors', 1);
#echo __LINE__."<br>";
*/
$user_admin=$_COOKIE["user_admin"];
require("config/datenbankanbindung.php"); // f&uuml;gt die Datenbankanbindung ein: Sys:\php\includes\kurs\datenbankanbindung.php
$db = dbconnect();
$result_header = $db->query("SELECT export_header FROM profil WHERE user = '$user_admin'");
$row_header = $result_header->fetch_array();
if($row_header['export_header'] == 'utf8'){
header("Content-Type: text/html; charset=utf-8");
}
require_once("func_rollenrechte.php");
$user_admin=$_COOKIE["user_admin"];
$timezone = 'Europe/Berlin';
ini_set('date.timezone',$timezone);
if(isset($_GET['mon'])){
$mon = $_GET['mon'];
}else{
$mon = "";
}
if(isset($_GET['jahr'])){
$jahr = $_GET['jahr'];
}else{
$jahr = "";
}
if(isset($_GET['tag'])){
$tag = $_GET['tag'];
}else{
$tag = "";
}
if(isset($_GET['typ'])){
$typ = $_GET['typ'];
}else{
$typ = "";
}
if(isset($_GET['lid'])){
$lid = $_GET['lid'];
}else{
$lid = "";
}
// Rechteüberprüfung
$db = dbconnect();
if ($user_admin == ""){ require("index.php"); exit;} //Wenn man nicht angemeldet ist, darf man nicht auf die Seite
if(!rore($user_admin,'a_outlook','RE')){require("lib/rechte.php");exit;}
// Rechteüberprüfung ende
$db = dbconnect();
if($mon < 10){
$mon = "0".$mon; # 0 voranstellen
}
#################
## TYP=1 Einzelexport
#################
if ($typ == 1){
$datum = "$jahr-$mon-$tag";
$Filename = "LG-Online_Monat_$lid.ics";
$query2 = "SELECT lid, textstelle, ueberschrift, vorwort, botschaft, textwort, inhalt, zusammenfassung, kontext, datum, DATE_Format(datum, '%d') tag, DATE_Format(datum, '%m') monat, DATE_Format(datum, '%Y') jahr, DATE_Format(datum, '%Y-%m-%d')AS datum_berechnung
FROM quelle
WHERE lid=$lid
";
}
#################
## TYP=2 Monatsexport
#################
if ($typ == 2){
$Filename = "LG-Online_Monat-$jahr_$mon.ics";
$datum = "$jahr-$mon";
$query2 = "SELECT lid, textstelle, ueberschrift, textwort, vorwort, botschaft, inhalt, zusammenfassung, kontext, datum, DATE_Format(datum, '%d') tag, DATE_Format(datum, '%m') monat, DATE_Format(datum, '%Y') jahr, DATE_Format(datum, '%Y-%m-%d')AS datum_berechnung
FROM quelle
WHERE datum LIKE'$datum%'
AND kid=1
AND ( ukid=1 OR ukid=2 OR ukid=6 OR ukid=13 OR ukid=14 OR ukid=15 OR ukid=16 OR ukid=17 OR ukid=22 OR ukid=25 OR ukid=26 OR ukid=30 OR ukid=68 )
ORDER BY datum ASC
";
}
header("Content-Type: text/x-vCalendar");
header("Content-Disposition: inline; filename=$Filename");
$result = $db->query( $query2)
or die ("Cannot execute query2");
echo"BEGIN:VCALENDAR
VERSION:2.0
METHOD:PUBLISH";
while ($row = $result->fetch_array()){
$uid = md5($row['lid']);
$lieder=""; ## Sonst bekommen bei der Schleife die nachfolgenden GDs dieselben Lieder, wenn keine erfasst wurden
$el="";
$al="";
$wl="";
$date_nlg = mktime(0, 0, 0, 12, 1, 2007); // Datum ab dem neue LGs gelten
$date_nlg_format = date("Y-m-d", $date_nlg); // ISO-8601 Format wie in der Datenbank: Formatierung f&uuml;r Vergleiche erforderlich
$switch_date = strtotime ($date_nlg_format); //Umrechnung des Fristgrenztages in eine Zahl
$lg_datum = strtotime ($row[datum_berechnung]); // Umrechnung des Enddatums in eine Zahl
$result2 = $db->query("SELECT notiz
FROM notizen
WHERE lid = '$row[lid]'
AND user = '$user_admin'
");
$row2 = $result2->fetch_array();
##################################
## Aufbau der Lieder
##################################
$query = "SELECT nr, titel FROM lieder_quelle, lieder WHERE art='el' AND lid=$row[lid] AND lieder_quelle.gbid = lieder.gbid ORDER BY lieder.gbid";
$result4 = $db->query( $query)
or die ("Cannot execute query4");
$zaehler = 1;
$el ="";
while ($row4 = $result4->fetch_array()){
if($zaehler != 1){
$el .= "; $row4[nr] - $row4[titel]";
}else{
$el = "Eingangslied: $row4[nr] - $row4[titel]";
$zaehler = $zaehler+1;
}
}
$query = "SELECT nr, titel FROM lieder_quelle, lieder WHERE art='al' AND lid=$row[lid] AND lieder_quelle.gbid = lieder.gbid ORDER BY lieder.gbid";
$result4 = $db->query( $query)
or die ("Cannot execute query AL");
$zaehler = 1;
$al ="";
while ($row4 = $result4->fetch_array()){
if($zaehler != 1){
$al .= "; $row4[nr] - $row4[titel]";
}else{
$al = "Abendmahlslied: $row4[nr] - $row4[titel]";
$zaehler = $zaehler+1;
}
}
$query = "SELECT nr, titel FROM lieder_quelle, lieder WHERE art='wl' AND lid=$row[lid] AND lieder_quelle.gbid = lieder.gbid ORDER BY lieder.gbid";
$result4 = $db->query( $query)
or die ("Cannot execute query WL");
$zaehler = 1;
$wl ="";
while ($row4 = $result4->fetch_array()){
if($zaehler != 1){
$wl .= "; $row4[nr] - $row4[titel]";
}else{
$wl = "Weitere Lieder: $row4[nr] - $row4[titel]";
$zaehler = $zaehler+1;
}
}
$query = "SELECT nr, titel FROM lieder_quelle, lieder WHERE art='bl' AND lid=$row[lid] AND lieder_quelle.gbid = lieder.gbid ORDER BY lieder.gbid";
$result5 = $db->query( $query)
or die ("Cannot execute query BL");
$zaehler = 1;
$bl = "";
while ($row5 = $result5->fetch_array()){
if($zaehler != 1){
$bl .= "; $row5[nr] - $row5[titel]";
}else{
$bl = "Bußlied: $row5[nr] - $row5[titel]";
$zaehler = $zaehler+1;
}
}
if ($el != ""){
$el .= "\\n";
}
if ($al != ""){
$al .= "\\n";
}
if ($wl != ""){
$wl .= "\\n";
}
if ($bl != ""){
$bl .= "\\n";
}
if ($el != "" OR $al != "" OR $wl != "" OR $bl != ""){
$lieder ="$el$bl$al$wl\\n";
}
##################################
## Aufbau der Lieder ENDE
##################################
$text = strip_tags($row['inhalt'],'<br>,<li>,<p>,<ul>');
$textstelle = strip_tags($row['textstelle'],'<br>,<li>,<p>,<ul>');
$textwort = strip_tags($row['textwort'],'<br>,<li>,<p>,<ul>');
$ueberschrift = strip_tags($row['ueberschrift'],'<br>,<li>,<p>,<ul>');
$notiz = strip_tags($row2['notiz'],'<br>,<li>,<p>,<ul>');
# =0D=0A --> Zeilenumbrüche im VCS
if ($lg_datum >= $switch_date){
$botschaft = strip_tags($row['botschaft'],'<br>,<li>,<p>,<ul>');
$vorwort = strip_tags($row['vorwort'],'<br>,<li>,<p>,<ul>');
$zusammenfassung = strip_tags($row['zusammenfassung'],'<br>,<li>,<p>,<ul>');
$kontext = strip_tags($row['kontext'],'<br>,<li>,<p>,<ul>');
}
$lieder = str_replace (array("<br /><ul>",
"<br /> ",
"<br />",
"<ul>",
"<li>",
"</li>",
"&auml;",
"&Auml;",
"&uuml;",
"&Uuml;",
"&ouml;",
"&Ouml;",
"&szlig;",
"&bdquo;",
"&ldquo;",
"\t",
"</ul>",
"&#39;"
)
, array('',
"\\n",
"\\n",
"",
'\\n-',
"",
"ä",
"Ä",
"ü",
"Ü",
"ö",
"Ö",
"ß",
"\"",
"\"",
"",
"\\n",
"'"
)
, $lieder
);
$lieder = trim(str_replace(array("\n", "\r")
, array("","")
, $lieder
));
$lieder = html_entity_decode($lieder);
$textstelle = str_replace (array("<br /><ul>",
"<br /> ",
"<br />",
"<ul>",
"<li>",
"</li>",
"&auml;",
"&Auml;",
"&uuml;",
"&Uuml;",
"&ouml;",
"&Ouml;",
"&szlig;",
"&bdquo;",
"&ldquo;",
"\t",
"</ul>",
"&#39;"
)
, array('',
"\\n",
"\\n",
"",
'\\n-',
"",
"ä",
"Ä",
"ü",
"Ü",
"ö",
"Ö",
"ß",
"\"",
"\"",
"",
"\\n",
"'"
)
, $textstelle
);
$textstelle = trim(str_replace(array("\n", "\r")
, array("","")
, $textstelle
));
$textstelle = html_entity_decode($textstelle);
$textwort = str_replace (array("<br /><ul>",
"<br /> ",
"<br />",
"<ul>",
"<li>",
"</li>",
"&auml;",
"&Auml;",
"&uuml;",
"&Uuml;",
"&ouml;",
"&Ouml;",
"&szlig;",
"&bdquo;",
"&ldquo;",
"\t",
"</ul>",
"&#39;"
)
, array('',
"\\n",
"\\n",
"",
'\\n-',
"",
"ä",
"Ä",
"ü",
"Ü",
"ö",
"Ö",
"ß",
"\"",
"\"",
"",
"\\n",
"'"
)
, $textwort
);
$textwort = trim(str_replace(array("\n", "\r")
, array("","")
, $textwort
));
$textwort = html_entity_decode($textwort);
$text = str_replace (array("<br /><ul>",
"<br /> ",
"<br />",
"<ul>",
"<li>",
"</li>",
"&auml;",
"&Auml;",
"&uuml;",
"&Uuml;",
"&ouml;",
"&Ouml;",
"&szlig;",
"&bdquo;",
"&ldquo;",
"\t",
"</ul>",
"&#39;"
)
, array('',
"\\n",
"\\n",
"",
'\\n-',
"",
"ä",
"Ä",
"ü",
"Ü",
"ö",
"Ö",
"ß",
"\"",
"\"",
"",
"\\n",
"'"
)
, $text
);
$text = trim(str_replace(array("\n", "\r")
, array("","")
, $text
));
$text = html_entity_decode($text);
$ueberschrift = str_replace (array("<br /><ul>",
"<br /> ",
"<br />",
"<ul>",
"<li>",
"</li>",
"&auml;",
"&Auml;",
"&uuml;",
"&Uuml;",
"&ouml;",
"&Ouml;",
"&szlig;",
"&bdquo;",
"&ldquo;",
"\t",
"</ul>",
"&#39;"
)
, array('',
"\\n",
"\\n",
"",
'\\n-',
"",
"ä",
"Ä",
"ü",
"Ü",
"ö",
"Ö",
"ß",
"\"",
"\"",
"",
"\\n",
"'"
)
, $ueberschrift
);
$ueberschrift = trim(str_replace(array("\n", "\r")
, array("","")
, $ueberschrift
));
$ueberschrift = html_entity_decode($ueberschrift);
if ($ueberschrift == ""){
$ueberschrift_header = "";
}else{
$ueberschrift_header = "\\n\\nÜberschrift:\\n";
}
$notiz = str_replace (array("<br /><ul>",
"<br /> ",
"<br />",
"<ul>",
"<li>",
"</li>",
"&auml;",
"&Auml;",
"&uuml;",
"&Uuml;",
"&ouml;",
"&Ouml;",
"&szlig;",
"&bdquo;",
"&ldquo;",
"\t",
"</ul>",
"&#39;"
)
, array('',
"\\n",
"\\n",
"",
'\\n-',
"",
"ä",
"Ä",
"ü",
"Ü",
"ö",
"Ö",
"ß",
"\"",
"\"",
"",
"\\n",
"'"
)
, $notiz
);
$notiz = trim(str_replace(array("\n", "\r")
, array("","")
, $notiz
));
$notiz = html_entity_decode($notiz);
if ($notiz == ""){
$notiz_header = "";
}else{
$notiz_header = "\\n\\nNotizen:\\n";
}
if ($lg_datum >= $switch_date){ #Neue LGs?
$text_header="\\n\\nAusführungen:\\n"; ## Soll nur angezeigt werden in den neuen LGs
$vorwort = str_replace (array("<br /><ul>",
"<br /> ",
"<br />",
"<ul>",
"<li>",
"</li>",
"&auml;",
"&Auml;",
"&uuml;",
"&Uuml;",
"&ouml;",
"&Ouml;",
"&szlig;",
"&bdquo;",
"&ldquo;",
"\t",
"</ul>",
"&#39;"
)
, array('',
"\\n",
"\\n",
"",
'\\n-',
"",
"ä",
"Ä",
"ü",
"Ü",
"ö",
"Ö",
"ß",
"\"",
"\"",
"",
"\\n",
"'"
)
, $vorwort
);
$vorwort = html_entity_decode($vorwort);
$vorwort = trim(str_replace(array("\n", "\r")
, array("","")
, $vorwort
));
$vorwort_header="\\n\\nVorwort:\\n";
$botschaft = str_replace (array("<br /><ul>",
"<br /> ",
"<br />",
"<ul>",
"<li>",
"</li>",
"&auml;",
"&Auml;",
"&uuml;",
"&Uuml;",
"&ouml;",
"&Ouml;",
"&szlig;",
"&bdquo;",
"&ldquo;",
"\t",
"</ul>",
"&#39;"
)
, array('',
"\\n",
"\\n",
"",
'\\n-',
"",
"ä",
"Ä",
"ü",
"Ü",
"ö",
"Ö",
"ß",
"\"",
"\"",
"",
"\\n",
"'"
)
, $botschaft
);
$botschaft = html_entity_decode($botschaft);
$botschaft = trim(str_replace(array("\n", "\r")
, array("","")
, $botschaft
));
$botschaft_header="\\n\\nBotschaft:\\n";
$zusammenfassung = str_replace (array("<br /><ul>",
"<br /> ",
"<br />",
"<ul>",
"<li>",
"</li>",
"&auml;",
"&Auml;",
"&uuml;",
"&Uuml;",
"&ouml;",
"&Ouml;",
"&szlig;",
"&bdquo;",
"&ldquo;",
"\t",
"</ul>",
"&#39;"
)
, array('',
"\\n",
"\\n",
"",
'\\n-',
"",
"ä",
"Ä",
"ü",
"Ü",
"ö",
"Ö",
"ß",
"\"",
"\"",
"",
"\\n",
"'"
)
, $zusammenfassung
);
$zusammenfassung = trim(str_replace(array("\n", "\r")
, array("","")
, $zusammenfassung
));
$zusammenfassung = html_entity_decode($zusammenfassung);
# Das Tag <ul> wird durch Zeilenumbruch ersetzt (=0D=0A). Gerade bei der Zusammenfassung
# kommt es vor, dass mit <ul> begonnen wird. Dann soll nicht gleich eine Leerzeile
# nach der Überschrift erscheinen
if(preg_match("/^=0D=0A/", $zusammenfassung)){
$zusammenfassung_header="=\\n\\nZusammenfassung:";
}else{
$zusammenfassung_header="\\n\\nZusammenfassung:\\n";
}
$kontext = str_replace (array("<br /><ul>",
"<br /> ",
"<br />",
"<ul>",
"<li>",
"</li>",
"&auml;",
"&Auml;",
"&uuml;",
"&Uuml;",
"&ouml;",
"&Ouml;",
"&szlig;",
"&bdquo;",
"&ldquo;",
"\t",
"</ul>",
"&#39;"
)
, array('',
"\\n",
"\\n",
"",
'\\n-',
"",
"ä",
"Ä",
"ü",
"Ü",
"ö",
"Ö",
"ß",
"\"",
"\"",
"",
"\\n",
"'"
)
, $kontext
);
$kontext = trim(str_replace(array("\n", "\r")
, array("","")
, $kontext
));
$kontext = html_entity_decode($kontext);
$kontext_header="\\n\\nKontext:\\n";
}
$wochentag = date("l", mktime(0,0,0,$row['monat'],$row['tag'],$row['jahr']));
$result_gd = $db->query("SELECT wgd FROM profil WHERE user = '$user_admin'");
$row_gd = $result_gd->fetch_array();
if($wochentag == 'Wednesday' AND $row_gd['wgd'] != '0'){
$datum = date("Ymd", mktime(0,0,0,$row['monat'],$row['tag']+$row_gd['wgd'],$row['jahr'])); // + relativer Tag zum Mittwoch Do--> +1
}else{
$datum = date("Ymd", mktime(0,0,0,$row['monat'],$row['tag'],$row['jahr'])); // Diese Zeile ist für Sonntag, da braucht man den Tag ja nicht verschieben, nur Werktags
}
# Pear Package date: Wird hier zur Überprüfung der Sommerzeit verwendet
require_once("Date/Date.php");
$date=new Date("$row[jahr]-$row[monat]-$row[tag] 06:00:00"); ## Uhrzeit egal. Zu den Zeiten wo GDs stattfinden ist die Zeitumstellung schon rum
// UTC hat keine Sommerzeit
$date->setTZbyID("Europe/Berlin");
if (true==$date->inDaylightTime())
{
$faktor = "0";
}else{
$faktor = "1";
}
switch($wochentag)
{
case 'Sunday':
$stunde_beg = 7+$faktor; # Sommerzeitbedingt
$stunde_end = 8+$faktor; # Sommerzeitbedingt
$vCalStart = "$datum"."T0".$stunde_beg."3000Z";
$vCalEnd ="$datum"."T0".$stunde_end."3000Z";
break;
case 'Wednesday':
$stunde_beg = 18+$faktor; # Sommerzeitbedingt
$stunde_end = 19+$faktor; # Sommerzeitbedingt
$vCalStart = "$datum"."T".$stunde_beg."0000Z";
$vCalEnd ="$datum"."T".$stunde_end."0000Z";
break;
case 'Thursday':
$stunde_beg = 18+$faktor; # Sommerzeitbedingt
$stunde_end = 19+$faktor; # Sommerzeitbedingt
$vCalStart = "$datum"."T".$stunde_beg."0000Z";
$vCalEnd ="$datum"."T".$stunde_end."0000Z";
break;
default:
$stunde_beg = 7+$faktor; # Sommerzeitbedingt
$stunde_end = 8+$faktor; # Sommerzeitbedingt
$vCalStart = "$datum"."T0".$stunde_beg."3000Z";
$vCalEnd ="$datum"."T0".$stunde_end."3000Z";
break;
}
$lieder = strip_tags($lieder);
$textwort = strip_tags($textwort);
$vorwort_header = strip_tags($vorwort_header);
$vorwort = strip_tags($vorwort);
$botschaft_header = strip_tags($botschaft_header);
$botschaft = strip_tags($botschaft);
$text_header = strip_tags($text_header);
$text = strip_tags($text);
$zusammenfassung_header = strip_tags($zusammenfassung_header);
$zusammenfassung = strip_tags($zusammenfassung);
$kontext_header = strip_tags($kontext_header);
$kontext = strip_tags($kontext);
$notiz_header = strip_tags($notiz_header);
$notiz = strip_tags($notiz);
$ueberschrift_header = strip_tags($ueberschrift_header);
$ueberschrift = strip_tags($ueberschrift);
$textstelle = strip_tags($textstelle);
$description = "$lieder$textstelle: \"$textwort\" $ueberschrift_header$ueberschrift $vorwort_header$vorwort $botschaft_header$botschaft $text_header$text $zusammenfassung_header$zusammenfassung $kontext_header$kontext $notiz_header$notiz";
echo"
BEGIN:VEVENT
DTSTART:$vCalStart
DTEND:$vCalEnd
LOCATION:
TRANSP: OPAQUE
SEQUENCE:0
SUMMARY:Gottesdienst: $ueberschrift
CATEGORIES:NAK
DESCRIPTION:$description
PRIORITY:1
CLASS:PUBLIC
ATTACH;VALUE=URL:http://www.lg-on.de
UID: $uid
END:VEVENT";
}
echo"END:VCALENDAR";
exit;
?>