From 2c7333fd65a916e8e9cf7b1be96f7edb90a45258 Mon Sep 17 00:00:00 2001 From: Alexandre Simonet Date: Wed, 24 Feb 2016 17:15:28 +0100 Subject: [PATCH 01/13] Done functional config module --- modules/contactform/contactform.php | 98 ++++++++++++++++------------- 1 file changed, 54 insertions(+), 44 deletions(-) diff --git a/modules/contactform/contactform.php b/modules/contactform/contactform.php index be180d77..fde6ab72 100644 --- a/modules/contactform/contactform.php +++ b/modules/contactform/contactform.php @@ -44,20 +44,18 @@ class Contactform extends Module { PRIMARY KEY (`id_contactform`) ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8; ') -// && Db::getInstance()->Execute(' -// CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'contactform_email` ( -// `id_contactform_email` INT UNSIGNED NOT NULL AUTO_INCREMENT, -// `email` VARCHAR(255) NULL, -// PRIMARY KEY (`id_contactform_email`) -// ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8; -// ') -; + && Db::getInstance()->Execute(' + CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'contactform_email` ( + `id_contactform_email` INT UNSIGNED NOT NULL AUTO_INCREMENT, + `email` VARCHAR(255) NULL, + PRIMARY KEY (`id_contactform_email`) + ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8; + '); } public function uninstallDB() { return Db::getInstance()->Execute('DROP TABLE `'._DB_PREFIX_.'contactform`;') - //&& Db::getInstance()->Execute('DROP TABLE `'._DB_PREFIX_.'contactform_email`;') - ; + && Db::getInstance()->Execute('DROP TABLE `'._DB_PREFIX_.'contactform_email`;'); } public function install() { @@ -74,39 +72,51 @@ class Contactform extends Module { return TRUE; } -// public function getContent() { -// -// $content = " -// {{ error }} -//
-// -// -// -// "; -// -// if ($_POST) { -// if (empty($_POST['emails'])) { -// $content = str_replace('{{ error }}', "Aucune adresse email n'a été renseignée", $content); -// return $content; -// } -// $emails = explode("\n", $_POST['emails']); -// foreach ($emails as $k => $email) { -// $email[$k] = trim($email); -// } -// $emails = array_unique($emails); -// foreach ($emails as $k => $email) { -// if (!$this->emailExistInDb($email)) { -// $content = str_replace('{{ error }}', "Existe pas", $content); -// } -// } -// } -// -// $content = str_replace('{{ error }}', "", $content); -// return $content; -// } -// -// private function emailExistInDb($email) { -// return (Db::getInstance()->executeS("SELECT COUNT(*) as count FROM `"._DB_PREFIX_."contactform_email` WHERE email = \"".pSQL($email)."\" ")[0]['count'] != 0); -// } + public function getContent() { + + $content = " + {{ error }} + + + + + "; + + if ($_POST) { + if (empty($_POST['emails'])) { + $content = str_replace('{{ error }}', $this->l("Aucune adresse email n'a été renseignée"), $content); + $content = str_replace('{{ emails }}', "", $content); + return $content; + } + $emails = explode("\n", trim($_POST['emails'])); + foreach ($emails as $k => $email) { + $email[$k] = trim($email); + } + $emails = array_unique($emails); + + DB::getInstance()->executeS("DELETE FROM "._DB_PREFIX_."contactform_email"); + + foreach ($emails as $k => $email) { + Db::getInstance()->autoExecute(_DB_PREFIX_.'contactform_email', [ + 'email' => pSQL($email) + ], 'INSERT'); + } + + $content = str_replace('{{ error }}', $this->l("Modification effectuée"), $content); + } else { + $content = str_replace('{{ error }}', "", $content); + } + + $currentEmails = Db::getInstance()->ExecuteS("SELECT email FROM "._DB_PREFIX_."contactform_email"); + + $contentEmail = ''; + foreach ($currentEmails as $k => $row) { + $contentEmail .= $row['email']."\n"; + } + + $content = str_replace('{{ emails }}', $contentEmail, $content); + return $content; + } + } From 191ccd100548361eb8626d51e9758e1c11ff1723 Mon Sep 17 00:00:00 2001 From: Alexandre Simonet Date: Wed, 24 Feb 2016 17:20:15 +0100 Subject: [PATCH 02/13] Fix mail on sending mail --- modules/contactform/Process.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/contactform/Process.php b/modules/contactform/Process.php index 23da34ba..3722475a 100644 --- a/modules/contactform/Process.php +++ b/modules/contactform/Process.php @@ -4,12 +4,16 @@ class Process { private $data; private $mail_dir; - private $to; + private $to = []; public function __construct() { $this->mail_dir = dirname(__FILE__); - $this->to = 'simonet@antadis.com'; + + $_to = Db::getInstance()->ExecuteS("SELECT email FROM "._DB_PREFIX_."contactform_email"); + foreach ($_to as $k => $email) { + $this->to[] = $email; + } } public function addProvider($post) From 24622917fe70893a64332399305027ca0efa749d Mon Sep 17 00:00:00 2001 From: Alexandre Simonet Date: Thu, 25 Feb 2016 10:28:03 +0100 Subject: [PATCH 03/13] Front module configuration --- modules/contactform/contactform.php | 63 +++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 13 deletions(-) diff --git a/modules/contactform/contactform.php b/modules/contactform/contactform.php index fde6ab72..20f18b8d 100644 --- a/modules/contactform/contactform.php +++ b/modules/contactform/contactform.php @@ -18,8 +18,8 @@ class Contactform extends Module { parent::__construct(); - $this->displayName = $this->l('Contact form for press and providers'); - $this->description = $this->l('Integrate contact form.'); + $this->displayName = $this->l('Formulaire de contact pour les fournisseurs et la presse'); + $this->description = $this->l('Intégration de formulaire de contact'); $this->assets_module_dir = dirname(__FILE__); } @@ -74,15 +74,47 @@ class Contactform extends Module { public function getContent() { - $content = " - {{ error }} - - - - - "; + $content = " - if ($_POST) { +

Formulaire de contact pour les fournisseurs et la presse

+ + +

{{ error }}

+ + + + "; + + if (Tools::isSubmit('update_mail')) { if (empty($_POST['emails'])) { $content = str_replace('{{ error }}', $this->l("Aucune adresse email n'a été renseignée"), $content); $content = str_replace('{{ emails }}', "", $content); @@ -90,11 +122,16 @@ class Contactform extends Module { } $emails = explode("\n", trim($_POST['emails'])); foreach ($emails as $k => $email) { - $email[$k] = trim($email); + $email = trim($email); + if (Validate::isEmail($email)) { + $emails[$k] = $email; + } else { + array_splice($emails, $k); + } } $emails = array_unique($emails); - DB::getInstance()->executeS("DELETE FROM "._DB_PREFIX_."contactform_email"); + DB::getInstance()->executeS("DELETE FROM `"._DB_PREFIX_."contactform_email`"); foreach ($emails as $k => $email) { Db::getInstance()->autoExecute(_DB_PREFIX_.'contactform_email', [ @@ -107,7 +144,7 @@ class Contactform extends Module { $content = str_replace('{{ error }}', "", $content); } - $currentEmails = Db::getInstance()->ExecuteS("SELECT email FROM "._DB_PREFIX_."contactform_email"); + $currentEmails = Db::getInstance()->ExecuteS("SELECT `email` FROM `"._DB_PREFIX_."contactform_email`"); $contentEmail = ''; foreach ($currentEmails as $k => $row) { From 451bb54c507395cf5b35f18d68ed0e2e162e4d90 Mon Sep 17 00:00:00 2001 From: Alexandre Simonet Date: Thu, 25 Feb 2016 10:42:49 +0100 Subject: [PATCH 04/13] Validate form --- modules/contactform/Process.php | 126 ++++++++++++++++--------------- modules/contactform/press.php | 2 +- modules/contactform/press.tpl | 2 +- modules/contactform/provider.php | 2 +- modules/contactform/provider.tpl | 2 +- 5 files changed, 71 insertions(+), 63 deletions(-) diff --git a/modules/contactform/Process.php b/modules/contactform/Process.php index 3722475a..47eb158d 100644 --- a/modules/contactform/Process.php +++ b/modules/contactform/Process.php @@ -10,7 +10,7 @@ class Process { $this->mail_dir = dirname(__FILE__); - $_to = Db::getInstance()->ExecuteS("SELECT email FROM "._DB_PREFIX_."contactform_email"); + $_to = Db::getInstance()->ExecuteS('SELECT email FROM '._DB_PREFIX_.'contactform_email'); foreach ($_to as $k => $email) { $this->to[] = $email; } @@ -24,37 +24,41 @@ class Process if (!$isCorrect) { $errors[] = 'Tous les champs ne sont pas remplis'; } else { - $query = Db::getInstance()->autoExecute(_DB_PREFIX_.'contactform', [ - 'brand' => pSQL($this->data['brand']), - 'compagny' => pSQL($this->data['compagny']), - 'lastname' => pSQL($this->data['lastname']), - 'firstname' => pSQL($this->data['firstname']), - 'function' => pSQL($this->data['function']), - 'email1' => pSQL($this->data['email1']), - 'email2' => pSQL($this->data['email2']), - 'phone1' => pSQL($this->data['phone1']), - 'phone2' => pSQL($this->data['phone2']), - 'purpose' => pSQL($this->data['purpose']), - 'content' => pSQL($this->data['content']), - 'type' => Contactform::TYPE_PROVIDER - ], 'INSERT'); - - if (!$query) { - $errors[] = "Une erreur s'est produite. Votre message n'a pas été envoyé"; + if (!Validate::isEmail($tthis->data['email1']) || !(Validate::isEmail($tthis->data['email1']) && Validate::isEmail($tthis->data['email2']))) { + $errors[] = 'Certains champs ne sont pas valide'; } else { - Mail::Send( - intval($cookie->id_lang), - 'provider', - 'sujet', - $this->data, - $this->to, - NULL, - NULL, - NULL, - NULL, - NULL, - $this->mail_dir - ); + $query = Db::getInstance()->autoExecute(_DB_PREFIX_.'contactform', [ + 'brand' => pSQL($this->data['brand']), + 'compagny' => pSQL($this->data['compagny']), + 'lastname' => pSQL($this->data['lastname']), + 'firstname' => pSQL($this->data['firstname']), + 'function' => pSQL($this->data['function']), + 'email1' => pSQL($this->data['email1']), + 'email2' => pSQL($this->data['email2']), + 'phone1' => pSQL($this->data['phone1']), + 'phone2' => pSQL($this->data['phone2']), + 'purpose' => pSQL($this->data['purpose']), + 'content' => pSQL($this->data['content']), + 'type' => Contactform::TYPE_PROVIDER + ], 'INSERT'); + + if (!$query) { + $errors[] = 'Une erreur s\'est produite. Votre message n\'a pas été envoyé'; + } else { + Mail::Send( + intval($cookie->id_lang), + 'provider', + 'sujet', + $this->data, + $this->to, + NULL, + NULL, + NULL, + NULL, + NULL, + $this->mail_dir + ); + } } } @@ -72,35 +76,39 @@ class Process if (!$isCorrect) { $errors[] = 'Tous les champs ne sont pas remplis'; } else { - $query = Db::getInstance()->autoExecute(_DB_PREFIX_.'contactform', [ - 'compagny' => pSQL($this->data['compagny']), - 'lastname' => pSQL($this->data['lastname']), - 'firstname' => pSQL($this->data['firstname']), - 'function' => pSQL($this->data['function']), - 'email1' => pSQL($this->data['email1']), - 'email2' => pSQL($this->data['email2']), - 'phone1' => pSQL($this->data['phone1']), - 'phone2' => pSQL($this->data['phone2']), - 'content' => pSQL($this->data['content']), - 'type' => Contactform::TYPE_PRESS - ], 'INSERT'); - - if (!$query) { - $errors[] = "Une erreur s'est produite. Votre message n'a pas été envoyé"; + if (!Validate::isEmail($tthis->data['email1']) || !(Validate::isEmail($tthis->data['email1']) && Validate::isEmail($tthis->data['email2']))) { + $errors[] = 'Certains champs ne sont pas valide'; } else { - Mail::Send( - intval($cookie->id_lang), - 'press', - 'sujet', - $this->data, - $this->to, - NULL, - NULL, - NULL, - NULL, - NULL, - $this->mail_dir - ); + $query = Db::getInstance()->autoExecute(_DB_PREFIX_.'contactform', [ + 'compagny' => pSQL($this->data['compagny']), + 'lastname' => pSQL($this->data['lastname']), + 'firstname' => pSQL($this->data['firstname']), + 'function' => pSQL($this->data['function']), + 'email1' => pSQL($this->data['email1']), + 'email2' => pSQL($this->data['email2']), + 'phone1' => pSQL($this->data['phone1']), + 'phone2' => pSQL($this->data['phone2']), + 'content' => pSQL($this->data['content']), + 'type' => Contactform::TYPE_PRESS + ], 'INSERT'); + + if (!$query) { + $errors[] = 'Une erreur s\'est produite. Votre message n\'a pas été envoyé'; + } else { + Mail::Send( + intval($cookie->id_lang), + 'press', + 'sujet', + $this->data, + $this->to, + NULL, + NULL, + NULL, + NULL, + NULL, + $this->mail_dir + ); + } } } diff --git a/modules/contactform/press.php b/modules/contactform/press.php index 5f8450c9..09d61219 100644 --- a/modules/contactform/press.php +++ b/modules/contactform/press.php @@ -8,7 +8,7 @@ include_once(dirname(__FILE__).'/Process.php'); include(dirname(__FILE__).'/../../header.php'); $result = null; -if (!empty($_POST['type'])) { +if (Tools::isSubmit('press_form')) { $Process = new Process(); $result = $Process->addPress($_POST); } diff --git a/modules/contactform/press.tpl b/modules/contactform/press.tpl index 809a546a..818ada7e 100644 --- a/modules/contactform/press.tpl +++ b/modules/contactform/press.tpl @@ -75,7 +75,7 @@ - + diff --git a/modules/contactform/provider.php b/modules/contactform/provider.php index 0e8cd09c..1821248a 100644 --- a/modules/contactform/provider.php +++ b/modules/contactform/provider.php @@ -8,7 +8,7 @@ include_once(dirname(__FILE__).'/Process.php'); include(dirname(__FILE__).'/../../header.php'); $result = null; -if (!empty($_POST['type'])) { +if (Tools::isSubmit('provider_form')) { $Process = new Process(); $result = $Process->addProvider($_POST); } diff --git a/modules/contactform/provider.tpl b/modules/contactform/provider.tpl index 5ba4a346..fe26fc0d 100644 --- a/modules/contactform/provider.tpl +++ b/modules/contactform/provider.tpl @@ -84,7 +84,7 @@ - + From 0f07c1ab385e17db3ea6d67de4c1c5681be760d2 Mon Sep 17 00:00:00 2001 From: Alexandre Simonet Date: Thu, 25 Feb 2016 10:55:05 +0100 Subject: [PATCH 05/13] Fix email checking --- modules/contactform/Process.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/contactform/Process.php b/modules/contactform/Process.php index 47eb158d..feee4493 100644 --- a/modules/contactform/Process.php +++ b/modules/contactform/Process.php @@ -24,7 +24,7 @@ class Process if (!$isCorrect) { $errors[] = 'Tous les champs ne sont pas remplis'; } else { - if (!Validate::isEmail($tthis->data['email1']) || !(Validate::isEmail($tthis->data['email1']) && Validate::isEmail($tthis->data['email2']))) { + if (!Validate::isEmail($this->data['email1'])) { $errors[] = 'Certains champs ne sont pas valide'; } else { $query = Db::getInstance()->autoExecute(_DB_PREFIX_.'contactform', [ @@ -76,7 +76,7 @@ class Process if (!$isCorrect) { $errors[] = 'Tous les champs ne sont pas remplis'; } else { - if (!Validate::isEmail($tthis->data['email1']) || !(Validate::isEmail($tthis->data['email1']) && Validate::isEmail($tthis->data['email2']))) { + if (!Validate::isEmail($this->data['email1'])) { $errors[] = 'Certains champs ne sont pas valide'; } else { $query = Db::getInstance()->autoExecute(_DB_PREFIX_.'contactform', [ From e2806c9a6b5774bba1e65699eef7aa74d31b1aa1 Mon Sep 17 00:00:00 2001 From: Alexandre Simonet Date: Thu, 25 Feb 2016 11:11:35 +0100 Subject: [PATCH 06/13] Fix quote --- modules/contactform/Process.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/contactform/Process.php b/modules/contactform/Process.php index feee4493..8d5d9b6d 100644 --- a/modules/contactform/Process.php +++ b/modules/contactform/Process.php @@ -10,7 +10,7 @@ class Process { $this->mail_dir = dirname(__FILE__); - $_to = Db::getInstance()->ExecuteS('SELECT email FROM '._DB_PREFIX_.'contactform_email'); + $_to = Db::getInstance()->ExecuteS('SELECT `email` FROM '._DB_PREFIX_.'contactform_email'); foreach ($_to as $k => $email) { $this->to[] = $email; } From 11966aea9bd701bb1d878968303e801a0a277f19 Mon Sep 17 00:00:00 2001 From: Alexandre Simonet Date: Thu, 25 Feb 2016 11:11:56 +0100 Subject: [PATCH 07/13] Fix quote --- modules/contactform/Process.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/contactform/Process.php b/modules/contactform/Process.php index 8d5d9b6d..432d32fc 100644 --- a/modules/contactform/Process.php +++ b/modules/contactform/Process.php @@ -10,7 +10,7 @@ class Process { $this->mail_dir = dirname(__FILE__); - $_to = Db::getInstance()->ExecuteS('SELECT `email` FROM '._DB_PREFIX_.'contactform_email'); + $_to = Db::getInstance()->ExecuteS('SELECT `email` FROM `'._DB_PREFIX_.'contactform_email`'); foreach ($_to as $k => $email) { $this->to[] = $email; } From 9c7c23d9fb161517f90878745469ed7ec1d723d3 Mon Sep 17 00:00:00 2001 From: Alexandre Simonet Date: Thu, 25 Feb 2016 12:27:58 +0100 Subject: [PATCH 08/13] Fix config multi form --- modules/contactform/contactform.php | 93 +++++++++++++++++++++++------ 1 file changed, 75 insertions(+), 18 deletions(-) diff --git a/modules/contactform/contactform.php b/modules/contactform/contactform.php index 20f18b8d..78792ae9 100644 --- a/modules/contactform/contactform.php +++ b/modules/contactform/contactform.php @@ -48,6 +48,7 @@ class Contactform extends Module { CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'contactform_email` ( `id_contactform_email` INT UNSIGNED NOT NULL AUTO_INCREMENT, `email` VARCHAR(255) NULL, + `type` INT(11) NOT NULL, PRIMARY KEY (`id_contactform_email`) ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8; '); @@ -83,6 +84,7 @@ class Contactform extends Module { form.module { padding: 20px; background: #F4E6C9; + display: inline-block; } form.module label, form.module input, form.module textarea { display: block; @@ -103,21 +105,61 @@ class Contactform extends Module { padding: 10px 20px; cursor: pointer; } + .form-inline { + display: inline-block; + margin: 20px; + } -

Formulaire de contact pour les fournisseurs et la presse

+
+

Formulaire de contact pour les fournisseurs

-
-

{{ error }}

- - - -
"; +
+

{{ error_provider }}

+ + + + +
+
+ +
+

Formulaire de contact pour la presse

+ +
+

{{ error_press }}

+ + + + +
+
"; if (Tools::isSubmit('update_mail')) { if (empty($_POST['emails'])) { - $content = str_replace('{{ error }}', $this->l("Aucune adresse email n'a été renseignée"), $content); - $content = str_replace('{{ emails }}', "", $content); + if ($_POST['type'] == Contactform::TYPE_PROVIDER) { + $content = str_replace('{{ error_provider }}', $this->l("Aucune adresse email n'a été renseignée"), $content); + $content = str_replace('{{ error_press }}', "", $content); + } else { + $content = str_replace('{{ error_press }}', $this->l("Aucune adresse email n'a été renseignée"), $content); + $content = str_replace('{{ error_provider }}', "", $content); + } + + $contentEmails = Db::getInstance()->ExecuteS('SELECT `email`, `type` FROM `'._DB_PREFIX_.'contactform_email`'); + $contentEmailProvider = ''; + $contentEmailPress = ''; + foreach ($contentEmails as $k => $row) { + if ($row['type'] == Contactform::TYPE_PROVIDER) { + $contentEmailProvider .= $row['email']."\n"; + } + if ($row['type'] == Contactform::TYPE_PRESS) { + $contentEmailPress .= $row['email']."\n"; + } + } + + $content = str_replace('{{ emails_provider }}', $contentEmailProvider, $content); + $content = str_replace('{{ emails_press }}', $contentEmailPress, $content); + return $content; } $emails = explode("\n", trim($_POST['emails'])); @@ -131,27 +173,42 @@ class Contactform extends Module { } $emails = array_unique($emails); - DB::getInstance()->executeS("DELETE FROM `"._DB_PREFIX_."contactform_email`"); + DB::getInstance()->executeS('DELETE FROM `'._DB_PREFIX_.'contactform_email` WHERE `type` = '.$_POST['type']); foreach ($emails as $k => $email) { Db::getInstance()->autoExecute(_DB_PREFIX_.'contactform_email', [ - 'email' => pSQL($email) + 'email' => pSQL($email), + 'type' => pSQL($_POST['type']) ], 'INSERT'); } - $content = str_replace('{{ error }}', $this->l("Modification effectuée"), $content); + if ($_POST['type'] == Contactform::TYPE_PROVIDER) { + $content = str_replace('{{ error_provider }}', $this->l("Modification effectuée"), $content); + $content = str_replace('{{ error_press }}', "", $content); + } else { + $content = str_replace('{{ error_press }}', $this->l("Modification effectuée"), $content); + $content = str_replace('{{ error_provider }}',"", $content); + } } else { - $content = str_replace('{{ error }}', "", $content); + $content = str_replace('{{ error_provider }}', "", $content); + $content = str_replace('{{ error_press }}', "", $content); } - $currentEmails = Db::getInstance()->ExecuteS("SELECT `email` FROM `"._DB_PREFIX_."contactform_email`"); + $contentEmails = Db::getInstance()->ExecuteS('SELECT `email`, `type` FROM `'._DB_PREFIX_.'contactform_email`'); - $contentEmail = ''; - foreach ($currentEmails as $k => $row) { - $contentEmail .= $row['email']."\n"; + $contentEmailProvider = ''; + $contentEmailPress = ''; + foreach ($contentEmails as $k => $row) { + if ($row['type'] == Contactform::TYPE_PROVIDER) { + $contentEmailProvider .= $row['email']."\n"; + } + if ($row['type'] == Contactform::TYPE_PRESS) { + $contentEmailPress .= $row['email']."\n"; + } } - $content = str_replace('{{ emails }}', $contentEmail, $content); + $content = str_replace('{{ emails_provider }}', $contentEmailProvider, $content); + $content = str_replace('{{ emails_press }}', $contentEmailPress, $content); return $content; } From 9943a42a9e243a2b19da79ecfd2089740756aaaa Mon Sep 17 00:00:00 2001 From: Alexandre Simonet Date: Thu, 25 Feb 2016 12:30:06 +0100 Subject: [PATCH 09/13] Fix multi mail config --- modules/contactform/Process.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/modules/contactform/Process.php b/modules/contactform/Process.php index 432d32fc..37d0eec9 100644 --- a/modules/contactform/Process.php +++ b/modules/contactform/Process.php @@ -4,15 +4,21 @@ class Process { private $data; private $mail_dir; - private $to = []; + private $to_provider = []; + private $to_press = []; public function __construct() { $this->mail_dir = dirname(__FILE__); - $_to = Db::getInstance()->ExecuteS('SELECT `email` FROM `'._DB_PREFIX_.'contactform_email`'); + $_to = Db::getInstance()->ExecuteS('SELECT `email`, `type` FROM `'._DB_PREFIX_.'contactform_email`'); foreach ($_to as $k => $email) { - $this->to[] = $email; + if ($email['type'] == Contactform::TYPE_PROVIDER) { + $to_provider[] = $email['email']; + } + if ($email['type'] == Contactform::TYPE_PRESS) { + $to_press[] = $email['email']; + } } } @@ -50,7 +56,7 @@ class Process 'provider', 'sujet', $this->data, - $this->to, + $this->to_provider, NULL, NULL, NULL, @@ -100,7 +106,7 @@ class Process 'press', 'sujet', $this->data, - $this->to, + $this->to_press, NULL, NULL, NULL, From d74c4003eabaee6844a713ff0b5ffd55d6047713 Mon Sep 17 00:00:00 2001 From: Alexandre Simonet Date: Thu, 25 Feb 2016 12:32:31 +0100 Subject: [PATCH 10/13] Change subject mail --- modules/contactform/Process.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/contactform/Process.php b/modules/contactform/Process.php index 37d0eec9..9ccdd48b 100644 --- a/modules/contactform/Process.php +++ b/modules/contactform/Process.php @@ -54,7 +54,7 @@ class Process Mail::Send( intval($cookie->id_lang), 'provider', - 'sujet', + 'Contact fournisseur', $this->data, $this->to_provider, NULL, @@ -104,7 +104,7 @@ class Process Mail::Send( intval($cookie->id_lang), 'press', - 'sujet', + 'Contact presse', $this->data, $this->to_press, NULL, From 13d92a673257ee28921686bc15874879392694cf Mon Sep 17 00:00:00 2001 From: Alexandre Simonet Date: Thu, 25 Feb 2016 12:43:33 +0100 Subject: [PATCH 11/13] Fix injection --- modules/contactform/contactform.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/contactform/contactform.php b/modules/contactform/contactform.php index 78792ae9..acff7c45 100644 --- a/modules/contactform/contactform.php +++ b/modules/contactform/contactform.php @@ -173,7 +173,7 @@ class Contactform extends Module { } $emails = array_unique($emails); - DB::getInstance()->executeS('DELETE FROM `'._DB_PREFIX_.'contactform_email` WHERE `type` = '.$_POST['type']); + DB::getInstance()->executeS('DELETE FROM `'._DB_PREFIX_.'contactform_email` WHERE `type` = '.pSQL($_POST['type'])); foreach ($emails as $k => $email) { Db::getInstance()->autoExecute(_DB_PREFIX_.'contactform_email', [ From f4f1b00946b589634659c1feb71014d0a537e678 Mon Sep 17 00:00:00 2001 From: Alexandre Simonet Date: Thu, 25 Feb 2016 14:15:51 +0100 Subject: [PATCH 12/13] Fix var --- modules/contactform/contactform.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/contactform/contactform.php b/modules/contactform/contactform.php index acff7c45..bf951baf 100644 --- a/modules/contactform/contactform.php +++ b/modules/contactform/contactform.php @@ -173,7 +173,7 @@ class Contactform extends Module { } $emails = array_unique($emails); - DB::getInstance()->executeS('DELETE FROM `'._DB_PREFIX_.'contactform_email` WHERE `type` = '.pSQL($_POST['type'])); + Db::getInstance()->executeS('DELETE FROM `'._DB_PREFIX_.'contactform_email` WHERE `type` = '.pSQL($_POST['type'])); foreach ($emails as $k => $email) { Db::getInstance()->autoExecute(_DB_PREFIX_.'contactform_email', [ From 836cdfec5936ecc05a11a8aa4830c1363d9e836e Mon Sep 17 00:00:00 2001 From: Alexandre Simonet Date: Thu, 25 Feb 2016 16:18:37 +0100 Subject: [PATCH 13/13] Fix --- modules/contactform/Process.php | 28 ++++++++++++++++----- modules/contactform/press.tpl | 34 +++++++++++++------------- modules/contactform/provider.tpl | 42 ++++++++++++++++---------------- 3 files changed, 60 insertions(+), 44 deletions(-) diff --git a/modules/contactform/Process.php b/modules/contactform/Process.php index 9ccdd48b..392fe7de 100644 --- a/modules/contactform/Process.php +++ b/modules/contactform/Process.php @@ -28,10 +28,10 @@ class Process $errors = []; $isCorrect = $this->validate(Contactform::TYPE_PROVIDER); if (!$isCorrect) { - $errors[] = 'Tous les champs ne sont pas remplis'; + $errors[] = Tools::displayError('Tous les champs ne sont pas remplis'); } else { if (!Validate::isEmail($this->data['email1'])) { - $errors[] = 'Certains champs ne sont pas valide'; + $errors[] = Tools::displayError('Certains champs ne sont pas valide'); } else { $query = Db::getInstance()->autoExecute(_DB_PREFIX_.'contactform', [ 'brand' => pSQL($this->data['brand']), @@ -49,7 +49,7 @@ class Process ], 'INSERT'); if (!$query) { - $errors[] = 'Une erreur s\'est produite. Votre message n\'a pas été envoyé'; + $errors[] = Tools::displayError('Une erreur s\'est produite. Votre message n\'a pas été envoyé'); } else { Mail::Send( intval($cookie->id_lang), @@ -71,6 +71,7 @@ class Process if (!empty($errors)) { return $errors; } + $this->emptyForm(); return true; } @@ -80,10 +81,10 @@ class Process $errors = []; $isCorrect = $this->validate(Contactform::TYPE_PRESS); if (!$isCorrect) { - $errors[] = 'Tous les champs ne sont pas remplis'; + $errors[] = Tools::displayError('Tous les champs ne sont pas remplis'); } else { if (!Validate::isEmail($this->data['email1'])) { - $errors[] = 'Certains champs ne sont pas valide'; + $errors[] = Tools::displayError('Certains champs ne sont pas valide'); } else { $query = Db::getInstance()->autoExecute(_DB_PREFIX_.'contactform', [ 'compagny' => pSQL($this->data['compagny']), @@ -99,7 +100,7 @@ class Process ], 'INSERT'); if (!$query) { - $errors[] = 'Une erreur s\'est produite. Votre message n\'a pas été envoyé'; + $errors[] = Tools::displayError('Une erreur s\'est produite. Votre message n\'a pas été envoyé'); } else { Mail::Send( intval($cookie->id_lang), @@ -121,6 +122,7 @@ class Process if (!empty($errors)) { return $errors; } + $this->emptyForm(); return true; } @@ -154,4 +156,18 @@ class Process break; } } + + private function emptyForm() { + $_POST['brand'] = ''; + $_POST['compagny'] = ''; + $_POST['function'] = ''; + $_POST['lastname'] = ''; + $_POST['firstname'] = ''; + $_POST['email1'] = ''; + $_POST['email2'] = ''; + $_POST['phone1'] = ''; + $_POST['phone2'] = ''; + $_POST['purpose'] = ''; + $_POST['content'] = ''; + } } diff --git a/modules/contactform/press.tpl b/modules/contactform/press.tpl index 818ada7e..a773b9ed 100644 --- a/modules/contactform/press.tpl +++ b/modules/contactform/press.tpl @@ -14,7 +14,7 @@

{$error}

{/foreach} {else} -

{l s='Votre message à été envoye' mod='contactform'}

+

{l s='Votre message a été envoyé' mod='contactform'}

{/if} {/if} @@ -22,55 +22,55 @@

- - + +

- - + +

- - + +

- - + +

- - + +

- +

- - + +

- +

- - + +

diff --git a/modules/contactform/provider.tpl b/modules/contactform/provider.tpl index fe26fc0d..683601f1 100644 --- a/modules/contactform/provider.tpl +++ b/modules/contactform/provider.tpl @@ -13,7 +13,7 @@

{$error}

{/foreach} {else} -

{l s='Votre message à été envoye' mod='contactform'}

+

{l s='Votre message a été envoyé' mod='contactform'}

{/if} {/if} @@ -21,65 +21,65 @@

- - + +

- - + +

- - + +

- - + +

- - + +

- - + +

- +

- - + +

- +

- - + +

- - + +