corrects parts of the hooks code + hook for banana subscription
authorx2000habouzit <x2000habouzit>
Wed, 1 Dec 2004 13:13:03 +0000 (13:13 +0000)
committerx2000habouzit <x2000habouzit>
Wed, 1 Dec 2004 13:13:03 +0000 (13:13 +0000)
hooks/core/API [new file with mode: 0644]
hooks/core/banana.inc.php [new file with mode: 0644]
htdocs/inscription/step4.php
include/user.func.inc.php
include/xorg.hook.inc.php

diff --git a/hooks/core/API b/hooks/core/API
new file mode 100644 (file)
index 0000000..2d872d7
--- /dev/null
@@ -0,0 +1 @@
+function subscribe($forlife, $uid, $promo, $pass)
diff --git a/hooks/core/banana.inc.php b/hooks/core/banana.inc.php
new file mode 100644 (file)
index 0000000..3d05d48
--- /dev/null
@@ -0,0 +1,63 @@
+<?php
+/***************************************************************************
+ *  Copyright (C) 2003-2004 Polytechnique.org                              *
+ *  http://opensource.polytechnique.org/                                   *
+ *                                                                         *
+ *  This program is free software; you can redistribute it and/or modify   *
+ *  it under the terms of the GNU General Public License as published by   *
+ *  the Free Software Foundation; either version 2 of the License, or      *
+ *  (at your option) any later version.                                    *
+ *                                                                         *
+ *  This program is distributed in the hope that it will be useful,        *
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
+ *  GNU General Public License for more details.                           *
+ *                                                                         *
+ *  You should have received a copy of the GNU General Public License      *
+ *  along with this program; if not, write to the Free Software            *
+ *  Foundation, Inc.,                                                      *
+ *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
+ ***************************************************************************
+    $Id: banana.inc.php,v 1.1 2004-12-01 13:13:03 x2000habouzit Exp $
+ ***************************************************************************/
+
+// {{{ function banana_subscirbe()
+
+function &banana_subscribe($forlife, $uid, $promo, $password, &$result)
+{
+    global $globals;
+    
+    $cible = array('xorg.general','xorg.pa.emploi','xorg.pa.divers','xorg.pa.logements');
+    $p_for = "xorg.promo.x$promo";
+    
+    // récupération de l'id du forum promo
+    $res = $globals->db->query("SELECT fid FROM forums.list WHERE nom='$p_for'");
+    if (mysql_num_rows($res) == 1) {
+        $cible[] = $p_for;
+    } else { // pas de forum promo, il faut le créer
+       $req_au=$globals->db->query("SELECT SUM(perms IN ('admin','user') AND deces=0),COUNT(*) FROM auth_user_md5 WHERE promo='$promo'");
+       list($effau, $effid) = mysql_fetch_row($req_au);
+        mysql_free_result($req_au);
+       if (5*$effau>$effid) { // + de 20% d'inscrits
+           require_once("xorg.mailer.inc.php");
+           $mymail = new XOrgMailer('forums.promo.tpl');
+           $mymail->assign('promo', $promo);
+           $mymail->send();
+       }
+    }
+    mysql_free_result($res);
+    
+    while (list ($key, $val) = each ($cible)) {
+        $globals->db->query("INSERT INTO  forums.abos (fid,uid)
+                                  SELECT  fid,'$uid'
+                                    FROM  forums.list
+                                   WHERE  nom='$val'");
+    }
+
+    return ($result = true);
+}
+
+// }}}
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker:
+?>
index 038dfe0..ece9506 100644 (file)
@@ -18,7 +18,7 @@
  *  Foundation, Inc.,                                                      *
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************
-        $Id: step4.php,v 1.20 2004-11-30 21:11:39 x2000habouzit Exp $
+        $Id: step4.php,v 1.21 2004-12-01 13:13:03 x2000habouzit Exp $
  ***************************************************************************/
 
 require_once("xorg.inc.php");
@@ -58,10 +58,10 @@ if (!empty($_REQUEST['ref'])) {
     $sql = "UPDATE auth_user_md5 SET password='$password', nationalite=$nationalite, perms='user',
             date='$date', naissance='$naissance', date_ins = NULL WHERE matricule='$matricule'";
     $globals->db->query($sql);
-    $sql = "INSERT INTO  auth_user_quick (user_id)
-                 SELECT  user_id
-                  FROM  auth_user_md5
-                 WHERE  matricule='$matricule'";
+    $sql = "REPLACE INTO  auth_user_quick (user_id)
+                  SELECT  user_id
+                   FROM  auth_user_md5
+                  WHERE  matricule='$matricule'";
     $globals->db->query($sql);
     
     // on vérifie qu'il n'y a pas eu d'erreur
@@ -114,13 +114,6 @@ if (!empty($_REQUEST['ref'])) {
         $mymail->send();
     }
    
-
-    /****************** inscription à la liste promo +nl ****************/
-    $inspromo = inscription_listes_base($uid,$password,$promo);
-    /****************** inscription aux forums de base   ****************/
-    $insforumpromo = inscription_forum_promo($uid,$promo);
-    $insforums = inscription_forums($uid);
-
     // effacer la pré-inscription devenue 
     $globals->db->query("update en_cours set loginbis='INSCRIT' WHERE username='$forlife'");
 
@@ -141,7 +134,14 @@ if (!empty($_REQUEST['ref'])) {
 
     // s'il est dans la table envoidirect, on le marque comme inscrit
     $globals->db->query("update envoidirect set date_succes=NOW() where matricule = $matricule");
+
+    require_once("xorg.hook.inc.php");
+    $hook = new XOrgHook('core');
+    $hook->subscribe($forlife, $uid, $promo, $password, true);
+    
     start_connexion($uid,false);
+    /****************** inscription à la liste promo +nl ****************/
+    $inspromo = inscription_listes_base($uid,$password,$promo);
 } else
     $page->assign('error',ERROR_REF);
 
index 1552bab..509c4eb 100644 (file)
@@ -18,7 +18,7 @@
  *  Foundation, Inc.,                                                      *
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************
-    $Id: user.func.inc.php,v 1.5 2004-11-22 07:40:17 x2000habouzit Exp $
+    $Id: user.func.inc.php,v 1.6 2004-12-01 13:13:03 x2000habouzit Exp $
  ***************************************************************************/
 
 // {{{ function user_clear_all_subs()
@@ -67,63 +67,6 @@ function user_clear_all_subs($user_id, $really_del=true)
 }
 
 // }}}
-// {{{ function inscription_forum_promo()
-
-/** inscrit l'uid donnée au forum promo 
- * @param $uid UID
- * @param $promo promo
- * @return la reponse MySQL
- * @see step4.php
- */
-function inscription_forum_promo($uid,$promo)
-{
-    global $globals;
-    // récupération de l'id du forum promo
-    $result=$globals->db->query("SELECT fid FROM forums.list WHERE nom='xorg.promo.x$promo'");
-    if (!list($fid)=mysql_fetch_row($result)) { // pas de forum promo, il faut le créer
-       $req_au=$globals->db->query("SELECT count(*) FROM auth_user_md5 WHERE promo='$promo' AND perms IN ('admin','user')");
-       list($effau) = mysql_fetch_row($req_au);
-       $req_id=$globals->db->query("SELECT count(*) FROM auth_user_md5 WHERE promo='$promo'");
-       list($effid) = mysql_fetch_row($req_id);
-       if (5*$effau>$effid) { // + de 20% d'inscrits
-           require_once("xorg.mailer.inc.php");
-           $mymail = new XOrgMailer('forums.promo.tpl');
-           $mymail->assign('promo', $promo);
-           $mymail->send();
-       }
-       $fid = false; 
-    }
-    mysql_free_result($result);
-    if ($fid) {
-       $globals->db->query("INSERT INTO forums.abos (fid,uid) VALUES ('$fid','$uid')");
-       $res = !($globals->db->err());
-    } else  $res = false;
-    return $res;
-} 
-
-// }}}
-// {{{ function inscription_forums()
-
-/** inscrit UID aux forums par défaut
- * @param $uid UID
- * @return la reponse MySQL globale
- * @see step4.php
- */
-function inscription_forums($uid)
-{
-    global $globals;
-    $res = true;
-    $cible = array('xorg.general','xorg.pa.emploi','xorg.pa.divers','xorg.pa.logements');
-    while (list ($key, $val) = each ($cible)) {
-       $result=$globals->db->query("SELECT fid FROM forums.list WHERE nom='$val'");
-       list($fid)=mysql_fetch_row($result);
-       $globals->db->query("INSERT INTO forums.abos (fid,uid) VALUES ('$fid','$uid')");
-       $res = $res and !($globals->db->err());
-    }
-    return $res;
-}
-
-// }}}
 // {{{ function inscription_listes_base()
 
 /** inscrit l'uid donnée à la promo
index 2ec2551..438fa4e 100644 (file)
@@ -41,7 +41,7 @@ require_once("PEAR.php");
  * @category XOrgCore
  * @package  XOrgCore
  * @author   Pierre Habouzit <pierre.habouzit@polytechnique.org>
- * @version  $Id: xorg.hook.inc.php,v 1.7 2004-11-21 15:19:00 x2000habouzit Exp $
+ * @version  $Id: xorg.hook.inc.php,v 1.8 2004-12-01 13:13:03 x2000habouzit Exp $
  * @access   public
  * @link     http://doc.polytechnique.org/XOrgModule/#hook
  * @since    Classe available since 0.9.3
@@ -84,7 +84,7 @@ class XOrgHook extends PEAR
         }
         foreach (glob($globals->root."/hooks/$name/*.inc.php") as $file) {
             require_once("$file");
-            $this->_mods[] = str_replace('.inc.php', '', $file);
+            $this->_mods[] = basename($file, '.inc.php');
         }
     }
 
@@ -103,15 +103,16 @@ class XOrgHook extends PEAR
      */
     function __call($function, $arguments, &$return)
     {
-        if ( ($i = count($argument) - 1) < 0) {
+        if ( ($i = count($arguments) - 1) < 0) {
             $this->raiseError("In the Hook « {$this->_name} » the function « $function » expects at least 1 argument");
         }
         foreach ($this->_mods as $mod) {
+            echo $mod.'_'.$function;
             if (!function_exists($mod.'_'.$function)) continue;
-            $argument[$i] =& call_user_func_array($mod.'_'.$function,$argument);
+            $arguments[$i] =& call_user_func_array($mod.'_'.$function,$arguments);
         }
 
-        $return =& $argument[$i];
+        $return =& $arguments[$i];
         
         return true;
     }