2018-04-02 08:29:19 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This file is part of Zwii.
|
|
|
|
*
|
|
|
|
* For full copyright and license information, please see the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*
|
|
|
|
* @author Rémi Jean <remi.jean@outlook.com>
|
|
|
|
* @copyright Copyright (C) 2008-2018, Rémi Jean
|
2019-01-23 20:11:43 +01:00
|
|
|
* @author Frédéric Tempez <frederic.tempez@outlook.com>
|
2023-01-09 10:23:32 +01:00
|
|
|
* @copyright Copyright (C) 2018-2023, Frédéric Tempez
|
2022-12-29 17:02:20 +01:00
|
|
|
* @license CC Attribution-NonCommercial-NoDerivatives 4.0 International
|
2020-09-01 20:48:40 +02:00
|
|
|
* @link http://zwiicms.fr/
|
2018-04-02 08:29:19 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
class form extends common {
|
|
|
|
|
2023-01-27 08:26:34 +01:00
|
|
|
const VERSION = '3.4';
|
2021-02-18 10:07:05 +01:00
|
|
|
const REALNAME = 'Formulaire';
|
2021-04-06 11:20:04 +02:00
|
|
|
const DATADIRECTORY = ''; // Contenu localisé inclus par défaut (page.json et module.json)
|
2021-02-18 10:07:05 +01:00
|
|
|
|
2018-04-02 08:29:19 +02:00
|
|
|
public static $actions = [
|
|
|
|
'config' => self::GROUP_MODERATOR,
|
2022-02-18 12:43:48 +01:00
|
|
|
'option' => self::GROUP_MODERATOR,
|
2018-04-02 08:29:19 +02:00
|
|
|
'data' => self::GROUP_MODERATOR,
|
|
|
|
'delete' => self::GROUP_MODERATOR,
|
2019-01-26 11:09:47 +01:00
|
|
|
'deleteall' => self::GROUP_MODERATOR,
|
2019-01-23 20:11:43 +01:00
|
|
|
'index' => self::GROUP_VISITOR,
|
|
|
|
'export2csv' => self::GROUP_MODERATOR,
|
2022-10-10 11:28:27 +02:00
|
|
|
'output2csv' => self::GROUP_MODERATOR,
|
|
|
|
'init' => self::GROUP_MODERATOR,
|
|
|
|
'update' => self::GROUP_MODERATOR,
|
2018-04-02 08:29:19 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
public static $data = [];
|
|
|
|
|
|
|
|
public static $pages = [];
|
2020-06-03 08:54:48 +02:00
|
|
|
|
2018-04-02 08:29:19 +02:00
|
|
|
public static $pagination;
|
2020-06-03 08:54:48 +02:00
|
|
|
|
2022-02-18 12:43:48 +01:00
|
|
|
// Nombre d'articles dans la page de config:
|
2022-11-07 08:47:49 +01:00
|
|
|
public static $itemsperPage = 20;
|
2022-02-18 12:43:48 +01:00
|
|
|
|
2018-04-02 08:29:19 +02:00
|
|
|
|
2019-11-26 19:22:30 +01:00
|
|
|
// Objets
|
2018-04-02 08:29:19 +02:00
|
|
|
const TYPE_MAIL = 'mail';
|
|
|
|
const TYPE_SELECT = 'select';
|
|
|
|
const TYPE_TEXT = 'text';
|
|
|
|
const TYPE_TEXTAREA = 'textarea';
|
2019-11-26 19:22:30 +01:00
|
|
|
const TYPE_DATETIME = 'date';
|
|
|
|
const TYPE_CHECKBOX = 'checkbox';
|
|
|
|
const TYPE_LABEL = 'label';
|
2021-04-13 16:22:17 +02:00
|
|
|
const ITEMSPAGE = 10;
|
2019-02-14 15:17:03 +01:00
|
|
|
|
2018-04-02 08:29:19 +02:00
|
|
|
|
|
|
|
public static $types = [
|
2020-06-03 08:54:48 +02:00
|
|
|
self::TYPE_LABEL => 'Etiquette',
|
2018-04-02 08:29:19 +02:00
|
|
|
self::TYPE_TEXT => 'Champ texte',
|
|
|
|
self::TYPE_TEXTAREA => 'Grand champ texte',
|
|
|
|
self::TYPE_MAIL => 'Champ mail',
|
2018-11-28 12:44:32 +01:00
|
|
|
self::TYPE_SELECT => 'Sélection',
|
2020-06-03 08:54:48 +02:00
|
|
|
self::TYPE_CHECKBOX => 'Case à cocher',
|
2020-01-21 09:14:04 +01:00
|
|
|
self::TYPE_DATETIME => 'Date'
|
2018-04-02 08:29:19 +02:00
|
|
|
];
|
|
|
|
|
2019-02-12 14:39:36 +01:00
|
|
|
public static $listUsers = [
|
|
|
|
];
|
|
|
|
|
2021-05-03 09:02:58 +02:00
|
|
|
public static $signature = [
|
|
|
|
'text' => 'Nom du site',
|
|
|
|
'logo' => 'Logo du site'
|
|
|
|
];
|
|
|
|
|
|
|
|
public static $logoWidth = [
|
|
|
|
'40' => '40%',
|
|
|
|
'60' => '60%',
|
|
|
|
'80' => '80%',
|
|
|
|
'100' => '100%'
|
|
|
|
];
|
2021-04-13 16:22:17 +02:00
|
|
|
|
2022-02-18 12:43:48 +01:00
|
|
|
public static $optionOffset = [
|
|
|
|
0 => 'Aucune',
|
|
|
|
1 => 'Une colonne',
|
|
|
|
2 => 'Deux colonnes'
|
|
|
|
];
|
|
|
|
|
|
|
|
public static $optionWidth = [
|
|
|
|
6 => 'Six colonnes',
|
|
|
|
7 => 'Sept colonnes',
|
|
|
|
8 => 'Huit colonnes',
|
|
|
|
9 => 'Neuf colonnes',
|
|
|
|
10 => 'Dix colonnes',
|
|
|
|
11 => 'Onze colonnes',
|
|
|
|
12 => 'Douze colonnes',
|
|
|
|
];
|
|
|
|
|
|
|
|
public static $optionAlign = [
|
|
|
|
'' => 'A gauche',
|
|
|
|
'textAlignCenter' => 'Au centre',
|
|
|
|
'textAlignRight' => 'A droite'
|
|
|
|
];
|
|
|
|
|
|
|
|
|
2018-04-02 08:29:19 +02:00
|
|
|
/**
|
|
|
|
* Configuration
|
|
|
|
*/
|
|
|
|
public function config() {
|
2022-10-10 11:28:27 +02:00
|
|
|
|
|
|
|
// Mise à jour des données de module
|
|
|
|
$this->update();
|
|
|
|
|
2022-02-12 17:10:59 +01:00
|
|
|
// Liste des utilisateurs
|
2022-04-06 09:46:28 +02:00
|
|
|
$userIdsFirstnames = helper::arrayColumn($this->getData(['user']), 'firstname');
|
2022-02-12 17:10:59 +01:00
|
|
|
ksort($userIdsFirstnames);
|
|
|
|
self::$listUsers [] = '';
|
|
|
|
foreach($userIdsFirstnames as $userId => $userFirstname) {
|
|
|
|
self::$listUsers [] = $userId;
|
|
|
|
}
|
2018-04-02 08:29:19 +02:00
|
|
|
// Soumission du formulaire
|
|
|
|
if($this->isPost()) {
|
2019-10-07 14:57:32 +02:00
|
|
|
// Génération des données vides
|
2020-12-01 21:05:22 +01:00
|
|
|
if ($this->getData(['module', $this->getUrl(0), 'data']) === null) {
|
|
|
|
$this->setData(['module', $this->getUrl(0), 'data', []]);
|
|
|
|
}
|
2018-04-02 08:29:19 +02:00
|
|
|
// Génération des champs
|
|
|
|
$inputs = [];
|
|
|
|
foreach($this->getInput('formConfigPosition', null) as $index => $position) {
|
|
|
|
$inputs[] = [
|
2021-02-04 16:52:37 +01:00
|
|
|
'name' => htmlspecialchars_decode($this->getInput('formConfigName[' . $index . ']'),ENT_QUOTES),
|
2018-04-02 08:29:19 +02:00
|
|
|
'position' => helper::filter($position, helper::FILTER_INT),
|
|
|
|
'required' => $this->getInput('formConfigRequired[' . $index . ']', helper::FILTER_BOOLEAN),
|
|
|
|
'type' => $this->getInput('formConfigType[' . $index . ']'),
|
|
|
|
'values' => $this->getInput('formConfigValues[' . $index . ']')
|
|
|
|
];
|
|
|
|
}
|
|
|
|
$this->setData(['module', $this->getUrl(0), 'input', $inputs]);
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
2023-01-24 09:57:45 +01:00
|
|
|
'notification' => helper::translate('Modifications enregistrées'),
|
2018-04-02 08:29:19 +02:00
|
|
|
'redirect' => helper::baseUrl() . $this->getUrl(),
|
|
|
|
'state' => true
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
// Liste des pages
|
|
|
|
foreach($this->getHierarchy(null, false) as $parentPageId => $childrenPageIds) {
|
|
|
|
self::$pages[$parentPageId] = $this->getData(['page', $parentPageId, 'title']);
|
|
|
|
foreach($childrenPageIds as $childKey) {
|
|
|
|
self::$pages[$childKey] = ' ' . $this->getData(['page', $childKey, 'title']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
2023-01-24 09:57:45 +01:00
|
|
|
'title' => self::translate('Configuration du module'),
|
2018-04-02 08:29:19 +02:00
|
|
|
'vendor' => [
|
2018-11-28 12:44:32 +01:00
|
|
|
'html-sortable',
|
|
|
|
'flatpickr'
|
2018-04-02 08:29:19 +02:00
|
|
|
],
|
|
|
|
'view' => 'config'
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2022-02-18 12:43:48 +01:00
|
|
|
|
|
|
|
public function option() {
|
|
|
|
// Liste des utilisateurs
|
2022-04-06 09:46:28 +02:00
|
|
|
$userIdsFirstnames = helper::arrayColumn($this->getData(['user']), 'firstname');
|
2022-02-18 12:43:48 +01:00
|
|
|
ksort($userIdsFirstnames);
|
|
|
|
self::$listUsers [] = '';
|
|
|
|
foreach ($userIdsFirstnames as $userId => $userFirstname) {
|
|
|
|
self::$listUsers [] = $userId;
|
|
|
|
}
|
|
|
|
// Soumission du formulaire
|
|
|
|
if ($this->isPost()) {
|
|
|
|
// Débordement
|
|
|
|
$width = $this->getInput('formOptionWidth');
|
|
|
|
if ($this->getInput('formOptionWidth',helper::FILTER_INT) + $this->getInput('formOptionOffset',helper::FILTER_INT) > 12 ) {
|
|
|
|
$width = (string) $this->getInput('formOptionWidth',helper::FILTER_INT) - $this->getInput('formOptionOffset',helper::FILTER_INT);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Configuration
|
|
|
|
$this->setData([
|
|
|
|
'module',
|
|
|
|
$this->getUrl(0),
|
|
|
|
'config',
|
|
|
|
[
|
|
|
|
'button' => $this->getInput('formOptionButton'),
|
|
|
|
'captcha' => $this->getInput('formOptionCaptcha', helper::FILTER_BOOLEAN),
|
|
|
|
'group' => $this->getInput('formOptionGroup', helper::FILTER_INT),
|
|
|
|
'user' => self::$listUsers [$this->getInput('formOptionUser', helper::FILTER_INT)],
|
|
|
|
'mail' => $this->getInput('formOptionMail') ,
|
|
|
|
'pageId' => $this->getInput('formOptionPageIdToggle', helper::FILTER_BOOLEAN) === true ? $this->getInput('formOptionPageId', helper::FILTER_ID) : '',
|
|
|
|
'subject' => $this->getInput('formOptionSubject'),
|
|
|
|
'replyto' => $this->getInput('formOptionMailReplyTo', helper::FILTER_BOOLEAN),
|
|
|
|
'signature' => $this->getInput('formOptionSignature'),
|
|
|
|
'logoUrl' => $this->getInput('formOptionLogo'),
|
|
|
|
'logoWidth' => $this->getInput('formOptionLogoWidth'),
|
|
|
|
'offset' =>$this->getInput('formOptionOffset'),
|
|
|
|
'width' =>$width,
|
|
|
|
'align' =>$this->getInput('formOptionAlign'),
|
|
|
|
]
|
|
|
|
]);
|
|
|
|
// Génération des données vides
|
|
|
|
if ($this->getData(['module', $this->getUrl(0), 'data']) === null) {
|
|
|
|
$this->setData(['module', $this->getUrl(0), 'data', []]);
|
|
|
|
}
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
2023-01-24 09:57:45 +01:00
|
|
|
'notification' => helper::translate('Modifications enregistrées'),
|
2022-02-18 12:43:48 +01:00
|
|
|
'redirect' => helper::baseUrl() . $this->getUrl(),
|
|
|
|
'state' => true
|
|
|
|
]);
|
|
|
|
} else {
|
|
|
|
// Liste des pages
|
|
|
|
foreach($this->getHierarchy(null, false) as $parentPageId => $childrenPageIds) {
|
|
|
|
self::$pages[$parentPageId] = $this->getData(['page', $parentPageId, 'title']);
|
|
|
|
foreach($childrenPageIds as $childKey) {
|
|
|
|
self::$pages[$childKey] = ' ' . $this->getData(['page', $childKey, 'title']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
2023-01-23 15:44:11 +01:00
|
|
|
'title' => helper::translate('Options de configuration'),
|
2022-02-18 12:43:48 +01:00
|
|
|
'vendor' => [
|
|
|
|
'html-sortable',
|
|
|
|
'flatpickr'
|
|
|
|
],
|
|
|
|
'view' => 'option'
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-02 08:29:19 +02:00
|
|
|
/**
|
|
|
|
* Données enregistrées
|
|
|
|
*/
|
|
|
|
public function data() {
|
|
|
|
$data = $this->getData(['module', $this->getUrl(0), 'data']);
|
|
|
|
if($data) {
|
|
|
|
// Pagination
|
2022-11-07 08:47:49 +01:00
|
|
|
$pagination = helper::pagination($data, $this->getUrl(), self::$itemsperPage);
|
2018-04-02 08:29:19 +02:00
|
|
|
// Liste des pages
|
2021-10-06 18:13:25 +02:00
|
|
|
self::$pages = $pagination['pages'];
|
2018-04-02 08:29:19 +02:00
|
|
|
// Inverse l'ordre du tableau
|
|
|
|
$dataIds = array_reverse(array_keys($data));
|
|
|
|
$data = array_reverse($data);
|
|
|
|
// Données en fonction de la pagination
|
|
|
|
for($i = $pagination['first']; $i < $pagination['last']; $i++) {
|
|
|
|
$content = '';
|
|
|
|
foreach($data[$i] as $input => $value) {
|
|
|
|
$content .= $input . ' : ' . $value . '<br>';
|
|
|
|
}
|
|
|
|
self::$data[] = [
|
|
|
|
$content,
|
|
|
|
template::button('formDataDelete' . $dataIds[$i], [
|
|
|
|
'class' => 'formDataDelete buttonRed',
|
2019-01-26 11:09:47 +01:00
|
|
|
'href' => helper::baseUrl() . $this->getUrl(0) . '/delete/' . $dataIds[$i] . '/' . $_SESSION['csrf'],
|
2022-02-25 10:04:46 +01:00
|
|
|
'value' => template::ico('trash')
|
2018-04-02 08:29:19 +02:00
|
|
|
])
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
2023-01-24 09:57:45 +01:00
|
|
|
'title' => helper::translate('Modifications enregistrées'),
|
2018-04-02 08:29:19 +02:00
|
|
|
'view' => 'data'
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2019-01-23 20:11:43 +01:00
|
|
|
/**
|
|
|
|
* Export CSV
|
|
|
|
* @author Frédéric Tempez <frederic.tempez@outlook.com>
|
2023-01-09 10:23:32 +01:00
|
|
|
* @copyright Copyright (C) 2018-2023, Frédéric Tempez
|
2019-01-23 20:11:43 +01:00
|
|
|
*/
|
|
|
|
public function export2csv() {
|
2019-01-26 11:09:47 +01:00
|
|
|
// Jeton incorrect
|
|
|
|
if ($this->getUrl(2) !== $_SESSION['csrf']) {
|
2019-01-23 20:11:43 +01:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
2019-01-26 11:09:47 +01:00
|
|
|
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/data',
|
2023-01-24 09:57:45 +01:00
|
|
|
'notification' => helper::translate('Action interdite')
|
2019-01-23 20:11:43 +01:00
|
|
|
]);
|
2019-01-24 09:31:19 +01:00
|
|
|
} else {
|
2019-01-26 11:09:47 +01:00
|
|
|
$data = $this->getData(['module', $this->getUrl(0), 'data']);
|
|
|
|
if ($data !== []) {
|
|
|
|
$csvfilename = 'data-'.date('dmY').'-'.date('hm').'-'.rand(10,99).'.csv';
|
2019-05-27 20:35:04 +02:00
|
|
|
if (!file_exists(self::FILE_DIR.'source/data')) {
|
2021-09-29 14:50:25 +02:00
|
|
|
mkdir(self::FILE_DIR.'source/data', 0755);
|
2019-01-26 11:09:47 +01:00
|
|
|
}
|
2019-05-27 20:35:04 +02:00
|
|
|
$fp = fopen(self::FILE_DIR.'source/data/'.$csvfilename, 'w');
|
2019-01-26 11:09:47 +01:00
|
|
|
fputcsv($fp, array_keys($data[1]), ';','"');
|
|
|
|
foreach ($data as $fields) {
|
|
|
|
fputcsv($fp, $fields, ';','"');
|
|
|
|
}
|
|
|
|
fclose($fp);
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
2023-01-24 09:57:45 +01:00
|
|
|
'notification' => sprintf(helper::translate('Export CSV effectué dans %1 '), $csvfilename),
|
2019-01-26 11:09:47 +01:00
|
|
|
'redirect' => helper::baseUrl() . $this->getUrl(0) .'/data',
|
|
|
|
'state' => true
|
|
|
|
]);
|
|
|
|
} else {
|
|
|
|
$this->addOutput([
|
2023-01-24 09:57:45 +01:00
|
|
|
'notification' => helper::translate('Aucune donnée à exporter'),
|
2019-01-26 11:09:47 +01:00
|
|
|
'redirect' => helper::baseUrl() . $this->getUrl(0) .'/data'
|
|
|
|
]);
|
|
|
|
}
|
2019-01-23 20:11:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-02 08:29:19 +02:00
|
|
|
/**
|
|
|
|
* Suppression
|
|
|
|
*/
|
2019-01-26 11:09:47 +01:00
|
|
|
public function deleteall() {
|
|
|
|
// Jeton incorrect
|
|
|
|
if ($this->getUrl(2) !== $_SESSION['csrf']) {
|
2018-04-02 08:29:19 +02:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
2019-01-26 11:09:47 +01:00
|
|
|
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/data',
|
2023-01-24 09:57:45 +01:00
|
|
|
'notification' => helper::translate('Action interdite')
|
2018-04-02 08:29:19 +02:00
|
|
|
]);
|
2020-06-03 08:54:48 +02:00
|
|
|
} else {
|
2019-01-26 11:09:47 +01:00
|
|
|
$data = ($this->getData(['module', $this->getUrl(0), 'data']));
|
|
|
|
if (count($data) > 0 ) {
|
|
|
|
// Suppression multiple
|
|
|
|
for ($i = 1; $i <= count($data) ; $i++) {
|
2019-01-26 11:27:00 +01:00
|
|
|
echo $this->deleteData(['module', $this->getUrl(0), 'data', $i]);
|
2019-01-26 11:09:47 +01:00
|
|
|
}
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/data',
|
2023-01-24 09:57:45 +01:00
|
|
|
'notification' => helper::translate('Données effacées'),
|
2019-01-26 11:09:47 +01:00
|
|
|
'state' => true
|
|
|
|
]);
|
|
|
|
} else {
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/data',
|
2023-01-24 09:57:45 +01:00
|
|
|
'notification' => helper::translate('Aucune donnée à effacer')
|
2019-01-26 11:09:47 +01:00
|
|
|
]);
|
|
|
|
}
|
2018-04-02 08:29:19 +02:00
|
|
|
}
|
2019-01-26 11:09:47 +01:00
|
|
|
}
|
|
|
|
|
2020-06-03 08:54:48 +02:00
|
|
|
|
2019-01-26 11:09:47 +01:00
|
|
|
/**
|
|
|
|
* Suppression
|
|
|
|
*/
|
|
|
|
public function delete() {
|
|
|
|
// Jeton incorrect
|
|
|
|
if ($this->getUrl(3) !== $_SESSION['csrf']) {
|
2018-04-02 08:29:19 +02:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
2019-01-26 11:09:47 +01:00
|
|
|
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/data',
|
2023-01-24 09:57:45 +01:00
|
|
|
'notification' => helper::translate('Action interdite')
|
2018-04-02 08:29:19 +02:00
|
|
|
]);
|
2019-01-26 11:09:47 +01:00
|
|
|
} else {
|
|
|
|
// La donnée n'existe pas
|
|
|
|
if($this->getData(['module', $this->getUrl(0), 'data', $this->getUrl(2)]) === null) {
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'access' => false
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
// Suppression
|
|
|
|
else {
|
|
|
|
$this->deleteData(['module', $this->getUrl(0), 'data', $this->getUrl(2)]);
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/data',
|
2023-01-24 09:57:45 +01:00
|
|
|
'notification' => helper::translate('Donnée effacée'),
|
2019-01-26 11:09:47 +01:00
|
|
|
'state' => true
|
|
|
|
]);
|
|
|
|
}
|
2018-04-02 08:29:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-26 11:09:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2018-04-02 08:29:19 +02:00
|
|
|
/**
|
|
|
|
* Accueil
|
|
|
|
*/
|
|
|
|
public function index() {
|
2022-10-10 11:28:27 +02:00
|
|
|
|
|
|
|
// Mise à jour des données de module
|
|
|
|
$this->update();
|
|
|
|
|
2018-04-02 08:29:19 +02:00
|
|
|
// Soumission du formulaire
|
|
|
|
if($this->isPost()) {
|
2020-08-10 19:07:17 +02:00
|
|
|
// Check la captcha
|
2018-04-02 08:29:19 +02:00
|
|
|
if(
|
2020-08-10 19:07:17 +02:00
|
|
|
$this->getData(['module', $this->getUrl(0), 'config', 'captcha'])
|
2020-10-01 15:50:19 +02:00
|
|
|
// AND $this->getInput('formcaptcha', helper::FILTER_INT) !== $this->getInput('formcaptchaFirstNumber', helper::FILTER_INT) + $this->getInput('formcaptchaSecondNumber', helper::FILTER_INT))
|
2021-02-25 07:53:57 +01:00
|
|
|
AND password_verify($this->getInput('formCaptcha', helper::FILTER_INT), $this->getInput('formCaptchaResult') ) === false )
|
2018-04-02 08:29:19 +02:00
|
|
|
{
|
2023-01-24 09:57:45 +01:00
|
|
|
self::$inputNotices['formCaptcha'] = helper::translate('Captcha incorrect');
|
2020-06-03 08:54:48 +02:00
|
|
|
|
2018-04-02 08:29:19 +02:00
|
|
|
}
|
|
|
|
// Préparation le contenu du mail
|
|
|
|
$data = [];
|
2020-02-28 14:58:50 +01:00
|
|
|
$replyTo = null;
|
2020-06-03 08:54:48 +02:00
|
|
|
$content = '';
|
2018-04-02 08:29:19 +02:00
|
|
|
foreach($this->getData(['module', $this->getUrl(0), 'input']) as $index => $input) {
|
|
|
|
// Filtre la valeur
|
|
|
|
switch($input['type']) {
|
|
|
|
case self::TYPE_MAIL:
|
|
|
|
$filter = helper::FILTER_MAIL;
|
|
|
|
break;
|
|
|
|
case self::TYPE_TEXTAREA:
|
|
|
|
$filter = helper::FILTER_STRING_LONG;
|
|
|
|
break;
|
2020-06-03 08:54:48 +02:00
|
|
|
case self::TYPE_DATETIME:
|
2018-11-28 15:32:22 +01:00
|
|
|
$filter = helper::FILTER_STRING_SHORT; // Mettre TYPE_DATETIME pour récupérer un TIMESTAMP
|
2018-11-28 12:44:32 +01:00
|
|
|
break;
|
2020-06-03 08:54:48 +02:00
|
|
|
case self::TYPE_CHECKBOX:
|
2019-01-23 13:07:28 +01:00
|
|
|
$filter = helper::FILTER_BOOLEAN;
|
|
|
|
break;
|
2018-04-02 08:29:19 +02:00
|
|
|
default:
|
|
|
|
$filter = helper::FILTER_STRING_SHORT;
|
|
|
|
}
|
2019-11-27 14:28:23 +01:00
|
|
|
$value = $this->getInput('formInput[' . $index . ']', $filter, $input['required']) === true ? 'X' : $this->getInput('formInput[' . $index . ']', $filter, $input['required']);
|
2020-06-03 08:54:48 +02:00
|
|
|
// premier champ email ajouté au mail en reply si option active
|
|
|
|
if ($this->getData(['module', $this->getUrl(0), 'config', 'replyto']) === true &&
|
|
|
|
$input['type'] === 'mail') {
|
2020-02-26 23:45:49 +01:00
|
|
|
$replyTo = $value;
|
2020-02-28 15:00:28 +01:00
|
|
|
}
|
2018-04-02 08:29:19 +02:00
|
|
|
// Préparation des données pour la création dans la base
|
|
|
|
$data[$this->getData(['module', $this->getUrl(0), 'input', $index, 'name'])] = $value;
|
|
|
|
// Préparation des données pour le mail
|
|
|
|
$content .= '<strong>' . $this->getData(['module', $this->getUrl(0), 'input', $index, 'name']) . ' :</strong> ' . $value . '<br>';
|
|
|
|
}
|
|
|
|
// Crée les données
|
|
|
|
$this->setData(['module', $this->getUrl(0), 'data', helper::increment(1, $this->getData(['module', $this->getUrl(0), 'data'])), $data]);
|
|
|
|
// Envoi du mail
|
2019-02-13 19:57:10 +01:00
|
|
|
// Rechercher l'adresse en fonction du mail
|
2018-04-02 08:29:19 +02:00
|
|
|
$sent = true;
|
2019-02-13 19:57:10 +01:00
|
|
|
$singleuser = $this->getData(['user',
|
2019-03-10 20:56:36 +01:00
|
|
|
$this->getData(['module', $this->getUrl(0), 'config', 'user']),
|
|
|
|
'mail']);
|
2019-02-12 14:39:36 +01:00
|
|
|
$singlemail = $this->getData(['module', $this->getUrl(0), 'config', 'mail']);
|
2019-03-10 20:56:36 +01:00
|
|
|
$group = $this->getData(['module', $this->getUrl(0), 'config', 'group']);
|
2019-02-13 19:57:10 +01:00
|
|
|
// Verification si le mail peut être envoyé
|
2018-04-02 08:29:19 +02:00
|
|
|
if(
|
2019-03-10 10:26:12 +01:00
|
|
|
self::$inputNotices === [] && (
|
2019-03-10 20:56:36 +01:00
|
|
|
$group > 0 ||
|
2019-03-10 10:26:12 +01:00
|
|
|
$singleuser !== '' ||
|
|
|
|
$singlemail !== '' )
|
2018-04-02 08:29:19 +02:00
|
|
|
) {
|
|
|
|
// Utilisateurs dans le groupe
|
2019-03-10 20:56:36 +01:00
|
|
|
$to = [];
|
|
|
|
if ($group > 0){
|
2019-03-10 10:26:12 +01:00
|
|
|
foreach($this->getData(['user']) as $userId => $user) {
|
2019-05-02 13:21:48 +02:00
|
|
|
if($user['group'] >= $group) {
|
2019-03-10 10:26:12 +01:00
|
|
|
$to[] = $user['mail'];
|
|
|
|
}
|
2018-04-02 08:29:19 +02:00
|
|
|
}
|
2020-06-03 08:54:48 +02:00
|
|
|
}
|
2019-02-12 14:39:36 +01:00
|
|
|
// Utilisateur désigné
|
|
|
|
if (!empty($singleuser)) {
|
|
|
|
$to[] = $singleuser;
|
|
|
|
}
|
|
|
|
// Mail désigné
|
|
|
|
if (!empty($singlemail)) {
|
|
|
|
$to[] = $singlemail;
|
|
|
|
}
|
2018-04-02 08:29:19 +02:00
|
|
|
if($to) {
|
|
|
|
// Sujet du mail
|
|
|
|
$subject = $this->getData(['module', $this->getUrl(0), 'config', 'subject']);
|
|
|
|
if($subject === '') {
|
|
|
|
$subject = 'Nouveau message en provenance de votre site';
|
|
|
|
}
|
|
|
|
// Envoi le mail
|
|
|
|
$sent = $this->sendMail(
|
|
|
|
$to,
|
|
|
|
$subject,
|
|
|
|
'Nouveau message en provenance de la page "' . $this->getData(['page', $this->getUrl(0), 'title']) . '" :<br><br>' .
|
2020-02-26 23:45:49 +01:00
|
|
|
$content,
|
|
|
|
$replyTo
|
2018-04-02 08:29:19 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Redirection
|
|
|
|
$redirect = $this->getData(['module', $this->getUrl(0), 'config', 'pageId']);
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
2023-01-24 09:57:45 +01:00
|
|
|
'notification' => ($sent === true ? helper::translate('Formulaire soumis') : $sent),
|
2018-04-02 08:29:19 +02:00
|
|
|
'redirect' => $redirect ? helper::baseUrl() . $redirect : '',
|
2020-08-21 18:01:55 +02:00
|
|
|
'state' => ($sent === true ? true : null),
|
|
|
|
'vendor' => [
|
|
|
|
'flatpickr'
|
|
|
|
],
|
2018-04-02 08:29:19 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'showBarEditButton' => true,
|
|
|
|
'showPageContent' => true,
|
2018-11-28 12:44:32 +01:00
|
|
|
'view' => 'index',
|
2020-08-21 18:01:55 +02:00
|
|
|
'vendor' => [
|
|
|
|
'flatpickr'
|
|
|
|
],
|
2018-04-02 08:29:19 +02:00
|
|
|
]);
|
|
|
|
}
|
2022-10-10 11:28:27 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Mise à jour du module
|
|
|
|
* Appelée par les fonctions index et config
|
|
|
|
*/
|
|
|
|
private function update() {
|
|
|
|
|
|
|
|
// le module n'est pas initialisé
|
|
|
|
if ( $this->getData(['module',$this->getUrl(0), 'config']) === NULL ) {
|
|
|
|
$this->init();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialisation du thème d'un nouveau module
|
|
|
|
*/
|
|
|
|
private function init() {
|
|
|
|
// Données du module absentes
|
|
|
|
require_once('module/form/ressource/defaultdata.php');
|
|
|
|
if ($this->getData(['module', $this->getUrl(0), 'config' ]) === null) {
|
|
|
|
$this->setData(['module', $this->getUrl(0), 'config', init::$defaultData]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-07 14:57:32 +02:00
|
|
|
}
|