| Server IP : 104.21.21.239 / Your IP : 216.73.216.25 Web Server : Apache/2.4.68 (Amazon Linux) OpenSSL/3.5.5 System : Linux ip-172-31-69-123.ec2.internal 6.1.176-223.369.amzn2023.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Jul 24 13:34:27 UTC 2026 x86_64 User : ec2-user ( 1000) PHP Version : 8.4.23 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/hotel-dev/public_html/mod/ |
Upload File : |
<?php include('_mod_security.php'); ?>
<?php
$ar_rsvp_status = ['rsvp', 'attended', 'conf', 'cancel', 'wait'];
switch ($_GET['func']) :
case 'load_email_guests' :
//var_dump($_GET);
$event_id = nz($_GET['event_id'], '0');
$venue = nz($_GET['venue'], '0');
if ($venue != '1' && $venue != '2') :
echo 'Venue invalid!';
return;
endif;
if (!in_array($_GET['rsvp_status'], $ar_rsvp_status)) :
echo 'RSVP Status invalid!';
return;
endif;
$rsvp_status = $_GET['rsvp_status'];
$sql_concierges = "SELECT DISTINCT c.concierge_id AS id, c.first_name, c.last_name, 'concierge' AS guest_type, h.hotel_name AS org FROM concierges c ".
"INNER JOIN events_concierges ec ON (c.concierge_id = ec.concierge_id) ".
"INNER JOIN hotels h ON (c.hotel_id = h.hotel_id) ".
"WHERE ec.event_id = " . $event_id . " AND ec." . $rsvp_status . "_" . $venue . " = 1 AND c.status = 1 ".
"AND (c.primary_email > ' ' OR c.secondary_email > ' ') ORDER BY c.first_name, c.last_name, h.hotel_name";
$sql_guests = "SELECT DISTINCT g.guest_id AS id, g.first_name, g.last_name, 'guest' AS guest_type, g.company AS org FROM guests g ".
"INNER JOIN events_guests eg ON (g.guest_id = eg.guest_id) ".
"WHERE eg.event_id = " . $event_id . " AND eg." . $rsvp_status . "_" . $venue . " = 1 AND g.active = 1 ".
"AND g.email > ' ' ORDER BY g.first_name, g.last_name, g.company";
if ($_GET['guest_type'] == 'concierges') :
$sql = $sql_concierges;
elseif ($_GET['guest_type'] == 'guests') :
$sql = $sql_guests;
elseif ($_GET['guest_type'] == 'both') :
$sql = '(' . $sql_concierges . ') UNION (' . $sql_guests . ')';
else :
echo 'Email Type invalid!';
return;
endif;
//echo $sql.'=====';
$result = $db->query($sql) or die('Database Error!');
if ($result->rowCount() > 0) :
$ar_guest_sel = [];
while ($row = $result->fetch(PDO::FETCH_OBJ)) :
$guest_text = $row->first_name . ' ' . $row->last_name . ' - ' . $row->org . ' - ' . $row->guest_type;
$ar_guest_sel[$row->id . '-' . $row->guest_type] = $guest_text;
endwhile;
form_field(['fname'=>'email_specific_id_list', 'ftype'=>'checkgroup', 'fsize'=>10, 'frequired'=>false, 'fdbname'=>'', 'ar_group'=>$ar_guest_sel, 'flabel'=>'Specific Recipient Selection', 'fstyle'=>'max-height: 300px; overflow-y: auto;']);
else :
echo 'No data for selection!';
endif;
break;
case 'get_job_status' :
if (isset($_SESSION['batch_email']) && $_SESSION['batch_email']['processing'] === true) :
echo json_encode([
'status' => 'inprogress',
'current_rec' => $_SESSION['batch_email']['current_rec'],
'total_recs' => $_SESSION['batch_email']['total_recs'],
'html' => $_SESSION['batch_email']['html'],
]);
elseif (isset($_SESSION['batch_email']) && $_SESSION['batch_email']['cancel'] === true) :
echo json_encode([
'status' => 'cancel',
'current_rec' => $_SESSION['batch_email']['current_rec'],
'total_recs' => $_SESSION['batch_email']['total_recs'],
'html' => $_SESSION['batch_email']['html'],
]);
unset($_SESSION['batch_email']);
else :
echo json_encode([
'status' => 'completed',
'current_rec' => $_SESSION['batch_email']['current_rec'],
'total_recs' => $_SESSION['batch_email']['total_recs'],
'html' => $_SESSION['batch_email']['html'],
]);
unset($_SESSION['batch_email']);
endif;
//var_dump($_GET);
break;
case 'cancel_job' :
if (isset($_SESSION['batch_email']) && $_SESSION['batch_email']['processing'] === true) :
$_SESSION['batch_email']['cancel'] = true;
$_SESSION['batch_email']['processing'] = false;
endif;
break;
case 'send_email' :
$event_id = nz($_POST['event_id'], '0');
$survey_id = nz($_POST['survey_id'], '0');
$batch_type = $_GET['batch_type'];
$venue = nz($_POST['venue'], '0');
if ($venue != '1' && $venue != '2') :
echo 'Venue invalid!';
return;
endif;
if (!in_array($_POST['rsvp_status'], $ar_rsvp_status)) :
echo 'RSVP Status invalid!';
return;
endif;
$rsvp_status = $_POST['rsvp_status'];
$id_list_concierges = '';
$id_list_guests = '';
$ar_id_list_concierges = [];
$ar_id_list_guests = [];
$nonresponder_join_concierge = '';
$nonresponder_join_guest = '';
if ($_POST['email_selection'] == 'specific') :
foreach ($_POST['email_specific_id_list'] as $value) :
$ar_id = explode('-', $value);
if ($ar_id[1] == 'concierge') :
$ar_id_list_concierges[] = $ar_id[0];
elseif ($ar_id[1] == 'guest') :
$ar_id_list_guests[] = $ar_id[0];
endif;
endforeach;
$id_list_concierges = implode(',', $ar_id_list_concierges);
if (empty($id_list_concierges)) :
$id_list_concierges = '0';
endif;
$id_list_guests = implode(',', $ar_id_list_guests);
if (empty($id_list_guests)) :
$id_list_guests = '0';
endif;
$id_list_concierges = ' AND c.concierge_id IN ('.$id_list_concierges.') ';
$id_list_guests = ' AND g.guest_id IN ('.$id_list_guests.') ';
endif;
if ($_POST['email_selection'] == 'nonresponders') :
$nonresponder_join_concierge = " LEFT JOIN surveys_responders sr ON (sr.concierge_id = c.concierge_id AND sr.survey_id = {$survey_id}) ";
$nonresponder_where_concierge = " AND sr.responded_date IS NULL ";
$nonresponder_join_guest = " LEFT JOIN surveys_responders sr ON (sr.guest_id = g.guest_id AND sr.survey_id = {$survey_id}) ";
$nonresponder_where_guest = " AND sr.responded_date IS NULL ";
endif;
$sql_concierges = "SELECT DISTINCT c.concierge_id AS id, c.first_name, c.last_name, h.hotel_name AS org, 'concierge' AS guest_type, ".
"e.event_name, e.event_date_time, e.venue_1_address, ".
" (CASE WHEN c.primary_email > ' ' THEN c.primary_email ELSE c.secondary_email END) AS email FROM concierges c ".
"INNER JOIN events_concierges ec ON (c.concierge_id = ec.concierge_id) ".
"INNER JOIN events e ON (e.event_id = ec.event_id) ".
"INNER JOIN hotels h ON (c.hotel_id = h.hotel_id) ".
$nonresponder_join_concierge .
"WHERE ec.event_id = " . $event_id . " AND ec." . $rsvp_status . "_" . $venue . " = 1 AND c.status = 1 ".
"AND (c.primary_email > ' ' OR c.secondary_email > ' ') ".$id_list_concierges.$nonresponder_where_concierge." ORDER BY c.first_name, c.last_name, h.hotel_name";
$sql_guests = "SELECT DISTINCT g.guest_id AS id, g.first_name, g.last_name, g.company AS org, 'guest' AS guest_type, ".
"e.event_name, e.event_date_time, e.venue_1_address, g.email FROM guests g ".
"INNER JOIN events_guests eg ON (g.guest_id = eg.guest_id) ".
"INNER JOIN events e ON (e.event_id = eg.event_id) ".
$nonresponder_join_guest .
"WHERE eg.event_id = " . $event_id . " AND eg." . $rsvp_status . "_" . $venue . " = 1 AND g.active = 1 ".
"AND g.email > ' ' ".$id_list_guests.$nonresponder_where_guest." ORDER BY g.first_name, g.last_name, g.company";
if ($_POST['guest_type'] == 'concierges') :
$sql = $sql_concierges;
elseif ($_POST['guest_type'] == 'guests') :
$sql = $sql_guests;
elseif ($_POST['guest_type'] == 'both') :
$sql = '(' . $sql_concierges . ') UNION (' . $sql_guests . ')';
else :
echo 'Email Type invalid!';
return;
endif;
$result = $db->query($sql);
$row_count = $result->rowCount();
$count = 0;
$count_ok = 0;
$count_err = 0;
$html = '';
if ($row_count > 0) :
if ($_GET['action'] == 'send') :
$_SESSION['batch_email'] = [];
$_SESSION['batch_email']['processing'] = true;
$_SESSION['batch_email']['total_recs'] = $row_count;
set_time_limit(900);
elseif ($_GET['action'] == 'preview') :
$html .= '<p>'.$row_count.' emails selected for processing.</p>';
$html .= '<hr style="color:#262626; background-color:#262626; height:3px;" />';
endif;
$i = 0;
$ar_placeholders = [];
while ($i < $result->columnCount()) :
$meta = $result->getColumnMeta($i);
if ($meta) :
$ar_placeholders[] = strtolower($meta['name']);
endif;
$i++;
endwhile;
$ar_placeholders[] = 'ical_link';
$ar_placeholders[] = 'event_date';
$ar_placeholders[] = 'event_time';
$ar_placeholders[] = 'survey_link';
$ar_placeholders[] = '/survey_link';
while ($row = $result->fetch(PDO::FETCH_OBJ)) :
$count++;
$email_body = $_POST['batch_email_html'];
$email_subject = $_POST['batch_email_subject'];
$hash_key = '';
if ($batch_type == 'survey' && !empty($survey_id)) :
$hash_key = hash('sha512', $row->guest_type . $row->id . $event_id . $survey_id);
endif;
foreach ($ar_placeholders as $key) :
switch ($key) :
case 'ical_link' :
$start_date = date_create($row->event_date_time);
$end_date = date_create($row->event_date_time);
date_add($end_date, date_interval_create_from_date_string('3 hours'));
$start_date->setTimezone(new DateTimeZone('UTC'));
$end_date->setTimezone(new DateTimeZone('UTC'));
$event_duration = '0300';
$event_name = $row->event_name;
$event_desc = $row->event_name . ' - ' . $row->event_venue_1 . ' - ' .$row->event_venue_2;
$event_location = $row->venue_1_address;
$value = '<b>Add to calendar:</b><br>';
$value .= '<a target="_blank" href="https://www.google.com/calendar/render?action=TEMPLATE'.
'&text='.urlencode($event_name).
'&dates='.$start_date->format('Ymd\THis\Z').'/'.$end_date->format('Ymd\THis\Z').
'&details='.urlencode($event_desc).
'&location='.urlencode($event_location).
'&sprop=&sprop=name:">Add to Google Calendar</a><br>';
$value .= '<a target="_blank" href="http://calendar.yahoo.com/?v=60&view=d&type=20'.
'&title='.urlencode($event_name).
'&st='.$start_date->format('Ymd\THis\Z').'&dur='.$event_duration.
'&desc='.urlencode($event_desc).
'&in_loc='.urlencode($event_location).
'">Add to Yahoo Calendar</a><br>';
$value .= '<a href="'.APP_BASE_SECURE.'ajax.php?call=_file_download&event_id='.$event_id.'&type=batch_email_ical">Add to Outlook Calendar</a><br>';
$value .= '<a href="'.APP_BASE_SECURE.'ajax.php?call=_file_download&event_id='.$event_id.'&type=batch_email_ical">Add to iCal Calendar</a><br>';
break;
case 'event_date' :
$value = nzdate_display($row->event_date_time);
break;
case 'event_time' :
$value = nztime_display($row->event_date_time);
break;
case 'survey_link' :
$value = '<a href="'.APP_BASE_SECURE.'survey.php?key='.$hash_key.'">';
break;
case '/survey_link' :
$value = '</a>';
break;
default :
$value = $row->{$key};
endswitch;
$email_body = str_replace('['.$key.']', $value, $email_body);
//$email_body = str_replace('['.$key.']', htmlentities($value), $email_body);
//$email_subject = str_replace('['.$key.']', htmlentities($value), $email_subject);
endforeach;
if ($batch_type == 'survey') :
if (empty(lookup_db_field('surveys_responders', 'hash_key', $hash_key, 'hash_key'))) :
$sql = "
INSERT INTO surveys_responders
SET
survey_id = {$survey_id}
,responder_type = " . $db->quote($row->guest_type) . "
,concierge_id = " . ($row->guest_type == 'concierge' ? $row->id : 'NULL') . "
,guest_id = " . ($row->guest_type == 'guest' ? $row->id : 'NULL') . "
,hash_key = " . $db->quote($hash_key) . "
";
$db->query($sql) or die('Database Error!');
endif;
endif;
if ($_GET['action'] == 'preview') :
$html .= '<p>';
$html .= '<b>FROM:</b> '.$_POST['batch_email_reply_name'].' <'.$_POST['batch_email_reply_address'].'><br />';
$html .= '<b>TO:</b> '.$row->email.'<br />';
$html .= '<b>CC:</b> '.$_POST['batch_email_cc'].'<br />';
$html .= '<b>BCC:</b> '.$_POST['batch_email_bcc'].'<br />';
$html .= '<b>SUBJECT:</b> '.$email_subject.'<br />';
if (!empty($_POST['batch_email_attachment_1_filename'])) :
$html .= '<b>ATTACHMENT 1:</b> <a href="ajax.php?call=_file_download&event_id='.$event_id.'&type=batch_email_attachment&ordinal=1" >'.$_POST['batch_email_attachment_1_filename'].'</a><br />';
endif;
if (!empty($_POST['batch_email_attachment_2_filename'])) :
$html .= '<b>ATTACHMENT 2:</b> <a href="ajax.php?call=_file_download&event_id='.$event_id.'&type=batch_email_attachment&ordinal=2" >'.$_POST['batch_email_attachment_2_filename'].'</a><br />';
endif;
$html .= '</p>';
$html .= '<p style="font-family:Arial, Helvetica, sans-serif; font-size:14px;">';
$html .= $email_body;
$html .= '</p>';
$html .= '<hr style="color:#262626; background-color:#262626; height:3px;" />';
elseif ($_GET['action'] == 'send') :
$attachments = [];
$uploaddir = APP_UPLOAD_DIR.'/eventdocs/batch_email_attachments/'.str_pad($event_id, 10, '0', STR_PAD_LEFT);
if (!empty($_POST['batch_email_attachment_1_filename'])) :
$attachments[] = $uploaddir . '/' . $_POST['batch_email_attachment_1_filename'];
endif;
if (!empty($_POST['batch_email_attachment_2_filename'])) :
$attachments[] = $uploaddir . '/' . $_POST['batch_email_attachment_2_filename'];
endif;
if (send_mail($email_subject, $row->email, $_POST['batch_email_cc'], $_POST['batch_email_bcc'], $email_body, $attachments, [], $_POST['batch_email_reply_address'], $_POST['batch_email_reply_name'], $_POST['batch_email_reply_address'])) :
$count_ok++;
$html .= '<p>Message has been sent to '.$row->email.'</p>';
if ($batch_type == 'survey') :
if (!empty(lookup_db_field('surveys_responders', 'hash_key', $hash_key, 'hash_key'))) :
$sql = "
UPDATE surveys_responders
SET
sent_date = NOW()
WHERE
hash_key = {$db->quote($hash_key)}
";
$db->query($sql) or die('Database Error!');
endif;
endif;
else :
$count_err++;
$html .= '<p>Error sending mail to '.$row->email.' - '.$mail->ErrorInfo.'</p>';
endif;
$_SESSION['batch_email']['current_rec'] = $count;
session_write_close();
sleep(1);
session_start();
if ($_SESSION['batch_email']['cancel'] === true) :
break;
endif;
endif;
endwhile;
if ($_GET['action'] == 'send') :
if ($batch_type == 'survey') :
$sql = "
UPDATE surveys
SET
send_date = NOW()
WHERE
id = {$survey_id}
";
$db->query($sql) or die('Database Error!');
endif;
$html = '<p>Sent successfully: '.$count_ok.'</p>'.
'<p>Errors: '.$count_err.'</p>'.
$html;
endif;
if ($_GET['action'] == 'send') :
$_SESSION['batch_email']['html'] = $html;
$_SESSION['batch_email']['processing'] = false;
session_write_close();
else :
echo $html;
endif;
else :
$html .= 'No data for report!';
echo $html;
endif;
//$html .= 'dimension x: '.$page_dimension_x.' y: '.$page_dimension_y.' orientation: '.$orientation;
break;
endswitch;