PHP Code:
<?php
/**
* customerGdpr Class.
* This class is used to manage customers RGPD compliance
*
* @package classes
*/
class CustomerGdpr extends base {
private $has_accepted = false;
private $was_notify = false;
private $was_notify_date = '';
var $users_delete_request = '';
function __construct() {
global $zco_notifier;
$notifyme = array();
// if not redirects to account page
$notifyme[] = 'NOTIFY_LOGIN_SUCCESS';
// Now the customer can agree or not. Either way it was a record is inserted in DB
$notifyme[] = 'NOTIFY_HEADER_END_ACCOUNT';
// Inserts privacy policy into DB at registration page
$notifyme[] = 'NOTIFY_MODULE_CREATE_ACCOUNT_ADDED_CUSTOMER_RECORD';
$this->attach($this, $notifyme);
if($_SESSION['customers_delete_account_request']==1) {
$this->users_delete_request = true;
}
}
/**
* NOTIFY_LOGIN_SUCCESS
* Verifica se o cliente já concordou com a RGPD.
*/
public function updateNotifyLoginSuccess(&$callingClass, $notifier, $paramsArray) {
global $db, $messageStack;
if ($_SESSION['customer_rgpd'] =='' && $_SESSION['customer_rgpd_notified'] == '') {
$customer_id = $_SESSION['customer_id'];
$customers_info = $db->Execute("SELECT customers_info_date_account_created FROM " . TABLE_CUSTOMERS_INFO . " WHERE customers_info_id=" . (int)$customer_id. ";");
$sql = " SELECT * FROM ".TABLE_CUSTOMERS_GDPR." WHERE customers_id = :customers_id: ";
$sql = $db->bindVars($sql , ':customers_id:', $_SESSION['customer_id'], 'integer');
$res = $db->Execute($sql);
if ($res->RecordCount() == 0) {
$sql = "INSERT INTO ".TABLE_CUSTOMERS_GDPR." VALUES (:customers_id:, :customers_account_created_date:, :customers_accept_terms:, :customers_accept_terms_date:, :customers_was_notify_date:, :customers_delete_account_request:)";
$sql = $db->bindVars($sql , ':customers_id:', $customer_id, 'integer');
$sql = $db->bindVars($sql, ':customers_account_created_date:', $customers_info->fields['customers_info_date_account_created'], 'date');
$sql = $db->bindVars($sql, ':customers_accept_terms:', '0', 'integer');
$sql = $db->bindVars($sql, ':customers_accept_terms_date:', 'NULL', 'string');
$sql = $db->bindVars($sql, ':customers_was_notify_date:', 'NOW()', 'noquotestring');
$sql = $db->bindVars($sql, ':customers_delete_account_request:', '0', 'integer');
$res = $db->Execute($sql);
$_SESSION['customer_rgpd_notified'] = true;
//$messageStack->add_session('site_notifications', $this->displayRgpdMsg(), 'caution');
}
} elseif ($_SESSION['customer_rgpd'] =='0' && $_SESSION['customer_rgpd_notified'] !== '') {
//$messageStack->add_session('site_notifications', $this->displayRgpdMsg(), 'caution');
}
}
/**
* Inserir politica de privacidade no registo do cliente
*/
public function updateCreateAccountAddedCustomerRecord(&$callingClass, $notifier, $paramsArray) {
global $db;
$customer_id = $_SESSION['customer_id'];
$sql = "INSERT INTO ".TABLE_CUSTOMERS_GDPR." VALUES (:customers_id:, :customers_account_created_date:, :customers_accept_terms:, :customers_accept_terms_date:, :customers_was_notify_date:, :customers_delete_account_request:)";
$sql = $db->bindVars($sql , ':customers_id:', $customer_id, 'integer');
$sql = $db->bindVars($sql, ':customers_account_created_date:', 'NOW()', 'noquotestring');
$sql = $db->bindVars($sql, ':customers_accept_terms:', '1', 'integer');
$sql = $db->bindVars($sql, ':customers_accept_terms_date:', 'NOW()', 'noquotestring');
$sql = $db->bindVars($sql, ':customers_was_notify_date:', 'NOW()', 'noquotestring');
$sql = $db->bindVars($sql, ':customers_delete_account_request:', '0', 'integer');
$res = $db->Execute($sql);
unset($sql, $res);
}
// Notifier user account page
public function updateHeaderEndAccount(&$callingClass, $notifier, $paramsArray) {
global $db, $customer_newsletter_status;
global $messageStack;
$customer_id = $_SESSION['customer_id'];
if ( $_SESSION['customer_rgpd'] == '' ) {
if (isset($_POST) && ($_POST['privacy_conditions'] =='1')) {
$_SESSION['customer_rgpd'] = true;
$customers_info = $db->Execute("SELECT customers_info_date_account_created FROM " . TABLE_CUSTOMERS_INFO . " WHERE customers_info_id=" . (int)$customer_id. ";");
$sql = " SELECT * FROM ".TABLE_CUSTOMERS_GDPR." WHERE customers_id = :customers_id: ";
$sql = $db->bindVars($sql , ':customers_id:', $customer_id, 'integer');
$res = $db->Execute($sql);
if ($res->RecordCount() > 0) {
$sql_up = "UPDATE ".TABLE_CUSTOMERS_GDPR." SET customers_id = :customers_id:, customers_account_created_date= :customers_account_created_date:, customers_accept_terms = :customers_accept_terms:, customers_accept_terms_date = :customers_accept_terms_date:, customers_was_notify_date = :customers_was_notify_date: WHERE customers_id = :customers_id:";
$sql_up = $db->bindVars($sql_up , ':customers_id:', $customer_id, 'integer');
$sql_up = $db->bindVars($sql_up, ':customers_account_created_date:', $customers_info->fields['customers_info_date_account_created'], 'date');
$sql_up = $db->bindVars($sql_up, ':customers_accept_terms:', '1', 'integer');
$sql_up = $db->bindVars($sql_up, ':customers_accept_terms_date:', 'NOW()', 'noquotestring');
$sql_up = $db->bindVars($sql_up, ':customers_was_notify_date:', 'NOW()', 'noquotestring');
$res_up = $db->Execute($sql_up);
$messageStack->add_session('site_notifications', 'Obrigado por Actualizar!', 'caution');
}
//Send Emails
$to_name = STORE_NAME;
$to_address = EMAIL_FROM;
$email_subject = "Cliente Aceita Politica de privacidade";
$email_text = "------------------------------------------------------------"."\n";
$email_text .= "O Cliente " .$customer_id." aceitou politica de privacidade"."\n";
$email_text .= "-----------------------------------------------------------"."\n";
$from_email_name = STORE_NAME;
$from_email_address = EMAIL_FROM;
$html_msg['EMAIL_MESSAGE_HTML'] = strip_tags($_POST['privacy_conditions']);
zen_mail($to_name, $to_address, $email_subject, $email_text, $from_email_name, $from_email_address, $html_msg );
}
unset($sql, $res, $sql_up, $res_up,$_POST['privacy_conditions']);
}
//DELETE ACCOUNT
if (isset($_POST) && ($_POST['action'] == 'delete_customer_account')) {
$_SESSION['customers_delete_account_request'] == '1';
//Collect Customer Info
$sql = "SELECT customers_firstname, customers_lastname, customers_email_address, customers_email_format FROM ".TABLE_CUSTOMERS." WHERE customers_id = :customers_id:";
$sql = $db->bindVars($sql , ':customers_id:', $customer_id, 'integer');
$res = $db->Execute($sql);
$customer_name = $res->fields['customers_firstname']. ' '. $res->fields['customers_lastname'];
$email_address = $res->fields['customers_email_address'];
//SEND MAIL TO CUSTOMER
$to_name = $customer_name;
$to_address = $email_address;
$email_subject = "Pedido para Apagar a Conta na Livraria PromoBooks";
$email_text = "Olá ".$customer_name." Recebemos um pedido para apagar a sua conta na Livraria PromoBooks"."\n";
$email_text .= "Gostariamos que continuasse connosco, mas vamos proceder à eliminação da conta no prazo máximo de 20 dias"."\n\n";
$email_text .= "Todos os dados serão eliminados da Loja Online."."\n";
$email_text .= "Caso tenha efectuado encomendas, os dados relativos a facturação continuarão na LUNADIL UNIPESSOAL LDA, ao abrigo da lei portuguesa."."\n";
$email_text .= "Se pensa que este email é um engano, ou tem outras questões, por favor entre em contacto connosco"."\n";
$email_text .= "------------------------------------------------------"."\n\n";
$from_email_name = STORE_NAME;
$from_email_address = EMAIL_FROM;
zen_mail($to_name, $to_address, $email_subject, $email_text, $from_email_name, $from_email_address );
$email_text_to_admin = "Pedido para apagar conta de ".$customer_name." com o ID:".$customer_id." ";
zen_mail(STORE_NAME, EMAIL_FROM, $email_subject , $email_text_to_admin , STORE_NAME, EMAIL_FROM, $html_msg, 'welcome_extra');
// Insere pedido na base de dados
$sql_del_account = "UPDATE ".TABLE_CUSTOMERS_GDPR." SET customers_delete_account_request = :customers_delete_account_request: WHERE customers_id = :customers_id:";
$sql_del_account = $db->bindVars($sql_del_account , ':customers_delete_account_request:', '1', 'integer');
$sql_del_account = $db->bindVars($sql_del_account , ':customers_id:', $customer_id, 'integer');
$res_del_account = $db->Execute($sql_del_account);
}
//Informa cliente das sua subscrição em newsletter
$sql = " SELECT customers_newsletter FROM ".TABLE_CUSTOMERS." WHERE customers_id = :customers_id: ";
$sql = $db->bindVars($sql, ':customers_id:', $customer, 'integer');
$res = $db->Execute($sql);
//pr($res);
$customer_newsletter_status = $res->fields['customers_newsletter'];
}
function update(&$callingClass, $notifier, $paramsArray)
{
if ( $notifier == 'NOTIFY_LOGIN_SUCCESS' ) {
$this->updateNotifyLoginSuccess($callingClass, $notifier, $paramsArray);
}
if ( $notifier == 'NOTIFY_MODULE_CREATE_ACCOUNT_ADDED_CUSTOMER_RECORD' ) {
$this->updateCreateAccountAddedCustomerRecord($callingClass, $notifier, $paramsArray);
}
if ( $notifier == 'NOTIFY_HEADER_END_ACCOUNT' ) {
$this->updateHeaderEndAccount($callingClass, $notifier, $paramsArray);
}
}
}
INIT_SCRIPT
PHP Code:
<?php
if (!defined('IS_ADMIN_FLAG')) {
die('Illegal Access');
}
$check_until_date = '20181231'; // ON
$rgpd_date = '20180528';
// GDPR - If cookieconsent_status is set, allow tag manager to load.
// Leaving two choices here for something
$cookie_config = false; // Start only with zenid cookie
$cookie_ga_default = true; // Analytics default: doesn't track remarketing and sets anonymous IP
$cookie_external = false; // GA tracks for marketing, FB pixel, social shares, etc
//adds analytics cookie with Anonymous IP
if (!$_COOKIE["cookieconsent_status"] ) {
if( !$_COOKIE["cc_analytics"] == 'deny') {
zen_setcookie('cc_analytics', 'allow', time()+60*60*24*30, '/', (zen_not_null($current_domain) ? $current_domain : ''));
}
if ( (str_replace('-','',$_SESSION['today_is']) <= $rgpd_date) && !$_COOKIE["cc_allowSocial"] == 'deny' ) {
$cookie_external = true;
zen_setcookie('cc_allowSocial', 'allow', time()+60*60*24*30, '/', (zen_not_null($current_domain) ? $current_domain : ''));
}
}
if (isset($_COOKIE['cc_analytics']) && $_COOKIE['cc_analytics'] == 'deny') {
$cookie_ga_default = false;
}
if (isset($_COOKIE['cc_allowSocial']) && $_COOKIE['cc_allowSocial'] == 'allow') {
$cookie_external = true;
}
if (isset($_COOKIE['cookieconsent_status'])) { // It's set, check
$cookie_config = true; // flag that the user made some configuration
// allow all cookies
if ($_COOKIE['cookieconsent_status'] == 'allow') {
$cookie_ga_default = true;
$cookie_external = true;
}
}
if ( !isset($_SESSION['customers_warning_count'])) {
$_SESSION['customers_warning_count'] = 0;
}
if($_SESSION['customer_id']) {
if ( !$_SESSION['customers_delete_account_request']) {
$sql = " SELECT customers_delete_account_request FROM ".TABLE_CUSTOMERS_GDPR." WHERE customers_id = :customers_id: ";
$sql = $db->bindVars($sql , ':customers_id:', $_SESSION['customer_id'], 'integer');
$res = $db->Execute($sql);
if ($res->fields['customers_delete_account_request'] == '1') {
$_SESSION['customers_delete_account_request'] = $res->fields['customers_delete_account_request'];
unset($sql, $res);
}
}
if(str_replace('-','',$_SESSION['today_is']) <= $check_until_date ) {
define('RGPD_MSG', 'Para estar em conformidade com o Regulamento Geral da Protecção de Dados Europeia, a Livraria PromoBooks, está a informar todos os seus cliente registados antes da nova lei, a fim de tomarem conhecimento sobre os dados processados. Por favor leia a nossa política de privacidade e aceda à <a href="'.zen_href_link(FILENAME_ACCOUNT, '', 'SSL').'"> Sua Área de Cliente</a> para efectuar as alterações necessárias. Ao continuar no site, pressupõe que tem conhecimento e que assim deseja continuar. ');
if ( $_SESSION['customer_rgpd'] == '') {
$sql = " SELECT customers_accept_terms, customers_was_notify_date, customers_delete_account_request FROM ".TABLE_CUSTOMERS_GDPR." WHERE customers_id = :customers_id: ";
$sql = $db->bindVars($sql , ':customers_id:', $_SESSION['customer_id'], 'integer');
$res = $db->Execute($sql);
if ($res->RecordCount() > 0) {
if ($res->fields['customers_accept_terms'] !=='0') {
$_SESSION['customer_rgpd'] = true;
}else {
$_SESSION['customer_rgpd'] = '';
if($_SESSION['customers_warning_count'] <= 2 && $_SESSION['customers_warning_count'] !=='stop') {
$messageStack->add_session('site_notifications', RGPD_MSG, 'caution');
$_SESSION['customers_warning_count'] ++;
}
}
if ($res->fields['customers_was_notify_date'] !=='') {
$_SESSION['customer_rgpd_notified'] = $res->fields['customers_was_notify_date'];
} else {
$_SESSION['customer_rgpd_notified'] = '';
}
} else {
$_SESSION['customer_rgpd'] = '';
$_SESSION['customer_rgpd_notified'] = '';
if(($_SESSION['customers_warning_count'] <= 2) && ($_SESSION['customers_warning_count'] !=='stop')) {
$messageStack->add_session('site_notifications', RGPD_MSG, 'caution');
}
}
}
}
}
if($_SESSION['customers_warning_count'] == 2) {
unset($_SESSION['customers_warning_count']);
$_SESSION['customers_warning_count'] ='stop';
}
if ( $_SESSION['customers_delete_account_request'] == '1') {
$messageStack->add_session('site_notifications', 'Recebemos a notificação para apagar a sua conta dentro do prazo estipulado po lei será eliminada', 'caution');
}
And then at template user account_default
Bookmarks