Fix an error in error_handler making debug a bit harder
[platal.git] / modules / xnetgrp.php
index acaf70e..db37f2a 100644 (file)
@@ -54,12 +54,12 @@ function get_infos($email)
                          u.prenom, b.alias,
                          CONCAT(b.alias, '@m4x.org') AS email,
                          CONCAT(b.alias, '@polytechnique.org') AS email2,
-                         m.perms='admin' AS perms, m.origine,
+                         m.perms = 'admin' AS perms, m.origine,
                          FIND_IN_SET('femme', u.flags) AS sexe
                    FROM  auth_user_md5   AS u
              INNER JOIN  aliases         AS a ON ( u.user_id = a.id AND a.type != 'homonyme' )
              INNER JOIN  aliases         AS b ON ( u.user_id = b.id AND b.type = 'a_vie' )
-             INNER JOIN  groupex.membres AS m ON ( m.uid = u.user_id AND asso_id={?})
+              LEFT JOIN  groupex.membres AS m ON ( m.uid = u.user_id AND asso_id={?})
                   WHERE  a.alias = {?} AND u.user_id < 50000", $globals->asso('id'), $mbox);
         return $res->fetchOneAssoc();
     }
@@ -171,10 +171,7 @@ class XnetGrpModule extends PLModule
                               'rss/'.S::v('forlife') .'/'.S::v('core_rss_hash').'/rss.xml');
         }
 
-        $page->register_modifier('wiki_to_html', array('MiniWiki','WikiToHTML'));
         $page->assign('articles', $arts);
-
-        $page->assign('asso', $globals->asso());
     }
 
     function handler_logo(&$page)
@@ -233,7 +230,8 @@ class XnetGrpModule extends PLModule
                         SET  nom={?}, diminutif={?}, cat={?}, dom={?},
                              descr={?}, site={?}, mail={?}, resp={?},
                              forum={?}, mail_domain={?}, ax={?}, pub={?},
-                             sub_url={?}, inscriptible={?}, unsub_url={?}
+                             sub_url={?}, inscriptible={?}, unsub_url={?},
+                             flags='wiki_desc'
                       WHERE  id={?}",
                       Post::v('nom'), Post::v('diminutif'),
                       Post::v('cat'), Post::i('dom'),
@@ -252,7 +250,7 @@ class XnetGrpModule extends PLModule
                     "UPDATE  groupex.asso
                         SET  descr={?}, site={?}, mail={?}, resp={?},
                              forum={?}, ax={?}, pub= {?}, sub_url={?},
-                             unsub_url={?}
+                             unsub_url={?},flags='wiki_desc'
                       WHERE  id={?}",
                       Post::v('descr'), Post::v('site'),
                       Post::v('mail'), Post::v('resp'),
@@ -266,9 +264,9 @@ class XnetGrpModule extends PLModule
                 $logo = file_get_contents($_FILES['logo']['tmp_name']);
                 $mime = $_FILES['logo']['type'];
                 XDB::execute('UPDATE groupex.asso
-                                           SET logo={?}, logo_mime={?}
-                                         WHERE id={?}', $logo, $mime,
-                                        $globals->asso('id'));
+                                 SET logo={?}, logo_mime={?}
+                               WHERE id={?}', $logo, $mime,
+                             $globals->asso('id'));
             }
 
             pl_redirect('../'.Post::v('diminutif', $globals->asso('diminutif')).'/edit');
@@ -279,6 +277,11 @@ class XnetGrpModule extends PLModule
             $page->assign('dom', $dom);
             $page->assign('super', true);
         }
+        if (!$globals->asso('wiki_desc') && $globals->asso('descr')) {
+            $page->trig("Attention, le format de la description a changé et utilise désormais la syntaxe wiki "
+                      . "intégrée au site. Il te faudra probablement adapter le formatage du texte actuel pour "
+                      . "qu'il s'affiche correctement avec cette nouvelle syntaxe.");
+        }
     }
 
     function handler_mail(&$page)
@@ -358,7 +361,7 @@ class XnetGrpModule extends PLModule
                                      1, 1)) as letter, COUNT(*)
                            FROM  groupex.membres AS m
                       LEFT JOIN  auth_user_md5   AS u ON ( u.user_id = m.uid)
-                          WHERE  asso_id = {?} and (u.perms != \'pending\' OR u.perms IS NULL)
+                          WHERE  asso_id = {?} and (u.perms != \'pending\' OR m.email IS NOT NULL)
                        GROUP BY  letter
                        ORDER BY  letter', $globals->asso('id'));
         } else {
@@ -472,19 +475,17 @@ class XnetGrpModule extends PLModule
 
         if (!is_null($u) && may_update()) {
             $page->assign('u', $u);
-            $res = XDB::query("SELECT nom, prenom, promo, user_id
-                                           FROM auth_user_md5 AS u
-                                     INNER JOIN aliases AS al ON (al.id = u.user_id
-                                                                  AND al.type != 'liste')
-                                          WHERE al.alias = {?}", $u);
+            $res = XDB::query("SELECT  u.nom, u.prenom, u.promo, u.user_id, FIND_IN_SET('femme', u.flags)
+                                 FROM  auth_user_md5 AS u
+                           INNER JOIN  aliases AS al ON (al.id = u.user_id AND al.type != 'liste')
+                                WHERE  al.alias = {?}", $u);
 
-            if (list($nom, $prenom, $promo, $uid) = $res->fetchOneRow()) {
+            if (list($nom, $prenom, $promo, $uid, $sexe) = $res->fetchOneRow()) {
                 $res = XDB::query("SELECT  COUNT(*)
-                                               FROM  groupex.membres AS m
-                                         INNER JOIN  aliases  AS a ON (m.uid = a.id
-                                                                       AND a.type != 'homonyme')
-                                              WHERE  a.alias = {?} AND m.asso_id = {?}",
-                                            $u, $globals->asso('id'));
+                                     FROM  groupex.membres AS m
+                               INNER JOIN  aliases  AS a ON (m.uid = a.id AND a.type != 'homonyme')
+                                    WHERE  a.alias = {?} AND m.asso_id = {?}",
+                                  $u, $globals->asso('id'));
                 $n   = $res->fetchOneCell();
                 if ($n) {
                     $page->kill("$prenom $nom est déjà membre du groupe !");
@@ -492,15 +493,15 @@ class XnetGrpModule extends PLModule
                 }
                 elseif (Env::has('accept'))
                 {
-                    XDB::execute("INSERT INTO groupex.membres
-                                            VALUES ({?}, {?}, 'membre', 'X', NULL, NULL, NULL, NULL, NULL)",
+                    XDB::execute("INSERT INTO  groupex.membres (asso_id, uid)
+                                       VALUES  ({?}, {?})",
                                             $globals->asso('id'), $uid);
                     $mailer = new PlMailer();
                     $mailer->addTo("$u@polytechnique.org");
                     $mailer->setFrom('"'.S::v('prenom').' '.S::v('nom')
                                      .'" <'.S::v('forlife').'@polytechnique.org>');
                     $mailer->setSubject('['.$globals->asso('nom').'] Demande d\'inscription');
-                    $message = "Cher Camarade,\n"
+                    $message = ($sexe ? 'Chère' : 'Cher') . " Camarade,\n"
                              . "\n"
                              . "  Suite à ta demande d'adhésion à ".$globals->asso('nom').",\n"
                              . "j'ai le plaisir de t'annoncer que ton inscription a été validée !\n"
@@ -509,7 +510,7 @@ class XnetGrpModule extends PLModule
                              . "{$_SESSION["prenom"]} {$_SESSION["nom"]}.";
                     $mailer->setTxtBody($message);
                     $mailer->send();
-                    $page->kill("$prenom $nom a bien été inscrit");
+                    $page->kill("$prenom $nom a bien été inscrit" . ($sexe ? 'e' : ''));
                 }
                 elseif (Env::has('refuse'))
                 {
@@ -752,7 +753,7 @@ class XnetGrpModule extends PLModule
                                     FROM auth_user_md5
                                    WHERE $where");
         }
-        if ($res->total() < 30) {
+        if ($res && $res->total() < 30) {
             $page->assign("choix", $res);
         }
     }
@@ -814,7 +815,7 @@ class XnetGrpModule extends PLModule
         }
 
         if ($this->unsubscribe($user)) {
-            $page->trig('Vous avez été désinscrit du groupe avec succès');
+            $page->trig('Vous avez été désinscrit du groupe avec succès.');
         } else {
             $page->trig('Vous avez été désinscrit du groupe, mais des erreurs se sont produites lors des désinscriptions des alias et des mailing-lists.');
         }
@@ -1023,7 +1024,6 @@ class XnetGrpModule extends PLModule
         global $globals;
         require_once('rss.inc.php');
         $uid = init_rss('xnetgrp/announce-rss.tpl', $user, $hash, false);
-        $page->register_modifier('wiki_to_html', array('MiniWiki', 'WikiToHTML'));
 
         if ($uid) {
             $rss = XDB::iterator("SELECT a.id, a.titre, a.texte, a.contacts, a.create_date,
@@ -1050,7 +1050,6 @@ class XnetGrpModule extends PLModule
     {
         global $globals, $platal;
         $page->changeTpl('xnetgrp/announce-edit.tpl');
-        $page->register_modifier('wiki_to_html', array('MiniWiki','WikiToHTML'));
         $page->assign('new', is_null($aid));
         $art = array();
 
@@ -1117,8 +1116,7 @@ class XnetGrpModule extends PLModule
                 $aid = XDB::insertId();
                 if ($art['xorg']) {
                     require_once('validations.inc.php');
-                    $article = new EvtReq("[{$globals->asso('nom')}] " . $art['titre'],
-                                    MiniWiki::WikiToHTML($fulltext),
+                    $article = new EvtReq("[{$globals->asso('nom')}] " . $art['titre'], $fulltext,
                                     $art['promo_min'], $art['promo_max'], $art['peremption'], "", S::v('uid'));
                     $article->submit();
                     $page->trig("L'affichage sur la page d'accueil de Polytechnique.org est en attente de validation");