Browse Source

Merge branch 'master' of github.com:TheMrNomis/KiWi-calendar

master
AmarOk 10 years ago
parent
commit
176e0da8d5
3 changed files with 68 additions and 7 deletions
  1. +37
    -0
      export.php
  2. +25
    -1
      getEvents.php
  3. +6
    -6
      index.php

+ 37
- 0
export.php View File

@ -0,0 +1,37 @@
<?php
header('Content-type: text/calendar; charset=utf-8');
header('Content-Disposition: inline; filename=calendar.ics');
if(isset($_GET['w'])&&is_numeric($_GET['w']))
$weekOffset = $_GET['w'];
else
$weekOffset = 0;
function icaldate($date)
{
$dt = strtotime($date);
return date('Ymd',$dt).'T'. date('His',$dt). 'Z';
}
include_once('getEvents.php');
$db = connect();
$events = getEventsSince($db, strtotime('last monday +'.$weekOffset.' weeks'));
$eol = "\r\n";
echo('BEGIN:VCALENDAR'.$eol);
echo('VERSION:2.0'.$eol);
echo('PRODID:-//KiWi-Calendar//NONSGML v1.0//EN'.$eol);
foreach($events as $event)
{
echo('BEGIN:VEVENT'.$eol);
echo('UID:' . md5($event['id']) . '@kiwi-calendar'.$eol);
echo('DTSTAMP:'.icaldate($event['dtstart']).$eol);
echo('DTSTART:'.icaldate($event['dtstart']).$eol);
echo('DTEND:'.icaldate($event['dtend']).$eol);
echo('SUMMARY:'.$event['description'].$eol);
echo('END:VEVENT'.$eol);
}
echo('END:VCALENDAR');
?>

+ 25
- 1
getEvents.php View File

@ -35,7 +35,31 @@ function getEventsByDate($db, $date)
{ {
try try
{ {
$request = $db->prepare('SELECT * FROM events, categorie WHERE events.categorie = categorie.id AND dtstart <= :date AND dtend >= :date');
$request = $db->prepare('SELECT * FROM events, categorie WHERE events.categorie = categorie.id AND (dtstart <= :date AND dtend >= :date)');
$request->execute(array('date'=>date("Y-m-d",$date)));
$result = $request->fetchAll();
$request->closeCursor();
return $result;
}
catch(PDOException $e)
{
//NOTE: change $e->getMessage() by an error message before going to production
echo($e->getMessage());
die();
}
}
/**
* @brief queries the database for the events after a certain date
* @param $db: the PDO connection to the database
* @param $date: the date to search for
* @return a list of all the events future to $date
*/
function getEventsSince($db,$date)
{
try
{
$request = $db->prepare('SELECT events.id, events.titre, events.localisation, events.dtstart, events.dtend, events.description FROM events, categorie WHERE events.categorie = categorie.id AND (events.dtstart >= :date OR events.dtend >= :date)');
$request->execute(array('date'=>date("Y-m-d",$date))); $request->execute(array('date'=>date("Y-m-d",$date)));
$result = $request->fetchAll(); $result = $request->fetchAll();
$request->closeCursor(); $request->closeCursor();


+ 6
- 6
index.php View File

@ -27,6 +27,11 @@ $months = array(
12 => "Decembre" 12 => "Decembre"
); );
if(isset($_GET['w'])&&is_numeric($_GET['w']))
$weekOffset = $_GET['w'];
else
$weekOffset = 0;
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
@ -105,11 +110,6 @@ $months = array(
<div id="calendar"> <div id="calendar">
<?php <?php
if(isset($_GET['w'])&&is_numeric($_GET['w']))
$weekOffset = $_GET['w'];
else
$weekOffset = 0;
$monthDate = strtotime('last monday +'.($weekOffset+3).' weeks'); $monthDate = strtotime('last monday +'.($weekOffset+3).' weeks');
for($week = $weekOffset; $week < $weekOffset + 5; ++$week) for($week = $weekOffset; $week < $weekOffset + 5; ++$week)
@ -160,7 +160,7 @@ $months = array(
<div id="Mois"><?php echo($months[date('n',$monthDate)].' '.date('Y',$monthDate)); ?></div> <div id="Mois"><?php echo($months[date('n',$monthDate)].' '.date('Y',$monthDate)); ?></div>
<a id="ancherLess" href="./index.php?w=<?php echo($weekOffset + 1); ?>"><img id="exLess" alt="expand more" src="images/expand_more.png" /></a> <a id="ancherLess" href="./index.php?w=<?php echo($weekOffset + 1); ?>"><img id="exLess" alt="expand more" src="images/expand_more.png" /></a>
</div> </div>
<div id="Export">Exporter en <a href="#RSS">RSS</a>, <a href="#iCal">iCal</a>, <a href="#webCal">WebCal</a></div>
<div id="Export"><a href="./export.php?w=<?php echo($weekOffset); ?>">Exporter (iCal)</a></div>
</div> </div>
<div> <div>
</div> </div>


Loading…
Cancel
Save