Add a announce system on X.net
[platal.git] / modules / xnetevents.php
index 3ffa2eb..15eaa7f 100644 (file)
@@ -290,11 +290,20 @@ class XnetEventsModule extends PLModule
         $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(dirname(__FILE__).'/carnet/smarty.php');
+        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);
     
@@ -305,11 +314,22 @@ class XnetEventsModule extends PLModule
     {
         global $globals;
 
+        // get eid if the the given one is a short name
+        if (!is_null($eid) && !is_numeric($eid)) {
+            $res = XDB::query("SELECT eid
+                                 FROM groupex.evenements
+                                WHERE asso_id = {?} AND short_name = {?}",
+                              $globals->asso('id'), $eid);
+            if ($res->numRows()) {
+                $eid = (int)$res->fetchOneCell();
+            }
+        }
+
         // check the event is in our group
         if (!is_null($eid)) {
             $res = XDB::query("SELECT short_name, asso_id
-                                           FROM groupex.evenements
-                                          WHERE eid = {?}", $eid);
+                                 FROM groupex.evenements
+                                WHERE eid = {?}", $eid);
             $infos = $res->fetchOneAssoc();
             if ($infos['asso_id'] != $globals->asso('id')) {
                 return PL_NOT_ALLOWED;
@@ -329,7 +349,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')
@@ -341,10 +360,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').'-'
@@ -409,15 +431,13 @@ class XnetEventsModule extends PLModule
                                         VALUES ({?}, {?}, '', '', 0)", $eid, 1);
             }
 
-            if (is_null($evt['eid'])) {
-                pl_redirect('events/'.$eid);
-            }
+            pl_redirect('events');
         }
 
         // get a list of all the payment for this asso
         $res = XDB::iterator("SELECT id, text
-                                        FROM {$globals->money->mpay_tprefix}paiements
-                                        WHERE asso_id = {?}", $globals->asso('id'));
+                                FROM {$globals->money->mpay_tprefix}paiements
+                               WHERE asso_id = {?}", $globals->asso('id'));
         $paiements = array();
         while ($a = $res->next()) $paiements[$a['id']] = $a['text']; {
             $page->assign('paiements', $paiements);
@@ -426,17 +446,17 @@ 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();
             // find out if there is already a request for a payment for this event
             require_once 'validations.inc.php';
             $res = XDB::query("SELECT stamp FROM requests
-                                         WHERE type = 'paiements' AND data LIKE {?}",
-                                        PayReq::same_event($eid, $globals->asso('id')));
+                                WHERE type = 'paiements' AND data LIKE {?}",
+                               PayReq::same_event($eid, $globals->asso('id')));
             $stamp = $res->fetchOneCell();
             if ($stamp) {
                 $evt['paiement_id'] = -2;
@@ -456,6 +476,7 @@ class XnetEventsModule extends PLModule
             }
             $page->assign('items', $items);
         }
+        $page->assign('url_ref', $eid);
     }
 
     function handler_admin(&$page, $eid = null, $item_id = null)