dolibarr  13.0.2
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 
27 
32 {
38  public function __construct($db)
39  {
40  $this->db = $db;
41  }
42 
48  public function getAllContactNotInformed()
49  {
50  global $langs, $conf, $db, $user;
51 
52  $langs->load("companies");
53 
54  $sql = "SELECT c.rowid";
55  $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as c";
56  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON c.fk_soc = s.rowid";
57  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople_extrafields as spe ON spe.fk_object = c.rowid";
58  $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))";
59  $sql .= " AND spe.datapolicy_send IS NULL";
60  $sql .= " AND c.entity=".$conf->entity;
61  $resql = $this->db->query($sql);
62  if ($resql) {
63  $num = $this->db->num_rows($resql);
64  $i = 0;
65  while ($i < $num) {
66  $obj = $this->db->fetch_object($resql);
67  $contact = new Contact($db);
68  $contact->fetch($obj->rowid);
69 
71  $i++;
72  }
73  } else {
74  $this->error = $this->db->error();
75  return -1;
76  }
77  }
78 
84  public function getAllCompaniesNotInformed()
85  {
86  global $langs, $conf, $db, $user;
87 
88  $langs->load("companies");
89 
90  $sql = "SELECT s.rowid";
91  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
92  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_extrafields as se ON se.fk_object = s.rowid";
93  $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)";
94  $sql .= " AND se.datapolicy_send IS NULL";
95  $sql .= " AND s.entity=".$conf->entity;
96  $resql = $this->db->query($sql);
97  if ($resql) {
98  $num = $this->db->num_rows($resql);
99  $i = 0;
100  while ($i < $num) {
101  $obj = $this->db->fetch_object($resql);
102  $societe = new Societe($db);
103  $societe->fetch($obj->rowid);
104 
106  $i++;
107  }
108  } else {
109  $this->error = $this->db->error();
110  return -1;
111  }
112  }
113 
119  public function getAllAdherentsNotInformed()
120  {
121  global $langs, $conf, $db, $user;
122 
123  $langs->load("adherent");
124 
125  $sql = "SELECT a.rowid";
126  $sql .= " FROM ".MAIN_DB_PREFIX."adherent as a";
127  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."adherent_extrafields as ae ON ae.fk_object = a.rowid";
128  $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)";
129  $sql .= " AND ae.datapolicy_send IS NULL";
130  $sql .= " AND a.entity=".$conf->entity;
131  $resql = $this->db->query($sql);
132  if ($resql) {
133  $num = $this->db->num_rows($resql);
134  $i = 0;
135  while ($i < $num) {
136  $obj = $this->db->fetch_object($resql);
137  $adherent = new Adherent($db);
138  $adherent->fetch($obj->rowid);
139 
141  $i++;
142  }
143  } else {
144  $this->error = $this->db->error();
145  return -1;
146  }
147  }
148 
155  public static function sendMailDataPolicyContact($contact)
156  {
157  global $langs, $conf, $db, $user;
158 
159  $error = 0;
160 
161  $from = $user->getFullName($langs).' <'.$user->email.'>';
162 
163  $sendto = $contact->email;
164  $code = md5($contact->email);
165  if (!empty($contact->default_lang)) {
166  $l = $contact->default_lang;
167  } else {
168  $l = $langs->defaultlang;
169  }
170  // TODO Use a dolibarr email template
171  $s = "DATAPOLICIESSUBJECT_".$l;
172  $ma = "DATAPOLICIESCONTENT_".$l;
173  $la = 'TXTLINKDATAPOLICIESACCEPT_'.$l;
174  $lr = 'TXTLINKDATAPOLICIESREFUSE_'.$l;
175 
176  $subject = $conf->global->$s;
177  $message = $conf->global->$ma;
178  $linka = $conf->global->$la;
179  $linkr = $conf->global->$lr;
180  $sendtocc = $sendtobcc = '';
181  $filepath = $mimetype = $filename = array();
182  $deliveryreceipt = 0;
183 
184  $substitutionarray = array(
185  '__LINKACCEPT__' => '<a href="'.dol_buildpath('/datapolicy/public/index.php?action=1&c='.$contact->id.'&l='.$l.'&key='.$code, 3).'" target="_blank">'.$linka.'</a>',
186  '__LINKREFUSED__' => '<a href="'.dol_buildpath('/datapolicy/public/index.php?action=2&c='.$contact->id.'&l='.$l.'&key='.$code, 3).'" target="_blank">'.$linkr.'</a>',
187  '__FIRSTNAME__' => $contact->firstname,
188  '__NAME__' => $contact->lastname,
189  '__CIVILITY__' => $contact->civility,
190  );
191  $subject = make_substitutions($subject, $substitutionarray);
192  $message = make_substitutions($message, $substitutionarray);
193 
194  $actiontypecode = 'AC_EMAIL';
195  $actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto;
196  if ($message) {
197  if ($sendtocc)
198  $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc').": ".$sendtocc);
199  $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic').": ".$subject);
200  $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody').":");
201  $actionmsg = dol_concatdesc($actionmsg, $message);
202  }
203 
204 
205  // Send mail
206  require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
207  $mailfile = new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename, $sendtocc, $sendtobcc, $deliveryreceipt, -1);
208 
209  if ($mailfile->error) {
210  $resultmasssend .= '<div class="error">'.$mailfile->error.'</div>';
211  } else {
212  $result4 = $mailfile->sendfile();
213  if (!$error) {
214  $resultmasssend .= $langs->trans("MailSent").': '.$sendto."<br>";
215  $contact->array_options['options_datapolicy_send'] = date('Y-m-d', time());
216  $contact->update($contact->id);
217  } else {
218  dol_print_error($db);
219  }
220  }
221  setEventMessage($resultmasssend);
222  }
223 
230  public static function sendMailDataPolicyCompany($societe)
231  {
232  global $langs, $conf, $db, $user;
233 
234  $error = 0;
235 
236  $from = $user->getFullName($langs).' <'.$user->email.'>';
237 
238  $sendto = $societe->email;
239 
240  $code = md5($societe->email);
241  if (!empty($societe->default_lang)) {
242  $l = $societe->default_lang;
243  } else {
244  $l = $langs->defaultlang;
245  }
246  // TODO Use a dolibarr email template
247  $s = "DATAPOLICIESSUBJECT_".$l;
248  $ma = "DATAPOLICIESCONTENT_".$l;
249  $la = 'TXTLINKDATAPOLICIESACCEPT_'.$l;
250  $lr = 'TXTLINKDATAPOLICIESREFUSE_'.$l;
251 
252  $subject = $conf->global->$s;
253  $message = $conf->global->$ma;
254  $linka = $conf->global->$la;
255  $linkr = $conf->global->$lr;
256  $sendtocc = $sendtobcc = '';
257  $filepath = $mimetype = $filename = array();
258  $deliveryreceipt = 0;
259 
260  $substitutionarray = array(
261  '__LINKACCEPT__' => '<a href="'.dol_buildpath('/datapolicy/public/index.php?action=1&s='.$societe->id.'&l='.$l.'&key='.$code, 3).'" target="_blank">'.$linka.'</a>',
262  '__LINKREFUSED__' => '<a href="'.dol_buildpath('/datapolicy/public/index.php?action=2&s='.$societe->id.'&l='.$l.'&key='.$code, 3).'" target="_blank">'.$linkr.'</a>',
263  );
264  $subject = make_substitutions($subject, $substitutionarray);
265  $message = make_substitutions($message, $substitutionarray);
266 
267  $actiontypecode = 'AC_EMAIL';
268  $actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto;
269  if ($message) {
270  if ($sendtocc) {
271  $actionmsg .= dol_concatdesc($actionmsg, $langs->transnoentities('Bcc').": ".$sendtocc);
272  }
273  $actionmsg .= dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic').": ".$subject);
274  $actionmsg .= dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody').":");
275  $actionmsg .= dol_concatdesc($actionmsg, $message);
276  }
277 
278  // Send mail
279  require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
280  $mailfile = new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename, $sendtocc, $sendtobcc, $deliveryreceipt, -1);
281  if ($mailfile->error) {
282  $resultmasssend .= '<div class="error">'.$mailfile->error.'</div>';
283  } else {
284  $result4 = $mailfile->sendfile();
285 
286  if (!$error) {
287  $resultmasssend .= $langs->trans("MailSent").': '.$sendto."<br>";
288  $societe->array_options['options_datapolicy_send'] = date('Y-m-d', time());
289  $societe->update($societe->id);
290  } else {
291  dol_print_error($db);
292  }
293  }
294  setEventMessage($resultmasssend);
295  }
296 
303  public static function sendMailDataPolicyAdherent($adherent)
304  {
305  global $langs, $conf, $db, $user;
306 
307  $error = 0;
308 
309  $from = $user->getFullName($langs).' <'.$user->email.'>';
310 
311  $sendto = $adherent->email;
312 
313 
314  $code = md5($adherent->email);
315  if (!empty($adherent->default_lang)) {
316  $l = $adherent->default_lang;
317  } else {
318  $l = $langs->defaultlang;
319  }
320  // TODO Use a dolibarr email template
321  $s = 'TXTLINKDATAPOLICIESSUBJECT_'.$l;
322  $ma = 'TXTLINKDATAPOLICIESMESSAGE_'.$l;
323  $la = 'TXTLINKDATAPOLICIESACCEPT_'.$l;
324  $lr = 'TXTLINKDATAPOLICIESREFUSE_'.$l;
325 
326  $subject = $conf->global->$s;
327  $message = $conf->global->$ma;
328  $linka = $conf->global->$la;
329  $linkr = $conf->global->$lr;
330  $sendtocc = $sendtobcc = '';
331  $filepath = $mimetype = $filename = array();
332  $deliveryreceipt = 0;
333 
334  $substitutionarray = array(
335  '__LINKACCEPT__' => '<a href="'.dol_buildpath('/datapolicy/public/index.php?action=1&a='.$adherent->id.'&l='.$l.'&key='.$code, 3).'" target="_blank">'.$linka.'</a>',
336  '__LINKREFUSED__' => '<a href="'.dol_buildpath('/datapolicy/public/index.php?action=2&a='.$adherent->id.'&l='.$l.'&key='.$code, 3).'" target="_blank">'.$linkr.'</a>',
337  );
338  $subject = make_substitutions($subject, $substitutionarray);
339  $message = make_substitutions($message, $substitutionarray);
340 
341  $actiontypecode = 'AC_EMAIL';
342  $actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto;
343  if ($message) {
344  if ($sendtocc) {
345  $actionmsg .= dol_concatdesc($actionmsg, $langs->transnoentities('Bcc').": ".$sendtocc);
346  }
347  $actionmsg .= dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic').": ".$subject);
348  $actionmsg .= dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody').":");
349  $actionmsg .= dol_concatdesc($actionmsg, $message);
350  }
351 
352 
353  // Send mail
354  require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
355  $mailfile = new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename, $sendtocc, $sendtobcc, $deliveryreceipt, -1);
356  if ($mailfile->error) {
357  $resultmasssend .= '<div class="error">'.$mailfile->error.'</div>';
358  } else {
359  $result4 = $mailfile->sendfile();
360 
361  if (!$error) {
362  $resultmasssend .= $langs->trans("MailSent").': '.$sendto."<br>";
363  $adherent->array_options['options_datapolicy_send'] = date('Y-m-d', time());
364  $adherent->update($user);
365  } else {
366  dol_print_error($db);
367  }
368  }
369  setEventMessage($resultmasssend);
370  }
371 }
Class to manage contact/addresses.
setEventMessage($mesgs, $style= 'mesgs')
Set event message in dol_events session object.
getAllContactNotInformed()
getAllContactNotInformed
getAllCompaniesNotInformed()
getAllCompaniesNotInformed
static sendMailDataPolicyContact($contact)
sendMailDataPolicyContact
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...
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
$conf db
API class for accounts.
Definition: inc.php:54
Class to manage third parties objects (customers, suppliers, prospects...)
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,$sendto,$replyto,$message,$filepath,$mimetype,$filename,$cc,$ccc,$deliveryreceipt,$msgishtml,$errors_to,$css,$trackid,$moreinheader,$sendcontext,$replyto); $mailfile-&gt;sendfile();.
Class to manage members of a foundation.
static sendMailDataPolicyAdherent($adherent)
sendMailDataPolicyAdherent
static sendMailDataPolicyCompany($societe)
sendMailDataPolicyCompany
__construct($db)
Constructor.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getAllAdherentsNotInformed()
getAllAdherentsNotInformed
Class DataPolicy.
make_substitutions($text, $substitutionarray, $outputlangs=null)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=&gt;newva...