1
0
Fork 0
This repository has been archived on 2020-09-27. You can view files and clone it, but cannot push or open issues or pull requests.
websites_kartontage-de/ical.php

71 lines
2.0 KiB
PHP

<?php
try {
$conn = new PDO("mysql:dbname=d02a1996;host=dd29132.kasserver.com", 'd02a1996', 'VaR3DFKpSThyBB7m');
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$conn-> exec("SET CHARACTER SET utf8");
} catch(PDOException $e) {
echo "Webseite wird momentan überarbeitet";
}
header('Content-type: text/calendar; charset=utf-8');
$stmt = $conn->prepare('select * from places');
if(isset($_GET["places_id"])){
$stmt = $conn->prepare('select * from places where id = :id');
$stmt->bindParam(':id', $_GET["places_id"]);
}else{
$filename = "all.ics";
}
$stmt->execute();
$result = $stmt->fetch(PDO::FETCH_ASSOC);
if(isset($_GET["places_id"])){
$filename = $result['name'].'.ics';
}else{
$filename = "all.ics";
}
header('Content-Disposition: inline; filename=' . $filename);
function dateToCal($timestamp) {
return date('Ymd\THis\Z', strtotime($timestamp));
}
// Escapes a string of characters
function escapeString($string) {
return preg_replace('/([\,;])/','\\\$1', str_replace("\n","\r\n ", str_replace("\r\n","\n",$string)));
}
$stmt = $conn->prepare('select events.*,places.address from events join places on events.places_id=places.id');
if(isset($_GET["places_id"])){
$stmt = $conn->prepare('select events.*,places.address from events join places on events.places_id=places.id where places_id = :id');
$stmt->bindParam(':id', $_GET["places_id"]);
}
$stmt->execute();
?>
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
CALSCALE:GREGORIAN
<?php
foreach($stmt->fetchAll() as $row) {
?>
BEGIN:VEVENT
UID:<?= uniqid() ?>
DTSTAMP:<?= date('Ymd\THis\Z',time()) ?>
LOCATION:<?= escapeString($row['address']) ?>
DESCRIPTION:<?= escapeString($row['description']) ?>
URL;VALUE=URI:<?= escapeString("http://kartontage.de/") ?>
SUMMARY:<?= escapeString($row['title']) ?>
CATEGORIES:<?= escapeString($row['category']) ?>
DTSTART:<?= dateToCal($row['time']) ?>
END:VEVENT
<?php } ?>
END:VCALENDAR