| 1 | {**************************************************************************} |
| 2 | {* *} |
| 3 | {* Copyright (C) 2003-2010 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 email</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 | var sent = false; |
| 35 | function check(form) |
| 36 | { |
| 37 | _selectAll('to_contacts'); |
| 38 | _selectAll('cc_contacts'); |
| 39 | if(form.sujet.value == "" && !confirm("Le sujet de l'email 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."); |
| 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 | sent = true; |
| 55 | return true; |
| 56 | } |
| 57 | |
| 58 | function saveMessage() { |
| 59 | var form = document.forms.form_mail; |
| 60 | var toc = ""; |
| 61 | var ccc = ""; |
| 62 | for (var i = 0 ; i < form['to_contacts[]'].length ; ++i) { |
| 63 | toc += form['to_contacts[]'].options[i].value + ";"; |
| 64 | } |
| 65 | for (var i = 0 ; i < form['cc_contacts[]'].length ; ++i) { |
| 66 | ccc += form['cc_contacts[]'].options[i].value + ";"; |
| 67 | } |
| 68 | $.post(platal_baseurl + "emails/send", |
| 69 | { save: true, |
| 70 | token: '{xsrf_token}', |
| 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 | |
| 81 | var doAuth = true; |
| 82 | function _keepAuth() { |
| 83 | doAuth = true; |
| 84 | } |
| 85 | |
| 86 | function keepAuth() { |
| 87 | if (doAuth) { |
| 88 | saveMessage(); |
| 89 | doAuth = false; |
| 90 | setTimeout("_keepAuth()", 10000); |
| 91 | } |
| 92 | } |
| 93 | |
| 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 | } |
| 133 | |
| 134 | function updateWikiView(box) { |
| 135 | if (box.checked) { |
| 136 | document.getElementById("preview_bt").style.display = "none"; |
| 137 | document.getElementById("preview").style.display = "none"; |
| 138 | document.getElementById("preview_pv").style.display = "none"; |
| 139 | } else { |
| 140 | document.getElementById("preview_bt").style.display = ""; |
| 141 | document.getElementById("preview").style.display = ""; |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | $(window).unload( |
| 146 | function() { |
| 147 | if (sent) { |
| 148 | return true; |
| 149 | } |
| 150 | saveMessage(); |
| 151 | return true; |
| 152 | }); |
| 153 | $(document).ready( |
| 154 | function() { |
| 155 | // Remove empty options in select (they were added only for HTML |
| 156 | // compatibility). |
| 157 | $('#to_contacts option[value=""]').remove(); |
| 158 | $('#cc_contacts option[value=""]').remove(); |
| 159 | }); |
| 160 | |
| 161 | $(document).ready(function() { |
| 162 | $("[name='to']").focus(); |
| 163 | }); |
| 164 | {/literal} |
| 165 | //]]> |
| 166 | </script> |
| 167 | |
| 168 | <p> |
| 169 | <small>{icon name=information title="Envoi d'email"} Pour envoyer un email, tu peux soit le faire depuis l'interface |
| 170 | ci-dessous, soit utiliser <a href="Xorg/SMTPSecurise">notre serveur d'envoi SMTP</a>.</small> |
| 171 | </p> |
| 172 | |
| 173 | <form action="emails/send" method="post" enctype="multipart/form-data" id="form_mail" onsubmit="return check(this);"> |
| 174 | {xsrf_token_field} |
| 175 | <table class="bicol" cellpadding="2" cellspacing="0"> |
| 176 | <tr> |
| 177 | <th colspan="2">Destinataires</th> |
| 178 | </tr> |
| 179 | <tr> |
| 180 | <td class="titre">de :</td> |
| 181 | <td> |
| 182 | <input type='hidden' name='signature' value='1' /> |
| 183 | <input type='text' name='from' size='60' value='{if $smarty.request.from} |
| 184 | {$smarty.request.from} |
| 185 | {else} |
| 186 | "{$user->fullName()}" <{$user->bestEmail()}> |
| 187 | {/if}' /> |
| 188 | </td> |
| 189 | </tr> |
| 190 | <tr> |
| 191 | <td class="titre">à :</td> |
| 192 | <td> |
| 193 | <input type='text' name='to' size='60' value="{$smarty.request.to}" /> |
| 194 | </td> |
| 195 | </tr> |
| 196 | <tr> |
| 197 | <td class="titre">copie :</td> |
| 198 | <td> |
| 199 | <input type='text' name='cc' size='60' value="{$smarty.request.cc}" /> |
| 200 | </td> |
| 201 | </tr> |
| 202 | <tr> |
| 203 | <td class="titre">copie cachée :</td> |
| 204 | <td> |
| 205 | <input type='text' name='bcc' size='60' value="{$smarty.request.bcc}" /> |
| 206 | </td> |
| 207 | </tr> |
| 208 | <tr class="pair"> |
| 209 | <td colspan="2" class="smaller"> |
| 210 | • Les destinataires sont simplement séparés par des virgules.<br /> |
| 211 | • Pense à te mettre en copie cachée de l'email pour en avoir une trace. |
| 212 | </td> |
| 213 | </tr> |
| 214 | {if $contacts|@count} |
| 215 | <tr> |
| 216 | <th colspan="2"> |
| 217 | Destinataires parmi tes contacts |
| 218 | </th> |
| 219 | </tr> |
| 220 | <tr> |
| 221 | <td colspan="2" style="padding: 4px"> |
| 222 | <div style="float: right; width: 40%;"> |
| 223 | <select id="to_contacts" name="to_contacts[]" multiple="multiple" style="width: 100%; height: 5em"> |
| 224 | {foreach key=key item=contact from=$contacts} |
| 225 | {if t($smarty.request.to_contacts) && in_array($contact->hrpid,$smarty.request.to_contacts)} |
| 226 | <option value="{$contact->hrpid}"> |
| 227 | {$contact->full_name} |
| 228 | </option> |
| 229 | {assign var="to_not_empty" value="true"} |
| 230 | {/if} |
| 231 | {/foreach} |
| 232 | {if !$to_not_empty} |
| 233 | {* HTML compatibility *} |
| 234 | <option value=""> </option> |
| 235 | {/if} |
| 236 | </select> |
| 237 | {if !$to_not_empty} |
| 238 | {/if} |
| 239 | <br /> |
| 240 | <select id="cc_contacts" name="cc_contacts[]" multiple="multiple" style="width: 100%; height: 5em"> |
| 241 | {foreach key=key item=contact from=$contacts} |
| 242 | {if t($smarty.request.cc_contacts) && in_array($contact->hrpid,$smarty.request.cc_contacts)} |
| 243 | <option value="{$contact->hrpid}"> |
| 244 | {$contact->full_name} |
| 245 | </option> |
| 246 | {assign var="cc_not_empty" value="true"} |
| 247 | {/if} |
| 248 | {/foreach} |
| 249 | {if !$cc_not_empty} |
| 250 | {* HTML compatibility *} |
| 251 | <option value=""> </option> |
| 252 | {/if} |
| 253 | </select> |
| 254 | </div> |
| 255 | <div style="width: 19%; text-align: center; height: 8em; float: right;"> |
| 256 | <div style="height: 4em"> |
| 257 | Destinataires<br /> |
| 258 | <a href="emails/send/addTo" onclick="addTo(); return false" style="text-decoration: none">>> >></a><br /> |
| 259 | <a href="emails/send/removeTo" onclick="removeTo(); return false" style="text-decoration: none"><< <<</a> |
| 260 | </div> |
| 261 | <div style="height: 4em"> |
| 262 | En copie<br /> |
| 263 | <a href="emails/send/addCc" onclick="addCc(); return false" style="text-decoration: none">>> >></a><br /> |
| 264 | <a href="emails/send/removeCc" onclick="removeCc(); return false" style="text-decoration: none"><< <<</a> |
| 265 | </div> |
| 266 | </div> |
| 267 | <div style="float: right; width: 40%"> |
| 268 | <select id="contacts" name="all_contacts[]" multiple="multiple" style="height: 10em; width: 100%"> |
| 269 | {foreach item=contact from=$contacts} |
| 270 | {if !(isset($smarty.request.to_contacts|smarty:nodefaults) && isset($smarty.request.cc_contacts|smarty:nodefaults)) || |
| 271 | (!in_array($contact->hrpid,$smarty.request.to_contacts) && !in_array($contact->hrpid,$smarty.request.cc_contacts))} |
| 272 | <option value="{$contact->hrpid}"> |
| 273 | {$contact->full_name} |
| 274 | </option> |
| 275 | {/if} |
| 276 | {/foreach} |
| 277 | </select> |
| 278 | </div> |
| 279 | </td> |
| 280 | </tr> |
| 281 | {/if} |
| 282 | </table> |
| 283 | <fieldset> |
| 284 | <legend>Sujet : <input type='text' name='sujet' size='60' value="{$smarty.request.sujet}" /></legend> |
| 285 | <div class="center"> |
| 286 | Tu peux utiliser des <a href="wiki_help" class="popup3">{icon name=information title="Syntaxe wiki"} marqueurs wiki</a> pour formatter ton texte.<br /> |
| 287 | <small><label><input type="checkbox" name="nowiki" value="1" {if $smarty.request.nowiki}checked="checked"{/if} onchange="updateWikiView(this);" /> |
| 288 | coche cette case pour envoyer l'email en texte brut, sans formattage</label></small> |
| 289 | </div> |
| 290 | <div id="preview"> |
| 291 | <div id="preview_pv" style="display: none"> |
| 292 | <strong>Aperçu de l'email :</strong> |
| 293 | <div id="mail_preview"> |
| 294 | </div> |
| 295 | <div class="center"> |
| 296 | <input type="submit" name="submit" value="Envoyer" /> |
| 297 | </div> |
| 298 | </div> |
| 299 | <div class="center"> |
| 300 | <input type="submit" name="preview" id="preview_bt_top" value="Aperçu" |
| 301 | onclick="previewWiki('mail_text', 'mail_preview', true, 'preview_pv'); return false;" /> |
| 302 | </div> |
| 303 | </div> |
| 304 | <textarea name='contenu' rows="30" cols="75" id="mail_text" onkeyup="keepAuth()"> |
| 305 | {$smarty.request.contenu} |
| 306 | {if !$smarty.request.contenu} |
| 307 | -- |
| 308 | {$smarty.session.user->full_name} |
| 309 | {/if}</textarea> |
| 310 | <script type="text/javascript">//<![CDATA[ |
| 311 | {literal} |
| 312 | function removeAttachments() |
| 313 | { |
| 314 | Ajax.update_html(null, 'emails/send', null); |
| 315 | document.getElementById('att_already').style.display = 'none'; |
| 316 | document.getElementById('att_form').style.display = ''; |
| 317 | } |
| 318 | {/literal} |
| 319 | //]]></script> |
| 320 | {if $uploaded_f|@count} |
| 321 | <div id="att_already"> |
| 322 | <strong>{icon name=email_attach} Pièce jointe : </strong> |
| 323 | {$uploaded_f[0]} |
| 324 | <a href="javascript:removeAttachments()"> |
| 325 | {icon name=cross alt="Supprimer" title="Supprimer la pièce jointe"} |
| 326 | </a> |
| 327 | </div> |
| 328 | {/if} |
| 329 | <div id="att_form" {if $uploaded_f|@count neq 0}style="display: none"{/if}> |
| 330 | <strong>{icon name=email_attach} Ajouter une pièce jointe (max. {$maxsize}) : </strong> |
| 331 | <input type="file" name="uploaded" /> |
| 332 | </div> |
| 333 | <div class="center"> |
| 334 | <input type="submit" name="preview" id="preview_bt" value="Aperçu" |
| 335 | onclick="previewWiki('mail_text', 'mail_preview', true, 'preview_pv'); return false;" /> |
| 336 | <input type="submit" name="submit" value="Envoyer" /> |
| 337 | </div> |
| 338 | </fieldset> |
| 339 | </form> |
| 340 | |
| 341 | |
| 342 | {* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *} |