dolibarr 18.0.6
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{
39 public function __construct($db)
40 {
41 $this->db = $db;
42 }
43
49 public function getAllContactNotInformed()
50 {
51 global $langs, $conf, $db, $user;
52
53 $langs->load("companies");
54
55 $sql = "SELECT c.rowid";
56 $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as c";
57 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON c.fk_soc = s.rowid";
58 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople_extrafields as spe ON spe.fk_object = c.rowid";
59 $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))";
60 $sql .= " AND spe.datapolicy_send IS NULL";
61 $sql .= " AND c.entity=".$conf->entity;
62 $resql = $this->db->query($sql);
63 if ($resql) {
64 $num = $this->db->num_rows($resql);
65 $i = 0;
66 while ($i < $num) {
67 $obj = $this->db->fetch_object($resql);
68 $contact = new Contact($db);
69 $contact->fetch($obj->rowid);
70
72 $i++;
73 }
74 } else {
75 $this->error = $this->db->error();
76 return -1;
77 }
78
79 return 1;
80 }
81
88 {
89 global $langs, $conf, $db, $user;
90
91 $langs->load("companies");
92
93 $sql = "SELECT s.rowid";
94 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
95 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_extrafields as se ON se.fk_object = s.rowid";
96 $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)";
97 $sql .= " AND se.datapolicy_send IS NULL";
98 $sql .= " AND s.entity=".$conf->entity;
99 $resql = $this->db->query($sql);
100 if ($resql) {
101 $num = $this->db->num_rows($resql);
102 $i = 0;
103 while ($i < $num) {
104 $obj = $this->db->fetch_object($resql);
105 $societe = new Societe($db);
106 $societe->fetch($obj->rowid);
107
109 $i++;
110 }
111 } else {
112 $this->error = $this->db->error();
113 return -1;
114 }
115
116 return 1;
117 }
118
125 {
126 global $langs, $conf, $db, $user;
127
128 $langs->load("adherent");
129
130 $sql = "SELECT a.rowid";
131 $sql .= " FROM ".MAIN_DB_PREFIX."adherent as a";
132 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."adherent_extrafields as ae ON ae.fk_object = a.rowid";
133 $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)";
134 $sql .= " AND ae.datapolicy_send IS NULL";
135 $sql .= " AND a.entity=".$conf->entity;
136 $resql = $this->db->query($sql);
137 if ($resql) {
138 $num = $this->db->num_rows($resql);
139 $i = 0;
140 while ($i < $num) {
141 $obj = $this->db->fetch_object($resql);
142 $adherent = new Adherent($db);
143 $adherent->fetch($obj->rowid);
144
146 $i++;
147 }
148 } else {
149 $this->error = $this->db->error();
150 return -1;
151 }
152
153 return 1;
154 }
155
162 public static function sendMailDataPolicyContact($contact)
163 {
164 global $langs, $conf, $db, $user;
165
166 $error = 0;
167
168 $from = $user->getFullName($langs).' <'.$user->email.'>';
169
170 $sendto = $contact->email;
171 $code = dol_hash($contact->email, 'md5');
172 if (!empty($contact->default_lang)) {
173 $l = $contact->default_lang;
174 } else {
175 $l = $langs->defaultlang;
176 }
177 // TODO Use a dolibarr email template
178 $s = "DATAPOLICYSUBJECT_".$l;
179 $ma = "DATAPOLICYCONTENT_".$l;
180 $la = 'TXTLINKDATAPOLICYACCEPT_'.$l;
181 $lr = 'TXTLINKDATAPOLICYREFUSE_'.$l;
182
183 $subject = $conf->global->$s;
184 $message = $conf->global->$ma;
185 $linka = $conf->global->$la;
186 $linkr = $conf->global->$lr;
187 $sendtocc = $sendtobcc = '';
188 $filepath = $mimetype = $filename = array();
189 $deliveryreceipt = 0;
190
191 $substitutionarray = array(
192 '__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>',
193 '__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>',
194 '__FIRSTNAME__' => $contact->firstname,
195 '__NAME__' => $contact->lastname,
196 '__CIVILITY__' => $contact->civility,
197 );
198 $subject = make_substitutions($subject, $substitutionarray);
199 $message = make_substitutions($message, $substitutionarray);
200
201 $actiontypecode = 'AC_EMAIL';
202 $actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto;
203 if ($message) {
204 if ($sendtocc) {
205 $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc').": ".$sendtocc);
206 }
207 $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic').": ".$subject);
208 $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody').":");
209 $actionmsg = dol_concatdesc($actionmsg, $message);
210 }
211
212
213 // Send mail
214 require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
215 $mailfile = new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename, $sendtocc, $sendtobcc, $deliveryreceipt, -1);
216
217 if ($mailfile->error) {
218 $resultmasssend .= '<div class="error">'.$mailfile->error.'</div>';
219 } else {
220 $result4 = $mailfile->sendfile();
221 if (!$error) {
222 $resultmasssend .= $langs->trans("MailSent").': '.$sendto."<br>";
223 $contact->array_options['options_datapolicy_send'] = date('Y-m-d', time());
224 $contact->update($contact->id);
225 } else {
226 dol_print_error($db);
227 }
228 }
229 setEventMessage($resultmasssend);
230 }
231
238 public static function sendMailDataPolicyCompany($societe)
239 {
240 global $langs, $conf, $db, $user;
241
242 $error = 0;
243
244 $from = $user->getFullName($langs).' <'.$user->email.'>';
245
246 $sendto = $societe->email;
247
248 $code = dol_hash($societe->email, 'md5');
249 if (!empty($societe->default_lang)) {
250 $l = $societe->default_lang;
251 } else {
252 $l = $langs->defaultlang;
253 }
254 // TODO Use a dolibarr email template
255 $s = "DATAPOLICYSUBJECT_".$l;
256 $ma = "DATAPOLICYCONTENT_".$l;
257 $la = 'TXTLINKDATAPOLICYACCEPT_'.$l;
258 $lr = 'TXTLINKDATAPOLICYREFUSE_'.$l;
259
260 $subject = $conf->global->$s;
261 $message = $conf->global->$ma;
262 $linka = $conf->global->$la;
263 $linkr = $conf->global->$lr;
264 $sendtocc = $sendtobcc = '';
265 $filepath = $mimetype = $filename = array();
266 $deliveryreceipt = 0;
267
268 $substitutionarray = array(
269 '__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>',
270 '__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>',
271 );
272 $subject = make_substitutions($subject, $substitutionarray);
273 $message = make_substitutions($message, $substitutionarray);
274
275 $actiontypecode = 'AC_EMAIL';
276 $actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto;
277 if ($message) {
278 if ($sendtocc) {
279 $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc').": ".$sendtocc);
280 }
281 $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic').": ".$subject);
282 $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody').":");
283 $actionmsg = dol_concatdesc($actionmsg, $message);
284 }
285
286 // Send mail
287 require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
288 $mailfile = new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename, $sendtocc, $sendtobcc, $deliveryreceipt, -1);
289 if ($mailfile->error) {
290 $resultmasssend .= '<div class="error">'.$mailfile->error.'</div>';
291 } else {
292 $result4 = $mailfile->sendfile();
293
294 if (!$error) {
295 $resultmasssend .= $langs->trans("MailSent").': '.$sendto."<br>";
296 $societe->array_options['options_datapolicy_send'] = date('Y-m-d', time());
297 $societe->update($societe->id);
298 } else {
299 dol_print_error($db);
300 }
301 }
302 setEventMessage($resultmasssend);
303 }
304
311 public static function sendMailDataPolicyAdherent($adherent)
312 {
313 global $langs, $conf, $db, $user;
314
315 $error = 0;
316
317 $from = $user->getFullName($langs).' <'.$user->email.'>';
318
319 $sendto = $adherent->email;
320
321 $code = dol_hash($adherent->email, 'md5');
322 if (!empty($adherent->default_lang)) {
323 $l = $adherent->default_lang;
324 } else {
325 $l = $langs->defaultlang;
326 }
327 // TODO Use a dolibarr email template
328 $s = 'TXTLINKDATAPOLICYSUBJECT_'.$l;
329 $ma = 'TXTLINKDATAPOLICYMESSAGE_'.$l;
330 $la = 'TXTLINKDATAPOLICYACCEPT_'.$l;
331 $lr = 'TXTLINKDATAPOLICYREFUSE_'.$l;
332
333 $subject = $conf->global->$s;
334 $message = $conf->global->$ma;
335 $linka = $conf->global->$la;
336 $linkr = $conf->global->$lr;
337 $sendtocc = $sendtobcc = '';
338 $filepath = $mimetype = $filename = array();
339 $deliveryreceipt = 0;
340
341 $substitutionarray = array(
342 '__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>',
343 '__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>',
344 );
345 $subject = make_substitutions($subject, $substitutionarray);
346 $message = make_substitutions($message, $substitutionarray);
347
348 $actiontypecode = 'AC_EMAIL';
349 $actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto;
350 if ($message) {
351 if ($sendtocc) {
352 $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc').": ".$sendtocc);
353 }
354 $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic').": ".$subject);
355 $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody').":");
356 $actionmsg = dol_concatdesc($actionmsg, $message);
357 }
358
359
360 // Send mail
361 require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
362 $mailfile = new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename, $sendtocc, $sendtobcc, $deliveryreceipt, -1);
363 if ($mailfile->error) {
364 $resultmasssend .= '<div class="error">'.$mailfile->error.'</div>';
365 } else {
366 $result4 = $mailfile->sendfile();
367
368 if (!$error) {
369 $resultmasssend .= $langs->trans("MailSent").': '.$sendto."<br>";
370 $adherent->array_options['options_datapolicy_send'] = date('Y-m-d', time());
371 $adherent->update($user);
372 } else {
373 dol_print_error($db);
374 }
375 }
376 setEventMessage($resultmasssend);
377 }
378}
Class to manage members of a foundation.
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
Class to manage contact/addresses.
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')
Returns a hash (non reversible encryption) of a string.