| Server IP : 104.21.21.239 / Your IP : 216.73.216.201 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/connections/mod/ |
Upload File : |
<?php
use classes\lib\EmailEngine;
include('_mod_security.php');
form_prep('frm_email_template', 'basic_info');
if ($_POST['ajax_event_submitted'] == '1') :
$config = HTMLPurifier_Config::createDefault();
$purifier = new HTMLPurifier($config);
$_POST['html'] = $purifier->purify($_POST['html']);
form_prep_submit();
form_validate_all();
if (isset($_FILES['attachment_1']) && !empty($_FILES['attachment_1']['name'])) :
$allowed_ext = ['pdf', 'png', 'jpg', 'jpeg', 'gif', 'bmp', 'doc', 'docx', 'ics', 'ical', 'txt'];
$ext = pathinfo(strtolower($_FILES['attachment_1']['name']), PATHINFO_EXTENSION);
//var_dump($_FILES);
if (!in_array($ext, $allowed_ext)) :
$ar_err['attachment_1'] = 'File type "'.$ext.'" not allowed!';
$err_tab = 'basic_info';
$err_flag = true;
endif;
endif;
if (isset($_FILES['attachment_2']) && !empty($_FILES['attachment_2']['name'])) :
$allowed_ext = ['pdf', 'png', 'jpg', 'jpeg', 'gif', 'bmp', 'doc', 'docx', 'ics', 'ical', 'txt'];
$ext = pathinfo(strtolower($_FILES['attachment_2']['name']), PATHINFO_EXTENSION);
//var_dump($_FILES);
if (!in_array($ext, $allowed_ext)) :
$ar_err['attachment_2'] = 'File type "'.$ext.'" not allowed!';
$err_tab = 'basic_info';
$err_flag = true;
endif;
endif;
if (!$err_flag) :
try {
$db->beginTransaction();
$set = sql_set_update() . form_generate_set();
if ($action == 'Edit') :
$template_id = nz(trim($_REQUEST['id']), '0');
else :
$template_id = next_id('email_templates');
endif;
//************** Attachments ****************
if (isset($_FILES['attachment_1']) && !empty($_FILES['attachment_1']['name'])) :
$upload_file_name_1 = str_replace(' ','_',basename($_FILES['attachment_1']['name']));
$upload_file_name_1 = preg_replace('/[^0-9a-z\.\_\-]/i','',$upload_file_name_1);
$_POST['attachment_1_filename'] = $upload_file_name_1;
$uploaddir = APP_UPLOAD_DIR.'/batch_email_attachments/'.str_pad($template_id, 10, '0', STR_PAD_LEFT);
if (!is_dir($uploaddir)) :
mkdir($uploaddir, 0777, true);
endif;
else :
$upload_file_name_1 = $_POST['attachment_1_filename'];
endif;
if (isset($_FILES['attachment_2']) && !empty($_FILES['attachment_2']['name'])) :
$upload_file_name_2 = str_replace(' ','_',basename($_FILES['attachment_2']['name']));
$upload_file_name_2 = preg_replace('/[^0-9a-z\.\_\-]/i','',$upload_file_name_2);
$_POST['attachment_2_filename'] = $upload_file_name_2;
$uploaddir = APP_UPLOAD_DIR.'/batch_email_attachments/'.str_pad($template_id, 10, '0', STR_PAD_LEFT);
if (!is_dir($uploaddir)) :
mkdir($uploaddir, 0777, true);
endif;
else :
$upload_file_name_2 = $_POST['attachment_2_filename'];
endif;
$set = "attachment_1 = ".$db->quote($upload_file_name_1).", " . $set;
$set = "attachment_2 = ".$db->quote($upload_file_name_2).", " . $set;
//********************************************
if ($action == 'Edit') :
$sql = "UPDATE email_templates set " . $set .
"WHERE id = ".nz(trim($_REQUEST['id']), '0')." ";
$db->query($sql) or die('Database Error!');
post_set_update();
else :
if ($action == 'Add New') :
$sql = "INSERT INTO email_templates SET ".
sql_set_create().
$set;
$db->query($sql) or die('Database Error!');
$_REQUEST['id'] = last_id();
$_POST['id'] = $_REQUEST['id'];
post_set_create_update();
endif;
endif;
//********* clean up existing files for this event **********
if (isset($_FILES['attachment_1']) && !empty($_FILES['attachment_1']['name']) &&
isset($_FILES['attachment_2']) && !empty($_FILES['attachment_2']['name'])) :
$files = glob($uploaddir.'/*');
foreach ($files as $file) :
if (is_file($file)) :
unlink($file);
endif;
endforeach;
endif;
//************** store file upload 1 ***************
if (isset($_FILES['attachment_1']) && !empty($_FILES['attachment_1']['name'])) :
$uploadfile = $uploaddir.'/'.$upload_file_name_1;
if (!move_uploaded_file($_FILES['attachment_1']['tmp_name'], $uploadfile)) :
$ar_err['attachment_1'] = 'Failed to upload file!';
throw new Exception('Failed to upload file.');
endif;
endif;
$_POST['attachment_1_filename'] = $upload_file_name_1;
//************** store file upload 2 ***************
if (isset($_FILES['attachment_2']) && !empty($_FILES['attachment_2']['name'])) :
$uploadfile = $uploaddir.'/'.$upload_file_name_2;
if (!move_uploaded_file($_FILES['attachment_2']['tmp_name'], $uploadfile)) :
$ar_err['attachment_2'] = 'Failed to upload file!';
throw new Exception('Failed to upload file.');
endif;
endif;
$_POST['attachment_2_filename'] = $upload_file_name_2;
//************************************************
$db->commit();
} catch(Exception $e) {
db_err_rollback($e);
}
$form_message = "Saved sucessfully!";
form_uid_reset();
if ($_POST['xsubmit'] == 'Save & Close') :
echo "<SCRIPT>";
echo "appstack_pop()";
echo "</SCRIPT>";
endif;
if ($_POST['xsubmit'] == 'Save & New') :
echo "<SCRIPT>";
echo "window.location.href = 'index.php?IX=email_template_form&ref=".urlencode($_REQUEST['ref'])."'";
echo "</SCRIPT>";
endif;
if ($_POST['xsubmit'] == 'Copy') :
$copied_template_id = EmailEngine::copy_template(nz(trim($_REQUEST['id']), '0'));
echo "<SCRIPT>";
echo "window.location.href = 'index.php?IX=email_template_form&id=".$copied_template_id."'";
echo "</SCRIPT>";
endif;
if ($_POST['xsubmit'] == 'Preview') :
echo "<SCRIPT>";
echo '$(document).ready(function() {';
echo "process_email('preview');";
echo '});';
echo "</SCRIPT>";
$active_tab = 'preview';
$email_function = 'preview';
endif;
if ($_POST['xsubmit'] == 'Send') :
echo "<SCRIPT>";
echo '$(document).ready(function() {';
echo "process_email('send');";
echo '});';
echo "</SCRIPT>";
$active_tab = 'job_status';
$email_function = 'send';
endif;
else :
$active_tab = $err_tab;
$form_message = "Errors found!";
endif;
else:
if ($action == 'Edit') :
$sql = "SELECT * FROM email_templates WHERE id = ".nz(trim($_REQUEST['id']), '0')." ";
if (!get_row_to_post($sql)) :
echo form_fatal_error('Invalid Operation!');
return;
endif;
$_POST['attachment_1_filename'] = $row['attachment_1'];
$_POST['attachment_2_filename'] = $row['attachment_2'];
else :
endif;
endif;
?>
<style>
#db_grid_contacts div.lcs_dbg_wrapper div.lcs_dbg_data_section {
max-height: 200px !important;
}
</style>
<script>
var active_page = '<?php echo $_REQUEST['IX']; ?>';
var active_tab = '';
var ar_selected_contacts = <?php echo json_encode(array_keys($_POST['contact_selected'] ?? [])); ?>;
var db_grid_contacts_reload_finished = false;
update_header = function() {
if ($("#description").val() > "" ) {
$("#header_repeater").text(" - " + $("#description").val());
}
}
function click_email_selection(elem, ix) {
if ($(elem).prop('checked')) {
ar_selected_contacts.push(ix);
} else {
const index = ar_selected_contacts.indexOf(ix);
if (index > -1) {
ar_selected_contacts.splice(index, 1);
}
}
}
function set_email_selection(sel) {
if (sel == 'all') {
$('#email_contact_selection').hide();
} else {
$('#email_contact_selection').show();
}
}
function set_email_selection_checked() {
//console.log(ar_selected_contacts);
ar_selected_contacts.forEach(function(item, index) {
//console.log('item: ' + item + ', index: ' + index);
$('#contact_selected_' + item).prop('checked', true);
});
db_grid_contacts_reload_finished = true;
}
function contact_selection_show_selected() {
db_grid_contacts_reload_finished = false;
window['db_grid_contacts' + "_search_str"] = '';
$('#db_grid_contacts_strSearch').val('');
lcs_db_grid_reload('db_grid_contacts');
when(function() {
if (db_grid_contacts_reload_finished) {
return true;
} else {
return false;
}
},
function(){
$('input.contact_selected:checkbox:not(:checked)').each(function() {
$(this).parent().parent().parent().hide();
});
});
}
function contact_selection_show_all() {
db_grid_contacts_reload_finished = false;
window['db_grid_contacts' + "_search_str"] = '';
$('#db_grid_contacts_strSearch').val('');
lcs_db_grid_reload('db_grid_contacts');
when(function() {
if (db_grid_contacts_reload_finished) {
return true;
} else {
return false;
}
},
function(){
$('input.contact_selected:checkbox').each(function() {
$(this).parent().parent().parent().show();
});
});
}
function contact_selection_clear_all() {
$('input.contact_selected:checkbox:checked').removeAttr('checked');
ar_selected_contacts = [];
contact_selection_show_all();
}
function batch_finished(html) {
$('#job_status').append(html);
}
function process_email(action) {
$.ajax({
url: 'ajax.php?call=batch_email_ajax&func=send_email&action=' + action,
method: 'POST',
data: <?php echo json_encode($_POST); ?>,
dataType: 'text',
success: function(data) {
if (action == 'preview') {
batch_finished(data);
}
},
error: function (request, status, error) {
if (error > ' ') {
alert('Error! ' + error);
}
},
});
}
function confirm_cancel(id) {
var answer = confirm('Are you sure?');
if (answer == true) {
$.ajax({
url: 'ajax.php?call=email_template_jobs_ajax&func=cancel_job&id=' + id,
data: '',
dataType: 'json',
success: function(json) {
if (json.result == 'Success') {
$('#' + prefix + 'cancel_' + item.id).text('Requested');
}
},
error: function (request, status, error) {
alert('Error! ' + error);
},
});
}
}
function show_job_output(id) {
$.ajax({
url: 'ajax.php?call=email_template_jobs_ajax&func=get_output&id=' + id,
data: '',
dataType: 'json',
success: function(json) {
if (json.result == 'Success') {
$('#grid_popup_contents').html(json.html);
$('#grid_popup').show();
}
},
error: function (request, status, error) {
alert('Error! ' + error);
},
});
}
function hide_output_details() {
$('div.grid_popup').hide();
}
function update_running_jobs() {
if ($('#tab_content_job_status').is(':visible')) {
const prefix = 'db_grid_jobs_cell_';
$.ajax({
url: 'ajax.php?call=email_template_jobs_ajax&func=get_job_status&id=<?=nz($_REQUEST['id'], '0');?>',
data: '',
dataType: 'json',
success: function(json) {
if (json.result == 'Success') {
json.data.map(function(item) {
$('#' + prefix + 'status_' + item.id).text(item.status);
$('#' + prefix + 'end_time_' + item.id).text(item.end_time);
$('#' + prefix + 'processed_recs_' + item.id).text(item.processed_recs);
$('#' + prefix + 'total_recs_' + item.id).text(item.total_recs);
$('#' + prefix + 'percent_' + item.id).text(item.percent_complete);
$('#' + prefix + 'output_' + item.id + ' a').first().text(item.output);
if (item.status != 'running') {
$('#' + prefix + 'cancel_' + item.id).text('');
}
});
}
},
error: function (request, status, error) {
alert('Error! ' + error);
},
});
}
}
$(document).ready(function() {
switch_tab('<?php echo $active_tab; ?>');
update_header();
//$(':input:not(.search)').change(function() {sheet_dirty = true; } );
$(':input:not(.search, .no_dirty, .no_dirty input)').change(function() {sheet_dirty = true; } );
set_email_selection($('input:radio[name=email_selection]:checked').val());
setInterval(function() {
if ($('#tab_content_job_status').is(':visible')) {
lcs_db_load('db_grid_jobs', 'email_template_jobs_ajax', 'grid', '', db_grid_jobs_sort_col, db_grid_jobs_sort_order, $('#db_grid_jobs_strSearch').val(), db_grid_jobs_parm1, db_grid_jobs_parm2, db_grid_jobs_parm3, db_grid_jobs_filter_cols, db_grid_jobs_multi_filter);
}
}, 60000);
setInterval(function() {
update_running_jobs();
}, 2000);
editor = $('#html').trumbowyg({
removeformatPasted: true,
btns: ['fontfamily'],
btns: [
['viewHTML'],
['undo', 'redo'], // Only supported in Blink browsers
['formatting'],
['strong', 'em', 'del'],
['superscript', 'subscript'],
['link'],
['insertImage'],
['justifyLeft', 'justifyCenter', 'justifyRight', 'justifyFull'],
['unorderedList', 'orderedList'],
['horizontalRule'],
['removeformat'],
['fullscreen'],
['fontfamily'],
['table'],
['tableCellBackgroundColor', 'tableBorderColor'],
],
});
});
</script>
<h1>Email Template - <?php echo $action; ?><span id="header_repeater"></span></h1>
<?php echo form_message($form_message); ?>
<form name="frm_email_template" id="frm_email_template" enctype="multipart/form-data" method="post" action="">
<input name="ajax_event_submitted" type="hidden" value="1" />
<input name="id" type="hidden" value="<?php echo $_REQUEST['id']; ?>" />
<input name="active_tab" id="active_tab" type="hidden" value="basic_info" />
<?php
form_button_strip('top', [
'save_as' => ['show' => true, 'caption' => 'Copy', 'js' => "sheet_dirty = false; document.getElementById('xsubmit').value = this.value; this.form.submit();"],
'preview'=>['show'=>true, 'caption'=>'Preview', 'js' => "sheet_dirty = false; document.getElementById('xsubmit').value = this.value; this.form.submit();"],
'send'=>['show'=>true, 'caption'=>'Send', 'js'=>"sheet_dirty = false; document.getElementById('xsubmit').value = this.value; this.form.submit();"],
]);
form_tab_strip_start();
form_tab_header('basic_info', 'Basic Info', 'admin');
if (!empty($_REQUEST['id'])) :
form_tab_header('preview', 'Preview', 'admin');
form_tab_header('job_status', 'Job Status', 'admin');
endif;
form_tab_strip_end();
//******************************************************************************************
form_tab_start('basic_info', 'Basic Info');
form_column_start();
form_field('id', 'text', 10, 0, false, false, true, '', '', 'id', 'Template ID');
form_field('description', 'text', 50, 0, true, false, false, '', '', 'description', 'Description', [], '', 'update_header();');
form_field('subject', 'text', 150, 0, false, false, false, '', '', 'subject', 'Email Subject');
form_field(['fname'=>'reply_name', 'ftype'=>'text', 'fsize'=>100, 'frequired'=>false, 'fdbname'=>'reply_name', 'flabel'=>'Email Reply To Name']);
form_field(['fname'=>'reply_address', 'ftype'=>'text', 'datatype'=>'email', 'fsize'=>100, 'frequired'=>false, 'fdbname'=>'reply_address', 'flabel'=>'Email Reply To Address']);
form_field(['fname'=>'cc', 'ftype'=>'text', 'fsize'=>100, 'frequired'=>false, 'fdbname'=>'cc', 'flabel'=>'Email CC (comma separated)']);
form_field(['fname'=>'bcc', 'ftype'=>'text', 'fsize'=>100, 'frequired'=>false, 'fdbname'=>'bcc', 'flabel'=>'Email BCC (comma separated)']);
form_field(['fname'=>'attachment_1', 'ftype'=>'file', 'fsize'=>10, 'frequired'=>false, 'fdbname'=>'attachment_1', 'flabel'=>'Email Attachment 1']);
if (!empty($_POST['attachment_1_filename'])) :
echo '<span id="file_attachment_spec">';
echo '<br /><br /><a href="ajax.php?call=_file_download&id='.$_REQUEST['id'].'&type=batch_email_attachment&ordinal=1" >'.$_POST['attachment_1_filename'].'</a>';
echo '  <a href="#" onclick="$(\'#attachment_1_filename\').val(\'\'); $(\'#file_attachment_spec\').hide(); return false;">Remove attachment</a><br /><br />';
echo '</span>';
endif;
form_field(['fname'=>'attachment_2', 'ftype'=>'file', 'fsize'=>10, 'frequired'=>false, 'fdbname'=>'attachment_2', 'flabel'=>'Email Attachment 2']);
if (!empty($_POST['attachment_2_filename'])) :
echo '<span id="file_attachment2_spec">';
echo '<br /><br /><a href="ajax.php?call=_file_download&id='.$_REQUEST['id'].'&type=batch_email_attachment&ordinal=2" >'.$_POST['attachment_2_filename'].'</a>';
echo '  <a href="#" onclick="$(\'#attachment_2_filename\').val(\'\'); $(\'#file_attachment2_spec\').hide(); return false;">Remove attachment</a><br /><br />';
echo '</span>';
endif;
if (empty($_POST['contact_type'])) :
$_POST['contact_type'] = 1;
endif;
form_field(['fname'=>'contact_type', 'ftype'=>'radiogroup', 'frequired'=>false, 'fdbname'=>'', 'flabel'=>'Contact Status', 'ar_group'=>APP_CONTACT_STATUSES]);
$ar_print_selection = ['all'=>'All emails', 'specific'=>'Specific'];
if (empty($_POST['email_selection'])) :
$_POST['email_selection'] = 'all';
endif;
form_field(['fname'=>'email_selection', 'ftype'=>'radiogroup', 'fsize'=>10, 'frequired'=>false, 'fdbname'=>'', 'ar_group'=>$ar_print_selection, 'flabel'=>'Email Send Selection', 'fclass'=>'no_dirty', 'onchange'=>'set_email_selection($(this).val());']);
echo '<div id="email_contact_selection">';
echo '<label style="margin-top:8px;">Contact Selection</label>';
db_navigator_bar(array('table_id'=>'db_grid_contacts', 'form'=>'', 'print_section'=>'', 'call'=>'email_template_jobs_ajax', 'sort_col'=>'2', 'sort_order'=>'0', 'subtab'=>'true', 'parm1'=>'', 'func'=>'load_email_contacts', 'btn_addnew'=>'false', 'btn_print'=>'false', 'btn_excel'=>'false', 'btn_pdf'=>'false', 'record_count'=>'false', 'extra_data'=>'false', 'diag'=>'false', 'lazy_callback'=>'function() {set_email_selection_checked();}' ));
echo '<button onclick="contact_selection_show_selected(); return false;">Show Selected</button> ';
echo '<button onclick="contact_selection_show_all(); return false;">Show All</button> ';
echo '<button onclick="contact_selection_clear_all(); return false;">Clear All</button><hr style="border-color: lightgray;">';
echo '</div>';
form_field(['fname'=>'test_mode', 'ftype'=>'checkbox', 'frequired'=>false, 'fdbname'=>'', 'flabel'=>'Test Mode', 'fclass'=>'no_dirty']);
form_field(['fname'=>'test_email_address', 'ftype'=>'text', 'fsize'=>'50', 'frequired'=>false, 'fdbname'=>'', 'flabel'=>'Test Email Address', 'fclass'=>'no_dirty']);
form_field(['fname'=>'test_email_limit', 'ftype'=>'text', 'fsize'=>'4', 'frequired'=>false, 'fdbname'=>'', 'flabel'=>'Test Email Limit', 'fclass'=>'no_dirty']);
form_column_end();
form_column_start('max-width:750px;');
form_field(['fname'=>'placeholder', 'ftype'=>'select', 'fsize'=>25, 'frequired'=>false, 'fdbname'=>'', 'flabel'=>'Placeholder - select to insert into HTML below', 'ar_group'=>EmailEngine::PLACEHOLDERS, 'onchange'=>'insert_text_at_cursor(\'[\' + $(this).val() + \']\', false, \'html\'); return false;']);
form_field(['fname'=>'html', 'ftype'=>'textarea', 'fsize'=>70, 'frows'=>25, 'frequired'=>false, 'fdbname'=>'html', 'flabel'=>'Default Email HTML (TIP: use SHIFT+ENTER for Carriage Return)']);
form_column_end();
form_tab_end();
if (!empty($_REQUEST['id'])) :
//******************************************************************************************
form_tab_start('preview', 'Preview');
echo '<h2>Email Preview</h2>';
echo '<div id="job_status"></div>';
form_tab_end();
//******************************************************************************************
form_tab_start('job_status', 'Job Status');
db_navigator_bar(['table_id' => 'db_grid_jobs', 'form' => '', 'btn_addnew'=>'false', 'print_section' => 'db_grid_jobs', 'call' => 'email_template_jobs_ajax', 'sort_col' => '3', 'sort_order' => '1', 'parm1' => " AND bj.job_type = 'batch_email' AND bj.reference_id = " . nz($_REQUEST['id'], '0') . " ", 'func' => 'grid']);
form_tab_end();
?>
<div id="grid_popup" class="grid_popup" style="padding:18px!important;">
<div style="position:absolute; right:0; top:0; padding:8px;">
<a href="javascript:hide_output_details();">X</a>
</div>
<b><br>Job Output:</b> <br />
<div id="grid_popup_contents">
</div>
</div>
<?php
endif;
form_button_strip('bottom', [
'save_as' => ['show' => true, 'caption' => 'Copy', 'js' => "sheet_dirty = false; document.getElementById('xsubmit').value = this.value; this.form.submit();"],
'preview'=>['show'=>true, 'caption'=>'Preview', 'js' => "sheet_dirty = false; document.getElementById('xsubmit').value = this.value; this.form.submit();"],
'send'=>['show'=>true, 'caption'=>'Send', 'js'=>"sheet_dirty = false; document.getElementById('xsubmit').value = this.value; this.form.submit();"],
]);
?>
</form>
<script src="trumbowyg/dist/trumbowyg.min.js?ver=<?php echo filemtime(__DIR__.'/../trumbowyg/dist/trumbowyg.min.js') ?>"></script>
<script src="trumbowyg/dist/plugins/fontfamily/trumbowyg.fontfamily.min.js?ver=<?php echo filemtime(__DIR__.'/../trumbowyg/dist/plugins/fontfamily/trumbowyg.fontfamily.min.js') ?>"></script>
<script src="trumbowyg/dist/plugins/table/trumbowyg.table.min.js?ver=<?php echo filemtime(__DIR__.'/../trumbowyg/dist/plugins/table/trumbowyg.table.min.js') ?>"></script>