Improves my previous commit by saving the mail during edition
[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
440a32c3
FB
59 function saveMessage() {
60 var form = document.forms.form_mail;
61 var toc = "";
62 var ccc = "";
63 for (var i = 0 ; i < form['to_contacts[]'].length ; ++i) {
64 toc += form['to_contacts[]'].options[i].value + ";";
65 }
66 for (var i = 0 ; i < form['cc_contacts[]'].length ; ++i) {
67 ccc += form['cc_contacts[]'].options[i].value + ";";
68 }
69 $.post(platal_baseurl + "emails/send",
70 { save: true,
71 from: form.from.value,
72 to_contacts: toc,
73 cc_contacts: ccc,
74 contenu: form.contenu.value,
75 to: form.to.value,
76 sujet: form.sujet.value,
77 cc: form.cc.value,
78 bcc: form.bcc.value });
79 }
80
0938c545 81 var doAuth = true;
82 function _keepAuth() {
83 doAuth = true;
84 }
85
86 function keepAuth() {
87 if (doAuth) {
440a32c3 88 saveMessage();
0938c545 89 doAuth = false;
90 setTimeout("_keepAuth()", 10000);
91 }
92 }
93
91a14f73 94 function _move(idFrom, idTo) {
95 var from = document.getElementById(idFrom);
96 var to = document.getElementById(idTo);
97
98 var index = new Array();
99 var j = 0;
100 for (i = 0 ; i < from.length ; i++) {
101 if (from.options[i].selected) {
102 var option = document.createElement('option');
103 option.value = from.options[i].value;
104 option.text = from.options[i].text;
105 try {
106 to.add(option, null);
107 } catch(ex) {
108 to.add(option);
109 }
110 index[j++] = i;
111 }
112 }
113 for (i = index.length - 1 ; i >= 0 ; i--) {
114 from.remove(index[i]);
115 }
116 }
117
118 function addTo() {
119 _move('contacts', 'to_contacts');
120 }
121
122 function removeTo() {
123 _move('to_contacts', 'contacts');
124 }
125
126 function addCc() {
127 _move('contacts', 'cc_contacts');
128 }
129
130 function removeCc() {
131 _move('cc_contacts', 'contacts');
132 }
fdbeba4f 133
134 function updateWikiView(box) {
135 if (box.checked) {
136 document.getElementById("preview_bt").style.display = "none";
137 document.getElementById("preview").style.display = "none";
3360c04f 138 document.getElementById("preview_pv").style.display = "none";
fdbeba4f 139 } else {
140 document.getElementById("preview_bt").style.display = "";
3360c04f 141 document.getElementById("preview").style.display = "";
fdbeba4f 142 }
143 }
3360c04f
FB
144
145 $(window).unload(
146 function() {
147 if (sent) {
148 return true;
149 }
440a32c3 150 saveMessage();
3360c04f
FB
151 return true;
152 });
0337d704 153 {/literal}
154//]]>
155</script>
156
3360c04f 157<form action="emails/send" method="post" enctype="multipart/form-data" id="form_mail" onsubmit="return check(this);">
0337d704 158 <table class="bicol" cellpadding="2" cellspacing="0">
159 <tr>
160 <th colspan="2">Destinataires</th>
161 </tr>
162 <tr>
163 <td class="titre">de&nbsp;:</td>
164 <td>
165 <input type='hidden' name='signature' value='1' />
166 <input type='text' name='from' size='60' value='{if $smarty.request.from}
167{$smarty.request.from}
168{else}
e4df055c 169"{$smarty.session.prenom} {$smarty.session.nom_usage|default:$smarty.session.nom}" &lt;{$smarty.session.bestalias}@{#globals.mail.domain#}&gt;
0337d704 170{/if}' />
171 </td>
172 </tr>
173 <tr>
a7de4ef7 174 <td class="titre">à&nbsp;:</td>
0337d704 175 <td>
176 <input type='text' name='to' size='60' value="{$smarty.request.to}" />
177 </td>
178 </tr>
179 <tr>
180 <td class="titre">copie&nbsp;:</td>
181 <td>
182 <input type='text' name='cc' size='60' value="{$smarty.request.cc}" />
183 </td>
184 </tr>
185 <tr>
a7de4ef7 186 <td class="titre">copie cachée&nbsp;:</td>
0337d704 187 <td>
188 <input type='text' name='bcc' size='60' value="{$smarty.request.bcc}" />
189 </td>
190 </tr>
91a14f73 191 <tr class="pair">
192 <td colspan="2" class="smaller">
9e92370d 193 &bull;&nbsp;Les destinataires sont simplement séparés par des virgules.<br />
194 &bull;&nbsp;Pense à te mettre en copie cachée du mail pour en avoir une trace.
0337d704 195 </td>
196 </tr>
91a14f73 197 {if $contacts|@count}
198 <tr>
199 <th colspan="2">
200 Destinataires parmi tes contacts
0337d704 201 </th>
202 </tr>
91a14f73 203 <tr>
204 <td colspan="2" style="padding: 4px">
205 <div style="float: right; width: 40%;">
206 <select id="to_contacts" name="to_contacts[]" multiple="multiple" style="width: 100%; height: 5em">
207 {foreach key=key item=contact from=$contacts}
208 {if in_array($contact.forlife, $smarty.request.to_contacts)}
209 <option value="{$contact.forlife}">
210 {$contact.prenom} {$contact.nom} (X{$contact.promo})
211 </option>
212 {/if}
213 {/foreach}
214 </select><br />
215 <select id="cc_contacts" name="cc_contacts[]" multiple="multiple" style="width: 100%; height: 5em">
216 {foreach key=key item=contact from=$contacts}
217 {if in_array($contact.forlife, $smarty.request.cc_contacts)}
218 <option value="{$contact.forlife}">
219 {$contact.prenom} {$contact.nom} (X{$contact.promo})
220 </option>
221 {/if}
222 {/foreach}
223 </select>
224 </div>
225 <div style="width: 19%; text-align: center; height: 8em; float: right;">
226 <div style="height: 4em">
227 Destinataires<br />
db0873ff 228 <a href="" onclick="addTo(); return false" style="text-decoration: none">&gt;&gt; &gt;&gt;</a><br />
229 <a href="" onclick="removeTo(); return false" style="text-decoration: none">&lt;&lt; &lt;&lt;</a>
91a14f73 230 </div>
231 <div style="height: 4em">
232 En copie<br />
db0873ff 233 <a href="" onclick="addCc(); return false" style="text-decoration: none">&gt;&gt; &gt;&gt;</a><br />
234 <a href="" onclick="removeCc(); return false" style="text-decoration: none">&lt;&lt; &lt;&lt;</a>
91a14f73 235 </div>
236 </div>
237 <div style="float: right; width: 40%">
238 <select id="contacts" name="all_contacts[]" multiple="multiple" style="height: 10em; width: 100%">
239 {foreach item=contact from=$contacts}
240 {if !in_array($contact.forlife, $smarty.request.to_contacts) && !in_array($contact.forlife, $smarty.request.cc_contacts)}
241 <option value="{$contact.forlife}">
242 {$contact.prenom} {$contact.nom} (X{$contact.promo})
243 </option>
244 {/if}
245 {/foreach}
246 </select>
247 </div>
248 {foreach item=contact from=$contacts}
249 <input type="hidden" name="contacts[{$contact.forlife}]" value="{$contact.prenom} {$contact.nom} &lt;{$contact.forlife}@{#globals.mail.domain#}&gt;" />
250 {/foreach}
251 </td>
252 </tr>
253 {/if}
254 </table>
91a14f73 255 <fieldset>
256 <legend>Sujet&nbsp;:&nbsp;<input type='text' name='sujet' size='60' value="{$smarty.request.sujet}" /></legend>
5b21237d 257 <div class="center">
72b2f8bb 258 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 259 <small><input type="checkbox" name="nowiki" value="1" {if $smarty.request.nowiki}checked="checked"{/if} onchange="updateWikiView(this);" />
5b21237d 260 coche cette case pour envoyer le mail en texte brut, sans formattage</small>
261 </div>
3360c04f
FB
262 <div id="preview">
263 <div id="preview_pv" style="display: none">
264 <strong>Aperçu du mail :</strong>
265 <div id="mail_preview">
266 </div>
267 <div class="center">
268 <input type="submit" name="submit" value="Envoyer" />
269 </div>
fdbeba4f 270 </div>
271 <div class="center">
3360c04f
FB
272 <input type="submit" name="preview" id="preview_bt_top" value="Aperçu"
273 onclick="previewWiki('mail_text', 'mail_preview', true, 'preview_pv'); return false;" />
fdbeba4f 274 </div>
275 </div>
0938c545 276 <textarea name='contenu' rows="30" cols="75" id="mail_text" onkeyup="keepAuth()">
0337d704 277{$smarty.request.contenu}
278{if !$smarty.request.contenu}
279--
280{$smarty.session.prenom} {$smarty.session.nom}
281{/if}</textarea>
da419622 282 <script type="text/javascript">//<![CDATA[
283 {literal}
284 function removeAttachments()
285 {
286 Ajax.update_html(null, 'emails/send', null);
287 document.getElementById('att_already').style.display = 'none';
288 document.getElementById('att_form').style.display = '';
289 }
290 {/literal}
291 //]]></script>
292 {if $uploaded_f|@count}
293 <div id="att_already">
294 <strong>{icon name=email_attach}&nbsp;Pièce jointe&nbsp;:&nbsp;</strong>
295 {$uploaded_f[0]}
296 <a href="javascript:removeAttachments()">
5124d583 297 {icon name=cross alt="Supprimer" title="Supprimer la pièce jointe"}
da419622 298 </a>
299 </div>
300 {/if}
301 <div id="att_form" {if $uploaded_f|@count neq 0}style="display: none"{/if}>
f3fb8eda 302 <strong>{icon name=email_attach}&nbsp;Ajouter une pièce jointe (max. {$maxsize})&nbsp;:&nbsp;</strong>
91a14f73 303 <input type="file" name="uploaded" />
304 </div>
305 <div class="center">
3360c04f
FB
306 <input type="submit" name="preview" id="preview_bt" value="Aperçu"
307 onclick="previewWiki('mail_text', 'mail_preview', true, 'preview_pv'); return false;" />
91a14f73 308 <input type="submit" name="submit" value="Envoyer" />
309 </div>
310 </fieldset>
0337d704 311</form>
312
313
a7de4ef7 314{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}