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

190 lines
6.2 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;
}
$ReplyTo = $_SESSION['UserInfo']['email'];
//$ReplyDescription = "{$_SESSION['UserInfo']['first_name']} {$_SESSION['UserInfo']['last_name']}";
$ReplyDescription = "EASY School Software";
?>
<form action="/" method="post">
<center>
<table width="90%" cellpadding="2" cellspacing="1" border="0">
<tr>
<td align='left' colspan='2'>
<h3><?php displayLanguageText('TEXT-SEND-EMAIL-TO-CONTACTS'); ?></h3>
</td>
</tr>
<tr>
<td align="right"><?php displayLanguageText('TEXT-REPLY-TO-ADDRESS'); ?>:</td>
<td align='left'><input type="text" name="ReplyTo" value="<?php echo($ReplyTo); ?>" size="40"></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="40"></td>
</tr>
<tr id="messageRow">
<td align="right"><?php displayLanguageText('TEXT-EMAIL-MESSAGE'); ?>:</td>
<td align='left'>
<select name="MessageID" id="MessageID" onChange="DoMessageChange();">
<?php
$customFields = array();
$query = "select * from formatted_content 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"];
$text = $subject;
if (strlen($text) > 50) $text = substr($subject, 0, 50)."...";
echo(" <option value='$record_num'>$text</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">
<?php BuildDirList("email_templates",array("html$","htm$")) ?>
</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 "contacts.form.fields.php";
?>
<?php
// Get set of attachment files
$files = array();
$dir = opendir($attachdir);
$i = 0;
while (($file = readdir($dir)) != false) {
if ($file == ".") continue;
if ($file == "..") continue;
$files[] = $file;
$i+=1;
}
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 $f ?>"><?php echo $f; ?><br>
<?php
$jscript .= "attachListArr[$count] = '$f';\n";
$count++;
}
$jscript .= "</script>\n";
echo $jscript;
?>
</td>
</tr>
</table>
<br>
<input type="submit" class="vlgbutton" value="<?php displayLanguageText('TEXT-SEND-EMAIL-TO-CONTACTS'); ?>">
<input type="hidden" name="action" value="email-contacts">
<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>
<script language="JavaScript">
DoMessageChange();
</script>