<modification>
  <name>iSenseLabs GDPR</name>
  <code>isenselabs_gdpr</code>
  <version>3.13</version>
  <author>iSenseLabs</author>
  <link>http://www.isenselabs.com</link>

  <!-- Added Admin Link in the Main Menu -->
  <!-- OC 2.3 -->
  <file path="admin/controller/common/column_left.php">
	<operation error="skip">
      <search>
        <![CDATA[if ($design) {]]>
      </search>
      <add position="before">
        <![CDATA[
		$file = DIR_SYSTEM . 'library/gdpr.php';
		if (is_file($file)) {
			$this->load->model('setting/setting');
			$gdpr_settings = $this->model_setting_setting->getSetting('isenselabs_gdpr', $this->config->get('config_store_id'));

			if (!empty($gdpr_settings['isenselabs_gdpr']['Enabled']) && $gdpr_settings['isenselabs_gdpr']['Enabled'] == '1' && !empty($gdpr_settings['isenselabs_gdpr']['LinkInMenu']) && $gdpr_settings['isenselabs_gdpr']['LinkInMenu']=='1') {
				$this->config->load('isenselabs/isenselabs_gdpr');
				$data['menus'][] = array(
					'id'       => 'menu-isenselabs-gdpr',
					'icon'	   => 'fa-list-alt',
					'name'	   => 'GDPR Requests',
					'href'     => $this->url->link($this->config->get('isenselabs_gdpr_path'), $this->config->get('isenselabs_gdpr_token_string').'=' . $this->session->data['user_token'], true).'#requests-tab',
					'children'  => array()
				);
			}
        }
        ]]>
      </add>
    </operation>
  </file>

  <!-- Added Link in the Footer Menu -->
  <file path="catalog/controller/common/footer.php">
	<operation error="log">
      <search>
        <![CDATA[$data['informations'] = array();]]>
      </search>
      <add position="after">
        <![CDATA[
        $file = DIR_SYSTEM . 'library/gdpr.php';
		if (is_file($file)) {
			$this->config->load('isenselabs/isenselabs_gdpr');
			$gdpr_name = $this->config->get('isenselabs_gdpr_name');
			$gdpr_path = $this->config->get('isenselabs_gdpr_path');
			$this->load->language($gdpr_path);

			$this->load->model('setting/setting');
			$moduleSettings = $this->model_setting_setting->getSetting($gdpr_name, $this->config->get('config_store_id'));
			$gdpr_settings = !empty($moduleSettings[$gdpr_name]) ? $moduleSettings[$gdpr_name] : array();

			if (!empty($gdpr_settings['Enabled']) && $gdpr_settings['Enabled'] == '1' && !empty($gdpr_settings['LinkInFooter']) && $gdpr_settings['LinkInFooter'] == '1') {
				$data['informations'][] = array(
					'title' => $this->language->get('text_gdpr'),
					'href'  => $this->url->link($gdpr_path, '', true)
				);
			}
		}
        ]]>
      </add>
    </operation>
  </file>

  <!-- Privacy policy acceptance -->
  <file path="catalog/model/account/customer.php">
	<operation error="log">
      <search>
        <![CDATA[$customer_id = $this->db->getLastId();]]>
      </search>
      <add position="after">
        <![CDATA[
        $file = DIR_SYSTEM . 'library/gdpr.php';
		if (is_file($file)) {
			if ($this->config->get('config_account_id')) {
				$this->load->library('gdpr');
				$this->gdpr->newAcceptanceRequest($this->config->get('config_account_id'), $data['email']);
			}
		}
        ]]>
      </add>
    </operation>
  </file>

  <!-- Terms & conditions acceptance -->
  <file path="catalog/model/checkout/order.php">
	<operation error="log">
      <search>
        <![CDATA[$order_id = $this->db->getLastId();]]>
      </search>
      <add position="after">
        <![CDATA[
		$file = DIR_SYSTEM . 'library/gdpr.php';
		if (is_file($file)) {
			if ($this->config->get('config_checkout_id')) {
				$this->load->library('gdpr');
				$this->gdpr->newAcceptanceRequest($this->config->get('config_checkout_id'), $data['email'], false);
			}
		}
        ]]>
      </add>
    </operation>
  </file>

  <!-- Terms & conditions acceptance -->
  <file path="catalog/controller/common/header.php">
	<operation error="log">
      <search>
        <![CDATA[public function index() {]]>
      </search>
      <add position="after">
        <![CDATA[
        $file = DIR_SYSTEM . 'library/gdpr.php';
		$data['cookie_consent_bar'] = '';
		if (is_file($file)) {
			$this->config->load('isenselabs/isenselabs_gdpr');
			$gdpr_name = $this->config->get('isenselabs_gdpr_name');

			$this->load->model('setting/setting');
			$moduleSettings = $this->model_setting_setting->getSetting($gdpr_name, $this->config->get('config_store_id'));
			$gdprData = !empty($moduleSettings[$gdpr_name]) ? $moduleSettings[$gdpr_name] : array();

			if (!empty($gdprData['Enabled']) && $gdprData['Enabled']) {

			  $this->document->addScript('catalog/view/javascript/'. $gdpr_name . '/utils.js');

			  if (!empty($gdprData['CC']['Enabled']) && $gdprData['CC']['Enabled']) {
				if (defined('JOURNAL3_ACTIVE')) {
					$this->document->addScript('catalog/view/javascript/'. $gdpr_name . '/journal3/cookiemanager.js');
					$this->document->addScript('catalog/view/javascript/'. $gdpr_name . '/journal3/cookieconsent.min.js');
				} else {
					$this->document->addScript('catalog/view/javascript/'. $gdpr_name . '/cookiemanager.js');
					$this->document->addScript('catalog/view/javascript/'. $gdpr_name . '/cookieconsent.min.js');
				}
				$this->document->addStyle('catalog/view/javascript/' . $gdpr_name . '/cookieconsent.min.css');
				$data['cookie_consent_bar'] = true;
				$data['gdprModulePath'] = $this->config->get('isenselabs_gdpr_path');
			  }
			}
        }
        ]]>
      </add>
    </operation>
  </file>

  <!-- Contact Form Opt-in Log -->
  <file path="catalog/controller/information/contact.php">
    <operation error="log">
      <search>
        <![CDATA[$this->response->redirect($this->url->link('information/contact/success'));]]>
      </search>
      <add position="before">
        <![CDATA[
		$file = DIR_SYSTEM . 'library/gdpr.php';
		if (is_file($file)) {
			$privacy_policy_id = $this->config->get('config_account_id');
			$this->config->load('isenselabs/isenselabs_gdpr');
			$gdpr_name = $this->config->get('isenselabs_gdpr_name');

			$this->load->model('setting/setting');
			$moduleSettings = $this->model_setting_setting->getSetting($gdpr_name, $this->config->get('config_store_id'));
			$gdpr_data = !empty($moduleSettings[$gdpr_name]) ? $moduleSettings[$gdpr_name] : array();

			if (!empty($gdpr_data['EnabledContactFormOptIn']) && ($gdpr_data['EnabledContactFormOptIn'] == 1) && $privacy_policy_id) {
			  $this->load->library('gdpr');
			  $this->gdpr->newOptin($privacy_policy_id, $this->request->post['email'], 'contact_form', 'acceptance');
			}
        }
        ]]>
      </add>
    </operation>
  </file>

  <!-- Newsletter Opt-in Log -->
  <file path="catalog/model/account/customer.php">
    <operation error="log">
      <search>
        <![CDATA[public function editNewsletter($newsletter) {]]>
      </search>
      <add position="after">
        <![CDATA[
		$file = DIR_SYSTEM . 'library/gdpr.php';
		if (is_file($file)) {
			$privacy_policy_id = $this->config->get('config_account_id');
			$customer_email = $this->customer->getEmail();
			$customer_id = $this->customer->getId();
			$this->config->load('isenselabs/isenselabs_gdpr');
			$gdpr_name = $this->config->get('isenselabs_gdpr_name');

			$this->load->model('setting/setting');
			$moduleSettings = $this->model_setting_setting->getSetting($gdpr_name, $this->config->get('config_store_id'));
			$gdpr_data = !empty($moduleSettings[$gdpr_name]) ? $moduleSettings[$gdpr_name] : array();

			if (!empty($gdpr_data['NewsletterDoubleOptIn']) && ($gdpr_data['NewsletterDoubleOptIn'] == '1') && !empty($customer_email) && isset($newsletter) && $newsletter == '1') {
			  $gdpr_path = $this->config->get('isenselabs_gdpr_path');
			  $gdpr_model = $this->config->get('isenselabs_gdpr_model');
			  $this->load->model($gdpr_path);
			  $gdpr_data = array(
				  'store_id' => $this->config->get('config_store_id'),
				  'email' => $customer_email,
				  'customer_id' => $customer_id
			  );
			  $email_message = $this->{$gdpr_model}->sendNewsletterOptinEmail($gdpr_data);
			  return true;
			}

			if (!empty($gdpr_data['NewsletterOptIn']) && ($gdpr_data['NewsletterOptIn'] == '1') && $privacy_policy_id && !empty($customer_email) && isset($newsletter)) {
			  $this->load->library('gdpr');
			  $this->gdpr->newOptin($privacy_policy_id, $customer_email, 'newsletter', $newsletter ? 'opt-in' : 'opt-out');
			}
        }
        ]]>
      </add>
    </operation>

    <operation error="log">
      <search>
        <![CDATA[$customer_id = $this->db->getLastId();]]>
      </search>
      <add position="after">
        <![CDATA[
		$file = DIR_SYSTEM . 'library/gdpr.php';
		if (is_file($file)) {
			$privacy_policy_id = $this->config->get('config_account_id');
			$newsletter_check = (isset($data['newsletter']) && !empty($data['newsletter'])) ? (int)$data['newsletter'] : 0;
			$this->config->load('isenselabs/isenselabs_gdpr');
			$gdpr_name = $this->config->get('isenselabs_gdpr_name');

			$this->load->model('setting/setting');
			$moduleSettings = $this->model_setting_setting->getSetting($gdpr_name, $this->config->get('config_store_id'));
			$gdpr_data = !empty($moduleSettings[$gdpr_name]) ? $moduleSettings[$gdpr_name] : array();

			if (!empty($gdpr_data['NewsletterDoubleOptIn']) && ($gdpr_data['NewsletterDoubleOptIn'] == '1') && !empty($data['email']) && $newsletter_check) {
			  $gdpr_path = $this->config->get('isenselabs_gdpr_path');
			  $gdpr_model = $this->config->get('isenselabs_gdpr_model');
			  $this->load->model($gdpr_path);
			  $gdpr_data = array(
				  'store_id' => $this->config->get('config_store_id'),
				  'email' => $data['email'],
				  'customer_id' => $customer_id
			  );
			  $email_message = $this->{$gdpr_model}->sendNewsletterOptinEmail($gdpr_data);
			  $customer_newsletter = $this->db->query("UPDATE `" . DB_PREFIX . "customer` SET `newsletter` = '0' WHERE `customer_id` = '" . $this->db->escape($customer_id) . "'");
			} else if (!empty($gdpr_data['NewsletterOptIn']) && ($gdpr_data['NewsletterOptIn'] == '1') && $privacy_policy_id && !empty($data['email']) && $newsletter_check) {
			  $this->load->library('gdpr');
			  $this->gdpr->newOptin($privacy_policy_id, $data['email'], 'newsletter', 'opt-in');
			}
        }
        ]]>
      </add>
    </operation>
  </file>

  <file path="catalog/controller/account/newsletter.php">
    <operation error="log">
      <search>
        <![CDATA[$this->session->data['success'] = $this->language->get('text_success');]]>
      </search>
      <add position="replace">
        <![CDATA[
		$file = DIR_SYSTEM . 'library/gdpr.php';
		if (is_file($file)) {
			$this->config->load('isenselabs/isenselabs_gdpr');
			$gdpr_name = $this->config->get('isenselabs_gdpr_name');

			$this->load->model('setting/setting');
			$moduleSettings = $this->model_setting_setting->getSetting($gdpr_name, $this->config->get('config_store_id'));
			$gdpr_data = !empty($moduleSettings[$gdpr_name]) ? $moduleSettings[$gdpr_name] : array();

			if (!empty($gdpr_data['NewsletterDoubleOptIn']) && ($gdpr_data['NewsletterDoubleOptIn'] == '1') && isset($this->request->post['newsletter']) && $this->request->post['newsletter'] == '1') {
				$gdpr_path = $this->config->get('isenselabs_gdpr_path');
				$gdpr_language_files = $this->language->load($gdpr_path);
				$this->session->data['success'] = $gdpr_language_files['text_succes_message_after_edit_newsletter'];
			}
		} else {
			$this->session->data['success'] = $this->language->get('text_success');
		}
        ]]>
      </add>
    </operation>
  </file>

  <!-- SEO URLs -->
  <file path="catalog/controller/startup/seo_url.php">
	<operation error="skip">
		<search><![CDATA[$parts = explode('/', $this->request->get['_route_']);]]></search>
		<add position="after"><![CDATA[

		$this->load->model('setting/setting');
		$moduleSettings = $this->model_setting_setting->getSetting('isenselabs_gdpr', $this->config->get('config_store_id'));
		$gdprSettings = !empty($moduleSettings['isenselabs_gdpr']) ? $moduleSettings['isenselabs_gdpr'] : array();

		$gdprSeoSlugs = !empty($gdprSettings['Slug']) ? $gdprSettings['Slug'] : array('gdpr-tools');
		$parts = array_filter($parts);
		foreach ($gdprSeoSlugs as $gdpr_slug) {
			if (count($parts) == 1 && ($parts[0] == $gdpr_slug)) {
				$this->request->get['route'] = 'extension/module/isenselabs_gdpr';
				return new Action($this->request->get['route']);
			}
		}
		]]></add>
	</operation>

	<operation error="skip">
		<search><![CDATA[parse_str($url_info['query'], $data);]]></search>
		<add position="after"><![CDATA[
		if (isset($data['route']) && $data['route'] == 'extension/module/isenselabs_gdpr') {
			$this->load->model('setting/setting');
			$moduleSettings = $this->model_setting_setting->getSetting('isenselabs_gdpr', $this->config->get('config_store_id'));
			$gdprSettings = !empty($moduleSettings['isenselabs_gdpr']) ? $moduleSettings['isenselabs_gdpr'] : array();

			$gdprSeoSlug = isset($gdprSettings['Slug'][$this->config->get('config_language_id')]) ? $gdprSettings['Slug'][$this->config->get('config_language_id')] : 'gdpr-tools';
			$url .= '/'.$gdprSeoSlug;
		}
		]]></add>
	</operation>
  </file>

  <!--  Link in My Account Page-->
  <file path="catalog/controller/account/account.php">
	<operation error="log">
      <search>
        <![CDATA[$data['column_left'] = $this->load->controller('common/column_left');]]>
      </search>
      <add position="before">
        <![CDATA[
        $file = DIR_SYSTEM . 'library/gdpr.php';
		$data['text_my_gdpr_tools_header'] = '';
		$data['text_my_gdpr_tools'] = '';
		$data['link_my_gdpr_tools'] = '';
		if (is_file($file)) {
			$this->config->load('isenselabs/isenselabs_gdpr');
			$gdpr_name = $this->config->get('isenselabs_gdpr_name');

			$this->load->model('setting/setting');
			$moduleSettings = $this->model_setting_setting->getSetting($gdpr_name, $this->config->get('config_store_id'));
			$gdprData = !empty($moduleSettings[$gdpr_name]) ? $moduleSettings[$gdpr_name] : array();

			$gdpr_path = $this->config->get('isenselabs_gdpr_path');
			$this->load->language($gdpr_path);
			if (!empty($gdprData['Enabled']) && $gdprData['Enabled']) {
				$data['text_my_gdpr_tools_header'] = $this->language->get('text_my_gdpr_tools_header');
				$data['text_my_gdpr_tools'] = $this->language->get('text_gdpr');
				$data['link_my_gdpr_tools'] = $this->url->link($gdpr_path, '', true);
			}
        }
        ]]>
      </add>
    </operation>
  </file>

  <!-- Save Policies in the GDPR module table -->
  <file path="admin/model/catalog/information.php">
	<operation error="log">
      <search>
        <![CDATA[foreach ($data['information_description'] as $language_id => $value) {]]>
      </search>
      <add position="after">
        <![CDATA[
        // GDPR Compliance 1.9/2.9/3.9
		$file = DIR_SYSTEM . 'library/gdpr.php';
		if (is_file($file)) {
			$check_if_gdpr_table_exists = $this->db->query("SHOW TABLES LIKE '" . DB_PREFIX . "isense_gdpr_policies'");

			if ($check_if_gdpr_table_exists->num_rows) {
				$insert_data = $this->db->query("INSERT INTO `" . DB_PREFIX . "isense_gdpr_policies` SET `policy_id` = '" . (int) $information_id . "', `title` = '" . $this->db->escape($value['title']) . "', `description` = '" . $this->db->escape($value['description']) . "', `date_added` = NOW(), `language_id` = '" . (int) $language_id . "', `store_id` = '0'");
			}
        }
        // GDPR Compliance 1.9/2.9/3.9
        ]]>
      </add>
    </operation>
  </file>

  <!-- AJAX Quick Checkout - Compatibility Fix -->
  <file path="catalog/controller/extension/d_quickcheckout/confirm.php">
	<operation error="skip">
      <search>
        <![CDATA[public function recreateOrder(){]]>
      </search>
      <add position="after">
        <![CDATA[
		$file = DIR_SYSTEM . 'library/gdpr.php';
		if (is_file($file)) {
			if (!empty($this->session->data['confirm']['agree']) && $this->session->data['confirm']['agree'] == 1) {
				$email = $this->customer->getEmail();
				if (empty($email)) {
					if (!empty($this->session->data['guest']['email'])) {
						$email = $this->session->data['guest']['email'];
					} else if (!empty($this->session->data['payment_address']['email'])) {
						$email = $this->session->data['payment_address']['email'];
					}
				}

				if ($this->config->get('config_account_id') && !empty($email)) {
					$this->load->library('gdpr');
					$this->gdpr->newAcceptanceRequest($this->config->get('config_account_id'), $email);
				}
			}
		}
        ]]>
      </add>
    </operation>
  </file>

  <!-- Journal2 Checkout Compatibility Fix -->
  <file path="catalog/controller/journal2/checkout.php">
	<operation error="skip">
      <search>
        <![CDATA[if (Journal2Utils::getProperty($this->request->get, 'saveOnly') === 'true') {]]>
      </search>
      <add position="before">
        <![CDATA[
        $file = DIR_SYSTEM . 'library/gdpr.php';
		if (is_file($file)) {
			if (!$errors) {
				if (!empty($this->request->post['privacy']) && $this->request->post['privacy']==1) {
					if ($this->config->get('config_account_id')) {
						$this->load->library('gdpr');
						$this->gdpr->newAcceptanceRequest($this->config->get('config_account_id'), $order_data['email']);
					}
				}
				if (!empty($this->request->post['agree']) && $this->request->post['agree']==1) {
					if ($this->config->get('config_checkout_id')) {
						$this->load->library('gdpr');
						$this->gdpr->newAcceptanceRequest($this->config->get('config_checkout_id'), $order_data['email']);
					}
				}
			}
        }
        ]]>
      </add>
    </operation>
  </file>

  <!-- Journal3 Checkout Compatibility -->
  <file path="catalog/controller/journal3/checkout.php">
	<operation error="skip">
      <search>
        <![CDATA[$json['error'] = $error ? $error : null;]]>
      </search>
      <add position="after">
        <![CDATA[
		$file = DIR_SYSTEM . 'library/gdpr.php';
		if (is_file($file)) {
			if ($json['error'] == null && !empty($this->request->get['confirm']) && $this->request->get['confirm'] == 'true') {
				if (!empty($this->request->post['privacy']) && $this->request->post['privacy']) {
					if ($this->config->get('config_account_id')) {
						$this->load->library('gdpr');
						$this->gdpr->newAcceptanceRequest($this->config->get('config_account_id'), $this->request->post['order_data']['email']);
					}
				}
				if (!empty($this->request->post['agree']) && $this->request->post['agree']) {
					if ($this->config->get('config_checkout_id')) {
						$this->load->library('gdpr');
						$this->gdpr->newAcceptanceRequest($this->config->get('config_checkout_id'), $this->request->post['order_data']['email']);
					}
				}
			}
        }
        ]]>
      </add>
    </operation>
  </file>
  <!-- Journal3 Newsletter Opt-in Log -->
  <file path="catalog/controller/journal3/newsletter.php">
	<operation error="log">
      <search>
        <![CDATA[$this->model_journal3_newsletter->unsubscribe($email);]]>
      </search>
      <add position="after">
        <![CDATA[$file = DIR_SYSTEM . 'library/gdpr.php';
		if (is_file($file)) {
			$privacy_policy_id = $this->config->get('config_account_id');
			$this->config->load('isenselabs/isenselabs_gdpr');
			$gdpr_name = $this->config->get('isenselabs_gdpr_name');

			$this->load->model('setting/setting');
			$moduleSettings = $this->model_setting_setting->getSetting($gdpr_name, $this->config->get('config_store_id'));
			$gdpr_data = !empty($moduleSettings[$gdpr_name]) ? $moduleSettings[$gdpr_name] : array();

			if (!empty($gdpr_data['NewsletterOptIn']) && ($gdpr_data['NewsletterOptIn'] == '1') && $privacy_policy_id && !empty($unsubscribe) && isset($unsubscribe)) {
			  $this->load->library('gdpr');
			  $this->gdpr->newOptin($privacy_policy_id, $email, 'journal3 newsletter', 'opt-out');
			}
        }]]>
      </add>
    </operation>
    <operation error="log">
      <search>
        <![CDATA[$this->model_journal3_newsletter->subscribe($email);]]>
      </search>
      <add position="after">
        <![CDATA[
		$file = DIR_SYSTEM . 'library/gdpr.php';
		if (is_file($file)) {
			$privacy_policy_id = $this->config->get('config_account_id');
			$customer_id = $this->customer->getId();
			$this->config->load('isenselabs/isenselabs_gdpr');
			$gdpr_name = $this->config->get('isenselabs_gdpr_name');

			$this->load->model('setting/setting');
			$moduleSettings = $this->model_setting_setting->getSetting($gdpr_name, $this->config->get('config_store_id'));
			$gdpr_data = !empty($moduleSettings[$gdpr_name]) ? $moduleSettings[$gdpr_name] : array();

			if (!empty($gdpr_data['NewsletterDoubleOptIn']) && ($gdpr_data['NewsletterDoubleOptIn'] == '1') && !empty($email)) {
			  $gdpr_path = $this->config->get('isenselabs_gdpr_path');
			  $gdpr_language_files = $this->language->load($gdpr_path);
			  $gdpr_model = $this->config->get('isenselabs_gdpr_model');
			  $this->load->model($gdpr_path);
			  $gdpr_data = array(
				  'store_id' => $this->config->get('config_store_id'),
				  'email' => $email,
				  'customer_id' => $customer_id
			  );
			  $email_message = $this->{$gdpr_model}->sendJournal3NewsletterOptinEmail($gdpr_data);
			  $customer_newsletter = $this->db->query("DELETE FROM `" . DB_PREFIX . "journal3_newsletter` WHERE `email` = '" . $this->db->escape($email) . "'");
			  $data['message'] = $gdpr_language_files['text_succes_message_after_edit_newsletter'];
			} else if (!empty($gdpr_data['NewsletterOptIn']) && ($gdpr_data['NewsletterOptIn'] == '1') && $privacy_policy_id && !empty($email)) {
			  $this->load->library('gdpr');
			  $this->gdpr->newOptin($privacy_policy_id, $email, 'journal3 newsletter', 'opt-in');
			  $data['message'] = $this->settings['subscribedMessage'];

				if ($this->settings['subscribedEmail']) {
					$email_data['message'] = $this->settings['subscribedEmailMessage'];

					$this->load->controller('journal3/mail/send', array(
						'to'      => $email,
						'subject' => $this->config->get('config_name'),
						'message' => $this->load->view('journal3/module/newsletter_subscribed_email', $email_data),
					));
				}

				if ($this->settings['adminAlerts']) {
					$email_data['message'] = sprintf('New customer subscribed: %s.', $email);

					$this->load->controller('journal3/mail/send', array(
						'to'      => $this->config->get('config_email'),
						'subject' => $this->config->get('config_name'),
						'message' => $this->load->view('journal3/module/newsletter_admin_email', $email_data),
					));
				}
			} else {
				$data['message'] = $this->settings['subscribedMessage'];

				if ($this->settings['subscribedEmail']) {
					$email_data['message'] = $this->settings['subscribedEmailMessage'];

					$this->load->controller('journal3/mail/send', array(
						'to'      => $email,
						'subject' => $this->config->get('config_name'),
						'message' => $this->load->view('journal3/module/newsletter_subscribed_email', $email_data),
					));
				}

				if ($this->settings['adminAlerts']) {
					$email_data['message'] = sprintf('New customer subscribed: %s.', $email);

					$this->load->controller('journal3/mail/send', array(
						'to'      => $this->config->get('config_email'),
						'subject' => $this->config->get('config_name'),
						'message' => $this->load->view('journal3/module/newsletter_admin_email', $email_data),
					));
				}
			}
		} else {
        ]]>
      </add>
    </operation>
  
    <operation error="log">
      <search>
        <![CDATA[$this->renderJson(self::SUCCESS, $data);]]>
      </search>
      <add position="before" offset="2">
        <![CDATA[}]]>
      </add>
    </operation>
  </file>
  <!-- Journal2 Newsletter Opt-in Log -->
  <file path="catalog/controller/module/journal2_newsletter.php">
	<operation error="log">
      <search>
        <![CDATA[$response['message'] = $this->journal2->settings->get('newsletter_subscribed_message', 'Thank you for subscribing on our newsletter.');]]>
      </search>
      <add position="after">
        <![CDATA[}]]>
      </add>
    </operation>
	<operation error="log">
      <search>
        <![CDATA[$newsletter->subscribe();]]>
      </search>
      <add position="after">
        <![CDATA[$file = DIR_SYSTEM . 'library/gdpr.php';
				if (is_file($file)) {
					$privacy_policy_id = $this->config->get('config_account_id');
					$customer_id = $this->customer->getId();
					$this->config->load('isenselabs/isenselabs_gdpr');
					$gdpr_name = $this->config->get('isenselabs_gdpr_name');

					$this->load->model('setting/setting');
					$moduleSettings = $this->model_setting_setting->getSetting($gdpr_name, $this->config->get('config_store_id'));
					$gdpr_data = !empty($moduleSettings[$gdpr_name]) ? $moduleSettings[$gdpr_name] : array();

					if (!empty($gdpr_data['NewsletterDoubleOptIn']) && ($gdpr_data['NewsletterDoubleOptIn'] == '1') && !empty($this->request->post['email'])) {
						$gdpr_path = $this->config->get('isenselabs_gdpr_path');
						$gdpr_language_files = $this->language->load($gdpr_path);
						$gdpr_model = $this->config->get('isenselabs_gdpr_model');
						$this->load->model($gdpr_path);
						$gdpr_data = array(
							'store_id' => $this->config->get('config_store_id'),
							'email' => $this->request->post['email'],
							'customer_id' => $customer_id
						);
					  $email_message = $this->{$gdpr_model}->sendJournal2NewsletterOptinEmail($gdpr_data);
					  $query = $this->db->query('SELECT customer_id FROM ' . DB_PREFIX . 'customer WHERE email = "' . $this->db->escape($this->request->post['email']) . '"');
						if ($query->num_rows > 0) {
							$this->db->query('UPDATE ' . DB_PREFIX . 'customer SET newsletter = 0 WHERE customer_id = "' . (int)$query->row['customer_id'] . '"');
						} else {
							$this->db->query("DELETE FROM `" . DB_PREFIX . "journal2_newsletter` WHERE `email` = '" . $this->db->escape($this->request->post['email']) . "'");
						}
						//$data['message'] = $gdpr_language_files['text_succes_message_after_edit_newsletter'];
						$response['status'] = 'success';
						$response['message'] = $this->journal2->settings->get('newsletter_subscribed_message', $gdpr_language_files['text_succes_message_after_edit_newsletter']);
					} else if (!empty($gdpr_data['NewsletterOptIn']) && ($gdpr_data['NewsletterOptIn'] == '1') && $privacy_policy_id && !empty($this->request->post['email'])) {
					  $this->load->library('gdpr');
					  $this->gdpr->newOptin($privacy_policy_id, $this->request->post['email'], 'journal2 newsletter', 'opt-in');
						$response['status'] = 'success';
						$response['message'] = $this->journal2->settings->get('newsletter_subscribed_message', 'Thank you for subscribing on our newsletter.');
					} else {
						$response['status'] = 'success';
						$response['message'] = $this->journal2->settings->get('newsletter_subscribed_message', 'Thank you for subscribing on our newsletter.');
					}
				} else {]]>
      </add>
    </operation>
    <operation error="log">
      <search>
        <![CDATA[$newsletter->unsubscribe();]]>
      </search>
      <add position="after">
        <![CDATA[
				$file = DIR_SYSTEM . 'library/gdpr.php';
				if (is_file($file)) {
					$privacy_policy_id = $this->config->get('config_account_id');
					$this->config->load('isenselabs/isenselabs_gdpr');
					$gdpr_name = $this->config->get('isenselabs_gdpr_name');

					$this->load->model('setting/setting');
					$moduleSettings = $this->model_setting_setting->getSetting($gdpr_name, $this->config->get('config_store_id'));
					$gdpr_data = !empty($moduleSettings[$gdpr_name]) ? $moduleSettings[$gdpr_name] : array();

					if (!empty($gdpr_data['NewsletterOptIn']) && ($gdpr_data['NewsletterOptIn'] == '1') && $privacy_policy_id) {
					  $this->load->library('gdpr');
					  $this->gdpr->newOptin($privacy_policy_id, $this->request->post['email'], 'journal2 newsletter', 'opt-out');
					}
				}]]>
      </add>
    </operation>
  </file>

</modification>
