From e6f20872269b40f040a7ab2eccbc1040eab0cd40 Mon Sep 17 00:00:00 2001 From: tofulm Date: Thu, 11 Mar 2021 14:38:17 +0100 Subject: [PATCH] Gestion de l'envoi du formulaire : - id_auteur du param - liste d'id_auteur de la conf - liste d'email de la conf - --- content/contact.html | 5 + formulaires/configurer_gamucontact.html | 26 ++++++ formulaires/gamucontact.html | 27 ++++++ formulaires/gamucontact.php | 116 ++++++++++++++++++++++++ gamucontact_administrations.php | 3 + gamucontact_options.php | 50 ++++++++++ modeles/gamucontact_message.html | 25 +++++ paquet.xml | 14 +-- test.html | 4 + 9 files changed, 263 insertions(+), 7 deletions(-) create mode 100644 content/contact.html create mode 100644 formulaires/gamucontact.html create mode 100644 formulaires/gamucontact.php create mode 100644 modeles/gamucontact_message.html create mode 100644 test.html diff --git a/content/contact.html b/content/contact.html new file mode 100644 index 0000000..a9e3cc1 --- /dev/null +++ b/content/contact.html @@ -0,0 +1,5 @@ +#CACHE{0} + +
+ [(#FORMULAIRE_GAMUCONTACT{#ENV{id_auteur}, #ENV{redirect}})] +
diff --git a/formulaires/configurer_gamucontact.html b/formulaires/configurer_gamucontact.html index ada9d9c..3bd2288 100644 --- a/formulaires/configurer_gamucontact.html +++ b/formulaires/configurer_gamucontact.html @@ -9,6 +9,32 @@
#ACTION_FORMULAIRE +
+ #SET{name,liste_emails} + #SET{erreurs,#ENV**{erreurs}|table_valeur{#GET{name}}} + #SET{obli,"obligatoire"} +
+ + [(#GET{erreurs})] + +

Liste d'emails séparés par des ;

+
+
+ +
+ #SET{name,liste_id_auteur} + #SET{erreurs,#ENV**{erreurs}|table_valeur{#GET{name}}} + #SET{obli,"obligatoire"} +
+ + [(#GET{erreurs})] + +

Liste d'id_auteur séparés par des ;

+
+
+ + +

 

diff --git a/formulaires/gamucontact.html b/formulaires/gamucontact.html new file mode 100644 index 0000000..aea865e --- /dev/null +++ b/formulaires/gamucontact.html @@ -0,0 +1,27 @@ +
+ +[

(#ENV*{message_erreur})

] +[

(#ENV*{message_ok})

] + +
+ #ACTION_FORMULAIRE{#ENV{action}} + + +
+ <:gamucontact:votre_message:> + #GENERER_SAISIES{#ENV{_saisies}} +
+ + [(#REM) Piege a robots spammeurs ] +

+ + +

+
+ +
+
+ +
diff --git a/formulaires/gamucontact.php b/formulaires/gamucontact.php new file mode 100644 index 0000000..6b0a970 --- /dev/null +++ b/formulaires/gamucontact.php @@ -0,0 +1,116 @@ + 0) { + $set = pipeline( + 'pre_edition', + array( + 'args' => array( + 'action' => 'gamucontact_pre_contact', + ), + 'data' => $set + ) + ); + $id_message = sql_insertq('spip_messages', $set); + } + } + + $destinataires = []; + if (intval($id_auteur)) { + $email = sql_getfetsel('email', 'spip_auteurs', 'id_auteur='.intval($id_auteur)); + if ($email) { + $destinataires[] = $email; + } + } + + $liste_emails = lire_config('gamucontact/liste_emails'); + if (strlen($liste_emails)) { + $Tliste_emails = explode(';', $liste_emails); + if (is_array($Tliste_emails) and count($Tliste_emails)) { + $destinataires = array_merge($Tliste_emails, $destinataires); + } + } + + $liste_id_auteur = lire_config('gamucontact/liste_id_auteur'); + if (strlen($liste_id_auteur)) { + $Tliste_id_auteur = explode(';', $liste_id_auteur); + if (is_array($Tliste_id_auteur) and count($Tliste_id_auteur)) { + $t = sql_allfetsel('email', 'spip_auteurs', sql_in('id_auteur', $Tliste_id_auteur)); + if(is_array($t) and count($t)) { + $t = array_column($t, 'email'); + $destinataires = array_merge($t, $destinataires); + } + } + } + if (count($destinataires)) { + $html = recuperer_fond('modeles/gamucontact_message', ['id_message' => $id_message]); + include_spip('classes/facteur'); + $texte = Facteur::html2text($html); + + $corps = array( + 'html' => $html, + 'texte' => $texte, + ); + + $envoyer_mail = charger_fonction('envoyer_mail', 'inc'); + $envoyer_mail($destinataires, _request('objet'), $corps, '', 'X-Originating-IP: '.$GLOBALS['ip']); + } + + + if ($redirect) { + $retour['redirect'] = $redirect; + } + + return $retour; +} diff --git a/gamucontact_administrations.php b/gamucontact_administrations.php index ae4e950..e423ad9 100644 --- a/gamucontact_administrations.php +++ b/gamucontact_administrations.php @@ -26,6 +26,9 @@ if (!defined('_ECRIRE_INC_VERSION')) { function gamucontact_upgrade($nom_meta_base_version, $version_cible) { $maj = array(); + $maj['create'] = array(array('maj_tables', array('spip_messages'))); + $maj['1.0.4'] = array(array('maj_tables', array('spip_messages'))); + include_spip('base/upgrade'); maj_plugin($nom_meta_base_version, $version_cible, $maj); } diff --git a/gamucontact_options.php b/gamucontact_options.php index c29e5be..cc921d4 100644 --- a/gamucontact_options.php +++ b/gamucontact_options.php @@ -12,3 +12,53 @@ if (!defined('_ECRIRE_INC_VERSION')) { return; } + + +$GLOBALS['gamucontact'] = [ + [ + 'saisie' => 'input', + 'options' => array( + 'nom' => 'nom', + 'label' => 'Votre Nom', + 'obligatoire' => 'oui', + //'fonction' => 'ma_super_fonction' + ) + ], + [ + 'saisie' => 'input', + 'options' => array( + 'nom' => 'email_contact', + 'label' => 'Votre Email', + 'obligatoire' => 'oui', + ) + ], + [ + 'saisie' => 'input', + 'options' => array( + 'nom' => 'objet', + 'label' => 'Objet', + 'obligatoire' => 'oui', + //'fonction' => 'ma_super_fonction' + ) + ], + [ + 'saisie' => 'textarea', + 'options' => array( + 'nom' => 'texte', + 'label' => 'Message', + 'obligatoire' => 'oui', + //'fonction' => 'ma_super_fonction' + ) + ], +]; + + +function gamucontact_declarer_tables_objets_sql($tables) { + + $tables['spip_messages']['field']['telephone'] = "varchar(55) NOT NULL"; + $tables['spip_messages']['field']['nom'] = "varchar(255) NOT NULL"; + $tables['spip_messages']['field']['objet'] = "varchar(255) NOT NULL"; + $tables['spip_messages']['field']['email_contact'] = "varchar(255) NOT NULL"; + + return $tables; +} diff --git a/modeles/gamucontact_message.html b/modeles/gamucontact_message.html new file mode 100644 index 0000000..0a70be5 --- /dev/null +++ b/modeles/gamucontact_message.html @@ -0,0 +1,25 @@ + + + + + + #NOM_SITE_SPIP + + +
+ [] +
+
+

Formulaire de contact

+ +
+ [Nom : (#NOM)
] + [Email : (#EMAIL_CONTACT)
] + [Téléphone : (#TELEPHONE)] + [
objet : (#OBJET)
] + [message : (#TEXTE)
] +
+ +
+ + diff --git a/paquet.xml b/paquet.xml index fb1e14d..8ca308b 100644 --- a/paquet.xml +++ b/paquet.xml @@ -1,25 +1,25 @@ - Gamu Contact - tofulm GNU/GPL + - + + + + diff --git a/test.html b/test.html new file mode 100644 index 0000000..afd1b1b --- /dev/null +++ b/test.html @@ -0,0 +1,4 @@ +#CACHE{0} + + +