From: Stéphane Jacob Date: Tue, 20 Sep 2011 21:21:03 +0000 (+0200) Subject: Stores and uses preferences for sending emails from site (Closes #1529). X-Git-Tag: xorg/1.1.4~145 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=40279e62029b638edf26eddc799a80561cc02ac3;hp=7f3ac125d8b532fd0fc643e3504e5bd06be01fc4;p=platal.git Stores and uses preferences for sending emails from site (Closes #1529). Signed-off-by: Stéphane Jacob --- diff --git a/ChangeLog b/ChangeLog index cc46cb5..e4e6b15 100644 --- a/ChangeLog +++ b/ChangeLog @@ -9,6 +9,9 @@ Bug/Wish: * Core: - #1523: Rename AUTH_MDP to AUTH_PASSWD -JAC + * Email: + - #1529: Stores and uses preferences for sending emails from site -JAC + * Payments: - #1512: Allows payments for unlogged users -JAC - #1537: Replaces payments page on main site by a donation page -JAC diff --git a/modules/email.php b/modules/email.php index 457157f..6c5d96f 100644 --- a/modules/email.php +++ b/modules/email.php @@ -463,7 +463,7 @@ class EmailModule extends PLModule foreach ($files as $name=>&$upload) { $mymail->addUploadAttachment($upload, $name); } - if (Env::v('nowiki')) { + if (Env::v('wiki') == 'text') { $mymail->setTxtBody(wordwrap($txt, 78, "\n")); } else { $mymail->setWikiBody($txt); @@ -498,6 +498,14 @@ class EmailModule extends PLModule $page->assign('contacts', $contacts); $page->assign('maxsize', ini_get('upload_max_filesize') . 'o'); $page->assign('user', S::user()); + $preferences = XDB::fetchOneAssoc('SELECT from_email, from_format + FROM accounts + WHERE uid = {?}', + S::user()->id()); + if ($preferences['from_email'] == '') { + $preferences['from_email'] = '"' . S::user()->fullName() . '" <' . S::user()->bestEmail() . '>'; + } + $page->assign('preferences', $preferences); } function handler_test($page, $hruid = null) diff --git a/modules/platal.php b/modules/platal.php index 1dee07e..baa18b1 100644 --- a/modules/platal.php +++ b/modules/platal.php @@ -47,6 +47,7 @@ class PlatalModule extends PLModule 'prefs/rss' => $this->make_hook('prefs_rss', AUTH_COOKIE, 'user'), 'prefs/webredirect' => $this->make_hook('webredir', AUTH_PASSWD, 'mail'), 'prefs/skin' => $this->make_hook('skin', AUTH_COOKIE, 'user'), + 'prefs/email' => $this->make_hook('prefs_email', AUTH_COOKIE, 'mail'), // password related thingies 'password' => $this->make_hook('password', AUTH_PASSWD, 'user,groups'), @@ -199,6 +200,47 @@ class PlatalModule extends PLModule } } + function handler_prefs_email($page) + { + $page->changeTpl('platal/email_preferences.tpl'); + + if (Post::has('submit')) { + S::assert_xsrf_token(); + + $from_email = Post::t('from_email'); + $from_format = Post::v('from_format'); + + // Checks email. + $email_regex = '/^[a-z0-9.\-+_\$]+@([\-.+_]?[a-z0-9])+$/i'; + if (!preg_match($email_regex, $from_email)) { + $full_regex = '/^[^<]*<[a-z0-9.\-+_\$]+@([\-.+_]?[a-z0-9])+>$/i'; + if (!preg_match($full_regex, $from_email)) { + $page->trigError("L'adresse email est erronée."); + $error = true; + $page->assign('from_email', $from_email); + $page->assign('from_format', $from_format); + $page->assign('error', true); + return; + } + } + + // Saves data. + XDB::execute('UPDATE accounts + SET from_email = {?}, from_format = {?} + WHERE uid = {?}', + $from_email, ($from_format == 'html' ? 'html' : 'text'), S::user()->id()); + $page->trigSuccess('Données enregistrées.'); + } + + $data = XDB::fetchOneAssoc('SELECT from_email, from_format + FROM accounts + WHERE uid = {?}', + S::user()->id()); + $page->assign('from_email', $data['from_email']); + $page->assign('from_format', $data['from_format']); + $page->assign('error', false); + } + function handler_password($page) { global $globals; diff --git a/templates/emails/send.tpl b/templates/emails/send.tpl index 1434bc5..1524824 100644 --- a/templates/emails/send.tpl +++ b/templates/emails/send.tpl @@ -142,6 +142,15 @@ } } + function toggleWiki() + { + if ($('[name="wiki"]').val() == 'text') { + $('[name="wiki"]').val('wiki'); + } else { + $('[name="wiki"]').val('text'); + } + } + $(window).unload( function() { if (sent) { @@ -180,11 +189,8 @@ de : - + @@ -284,8 +290,12 @@ Sujet : 
Tu peux utiliser des {icon name=information title="Syntaxe wiki"} marqueurs wiki pour formatter ton texte.
- +