Files
HotLunches/email-hotlunch-contacts-confirm.php
2026-10-19 15:22:52 -07:00

324 lines
11 KiB
PHP

<?php
require_once("include/globals.php");
if (SessionActive() != 1 || ! UserLoggedIn()) {
header("Location: /");
exit();
}
// Ensure that only admin users have access to this module
$AllowedUserTypes = array('SuperUser','System Administrator','Communications Administrator');
if (checkPermission($AllowedUserTypes) != 1) {
echo("<br>\n");
$error_message = getLanguageText('ERRORMSG-ACCESS-DENIED');
include "form.messages.php";
return;
}
//
// Build a database query based on the input data provided
//
if (!$_POST) return;
extract($_POST);
$PrimaryTable = "school_contact_list";
//
// Define the default query to be used
//
$Parameters = "";
$EmailField = "contact_email";
$Recipients = array("contact_email","contact_name","school_name");
$Alignment = array("left","left","left");
$Category = "Hot Lunch Contacts Broadcast";
$Description = "Broadcast to Hot Lunch Application Contacts";
$Where = "";
//
// Handle any parameters
//
if (isset($SelectedProvinces) && count($SelectedProvinces) > 0) {
if (count($SelectedProvinces) > 1 || strlen($SelectedProvinces[0]) > 0) {
$selectedProvinces = join(",",$SelectedProvinces);
$Where .= "AND province IN ($selectedProvinces) ";
}
}
if (isset($SelectedReseller) && count($SelectedReseller) > 0) {
if (count($SelectedReseller) > 1 || strlen($SelectedReseller[0]) > 0) {
$selectedReseller = join(",",$SelectedReseller);
$Where .= "AND reseller IN ($selectedReseller) ";
}
}
if (isset($SelectedSchools) && count($SelectedSchools) > 0) {
if (count($SelectedSchools) > 1 || $SelectedSchools[0] != 0) {
$selectedSchools = join(",",$SelectedSchools);
$Where .= "AND school_num IN ($selectedSchools) ";
}
}
if (isset($renewal_invoice_issued) && $renewal_invoice_issued != "") $Where .= "AND renewal_invoice_issued = '$renewal_invoice_issued' ";
if (isset($renewal_invoice_paid) && $renewal_invoice_paid != "") $Where .= "AND renewal_invoice_paid = '$renewal_invoice_paid' ";
if (isset($BalanceOwing) && $BalanceOwing == 'Y') {
$Where .= "AND balance_owing > 0 ";
}
// Process updated selection list
if (array_key_exists('sel',$_POST)) {
if (is_array($_POST['sel'])) {
$_POST['sel'] = join(",", $_POST['sel']);
}
$Where .= " and c.record_num IN ({$_POST['sel']})";
$Description .= " (custom recipient list)";
}
// Set the set of fields from the schools table
$schoolsFields = "timezone,url,expiry_date,system_configuration,system_access_code,status";
// Build the query
$today = date("Y-m-d",time());
$Query = "SELECT DISTINCT c.contact_name,c.contact_email,c.contact_phone,school_name,city,province,$schoolsFields,c.record_num " .
"FROM school_contact_list AS c, schools AS s " .
"WHERE c.contact_email is not null " .
"AND c.contact_email != '' " .
"AND school_num = s.record_num " .
"AND c.active = 'Y' " .
"AND s.status in ('Active','Special') " .
"AND s.expiry_date >= '$today' " .
$Where .
"ORDER BY school_name,c.contact_email,c.contact_name";
// create attachment list
if (array_key_exists('attachments',$_POST)) {
if (is_array($_POST['attachments'])) {
$attachments = $_POST['attachments'] = join(",", $_POST['attachments']);
}
}
//
// Determine how many emails will be sent
//
$results = db_query($Query);
$num_rows = db_num_rows($results);
//
// Determine the number of schools
//
$num_schools = db_getVal("SELECT count(DISTINCT s.record_num) " .
"FROM school_contact_list AS c, schools AS s " .
"WHERE c.contact_email is not null " .
"AND c.contact_email != '' " .
"AND school_num = s.record_num " .
"AND c.active = 'Y' " .
"AND s.status in ('Active','Special') " .
$Where);
?>
<center>
<form method="post" action="/">
<table width='90%' cellpadding='2' cellspacing='0' border='0'>
<tr>
<td align='center'>
<h3>Confirm Email Send</h3>
</td>
</tr>
<tr>
<td align='center'>
<?php
$Subject = db_getVal("SELECT content_id FROM formatted_content WHERE school_num = $school_num AND record_num = $MessageID");
echo("<b>$Subject</b><br>\n");
echo("$Category:<br>\n");
echo("$Description:<br>\n");
?>
</td>
</tr>
<tr>
<td align='center'>
<table width='500' cellpadding='5' cellspacing='0' border='0'>
<tr>
<td align='center' colspan='2'><p><strong><?php echo($num_rows) ?> record(s) found - <?php echo($num_schools) ?> Schools</strong></p></td>
</tr>
<?php
if ($num_rows > 0) {
?>
<tr>
<td align='center'>Send Emails:</td>
<td align='center'>
<select name="SendAfter">
<?php include "email-send-times.php"; ?>
</select>
</td>
</tr>
<tr>
<td colspan='2' align='center'>
<br>
<input type='submit' class='btn btn--primary' value="Send Emails">
</td>
</tr>
</table>
</td>
</tr>
</table>
<input type="hidden" name="ReplyTo" value="<?php echo($ReplyTo) ?>">
<input type="hidden" name="ReplyDescription" value="<?php echo($ReplyDescription) ?>">
<input type="hidden" name="MessageID" value="<?php echo($MessageID) ?>">
<input type="hidden" name="EmailTemplate" value="<?php echo($EmailTemplate) ?>">
<input type="hidden" name="Category" value="<?php echo($Category) ?>">
<input type="hidden" name="Description" value="<?php echo($Description) ?>">
<input type="hidden" name="Query" value="<?php echo($Query) ?>">
<input type="hidden" name="EmailField" value="<?php echo($EmailField) ?>">
<input type="hidden" name="attachments" value="<?php echo($attachments) ?>">
<input type="hidden" name="Parameters" value="<?php echo($Parameters) ?>">
<input type="hidden" name="PrimaryTable" value="<?php echo($PrimaryTable) ?>">
<?php
$post_fields = array_keys($_POST);
for ($i = 0; $i < count($post_fields); $i++) {
$field_name = $post_fields[$i];
if (array_key_exists($field_name, $_POST) && is_string($_POST[$field_name])) {
$field_value = htmlentities($_POST[$field_name]);
if (strpos($field_name, 'custom_') === 0) {
echo(" <input type='hidden' name=\"{$field_name}\" value=\"{$field_value}\">\n");
}
}
}
?>
<input type="hidden" name="action" value="email-hotlunch-contacts">
<input type="hidden" name="naction" value="send">
</form>
<?php if ($view_recipients != 'Y') { ?>
<form method='post' action='/'>
<table width='90%' cellpadding='2' cellspacing='0' border='0'>
<tr>
<td align='center'>
<table width='400' cellpadding='5' cellspacing='0' border='0'>
<tr>
<td align='center'>
<input type='submit' class='btn btn--primary' value="View Recipient List">
</td>
</tr>
</table>
</td>
</tr>
</table>
<?php
$post_fields = array_keys($_POST);
for ($i = 0; $i < count($post_fields); $i++) {
$field_name = $post_fields[$i];
$field_value = $_POST[$field_name];
if (is_array($field_value)) {
foreach ($field_value as $a => $b) {
echo(" <input type='hidden' name='{$field_name}[{$a}]' value=\"$b\">\n");
}
} else {
echo(" <input type='hidden' name='$field_name' value=\"$field_value\">\n");
}
}
?>
<input type='hidden' name='view_recipients' value='Y'>
</form>
<?php } else { ?>
<h3>Recipient List</h3>
<form action="/" method=post>
<input type="hidden" name="action" value="email-hotlunch-contacts">
<input type="hidden" name="naction" value="confirm">
<input type="hidden" name="ReplyTo" value="<?php echo $_POST['ReplyTo'] ?>">
<input type="hidden" name="ReplyDescription" value="<?php echo $_POST['ReplyDescription'] ?>">
<input type="hidden" name="MessageID" value="<?php echo $_POST['MessageID'] ?>">
<input type="hidden" name="EmailTemplate" value="<?php echo $_POST['EmailTemplate'] ?>">
<input type="hidden" name="attachments" value="<?php echo $_POST['attachments'] ?>">
<?php
$post_fields = array_keys($_POST);
for ($i = 0; $i < count($post_fields); $i++) {
$field_name = $post_fields[$i];
$field_value = $_POST[$field_name];
if (is_array($field_value)) {
foreach ($field_value as $a => $b) {
echo(" <input type='hidden' name='{$field_name}[{$a}]' value=\"$b\">\n");
}
} else {
echo(" <input type='hidden' name='$field_name' value=\"$field_value\">\n");
}
}
?>
<input type="hidden" name="sel[]" value="0">
<!--
<input type='submit' class='btn btn--primary' value="Update Recipient List"><br><br>
-->
<table width='600' cellpadding='3' cellspacing='1' border='0' class='content-table'>
<tr>
<?php
for ($i = 0; $i < count($Recipients); $i++) {
$field = ucwords(str_replace("_"," ",$Recipients[$i]));
$align = $Alignment[$i];
echo(" <td align='$align' class='heading'>$field</td>\n");
}
?>
<td align=center class='heading'><a href="javascript:checkAll();"><span class='heading'>All</span></a>&nbsp;
<a href="javascript:checkNone();"><span class='heading'>None</span></a></td>
</tr>
<?php
$results = db_query($Query);
$count = 0;
while ($row = db_fetch_array($results)) {
$bgclass = "data-even";
if ($count % 2) $bgclass = "data-odd";
$count++;
echo(" <tr>\n");
for ($i = 0; $i < count($Recipients); $i++) {
$field = $Recipients[$i];
$align = $Alignment[$i];
echo(" <td align='$align' class='$bgclass'>$row[$field]</td>\n");
}
echo("<td class='$bgclass' align=center><input class=checkbox type=checkbox name=\"sel[]\" id=sel{$count} checked value=\"{$row['record_num']}\"></td>");
echo(" </tr>\n");
}
?>
</table>
<br><input type=submit value="Update Recipient List" class='btn btn--primary'>
</form>
<script type="text/javascript">
function checkAll() {
for (i=1; i<= <?php echo $count ?>; i++) {
document.getElementById('sel'+i).checked = true;
}
}
function checkNone() {
for (i=1; i<= <?php echo $count ?>; i++) {
document.getElementById('sel'+i).checked = false;
}
}
</script>
<?php
}
}
else {
?>
</table>
</td>
</tr>
</table>
<?php
}
?>
<br>
<br>
<br>