From: Pascal Corpet Date: Sat, 15 Jan 2005 01:57:37 +0000 (+0000) Subject: switch the mail format preference (carnet and nl) to auth_user_quick X-Git-Tag: xorg/old~429 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=e8d2b60854e5a5c8dfaa0b3f91ec7bf0aeffff44;p=platal.git switch the mail format preference (carnet and nl) to auth_user_quick git-archimport-id: opensource@polytechnique.org--2005/platal--mainline--0.9--patch-327 --- diff --git a/bin/newsletter.send.php b/bin/newsletter.send.php index 86fce41..465ca00 100755 --- a/bin/newsletter.send.php +++ b/bin/newsletter.send.php @@ -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; } diff --git a/hooks/newsletter.inc.php b/hooks/newsletter.inc.php index 9f6bdf3..0d9e1b4 100644 --- a/hooks/newsletter.inc.php +++ b/hooks/newsletter.inc.php @@ -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); } // }}} diff --git a/htdocs/newsletter/index.php b/htdocs/newsletter/index.php index 517b4d1..ebdb707 100644 --- a/htdocs/newsletter/index.php +++ b/htdocs/newsletter/index.php @@ -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()); diff --git a/htdocs/newsletter/show.php b/htdocs/newsletter/show.php index 18cba2a..47850be 100644 --- a/htdocs/newsletter/show.php +++ b/htdocs/newsletter/show.php @@ -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(); diff --git a/htdocs/preferences.php b/htdocs/preferences.php index 6d49391..1a3eed1 100644 --- a/htdocs/preferences.php +++ b/htdocs/preferences.php @@ -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: ?> diff --git a/include/newsletter.inc.php b/include/newsletter.inc.php index 91fc1cd..f6ef54c 100644 --- a/include/newsletter.inc.php +++ b/include/newsletter.inc.php @@ -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: ?> diff --git a/include/xorg/session.inc.php b/include/xorg/session.inc.php index f329f22..5541a66 100644 --- a/include/xorg/session.inc.php +++ b/include/xorg/session.inc.php @@ -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 diff --git a/templates/newsletter/index.tpl b/templates/newsletter/index.tpl index 3a719b9..bb5e1c8 100644 --- a/templates/newsletter/index.tpl +++ b/templates/newsletter/index.tpl @@ -30,44 +30,19 @@ utilise le formulaire d

Ton statut

-{if $nls eq html} -

-Tu es actuellement inscrit à la lettre mensuelle de Polytechnique.org dans sont format HTML ! -

-{elseif $nls eq text} -

-Tu es actuellement inscrit à la lettre mensuelle de Polytechnique.org dans sont format texte ! -

-{else} -

-Tu n'es actuellement pas inscrit à la lettre mensuelle de Polytechnique.org. -

-{/if} - -{if $nls neq "text"} -

-Pour recevoir la version texte suis le lien : -

-
- [m'inscrire pour le format texte] -
-{/if} - -{if $nls neq "html"} +{if $nls}

-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 des préférences)

- [m'inscrire pour le format HTML] + [me désinscrire de la lettre mensuelle]
-{/if} - -{if $nls} +{else}

-Pour te désinscrire suis le lien : +Tu n'es actuellement pas inscrit à la lettre mensuelle de Polytechnique.org.

- [me désinscrire] + [m'inscrire à la lettre mensuelle]
{/if} diff --git a/templates/preferences.tpl.d/30.mailformat.tpl b/templates/preferences.tpl.d/30.mailformat.tpl new file mode 100644 index 0000000..d283961 --- /dev/null +++ b/templates/preferences.tpl.d/30.mailformat.tpl @@ -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'} +

Recevoir les mails en format HTML

+{else} +

Recevoir les mails en format texte

+{/if} +
+ 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. +
+ +{* vim:set et sw=2 sts=2 sws=2: *} diff --git a/upgrade/0.9.4/30_auth_user_quick.sql b/upgrade/0.9.4/30_auth_user_quick.sql index 5e0ccc9..fd482b7 100644 --- a/upgrade/0.9.4/30_auth_user_quick.sql +++ b/upgrade/0.9.4/30_auth_user_quick.sql @@ -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 index 0000000..103d466 --- /dev/null +++ b/upgrade/0.9.4/70_newsletter.sql @@ -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; +