switch the mail format preference (carnet and nl) to auth_user_quick
authorPascal Corpet <pascal.corpet@m4x.org>
Sat, 15 Jan 2005 01:57:37 +0000 (01:57 +0000)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Thu, 26 Jun 2008 21:27:35 +0000 (23:27 +0200)
git-archimport-id: opensource@polytechnique.org--2005/platal--mainline--0.9--patch-327

bin/newsletter.send.php
hooks/newsletter.inc.php
htdocs/newsletter/index.php
htdocs/newsletter/show.php
htdocs/preferences.php
include/newsletter.inc.php
include/xorg/session.inc.php
templates/newsletter/index.tpl
templates/preferences.tpl.d/30.mailformat.tpl [new file with mode: 0644]
upgrade/0.9.4/30_auth_user_quick.sql
upgrade/0.9.4/70_newsletter.sql [new file with mode: 0644]

index 86fce41..465ca00 100755 (executable)
@@ -39,12 +39,14 @@ $nl->setSent();
 
 while(true) {
     $res = $globals->dbx->iterRow(
-            "SELECT  ni.user_id, ni.pref, a.alias,
+            "SELECT  ni.user_id, a.alias,
                      u.prenom, IF(u.epouse='', u.nom, u.epouse),
-                     FIND_IN_SET('femme', u.flags)
-               FROM  newsletter_ins AS ni
-         INNER JOIN  auth_user_md5  AS u  USING(user_id)
-         INNER JOIN  aliases        AS a  ON(u.user_id=a.id AND FIND_IN_SET('bestalias',a.flags))
+                     FIND_IN_SET('femme', u.flags),
+                    q.core_mail_fmt AS pref
+               FROM  newsletter_ins  AS ni
+         INNER JOIN  auth_user_md5   AS u  USING(user_id)
+        INNER JOIN  auth_user_quick AS q  ON(q.user_id = u.user_id)
+         INNER JOIN  aliases         AS a  ON(u.user_id=a.id AND FIND_IN_SET('bestalias',a.flags))
               WHERE  ni.last<{?}
               LIMIT  60", $id);
     if (!$res->numRows()) { exit; }
index 9f6bdf3..0d9e1b4 100644 (file)
@@ -51,7 +51,7 @@ function newsletter_menu()
 function newsletter_subscribe($forlife, $uid, $promo, $password)
 {
     require_once('newsletter.inc.php');
-    subscribe_nl(true,$uid);
+    subscribe_nl($uid);
 }
 
 // }}}
index 517b4d1..ebdb707 100644 (file)
@@ -24,7 +24,7 @@ new_skinned_page('newsletter/index.tpl', AUTH_COOKIE);
 require_once("newsletter.inc.php");
 
 if(Get::has('out')) { unsubscribe_nl(); }
-if(Get::has('in'))  { subscribe_nl(Get::get('in')=='html'); }
+if(Get::has('in'))  { subscribe_nl(); }
 
 $page->assign('nls',get_nl_state());
 $page->assign_by_ref('nl_list',get_nl_list());
index 18cba2a..47850be 100644 (file)
@@ -29,10 +29,7 @@ $nl = new NewsLetter($nid);
 $page->assign_by_ref('nl',$nl);
 
 if (Post::has('send')) {
-    $res = $globals->xdb->query('SELECT pref FROM newsletter_ins WHERE user_id={?}', Session::getInt('uid'));
-    $fmt = $res->fetchOneCell();
-    if (empty($fmt)) { $fmt = 'html'; }
-    $nl->sendTo(Session::get('prenom'), Session::get('nom'), Session::get('bestalias'), Session::get('femme'), $fmt=='html');
+    $nl->sendTo(Session::get('prenom'), Session::get('nom'), Session::get('bestalias'), Session::get('femme'), Session::get('mail_fmt')!='text');
 }
 
 $page->run();
index 6d49391..1a3eed1 100644 (file)
@@ -39,5 +39,16 @@ if (Env::has('forget')) {
     header('Location: preferences.php');
 }
 
+if (Env::has('mail_fmt')) {
+    $fmt=Env::get('mail_fmt');
+    if ($fmt != 'texte') $fmt = 'html';
+    $globals->xdb->execute("REPLACE INTO auth_user_quick
+                                     SET core_mail_fmt = '$fmt'
+                                   WHERE user_id = {?}", Session::get('uid'));
+    $_SESSION['mail_fmt'] = $fmt;
+}
+
 $page->run($has_cookie);
+
+// vim:set et sw=4 sts=4 sws=4:
 ?>
index 91fc1cd..f6ef54c 100644 (file)
@@ -454,7 +454,7 @@ function get_nl_list()
 function get_nl_state()
 {
     global $globals;
-    $res = $globals->xdb->query('SELECT pref FROM newsletter_ins WHERE user_id={?}', Session::getInt('uid'));
+    $res = $globals->xdb->query('SELECT 1 FROM newsletter_ins WHERE user_id={?}', Session::getInt('uid'));
     return $res->fetchOneCell();
 }
  
@@ -464,13 +464,12 @@ function unsubscribe_nl()
     $globals->xdb->execute('DELETE FROM newsletter_ins WHERE user_id={?}', Session::getInt('uid'));
 }
  
-function subscribe_nl($html=true, $uid=-1)
+function subscribe_nl($uid=-1)
 {
     global $globals;
     $user = ($uid == -1) ? Session::getInt('uid') : $uid;
-    $format = $html ? 'html' : 'text';
-    $globals->xdb->execute('REPLACE INTO  newsletter_ins (user_id,last,pref)
-                                 SELECT  {?}, MAX(id), {?} FROM newsletter WHERE bits!="new"', $user, $format);
+    $globals->xdb->execute('REPLACE INTO  newsletter_ins (user_id,last)
+                                 VALUES  ({?}, 0)', $user);
 }
  
 function justify($text,$n)
@@ -548,4 +547,5 @@ function enriched_to_text($input,$html=false,$just=false,$indent=0,$width=68)
 
 // }}}
 
+// vim:set et sw=4 sts=4 sws=4:
 ?>
index f329f22..5541a66 100644 (file)
@@ -326,7 +326,7 @@ function start_connexion ($uid, $identified)
 {
     global $globals;
     $res  = $globals->xdb->query("
-       SELECT  u.user_id AS uid, prenom, nom, perms, promo, matricule, UNIX_TIMESTAMP(s.start) AS lastlogin, s.host,
+       SELECT  u.user_id AS uid, prenom, nom, perms, promo, matricule, UNIX_TIMESTAMP(s.start) AS lastlogin, s.host, q.core_mail_fmt AS mail_fmt,
                 a.alias AS forlife, UNIX_TIMESTAMP(q.banana_last) AS banana_last, q.watch_last,
                a2.alias AS bestalias, password, FIND_IN_SET('femme', u.flags) AS femme
           FROM  auth_user_md5   AS u
index 3a719b9..bb5e1c8 100644 (file)
@@ -30,44 +30,19 @@ utilise <a href='submit.php'>le formulaire d
 
 <h2>Ton statut</h2>
 
-{if $nls eq html}
-<p>
-Tu es actuellement inscrit à la lettre mensuelle de Polytechnique.org dans sont format HTML !
-</p>
-{elseif $nls eq text}
-<p>
-Tu es actuellement inscrit à la lettre mensuelle de Polytechnique.org dans sont format texte !
-</p>
-{else}
-<p>
-Tu n'es actuellement pas inscrit à la lettre mensuelle de Polytechnique.org.
-</p>
-{/if}
-
-{if $nls neq "text"}
-<p>
-Pour recevoir la version texte suis le lien :
-</p>
-<div class='center'>
-  [<a href='?in=text'>m'inscrire pour le format texte</a>]
-</div>
-{/if}
-
-{if $nls neq "html"}
+{if $nls}
 <p>
-Pour recevoir la version HTML suis le lien :
+Tu es actuellement inscrit à la lettre mensuelle de Polytechnique.org (pour choisir le format HTML ou texte, rends toi sur la page <a href='../preferences.php'>des préférences</a>)
 </p>
 <div class='center'>
-  [<a href='?in=html'>m'inscrire pour le format HTML</a>]
+  [<a href='?out=1'>me désinscrire de la lettre mensuelle</a>]
 </div>
-{/if}
-
-{if $nls}
+{else}
 <p>
-Pour te désinscrire suis le lien :
+Tu n'es actuellement pas inscrit à la lettre mensuelle de Polytechnique.org.
 </p>
 <div class='center'>
-  [<a href='?out=1'>me désinscrire</a>]
+  [<a href='?in=1'>m'inscrire à la lettre mensuelle</a>]
 </div>
 {/if}
 
diff --git a/templates/preferences.tpl.d/30.mailformat.tpl b/templates/preferences.tpl.d/30.mailformat.tpl
new file mode 100644 (file)
index 0000000..d283961
--- /dev/null
@@ -0,0 +1,30 @@
+{***************************************************************************
+ *  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                *
+ ***************************************************************************}
+
+{if $smarty.session.mail_fmt eq 'texte'}
+<h3><a href="?mail_fmt=html">Recevoir les mails en format HTML</a></h3>
+{else}
+<h3><a href="?mail_fmt=texte">Recevoir les mails en format texte</a></h3>
+{/if}
+<div class='explication'>
+  La lettre mensuelle et les mails de notification du carnet te sont actuellement envoyé en format {$smarty.session.mail_fmt} si tu t'y es inscrit.
+</div>
+
+{* vim:set et sw=2 sts=2 sws=2: *}
index 5e0ccc9..fd482b7 100644 (file)
@@ -1,3 +1,4 @@
 alter table auth_user_quick add column emails_alias_pub enum('public', 'private') not null default 'private';
 alter table auth_user_quick add column profile_from_ax INT(1) not null default 0;
+alter table auth_user_quick add column core_mail_fmt enum('html', 'texte') not null default 'html';
 
diff --git a/upgrade/0.9.4/70_newsletter.sql b/upgrade/0.9.4/70_newsletter.sql
new file mode 100644 (file)
index 0000000..103d466
--- /dev/null
@@ -0,0 +1,3 @@
+update auth_user_quick as q INNER JOIN newsletter_ins as n USING(user_id) SET q.core_mail_fmt = n.pref;
+alter table newsletter_ins drop pref;
+