[SPIP] ~v3.0.20-->v3.0.25
[lhc/web/clavette_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-2016 *
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')) return;
14
15
16 /**
17 * Envoyer les notifications consecutives a l'envoi d'un message
18 * (ie passage en statut=publie)
19 *
20 * @param string $quoi
21 * @param int $id_message
22 * @param array $options
23 */
24 function notifications_instituermessage_dist($quoi, $id_message, $options=array()){
25
26 // ne devrait jamais se produire
27 if ($options['statut'] == $options['statut_ancien']) {
28 spip_log("statut inchange",'notifications');
29 return;
30 }
31
32 if ($options['statut']=='publie'){
33 include_spip('inc/messages');
34 $type = sql_getfetsel('type','spip_messages','id_message='.intval($id_message));
35 $vue = "notifications/message_{$type}_publie";
36 if (trouver_fond($vue)){
37 $envoyer_mail = charger_fonction('envoyer_mail','inc'); // pour nettoyer_titre_email
38 $texte = recuperer_fond($vue,array('id_message'=>$id_message));
39
40 // recuperer tous les emails des auteurs qui ont recu le message dans leur boite
41 // si c'est une annonce generale, on envoie a tout le monde
42 include_spip('inc/messages');
43 $where = array(
44 "email!=''",
45 "statut!='5poubelle'",
46 sql_in('statut',messagerie_statuts_destinataires_possibles())
47 );
48 // pour une annonce : tous ceux qui recoivent des messages
49 if ($type!=='affich'){
50 $ids = sql_allfetsel('id_auteur','spip_auteurs_liens',"objet='message' AND id_objet=".intval($id_message));
51 $ids = array_map('reset',$ids);
52 $where[] = sql_in('id_auteur',$ids);
53 }
54 $emails = sql_allfetsel('email',"spip_auteurs",$where);
55 $emails = array_map('reset',$emails);
56
57 include_spip('inc/notifications');
58 notifications_envoyer_mails($emails,$texte);
59 }
60 }
61 }