From 3360c04f67f5c37696d1dad6ed3267a331670e18 Mon Sep 17 00:00:00 2001 From: Florent Bruneau Date: Thu, 20 Sep 2007 08:27:42 +0200 Subject: [PATCH] Close #720: Save not sent mail when leaving the emails/send page and restore it the next time the page is loaded. (Also include small layout improvements); Signed-off-by: Florent Bruneau --- ChangeLog | 1 + modules/email.php | 28 ++++++++++++++++++---- templates/emails/send.tpl | 52 +++++++++++++++++++++++++++++++++++------ upgrade/0.9.15/06_mail_send.sql | 8 +++++++ 4 files changed, 78 insertions(+), 11 deletions(-) create mode 100644 upgrade/0.9.15/06_mail_send.sql diff --git a/ChangeLog b/ChangeLog index 1363407..a540d5b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -38,6 +38,7 @@ Bug/Wish: - #687: Don't lose authentication when editing a long mail -FRU - #688: From name in the sending form -FRU - #703: Fix management of mail adresses containing '+' -ALK + - #720: Save not sent mail at exit -FRU * Lists: - #700: Fix several encoding issues -FRU diff --git a/modules/email.php b/modules/email.php index 9648534..c280f14 100644 --- a/modules/email.php +++ b/modules/email.php @@ -313,8 +313,17 @@ class EmailModule extends PLModule $page->assign('xorg_title','Polytechnique.org - Envoyer un email'); // action si on recoit un formulaire - if (Env::v('submit') == 'Envoyer') - { + if (Post::has('save')) { + unset($_POST['save']); + if (trim(preg_replace('/-- .*/', '', Post::v('contenu'))) != "") { + $_POST['to_contacts'] = explode(';', @$_POST['to_contacts']); + $_POST['cc_contacts'] = explode(';', @$_POST['cc_contacts']); + $data = serialize($_POST); + XDB::execute("REPLACE INTO email_send_save + VALUES ({?}, {?})", S::i('uid'), $data); + } + exit; + } else if (Env::v('submit') == 'Envoyer') { function getEmails($aliases) { if (!is_array($aliases)) { @@ -334,6 +343,9 @@ class EmailModule extends PLModule } } + XDB::execute("DELETE FROM email_send_save + WHERE uid = {?}", S::i('uid')); + $to2 = getEmails(Env::v('to_contacts')); $cc2 = getEmails(Env::v('cc_contacts')); $txt = str_replace('^M', '', Env::v('contenu')); @@ -374,8 +386,16 @@ class EmailModule extends PLModule } } } else { - PlUpload::clear(S::v('forlife'), 'emails.send'); - $_REQUEST['bcc'] = S::v('bestalias').'@'.$globals->mail->domain; + $res = XDB::query("SELECT data + FROM email_send_save + WHERE uid = {?}", S::i('uid')); + if ($res->numRows() == 0) { + PlUpload::clear(S::v('forlife'), 'emails.send'); + $_REQUEST['bcc'] = S::v('bestalias').'@'.$globals->mail->domain; + } else { + $data = unserialize($res->fetchOneCell()); + $_REQUEST = array_merge($_REQUEST, $data); + } } $res = XDB::query( diff --git a/templates/emails/send.tpl b/templates/emails/send.tpl index 0374746..cca3488 100644 --- a/templates/emails/send.tpl +++ b/templates/emails/send.tpl @@ -22,6 +22,7 @@

Envoyer un mail

+{javascript name="jquery"} -
+ @@ -224,12 +255,18 @@ coche cette case pour envoyer le mail en texte brut, sans formattage -
Destinataires