Small fix
[platal.git] / modules / xnetevents.php
index 5e3d31b..977ea1f 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,38 @@ 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']);
+
+        foreach ($evt['moments'] as $m) {
+            $evt['descriptif'] .= "\n\n** " . $m['titre'] . " **\n" . $m['details'];
+        }
+
+        $page->changeTpl('xnetevents/calendar.tpl', NO_SKIN);
+
+        require_once('ical.inc.php');
+        $page->assign('asso', $globals->asso());
+        $page->assign('timestamp', time());
+        $page->assign('admin', may_update());
+
+        if (may_update()) {
+            $page->assign('participants', get_event_participants($evt, null, 'promo, nom, prenom'));
+        }
+        $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;
@@ -305,7 +338,6 @@ class XnetEventsModule extends PLModule
             $evt = array(
                 'eid'              => $eid,
                 'asso_id'          => $globals->asso('id'),
-                'organisateur_uid' => S::v('uid'),
                 'paiement_id'      => Post::v('paiement_id') > 0 ? Post::v('paiement_id') : null,
                 'debut'            => Post::v('deb_Year').'-'.Post::v('deb_Month')
                                       .'-'.Post::v('deb_Day').' '.Post::v('deb_Hour')
@@ -317,10 +349,13 @@ class XnetEventsModule extends PLModule
             );
 
             $trivial = array('intitule', 'descriptif', 'noinvite',
-                             'show_participants', 'accept_nonmembre');
+                             'show_participants', 'accept_nonmembre', 'organisateur_uid');
             foreach ($trivial as $k) {
                 $evt[$k] = Post::v($k);
             }
+            if (!$eid) {
+                $evt['organisateur_uid'] = S::v('uid');
+            }
 
             if (Post::v('deadline')) {
                 $evt['deadline_inscription'] = Post::v('inscr_Year').'-'
@@ -386,7 +421,7 @@ class XnetEventsModule extends PLModule
             }
 
             if (is_null($evt['eid'])) {
-                pl_redirect('events/'.$eid);
+                pl_redirect('events');
             }
         }
 
@@ -402,9 +437,9 @@ class XnetEventsModule extends PLModule
         // when modifying an old event retreive the old datas
         if ($eid) {
             $res = XDB::query(
-                    "SELECT    eid, intitule, descriptif, debut, fin,
-                                show_participants, paiement_id, short_name,
-                                deadline_inscription, noinvite, accept_nonmembre
+                    "SELECT    eid, intitule, descriptif, debut, fin, organisateur_uid,
+                            show_participants, paiement_id, short_name,
+                            deadline_inscription, noinvite, accept_nonmembre
                        FROM    groupex.evenements
                       WHERE eid = {?}", $eid);
             $evt = $res->fetchOneAssoc();