[SPIP] v3.2.1-->v3.2.3
[lhc/web/www.git] / www / plugins-dist / organiseur / notifications / instituermessage.php
1 <?php
2
3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
5 * *
6 * Copyright (c) 2001-2019 *
7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
8 * *
9 * Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
10 * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
11 \***************************************************************************/
12
13 if (!defined('_ECRIRE_INC_VERSION')) {
14 return;
15 }
16
17
18 /**
19 * Envoyer les notifications consecutives a l'envoi d'un message
20 * (ie passage en statut=publie)
21 *
22 * @param string $quoi
23 * @param int $id_message
24 * @param array $options
25 */
26 function notifications_instituermessage_dist($quoi, $id_message, $options = array()) {
27
28 // ne devrait jamais se produire
29 if ($options['statut'] == $options['statut_ancien']) {
30 spip_log('statut inchange', 'notifications');
31 return;
32 }
33
34 if ($options['statut'] == 'publie') {
35 include_spip('inc/messages');
36 $type = sql_getfetsel('type', 'spip_messages', 'id_message=' . intval($id_message));
37 $vue = "notifications/message_{$type}_publie";
38 if (trouver_fond($vue)) {
39 $envoyer_mail = charger_fonction('envoyer_mail', 'inc'); // pour nettoyer_titre_email
40 $texte = recuperer_fond($vue, array('id_message' => $id_message));
41
42 // recuperer tous les emails des auteurs qui ont recu le message dans leur boite
43 // si c'est une annonce generale, on envoie a tout le monde
44 include_spip('inc/messages');
45 $where = array(
46 "email!=''",
47 "statut!='5poubelle'",
48 sql_in('statut', messagerie_statuts_destinataires_possibles())
49 );
50 // pour une annonce : tous ceux qui recoivent des messages
51 if ($type !== 'affich') {
52 $ids = sql_allfetsel('id_auteur', 'spip_auteurs_liens', "objet='message' AND id_objet=" . intval($id_message));
53 $ids = array_map('reset', $ids);
54 $where[] = sql_in('id_auteur', $ids);
55 }
56 $emails = sql_allfetsel('email', 'spip_auteurs', $where);
57 $emails = array_map('reset', $emails);
58
59 include_spip('inc/notifications');
60 notifications_envoyer_mails($emails, $texte);
61 }
62 }
63 }