Add a small tool for ajax wiki preview and use it on email/send and %grp/mail
[platal.git] / templates / emails / send.tpl
1 {**************************************************************************}
2 {*                                                                        *}
3 {*  Copyright (C) 2003-2007 Polytechnique.org                             *}
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
23 <h1>Envoyer un mail</h1>
24
25 <script type="text/javascript">//<![CDATA[
26   {literal}
27   function _selectAll(id) {
28     var list = document.getElementById(id);
29     for (i = 0 ; i < list.length ; i++) {
30       list.options[i].selected = true;
31     }
32   }
33
34   function check(form)
35   {
36     var send = true;
37     _selectAll('to_contacts');
38     _selectAll('cc_contacts');
39     if(form.sujet.value == "" && !confirm("Le sujet du mail est vide, veux-tu continuer ?")) {
40         form.sujet.focus();
41         return false;
42     }
43     if (form.to.value == "" && form.cc.value == ""
44         && document.getElementById('to_contacts').length == 0 && document.getElementById('cc_contacts').length == 0) {
45       if (form.bcc.value == "") {
46         alert("Il faut définir au moins un destinataire au mail");
47         return false;
48       }
49       if (!confirm("Tous les destinataires sont en copie cachée, veux-tu continuer ?")) {
50         form.to.focus();
51         return false;
52       }
53     }
54     return true;
55   }
56
57   function _move(idFrom, idTo) {
58     var from = document.getElementById(idFrom);
59     var to   = document.getElementById(idTo);
60
61     var index = new Array();
62     var j = 0;
63     for (i = 0 ; i < from.length ; i++) {
64       if (from.options[i].selected) {
65         var option = document.createElement('option');
66         option.value = from.options[i].value;
67         option.text  = from.options[i].text;
68         try {
69           to.add(option, null);
70         } catch(ex) {
71           to.add(option);
72         }
73         index[j++] = i;
74       }
75     }
76     for (i = index.length - 1 ; i >= 0 ; i--) {
77       from.remove(index[i]);
78     }
79   }
80
81   function addTo() {
82     _move('contacts', 'to_contacts');
83   }
84
85   function removeTo() {
86     _move('to_contacts', 'contacts');
87   }
88
89   function addCc() {
90     _move('contacts', 'cc_contacts');
91   }
92
93   function removeCc() {
94     _move('cc_contacts', 'contacts');
95   }
96
97   function updateWikiView(box) {
98     if (box.checked) {
99       document.getElementById("preview_bt").style.display = "none";
100       document.getElementById("preview").style.display = "none";
101     } else {
102       document.getElementById("preview_bt").style.display = "";
103     }
104   }
105   {/literal}
106 //]]>
107 </script>
108
109 <form action="emails/send" method="post" enctype="multipart/form-data" onsubmit="return check(this);">
110   <table class="bicol" cellpadding="2" cellspacing="0">
111     <tr> 
112       <th colspan="2">Destinataires</th>
113     </tr>
114     <tr> 
115       <td class="titre">de&nbsp;:</td>
116       <td>
117         <input type='hidden' name='signature' value='1' />
118         <input type='text' name='from' size='60' value='{if $smarty.request.from}
119 {$smarty.request.from}
120 {else}
121 "{$smarty.session.prenom} {$smarty.session.nom}" &lt;{$smarty.session.bestalias}@{#globals.mail.domain#}&gt;
122 {/if}' />
123       </td>
124     </tr>
125     <tr> 
126       <td class="titre">à&nbsp;:</td>
127       <td>
128         <input type='text' name='to' size='60' value="{$smarty.request.to}" />
129       </td>
130     </tr>
131     <tr> 
132       <td class="titre">copie&nbsp;:</td>
133       <td>
134         <input type='text' name='cc' size='60' value="{$smarty.request.cc}" />
135       </td>
136     </tr>
137     <tr> 
138       <td class="titre">copie cachée&nbsp;:</td>
139       <td>
140         <input type='text' name='bcc' size='60' value="{$smarty.request.bcc}" />
141       </td>
142     </tr>
143     <tr class="pair">
144       <td colspan="2" class="smaller">
145         &bull;&nbsp;Les destinataires sont simplement séparés par des virgules<br />
146         &bull;&nbsp;Pense à te mettre en copie cachée du mail pour en avoir une trace
147       </td>
148     </tr>
149     {if $contacts|@count}
150     <tr>
151       <th colspan="2">
152         Destinataires parmi tes contacts
153       </th>
154     </tr>
155     <tr>
156       <td colspan="2" style="padding: 4px">
157         <div style="float: right; width: 40%;">
158           <select id="to_contacts" name="to_contacts[]" multiple="multiple" style="width: 100%; height: 5em">
159           {foreach key=key item=contact from=$contacts}
160           {if in_array($contact.forlife, $smarty.request.to_contacts)}
161           <option value="{$contact.forlife}">
162             {$contact.prenom} {$contact.nom} (X{$contact.promo})
163           </option>
164           {/if}
165           {/foreach}
166           </select><br />
167           <select id="cc_contacts" name="cc_contacts[]" multiple="multiple" style="width: 100%; height: 5em">
168           {foreach key=key item=contact from=$contacts}
169           {if in_array($contact.forlife, $smarty.request.cc_contacts)}
170           <option value="{$contact.forlife}">
171             {$contact.prenom} {$contact.nom} (X{$contact.promo})
172           </option>
173           {/if}
174           {/foreach}
175           </select>
176         </div>
177         <div style="width: 19%; text-align: center; height: 8em; float: right;">
178           <div style="height: 4em">
179               Destinataires<br />
180               <a href="" onclick="addTo(); return false" style="text-decoration: none">&gt;&gt; &gt;&gt;</a><br />
181               <a href="" onclick="removeTo(); return false" style="text-decoration: none">&lt;&lt; &lt;&lt;</a>
182           </div>
183           <div style="height: 4em">
184               En copie<br />
185               <a href="" onclick="addCc(); return false" style="text-decoration: none">&gt;&gt; &gt;&gt;</a><br />
186               <a href="" onclick="removeCc(); return false" style="text-decoration: none">&lt;&lt; &lt;&lt;</a>
187           </div>
188         </div>
189         <div style="float: right; width: 40%">
190           <select id="contacts" name="all_contacts[]" multiple="multiple" style="height: 10em; width: 100%">
191             {foreach item=contact from=$contacts}
192             {if !in_array($contact.forlife, $smarty.request.to_contacts) && !in_array($contact.forlife, $smarty.request.cc_contacts)}
193             <option value="{$contact.forlife}">
194               {$contact.prenom} {$contact.nom} (X{$contact.promo})
195             </option>
196             {/if}
197             {/foreach}
198           </select>
199         </div>
200         {foreach item=contact from=$contacts}
201         <input type="hidden" name="contacts[{$contact.forlife}]" value="{$contact.prenom} {$contact.nom} &lt;{$contact.forlife}@{#globals.mail.domain#}&gt;" />
202         {/foreach}
203       </td>
204     </tr>
205     {/if}
206   </table>
207   <fieldset>
208     <legend>Sujet&nbsp;:&nbsp;<input type='text' name='sujet' size='60' value="{$smarty.request.sujet}" /></legend>
209     <div class="center">
210       Tu peux utiliser des <a href="wiki_help" class="popup3">{icon name=information title="Syntaxe wiki"} marqueurs wiki</a> pour formatter ton texte.<br />
211       <small><input type="checkbox" name="nowiki" value="1" {if $smarty.request.nowiki}checked="checked"{/if} onchange="updateWikiView(this);" />
212       coche cette case pour envoyer le mail en texte brut, sans formattage</small>
213     </div>
214     <div id="preview" style="display: none">
215       <strong>Aperçu du mail :</strong>
216       <div id="mail_preview">
217       </div>
218       <div class="center">
219         <input type="submit" name="submit" value="Envoyer" />
220       </div>
221     </div>
222     <textarea name='contenu' rows="30" cols="75" id="mail_text">
223 {$smarty.request.contenu}
224 {if !$smarty.request.contenu}
225 -- 
226 {$smarty.session.prenom} {$smarty.session.nom}
227 {/if}</textarea>
228     <script type="text/javascript">//<![CDATA[
229       {literal}
230       function removeAttachments()
231       {
232           Ajax.update_html(null, 'emails/send', null);
233           document.getElementById('att_already').style.display = 'none';
234           document.getElementById('att_form').style.display = '';
235       }
236       {/literal}
237     //]]></script>
238     {if $uploaded_f|@count}
239     <div id="att_already">
240       <strong>{icon name=email_attach}&nbsp;Pièce jointe&nbsp;:&nbsp;</strong>
241       {$uploaded_f[0]}
242       <a href="javascript:removeAttachments()">
243         <img src="images/icons/bin_empty.gif" alt="Supprimer" title="Supprimer la pièce jointe" />
244       </a>
245     </div>
246     {/if}
247     <div id="att_form" {if $uploaded_f|@count neq 0}style="display: none"{/if}>
248       <strong>{icon name=email_attach}&nbsp;Ajouter une pièce jointe (max. {$maxsize})&nbsp;:&nbsp;</strong>
249       <input type="file" name="uploaded" />
250     </div>
251     <div class="center">
252       <input type="submit" name="preview" id="preview_bt" value="Aperçu" onclick="previewWiki('mail_text', 'mail_preview', true, 'preview'); return false;" />
253       <input type="submit" name="submit" value="Envoyer" />
254     </div>
255   </fieldset>
256 </form>
257
258
259 {* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}