Fix Delay between marketing attempts on same adress : the delay is now 30 days.
authorx2004lefloch <x2004lefloch@839d8a87-29fc-0310-9880-83ba4fa771e5>
Mon, 6 Aug 2007 14:24:35 +0000 (14:24 +0000)
committerx2004lefloch <x2004lefloch@839d8a87-29fc-0310-9880-83ba4fa771e5>
Mon, 6 Aug 2007 14:24:35 +0000 (14:24 +0000)
git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1909 839d8a87-29fc-0310-9880-83ba4fa771e5

include/marketing.inc.php
modules/marketing.php

index a49b4aa..cbbd43a 100644 (file)
@@ -168,11 +168,14 @@ class Marketing
         return $array;
     }
 
-    static public function get($uid, $email)
+    static public function get($uid, $email, $recentOnly = false)
     {
         $res = XDB::query("SELECT  uid, email, message, message_data, type, sender
                              FROM  register_marketing
-                            WHERE  uid = {?} AND email = {?}", $uid, $email);
+                            WHERE  uid = {?}
+                              AND  email = {?}".(
+              $recentOnly ? ' AND  DATEDIFF(NOW(), last) < 30' : ''), $uid, $email);
+
         if ($res->numRows() == 0) {
             return null;
         }
index 70d0c12..1b62a06 100644 (file)
@@ -261,16 +261,21 @@ class MarketingModule extends PLModule
             if (Post::has('valide')) {
                 require_once('xorg.misc.inc.php');
                 $email = trim(Post::v('mail'));
-                $market = Marketing::get($uid, $email);
+
                 if (!isvalid_email_redirection($email)) {
                     $page->trig("Email invalide !");
-                } elseif ($market) {
-                    $page->assign('already', true);
                 } else {
-                    $page->assign('ok', true);
-                    check_email($email, "Une adresse surveillée est proposée au marketing par " . S::v('forlife'));
-                    $market = new Marketing($uid, $email, 'default', null, Post::v('origine'), S::v('uid'));
-                    $market->add();
+                    // On cherche les marketings précédents sur cette adresse
+                    // email, en se restreignant au dernier mois
+                    
+                    if (Marketing::get($uid, $email, true)) {
+                        $page->assign('already', true);
+                    } else {
+                        $page->assign('ok', true);
+                        check_email($email, "Une adresse surveillée est proposée au marketing par " . S::v('forlife'));
+                        $market = new Marketing($uid, $email, 'default', null, Post::v('origine'), S::v('uid'));
+                        $market->add();
+                    }
                 }
             }
         }