* @copyright Radek Polasek, www.broucek-a-beruska.cz * The buyer can free use/edit/modify this software in anyway * The buyer is NOT allowed to redistribute this module in anyway or resell it or redistribute it to third party */ class GDPR extends Module { function __construct() { $this->name = 'gdpr'; $this->tab = 'Tools'; $this->author = 'Brouček a Beruška Webdesign'; parent::__construct(); $this->page = basename(__FILE__, '.php'); $this->displayName = $this->l('GDPR - Privacy Policy'); $this->description = $this->l('Consent to processing personal data, request data, delete account'); } function install() { @Db::getInstance()->execute('ALTER TABLE '._DB_PREFIX_.'customer ADD COLUMN `gdpr_ip` varchar(255) NULL'); @Db::getInstance()->execute('ALTER TABLE '._DB_PREFIX_.'customer ADD COLUMN `gdpr_date_add` datetime NULL'); @Db::getInstance()->execute('ALTER TABLE '._DB_PREFIX_.'customer ADD COLUMN `gdpr_consent_sent` tinyint(1) unsigned NOT NULL DEFAULT "0"'); if (parent::install() AND Configuration::updateValue('GDPR_VALIDITY', 30) AND Configuration::updateValue('GDPR_REQUIRED', 1) AND Configuration::updateValue('GDPR_CART', 0) AND Configuration::updateValue('GDPR_REGISTER', 1) AND $this->registerHook('shoppingCart') AND $this->registerHook('createAccount') AND $this->registerHook('customerAccount') AND $this->registerHook('createAccountForm') AND $this->registerHook('header') AND $this->registerHook('newOrder') ) return true; return false; } public function uninstall() { if (parent::uninstall() AND $this->unregisterHook('shoppingCart') AND $this->unregisterHook('customerAccount') AND $this->unregisterHook('createAccount') AND $this->unregisterHook('createAccountForm') AND $this->unregisterHook('header') AND $this->unregisterHook('newOrder') AND Configuration::deleteByName('GDPR_ACCOUNT_DELETE') AND Configuration::deleteByName('GDPR_REQUEST_TYPE') AND Configuration::deleteByName('GDPR_VALIDITY') AND Configuration::deleteByName('GDPR_REQUIRED') AND Configuration::deleteByName('GDPR_REGISTER') AND Configuration::deleteByName('GDPR_CART') ) return true; return false; } function hookNewOrder($params) { $customer = $params['customer']; if (!Configuration::get('GDPR_REQUIRED') OR $customer->is_guest) return false; Db::getInstance()->Execute(' UPDATE '._DB_PREFIX_.'customer SET gdpr_ip = "'. $_SERVER['REMOTE_ADDR'] .'", gdpr_date_add = NOW() WHERE id_customer = '. $customer->id .' '); } private function getAgreement($id_customer) { $gdpr = Db::getInstance()->getRow(' SELECT DATEDIFF(gdpr_date_add, DATE_SUB(NOW(), INTERVAL '. Configuration::get('GDPR_VALIDITY') .' DAY)) > 0 AS agree FROM '._DB_PREFIX_.'customer WHERE id_customer = '. $id_customer .' '); return $gdpr['agree']; } function showRequest() { global $smarty, $cookie; if (Tools::isSubmit('request')) { $subject = $this->l('Request my data') .' - '. Configuration::get('PS_SHOP_NAME'); $customer = new Customer($cookie->id_customer); $templateVars = array( '{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname, '{email}' => $customer->email ); // Manual retrieve if (Configuration::get('GDPR_REQUEST_TYPE')) { if (Mail::Send(intval($cookie->id_lang), 'request', $subject, $templateVars, Configuration::get('PS_SHOP_EMAIL'), Configuration::get('PS_SHOP_NAME'), $customer->email, $customer->firstname.' '.$customer->lastname, NULL, NULL, dirname(__FILE__).'/mails/')) $report = 2; else $report = 1; } // Automatic e-mail with CSV file else { $types = array('customer', 'address', 'orders'); foreach ($types as $type) { $rows = Db::getInstance()->ExecuteS('SELECT * FROM `'._DB_PREFIX_ . $type .'` WHERE id_customer = '. $customer->id); foreach ($rows as $count=>$row) { $columns = $values = ''; foreach ($row as $key=>$value) { $columns .= $key .';'; $values .= $value .';'; } if (!$count) $data .= $columns ."\n"; $data .= $values ."\n"; } } $fileAttachment['content'] = $data; $fileAttachment['name'] = 'customer_'. $customer->id .'.csv'; $fileAttachment['mime'] = 'application/x-download'; if (Mail::Send(intval($cookie->id_lang), 'request_auto', $subject, $templateVars, Configuration::get('PS_SHOP_EMAIL'), Configuration::get('PS_SHOP_NAME'), $customer->email, $customer->firstname.' '.$customer->lastname, NULL, NULL, dirname(__FILE__).'/mails/') AND Mail::Send(intval($cookie->id_lang), 'retrieve', $subject, $templateVars, $customer->email, $customer->firstname.' '.$customer->lastname, Configuration::get('PS_SHOP_EMAIL'), Configuration::get('PS_SHOP_NAME'), $fileAttachment, NULL, dirname(__FILE__).'/mails/') ) $report = 2; else $report = 1; } $smarty->assign('report', $report); } return $this->display(__FILE__, 'tpl/request.tpl'); } function showDelete() { global $smarty, $cookie; if (Tools::isSubmit('delete')) { $subject = $this->l('Delete and forget my account') .' - '. Configuration::get('PS_SHOP_NAME'); $customer = new Customer($cookie->id_customer); $templateVars = array( '{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname, '{email}' => $customer->email ); if (Mail::Send(intval($cookie->id_lang), 'delete', $subject, $templateVars, Configuration::get('PS_SHOP_EMAIL'), Configuration::get('PS_SHOP_NAME'), $customer->email, $customer->firstname.' '.$customer->lastname, NULL, NULL, dirname(__FILE__).'/mails/')) $report = 2; else $report = 1; $smarty->assign('report', $report); } return $this->display(__FILE__, 'tpl/delete.tpl'); } function showConsent() { global $smarty, $cookie; $key = Tools::getValue('key'); $id_customer = Tools::getValue('id_customer') ? Tools::getValue('id_customer') : $cookie->id_customer; if ((Tools::isSubmit('consent') AND $cookie->id_customer) OR (Tools::isSubmit('consent') AND $key == _COOKIE_IV_)) { if (Tools::getValue('gdpr')) { Db::getInstance()->Execute(' UPDATE '._DB_PREFIX_.'customer SET gdpr_ip = "'. $_SERVER['REMOTE_ADDR'] .'", gdpr_date_add = NOW() WHERE id_customer = '. $id_customer .' '); } else { Db::getInstance()->Execute(' UPDATE '._DB_PREFIX_.'customer SET gdpr_ip = NULL, gdpr_date_add = NULL WHERE id_customer = '. $id_customer .' '); } $smarty->assign('report', $this->l('Settings updated')); } $xml = simplexml_load_file(dirname(__FILE__).'/gdpr.xml'); $smarty->assign(array( 'agree' => $this->getAgreement($id_customer), 'id_customer' => $id_customer, 'gdpr_consent' => $xml->{'consent_'.$cookie->id_lang} )); return $this->display(__FILE__, 'tpl/consent.tpl'); } function hookCustomerAccount($params) { global $smarty; $smarty->assign('account_delete', Configuration::get('GDPR_ACCOUNT_DELETE')); return $this->display(__FILE__, 'tpl/my-account.tpl'); } function hookCreateAccount($params) { if (!Configuration::get('GDPR_REGISTER')) return false; if (Tools::getValue('gdpr')) { Db::getInstance()->Execute(' UPDATE '._DB_PREFIX_.'customer SET gdpr_ip = "'. $_SERVER['REMOTE_ADDR'] .'", gdpr_date_add = NOW() WHERE id_customer = '. $params['newCustomer']->id .' '); } } function hookCreateAccountForm($params) { global $smarty, $cookie; if (!Configuration::get('GDPR_REGISTER')) return false; $xml = simplexml_load_file(dirname(__FILE__).'/gdpr.xml'); $smarty->assign(array( 'gdpr_consent' => $xml->{'consent_'.$cookie->id_lang}, 'gdpr_account_required' => Configuration::get('GDPR_REQUIRED')?1:0 )); return $this->display(__FILE__, 'tpl/create-account.tpl'); } function hookShoppingCart($params) { global $smarty, $cookie; if (!Configuration::get('GDPR_CART')) return false; $xml = simplexml_load_file(dirname(__FILE__).'/gdpr.xml'); $smarty->assign(array( 'agree' => $this->getAgreement($cookie->id_customer), 'id_customer' => $cookie->id_customer, 'gdpr_consent' => $xml->{'consent_'.$cookie->id_lang}, 'gdpr_required' => Configuration::get('GDPR_REQUIRED')?1:0 )); return $this->display(__FILE__, 'tpl/gdpr.tpl'); } function hookHeader($params) { global $smarty; return $this->display(__FILE__, 'tpl/header.tpl'); } public function getContent() { global $cookie, $currentIndex, $token; $defaultLanguage = intval(Configuration::get('PS_LANG_DEFAULT')); $languages = Language::getLanguages(); $iso = Language::getIsoById($defaultLanguage); $isoTinyMCE = (file_exists(_PS_ROOT_DIR_.'/js/tiny_mce/langs/'.$iso.'.js') ? $iso : 'en'); $ad = dirname($_SERVER["PHP_SELF"]); $divLangName = 'consent'; if (!Tools::getValue('orderby')) $orderby = 'id_customer'; else $orderby = Tools::getValue('orderby'); if (!Tools::getValue('orderway')) $orderway = 'DESC'; else $orderway = Tools::getValue('orderway'); $this->_html = '
'. $this->l('Request sent').'
'. $this->l('Error happened') .'
'. $this->l('Settings updated') .'
'. $this->l('Settings updated').'
'. $this->l('Error happened') .'