Skip to content

#82 checkbox has been added to send invitation to multiple guests #83

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 65 additions & 1 deletion event-and-guest-management.php
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,71 @@ function send_message(){
add_action('wp_ajax_send_message', 'send_message');
add_action('wp_ajax_nopriv_send_message', 'send_message');



function send_email_to_all(){
if(isset($_POST['event_id'])&&isset($_POST['guest_array'])){
$guest_array=stripslashes($_POST['guest_array']);
$event_id=$_POST['event_id'];
$subject=stripslashes($_POST['subject']);
$ebody=nl2br(stripslashes($_POST['body']));
$myArray = explode(',', $guest_array);
foreach($myArray as $guest_id){
global $wpdb;
$table_name_event_guest = $wpdb->prefix . 'event_guest';
$check_guest_id = $wpdb->get_results("SELECT * FROM $table_name_event_guest WHERE guest_id = $guest_id AND event_id = $event_id ");
if($wpdb->num_rows > 0) {
echo'<div class="alert alert-danger alert-dismissable">
<a href="#" class="close" data-dismiss="alert" aria-label="close">&times;
</a>
<strong>Sorry!</strong> Invitation Mail has been Already sent to this guest.
</div>';
}
else
{
$table_name_events = $wpdb->prefix . 'events';
$table_name_guests = $wpdb->prefix . 'guests';
$table_name_event_guest = $wpdb->prefix . 'event_guest';

$thepost = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $table_name_guests where guest_id = $guest_id"));
$guest_name = $thepost->guest_name;
$guest_email = $thepost->guest_email;

$emailTo = $guest_email;
$subject = $subject;
$body = 'Hi '.$guest_name.',
<br><br>
<font style="font-family:Tahoma;">'.$ebody.'</font>';
$headers = array('Content-Type: text/html; charset=UTF-8');
if(wp_mail($emailTo, $subject, $body, $headers)){
echo '
<div class="alert alert-success alert-dismissable">
<a href="#" class="close" data-dismiss="alert" aria-label="close">&times;
</a>
<strong>Successfull!</strong> Invitation Mail has been sent to <strong> '.$guest_name.' </strong>.
</div>
';
$table_name = $wpdb->prefix . 'event_guest';
$wpdb->insert( $table_name, array(
'event_id' => $event_id,
'guest_id' => $guest_id,
'email_status' => 'send',
'guest_status' => 'pending',
));
}
else
{
echo "
<div class='alert alert-warning'>Mail function Error!</div>
";
}
}
}
}
wp_die();
}

add_action('wp_ajax_send_email_to_all', 'send_email_to_all');
add_action('wp_ajax_nopriv_send_email_to_all', 'send_email_to_all');

add_filter( 'wp_mail_content_type', 'set_content_type' );
function set_content_type( $content_type ) {
Expand Down
4 changes: 4 additions & 0 deletions send_invitation.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<div class="overlay" id="loading_process"></div>
<div class="heading">Send Invitation</div>
<div class="container-fluid">
<div class="alert alert-danger alert-dismissable hide-message" id="error_message">
<button type="button" class="btn btn-outline-danger btn-sm pull-right hide">&times;</button>
<strong> Please! </strong> Select atleast one guest.
</div>
<div id="show_fetch_select_events"></div>
<hr>
<div id="email_test_result"></div>
Expand Down
4 changes: 4 additions & 0 deletions src/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,9 @@ th, td {
background-color: grey;
}

.hide-message{
display: none;
}

.hover-background:hover{background-color:#f5f5f5}

42 changes: 42 additions & 0 deletions src/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ jQuery(document).ready(function($) {
$(document).on("click",'.hide',function(){
$("#edit_event_form").hide();
$("#edit_guest_form").hide();
$("#error_message").hide();
});

$(document).on("click",'.update-event',function(){
Expand Down Expand Up @@ -280,4 +281,45 @@ jQuery(document).ready(function($) {
}
});
}

$(document).on("click",'.send-to-selected',function(){
var event_id=$(this).attr('id');
var guest_chk_array = [];

$(".guest-checkbox:checked").each(function() {
guest_chk_array.push($(this).val());
});

if(guest_chk_array.length===0){
$('#error_message').show();
}
else
{
$('#loading_process').show();
var guest_array = guest_chk_array.join(', ');


var perform_action ="action=send_email_to_all&guest_array="+guest_array+"&event_id="+event_id+"&"+$('#email_form').serialize();
$.ajax({
type:'POST',
url:PARAMS.ajaxurl,
data:perform_action,
success:function(result){
fetch_all_guest_invitation(event_id);
$("#successfull_send_message").html(result);
$('#loading_process').hide();
}
});
}
});

$(document).on("click",'#check_all_guest',function() {
$(".guest-checkbox").prop('checked', $(this).prop('checked'));
});

$(".guest-checkbox").change(function(){
if (!$(this).prop("checked")){
$("#check_all_guest").prop("checked",false);
}
});
});
7 changes: 5 additions & 2 deletions template/email-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@

See You in the event.
';
?>
<button type="button" class="btn btn-success btn-sm email">Email Template</button>
?>
<div class="container-fluid">
<button type="button" class="btn btn-success btn-sm email">Email Template</button>&nbsp;&nbsp;
<button type="button" class="btn btn-primary btn-sm send-to-selected" id="<?php echo $event_id ?>">Send to selected</button>
</div>
<hr>
<div id="email-temp" style="display:none;">
<div class="alert alert-success">
Expand Down
5 changes: 3 additions & 2 deletions template/send-invitation-table.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<table class="header-table">
<thead>
<tr>
<th>S.No</th>
<th><input type="checkbox" id="check_all_guest">S.No</th>
<th>Name</th>
<th>Email</th>
<th>Gender</th>
Expand All @@ -20,7 +20,8 @@
<table>
<thead>
<tr class="hover-background">
<th><?php echo $serial_number++ ?></th>
<th><input type="checkbox" value="<?php echo $guest_id ?>" class="guest-checkbox checkBoxClass chk">
<?php echo $serial_number++ ?></th>
<th><?php echo $guest_name ?></th>
<th><?php echo $guest_email ?></th>
<th><?php echo $guest_gender ?></th>
Expand Down