dolibarr 21.0.0-alpha
pomme.modules.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2005-2011 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
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 3 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, see <https://www.gnu.org/licenses/>.
18 * or see https://www.gnu.org/
19 */
20
26include_once DOL_DOCUMENT_ROOT.'/core/modules/mailings/modules_mailings.php';
27
28
33{
34 public $name = 'DolibarrUsers'; // Identifiant du module mailing
35 // This label is used if no translation is found for key XXX neither MailingModuleDescXXX where XXX=name is found
36 public $desc = 'Dolibarr users with emails'; // Libelle utilise si aucune traduction pour MailingModuleDescXXX ou XXX=name trouv�e
37 public $require_module = array(); // Module mailing actif si modules require_module actifs
38 public $require_admin = 1; // Module mailing actif pour user admin ou non
39
43 public $picto = 'user';
44
45
51 public function __construct($db)
52 {
53 $this->db = $db;
54 }
55
56
65 public function getSqlArrayForStats()
66 {
67 global $conf, $langs;
68
69 $langs->load("users");
70
71 $statssql = array();
72 $sql = "SELECT '".$this->db->escape($langs->trans("DolibarrUsers"))."' as label,";
73 $sql .= " count(distinct(u.email)) as nb";
74 $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
75 $sql .= " WHERE u.email != ''"; // u.email IS NOT NULL est implicit dans ce test
76 $sql .= " AND u.entity IN (0,".$conf->entity.")";
77
78 $statssql[0] = $sql;
79
80 return $statssql;
81 }
82
83
92 public function getNbOfRecipients($sql = '')
93 {
94 global $conf;
95
96 $sql = "SELECT count(distinct(u.email)) as nb";
97 $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
98 $sql .= " WHERE u.email != ''"; // u.email IS NOT NULL est implicit dans ce test
99 $sql .= " AND u.entity IN (0,".$conf->entity.")";
100 if (empty($this->evenunsubscribe)) {
101 $sql .= " AND NOT EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX."mailing_unsubscribe as mu WHERE mu.email = u.email and mu.entity = ".((int) $conf->entity).")";
102 }
103
104 // La requete doit retourner un champ "nb" pour etre comprise par parent::getNbOfRecipients
105 return parent::getNbOfRecipients($sql);
106 }
107
108
114 public function formFilter()
115 {
116 global $langs;
117
118 $langs->load("users");
119
120 $s = '';
121 $s .= '<select id="filter_pomme"" name="filter" class="flat minwidth100">';
122 $s .= '<option value="-1">'.$langs->trans("Status").'</option>';
123 $s .= '<option value="1">'.$langs->trans("Enabled").'</option>';
124 $s .= '<option value="0">'.$langs->trans("Disabled").'</option>';
125 $s .= '</select>';
126 $s .= ajax_combobox("filter_pomme");
127
128 $s .= ' ';
129 $s .= '<select id="filteremployee_pomme" name="filteremployee" class="flat minwidth100">';
130 $s .= '<option value="-1">'.$langs->trans("Employee").'</option>';
131 $s .= '<option value="1">'.$langs->trans("Yes").'</option>';
132 $s .= '<option value="0">'.$langs->trans("No").'</option>';
133 $s .= '</select>';
134 $s .= ajax_combobox("filteremployee_pomme");
135
136 return $s;
137 }
138
139
146 public function url($id)
147 {
148 return '<a href="'.DOL_URL_ROOT.'/user/card.php?id='.$id.'">'.img_object('', "user").'</a>';
149 }
150
151
152 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
159 public function add_to_target($mailing_id)
160 {
161 // phpcs:enable
162 global $conf, $langs;
163 $langs->load("companies");
164
165 $cibles = array();
166
167 // La requete doit retourner: id, email, fk_contact, lastname, firstname
168 $sql = "SELECT u.rowid as id, u.email as email, null as fk_contact,";
169 $sql .= " u.lastname, u.firstname as firstname, u.civility as civility_id, u.login, u.office_phone";
170 $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
171 $sql .= " WHERE u.email <> ''"; // u.email IS NOT NULL est implicit dans ce test
172 $sql .= " AND u.entity IN (0,".$conf->entity.")";
173 $sql .= " AND u.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".((int) $mailing_id).")";
174 if (GETPOSTISSET("filter") && GETPOST("filter") == '1') {
175 $sql .= " AND u.statut=1";
176 }
177 if (GETPOSTISSET("filter") && GETPOST("filter") == '0') {
178 $sql .= " AND u.statut=0";
179 }
180 if (GETPOSTISSET("filteremployee") && GETPOST("filteremployee") == '1') {
181 $sql .= " AND u.employee=1";
182 }
183 if (GETPOSTISSET("filteremployee") && GETPOST("filteremployee") == '0') {
184 $sql .= " AND u.employee=0";
185 }
186 if (empty($this->evenunsubscribe)) {
187 $sql .= " AND NOT EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX."mailing_unsubscribe as mu WHERE mu.email = u.email and mu.entity = ".((int) $conf->entity).")";
188 }
189 $sql .= " ORDER BY u.email";
190
191 // Stocke destinataires dans cibles
192 $result = $this->db->query($sql);
193 if ($result) {
194 $num = $this->db->num_rows($result);
195 $i = 0;
196 $j = 0;
197
198 dol_syslog(get_class($this)."::add_to_target mailing ".$num." targets found");
199
200 $old = '';
201 while ($i < $num) {
202 $obj = $this->db->fetch_object($result);
203 if ($old != $obj->email) {
204 $cibles[$j] = array(
205 'email' => $obj->email,
206 'fk_contact' => $obj->fk_contact,
207 'lastname' => $obj->lastname,
208 'firstname' => $obj->firstname,
209 'other' =>
210 ($langs->transnoentities("Login").'='.$obj->login).';'.
211 ($langs->transnoentities("UserTitle").'='.$obj->civility_id).';'.
212 ($langs->transnoentities("PhonePro").'='.$obj->office_phone),
213 'source_url' => $this->url($obj->id),
214 'source_id' => $obj->id,
215 'source_type' => 'user'
216 );
217 $old = $obj->email;
218 $j++;
219 }
220
221 $i++;
222 }
223 } else {
224 dol_syslog($this->db->error());
225 $this->error = $this->db->error();
226 return -1;
227 }
228
229 return parent::addTargetsToDatabase($mailing_id, $cibles);
230 }
231}
$id
Definition account.php:39
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
Definition ajax.lib.php:457
Parent class of emailing target selectors modules.
Class to offer a selector of emailing targets with Rule 'Pomme'.
formFilter()
Affiche formulaire de filtre qui apparait dans page de selection des destinataires de mailings.
getNbOfRecipients($sql='')
Return here number of distinct emails returned by your selector.
__construct($db)
Constructor.
url($id)
Provide the URL to the car of the source information of the recipient for the mailing.
add_to_target($mailing_id)
Ajoute destinataires dans table des cibles.
getSqlArrayForStats()
On the main mailing area, there is a box with statistics.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.