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