dolibarr 21.0.0-beta
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 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 * or see https://www.gnu.org/
20 */
21
27include_once DOL_DOCUMENT_ROOT.'/core/modules/mailings/modules_mailings.php';
28
29
34{
38 public $name = 'DolibarrUsers';
39
43 public $desc = 'Dolibarr users with emails'; // Libelle utilise si aucune traduction pour MailingModuleDescXXX ou XXX=name trouvée
44
48 public $require_module = array();
49
53 public $require_admin = 1;
54
58 public $picto = 'user';
59
60
66 public function __construct($db)
67 {
68 $this->db = $db;
69 }
70
71
80 public function getSqlArrayForStats()
81 {
82 global $conf, $langs;
83
84 $langs->load("users");
85
86 $statssql = array();
87 $sql = "SELECT '".$this->db->escape($langs->trans("DolibarrUsers"))."' as label,";
88 $sql .= " count(distinct(u.email)) as nb";
89 $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
90 $sql .= " WHERE u.email != ''"; // u.email IS NOT NULL est implicit dans ce test
91 $sql .= " AND u.entity IN (0,".$conf->entity.")";
92
93 $statssql[0] = $sql;
94
95 return $statssql;
96 }
97
98
107 public function getNbOfRecipients($sql = '')
108 {
109 global $conf;
110
111 $sql = "SELECT count(distinct(u.email)) as nb";
112 $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
113 $sql .= " WHERE u.email != ''"; // u.email IS NOT NULL est implicit dans ce test
114 $sql .= " AND u.entity IN (0,".$conf->entity.")";
115 if (empty($this->evenunsubscribe)) {
116 $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).")";
117 }
118
119 // La requete doit retourner un champ "nb" pour etre comprise par parent::getNbOfRecipients
120 return parent::getNbOfRecipients($sql);
121 }
122
123
129 public function formFilter()
130 {
131 global $langs;
132
133 $langs->load("users");
134
135 $s = '';
136 $s .= '<select id="filter_pomme"" name="filter" class="flat minwidth100">';
137 $s .= '<option value="-1">'.$langs->trans("Status").'</option>';
138 $s .= '<option value="1">'.$langs->trans("Enabled").'</option>';
139 $s .= '<option value="0">'.$langs->trans("Disabled").'</option>';
140 $s .= '</select>';
141 $s .= ajax_combobox("filter_pomme");
142
143 $s .= ' ';
144 $s .= '<select id="filteremployee_pomme" name="filteremployee" class="flat minwidth100">';
145 $s .= '<option value="-1">'.$langs->trans("Employee").'</option>';
146 $s .= '<option value="1">'.$langs->trans("Yes").'</option>';
147 $s .= '<option value="0">'.$langs->trans("No").'</option>';
148 $s .= '</select>';
149 $s .= ajax_combobox("filteremployee_pomme");
150
151 return $s;
152 }
153
154
161 public function url($id)
162 {
163 return '<a href="'.DOL_URL_ROOT.'/user/card.php?id='.$id.'">'.img_object('', "user").'</a>';
164 }
165
166
167 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
174 public function add_to_target($mailing_id)
175 {
176 // phpcs:enable
177 global $conf, $langs;
178 $langs->load("companies");
179
180 $cibles = array();
181
182 // La requete doit retourner: id, email, fk_contact, lastname, firstname
183 $sql = "SELECT u.rowid as id, u.email as email, null as fk_contact,";
184 $sql .= " u.lastname, u.firstname as firstname, u.civility as civility_id, u.login, u.office_phone";
185 $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
186 $sql .= " WHERE u.email <> ''"; // u.email IS NOT NULL est implicit dans ce test
187 $sql .= " AND u.entity IN (0,".$conf->entity.")";
188 $sql .= " AND u.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".((int) $mailing_id).")";
189 if (GETPOSTISSET("filter") && GETPOST("filter") == '1') {
190 $sql .= " AND u.statut=1";
191 }
192 if (GETPOSTISSET("filter") && GETPOST("filter") == '0') {
193 $sql .= " AND u.statut=0";
194 }
195 if (GETPOSTISSET("filteremployee") && GETPOST("filteremployee") == '1') {
196 $sql .= " AND u.employee=1";
197 }
198 if (GETPOSTISSET("filteremployee") && GETPOST("filteremployee") == '0') {
199 $sql .= " AND u.employee=0";
200 }
201 if (empty($this->evenunsubscribe)) {
202 $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).")";
203 }
204 $sql .= " ORDER BY u.email";
205
206 // Stocke destinataires dans cibles
207 $result = $this->db->query($sql);
208 if ($result) {
209 $num = $this->db->num_rows($result);
210 $i = 0;
211 $j = 0;
212
213 dol_syslog(get_class($this)."::add_to_target mailing ".$num." targets found");
214
215 $old = '';
216 while ($i < $num) {
217 $obj = $this->db->fetch_object($result);
218 if ($old != $obj->email) {
219 $cibles[$j] = array(
220 'email' => $obj->email,
221 'fk_contact' => (int) $obj->fk_contact,
222 'lastname' => $obj->lastname,
223 'firstname' => $obj->firstname,
224 'other' =>
225 ($langs->transnoentities("Login").'='.$obj->login).';'.
226 ($langs->transnoentities("UserTitle").'='.$obj->civility_id).';'.
227 ($langs->transnoentities("PhonePro").'='.$obj->office_phone),
228 'source_url' => $this->url($obj->id),
229 'source_id' => (int) $obj->id,
230 'source_type' => 'user'
231 );
232 $old = $obj->email;
233 $j++;
234 }
235
236 $i++;
237 }
238 } else {
239 dol_syslog($this->db->error());
240 $this->error = $this->db->error();
241 return -1;
242 }
243
244 return parent::addTargetsToDatabase($mailing_id, $cibles);
245 }
246}
$id
Definition account.php:48
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:459
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79