2006 => 2007 Happy New Year\!
[platal.git] / modules / banana.php
index aa5ccca..78e4e4c 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2006 Polytechnique.org                              *
+ *  Copyright (C) 2003-2007 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -31,6 +31,32 @@ class BananaModule extends PLModule
         );
     }
 
+    function on_subscribe($forlife, $uid, $promo, $password)
+    {
+        $cible = array('xorg.general', 'xorg.pa.divers', 'xorg.pa.logements');
+        $p_for = "xorg.promo.x$promo";
+
+        // récupération de l'id du forum promo
+        $res = XDB::query("SELECT fid FROM forums.list WHERE nom={?}", $p_for);
+        if ($res->numRows()) {
+            $cible[] = $p_for;
+        } else { // pas de forum promo, il faut le créer
+            $res = XDB::query("SELECT  SUM(perms IN ('admin','user') AND deces=0),COUNT(*)
+                                 FROM  auth_user_md5 WHERE promo={?}", $promo);
+            list($effau, $effid) = $res->fetchOneRow();
+            if (5*$effau>$effid) { // + de 20% d'inscrits
+                $mymail = new PlMailer('mails/forums.promo.tpl');
+                $mymail->assign('promo', $promo);
+                $mymail->send();
+            }
+        }
+
+        while (list ($key, $val) = each ($cible)) {
+            XDB::execute("INSERT INTO  forums.abos (fid,uid)
+                               SELECT  fid,{?} FROM forums.list WHERE nom={?}", $uid, $val);
+        }
+    }
+
     function handler_banana(&$page, $group = null, $action = null, $artid = null)
     {
         $get = Array();
@@ -38,7 +64,7 @@ class BananaModule extends PLModule
             $get['group'] = $group;
         }
         if (Post::has('updateall')) {
-            $get['banana'] = 'updateall';
+            $get['updateall'] = Post::v('updateall');
         }
         if (!is_null($action)) {
             if ($action == 'new') {
@@ -66,17 +92,17 @@ class BananaModule extends PLModule
 
         if (!(Post::has('action') && Post::has('banananame') && Post::has('bananasig')
         && Post::has('bananadisplay') && Post::has('bananamail')
-        && Post::has('bananaupdate') && Post::get('action')=="OK" ))
+        && Post::has('bananaupdate') && Post::v('action')=="OK" ))
         {
             $req = XDB::query("
                 SELECT  nom,mail,sig,if(FIND_IN_SET('threads',flags),'1','0'),
                         IF(FIND_IN_SET('automaj',flags),'1','0') 
                   FROM  forums.profils
-                 WHERE  uid = {?}", Session::getInt('uid'));
+                 WHERE  uid = {?}", S::v('uid'));
             if (!(list($nom,$mail,$sig,$disp,$maj) = $req->fetchOneRow())) {
-                $nom  = Session::get('prenom').' '.Session::get('nom');
-                $mail = Session::get('forlife').'@'.$globals->mail->domain;
-                $sig  = $nom.' ('.Session::getInt('promo').')';
+                $nom  = S::v('prenom').' '.S::v('nom');
+                $mail = S::v('forlife').'@'.$globals->mail->domain;
+                $sig  = $nom.' ('.S::v('promo').')';
                 $disp = 0;
                 $maj  = 0;
             }
@@ -89,10 +115,10 @@ class BananaModule extends PLModule
             XDB::execute(
                 'REPLACE INTO  forums.profils (uid,sig,mail,nom,flags)
                        VALUES  ({?},{?},{?},{?},{?})',
-                Session::getInt('uid'), Post::get('bananasig'),
-                Post::get('bananamail'), Post::get('banananame'),
-                (Post::getBool('bananadisplay') ? 'threads,' : '') .
-                (Post::getBool('bananaupdate') ? 'automaj' : '')
+                S::v('uid'), Post::v('bananasig'),
+                Post::v('bananamail'), Post::v('banananame'),
+                (Post::b('bananadisplay') ? 'threads,' : '') .
+                (Post::b('bananaupdate') ? 'automaj' : '')
             );
         }
     }
@@ -113,10 +139,10 @@ class BananaModule extends PLModule
     function run_banana(&$page, $params = null)
     {
         $page->changeTpl('banana/index.tpl');
-        $page->addCssLink('css/banana.css');
+        $page->addCssLink('banana.css');
         $page->assign('xorg_title','Polytechnique.org - Forums & PA');
 
-        require_once('banana.inc.php');
+        require_once dirname(__FILE__).'/banana/banana.inc.php';
 
         $res = PlatalBanana::run($params);
         $page->assign_by_ref('banana', $banana);