Files
HotLunches/email-parents-form.php
T
2026-10-19 15:22:52 -07:00

235 lines
7.4 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','Application Administrator','Volunteer Administrator','Communications Administrator','Financial','Financial Team');
if (checkPermission($AllowedUserTypes) != 1) {
echo("<br>\n");
$error_message = getLanguageText('ERRORMSG-ACCESS-DENIED');
include "form.messages.php";
return;
}
$ReplyTo = setReplyAddress($school_record['reply_email']);
$ReplyDescription = $school_record['reply_description'];
?>
<form action="/" method="post">
<table width="90%" cellpadding="2" cellspacing="1" border="0">
<tr>
<td align='left' colspan='2'>
<h3><?php displayLanguageText('TEXT-SEND-EMAILS-TO-USERS'); ?></h3>
</td>
</tr>
<tr>
<td align="right"><?php displayLanguageText('TEXT-REPLY-TO-ADDRESS'); ?>:</td>
<td align='left'><input type="text" name="ReplyTo" id="ReplyTo" value="<?php echo($ReplyTo); ?>" size="60"></td>
</tr>
<tr>
<td align="right"><?php displayLanguageText('TEXT-REPLY-TO-DESCRIPTION'); ?>:</td>
<td align='left'><input type="text" name="ReplyDescription" value="<?php echo($ReplyDescription); ?>" size="60"></td>
</tr>
<tr id="messageRow">
<td align="right"><?php displayLanguageText('TEXT-EMAIL-MESSAGE'); ?>:</td>
<td align='left'>
<select name="MessageID" id="MessageID" onChange="DoMessageChange();" class='select-width500'>
<?php
$customFields = array();
$query = "select * from formatted_content " .
"where content_type in ('E','Reminder') " .
"and school_num = $school_num " .
"order by date_modified desc,date_added desc";
$results = db_query($query);
if (db_num_rows($results)) {
while ($row = db_fetch_array($results)) {
$subject = $row["content_id"];
$record_num = $row["record_num"];
echo(" <option value='$record_num'>$subject</option>\n");
$numFields = preg_match_all('/\{custom\.(text|textarea)\.([a-z0-9_]+)\}/', $row['content'], $matches, PREG_SET_ORDER);
for ($i=0; $i<$numFields; $i++) {
$customFields[] = array($record_num, $i+1, $matches[$i][1], $matches[$i][2]);
}
}
}
?>
</select>
</td>
</tr>
<tr>
<td align="right"><?php displayLanguageText('TEXT-TEMPLATE'); ?>:</td>
<td align="left">
<select name="EmailTemplate" class='select-width500'>
<option value="EmailTemplate.html"><?php displayLanguageText('TEXT-STANDARD-EMAIL-TEMPLATE'); ?></option>
<option value="EmailTemplate.NoHeader.html"><?php displayLanguageText('TEXT-NO-HEADER-EMAIL-TEMPLATE'); ?></option>
</select>
</td>
</tr>
<?php
foreach ($customFields as $x) {
list($msg_num, $field_num, $field_type, $field_name) = $x;
$field_title = ucwords(str_replace('_', ' ', $field_name));
if ($field_name == "intro_text") {
$GLOBALS["custom_{$field_name}"] = "Thank you for your time yesterday, it was a pleasure speaking with you. I would " .
"also like to thank you for the opportunity to work with you to redesign and develop your web site. Please feel free to " .
"contact me directly for a personalized quote or with any questions you may have.";
}
?>
<tr id="custom_row_<?php echo $msg_num ?>_<?php echo $field_num ?>" style="display:none;">
<td align="right" valign=top><?php echo $field_title ?>:</td>
<td align="left" valign=top>
<?php if ($field_type == 'textarea') { ?>
<textarea rows=5 cols=80 id="custom_<?php echo $msg_num ?>_<?php echo $field_num ?>"
name="custom_<?php echo $field_name ?>" disabled><?php echo $GLOBALS["custom_{$field_name}"] ?></textarea>
<?php } else { ?>
<input type=text id="custom_<?php echo $msg_num ?>_<?php echo $field_num ?>" name="custom_<?php echo $field_name ?>" disabled
value="<?php echo $GLOBALS["custom_{$field_name}"] ?>" size=70>
<?php } ?>
</td>
</tr>
<?php
}
?>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<?php
include "parents.form.fields.php";
?>
<?php
// Get set of attachment files
$files = array();
$dir = opendir($attachdir);
echo("\n\n<!-- $attachdir -->\n\n");
$i = 0;
while (($file = readdir($dir)) != false) {
if ($file == ".") continue;
if ($file == "..") continue;
$files[] = $file;
$i+=1;
}
if ($i > 0) {
sort($files);
?>
<tr>
<td align="right" valign="top"><?php displayLanguageText('TEXT-ATTACHMENTS'); ?>:</td>
<td align='left'>
<?php
$count = 0;
$jscript = "<script type='text/javascript'>\n";
$jscript .= "var attachListArr = new Array();\n";
foreach ($files as $f) { ?>
<input type="checkbox" class=checkbox name="attachments[]" id="<?php echo($f) ?>" value="<?php echo("$attachpath/$f") ?>"><?php echo($f); ?><br>
<?php
$jscript .= "attachListArr[$count] = '$f';\n";
$count++;
}
$jscript .= "</script>\n";
echo $jscript;
?>
</td>
</tr>
<?php
}
?>
</table>
<input type='submit' id='submitButton' class='btn btn--primary' value="<?php displayLanguageText('TEXT-SEND-EMAILS-TO-USERS'); ?>">
<input type="hidden" name="action" value="email-parents">
<input type="hidden" name="naction" value="confirm">
</center>
</form>
<script language="JavaScript">
var currMessage=0;
var goodRowDisplay = document.getElementById('messageRow').style.display;
function DoMessageChange() {
// deactivate all attachment check boxes
var arrLen=attachListArr.length;
for (var j=0, len=arrLen; j<len; ++j) {
var attachSel = attachListArr[j];
document.getElementById(attachSel).checked = false;
}
// activate the corrects ones
var msgVar = document.getElementById('MessageID').value;
var arrLen = (attachArr[msgVar] ? attachArr[msgVar].length : 0);
for (var j=0, len=arrLen; j<len; ++j) {
var attachSel = attachArr[msgVar][j];
document.getElementById(attachSel).checked = true;
}
if (currMessage) {
i = 1;
while (x = document.getElementById('custom_' + currMessage + '_' + i)) {
x.disabled = true;
document.getElementById('custom_row_'+ currMessage + '_' + i).style.display = 'none';
i++;
}
}
currMessage = msgVar;
i = 1;
while (x = document.getElementById('custom_' + currMessage + '_' + i)) {
x.disabled = false;
document.getElementById('custom_row_'+ currMessage + '_' + i).style.display = goodRowDisplay;
i++;
}
}
</script>
<?php
$school_url = $school_record['url'];
$parts = explode('.', $school_url);
if (count($parts) == 2) $email_domain = $school_url;
else {
$email_domain = $parts[1].'.'.$parts[2];
}
?>
<script>
$(document).ready(function() {
$("#submitButton").click(function() {
return(verifyEmail());
});
$("#ReplyTo").on('blur', function(e) {
return(verifyEmail());
});
function verifyEmail() {
var reply = $("#ReplyTo").val();
if (reply.length == 0) {
alert("<?php displayLanguageText('ERRORMSG-MISSING-REPLY-ADDRESS'); ?>");
return(false);
}
if (reply.includes("<?php echo($email_domain) ?>")) {
return(true);
}
else {
alert("<?php displayLanguageText('ERRORMSG-INVALID-REPLY-ADDRESS'); ?>");
return(false);
}
}
});
</script>
<script language="JavaScript">
DoMessageChange();
</script>