Close #720: Save not sent mail when leaving the emails/send page and restore
[platal.git] / templates / emails / send.tpl
CommitLineData
0337d704 1{**************************************************************************}
2{* *}
5ddeb07c 3{* Copyright (C) 2003-2007 Polytechnique.org *}
0337d704 4{* http://opensource.polytechnique.org/ *}
5{* *}
6{* This program is free software; you can redistribute it and/or modify *}
7{* it under the terms of the GNU General Public License as published by *}
8{* the Free Software Foundation; either version 2 of the License, or *}
9{* (at your option) any later version. *}
10{* *}
11{* This program is distributed in the hope that it will be useful, *}
12{* but WITHOUT ANY WARRANTY; without even the implied warranty of *}
13{* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *}
14{* GNU General Public License for more details. *}
15{* *}
16{* You should have received a copy of the GNU General Public License *}
17{* along with this program; if not, write to the Free Software *}
18{* Foundation, Inc., *}
19{* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *}
20{* *}
21{**************************************************************************}
22
81b5b746 23<h1>Envoyer un mail</h1>
0337d704 24
3360c04f 25{javascript name="jquery"}
0337d704 26<script type="text/javascript">//<![CDATA[
27 {literal}
91a14f73 28 function _selectAll(id) {
29 var list = document.getElementById(id);
30 for (i = 0 ; i < list.length ; i++) {
31 list.options[i].selected = true;
32 }
33 }
34
3360c04f 35 var sent = false;
f3fb8eda 36 function check(form)
37 {
91a14f73 38 _selectAll('to_contacts');
39 _selectAll('cc_contacts');
f3fb8eda 40 if(form.sujet.value == "" && !confirm("Le sujet du mail est vide, veux-tu continuer ?")) {
41 form.sujet.focus();
42 return false;
43 }
44 if (form.to.value == "" && form.cc.value == ""
45 && document.getElementById('to_contacts').length == 0 && document.getElementById('cc_contacts').length == 0) {
46 if (form.bcc.value == "") {
9e92370d 47 alert("Il faut définir au moins un destinataire au mail.");
f3fb8eda 48 return false;
49 }
50 if (!confirm("Tous les destinataires sont en copie cachée, veux-tu continuer ?")) {
51 form.to.focus();
52 return false;
53 }
0337d704 54 }
3360c04f 55 sent = true;
0337d704 56 return true;
57 }
91a14f73 58
0938c545 59 var doAuth = true;
60 function _keepAuth() {
61 doAuth = true;
62 }
63
64 function keepAuth() {
65 if (doAuth) {
66 Ajax.update_html(null, "login", null);
67 doAuth = false;
68 setTimeout("_keepAuth()", 10000);
69 }
70 }
71
91a14f73 72 function _move(idFrom, idTo) {
73 var from = document.getElementById(idFrom);
74 var to = document.getElementById(idTo);
75
76 var index = new Array();
77 var j = 0;
78 for (i = 0 ; i < from.length ; i++) {
79 if (from.options[i].selected) {
80 var option = document.createElement('option');
81 option.value = from.options[i].value;
82 option.text = from.options[i].text;
83 try {
84 to.add(option, null);
85 } catch(ex) {
86 to.add(option);
87 }
88 index[j++] = i;
89 }
90 }
91 for (i = index.length - 1 ; i >= 0 ; i--) {
92 from.remove(index[i]);
93 }
94 }
95
96 function addTo() {
97 _move('contacts', 'to_contacts');
98 }
99
100 function removeTo() {
101 _move('to_contacts', 'contacts');
102 }
103
104 function addCc() {
105 _move('contacts', 'cc_contacts');
106 }
107
108 function removeCc() {
109 _move('cc_contacts', 'contacts');
110 }
fdbeba4f 111
112 function updateWikiView(box) {
113 if (box.checked) {
114 document.getElementById("preview_bt").style.display = "none";
115 document.getElementById("preview").style.display = "none";
3360c04f 116 document.getElementById("preview_pv").style.display = "none";
fdbeba4f 117 } else {
118 document.getElementById("preview_bt").style.display = "";
3360c04f 119 document.getElementById("preview").style.display = "";
fdbeba4f 120 }
121 }
3360c04f
FB
122
123 $(window).unload(
124 function() {
125 if (sent) {
126 return true;
127 }
128 var form = document.forms.form_mail;
129 var toc = "";
130 var ccc = "";
131 for (var i = 0 ; i < form['to_contacts[]'].length ; ++i) {
132 toc += form['to_contacts[]'].options[i].value + ";";
133 }
134 for (var i = 0 ; i < form['cc_contacts[]'].length ; ++i) {
135 ccc += form['cc_contacts[]'].options[i].value + ";";
136 }
137 $.post(platal_baseurl + "emails/send",
138 { save: true,
139 from: form.from.value,
140 to_contacts: toc,
141 cc_contacts: ccc,
142 contenu: form.contenu.value,
143 to: form.to.value,
144 sujet: form.sujet.value,
145 cc: form.cc.value,
146 bcc: form.bcc.value });
147 return true;
148 });
0337d704 149 {/literal}
150//]]>
151</script>
152
3360c04f 153<form action="emails/send" method="post" enctype="multipart/form-data" id="form_mail" onsubmit="return check(this);">
0337d704 154 <table class="bicol" cellpadding="2" cellspacing="0">
155 <tr>
156 <th colspan="2">Destinataires</th>
157 </tr>
158 <tr>
159 <td class="titre">de&nbsp;:</td>
160 <td>
161 <input type='hidden' name='signature' value='1' />
162 <input type='text' name='from' size='60' value='{if $smarty.request.from}
163{$smarty.request.from}
164{else}
e4df055c 165"{$smarty.session.prenom} {$smarty.session.nom_usage|default:$smarty.session.nom}" &lt;{$smarty.session.bestalias}@{#globals.mail.domain#}&gt;
0337d704 166{/if}' />
167 </td>
168 </tr>
169 <tr>
a7de4ef7 170 <td class="titre">à&nbsp;:</td>
0337d704 171 <td>
172 <input type='text' name='to' size='60' value="{$smarty.request.to}" />
173 </td>
174 </tr>
175 <tr>
176 <td class="titre">copie&nbsp;:</td>
177 <td>
178 <input type='text' name='cc' size='60' value="{$smarty.request.cc}" />
179 </td>
180 </tr>
181 <tr>
a7de4ef7 182 <td class="titre">copie cachée&nbsp;:</td>
0337d704 183 <td>
184 <input type='text' name='bcc' size='60' value="{$smarty.request.bcc}" />
185 </td>
186 </tr>
91a14f73 187 <tr class="pair">
188 <td colspan="2" class="smaller">
9e92370d 189 &bull;&nbsp;Les destinataires sont simplement séparés par des virgules.<br />
190 &bull;&nbsp;Pense à te mettre en copie cachée du mail pour en avoir une trace.
0337d704 191 </td>
192 </tr>
91a14f73 193 {if $contacts|@count}
194 <tr>
195 <th colspan="2">
196 Destinataires parmi tes contacts
0337d704 197 </th>
198 </tr>
91a14f73 199 <tr>
200 <td colspan="2" style="padding: 4px">
201 <div style="float: right; width: 40%;">
202 <select id="to_contacts" name="to_contacts[]" multiple="multiple" style="width: 100%; height: 5em">
203 {foreach key=key item=contact from=$contacts}
204 {if in_array($contact.forlife, $smarty.request.to_contacts)}
205 <option value="{$contact.forlife}">
206 {$contact.prenom} {$contact.nom} (X{$contact.promo})
207 </option>
208 {/if}
209 {/foreach}
210 </select><br />
211 <select id="cc_contacts" name="cc_contacts[]" multiple="multiple" style="width: 100%; height: 5em">
212 {foreach key=key item=contact from=$contacts}
213 {if in_array($contact.forlife, $smarty.request.cc_contacts)}
214 <option value="{$contact.forlife}">
215 {$contact.prenom} {$contact.nom} (X{$contact.promo})
216 </option>
217 {/if}
218 {/foreach}
219 </select>
220 </div>
221 <div style="width: 19%; text-align: center; height: 8em; float: right;">
222 <div style="height: 4em">
223 Destinataires<br />
db0873ff 224 <a href="" onclick="addTo(); return false" style="text-decoration: none">&gt;&gt; &gt;&gt;</a><br />
225 <a href="" onclick="removeTo(); return false" style="text-decoration: none">&lt;&lt; &lt;&lt;</a>
91a14f73 226 </div>
227 <div style="height: 4em">
228 En copie<br />
db0873ff 229 <a href="" onclick="addCc(); return false" style="text-decoration: none">&gt;&gt; &gt;&gt;</a><br />
230 <a href="" onclick="removeCc(); return false" style="text-decoration: none">&lt;&lt; &lt;&lt;</a>
91a14f73 231 </div>
232 </div>
233 <div style="float: right; width: 40%">
234 <select id="contacts" name="all_contacts[]" multiple="multiple" style="height: 10em; width: 100%">
235 {foreach item=contact from=$contacts}
236 {if !in_array($contact.forlife, $smarty.request.to_contacts) && !in_array($contact.forlife, $smarty.request.cc_contacts)}
237 <option value="{$contact.forlife}">
238 {$contact.prenom} {$contact.nom} (X{$contact.promo})
239 </option>
240 {/if}
241 {/foreach}
242 </select>
243 </div>
244 {foreach item=contact from=$contacts}
245 <input type="hidden" name="contacts[{$contact.forlife}]" value="{$contact.prenom} {$contact.nom} &lt;{$contact.forlife}@{#globals.mail.domain#}&gt;" />
246 {/foreach}
247 </td>
248 </tr>
249 {/if}
250 </table>
91a14f73 251 <fieldset>
252 <legend>Sujet&nbsp;:&nbsp;<input type='text' name='sujet' size='60' value="{$smarty.request.sujet}" /></legend>
5b21237d 253 <div class="center">
72b2f8bb 254 Tu peux utiliser des <a href="wiki_help" class="popup3">{icon name=information title="Syntaxe wiki"} marqueurs wiki</a> pour formatter ton texte.<br />
fdbeba4f 255 <small><input type="checkbox" name="nowiki" value="1" {if $smarty.request.nowiki}checked="checked"{/if} onchange="updateWikiView(this);" />
5b21237d 256 coche cette case pour envoyer le mail en texte brut, sans formattage</small>
257 </div>
3360c04f
FB
258 <div id="preview">
259 <div id="preview_pv" style="display: none">
260 <strong>Aperçu du mail :</strong>
261 <div id="mail_preview">
262 </div>
263 <div class="center">
264 <input type="submit" name="submit" value="Envoyer" />
265 </div>
fdbeba4f 266 </div>
267 <div class="center">
3360c04f
FB
268 <input type="submit" name="preview" id="preview_bt_top" value="Aperçu"
269 onclick="previewWiki('mail_text', 'mail_preview', true, 'preview_pv'); return false;" />
fdbeba4f 270 </div>
271 </div>
0938c545 272 <textarea name='contenu' rows="30" cols="75" id="mail_text" onkeyup="keepAuth()">
0337d704 273{$smarty.request.contenu}
274{if !$smarty.request.contenu}
275--
276{$smarty.session.prenom} {$smarty.session.nom}
277{/if}</textarea>
da419622 278 <script type="text/javascript">//<![CDATA[
279 {literal}
280 function removeAttachments()
281 {
282 Ajax.update_html(null, 'emails/send', null);
283 document.getElementById('att_already').style.display = 'none';
284 document.getElementById('att_form').style.display = '';
285 }
286 {/literal}
287 //]]></script>
288 {if $uploaded_f|@count}
289 <div id="att_already">
290 <strong>{icon name=email_attach}&nbsp;Pièce jointe&nbsp;:&nbsp;</strong>
291 {$uploaded_f[0]}
292 <a href="javascript:removeAttachments()">
5124d583 293 {icon name=cross alt="Supprimer" title="Supprimer la pièce jointe"}
da419622 294 </a>
295 </div>
296 {/if}
297 <div id="att_form" {if $uploaded_f|@count neq 0}style="display: none"{/if}>
f3fb8eda 298 <strong>{icon name=email_attach}&nbsp;Ajouter une pièce jointe (max. {$maxsize})&nbsp;:&nbsp;</strong>
91a14f73 299 <input type="file" name="uploaded" />
300 </div>
301 <div class="center">
3360c04f
FB
302 <input type="submit" name="preview" id="preview_bt" value="Aperçu"
303 onclick="previewWiki('mail_text', 'mail_preview', true, 'preview_pv'); return false;" />
91a14f73 304 <input type="submit" name="submit" value="Envoyer" />
305 </div>
306 </fieldset>
0337d704 307</form>
308
309
a7de4ef7 310{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}