mail_dir = dirname(__FILE__); var_dump($this->mail_dir); $_to = Db::getInstance()->ExecuteS('SELECT `email`, `type` FROM `'._DB_PREFIX_.'contactform_email`'); foreach ($_to as $k => $email) { if ($email['type'] == Contactform::TYPE_PROVIDER) { $this->to_provider[] = $email['email']; } if ($email['type'] == Contactform::TYPE_PRESS) { $this->to_press[] = $email['email']; } } } public function addProvider($post) { $this->data = $post; $errors = []; $isCorrect = $this->validate(Contactform::TYPE_PROVIDER); if (!$isCorrect) { $errors[] = Tools::displayError('Tous les champs ne sont pas remplis'); } else { if (!Validate::isEmail($this->data['email1'])) { $errors[] = Tools::displayError('Certains champs ne sont pas valide'); } else { $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'); if (!$query) { $errors[] = Tools::displayError('Une erreur s\'est produite. Votre message n\'a pas été envoyé'); } else { $sended = Mail::Send( intval($cookie->id_lang), 'provider', 'Contact fournisseur', $this->data, $this->to_provider, NULL, NULL, NULL, NULL, NULL, $this->mail_dir ); if (!$sended) { $errors[] = Tools::displayError('Une erreur s\'est produite. Votre message n\'a pas été envoyé'); } } } } if (!empty($errors)) { return $errors; } $this->emptyForm(); return true; } public function addPress($post) { $this->data = $post; $errors = []; $isCorrect = $this->validate(Contactform::TYPE_PRESS); if (!$isCorrect) { $errors[] = Tools::displayError('Tous les champs ne sont pas remplis'); } else { if (!Validate::isEmail($this->data['email1'])) { $errors[] = Tools::displayError('Certains champs ne sont pas valide'); } else { $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[] = Tools::displayError('Une erreur s\'est produite. Votre message n\'a pas été envoyé'); } else { $sended = Mail::Send( intval($cookie->id_lang), 'press', 'Contact presse', $this->data, $this->to_press, NULL, NULL, NULL, NULL, NULL, $this->mail_dir ); if (!$sended) { $errors[] = Tools::displayError('Une erreur s\'est produite. Votre message n\'a pas été envoyé'); } } } } if (!empty($errors)) { return $errors; } $this->emptyForm(); return true; } 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; } } private function emptyForm() { $_POST['brand'] = ''; $_POST['compagny'] = ''; $_POST['function'] = ''; $_POST['lastname'] = ''; $_POST['firstname'] = ''; $_POST['email1'] = ''; $_POST['email2'] = ''; $_POST['phone1'] = ''; $_POST['phone2'] = ''; $_POST['purpose'] = ''; $_POST['content'] = ''; } }