2016-02-23 13:25:19 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class Process
|
|
|
|
{
|
|
|
|
private $data;
|
2016-02-23 15:00:13 +01:00
|
|
|
private $mail_dir;
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->mail_dir = dirname(__FILE__).'/mails/';
|
|
|
|
}
|
2016-02-23 13:25:19 +01:00
|
|
|
|
|
|
|
public function addProvider($post)
|
|
|
|
{
|
|
|
|
$this->data = $post;
|
|
|
|
$errors = [];
|
|
|
|
$isCorrect = $this->validate(Contactform::TYPE_PROVIDER);
|
|
|
|
if (!$isCorrect) {
|
|
|
|
$errors[] = 'All fields are not filled';
|
|
|
|
}
|
|
|
|
|
2016-02-23 15:00:13 +01:00
|
|
|
$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');
|
2016-02-23 13:25:19 +01:00
|
|
|
|
|
|
|
if (!$query) {
|
|
|
|
$errors[] = "something went wrong";
|
|
|
|
}
|
|
|
|
|
2016-02-23 15:00:13 +01:00
|
|
|
Mail::Send(
|
|
|
|
intval($cookie->id_lang),
|
|
|
|
'provider',
|
|
|
|
'sujet',
|
|
|
|
[],
|
|
|
|
'simonet@antadis.fr',
|
|
|
|
NULL,
|
|
|
|
$this->data['email1'],
|
|
|
|
$this->data['lastname'].' '.$this->data['firstname'],
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
$this->mail_dir
|
|
|
|
);
|
|
|
|
|
2016-02-23 17:33:08 +01:00
|
|
|
if (!empty($errors)) {
|
|
|
|
return $errors;
|
|
|
|
}
|
|
|
|
return true;
|
2016-02-23 13:25:19 +01:00
|
|
|
}
|
|
|
|
|
2016-02-23 15:38:51 +01:00
|
|
|
public function addPress($post)
|
|
|
|
{
|
|
|
|
$this->data = $post;
|
|
|
|
$errors = [];
|
|
|
|
$isCorrect = $this->validate(Contactform::TYPE_PRESS);
|
|
|
|
if (!$isCorrect) {
|
|
|
|
$errors[] = 'All fields are not filled';
|
|
|
|
}
|
|
|
|
|
|
|
|
$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[] = "something went wrong";
|
|
|
|
}
|
|
|
|
|
|
|
|
Mail::Send(
|
|
|
|
intval($cookie->id_lang),
|
|
|
|
'press',
|
|
|
|
'sujet',
|
|
|
|
[],
|
|
|
|
'simonet@antadis.fr',
|
|
|
|
NULL,
|
|
|
|
$this->data['email1'],
|
|
|
|
$this->data['lastname'].' '.$this->data['firstname'],
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
$this->mail_dir
|
|
|
|
);
|
|
|
|
|
2016-02-23 17:33:08 +01:00
|
|
|
if (!empty($errors)) {
|
|
|
|
return $errors;
|
|
|
|
}
|
|
|
|
return true;
|
2016-02-23 15:38:51 +01:00
|
|
|
}
|
|
|
|
|
2016-02-23 13:25:19 +01:00
|
|
|
private function validate($type)
|
|
|
|
{
|
|
|
|
switch ($type) {
|
|
|
|
case Contactform::TYPE_PROVIDER:
|
|
|
|
return (!empty($this->data['brand'])
|
|
|
|
&& !empty($this->data['compagny'])
|
|
|
|
&& !empty($this->data['lastname'])
|
|
|
|
&& !empty($this->data['firstname'])
|
|
|
|
&& !empty($this->data['function'])
|
|
|
|
&& !empty($this->data['email1'])
|
|
|
|
&& !empty($this->data['phone1'])
|
|
|
|
&& !empty($this->data['purpose'])
|
|
|
|
&& !empty($this->data['content']));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Contactform::TYPE_PRESS:
|
|
|
|
return (!empty($this->data['compagny'])
|
|
|
|
&& !empty($this->data['lastname'])
|
|
|
|
&& !empty($this->data['firstname'])
|
|
|
|
&& !empty($this->data['function'])
|
|
|
|
&& !empty($this->data['email1'])
|
|
|
|
&& !empty($this->data['phone1'])
|
|
|
|
&& !empty($this->data['content']));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|