2018-10-06 02:51:47 +02:00
< ? php
2018-10-09 14:40:15 +02:00
/* Copyright ( C ) 2018 Nicolas ZABOURI < info @ inovea - conseil . com >
2024-03-03 18:55:30 +01:00
* Copyright ( C ) 2024 Frédéric France < frederic . france @ free . fr >
2024-10-03 19:40:34 +02:00
* Copyright ( C ) 2024 MDW < mdeweerd @ users . noreply . github . com >
2018-10-06 02:51:47 +02:00
*
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation , either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2018-10-06 02:51:47 +02:00
*/
/**
2018-10-15 14:04:42 +02:00
* \file datapolicy / class / datapolicy . class . php
* \ingroup datapolicy
* \brief Class to manage feature of Data Policy module .
2024-12-30 04:53:07 +01:00
* This class file is not used .
2018-10-06 02:51:47 +02:00
*/
2020-04-10 10:59:32 +02:00
include_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php' ;
include_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php' ;
include_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php' ;
2022-09-08 16:19:11 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/lib/security.lib.php' ;
2018-10-06 02:51:47 +02:00
2018-10-06 03:13:03 +02:00
2018-10-06 02:51:47 +02:00
/**
2018-10-15 14:04:42 +02:00
* Class DataPolicy
2018-10-06 02:51:47 +02:00
*/
2019-03-09 01:02:05 +01:00
class DataPolicy
2018-10-06 03:13:03 +02:00
{
2023-08-05 22:57:12 +02:00
/**
* @ var DoliDB Database handler .
*/
public $db ;
2024-10-03 19:40:34 +02:00
/**
* @ var string
*/
2023-08-05 22:57:12 +02:00
public $error ;
2019-09-06 19:41:15 +02:00
/**
* Constructor
*
* @ param DoliDB $db Database handler
*/
public function __construct ( $db )
{
$this -> db = $db ;
}
2020-10-31 14:32:18 +01:00
/**
* getAllContactNotInformed
*
2023-03-21 19:14:43 +01:00
* @ return integer
2020-10-31 14:32:18 +01:00
*/
public function getAllContactNotInformed ()
{
2024-12-30 04:53:07 +01:00
global $langs , $conf , $db ;
2020-10-31 14:32:18 +01:00
$langs -> load ( " companies " );
$sql = " SELECT c.rowid " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " socpeople as c " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " societe as s ON c.fk_soc = s.rowid " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " socpeople_extrafields as spe ON spe.fk_object = c.rowid " ;
2024-12-30 04:53:07 +01:00
$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)) " ;
2020-10-31 14:32:18 +01:00
$sql .= " AND spe.datapolicy_send IS NULL " ;
2024-12-30 04:53:07 +01:00
$sql .= " AND c.entity = " . (( int ) $conf -> entity );
2020-10-31 14:32:18 +01:00
$resql = $this -> db -> query ( $sql );
if ( $resql ) {
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
while ( $i < $num ) {
$obj = $this -> db -> fetch_object ( $resql );
$contact = new Contact ( $db );
$contact -> fetch ( $obj -> rowid );
DataPolicy :: sendMailDataPolicyContact ( $contact );
$i ++ ;
}
} else {
$this -> error = $this -> db -> error ();
return - 1 ;
}
2023-03-21 19:14:43 +01:00
return 1 ;
2020-10-31 14:32:18 +01:00
}
/**
* getAllCompaniesNotInformed
*
2023-03-21 19:14:43 +01:00
* @ return integer
2020-10-31 14:32:18 +01:00
*/
public function getAllCompaniesNotInformed ()
{
2024-12-30 04:53:07 +01:00
global $langs , $conf , $db ;
2020-10-31 14:32:18 +01:00
$langs -> load ( " companies " );
$sql = " SELECT s.rowid " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " societe as s " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " societe_extrafields as se ON se.fk_object = s.rowid " ;
2024-12-30 04:53:07 +01:00
$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) " ;
2020-10-31 14:32:18 +01:00
$sql .= " AND se.datapolicy_send IS NULL " ;
2024-12-30 04:53:07 +01:00
$sql .= " AND s.entity = " . (( int ) $conf -> entity );
2020-10-31 14:32:18 +01:00
$resql = $this -> db -> query ( $sql );
if ( $resql ) {
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
while ( $i < $num ) {
$obj = $this -> db -> fetch_object ( $resql );
$societe = new Societe ( $db );
$societe -> fetch ( $obj -> rowid );
DataPolicy :: sendMailDataPolicyCompany ( $societe );
$i ++ ;
}
} else {
$this -> error = $this -> db -> error ();
return - 1 ;
}
2023-03-21 19:14:43 +01:00
return 1 ;
2020-10-31 14:32:18 +01:00
}
/**
* getAllAdherentsNotInformed
*
2023-03-21 19:14:43 +01:00
* @ return integer
2020-10-31 14:32:18 +01:00
*/
public function getAllAdherentsNotInformed ()
{
2024-12-30 04:53:07 +01:00
global $langs , $conf , $db ;
2020-10-31 14:32:18 +01:00
$langs -> load ( " adherent " );
$sql = " SELECT a.rowid " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " adherent as a " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " adherent_extrafields as ae ON ae.fk_object = a.rowid " ;
2024-12-30 04:53:07 +01:00
$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) " ;
2020-10-31 14:32:18 +01:00
$sql .= " AND ae.datapolicy_send IS NULL " ;
2024-12-30 04:53:07 +01:00
$sql .= " AND a.entity = " . (( int ) $conf -> entity );
2020-10-31 14:32:18 +01:00
$resql = $this -> db -> query ( $sql );
if ( $resql ) {
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
while ( $i < $num ) {
$obj = $this -> db -> fetch_object ( $resql );
$adherent = new Adherent ( $db );
$adherent -> fetch ( $obj -> rowid );
DataPolicy :: sendMailDataPolicyAdherent ( $adherent );
$i ++ ;
}
} else {
$this -> error = $this -> db -> error ();
return - 1 ;
}
2023-03-21 19:14:43 +01:00
return 1 ;
2020-10-31 14:32:18 +01:00
}
/**
* sendMailDataPolicyContact
*
2024-10-03 19:40:34 +02:00
* @ param Contact $contact Contact
2020-10-31 14:32:18 +01:00
* @ return void
*/
public static function sendMailDataPolicyContact ( $contact )
{
2024-12-30 04:53:07 +01:00
global $langs , $db , $user ;
2020-10-31 14:32:18 +01:00
$error = 0 ;
$from = $user -> getFullName ( $langs ) . ' <' . $user -> email . '>' ;
$sendto = $contact -> email ;
2022-09-08 16:19:11 +02:00
$code = dol_hash ( $contact -> email , 'md5' );
2020-10-31 14:32:18 +01:00
if ( ! empty ( $contact -> default_lang )) {
$l = $contact -> default_lang ;
} else {
$l = $langs -> defaultlang ;
}
// TODO Use a dolibarr email template
2022-09-08 16:19:11 +02:00
$s = " DATAPOLICYSUBJECT_ " . $l ;
$ma = " DATAPOLICYCONTENT_ " . $l ;
$la = 'TXTLINKDATAPOLICYACCEPT_' . $l ;
$lr = 'TXTLINKDATAPOLICYREFUSE_' . $l ;
2020-10-31 14:32:18 +01:00
2024-01-05 03:41:22 +01:00
$subject = getDolGlobalString ( $s );
$message = getDolGlobalString ( $ma );
$linka = getDolGlobalString ( $la );
$linkr = getDolGlobalString ( $lr );
2020-10-31 14:32:18 +01:00
$sendtocc = $sendtobcc = '' ;
$filepath = $mimetype = $filename = array ();
$deliveryreceipt = 0 ;
$substitutionarray = array (
2022-09-08 16:19:11 +02:00
'__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>' ,
'__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>' ,
2020-10-31 14:32:18 +01:00
'__FIRSTNAME__' => $contact -> firstname ,
'__NAME__' => $contact -> lastname ,
'__CIVILITY__' => $contact -> civility ,
);
$subject = make_substitutions ( $subject , $substitutionarray );
$message = make_substitutions ( $message , $substitutionarray );
$actiontypecode = 'AC_EMAIL' ;
2024-03-28 09:38:09 +01:00
$actionmsg = $langs -> transnoentities ( 'MailSentByTo' , $from , $sendto );
2020-10-31 14:32:18 +01:00
if ( $message ) {
2021-02-25 22:09:10 +01:00
if ( $sendtocc ) {
2020-10-31 14:32:18 +01:00
$actionmsg = dol_concatdesc ( $actionmsg , $langs -> transnoentities ( 'Bcc' ) . " : " . $sendtocc );
2021-02-25 22:09:10 +01:00
}
2023-12-04 12:12:12 +01:00
$actionmsg = dol_concatdesc ( $actionmsg , $langs -> transnoentities ( 'MailTopic' ) . " : " . $subject );
$actionmsg = dol_concatdesc ( $actionmsg , $langs -> transnoentities ( 'TextUsedInTheMessageBody' ) . " : " );
$actionmsg = dol_concatdesc ( $actionmsg , $message );
2020-10-31 14:32:18 +01:00
}
// Send mail
require_once DOL_DOCUMENT_ROOT . '/core/class/CMailFile.class.php' ;
$mailfile = new CMailFile ( $subject , $sendto , $from , $message , $filepath , $mimetype , $filename , $sendtocc , $sendtobcc , $deliveryreceipt , - 1 );
2023-08-10 11:42:59 +02:00
$resultmasssend = '' ;
2020-10-31 14:32:18 +01:00
if ( $mailfile -> error ) {
$resultmasssend .= '<div class="error">' . $mailfile -> error . '</div>' ;
} else {
2023-08-10 11:42:59 +02:00
$resultmail = $mailfile -> sendfile ();
if ( $resultmail ) {
2020-10-31 14:32:18 +01:00
$resultmasssend .= $langs -> trans ( " MailSent " ) . ': ' . $sendto . " <br> " ;
$contact -> array_options [ 'options_datapolicy_send' ] = date ( 'Y-m-d' , time ());
$contact -> update ( $contact -> id );
} else {
dol_print_error ( $db );
}
}
setEventMessage ( $resultmasssend );
}
/**
* sendMailDataPolicyCompany
*
* @ param Societe $societe Object societe
* @ return void
*/
public static function sendMailDataPolicyCompany ( $societe )
{
2024-12-30 04:53:07 +01:00
global $langs , $db , $user ;
2020-10-31 14:32:18 +01:00
$error = 0 ;
$from = $user -> getFullName ( $langs ) . ' <' . $user -> email . '>' ;
$sendto = $societe -> email ;
2022-09-08 16:19:11 +02:00
$code = dol_hash ( $societe -> email , 'md5' );
2020-10-31 14:32:18 +01:00
if ( ! empty ( $societe -> default_lang )) {
$l = $societe -> default_lang ;
} else {
$l = $langs -> defaultlang ;
}
// TODO Use a dolibarr email template
2022-09-08 16:19:11 +02:00
$s = " DATAPOLICYSUBJECT_ " . $l ;
$ma = " DATAPOLICYCONTENT_ " . $l ;
$la = 'TXTLINKDATAPOLICYACCEPT_' . $l ;
$lr = 'TXTLINKDATAPOLICYREFUSE_' . $l ;
2020-10-31 14:32:18 +01:00
2024-01-05 03:41:22 +01:00
$subject = getDolGlobalString ( $s );
$message = getDolGlobalString ( $ma );
$linka = getDolGlobalString ( $la );
$linkr = getDolGlobalString ( $lr );
2020-10-31 14:32:18 +01:00
$sendtocc = $sendtobcc = '' ;
$filepath = $mimetype = $filename = array ();
$deliveryreceipt = 0 ;
$substitutionarray = array (
2022-09-08 16:19:11 +02:00
'__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>' ,
'__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>' ,
2020-10-31 14:32:18 +01:00
);
$subject = make_substitutions ( $subject , $substitutionarray );
$message = make_substitutions ( $message , $substitutionarray );
$actiontypecode = 'AC_EMAIL' ;
2024-03-28 09:38:09 +01:00
$actionmsg = $langs -> transnoentities ( 'MailSentByTo' , $from , $sendto );
2020-10-31 14:32:18 +01:00
if ( $message ) {
if ( $sendtocc ) {
2023-12-04 12:12:12 +01:00
$actionmsg = dol_concatdesc ( $actionmsg , $langs -> transnoentities ( 'Bcc' ) . " : " . $sendtocc );
2020-10-31 14:32:18 +01:00
}
2021-11-11 15:35:34 +01:00
$actionmsg = dol_concatdesc ( $actionmsg , $langs -> transnoentities ( 'MailTopic' ) . " : " . $subject );
$actionmsg = dol_concatdesc ( $actionmsg , $langs -> transnoentities ( 'TextUsedInTheMessageBody' ) . " : " );
$actionmsg = dol_concatdesc ( $actionmsg , $message );
2020-10-31 14:32:18 +01:00
}
// Send mail
require_once DOL_DOCUMENT_ROOT . '/core/class/CMailFile.class.php' ;
$mailfile = new CMailFile ( $subject , $sendto , $from , $message , $filepath , $mimetype , $filename , $sendtocc , $sendtobcc , $deliveryreceipt , - 1 );
2023-08-10 11:42:59 +02:00
$resultmasssend = '' ;
2020-10-31 14:32:18 +01:00
if ( $mailfile -> error ) {
$resultmasssend .= '<div class="error">' . $mailfile -> error . '</div>' ;
} else {
2023-08-10 11:42:59 +02:00
$resultmail = $mailfile -> sendfile ();
2020-10-31 14:32:18 +01:00
2023-08-10 11:42:59 +02:00
if ( $resultmail ) {
2020-10-31 14:32:18 +01:00
$resultmasssend .= $langs -> trans ( " MailSent " ) . ': ' . $sendto . " <br> " ;
$societe -> array_options [ 'options_datapolicy_send' ] = date ( 'Y-m-d' , time ());
2024-03-03 18:55:30 +01:00
$societe -> update ( $societe -> id , $user );
2020-10-31 14:32:18 +01:00
} else {
dol_print_error ( $db );
}
}
setEventMessage ( $resultmasssend );
}
/**
* sendMailDataPolicyAdherent
*
* @ param Adherent $adherent Member
* @ return void
*/
public static function sendMailDataPolicyAdherent ( $adherent )
{
2024-12-30 04:53:07 +01:00
global $langs , $db , $user ;
2020-10-31 14:32:18 +01:00
$error = 0 ;
$from = $user -> getFullName ( $langs ) . ' <' . $user -> email . '>' ;
$sendto = $adherent -> email ;
2022-09-08 16:19:11 +02:00
$code = dol_hash ( $adherent -> email , 'md5' );
2020-10-31 14:32:18 +01:00
if ( ! empty ( $adherent -> default_lang )) {
$l = $adherent -> default_lang ;
} else {
$l = $langs -> defaultlang ;
}
// TODO Use a dolibarr email template
2022-09-08 16:19:11 +02:00
$s = 'TXTLINKDATAPOLICYSUBJECT_' . $l ;
$ma = 'TXTLINKDATAPOLICYMESSAGE_' . $l ;
$la = 'TXTLINKDATAPOLICYACCEPT_' . $l ;
$lr = 'TXTLINKDATAPOLICYREFUSE_' . $l ;
2020-10-31 14:32:18 +01:00
2024-01-05 03:41:22 +01:00
$subject = getDolGlobalString ( $s );
$message = getDolGlobalString ( $ma );
$linka = getDolGlobalString ( $la );
$linkr = getDolGlobalString ( $lr );
2020-10-31 14:32:18 +01:00
$sendtocc = $sendtobcc = '' ;
$filepath = $mimetype = $filename = array ();
$deliveryreceipt = 0 ;
$substitutionarray = array (
2022-09-08 16:19:11 +02:00
'__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>' ,
'__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>' ,
2020-10-31 14:32:18 +01:00
);
$subject = make_substitutions ( $subject , $substitutionarray );
$message = make_substitutions ( $message , $substitutionarray );
$actiontypecode = 'AC_EMAIL' ;
2024-03-28 09:38:09 +01:00
$actionmsg = $langs -> transnoentities ( 'MailSentByTo' , $from , $sendto );
2020-10-31 14:32:18 +01:00
if ( $message ) {
if ( $sendtocc ) {
2021-11-11 15:35:34 +01:00
$actionmsg = dol_concatdesc ( $actionmsg , $langs -> transnoentities ( 'Bcc' ) . " : " . $sendtocc );
2020-10-31 14:32:18 +01:00
}
2021-11-11 15:35:34 +01:00
$actionmsg = dol_concatdesc ( $actionmsg , $langs -> transnoentities ( 'MailTopic' ) . " : " . $subject );
$actionmsg = dol_concatdesc ( $actionmsg , $langs -> transnoentities ( 'TextUsedInTheMessageBody' ) . " : " );
$actionmsg = dol_concatdesc ( $actionmsg , $message );
2020-10-31 14:32:18 +01:00
}
// Send mail
require_once DOL_DOCUMENT_ROOT . '/core/class/CMailFile.class.php' ;
$mailfile = new CMailFile ( $subject , $sendto , $from , $message , $filepath , $mimetype , $filename , $sendtocc , $sendtobcc , $deliveryreceipt , - 1 );
2023-10-10 23:52:46 +02:00
$resultmasssend = '' ;
2020-10-31 14:32:18 +01:00
if ( $mailfile -> error ) {
$resultmasssend .= '<div class="error">' . $mailfile -> error . '</div>' ;
} else {
2023-08-10 11:42:59 +02:00
$resultmail = $mailfile -> sendfile ();
2020-10-31 14:32:18 +01:00
2023-08-10 11:42:59 +02:00
if ( $resultmail ) {
2020-10-31 14:32:18 +01:00
$resultmasssend .= $langs -> trans ( " MailSent " ) . ': ' . $sendto . " <br> " ;
$adherent -> array_options [ 'options_datapolicy_send' ] = date ( 'Y-m-d' , time ());
$adherent -> update ( $user );
} else {
dol_print_error ( $db );
}
}
setEventMessage ( $resultmasssend );
}
2018-10-06 02:51:47 +02:00
}