name = 'contactform'; $this->tab = 'advertising_marketing'; $this->version = '1.0'; $this->author = 'Antadis'; $this->need_instance = 0; parent::__construct(); $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__); } 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, `email1` VARCHAR(255) NOT NULL, `email2` VARCHAR(255) NULL, `phone1` VARCHAR(255) NOT NULL, `phone2` VARCHAR(255) NULL, `purpose` VARCHAR(255) NULL, `content` TEXT(65535) NOT NULL, `date_add` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, `type` INT(11) NOT NULL, 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, `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`;'); } public function install() { if(!parent::install() || !$this->installDB()) { return FALSE; } return TRUE; } public function uninstall() { if (!parent::uninstall() || !$this->uninstallDB() ) { return FALSE; } return TRUE; } public function getContent() { $content = "

Formulaire de contact pour les fournisseurs

{{ error_provider }}

Formulaire de contact pour la presse

{{ error_press }}

"; 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; } }