Can get an iCal version of the events (it works but is not finished)
authorx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Mon, 23 Oct 2006 16:35:47 +0000 (16:35 +0000)
committerx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Mon, 23 Oct 2006 16:35:47 +0000 (16:35 +0000)
git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1019 839d8a87-29fc-0310-9880-83ba4fa771e5

ChangeLog
modules/carnet/smarty.php
modules/xnetevents.php
modules/xnetevents/xnetevents.inc.php
templates/xnetevents/calendar.tpl [new file with mode: 0644]
templates/xnetevents/index.tpl

index a1c5ba4..ae1c150 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -14,6 +14,7 @@ New:
 
     * Xnet/Events:
         - Events can be archived                                           -FRU
+        - Can get iCal version of the events                               -FRU
 
 Bug/Wish:
 
index 4a709f7..09d5504 100644 (file)
@@ -27,7 +27,9 @@ function display_ical($param) {
         $txt .= ';'.$param['param'];
     if (isset($param['value'])) {
         if ($txt) $txt .= ':';
-        $txt .= utf8_encode($param['value']);
+        $txt .= utf8_encode(
+                    preg_replace('/[,;:]/', '\\\\$0',
+                    preg_replace("/(\r\n|\r|\n)/", '\n', $param['value'])));
     }
     $length = strlen($txt);
     $endline = "\r\n";
index 5e3d31b..3ffa2eb 100644 (file)
@@ -29,6 +29,7 @@ class XnetEventsModule extends PLModule
             '%grp/events'       => $this->make_hook('events',  AUTH_MDP),
             '%grp/events/sub'   => $this->make_hook('sub',     AUTH_MDP),
             '%grp/events/csv'   => $this->make_hook('csv',     AUTH_MDP),
+            '%grp/events/ical'  => $this->make_hook('ical',    AUTH_MDP),
             '%grp/events/edit'  => $this->make_hook('edit',    AUTH_MDP),
             '%grp/events/admin' => $this->make_hook('admin',   AUTH_MDP),
         );
@@ -277,6 +278,29 @@ class XnetEventsModule extends PLModule
         $page->assign('tout', !Env::v('item_id', false));
     }
 
+    function handler_ical(&$page, $eid = null)
+    {
+        global $globals;
+
+        require_once dirname(__FILE__).'/xnetevents/xnetevents.inc.php';
+        $evt = get_event_detail($eid);
+        if (!$evt) {
+            return PL_NOT_FOUND;
+        }
+        $evt['debut'] = preg_replace('/(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)/', "\\1\\2\\3T\\4\\5\\6", $evt['debut']);
+        $evt['fin'] = preg_replace('/(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)/', "\\1\\2\\3T\\4\\5\\6", $evt['fin']);
+
+        $page->changeTpl('xnetevents/calendar.tpl', NO_SKIN);
+
+        require_once(dirname(__FILE__).'/carnet/smarty.php');
+        $page->assign('asso', $globals->asso());
+        $page->assign('timestamp', time());
+        $page->register_function('display_ical', 'display_ical');
+        $page->assign_by_ref('e', $evt);
+    
+        header('Content-Type: text/calendar; charset=utf-8');
+    }
+
     function handler_edit(&$page, $eid = null)
     {
         global $globals;
index c71b83d..aa3682d 100644 (file)
@@ -48,7 +48,7 @@ function get_event_detail($eid, $item_id = false)
 
     $evt = $res->fetchOneAssoc();
 
-    if (!$evt) {
+    if (!$evt || ($evt['accept_nonmembre'] == 0 && !is_member() && !may_update())) {
         return null;
     }
 
diff --git a/templates/xnetevents/calendar.tpl b/templates/xnetevents/calendar.tpl
new file mode 100644 (file)
index 0000000..85d62c3
--- /dev/null
@@ -0,0 +1,43 @@
+{**************************************************************************}
+{*                                                                        *}
+{*  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               *}
+{*                                                                        *}
+{**************************************************************************}
+BEGIN:VCALENDAR
+{display_ical name="prodid" value="-//Polytechnique.org//Plat-al//FR"}
+VERSION:2.0
+CALSCALE:GREGORIAN
+X-WR-TIMEZONE:Europe/Paris
+METHOD:PUBLISH
+{display_ical name="x-wr-calname" value=$asso.nom}
+BEGIN:VEVENT
+DSTAMP:{$timestamp|date_format:"%Y%m%dT%H%M%SZ"}
+DTSTART;VALUE=DATE;TZID=Europe/Paris:{$e.debut}
+DTEND;VALUE=DATE;TZID=Europe/Paris:{$e.fin}
+ORGANIZER:CN="{$e.prenom} {$e.nom}":MAILTO:{$e.alias}@polytechnique.org
+UID:event-{$asso.diminutif}-{$e.short_name}@polytechnique.org
+{if $e.accept_nonmembre}
+CLASS:PUBLIC
+{else}
+CLASS:PRIVATE
+{/if}
+{display_ical name="summary" value=$e.intitule}
+{display_ical name="description" value=$e.descriptif}
+END:VEVENT
+END:VCALENDAR
index 54187c9..5a47665 100644 (file)
@@ -42,7 +42,9 @@
   </colgroup>
   <tr>
     <th colspan="2"{if !$e.inscr_open} class="grayed"{/if}>
-      {$e.intitule}
+      <a href="{$platal->ns}events/ical/{$e.eid}/{$e.short_name}.ics">
+        {icon name=calendar_view_day} {$e.intitule}
+      </a>
       {if !$e.inscr_open}
       (<span class="error">Inscriptions closes</span>)
       {/if}