fix contact bug (tk 349)
This commit is contained in:
parent
34c2544d3f
commit
407158963e
1 changed files with 63 additions and 46 deletions
|
|
@ -22,8 +22,13 @@ function getPostContactInfo($postID)
|
|||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
function getPostContacts($postID)
|
||||
/**
|
||||
* Recupere les email de contact pour un post donné
|
||||
*
|
||||
* @param int $postID
|
||||
* @return array
|
||||
*/
|
||||
function getPostContacts($postID): array
|
||||
{
|
||||
$contactInfo = getPostContactInfo($postID);
|
||||
return $contactInfo['contacts'] ?? [];
|
||||
|
|
@ -35,24 +40,27 @@ function plugin_menu()
|
|||
add_menu_page('LDC Messages', 'LDC Messages', LDC_MESSAGE_CAP, 'ldc-messages', 'init', 'dashicons-email-alt', 30);
|
||||
}
|
||||
|
||||
function ldc_messages() {
|
||||
wp_register_style('ldc_messages', plugins_url('style.css',__FILE__ ));
|
||||
function ldc_messages()
|
||||
{
|
||||
wp_register_style('ldc_messages', plugins_url('style.css', __FILE__));
|
||||
wp_enqueue_style('ldc_messages');
|
||||
}
|
||||
add_action('admin_init','ldc_messages');
|
||||
add_action('admin_init', 'ldc_messages');
|
||||
|
||||
function my_admin_scripts() {
|
||||
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');
|
||||
function my_admin_scripts()
|
||||
{
|
||||
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);
|
||||
wp_enqueue_script('ldc_messages', plugins_url('script.js', __FILE__), array('jquery'), '1.0.0', false);
|
||||
}
|
||||
add_action( 'admin_enqueue_scripts', 'my_admin_scripts' );
|
||||
add_action('admin_enqueue_scripts', 'my_admin_scripts');
|
||||
|
||||
add_action( 'wp_ajax_getMsg', 'getMsg' );
|
||||
add_action( 'wp_ajax_nopriv_getMsg', 'getMsg' );
|
||||
add_action('wp_ajax_getMsg', 'getMsg');
|
||||
add_action('wp_ajax_nopriv_getMsg', 'getMsg');
|
||||
|
||||
function getMsg(){
|
||||
function getMsg()
|
||||
{
|
||||
global $wpdb;
|
||||
|
||||
$msg_id = $_POST['id'];
|
||||
|
|
@ -68,10 +76,11 @@ function getMsg(){
|
|||
}
|
||||
|
||||
//Ajax pour ouvrir la page de réponse
|
||||
add_action( 'wp_ajax_getReponseForMsg', 'getReponseForMsg' );
|
||||
add_action( 'wp_ajax_nopriv_getReponseForMsg', 'getReponseForMsg' );
|
||||
add_action('wp_ajax_getReponseForMsg', 'getReponseForMsg');
|
||||
add_action('wp_ajax_nopriv_getReponseForMsg', 'getReponseForMsg');
|
||||
|
||||
function getReponseForMsg(){
|
||||
function getReponseForMsg()
|
||||
{
|
||||
global $wpdb;
|
||||
|
||||
$msg_id = $_POST['id'];
|
||||
|
|
@ -87,10 +96,11 @@ function getReponseForMsg(){
|
|||
}
|
||||
|
||||
//Ajax d'envoi de la réponse
|
||||
add_action( 'wp_ajax_sendReponse', 'sendReponse' );
|
||||
add_action( 'wp_ajax_nopriv_sendReponse', 'sendReponse' );
|
||||
add_action('wp_ajax_sendReponse', 'sendReponse');
|
||||
add_action('wp_ajax_nopriv_sendReponse', 'sendReponse');
|
||||
|
||||
function sendReponse(){
|
||||
function sendReponse()
|
||||
{
|
||||
global $wpdb;
|
||||
|
||||
$email = $_POST['email'];
|
||||
|
|
@ -108,7 +118,9 @@ function sendReponse(){
|
|||
'response' => $message,
|
||||
'response_date' => date('Y-m-d H:i:s'),
|
||||
'status' => 1,
|
||||
], ['id' => $msg_id], [
|
||||
],
|
||||
['id' => $msg_id],
|
||||
[
|
||||
'%s',
|
||||
'%s',
|
||||
'%d',
|
||||
|
|
@ -117,7 +129,7 @@ function sendReponse(){
|
|||
|
||||
$html = "<h1>Message Envoyé !</h1>";
|
||||
|
||||
echo($html);
|
||||
echo ($html);
|
||||
|
||||
die();
|
||||
}
|
||||
|
|
@ -156,7 +168,8 @@ function downloadMsg()
|
|||
exit;
|
||||
}
|
||||
|
||||
function generateRandomString($length = 10) {
|
||||
function generateRandomString($length = 10)
|
||||
{
|
||||
$characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
$charactersLength = strlen($characters);
|
||||
$randomString = '';
|
||||
|
|
@ -166,14 +179,15 @@ function generateRandomString($length = 10) {
|
|||
return $randomString;
|
||||
}
|
||||
|
||||
add_action( 'wp_ajax_ContactAjx', 'ContactAjx');
|
||||
add_action( 'wp_ajax_nopriv_ContactAjx', 'ContactAjx');
|
||||
add_action('wp_ajax_ContactAjx', 'ContactAjx');
|
||||
add_action('wp_ajax_nopriv_ContactAjx', 'ContactAjx');
|
||||
|
||||
function ContactAjx() {
|
||||
function ContactAjx()
|
||||
{
|
||||
global $wpdb;
|
||||
|
||||
if (!isset($_POST['id']) || empty($_POST['id']) || !isset($_POST['firstname']) || empty($_POST['firstname']) || !isset($_POST['lastname']) || empty($_POST['lastname']) || !isset($_POST['email']) || empty($_POST['email'])){
|
||||
$error = new WP_Error( '001', 'Check Failure', 'Required values');
|
||||
if (!isset($_POST['id']) || empty($_POST['id']) || !isset($_POST['firstname']) || empty($_POST['firstname']) || !isset($_POST['lastname']) || empty($_POST['lastname']) || !isset($_POST['email']) || empty($_POST['email'])) {
|
||||
$error = new WP_Error('001', 'Check Failure', 'Required values');
|
||||
wp_send_json_error($error, 500);
|
||||
die();
|
||||
}
|
||||
|
|
@ -232,7 +246,8 @@ function ContactAjx() {
|
|||
'status' => 0,
|
||||
'date' => date('Y-m-d H:i:s'),
|
||||
'type_id' => getPostContactInfo($postID)['MessageTypeID']
|
||||
], [
|
||||
],
|
||||
[
|
||||
'%s',
|
||||
'%s',
|
||||
'%s',
|
||||
|
|
@ -246,7 +261,7 @@ function ContactAjx() {
|
|||
|
||||
$mInfo = getPostContactInfo($postID);
|
||||
|
||||
$email = getPostContacts($postID);
|
||||
$dest_emails = getPostContacts($postID);
|
||||
$title = "Vous avez un message à traiter sur le site LDC";
|
||||
$content = genMailString($title, nl2br(sprintf(
|
||||
"<p>%s : %s %s \n E-mail : %s \n %s \n %s</p>",
|
||||
|
|
@ -257,9 +272,9 @@ function ContactAjx() {
|
|||
$mInfo['MessageLabel'] ?? '',
|
||||
$content
|
||||
)));
|
||||
wp_mail($email, $title, $content, ['Content-Type: text/html; charset=UTF-8']);
|
||||
wp_mail($dest_emails, $title, $content, ['Content-Type: text/html; charset=UTF-8']);
|
||||
} else {
|
||||
$error = new WP_Error( '002', 'Check Failure', 'Recaptcha');
|
||||
$error = new WP_Error('002', 'Check Failure', 'Recaptcha');
|
||||
wp_send_json_error($error, 500);
|
||||
}
|
||||
die();
|
||||
|
|
@ -271,18 +286,20 @@ function genMailString(string $title, string $message)
|
|||
}
|
||||
|
||||
// Function to change email address
|
||||
function wpb_sender_email( $original_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 ) {
|
||||
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' );
|
||||
add_filter('wp_mail_from', 'wpb_sender_email');
|
||||
add_filter('wp_mail_from_name', 'wpb_sender_name');
|
||||
|
||||
function renderMessage($msg, $isPdf = false)
|
||||
{
|
||||
|
|
@ -369,8 +386,8 @@ function getMessages($page, $limit = 8, $search = false, $status = null)
|
|||
$offset = ($page * $limit) - $limit;
|
||||
|
||||
$query = 'wp_messages.id AS msg_id' .
|
||||
' FROM wp_messages, wp_messages_types' .
|
||||
' WHERE wp_messages.type_id = wp_messages_types.id';
|
||||
' FROM wp_messages, wp_messages_types' .
|
||||
' WHERE wp_messages.type_id = wp_messages_types.id';
|
||||
|
||||
if ($search !== false) {
|
||||
|
||||
|
|
@ -494,11 +511,11 @@ function init()
|
|||
|
||||
$page .= "<td style='font-weight: bold;'>$message->ref</td>";
|
||||
|
||||
$page .= "<td>". date('d/m/Y H:i', strtotime($message->date)) ."</td>";
|
||||
$page .= "<td>" . date('d/m/Y H:i', strtotime($message->date)) . "</td>";
|
||||
|
||||
if ($message->status === '0'){
|
||||
if ($message->status === '0') {
|
||||
$page .= "<td><p class='ldc_messages_red'>À traiter</p></td>";
|
||||
}else{
|
||||
} else {
|
||||
$page .= "<td><p class='ldc_messages_green'>Traité</p></td>";
|
||||
}
|
||||
|
||||
|
|
@ -507,24 +524,24 @@ function init()
|
|||
$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>";
|
||||
if ($message->response_date !== NULL) {
|
||||
$page .= "<td>" . date('d/m/Y H:i', strtotime($message->response_date)) . "</td>";
|
||||
} elseif ($message->status) {
|
||||
$page .= "<td>Marqué comme traité</td>";
|
||||
} else {
|
||||
$page .= "<td>-</td>";
|
||||
}
|
||||
|
||||
if ($message->status === '0'){
|
||||
if ($message->status === '0') {
|
||||
$page .= "<td>";
|
||||
$page .= "<a href='#' class='answer-msg' data-id='$message->msg_id' data-ref='$message->ref'>Répondre</a><br>";
|
||||
$page .= "<a href='#' class='mark-msg' data-id='$message->msg_id' data-ref='$message->ref'>Marquer comme traité</a><br>";
|
||||
$page .= "<a href='".admin_url( 'admin-ajax.php' )."?action=downloadMsg&id=$message->msg_id'>Télécharger en PDF</a>";
|
||||
$page .= "<a href='" . admin_url('admin-ajax.php') . "?action=downloadMsg&id=$message->msg_id'>Télécharger en PDF</a>";
|
||||
$page .= "</td>";
|
||||
}else{
|
||||
} else {
|
||||
$page .= "<td>";
|
||||
$page .= "<a href='#' class='show-msg' data-id='$message->msg_id'>Afficher</a><br>";
|
||||
$page .= "<a href='".admin_url( 'admin-ajax.php' )."?action=downloadMsg&id=$message->msg_id'>Télécharger en PDF</a>";
|
||||
$page .= "<a href='" . admin_url('admin-ajax.php') . "?action=downloadMsg&id=$message->msg_id'>Télécharger en PDF</a>";
|
||||
$page .= "</td>";
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue