calendrier iCal des anniversaires
authorx2001corpet <x2001corpet@839d8a87-29fc-0310-9880-83ba4fa771e5>
Wed, 14 Jun 2006 12:06:33 +0000 (12:06 +0000)
committerx2001corpet <x2001corpet@839d8a87-29fc-0310-9880-83ba4fa771e5>
Wed, 14 Jun 2006 12:06:33 +0000 (12:06 +0000)
git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@314 839d8a87-29fc-0310-9880-83ba4fa771e5

ChangeLog
htdocs/carnet/calendar.php [new file with mode: 0644]
htdocs/images/icalicon.gif [new file with mode: 0644]
plugins/function.display_ical.php [new file with mode: 0644]
templates/carnet/calendar.tpl [new file with mode: 0644]
templates/carnet/mescontacts.tpl

index 4df9c06..043a063 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -10,8 +10,11 @@ New :
         - Dynamic maps using geodesix plugin.                               -Car
         - Link to local maps for all addresses.                             -Car
 
+    * Notifications :
+        - iCal calendar for birthdays.                                      -Car
+
     * Profile :
-        - See fiche send to AX.                                             -Car
+        - See fiche sent to AX.                                             -Car
 
     * Skin :
         - Common file for header above title.                               -Car
diff --git a/htdocs/carnet/calendar.php b/htdocs/carnet/calendar.php
new file mode 100644 (file)
index 0000000..3746842
--- /dev/null
@@ -0,0 +1,69 @@
+<?php
+/***************************************************************************
+ *  Copyright (C) 2003-2004 Polytechnique.org                              *
+ *  http://opensource.polytechnique.org/                                   *
+ *                                                                         *
+ *  This program is free software; you can redistribute it and/or modify   *
+ *  it under the terms of the GNU General Public License as published by   *
+ *  the Free Software Foundation; either version 2 of the License, or      *
+ *  (at your option) any later version.                                    *
+ *                                                                         *
+ *  This program is distributed in the hope that it will be useful,        *
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
+ *  GNU General Public License for more details.                           *
+ *                                                                         *
+ *  You should have received a copy of the GNU General Public License      *
+ *  along with this program; if not, write to the Free Software            *
+ *  Foundation, Inc.,                                                      *
+ *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
+ ***************************************************************************/
+
+require_once("xorg.inc.php");
+new_nonhtml_page('carnet/calendar.tpl', AUTH_PUBLIC);
+
+if (preg_match(',^/([^/]+)/([^/_]+)(_all)?\.ics$,', $_SERVER['PATH_INFO'], $m)) {
+    $alias = $m[1];
+    $hash  = $m[2];
+    $all = $m[3];
+} else {
+    $alias = Env::get('alias');
+    $hash = Env::get('hash');
+    $all = Env::has('all');
+}
+if ($alias && $hash) {
+    $res = $globals->xdb->query(
+        'SELECT  a.id
+           FROM  aliases         AS a
+     INNER JOIN  auth_user_quick AS q ON ( a.id = q.user_id AND q.core_rss_hash = {?} )
+          WHERE  a.alias = {?} AND a.type != "homonyme"', $hash, $alias);
+    $uid = $res->fetchOneCell();
+}
+
+require_once('notifs.inc.php');
+$notifs = new Notifs($uid, true);
+
+$annivcat = false;
+foreach ($notifs->_cats as $cat)
+    if (preg_match('/anniv/i', $cat['short']))
+        $annivcat = $cat['id'];
+
+if ($annivcat !== false) {
+    $annivs = array();
+    foreach ($notifs->_data[$annivcat] as $promo) foreach ($promo as $notif)
+    if ($all || $notif['contact']) {
+        $annivs[] = array(
+            'timestamp' => $notif['known'],
+            'date' => strtotime($notif['date']),
+            'tomorrow' => strtotime("+1 day", strtotime($notif['date'])),
+            'bestalias' => $notif['bestalias'],
+            'summary' => 'Anniversaire de '.$notif['prenom'].' '.$notif['nom'].' - x '.$notif['promo'],
+        );        
+    }
+    $page->assign('events', $annivs);
+}
+
+header('Content-Type: text/calendar; charset=utf-8');
+
+$page->run();
+?>
\ No newline at end of file
diff --git a/htdocs/images/icalicon.gif b/htdocs/images/icalicon.gif
new file mode 100644 (file)
index 0000000..01cc8cd
Binary files /dev/null and b/htdocs/images/icalicon.gif differ
diff --git a/plugins/function.display_ical.php b/plugins/function.display_ical.php
new file mode 100644 (file)
index 0000000..1caf15f
--- /dev/null
@@ -0,0 +1,40 @@
+<?php
+/***************************************************************************
+ *  Copyright (C) 2003-2006 Polytechnique.org                              *
+ *  http://opensource.polytechnique.org/                                   *
+ *                                                                         *
+ *  This program is free software; you can redistribute it and/or modify   *
+ *  it under the terms of the GNU General Public License as published by   *
+ *  the Free Software Foundation; either version 2 of the License, or      *
+ *  (at your option) any later version.                                    *
+ *                                                                         *
+ *  This program is distributed in the hope that it will be useful,        *
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
+ *  GNU General Public License for more details.                           *
+ *                                                                         *
+ *  You should have received a copy of the GNU General Public License      *
+ *  along with this program; if not, write to the Free Software            *
+ *  Foundation, Inc.,                                                      *
+ *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
+ ***************************************************************************/
+
+function smarty_function_display_ical($param, &$smarty) {
+    $txt = '';
+    if (isset($param['name']))
+        $txt .= strtoupper($param['name']);
+    if (isset($param['param']))
+        $txt .= ';'.$param['param'];
+    if (isset($param['value'])) {
+        if ($txt) $txt .= ':';
+        $txt .= utf8_encode($param['value']);
+    }
+    $length = strlen($txt);
+    $endline = "\r\n";
+    $maxchars = 75;
+    $folded_txt = substr($txt, 0, $maxchars);
+    for ($i = $maxchars; $i < $length; $i += $maxchars - 1)
+        $folded_txt .= $endline.' '.substr($txt, $i, $maxchars - 1);
+    return $folded_txt;
+}
+?>
diff --git a/templates/carnet/calendar.tpl b/templates/carnet/calendar.tpl
new file mode 100644 (file)
index 0000000..0e3b207
--- /dev/null
@@ -0,0 +1,39 @@
+{**************************************************************************}\r
+{*                                                                        *}\r
+{*  Copyright (C) 2003-2006 Polytechnique.org                             *}\r
+{*  http://opensource.polytechnique.org/                                  *}\r
+{*                                                                        *}\r
+{*  This program is free software; you can redistribute it and/or modify  *}\r
+{*  it under the terms of the GNU General Public License as published by  *}\r
+{*  the Free Software Foundation; either version 2 of the License, or     *}\r
+{*  (at your option) any later version.                                   *}\r
+{*                                                                        *}\r
+{*  This program is distributed in the hope that it will be useful,       *}\r
+{*  but WITHOUT ANY WARRANTY; without even the implied warranty of        *}\r
+{*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *}\r
+{*  GNU General Public License for more details.                          *}\r
+{*                                                                        *}\r
+{*  You should have received a copy of the GNU General Public License     *}\r
+{*  along with this program; if not, write to the Free Software           *}\r
+{*  Foundation, Inc.,                                                     *}\r
+{*  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA               *}\r
+{*                                                                        *}\r
+{**************************************************************************}\r
+BEGIN:VCALENDAR\r
+{display_ical name="prodid" value="-//Polytechnique.org//Plat-al//FR"}\r
+VERSION:2.0\r
+CALSCALE:GREGORIAN\r
+METHOD:PUBLISH\r
+{display_ical name="x-wr-calname" value="Anniversaires des X"}\r
+X-WR-TIMEZONE:Europe/Paris\r
+{foreach from=$events item=e}\r
+BEGIN:VEVENT\r
+DTSTAMP:{$e.timestamp|date_format:"%Y%m%dT%H%M%SZ"}\r
+DTSTART;VALUE=DATE:{$e.date|date_format:"%Y%m%d"}\r
+DTEND;VALUE=DATE:{$e.tomorrow|date_format:"%Y%m%d"}\r
+UID:anniv-{$e.date|date_format:"%Y%m%d"}-{$e.bestalias}@polytechnique.org\r
+CLASS:PUBLIC\r
+{display_ical name="summary" value=$e.summary}\r
+END:VEVENT\r
+{/foreach}\r
+END:VCALENDAR
\ No newline at end of file
index fd6846e..5fe05e1 100644 (file)
@@ -54,6 +54,19 @@ Pour r
   [<a href="mescontacts_pdf.php/mes_contacts.pdf" class='popup'><strong>tri par noms</strong></a>]
   </li>
 </ul>
+{if $smarty.session.core_rss_hash}
+<p>
+  Tu peux récupérer un calendrier iCal avec l'anniversaire de tes contacts.
+</p>
+  <div class="right">
+    <a href='{rel}/carnet/calendar/{$smarty.session.forlife}/{$smarty.session.core_rss_hash}.ics'><img src='{rel}/images/icalicon.gif' alt='fichier ical' title='Anniversaires'/></a>
+  </div>
+{else}
+<p>
+  Pour récupérer un calendrier iCal avec l'anniversaire de tes contacts, active les flux RSS dans <a href="{rel}/preferences.php">Mes préférences</a>.
+</p>
+{/if}
+
 
 {if $trombi}
 
@@ -76,7 +89,7 @@ Pour afficher la liste d
 </h1>
 
 <p>
-Pour afficher le trombi de tes contacts : [<a href="?trombi=1&amp;order={$order}&amp;inv={$inv}"><strong>vue sous forme de trombi</strong></a>]
+[<a href="?trombi=1&amp;order={$order}&amp;inv={$inv}"><strong>Afficher le trombi de tes contacts</strong></a>]
 </p>
 
 {include file=carnet/tricontacts.tpl order=$order}