Adds support for database tablename prefixs.
[platal.git] / modules / xnetgrp / mail.inc.php
index b6574c5..654add1 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2007 Polytechnique.org                              *
+ *  Copyright (C) 2003-2009 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -24,9 +24,9 @@
 function get_all_redirects($membres, $mls, &$client)
 {
     global $globals;
-    
+
     $tos = array();
-    
+
     if (!empty($membres)) {
         $membres = array_map(create_function('$str', 'return "\"$str\"";'), $membres);
         $membres = join(',', $membres);
@@ -35,9 +35,9 @@ function get_all_redirects($membres, $mls, &$client)
                              IF(u.prenom <> "", u.prenom, m.prenom) AS prenom,
                              IF(m.email <> "", m.email, CONCAT(a.alias, "@polytechnique.org")) as email,
                              IF(m.sexe IS NULL, FIND_IN_SET("femme", u.flags), m.sexe) AS sexe
-                       FROM  groupex.membres AS m
-                  LEFT JOIN  auth_user_md5   AS u ON (m.uid=u.user_id AND m.uid<50000)
-                  LEFT JOIN  aliases         AS a ON (a.id=u.user_id and a.type="a_vie")
+                       FROM  #groupex#.membres     AS m
+                  LEFT JOIN  #x4dat#.auth_user_md5 AS u ON (m.uid=u.user_id AND m.uid<50000)
+                  LEFT JOIN  #x4dat#.aliases       AS a ON (a.id=u.user_id and a.type="a_vie")
                       WHERE  asso_id = {?}
                              AND m.origine IN (' . $membres . ')
                              AND (m.email <> "" OR u.perms <> "pending")', $globals->asso('id'));
@@ -58,7 +58,7 @@ function get_all_redirects($membres, $mls, &$client)
                         $tos[] = $person;
                     }
                 } else {
-                    $res = XDB::query('SELECT prenom, nom, sexe FROM groupex.membres WHERE email={?}', $mem[1]);
+                    $res = XDB::query('SELECT prenom, nom, sexe FROM #groupex#.membres WHERE email={?}', $mem[1]);
                     if ($person = $res->fetchOneAssoc()) {
                         $person['email'] = $mem[1];
                         $tos[] = $person;
@@ -76,13 +76,13 @@ function get_all_redirects($membres, $mls, &$client)
 // }}}
 // {{{ _send_xnet_mail
 
-function _send_xnet_mail($user, $body, $mailer, $replyto = null)
+function _send_xnet_mail($user, $body, $wiki, $mailer, $replyto = null)
 {
     $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('!@.*!u', '', $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);
@@ -92,14 +92,18 @@ function _send_xnet_mail($user, $body, $mailer, $replyto = null)
     if ($replyto) {
         $mailer->addHeader('Reply-To', $replyto);
     }
-    $mailer->setTxtBody(wordwrap($text, 72));
+    if ($wiki) {
+        $mailer->setWikiBody($text);
+    } else {
+        $mailer->setTxtBody(wordwrap($text, 72));
+    }
     $mailer->send();
 }
 
 // }}}
 // {{{ send_xnet_mails
 
-function send_xnet_mails($from, $sujet, $body, $tos, $replyto = null, $upload = null, $name = null)
+function send_xnet_mails($from, $sujet, $body, $wiki, $tos, $replyto = null, $upload = null, $name = null)
 {
     global $globals;
     $sent = array();
@@ -113,7 +117,7 @@ function send_xnet_mails($from, $sujet, $body, $tos, $replyto = null, $upload =
 
     foreach ($tos as $user) {
         if ($sent[$user['email']]) continue;
-        _send_xnet_mail($user, $body, $mailer, $replyto);
+        _send_xnet_mail($user, $body, $wiki, $mailer, $replyto);
         $sent[$user['email']] = true;
     }
 }