marketing
authorPierre Habouzit (MadCoder <pierre.habouzit@m4x.org>
Tue, 11 Jan 2005 16:36:27 +0000 (16:36 +0000)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Thu, 26 Jun 2008 21:27:27 +0000 (23:27 +0200)
 - rework a lot of things (relance for example)
 - add private.php/tpl

git-archimport-id: opensource@polytechnique.org--2005/platal--mainline--0.9--patch-289

htdocs/marketing/private.php [new file with mode: 0644]
htdocs/marketing/relance.php
include/marketing.inc.php
plugins/modifier.date_format.php
templates/mails/marketing.utilisateur.tpl
templates/marketing/private.tpl [new file with mode: 0644]
templates/marketing/relance.tpl
upgrade/0.9.4/20_register.sql

diff --git a/htdocs/marketing/private.php b/htdocs/marketing/private.php
new file mode 100644 (file)
index 0000000..0fbf106
--- /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                *
+ ***************************************************************************/
+
+require_once('xorg.inc.php');
+new_admin_page('marketing/private.tpl');
+
+$uid = Env::get('uid');
+$res = $globals->xdb->query("SELECT nom, prenom, promo FROM auth_user_md5 WHERE user_id={?} AND perms='pending'", $uid);
+
+if (list($nom, $prenom, $promo) = $res->fetchOneRow()) {
+    $page->gassign('nom');
+    $page->gassign('prenom');
+    $page->gassign('promo');
+} else {
+    $page->kill('uid invalide');
+}
+
+if (Env::has('del')) {
+    $globals->xdb->execute('DELETE FROM register_marketing WHERE uid={?} AND email={?}', $uid, Env::get('del'));
+}
+
+if (Env::has('relance')) {
+    require_once('marketing.inc.php');
+    if (relance($uid)) {
+        $page->trig('relance faite');
+    }
+}
+
+$res = $globals->xdb->iterator(
+        "SELECT  r.*, a.alias
+           FROM  register_marketing AS r
+     INNER JOIN  aliases            AS a ON (r.sender=a.id AND a.type = 'a_vie')
+          WHERE  uid={?}
+       ORDER BY  date", $uid);
+$page->assign('addr', $res);
+
+$res = $globals->xdb->query("SELECT date, relance FROM register_pending WHERE uid = {?}", $uid);
+if (list($pending, $relance) = $res->fetchOneCell()) {
+    $page->gassign('pending');
+    $page->gassign('relance');
+}
+
+
+$page->run();
+?>
index aa77a9e..4c10451 100644 (file)
@@ -24,47 +24,22 @@ new_admin_page('marketing/relance.tpl');
 
 /* une relance a été demandée - on envoit les mails correspondants */
 if (Post::has('relancer')) {
-    require_once("xorg.mailer.inc.php");
-    
     $res   = $globals->xdb->query("SELECT COUNT(*) FROM auth_user_md5 WHERE deces=0");
     $nbdix = $res->fetchOneCell();
-    $res   = $globals->xdb->iterRow(
-            "SELECT  r.date, u.promo, u.nom, u.prenom, r.uid, r.email, r.bestalias
-               FROM  register_pending AS r
-         INNER JOIN  auth_user_md5    AS u ON u.user_id = r.uid");
 
-    $sent = Array();
-
-    while (list($ldate, $lpromo, $lnom, $lprenom, $uid, $lemail, $lusername) = $res->next()) {
-        if (Post::get($uid) == "1") {
-            $hash     = rand_url_id(12);
-            $pass     = rand_pass();
-            $pass_md5 = md5($nveau_pass);
-            $fdate    = substr($ldate, 8, 2)."/".substr($ldate, 5, 2)."/".substr($ldate, 0, 4);
-            
-            $mymail = new XOrgMailer('marketing.relance.tpl');
-            $mymail->assign('nbdix',      $nbdix);
-            $mymail->assign('fdate',      $fdate);
-            $mymail->assign('lusername',  $lusername);
-            $mymail->assign('nveau_pass', $pass);
-            $mymail->assign('baseurl',    $globals->baseurl);
-            $mymail->assign('lins_id',    $hash);
-            $mymail->assign('lemail',     $lemail);
-            $mymail->assign('subj',       $lusername."@polytechnique.org");
-
-            $globals->xdb->execute("UPDATE register_pending SET hash={?}, password={?}, relance=NOW() WHERE uid={?}",
-                    $hash, $pass, $uid);
-            $mymail->send();
-
-            $sent[] = "$lprenom $lnom ($lpromo) a été relancé !";
+    $sent  = Array();
+    foreach (array_keys($_POST['relance']) as $uid) {
+        if ($tmp = relance($uid, $nbdix)) {
+            $sent[] = $tmp.' a été relancé';
         }
     }
-    $page->assign_by_ref('sent', $sent);
+    $page->assign('sent', $sent);
 }
 
 $sql = "SELECT  r.date, r.relance, r.uid, u.promo, u.nom, u.prenom
           FROM  register_pending AS r
     INNER JOIN  auth_user_md5    AS u ON r. uid = u.user_id
+         WHERE  hash!='INSCRIT'
       ORDER BY  date DESC";
 $page->assign('relance', $globals->xdb->iterator($sql));
 
index b23d0b3..b4522b1 100644 (file)
@@ -19,7 +19,7 @@
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************/
 
-// {{{ function user_cmp
+// {{{ function mark_send_mail
 
 function mark_send_mail($uid, $email)
 {
@@ -31,4 +31,46 @@ function mark_send_mail($uid, $email)
 }
 
 // }}}
+// {{{ function relance
+
+function relance($uid, $nbx = -1)
+{
+    require_once('xorg.mailer.inc.php');
+    global $globals;
+
+    if ($nbx < 0) {
+        $res = $globals->xdb->query("SELECT COUNT(*) FROM auth_user_md5 WHERE deces=0");
+        $nbx = $res->fetchOneCell();
+    }
+
+    $res = $globals->xdb->query(
+            "SELECT  r.date, u.promo, u.nom, u.prenom, r.email, r.bestalias
+               FROM  register_pending AS r
+         INNER JOIN  auth_user_md5    AS u ON u.user_id = r.uid
+              WHERE  hash!='INSCRIT' AND uid={?} AND TO_DAYS(relance) < TO_DAYS(NOW())", $uid);
+    if (!list($date, $promo, $nom, $prenom, $email, $alias) = $res->fetchOneRow()) {
+        return false;
+    }
+
+    $hash     = rand_url_id(12);
+    $pass     = rand_pass();
+    $pass_md5 = md5($pass);
+    $fdate    = strftime('%d %B %Y', strtotime($date));
+    
+    $mymail = new XOrgMailer('marketing.relance.tpl');
+    $mymail->assign('nbdix',      $nbx);
+    $mymail->assign('fdate',      $fdate);
+    $mymail->assign('lusername',  $alias);
+    $mymail->assign('nveau_pass', $pass);
+    $mymail->assign('baseurl',    $globals->baseurl);
+    $mymail->assign('lins_id',    $hash);
+    $mymail->assign('lemail',     $email);
+    $mymail->assign('subj',       $alias.'@'.$globals->mail->domain);
+    $mymail->send();
+    $globals->xdb->execute('UPDATE register_pending SET hash={?}, password={?}, relance=NOW() WHERE uid={?}', $hash, $pass_md5, $uid);
+
+    return "$prenom $nom ($promo)";
+}
+
+// }}}
 ?>
index 72c8b08..66211d7 100644 (file)
 
 function smarty_modifier_date_format($string, $format = '%x', $default_date=null)
 {
-    if (empty($format) && empty($default_date)) return;
-    $f = empty($format) ? $default_date : $format;
-    $f = str_replace('%X', '%T', str_replace('%x', '%d %B %Y', $f));
+    $d = empty($string) ? $default_date : $string;
+    if (empty($format) || preg_match('/^[ 0\-]*$/', $d)) return;
+    $f = str_replace('%X', '%T', str_replace('%x', '%d %B %Y', $format));
 
-    if (preg_match('/^\d{14}$/', $string)) {
-        $t = mktime(substr($string,8,2),substr($string,10,2),substr($string,12,2),
-                substr($string,4,2),substr($string,6,2),substr($string,0,4));
+    if (preg_match('/^\d{14}$/', $d)) {
+        $t = mktime(substr($d,8,2), substr($d,10,2), substr($d,12,2), substr($d,4,2), substr($d,6,2), substr($d,0,4));
     } else {
-        $t = strtotime($string);
+        $t = strtotime($d);
     }
 
     if ( $t != -1 ) {
         return strftime($f , $t);
     } else {
         require_once('Date.php');
-        $date = new Date($string);
+        $date = new Date($d);
         return $date->format($f);
     }
 }
index 00e767a..15b9015 100644 (file)
@@ -30,7 +30,7 @@ Cher camarade,
 Ta fiche n'est pas à jour dans l'annuaire des Polytechniciens sur Internet. Pour la mettre à jour, il te suffit de visiter cette page ou de copier cette adresse dans la barre de ton navigateur :
 
 ==========================================================
-{$baseurl}/register/maj.php?n={$user_id}
+{$baseurl}/register/?hash={$user_id}
 ==========================================================
 
 Il ne te faut que 5 minutes sur http://www.polytechnique.org/ pour rejoindre les {$num_users} camarades branchés grâce au système de reroutage de l'X et qui permet de joindre un camarade en connaissant seulement son nom et son prénom... et de bénéficier pour la vie d'une adresse prestigieuse {$mailorg}@polytechnique.org et son alias discret {$mailorg}@m4x.org (m4x = mail for X).
diff --git a/templates/marketing/private.tpl b/templates/marketing/private.tpl
new file mode 100644 (file)
index 0000000..ceb2afb
--- /dev/null
@@ -0,0 +1,72 @@
+{***************************************************************************
+ *  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                *
+ ***************************************************************************}
+
+
+<h1>Marketing de {$prenom} {$nom}</h1>
+
+{if $pending}
+
+<h2>Inscription en cours</h2>
+
+<p>
+Cet utilisateur a une inscription en cours depuis le {$pending|date_format}.
+</p>
+<p>
+{if $relance eq '0000-00-00'}
+il n'a jamais été relancé.
+{else}
+sa dernière relance date du {$relance|date_format}
+{/if}
+</p>
+
+<p>[<a href='{$smarty.server.REQUEST_URI}&amp;relance=1'>le relancer</a>]</p>
+
+{/if}
+
+<h2>Adresses connues</h2>
+
+<table class="bicol" cellpadding="0" cellspacing="0">
+  <tr>
+    <th>Adresse</th>
+    <th>Marketeur</th>
+    <th>Date</th>
+    <th>Envois</th>
+    <th>Nb.</th>
+    <th>&nbsp;</th>
+  </tr>
+  {iterate from=$addr item=a}
+  <tr class="{cycle values='impair,pair'}">
+    <td>{$a.email}</td>
+    <td><a href="{rel}/fiche.php?user={$a.alias}" class="popup2">{$a.alias}</a> {if $a.type eq user}(*){/if}</td>
+    <td>{$a.date|date_format|default:'-'}</td>
+    <td>{$a.last|date_format|default:'-'}</td>
+    <td class='center'>{$a.nb|default:"-"}</td>
+    <td class='action'>
+      <a href='{$smarty.server.REQUEST_URI}&amp;del={$a.email}'>del</a>
+    </td>
+  </tr>
+  {/iterate}
+  <tr>
+    <td></td>
+    <td colspan='5' class='smaller'>(*): mail perso</td>
+  </tr>
+</table>
+
+{* vim:set et sw=2 sts=2 sws=2: *}
index 338e239..0af3ac0 100644 (file)
@@ -43,7 +43,7 @@
         {if $it.relance eq "0000-00-00"}Jamais{else}{$it.relance}{/if}
       </td>
       <td class="center">
-        <input type="checkbox" name="{$it.uid}" value="1" />
+        <input type="checkbox" name="relance[{$it.uid}]" value="1" />
       </td>
     </tr>
     {/iterate}
index 6b33c79..bf257dd 100644 (file)
@@ -21,7 +21,7 @@ CREATE TABLE register_pending (
     INDEX       (hash)
 );
 
-create table register_marketing (
+create table register_marketing (/*{{{*/
     uid         int          not null default 0,
     sender      int          not null default 0,
     email       varchar(255) not null default '',
@@ -68,4 +68,15 @@ replace into register_marketing (uid, sender, email, date, last, nb, type, hash)
       where date_ins = 0 and deces = 0;
 
 drop table envoidirect;
-drop table marketing;
+drop table marketing;/*}}}*/
+
+insert into  register_pending (uid, forlife, bestalias, mailorg2, password, email, date, relance, naissance, hash)
+     select  u.user_id, e.username,
+             IF(e.loginbis, e.loginbis, REPLACE(REPLACE(e.username, '.19', ''), '.20', '')),
+             IF(e.loginbis, REPLACE(REPLACE(e.username, '.19', ''), '.20', ''), NULL),
+             e.password, email, e.date, relance, e.naissance, ins_id
+       from  en_cours      AS e
+ inner join  auth_user_md5 AS u USING( matricule )
+      where  u.perms = 'pending';
+
+drop table en_cours;