Fix config multi form

This commit is contained in:
Alexandre Simonet 2016-02-25 12:27:58 +01:00
parent 11966aea9b
commit 9c7c23d9fb

View File

@ -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;
}
</style>
<h2>Formulaire de contact pour les fournisseurs et la presse</h2>
<div class='form-inline'>
<h2>Formulaire de contact pour les fournisseurs</h2>
<form method='post' class='module'>
<p class='bold'>{{ error }}</p>
<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 }}</textarea>
<textarea name='emails' id='email' cols='50' rows='10'>{{ emails_provider }}</textarea>
<input type='submit' value='Modifier' name='update_mail'>
</form>";
<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'])) {
$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 }}', "", $content);
$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);
}
$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;
}