Split the SearchSet into QuickSet and AdvancedSet
[platal.git] / modules / marketing.php
index 5b35bb8..96b2cf2 100644 (file)
@@ -39,9 +39,62 @@ class MarketingModule extends PLModule
     function handler_marketing(&$page)
     {
         $page->changeTpl('marketing/index.tpl');
-
         $page->setTitle('Marketing');
-        $page->trigWarning("Les statistiques sont momentanéement désactivées");
+
+        $alive = new UserFilter(new PFC_Not(new UFC_Dead()));
+        $registered = new UserFilter(new PFC_And(new UFC_Registered(), new PFC_Not(new UFC_Dead())));
+        $alive72 = new UserFilter(new PFC_And(new UFC_Promo('>=', UserFilter::GRADE_ING, 1972), new PFC_Not(new UFC_Dead())));
+        $registered72 = new UserFilter(new PFC_And(new UFC_Registered(), new UFC_Promo('>=', UserFilter::GRADE_ING, 1972), new PFC_Not(new UFC_Dead())));
+        $aliveWomen = new UserFilter(new PFC_And(new UFC_Sex(User::GENDER_FEMALE) , new PFC_Not(new UFC_Dead())));
+        $registeredWomen = new UserFilter(new PFC_And(new UFC_Registered(), new UFC_Sex(User::GENDER_FEMALE), new PFC_Not(new UFC_Dead())));
+        $statistics = array(
+            'alive'           => $alive->getTotalCount(),
+            'registered'      => $registered->getTotalCount(),
+            'alive72'         => $alive72->getTotalCount(),
+            'registered72'    => $registered72->getTotalCount(),
+            'womenAlive'      => $aliveWomen->getTotalCount(),
+            'womenRegistered' => $registeredWomen->getTotalCount(),
+        );
+        $statistics['registeredRate']      = $statistics['registered'] / $statistics['alive'] * 100;
+        $statistics['registeredRate72']    = $statistics['registered72'] / $statistics['alive72'] * 100;
+        $statistics['womenRegisteredRate'] = $statistics['womenRegistered'] / $statistics['womenAlive'] * 100;
+
+        $registeredWeek = new UserFilter(new PFC_And(new UFC_Registered(false, '>=', strtotime('1 week ago')), new PFC_Not(new UFC_Dead())));
+        $registrationPending = XDB::fetchOneCell('SELECT  COUNT(*)
+                                                    FROM  register_pending');
+        $registrations = array(
+            'week'    => $registeredWeek->getTotalCount(),
+            'pending' => $registrationPending,
+        );
+
+        $ok = XDB::fetchOneCell('SELECT  COUNT(*)
+                                   FROM  register_mstats
+                                  WHERE  success != \'0000-00-00\'');
+        $okWeek = XDB::fetchOneCell('SELECT  COUNT(*)
+                                       FROM  register_mstats
+                                      WHERE  success >= {?}', strtotime('1 week ago'));
+        $res = XDB::fetchAllAssoc('SELECT  type, COUNT(*) as count
+                                     FROM  register_marketing
+                                 GROUP BY  type');
+        $no = array();
+        foreach ($res as $value) {
+            $no[$value['type']] = $value['count'];
+        }
+        $no['week'] = XDB::fetchOneCell('SELECT  COUNT(*)
+                                           FROM  register_marketing
+                                          WHERE  last >= {?}', strtotime('1 week ago'));
+        $marketings = array(
+            'ok'      => $ok,
+            'okWeek'  => $okWeek,
+            'noPerso' => (isset($no['user']) ? $no['user'] : 0),
+            'noXorg'  => (isset($no['staff']) ? $no['staff'] : 0),
+            'noAX'    => (isset($no['ax']) ? $no['ax'] : 0),
+            'noWeek'  => $no['week'],
+        );
+
+        $page->assign('statistics', $statistics);
+        $page->assign('registrations', $registrations);
+        $page->assign('marketings', $marketings);
     }
 
     function handler_private(&$page, $hruid = null,
@@ -190,7 +243,6 @@ class MarketingModule extends PLModule
                 $page->trigError("Il faut que tu ajoutes un commentaire à ta proposition pour justifier le "
                                . "besoin de changer la redirection de {$user->fullName()}.");
             } else {
-                require_once 'validations.inc.php';
                 $valid = new BrokenReq(S::user(), $user, $email, trim(Post::v('comment')));
                 $valid->submit();
                 $page->assign('sent', true);
@@ -260,6 +312,7 @@ class MarketingModule extends PLModule
             require_once 'marketing.inc.php';
 
             $sender = User::getSilent(S::v('uid'));
+            $perso_signature = 'Cordialement,<br />-- <br />' . $sender->fullName();
             $market = new AnnuaireMarketing(null, true);
             $text = $market->getText(array(
                 'sexe'           => $user->isFemale(),
@@ -269,11 +322,10 @@ class MarketingModule extends PLModule
             $text = str_replace('%%hash%%', '', $text);
             $text = str_replace('%%personal_notes%%', '<em id="personal_notes_display"></em>', $text);
             $text = str_replace('%%sender%%',
-                                "<span id=\"sender\">" . $sender->fullName() . '</span>', $text);
+                                '<span id="sender">' . $perso_signature . '</span>', $text);
             $page->assign('text', nl2br($text));
-            // TODO (JAC): define a unique Xorg signature for all the emails we send.
-            $page->assign('xorg_signature', "L'équipe de Polytechnique.org,<br />Le portail des élèves & anciens élèves de l'École polytechnique");
-            $page->assign('perso_signature', $sender->fullName());
+            $page->assign('perso_signature', $perso_signature);
+            $page->assign('mail_part', 'escaped_html');
         }
     }