Merge branch 'alexandre-contactform' into develop

This commit is contained in:
Thibault UBUNTU 2016-03-01 16:17:02 +01:00
commit 5f714a6e3b
6 changed files with 288 additions and 150 deletions

View File

@ -4,12 +4,22 @@ class Process
{
private $data;
private $mail_dir;
private $to;
private $to_provider = [];
private $to_press = [];
public function __construct()
{
$this->mail_dir = dirname(__FILE__);
$this->to = 'simonet@antadis.com';
$_to = Db::getInstance()->ExecuteS('SELECT `email`, `type` FROM `'._DB_PREFIX_.'contactform_email`');
foreach ($_to as $k => $email) {
if ($email['type'] == Contactform::TYPE_PROVIDER) {
$to_provider[] = $email['email'];
}
if ($email['type'] == Contactform::TYPE_PRESS) {
$to_press[] = $email['email'];
}
}
}
public function addProvider($post)
@ -18,45 +28,50 @@ 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 {
$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($this->data['email1'])) {
$errors[] = Tools::displayError('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[] = Tools::displayError('Une erreur s\'est produite. Votre message n\'a pas été envoyé');
} else {
Mail::Send(
intval($cookie->id_lang),
'provider',
'Contact fournisseur',
$this->data,
$this->to_provider,
NULL,
NULL,
NULL,
NULL,
NULL,
$this->mail_dir
);
}
}
}
if (!empty($errors)) {
return $errors;
}
$this->emptyForm();
return true;
}
@ -66,43 +81,48 @@ 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 {
$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($this->data['email1'])) {
$errors[] = Tools::displayError('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[] = Tools::displayError('Une erreur s\'est produite. Votre message n\'a pas été envoyé');
} else {
Mail::Send(
intval($cookie->id_lang),
'press',
'Contact presse',
$this->data,
$this->to_press,
NULL,
NULL,
NULL,
NULL,
NULL,
$this->mail_dir
);
}
}
}
if (!empty($errors)) {
return $errors;
}
$this->emptyForm();
return true;
}
@ -136,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'] = '';
}
}

View File

@ -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__);
}
@ -44,20 +44,19 @@ 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,
`type` INT(11) NOT 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 +73,144 @@ class Contactform extends Module {
return TRUE;
}
// public function getContent() {
//
// $content = "
// {{ error }}
// <form method='post'>
// <textarea name='emails'></textarea>
// <input type='submit' value='Modifier'>
// <form>
// ";
//
// 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 = "<style>
h2 {
font-size: 1.4em;
margin: 0 0 .83em 0;
color: #268CCD;
}
form.module {
padding: 20px;
background: #F4E6C9;
display: inline-block;
}
form.module label, form.module input, form.module textarea {
display: block;
margin: 10px 0;
}
form.module label {
float: none;
width: auto;
padding: 0.2em 0.5em 0 0;
text-align: left;
font-weight: bold;
}
form.module input[type=submit] {
border: none;
color: black;
font-weight: bold;
background: #D6C195;
padding: 10px 20px;
cursor: pointer;
}
.form-inline {
display: inline-block;
margin: 20px;
}
</style>
<div class='form-inline'>
<h2>Formulaire de contact pour les fournisseurs</h2>
<form method='post' class='module'>
<p class='bold'>{{ error_provider }}</p>
<label for='email'>Emails destinataire (Une adresse email par ligne):</label>
<textarea name='emails' id='email' cols='50' rows='10'>{{ emails_provider }}</textarea>
<input type='submit' value='Modifier' name='update_mail'>
<input type='hidden' name='type' value='".Contactform::TYPE_PROVIDER."'>
</form>
</div>
<div class='form-inline'>
<h2>Formulaire de contact pour la presse</h2>
<form method='post' class='module'>
<p class='bold'>{{ error_press }}</p>
<label for='email'>Emails destinataire (Une adresse email par ligne):</label>
<textarea name='emails' id='email' cols='50' rows='10'>{{ emails_press }}</textarea>
<input type='submit' value='Modifier' name='update_mail'>
<input type='hidden' name='type' value='".Contactform::TYPE_PRESS."'>
</form>
</div>";
if (Tools::isSubmit('update_mail')) {
if (empty($_POST['emails'])) {
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']));
foreach ($emails as $k => $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` WHERE `type` = '.pSQL($_POST['type']));
foreach ($emails as $k => $email) {
Db::getInstance()->autoExecute(_DB_PREFIX_.'contactform_email', [
'email' => pSQL($email),
'type' => pSQL($_POST['type'])
], 'INSERT');
}
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_provider }}', "", $content);
$content = str_replace('{{ error_press }}', "", $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;
}
}

View File

@ -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);
}

View File

@ -14,7 +14,7 @@
<p class="bold text" style="color: red">{$error}</p>
{/foreach}
{else}
<p class="bold text">{l s='Votre message à été envoye' mod='contactform'}</p>
<p class="bold text">{l s='Votre message a été envoyé' mod='contactform'}</p>
{/if}
{/if}
@ -22,60 +22,60 @@
<div>
<p class="text module-contactform-input-group" style="display: inline-block">
<label for="compagny">{l s='Entreprise' mod='contactform'}*</label>
<input type="text" name="compagny" id="compagny">
<label for="compagny">{l s='Entreprise' mod='contactform'}<sup>*</sup> </label>
<input type="text" name="compagny" id="compagny" value="{if Tools::getValue('compagny')} {Tools::getValue('compagny')} {/if}">
</p>
<p class="text module-contactform-input-group" style="display: inline-block; margin-left: 30px">
<label for="function">{l s='Fonction' mod='contactform'}*</label>
<input type="text" name="function" id="function">
<label for="function">{l s='Fonction' mod='contactform'}<sup>*</sup></label>
<input type="text" name="function" id="function" value="{if Tools::getValue('function')} {Tools::getValue('function')} {/if}">
</p>
</div>
<div>
<p class="text module-contactform-input-group" style="display: inline-block">
<label for="lastname">{l s='Nom' mod='contactform'}*</label>
<input type="text" name="lastname" id="lastname">
<label for="lastname">{l s='Nom' mod='contactform'}<sup>*</sup></label>
<input type="text" name="lastname" id="lastname" value="{if Tools::getValue('lastname')} {Tools::getValue('lastname')} {/if}">
</p>
<p class="text module-contactform-input-group" style="display: inline-block; margin-left: 30px">
<label for="firstname">{l s='Prénom' mod='contactform'}*</label>
<input type="text" name="firstname" id="firstname">
<label for="firstname">{l s='Prénom' mod='contactform'}<sup>*</sup></label>
<input type="text" name="firstname" id="firstname" value="{if Tools::getValue('firtname')} {Tools::getValue('firstname')} {/if}">
</p>
</div>
<div>
<p class="text module-contactform-input-group" style="display: inline-block">
<label for="email1">{l s='Email' mod='contactform'}*</label>
<input type="text" name="email1" id="email1">
<label for="email1">{l s='Email' mod='contactform'}<sup>*</sup></label>
<input type="text" name="email1" id="email1" value="{if Tools::getValue('email1')} {Tools::getValue('email1')} {/if}">
</p>
<p class="text module-contactform-input-group" style="display: inline-block; margin-left: 30px">
<label for="email2">{l s='Email secondaire' mod='contactform'}</label>
<input type="text" name="email2" id="email2">
<input type="text" name="email2" id="email2" value="{if Tools::getValue('email2')} {Tools::getValue('email2')} {/if}">
</p>
</div>
<div>
<p class="text module-contactform-input-group" style="display: inline-block">
<label for="phone1">{l s='Téléphone' mod='contactform'}*</label>
<input type="text" name="phone1" id="phone1">
<label for="phone1">{l s='Téléphone' mod='contactform'}<sup>*</sup></label>
<input type="text" name="phone1" id="phone1" {if Tools::getValue('phone1')} {Tools::getValue('phone1')} {/if}>
</p>
<p class="text module-contactform-input-group" style="display: inline-block; margin-left: 30px">
<label for="phone2">{l s='Téléphone secondaire' mod='contactform'}</label>
<input type="text" name="phone2" id="phone2">
<input type="text" name="phone2" id="phone2" {if Tools::getValue('phone2')} {Tools::getValue('phone2')} {/if}>
</p>
</div>
<p class="text module-contactform-input-group">
<label for="content">{l s='Message' mod='contactform'}*</label>
<textarea name="content" id="content" cols="65" rows="10"></textarea>
<label for="content">{l s='Message' mod='contactform'}<sup>*</sup></label>
<textarea name="content" id="content" cols="65" rows="10">{if Tools::getValue('content')} {Tools::getValue('content')} {/if}</textarea>
</p>
<input type="hidden" name="type" value="{Contactform::TYPE_PRESS}">
<button type="submit" id="SubmitLogin" class="module-contactform-button">{l s='Envoyer' mod='contactform'}</button>
<button type="submit" id="SubmitLogin" class="module-contactform-button" name="press_form">{l s='Envoyer' mod='contactform'}</button>
</form>
</div>

View File

@ -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);
}

View File

@ -13,7 +13,7 @@
<p class="bold text" style="color: red">{$error}</p>
{/foreach}
{else}
<p class="bold text">{l s='Votre message à été envoye' mod='contactform'}</p>
<p class="bold text">{l s='Votre message a été envoyé' mod='contactform'}</p>
{/if}
{/if}
@ -21,70 +21,70 @@
<div>
<p class="text module-contactform-input-group" style="display: inline-block">
<label for="brand">{l s='Marque' mod='contactform'}*</label>
<input type="text" name="brand" id="brand">
<label for="brand">{l s='Marque' mod='contactform'}<sup>*</sup> </label>
<input type="text" name="brand" id="brand" value="{if Tools::getValue('brand')} {Tools::getValue('brand')} {/if}">
</p>
<p class="text module-contactform-input-group" style="display: inline-block; margin-left: 30px">
<label for="compagny">{l s='Entreprise' mod='contactform'}*</label>
<input type="text" name="compagny" id="compagny">
<label for="compagny">{l s='Entreprise' mod='contactform'}<sup>*</sup></label>
<input type="text" name="compagny" id="compagny" value="{if Tools::getValue('compagny')} {Tools::getValue('compagny')} {/if}">
</p>
</div>
<p class="text module-contactform-input-group">
<label for="function">{l s='Fonction' mod='contactform'}*</label>
<input type="text" name="function" id="function">
<label for="function">{l s='Fonction' mod='contactform'}<sup>*</sup></label>
<input type="text" name="function" id="function" value="{if Tools::getValue('function')} {Tools::getValue('function')} {/if}">
</p>
<div>
<p class="text module-contactform-input-group" style="display: inline-block">
<label for="lastname">{l s='Nom' mod='contactform'}*</label>
<input type="text" name="lastname" id="lastname">
<label for="lastname">{l s='Nom' mod='contactform'}<sup>*</sup></label>
<input type="text" name="lastname" id="lastname" value="{if Tools::getValue('lastname')} {Tools::getValue('lastname')} {/if}">
</p>
<p class="text module-contactform-input-group" style="display: inline-block; margin-left: 30px">
<label for="firstname">{l s='Prénom' mod='contactform'}*</label>
<input type="text" name="firstname" id="firstname">
<label for="firstname">{l s='Prénom' mod='contactform'}<sup>*</sup></label>
<input type="text" name="firstname" id="firstname" value="{if Tools::getValue('firstname')} {Tools::getValue('firstname')} {/if}">
</p>
</div>
<div>
<p class="text module-contactform-input-group" style="display: inline-block">
<label for="email1">{l s='Email' mod='contactform'}*</label>
<input type="text" name="email1" id="email1">
<label for="email1">{l s='Email' mod='contactform'}<sup>*</sup></label>
<input type="text" name="email1" id="email1" value="{if Tools::getValue('email1')} {Tools::getValue('email1')} {/if}">
</p>
<p class="text module-contactform-input-group" style="display: inline-block; margin-left: 30px">
<label for="email2">{l s='Email secondaire' mod='contactform'}</label>
<input type="text" name="email2" id="email2">
<input type="text" name="email2" id="email2" value="{if Tools::getValue('email2')} {Tools::getValue('email2')} {/if}">
</p>
</div>
<div>
<p class="text module-contactform-input-group" style="display: inline-block">
<label for="phone1">{l s='Téléphone' mod='contactform'}*</label>
<input type="text" name="phone1" id="phone1">
<label for="phone1">{l s='Téléphone' mod='contactform'}<sup>*</sup></label>
<input type="text" name="phone1" id="phone1" value="{if Tools::getValue('phone1')} {Tools::getValue('phone1')} {/if}">
</p>
<p class="text module-contactform-input-group" style="display: inline-block; margin-left: 30px">
<label for="phone2">{l s='Téléphone secondaire' mod='contactform'}</label>
<input type="text" name="phone2" id="phone2">
<input type="text" name="phone2" id="phone2" value="{if Tools::getValue('phone2')} {Tools::getValue('phone1')} {/if}">
</p>
</div>
<p class="text module-contactform-input-group">
<label for="purpose">{l s='Proposition' mod='contactform'}*</label>
<input type="text" name="purpose" id="purpose">
<label for="purpose">{l s='Proposition' mod='contactform'}<sup>*</sup></label>
<input type="text" name="purpose" id="purpose" value="{if Tools::getValue('purpose')} {Tools::getValue('purpose')} {/if}">
</p>
<p class="text module-contactform-input-group">
<label for="content">{l s='Message' mod='contactform'}*</label>
<textarea name="content" id="content" cols="65" rows="10"></textarea>
<label for="content">{l s='Message' mod='contactform'}<sup>*</sup></label>
<textarea name="content" id="content" cols="65" rows="10">{if Tools::getValue('content')} {Tools::getValue('content')} {/if}</textarea>
</p>
<input type="hidden" name="type" value="{Contactform::TYPE_PROVIDER}">
<button type="submit" id="SubmitLogin" class="btn_box login_box module-contactform-button">{l s='Envoyer' mod='contactform'}</button>
<button type="submit" id="SubmitLogin" class="btn_box login_box module-contactform-button" name="provider_form">{l s='Envoyer' mod='contactform'}</button>
</form>
</div>
</div>