2016-02-23 11:23:41 +01:00
|
|
|
<?php
|
|
|
|
if (!defined('_PS_VERSION_'))
|
|
|
|
exit;
|
|
|
|
|
|
|
|
class Contactform extends Module {
|
|
|
|
|
2016-02-24 15:33:47 +01:00
|
|
|
const TYPE_PRESS = 1;
|
|
|
|
const TYPE_PROVIDER = 2;
|
|
|
|
|
|
|
|
private $assets_module_dir;
|
2016-02-23 11:23:41 +01:00
|
|
|
|
|
|
|
public function __construct() {
|
2016-02-24 16:38:11 +01:00
|
|
|
$this->name = 'contactform';
|
2016-02-23 11:23:41 +01:00
|
|
|
$this->tab = 'advertising_marketing';
|
|
|
|
$this->version = '1.0';
|
|
|
|
$this->author = 'Antadis';
|
|
|
|
$this->need_instance = 0;
|
|
|
|
|
|
|
|
parent::__construct();
|
|
|
|
|
2016-02-25 10:28:03 +01:00
|
|
|
$this->displayName = $this->l('Formulaire de contact pour les fournisseurs et la presse');
|
|
|
|
$this->description = $this->l('Intégration de formulaire de contact');
|
2016-02-23 11:23:41 +01:00
|
|
|
|
2016-02-24 15:33:47 +01:00
|
|
|
$this->assets_module_dir = dirname(__FILE__);
|
2016-02-23 11:23:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function installDB() {
|
|
|
|
return Db::getInstance()->Execute('
|
|
|
|
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'contactform` (
|
|
|
|
`id_contactform` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
|
|
`brand` VARCHAR(255) NULL,
|
|
|
|
`compagny` VARCHAR(255) NOT NULL,
|
|
|
|
`lastname` VARCHAR(128) NOT NULL,
|
|
|
|
`firstname` VARCHAR(128) NOT NULL,
|
|
|
|
`function` VARCHAR(255) NOT NULL,
|
2016-02-23 13:25:19 +01:00
|
|
|
`email1` VARCHAR(255) NOT NULL,
|
2016-02-23 11:23:41 +01:00
|
|
|
`email2` VARCHAR(255) NULL,
|
|
|
|
`phone1` VARCHAR(255) NOT NULL,
|
|
|
|
`phone2` VARCHAR(255) NULL,
|
|
|
|
`purpose` VARCHAR(255) NULL,
|
|
|
|
`content` TEXT(65535) NOT NULL,
|
2016-02-23 16:08:21 +01:00
|
|
|
`date_add` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
2016-02-23 11:23:41 +01:00
|
|
|
`type` INT(11) NOT NULL,
|
2016-02-23 16:08:21 +01:00
|
|
|
PRIMARY KEY (`id_contactform`)
|
2016-02-23 11:23:41 +01:00
|
|
|
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8;
|
2016-02-24 16:38:11 +01:00
|
|
|
')
|
2016-02-24 17:15:28 +01:00
|
|
|
&& 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,
|
2016-02-25 12:27:58 +01:00
|
|
|
`type` INT(11) NOT NULL,
|
2016-02-24 17:15:28 +01:00
|
|
|
PRIMARY KEY (`id_contactform_email`)
|
|
|
|
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8;
|
|
|
|
');
|
2016-02-23 11:23:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function uninstallDB() {
|
2016-02-24 16:45:42 +01:00
|
|
|
return Db::getInstance()->Execute('DROP TABLE `'._DB_PREFIX_.'contactform`;')
|
2016-02-24 17:15:28 +01:00
|
|
|
&& Db::getInstance()->Execute('DROP TABLE `'._DB_PREFIX_.'contactform_email`;');
|
2016-02-23 11:23:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function install() {
|
|
|
|
if(!parent::install() || !$this->installDB()) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function uninstall() {
|
2016-02-23 16:08:21 +01:00
|
|
|
if (!parent::uninstall() || !$this->uninstallDB() ) {
|
2016-02-23 11:23:41 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2016-02-24 17:15:28 +01:00
|
|
|
public function getContent() {
|
|
|
|
|
2016-02-25 10:28:03 +01:00
|
|
|
$content = "<style>
|
|
|
|
h2 {
|
|
|
|
font-size: 1.4em;
|
|
|
|
margin: 0 0 .83em 0;
|
|
|
|
color: #268CCD;
|
|
|
|
}
|
|
|
|
form.module {
|
|
|
|
padding: 20px;
|
|
|
|
background: #F4E6C9;
|
2016-02-25 12:27:58 +01:00
|
|
|
display: inline-block;
|
2016-02-25 10:28:03 +01:00
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
2016-02-25 12:27:58 +01:00
|
|
|
.form-inline {
|
|
|
|
display: inline-block;
|
|
|
|
margin: 20px;
|
|
|
|
}
|
2016-02-25 10:28:03 +01:00
|
|
|
</style>
|
|
|
|
|
2016-02-25 12:27:58 +01:00
|
|
|
<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>";
|
2016-02-25 10:28:03 +01:00
|
|
|
|
|
|
|
if (Tools::isSubmit('update_mail')) {
|
2016-02-24 17:15:28 +01:00
|
|
|
if (empty($_POST['emails'])) {
|
2016-02-25 12:27:58 +01:00
|
|
|
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);
|
|
|
|
|
2016-02-24 17:15:28 +01:00
|
|
|
return $content;
|
|
|
|
}
|
|
|
|
$emails = explode("\n", trim($_POST['emails']));
|
|
|
|
foreach ($emails as $k => $email) {
|
2016-02-25 10:28:03 +01:00
|
|
|
$email = trim($email);
|
|
|
|
if (Validate::isEmail($email)) {
|
|
|
|
$emails[$k] = $email;
|
|
|
|
} else {
|
|
|
|
array_splice($emails, $k);
|
|
|
|
}
|
2016-02-24 17:15:28 +01:00
|
|
|
}
|
|
|
|
$emails = array_unique($emails);
|
|
|
|
|
2016-02-25 14:15:51 +01:00
|
|
|
Db::getInstance()->executeS('DELETE FROM `'._DB_PREFIX_.'contactform_email` WHERE `type` = '.pSQL($_POST['type']));
|
2016-02-24 17:15:28 +01:00
|
|
|
|
|
|
|
foreach ($emails as $k => $email) {
|
|
|
|
Db::getInstance()->autoExecute(_DB_PREFIX_.'contactform_email', [
|
2016-02-25 12:27:58 +01:00
|
|
|
'email' => pSQL($email),
|
|
|
|
'type' => pSQL($_POST['type'])
|
2016-02-24 17:15:28 +01:00
|
|
|
], 'INSERT');
|
|
|
|
}
|
|
|
|
|
2016-02-25 12:27:58 +01:00
|
|
|
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);
|
|
|
|
}
|
2016-02-24 17:15:28 +01:00
|
|
|
} else {
|
2016-02-25 12:27:58 +01:00
|
|
|
$content = str_replace('{{ error_provider }}', "", $content);
|
|
|
|
$content = str_replace('{{ error_press }}', "", $content);
|
2016-02-24 17:15:28 +01:00
|
|
|
}
|
|
|
|
|
2016-02-25 12:27:58 +01:00
|
|
|
$contentEmails = Db::getInstance()->ExecuteS('SELECT `email`, `type` FROM `'._DB_PREFIX_.'contactform_email`');
|
2016-02-24 17:15:28 +01:00
|
|
|
|
2016-02-25 12:27:58 +01:00
|
|
|
$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";
|
|
|
|
}
|
2016-02-24 17:15:28 +01:00
|
|
|
}
|
|
|
|
|
2016-02-25 12:27:58 +01:00
|
|
|
$content = str_replace('{{ emails_provider }}', $contentEmailProvider, $content);
|
|
|
|
$content = str_replace('{{ emails_press }}', $contentEmailPress, $content);
|
2016-02-24 17:15:28 +01:00
|
|
|
return $content;
|
|
|
|
}
|
|
|
|
|
2016-02-24 16:38:11 +01:00
|
|
|
|
2016-02-23 11:23:41 +01:00
|
|
|
}
|