- Add message plugin
- Update contact
This commit is contained in:
parent
b567357140
commit
1ec7c28ea2
6 changed files with 530 additions and 246 deletions
100
content/plugins/ldc-messages/ldc-messages.php
Normal file
100
content/plugins/ldc-messages/ldc-messages.php
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
<?php
|
||||
/*
|
||||
Plugin Name: LDC Messages
|
||||
Description: Gestion des formulaires de contact
|
||||
Version: 1.0
|
||||
Author: Vincent BRIDIER
|
||||
*/
|
||||
|
||||
add_action('admin_menu', 'plugin_menu');
|
||||
function plugin_menu()
|
||||
{
|
||||
add_menu_page('LDC Messages', 'LDC Messages', 'manage_options', 'ldc-messages', 'init', 'dashicons-email-alt', 30);
|
||||
}
|
||||
|
||||
function ldc_messages() {
|
||||
wp_register_style('ldc_messages', plugins_url('style.css',__FILE__ ));
|
||||
wp_enqueue_style('ldc_messages');
|
||||
}
|
||||
add_action('admin_init','ldc_messages');
|
||||
|
||||
function my_admin_scripts() {
|
||||
/* wp_deregister_script('jquery');
|
||||
wp_enqueue_script('jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array(), null, true);*/
|
||||
wp_enqueue_style( 'fancyboxcss', get_template_directory_uri() . '/assets/js/fancybox/jquery.fancybox.min.css',false,'1.1','all');
|
||||
wp_enqueue_script( 'fancyboxjs', get_template_directory_uri() . '/assets/js/fancybox/jquery.fancybox.min.js',false,'1.1','all');
|
||||
|
||||
wp_enqueue_script( 'ldc_messages', plugins_url('script.js',__FILE__ ), array('jquery'), '1.0.0', false);
|
||||
}
|
||||
add_action( 'admin_enqueue_scripts', 'my_admin_scripts' );
|
||||
|
||||
function getMessages()
|
||||
{
|
||||
global $wpdb;
|
||||
return $wpdb->get_results("SELECT *, wp_messages.id AS msg_id FROM wp_messages, wp_messages_types WHERE wp_messages.type_id = wp_messages_types.id ORDER BY date DESC", OBJECT);
|
||||
}
|
||||
|
||||
function init()
|
||||
{
|
||||
$page = '<div class="wrap">';
|
||||
$page .= '<h1 class="wp-heading-inline">Gestion des messages - LDC</h1>';
|
||||
|
||||
// Tableau
|
||||
$page .= "<table class='ldc_messages_table'>";
|
||||
|
||||
$page .= "<tr>";
|
||||
|
||||
$page .= "<th>#</th>";
|
||||
$page .= "<th>Date</th>";
|
||||
$page .= "<th>Statut</th>";
|
||||
$page .= "<th>Nom</th>";
|
||||
$page .= "<th>Prénom</th>";
|
||||
$page .= "<th>Email</th>";
|
||||
$page .= "<th>Type</th>";
|
||||
$page .= "<th>Date de réponse</th>";
|
||||
$page .= "<th></th>";
|
||||
|
||||
$page .= "</tr>";
|
||||
|
||||
$messages = getMessages();
|
||||
foreach ($messages as $message){
|
||||
$page .= "<tr>";
|
||||
|
||||
$page .= "<td style='font-weight: bold;'>$message->ref</td>";
|
||||
|
||||
$page .= "<td>". date('d/m/Y H:i', strtotime($message->date)) ."</td>";
|
||||
|
||||
if ($message->status === '0'){
|
||||
$page .= "<td><p class='ldc_messages_red'>À traiter</p></td>";
|
||||
}else{
|
||||
$page .= "<td><p class='ldc_messages_green'>Traité</p></td>";
|
||||
}
|
||||
|
||||
$page .= "<td>$message->lastname</td>";
|
||||
$page .= "<td>$message->firstname</td>";
|
||||
$page .= "<td><a href='mailto:$message->email'>$message->email</a></td>";
|
||||
$page .= "<td>$message->name</td>";
|
||||
|
||||
if ($message->response_date !== NULL){
|
||||
$page .= "<td>". date('d/m/Y H:i', strtotime($message->response_date)) ."</td>";
|
||||
}else{
|
||||
$page .= "<td>-</td>";
|
||||
}
|
||||
|
||||
if ($message->status === '0'){
|
||||
$page .= "<td><a href='#' class='answer-msg' data-id='$message->msg_id' data-ref='$message->ref'>Répondre</a></td>";
|
||||
}else{
|
||||
$page .= "<td><a href='#' class='show-msg' data-id='$message->msg_id'>Afficher</a></td>";
|
||||
}
|
||||
|
||||
$page .= "</tr>";
|
||||
}
|
||||
|
||||
$page .= "</table>";
|
||||
|
||||
$page .= "<div id='reponse-msg' style='display:none'></div>";
|
||||
|
||||
$page .= '</div>';
|
||||
|
||||
echo $page;
|
||||
}
|
||||
80
content/plugins/ldc-messages/script.js
Normal file
80
content/plugins/ldc-messages/script.js
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
let $j = jQuery.noConflict();
|
||||
|
||||
$j(function(){
|
||||
|
||||
let currentMsg;
|
||||
let currentMsgRef;
|
||||
|
||||
$j('body').on('click', '.answer-msg', function(e){
|
||||
e.preventDefault();
|
||||
|
||||
currentMsg = $j(this).data('id');
|
||||
currentMsgRef = $j(this).data('ref');
|
||||
|
||||
$j.post(
|
||||
ajaxurl,
|
||||
{
|
||||
'action': 'getReponseForMsg',
|
||||
'id' : currentMsg,
|
||||
},
|
||||
function(response){
|
||||
$j('#reponse-msg').empty().html(response);
|
||||
$j.fancybox.open({
|
||||
src : '#reponse-msg',
|
||||
type : 'inline',
|
||||
afterClose: function (){
|
||||
window.location.reload();
|
||||
},
|
||||
closeBtn: true
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
});
|
||||
|
||||
$j('body').on('click', '.show-msg', function(e){
|
||||
e.preventDefault();
|
||||
|
||||
currentMsg = $j(this).data('id');
|
||||
|
||||
$j.post(
|
||||
ajaxurl,
|
||||
{
|
||||
'action': 'getMsg',
|
||||
'id' : currentMsg,
|
||||
},
|
||||
function(response){
|
||||
$j('#reponse-msg').empty().html(response);
|
||||
$j.fancybox.open({
|
||||
src : '#reponse-msg',
|
||||
type : 'inline',
|
||||
afterClose: function (){
|
||||
window.location.reload();
|
||||
},
|
||||
closeBtn: true
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
});
|
||||
|
||||
$j('body').on('click', '.send-answer', function(e){
|
||||
e.preventDefault();
|
||||
let email = $j('#emailTosend').val();
|
||||
let message = $j('#msgTosend').val();
|
||||
$j.post(
|
||||
ajaxurl,
|
||||
{
|
||||
'action': 'sendReponse',
|
||||
'email' : email,
|
||||
'message' : message,
|
||||
'id' : currentMsg,
|
||||
'ref': currentMsgRef
|
||||
},
|
||||
function(response){
|
||||
$j('#reponse-msg').empty().html(response);
|
||||
}
|
||||
);
|
||||
})
|
||||
|
||||
});
|
||||
40
content/plugins/ldc-messages/style.css
Normal file
40
content/plugins/ldc-messages/style.css
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
.ldc_messages_table {
|
||||
border-collapse: collapse;
|
||||
width: 90%;
|
||||
margin: 30px auto 0 auto;
|
||||
background-color: white;
|
||||
}
|
||||
|
||||
.ldc_messages_table, .ldc_messages_table th, .ldc_messages_table td {
|
||||
border: 1px solid;
|
||||
}
|
||||
|
||||
.ldc_messages_table th, .ldc_messages_table td {
|
||||
padding: 15px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.ldc_messages_table th {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.ldc_messages_red {
|
||||
color: red;
|
||||
}
|
||||
|
||||
.ldc_messages_green {
|
||||
color: green;
|
||||
}
|
||||
|
||||
#reponse-msg {
|
||||
width:700px;
|
||||
}
|
||||
|
||||
#reponse-msg p{
|
||||
margin:0;
|
||||
}
|
||||
|
||||
#reponse-msg textarea {
|
||||
width:100%;
|
||||
height:250px;
|
||||
}
|
||||
167
content/themes/ldc/contacts/6249_eleveurs.php
Normal file
167
content/themes/ldc/contacts/6249_eleveurs.php
Normal file
|
|
@ -0,0 +1,167 @@
|
|||
<h2 class="contacts-page-subtitle subtitle_paint"><?= the_title(); ?></h2>
|
||||
<div class="contacts-category-page wrapper">
|
||||
<div class="back-button-wrapper">
|
||||
<a href="/nous-contacter/" class="back-button" title="Retour au choix de contact">Retour au choix de contact</a>
|
||||
</div>
|
||||
<div class="contacts-form__wrapper">
|
||||
<form class="form">
|
||||
<div class="form__container">
|
||||
<div class="form-top-text">Vous êtes éleveur de volailles ou souhaitez le devenir, et nous rejoindre ? <br>Décrivez-nous votre projet le plus précisément possible afin que nous puissions orienter votre demande vers l'interlocuteur adéquat.</div>
|
||||
<div class="form__row">
|
||||
<div class="form__field">
|
||||
<div class="form__field-title">Nom *</div>
|
||||
<input type="text" name="lastname" size="40" class="form__input" placeholder="Votre Nom" required>
|
||||
</div>
|
||||
<div class="form__field">
|
||||
<div class="form__field-title">Prénom *</div>
|
||||
<input type="text" name="firstname" size="40" class="form__input" placeholder="Votre Prénom" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form__row">
|
||||
<div class="form__field">
|
||||
<div class="form__field-title">Téléphone *</div>
|
||||
<input type="tel" name="phone" size="20" class="form__input" placeholder="Par exemple, 02 43 62 70 00" required>
|
||||
</div>
|
||||
<div class="form__field">
|
||||
<div class="form__field-title">Adresse Email *</div>
|
||||
<input type="email" name="email" size="40" class="form__input" aria-required="true" aria-invalid="false" placeholder="Prenom.nom@mail.fr" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form__row">
|
||||
<div class="form__field">
|
||||
<div class="form__field-title">Type d'élevage souhaité * <span class="normal">(choix multiple)</span></div>
|
||||
<label class="form__field-pseudolabel">
|
||||
<input type="checkbox" name="types" value="Poulets/dindes/pintades" required>
|
||||
<span class="form__field-pseudocircle">Poulets/dindes/pintades</span>
|
||||
</label>
|
||||
<label class="form__field-pseudolabel">
|
||||
<input type="checkbox" name="types" value="Canards" required>
|
||||
<span class="form__field-pseudocircle">Canards</span>
|
||||
</label>
|
||||
<label class="form__field-pseudolabel">
|
||||
<input type="checkbox" name="types" value="Poules pondeuses" required>
|
||||
<span class="form__field-pseudocircle">Poules pondeuses</span>
|
||||
</label>
|
||||
<label class="form__field-pseudolabel">
|
||||
<input type="checkbox" name="types" value="Autres" required>
|
||||
<span class="form__field-pseudocircle">Autres</span>
|
||||
</label>
|
||||
<div class="form__error" id="<?= $post->ID; ?>_types" style="display: none;">Ce champs est obligatoire</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form__row">
|
||||
<div class="form__field">
|
||||
<div class="form__field-title">Zone géographique de votre projet *</div>
|
||||
<div class="geographic-checkboxes-block">
|
||||
<div class="geographic-checkboxes-result form__input"><span class="zones-wrapper">Liste déroulante de départements</span></div>
|
||||
<div class="geographic-checkboxes-list">
|
||||
<?php $dps = ["Ain","Aisne","Allier","Alpes-de-Haute-Provence","Alpes-Maritimes","Ardèche","Ardennes","Ariège","Aube","Aude","Aveyron","Bas-Rhin","Bouches-du-Rhône","Calvados","Cantal","Charente","Charente-Maritime","Cher","Corrèze","Corse-du-Sud","Côte-d'Or","Côtes-d'Armor","Creuse","Deux-Sèvres","Dordogne","Doubs","Drôme","Essonne","Eure","Eure-et-Loir","Finistère","Gard","Gers","Gironde","Guadeloupe","Guyane","Haut-Rhin","Haute-Corse","Haute-Garonne","Haute-Loire","Haute-Marne","Haute-Saône","Haute-Savoie","Haute-Vienne","Hautes-Alpes","Hautes-Pyrénées","Hauts-de-Seine","Hérault","Ille-et-Vilaine","Indre","Indre-et-Loire","Isère","Jura","La,Réunion","Landes","Loir-et-Cher","Loire","Loire-Atlantique","Loiret","Lot","Lot-et-Garonne","Lozère","Lyon,Metropolis","Maine-et-Loire","Manche","Marne","Martinique","Mayenne","Mayotte","Meurthe-et-Moselle","Meuse","Morbihan","Moselle","Nièvre","Nord","Oise","Orne","Paris","Pas-de-Calais","Puy-de-Dôme","Pyrénées-Atlantiques","Pyrénées-Orientales","Rhône","Saône-et-Loire","Sarthe","Savoie","Seine-Maritime","Seine-et-Marne","Seine-Saint-Denis","Somme","Tarn","Tarn-et-Garonne","Territoire,de,Belfort","Var","Val-d'Oise","Val-de-Marne","Vaucluse","Vendée","Vienne","Vosges","Yonne","Yvelines"]; ?>
|
||||
<?php foreach ($dps as $dp): ?>
|
||||
<label class="form__field-pseudolabel">
|
||||
<input type="checkbox" name="geo" value="<?= $dp; ?>" required>
|
||||
<span class="form__field-pseudosquare"><?= $dp; ?></span>
|
||||
</label>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form__container">
|
||||
<div class="form__field-title">Votre projet *</div>
|
||||
|
||||
<div class="form__field">
|
||||
<textarea name="message" cols="40" rows="10" class="form__input" placeholder="Détailler ici votre projet et votre demande" required></textarea>
|
||||
</div>
|
||||
|
||||
<div class="form__row">
|
||||
<div class="form__field">
|
||||
<label class="form__field-pseudolabel">
|
||||
<input type="checkbox" name="agree">
|
||||
<span class="form__field-pseudosquare">J’accepte les conditions d’utilisation *</span>
|
||||
</label>
|
||||
<label class="form__field-pseudolabel">
|
||||
<input type="checkbox" name="newsletter">
|
||||
<span class="form__field-pseudosquare">Je souhaite m’inscrire à la newsletter</span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="form__field"><div class="form__tip">* Champs obligatoires</div></div>
|
||||
</div>
|
||||
|
||||
<div class="form__row">
|
||||
<!-- TODO : Gestion recaptcha -->
|
||||
<div class="form__field">[recaptcha]</div>
|
||||
</div>
|
||||
|
||||
<div class="form__response" style="display: none;">Un ou plusieurs champs contiennent une erreur. Veuillez vérifier et essayer à nouveau.</div>
|
||||
|
||||
<div class="form__row">
|
||||
<div class="form-submit">
|
||||
<input type="submit" value="Envoyer" class="form-submit__btn btn">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
let lastname = $("input[name=lastname]");
|
||||
let firstname = $("input[name=firstname]");
|
||||
let phone = $("input[name=phone]");
|
||||
let email = $("input[name=email]");
|
||||
let message = $("textarea[name=message]");
|
||||
let agree = $("input[name=agree]");
|
||||
// TODO : Gestion newsletter
|
||||
let newsletter = $("input[name=newsletter]");
|
||||
|
||||
$("input[type=submit]").on('click', function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
let types = $('input[name=types]:checked').map(function(_, el) {
|
||||
return $(el).val();
|
||||
}).get();
|
||||
|
||||
let geo = $('input[name=geo]:checked').map(function(_, el) {
|
||||
return $(el).val();
|
||||
}).get();
|
||||
|
||||
if (lastname.val().length > 0 && firstname.val().length > 0 && phone.val().length > 0 && email.val().length > 0 && message.val().length > 0 && types.length > 0 && geo.length > 0) {
|
||||
|
||||
$(".form__response").hide();
|
||||
|
||||
if (agree.is(':checked') === false){
|
||||
alert("Vous devez accepter les conditions d'utilisation.");
|
||||
}else{
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: window.location.origin + '/wp-admin/admin-ajax.php',
|
||||
data: {
|
||||
'action': 'ContactAjx',
|
||||
'id': <?= $post->ID; ?>,
|
||||
'firstname': firstname.val(),
|
||||
'lastname': lastname.val(),
|
||||
'email': email.val(),
|
||||
'phone': phone.val(),
|
||||
'message': message.val(),
|
||||
'zonegeo': geo,
|
||||
'typeelevage': types
|
||||
},
|
||||
success: function (response, textStatus, jqXHR ) {
|
||||
alert('Bonjour. Nous vous remercions de nous avoir contactés pour nous rejoindre en tant qu\'éleveur. Notre équipe Élevage vous répondra dans les meilleurs délais.');
|
||||
},
|
||||
error: function(jqXHR, textStatus, errorThrown) {
|
||||
alert('Une erreur est survenue, veuillez recharger la page.');
|
||||
}
|
||||
});
|
||||
}
|
||||
}else{
|
||||
$(".form__response").show();
|
||||
}
|
||||
|
||||
});
|
||||
</script>
|
||||
|
|
@ -409,120 +409,92 @@ function catLink($cat_id) {
|
|||
|
||||
///////////////////// POC : REPONDRE AUX CONTACTS DIRECTEMENT DEPUIS L'ADMINISTRATION //////////////////////
|
||||
|
||||
// ---- CPT Message
|
||||
function wp_cpt_messages() {
|
||||
$labels = array(
|
||||
'name' => _x( 'Message', 'Post Type General Name'),
|
||||
'singular_name' => _x( 'Message', 'Post Type Singular Name'),
|
||||
'menu_name' => __( 'Messages'),
|
||||
'all_items' => __( 'Tous les Messages'),
|
||||
'view_item' => __( 'Voir les Messages'),
|
||||
'add_new_item' => __( 'Ajouter un Message'),
|
||||
'add_new' => __( 'Ajouter'),
|
||||
'edit_item' => __( 'Editer le Message'),
|
||||
'update_item' => __( 'Modifier le Message'),
|
||||
'search_items' => __( 'Rechercher un Message'),
|
||||
'not_found' => __( 'Non trouvée'),
|
||||
'not_found_in_trash' => __( 'Non trouvée dans la corbeille'),
|
||||
);
|
||||
|
||||
$args = array(
|
||||
'label' => __( 'Message'),
|
||||
'labels' => $labels,
|
||||
'supports' => array( 'title', 'editor', 'thumbnail'),
|
||||
'hierarchical' => true,
|
||||
'public' => true,
|
||||
'has_archive' => true,
|
||||
'taxonomies' => array('type'),
|
||||
'rewrite' => array( 'slug' => 'type/%gamme%'),
|
||||
'map_meta_cap' => true,
|
||||
'menu_icon' => 'dashicons-email-alt'
|
||||
);
|
||||
|
||||
register_post_type( 'message', $args );
|
||||
// Contact Ajax
|
||||
function getMessageType($postID){
|
||||
switch ($postID){
|
||||
case 6249:
|
||||
return 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
add_action( 'init', 'wp_cpt_messages', 0 );
|
||||
|
||||
// ---- Taxo : Type de message
|
||||
function taxo_type_message() {
|
||||
$args = array(
|
||||
'label' => __( 'Type' ),
|
||||
'hierarchical' => true,
|
||||
'rewrite' => array( 'slug' => 'type', 'with_front' => false ),
|
||||
'show_ui' => true,
|
||||
'show_in_quick_edit' => false,
|
||||
'show_admin_column' => true,
|
||||
);
|
||||
register_taxonomy( 'type', 'message', $args );
|
||||
function sendNotification($postID, $ref) {
|
||||
switch ($postID){
|
||||
case 6249:
|
||||
$email = ['vincent.bridier@ldc.fr'];
|
||||
break;
|
||||
}
|
||||
wp_mail($email, "Vous avez un message à traiter sur le site LDC", "$ref");
|
||||
}
|
||||
add_action( 'init', 'taxo_type_message');
|
||||
|
||||
// Ajout de la possibilité d'ordonner la colonne par type
|
||||
function add_message_sortable_columns( $cols ) {
|
||||
$cols[ 'taxonomy-type' ] = 'taxonomy-type';
|
||||
return $cols;
|
||||
function generateRandomString($length = 10) {
|
||||
$characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
$charactersLength = strlen($characters);
|
||||
$randomString = '';
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$randomString .= $characters[rand(0, $charactersLength - 1)];
|
||||
}
|
||||
return $randomString;
|
||||
}
|
||||
add_filter( 'manage_edit-message_sortable_columns', 'add_message_sortable_columns' );
|
||||
|
||||
//Ajout du selecteur permettant de filtrer par type
|
||||
function filter_message_by_taxonomies( $post_type, $which ) {
|
||||
add_action( 'wp_ajax_ContactAjx', 'ContactAjx');
|
||||
add_action( 'wp_ajax_nopriv_ContactAjx', 'ContactAjx');
|
||||
function ContactAjx() {
|
||||
global $wpdb;
|
||||
|
||||
// Apply this only on a specific post type
|
||||
if ( 'message' !== $post_type )
|
||||
return;
|
||||
// TODO : Validation Recaptcha with toekn
|
||||
// TODO : Test variables required
|
||||
//check_ajax_referer( 'ajax-security-nonce', 'security' );
|
||||
|
||||
// A list of taxonomy slugs to filter by
|
||||
$taxonomies = array( 'type');
|
||||
$postID = sanitize_text_field($_POST['id']);
|
||||
$firstname = sanitize_text_field($_POST['firstname']);
|
||||
$lastname = sanitize_text_field($_POST['lastname']);
|
||||
$email = sanitize_email($_POST['email']);
|
||||
$content = "";
|
||||
|
||||
foreach ( $taxonomies as $taxonomy_slug ) {
|
||||
foreach ($_POST as $key => $item){
|
||||
if ($key === 'firstname' || $key === 'lastname' || $key === 'email' || $key === 'action' || $key === 'id' || $key === 'token')
|
||||
continue;
|
||||
|
||||
// Retrieve taxonomy data
|
||||
$taxonomy_obj = get_taxonomy( $taxonomy_slug );
|
||||
$taxonomy_name = $taxonomy_obj->labels->name;
|
||||
if (is_array($item)){
|
||||
$content .= ucfirst($key) . " :\n\r";
|
||||
foreach ($item as $v){
|
||||
$content .= "- $v \n\r";
|
||||
}
|
||||
}else{
|
||||
$content .= ucfirst($key) . " : " . $item . "\n\r";
|
||||
}
|
||||
}
|
||||
|
||||
// Retrieve taxonomy terms
|
||||
$terms = get_terms( $taxonomy_slug );
|
||||
$ref = date('ymd') . '-' . generateRandomString(4);
|
||||
|
||||
// Display filter HTML
|
||||
echo "<select name='{$taxonomy_slug}' id='{$taxonomy_slug}' class='postform'>";
|
||||
echo '<option value="">' . sprintf( esc_html__( 'Montrer tous les types', 'text_domain' ), $taxonomy_name ) . '</option>';
|
||||
foreach ( $terms as $term ) {
|
||||
printf(
|
||||
'<option value="%1$s" %2$s>%3$s (%4$s)</option>',
|
||||
$term->slug,
|
||||
( ( isset( $_GET[$taxonomy_slug] ) && ( $_GET[$taxonomy_slug] == $term->slug ) ) ? ' selected="selected"' : '' ),
|
||||
$term->name,
|
||||
$term->count
|
||||
);
|
||||
}
|
||||
echo '</select>';
|
||||
}
|
||||
$wpdb->insert(
|
||||
'wp_messages',
|
||||
[
|
||||
'ref' => $ref,
|
||||
'firstname' => $firstname,
|
||||
'lastname' => $lastname,
|
||||
'email' => $email,
|
||||
'content' => $content,
|
||||
'status' => 0,
|
||||
'date' => date('Y-m-d H:i:s'),
|
||||
'type_id' => getMessageType($postID)
|
||||
], [
|
||||
'%s',
|
||||
'%s',
|
||||
'%s',
|
||||
'%s',
|
||||
'%s',
|
||||
'%d',
|
||||
'%s',
|
||||
'%d'
|
||||
]
|
||||
);
|
||||
|
||||
sendNotification($postID, $ref);
|
||||
|
||||
die();
|
||||
}
|
||||
add_action( 'restrict_manage_posts', 'filter_message_by_taxonomies' , 10, 2);
|
||||
|
||||
|
||||
// Ajout colonne de réponse
|
||||
function custom_message_columns_title($columns) {
|
||||
$columns['repondre'] = 'Répondre';
|
||||
unset($columns['date']);
|
||||
return $columns;
|
||||
}
|
||||
add_filter('manage_edit-message_columns', 'custom_message_columns_title');
|
||||
|
||||
|
||||
// Ajout contenu dans colonne de réponse
|
||||
function custom_message_columns_content($column) {
|
||||
global $post;
|
||||
switch ($column) {
|
||||
case 'repondre' :
|
||||
echo('<a class="answer-msg" data-id="'.$post->ID.'" style="cursor:pointer;" title="Répondre au message">Répondre au message</a>');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
add_action('manage_message_posts_custom_column', 'custom_message_columns_content');
|
||||
|
||||
|
||||
// Ajout script spécifique sur l'admin message
|
||||
function my_enqueue($hook) {
|
||||
|
|
@ -546,6 +518,33 @@ function my_enqueue($hook) {
|
|||
}
|
||||
add_action('admin_enqueue_scripts', 'my_enqueue');
|
||||
|
||||
add_action( 'wp_ajax_getMsg', 'getMsg' );
|
||||
add_action( 'wp_ajax_nopriv_getMsg', 'getMsg' );
|
||||
|
||||
function getMsg(){
|
||||
global $wpdb;
|
||||
|
||||
$msg_id = $_POST['id'];
|
||||
|
||||
$msg = $wpdb->get_row("SELECT * FROM wp_messages, wp_messages_types WHERE wp_messages.type_id = wp_messages_types.id AND wp_messages.id = $msg_id LIMIT 1", OBJECT);
|
||||
|
||||
if ($msg === NULL)
|
||||
die('<h1>Message inconnu</h1>');
|
||||
|
||||
$html = "<div class='msg-reponse'>";
|
||||
$html .= "<h1>Message du consommateur :</h1>";
|
||||
$html .= "<p><strong>Nom Prénom : </strong>".$msg->lastname." ".$msg->firstname."</p>";
|
||||
$html .= "<p><strong>E-mail : </strong>".$msg->email."</p>";
|
||||
$html .= "<p>".nl2br($msg->content)."</p>";
|
||||
$html .= "<h1>Réponse :</h1>";
|
||||
$html .= "<p>".nl2br($msg->response)."</p>";
|
||||
$html .= "</div>";
|
||||
|
||||
echo($html);
|
||||
|
||||
die();
|
||||
}
|
||||
|
||||
//Ajax pour ouvrir la page de réponse
|
||||
add_action( 'wp_ajax_getReponseForMsg', 'getReponseForMsg' );
|
||||
add_action( 'wp_ajax_nopriv_getReponseForMsg', 'getReponseForMsg' );
|
||||
|
|
@ -553,31 +552,21 @@ add_action( 'wp_ajax_nopriv_getReponseForMsg', 'getReponseForMsg' );
|
|||
function getReponseForMsg(){
|
||||
global $wpdb;
|
||||
|
||||
$postid = $_POST['id'];
|
||||
// TODO : Add civilité
|
||||
$civilite = get_field('field_5e57a09acdacf', $postid);
|
||||
$nom = get_field('field_5e57a087cdacd', $postid);
|
||||
$prenom = get_field('field_5e57a095cdace', $postid);
|
||||
$adresse = get_field('field_5e57a0a9cdad0', $postid);
|
||||
$codepostal = get_field('field_5e57a0afcdad1', $postid);
|
||||
$ville = get_field('field_5e57a0b8cdad2', $postid);
|
||||
$email = get_field('field_5e57a0becdad3', $postid);
|
||||
$telephone = get_field('field_5e57a0c3cdad4', $postid);
|
||||
$message = get_field('field_5e57a0d9cdad5', $postid);
|
||||
$msg_id = $_POST['id'];
|
||||
|
||||
$msg = $wpdb->get_row("SELECT * FROM wp_messages, wp_messages_types WHERE wp_messages.type_id = wp_messages_types.id AND wp_messages.id = $msg_id LIMIT 1", OBJECT);
|
||||
|
||||
if ($msg === NULL)
|
||||
die('<h1>Message inconnu</h1>');
|
||||
|
||||
$html = "<div class='msg-reponse'>";
|
||||
$html .= "<h1>Message du consommateur :</h1>";
|
||||
$html .= "<p><strong>Nom Prénom : </strong>".$nom." ".$prenom."</p>";
|
||||
$html .= "<p><strong>E-mail : </strong>".$email."</p>";
|
||||
$html .= "<p><strong>Adresse : </strong>".$adresse."</p>";
|
||||
$html .= "<p><strong>Code Postal : </strong>".$codepostal."</p>";
|
||||
$html .= "<p><strong>Ville : </strong>".$ville."</p>";
|
||||
$html .= "<p><strong>Téléphone : </strong>".$telephone."</p>";
|
||||
$html .= "<p><strong>Message envoyé : </strong></p>";
|
||||
$html .= "<p>".$message."</p>";
|
||||
$html .= "<p><strong>Nom Prénom : </strong>".$msg->lastname." ".$msg->firstname."</p>";
|
||||
$html .= "<p><strong>E-mail : </strong>".$msg->email."</p>";
|
||||
$html .= "<p>".nl2br($msg->content)."</p>";
|
||||
$html .= "<h1>Votre Réponse :</h1>";
|
||||
$html .= "<input type='hidden' name='email' id='emailTosend' value='".$email."'/>";
|
||||
$html .= "<textarea name='answer'></textarea>";
|
||||
$html .= "<input type='hidden' name='email' id='emailTosend' value='".$msg->email."'/>";
|
||||
$html .= "<textarea name='answer' id='msgTosend'></textarea>";
|
||||
$html .= "<button class='send-answer' id='msgTosend'>Envoyer</button>";
|
||||
$html .= "</div>";
|
||||
|
||||
|
|
@ -586,6 +575,20 @@ function getReponseForMsg(){
|
|||
die();
|
||||
}
|
||||
|
||||
// Function to change email address
|
||||
function wpb_sender_email( $original_email_address ) {
|
||||
return 'nepasrepondre@ldc.fr';
|
||||
}
|
||||
|
||||
// Function to change sender name
|
||||
function wpb_sender_name( $original_email_from ) {
|
||||
return 'Groupe LDC';
|
||||
}
|
||||
|
||||
// Hooking up our functions to WordPress filters
|
||||
add_filter( 'wp_mail_from', 'wpb_sender_email' );
|
||||
add_filter( 'wp_mail_from_name', 'wpb_sender_name' );
|
||||
|
||||
//Ajax d'envoi de la réponse
|
||||
add_action( 'wp_ajax_sendReponse', 'sendReponse' );
|
||||
add_action( 'wp_ajax_nopriv_sendReponse', 'sendReponse' );
|
||||
|
|
@ -595,8 +598,25 @@ function sendReponse(){
|
|||
|
||||
$email = $_POST['email'];
|
||||
$message = $_POST['message'];
|
||||
$msg_id = $_POST['id'];
|
||||
$ref = $_POST['ref'];
|
||||
|
||||
wp_mail($email, "Réponse à votre message sur le site LDC", $message, '');
|
||||
$message = "REF: $ref <br><br>" . nl2br($message);
|
||||
|
||||
wp_mail($email, "Réponse à votre message sur le site LDC", $message);
|
||||
|
||||
$wpdb->update(
|
||||
'wp_messages',
|
||||
[
|
||||
'response' => $message,
|
||||
'response_date' => date('Y-m-d H:i:s'),
|
||||
'status' => 1,
|
||||
], ['id' => $msg_id], [
|
||||
'%s',
|
||||
'%s',
|
||||
'%d',
|
||||
]
|
||||
);
|
||||
|
||||
$html = "<h1>Message Envoyé !</h1>";
|
||||
|
||||
|
|
|
|||
|
|
@ -37,129 +37,6 @@ get_header();
|
|||
</div>
|
||||
<?php endif; ?>
|
||||
<!-- Nous rejoindre en tant qu'éleveur -->
|
||||
<?php if ($post->ID === 6249): ?>
|
||||
<h2 class="contacts-page-subtitle subtitle_paint"><?= the_title(); ?></h2>
|
||||
<div class="contacts-category-page wrapper">
|
||||
<div class="back-button-wrapper">
|
||||
<a href="/nous-contacter/" class="back-button" title="Retour au choix de contact">Retour au choix de contact</a>
|
||||
</div>
|
||||
<div class="contacts-form__wrapper">
|
||||
<form class="form">
|
||||
<div class="form__container">
|
||||
<div class="form-top-text">Vous êtes éleveur de volailles ou souhaitez le devenir, et nous rejoindre ? <br>Décrivez-nous votre projet le plus précisément possible afin que nous puissions orienter votre demande vers l'interlocuteur adéquat.</div>
|
||||
<div class="form__row">
|
||||
<div class="form__field">
|
||||
<div class="form__field-title">Nom *</div>
|
||||
<input type="text" name="lastname" size="40" class="form__input" placeholder="Votre Nom" required>
|
||||
</div>
|
||||
<div class="form__field">
|
||||
<div class="form__field-title">Prénom *</div>
|
||||
<input type="text" name="firstname" size="40" class="form__input" placeholder="Votre Prénom" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form__row">
|
||||
<div class="form__field">
|
||||
<div class="form__field-title">Téléphone *</div>
|
||||
<input type="tel" name="phone" size="20" class="form__input" placeholder="Par exemple, 02 43 62 70 00" required>
|
||||
</div>
|
||||
<div class="form__field">
|
||||
<div class="form__field-title">Adresse Email *</div>
|
||||
<input type="email" name="email" size="40" class="form__input" aria-required="true" aria-invalid="false" placeholder="Prenom.nom@mail.fr" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form__row">
|
||||
<div class="form__field">
|
||||
<div class="form__field-title">Type d'élevage souhaité * <span class="normal">(choix multiple)</span></div>
|
||||
<label class="form__field-pseudolabel">
|
||||
<input type="checkbox" name="types" value="Poulets/dindes/pintades" oninvalid="showError('<?= $post->ID; ?>_types');" required>
|
||||
<span class="form__field-pseudocircle">Poulets/dindes/pintades</span>
|
||||
</label>
|
||||
<label class="form__field-pseudolabel">
|
||||
<input type="checkbox" name="types" value="Canards" required>
|
||||
<span class="form__field-pseudocircle">Canards</span>
|
||||
</label>
|
||||
<label class="form__field-pseudolabel">
|
||||
<input type="checkbox" name="types" value="Poules pondeuses" required>
|
||||
<span class="form__field-pseudocircle">Poules pondeuses</span>
|
||||
</label>
|
||||
<label class="form__field-pseudolabel">
|
||||
<input type="checkbox" name="types" value="Autres" required>
|
||||
<span class="form__field-pseudocircle">Autres</span>
|
||||
</label>
|
||||
<div class="form__error" id="<?= $post->ID; ?>_types" style="display: none;">Ce champs est obligatoire</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form__row">
|
||||
<div class="form__field">
|
||||
<div class="form__field-title">Zone géographique de votre projet *</div>
|
||||
<div class="geographic-checkboxes-block">
|
||||
<div class="geographic-checkboxes-result form__input"><span class="zones-wrapper">Liste déroulante de départements</span></div>
|
||||
<div class="geographic-checkboxes-list">
|
||||
<?php $dps = ["Ain","Aisne","Allier","Alpes-de-Haute-Provence","Alpes-Maritimes","Ardèche","Ardennes","Ariège","Aube","Aude","Aveyron","Bas-Rhin","Bouches-du-Rhône","Calvados","Cantal","Charente","Charente-Maritime","Cher","Corrèze","Corse-du-Sud","Côte-d'Or","Côtes-d'Armor","Creuse","Deux-Sèvres","Dordogne","Doubs","Drôme","Essonne","Eure","Eure-et-Loir","Finistère","Gard","Gers","Gironde","Guadeloupe","Guyane","Haut-Rhin","Haute-Corse","Haute-Garonne","Haute-Loire","Haute-Marne","Haute-Saône","Haute-Savoie","Haute-Vienne","Hautes-Alpes","Hautes-Pyrénées","Hauts-de-Seine","Hérault","Ille-et-Vilaine","Indre","Indre-et-Loire","Isère","Jura","La,Réunion","Landes","Loir-et-Cher","Loire","Loire-Atlantique","Loiret","Lot","Lot-et-Garonne","Lozère","Lyon,Metropolis","Maine-et-Loire","Manche","Marne","Martinique","Mayenne","Mayotte","Meurthe-et-Moselle","Meuse","Morbihan","Moselle","Nièvre","Nord","Oise","Orne","Paris","Pas-de-Calais","Puy-de-Dôme","Pyrénées-Atlantiques","Pyrénées-Orientales","Rhône","Saône-et-Loire","Sarthe","Savoie","Seine-Maritime","Seine-et-Marne","Seine-Saint-Denis","Somme","Tarn","Tarn-et-Garonne","Territoire,de,Belfort","Var","Val-d'Oise","Val-de-Marne","Vaucluse","Vendée","Vienne","Vosges","Yonne","Yvelines"]; ?>
|
||||
<?php foreach ($dps as $dp): ?>
|
||||
<label class="form__field-pseudolabel">
|
||||
<input type="checkbox" name="geo" value="<?= $dp; ?>" required>
|
||||
<span class="form__field-pseudosquare"><?= $dp; ?></span>
|
||||
</label>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form__container">
|
||||
<div class="form__field-title">Votre projet *</div>
|
||||
|
||||
<div class="form__field">
|
||||
<textarea name="Message" cols="40" rows="10" class="form__input" placeholder="Détailler ici votre projet et votre demande" required></textarea>
|
||||
</div>
|
||||
|
||||
<div class="form__row">
|
||||
<div class="form__field">
|
||||
<label class="form__field-pseudolabel">
|
||||
<input type="checkbox" name="agree" value="Poulets/dindes/pintades">
|
||||
<span class="form__field-pseudosquare">J’accepte les conditions d’utilisation</span>
|
||||
</label>
|
||||
<label class="form__field-pseudolabel">
|
||||
<input type="checkbox" name="news" value="Poulets/dindes/pintades">
|
||||
<span class="form__field-pseudosquare">Je souhaite m’inscrire à la newsletter</span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="form__field"><div class="form__tip">* Champs obligatoires</div></div>
|
||||
</div>
|
||||
|
||||
<div class="form__row">
|
||||
<div class="form__field">[recaptcha]</div>
|
||||
</div>
|
||||
|
||||
<div class="form__response">Un ou plusieurs champs contiennent une erreur. Veuillez vérifier et essayer à nouveau.</div>
|
||||
|
||||
<div class="form__row">
|
||||
<div class="form-submit">
|
||||
<input type="submit" value="Envoyer" class="form-submit__btn btn">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if ($post->ID === 6249) : require_once('contacts/6249_eleveurs.php'); endif ?>
|
||||
</div>
|
||||
<script>
|
||||
$('.form').on('submit', function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
let types = $('input[name=types]:checked').map(function(_, el) {
|
||||
return $(el).val();
|
||||
}).get();
|
||||
|
||||
$(this).unbind('submit').submit();
|
||||
});
|
||||
function showError(id) {
|
||||
$("#" + id).show();
|
||||
}
|
||||
</script>
|
||||
<?php get_footer(); ?>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue