| Server IP : 104.21.21.239 / Your IP : 216.73.216.114 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/tgnewprod/admin/mod/ |
Upload File : |
<?php
use classes\lib\BatchJob;
use classes\lib\EmailEngine;
require('_mod_security.php'); ?>
<?php
$ar_rsvp_status = ['rsvp', 'attended', 'conf', 'cancel', 'wait'];
switch ($_GET['func']) :
case 'send_email' :
$template_id = nz($_POST['id'], '0');
$limit = '';
if ($_POST['test_mode'] === '1') :
$limit = ' LIMIT ' . nz($_POST['test_email_limit'], '1');
endif;
if (is_null($_POST['contact_type']) || !array_key_exists((int)$_POST['contact_type'], APP_CONTACT_STATUSES)) :
echo '<p>Error! Contact Status missing or invalid.</p>';
return;
endif;
$contact_status = (int)$_POST['contact_type'];
if ($_POST['email_selection'] === 'all') :
$search = '';
$venue_status = '1';
elseif ($_POST['email_selection'] === 'specific') :
$ar_contacts_selected = array_keys($_POST['contact_selected'] ?? []);
$search = " AND c.id IN (" . implode(',', $ar_contacts_selected) . ") ";
$venue_status = '1,2';
else :
echo '<p>Error! Invalid All/Specific selection.</p>';
return;
endif;
$sql = "SELECT c.*, v.name AS venue_name FROM contacts c JOIN venues v ON (v.id = c.venue_id) WHERE c.status = {$contact_status} AND c.email > '' AND v.status IN ({$venue_status}) " . $search . $limit;
$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') :
$batch_job = new BatchJob(reference_id: $template_id, job_type: 'batch_email');
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[] = 'form_link';
$ar_placeholders[] = '/form_link';
while ($row = $result->fetch(PDO::FETCH_OBJ)) :
$count++;
$email_body = $_POST['html'];
$email_subject = $_POST['subject'];
$hash_key = sys_encrypt_string($row->id);
foreach ($ar_placeholders as $key) :
switch ($key) :
case 'form_link' :
$value = '<a target="_blank" href="'.APP_BASE_SECURE.'venue_update?key='.urlencode($hash_key).'">';
break;
case '/form_link' :
$value = '</a>';
break;
default :
$value = $row->{$key};
endswitch;
$email_body = str_replace('['.$key.']', $value, $email_body);
endforeach;
if ($_POST['test_mode'] === '1') :
$email_to = $_POST['test_email_address'];
$email_cc = '';
$email_bcc = '';
else :
$email_to = $row->email;
$email_cc = $_POST['cc'];
$email_bcc = $_POST['bcc'];
endif;
if ($_GET['action'] == 'preview') :
$html .= '<p>';
$html .= '<b>FROM:</b> '.$_POST['reply_name'].' <'.$_POST['reply_address'].'><br />';
$html .= '<b>TO:</b> '.$email_to.'<br />';
$html .= '<b>CC:</b> '.$email_cc.'<br />';
$html .= '<b>BCC:</b> '.$email_bcc.'<br />';
$html .= '<b>SUBJECT:</b> '.$email_subject.'<br />';
if (!empty($_POST['attachment_1_filename'])) :
$html .= '<b>ATTACHMENT 1:</b> <a href="ajax.php?call=_file_download&id='.$template_id.'&type=batch_email_attachment&ordinal=1" >'.$_POST['attachment_1_filename'].'</a><br />';
endif;
if (!empty($_POST['attachment_2_filename'])) :
$html .= '<b>ATTACHMENT 2:</b> <a href="ajax.php?call=_file_download&id='.$template_id.'&type=batch_email_attachment&ordinal=2" >'.$_POST['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.'/batch_email_attachments/'.str_pad($template_id, 10, '0', STR_PAD_LEFT);
if (!empty($_POST['attachment_1_filename'])) :
$attachments[] = $uploaddir . '/' . $_POST['attachment_1_filename'];
endif;
if (!empty($_POST['attachment_2_filename'])) :
$attachments[] = $uploaddir . '/' . $_POST['attachment_2_filename'];
endif;
EmailEngine::add_to_queue($batch_job->get_job_id(), $email_subject, $email_to, $email_cc, $email_bcc, $email_body, $attachments, [], $_POST['reply_address'], $_POST['reply_name'], $_POST['reply_address']);
endif;
endwhile;
if ($_GET['action'] == 'send') :
$html = '<p>Sent successfully: '.$count_ok.'</p>'.
'<p>Errors: '.$count_err.'</p>'.
$html;
session_write_close();
$batch_job->start('process_email_queue', [$batch_job->get_job_id()]);
endif;
if ($_GET['action'] == 'send') :
else :
echo $html;
endif;
else :
$html .= 'No data for report!';
echo $html;
endif;
break;
endswitch;