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();
|
|
|
|
|
|
|
|
$this->displayName = $this->l('Contact form for press and providers');
|
|
|
|
$this->description = $this->l('Integrate contact form.');
|
|
|
|
|
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
|
|
|
')
|
|
|
|
&& 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;
|
2016-02-23 11:23:41 +01:00
|
|
|
');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function uninstallDB() {
|
2016-02-24 16:38:11 +01:00
|
|
|
return Db::getInstance()->Execute('DROP TABLE `'._DB_PREFIX_.'contactform`;') && 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 16:38:11 +01:00
|
|
|
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) == 0) {
|
|
|
|
$content = str_replace('{{ error }}', "Existe pas", $content);
|
|
|
|
}
|
|
|
|
var_dump(Db::getInstance());
|
|
|
|
}
|
|
|
|
$content = str_replace('{{ error }}', "Existe", $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'];
|
|
|
|
}
|
|
|
|
|
2016-02-23 11:23:41 +01:00
|
|
|
}
|