mail.php
authorPierre Habouzit (MadCoder <pierre.habouzit@m4x.org>
Thu, 28 Apr 2005 14:59:56 +0000 (14:59 +0000)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Thu, 26 Jun 2008 21:28:48 +0000 (23:28 +0200)
git-archimport-id: opensource@polytechnique.org--2005/platal--mainline--0.9--patch-607

htdocs.net/groupe/mail.php [new file with mode: 0644]
include/lists.inc.php
include/xnet/mail.inc.php [new file with mode: 0644]
templates/xnet/groupe/alias-admin.tpl
templates/xnet/groupe/mail.tpl [new file with mode: 0644]

diff --git a/htdocs.net/groupe/mail.php b/htdocs.net/groupe/mail.php
new file mode 100644 (file)
index 0000000..f81937a
--- /dev/null
@@ -0,0 +1,28 @@
+<?php
+    require_once 'xnet.inc.php';
+    require_once 'lists.inc.php';
+
+    new_groupadmin_page('xnet/groupe/mail.tpl');
+    $client =& lists_xmlrpc(Session::getInt('uid'), Session::get('password'), $globals->asso('mail_domain'));
+    $page->assign('listes', $client->get_lists());
+
+    $alias = $globals->xdb->query("SELECT alias FROM virtual WHERE alias LIKE {?} AND type='user' ORDER BY alias", '%@'.$globals->asso("mail_domain"));
+    $page->assign('alias', $alias->fetchColumn());
+
+    if (Post::has('send')) {
+        $from  = Post::get('from');
+        $sujet = Post::get('sujet');
+        $body  = Post::get('body');
+
+        $mls = array_keys(Env::getMixed('ml', array()));
+        $als = array_keys(Env::getMixed('al', array()));
+
+        require_once 'xnet/mail.inc.php';
+        $tos = get_all_redirects(Post::has('membres'), $mls, $als, $client);
+        send_xnet_mails($from, $sujet, $body, $tos);
+        $page->kill("Mail envoyé !");
+        $page->assign('sent', true);
+    }
+
+    $page->run();
+?>
index 8582278..0df70b2 100644 (file)
@@ -55,16 +55,16 @@ function list_sort_owners(&$members, $tri_promo = true) {
                 $key = $tri_promo ? $promo : strtoupper($nom{0});
                 $membres[$key][$nom.$m] = Array('n' => "$prenom $nom", 'l' => $m);
             } else {
-                $res = $globals->xdb->query('SELECT prenom, nom FROM groupex.membres WHERE email={?}', $mem);
-                if (list($prenom, $nom) = $res->fetchOneRow()) {
-                    $key = $tri_promo ? 0 : strtoupper($nom{0});
-                    $membres[$key][$nom.$m] = Array('n' => "$prenom $nom", 'l' => $m);
-                } else {
-                    $membres[0][] = Array('l' => $mem);
-                }
+                $membres[0][] = Array('l' => $mem);
             }
         } else {
-            $membres[0][] = Array('l' => $mem);
+            $res = $globals->xdb->query('SELECT prenom, nom FROM groupex.membres WHERE email={?}', $mem);
+            if (list($prenom, $nom) = $res->fetchOneRow()) {
+                $key = $tri_promo ? 0 : strtoupper($nom{0});
+                $membres[$key][$nom.$m] = Array('n' => "$prenom $nom", 'l' => $m);
+            } else {
+                $membres[0][] = Array('l' => $mem);
+            }
         }
     }
     
diff --git a/include/xnet/mail.inc.php b/include/xnet/mail.inc.php
new file mode 100644 (file)
index 0000000..328b959
--- /dev/null
@@ -0,0 +1,115 @@
+<?php
+/***************************************************************************
+ *  Copyright (C) 2003-2004 Polytechnique.org                              *
+ *  http://opensource.polytechnique.org/                                   *
+ *                                                                         *
+ *  This program is free software; you can redistribute it and/or modify   *
+ *  it under the terms of the GNU General Public License as published by   *
+ *  the Free Software Foundation; either version 2 of the License, or      *
+ *  (at your option) any later version.                                    *
+ *                                                                         *
+ *  This program is distributed in the hope that it will be useful,        *
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
+ *  GNU General Public License for more details.                           *
+ *                                                                         *
+ *  You should have received a copy of the GNU General Public License      *
+ *  along with this program; if not, write to the Free Software            *
+ *  Foundation, Inc.,                                                      *
+ *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
+ ***************************************************************************/
+
+require_once 'diogenes/diogenes.hermes.inc.php';
+
+// {{{ get_all_redirects
+
+function get_all_redirects($membres, $mls, $alias, &$client)
+{
+    global $globals;
+    
+    $tos = array();
+    
+    if ($membres) {
+        $res = $globals->xdb->query(
+                    'SELECT  IF(u.nom, u.nom, m.nom) AS nom,
+                             IF(u.prenom, u.prenom, m.prenom) AS prenom,
+                             IF(m.email, m.email, CONCAT(a.alias, "@polytechnique.org")) as email,
+                             FIND_IN_SET("femme", u.flags) AS sexe
+                       FROM  groupex.membres AS m
+                  LEFT JOIN  auth_user_md5   AS u ON (m.uid=u.user_id AND m.uid<50000)
+                 INNER JOIN  aliases         AS a ON (a.id=u.user_id and a.type="a_vie")
+                      WHERE  asso_id = {?}', $globals->asso('id'));
+        $tos = $res->fetchAllAssoc();
+    }
+
+    foreach ($mls as $ml) {
+        if (list(,$members) = $client->get_members($ml)) {
+            foreach ($members as $mem) {
+                list($m, $dom) = split('@',$mem[1]);
+                if ($dom == $globals->mail->domain || $dom == $globals->mail->domain2) {
+                    $res = $globals->xdb->query('SELECT  prenom, nom, FIND_IN_SET("femme", u.flags) AS sexe
+                                                   FROM  auth_user_md5 AS u
+                                             INNER JOIN  aliases AS a ON u.user_id = a.id
+                                                  WHERE  a.alias = {?}', $m);
+                    if ($person = $res->fetchOneAssoc()) {
+                        $person['email'] = $mem[1];
+                        $tos[] = $person;
+                    }
+                } else {
+                    $res = $globals->xdb->query('SELECT prenom, nom FROM groupex.membres WHERE email={?}', $mem);
+                    if ($person = $res->fetchOneAssoc()) {
+                        $person['email'] = $mem[1];
+                        $tos[] = $person;
+                    } else {
+                        $tos[] = array('email' => $mem[1]);
+                    }
+                }
+            }
+        }
+    }
+
+    return $tos;
+}
+
+// }}}
+// {{{ _send_xnet_mail
+
+function _send_xnet_mail($user, $body, $mailer)
+{
+    $cher = isset($user['sexe']) ? ($user['sexe'] ? 'Chère' : 'Cher') : 'Cher(e)';
+    $nom  = isset($user['nom']) ? $user['nom'] : "";
+    $pnom = isset($user['prenom']) ? $user['prenom'] : preg_replace('!@.*!', $user['email']);
+    $to   = isset($user['prenom']) ? "\"{$user['prenom']} {$user['nom']}\" <{$user['email']}>" : $user['email'];
+    
+    $text = $body;
+    $text = preg_replace('!<cher>!i',   $cher, $text);
+    $text = preg_replace('!<nom>!i',    $nom,  $text);
+    $text = preg_replace('!<prenom>!i', $pnom, $text);
+
+    $mailer->addHeader('To', $to);
+    $mailer->setTxtBody(wordwrap($text, 72));
+    $mailer->send();
+}
+
+// }}}
+// {{{ send_xnet_mails
+
+function send_xnet_mails($from, $sujet, $body, $tos)
+{
+    $sent = array();
+
+    $mailer = new HermesMailer();
+    $mailer->setSubject($sujet);
+    $mailer->setFrom($from);
+
+    foreach ($tos as $user) {
+        if ($sent[$user['email']]) continue;
+        _send_xnet_mail($user, $body, $mailer);
+        $sent[$user['email']] = true;
+    }
+}
+
+// }}}
+
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker:
+?>
index 4af3af8..20b178e 100644 (file)
@@ -22,9 +22,9 @@
 
 <h1>Membres de {$smarty.request.liste}</h1>
       
-<table style="width:80%; margin: 0px 10%;">
+<table class='tiny'>
   <tr>
-    <th>Membres</th>
+    <td class='titre'>Membres</td>
     <td>
       {if $mem->total()}
       {iterate from=$mem item=m}
diff --git a/templates/xnet/groupe/mail.tpl b/templates/xnet/groupe/mail.tpl
new file mode 100644 (file)
index 0000000..95034b9
--- /dev/null
@@ -0,0 +1,111 @@
+{***************************************************************************
+ *  Copyright (C) 2003-2004 Polytechnique.org                              *
+ *  http://opensource.polytechnique.org/                                   *
+ *                                                                         *
+ *  This program is free software; you can redistribute it and/or modify   *
+ *  it under the terms of the GNU General Public License as published by   *
+ *  the Free Software Foundation; either version 2 of the License, or      *
+ *  (at your option) any later version.                                    *
+ *                                                                         *
+ *  This program is distributed in the hope that it will be useful,        *
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
+ *  GNU General Public License for more details.                           *
+ *                                                                         *
+ *  You should have received a copy of the GNU General Public License      *
+ *  along with this program; if not, write to the Free Software            *
+ *  Foundation, Inc.,                                                      *
+ *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
+ ***************************************************************************}
+
+
+<h1>{$asso.nom} : Envoyer un mail</h1>
+
+<p class="descr">
+Ton message peut être personnalisé : si tu rentres les mots &lt;cher&gt;, &lt;prenom&gt;,
+&lt;nom&gt;, ces mots seront remplacés, pour chacun des destinataires, par "cher" accordé au
+masculin ou féminin, par son prénom, ou son nom.
+</p>
+<form action="{$smarty.server.PHP_SELF}" method="post">
+  <table class='large'>
+    <tr>
+      <th colspan="2">Ecrire un mail :</th>
+    </tr>
+    <tr>
+      <td class="titre">Expéditeur :</td>
+      <td>
+        <input type="text" name="from" size="55" maxlength="70"
+          value="{if $smarty.request.from}{$smarty.request.from}{else}&quot;{$smarty.session.prenom} {$smarty.session.nom}&quot; <{$smarty.session.bestalias}@polytechnique.org>{/if}" />
+      </td>
+    </tr>
+
+    <tr>
+      <th colspan="2">Destinataires</th>
+    </tr>
+    <tr valign="top">
+      <td style='padding-left: 1em' class='titre'>
+        *&nbsp;<em>membres</em>
+      </td>
+      <td>
+        <input type="checkbox" name="membres" value="1" {if $smarty.request.membres}checked="checked"{/if} />
+        <em>écrit à tous les membres du groupe</em> <a href="annuaire.php" class='popup'>(voir membres)</a>
+      </td>
+    </tr>
+
+    {foreach from=$listes item=l}
+    <tr>
+      <td style='padding-left: 1em' class='titre'>
+        *&nbsp;{$l.list}
+      </td>
+      <td>
+        <input type="checkbox" name="ml[{$l.list}]" value="1" {if $smarty.request.ml[$l.list]}checked="checked"{/if} />
+        {$l.addr}
+        <a href="listes-admin.php?liste={$l.list}" class="popup">(voir composition)</a>
+      </td>
+    </tr>
+    {/foreach}
+
+    {* NOT SUPPORTED ATM
+    {foreach from=$alias item=a}
+    {assign var=b value=$a|regex_replace:"!@.*!":""}
+    <tr>
+      <td style='padding-left: 1em' class='titre'>
+        *&nbsp;{$b}
+      </td>
+      <td>
+        <input type="checkbox" name="al[{$b}]" value="1" {if $smarty.request.al[$b]}checked="checked"{/if} />
+        {$a} <a href="alias-admin.php?liste={$b}" class='popup'>(voir composition)</a>
+      </td>
+    </tr>
+    {/foreach}
+    *}
+
+    <tr>
+      <th colspan="2">Contenu du mail</th>
+    </tr>
+    <tr>
+      <td class="titre">
+        Sujet :
+      </td>
+      <td><input type="text" name="sujet" value="{$smarty.request.sujet|default:"remplir le sujet ..."}" size=55 maxlength=70></td>
+    </tr>
+    <tr>
+      <td colspan="2">
+        <textarea name="body" cols="72" rows="25">{if $smarty.request.body}{$smarty.request.body}{else}  &lt;cher&gt; &lt;prenom&gt;,
+          
+  Nous avons le plaisir de t'adresser la lettre mensuelle du groupe {$asso.nom}.
+
+  (insérer le texte...)
+
+  Le bureau du groupe {$asso.nom}.{/if}
+</textarea>
+      </td>
+    </tr>
+    <tr>
+      <td colspan="2" align="center"><input type="submit" name="send" value="Envoyer le message"></td>
+    </tr>
+  </table>
+</form>
+
+{* vim:set et sw=2 sts=2 sws=2: *}