changelog entry.
[platal.git] / htdocs / emails / send.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2006 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 require_once("xorg.inc.php");
23 new_skinned_page('emails/send.tpl',AUTH_MDP);
24 $page->assign('xorg_title','Polytechnique.org - Envoyer un email');
25
26 // action si on recoit un formulaire
27 if (Env::get('submit') == 'Envoyer')
28 {
29 $to2 = join(', ', Env::getMixed('contacts', Array()));
30 $txt = str_replace('^M', '', Env::get('contenu'));
31 $to = Env::get('to');
32 $subj = Env::get('sujet');
33 $from = Env::get('from');
34 $cc = Env::get('cc');
35 $bcc = Env::get('bcc');
36
37 if (empty($to) && empty($cc) && empty($to2)) {
38 $page->trig("Indique au moins un destinataire.");
39 } else {
40 require_once("diogenes/diogenes.hermes.inc.php");
41
42 $mymail = new HermesMailer();
43 $mymail->setFrom($from);
44 $mymail->setSubject($subj);
45 if (!empty($to)) { $mymail->addTo($to); }
46 if (!empty($cc)) { $mymail->addCc($cc); }
47 if (!empty($bcc)) { $mymail->addBcc($bcc); }
48 if (!empty($to2)) { $mymail->addTo($to2); }
49 $mymail->setTxtBody(wordwrap($txt,72,"\n"));
50 if ($mymail->send()) {
51 $page->trig("Ton mail a bien été envoyé.");
52 $_REQUEST = array('bcc' => Session::get('bestalias').'@'.$globals->mail->domain);
53 } else {
54 $page->trig("Erreur lors de l'envoi du courriel, réessaye.");
55 }
56 }
57 } else {
58 $_REQUEST['bcc'] = Session::get('bestalias').'@'.$globals->mail->domain;
59 }
60
61 $res = $globals->xdb->query(
62 "SELECT u.prenom, u.nom, u.promo, a.alias as forlife
63 FROM auth_user_md5 AS u
64 INNER JOIN contacts AS c ON (u.user_id = c.contact)
65 INNER JOIN aliases AS a ON (u.user_id=a.id AND FIND_IN_SET('bestalias',a.flags))
66 WHERE c.uid = {?}
67 ORDER BY u.nom, u.prenom", Session::getInt('uid'));
68 $page->assign('contacts', $res->fetchAllAssoc());
69
70 $page->run();
71 ?>