first commit
This commit is contained in:
112
modules/psgdpr/controllers/admin/AdminAjaxPsgdprController.php
Normal file
112
modules/psgdpr/controllers/admin/AdminAjaxPsgdprController.php
Normal file
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
*/
|
||||
class AdminAjaxPsgdprController extends ModuleAdminController
|
||||
{
|
||||
/**
|
||||
* @var Psgdpr
|
||||
*/
|
||||
public $module;
|
||||
|
||||
/**
|
||||
* This function allow to delete users
|
||||
*/
|
||||
public function ajaxProcessDeleteCustomer()
|
||||
{
|
||||
$delete = Tools::getValue('delete');
|
||||
$value = Tools::getValue('value');
|
||||
$this->module->deleteCustomer($delete, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all customers matches for the search
|
||||
*
|
||||
* @throws PrestaShopDatabaseException
|
||||
*/
|
||||
public function ajaxProcessSearchCustomers()
|
||||
{
|
||||
$searches = explode(' ', Tools::getValue('customer_search'));
|
||||
$customers = [];
|
||||
$searches = array_unique($searches);
|
||||
foreach ($searches as $search) {
|
||||
if (!empty($search) && $results = Customer::searchByName($search, 50)) {
|
||||
foreach ($results as $result) {
|
||||
if ($result['active']) {
|
||||
$result['fullname_and_email'] = $result['firstname'] . ' ' . $result['lastname'] . ' - ' . $result['email'];
|
||||
$customers[$result['id_customer']] = $result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty($customers) && !Tools::getValue('sf2')) {
|
||||
$customerList = [];
|
||||
foreach ($customers as $customer) {
|
||||
array_push($customerList, [
|
||||
'id_customer' => $customer['id_customer'],
|
||||
'firstname' => $customer['firstname'],
|
||||
'lastname' => $customer['lastname'],
|
||||
'email' => $customer['email'],
|
||||
'birthday' => $customer['birthday'],
|
||||
'nb_orders' => Order::getCustomerNbOrders($customer['id_customer']),
|
||||
'customerData' => [],
|
||||
]);
|
||||
}
|
||||
$to_return = [
|
||||
'customers' => $customerList,
|
||||
'found' => true,
|
||||
];
|
||||
} else {
|
||||
$to_return = Tools::getValue('sf2') ? [] : ['found' => false];
|
||||
}
|
||||
$this->ajaxDie(json_encode($to_return));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all collected for the giver customer
|
||||
*
|
||||
* @throws PrestaShopException
|
||||
*/
|
||||
public function ajaxProcessGetCustomerData()
|
||||
{
|
||||
$delete = Tools::getValue('delete');
|
||||
$value = Tools::getValue('value');
|
||||
|
||||
$return = $this->module->getCustomerData($delete, $value);
|
||||
|
||||
$this->ajaxDie(json_encode($return['data']));
|
||||
}
|
||||
|
||||
/**
|
||||
* check if there are orders associated to the customer
|
||||
*
|
||||
* @throws PrestaShopDatabaseException
|
||||
*/
|
||||
public function ajaxProcessDownloadInvoicesByCustomer()
|
||||
{
|
||||
$id_customer = Tools::getValue('id_customer');
|
||||
|
||||
$order_invoice_list = (int) Db::getInstance()->getValue('SELECT COUNT(1)
|
||||
FROM `' . _DB_PREFIX_ . 'order_invoice` oi
|
||||
LEFT JOIN `' . _DB_PREFIX_ . 'orders` o ON (o.`id_order` = oi.`id_order`)
|
||||
WHERE o.id_customer =' . (int) $id_customer . '
|
||||
AND oi.number > 0');
|
||||
|
||||
$this->ajaxDie(json_encode($order_invoice_list));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
*/
|
||||
class AdminDownloadInvoicesPsgdprController extends ModuleAdminController
|
||||
{
|
||||
/**
|
||||
* Download invoice
|
||||
*/
|
||||
public function postProcess()
|
||||
{
|
||||
$id_customer = (int) Tools::getValue('id_customer');
|
||||
|
||||
if (!empty($id_customer)) {
|
||||
$this->downloadInvoices($id_customer);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* download all invoices from specific customer into one .pdf file
|
||||
*
|
||||
* @param int $id_customer
|
||||
*/
|
||||
public function downloadInvoices($id_customer)
|
||||
{
|
||||
$order_invoice_collection = $this->getCustomerInvoiceList($id_customer);
|
||||
|
||||
if (empty($order_invoice_collection)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->generatePDF($order_invoice_collection, PDF::TEMPLATE_INVOICE);
|
||||
}
|
||||
|
||||
/**
|
||||
* get all the invoices from specific customer into a list
|
||||
*
|
||||
* @param int $id_customer
|
||||
*
|
||||
* @return array|ObjectModel[]
|
||||
*
|
||||
* @throws PrestaShopDatabaseException
|
||||
* @throws PrestaShopException
|
||||
*/
|
||||
public function getCustomerInvoiceList($id_customer)
|
||||
{
|
||||
$order_invoice_list = Db::getInstance()->executeS('SELECT oi.*
|
||||
FROM `' . _DB_PREFIX_ . 'order_invoice` oi
|
||||
LEFT JOIN `' . _DB_PREFIX_ . 'orders` o ON (o.`id_order` = oi.`id_order`)
|
||||
WHERE o.id_customer =' . (int) $id_customer . '
|
||||
AND oi.number > 0');
|
||||
|
||||
if (empty($order_invoice_list)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return ObjectModel::hydrateCollection('OrderInvoice', $order_invoice_list);
|
||||
}
|
||||
|
||||
/**
|
||||
* generate a .pdf file
|
||||
*
|
||||
* @param ObjectModel[] $object
|
||||
* @param string $template
|
||||
*
|
||||
* @throws PrestaShopException
|
||||
*/
|
||||
public function generatePDF($object, $template)
|
||||
{
|
||||
$pdf = new PDF($object, $template, Context::getContext()->smarty);
|
||||
$pdf->render(true);
|
||||
}
|
||||
}
|
||||
28
modules/psgdpr/controllers/admin/index.php
Normal file
28
modules/psgdpr/controllers/admin/index.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
*/
|
||||
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||
header('Pragma: no-cache');
|
||||
|
||||
header('Location: ../');
|
||||
exit;
|
||||
421
modules/psgdpr/controllers/front/ExportDataToCsv.php
Normal file
421
modules/psgdpr/controllers/front/ExportDataToCsv.php
Normal file
@@ -0,0 +1,421 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
*/
|
||||
class psgdprExportDataToCsvModuleFrontController extends ModuleFrontController
|
||||
{
|
||||
/**
|
||||
* @var Psgdpr
|
||||
*/
|
||||
public $module;
|
||||
|
||||
/**
|
||||
* @throws PrestaShopDatabaseException
|
||||
*/
|
||||
public function initContent()
|
||||
{
|
||||
$customer = Context::getContext()->customer;
|
||||
$secure_key = sha1($customer->secure_key);
|
||||
$token = Tools::getValue('psgdpr_token');
|
||||
|
||||
if ($customer->isLogged() === false || !isset($token) || $token != $secure_key) {
|
||||
exit('bad token');
|
||||
}
|
||||
|
||||
GDPRLog::addLog($customer->id, 'exportCsv', 0);
|
||||
$this->exportDataToCsv($customer->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id_customer
|
||||
*/
|
||||
public function exportDataToCsv($id_customer)
|
||||
{
|
||||
$data = $this->module->getCustomerData('customer', $id_customer);
|
||||
|
||||
$customerInfo = $data['data']['prestashopData']['customerInfo'];
|
||||
$addresses = $data['data']['prestashopData']['addresses'];
|
||||
$orders = $data['data']['prestashopData']['orders'];
|
||||
$carts = $data['data']['prestashopData']['carts'];
|
||||
$messages = $data['data']['prestashopData']['messages'];
|
||||
$connections = $data['data']['prestashopData']['connections'];
|
||||
$modules = $data['data']['modulesData'];
|
||||
|
||||
// Open the output stream
|
||||
$fh = fopen('php://output', 'w');
|
||||
$delimiter = "\t";
|
||||
|
||||
// Start output buffering (to capture stream contents)
|
||||
ob_start();
|
||||
|
||||
// GENERAL INFO
|
||||
$line = [Tools::strtoupper($this->module->l('General info', 'ExportDataToCsv'))];
|
||||
fputcsv($fh, $line, $delimiter);
|
||||
|
||||
$line = [
|
||||
$this->module->l('Gender', 'ExportDataToCsv'),
|
||||
$this->module->l('Name', 'ExportDataToCsv'),
|
||||
$this->module->l('Birth date', 'ExportDataToCsv'),
|
||||
$this->module->l('Age', 'ExportDataToCsv'),
|
||||
$this->module->l('Email', 'ExportDataToCsv'),
|
||||
$this->module->l('Language', 'ExportDataToCsv'),
|
||||
$this->module->l('Creation account data', 'ExportDataToCsv'),
|
||||
$this->module->l('Last visit', 'ExportDataToCsv'),
|
||||
$this->module->l('Siret', 'ExportDataToCsv'),
|
||||
$this->module->l('Ape', 'ExportDataToCsv'),
|
||||
$this->module->l('Company', 'ExportDataToCsv'),
|
||||
$this->module->l('Website', 'ExportDataToCsv'),
|
||||
];
|
||||
fputcsv($fh, $line, $delimiter);
|
||||
unset($line);
|
||||
|
||||
$line = [
|
||||
$customerInfo['gender'],
|
||||
$customerInfo['firstname'] . ' ' . $customerInfo['lastname'],
|
||||
$customerInfo['birthday'],
|
||||
$customerInfo['age'],
|
||||
$customerInfo['email'],
|
||||
$customerInfo['language'],
|
||||
$customerInfo['date_add'],
|
||||
$customerInfo['last_visit'],
|
||||
$customerInfo['siret'],
|
||||
$customerInfo['ape'],
|
||||
$customerInfo['company'],
|
||||
$customerInfo['website'],
|
||||
];
|
||||
fputcsv($fh, $line, $delimiter);
|
||||
unset($line);
|
||||
// GENERAL INFO
|
||||
|
||||
// empty line
|
||||
$line = [];
|
||||
fputcsv($fh, $line, $delimiter);
|
||||
|
||||
// ADDRESSES
|
||||
$line = [Tools::strtoupper($this->module->l('Addresses', 'ExportDataToCsv'))];
|
||||
fputcsv($fh, $line, $delimiter);
|
||||
|
||||
$line = [
|
||||
$this->module->l('Alias', 'ExportDataToCsv'),
|
||||
$this->module->l('Company', 'ExportDataToCsv'),
|
||||
$this->module->l('Name', 'ExportDataToCsv'),
|
||||
$this->module->l('Address', 'ExportDataToCsv'),
|
||||
$this->module->l('Phone(s)', 'ExportDataToCsv'),
|
||||
$this->module->l('Country', 'ExportDataToCsv'),
|
||||
$this->module->l('Date', 'ExportDataToCsv'),
|
||||
];
|
||||
fputcsv($fh, $line, $delimiter);
|
||||
unset($line);
|
||||
|
||||
if (count($addresses) >= 1) {
|
||||
foreach ($addresses as $address) {
|
||||
$line = [
|
||||
$address['alias'],
|
||||
$address['company'],
|
||||
$address['firstname'] . ' ' . $address['lastname'],
|
||||
$address['address1'] . ' ' . $address['address2'],
|
||||
$address['phone'] . ' ' . $address['phone_mobile'],
|
||||
$address['country'],
|
||||
$address['date_add'],
|
||||
];
|
||||
fputcsv($fh, $line, $delimiter);
|
||||
unset($line);
|
||||
}
|
||||
} else {
|
||||
$line = [$this->module->l('No addresses', 'ExportDataToCsv')];
|
||||
fputcsv($fh, $line, $delimiter);
|
||||
unset($line);
|
||||
}
|
||||
// ADDRESSES
|
||||
|
||||
// empty line
|
||||
$line = [];
|
||||
fputcsv($fh, $line, $delimiter);
|
||||
|
||||
// ORDERS
|
||||
$line = [Tools::strtoupper($this->module->l('Orders', 'ExportDataToCsv'))];
|
||||
fputcsv($fh, $line, $delimiter);
|
||||
|
||||
$line = [
|
||||
$this->module->l('Reference', 'ExportDataToCsv'),
|
||||
$this->module->l('Payment', 'ExportDataToCsv'),
|
||||
$this->module->l('Order state', 'ExportDataToCsv'),
|
||||
$this->module->l('Total paid', 'ExportDataToCsv'),
|
||||
$this->module->l('Date', 'ExportDataToCsv'),
|
||||
];
|
||||
fputcsv($fh, $line, $delimiter);
|
||||
unset($line);
|
||||
|
||||
if (count($orders) >= 1) {
|
||||
foreach ($orders as $order) {
|
||||
$line = [
|
||||
$order['reference'],
|
||||
$order['payment'],
|
||||
$order['order_state'],
|
||||
$order['total_paid_tax_incl'],
|
||||
$order['date_add'],
|
||||
];
|
||||
fputcsv($fh, $line, $delimiter);
|
||||
unset($line);
|
||||
}
|
||||
} else {
|
||||
$line = [$this->module->l('No orders', 'ExportDataToCsv')];
|
||||
fputcsv($fh, $line, $delimiter);
|
||||
unset($line);
|
||||
}
|
||||
// ORDERS
|
||||
|
||||
// empty line
|
||||
$line = [];
|
||||
fputcsv($fh, $line, $delimiter);
|
||||
|
||||
// PRODUCTS IN ORDER
|
||||
if (count($orders) >= 1) {
|
||||
$line = [Tools::strtoupper($this->module->l('Products bought', 'ExportDataToCsv'))];
|
||||
fputcsv($fh, $line, $delimiter);
|
||||
|
||||
$line = [
|
||||
$this->module->l('Order ref', 'ExportDataToCsv'),
|
||||
$this->module->l('Product ref', 'ExportDataToCsv'),
|
||||
$this->module->l('Name', 'ExportDataToCsv'),
|
||||
$this->module->l('Quantity', 'ExportDataToCsv'),
|
||||
];
|
||||
fputcsv($fh, $line, $delimiter);
|
||||
unset($line);
|
||||
|
||||
foreach ($orders as $order) {
|
||||
$products = $order['products'];
|
||||
foreach ($products as $product) {
|
||||
$line = [
|
||||
$order['reference'],
|
||||
$product['product_reference'],
|
||||
$product['product_name'],
|
||||
$product['product_quantity'],
|
||||
];
|
||||
fputcsv($fh, $line, $delimiter);
|
||||
unset($line);
|
||||
}
|
||||
}
|
||||
}
|
||||
// PRODUCTS IN ORDER
|
||||
|
||||
// empty line
|
||||
$line = [];
|
||||
fputcsv($fh, $line, $delimiter);
|
||||
|
||||
// CARTS
|
||||
$line = [Tools::strtoupper($this->module->l('Carts', 'ExportDataToCsv'))];
|
||||
fputcsv($fh, $line, $delimiter);
|
||||
|
||||
$line = [
|
||||
$this->module->l('Id', 'ExportDataToCsv'),
|
||||
$this->module->l('Total products', 'ExportDataToCsv'),
|
||||
$this->module->l('Date', 'ExportDataToCsv'),
|
||||
];
|
||||
fputcsv($fh, $line, $delimiter);
|
||||
unset($line);
|
||||
|
||||
if (count($carts) >= 1) {
|
||||
foreach ($carts as $cart) {
|
||||
$line = [
|
||||
'#' . $cart['id_cart'],
|
||||
$cart['nb_products'],
|
||||
$cart['date_add'],
|
||||
];
|
||||
fputcsv($fh, $line, $delimiter);
|
||||
unset($line);
|
||||
}
|
||||
} else {
|
||||
$line = [$this->module->l('No carts', 'ExportDataToCsv')];
|
||||
fputcsv($fh, $line, $delimiter);
|
||||
unset($line);
|
||||
}
|
||||
// CARTS
|
||||
|
||||
// empty line
|
||||
$line = [];
|
||||
fputcsv($fh, $line, $delimiter);
|
||||
|
||||
// PRODUCTS IN CART
|
||||
$line = [Tools::strtoupper($this->module->l('Product(s) still in cart', 'ExportDataToCsv'))];
|
||||
fputcsv($fh, $line, $delimiter);
|
||||
|
||||
$line = [
|
||||
$this->module->l('Cart ID', 'ExportDataToCsv'),
|
||||
$this->module->l('Product reference', 'ExportDataToCsv'),
|
||||
$this->module->l('Name', 'ExportDataToCsv'),
|
||||
$this->module->l('Quantity', 'ExportDataToCsv'),
|
||||
];
|
||||
fputcsv($fh, $line, $delimiter);
|
||||
unset($line);
|
||||
|
||||
if (count($carts) >= 1) {
|
||||
foreach ($carts as $cart) {
|
||||
$products = $cart['products'];
|
||||
if (count($products) >= 1) {
|
||||
foreach ($products as $product) {
|
||||
$line = [
|
||||
'#' . $cart['id_cart'],
|
||||
$product['product_reference'],
|
||||
$product['product_name'],
|
||||
$product['product_quantity'],
|
||||
];
|
||||
fputcsv($fh, $line, $delimiter);
|
||||
unset($line);
|
||||
}
|
||||
} else {
|
||||
$line = [$this->module->l('No products', 'ExportDataToCsv')];
|
||||
fputcsv($fh, $line, $delimiter);
|
||||
unset($line);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$line = [$this->module->l('No carts', 'ExportDataToCsv')];
|
||||
fputcsv($fh, $line, $delimiter);
|
||||
unset($line);
|
||||
}
|
||||
// PRODUCTS IN CART
|
||||
|
||||
// empty line
|
||||
$line = [];
|
||||
fputcsv($fh, $line, $delimiter);
|
||||
|
||||
// MESSSAGES
|
||||
$line = [Tools::strtoupper($this->module->l('Messages', 'ExportDataToCsv'))];
|
||||
fputcsv($fh, $line, $delimiter);
|
||||
|
||||
$line = [
|
||||
$this->module->l('IP', 'ExportDataToCsv'),
|
||||
$this->module->l('Message', 'ExportDataToCsv'),
|
||||
$this->module->l('Date', 'ExportDataToCsv'),
|
||||
];
|
||||
fputcsv($fh, $line, $delimiter);
|
||||
unset($line);
|
||||
|
||||
if (count($messages) >= 1) {
|
||||
foreach ($messages as $message) {
|
||||
$line = [
|
||||
$message['ip'],
|
||||
$message['message'],
|
||||
$message['date_add'],
|
||||
];
|
||||
fputcsv($fh, $line, $delimiter);
|
||||
unset($line);
|
||||
}
|
||||
} else {
|
||||
$line = [$this->module->l('No messages', 'ExportDataToCsv')];
|
||||
fputcsv($fh, $line, $delimiter);
|
||||
unset($line);
|
||||
}
|
||||
// MESSAGES
|
||||
|
||||
// empty line
|
||||
$line = [];
|
||||
fputcsv($fh, $line, $delimiter);
|
||||
|
||||
// CONNECTIONS
|
||||
$line = [Tools::strtoupper($this->module->l('Last connections', 'ExportDataToCsv'))];
|
||||
fputcsv($fh, $line, $delimiter);
|
||||
|
||||
$line = [
|
||||
$this->module->l('Origin request', 'ExportDataToCsv'),
|
||||
$this->module->l('Page viewed', 'ExportDataToCsv'),
|
||||
$this->module->l('Time on the page', 'ExportDataToCsv'),
|
||||
$this->module->l('IP address', 'ExportDataToCsv'),
|
||||
$this->module->l('Date', 'ExportDataToCsv'),
|
||||
$this->module->l('Country', 'ExportDataToCsv'),
|
||||
$this->module->l('Date', 'ExportDataToCsv'),
|
||||
];
|
||||
fputcsv($fh, $line, $delimiter);
|
||||
unset($line);
|
||||
|
||||
if (count($connections) >= 1) {
|
||||
foreach ($connections as $connection) {
|
||||
$line = [
|
||||
$connection['http_referer'],
|
||||
$connection['pages'],
|
||||
$connection['time'],
|
||||
$connection['ipaddress'],
|
||||
$connection['date_add'],
|
||||
];
|
||||
fputcsv($fh, $line, $delimiter);
|
||||
unset($line);
|
||||
}
|
||||
} else {
|
||||
$line = [$this->module->l('No connections', 'ExportDataToCsv')];
|
||||
fputcsv($fh, $line, $delimiter);
|
||||
unset($line);
|
||||
}
|
||||
// CONNECTIONS
|
||||
|
||||
// empty line
|
||||
$line = [];
|
||||
fputcsv($fh, $line, $delimiter);
|
||||
|
||||
// MODULES
|
||||
if (count($modules) >= 1) {
|
||||
foreach ($modules as $index => $module) {
|
||||
$line = [Tools::strtoupper('Module : ' . $index)];
|
||||
fputcsv($fh, $line, $delimiter);
|
||||
$line = [];
|
||||
if (is_array($module)) {
|
||||
foreach ($module as $table) {
|
||||
foreach ($table as $key => $value) {
|
||||
$line[] = $key;
|
||||
}
|
||||
fputcsv($fh, $line, $delimiter);
|
||||
$line = [];
|
||||
foreach ($table as $key => $value) {
|
||||
$line[] = $value;
|
||||
}
|
||||
fputcsv($fh, $line, $delimiter);
|
||||
$line = [];
|
||||
}
|
||||
} else {
|
||||
$line[] = $module;
|
||||
fputcsv($fh, $line, $delimiter);
|
||||
}
|
||||
// empty line
|
||||
$line = [];
|
||||
fputcsv($fh, $line, $delimiter);
|
||||
}
|
||||
}
|
||||
// MODULES
|
||||
|
||||
// Get the contents of the output buffer
|
||||
$csv = ob_get_clean();
|
||||
|
||||
// Set the filename of the download
|
||||
$filename = 'personalData-' . date('Y-m-d');
|
||||
|
||||
// Output CSV-specific headers
|
||||
header('Content-Description: File Transfer');
|
||||
//header('Content-Type: application/octet-stream');
|
||||
header('Content-Type: application/vnd.ms-excel;');
|
||||
header('Content-Type: application/x-msexcel;');
|
||||
header('Content-Disposition: attachment; filename="' . $filename . '.csv";');
|
||||
header('Content-Transfer-Encoding: binary');
|
||||
header('Expires: 0');
|
||||
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
|
||||
header('Pragma: public');
|
||||
|
||||
$csv = chr(255) . chr(254) . iconv('UTF-8', 'UTF-16LE', $csv);
|
||||
|
||||
exit($csv);
|
||||
}
|
||||
}
|
||||
55
modules/psgdpr/controllers/front/ExportDataToPdf.php
Normal file
55
modules/psgdpr/controllers/front/ExportDataToPdf.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
*/
|
||||
class psgdprExportDataToPdfModuleFrontController extends ModuleFrontController
|
||||
{
|
||||
/**
|
||||
* @var Psgdpr
|
||||
*/
|
||||
public $module;
|
||||
|
||||
/**
|
||||
* @throws PrestaShopDatabaseException
|
||||
*/
|
||||
public function initContent()
|
||||
{
|
||||
$customer = Context::getContext()->customer;
|
||||
$secure_key = sha1($customer->secure_key);
|
||||
$token = Tools::getValue('psgdpr_token');
|
||||
|
||||
if ($customer->isLogged() === false || !isset($token) || $token != $secure_key) {
|
||||
exit('bad token');
|
||||
}
|
||||
|
||||
GDPRLog::addLog($customer->id, 'exportPdf', 0);
|
||||
$this->exportDataToPdf($customer->id);
|
||||
exit();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id_customer
|
||||
*
|
||||
* @throws PrestaShopException
|
||||
*/
|
||||
public function exportDataToPdf($id_customer)
|
||||
{
|
||||
$pdf = new PDF($this->module->getCustomerData('customer', $id_customer), 'PSGDPRModule', Context::getContext()->smarty);
|
||||
$pdf->render(true);
|
||||
}
|
||||
}
|
||||
58
modules/psgdpr/controllers/front/FrontAjaxGdpr.php
Normal file
58
modules/psgdpr/controllers/front/FrontAjaxGdpr.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
*/
|
||||
class psgdprFrontAjaxGdprModuleFrontController extends FrontController
|
||||
{
|
||||
/**
|
||||
* Store if the client consented or not to GDPR on a specific module for statistic purpose only
|
||||
*
|
||||
* @throws PrestaShopDatabaseException
|
||||
* @throws PrestaShopException
|
||||
*/
|
||||
public function display()
|
||||
{
|
||||
if (Tools::getValue('action') !== 'AddLog') {
|
||||
$this->ajaxDie();
|
||||
}
|
||||
|
||||
$id_customer = (int) Tools::getValue('id_customer');
|
||||
$customer_token = Tools::getValue('customer_token');
|
||||
|
||||
$id_module = (int) Tools::getValue('id_module');
|
||||
|
||||
$id_guest = (int) Tools::getValue('id_guest');
|
||||
$guest_token = Tools::getValue('guest_token');
|
||||
|
||||
$customer = Context::getContext()->customer;
|
||||
|
||||
if ($customer->isLogged() === true) {
|
||||
$token = sha1($customer->secure_key);
|
||||
if (!isset($customer_token) || $customer_token == $token) {
|
||||
GDPRLog::addLog($id_customer, 'consent', $id_module);
|
||||
}
|
||||
} else {
|
||||
$token = sha1('psgdpr' . Context::getContext()->cart->id_guest . $_SERVER['REMOTE_ADDR'] . date('Y-m-d'));
|
||||
if (!isset($guest_token) || $guest_token == $token) {
|
||||
GDPRLog::addLog($id_customer, 'consent', $id_module, $id_guest);
|
||||
}
|
||||
}
|
||||
|
||||
$this->ajaxDie();
|
||||
}
|
||||
}
|
||||
89
modules/psgdpr/controllers/front/gdpr.php
Normal file
89
modules/psgdpr/controllers/front/gdpr.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
*/
|
||||
class psgdprgdprModuleFrontController extends ModuleFrontController
|
||||
{
|
||||
/**
|
||||
* @var Psgdpr
|
||||
*/
|
||||
public $module;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $display_column_right;
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $display_column_left;
|
||||
|
||||
/**
|
||||
* @throws PrestaShopException
|
||||
*/
|
||||
public function initContent()
|
||||
{
|
||||
$this->display_column_right = false;
|
||||
$this->display_column_left = false;
|
||||
$context = Context::getContext();
|
||||
if (empty($context->customer->id)) {
|
||||
Tools::redirect('index.php');
|
||||
}
|
||||
|
||||
parent::initContent();
|
||||
|
||||
$params = [
|
||||
'psgdpr_token' => sha1($context->customer->secure_key),
|
||||
];
|
||||
|
||||
$this->context->smarty->assign([
|
||||
'psgdpr_contactUrl' => $this->context->link->getPageLink('contact', true, $this->context->language->id),
|
||||
'psgdpr_front_controller' => Context::getContext()->link->getModuleLink('psgdpr', 'gdpr', $params, true),
|
||||
'psgdpr_csv_controller' => Context::getContext()->link->getModuleLink('psgdpr', 'ExportDataToCsv', $params, true),
|
||||
'psgdpr_pdf_controller' => Context::getContext()->link->getModuleLink('psgdpr', 'ExportDataToPdf', $params, true),
|
||||
'psgdpr_ps_version' => (bool) version_compare(_PS_VERSION_, '1.7', '>='),
|
||||
'psgdpr_id_customer' => Context::getContext()->customer->id,
|
||||
]);
|
||||
|
||||
$this->context->smarty->tpl_vars['page']->value['body_classes']['page-customer-account'] = true;
|
||||
|
||||
$this->setTemplate('module:psgdpr/views/templates/front/customerPersonalData.tpl');
|
||||
}
|
||||
|
||||
public function getBreadcrumbLinks()
|
||||
{
|
||||
$breadcrumb = parent::getBreadcrumbLinks();
|
||||
$breadcrumb['links'][] = $this->addMyAccountToBreadcrumb();
|
||||
$breadcrumb['links'][] = [
|
||||
'title' => $this->trans('GDPR - Personal data', [], 'Modules.Psgdpr.Customeraccount'),
|
||||
'url' => $this->context->link->getModuleLink($this->module->name, 'gdpr', [], true),
|
||||
];
|
||||
|
||||
return $breadcrumb;
|
||||
}
|
||||
|
||||
public function setMedia()
|
||||
{
|
||||
$js_path = $this->module->getPathUri() . '/views/js/';
|
||||
$css_path = $this->module->getPathUri() . '/views/css/';
|
||||
|
||||
parent::setMedia();
|
||||
$this->context->controller->addJS($js_path . 'front.js');
|
||||
$this->context->controller->addCSS($css_path . 'customerPersonalData.css');
|
||||
}
|
||||
}
|
||||
28
modules/psgdpr/controllers/front/index.php
Normal file
28
modules/psgdpr/controllers/front/index.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
*/
|
||||
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||
header('Pragma: no-cache');
|
||||
|
||||
header('Location: ../');
|
||||
exit;
|
||||
28
modules/psgdpr/controllers/index.php
Normal file
28
modules/psgdpr/controllers/index.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
*/
|
||||
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||
header('Pragma: no-cache');
|
||||
|
||||
header('Location: ../');
|
||||
exit;
|
||||
Reference in New Issue
Block a user