Migrate Xnet mailer to use PlUpload for attachments
[platal.git] / modules / xnetgrp.php
index d16a08a..e44b1ba 100644 (file)
@@ -301,7 +301,11 @@ class XnetGrpModule extends PLModule
 
             require_once dirname(__FILE__) . '/xnetgrp/mail.inc.php';
             $tos = get_all_redirects($mbr,  $mls, $mmlist);
-            send_xnet_mails($from, $sujet, $body, $tos, Post::v('replyto'), $_FILES['uploaded']);
+            $upload = PlUpload::get($_FILES['uploaded'], S::v('forlife'), 'xnet.emails', true);
+            send_xnet_mails($from, $sujet, $body, $tos, Post::v('replyto'), $upload, @$_FILES['uploaded']['name']);
+            if ($upload) {
+                $upload->rm();
+            }
             $page->kill("Mail envoyé !");
             $page->assign('sent', true);
         }
@@ -409,7 +413,7 @@ class XnetGrpModule extends PLModule
                            m.perms='admin' AS admin,
                            m.origine='X' AS x,
                            u.perms!='pending' AS inscrit,
-                           m.uid, e.email AS actif
+                           m.uid, IF(e.email IS NULL,NULL,1) AS actif
                      FROM  groupex.membres AS m
                 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' )
@@ -420,6 +424,7 @@ class XnetGrpModule extends PLModule
                  ORDER BY  $tri
                     LIMIT  {?},{?}", $globals->asso('id'), $ofs*NB_PER_PAGE, NB_PER_PAGE);
         $page->assign('ann', $ann);
+        $page->jsonAssign('ann', $ann);
     }
 
     function handler_trombi(&$page, $num = 1)
@@ -467,7 +472,6 @@ class XnetGrpModule extends PLModule
             $res = XDB::query('SELECT uid
                                  FROM groupex.membres
                                 WHERE asso_id = {?}', $globals->asso('id'));
-            require_once('vcard.inc.php');
             $vcard = new VCard($res->fetchColumn(), $photos == 'photos', 'Membre du groupe ' . $globals->asso('nom'));
             $vcard->do_page($page);
         } else {
@@ -712,22 +716,17 @@ class XnetGrpModule extends PLModule
                                          FROM auth_user_md5
                                         WHERE user_id = {?} AND perms = 'pending'", $uid);
                     if ($res->numRows() == 1) {
-                        XDB::execute('INSERT INTO groupex.membres (uid, asso_id, origine, email)
-                                           VALUES ({?}, {?}, "X", {?})',
-                                               $uid, $globals->asso('id'), $email);
                         if (Env::v('market')) {
-                            $res   = XDB::query('SELECT COUNT(*)
-                                                   FROM register_marketing
-                                                  WHERE uid={?} AND email={?}', $uid, $email);
-                            if (!$res->fetchOneCell()) {
-                                XDB::execute("INSERT INTO  register_marketing (uid,sender,email,date,last,nb,type,hash)
-                                                   VALUES  ({?}, {?}, {?}, NOW(), 0, 0, {?}, '')",
-                                             $uid, S::v('uid'), $email, Env::v('market_from')); 
-                                require_once('validations.inc.php');
-                                $req = new MarkReq(S::v('uid'), $uid, $email, Env::v('market_from') == 'user');
-                                $req->submit();
+                            $market = Marketing::get($uid, $email);
+                            if (!$market) {
+                                $market = new Marketing($uid, $email, 'group', $globals->asso('nom'),
+                                                        Env::v('market_from'), S::v('uid'));
+                                $market->add();
                             }            
                         }
+                        XDB::execute('INSERT INTO groupex.membres (uid, asso_id, origine, email)
+                                           VALUES ({?}, {?}, "X", {?})',
+                                     $uid, $globals->asso('id'), $email);
                         pl_redirect("member/$email");
                     }
                     $page->trig("Utilisateur invalide");
@@ -749,22 +748,29 @@ class XnetGrpModule extends PLModule
     {
         header('Content-Type: text/html; charset="UTF-8"');
         $page->changeTpl('xnetgrp/membres-new-search.tpl', NO_SKIN);
-        list($nom, $prenom) = str_replace(array('-', ' ', "'"), '%', array(Env::v('nom'), Env::v('prenom')));
-        $where = "perms = 'pending'";
-        if (!empty($nom)) {
-            $where .= " AND nom LIKE '%$nom%'";
-        }
-        if (!empty($prenom)) {
-            $where .= " AND prenom LIKE '%$prenom%'";
-        }
-        if (preg_match('/^[0-9]{4}$/', Env::v('promo'))) {
-            $where .= " AND promo = " . Env::i('promo');
-        } elseif (Env::has('promo')) {
-            return;
+        if (Env::has('login')) {
+            require_once 'user.func.inc.php';
+            $res = get_not_registered_user(Env::v('login'), true);
+        } else {
+            list($nom, $prenom) = str_replace(array('-', ' ', "'"), '%', array(Env::v('nom'), Env::v('prenom')));
+            $where = "perms = 'pending'";
+            if (!empty($nom)) {
+                $where .= " AND nom LIKE '%$nom%'";
+            }
+            if (!empty($prenom)) {
+                $where .= " AND prenom LIKE '%$prenom%'";
+            }
+            if (preg_match('/^[0-9]{4}$/', Env::v('promo'))) {
+                $where .= " AND promo = " . Env::i('promo');
+            } elseif (preg_match('/^[0-9]{2}$/', Env::v('promo'))) {
+                $where .= " AND MOD(promo, 100) = " . Env::i('promo');
+            } elseif (Env::has('promo')) {
+                return;
+            }
+            $res = XDB::iterator("SELECT user_id, nom, prenom, promo
+                                    FROM auth_user_md5
+                                   WHERE $where");
         }
-        $res = XDB::iterator("SELECT user_id, nom, prenom, promo
-                                FROM auth_user_md5
-                               WHERE $where");
         if ($res->total() < 30) {
             $page->assign("choix", $res);
         }