alias pour mails aux presents ou absents d'un evenement
authorPascal Corpet <pascal.corpet@m4x.org>
Fri, 17 Jun 2005 23:41:10 +0000 (23:41 +0000)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Thu, 26 Jun 2008 21:29:17 +0000 (23:29 +0200)
git-archimport-id: opensource@polytechnique.org--2005/platal--mainline--0.9--patch-716

ChangeLog
htdocs.net/groupe/evenements.php
htdocs.net/groupe/evt-admin.php
htdocs.net/groupe/evt-detail.php
include/xnet/evenements.php
templates/xnet/groupe/evt-admin.tpl
templates/xnet/groupe/form_evenement.tpl
upgrade/0.9.7/00_xnet.sql

index f7b1044..75cb086 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -12,6 +12,7 @@ New :
        * Xnet :
                - Events management.                                                                                            -Car
                - Events using paiements.                                                                                       -Car
+               - Sending mail to all the participants/absents of an event.                     -Car
 
 Bug/Wish :
 
index 37a53b1..23c0f0f 100644 (file)
@@ -10,22 +10,75 @@ $moments = range(1, 4);
 $page->assign('moments', $moments);
 
 if ($eid = Env::get('eid')) {
-       $res = $globals->xdb->query("SELECT asso_id FROM groupex.evenements WHERE eid = {?}", $eid);
-       if ($res->fetchOneCell() != $globals->asso('id')) unset($eid);
+       $res = $globals->xdb->query("SELECT asso_id, short_name FROM groupex.evenements WHERE eid = {?}", $eid);
+       $infos = $res->fetchOneAssoc();
+       if ($infos['asso_id'] != $globals->asso('id')) {
+               unset($eid);
+               unset($infos);
+       }
 }
 
 if (may_update() && Post::get('intitule')) {
+       $short_name = Env::get('short_name');
+       //Quelques vérifications sur l'alias (caractères spéciaux)
+       if ($short_name && !preg_match( "/^[a-zA-Z0-9\-.]{3,20}$/", $short_name)) {
+               $page->trig("Le raccourci demandé n'est pas valide.
+                           Vérifie qu'il comporte entre 3 et 20 caractères
+                           et qu'il ne contient que des lettres non accentuées,
+                           des chiffres ou les caractères - et .");
+               $short_name = $infos['short_name'];
+       }
+       //vérifier que l'alias n'est pas déja pris
+       if ($short_name && $short_name != $infos['short_name']) {
+               $res = $globals->xdb->query('SELECT COUNT(*) FROM virtual WHERE alias LIKE {?}', $short_name."-%");
+               if ($res->fetchOneCell() > 0) {
+                       $page->trig("Le raccourci demandé est déjà utilisé. Choisis en un autre.");
+                       $short_name = $infos['short_name'];
+               }
+       }
+       if ($short_name && $infos['short_name'] && $short_name != $infos['short_name']) {
+               $globals->xdb->execute("UPDATE virtual SET alias = REPLACE(alias, {?}, {?}) WHERE type = 'evt' AND alias LIKE {?}",
+                       $infos['short_name'], $short_name, $infos['short_name']."-%");
+       } elseif ($short_name && !$infos['short_name']) {
+               $globals->xdb->execute("INSERT INTO virtual SET type = 'evt', alias = {?}", $short_name."-participants@".$globals->mail->domain);
+               $res = $globals->xdb->query("SELECT LAST_INSERT_ID()");
+               $globals->xdb->execute("INSERT INTO virtual_redirect (
+                       SELECT {?} AS vid, IF(u.nom IS NULL, m.email, CONCAT(a.alias, {?})) AS redirect
+                         FROM groupex.evenements_participants AS ep
+                    LEFT JOIN groupex.membres AS m ON (ep.uid = m.uid)
+                    LEFT JOIN auth_user_md5 AS u ON (u.user_id = ep.uid)
+                    LEFT JOIN aliases AS a ON (a.id = ep.uid AND a.type = 'a_vie')
+                        WHERE ep.eid = {?}
+                     GROUP BY ep.uid)",
+                        $res->fetchOneCell(), "@".$globals->mail->domain, $eid);
+
+               $globals->xdb->execute("INSERT INTO virtual SET type = 'evt', alias = {?}", $short_name."-absents@".$globals->mail->domain);
+               $res = $globals->xdb->query("SELECT LAST_INSERT_ID()");
+               $globals->xdb->execute("INSERT INTO virtual_redirect (
+                       SELECT {?} AS vid, IF(u.nom IS NULL, m.email, CONCAT(a.alias, {?})) AS redirect
+                         FROM groupex.membres AS m
+                    LEFT JOIN groupex.evenements_participants AS ep ON (ep.uid = m.uid)
+                    LEFT JOIN auth_user_md5 AS u ON (u.user_id = m.uid)
+                    LEFT JOIN aliases AS a ON (a.id = m.uid AND a.type = 'a_vie')
+                        WHERE m.asso_id = {?} AND ep.uid IS NULL
+                     GROUP BY m.uid)",
+                        $res->fetchOneCell(), "@".$globals->mail->domain, $globals->asso('id'));
+       } elseif (!$short_name && $infos['short_name']) {
+               $globals->xdb->execute("DELETE virtual, virtual_redirect FROM virtual LEFT JOIN virtual_redirect USING(vid) WHERE virtual.alias LIKE {?}",
+                       $infos['short_name']."-%");
+       }
+
        $globals->xdb->execute("REPLACE INTO groupex.evenements VALUES (
                {?}, {?}, {?}, {?},
                {?}, {?},
                {?},
                {?},
-               {?}, {?}, {?})",
+               {?}, {?}, {?}, {?})",
                $eid, $globals->asso('id'), Session::get('uid'), Post::get('intitule'),
                (Post::get('paiement')>0)?Post::get('paiement'):NULL, Post::get('descriptif'),
                Post::get('deb_Year')."-".Post::get('deb_Month')."-".Post::get('deb_Day')." ".Post::get('deb_Hour').":".Post::get('deb_Minute').":00",
                Post::get('fin_Year')."-".Post::get('fin_Month')."-".Post::get('fin_Day')." ".Post::get('fin_Hour').":".Post::get('fin_Minute').":00",
-               Post::get('membres_only'), Post::get('advertise'), Post::get('show_participants'));
+               Post::get('membres_only'), Post::get('advertise'), Post::get('show_participants'), $short_name);
 
        if (!$eid) {
                $res = $globals->xdb->query("SELECT LAST_INSERT_ID()");
@@ -59,11 +112,15 @@ if (may_update() && Post::get('intitule')) {
 }
 
 if (may_update() && Env::has('sup') && $eid) {
+       // deletes the event
        $globals->xdb->execute("DELETE FROM groupex.evenements WHERE eid = {?} AND asso_id = {?}", $eid, $globals->asso('id'));
-
+       // deletes the event items
        $globals->xdb->execute("DELETE FROM groupex.evenements_items WHERE eid = {?}", $eid);
-
+       // deletes the event participants
        $globals->xdb->execute("DELETE FROM groupex.evenements_participants WHERE eid = {?}", $eid);
+       // deletes the event mailing aliases
+       if ($infos['short_name'])
+               $globals->xdb->execute("DELETE FROM virtual WHERE type = 'evt' AND alias LIKE {?}", $infos['short_name']."-%");
 }
 
 if (may_update() && (Env::has('add') || (Env::has('mod') && $eid))) {
@@ -77,7 +134,7 @@ if (may_update() && (Env::has('add') || (Env::has('mod') && $eid))) {
 
 if (may_update() && Env::has('mod') && $eid) {
        $res = $globals->xdb->query(
-               "SELECT eid, intitule, descriptif, debut, fin, membres_only, advertise, show_participants, paiement_id
+               "SELECT eid, intitule, descriptif, debut, fin, membres_only, advertise, show_participants, paiement_id, short_name
                   FROM groupex.evenements
                  WHERE eid = {?}", $eid);
        $evt = $res->fetchOneAssoc();
@@ -95,7 +152,8 @@ if (may_update() && Env::has('mod') && $eid) {
 } else {
 
        $evenements = $globals->xdb->iterator(
-           "SELECT  e.eid, e.intitule, e.descriptif, e.debut, e.fin, e.show_participants, u.nom, u.prenom, u.promo, a.alias, MAX(ep.nb)>=1 AS inscrit
+       "SELECT  e.eid, e.intitule, e.descriptif, e.debut, e.fin, e.show_participants, u.nom, u.prenom, u.promo, a.alias, MAX(ep.nb)>=1 AS inscrit,
+                e.short_name
              FROM  groupex.evenements AS e
        INNER JOIN  x4dat.auth_user_md5 AS u ON u.user_id = e.organisateur_uid
         LEFT JOIN  x4dat.aliases AS a ON (a.type = 'a_vie' AND a.id = u.user_id)
index 6104810..ecab320 100644 (file)
@@ -49,10 +49,12 @@ if ($admin && Env::get('adm') == 'prix' && $member) {
 if ($admin && Env::get('adm') == 'nbs' && $member) {
        $res = $globals->xdb->query("SELECT paid FROM groupex.evenements_participants WHERE uid = {?} AND eid = {?}", $member, Env::get('eid'));
        $paid = $res->fetchOneCell();
+       $participate = false;
        foreach ($evt['moments'] as $m) if (Env::has('nb'.$m['item_id'])) {
                $nb = Env::getInt('nb'.$m['item_id'], 0);
                if ($nb < 0) $nb = 0;
                if ($nb) {
+                       $participate = true;
                        if (!$paid) $paid = 0;
                        $globals->xdb->execute("REPLACE INTO groupex.evenements_participants VALUES ({?}, {?}, {?}, {?}, {?})",
                        Env::get('eid'), $member, $m['item_id'], $nb, $paid);
@@ -60,6 +62,13 @@ if ($admin && Env::get('adm') == 'nbs' && $member) {
                else
                $globals->xdb->execute("DELETE FROM groupex.evenements_participants WHERE uid = {?} AND eid = {?} AND item_id = {?}", $member, Env::get('eid'), $m['item_id']);
        }
+       if ($participate) 
+               subscribe_lists_event(true, $member, $evt['participant_list'], $evt['absent_list']);
+       else {
+               $res = $globals->xdb->query("SELECT uid FROM groupex.evenements_participants WHERE uid = {?} AND eid = {?}", $member, Env::get('eid'));
+               $u = $res->fetchOneCell();
+               subscribe_lists_event($u, $member, $evt['participant_list'], $evt['absent_list']);
+       }
 }
 
 $page->assign('admin', $admin);
index 306ca90..e3e8cb6 100644 (file)
@@ -10,6 +10,7 @@ if (!Env::get("eid"))
 $may_participate = !$members_only || is_member() || may_update(); 
 $page->assign('may_participate', $may_participate);
 
+$participate = false;
 for ($i=1; Env::has('item_id'.$i); $i++) {
        $res = $globals->xdb->query("SELECT paid FROM groupex.evenements_participants WHERE eid = {?} AND uid = {?}", Env::get("eid"), Session::get("uid"));
        $paid = $res->fetchOneCell();
@@ -17,11 +18,13 @@ for ($i=1; Env::has('item_id'.$i); $i++) {
        $j = Env::get('item_id'.$i);
        $nb = Env::get('item_'.$j);
        if ($nb == '+') $nb = Env::get('itemnb_'.$j)+1;
-       if ($nb > 0)
+       if ($nb > 0) {
                $globals->xdb->execute(
        "REPLACE INTO groupex.evenements_participants
               VALUES ({?}, {?}, {?}, {?}, {?})",
               Env::get("eid"), Session::get("uid"), $j, $nb, $paid);
+              $participate = true;
+       }
        else
                $globals->xdb->execute(
        "DELETE FROM groupex.evenements_participants
@@ -29,18 +32,15 @@ for ($i=1; Env::has('item_id'.$i); $i++) {
               Env::get("eid"), Session::get("uid"), $j);               
 }
 
+require_once('xnet/evenements.php');
+$evt = get_event_detail(Env::get('eid'));
+
+subscribe_lists_event($participate, Session::get("uid"), $evt['participant_list'], $evt['absent_list']);
+
 // return to the main page after modifying
 if (Env::has("ins"))
        header("Location: evenements.php");
 
-$res = $globals->xdb->query(
-        "SELECT  e.eid, a.nom, a.prenom, a.promo, intitule, descriptif, debut AS deb,
-                fin, membres_only, paiement_id
-          FROM  groupex.evenements AS e
-         INNER  JOIN x4dat.auth_user_md5 AS a ON a.user_id = e.organisateur_uid
-         WHERE  e.eid = {?}", Env::get("eid"));
-
-$evt = $res->fetchOneAssoc();
 $page->assign('evt', $evt);
 
 $moments = $globals->xdb->iterator(
index 7b75805..0ebbfa7 100644 (file)
 function get_event_detail($eid, $item_id = false) {
     global $globals;
     $res = $globals->xdb->query(
-        "SELECT        SUM(nb) AS nb_tot, e.intitule, ei.titre, e.show_participants, e.paiement_id
+        "SELECT        SUM(nb) AS nb_tot, e.intitule, ei.titre,
+                debut AS deb, fin, membres_only, descriptif, e.eid,
+                e.show_participants, e.paiement_id, e.short_name,
+                al.vid AS absent_list, pl.vid AS participant_list,
+                a.nom, a.prenom, a.promo
            FROM        groupex.evenements AS e
      INNER JOIN        groupex.evenements_items AS ei ON (e.eid = ei.eid)
       LEFT JOIN        groupex.evenements_participants AS ep ON(e.eid = ep.eid AND ei.item_id = ep.item_id)
-          WHERE        e.eid = {?} AND ei.item_id = {?} AND e.asso_id = {?}
+      LEFT JOIN virtual AS al ON(al.type = 'evt' AND al.alias = CONCAT(short_name, {?}))
+      LEFT JOIN virtual AS pl ON(pl.type = 'evt' AND pl.alias = CONCAT(short_name, {?}))
+      LEFT JOIN auth_user_md5 AS a ON (a.user_id = e.organisateur_uid)
+          WHERE        e.eid = {?} AND ei.item_id = {?} AND e.asso_id = {?} 
        GROUP BY ei.item_id",
+       '-absents@'.$globals->mail->domain,
+       '-participants@'.$globals->mail->domain,
        $eid, $item_id?$item_id:1, $globals->asso('id'));
     $evt = $res->fetchOneAssoc();
     if (!$evt) return false;
@@ -121,5 +130,34 @@ function get_event_participants($eid, $item_id, $where, $tri, $limit, $money, $p
     return $tab;
 }
 // }}}
+
+//  {{{ function subscribe_lists_event()
+function subscribe_lists_event($participate, $uid, $participant_list, $absent_list) {
+    echo "poulpe - $uid - $participant_list";
+    global $globals;
+    
+    $email = Session::get('forlife');
+
+    if ($email) $email .= '@'.$globals->mail->domain;
+    else {
+        $res = $globals->xdb->query("SELECT email FROM groupex.membres WHERE uid = {?} AND asso_id = {?}", Session::get('uid'), $globals->asso('id'));
+        $email = $res->fetchOneCell();
+    }
+
+    $subscribe = $participate?$participant_list:(is_member()?$absent_list:0);
+    $unsubscri = $participate?$absent_list:$participant_list;
+
+    if ($subscribe)
+        $globals->xdb->execute(
+            "REPLACE INTO virtual_redirect VALUES({?},{?})",
+                $subscribe, $email);
+
+    if ($unsubscri)
+        $globals->xdb->execute(
+            "DELETE FROM virtual_redirect WHERE vid = {?} AND redirect = {?}",
+                $unsubscri, $email);
+}
+// }}}
+
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker:
 ?>
index bc79d24..a99a5e1 100644 (file)
 
 <h1>{$asso.nom} : <a href='evenements.php'>Evénements</a> </h1>
 
+{if $evt.participant_list}
+<p class="center">
+[<a href="mailto:{$evt.short_name}-participants@polytechnique.org">envoyer un mail à ceux qui viennent</a>] - [<a href="mailto:{$evt.short_name}-absents@polytechnique.org">envoyer un mail aux membres non inscrits</a>]
+</p>
+{/if}
+
 {if $moments}
 <p class="center">
 [<a href="{$smarty.server.PHP_SELF}?eid={$smarty.request.eid}"{if !$smarty.request.item_id}class="erreur"{/if}>tout</a>]
index 54077fa..9c415f7 100644 (file)
       <td><input type="text" name="intitule" value="{$evt.intitule}" size="45" maxlength="100" /></td>
     </tr>
     <tr>
+      <td>Evénement en raccourci (pour les mailings listes) :</td>
+      <td><input type="text" name="short_name" value="{$evt.short_name}" size="20"/></td>
+    </tr>
+    <tr>
       <td>Descriptif :</td>
       <td><textarea name="descriptif" cols="45" rows="6">{$evt.descriptif}</textarea></td>
     </tr>
index 22c9e6c..c4c55c7 100644 (file)
@@ -2,4 +2,6 @@ ALTER TABLE groupex.asso ADD `pub` ENUM( 'public', 'private' ) DEFAULT 'public'
 ALTER TABLE groupex.evenements_participants ADD PRIMARY KEY (eid, item_id, uid);
 ALTER TABLE groupex.evenements ADD `show_participants` TINYINT( 1 ) NOT NULL ;
 ALTER TABLE groupex.evenements_participants ADD paid FLOAT DEFAULT 0 NOT NULL;
+ALTER TABLE virtual CHANGE `type` `type` ENUM('user', 'list', 'dom', 'evt') DEFAULT 'user' NOT NULL;
+ALTER TABLE groupex.evenements ADD `short_name` VARCHAR(30) DEFAULT '' NOT NULL;