dolibarr 19.0.3
datapolicy.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
23include_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
24include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
25include_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
26include_once DOL_DOCUMENT_ROOT.'/core/lib/security.lib.php';
27
28
33{
37 public $db;
38
39 public $error;
40
41
47 public function __construct($db)
48 {
49 $this->db = $db;
50 }
51
57 public function getAllContactNotInformed()
58 {
59 global $langs, $conf, $db, $user;
60
61 $langs->load("companies");
62
63 $sql = "SELECT c.rowid";
64 $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as c";
65 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON c.fk_soc = s.rowid";
66 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople_extrafields as spe ON spe.fk_object = c.rowid";
67 $sql .= " WHERE (c.statut=1 AND c.no_email=0 AND (spe.datapolicy_consentement=0 OR spe.datapolicy_consentement IS NULL) AND (spe.datapolicy_opposition_traitement=0 OR spe.datapolicy_opposition_traitement IS NULL) AND (spe.datapolicy_opposition_prospection=0 OR spe.datapolicy_opposition_prospection IS NULL))";
68 $sql .= " AND spe.datapolicy_send IS NULL";
69 $sql .= " AND c.entity=".$conf->entity;
70 $resql = $this->db->query($sql);
71 if ($resql) {
72 $num = $this->db->num_rows($resql);
73 $i = 0;
74 while ($i < $num) {
75 $obj = $this->db->fetch_object($resql);
76 $contact = new Contact($db);
77 $contact->fetch($obj->rowid);
78
80 $i++;
81 }
82 } else {
83 $this->error = $this->db->error();
84 return -1;
85 }
86
87 return 1;
88 }
89
96 {
97 global $langs, $conf, $db, $user;
98
99 $langs->load("companies");
100
101 $sql = "SELECT s.rowid";
102 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
103 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_extrafields as se ON se.fk_object = s.rowid";
104 $sql .= " WHERE s.statut=0 AND (se.datapolicy_consentement=0 OR se.datapolicy_consentement IS NULL) AND (se.datapolicy_opposition_traitement=0 OR se.datapolicy_opposition_traitement IS NULL) AND (se.datapolicy_opposition_prospection=0 OR se.datapolicy_opposition_prospection IS NULL)";
105 $sql .= " AND se.datapolicy_send IS NULL";
106 $sql .= " AND s.entity=".$conf->entity;
107 $resql = $this->db->query($sql);
108 if ($resql) {
109 $num = $this->db->num_rows($resql);
110 $i = 0;
111 while ($i < $num) {
112 $obj = $this->db->fetch_object($resql);
113 $societe = new Societe($db);
114 $societe->fetch($obj->rowid);
115
117 $i++;
118 }
119 } else {
120 $this->error = $this->db->error();
121 return -1;
122 }
123
124 return 1;
125 }
126
133 {
134 global $langs, $conf, $db, $user;
135
136 $langs->load("adherent");
137
138 $sql = "SELECT a.rowid";
139 $sql .= " FROM ".MAIN_DB_PREFIX."adherent as a";
140 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."adherent_extrafields as ae ON ae.fk_object = a.rowid";
141 $sql .= " WHERE a.statut=0 AND (ae.datapolicy_consentement=0 OR ae.datapolicy_consentement IS NULL) AND (ae.datapolicy_opposition_traitement=0 OR ae.datapolicy_opposition_traitement IS NULL) AND (ae.datapolicy_opposition_prospection=0 OR ae.datapolicy_opposition_prospection IS NULL)";
142 $sql .= " AND ae.datapolicy_send IS NULL";
143 $sql .= " AND a.entity=".$conf->entity;
144 $resql = $this->db->query($sql);
145 if ($resql) {
146 $num = $this->db->num_rows($resql);
147 $i = 0;
148 while ($i < $num) {
149 $obj = $this->db->fetch_object($resql);
150 $adherent = new Adherent($db);
151 $adherent->fetch($obj->rowid);
152
154 $i++;
155 }
156 } else {
157 $this->error = $this->db->error();
158 return -1;
159 }
160
161 return 1;
162 }
163
170 public static function sendMailDataPolicyContact($contact)
171 {
172 global $langs, $conf, $db, $user;
173
174 $error = 0;
175
176 $from = $user->getFullName($langs).' <'.$user->email.'>';
177
178 $sendto = $contact->email;
179 $code = dol_hash($contact->email, 'md5');
180 if (!empty($contact->default_lang)) {
181 $l = $contact->default_lang;
182 } else {
183 $l = $langs->defaultlang;
184 }
185 // TODO Use a dolibarr email template
186 $s = "DATAPOLICYSUBJECT_".$l;
187 $ma = "DATAPOLICYCONTENT_".$l;
188 $la = 'TXTLINKDATAPOLICYACCEPT_'.$l;
189 $lr = 'TXTLINKDATAPOLICYREFUSE_'.$l;
190
191 $subject = $conf->global->$s;
192 $message = $conf->global->$ma;
193 $linka = $conf->global->$la;
194 $linkr = $conf->global->$lr;
195 $sendtocc = $sendtobcc = '';
196 $filepath = $mimetype = $filename = array();
197 $deliveryreceipt = 0;
198
199 $substitutionarray = array(
200 '__LINKACCEPT__' => '<a href="'.dol_buildpath('/public/datapolicy/index.php?action=1&c='.$contact->id.'&l='.$l.'&key='.$code, 3).'" target="_blank" rel="noopener noreferrer">'.$linka.'</a>',
201 '__LINKREFUSED__' => '<a href="'.dol_buildpath('/public/datapolicy/index.php?action=2&c='.$contact->id.'&l='.$l.'&key='.$code, 3).'" target="_blank" rel="noopener noreferrer">'.$linkr.'</a>',
202 '__FIRSTNAME__' => $contact->firstname,
203 '__NAME__' => $contact->lastname,
204 '__CIVILITY__' => $contact->civility,
205 );
206 $subject = make_substitutions($subject, $substitutionarray);
207 $message = make_substitutions($message, $substitutionarray);
208
209 $actiontypecode = 'AC_EMAIL';
210 $actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto;
211 if ($message) {
212 if ($sendtocc) {
213 $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc').": ".$sendtocc);
214 }
215 $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic').": ".$subject);
216 $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody').":");
217 $actionmsg = dol_concatdesc($actionmsg, $message);
218 }
219
220
221 // Send mail
222 require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
223 $mailfile = new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename, $sendtocc, $sendtobcc, $deliveryreceipt, -1);
224
225 $resultmasssend = '';
226 if ($mailfile->error) {
227 $resultmasssend .= '<div class="error">'.$mailfile->error.'</div>';
228 } else {
229 $resultmail = $mailfile->sendfile();
230
231 if ($resultmail) {
232 $resultmasssend .= $langs->trans("MailSent").': '.$sendto."<br>";
233 $contact->array_options['options_datapolicy_send'] = date('Y-m-d', time());
234 $contact->update($contact->id);
235 } else {
236 dol_print_error($db);
237 }
238 }
239 setEventMessage($resultmasssend);
240 }
241
248 public static function sendMailDataPolicyCompany($societe)
249 {
250 global $langs, $conf, $db, $user;
251
252 $error = 0;
253
254 $from = $user->getFullName($langs).' <'.$user->email.'>';
255
256 $sendto = $societe->email;
257
258 $code = dol_hash($societe->email, 'md5');
259 if (!empty($societe->default_lang)) {
260 $l = $societe->default_lang;
261 } else {
262 $l = $langs->defaultlang;
263 }
264 // TODO Use a dolibarr email template
265 $s = "DATAPOLICYSUBJECT_".$l;
266 $ma = "DATAPOLICYCONTENT_".$l;
267 $la = 'TXTLINKDATAPOLICYACCEPT_'.$l;
268 $lr = 'TXTLINKDATAPOLICYREFUSE_'.$l;
269
270 $subject = $conf->global->$s;
271 $message = $conf->global->$ma;
272 $linka = $conf->global->$la;
273 $linkr = $conf->global->$lr;
274 $sendtocc = $sendtobcc = '';
275 $filepath = $mimetype = $filename = array();
276 $deliveryreceipt = 0;
277
278 $substitutionarray = array(
279 '__LINKACCEPT__' => '<a href="'.dol_buildpath('/public/datapolicy/index.php?action=1&s='.$societe->id.'&l='.$l.'&key='.$code, 3).'" target="_blank" rel="noopener noreferrer">'.$linka.'</a>',
280 '__LINKREFUSED__' => '<a href="'.dol_buildpath('/public/datapolicy/index.php?action=2&s='.$societe->id.'&l='.$l.'&key='.$code, 3).'" target="_blank" rel="noopener noreferrer">'.$linkr.'</a>',
281 );
282 $subject = make_substitutions($subject, $substitutionarray);
283 $message = make_substitutions($message, $substitutionarray);
284
285 $actiontypecode = 'AC_EMAIL';
286 $actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto;
287 if ($message) {
288 if ($sendtocc) {
289 $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc').": ".$sendtocc);
290 }
291 $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic').": ".$subject);
292 $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody').":");
293 $actionmsg = dol_concatdesc($actionmsg, $message);
294 }
295
296 // Send mail
297 require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
298 $mailfile = new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename, $sendtocc, $sendtobcc, $deliveryreceipt, -1);
299
300 $resultmasssend = '';
301 if ($mailfile->error) {
302 $resultmasssend .= '<div class="error">'.$mailfile->error.'</div>';
303 } else {
304 $resultmail = $mailfile->sendfile();
305
306 if ($resultmail) {
307 $resultmasssend .= $langs->trans("MailSent").': '.$sendto."<br>";
308 $societe->array_options['options_datapolicy_send'] = date('Y-m-d', time());
309 $societe->update($societe->id);
310 } else {
311 dol_print_error($db);
312 }
313 }
314 setEventMessage($resultmasssend);
315 }
316
323 public static function sendMailDataPolicyAdherent($adherent)
324 {
325 global $langs, $conf, $db, $user;
326
327 $error = 0;
328
329 $from = $user->getFullName($langs).' <'.$user->email.'>';
330
331 $sendto = $adherent->email;
332
333 $code = dol_hash($adherent->email, 'md5');
334 if (!empty($adherent->default_lang)) {
335 $l = $adherent->default_lang;
336 } else {
337 $l = $langs->defaultlang;
338 }
339 // TODO Use a dolibarr email template
340 $s = 'TXTLINKDATAPOLICYSUBJECT_'.$l;
341 $ma = 'TXTLINKDATAPOLICYMESSAGE_'.$l;
342 $la = 'TXTLINKDATAPOLICYACCEPT_'.$l;
343 $lr = 'TXTLINKDATAPOLICYREFUSE_'.$l;
344
345 $subject = $conf->global->$s;
346 $message = $conf->global->$ma;
347 $linka = $conf->global->$la;
348 $linkr = $conf->global->$lr;
349 $sendtocc = $sendtobcc = '';
350 $filepath = $mimetype = $filename = array();
351 $deliveryreceipt = 0;
352
353 $substitutionarray = array(
354 '__LINKACCEPT__' => '<a href="'.dol_buildpath('/public/datapolicy/index.php?action=1&a='.$adherent->id.'&l='.$l.'&key='.$code, 3).'" target="_blank" rel="noopener noreferrer">'.$linka.'</a>',
355 '__LINKREFUSED__' => '<a href="'.dol_buildpath('/public/datapolicy/index.php?action=2&a='.$adherent->id.'&l='.$l.'&key='.$code, 3).'" target="_blank" rel="noopener noreferrer">'.$linkr.'</a>',
356 );
357 $subject = make_substitutions($subject, $substitutionarray);
358 $message = make_substitutions($message, $substitutionarray);
359
360 $actiontypecode = 'AC_EMAIL';
361 $actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto;
362 if ($message) {
363 if ($sendtocc) {
364 $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc').": ".$sendtocc);
365 }
366 $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic').": ".$subject);
367 $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody').":");
368 $actionmsg = dol_concatdesc($actionmsg, $message);
369 }
370
371
372 // Send mail
373 require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
374 $mailfile = new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename, $sendtocc, $sendtobcc, $deliveryreceipt, -1);
375
376 $resultmasssend = '';
377 if ($mailfile->error) {
378 $resultmasssend .= '<div class="error">'.$mailfile->error.'</div>';
379 } else {
380 $resultmail = $mailfile->sendfile();
381
382 if ($resultmail) {
383 $resultmasssend .= $langs->trans("MailSent").': '.$sendto."<br>";
384 $adherent->array_options['options_datapolicy_send'] = date('Y-m-d', time());
385 $adherent->update($user);
386 } else {
387 dol_print_error($db);
388 }
389 }
390 setEventMessage($resultmasssend);
391 }
392}
Class to manage members of a foundation.
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
Class DataPolicy.
__construct($db)
Constructor.
static sendMailDataPolicyAdherent($adherent)
sendMailDataPolicyAdherent
getAllContactNotInformed()
getAllContactNotInformed
static sendMailDataPolicyContact($contact)
sendMailDataPolicyContact
getAllCompaniesNotInformed()
getAllCompaniesNotInformed
getAllAdherentsNotInformed()
getAllAdherentsNotInformed
static sendMailDataPolicyCompany($societe)
sendMailDataPolicyCompany
Class to manage third parties objects (customers, suppliers, prospects...)
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
setEventMessage($mesgs, $style='mesgs', $noduplicate=0)
Set event message in dol_events session object.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_hash($chain, $type='0', $nosalt=0)
Returns a hash (non reversible encryption) of a string.
Contact()
Old copy.
Definition index.php:572