diff --git a/.htaccess b/.htaccess
new file mode 100644
index 0000000..53cac3b
--- /dev/null
+++ b/.htaccess
@@ -0,0 +1,4 @@
+
+RewriteEngine on
+RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
+
\ No newline at end of file
diff --git a/ics.php b/ics.php
index 5b930aa..671def2 100644
--- a/ics.php
+++ b/ics.php
@@ -1,169 +1,150 @@
-
-
+
-
-
- Récupération du calendrier...
-
-
-
+$curl = curl_init();
+curl_setopt($curl, CURLOPT_URL, $davurl);
+curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
+curl_setopt($curl, CURLOPT_USERPWD, $davuser . ':' . $davpassword);
+curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
+$result = curl_exec($curl);
+if (!$result) {
+ die('error');
+}
+curl_close($curl);
+
+$params = [];
+parse_str($_SERVER['QUERY_STRING'], $params);
+$recent = isset($params['recent']) ? (int)$params['recent'] : 7;
+$recentonly = isset($params['recentonly']);
+$weblink = isset($params['weblink']) ? $params['weblink'] : '';
+
+$html = "Evénements à venir
";
+$html .= "" . strftime('%A, %e %B %Y %H:%M') . "
";
+$html .= "En gras: modifié les $recent derniers jours
";
+if ($weblink) {
+ $html .= "";
+}
+
+$o = ics2json($result);
+$lastmodified = new DateTime();
+$lastmodified->modify("-$recent days");
+$group = [];
+usort($o['VEVENTS'], function($a, $b) {
+ return $a['DTSTART'] <=> $b['DTSTART'];
+});
+
+foreach ($o['VEVENTS'] as $e) {
+ if ($e['DTSTART'] >= new DateTime() && (!$recentonly || $e['DTSTAMP'] >= $lastmodified)) {
+
+ $formatteddate = strftime('%A %d %B %Y %H:%M', $e['DTSTART']->getTimestamp());
+ $splitdate = explode(' ', $formatteddate);
+ $year = $splitdate[3];
+ $month = $splitdate[2];
+ $week = getWeek($e['DTSTART']);
+ if (!isset($group[$year])) {
+ $html .= "$year
";
+ $group[$year] = [];
+ }
+ if (!isset($group[$year][$month])) {
+ $html .= "$month
";
+ $group[$year][$month] = [];
+ }
+ if (!isset($group[$year][$month][$week])) {
+ $html .= "Semaine $week
";
+ $group[$year][$month][$week] = true;
+ }
+ $line = "getTimestamp()) . "\">";
+ if ($e['DTSTAMP'] >= $lastmodified) {
+ $line .= "";
+ }
+ $line .= "$formatteddate: " . $e['SUMMARY'];
+ if ($e['DTSTAMP'] >= $lastmodified) {
+ $line .= "";
+ }
+ $line .= '';
+ if ($e['DTSTAMP'] >= $lastmodified) {
+ $line = "$line";
+ }
+ $html .= $line;
+ }
+}
+echo $html;
+?>
+
+