dolibarr  17.0.4
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 
23 include_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
24 include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
25 include_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
26 include_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 
85  public function getAllCompaniesNotInformed()
86  {
87  global $langs, $conf, $db, $user;
88 
89  $langs->load("companies");
90 
91  $sql = "SELECT s.rowid";
92  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
93  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_extrafields as se ON se.fk_object = s.rowid";
94  $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)";
95  $sql .= " AND se.datapolicy_send IS NULL";
96  $sql .= " AND s.entity=".$conf->entity;
97  $resql = $this->db->query($sql);
98  if ($resql) {
99  $num = $this->db->num_rows($resql);
100  $i = 0;
101  while ($i < $num) {
102  $obj = $this->db->fetch_object($resql);
103  $societe = new Societe($db);
104  $societe->fetch($obj->rowid);
105 
107  $i++;
108  }
109  } else {
110  $this->error = $this->db->error();
111  return -1;
112  }
113  }
114 
120  public function getAllAdherentsNotInformed()
121  {
122  global $langs, $conf, $db, $user;
123 
124  $langs->load("adherent");
125 
126  $sql = "SELECT a.rowid";
127  $sql .= " FROM ".MAIN_DB_PREFIX."adherent as a";
128  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."adherent_extrafields as ae ON ae.fk_object = a.rowid";
129  $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)";
130  $sql .= " AND ae.datapolicy_send IS NULL";
131  $sql .= " AND a.entity=".$conf->entity;
132  $resql = $this->db->query($sql);
133  if ($resql) {
134  $num = $this->db->num_rows($resql);
135  $i = 0;
136  while ($i < $num) {
137  $obj = $this->db->fetch_object($resql);
138  $adherent = new Adherent($db);
139  $adherent->fetch($obj->rowid);
140 
142  $i++;
143  }
144  } else {
145  $this->error = $this->db->error();
146  return -1;
147  }
148  }
149 
156  public static function sendMailDataPolicyContact($contact)
157  {
158  global $langs, $conf, $db, $user;
159 
160  $error = 0;
161 
162  $from = $user->getFullName($langs).' <'.$user->email.'>';
163 
164  $sendto = $contact->email;
165  $code = dol_hash($contact->email, 'md5');
166  if (!empty($contact->default_lang)) {
167  $l = $contact->default_lang;
168  } else {
169  $l = $langs->defaultlang;
170  }
171  // TODO Use a dolibarr email template
172  $s = "DATAPOLICYSUBJECT_".$l;
173  $ma = "DATAPOLICYCONTENT_".$l;
174  $la = 'TXTLINKDATAPOLICYACCEPT_'.$l;
175  $lr = 'TXTLINKDATAPOLICYREFUSE_'.$l;
176 
177  $subject = $conf->global->$s;
178  $message = $conf->global->$ma;
179  $linka = $conf->global->$la;
180  $linkr = $conf->global->$lr;
181  $sendtocc = $sendtobcc = '';
182  $filepath = $mimetype = $filename = array();
183  $deliveryreceipt = 0;
184 
185  $substitutionarray = array(
186  '__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>',
187  '__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>',
188  '__FIRSTNAME__' => $contact->firstname,
189  '__NAME__' => $contact->lastname,
190  '__CIVILITY__' => $contact->civility,
191  );
192  $subject = make_substitutions($subject, $substitutionarray);
193  $message = make_substitutions($message, $substitutionarray);
194 
195  $actiontypecode = 'AC_EMAIL';
196  $actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto;
197  if ($message) {
198  if ($sendtocc) {
199  $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc').": ".$sendtocc);
200  }
201  $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic').": ".$subject);
202  $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody').":");
203  $actionmsg = dol_concatdesc($actionmsg, $message);
204  }
205 
206 
207  // Send mail
208  require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
209  $mailfile = new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename, $sendtocc, $sendtobcc, $deliveryreceipt, -1);
210 
211  if ($mailfile->error) {
212  $resultmasssend .= '<div class="error">'.$mailfile->error.'</div>';
213  } else {
214  $result4 = $mailfile->sendfile();
215  if (!$error) {
216  $resultmasssend .= $langs->trans("MailSent").': '.$sendto."<br>";
217  $contact->array_options['options_datapolicy_send'] = date('Y-m-d', time());
218  $contact->update($contact->id);
219  } else {
220  dol_print_error($db);
221  }
222  }
223  setEventMessage($resultmasssend);
224  }
225 
232  public static function sendMailDataPolicyCompany($societe)
233  {
234  global $langs, $conf, $db, $user;
235 
236  $error = 0;
237 
238  $from = $user->getFullName($langs).' <'.$user->email.'>';
239 
240  $sendto = $societe->email;
241 
242  $code = dol_hash($societe->email, 'md5');
243  if (!empty($societe->default_lang)) {
244  $l = $societe->default_lang;
245  } else {
246  $l = $langs->defaultlang;
247  }
248  // TODO Use a dolibarr email template
249  $s = "DATAPOLICYSUBJECT_".$l;
250  $ma = "DATAPOLICYCONTENT_".$l;
251  $la = 'TXTLINKDATAPOLICYACCEPT_'.$l;
252  $lr = 'TXTLINKDATAPOLICYREFUSE_'.$l;
253 
254  $subject = $conf->global->$s;
255  $message = $conf->global->$ma;
256  $linka = $conf->global->$la;
257  $linkr = $conf->global->$lr;
258  $sendtocc = $sendtobcc = '';
259  $filepath = $mimetype = $filename = array();
260  $deliveryreceipt = 0;
261 
262  $substitutionarray = array(
263  '__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>',
264  '__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>',
265  );
266  $subject = make_substitutions($subject, $substitutionarray);
267  $message = make_substitutions($message, $substitutionarray);
268 
269  $actiontypecode = 'AC_EMAIL';
270  $actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto;
271  if ($message) {
272  if ($sendtocc) {
273  $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc').": ".$sendtocc);
274  }
275  $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic').": ".$subject);
276  $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody').":");
277  $actionmsg = dol_concatdesc($actionmsg, $message);
278  }
279 
280  // Send mail
281  require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
282  $mailfile = new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename, $sendtocc, $sendtobcc, $deliveryreceipt, -1);
283  if ($mailfile->error) {
284  $resultmasssend .= '<div class="error">'.$mailfile->error.'</div>';
285  } else {
286  $result4 = $mailfile->sendfile();
287 
288  if (!$error) {
289  $resultmasssend .= $langs->trans("MailSent").': '.$sendto."<br>";
290  $societe->array_options['options_datapolicy_send'] = date('Y-m-d', time());
291  $societe->update($societe->id);
292  } else {
293  dol_print_error($db);
294  }
295  }
296  setEventMessage($resultmasssend);
297  }
298 
305  public static function sendMailDataPolicyAdherent($adherent)
306  {
307  global $langs, $conf, $db, $user;
308 
309  $error = 0;
310 
311  $from = $user->getFullName($langs).' <'.$user->email.'>';
312 
313  $sendto = $adherent->email;
314 
315  $code = dol_hash($adherent->email, 'md5');
316  if (!empty($adherent->default_lang)) {
317  $l = $adherent->default_lang;
318  } else {
319  $l = $langs->defaultlang;
320  }
321  // TODO Use a dolibarr email template
322  $s = 'TXTLINKDATAPOLICYSUBJECT_'.$l;
323  $ma = 'TXTLINKDATAPOLICYMESSAGE_'.$l;
324  $la = 'TXTLINKDATAPOLICYACCEPT_'.$l;
325  $lr = 'TXTLINKDATAPOLICYREFUSE_'.$l;
326 
327  $subject = $conf->global->$s;
328  $message = $conf->global->$ma;
329  $linka = $conf->global->$la;
330  $linkr = $conf->global->$lr;
331  $sendtocc = $sendtobcc = '';
332  $filepath = $mimetype = $filename = array();
333  $deliveryreceipt = 0;
334 
335  $substitutionarray = array(
336  '__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>',
337  '__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>',
338  );
339  $subject = make_substitutions($subject, $substitutionarray);
340  $message = make_substitutions($message, $substitutionarray);
341 
342  $actiontypecode = 'AC_EMAIL';
343  $actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto;
344  if ($message) {
345  if ($sendtocc) {
346  $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc').": ".$sendtocc);
347  }
348  $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic').": ".$subject);
349  $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody').":");
350  $actionmsg = dol_concatdesc($actionmsg, $message);
351  }
352 
353 
354  // Send mail
355  require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
356  $mailfile = new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename, $sendtocc, $sendtobcc, $deliveryreceipt, -1);
357  if ($mailfile->error) {
358  $resultmasssend .= '<div class="error">'.$mailfile->error.'</div>';
359  } else {
360  $result4 = $mailfile->sendfile();
361 
362  if (!$error) {
363  $resultmasssend .= $langs->trans("MailSent").': '.$sendto."<br>";
364  $adherent->array_options['options_datapolicy_send'] = date('Y-m-d', time());
365  $adherent->update($user);
366  } else {
367  dol_print_error($db);
368  }
369  }
370  setEventMessage($resultmasssend);
371  }
372 }
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...)
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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...
setEventMessage($mesgs, $style='mesgs')
Set event message in dol_events session object.
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.
$conf db
API class for accounts.
Definition: inc.php:41